diff options
author | vdhingra <vdhingra@vmware.com> | 2020-07-02 07:36:51 +0200 |
---|---|---|
committer | vdhingra <vdhingra@vmware.com> | 2020-07-16 17:40:42 +0200 |
commit | 755100ac8983324e02cca9e1ab50bca1ab2da4da (patch) | |
tree | 82f051868e1d186b7164788774ffe57858c34c5a | |
parent | staticd : Configuration northbound implementation (diff) | |
download | frr-755100ac8983324e02cca9e1ab50bca1ab2da4da.tar.xz frr-755100ac8983324e02cca9e1ab50bca1ab2da4da.zip |
zebra: Moving afi-safi identity to lib
afi-safi identity handling should be in the common place.
Signed-off-by: VishalDhingra <vdhingra@vmware.com>
-rw-r--r-- | lib/yang_wrappers.c | 35 | ||||
-rw-r--r-- | lib/yang_wrappers.h | 3 | ||||
-rw-r--r-- | yang/frr-routing.yang | 29 | ||||
-rw-r--r-- | yang/frr-zebra.yang | 31 | ||||
-rw-r--r-- | zebra/main.c | 2 | ||||
-rw-r--r-- | zebra/zebra_nb.c | 34 | ||||
-rw-r--r-- | zebra/zebra_nb.h | 4 | ||||
-rw-r--r-- | zebra/zebra_nb_config.c | 2 | ||||
-rw-r--r-- | zebra/zebra_nb_state.c | 7 |
9 files changed, 74 insertions, 73 deletions
diff --git a/lib/yang_wrappers.c b/lib/yang_wrappers.c index c31ba3fcc..8b0e89d52 100644 --- a/lib/yang_wrappers.c +++ b/lib/yang_wrappers.c @@ -1191,3 +1191,38 @@ const char *yang_nexthop_type2str(uint32_t ntype) break; } } + + +const char *yang_afi_safi_value2identity(afi_t afi, safi_t safi) +{ + if (afi == AFI_IP && safi == SAFI_UNICAST) + return "frr-routing:ipv4-unicast"; + if (afi == AFI_IP6 && safi == SAFI_UNICAST) + return "frr-routing:ipv6-unicast"; + if (afi == AFI_IP && safi == SAFI_MULTICAST) + return "frr-routing:ipv4-multicast"; + if (afi == AFI_IP6 && safi == SAFI_MULTICAST) + return "frr-routing:ipv6-multicast"; + + return NULL; +} + +void yang_afi_safi_identity2value(const char *key, afi_t *afi, safi_t *safi) +{ + if (strmatch(key, "frr-routing:ipv4-unicast")) { + *afi = AFI_IP; + *safi = SAFI_UNICAST; + } else if (strmatch(key, "frr-routing:ipv6-unicast")) { + *afi = AFI_IP6; + *safi = SAFI_UNICAST; + } else if (strmatch(key, "frr-routing:ipv4-multicast")) { + *afi = AFI_IP; + *safi = SAFI_MULTICAST; + } else if (strmatch(key, "frr-routing:ipv6-multicast")) { + *afi = AFI_IP6; + *safi = SAFI_MULTICAST; + } else { + *afi = AFI_UNSPEC; + *safi = SAFI_UNSPEC; + } +} diff --git a/lib/yang_wrappers.h b/lib/yang_wrappers.h index ba2cf5139..335ff319d 100644 --- a/lib/yang_wrappers.h +++ b/lib/yang_wrappers.h @@ -191,6 +191,9 @@ extern struct yang_data *yang_data_new_date_and_time(const char *xpath, /* nexthop enum2str */ extern const char *yang_nexthop_type2str(uint32_t ntype); +const char *yang_afi_safi_value2identity(afi_t afi, safi_t safi); +void yang_afi_safi_identity2value(const char *key, afi_t *afi, safi_t *safi); + #ifdef __cplusplus } #endif diff --git a/yang/frr-routing.yang b/yang/frr-routing.yang index 0f64f3f48..d22e12074 100644 --- a/yang/frr-routing.yang +++ b/yang/frr-routing.yang @@ -72,6 +72,35 @@ module frr-routing { "This identity represents an IPv6 address family."; } + identity afi-safi-type { + description + "Base identity type (AFI,SAFI) tuples for RIB"; + } + + identity ipv4-unicast { + base afi-safi-type; + description + "This identity represents the IPv4 unicast address family."; + } + + identity ipv6-unicast { + base afi-safi-type; + description + "This identity represents the IPv6 unicast address family."; + } + + identity ipv4-multicast { + base afi-safi-type; + description + "This identity represents the IPv4 multicast address family."; + } + + identity ipv6-multicast { + base afi-safi-type; + description + "This identity represents the IPv6 multicast address family."; + } + identity control-plane-protocol { description "Base identity from which control-plane protocol identities are diff --git a/yang/frr-zebra.yang b/yang/frr-zebra.yang index 159dd8f79..8894eeaa2 100644 --- a/yang/frr-zebra.yang +++ b/yang/frr-zebra.yang @@ -77,35 +77,6 @@ module frr-zebra { "Initial revision."; } - identity afi-safi-type { - description - "Base identity type (AFI,SAFI) tuples for RIB"; - } - - identity ipv4-unicast { - base afi-safi-type; - description - "This identity represents the IPv4 unicast address family."; - } - - identity ipv6-unicast { - base afi-safi-type; - description - "This identity represents the IPv6 unicast address family."; - } - - identity ipv4-multicast { - base afi-safi-type; - description - "This identity represents the IPv4 multicast address family."; - } - - identity ipv6-multicast { - base afi-safi-type; - description - "This identity represents the IPv6 multicast address family."; - } - typedef unix-timestamp { type uint32; units "seconds"; @@ -634,7 +605,7 @@ module frr-zebra { key "afi-safi-name table-id"; leaf afi-safi-name { type identityref { - base afi-safi-type; + base frr-rt:afi-safi-type; } description "AFI, SAFI name."; diff --git a/zebra/main.c b/zebra/main.c index 748e43b8d..9de24c5e4 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -35,6 +35,7 @@ #include "vrf.h" #include "libfrr.h" #include "routemap.h" +#include "routing_nb.h" #include "zebra/zebra_router.h" #include "zebra/zebra_errors.h" @@ -258,6 +259,7 @@ static const struct frr_yang_module_info *const zebra_yang_modules[] = { &frr_route_map_info, &frr_zebra_info, &frr_vrf_info, + &frr_routing_info, }; FRR_DAEMON_INFO( diff --git a/zebra/zebra_nb.c b/zebra/zebra_nb.c index 53fe8e8e3..6f01c41d7 100644 --- a/zebra/zebra_nb.c +++ b/zebra/zebra_nb.c @@ -22,40 +22,6 @@ #include "libfrr.h" #include "zebra_nb.h" -const char *zebra_afi_safi_value2identity(afi_t afi, safi_t safi) -{ - if (afi == AFI_IP && safi == SAFI_UNICAST) - return "ipv4-unicast"; - if (afi == AFI_IP6 && safi == SAFI_UNICAST) - return "ipv6-unicast"; - if (afi == AFI_IP && safi == SAFI_MULTICAST) - return "ipv4-multicast"; - if (afi == AFI_IP6 && safi == SAFI_MULTICAST) - return "ipv6-multicast"; - - return " "; -} - -void zebra_afi_safi_identity2value(const char *key, afi_t *afi, safi_t *safi) -{ - if (strmatch(key, "frr-zebra:ipv4-unicast")) { - *afi = AFI_IP; - *safi = SAFI_UNICAST; - } else if (strmatch(key, "frr-zebra:ipv6-unicast")) { - *afi = AFI_IP6; - *safi = SAFI_UNICAST; - } else if (strmatch(key, "frr-zebra:ipv4-multicast")) { - *afi = AFI_IP; - *safi = SAFI_MULTICAST; - } else if (strmatch(key, "frr-zebra:ipv6-multicast")) { - *afi = AFI_IP6; - *safi = SAFI_MULTICAST; - } else { - *afi = AFI_UNSPEC; - *safi = SAFI_UNSPEC; - } -} - /* clang-format off */ const struct frr_yang_module_info frr_zebra_info = { .name = "frr-zebra", diff --git a/zebra/zebra_nb.h b/zebra/zebra_nb.h index a9e7fd5fb..defa206d5 100644 --- a/zebra/zebra_nb.h +++ b/zebra/zebra_nb.h @@ -26,10 +26,6 @@ extern "C" { extern const struct frr_yang_module_info frr_zebra_info; -/* helper functions */ -const char *zebra_afi_safi_value2identity(afi_t afi, safi_t safi); -void zebra_afi_safi_identity2value(const char *key, afi_t *afi, safi_t *safi); - /* prototypes */ int get_route_information_rpc(struct nb_cb_rpc_args *args); int get_v6_mroute_info_rpc(struct nb_cb_rpc_args *args); diff --git a/zebra/zebra_nb_config.c b/zebra/zebra_nb_config.c index 948ef5132..259b5f1eb 100644 --- a/zebra/zebra_nb_config.c +++ b/zebra/zebra_nb_config.c @@ -1242,7 +1242,7 @@ int lib_vrf_zebra_ribs_rib_create(struct nb_cb_create_args *args) table_id = zvrf->table_id; afi_safi_name = yang_dnode_get_string(args->dnode, "./afi-safi-name"); - zebra_afi_safi_identity2value(afi_safi_name, &afi, &safi); + yang_afi_safi_identity2value(afi_safi_name, &afi, &safi); zrt = zebra_router_find_zrt(zvrf, table_id, afi, safi); diff --git a/zebra/zebra_nb_state.c b/zebra/zebra_nb_state.c index 4374da360..b5fde5f03 100644 --- a/zebra/zebra_nb_state.c +++ b/zebra/zebra_nb_state.c @@ -185,9 +185,8 @@ int lib_vrf_zebra_ribs_rib_get_keys(struct nb_cb_get_keys_args *args) args->keys->num = 2; - snprintfrr(args->keys->key[0], sizeof(args->keys->key[0]), "%s:%s", - "frr-zebra", - zebra_afi_safi_value2identity(zrt->afi, zrt->safi)); + snprintfrr(args->keys->key[0], sizeof(args->keys->key[0]), "%s", + yang_afi_safi_value2identity(zrt->afi, zrt->safi)); snprintfrr(args->keys->key[1], sizeof(args->keys->key[1]), "%u", zrt->tableid); @@ -205,7 +204,7 @@ lib_vrf_zebra_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args) zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id); - zebra_afi_safi_identity2value(args->keys->key[0], &afi, &safi); + yang_afi_safi_identity2value(args->keys->key[0], &afi, &safi); table_id = yang_str2uint32(args->keys->key[1]); /* table_id 0 assume vrf's table_id. */ if (!table_id) |