Skip to content

Commit

Permalink
controller: Support user defined vrf names.
Browse files Browse the repository at this point in the history
Previously vrf names where generated using "ovnvrf" + datapath id.
Now the controller supports the dynamic-routing-vrf-name setting to
freely configure the vrf name.
Note that the vrf ID is still the datapath id.

Signed-off-by: Felix Huettner <[email protected]>
Signed-off-by: Dumitru Ceara <[email protected]>
  • Loading branch information
felixhuettner authored and dceara committed Feb 11, 2025
1 parent b344a53 commit cb7ba9e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
14 changes: 6 additions & 8 deletions controller/route-exchange.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,27 +217,25 @@ route_exchange_run(const 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 therefore
* 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);
Expand Down
16 changes: 16 additions & 0 deletions controller/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ route_run(struct route_ctx_in *r_ctx_in,
"dynamic-routing-maintain-vrf",
false);

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);
}

const char *port_name = smap_get(&repb->options,
"dynamic-routing-port-name");
if (!port_name) {
Expand Down
2 changes: 2 additions & 0 deletions controller/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -59,6 +60,7 @@ struct advertise_datapath_entry {

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
Expand Down
27 changes: 21 additions & 6 deletions tests/system-ovn.at
Original file line number Diff line number Diff line change
Expand Up @@ -15921,6 +15921,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.
Expand Down Expand Up @@ -16195,10 +16196,26 @@ blackhole 198.51.100.0/24 proto 84 metric 1000
233.252.0.0/24 via 192.168.10.10 dev lo onlink
233.253.0.0/24 via 192.168.20.20 dev hv1-mll 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
233.253.0.0/24 via 192.168.20.20 dev hv1-mll 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
Expand All @@ -16207,14 +16224,12 @@ blackhole 198.51.100.0/24 proto 84 metric 1000
233.252.0.0/24 via 192.168.10.10 dev lo onlink
233.253.0.0/24 via 192.168.20.20 dev hv1-mll 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])
Expand Down

0 comments on commit cb7ba9e

Please sign in to comment.