[PATCH v2] Babel: allow enabling link quality estimation manually

Nick Cao nickcao at nichi.co
Fri Jun 23 06:33:22 CEST 2023


Link quality estimation is useful for link types other than wireless,
especially when using babel with tunnels where packet losses do occur.

Changes since v1:
 - fix missing reference to link quality in example configuration
 - fix mishandling of default configuration

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

diff --git a/doc/bird.sgml b/doc/bird.sgml
index 8041faa9..e597de83 100644
--- a/doc/bird.sgml
+++ b/doc/bird.sgml
@@ -1929,6 +1929,7 @@ protocol babel [<name>] {
 		rx buffer <number>;
 		tx length <number>;
 		check link <switch>;
+		link quality <switch>;
 		next hop ipv4 <address>;
 		next hop ipv6 <address>;
 		extended next hop <switch>;
@@ -2032,6 +2033,12 @@ protocol babel [<name>] {
       hardware drivers or platforms do not implement this feature. Default:
       yes.
 
+      <tag><label id="babel-link-quality">link quality <m/switch/</tag>
+      If set, link quality estimation is performed on this interface.
+      Link quality is measured by packet loss and is used for computing
+      metrics of routes going through this interface. Default: yes for
+      wireless interfaces, no otherwise.
+
       <tag><label id="babel-next-hop-ipv4">next hop ipv4 <m/address/</tag>
       Set the next hop address advertised for IPv4 routes advertised on this
       interface. Default: the preferred IPv4 address of the interface.
diff --git a/proto/babel/babel.c b/proto/babel/babel.c
index 7f0cca73..6a238d75 100644
--- a/proto/babel/babel.c
+++ b/proto/babel/babel.c
@@ -593,21 +593,15 @@ babel_update_cost(struct babel_neighbor *nbr)
   if (!rcv || !nbr->ifa->up)
     goto done;
 
-  switch (cf->type)
-  {
-  case BABEL_IFACE_TYPE_WIRED:
-  case BABEL_IFACE_TYPE_TUNNEL:
+  if (!cf->link_quality) {
     /* k-out-of-j selection - Appendix 2.1 in the RFC. */
 
     /* Link is bad if less than cf->limit/16 of expected hellos were received */
-    if (rcv * 16 < cf->limit * max)
-      break;
-
-    rxcost =  cf->rxcost;
-    txcost = nbr->txcost;
-    break;
-
-  case BABEL_IFACE_TYPE_WIRELESS:
+    if (!(rcv * 16 < cf->limit * max)) {
+      rxcost =  cf->rxcost;
+      txcost = nbr->txcost;
+    }
+  } else {
     /*
      * ETX - Appendix 2.2 in the RFC.
      *
@@ -622,7 +616,6 @@ babel_update_cost(struct babel_neighbor *nbr)
      */
     rxcost = MIN( cf->rxcost * max / rcv, BABEL_INFINITY);
     txcost = MIN(nbr->txcost * max / rcv, BABEL_INFINITY);
-    break;
   }
 
   if (cf->rtt_cost && nbr->srtt > cf->rtt_min)
diff --git a/proto/babel/babel.h b/proto/babel/babel.h
index edde4cab..6145bb58 100644
--- a/proto/babel/babel.h
+++ b/proto/babel/babel.h
@@ -145,6 +145,7 @@ struct babel_iface_config {
   u8 type;
   u8 limit;				/* Minimum number of Hellos to keep link up */
   u8 check_link;
+  u8 link_quality;			/* bool + 2 for unspecified */
   uint port;
   uint hello_interval;			/* Hello interval, in us */
   uint ihu_interval;			/* IHU interval, in us */
diff --git a/proto/babel/config.Y b/proto/babel/config.Y
index b8af0267..4a3d33cb 100644
--- a/proto/babel/config.Y
+++ b/proto/babel/config.Y
@@ -26,7 +26,7 @@ CF_KEYWORDS(BABEL, INTERFACE, METRIC, RXCOST, HELLO, UPDATE, INTERVAL, PORT,
 	TYPE, WIRED, WIRELESS, RX, TX, BUFFER, PRIORITY, LENGTH, CHECK, LINK,
 	NEXT, HOP, IPV4, IPV6, BABEL_METRIC, SHOW, INTERFACES, NEIGHBORS,
 	ENTRIES, RANDOMIZE, ROUTER, ID, AUTHENTICATION, NONE, MAC, PERMISSIVE,
-	EXTENDED, TUNNEL, RTT, MIN, MAX, DECAY, SEND, TIMESTAMPS)
+	EXTENDED, TUNNEL, RTT, MIN, MAX, DECAY, SEND, TIMESTAMPS, QUALITY)
 
 CF_GRAMMAR
 
@@ -72,6 +72,7 @@ babel_iface_start:
   BABEL_IFACE->rtt_decay = BABEL_RTT_DECAY;
   BABEL_IFACE->rtt_send = 1;
   BABEL_IFACE->check_link = 1;
+  BABEL_IFACE->link_quality = 2;
   BABEL_IFACE->ext_next_hop = 1;
 };
 
@@ -84,6 +85,8 @@ babel_iface_finish:
       BABEL_IFACE->hello_interval = BABEL_HELLO_INTERVAL_WIRELESS;
     if (!BABEL_IFACE->rxcost)
       BABEL_IFACE->rxcost = BABEL_RXCOST_WIRELESS;
+    if (BABEL_IFACE->link_quality == 2)
+      BABEL_IFACE->link_quality = 1;
   }
   else
   {
@@ -93,6 +96,8 @@ babel_iface_finish:
       BABEL_IFACE->rxcost = BABEL_RXCOST_WIRED;
     if (BABEL_IFACE->type == BABEL_IFACE_TYPE_TUNNEL && !BABEL_IFACE->rtt_cost)
       BABEL_IFACE->rtt_cost = BABEL_RXCOST_RTT;
+    if (BABEL_IFACE->link_quality == 2)
+      BABEL_IFACE->link_quality = 0;
   }
 
   if (BABEL_IFACE->rtt_cost && !BABEL_IFACE->rtt_send)
@@ -156,6 +161,7 @@ babel_iface_item:
  | TX tos { BABEL_IFACE->tx_tos = $2; }
  | TX PRIORITY expr { BABEL_IFACE->tx_priority = $3; }
  | CHECK LINK bool { BABEL_IFACE->check_link = $3; }
+ | LINK QUALITY bool { BABEL_IFACE->link_quality = $3; }
  | NEXT HOP IPV4 ipa { BABEL_IFACE->next_hop_ip4 = $4; if (!ipa_is_ip4($4)) cf_error("Must be an IPv4 address"); }
  | NEXT HOP IPV6 ipa { BABEL_IFACE->next_hop_ip6 = $4; if (!ipa_is_ip6($4)) cf_error("Must be an IPv6 address"); }
  | EXTENDED NEXT HOP bool { BABEL_IFACE->ext_next_hop = $4; }
-- 
2.41.0



More information about the Bird-users mailing list