[PATCH 2/2] Babel: Add option to control ecmp nexthop weight

Daniel Gröber dxld at darkboxed.org
Sun May 8 10:06:52 CEST 2022


---
 doc/bird.sgml        | 21 ++++++++++++++-------
 proto/babel/babel.c  |  1 +
 proto/babel/babel.h  |  2 ++
 proto/babel/config.Y |  2 ++
 4 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/doc/bird.sgml b/doc/bird.sgml
index 5e85d8ec..1fdda7bc 100644
--- a/doc/bird.sgml
+++ b/doc/bird.sgml
@@ -1865,6 +1865,7 @@ protocol babel [<name>] {
 	ipv4 { <channel config> };
 	ipv6 [sadr] { <channel config> };
         randomize router id <switch>;
+	ecmp <switch> [limit <num>];
 	interface <interface pattern> {
 		type <wired|wireless>;
 		rxcost <number>;
@@ -1879,7 +1880,7 @@ protocol babel [<name>] {
 		check link <switch>;
 		next hop ipv4 <address>;
 		next hop ipv6 <address>;
-		ecmp <switch> [limit <num>];
+		ecmp weight <num>;
 		authentication none|mac [permissive];
 		password "<text>";
 		password "<text>" {
@@ -1910,6 +1911,13 @@ protocol babel [<name>] {
       router ID every time it starts up, which avoids this problem at the cost
       of not having stable router IDs in the network. Default: no.
 
+      <tag><label id="babel-ecmp">ecmp <m>switch</m> [limit <m>number</m>]</tag>
+
+      Determines whether babel will emit ECMP (equal-cost multipath)
+      routes, allowing to load-balancing traffic across multiple paths. If
+      enabled the maximum number of next-hops to allow can be specified,
+      defaulting to 16.
+
       <tag><label id="babel-type">type wired|wireless </tag>
       This option specifies the interface type: Wired or wireless. On wired
       interfaces a neighbor is considered unreachable after a small number of
@@ -1984,12 +1992,11 @@ protocol babel [<name>] {
       source for Babel packets will be used. In normal operation, it should not
       be necessary to set this option.
 
-      <tag><label id="babel-ecmp">ecmp <m>switch</m> [limit <m>number</m>]</tag>
-
-      Determines whether babel will emit ECMP (equal-cost multipath)
-      routes, allowing to load-balancing traffic across multiple paths. If
-      enabled the maximum number of next-hops to allow can be specified,
-      defaulting to 16.
+      <tag><label id="babel-ecmp-weight">ecmp weight <m>number</m></tag>
+      This specifies the relative weight used for nexthops going through
+      the iface when ECMP is enabled. Larger weight values relative to other
+      nexthops attract more traffic. Valid values are 1-256. Default value
+      is 1.
 
       <tag><label id="babel-authentication">authentication none|mac [permissive]</tag>
       Selects authentication method to be used. <cf/none/ means that packets
diff --git a/proto/babel/babel.c b/proto/babel/babel.c
index 4d9c657c..83d9a1d0 100644
--- a/proto/babel/babel.c
+++ b/proto/babel/babel.c
@@ -639,6 +639,7 @@ babel_nexthop_insert(
 {
   nh->gw = r->next_hop;
   nh->iface = r->neigh->ifa->iface;
+  nh->weight = r->neigh->ifa->cf->ecmp_weight;
 
   /*
    * If we cannot find a reachable neighbour, set the entry to be onlink. This
diff --git a/proto/babel/babel.h b/proto/babel/babel.h
index 3868dcb2..2ad1ded0 100644
--- a/proto/babel/babel.h
+++ b/proto/babel/babel.h
@@ -145,6 +145,8 @@ struct babel_iface_config {
   int tx_tos;
   int tx_priority;
 
+  u8 ecmp_weight;
+
   ip_addr next_hop_ip4;
   ip_addr next_hop_ip6;
 
diff --git a/proto/babel/config.Y b/proto/babel/config.Y
index 8f18c790..6f03482a 100644
--- a/proto/babel/config.Y
+++ b/proto/babel/config.Y
@@ -70,6 +70,7 @@ babel_iface_start:
   BABEL_IFACE->tx_tos = IP_PREC_INTERNET_CONTROL;
   BABEL_IFACE->tx_priority = sk_priority_control;
   BABEL_IFACE->check_link = 1;
+  BABEL_IFACE->ecmp_weight = 0;
 };
 
 
@@ -149,6 +150,7 @@ babel_iface_item:
  | AUTHENTICATION NONE { BABEL_IFACE->auth_type = BABEL_AUTH_NONE; }
  | AUTHENTICATION MAC { BABEL_IFACE->auth_type = BABEL_AUTH_MAC; BABEL_IFACE->auth_permissive = 0; }
  | AUTHENTICATION MAC PERMISSIVE { BABEL_IFACE->auth_type = BABEL_AUTH_MAC; BABEL_IFACE->auth_permissive = 1; }
+ | ECMP WEIGHT expr { BABEL_IFACE->ecmp_weight = $3 - 1; if (($3<1) || ($3>256)) cf_error("ECMP weight must be in range 1-256"); }
  | password_list
  ;
 
-- 
2.30.2



More information about the Bird-users mailing list