Skip to content

Commit

Permalink
zebra: Score weighted values of ecmp to a number between 1-255
Browse files Browse the repository at this point in the history
Currently underlying asics get into a bit of trouble when the
nexthop weight passed down varies wildly between the different
numbers.  Let's normalize the weight values between 1 and 255

Signed-off-by: Donald Sharp <[email protected]>
  • Loading branch information
donaldsharp committed Sep 28, 2023
1 parent 8640fc9 commit cb5c1c9
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions zebra/zapi_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,8 @@ static int zapi_nhg_decode(struct stream *s, int cmd, struct zapi_nhg *api_nhg)
{
uint16_t i;
struct zapi_nexthop *znh;
bool same_weight = true;
uint64_t max_weight = 0;

STREAM_GETW(s, api_nhg->proto);
STREAM_GETL(s, api_nhg->id);
Expand Down Expand Up @@ -1888,8 +1890,29 @@ static int zapi_nhg_decode(struct stream *s, int cmd, struct zapi_nhg *api_nhg)
"%s: Nexthop creation failed", __func__);
return -1;
}

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

max_weight = znh->weight;
}
}

if (!same_weight) {
for (i = 0; i < api_nhg->nexthop_num; i++) {
uint64_t tmp;

znh = &((api_nhg->nexthops)[i]);

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

same_weight = true;
max_weight = 0;

/* Backup Nexthops */
STREAM_GETW(s, api_nhg->backup_nexthop_num);

Expand All @@ -1905,8 +1928,27 @@ static int zapi_nhg_decode(struct stream *s, int cmd, struct zapi_nhg *api_nhg)
__func__);
return -1;
}

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

max_weight = znh->weight;
}

}

if (!same_weight) {
for (i = 0; i < api_nhg->nexthop_num; i++) {
uint64_t tmp;

znh = &((api_nhg->backup_nexthops)[i]);

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

done:
return 0;

Expand Down

0 comments on commit cb5c1c9

Please sign in to comment.