Hi Jacob. Like with patch 1, I enlisted claude-code for assistance
with this review. Like in patch 1, I have annotated claude-code's
findings with [claude] and mine with [me]. In most cases, I've
shortened claude-code's response. If I haven't, then I've indicated it
otherwise.

On Tue, Nov 17, 2026 at 3:28 PM Jacob Tanenbaum <[email protected]> wrote:
>
> Commit 99b00d4c9 ("northd: Track router echo request/reply in the

[claude]
The commit hash is incorrect.

[me]
I'm guessing this was the hash of patch 1 in v1 of the series. But
edits to the first patch have changed the hash of patch 1. The easiest
way to work through this is to just refer to "the previous patch" or
something similar.

> router port ct zone.") assigned a CT zone to the switch-side patch
> port of every router port on a local logical switch.  To keep that
> assignment consistent it made ct_zones_runtime_data_handler() fall
> back to a full recompute whenever any non-ACL patch port was tracked,
> which is far more than the actual dependency: the zone of such a port
> is needed if and only if the port is still present in the peer set of
> a local logical switch.
>
> Track that condition instead.  The runtime_data engine node now
> maintains a shash of tracked peer ports, keyed by logical port name,
> which binding.c fills in whenever a peer relationship is added to or
> removed from an already local datapath.  The ct_zones handler
> processes those ports through the existing idempotent
> ct_zone_handle_port_update(), and for non-ACL patch ports found in
> tracked_dp_bindings it reads the need directly from the current peer
> set of the port's datapath -- the same condition ct_zones_update()
> applies on a full recompute -- so zones of ports that lost their peer
> relationship (e.g. a router port that stops being an l3gateway port)
> are still released.  Datapaths that become local keep riding the
> TRACKED_RESOURCE_NEW fallback, which is also required for the NAT
> zones of newly local router datapaths.
>
> Assisted-by: GLM 5.3, OpenCode
> Signed-off-by: Jacob Tanenbaum <[email protected]>
> ---
> v4:
>  - No change
> v3:
>  - No change
> v2:
>  - Found a discrepancy between recalculate and I-P when the peer
>    relationship is severed without changing the switch side SB port
>    binding.
> ---
>  controller/binding.c        |  21 +++--
>  controller/binding.h        |   5 ++
>  controller/local_data.c     |  43 +++++++++-
>  controller/local_data.h     |  19 ++++-
>  controller/ovn-controller.c |  64 +++++++++++++--
>  tests/ovn-controller.at     | 153 ++++++++++++++++++++++++++++++++++++
>  6 files changed, 286 insertions(+), 19 deletions(-)
>
> diff --git a/controller/binding.c b/controller/binding.c
> index a13b3928d..499bd77d0 100644
> --- a/controller/binding.c
> +++ b/controller/binding.c
> @@ -743,7 +743,8 @@ remove_related_lport(const struct sbrec_port_binding *pb,
>   */
>  static void
>  update_ld_peers(const struct sbrec_port_binding *pb,
> -                 struct hmap *local_datapaths)
> +                 struct hmap *local_datapaths,
> +                 struct shash *tracked_peer_ports)
>  {
>      struct local_datapath *ld =
>          get_local_datapath(local_datapaths, pb->datapath->tunnel_key);
> @@ -760,7 +761,8 @@ update_ld_peers(const struct sbrec_port_binding *pb,
>      enum en_lport_type type = get_lport_type(pb);
>      size_t num_peers = vector_len(&ld->peer_ports);
>      if (type != LP_PATCH) {
> -        remove_local_datapath_peer_port(pb, ld, local_datapaths);
> +        remove_local_datapath_peer_port(pb, ld, local_datapaths,
> +                                        tracked_peer_ports);
>          if (num_peers != vector_len(&ld->peer_ports)) {
>              static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
>              VLOG_DBG_RL(&rl,
> @@ -2040,7 +2042,8 @@ consider_nonvif_lport_(const struct sbrec_port_binding 
> *pb,
>                      b_ctx_in->sbrec_port_binding_by_datapath,
>                      b_ctx_in->sbrec_port_binding_by_name,
>                      ld, b_ctx_out->local_datapaths,
> -                    b_ctx_out->tracked_dp_bindings);
> +                    b_ctx_out->tracked_dp_bindings,
> +                    b_ctx_out->tracked_peer_ports);
>              }
>          }
>
> @@ -2074,7 +2077,8 @@ consider_nonvif_lport_(const struct sbrec_port_binding 
> *pb,
>
>          if (ld) {
>              remove_local_datapath_peer_port(pb, ld,
> -                                            b_ctx_out->local_datapaths);
> +                                            b_ctx_out->local_datapaths,
> +                                            b_ctx_out->tracked_peer_ports);
>          }
>      }
>
> @@ -2461,7 +2465,8 @@ remove_pb_from_local_datapath(const struct 
> sbrec_port_binding *pb,
>      remove_related_lport(pb, b_ctx_out);
>      if (!strcmp(pb->type, "patch") ||
>          !strcmp(pb->type, "l3gateway")) {
> -        remove_local_datapath_peer_port(pb, ld, b_ctx_out->local_datapaths);
> +        remove_local_datapath_peer_port(pb, ld, b_ctx_out->local_datapaths,
> +                                        b_ctx_out->tracked_peer_ports);
>      } else if (!strcmp(pb->type, "localnet")) {
>          if (ld->localnet_port && !strcmp(ld->localnet_port->logical_port,
>                                           pb->logical_port)) {
> @@ -3123,7 +3128,8 @@ consider_patch_port_for_local_datapaths(const struct 
> sbrec_port_binding *pb,
>                  b_ctx_in->sbrec_port_binding_by_datapath,
>                  b_ctx_in->sbrec_port_binding_by_name,
>                  ld, b_ctx_out->local_datapaths,
> -                b_ctx_out->tracked_dp_bindings);
> +                b_ctx_out->tracked_dp_bindings,
> +                b_ctx_out->tracked_peer_ports);
>          }
>      }
>
> @@ -3444,7 +3450,8 @@ delete_done:
>          }
>
>          if (sbrec_port_binding_is_updated(pb, SBREC_PORT_BINDING_COL_TYPE)) {
> -            update_ld_peers(pb, b_ctx_out->local_datapaths);
> +            update_ld_peers(pb, b_ctx_out->local_datapaths,
> +                            b_ctx_out->tracked_peer_ports);
>          }
>
>          if (!handle_updated_port(b_ctx_in, b_ctx_out, pb)) {
> diff --git a/controller/binding.h b/controller/binding.h
> index 817c4e296..618506286 100644
> --- a/controller/binding.h
> +++ b/controller/binding.h
> @@ -111,6 +111,11 @@ struct binding_ctx_out {
>       * the changed datapaths and port bindings. */
>      struct hmap *tracked_dp_bindings;
>
> +    /* shash of 'struct tracked_peer_port' (keyed by logical port name)
> +     * which the callee fills in when the peer relationship of a
> +     * switch-side patch port changes. */
> +    struct shash *tracked_peer_ports;
> +
>      struct if_status_mgr *if_mgr;
>
>      struct sset *postponed_ports;
> diff --git a/controller/local_data.c b/controller/local_data.c
> index ad4b92f1f..38aa982f9 100644
> --- a/controller/local_data.c
> +++ b/controller/local_data.c
> @@ -237,9 +237,13 @@ add_local_datapath_peer_port(
>      struct ovsdb_idl_index *sbrec_port_binding_by_name,
>      struct local_datapath *ld,
>      struct hmap *local_datapaths,
> -    struct hmap *tracked_datapaths)
> +    struct hmap *tracked_datapaths,
> +    struct shash *tracked_peer_ports)
>  {
>      local_datapath_peer_port_add(ld, pb, peer);
> +    if (ld->is_switch) {
> +        tracked_peer_port_add(pb, true, tracked_peer_ports);
> +    }
>
>      struct local_datapath *peer_ld =
>          get_local_datapath(local_datapaths,
> @@ -254,6 +258,9 @@ add_local_datapath_peer_port(
>      }
>
>      local_datapath_peer_port_add(peer_ld, peer, pb);
> +    if (peer_ld->is_switch) {
> +        tracked_peer_port_add(peer, true, tracked_peer_ports);
> +    }
>  }
>
>  void
> @@ -275,7 +282,8 @@ local_data_dump_peer_ports(struct hmap *local_datapaths, 
> struct ds *peer_ports)
>  void
>  remove_local_datapath_peer_port(const struct sbrec_port_binding *pb,
>                                  struct local_datapath *ld,
> -                                struct hmap *local_datapaths)
> +                                struct hmap *local_datapaths,
> +                                struct shash *tracked_peer_ports)
>  {
>      size_t i = 0;
>      const struct peer_ports *peers;
> @@ -297,6 +305,10 @@ remove_local_datapath_peer_port(const struct 
> sbrec_port_binding *pb,
>          local_datapath_usage += vector_memory_usage(&ld->peer_ports);
>      }
>
> +    if (ld->is_switch) {
> +        tracked_peer_port_add(pb, false, tracked_peer_ports);
> +    }
> +
>      const struct sbrec_port_binding *peer = removed.remote;
>      struct local_datapath *peer_ld =
>          get_local_datapath(local_datapaths, peer->datapath->tunnel_key);
> @@ -304,7 +316,8 @@ remove_local_datapath_peer_port(const struct 
> sbrec_port_binding *pb,
>          /* Remove the peer port from the peer datapath. The peer
>           * datapath also tries to remove its peer lport, but that would
>           * be no-op. */
> -        remove_local_datapath_peer_port(peer, peer_ld, local_datapaths);
> +        remove_local_datapath_peer_port(peer, peer_ld, local_datapaths,
> +                                        tracked_peer_ports);
>      }
>  }
>
> @@ -436,6 +449,30 @@ tracked_datapath_lport_add(const struct 
> sbrec_port_binding *pb,
>      lport->tracked_type = tracked_type;
>  }
>
> +/* Adds 'pb' to 'tracked_peer_ports' keyed by its logical port name,
> + * with the last write winning if the same logical port was already
> + * tracked (e.g. the peer relationship was added and removed within the
> + * same IDL iteration).  A NULL 'tracked_peer_ports' is allowed, in
> + * which case this is a no-op. */
> +void
> +tracked_peer_port_add(const struct sbrec_port_binding *pb,
> +                      bool zone_needed,
> +                      struct shash *tracked_peer_ports)
> +{
> +    if (!tracked_peer_ports) {
> +        return;
> +    }
> +
> +    struct tracked_peer_port *tpp =
> +        shash_find_data(tracked_peer_ports, pb->logical_port);
> +    if (!tpp) {
> +        tpp = xmalloc(sizeof *tpp);
> +        shash_add(tracked_peer_ports, pb->logical_port, tpp);
> +    }
> +    tpp->pb = pb;
> +    tpp->zone_needed = zone_needed;
> +}
> +
>  void
>  tracked_datapaths_clear(struct hmap *tracked_datapaths)
>  {
> diff --git a/controller/local_data.h b/controller/local_data.h
> index 130ae536a..06a73141c 100644
> --- a/controller/local_data.h
> +++ b/controller/local_data.h
> @@ -101,11 +101,13 @@ void add_local_datapath_peer_port(
>      struct ovsdb_idl_index *sbrec_port_binding_by_name,
>      struct local_datapath *,
>      struct hmap *local_datapaths,
> -    struct hmap *tracked_datapaths);
> +    struct hmap *tracked_datapaths,
> +    struct shash *tracked_peer_ports);
>
>  void remove_local_datapath_peer_port(const struct sbrec_port_binding *pb,
>                                       struct local_datapath *ld,
> -                                     struct hmap *local_datapaths);
> +                                     struct hmap *local_datapaths,
> +                                     struct shash *tracked_peer_ports);
>
>  enum en_tracked_resource_type {
>      TRACKED_RESOURCE_NEW,
> @@ -138,6 +140,19 @@ void tracked_datapath_lport_add(const struct 
> sbrec_port_binding *,
>  void tracked_datapaths_clear(struct hmap *tracked_datapaths);
>  void tracked_datapaths_destroy(struct hmap *tracked_datapaths);
>
> +/* A switch-side router patch port whose CT zone assignment may have
> + * changed: 'zone_needed' is true when the connected logical switch is
> + * (still) a local datapath, false when the peer relationship was
> + * removed. */
> +struct tracked_peer_port {
> +    const struct sbrec_port_binding *pb;
> +    bool zone_needed;
> +};
> +
> +void tracked_peer_port_add(const struct sbrec_port_binding *pb,
> +                           bool zone_needed,
> +                           struct shash *tracked_peer_ports);
> +
>  /* Maps from a chassis to the OpenFlow port number of the tunnel that can be
>   * used to reach that chassis. */
>  struct chassis_tunnel {
> diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c
> index 475ce4919..fdb65b5ab 100644
> --- a/controller/ovn-controller.c
> +++ b/controller/ovn-controller.c
> @@ -1390,6 +1390,11 @@ struct ed_type_runtime_data {
>      bool localnet_learn_fdb_changed;
>      struct hmap tracked_dp_bindings;
>
> +    /* Tracked peer (switch-side router) patch ports whose CT zone
> +     * assignment may have changed.  Only meaningful when 'tracked' is
> +     * true. */
> +    struct shash tracked_peer_ports;
> +
>      struct shash local_active_ports_ipv6_pd;
>      struct shash local_active_ports_ras;
>
> @@ -1479,6 +1484,7 @@ en_runtime_data_clear_tracked_data(void *data_)
>
>      tracked_datapaths_destroy(&data->tracked_dp_bindings);
>      hmap_init(&data->tracked_dp_bindings);
> +    shash_clear_free_data(&data->tracked_peer_ports);
>      data->local_lports_changed = false;
>      data->tracked = false;
>  }
> @@ -1503,6 +1509,7 @@ en_runtime_data_init(struct engine_node *node 
> OVS_UNUSED,
>
>      /* Init the tracked data. */
>      hmap_init(&data->tracked_dp_bindings);
> +    shash_init(&data->tracked_peer_ports);
>
>      return data;
>  }
> @@ -1522,6 +1529,7 @@ en_runtime_data_cleanup(void *data)
>      local_datapaths_destroy(&rt_data->local_datapaths);
>      shash_destroy(&rt_data->local_active_ports_ipv6_pd);
>      shash_destroy(&rt_data->local_active_ports_ras);
> +    shash_destroy_free_data(&rt_data->tracked_peer_ports);
>      local_binding_data_destroy(&rt_data->lbinding_data);
>  }
>
> @@ -1616,6 +1624,7 @@ init_binding_ctx(struct engine_node *node,
>      b_ctx_out->local_iface_ids = &rt_data->local_iface_ids;
>      b_ctx_out->postponed_ports = rt_data->postponed_ports;
>      b_ctx_out->tracked_dp_bindings = NULL;
> +    b_ctx_out->tracked_peer_ports = NULL;
>      b_ctx_out->if_mgr = ctrl_ctx->if_mgr;
>      b_ctx_out->localnet_learn_fdb = rt_data->localnet_learn_fdb;
>      b_ctx_out->localnet_learn_fdb_changed = false;
> @@ -1839,6 +1848,7 @@ runtime_data_ovs_interface_shadow_handler(struct 
> engine_node *node, void *data)
>      init_binding_ctx(node, rt_data, &b_ctx_in, &b_ctx_out);
>      rt_data->tracked = true;
>      b_ctx_out.tracked_dp_bindings = &rt_data->tracked_dp_bindings;
> +    b_ctx_out.tracked_peer_ports = &rt_data->tracked_peer_ports;
>
>      if (!binding_handle_ovs_interface_changes(&b_ctx_in, &b_ctx_out)) {
>          return EN_UNHANDLED;
> @@ -1991,6 +2001,7 @@ runtime_data_sb_port_binding_handler(struct engine_node 
> *node, void *data)
>
>      rt_data->tracked = true;
>      b_ctx_out.tracked_dp_bindings = &rt_data->tracked_dp_bindings;
> +    b_ctx_out.tracked_peer_ports = &rt_data->tracked_peer_ports;
>
>      if (!binding_handle_port_binding_changes(&b_ctx_in, &b_ctx_out)) {
>          return EN_UNHANDLED;
> @@ -2003,7 +2014,8 @@ runtime_data_sb_port_binding_handler(struct engine_node 
> *node, void *data)
>              b_ctx_out.non_vif_ports_changed ||
>              b_ctx_out.local_lports_changed ||
>              b_ctx_out.localnet_learn_fdb_changed ||
> -            !hmap_is_empty(b_ctx_out.tracked_dp_bindings)) {
> +            !hmap_is_empty(b_ctx_out.tracked_dp_bindings) ||
> +            !shash_is_empty(b_ctx_out.tracked_peer_ports)) {
>          result = EN_HANDLED_UPDATED;
>      }
>
> @@ -2873,15 +2885,33 @@ ct_zones_runtime_data_handler(struct engine_node 
> *node, void *data)
>                  continue;
>              }
>
> -            /* The CT zone of a patch port without the ACL flag depends
> -             * on the local datapaths of the connected switches, which is
> -             * not tracked incrementally.  Fall back to a full recompute
> -             * of ct_zones so that zones for router ports are assigned
> -             * and released consistently with ct_zones_update(). */
> +            /* The CT zone of a patch port without the ACL flag is needed
> +             * if and only if the port is the switch-side peer of a router
> +             * port on a local logical switch.  Read that condition
> +             * directly from the peer set of the port's datapath, which is
> +             * the same condition ct_zones_update() applies on a full
> +             * recompute; ports whose peer relationship was removed are
> +             * also tracked in rt_data->tracked_peer_ports below. */
>              if (!strcmp(t_lport->pb->type, "patch") &&
>                  !smap_get_bool(&t_lport->pb->options,
>                                 "enable_router_port_acl", false)) {
> -                return EN_UNHANDLED;
> +                bool zone_needed = false;
> +                struct local_datapath *ld = get_local_datapath(
> +                    &rt_data->local_datapaths,
> +                    t_lport->pb->datapath->tunnel_key);
> +                if (ld && ld->is_switch) {
> +                    const struct peer_ports *peers;
> +                    VECTOR_FOR_EACH_PTR (&ld->peer_ports, peers) {
> +                        if (peers->local == t_lport->pb) {
> +                            zone_needed = true;
> +                            break;
> +                        }
> +                    }
> +                }
> +                updated |= ct_zone_handle_port_update(
> +                    &ct_zones_data->ctx, t_lport->pb, zone_needed,
> +                    &scan_start, min_ct_zone, max_ct_zone);
> +                continue;

[claude] (I'm just going to copy-paste what it said)

I'm not sure physical flows stay in sync here.
pflow_output_ct_zones_handler() returns EN_HANDLED_UNCHANGED unless
ct_zones was recomputed.  It relies on the affected lport also being
in tracked_dp_bindings (or in the SB Port_Binding tracked rows), so
that the pflow_output handlers regenerate its flows.

The zone of the switch-side port is baked into OpenFlow in two places:

  consider_port_binding() -> put_local_common_flows(binding_zones)
  consider_port_binding() -> load_logical_ingress_metadata(peer_zones)

The first is in the switch-side port's own flows.  The second is in
the router-side port's flows.

A port can now land in tracked_peer_ports without its row, or its
peer's row, being tracked.  The second new test is one example: only
the router-side row is deleted.  Without enable_router_port_acl, the
zone of ls2-rp would be released by this loop, but the flows of ls2-rp
are never recomputed.  They keep loading a zone id that is now free and
can be handed to another port by ct_zone_assign_unused().

Before this patch, the EN_UNHANDLED fallback forced a ct_zones
recompute, and so a full pflow_output recompute, which covered this.
Should pflow_output_ct_zones_handler() fall back to a recompute when
tracked_peer_ports is non-empty?  Alternatively,
pflow_output_runtime_data_handler() could call
physical_handle_flows_for_lport() for each tracked peer port and its
remote.

It would also be useful if the tests checked that the zone loaded in
the OpenFlow tables matches ct-zone-<port> after the incremental
update, not only the br-int external_ids.

>              }
>              bool port_updated =
>                      t_lport->tracked_type == TRACKED_RESOURCE_NEW ||
> @@ -2893,6 +2923,26 @@ ct_zones_runtime_data_handler(struct engine_node 
> *node, void *data)
>          }
>      }
>
> +    struct shash_node *tpp_node;
> +    SHASH_FOR_EACH (tpp_node, &rt_data->tracked_peer_ports) {
> +        struct tracked_peer_port *tpp = tpp_node->data;
> +        bool zone_needed = tpp->zone_needed;
> +        if (!zone_needed) {
> +            /* The peer relationship was removed, but the port may still
> +             * be entitled to a zone through local_lports (e.g. a patch
> +             * port with enable_router_port_acl).  */
> +            struct simap_node *lport_node = simap_find(
> +                &rt_data->local_lports, tpp_node->name);
> +            if (lport_node && lport_node->data == LPORT_STATUS_BOUND) {
> +                zone_needed = true;
> +            }
> +        }
> +        updated |= ct_zone_handle_port_update(&ct_zones_data->ctx,
> +                                              tpp->pb, zone_needed,
> +                                              &scan_start, min_ct_zone,
> +                                              max_ct_zone);
> +    }
> +
>      return updated ? EN_HANDLED_UPDATED : EN_HANDLED_UNCHANGED;
>  }
>
> diff --git a/tests/ovn-controller.at b/tests/ovn-controller.at
> index fc5fa1001..8b704de49 100644
> --- a/tests/ovn-controller.at
> +++ b/tests/ovn-controller.at
> @@ -2870,6 +2870,159 @@ OVS_WAIT_UNTIL([check_ovsdb_zone lr0_snat $snat_zone])
>  OVN_CLEANUP([hv1])
>  AT_CLEANUP
>
> +OVN_FOR_EACH_NORTHD([
> +AT_SETUP([ovn-controller - I-P for CT zone patch ports])
> +AT_KEYWORDS([ovn-ct-zone-patch-ip])
> +
> +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
> +
> +# ls1 and ls2 are local through their VIFs and lr0 is local through
> +# rp-ls1, so attaching lr0 to ls2 only changes the peer set of already
> +# local datapaths.
> +check ovn-nbctl lr-add lr0
> +check ovn-nbctl ls-add ls1
> +check ovn-nbctl lrp-add lr0 rp-ls1 00:00:01:01:02:01 10.0.1.1/24
> +check ovn-nbctl lsp-add-router-port ls1 ls1-rp rp-ls1
> +check ovn-nbctl lsp-add ls1 lsp1 -- lsp-set-addresses lsp1 \
> +"00:11:00:00:00:01 10.0.1.2"
> +check ovn-nbctl ls-add ls2
> +check ovn-nbctl lsp-add ls2 lsp2 -- lsp-set-addresses lsp2 \
> +"00:11:00:00:00:02 10.0.2.2"
> +
> +as hv1
> +check ovs-vsctl add-port br-int vif1 \
> +    -- set Interface vif1 external_ids:iface-id=lsp1
> +check ovs-vsctl add-port br-int vif2 \
> +    -- set Interface vif2 external_ids:iface-id=lsp2
> +
> +wait_for_ports_up
> +check ovn-nbctl --wait=hv sync
> +
> +# Attaching lr0 to the already local ls2 assigns the CT zone of the
> +# switch-side patch port incrementally.
> +check as hv1 ovn-appctl -t ovn-controller inc-engine/clear-stats
> +check ovn-nbctl --wait=hv lrp-add lr0 rp-ls2 00:00:01:01:02:02 10.0.2.1/24 \
> +    -- lsp-add-router-port ls2 ls2-rp rp-ls2
> +OVS_WAIT_UNTIL([ovs-vsctl get Bridge br-int external_ids:ct-zone-ls2-rp])
> +check_controller_engine_stats hv1 runtime_data norecompute compute
> +check_controller_engine_stats hv1 ct_zones norecompute compute
> +
> +# Detaching lr0 from ls2 releases the CT zone incrementally.
> +check as hv1 ovn-appctl -t ovn-controller inc-engine/clear-stats
> +check ovn-nbctl --wait=hv lsp-del ls2-rp -- lrp-del rp-ls2
> +OVS_WAIT_WHILE([ovs-vsctl get Bridge br-int external_ids:ct-zone-ls2-rp])
> +check_controller_engine_stats hv1 runtime_data norecompute compute
> +check_controller_engine_stats hv1 ct_zones norecompute compute
> +
> +# Re-attaching with the same port names re-assigns the zone
> +# incrementally.
> +check as hv1 ovn-appctl -t ovn-controller inc-engine/clear-stats
> +check ovn-nbctl --wait=hv lrp-add lr0 rp-ls2 00:00:01:01:02:02 10.0.2.1/24 \
> +    -- lsp-add-router-port ls2 ls2-rp rp-ls2
> +OVS_WAIT_UNTIL([ovs-vsctl get Bridge br-int external_ids:ct-zone-ls2-rp])
> +check_controller_engine_stats hv1 ct_zones norecompute compute
> +
> +# ls3 is not local yet: attaching it to the already local lr0 makes the
> +# datapath newly tracked, so a full ct_zones recompute is expected and
> +# the zone is assigned by it.
> +check ovn-nbctl ls-add ls3
> +check as hv1 ovn-appctl -t ovn-controller inc-engine/clear-stats
> +check ovn-nbctl --wait=hv lrp-add lr0 rp-ls3 00:00:01:01:02:03 10.0.3.1/24 \
> +    -- lsp-add-router-port ls3 ls3-rp rp-ls3
> +OVS_WAIT_UNTIL([ovs-vsctl get Bridge br-int external_ids:ct-zone-ls3-rp])
> +check_controller_engine_stats hv1 ct_zones recompute nocompute
> +
> +# Toggling enable_router_port_acl on a local patch port is still handled
> +# by the tracked lports path of the ct_zones handler.
> +check as hv1 ovn-appctl -t ovn-controller inc-engine/clear-stats
> +check ovn-nbctl --wait=hv lsp-set-options ls1-rp enable_router_port_acl=true

[claude]
lsp-set-options doesn't add options to the switch port's existing
options values. It overwrites all options with whatever is given in
this command. In this case, it overwrites options:router-port, which
removes the peer relationship with the logical router port. If you use
`ovn-nbctl set Logical_Switch_Port ls1-rp
options:enable_router_port_acl=true` then this will add the
enable_router_port_acl to the existing options instead.

[me]
I'm not actually sure if this matters or not since we are so close to
the end of the test at this point. However, since the line below
specifically is checking for the ct-zone on ls1-rp1, it seems wrong
that we would be severing the peer relationship with the logical
router's port. I'm actually a bit confused as to how the
OVS_WAIT_UNTIL succeeds below since the peer relationship has been
removed. I would expect ls1-rp1 to no longer get a CT zone assigned in
this case. I suppose it's possible that the test is succeeding because
the br-int external_id has not been updated? What about if we checked
the CT zone assignments in ovn-controller itself using `ovn-appctl -t
ovn-controller ct-zone-list` instead? Would we still see a zone
assigned to ls1-rp?

> +OVS_WAIT_UNTIL([ovs-vsctl get Bridge br-int external_ids:ct-zone-ls1-rp])
> +check_controller_engine_stats hv1 ct_zones norecompute compute
> +
> +OVN_CLEANUP([hv1])
> +AT_CLEANUP
> +])
> +
> +OVN_FOR_EACH_NORTHD([
> +AT_SETUP([ovn-controller - CT zone for enable_router_port_acl patch port on 
> peer removal])
> +AT_KEYWORDS([ovn-ct-zone-patch-ip])
> +
> +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
> +
> +# ls1 and ls2 are local on hv1 through lsp1 and lsp2, and lr0 is local
> +# through rp-ls1, so lr0 stays local for the whole test.  rp-ls2 is a
> +# distributed gateway port, so northd propagates the
> +# enable_router_port_acl option of the switch-side port ls2-rp to its
> +# SB port binding and ls2-rp holds a CT zone on hv1 through
> +# local_lports.
> +check ovn-nbctl lr-add lr0
> +check ovn-nbctl ls-add ls1
> +check ovn-nbctl lrp-add lr0 rp-ls1 00:00:01:01:01:01 10.0.1.1/24
> +check ovn-nbctl lsp-add-router-port ls1 ls1-rp rp-ls1
> +check ovn-nbctl lsp-add ls1 lsp1 -- lsp-set-addresses lsp1 \
> +"00:11:00:00:00:01 10.0.1.2"
> +check ovn-nbctl ls-add ls2
> +check ovn-nbctl lrp-add lr0 rp-ls2 00:00:01:01:02:02 10.0.2.1/24
> +check ovn-nbctl lrp-set-gateway-chassis rp-ls2 hv1 20
> +check ovn-nbctl lsp-add-router-port ls2 ls2-rp rp-ls2
> +check ovn-nbctl set Logical_Switch_Port ls2-rp 
> options:enable_router_port_acl=true
> +check ovn-nbctl lsp-add ls2 lsp2 -- lsp-set-addresses lsp2 \
> +"00:11:00:00:00:02 10.0.2.2"
> +
> +as hv1
> +check ovs-vsctl add-port br-int vif1 \
> +    -- set Interface vif1 external_ids:iface-id=lsp1
> +check ovs-vsctl add-port br-int vif2 \
> +    -- set Interface vif2 external_ids:iface-id=lsp2
> +
> +wait_for_ports_up
> +check ovn-nbctl --wait=hv sync
> +
> +OVS_WAIT_UNTIL([ovs-vsctl get Bridge br-int external_ids:ct-zone-ls2-rp])
> +
> +# Pause northd and delete the router-side port binding directly in the
> +# SB database.  This severs the peer relationship on hv1 without
> +# touching the ls2-rp SB row, so the only incremental input is the
> +# tracked peer port with zone_needed=false.  The zone must be preserved
> +# on hv1: enable_router_port_acl still entitles ls2-rp to a zone through
> +# its local_lports entry, like on a full recompute.
> +check as northd ovn-appctl -t ovn-northd pause
> +rp_ls2_uuid=$(ovn-sbctl --bare --columns=_uuid list Port_Binding rp-ls2)
> +check as hv1 ovn-appctl -t ovn-controller inc-engine/clear-stats
> +check ovn-sbctl destroy Port_Binding $rp_ls2_uuid
> +OVS_WAIT_WHILE([as hv1 ovn-sbctl --bare --columns=logical_port list \
> +Port_Binding | grep -qx rp-ls2])

[me]
Using OVS_WAIT_WHILE here will always succeed immediately because the
`ovn-sbctl-destroy` call will not return until the SB DB has responded
to the transaction that deletes rp-ls2.

> +OVS_WAIT_UNTIL([as hv1 ovs-vsctl get Bridge br-int 
> external_ids:ct-zone-ls2-rp])

[claude]
There's a possible race condition here. It's possible that we are
actually reading the br-int ct zone from *before* ovn-controller has
processed the deletion of rp-ls2. We'd normally use something like
ovn-nbctl --wait=hv to ensure that ovn-controller has finished
processing all SB updates, but we can't do that here since northd is
paused and there's no such equivalent option for ovn-sbctl.

[me]
Claude went on to say that changing the SB DB on its own is artificial
and we should use the NB DB to facilitate the change. However, I
actually like what you're doing here to isolate the change to just the
one port binding being deleted. Unfortunately, I don't know of an easy
reliable way to query ovn-controller to know for sure that it has
processed the SB changes. The only way I've thought of is the
following:

1. Clear incremental engine stats in ovn-controller.
2. Delete the SB port binding.
3. Use OVS_WAIT_UNTIL() to block until we have seen the
SB_Port_Binding node's compute or recompute count change.

This should work for two reasons. By specifically waiting for a change
to SB_Port_Binding, it means we have seen ovn-controller process the
specific change to the port binding. If we waited on a different
engine node, like controller_output, that could update based on a
change to the OVS DB, or based on replying to an ECHO request from the
SB DB (unlikely, I know). Then since ovn-controller is
single-threaded, it won't be until the loop after the engine run that
we detect the engine node changes. This should mean that we have
already committed the CT zone change to the OVS DB, and we should be
clear to detect the value in the DB, assuming it's there.


> +check_controller_engine_stats hv1 ct_zones norecompute compute
> +
> +# Remove the deleted router port and its switch-side port from NB and
> +# force a full northd recompute, so that the SB database converges to
> +# a consistent state after the direct row deletion above.
> +check ovn-nbctl lrp-del rp-ls2 -- lsp-del ls2-rp
> +check as northd ovn-appctl -t ovn-northd resume
> +check as northd ovn-appctl -t ovn-northd inc-engine/recompute
> +
> +# The direct SB row deletion above transiently leaves the
> +# chassisredirect port referring to a deleted distributed port, which
> +# the controller logs a warning for before northd converges.
> +OVN_CLEANUP([hv1
> +/No port binding record for distributed port*/d
> +])
> +AT_CLEANUP
> +])
> +
>  OVN_FOR_EACH_NORTHD([
>  AT_SETUP([ovn-controller - Local Chassis_Template_Var updates])
>  AT_KEYWORDS([templates])
> --
> 2.56.1
>

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

Reply via email to