mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-15 11:30:30 +00:00
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>
This commit is contained in:
parent
02b89bdca2
commit
9d86e091bb
@ -642,7 +642,6 @@ module frr-zebra {
|
|||||||
type identityref {
|
type identityref {
|
||||||
base afi-safi-type;
|
base afi-safi-type;
|
||||||
}
|
}
|
||||||
mandatory true;
|
|
||||||
description
|
description
|
||||||
"AFI, SAFI name.";
|
"AFI, SAFI name.";
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "zebra_nb.h"
|
#include "zebra_nb.h"
|
||||||
#include "zebra/interface.h"
|
#include "zebra/interface.h"
|
||||||
#include "zebra/connected.h"
|
#include "zebra/connected.h"
|
||||||
|
#include "zebra/zebra_router.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* XPath: /frr-zebra:zebra/mcast-rpf-lookup
|
* 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)
|
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) {
|
switch (args->event) {
|
||||||
case NB_EV_VALIDATE:
|
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_PREPARE:
|
||||||
case NB_EV_ABORT:
|
case NB_EV_ABORT:
|
||||||
|
break;
|
||||||
case NB_EV_APPLY:
|
case NB_EV_APPLY:
|
||||||
/* TODO: implement me. */
|
|
||||||
|
nb_running_set_entry(args->dnode, zrt);
|
||||||
|
|
||||||
break;
|
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)
|
int lib_vrf_ribs_rib_destroy(struct nb_cb_destroy_args *args)
|
||||||
{
|
{
|
||||||
switch (args->event) {
|
if (args->event != NB_EV_APPLY)
|
||||||
case NB_EV_VALIDATE:
|
return NB_OK;
|
||||||
case NB_EV_PREPARE:
|
|
||||||
case NB_EV_ABORT:
|
nb_running_unset_entry(args->dnode);
|
||||||
case NB_EV_APPLY:
|
|
||||||
/* TODO: implement me. */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NB_OK;
|
return NB_OK;
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "libfrr.h"
|
#include "libfrr.h"
|
||||||
#include "zebra_nb.h"
|
#include "zebra_nb.h"
|
||||||
#include "zebra/interface.h"
|
#include "zebra/interface.h"
|
||||||
|
#include "zebra/zebra_router.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* XPath: /frr-interface:lib/interface/frr-zebra:zebra/state/up-count
|
* 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)
|
const void *lib_vrf_ribs_rib_get_next(struct nb_cb_get_next_args *args)
|
||||||
{
|
{
|
||||||
/* TODO: implement me. */
|
struct vrf *vrf = (struct vrf *)parent_list_entry;
|
||||||
return NULL;
|
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)
|
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;
|
return NB_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *lib_vrf_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args)
|
const void *lib_vrf_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args)
|
||||||
{
|
{
|
||||||
/* TODO: implement me. */
|
struct vrf *vrf = (struct vrf *)parent_list_entry;
|
||||||
return NULL;
|
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)
|
const void *lib_vrf_ribs_rib_route_get_next(struct nb_cb_get_next_args *args)
|
||||||
{
|
{
|
||||||
/* TODO: implement me. */
|
const struct zebra_router_table *zrt = parent_list_entry;
|
||||||
return NULL;
|
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)
|
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;
|
return NB_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *
|
const void *
|
||||||
lib_vrf_ribs_rib_route_lookup_entry(struct nb_cb_lookup_entry_args *args)
|
lib_vrf_ribs_rib_route_lookup_entry(struct nb_cb_lookup_entry_args *args)
|
||||||
{
|
{
|
||||||
/* TODO: implement me. */
|
const struct zebra_router_table *zrt = parent_list_entry;
|
||||||
return NULL;
|
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 *
|
struct yang_data *
|
||||||
lib_vrf_ribs_rib_route_prefix_get_elem(struct nb_cb_get_elem_args *args)
|
lib_vrf_ribs_rib_route_prefix_get_elem(struct nb_cb_get_elem_args *args)
|
||||||
{
|
{
|
||||||
/* TODO: implement me. */
|
const struct route_node *rn = list_entry;
|
||||||
return NULL;
|
|
||||||
|
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 *
|
const void *
|
||||||
lib_vrf_ribs_rib_route_route_entry_get_next(struct nb_cb_get_next_args *args)
|
lib_vrf_ribs_rib_route_route_entry_get_next(struct nb_cb_get_next_args *args)
|
||||||
{
|
{
|
||||||
/* TODO: implement me. */
|
struct route_entry *re = NULL;
|
||||||
return NULL;
|
|
||||||
|
return re;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lib_vrf_ribs_rib_route_route_entry_get_keys(
|
int lib_vrf_ribs_rib_route_route_entry_get_keys(
|
||||||
|
@ -66,6 +66,22 @@ zebra_router_table_entry_compare(const struct zebra_router_table *e1,
|
|||||||
return (e1->safi - e2->safi);
|
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,
|
struct route_table *zebra_router_find_table(struct zebra_vrf *zvrf,
|
||||||
uint32_t tableid, afi_t afi,
|
uint32_t tableid, afi_t afi,
|
||||||
|
@ -186,6 +186,9 @@ extern void zebra_router_init(void);
|
|||||||
extern void zebra_router_cleanup(void);
|
extern void zebra_router_cleanup(void);
|
||||||
extern void zebra_router_terminate(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,
|
extern struct route_table *zebra_router_find_table(struct zebra_vrf *zvrf,
|
||||||
uint32_t tableid, afi_t afi,
|
uint32_t tableid, afi_t afi,
|
||||||
safi_t safi);
|
safi_t safi);
|
||||||
|
Loading…
Reference in New Issue
Block a user