]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: Score weighted values of ecmp to a number between 1-255
authorDonald Sharp <sharpd@nvidia.com>
Thu, 28 Sep 2023 16:27:31 +0000 (12:27 -0400)
committerDonald Sharp <sharpd@nvidia.com>
Thu, 12 Oct 2023 17:34:43 +0000 (13:34 -0400)
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 <sharpd@nvidia.com>
zebra/zapi_msg.c

index 6754238ce582f9f112080551bc66d8986a876a88..2aeb1b97e9254804030b5326a9a710cce5742186 100644 (file)
@@ -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));
 
@@ -1697,6 +1701,40 @@ 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 * 255;
+                       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