A CMS exposes an overlay load balancer VIP on a provider network by
adding a dnat_and_snat entry whose external IP is also configured as a
VIP of the same, distributed, load balancer. With "lb" and "nat"
redistribution, northd then emits two kinds of Advertised_Route for that
address: one per backend port for the load balancer, carrying the health
selectors, and one for the NAT entry, tracked by the distributed gateway
port and without any health information.

The NAT route keeps the gateway chassis advertised after the load
balancer routes were withdrawn there. The fabric keeps steering flows to
that chassis, where the load balancer no longer has a local backend, and
the traffic is dropped.

Build the load balancer routes first and record the advertising port,
owning router and prefix of every distributed load balancer VIP. Skip a
NAT entry that is not distributed when its own router has such a route
for its external IP through the same port. The load balancer routes
carry the locality and health of the address, and the forwarding route
for the VIP is still installed on the advertising router. A NAT entry
keeps its route as before when:

- the port redistributes "nat" alone, or the load balancer does not
  advertise the VIP, so no load balancer route exists,
- the NAT entry belongs to another router, which keeps the existing
  overlap behaviour between routers,
- the NAT entry is distributed and tracked by its own logical port,
- the load balancer is centralized and shares the gateway port with the
  NAT entry, so its route stays unconditional.

The external IP is compared in its canonical form, so an IPv6 address
spelled differently in the two records still matches.

Fixes: 3c488ba9a2f4 ("northd: Emit per-backend Advertised_Route for LB 
redistribution.")
Signed-off-by: Dmitrii Shcherbakov <[email protected]>
---
 NEWS                              |   4 +
 northd/en-advertised-route-sync.c | 129 ++++++++++++---
 northd/en-advertised-route-sync.h |   6 +
 ovn-nb.xml                        |   7 +-
 tests/ovn-northd.at               | 265 ++++++++++++++++++++++++++++++
 5 files changed, 388 insertions(+), 23 deletions(-)

diff --git a/NEWS b/NEWS
index 45f44c7eb..5eedc627b 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,10 @@ Post v26.09.0
      only skipped if their action is "reroute". Router policies of type
      "allow", "drop", and "jump" will still be accepted, even if the
      "nexthop" column is set on those policies.
+   - A NAT entry whose external IP is also a VIP of a distributed load
+     balancer of the same router is no longer advertised as a NAT route.
+     The load balancer routes carry the locality and health of the
+     address.
    - Learn ARP sender hardware address (arp.sha) and IPv6 Neighbor
      Discovery link-layer addresses (nd.tll, nd.sll) into the FDB
      table in addition to eth.src.  This allows VRRP virtual MACs to
diff --git a/northd/en-advertised-route-sync.c 
b/northd/en-advertised-route-sync.c
index eb8a24a39..c43e73228 100644
--- a/northd/en-advertised-route-sync.c
+++ b/northd/en-advertised-route-sync.c
@@ -359,12 +359,56 @@ add_redistribute_parsed_route(struct hmap 
*parsed_routes_out,
     parsed_route_free(new_pr);
 }
 
+static char *
+distributed_lb_route_key(const struct ovn_port *advertising_op,
+                         const struct uuid *owner_lr,
+                         const char *ip_prefix)
+{
+    return xasprintf("%s "UUID_FMT" %s", advertising_op->key,
+                     UUID_ARGS(owner_lr), ip_prefix);
+}
+
+/* Records that a distributed load balancer owned by the logical router
+ * owner_lr advertises a route for ip_prefix through advertising_op. */
+static void
+distributed_lb_route_add(struct sset *distributed_lb_routes,
+                         const struct ovn_port *advertising_op,
+                         const struct uuid *owner_lr,
+                         const char *ip_prefix)
+{
+    sset_add_and_free(distributed_lb_routes,
+                      distributed_lb_route_key(advertising_op, owner_lr,
+                                               ip_prefix));
+}
+
+static bool
+distributed_lb_route_exists(const struct sset *distributed_lb_routes,
+                            const struct ovn_port *advertising_op,
+                            const struct uuid *owner_lr,
+                            const char *ip_prefix)
+{
+    char *key = distributed_lb_route_key(advertising_op, owner_lr,
+                                         ip_prefix);
+    bool exists = sset_contains(distributed_lb_routes, key);
+    free(key);
+    return exists;
+}
+
 /* This function adds a new route for each entry in lr_nat record
  * to "routes". Logical port of the route is set to "advertising_op" and
  * tracked port is set to NAT's distributed gw port. If NAT doesn't have
  * DGP (for example if it's set on gateway router), no tracked port will
  * be set.
  *
+ * A NAT entry that is not distributed is skipped when a distributed load
+ * balancer of the same router already advertises a route for its external
+ * IP through advertising_op, see distributed_lb_routes.  The per-backend
+ * load balancer routes carry the locality and health of that address, and a
+ * route tracked by the gateway port would keep that chassis advertised
+ * after the load balancer routes were withdrawn there.  A distributed NAT
+ * entry is tracked by its own logical port and stays advertised, and so
+ * does a NAT entry of another router that uses the same address.
+ *
  * If forwarding_port and parsed_routes_out are non-NULL, also installs a
  * local forwarding parsed_route on advertising_op->od.  forwarding_port is
  * the peer LRP on the shared network.  tracked_port can be a distributed
@@ -373,6 +417,7 @@ static void
 build_nat_route_for_port(const struct ovn_port *advertising_op,
                          const struct lr_nat_record *lr_nat,
                          const struct hmap *ls_ports,
+                         const struct sset *distributed_lb_routes,
                          struct hmap *routes,
                          const struct ovn_port *forwarding_port,
                          struct hmap *parsed_routes_out)
@@ -390,6 +435,19 @@ build_nat_route_for_port(const struct ovn_port 
*advertising_op,
             continue;
         }
 
+        /* Compare the canonical form of the external IP, the load balancer
+         * VIP it may match was parsed and formatted the same way. */
+        const char *external_ip =
+            nat_entry_is_v6(nat)
+            ? nat->ext_addrs.ipv6_addrs[0].addr_s
+            : nat->ext_addrs.ipv4_addrs[0].addr_s;
+        if (!nat->is_distributed
+            && distributed_lb_route_exists(distributed_lb_routes,
+                                           advertising_op, &lr_nat->nbr_uuid,
+                                           external_ip)) {
+            continue;
+        }
+
         const struct ovn_port *tracked_port =
             nat->is_distributed
             ? ovn_port_find(ls_ports, nat->nb->logical_port)
@@ -426,7 +484,7 @@ static void
 build_nat_routes(const struct ovn_datapath *od,
                  const struct lr_nat_record *lr_nat,
                  const struct hmap *ls_ports,
-                 struct hmap *routes)
+                 struct dynamic_routes_data *data)
 {
     const struct ovn_port *op;
     HMAP_FOR_EACH (op, dp_node, &od->ports) {
@@ -434,7 +492,9 @@ build_nat_routes(const struct ovn_datapath *od,
             continue;
         }
 
-        build_nat_route_for_port(op, lr_nat, ls_ports, routes, NULL, NULL);
+        build_nat_route_for_port(op, lr_nat, ls_ports,
+                                 &data->distributed_lb_routes,
+                                 &data->routes, NULL, NULL);
     }
 }
 
@@ -478,8 +538,8 @@ build_nat_connected_routes(
              * install forwarding routes so we can reach the
              * peer's external IPs. */
             build_nat_route_for_port(op, peer_lr_stateful->lrnat_rec,
-                                     ls_ports, &data->routes,
-                                     op->peer,
+                                     ls_ports, &data->distributed_lb_routes,
+                                     &data->routes, op->peer,
                                      &data->parsed_routes);
             continue;
         }
@@ -504,8 +564,8 @@ build_nat_connected_routes(
              * install forwarding routes so we can reach the
              * peer's external IPs. */
             build_nat_route_for_port(op, peer_lr_stateful->lrnat_rec,
-                                     ls_ports, &data->routes,
-                                     rp->peer,
+                                     ls_ports, &data->distributed_lb_routes,
+                                     &data->routes, rp->peer,
                                      &data->parsed_routes);
             /* Track the LR datapath on the other side of LS
              * for any changes. */
@@ -523,13 +583,18 @@ build_nat_connected_routes(
  * entry, one Advertised_Route covers the VIP with fallback_tracked_port
  * in place of a per-backend LSP. The forwarding route is emitted once
  * per VIP regardless of backend count: the data-plane forwarding
- * decision is independent of which backend ends up serving the flow. */
+ * decision is independent of which backend ends up serving the flow.
+ * Every VIP of a distributed LB is recorded in distributed_lb_routes with
+ * owner_lr, the logical router the LB is attached to, so that
+ * build_nat_route_for_port() can skip the NAT route for it. */
 static void
 build_lb_routes_for_lb(const struct ovn_port *advertising_op,
                        const struct ovn_port *fallback_tracked_port,
+                       const struct nbrec_logical_router *owner_lr,
                        const struct nbrec_load_balancer *nbrec_lb,
                        const struct hmap *lb_datapaths_map,
                        const struct hmap *ls_ports,
+                       struct sset *distributed_lb_routes,
                        struct hmap *routes,
                        struct hmap *parsed_routes_out)
 {
@@ -573,6 +638,9 @@ build_lb_routes_for_lb(const struct ovn_port 
*advertising_op,
             continue;
         }
 
+        distributed_lb_route_add(distributed_lb_routes, advertising_op,
+                                 &owner_lr->header_.uuid, vip->vip_str);
+
         bool emitted_any = false;
         for (size_t b = 0; b < vip_nb->n_backends; b++) {
             const struct ovn_northd_lb_backend *backend_nb =
@@ -632,6 +700,7 @@ build_lb_lr_routes(const struct ovn_port *advertising_op,
                    const struct nbrec_logical_router *peer_lr_nbr,
                    const struct hmap *lb_datapaths_map,
                    const struct hmap *ls_ports,
+                   struct sset *distributed_lb_routes,
                    struct hmap *routes,
                    struct hmap *parsed_routes_out)
 {
@@ -643,8 +712,9 @@ build_lb_lr_routes(const struct ovn_port *advertising_op,
     for (size_t i = 0; i < peer_lr_nbr->n_load_balancer; i++) {
         const struct nbrec_load_balancer *lb = peer_lr_nbr->load_balancer[i];
         uuidset_insert(&visited, &lb->header_.uuid);
-        build_lb_routes_for_lb(advertising_op, fallback_tracked_port, lb,
-                               lb_datapaths_map, ls_ports, routes,
+        build_lb_routes_for_lb(advertising_op, fallback_tracked_port,
+                               peer_lr_nbr, lb, lb_datapaths_map, ls_ports,
+                               distributed_lb_routes, routes,
                                parsed_routes_out);
     }
 
@@ -657,8 +727,9 @@ build_lb_lr_routes(const struct ovn_port *advertising_op,
                 continue;
             }
             uuidset_insert(&visited, &lb->header_.uuid);
-            build_lb_routes_for_lb(advertising_op, fallback_tracked_port, lb,
-                                   lb_datapaths_map, ls_ports, routes,
+            build_lb_routes_for_lb(advertising_op, fallback_tracked_port,
+                                   peer_lr_nbr, lb, lb_datapaths_map,
+                                   ls_ports, distributed_lb_routes, routes,
                                    parsed_routes_out);
         }
     }
@@ -695,6 +766,7 @@ build_lb_connected_routes(const struct ovn_datapath *od,
         if (peer_od->nbr) {
             build_lb_lr_routes(op, op->peer, peer_od->nbr,
                                lb_datapaths_map, ls_ports,
+                               &data->distributed_lb_routes,
                                &data->routes, &data->parsed_routes);
             continue;
         }
@@ -710,6 +782,7 @@ build_lb_connected_routes(const struct ovn_datapath *od,
             }
             build_lb_lr_routes(op, rp->peer, rp->peer->od->nbr,
                                lb_datapaths_map, ls_ports,
+                               &data->distributed_lb_routes,
                                &data->routes, &data->parsed_routes);
             /* Track the LR datapath on the other side of LS
              * for any changes. */
@@ -727,7 +800,7 @@ static void
 build_lb_routes(const struct ovn_datapath *od,
                 const struct hmap *lb_datapaths_map,
                 const struct hmap *ls_ports,
-                struct hmap *routes)
+                struct dynamic_routes_data *data)
 {
     const struct ovn_port *op;
     HMAP_FOR_EACH (op, dp_node, &od->ports) {
@@ -737,12 +810,16 @@ build_lb_routes(const struct ovn_datapath *od,
 
         if (od->is_gw_router) {
             build_lb_lr_routes(op, NULL, od->nbr,
-                               lb_datapaths_map, ls_ports, routes, NULL);
+                               lb_datapaths_map, ls_ports,
+                               &data->distributed_lb_routes,
+                               &data->routes, NULL);
         } else {
             struct ovn_port *dgp;
             VECTOR_FOR_EACH (&od->l3dgw_ports, dgp) {
                 build_lb_lr_routes(op, dgp, od->nbr,
-                                   lb_datapaths_map, ls_ports, routes, NULL);
+                                   lb_datapaths_map, ls_ports,
+                                   &data->distributed_lb_routes,
+                                   &data->routes, NULL);
             }
         }
     }
@@ -882,6 +959,8 @@ en_dynamic_routes_init(struct engine_node *node OVS_UNUSED,
         .old_parsed_routes = HMAP_INITIALIZER(&data->old_parsed_routes),
         .nb_lr = UUIDSET_INITIALIZER(&data->nb_lr),
         .nb_ls = UUIDSET_INITIALIZER(&data->nb_ls),
+        .distributed_lb_routes =
+            SSET_INITIALIZER(&data->distributed_lb_routes),
         .tracked = false,
         .trk_data.trk_created_parsed_routes =
             HMAPX_INITIALIZER(&data->trk_data.trk_created_parsed_routes),
@@ -924,6 +1003,7 @@ en_dynamic_routes_clear(struct dynamic_routes_data *data)
 
     uuidset_clear(&data->nb_lr);
     uuidset_clear(&data->nb_ls);
+    sset_clear(&data->distributed_lb_routes);
 }
 
 /* Mark the current parsed routes as deleted, then move them aside so each
@@ -950,6 +1030,7 @@ dynamic_routes_prepare_rebuild(struct dynamic_routes_data 
*data)
     }
     uuidset_clear(&data->nb_lr);
     uuidset_clear(&data->nb_ls);
+    sset_clear(&data->distributed_lb_routes);
 }
 
 void
@@ -965,6 +1046,7 @@ en_dynamic_routes_cleanup(void *data_)
     hmapx_destroy(&data->trk_data.trk_deleted_parsed_routes);
     uuidset_destroy(&data->nb_lr);
     uuidset_destroy(&data->nb_ls);
+    sset_destroy(&data->distributed_lb_routes);
 }
 
 enum engine_node_state
@@ -995,19 +1077,22 @@ en_dynamic_routes_run(struct engine_node *node, void 
*data)
             continue;
         }
 
-        build_nat_routes(od, lr_stateful_rec->lrnat_rec,
-                         &northd_data->ls_ports,
-                         &dynamic_routes_data->routes);
-        build_nat_connected_routes(od, &lr_stateful_data->table,
-                                   &northd_data->ls_ports,
-                                   dynamic_routes_data);
-
+        /* Load balancer routes come first: the NAT builders skip an
+         * external IP that a distributed load balancer already advertises
+         * through the same port. */
         build_lb_routes(od, &northd_data->lb_datapaths_map,
                         &northd_data->ls_ports,
-                        &dynamic_routes_data->routes);
+                        dynamic_routes_data);
         build_lb_connected_routes(od, &northd_data->lb_datapaths_map,
                                   &northd_data->ls_ports,
                                   dynamic_routes_data);
+
+        build_nat_routes(od, lr_stateful_rec->lrnat_rec,
+                         &northd_data->ls_ports,
+                         dynamic_routes_data);
+        build_nat_connected_routes(od, &lr_stateful_data->table,
+                                   &northd_data->ls_ports,
+                                   dynamic_routes_data);
     }
 
     dynamic_routes_data->tracked =
diff --git a/northd/en-advertised-route-sync.h 
b/northd/en-advertised-route-sync.h
index e7343072d..ea92c7eea 100644
--- a/northd/en-advertised-route-sync.h
+++ b/northd/en-advertised-route-sync.h
@@ -20,6 +20,7 @@
 #include "lib/uuidset.h"
 #include "openvswitch/hmap.h"
 #include "hmapx.h"
+#include "sset.h"
 
 /* Track what changed in the dynamic_routes engine node's parsed_routes.
  * All hmapx node data are pointers to struct parsed_route. */
@@ -50,6 +51,11 @@ struct dynamic_routes_data {
     /* Contains the uuids of all NB Logical Switches where we rely on port
      * changes for host routes. */
     struct uuidset nb_ls;
+    /* Advertising port and prefix of every distributed load balancer route
+     * emitted in this run, as "<port> <prefix>".  A NAT entry whose
+     * external IP is in this set is not advertised through that port, see
+     * build_nat_route_for_port(). */
+    struct sset distributed_lb_routes;
 
     /* 'tracked' is set to true if there is information available for
      * incremental processing. If true then trk_data is valid. */
diff --git a/ovn-nb.xml b/ovn-nb.xml
index bd8c4540f..dfcdd4508 100644
--- a/ovn-nb.xml
+++ b/ovn-nb.xml
@@ -3673,7 +3673,12 @@ or
           NAT's external IP on this router and it's neighboring routers.
           Neighboring routers are those that are either directly connected,
           via Logical Router Port, or those that are connected via shared
-          Logical Switch.
+          Logical Switch.  A NAT entry that is not distributed, that is,
+          without <ref column="logical_port" table="NAT"/>, is not advertised
+          through a port when a Load Balancer of the same router with
+          <ref column="options" key="distributed" table="Load_Balancer"/>
+          enabled advertises the same address through that port.  The Load
+          Balancer routes carry the locality and health of that address.
         </p>
 
         <p>
diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at
index 13dfe6c92..80330c03d 100644
--- a/tests/ovn-northd.at
+++ b/tests/ovn-northd.at
@@ -19953,6 +19953,271 @@ for old in "$nat_ids 172.16.1.10/32" "$lb_ids 
172.16.1.20/32"; do
         AT_CHECK([echo "${new#* }" | tr , '\n' | grep -qx $m])
     done
 done
+OVN_CLEANUP_NORTHD
+AT_CLEANUP
+])
+
+OVN_FOR_EACH_NORTHD_NO_HV([
+AT_SETUP([dynamic-routing - NAT external IP owned by a distributed LB VIP])
+AT_KEYWORDS([dynamic-routing])
+ovn_start
+
+# lr0 redistributes lb,nat toward the shared LS "join".  lr1 is a neighbour
+# with a distributed gateway port.  It owns a distributed LB and a
+# dnat_and_snat whose external IP is the LB VIP, the way a CMS exposes an
+# overlay VIP through a floating IP.  The per-backend LB routes carry the
+# locality and health of the VIP, so the NAT entry must not add a route
+# tracked by the gateway port: that route would keep the gateway chassis
+# advertised after the LB routes were withdrawn there.
+
+check ovn-nbctl lr-add lr0
+check ovn-nbctl set Logical_Router lr0 \
+    options:dynamic-routing=true       \
+    options:chassis=hv1
+check ovn-nbctl lrp-add lr0 lr0-join 00:00:00:00:00:01
+check ovn-nbctl lrp-set-options lr0-join \
+    dynamic-routing-redistribute=lb,nat
+check ovn-nbctl ls-add join
+check ovn-nbctl lsp-add-router-port join join-lr0 lr0-join
+
+check ovn-nbctl lr-add lr1
+check ovn-nbctl lrp-add lr1 lr1-join 00:00:00:00:00:02 10.0.0.1/24
+check ovn-nbctl lrp-set-gateway-chassis lr1-join hv1
+check ovn-nbctl lsp-add-router-port join join-lr1 lr1-join
+check ovn-nbctl lrp-add lr1 lr1-be 00:00:00:00:00:03 192.168.1.1/24
+check ovn-nbctl ls-add be
+check ovn-nbctl lsp-add-router-port be be-lr1 lr1-be
+check ovn-nbctl lsp-add be be-vm1
+check ovn-nbctl lsp-set-addresses be-vm1 "00:00:00:00:01:01 192.168.1.10"
+check ovn-nbctl lsp-add be be-vm2
+check ovn-nbctl lsp-set-addresses be-vm2 "00:00:00:00:01:02 192.168.1.11"
+
+check ovn-nbctl \
+    -- lb-add lb0 172.16.1.10:80 192.168.1.10:80,192.168.1.11:80 \
+    -- set Load_Balancer lb0 options:distributed=true \
+        ip_port_mappings:192.168.1.10="be-vm1:192.168.1.1" \
+        ip_port_mappings:192.168.1.11="be-vm2:192.168.1.1" \
+    -- lr-lb-add lr1 lb0
+check ovn-nbctl lr-nat-add lr1 dnat_and_snat 172.16.1.10 192.168.1.100
+check ovn-nbctl --wait=sb sync
+
+datapath_lr0=$(fetch_column Datapath_Binding _uuid external_ids:name=lr0)
+pb_lr0_join=$(fetch_column Port_Binding _uuid logical_port=lr0-join)
+pb_lr1_join=$(fetch_column Port_Binding _uuid logical_port=lr1-join)
+pb_be_vm1=$(fetch_column Port_Binding _uuid logical_port=be-vm1)
+pb_be_vm2=$(fetch_column Port_Binding _uuid logical_port=be-vm2)
+
+# Only the two per-backend LB routes exist.  No route tracks lr1-join.
+check_row_count Advertised_Route 2
+check_row_count Advertised_Route 1 \
+    ip_prefix="172.16.1.10"         \
+    datapath=$datapath_lr0           \
+    logical_port=$pb_lr0_join        \
+    tracked_port=$pb_be_vm1
+check_row_count Advertised_Route 1 \
+    ip_prefix="172.16.1.10"         \
+    datapath=$datapath_lr0           \
+    logical_port=$pb_lr0_join        \
+    tracked_port=$pb_be_vm2
+AT_CHECK([ovn-sbctl --bare --columns=external_ids \
+    find Advertised_Route ip_prefix=172.16.1.10 |
+    grep -c 'distributed-lb.*true'], [0], [2
+])
+
+# The VIP is still forwarded through lr1 once.
+ovn-sbctl lflow-list lr0 > lr0_flows
+AT_CHECK([grep -c 'lr_in_ip_routing.*172.16.1.10/32' lr0_flows], [0], [1
+])
+
+# A NAT entry of another router that uses the same address keeps its
+# route.  Only the router that owns the LB gives up its own NAT route.
+check ovn-nbctl --wait=sb lr-nat-add lr0 dnat_and_snat \
+    172.16.1.10 10.0.0.100
+check_row_count Advertised_Route 3
+check_row_count Advertised_Route 3 ip_prefix="172.16.1.10"
+check ovn-nbctl --wait=sb lr-nat-del lr0 dnat_and_snat 172.16.1.10
+check_row_count Advertised_Route 2
+
+# A port that redistributes nat alone has no LB route to rely on, so the
+# NAT entry is advertised and forwarded as before.
+check ovn-nbctl --wait=sb lrp-set-options lr0-join \
+    dynamic-routing-redistribute=nat
+check_row_count Advertised_Route 1
+check_row_count Advertised_Route 1 \
+    ip_prefix="172.16.1.10"         \
+    datapath=$datapath_lr0           \
+    logical_port=$pb_lr0_join        \
+    tracked_port=$pb_lr1_join
+ovn-sbctl lflow-list lr0 > lr0_flows
+AT_CHECK([grep -c 'lr_in_ip_routing.*172.16.1.10/32' lr0_flows], [0], [1
+])
+check ovn-nbctl --wait=sb lrp-set-options lr0-join \
+    dynamic-routing-redistribute=lb,nat
+check_row_count Advertised_Route 2
+
+# A NAT whose external IP is not a VIP is advertised as before.
+check ovn-nbctl --wait=sb lr-nat-add lr1 dnat_and_snat \
+    172.16.1.11 192.168.1.101
+check_row_count Advertised_Route 3
+check_row_count Advertised_Route 1 \
+    ip_prefix="172.16.1.11"         \
+    datapath=$datapath_lr0           \
+    logical_port=$pb_lr0_join        \
+    tracked_port=$pb_lr1_join
+
+# A centralized LB has one VIP-level route that shares the gateway port
+# with the NAT.  The NAT contributes to that route, which stays
+# unconditional.
+check ovn-nbctl --wait=sb set Load_Balancer lb0 options:distributed=false
+check_row_count Advertised_Route 2
+check_row_count Advertised_Route 1 \
+    ip_prefix="172.16.1.10"         \
+    datapath=$datapath_lr0           \
+    logical_port=$pb_lr0_join        \
+    tracked_port=$pb_lr1_join
+AT_CHECK([! ovn-sbctl --bare --columns=external_ids \
+    find Advertised_Route ip_prefix=172.16.1.10 |
+    grep -q 'source'])
+
+# Making the LB distributed again drops the NAT route for the VIP.
+check ovn-nbctl --wait=sb set Load_Balancer lb0 options:distributed=true
+check_row_count Advertised_Route 3
+check_row_count Advertised_Route 0 \
+    ip_prefix="172.16.1.10"         \
+    tracked_port=$pb_lr1_join
+
+# A centralized LB on the same router as a distributed one keeps the
+# route of its own VIP, which shares the gateway port with its NAT entry,
+# whether the port redistributes lb,nat or nat alone.
+check ovn-nbctl \
+    -- lb-add lb1 172.16.1.12:80 192.168.1.10:80 \
+    -- lr-lb-add lr1 lb1
+check ovn-nbctl --wait=sb lr-nat-add lr1 dnat_and_snat \
+    172.16.1.12 192.168.1.102
+check_row_count Advertised_Route 4
+check_row_count Advertised_Route 1 \
+    ip_prefix="172.16.1.12"         \
+    datapath=$datapath_lr0           \
+    logical_port=$pb_lr0_join        \
+    tracked_port=$pb_lr1_join
+check ovn-nbctl --wait=sb lrp-set-options lr0-join \
+    dynamic-routing-redistribute=nat
+check_row_count Advertised_Route 3
+check_row_count Advertised_Route 1 \
+    ip_prefix="172.16.1.12"         \
+    datapath=$datapath_lr0           \
+    logical_port=$pb_lr0_join        \
+    tracked_port=$pb_lr1_join
+check ovn-nbctl --wait=sb lrp-set-options lr0-join \
+    dynamic-routing-redistribute=lb,nat
+check ovn-nbctl --wait=sb \
+    -- lr-lb-del lr1 lb1 \
+    -- lb-del lb1 \
+    -- lr-nat-del lr1 dnat_and_snat 172.16.1.12
+check_row_count Advertised_Route 3
+
+# The external IP is matched in canonical form.  An IPv6 NAT entry spelled
+# with a leading zero still matches the VIP.
+check ovn-nbctl lsp-set-addresses be-vm1 \
+    "00:00:00:00:01:01 192.168.1.10 fd00::10"
+check ovn-nbctl lsp-set-addresses be-vm2 \
+    "00:00:00:00:01:02 192.168.1.11 fd00::11"
+check ovn-nbctl \
+    -- lb-add lb6 "[[2001:db8::10]]:80" "[[fd00::10]]:80,[[fd00::11]]:80" \
+    -- set Load_Balancer lb6 options:distributed=true \
+        ip_port_mappings:\"[[fd00::10]]\"=\"be-vm1:[[fd00::1]]\" \
+        ip_port_mappings:\"[[fd00::11]]\"=\"be-vm2:[[fd00::1]]\" \
+    -- lr-lb-add lr1 lb6
+check ovn-nbctl --wait=sb lr-nat-add lr1 dnat_and_snat \
+    2001:0db8::10 fd00::100
+check_row_count Advertised_Route 5
+check_row_count Advertised_Route 1 \
+    ip_prefix=\"2001:db8::10\"        \
+    datapath=$datapath_lr0           \
+    logical_port=$pb_lr0_join        \
+    tracked_port=$pb_be_vm1
+check_row_count Advertised_Route 1 \
+    ip_prefix=\"2001:db8::10\"        \
+    datapath=$datapath_lr0           \
+    logical_port=$pb_lr0_join        \
+    tracked_port=$pb_be_vm2
+check_row_count Advertised_Route 0 tracked_port=$pb_lr1_join \
+    ip_prefix=\"2001:0db8::10\"
+check_row_count Advertised_Route 0 tracked_port=$pb_lr1_join \
+    ip_prefix=\"2001:db8::10\"
+check ovn-nbctl --wait=sb \
+    -- lr-lb-del lr1 lb6 \
+    -- lb-del lb6 \
+    -- lr-nat-del lr1 dnat_and_snat 2001:0db8::10
+check_row_count Advertised_Route 3
+
+# Removing the LB leaves the plain NAT route.
+check ovn-nbctl --wait=sb lr-lb-del lr1 lb0
+check_row_count Advertised_Route 2
+check_row_count Advertised_Route 1 \
+    ip_prefix="172.16.1.10"         \
+    datapath=$datapath_lr0           \
+    logical_port=$pb_lr0_join        \
+    tracked_port=$pb_lr1_join
+
+# The router that owns both the LB and the NAT applies the same rule to
+# its own routes.
+check ovn-nbctl set Logical_Router lr1 options:dynamic-routing=true
+check ovn-nbctl lrp-set-options lr1-join \
+    dynamic-routing-redistribute=lb,nat
+check ovn-nbctl --wait=sb lr-lb-add lr1 lb0
+datapath_lr1=$(fetch_column Datapath_Binding _uuid external_ids:name=lr1)
+check_row_count Advertised_Route 2 \
+    ip_prefix="172.16.1.10"         \
+    datapath=$datapath_lr1           \
+    logical_port=$pb_lr1_join
+check_row_count Advertised_Route 0 \
+    ip_prefix="172.16.1.10"         \
+    datapath=$datapath_lr1           \
+    tracked_port=$pb_lr1_join
+check_row_count Advertised_Route 1 \
+    ip_prefix="172.16.1.11"         \
+    datapath=$datapath_lr1           \
+    logical_port=$pb_lr1_join        \
+    tracked_port=$pb_lr1_join
+
+# A distributed NAT entry is tracked by its own logical port and keeps its
+# route.  lr2 has a distributed gateway port on its own external switch with
+# a localnet port, so the peer of the gateway port gets no chassisredirect
+# port and a NAT entry with a logical port and an external MAC is
+# distributed.  It shares the row of the backend that it maps, which stays
+# unconditional.
+check ovn-nbctl lr-add lr2
+check ovn-nbctl lrp-add lr2 lr2-join 00:00:00:00:00:04 10.0.0.2/24
+check ovn-nbctl lsp-add-router-port join join-lr2 lr2-join
+check ovn-nbctl ls-add ext2
+check ovn-nbctl lrp-add lr2 lr2-ext2 00:00:00:00:00:05 203.0.113.1/24
+check ovn-nbctl lrp-set-gateway-chassis lr2-ext2 hv1
+check ovn-nbctl lsp-add-router-port ext2 ext2-lr2 lr2-ext2
+check ovn-nbctl lsp-add ext2 ln-ext2
+check ovn-nbctl lsp-set-type ln-ext2 localnet
+check ovn-nbctl lsp-set-options ln-ext2 network_name=phys
+check ovn-nbctl lrp-add lr2 lr2-be2 00:00:00:00:00:06 192.168.2.1/24
+check ovn-nbctl ls-add be2
+check ovn-nbctl lsp-add-router-port be2 be2-lr2 lr2-be2
+check ovn-nbctl lsp-add be2 be2-vm1
+check ovn-nbctl lsp-set-addresses be2-vm1 "00:00:00:00:02:01 192.168.2.10"
+check ovn-nbctl \
+    -- lb-add lb2 172.16.1.20:80 192.168.2.10:80 \
+    -- set Load_Balancer lb2 options:distributed=true \
+        ip_port_mappings:192.168.2.10="be2-vm1:192.168.2.1" \
+    -- lr-lb-add lr2 lb2
+check ovn-nbctl --wait=sb lr-nat-add lr2 dnat_and_snat \
+    172.16.1.20 192.168.2.10 be2-vm1 00:00:00:00:02:01
+pb_be2_vm1=$(fetch_column Port_Binding _uuid logical_port=be2-vm1)
+check_row_count Advertised_Route 1 \
+    ip_prefix="172.16.1.20"         \
+    datapath=$datapath_lr0           \
+    logical_port=$pb_lr0_join        \
+    tracked_port=$pb_be2_vm1
+AT_CHECK([! ovn-sbctl --bare --columns=external_ids \
+    find Advertised_Route ip_prefix=172.16.1.20 |
+    grep -q 'source'])
 
 OVN_CLEANUP_NORTHD
 AT_CLEANUP
-- 
2.53.0


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

Reply via email to