diff options
author | Chirag Shah <chirag@cumulusnetworks.com> | 2020-02-28 03:38:24 +0100 |
---|---|---|
committer | Chirag Shah <chirag@cumulusnetworks.com> | 2020-05-12 22:25:10 +0200 |
commit | 9d86e091bb2bf1a1385408631c90a4bf3694468f (patch) | |
tree | 8c1a576332be502119eea50b7fbe987c843e9a7d /zebra/zebra_nb_state.c | |
parent | Merge pull request #6334 from ton31337/fix/labeled_unicast_table_scount (diff) | |
download | frr-9d86e091bb2bf1a1385408631c90a4bf3694468f.tar.xz frr-9d86e091bb2bf1a1385408631c90a4bf3694468f.zip |
zebra: northbound changes for the rib model
This commit implements:
RIB operational list create/destroy.
Walk over RIB tables using keys.
The first RIB table will be IPV4/unicast (table-id 254)
will be fetched.
Create a new api to fetch RIB table based on
afi-safi and table id as the keys.
remove mandatory true statement from the leaf which
is part of the list key.
Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
Diffstat (limited to 'zebra/zebra_nb_state.c')
-rw-r--r-- | zebra/zebra_nb_state.c | 95 |
1 files changed, 81 insertions, 14 deletions
diff --git a/zebra/zebra_nb_state.c b/zebra/zebra_nb_state.c index 09c76e602..83252f592 100644 --- a/zebra/zebra_nb_state.c +++ b/zebra/zebra_nb_state.c @@ -22,6 +22,7 @@ #include "libfrr.h" #include "zebra_nb.h" #include "zebra/interface.h" +#include "zebra/zebra_router.h" /* * XPath: /frr-interface:lib/interface/frr-zebra:zebra/state/up-count @@ -149,20 +150,57 @@ lib_interface_zebra_state_mcast_group_get_elem(struct nb_cb_get_elem_args *args) const void *lib_vrf_ribs_rib_get_next(struct nb_cb_get_next_args *args) { - /* TODO: implement me. */ - return NULL; + struct vrf *vrf = (struct vrf *)parent_list_entry; + struct zebra_router_table *zrt = + (struct zebra_router_table *)list_entry; + + struct zebra_vrf *zvrf; + afi_t afi; + safi_t safi; + + zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id); + + if (list_entry == NULL) { + afi = AFI_IP; + safi = SAFI_UNICAST; + + zrt = zebra_router_find_zrt(zvrf, zvrf->table_id, afi, safi); + if (zrt == NULL) + return NULL; + } else { + zrt = RB_NEXT(zebra_router_table_head, zrt); + /* vrf_id/ns_id do not match, only walk for the given VRF */ + while (zrt && zrt->ns_id != zvrf->zns->ns_id) + zrt = RB_NEXT(zebra_router_table_head, zrt); + } + + return zrt; } int lib_vrf_ribs_rib_get_keys(struct nb_cb_get_keys_args *args) { - /* TODO: implement me. */ + const struct zebra_router_table *zrt = list_entry; + + keys->num = 2; + + snprintf(keys->key[0], sizeof(keys->key[0]), "%s", + "frr-zebra:ipv4-unicast"); + /* TODO: implement key[0], afi-safi identityref */ + snprintf(keys->key[1], sizeof(keys->key[1]), "%" PRIu32, zrt->tableid); + return NB_OK; } const void *lib_vrf_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args) { - /* TODO: implement me. */ - return NULL; + struct vrf *vrf = (struct vrf *)parent_list_entry; + struct zebra_vrf *zvrf; + afi_t afi = AFI_IP; + safi_t safi = SAFI_UNICAST; + + zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id); + + return zebra_router_find_zrt(zvrf, zvrf->table_id, afi, safi); } /* @@ -170,21 +208,48 @@ const void *lib_vrf_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args) */ const void *lib_vrf_ribs_rib_route_get_next(struct nb_cb_get_next_args *args) { - /* TODO: implement me. */ - return NULL; + const struct zebra_router_table *zrt = parent_list_entry; + const struct route_node *rn = list_entry; + + if (list_entry == NULL) + rn = route_top(zrt->table); + else + rn = srcdest_route_next((struct route_node *)rn); + + return rn; } int lib_vrf_ribs_rib_route_get_keys(struct nb_cb_get_keys_args *args) { - /* TODO: implement me. */ + const struct route_node *rn = list_entry; + char dst_buf[PREFIX_STRLEN]; + const struct prefix *dst_p; + + srcdest_rnode_prefixes(rn, &dst_p, NULL); + keys->num = 1; + strlcpy(keys->key[0], prefix2str(dst_p, dst_buf, sizeof(dst_p)), + sizeof(keys->key[0])); + return NB_OK; } const void * lib_vrf_ribs_rib_route_lookup_entry(struct nb_cb_lookup_entry_args *args) { - /* TODO: implement me. */ - return NULL; + const struct zebra_router_table *zrt = parent_list_entry; + struct prefix p; + struct route_node *rn; + + yang_str2prefix(keys->key[0], &p); + + rn = route_node_lookup(zrt->table, &p); + + if (!rn) + return NULL; + + route_unlock_node(rn); + + return rn; } /* @@ -193,8 +258,9 @@ lib_vrf_ribs_rib_route_lookup_entry(struct nb_cb_lookup_entry_args *args) struct yang_data * lib_vrf_ribs_rib_route_prefix_get_elem(struct nb_cb_get_elem_args *args) { - /* TODO: implement me. */ - return NULL; + const struct route_node *rn = list_entry; + + return yang_data_new_prefix(xpath, &rn->p); } /* @@ -203,8 +269,9 @@ lib_vrf_ribs_rib_route_prefix_get_elem(struct nb_cb_get_elem_args *args) const void * lib_vrf_ribs_rib_route_route_entry_get_next(struct nb_cb_get_next_args *args) { - /* TODO: implement me. */ - return NULL; + struct route_entry *re = NULL; + + return re; } int lib_vrf_ribs_rib_route_route_entry_get_keys( |