ct_lb_mark_local keeps only the backends that are local to a given
chassis, so the flow that the action encodes to depends on the local
binding of each backend port. lookup_local_port_cb() resolved that
binding without recording an lflow reference, so binding or unbinding a
backend never reprocessed the logical flow and the stale encoding
survived until the next full recompute.

Two cases show the stale flow:

- A router pinned to a given chassis has a local datapath before any
  backend is bound, so the load balancer flow is first encoded on the
  no-local-backend path and keeps dropping the VIP traffic.
- On a datapath that is already local, a backend bound afterwards is
  never added to the group and receives no traffic, which is the case of
  adding a backend to a chassis that already hosts one.

Register the lookup as an OBJDEP_TYPE_PORTBINDING reference, the way
lookup_port_cb() already does, so that the existing dependency tracking
reprocesses the affected logical flows.

Test binding, unbinding, and rebinding backends in both cases. Check the
group contents before comparing incremental and recomputed flows,
including removal of the last local backend on a pinned router. Extend
the multinode test to check fresh VIP connections after backend bindings
change without changing the load balancer configuration.

Check the multinode server-copy command with AT_CHECK so that a setup
failure cannot report the test as successful. Wait for the server
process before recording its cleanup PID.

CC: Alexandra Rukomoinikova <[email protected]>
Fixes: ada67dd17515 ("controller, lib: Add new ct_lb_mark_local action.")
Signed-off-by: Dmitrii Shcherbakov <[email protected]>
---
 controller/lflow.c        |   9 +++
 tests/multinode-macros.at |   4 +-
 tests/multinode.at        |  56 +++++++++++++++
 tests/ovn-controller.at   | 139 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 206 insertions(+), 2 deletions(-)

diff --git a/controller/lflow.c b/controller/lflow.c
index a71d4e0d7..5ed14dc4a 100644
--- a/controller/lflow.c
+++ b/controller/lflow.c
@@ -169,6 +169,15 @@ lookup_local_port_cb(const void *aux_, const char 
*port_name)
 {
     const struct lookup_port_aux *aux = aux_;
 
+    /* Store the name used to look up the lport as an lflow reference, so that
+     * when the lport's port binding changes the logical flow that depends on
+     * the port being local can be reprocessed.  Actions such as
+     * ct_lb_mark_local only keep the backends that are local to this chassis,
+     * so binding or unbinding a backend port changes the flow that the action
+     * encodes to. */
+    objdep_mgr_add(aux->deps_mgr, OBJDEP_TYPE_PORTBINDING, port_name,
+                   &aux->lflow->header_.uuid);
+
     if (local_binding_get_primary_pb(aux->local_bindings, port_name)) {
         return true;
     }
diff --git a/tests/multinode-macros.at b/tests/multinode-macros.at
index be177ed43..396870b32 100644
--- a/tests/multinode-macros.at
+++ b/tests/multinode-macros.at
@@ -630,13 +630,13 @@ host_ovs_vsctl() {
 #
 # Helper to properly start l4 server in inside 'fake_node''s namespace'.
 m4_define([M_START_L4_SERVER],
-    [podman cp $srcdir/server.py $1:/data/metadata_server.py || exit 1
+    [AT_CHECK([podman cp "$srcdir/server.py" $1:/data/metadata_server.py])
      M_NS_DAEMONIZE([$1], [$2],
                     [./data/metadata_server.py --bind-host $3 \
                                                --bind-port $4 \
                                                --reply-string $5],
                      [$6])
-     pid=$(podman exec $1 ip netns exec $2 ps aux | grep metadata_server.py | 
grep $5 | tr -s ' ' | cut -d' ' -f2)
+     OVS_WAIT_UNTIL([pid=$(podman exec $1 ip netns exec $2 ps aux | grep 
metadata_server.py | grep $5 | tr -s ' ' | cut -d' ' -f2) && test -n "$pid"])
      on_exit "podman exec $1 ip netns exec $2 kill $pid"
     ]
 )
diff --git a/tests/multinode.at b/tests/multinode.at
index bd556b8f5..6e5ead52d 100644
--- a/tests/multinode.at
+++ b/tests/multinode.at
@@ -5820,6 +5820,62 @@ AT_CHECK([m_as ovn-gw-1 /bin/bash -c 'for i in $(seq 
500); \
 # Check that requests are distributed among all backends.
 AT_CHECK([grep -q ls1p1 reply && grep -q ls1p2 reply && grep -q ls1p3 reply], 
[0], [])
 
+# Keep traffic on chassis-2 while its backend bindings change. Leave the NB
+# load balancer configuration and the backend servers unchanged.
+check m_as ovn-gw-1 ip route replace $lb_vip via $ip_ch2 dev eth1
+
+AT_CAPTURE_FILE([groups])
+get_lb_backends() {
+    m_as ovn-chassis-2 ovs-ofctl dump-groups br-int > groups || return 1
+    tr ')' '\n' < groups | sed -n 's/.*nat(dst=//p' | sort
+}
+
+check_lb_reply() {
+    m_as ovn-gw-1 /bin/bash -c '
+        for i in $(seq 10); do
+            reply=$(echo "" | timeout 5 nc -w 3 172.31.0.1 80) || exit 1
+            test "$reply" = "$1" || exit 1
+        done
+    ' bash "$1"
+}
+
+# Unbinding a backend must remove it from the group while the other backend
+# keeps the datapath local. Each request below uses a fresh TCP connection.
+check m_as ovn-chassis-2 ovs-vsctl del-port br-int ls1p3-p
+m_wait_row_count nb:Logical_Switch_Port 1 name=ls1p3 up=false
+check multinode_nbctl --wait=hv sync
+OVS_WAIT_FOR_OUTPUT([get_lb_backends], [0], [dnl
+192.168.1.2:10880
+])
+check check_lb_reply ls1p2
+
+check m_as ovn-chassis-2 ovs-vsctl add-port br-int ls1p3-p \
+    -- set Interface ls1p3-p external_ids:iface-id=ls1p3
+m_wait_row_count nb:Logical_Switch_Port 1 name=ls1p3 up=true
+check multinode_nbctl --wait=hv sync
+OVS_WAIT_FOR_OUTPUT([get_lb_backends], [0], [dnl
+192.168.1.2:10880
+192.168.1.3:10880
+])
+
+# Remove the other binding to make every request use the rebound backend.
+check m_as ovn-chassis-2 ovs-vsctl del-port br-int ls1p2-p
+m_wait_row_count nb:Logical_Switch_Port 1 name=ls1p2 up=false
+check multinode_nbctl --wait=hv sync
+OVS_WAIT_FOR_OUTPUT([get_lb_backends], [0], [dnl
+192.168.1.3:10880
+])
+check check_lb_reply ls1p3
+
+check m_as ovn-chassis-2 ovs-vsctl add-port br-int ls1p2-p \
+    -- set Interface ls1p2-p external_ids:iface-id=ls1p2
+m_wait_row_count nb:Logical_Switch_Port 1 name=ls1p2 up=true
+check multinode_nbctl --wait=hv sync
+OVS_WAIT_FOR_OUTPUT([get_lb_backends], [0], [dnl
+192.168.1.2:10880
+192.168.1.3:10880
+])
+
 AT_CHECK([cat ch1_genev.tcpdump], [0], [dnl
 ])
 AT_CHECK([cat ch1_eth2.tcpdump], [0], [dnl
diff --git a/tests/ovn-controller.at b/tests/ovn-controller.at
index 33b6858f6..e7cb463da 100644
--- a/tests/ovn-controller.at
+++ b/tests/ovn-controller.at
@@ -4558,3 +4558,142 @@ done
 OVN_CLEANUP([gw1],[gw3],[hv2])
 AT_CLEANUP
 ])
+
+OVN_FOR_EACH_NORTHD([
+AT_SETUP([ovn-controller - distributed LB backend binding on a local datapath])
+AT_KEYWORDS([ovn lb])
+ovn_start
+net_add n1
+sim_add hv1
+as hv1
+check ovs-vsctl add-br br-phys
+ovn_attach n1 br-phys 192.168.0.1
+
+AT_CAPTURE_FILE([groups])
+get_lb_backends() {
+    ovs-ofctl dump-groups br-int > groups || return 1
+    tr ')' '\n' < groups | sed -n 's/.*nat(dst=//p' | sort
+}
+
+# ct_lb_mark_local only keeps the backends that are local to this chassis, so
+# the flow it encodes to depends on the local binding of each backend port.
+# Binding a second backend on a datapath that is already local must add it to
+# the group instead of leaving the flow with only the first backend.
+check ovn-nbctl lr-add lr0
+check ovn-nbctl lrp-add lr0 lr0-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-lr0 lr0-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" \
+        ip_port_mappings:192.168.1.11="be-vm2"
+check ovn-nbctl lr-lb-add lr0 lb0
+check ovn-nbctl --wait=hv sync
+
+check ovs-vsctl add-port br-int vif1 \
+    -- set Interface vif1 external_ids:iface-id=be-vm1
+OVS_WAIT_UNTIL([test x$(ovn-nbctl get logical_switch_port be-vm1 up) = xtrue])
+check ovn-nbctl --wait=hv sync
+OVS_WAIT_FOR_OUTPUT([get_lb_backends], [0], [dnl
+192.168.1.10:80
+])
+
+check ovs-vsctl add-port br-int vif2 \
+    -- set Interface vif2 external_ids:iface-id=be-vm2
+OVS_WAIT_UNTIL([test x$(ovn-nbctl get logical_switch_port be-vm2 up) = xtrue])
+check ovn-nbctl --wait=hv sync
+OVS_WAIT_FOR_OUTPUT([get_lb_backends], [0], [dnl
+192.168.1.10:80
+192.168.1.11:80
+])
+CHECK_AFTER_RECOMPUTE([hv1], [hv1])
+
+# Keep the datapath local through be-vm1 while removing and rebinding be-vm2.
+check ovs-vsctl del-port br-int vif2
+OVS_WAIT_UNTIL([test x$(ovn-nbctl get logical_switch_port be-vm2 up) = xfalse])
+check ovn-nbctl --wait=hv sync
+OVS_WAIT_FOR_OUTPUT([get_lb_backends], [0], [dnl
+192.168.1.10:80
+])
+CHECK_AFTER_RECOMPUTE([hv1], [hv1])
+
+check ovs-vsctl add-port br-int vif2 \
+    -- set Interface vif2 external_ids:iface-id=be-vm2
+OVS_WAIT_UNTIL([test x$(ovn-nbctl get logical_switch_port be-vm2 up) = xtrue])
+check ovn-nbctl --wait=hv sync
+OVS_WAIT_FOR_OUTPUT([get_lb_backends], [0], [dnl
+192.168.1.10:80
+192.168.1.11:80
+])
+
+OVN_CLEANUP([hv1])
+AT_CLEANUP
+])
+
+OVN_FOR_EACH_NORTHD([
+AT_SETUP([ovn-controller - distributed LB backend binding on a pinned router])
+AT_KEYWORDS([ovn lb])
+ovn_start
+net_add n1
+sim_add hv1
+as hv1
+check ovs-vsctl add-br br-phys
+ovn_attach n1 br-phys 192.168.0.1
+
+AT_CAPTURE_FILE([groups])
+get_lb_backends() {
+    ovs-ofctl dump-groups br-int > groups || return 1
+    tr ')' '\n' < groups | sed -n 's/.*nat(dst=//p' | sort
+}
+
+# The datapath of a router pinned to this chassis is local before any backend
+# is bound, so the load balancer flow is first encoded with no local backend.
+# Binding a backend afterwards must re-encode the flow with it.
+check ovn-nbctl lr-add lr0
+check ovn-nbctl set Logical_Router lr0 options:chassis=hv1
+check ovn-nbctl lrp-add lr0 lr0-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-lr0 lr0-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 \
+    -- lb-add lb0 172.16.1.10:80 192.168.1.10:80 \
+    -- set Load_Balancer lb0 options:distributed=true \
+        ip_port_mappings:192.168.1.10="be-vm1"
+check ovn-nbctl lr-lb-add lr0 lb0
+check ovn-nbctl --wait=hv sync
+OVS_WAIT_FOR_OUTPUT([get_lb_backends], [0], [])
+
+check ovs-vsctl add-port br-int vif1 \
+    -- set Interface vif1 external_ids:iface-id=be-vm1
+OVS_WAIT_UNTIL([test x$(ovn-nbctl get logical_switch_port be-vm1 up) = xtrue])
+check ovn-nbctl --wait=hv sync
+OVS_WAIT_FOR_OUTPUT([get_lb_backends], [0], [dnl
+192.168.1.10:80
+])
+CHECK_AFTER_RECOMPUTE([hv1], [hv1])
+
+# The pinned router must encode with no local backend again after unbinding
+# its last backend, then use that backend once it is rebound.
+check ovs-vsctl del-port br-int vif1
+OVS_WAIT_UNTIL([test x$(ovn-nbctl get logical_switch_port be-vm1 up) = xfalse])
+check ovn-nbctl --wait=hv sync
+OVS_WAIT_FOR_OUTPUT([get_lb_backends], [0], [])
+CHECK_AFTER_RECOMPUTE([hv1], [hv1])
+
+check ovs-vsctl add-port br-int vif1 \
+    -- set Interface vif1 external_ids:iface-id=be-vm1
+OVS_WAIT_UNTIL([test x$(ovn-nbctl get logical_switch_port be-vm1 up) = xtrue])
+check ovn-nbctl --wait=hv sync
+OVS_WAIT_FOR_OUTPUT([get_lb_backends], [0], [dnl
+192.168.1.10:80
+])
+
+OVN_CLEANUP([hv1])
+AT_CLEANUP
+])
-- 
2.53.0


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

Reply via email to