diff mbox series

[ovs-dev,v3,12/33] northd: Add filtering which routes to advertise.

Message ID 4008ea1c9b092d796cb507758449874d2d22d15a.1732630355.git.felix.huettner@stackit.cloud
State Changes Requested
Headers show
Series OVN Fabric integration | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success

Commit Message

Felix Huettner Nov. 26, 2024, 2:38 p.m. UTC
previously all routes of a logical router where announced. However in
some cases it makes more sense to only announce static or connected
routes. Therefor we add options to LR and LRP to define which routes to
advertise.

Signed-off-by: Felix Huettner <felix.huettner@stackit.cloud>
---
 NEWS                    |  3 ++
 northd/en-routes-sync.c | 18 ++++++++++
 ovn-nb.xml              | 78 +++++++++++++++++++++++++++++++++++++----
 tests/ovn-northd.at     | 59 ++++++++++++++++++++++++++++++-
 4 files changed, 150 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/NEWS b/NEWS
index 5e266fed8..3961aa652 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,9 @@  Post v24.09.0
   - Add the option "dynamic-routing" to Logical Routers. If set to true all
     static and connected routes attached to the router are shared to the
     southbound "Route" table for sharing outside of OVN.
+    The routes can furthe be filtered by setting `dynamic-routing-connected`
+    and `dynamic-routing-static` on the LR or LRP. The LRP settings overwrite
+    the LR settings for all routes using this interface as an exit.
 
 OVN v24.09.0 - 13 Sep 2024
 --------------------------
diff --git a/northd/en-routes-sync.c b/northd/en-routes-sync.c
index bb61e0d51..581f21b8e 100644
--- a/northd/en-routes-sync.c
+++ b/northd/en-routes-sync.c
@@ -15,6 +15,7 @@ 
 #include <config.h>
 
 #include "openvswitch/vlog.h"
+#include "smap.h"
 #include "stopwatch.h"
 #include "northd.h"
 
@@ -128,6 +129,13 @@  route_erase_entry(struct route_entry *route_e)
     free(route_e);
 }
 
+static bool
+get_nbrp_or_nbr_option(const struct ovn_port *op, const char *key)
+{
+    return smap_get_bool(&op->nbrp->options, key,
+        smap_get_bool(&op->od->nbr->options, key, false));
+}
+
 static void
 routes_table_sync(struct ovsdb_idl_txn *ovnsb_txn,
                   const struct sbrec_route_table *sbrec_route_table,
@@ -164,6 +172,16 @@  routes_table_sync(struct ovsdb_idl_txn *ovnsb_txn,
                            false)) {
             continue;
         }
+        if (route->source == ROUTE_SOURCE_CONNECTED &&
+                !get_nbrp_or_nbr_option(route->out_port,
+                                        "dynamic-routing-connected")) {
+            continue;
+        }
+        if (route->source == ROUTE_SOURCE_STATIC &&
+                !get_nbrp_or_nbr_option(route->out_port,
+                                        "dynamic-routing-static")) {
+            continue;
+        }
         route_e = route_lookup_or_add(&sync_routes,
                                       route->od->sb,
                                       route->out_port->key,
diff --git a/ovn-nb.xml b/ovn-nb.xml
index dbe674f0b..75fe40c01 100644
--- a/ovn-nb.xml
+++ b/ovn-nb.xml
@@ -2935,13 +2935,45 @@  or
         If set to <code>true</code> then this <ref table="Logical_Router"/>
         can participate in dynamic routing with components outside of OVN.
 
-        It will synchronize all routes to the soutbound
-        <ref table="Route" db="OVN_SB"/> table that are relevant for the
-        router. This includes:
-        * all "connected" routes implicitly created by networks associated with
-          this Logical Router
-        * all <ref table="Logical_Router_Static_Route"/> that are applied to
-          this Logical Router
+        Users will need to use the following settings to opt into individual
+        routes types that should be advertised. See:
+        * <ref column="options" key="dynamic-routing-connected"
+               table="Logical_Router"/>
+        * <ref column="options" key="dynamic-routing-static"
+               table="Logical_Router"/>
+        * <ref column="options" key="dynamic-routing-connected"
+               table="Logical_Router_Port"/>
+        * <ref column="options" key="dynamic-routing-static"
+               table="Logical_Router_Port"/>
+      </column>
+
+      <column name="options" key="dynamic-routing-connected"
+              type='{"type": "boolean"}'>
+        Only relevant if <ref column="options" key="dynamic-routing"
+        table="Logical_Router"/> is set to <code>true</code>.
+
+        If this is <code>true</code> as well then northd will synchronize all
+        "connected" routes to the southbound <ref table="Route" db="OVN_SB"/>
+        table. "Connected" here means routes implicitly created by networks
+        associated with the LRPs.
+
+        This value can be overwritten on a per LRP basis using
+        <ref column="options" key="dynamic-routing-connected"
+             table="Logical_Router_Port"/>.
+      </column>
+
+      <column name="options" key="dynamic-routing-static"
+              type='{"type": "boolean"}'>
+        Only relevant if <ref column="options" key="dynamic-routing"
+        table="Logical_Router"/> is set to <code>true</code>.
+
+        If this is <code>true</code> as well then northd will synchronize all
+        <ref table="Logical_Router_Static_Route"/> to the southbound
+        <ref table="Route" db="OVN_SB"/> table.
+
+        This value can be overwritten on a per LRP basis using
+        <ref column="options" key="dynamic-routing-static"
+             table="Logical_Router_Port"/>.
       </column>
     </group>
 
@@ -3641,6 +3673,38 @@  or
           <ref column="options" key="gateway_mtu"/> option.
         </p>
       </column>
+
+      <column name="options" key="dynamic-routing-connected"
+              type='{"type": "boolean"}'>
+        Only relevant if <ref column="options" key="dynamic-routing"
+        table="Logical_Router"/> on the respective Logical_Router is set
+        to <code>true</code>.
+
+        If this is <code>true</code> as well then northd will synchronize all
+        "connected" routes associated with this LRP to the southbound
+        <ref table="Route" db="OVN_SB"/> table. "Connected" here means routes
+        implicitly created by network associated with this LRP.
+
+        If not set the value from <ref column="options"
+        key="dynamic-routing-connected" table="Logical_Router_Port"/> will be
+        used.
+      </column>
+
+      <column name="options" key="dynamic-routing-static"
+              type='{"type": "boolean"}'>
+        Only relevant if <ref column="options" key="dynamic-routing"
+        table="Logical_Router"/> on the respective Logical_Router is set
+        to <code>true</code>.
+
+        If this is <code>true</code> as well then northd will synchronize all
+        <ref table="Logical_Router_Static_Route"/> to the southbound
+        <ref table="Route" db="OVN_SB"/> table that use this LRP as an outgoin
+        interface.
+
+        If not set the value from <ref column="options"
+        key="dynamic-routing-static" table="Logical_Router_Port"/> will be
+        used.
+      </column>
     </group>
 
     <group title="Attachment">
diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at
index f1775c9c5..9b786bc1f 100644
--- a/tests/ovn-northd.at
+++ b/tests/ovn-northd.at
@@ -13836,7 +13836,9 @@  ovn_start
 
 # adding a router - still nothing here
 check ovn-nbctl lr-add lr0
-check ovn-nbctl --wait=sb set Logical_Router lr0 option:dynamic-routing=true
+check ovn-nbctl --wait=sb set Logical_Router lr0 option:dynamic-routing=true \
+                                 option:dynamic-routing-connected=true \
+                                 option:dynamic-routing-static=true
 check_row_count Route 0
 datapath=$(ovn-sbctl --bare --columns _uuid list datapath_binding lr0)
 
@@ -13881,3 +13883,58 @@  check_row_count Route 1 logical_port=lr0-sw1
 
 AT_CLEANUP
 ])
+
+OVN_FOR_EACH_NORTHD_NO_HV([
+AT_SETUP([dynamic-routing - sync to sb filtering])
+AT_KEYWORDS([dynamic-routing])
+ovn_start
+
+# we start with announcing everything on a lr with 2 lrps and 2 static routes
+check ovn-nbctl lr-add lr0
+check ovn-nbctl --wait=sb set Logical_Router lr0 option:dynamic-routing=true \
+                                 option:dynamic-routing-connected=true \
+                                 option:dynamic-routing-static=true
+check ovn-nbctl --wait=sb lrp-add lr0 lr0-sw0 00:00:00:00:ff:01 10.0.0.1/24
+check ovn-nbctl --wait=sb lrp-add lr0 lr0-sw1 00:00:00:00:ff:02 10.0.1.1/24
+check ovn-nbctl --wait=sb lr-route-add lr0 192.168.0.0/24 10.0.0.10
+check ovn-nbctl --wait=sb lr-route-add lr0 192.168.1.0/24 10.0.1.10
+check_row_count Route 4 type=advertise
+datapath=$(ovn-sbctl --bare --columns _uuid list datapath_binding lr0)
+
+# disabeling connected routes just keeps the static ones
+check ovn-nbctl --wait=sb remove Logical_Router lr0 option dynamic-routing-connected
+check_row_count Route 2 type=advertise
+AT_CHECK([ovn-sbctl --columns ip_prefix --bare find Route datapath=$datapath logical_port=lr0-sw0], [0], [dnl
+192.168.0.0/24
+])
+AT_CHECK([ovn-sbctl --columns ip_prefix --bare find Route datapath=$datapath logical_port=lr0-sw1], [0], [dnl
+192.168.1.0/24
+])
+
+# enabeling it on lr0-sw0 will just bring this one route back
+check ovn-nbctl --wait=sb set Logical_Router_Port lr0-sw0 option:dynamic-routing-connected=true
+check_row_count Route 3 type=advertise
+check_row_count Route 2 type=advertise logical_port=lr0-sw0
+check_row_count Route 1 type=advertise logical_port=lr0-sw0 ip_prefix=10.0.0.0/24
+check_row_count Route 1 type=advertise logical_port=lr0-sw0 ip_prefix=192.168.0.0/24
+
+# disabeling static routes just keeps the one explicit connected route
+check ovn-nbctl --wait=sb remove Logical_Router lr0 option dynamic-routing-static
+check_row_count Route 1 type=advertise
+AT_CHECK([ovn-sbctl --columns ip_prefix --bare find Route datapath=$datapath logical_port=lr0-sw0], [0], [dnl
+10.0.0.0/24
+])
+
+# enabeling static routes on the LR, but disabeling them on lr0-sw0 also works
+check ovn-nbctl --wait=sb set Logical_Router lr0 option:dynamic-routing-static=true
+check ovn-nbctl --wait=sb set Logical_Router_Port lr0-sw0 option:dynamic-routing-static=false
+check_row_count Route 2 type=advertise
+AT_CHECK([ovn-sbctl --columns ip_prefix --bare find Route datapath=$datapath logical_port=lr0-sw0], [0], [dnl
+10.0.0.0/24
+])
+AT_CHECK([ovn-sbctl --columns ip_prefix --bare find Route datapath=$datapath logical_port=lr0-sw1], [0], [dnl
+192.168.1.0/24
+])
+
+AT_CLEANUP
+])