]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: northbound changes for the rib model
authorChirag Shah <chirag@cumulusnetworks.com>
Fri, 28 Feb 2020 02:38:24 +0000 (18:38 -0800)
committerChirag Shah <chirag@cumulusnetworks.com>
Tue, 12 May 2020 20:25:10 +0000 (13:25 -0700)
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>
yang/frr-zebra.yang
zebra/zebra_nb_config.c
zebra/zebra_nb_state.c
zebra/zebra_router.c
zebra/zebra_router.h

index 0997a268e75cc89d234d814eaf5982dd73b9cb83..40d5ddc72b354766a6c87c75c1eb8c591bd9c5c1 100644 (file)
@@ -642,7 +642,6 @@ module frr-zebra {
           type identityref {
             base afi-safi-type;
           }
-          mandatory true;
           description
             "AFI, SAFI name.";
         }
index dbe265da8c2db9dd3958429601764391f54a2c5b..e7780e5338825a463301127310d2b9e0db06c69e 100644 (file)
@@ -29,6 +29,7 @@
 #include "zebra_nb.h"
 #include "zebra/interface.h"
 #include "zebra/connected.h"
+#include "zebra/zebra_router.h"
 
 /*
  * XPath: /frr-zebra:zebra/mcast-rpf-lookup
@@ -1220,12 +1221,40 @@ int lib_interface_zebra_bandwidth_destroy(struct nb_cb_destroy_args *args)
  */
 int lib_vrf_ribs_rib_create(struct nb_cb_create_args *args)
 {
+       struct vrf *vrf;
+       afi_t afi = AFI_IP;
+       safi_t safi = SAFI_UNICAST;
+       struct zebra_vrf *zvrf;
+       struct zebra_router_table *zrt;
+       uint32_t table_id;
+
+       vrf = nb_running_get_entry(args->dnode, NULL, false);
+       zvrf = vrf_info_lookup(vrf->vrf_id);
+       table_id = yang_dnode_get_uint32(args->dnode, "./table-id");
+       if (!table_id)
+               table_id = zvrf->table_id;
+
+       /* TODO: once identityref nb wrapper available, parse
+        * afi-safi-name and feed into the creation of the table
+        */
+
+       zrt = zebra_router_find_zrt(zvrf, table_id, afi, safi);
+
        switch (args->event) {
        case NB_EV_VALIDATE:
+               if (!zrt) {
+                       zlog_debug("%s: vrf %s table is not found.", __func__,
+                                  vrf->name);
+                       return NB_ERR_VALIDATION;
+               }
+               break;
        case NB_EV_PREPARE:
        case NB_EV_ABORT:
+               break;
        case NB_EV_APPLY:
-               /* TODO: implement me. */
+
+               nb_running_set_entry(args->dnode, zrt);
+
                break;
        }
 
@@ -1234,14 +1263,10 @@ int lib_vrf_ribs_rib_create(struct nb_cb_create_args *args)
 
 int lib_vrf_ribs_rib_destroy(struct nb_cb_destroy_args *args)
 {
-       switch (args->event) {
-       case NB_EV_VALIDATE:
-       case NB_EV_PREPARE:
-       case NB_EV_ABORT:
-       case NB_EV_APPLY:
-               /* TODO: implement me. */
-               break;
-       }
+       if (args->event != NB_EV_APPLY)
+               return NB_OK;
+
+       nb_running_unset_entry(args->dnode);
 
        return NB_OK;
 }
index 09c76e6022fde361605988c6d6e3b45f116a7b55..83252f5929ecefd922a4d2e194a4084fe4a712eb 100644 (file)
@@ -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(
index ab426ae603967757244e596616504530e4ad96ec..61fef8779f406cc5c47ffbac26dd4c7a07f4f18c 100644 (file)
@@ -66,6 +66,22 @@ zebra_router_table_entry_compare(const struct zebra_router_table *e1,
        return (e1->safi - e2->safi);
 }
 
+struct zebra_router_table *zebra_router_find_zrt(struct zebra_vrf *zvrf,
+                                                uint32_t tableid, afi_t afi,
+                                                safi_t safi)
+{
+       struct zebra_router_table finder;
+       struct zebra_router_table *zrt;
+
+       memset(&finder, 0, sizeof(finder));
+       finder.afi = afi;
+       finder.safi = safi;
+       finder.tableid = tableid;
+       finder.ns_id = zvrf->zns->ns_id;
+       zrt = RB_FIND(zebra_router_table_head, &zrouter.tables, &finder);
+
+       return zrt;
+}
 
 struct route_table *zebra_router_find_table(struct zebra_vrf *zvrf,
                                            uint32_t tableid, afi_t afi,
index 773e5a64152c187c311ad6ac6b92e0d04c268933..863c5fa71caf536001a29be677f1ad9193e71801 100644 (file)
@@ -186,6 +186,9 @@ extern void zebra_router_init(void);
 extern void zebra_router_cleanup(void);
 extern void zebra_router_terminate(void);
 
+extern struct zebra_router_table *zebra_router_find_zrt(struct zebra_vrf *zvrf,
+                                                       uint32_t tableid,
+                                                       afi_t afi, safi_t safi);
 extern struct route_table *zebra_router_find_table(struct zebra_vrf *zvrf,
                                                   uint32_t tableid, afi_t afi,
                                                   safi_t safi);