From ca2b3467830877ca279a7bad6d8c2d162fa45e8e Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 24 Oct 2022 09:49:40 -0400 Subject: [PATCH] *: Add ability to encode / decode resilence down zapi At this point add abilty for the encode/decode of the resilience down ZAPI to zebra. Just hookup sharpd at this point in time. Signed-off-by: Donald Sharp --- lib/zclient.c | 4 ++++ lib/zclient.h | 4 ++++ sharpd/sharp_nht.c | 14 ++++++++++++++ sharpd/sharp_zebra.c | 3 +++ zebra/zapi_msg.c | 6 ++++++ zebra/zebra_nhg.c | 1 + 6 files changed, 32 insertions(+) diff --git a/lib/zclient.c b/lib/zclient.c index 4a553f4718..2517773dc4 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1166,6 +1166,10 @@ static int zapi_nhg_encode(struct stream *s, int cmd, struct zapi_nhg *api_nhg) stream_putw(s, api_nhg->proto); stream_putl(s, api_nhg->id); + stream_putw(s, api_nhg->resilience.buckets); + stream_putl(s, api_nhg->resilience.idle_timer); + stream_putl(s, api_nhg->resilience.unbalanced_timer); + if (cmd == ZEBRA_NHG_ADD) { /* Nexthops */ zapi_nexthop_group_sort(api_nhg->nexthops, diff --git a/lib/zclient.h b/lib/zclient.h index fb5da9aad2..31ab60485e 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -35,6 +35,8 @@ struct zclient; /* For union g_addr */ #include "nexthop.h" +/* For resilience */ +#include "nexthop_group.h" /* For union pw_protocol_fields */ #include "pw.h" @@ -463,6 +465,8 @@ struct zapi_nhg { uint16_t proto; uint32_t id; + struct nhg_resilience resilience; + uint16_t nexthop_num; struct zapi_nexthop nexthops[MULTIPATH_NUM]; diff --git a/sharpd/sharp_nht.c b/sharpd/sharp_nht.c index da14899768..b032da6a1d 100644 --- a/sharpd/sharp_nht.c +++ b/sharpd/sharp_nht.c @@ -126,6 +126,20 @@ static void sharp_nhgroup_add_cb(const char *name) static void sharp_nhgroup_modify_cb(const struct nexthop_group_cmd *nhgc) { + struct sharp_nhg lookup; + struct sharp_nhg *snhg; + struct nexthop_group_cmd *bnhgc = NULL; + + strlcpy(lookup.name, nhgc->name, sizeof(lookup.name)); + snhg = sharp_nhg_rb_find(&nhg_head, &lookup); + + if (!nhgc->nhg.nexthop) + return; + + if (nhgc->backup_list_name[0]) + bnhgc = nhgc_find(nhgc->backup_list_name); + + nhg_add(snhg->id, &nhgc->nhg, (bnhgc ? &bnhgc->nhg : NULL)); } static void sharp_nhgroup_add_nexthop_cb(const struct nexthop_group_cmd *nhgc, diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index b40c2c6228..9d343576d6 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -550,6 +550,9 @@ void nhg_add(uint32_t id, const struct nexthop_group *nhg, bool is_valid = true; api_nhg.id = id; + + api_nhg.resilience = nhg->nhgr; + for (ALL_NEXTHOPS_PTR(nhg, nh)) { if (api_nhg.nexthop_num >= MULTIPATH_NUM) { zlog_warn( diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index 4d7ad21bf3..a3db53f296 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -1874,6 +1874,10 @@ static int zapi_nhg_decode(struct stream *s, int cmd, struct zapi_nhg *api_nhg) if (cmd == ZEBRA_NHG_DEL) goto done; + STREAM_GETW(s, api_nhg->resilience.buckets); + STREAM_GETL(s, api_nhg->resilience.idle_timer); + STREAM_GETL(s, api_nhg->resilience.unbalanced_timer); + /* Nexthops */ STREAM_GETW(s, api_nhg->nexthop_num); @@ -1998,6 +2002,8 @@ static void zread_nhg_add(ZAPI_HANDLER_ARGS) nhe->nhg.nexthop = nhg->nexthop; nhg->nexthop = NULL; + nhe->nhg.nhgr = api_nhg.resilience; + if (bnhg) { nhe->backup_info = bnhg; bnhg = NULL; diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index 07e1e5f305..5fadd4c82b 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -3367,6 +3367,7 @@ struct nhg_hash_entry *zebra_nhg_proto_add(uint32_t id, int type, zebra_nhe_init(&lookup, afi, nhg->nexthop); lookup.nhg.nexthop = nhg->nexthop; + lookup.nhg.nhgr = nhg->nhgr; lookup.id = id; lookup.type = type;