Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zebra weighted ecmp #14553

Merged
merged 5 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -1207,26 +1207,20 @@ static bool update_ipv6nh_for_route_install(int nh_othervrf, struct bgp *nh_bgp,
}

static bool bgp_zebra_use_nhop_weighted(struct bgp *bgp, struct attr *attr,
uint64_t tot_bw, uint32_t *nh_weight)
uint32_t *nh_weight)
{
uint32_t bw;
uint64_t tmp;

bw = attr->link_bw;
/* zero link-bandwidth and link-bandwidth not present are treated
* as the same situation.
*/
if (!bw) {
if (!attr->link_bw) {
/* the only situations should be if we're either told
* to skip or use default weight.
*/
if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING)
return false;
*nh_weight = BGP_ZEBRA_DEFAULT_NHOP_WEIGHT;
} else {
tmp = (uint64_t)bw * 100;
*nh_weight = ((uint32_t)(tmp / tot_bw));
}
} else
*nh_weight = attr->link_bw;

return true;
}
Expand Down Expand Up @@ -1255,7 +1249,6 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p,
int nh_othervrf = 0;
bool nh_updated = false;
bool do_wt_ecmp;
uint64_t cum_bw = 0;
uint32_t nhg_id = 0;
bool is_add;
uint32_t ttl = 0;
Expand Down Expand Up @@ -1339,8 +1332,6 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p,

/* Determine if we're doing weighted ECMP or not */
do_wt_ecmp = bgp_path_info_mpath_chkwtd(bgp, info);
if (do_wt_ecmp)
cum_bw = bgp_path_info_mpath_cumbw(info);

/* EVPN MAC-IP routes are installed with a L3 NHG id */
if (bgp_evpn_path_es_use_nhg(bgp, info, &nhg_id)) {
Expand Down Expand Up @@ -1382,7 +1373,7 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p,
*/
if (do_wt_ecmp) {
if (!bgp_zebra_use_nhop_weighted(bgp, mpinfo->attr,
cum_bw, &nh_weight))
&nh_weight))
continue;
}
api_nh = &api.nexthops[valid_nh_count];
Expand Down
4 changes: 2 additions & 2 deletions tests/topotests/bgp_link_bw_ip/r1/ip-route-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
{
"fib":true,
"ip":"11.1.1.6",
"weight":25
"weight":85
},
{
"fib":true,
"ip":"11.1.1.2",
"weight":75
"weight":255
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions tests/topotests/bgp_link_bw_ip/r1/ip-route-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
{
"fib":true,
"ip":"11.1.1.6",
"weight":33
"weight":127
},
{
"fib":true,
"ip":"11.1.1.2",
"weight":66
"weight":255
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions tests/topotests/bgp_link_bw_ip/r1/ip-route-3.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
{
"fib":true,
"ip":"11.1.1.6",
"weight":33
"weight":127
},
{
"fib":true,
"ip":"11.1.1.2",
"weight":66
"weight":255
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/topotests/bgp_link_bw_ip/r1/ip-route-6.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"fib":true,
"ip":"11.1.1.2",
"weight":100
"weight":255
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/topotests/bgp_link_bw_ip/r1/ip-route-7.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"fib":true,
"ip":"11.1.1.2",
"weight":100
"weight":255
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/topotests/bgp_link_bw_ip/r1/ip-route-8.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
"fib":true,
"ip":"11.1.1.2",
"weight":100
"weight":255
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/topotests/bgp_link_bw_ip/r1/ip-route-9.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
"fib":true,
"ip":"11.1.1.2",
"weight":100
"weight":255
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions tests/topotests/bgp_link_bw_ip/r2/ip-route-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
{
"fib":true,
"ip":"11.1.2.6",
"weight":33
"weight":127
},
{
"fib":true,
"ip":"11.1.2.2",
"weight":66
"weight":255
}
]
}
Expand Down
39 changes: 39 additions & 0 deletions zebra/zapi_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1679,10 +1679,14 @@ static bool zapi_read_nexthops(struct zserv *client, struct prefix *p,
struct nexthop_group **png,
struct nhg_backup_info **pbnhg)
{
struct zapi_nexthop *znh;
struct nexthop_group *ng = NULL;
struct nhg_backup_info *bnhg = NULL;
uint16_t i;
struct nexthop *last_nh = NULL;
bool same_weight = true;
uint64_t max_weight = 0;
uint64_t tmp;

assert(!(png && pbnhg));

Expand All @@ -1697,6 +1701,41 @@ static bool zapi_read_nexthops(struct zserv *client, struct prefix *p,
bnhg = zebra_nhg_backup_alloc();
}

for (i = 0; i < nexthop_num; i++) {
znh = &nhops[i];

if (max_weight < znh->weight) {
if (i != 0 || znh->weight != 1)
same_weight = false;

max_weight = znh->weight;
}
}

/*
* Let's convert the weights to a scaled value
* between 1 and zrouter.nexthop_weight_scale_value
* This is a simple application of a ratio:
* scaled_weight/zrouter.nexthop_weight_scale_value =
* weight/max_weight
* This translates to:
* scaled_weight = weight * zrouter.nexthop_weight_scale_value
* -------------------------------------------
* max_weight
*
* This same formula is applied to both the nexthops
* and the backup nexthops
*/
if (!same_weight) {
for (i = 0; i < nexthop_num; i++) {
znh = &nhops[i];

tmp = (uint64_t)znh->weight *
zrouter.nexthop_weight_scale_value;
znh->weight = MAX(1, ((uint32_t)(tmp / max_weight)));
}
}

/*
* TBD should _all_ of the nexthop add operations use
* api_nh->vrf_id instead of re->vrf_id ? I only changed
Expand Down
2 changes: 2 additions & 0 deletions zebra/zebra_router.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ void zebra_router_init(bool asic_offload, bool notify_on_ack,
#endif
zrouter.asic_notification_nexthop_control = false;

zrouter.nexthop_weight_scale_value = 255;

#ifdef HAVE_SCRIPTING
zebra_script_init();
#endif
Expand Down
2 changes: 2 additions & 0 deletions zebra/zebra_router.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ struct zebra_router {
bool allow_delete;

uint8_t protodown_r_bit;

uint64_t nexthop_weight_scale_value;
};

#define GRACEFUL_RESTART_TIME 60
Expand Down
Loading