Previously vrf names where generated using "ovnvrf" + datapath id.
Now the controller supports the dynamic-routing-vrf-name setting to
overwrite this to whatever value the user desires.
Note that the vrf ID is still the datapath id.

Signed-off-by: Felix Huettner <[email protected]>
---
v5->v6:
  * addressed review comments

 controller/route-exchange.c | 14 ++++++--------
 controller/route.c          | 19 ++++++++++++++++++-
 controller/route.h          |  2 ++
 tests/system-ovn.at         | 25 +++++++++++++++++++------
 4 files changed, 45 insertions(+), 15 deletions(-)

diff --git a/controller/route-exchange.c b/controller/route-exchange.c
index d01c3726f..70ef4474a 100644
--- a/controller/route-exchange.c
+++ b/controller/route-exchange.c
@@ -219,27 +219,25 @@ route_exchange_run(struct route_exchange_ctx_in *r_ctx_in,
     const struct advertise_datapath_entry *ad;
     HMAP_FOR_EACH (ad, node, r_ctx_in->announce_routes) {
         uint32_t table_id = ad->db->tunnel_key;
-        char vrf_name[IFNAMSIZ + 1];
-        snprintf(vrf_name, sizeof vrf_name, "ovnvrf%"PRIi32, table_id);
 
         if (ad->maintain_vrf) {
-            if (!sset_contains(&old_maintained_vrfs, vrf_name)) {
-                int error = re_nl_create_vrf(vrf_name, table_id);
+            if (!sset_contains(&old_maintained_vrfs, ad->vrf_name)) {
+                int error = re_nl_create_vrf(ad->vrf_name, table_id);
                 if (error && error != EEXIST) {
                     VLOG_WARN_RL(&rl,
                                  "Unable to create VRF %s for datapath "
                                  "%"PRIi32": %s.",
-                                 vrf_name, table_id,
+                                 ad->vrf_name, table_id,
                                  ovs_strerror(error));
                     continue;
                 }
             }
-            sset_add(&_maintained_vrfs, vrf_name);
+            sset_add(&_maintained_vrfs, ad->vrf_name);
         } else {
             /* a previous maintain-vrf flag was removed. We should therfore
              * also not delete it even if we created it previously. */
-            sset_find_and_delete(&_maintained_vrfs, vrf_name);
-            sset_find_and_delete(&old_maintained_vrfs, vrf_name);
+            sset_find_and_delete(&_maintained_vrfs, ad->vrf_name);
+            sset_find_and_delete(&old_maintained_vrfs, ad->vrf_name);
         }
 
         maintained_route_table_add(table_id);
diff --git a/controller/route.c b/controller/route.c
index 4cf143756..65ef903a9 100644
--- a/controller/route.c
+++ b/controller/route.c
@@ -30,7 +30,6 @@
 #include "route.h"
 
 VLOG_DEFINE_THIS_MODULE(exchange);
-static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
 
 #define PRIORITY_DEFAULT 1000
 #define PRIORITY_LOCAL_BOUND 100
@@ -138,6 +137,23 @@ route_run(struct route_ctx_in *r_ctx_in,
             char *ifname = nullable_xstrdup(
                                     smap_get(&repb->options,
                                              "dynamic-routing-ifname"));
+
+            const char *vrf_name = smap_get(&repb->options,
+                                            "dynamic-routing-vrf-name");
+            if (vrf_name && strlen(vrf_name) >= IFNAMSIZ) {
+                static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
+                VLOG_WARN_RL(&rl, "Ignoring vrf name %s, since it is too long."
+                             "Maximum length is %d characters", vrf_name,
+                             IFNAMSIZ);
+                vrf_name = NULL;
+            }
+            if (vrf_name) {
+                memcpy(ad->vrf_name, vrf_name, strlen(vrf_name) + 1);
+            } else {
+                snprintf(ad->vrf_name, sizeof ad->vrf_name, "ovnvrf%"PRIi64,
+                         ad->db->tunnel_key);
+            }
+
             smap_add_nocopy(&ad->bound_ports,
                             xstrdup(local_peer->logical_port), ifname);
         }
@@ -164,6 +180,7 @@ route_run(struct route_ctx_in *r_ctx_in,
         struct in6_addr prefix;
         unsigned int plen;
         if (!ip46_parse_cidr(route->ip_prefix, &prefix, &plen)) {
+            static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
             VLOG_WARN_RL(&rl, "bad 'ip_prefix' %s in route "
                          UUID_FMT, route->ip_prefix,
                          UUID_ARGS(&route->header_.uuid));
diff --git a/controller/route.h b/controller/route.h
index ca555171f..86c9f3206 100644
--- a/controller/route.h
+++ b/controller/route.h
@@ -20,6 +20,7 @@
 
 #include <stdbool.h>
 #include <netinet/in.h>
+#include <net/if.h>
 #include "openvswitch/hmap.h"
 #include "sset.h"
 #include "smap.h"
@@ -55,6 +56,7 @@ struct advertise_datapath_entry {
     struct hmap_node node;
     const struct sbrec_datapath_binding *db;
     bool maintain_vrf;
+    char vrf_name[IFNAMSIZ + 1];
     struct hmap routes;
 
     /* The name of the port bindings locally bound for this datapath and
diff --git a/tests/system-ovn.at b/tests/system-ovn.at
index b3ca1e58a..aedf82702 100644
--- a/tests/system-ovn.at
+++ b/tests/system-ovn.at
@@ -15470,6 +15470,7 @@ OVN_FOR_EACH_NORTHD([
 AT_SETUP([dynamic-routing - DGP])
 
 VRF_RESERVE([1337])
+VRF_RESERVE([1338])
 
 # This test uses dynamic routing on a simulated multi-tenant internet
 # connection.
@@ -15715,10 +15716,24 @@ blackhole 192.0.2.10 proto 84 metric 100
 blackhole 198.51.100.0/24 proto 84 metric 1000
 233.252.0.0/24 via 192.168.10.10 dev lo onlink])
 
+# Changing the vrf name will switch to the new one.
+# The old vrf will be removed.
+check ovn-nbctl --wait=hv set Logical_Router_Port internet-phys \
+                             options:dynamic-routing-maintain-vrf=true
+check ovn-nbctl --wait=hv set Logical_Router internet 
options:dynamic-routing-vrf-name=ovnvrf1338
+AT_CHECK([ip vrf | grep -q ovnvrf1337], [1], [])
+OVS_WAIT_UNTIL_EQUAL([ip route list vrf ovnvrf1338 | awk '{$1=$1};1'], [dnl
+blackhole 192.0.2.1 proto 84 metric 1000
+blackhole 192.0.2.2 proto 84 metric 100
+blackhole 192.0.2.3 proto 84 metric 100
+blackhole 192.0.2.10 proto 84 metric 100
+blackhole 198.51.100.0/24 proto 84 metric 1000
+233.252.0.0/24 via 192.168.10.10 dev lo onlink])
+
 # Stoping with --restart will not touch the routes.
 check ovn-appctl -t ovn-controller exit --restart
 OVS_WAIT_UNTIL([test "$(ovn-appctl -t ovn-controller debug/status)" != 
"running"])
-OVS_WAIT_UNTIL_EQUAL([ip route list vrf ovnvrf1337 | awk '{$1=$1};1'], [dnl
+OVS_WAIT_UNTIL_EQUAL([ip route list vrf ovnvrf1338 | awk '{$1=$1};1'], [dnl
 blackhole 192.0.2.1 proto 84 metric 1000
 blackhole 192.0.2.2 proto 84 metric 100
 blackhole 192.0.2.3 proto 84 metric 100
@@ -15726,14 +15741,12 @@ blackhole 192.0.2.10 proto 84 metric 100
 blackhole 198.51.100.0/24 proto 84 metric 1000
 233.252.0.0/24 via 192.168.10.10 dev lo onlink])
 
-# Now we set maintain-vrf again and stop the ovn-controller.
-# It will then remove the VRF.
+# When we now stop the ovn-controller it will remove the VRF.
 start_daemon ovn-controller
 OVS_WAIT_UNTIL([test "$(ovn-appctl -t ovn-controller debug/status)" == 
"running"])
-check ovn-nbctl --wait=hv set Logical_Router_Port internet-phys \
-        options:dynamic-routing-maintain-vrf=true
+check ovn-nbctl --wait=hv sync
 OVS_APP_EXIT_AND_WAIT([ovn-controller])
-AT_CHECK([ip vrf | grep -q ovnvrf1337], [1], [])
+AT_CHECK([ip vrf | grep -q ovnvrf1338], [1], [])
 
 as ovn-sb
 OVS_APP_EXIT_AND_WAIT([ovsdb-server])
-- 
2.47.1


_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to