On 2/11/25 9:36 AM, Felix Huettner via dev wrote:
> From: Frode Nordahl <fnord...@ubuntu.com>
> 
> This engine node takes the routes from the "route" engine node and ensures
> they are written to the linux side.
> 
> It is separate from the "route" engine node as it will also be used to
> learn routes in the future.
> 
> Acked-by: Lorenzo Bianconi <lorenzo.bianc...@redhat.com>
> Acked-by: Dumitru Ceara <dce...@redhat.com>
> Co-Authored-By: Felix Huettner <felix.huettner@stackit.cloud>
> Signed-off-by: Felix Huettner <felix.huettner@stackit.cloud>
> Signed-off-by: Frode Nordahl <fnord...@ubuntu.com>
> ---

Hi Felix, Frode,

I applied this patch to main with the following minor style changes:

diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c
index 2512c5db13..5bf155e811 100644
--- a/controller/ovn-controller.c
+++ b/controller/ovn-controller.c
@@ -5151,7 +5151,8 @@ en_route_exchange_init(struct engine_node *node 
OVS_UNUSED,
 
 static void
 en_route_exchange_cleanup(void *data OVS_UNUSED)
-{}
+{
+}
 
 /* Returns false if the northd internal version stored in SB_Global
  * and ovn-controller internal version don't match.
diff --git a/controller/route-exchange-stub.c b/controller/route-exchange-stub.c
index 3a7709d7fd..27827df1de 100644
--- a/controller/route-exchange-stub.c
+++ b/controller/route-exchange-stub.c
@@ -21,7 +21,7 @@
 #include "route-exchange.h"
 
 void
-route_exchange_run(struct route_exchange_ctx_in *r_ctx_in OVS_UNUSED,
+route_exchange_run(const struct route_exchange_ctx_in *r_ctx_in OVS_UNUSED,
                    struct route_exchange_ctx_out *r_ctx_out OVS_UNUSED)
 {
 }
diff --git a/controller/route-exchange.c b/controller/route-exchange.c
index bba2836abf..3b4ba5d4ad 100644
--- a/controller/route-exchange.c
+++ b/controller/route-exchange.c
@@ -37,7 +37,7 @@ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 
20);
 static struct sset _maintained_vrfs = SSET_INITIALIZER(&_maintained_vrfs);
 
 void
-route_exchange_run(struct route_exchange_ctx_in *r_ctx_in,
+route_exchange_run(const struct route_exchange_ctx_in *r_ctx_in,
                    struct route_exchange_ctx_out *r_ctx_out OVS_UNUSED)
 {
     struct sset old_maintained_vrfs = SSET_INITIALIZER(&old_maintained_vrfs);
diff --git a/controller/route-exchange.h b/controller/route-exchange.h
index 7d4ad38c4f..4a9275e359 100644
--- a/controller/route-exchange.h
+++ b/controller/route-exchange.h
@@ -26,7 +26,7 @@ struct route_exchange_ctx_in {
 struct route_exchange_ctx_out {
 };
 
-void route_exchange_run(struct route_exchange_ctx_in *,
+void route_exchange_run(const struct route_exchange_ctx_in *,
                         struct route_exchange_ctx_out *);
 void route_exchange_cleanup_vrfs(void);
 void route_exchange_destroy(void);
diff --git a/tests/system-ovn.at b/tests/system-ovn.at
index d8394b27da..0038251d07 100644
--- a/tests/system-ovn.at
+++ b/tests/system-ovn.at
@@ -15929,7 +15929,7 @@ VRF_RESERVE([1337])
 # The connections of pr1 and pr2 to public are using DGPs.
 # The connection from internet to phys is also using a DGP.
 # The LR internet is running dynamic-routing.
-# The LS phys is assumed to be used for peering with a router outside OVN
+# The LS phys is assumed to be used for peering with a router outside OVN.
 #
 #
 # +----+       +----+
@@ -15965,11 +15965,11 @@ ADD_BR([br-ext])
 check ovs-ofctl add-flow br-ext action=normal
 # Set external-ids in br-int needed for ovn-controller.
 check ovs-vsctl \
-        -- set Open_vSwitch . external-ids:system-id=hv1 \
-        -- set Open_vSwitch . 
external-ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb.sock \
-        -- set Open_vSwitch . external-ids:ovn-encap-type=geneve \
-        -- set Open_vSwitch . external-ids:ovn-encap-ip=169.0.0.1 \
-        -- set bridge br-int fail-mode=secure other-config:disable-in-band=true
+    -- set Open_vSwitch . external-ids:system-id=hv1 \
+    -- set Open_vSwitch . 
external-ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb.sock \
+    -- set Open_vSwitch . external-ids:ovn-encap-type=geneve \
+    -- set Open_vSwitch . external-ids:ovn-encap-ip=169.0.0.1 \
+    -- set bridge br-int fail-mode=secure other-config:disable-in-band=true
 
 # Start ovn-controller.
 start_daemon ovn-controller
@@ -15990,7 +15990,7 @@ check ovn-nbctl lr-add internet \
 check ovn-nbctl lrp-add internet internet-public \
         00:00:02:01:02:03 192.0.2.1/24 \
     -- set Logical_Router_Port internet-public \
-            options:dynamic-routing-redistribute="connected;static"
+            options:dynamic-routing-redistribute="connected,static"
 check ovn-nbctl lsp-add public public-internet \
     -- set Logical_Switch_Port public-internet type=router \
             options:router-port=internet-public \
@@ -16063,9 +16063,9 @@ check ovn-nbctl lr-route-add internet 198.51.100.0/24 
192.0.2.3
 # Configure external connectivity.
 check ovs-vsctl set Open_vSwitch . 
external-ids:ovn-bridge-mappings=phynet:br-ext
 check ovn-nbctl lsp-add phys phys1 \
-        -- lsp-set-addresses phys1 unknown \
-        -- lsp-set-type phys1 localnet \
-        -- lsp-set-options phys1 network_name=phynet
+    -- lsp-set-addresses phys1 unknown \
+    -- lsp-set-type phys1 localnet \
+    -- lsp-set-options phys1 network_name=phynet
 
 check ovn-nbctl --wait=hv sync
 wait_for_ports_up public-internet phys-internet public-pr1 p1-pr1 public-pr2 
p2-pr2
@@ -16092,7 +16092,7 @@ blackhole 198.51.100.0/24 proto 84])
 # * 192.0.2.3/32
 # * 192.0.2.10/32
 check ovn-nbctl --wait=hv set Logical_Router_Port internet-public \
-        options:dynamic-routing-redistribute="connected-as-host;static"
+    options:dynamic-routing-redistribute="connected-as-host,static"
 
 OVS_WAIT_UNTIL_EQUAL([ip route list vrf ovnvrf1337 | awk '{$1=$1};1'], [dnl
 blackhole 192.0.2.1 proto 84
@@ -16130,7 +16130,7 @@ VRF_RESERVE([1337])
 # The connections of pr1 and pr2 to public are using DGPs.
 # The LR internet is a gateway router.
 # The LR internet is running dynamic-routing.
-# The LS phys is assumed to be used for peering with a router outside OVN
+# The LS phys is assumed to be used for peering with a router outside OVN.
 #
 #
 # +----+       +----+
@@ -16166,11 +16166,11 @@ ADD_BR([br-ext])
 check ovs-ofctl add-flow br-ext action=normal
 # Set external-ids in br-int needed for ovn-controller.
 check ovs-vsctl \
-        -- set Open_vSwitch . external-ids:system-id=hv1 \
-        -- set Open_vSwitch . 
external-ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb.sock \
-        -- set Open_vSwitch . external-ids:ovn-encap-type=geneve \
-        -- set Open_vSwitch . external-ids:ovn-encap-ip=169.0.0.1 \
-        -- set bridge br-int fail-mode=secure other-config:disable-in-band=true
+    -- set Open_vSwitch . external-ids:system-id=hv1 \
+    -- set Open_vSwitch . 
external-ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb.sock \
+    -- set Open_vSwitch . external-ids:ovn-encap-type=geneve \
+    -- set Open_vSwitch . external-ids:ovn-encap-ip=169.0.0.1 \
+    -- set bridge br-int fail-mode=secure other-config:disable-in-band=true
 
 # Start ovn-controller.
 start_daemon ovn-controller
@@ -16192,7 +16192,7 @@ check ovn-nbctl lr-add internet \
 check ovn-nbctl lrp-add internet internet-public \
         00:00:02:01:02:03 192.0.2.1/24 \
     -- set Logical_Router_Port internet-public \
-            options:dynamic-routing-redistribute="connected;static" \
+            options:dynamic-routing-redistribute="connected,static" \
             options:dynamic-routing-port-name=wedontlearnstuffhere
 check ovn-nbctl lsp-add public public-internet \
     -- set Logical_Switch_Port public-internet type=router \
@@ -16265,9 +16265,9 @@ check ovn-nbctl lr-route-add internet 198.51.100.0/24 
192.0.2.3
 # Configure external connectivity.
 check ovs-vsctl set Open_vSwitch . 
external-ids:ovn-bridge-mappings=phynet:br-ext
 check ovn-nbctl lsp-add phys phys1 \
-        -- lsp-set-addresses phys1 unknown \
-        -- lsp-set-type phys1 localnet \
-        -- lsp-set-options phys1 network_name=phynet
+    -- lsp-set-addresses phys1 unknown \
+    -- lsp-set-type phys1 localnet \
+    -- lsp-set-options phys1 network_name=phynet
 
 check ovn-nbctl --wait=hv sync
 wait_for_ports_up public-internet phys-internet public-pr1 p1-pr1 public-pr2 
p2-pr2
@@ -16294,7 +16294,7 @@ blackhole 198.51.100.0/24 proto 84])
 # * 192.0.2.3/32
 # * 192.0.2.10/32
 check ovn-nbctl --wait=hv set Logical_Router_Port internet-public \
-        options:dynamic-routing-redistribute="connected-as-host;static"
+    options:dynamic-routing-redistribute="connected-as-host,static"
 
 OVS_WAIT_UNTIL_EQUAL([ip route list vrf ovnvrf1337 | awk '{$1=$1};1'], [dnl
 blackhole 192.0.2.1 proto 84
--

Regards,
Dumitru

> v6->v7:
>   * addressed review comments
> v5->v6:
>   * addressed review comments
> v3->v4:
>   - addressed review comments.
>   - fix authorship
> v2->v3:
>  * Set monitor conditions on sb Advertised_Route table.
> 
>  controller/automake.mk           |   7 +-
>  controller/ovn-controller.c      |  49 +++-
>  controller/route-exchange-stub.c |  37 +++
>  controller/route-exchange.c      | 106 ++++++++
>  controller/route-exchange.h      |  34 +++
>  tests/ovs-macros.at              |  10 +
>  tests/system-common-macros.at    |  15 ++
>  tests/system-ovn.at              | 401 +++++++++++++++++++++++++++++++
>  8 files changed, 655 insertions(+), 4 deletions(-)
>  create mode 100644 controller/route-exchange-stub.c
>  create mode 100644 controller/route-exchange.c
>  create mode 100644 controller/route-exchange.h
> 
> diff --git a/controller/automake.mk b/controller/automake.mk
> index a8b8dde44..d7a087e7e 100644
> --- a/controller/automake.mk
> +++ b/controller/automake.mk
> @@ -56,13 +56,18 @@ controller_ovn_controller_SOURCES = \
>       controller/ovn-dns.h \
>       controller/ecmp-next-hop-monitor.h \
>       controller/ecmp-next-hop-monitor.c \
> +     controller/route-exchange.h \
>       controller/route.h \
>       controller/route.c
>  
>  if HAVE_NETLINK
>  controller_ovn_controller_SOURCES += \
>       controller/route-exchange-netlink.h \
> -     controller/route-exchange-netlink.c
> +     controller/route-exchange-netlink.c \
> +     controller/route-exchange.c
> +else
> +controller_ovn_controller_SOURCES += \
> +     controller/route-exchange-stub.c
>  endif
>  
>  controller_ovn_controller_LDADD = lib/libovn.la 
> $(OVS_LIBDIR)/libopenvswitch.la
> diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c
> index 4f5da8b65..93433a14b 100644
> --- a/controller/ovn-controller.c
> +++ b/controller/ovn-controller.c
> @@ -90,6 +90,7 @@
>  #include "ovn-dns.h"
>  #include "acl-ids.h"
>  #include "route.h"
> +#include "route-exchange.h"
>  
>  VLOG_DEFINE_THIS_MODULE(main);
>  
> @@ -4923,6 +4924,14 @@ controller_output_acl_id_handler(struct engine_node 
> *node,
>      return true;
>  }
>  
> +static bool
> +controller_output_route_exchange_handler(struct engine_node *node,
> +                                         void *data OVS_UNUSED)
> +{
> +    engine_set_node_state(node, EN_UPDATED);
> +    return true;
> +}
> +
>  /* Handles sbrec_chassis changes.
>   * If a new chassis is added or removed return false, so that
>   * flows are recomputed.  For any updates, there is no need for
> @@ -5113,6 +5122,34 @@ route_sb_advertised_route_data_handler(struct 
> engine_node *node, void *data)
>      return true;
>  }
>  
> +static void
> +en_route_exchange_run(struct engine_node *node, void *data OVS_UNUSED)
> +{
> +    struct ed_type_route *route_data =
> +        engine_get_input_data("route", node);
> +
> +    struct route_exchange_ctx_in r_ctx_in = {
> +        .announce_routes = &route_data->announce_routes,
> +    };
> +    struct route_exchange_ctx_out r_ctx_out = {
> +    };
> +
> +    route_exchange_run(&r_ctx_in, &r_ctx_out);
> +    engine_set_node_state(node, EN_UPDATED);
> +}
> +
> +
> +static void *
> +en_route_exchange_init(struct engine_node *node OVS_UNUSED,
> +                       struct engine_arg *arg OVS_UNUSED)
> +{
> +    return NULL;
> +}
> +
> +static void
> +en_route_exchange_cleanup(void *data OVS_UNUSED)
> +{}
> +
>  /* Returns false if the northd internal version stored in SB_Global
>   * and ovn-controller internal version don't match.
>   */
> @@ -5351,6 +5388,8 @@ main(int argc, char *argv[])
>      ovsdb_idl_omit(ovnsb_idl_loop.idl, &sbrec_ha_chassis_col_external_ids);
>      ovsdb_idl_omit(ovnsb_idl_loop.idl,
>                     &sbrec_ha_chassis_group_col_external_ids);
> +    ovsdb_idl_omit(ovnsb_idl_loop.idl,
> +                   &sbrec_advertised_route_col_external_ids);
>  
>      /* We don't want to monitor Connection table at all. So omit all the
>       * columns. */
> @@ -5413,6 +5452,7 @@ main(int argc, char *argv[])
>      ENGINE_NODE(acl_id, "acl_id");
>      en_acl_id.is_valid = en_acl_id_is_valid;
>      ENGINE_NODE(route, "route");
> +    ENGINE_NODE(route_exchange, "route_exchange");
>  
>  #define SB_NODE(NAME, NAME_STR) ENGINE_NODE_SB(NAME, NAME_STR);
>      SB_NODES
> @@ -5444,6 +5484,8 @@ main(int argc, char *argv[])
>      engine_add_input(&en_route, &en_sb_advertised_route,
>                       route_sb_advertised_route_data_handler);
>  
> +    engine_add_input(&en_route_exchange, &en_route, NULL);
> +
>      engine_add_input(&en_addr_sets, &en_sb_address_set,
>                       addr_sets_sb_address_set_handler);
>      engine_add_input(&en_port_groups, &en_sb_port_group,
> @@ -5629,9 +5671,8 @@ main(int argc, char *argv[])
>                       controller_output_mac_cache_handler);
>      engine_add_input(&en_controller_output, &en_bfd_chassis,
>                       controller_output_bfd_chassis_handler);
> -    /* This is just temporary until the route output is actually used. */
> -    engine_add_input(&en_controller_output, &en_route,
> -                     controller_output_bfd_chassis_handler);
> +    engine_add_input(&en_controller_output, &en_route_exchange,
> +                     controller_output_route_exchange_handler);
>  
>      engine_add_input(&en_acl_id, &en_sb_acl_id, NULL);
>      engine_add_input(&en_controller_output, &en_acl_id,
> @@ -6374,6 +6415,7 @@ loop_done:
>  
>              poll_block();
>          }
> +        route_exchange_cleanup_vrfs();
>      }
>  
>      free(ovn_version);
> @@ -6403,6 +6445,7 @@ loop_done:
>      service_stop();
>      ovsrcu_exit();
>      dns_resolve_destroy();
> +    route_exchange_destroy();
>  
>      exit(retval);
>  }
> diff --git a/controller/route-exchange-stub.c 
> b/controller/route-exchange-stub.c
> new file mode 100644
> index 000000000..3a7709d7f
> --- /dev/null
> +++ b/controller/route-exchange-stub.c
> @@ -0,0 +1,37 @@
> +/*
> + * Copyright (c) 2025 Canonical, Ltd.
> + * Copyright (c) 2025, STACKIT GmbH & Co. KG
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at:
> + *
> + *     http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +#include <config.h>
> +
> +#include "openvswitch/compiler.h"
> +#include "route-exchange.h"
> +
> +void
> +route_exchange_run(struct route_exchange_ctx_in *r_ctx_in OVS_UNUSED,
> +                   struct route_exchange_ctx_out *r_ctx_out OVS_UNUSED)
> +{
> +}
> +
> +void
> +route_exchange_cleanup_vrfs(void)
> +{
> +}
> +
> +void
> +route_exchange_destroy(void)
> +{
> +}
> diff --git a/controller/route-exchange.c b/controller/route-exchange.c
> new file mode 100644
> index 000000000..bba2836ab
> --- /dev/null
> +++ b/controller/route-exchange.c
> @@ -0,0 +1,106 @@
> +/*
> + * Copyright (c) 2025 Canonical, Ltd.
> + * Copyright (c) 2025, STACKIT GmbH & Co. KG
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at:
> + *
> + *     http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +#include <config.h>
> +
> +#include <errno.h>
> +#include <net/if.h>
> +
> +#include "openvswitch/vlog.h"
> +
> +#include "lib/ovn-sb-idl.h"
> +
> +#include "binding.h"
> +#include "ha-chassis.h"
> +#include "local_data.h"
> +#include "route.h"
> +#include "route-exchange.h"
> +#include "route-exchange-netlink.h"
> +
> +VLOG_DEFINE_THIS_MODULE(route_exchange);
> +static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
> +
> +static struct sset _maintained_vrfs = SSET_INITIALIZER(&_maintained_vrfs);
> +
> +void
> +route_exchange_run(struct route_exchange_ctx_in *r_ctx_in,
> +                   struct route_exchange_ctx_out *r_ctx_out OVS_UNUSED)
> +{
> +    struct sset old_maintained_vrfs = SSET_INITIALIZER(&old_maintained_vrfs);
> +    sset_swap(&_maintained_vrfs, &old_maintained_vrfs);
> +
> +    const struct advertise_datapath_entry *ad;
> +    HMAP_FOR_EACH (ad, node, r_ctx_in->announce_routes) {
> +        struct hmap received_routes
> +                = HMAP_INITIALIZER(&received_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 (error && error != EEXIST) {
> +                    VLOG_WARN_RL(&rl,
> +                                 "Unable to create VRF %s for datapath "
> +                                 "%"PRIi32": %s.",
> +                                 vrf_name, table_id,
> +                                 ovs_strerror(error));
> +                    continue;
> +                }
> +            }
> +            sset_add(&_maintained_vrfs, 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);
> +        }
> +
> +        re_nl_sync_routes(ad->db->tunnel_key, &ad->routes);
> +    }
> +
> +    /* Remove VRFs previously maintained by us not found in the above loop. 
> */
> +    const char *vrf_name;
> +    SSET_FOR_EACH_SAFE (vrf_name, &old_maintained_vrfs) {
> +        if (!sset_contains(&_maintained_vrfs, vrf_name)) {
> +            re_nl_delete_vrf(vrf_name);
> +        }
> +        sset_delete(&old_maintained_vrfs, SSET_NODE_FROM_NAME(vrf_name));
> +    }
> +    sset_destroy(&old_maintained_vrfs);
> +}
> +
> +void
> +route_exchange_cleanup_vrfs(void)
> +{
> +    const char *vrf_name;
> +    SSET_FOR_EACH (vrf_name, &_maintained_vrfs) {
> +        re_nl_delete_vrf(vrf_name);
> +    }
> +}
> +
> +void
> +route_exchange_destroy(void)
> +{
> +    const char *vrf_name;
> +    SSET_FOR_EACH_SAFE (vrf_name, &_maintained_vrfs) {
> +        sset_delete(&_maintained_vrfs, SSET_NODE_FROM_NAME(vrf_name));
> +    }
> +
> +    sset_destroy(&_maintained_vrfs);
> +}
> diff --git a/controller/route-exchange.h b/controller/route-exchange.h
> new file mode 100644
> index 000000000..7d4ad38c4
> --- /dev/null
> +++ b/controller/route-exchange.h
> @@ -0,0 +1,34 @@
> +/*
> + * Copyright (c) 2025 Canonical, Ltd.
> + * Copyright (c) 2025, STACKIT GmbH & Co. KG
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at:
> + *
> + *     http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +#ifndef ROUTE_EXCHANGE_H
> +#define ROUTE_EXCHANGE_H 1
> +
> +struct route_exchange_ctx_in {
> +    /* Contains struct advertise_datapath_entry */
> +    const struct hmap *announce_routes;
> +};
> +
> +struct route_exchange_ctx_out {
> +};
> +
> +void route_exchange_run(struct route_exchange_ctx_in *,
> +                        struct route_exchange_ctx_out *);
> +void route_exchange_cleanup_vrfs(void);
> +void route_exchange_destroy(void);
> +
> +#endif /* ROUTE_EXCHANGE_H */
> diff --git a/tests/ovs-macros.at b/tests/ovs-macros.at
> index 0e3b1bcd6..25b34791a 100644
> --- a/tests/ovs-macros.at
> +++ b/tests/ovs-macros.at
> @@ -285,6 +285,16 @@ m4_define([OVS_WAIT_UNTIL],
>    [check_ovs_wait_until_args "$#" "$2"
>     OVS_WAIT([$1], [$2], [AT_LINE], [until $1])])
>  
> +dnl OVS_WAIT_UNTIL_EQUAL(COMMAND, OUTPUT)
> +dnl
> +dnl Executes shell COMMAND in a loop until it returns zero and the output
> +dnl equals OUTPUT.  If COMMAND does not return zero or a desired output 
> within
> +dnl a reasonable time limit, fails the test.
> +m4_define([OVS_WAIT_UNTIL_EQUAL],
> +  [AT_FAIL_IF([test "$#" -ge 3])
> +   echo "$2" > wait_until_expected
> +   OVS_WAIT_UNTIL([$1 | diff -u wait_until_expected - ])])
> +
>  dnl OVS_WAIT_FOR_OUTPUT(COMMAND, EXIT-STATUS, STDOUT, STDERR)
>  dnl OVS_WAIT_FOR_OUTPUT_UNQUOTED(COMMAND, EXIT-STATUS, STDOUT, STDERR)
>  dnl
> diff --git a/tests/system-common-macros.at b/tests/system-common-macros.at
> index bba2597cf..72ff6bdfc 100644
> --- a/tests/system-common-macros.at
> +++ b/tests/system-common-macros.at
> @@ -542,3 +542,18 @@ m4_define([CHECK_VRF],
>      AT_SKIP_IF([test $rc -ne 0])
>      on_exit 'modprobe -r vrf'
>  ])
> +
> +# VRF_RESERVE([id])
> +#
> +# Helper to ensure we actually support vrfs and the vrf in question has no
> +# route entries in it and is not existing.
> +# We need to add it before deleting as routes can actually survive in a
> +# deleted vrf.
> +m4_define([VRF_RESERVE],
> +    [
> +     CHECK_VRF()
> +     ip link add "ovnvrf$1" type vrf table "$1"
> +     ip route flush vrf "ovnvrf$1"
> +     ip link del "ovnvrf$1"
> +    ]
> +)
> diff --git a/tests/system-ovn.at b/tests/system-ovn.at
> index 781d8da84..d8394b27d 100644
> --- a/tests/system-ovn.at
> +++ b/tests/system-ovn.at
> @@ -15916,3 +15916,404 @@ OVS_TRAFFIC_VSWITCHD_STOP(["/.*error receiving.*/d
>  /.*terminating with signal 15.*/d"])
>  AT_CLEANUP
>  ])
> +
> +OVN_FOR_EACH_NORTHD([
> +AT_SETUP([dynamic-routing - DGP])
> +
> +VRF_RESERVE([1337])
> +
> +# This test uses dynamic routing on a simulated multi-tenant internet
> +# connection.
> +# Tenant 1 (pr1, p1, vif1) is connected to the internet via NAT on pr1.
> +# Tenant 2 (pr2, p2, vif2) is connected to the internet via routing.
> +# The connections of pr1 and pr2 to public are using DGPs.
> +# The connection from internet to phys is also using a DGP.
> +# The LR internet is running dynamic-routing.
> +# The LS phys is assumed to be used for peering with a router outside OVN
> +#
> +#
> +# +----+       +----+
> +# |vif1|       |vif2|
> +# +--+-+       +--+-+
> +#    |            |
> +# +--+--+      +--+--+
> +# |LS p1|      |LS p2|
> +# +--+--+      +--+--+
> +#    |            |
> +# +--+---+     +--+---+
> +# |LR pr1|     |LR pr2|
> +# +-----++     ++-----+
> +#       |       |
> +#      ++-------++
> +#      |LS public|
> +#      +-----+---+
> +#            |
> +#      +-----+-----+
> +#      |LR internet|
> +#      +-----+-----+
> +#            |
> +#        +---+---+
> +#        |LS phys|
> +#        +-------+
> +
> +ovn_start
> +OVS_TRAFFIC_VSWITCHD_START()
> +
> +ADD_BR([br-int])
> +ADD_BR([br-ext])
> +
> +check ovs-ofctl add-flow br-ext action=normal
> +# Set external-ids in br-int needed for ovn-controller.
> +check ovs-vsctl \
> +        -- set Open_vSwitch . external-ids:system-id=hv1 \
> +        -- set Open_vSwitch . 
> external-ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb.sock \
> +        -- set Open_vSwitch . external-ids:ovn-encap-type=geneve \
> +        -- set Open_vSwitch . external-ids:ovn-encap-ip=169.0.0.1 \
> +        -- set bridge br-int fail-mode=secure 
> other-config:disable-in-band=true
> +
> +# Start ovn-controller.
> +start_daemon ovn-controller
> +
> +# LS setup.
> +
> +check ovn-nbctl ls-add public
> +check ovn-nbctl ls-add phys
> +check ovn-nbctl ls-add p1
> +check ovn-nbctl ls-add p2
> +
> +# LR internet setup.
> +
> +check ovn-nbctl lr-add internet \
> +    -- set Logical_Router internet options:dynamic-routing=true \
> +                                   options:requested-tnl-key=1337
> +
> +check ovn-nbctl lrp-add internet internet-public \
> +        00:00:02:01:02:03 192.0.2.1/24 \
> +    -- set Logical_Router_Port internet-public \
> +            options:dynamic-routing-redistribute="connected;static"
> +check ovn-nbctl lsp-add public public-internet \
> +    -- set Logical_Switch_Port public-internet type=router \
> +            options:router-port=internet-public \
> +    -- lsp-set-addresses public-internet router
> +
> +check ovn-nbctl lrp-add internet internet-phys \
> +        00:00:ff:00:00:01 192.168.10.1/24 \
> +    -- set Logical_Router_Port internet-phys \
> +            options:dynamic-routing-maintain-vrf=true
> +check ovn-nbctl lrp-set-gateway-chassis internet-phys hv1
> +check ovn-nbctl lsp-add phys phys-internet \
> +    -- set Logical_Switch_Port phys-internet type=router \
> +            options:router-port=internet-phys \
> +    -- lsp-set-addresses phys-internet router
> +
> +# LR pr1 setup.
> +
> +check ovn-nbctl lr-add pr1 \
> +    -- set Logical_Router pr1 options:requested-tnl-key=1338
> +
> +check ovn-nbctl lrp-add pr1 pr1-public \
> +        00:00:02:01:02:04 192.0.2.2/24
> +check ovn-nbctl lrp-set-gateway-chassis pr1-public hv1
> +check ovn-nbctl lsp-add public public-pr1 \
> +    -- set Logical_Switch_Port public-pr1 type=router \
> +            options:router-port=pr1-public \
> +    -- lsp-set-addresses public-pr1 router
> +
> +check ovn-nbctl lrp-add pr1 pr1-p1 \
> +        00:00:03:00:00:01 10.0.0.1/24
> +check ovn-nbctl lsp-add p1 p1-pr1 \
> +    -- set Logical_Switch_Port p1-pr1 type=router \
> +            options:router-port=pr1-p1 \
> +    -- lsp-set-addresses p1-pr1 router
> +
> +check ovn-nbctl lr-route-add pr1 0.0.0.0/0 192.0.2.1
> +
> +# LR pr2 setup.
> +
> +check ovn-nbctl lr-add pr2 \
> +    -- set Logical_Router pr2 options:requested-tnl-key=1339
> +
> +check ovn-nbctl lrp-add pr2 pr2-public \
> +        00:00:02:01:02:05 192.0.2.3/24
> +check ovn-nbctl lrp-set-gateway-chassis pr2-public hv1
> +check ovn-nbctl lsp-add public public-pr2 \
> +    -- set Logical_Switch_Port public-pr2 type=router \
> +            options:router-port=pr2-public \
> +    -- lsp-set-addresses public-pr2 router
> +
> +check ovn-nbctl lrp-add pr2 pr2-p2 \
> +        00:00:04:00:00:01 198.51.100.1/24
> +check ovn-nbctl lsp-add p2 p2-pr2 \
> +    -- set Logical_Switch_Port p2-pr2 type=router \
> +            options:router-port=pr2-p2 \
> +    -- lsp-set-addresses p2-pr2 router
> +
> +check ovn-nbctl lr-route-add pr2 0.0.0.0/0 192.0.2.1
> +
> +# Setup lsp "vif1" with NAT.
> +check ovn-nbctl lsp-add p1 vif1 \
> +    -- lsp-set-addresses vif1 "00:00:ff:ff:ff:01 10.0.0.2"
> +check ovn-nbctl lr-nat-add pr1 dnat_and_snat 192.0.2.10 10.0.0.2
> +
> +# Setup lsp "vif2" with a static route on LR internet.
> +check ovn-nbctl lsp-add p2 vif2 \
> +    -- lsp-set-addresses vif2 "00:00:ff:ff:ff:02 198.51.100.10"
> +check ovn-nbctl lr-route-add internet 198.51.100.0/24 192.0.2.3
> +
> +# Configure external connectivity.
> +check ovs-vsctl set Open_vSwitch . 
> external-ids:ovn-bridge-mappings=phynet:br-ext
> +check ovn-nbctl lsp-add phys phys1 \
> +        -- lsp-set-addresses phys1 unknown \
> +        -- lsp-set-type phys1 localnet \
> +        -- lsp-set-options phys1 network_name=phynet
> +
> +check ovn-nbctl --wait=hv sync
> +wait_for_ports_up public-internet phys-internet public-pr1 p1-pr1 public-pr2 
> p2-pr2
> +
> +# Now the ovn-controller should have setup a vrf named "ovnvrf1337".
> +# It should contain routes for:
> +# * 192.0.2.0/24
> +# * 198.51.100.0/24
> +
> +AT_CHECK([ip vrf show ovnvrf1337], [0], [dnl
> +ovnvrf1337 1337
> +])
> +
> +# "ip route list" output has a trailing space on each line.
> +# The awk magic removes all trailing spaces.
> +OVS_WAIT_UNTIL_EQUAL([ip route list vrf ovnvrf1337 | awk '{$1=$1};1'], [dnl
> +blackhole 192.0.2.0/24 proto 84
> +blackhole 198.51.100.0/24 proto 84])
> +
> +# We now switch to announcing host routes and expect 192.0.2.0/24 to be gone
> +# and the following to be added:
> +# * 192.0.2.1/32
> +# * 192.0.2.2/32
> +# * 192.0.2.3/32
> +# * 192.0.2.10/32
> +check ovn-nbctl --wait=hv set Logical_Router_Port internet-public \
> +        options:dynamic-routing-redistribute="connected-as-host;static"
> +
> +OVS_WAIT_UNTIL_EQUAL([ip route list vrf ovnvrf1337 | awk '{$1=$1};1'], [dnl
> +blackhole 192.0.2.1 proto 84
> +blackhole 192.0.2.2 proto 84
> +blackhole 192.0.2.3 proto 84
> +blackhole 192.0.2.10 proto 84
> +blackhole 198.51.100.0/24 proto 84])
> +
> +OVS_APP_EXIT_AND_WAIT([ovn-controller])
> +
> +as ovn-sb
> +OVS_APP_EXIT_AND_WAIT([ovsdb-server])
> +
> +as ovn-nb
> +OVS_APP_EXIT_AND_WAIT([ovsdb-server])
> +
> +as northd
> +OVS_APP_EXIT_AND_WAIT([ovn-northd])
> +
> +as
> +OVS_TRAFFIC_VSWITCHD_STOP(["/.*error receiving.*/d
> +/.*terminating with signal 15.*/d"])
> +AT_CLEANUP
> +])
> +
> +OVN_FOR_EACH_NORTHD([
> +AT_SETUP([dynamic-routing - Gateway Router])
> +
> +VRF_RESERVE([1337])
> +
> +# This test uses dynamic routing on a simulated multi-tenant internet
> +# connection.
> +# Tenant 1 (pr1, p1, vif1) is connected to the internet via NAT on pr1.
> +# Tenant 2 (pr2, p2, vif2) is connected to the internet via routing.
> +# The connections of pr1 and pr2 to public are using DGPs.
> +# The LR internet is a gateway router.
> +# The LR internet is running dynamic-routing.
> +# The LS phys is assumed to be used for peering with a router outside OVN
> +#
> +#
> +# +----+       +----+
> +# |vif1|       |vif2|
> +# +--+-+       +--+-+
> +#    |            |
> +# +--+--+      +--+--+
> +# |LS p1|      |LS p2|
> +# +--+--+      +--+--+
> +#    |            |
> +# +--+---+     +--+---+
> +# |LR pr1|     |LR pr2|
> +# +-----++     ++-----+
> +#       |       |
> +#      ++-------++
> +#      |LS public|
> +#      +-----+---+
> +#            |
> +#      +-----+-----+
> +#      |LR internet|
> +#      +-----+-----+
> +#            |
> +#        +---+---+
> +#        |LS phys|
> +#        +-------+
> +
> +ovn_start
> +OVS_TRAFFIC_VSWITCHD_START()
> +
> +ADD_BR([br-int])
> +ADD_BR([br-ext])
> +
> +check ovs-ofctl add-flow br-ext action=normal
> +# Set external-ids in br-int needed for ovn-controller.
> +check ovs-vsctl \
> +        -- set Open_vSwitch . external-ids:system-id=hv1 \
> +        -- set Open_vSwitch . 
> external-ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb.sock \
> +        -- set Open_vSwitch . external-ids:ovn-encap-type=geneve \
> +        -- set Open_vSwitch . external-ids:ovn-encap-ip=169.0.0.1 \
> +        -- set bridge br-int fail-mode=secure 
> other-config:disable-in-band=true
> +
> +# Start ovn-controller.
> +start_daemon ovn-controller
> +
> +# LS setup.
> +
> +check ovn-nbctl ls-add public
> +check ovn-nbctl ls-add phys
> +check ovn-nbctl ls-add p1
> +check ovn-nbctl ls-add p2
> +
> +# LR internet setup.
> +
> +check ovn-nbctl lr-add internet \
> +    -- set Logical_Router internet options:dynamic-routing=true \
> +                                   options:requested-tnl-key=1337 \
> +                                   options:chassis=hv1
> +
> +check ovn-nbctl lrp-add internet internet-public \
> +        00:00:02:01:02:03 192.0.2.1/24 \
> +    -- set Logical_Router_Port internet-public \
> +            options:dynamic-routing-redistribute="connected;static" \
> +            options:dynamic-routing-port-name=wedontlearnstuffhere
> +check ovn-nbctl lsp-add public public-internet \
> +    -- set Logical_Switch_Port public-internet type=router \
> +            options:router-port=internet-public \
> +    -- lsp-set-addresses public-internet router
> +
> +check ovn-nbctl lrp-add internet internet-phys \
> +        00:00:ff:00:00:01 192.168.10.1/24 \
> +    -- set Logical_Router_Port internet-phys \
> +            options:dynamic-routing-maintain-vrf=true
> +check ovn-nbctl lsp-add phys phys-internet \
> +    -- set Logical_Switch_Port phys-internet type=router \
> +            options:router-port=internet-phys \
> +    -- lsp-set-addresses phys-internet router
> +
> +# LR pr1 setup.
> +
> +check ovn-nbctl lr-add pr1 \
> +    -- set Logical_Router pr1 options:requested-tnl-key=1338
> +
> +check ovn-nbctl lrp-add pr1 pr1-public \
> +        00:00:02:01:02:04 192.0.2.2/24
> +check ovn-nbctl lrp-set-gateway-chassis pr1-public hv1
> +check ovn-nbctl lsp-add public public-pr1 \
> +    -- set Logical_Switch_Port public-pr1 type=router \
> +            options:router-port=pr1-public \
> +    -- lsp-set-addresses public-pr1 router
> +
> +check ovn-nbctl lrp-add pr1 pr1-p1 \
> +        00:00:03:00:00:01 10.0.0.1/24
> +check ovn-nbctl lsp-add p1 p1-pr1 \
> +    -- set Logical_Switch_Port p1-pr1 type=router \
> +            options:router-port=pr1-p1 \
> +    -- lsp-set-addresses p1-pr1 router
> +
> +check ovn-nbctl lr-route-add pr1 0.0.0.0/0 192.0.2.1
> +
> +# LR pr2 setup.
> +
> +check ovn-nbctl lr-add pr2 \
> +    -- set Logical_Router pr2 options:requested-tnl-key=1339
> +
> +check ovn-nbctl lrp-add pr2 pr2-public \
> +        00:00:02:01:02:05 192.0.2.3/24
> +check ovn-nbctl lrp-set-gateway-chassis pr2-public hv1
> +check ovn-nbctl lsp-add public public-pr2 \
> +    -- set Logical_Switch_Port public-pr2 type=router \
> +            options:router-port=pr2-public \
> +    -- lsp-set-addresses public-pr2 router
> +
> +check ovn-nbctl lrp-add pr2 pr2-p2 \
> +        00:00:04:00:00:01 198.51.100.1/24
> +check ovn-nbctl lsp-add p2 p2-pr2 \
> +    -- set Logical_Switch_Port p2-pr2 type=router \
> +            options:router-port=pr2-p2 \
> +    -- lsp-set-addresses p2-pr2 router
> +
> +check ovn-nbctl lr-route-add pr2 0.0.0.0/0 192.0.2.1
> +
> +# Setup lsp "vif1" with NAT.
> +check ovn-nbctl lsp-add p1 vif1 \
> +    -- lsp-set-addresses vif1 "00:00:ff:ff:ff:01 10.0.0.2"
> +check ovn-nbctl lr-nat-add pr1 dnat_and_snat 192.0.2.10 10.0.0.2
> +
> +# Setup lsp "vif2" with a static route on LR internet.
> +check ovn-nbctl lsp-add p2 vif2 \
> +    -- lsp-set-addresses vif2 "00:00:ff:ff:ff:02 198.51.100.10"
> +check ovn-nbctl lr-route-add internet 198.51.100.0/24 192.0.2.3
> +
> +# Configure external connectivity.
> +check ovs-vsctl set Open_vSwitch . 
> external-ids:ovn-bridge-mappings=phynet:br-ext
> +check ovn-nbctl lsp-add phys phys1 \
> +        -- lsp-set-addresses phys1 unknown \
> +        -- lsp-set-type phys1 localnet \
> +        -- lsp-set-options phys1 network_name=phynet
> +
> +check ovn-nbctl --wait=hv sync
> +wait_for_ports_up public-internet phys-internet public-pr1 p1-pr1 public-pr2 
> p2-pr2
> +
> +# Now the ovn-controller should have setup a vrf named "ovnvrf1337".
> +# It should contain routes for:
> +# * 192.0.2.0/24
> +# * 198.51.100.0/24
> +
> +AT_CHECK([ip vrf show ovnvrf1337], [0], [dnl
> +ovnvrf1337 1337
> +])
> +
> +# "ip route list" output has a trailing space on each line.
> +# The awk magic removes all trailing spaces.
> +OVS_WAIT_UNTIL_EQUAL([ip route list vrf ovnvrf1337 | awk '{$1=$1};1'], [dnl
> +blackhole 192.0.2.0/24 proto 84
> +blackhole 198.51.100.0/24 proto 84])
> +
> +# We now switch to announcing host routes and expect 192.0.2.0/24 to be gone
> +# and the following to be added:
> +# * 192.0.2.1/32
> +# * 192.0.2.2/32
> +# * 192.0.2.3/32
> +# * 192.0.2.10/32
> +check ovn-nbctl --wait=hv set Logical_Router_Port internet-public \
> +        options:dynamic-routing-redistribute="connected-as-host;static"
> +
> +OVS_WAIT_UNTIL_EQUAL([ip route list vrf ovnvrf1337 | awk '{$1=$1};1'], [dnl
> +blackhole 192.0.2.1 proto 84
> +blackhole 192.0.2.2 proto 84
> +blackhole 192.0.2.3 proto 84
> +blackhole 192.0.2.10 proto 84
> +blackhole 198.51.100.0/24 proto 84])
> +
> +as ovn-sb
> +OVS_APP_EXIT_AND_WAIT([ovsdb-server])
> +
> +as ovn-nb
> +OVS_APP_EXIT_AND_WAIT([ovsdb-server])
> +
> +as northd
> +OVS_APP_EXIT_AND_WAIT([ovn-northd])
> +
> +as
> +OVS_TRAFFIC_VSWITCHD_STOP(["/.*error receiving.*/d
> +/.*terminating with signal 15.*/d"])
> +AT_CLEANUP
> +])

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to