Skip to content

Commit

Permalink
zebra: Added the picnh_dependents structure to assist in the kernel p…
Browse files Browse the repository at this point in the history
…latform by reverse looking up all associated NHEs through pic_nh, and then sending NHG updates to the kernel.

Signed-off-by: hanyu.zly <hanyu.zly@alibaba-inc.com>
  • Loading branch information
zice312963205 committed Jan 16, 2025
1 parent 594caa8 commit 1b945ec
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 8 deletions.
7 changes: 3 additions & 4 deletions zebra/dplane_fpm_nl.c
Original file line number Diff line number Diff line change
Expand Up @@ -927,10 +927,9 @@ static int fpm_nl_enqueue(struct fpm_nl_ctx *fnc, struct zebra_dplane_ctx *ctx)
* If we were configured to not use next hop groups, then quit as soon
* as possible.
*/
if ((!fnc->use_nhg) &&
(op == DPLANE_OP_NH_DELETE || op == DPLANE_OP_NH_INSTALL || op == DPLANE_OP_NH_UPDATE ||
op == DPLANE_OP_PIC_NH_DELETE || op == DPLANE_OP_PIC_NH_INSTALL ||
op == DPLANE_OP_PIC_NH_UPDATE))
if ((!fnc->use_nhg) && (op == DPLANE_OP_NH_DELETE || op == DPLANE_OP_NH_INSTALL ||
op == DPLANE_OP_NH_UPDATE || op == DPLANE_OP_PIC_NH_DELETE ||
op == DPLANE_OP_PIC_NH_INSTALL || op == DPLANE_OP_PIC_NH_UPDATE))
return 0;

nl_buf_len = 0;
Expand Down
57 changes: 53 additions & 4 deletions zebra/zebra_nhg.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,45 @@ static void zebra_nhg_depends_release(struct nhg_hash_entry *nhe)
}
}

unsigned int zebra_nhg_pic_dependents_count(const struct nhg_hash_entry *nhe)
{
return nhg_connected_tree_count(&nhe->picnh_dependents);
}


bool zebra_nhg_pic_dependents_is_empty(const struct nhg_hash_entry *nhe)
{
return nhg_connected_tree_is_empty(&nhe->picnh_dependents);
}

static void zebra_nhg_pic_dependents_del(struct nhg_hash_entry *from, struct nhg_hash_entry *pic_nh)
{
nhg_connected_tree_del_nhe(&from->picnh_dependents, pic_nh);
}

static void zebra_nhg_pic_dependents_add(struct nhg_hash_entry *to, struct nhg_hash_entry *pic_nh)
{
nhg_connected_tree_add_nhe(&to->picnh_dependents, pic_nh);
}

static void zebra_nhg_pic_dependents_init(struct nhg_hash_entry *nhe)
{
nhg_connected_tree_init(&nhe->picnh_dependents);
}

/* Release this nhe from anything depending on it */
static void zebra_nhg_pic_dependents_release(struct nhg_hash_entry *nhe)
{
struct nhg_connected *rb_node_dep = NULL;

frr_each_safe (nhg_connected_tree, &nhe->picnh_dependents, rb_node_dep) {
if (rb_node_dep->nhe->pic_nhe) {
zebra_nhg_pic_dependents_del(nhe, rb_node_dep->nhe);
zebra_nhg_decrement_ref(rb_node_dep->nhe->pic_nhe);
rb_node_dep->nhe->pic_nhe = NULL;
}
}
}

struct nhg_hash_entry *zebra_nhg_lookup_id(uint32_t id)
{
Expand Down Expand Up @@ -691,8 +730,12 @@ static bool zebra_need_to_create_pic(struct nexthop *nh)
{
if (!fpm_pic_nexthop)
return false;
if (nh && nh->nh_srv6 && nh->nh_srv6->seg6_segs && !sid_zero(nh->nh_srv6->seg6_segs))
return true;
if (nh) {
if (nh->nh_srv6 && nh->nh_srv6->seg6_segs && !sid_zero(nh->nh_srv6->seg6_segs))
return true;
if (nh->nh_label)
return true;
}
return false;
}

Expand Down Expand Up @@ -945,6 +988,9 @@ bool zebra_pic_nhe_find(struct nhg_hash_entry **pic_nhe, /* return value */
created = zebra_nhe_find(&picnhe, &pic_nh_lookup, NULL, afi, from_dplane, true);

*pic_nhe = picnhe;
if (created)
zebra_nhg_pic_dependents_init(picnhe);
zebra_nhg_pic_dependents_add(picnhe, nhe);
if (pic_nh_lookup.nhg.nexthop)
nexthops_free(pic_nh_lookup.nhg.nexthop);
if (IS_ZEBRA_DEBUG_NHG_DETAIL)
Expand Down Expand Up @@ -1221,6 +1267,7 @@ static void zebra_nhg_release_all_deps(struct nhg_hash_entry *nhe)
/* Remove it from any lists it may be on */
zebra_nhg_depends_release(nhe);
zebra_nhg_dependents_release(nhe);
zebra_nhg_pic_dependents_release(nhe);
if (nhe->ifp) {
struct zebra_if *zif = nhe->ifp->info;

Expand Down Expand Up @@ -1745,9 +1792,11 @@ static void zebra_nhg_free_members(struct nhg_hash_entry *nhe)

/* Decrement to remove connection ref */
nhg_connected_tree_decrement_ref(&nhe->nhg_depends);
if (nhe->pic_nhe)
if (nhe->pic_nhe) {
zebra_nhg_pic_dependents_del(nhe->pic_nhe, nhe);
zebra_nhg_decrement_ref(nhe->pic_nhe);
nhe->pic_nhe = NULL;
nhe->pic_nhe = NULL;
}
nhg_connected_tree_free(&nhe->nhg_depends);
nhg_connected_tree_free(&nhe->nhg_dependents);
}
Expand Down
5 changes: 5 additions & 0 deletions zebra/zebra_nhg.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct nhg_hash_entry {
* nhg(2)->nhg_dependents is 3 in the tree
*/
struct nhg_connected_tree_head nhg_depends, nhg_dependents;
struct nhg_connected_tree_head picnh_dependents;
struct nhg_hash_entry *pic_nhe;
struct event *timer;

Expand Down Expand Up @@ -299,6 +300,10 @@ extern unsigned int
zebra_nhg_dependents_count(const struct nhg_hash_entry *nhe);
extern bool zebra_nhg_dependents_is_empty(const struct nhg_hash_entry *nhe);

extern unsigned int zebra_nhg_pic_dependents_count(const struct nhg_hash_entry *nhe);
extern bool zebra_nhg_pic_dependents_is_empty(const struct nhg_hash_entry *nhe);


/* Lookup ID, doesn't create */
extern struct nhg_hash_entry *zebra_nhg_lookup_id(uint32_t id);

Expand Down
19 changes: 19 additions & 0 deletions zebra/zebra_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,7 @@ static void show_nexthop_group_out(struct vty *vty, struct nhg_hash_entry *nhe,
char time_left[MONOTIME_STRLEN];
json_object *json_dependants = NULL;
json_object *json_depends = NULL;
json_object *json_pic_dependants = NULL;
json_object *json_nexthop_array = NULL;
json_object *json_nexthops = NULL;
json_object *json = NULL;
Expand Down Expand Up @@ -1314,6 +1315,24 @@ static void show_nexthop_group_out(struct vty *vty, struct nhg_hash_entry *nhe,
if (nhe->pic_nhe)
vty_out(vty, " pic nhe:%d \n", nhe->pic_nhe->id);

if (!zebra_nhg_pic_dependents_is_empty(nhe)) {
if (json)
json_pic_dependants = json_object_new_array();
else
vty_out(vty, " PIC Dependents:");
frr_each (nhg_connected_tree, &nhe->picnh_dependents, rb_node_dep) {
if (json)
json_object_array_add(json_pic_dependants,
json_object_new_int(rb_node_dep->nhe->id));
else
vty_out(vty, " (%u)", rb_node_dep->nhe->id);
}
if (json)
json_object_object_add(json, "pic_dependents", json_pic_dependants);
else
vty_out(vty, "\n");
}

if (nhe->nhg.nhgr.buckets) {
if (json) {
json_object_int_add(json, "buckets",
Expand Down

0 comments on commit 1b945ec

Please sign in to comment.