| Message ID | 20261026210208.828138-4-trozet@nvidia.com |
|---|---|
| State | Under Review |
| Delegated to: | Mark Michelson |
| Headers | show |
| Series | Add shared MAC binding scopes | expand |
| Context | Check | Description |
|---|---|---|
| ovsrobot/apply-robot | success | apply and check: success |
| ovsrobot/github-robot-_ovn-kubernetes | success | github build: passed |
| ovsrobot/github-robot-_Build_and_Test | fail | github build: failed |
I want to give this a full review but I had a few questions. On Mon, Oct 26, 2026 at 5:03 PM Tim Rozet via dev <ovs-dev@openvswitch.org> wrote: > Learn scoped neighbors into Shared_MAC_Binding and install one set of > lookup flows per scope. Preserve private fallback, static overrides, > conditional monitoring, and packet-buffer release after cold resolution. > > Use shared bindings for GARP and EVPN synchronization, and probe and > refresh active bindings through the batched statistics update path. > Verify scope existence before inserting bindings so concurrent scope > withdrawal retries instead of failing referential integrity checks. > > Test two member routers learning one binding, timestamp refresh, feature > negotiation, static precedence, and remote-gateway conditional > monitoring. > > Assisted-by: OpenAI Codex > Signed-off-by: Tim Rozet <trozet@nvidia.com> > --- > controller/chassis.c | 7 + > controller/evpn-mac-binding-sync.c | 147 +++++++--- > controller/evpn-mac-binding-sync.h | 16 +- > controller/garp_rarp.c | 36 ++- > controller/garp_rarp.h | 1 + > controller/lflow.c | 135 ++++++++++ > controller/lflow.h | 10 + > controller/mac-cache.c | 417 ++++++++++++++++++++++------- > controller/mac-cache.h | 23 +- > controller/neighbor-of.c | 98 +++++-- > controller/neighbor-of.h | 4 + > controller/ovn-controller.8.xml | 18 ++ > controller/ovn-controller.c | 327 +++++++++++++++++++++- > controller/pinctrl.c | 81 ++++-- > controller/pinctrl.h | 3 + > controller/statctrl.c | 18 ++ > controller/statctrl.h | 1 + > lib/mac-binding-index.c | 67 +++++ > lib/mac-binding-index.h | 13 + > tests/ovn-controller.at | 1 + > tests/ovn-inc-proc-graph-dump.at | 12 +- > tests/ovn-macros.at | 10 +- > tests/ovn.at | 304 ++++++++++++++++++++- > tests/system-ovn.at | 43 +++ > 24 files changed, 1590 insertions(+), 202 deletions(-) > > diff --git a/controller/chassis.c b/controller/chassis.c > index b82683064..325ef3558 100644 > --- a/controller/chassis.c > +++ b/controller/chassis.c > @@ -424,6 +424,7 @@ chassis_build_other_config(const struct > ovs_chassis_cfg *ovs_cfg, > smap_replace(config, OVN_FEATURE_CT_LABEL_FLUSH, > ovs_cfg->ct_label_flush ? "true" :"false"); > smap_replace(config, OVN_FEATURE_CT_STATE_SAVE, "true"); > + smap_replace(config, OVN_FEATURE_SHARED_MAC_BINDING, "true"); > } > > /* > @@ -597,6 +598,11 @@ chassis_other_config_changed(const struct > ovs_chassis_cfg *ovs_cfg, > return true; > } > > + if (!smap_get_bool(&chassis_rec->other_config, > + OVN_FEATURE_SHARED_MAC_BINDING, false)) { > + return true; > + } > + > return false; > } > > @@ -779,6 +785,7 @@ update_supported_sset(struct sset *supported) > sset_add(supported, OVN_FEATURE_CT_NEXT_ZONE); > sset_add(supported, OVN_FEATURE_CT_LABEL_FLUSH); > sset_add(supported, OVN_FEATURE_CT_STATE_SAVE); > + sset_add(supported, OVN_FEATURE_SHARED_MAC_BINDING); > } > > static void > diff --git a/controller/evpn-mac-binding-sync.c > b/controller/evpn-mac-binding-sync.c > index be62c0f9a..535bb78ce 100644 > --- a/controller/evpn-mac-binding-sync.c > +++ b/controller/evpn-mac-binding-sync.c > @@ -28,24 +28,36 @@ > #include "ovn-util.h" > #include "vec.h" > > -/* Hash a (logical_port, ip) pair. */ > +/* Hash a private (logical_port, ip) or shared (scope, ip) pair. */ > static uint32_t > -evpn_mb_hash(const char *logical_port, const char *ip) > +evpn_mb_hash(const struct sbrec_port_binding *router_pb, const char *ip) > { > - uint32_t hash = hash_string(logical_port, 0); > + const struct sbrec_mac_binding_scope *scope = > + router_pb->mac_binding_scope; > + uint32_t hash = hash_boolean(!!scope, 0); > + hash = scope > + ? hash_add(hash, uuid_hash(&scope->header_.uuid)) > + : hash_string(router_pb->logical_port, hash); > return hash_string(ip, hash); > } > > static struct evpn_mb_synced_entry * > -evpn_mb_synced_find(const struct hmap *synced, const char *logical_port, > +evpn_mb_synced_find(const struct hmap *synced, > + const struct sbrec_port_binding *router_pb, > const char *ip) > { > - uint32_t hash = evpn_mb_hash(logical_port, ip); > + const struct sbrec_mac_binding_scope *scope = > + router_pb->mac_binding_scope; > + uint32_t hash = evpn_mb_hash(router_pb, ip); > > struct evpn_mb_synced_entry *entry; > HMAP_FOR_EACH_WITH_HASH (entry, hmap_node, hash, synced) { > - if (!strcmp(entry->logical_port, logical_port) && > - !strcmp(entry->ip, ip)) { > + bool same_binding = scope > + ? entry->shared && uuid_equals(&entry->scope_uuid, > + &scope->header_.uuid) > + : !entry->shared && > + !strcmp(entry->logical_port, router_pb->logical_port); > + if (same_binding && !strcmp(entry->ip, ip)) { > return entry; > } > } > @@ -54,15 +66,20 @@ evpn_mb_synced_find(const struct hmap *synced, const > char *logical_port, > } > > static struct evpn_mb_synced_entry * > -evpn_mb_synced_add(struct hmap *synced, const char *logical_port, > +evpn_mb_synced_add(struct hmap *synced, > + const struct sbrec_port_binding *router_pb, > const char *ip) > { > + const struct sbrec_mac_binding_scope *scope = > + router_pb->mac_binding_scope; > struct evpn_mb_synced_entry *entry = xmalloc(sizeof *entry); > *entry = (struct evpn_mb_synced_entry) { > - .logical_port = xstrdup(logical_port), > + .logical_port = scope ? NULL : xstrdup(router_pb->logical_port), > + .scope_uuid = scope ? scope->header_.uuid : UUID_ZERO, > + .shared = !!scope, > .ip = xstrdup(ip), > }; > - hmap_insert(synced, &entry->hmap_node, evpn_mb_hash(logical_port, > ip)); > + hmap_insert(synced, &entry->hmap_node, evpn_mb_hash(router_pb, ip)); > return entry; > } > > @@ -87,15 +104,17 @@ evpn_mb_sync_waker_schedule(struct evpn_mb_sync_waker > *waker, > } > } > > -/* Sync a single EVPN ARP entry to the SB MAC_Binding table for one > - * router port. Caller must ensure 'ovnsb_idl_txn' is valid. > +/* Sync a single EVPN ARP entry to the appropriate SB MAC binding table > for > + * one router port. Caller must ensure 'ovnsb_idl_txn' is valid. > * Returns the remaining time (in ms) until the next timestamp > * refresh is needed, or INT64_MAX if none. */ > static int64_t > sync_evpn_mb_for_router_port( > struct ovsdb_idl_txn *ovnsb_idl_txn, > struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, > + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, > const struct sbrec_mac_binding_table *mb_table, > + const struct sbrec_shared_mac_binding_table *shared_mb_table, > const struct sbrec_port_binding *router_pb, > const struct evpn_arp *arp, > struct mac_cache_data *mac_cache_data, > @@ -104,42 +123,73 @@ sync_evpn_mb_for_router_port( > { > char *ip_s = normalize_v46(&arp->ip); > struct evpn_mb_synced_entry *existing = > - evpn_mb_synced_find(&data->synced_entries, > - router_pb->logical_port, ip_s); > - > - const struct sbrec_mac_binding *sb_mb = existing > - ? sbrec_mac_binding_table_get_for_uuid(mb_table, > &existing->mb_uuid) > - : NULL; > - > - /* Insert or update the SB MAC_Binding row. */ > - const struct sbrec_mac_binding *b = > - mac_binding_add_to_sb(ovnsb_idl_txn, > - sbrec_mac_binding_by_lport_ip, > - router_pb->logical_port, > - router_pb->datapath, > - arp->mac, ip_s, false, > - sb_mb); > - > - if (!existing) { > - existing = evpn_mb_synced_add(&data->synced_entries, > - router_pb->logical_port, ip_s); > + evpn_mb_synced_find(&data->synced_entries, router_pb, ip_s); > + > + /* Multiple router ports can connect the same scope to this provider > + * datapath. The first one processed owns the shared update for this > + * iteration. */ > + if (existing && !existing->stale) { > + free(ip_s); > + return INT64_MAX; > + } > + > + const struct sbrec_shared_mac_binding *shared_binding = NULL; > + const struct sbrec_mac_binding *private_binding = NULL; > + long long timestamp; > + if (router_pb->mac_binding_scope) { > + const struct sbrec_shared_mac_binding *sb_mb = existing > + ? sbrec_shared_mac_binding_table_get_for_uuid( > + shared_mb_table, &existing->mb_uuid) > + : NULL; > + shared_binding = shared_mac_binding_add_to_sb( > + ovnsb_idl_txn, shared_mac_binding_by_scope_ip, > + router_pb->mac_binding_scope, arp->mac, ip_s, false, > + sb_mb); > + timestamp = shared_binding->timestamp; > + if (!existing) { > + existing = evpn_mb_synced_add(&data->synced_entries, > + router_pb, ip_s); > + } > + existing->mb_uuid = shared_binding->header_.uuid; > + } else { > + const struct sbrec_mac_binding *sb_mb = existing > + ? sbrec_mac_binding_table_get_for_uuid( > + mb_table, &existing->mb_uuid) > + : NULL; > + > + private_binding = mac_binding_add_to_sb( > + ovnsb_idl_txn, sbrec_mac_binding_by_lport_ip, > + router_pb->logical_port, router_pb->datapath, > + arp->mac, ip_s, false, sb_mb); > + timestamp = private_binding->timestamp; > + if (!existing) { > + existing = evpn_mb_synced_add(&data->synced_entries, > + router_pb, ip_s); > + } > + existing->mb_uuid = private_binding->header_.uuid; > } > > free(ip_s); > - existing->mb_uuid = b->header_.uuid; > existing->stale = false; > > /* Refresh timestamp to prevent aging. */ > - struct mac_cache_threshold *threshold = > - mac_cache_threshold_find(mac_cache_data, > - router_pb->datapath->tunnel_key); > + struct mac_cache_threshold *threshold = router_pb->mac_binding_scope > + ? mac_cache_threshold_find_scope( > + mac_cache_data, router_pb->mac_binding_scope->binding_key) > + : mac_cache_threshold_find( > + mac_cache_data, router_pb->datapath->tunnel_key); > if (!threshold) { > return INT64_MAX; > } > > - uint64_t since_updated = timewall_now - b->timestamp; > + uint64_t since_updated = timewall_now - timestamp; > if (since_updated >= threshold->cooldown_period) { > - sbrec_mac_binding_set_timestamp(b, timewall_now); > + if (shared_binding) { > + sbrec_shared_mac_binding_set_timestamp(shared_binding, > + timewall_now); > + } else { > + sbrec_mac_binding_set_timestamp(private_binding, > timewall_now); > + } > return threshold->cooldown_period; > } > > @@ -150,7 +200,9 @@ void > evpn_mac_binding_sync_run( > struct ovsdb_idl_txn *ovnsb_idl_txn, > struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, > + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, > const struct sbrec_mac_binding_table *mb_table, > + const struct sbrec_shared_mac_binding_table *shared_mb_table, > const struct hmap *local_datapaths, > const struct hmap *evpn_arps, > struct mac_cache_data *mac_cache_data, > @@ -191,7 +243,9 @@ evpn_mac_binding_sync_run( > int64_t remaining = > sync_evpn_mb_for_router_port(ovnsb_idl_txn, > > sbrec_mac_binding_by_lport_ip, > + > shared_mac_binding_by_scope_ip, > mb_table, > + shared_mb_table, > remote_pb, arp, > mac_cache_data, data, > timewall_now); > @@ -207,11 +261,20 @@ evpn_mac_binding_sync_run( > continue; > } > > - const struct sbrec_mac_binding *sb_mb = > - sbrec_mac_binding_table_get_for_uuid( > - mb_table, &synced_entry->mb_uuid); > - if (sb_mb) { > - sbrec_mac_binding_delete(sb_mb); > + if (synced_entry->shared) { > + const struct sbrec_shared_mac_binding *sb_mb = > + sbrec_shared_mac_binding_table_get_for_uuid( > + shared_mb_table, &synced_entry->mb_uuid); > + if (sb_mb) { > + sbrec_shared_mac_binding_delete(sb_mb); > + } > + } else { > + const struct sbrec_mac_binding *sb_mb = > + sbrec_mac_binding_table_get_for_uuid( > + mb_table, &synced_entry->mb_uuid); > + if (sb_mb) { > + sbrec_mac_binding_delete(sb_mb); > + } > } > > evpn_mb_synced_remove(&data->synced_entries, synced_entry); > diff --git a/controller/evpn-mac-binding-sync.h > b/controller/evpn-mac-binding-sync.h > index 249059d0e..0c70335c0 100644 > --- a/controller/evpn-mac-binding-sync.h > +++ b/controller/evpn-mac-binding-sync.h > @@ -24,22 +24,24 @@ struct mac_cache_data; > struct ovsdb_idl_index; > struct ovsdb_idl_txn; > struct sbrec_mac_binding_table; > +struct sbrec_shared_mac_binding_table; > > -/* Tracks a MAC_Binding row that was written to SB by the EVPN sync. */ > +/* Tracks a MAC_Binding or Shared_MAC_Binding row written by EVPN sync. */ > struct evpn_mb_synced_entry { > struct hmap_node hmap_node; > - char *logical_port; /* Router port name. */ > + char *logical_port; /* Router port name, if private. > */ > + struct uuid scope_uuid; /* Scope UUID, if shared. */ > + bool shared; > char *ip; /* Normalized IP string. */ > - struct uuid mb_uuid; /* UUID of the SB MAC_Binding > row. > - * All-zeros when not yet > synced. */ > + struct uuid mb_uuid; /* UUID of the SB binding row. */ > bool stale; /* Marked true at start of sync, > * cleared when still desired. */ > }; > > /* Persistent state for the en_evpn_mac_binding_sync engine node. */ > struct ed_type_evpn_mac_binding_sync { > - /* Contains 'struct evpn_mb_synced_entry'. Tracks which > - * (logical_port, ip) pairs we have written to SB. */ > + /* Contains 'struct evpn_mb_synced_entry'. Tracks private > + * (logical_port, ip) and shared (scope, ip) pairs written to SB. */ > struct hmap synced_entries; > > /* Contains LSP UUIDs belonging to synced entries peers. */ > @@ -59,7 +61,9 @@ struct evpn_mb_sync_waker { > void evpn_mac_binding_sync_run( > struct ovsdb_idl_txn *ovnsb_idl_txn, > struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, > + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, > const struct sbrec_mac_binding_table *mb_table, > + const struct sbrec_shared_mac_binding_table *shared_mb_table, > const struct hmap *local_datapaths, > const struct hmap *evpn_arps, > struct mac_cache_data *mac_cache_data, > diff --git a/controller/garp_rarp.c b/controller/garp_rarp.c > index 9de8345c7..9f54fc907 100644 > --- a/controller/garp_rarp.c > +++ b/controller/garp_rarp.c > @@ -355,17 +355,28 @@ send_garp_locally(const struct garp_rarp_ctx_in > *r_ctx_in, > continue; > } > > - bool update_only = !smap_get_bool(&remote->datapath->external_ids, > - "always_learn_from_arp_request", > - true); > + bool always_learn = remote->mac_binding_scope > + ? smap_get_bool(&remote->mac_binding_scope->options, > + "always_learn_from_arp_request", true) > + : smap_get_bool(&remote->datapath->external_ids, > + "always_learn_from_arp_request", true); > + bool update_only = !always_learn; > > struct ds ip_s = DS_EMPTY_INITIALIZER; > > ip_format_masked(ip, OVS_BE32_MAX, &ip_s); > - mac_binding_add_to_sb(r_ctx_in->ovnsb_idl_txn, > - r_ctx_in->sbrec_mac_binding_by_lport_ip, > - remote->logical_port, remote->datapath, > - ea, ds_cstr(&ip_s), update_only, NULL); > + if (remote->mac_binding_scope) { > + shared_mac_binding_add_to_sb( > + r_ctx_in->ovnsb_idl_txn, > + r_ctx_in->shared_mac_binding_by_scope_ip, > + remote->mac_binding_scope, ea, ds_cstr(&ip_s), > + update_only, NULL); > + } else { > + mac_binding_add_to_sb(r_ctx_in->ovnsb_idl_txn, > + r_ctx_in->sbrec_mac_binding_by_lport_ip, > + remote->logical_port, remote->datapath, > + ea, ds_cstr(&ip_s), update_only, NULL); > + } > ds_destroy(&ip_s); > } > } > @@ -458,9 +469,16 @@ garp_rarp_is_enabled(struct ovsdb_idl_index > *sbrec_port_binding_by_name, > /* Check if GARP probing is disabled on the peer logical router. */ > const struct sbrec_port_binding *peer = lport_get_peer( > pb, sbrec_port_binding_by_name); > - if (peer && smap_get_bool(&peer->datapath->external_ids, > + if (peer) { > + if (peer->mac_binding_scope) { > + if (smap_get_bool(&peer->mac_binding_scope->options, > "disable_garp_rarp", false)) { > - return false; > + return false; > + } > + } else if (smap_get_bool(&peer->datapath->external_ids, > + "disable_garp_rarp", false)) { > + return false; > + } > } > > return true; > diff --git a/controller/garp_rarp.h b/controller/garp_rarp.h > index f52262b99..2a21045b6 100644 > --- a/controller/garp_rarp.h > +++ b/controller/garp_rarp.h > @@ -54,6 +54,7 @@ struct garp_rarp_ctx_in { > struct ovsdb_idl_index *sbrec_port_binding_by_datapath; > struct ovsdb_idl_index *sbrec_port_binding_by_name; > struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip; > + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip; > const struct sbrec_chassis *chassis; > const struct hmap *local_datapaths; > const struct sset *active_tunnels; > diff --git a/controller/lflow.c b/controller/lflow.c > index 74848365f..a28d31836 100644 > --- a/controller/lflow.c > +++ b/controller/lflow.c > @@ -1406,6 +1406,83 @@ add_neighbor_flows(struct ovsdb_idl_index > *sbrec_port_binding_by_name, > } > } > > +static bool > +mac_binding_scope_is_local( > + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope, > + const struct sbrec_mac_binding_scope *scope, > + const struct hmap *local_datapaths, > + const struct sbrec_chassis *chassis) > +{ > + if (!chassis) { > + return false; > + } > + > + struct sbrec_port_binding *target = sbrec_port_binding_index_init_row( > + sbrec_port_binding_by_mac_binding_scope); > + sbrec_port_binding_index_set_mac_binding_scope(target, scope); > + > + const struct sbrec_port_binding *pb; > + bool is_local = false; > + SBREC_PORT_BINDING_FOR_EACH_EQUAL ( > + pb, target, sbrec_port_binding_by_mac_binding_scope) { > + if (pb->datapath && get_local_datapath( > + local_datapaths, pb->datapath->tunnel_key)) { > + is_local = true; > + break; > + } > + } > + sbrec_port_binding_index_destroy_row(target); > + return is_local; > +} > + > +static void > +consider_shared_neighbor_flow__( > + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope, > + const struct sbrec_shared_mac_binding *mb, > + const struct hmap *local_datapaths, > + const struct sbrec_chassis *chassis, > + struct ovn_desired_flow_table *flow_table) > +{ > + if (mac_binding_scope_is_local( > + sbrec_port_binding_by_mac_binding_scope, mb->scope, > + local_datapaths, chassis)) { > + consider_shared_neighbor_flow(mb, flow_table, true); > + } > +} > + > +static void > +add_shared_neighbor_flows_for_scope( > + struct ovsdb_idl_index *shared_mb_by_scope, > + const struct sbrec_mac_binding_scope *scope, > + struct ovn_desired_flow_table *flow_table) > +{ > + struct sbrec_shared_mac_binding *target = > + sbrec_shared_mac_binding_index_init_row(shared_mb_by_scope); > + sbrec_shared_mac_binding_index_set_scope(target, scope); > + const struct sbrec_shared_mac_binding *mb; > + SBREC_SHARED_MAC_BINDING_FOR_EACH_EQUAL (mb, target, > shared_mb_by_scope) { > + consider_shared_neighbor_flow(mb, flow_table, true); > + } > + sbrec_shared_mac_binding_index_destroy_row(target); > +} > + > +static void > +add_shared_neighbor_flows( > + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope, > + const struct sbrec_shared_mac_binding_table *shared_mac_binding_table, > + const struct hmap *local_datapaths, > + const struct sbrec_chassis *chassis, > + struct ovn_desired_flow_table *flow_table) > +{ > + const struct sbrec_shared_mac_binding *mb; > + SBREC_SHARED_MAC_BINDING_TABLE_FOR_EACH (mb, > + shared_mac_binding_table) { > + consider_shared_neighbor_flow__( > + sbrec_port_binding_by_mac_binding_scope, mb, > + local_datapaths, chassis, flow_table); > + } > +} > + > /* Builds the "learn()" action to be triggered by packets initiating a > * hairpin session. > * > @@ -1957,6 +2034,31 @@ lflow_handle_changed_static_mac_bindings( > } > } > > +void > +lflow_handle_changed_shared_mac_bindings( > + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope, > + const struct sbrec_shared_mac_binding_table *shared_mac_binding_table, > + const struct hmap *local_datapaths, > + const struct sbrec_chassis *chassis, > + struct ovn_desired_flow_table *flow_table) > +{ > + const struct sbrec_shared_mac_binding *mb; > + SBREC_SHARED_MAC_BINDING_TABLE_FOR_EACH_TRACKED ( > + mb, shared_mac_binding_table) { > + if (sbrec_shared_mac_binding_is_deleted(mb)) { > + ofctrl_remove_flows(flow_table, &mb->header_.uuid); > + continue; > + } > + > + if (!sbrec_shared_mac_binding_is_new(mb)) { > + ofctrl_remove_flows(flow_table, &mb->header_.uuid); > + } > + consider_shared_neighbor_flow__( > + sbrec_port_binding_by_mac_binding_scope, mb, > + local_datapaths, chassis, flow_table); > + } > +} > + > static void > consider_fdb_flows(const struct sbrec_fdb *fdb, > const struct hmap *local_datapaths, > @@ -2046,6 +2148,11 @@ lflow_run(struct lflow_ctx_in *l_ctx_in, struct > lflow_ctx_out *l_ctx_out) > l_ctx_in->static_mac_binding_table, > l_ctx_in->local_datapaths, > l_ctx_out->flow_table); > + add_shared_neighbor_flows( > + l_ctx_in->sbrec_port_binding_by_mac_binding_scope, > + l_ctx_in->shared_mac_binding_table, > + l_ctx_in->local_datapaths, l_ctx_in->chassis, > + l_ctx_out->flow_table); > add_lb_hairpin_flows(l_ctx_in->local_lbs, > l_ctx_in->local_datapaths, > l_ctx_out->flow_table); > @@ -2163,6 +2270,30 @@ lflow_add_flows_for_datapath(const struct > sbrec_datapath_binding *dp, > } > sbrec_mac_binding_index_destroy_row(mb_index_row); > > + /* Shared rows may already be monitored when this datapath becomes > local. > + * Install its scopes' bindings even if no shared row has changed. */ > + struct ovsdb_idl_index *pb_by_dp = > + l_ctx_in->sbrec_port_binding_by_datapath; > + struct ovsdb_idl_index *mb_by_scope = > + l_ctx_in->sbrec_shared_mac_binding_by_scope; > + struct sbrec_port_binding *pb_index_row = > + sbrec_port_binding_index_init_row(pb_by_dp); > + sbrec_port_binding_index_set_datapath(pb_index_row, dp); > + struct uuidset scopes = UUIDSET_INITIALIZER(&scopes); > + const struct sbrec_port_binding *pb; > + SBREC_PORT_BINDING_FOR_EACH_EQUAL (pb, pb_index_row, pb_by_dp) { > + const struct sbrec_mac_binding_scope *scope = > pb->mac_binding_scope; > + if (!scope || uuidset_find(&scopes, &scope->header_.uuid)) { > + continue; > + } > + uuidset_insert(&scopes, &scope->header_.uuid); > + > + add_shared_neighbor_flows_for_scope(mb_by_scope, scope, > + l_ctx_out->flow_table); > + } > + uuidset_destroy(&scopes); > + sbrec_port_binding_index_destroy_row(pb_index_row); > + > struct sbrec_static_mac_binding *smb_index_row = > sbrec_static_mac_binding_index_init_row( > l_ctx_in->sbrec_static_mac_binding_by_datapath); > @@ -2239,6 +2370,10 @@ lflow_handle_changed_port_bindings(struct > lflow_ctx_in *l_ctx_in, > const struct sbrec_port_binding *pb; > SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (pb, > > l_ctx_in->port_binding_table) { > + if (sbrec_port_binding_is_updated( > + pb, SBREC_PORT_BINDING_COL_MAC_BINDING_SCOPE)) { > + return false; > + } > if (!sbrec_port_binding_is_new(pb) > && !sbrec_port_binding_is_deleted(pb)) { > continue; > diff --git a/controller/lflow.h b/controller/lflow.h > index c20dedec7..bb12cf544 100644 > --- a/controller/lflow.h > +++ b/controller/lflow.h > @@ -126,6 +126,9 @@ struct lflow_ctx_in { > struct ovsdb_idl_index *sbrec_fdb_by_dp_key; > struct ovsdb_idl_index *sbrec_mac_binding_by_datapath; > struct ovsdb_idl_index *sbrec_static_mac_binding_by_datapath; > + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope; > + struct ovsdb_idl_index *sbrec_port_binding_by_datapath; > + struct ovsdb_idl_index *sbrec_shared_mac_binding_by_scope; > const struct sbrec_port_binding_table *port_binding_table; > const struct sbrec_datapath_binding_table *dp_binding_table; > const struct sbrec_mac_binding_table *mac_binding_table; > @@ -135,6 +138,7 @@ struct lflow_ctx_in { > const struct sbrec_fdb_table *fdb_table; > const struct sbrec_chassis *chassis; > const struct sbrec_static_mac_binding_table *static_mac_binding_table; > + const struct sbrec_shared_mac_binding_table *shared_mac_binding_table; > const struct hmap *local_datapaths; > const struct shash *addr_sets; > const struct shash *port_groups; > @@ -194,6 +198,12 @@ void lflow_handle_changed_static_mac_bindings( > const struct sbrec_static_mac_binding_table *smb_table, > const struct hmap *local_datapaths, > struct ovn_desired_flow_table *); > +void lflow_handle_changed_shared_mac_bindings( > + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope, > + const struct sbrec_shared_mac_binding_table *, > + const struct hmap *local_datapaths, > + const struct sbrec_chassis *, > + struct ovn_desired_flow_table *); > bool lflow_handle_changed_lbs(struct lflow_ctx_in *l_ctx_in, > struct lflow_ctx_out *l_ctx_out, > const struct uuidset *deleted_lbs, > diff --git a/controller/mac-cache.c b/controller/mac-cache.c > index b25115f19..d9dc94eca 100644 > --- a/controller/mac-cache.c > +++ b/controller/mac-cache.c > @@ -54,11 +54,17 @@ static inline bool > fdb_data_equals(const struct fdb_data *a, const struct fdb_data *b); > static uint64_t > mac_cache_threshold_get_value_ms(const struct sbrec_datapath_binding *dp); > +static uint64_t mac_cache_scope_threshold_get_value_ms( > + const struct sbrec_mac_binding_scope *); > static void > mac_cache_threshold_remove(struct hmap *thresholds, > struct mac_cache_threshold *threshold); > static void > mac_cache_update_req_delay(struct hmap *thresholds, uint64_t *req_delay); > +static struct mac_cache_threshold *mac_cache_threshold_find__( > + struct mac_cache_data *, uint32_t, bool); > +static void mac_cache_threshold_add__(struct mac_cache_data *, uint32_t, > + uint64_t, bool); > > static struct buffered_packets * > buffered_packets_find(struct cmap *bp_map, > @@ -73,26 +79,49 @@ buffered_packets_db_lookup(struct buffered_packets *bp, > struct ovsdb_idl_index *sbrec_pb_by_key, > struct ovsdb_idl_index *sbrec_dp_by_key, > struct ovsdb_idl_index *sbrec_pb_by_name, > - struct ovsdb_idl_index *sbrec_mb_by_lport_ip); > + struct ovsdb_idl_index *sbrec_mb_by_lport_ip, > + struct ovsdb_idl_index *shared_mb_by_scope_ip); > + > +static const struct sbrec_port_binding * > +buffered_packets_get_pb(const struct buffered_packets *bp, > + struct ovsdb_idl_index *sbrec_pb_by_key, > + struct ovsdb_idl_index *sbrec_dp_by_key, > + struct ovsdb_idl_index *sbrec_pb_by_name); > > /* Thresholds. */ > void > mac_cache_threshold_add(struct mac_cache_data *data, > const struct sbrec_datapath_binding *dp) > +{ > + mac_cache_threshold_add__(data, dp->tunnel_key, > + mac_cache_threshold_get_value_ms(dp), > false); > +} > + > +void > +mac_cache_threshold_add_scope(struct mac_cache_data *data, > + const struct sbrec_mac_binding_scope *scope) > +{ > + mac_cache_threshold_add__(data, scope->binding_key, > + > mac_cache_scope_threshold_get_value_ms(scope), > + true); > +} > + > +static void > +mac_cache_threshold_add__(struct mac_cache_data *data, uint32_t key, > + uint64_t value, bool is_scope) > { > struct mac_cache_threshold *threshold = > - mac_cache_threshold_find(data, dp->tunnel_key); > + mac_cache_threshold_find__(data, key, is_scope); > if (threshold) { > return; > } > - > - uint64_t value = mac_cache_threshold_get_value_ms(dp); > if (!value) { > return; > } > > threshold = xmalloc(sizeof *threshold); > - threshold->dp_key = dp->tunnel_key; > + threshold->dp_key = key; > + threshold->is_scope = is_scope; > threshold->value = value; > threshold->dump_period = (3 * value) / 16; > threshold->cooldown_period = (3 * value) / 16; > @@ -110,7 +139,8 @@ mac_cache_threshold_add(struct mac_cache_data *data, > ovs_assert(2 * (threshold->cooldown_period + threshold->dump_period) > < (9 * value) / 10); > > - hmap_insert(&data->thresholds, &threshold->hmap_node, dp->tunnel_key); > + hmap_insert(&data->thresholds, &threshold->hmap_node, > + hash_2words(key, is_scope)); > } > > void > @@ -134,10 +164,26 @@ mac_cache_threshold_replace(struct mac_cache_data > *data, > > struct mac_cache_threshold * > mac_cache_threshold_find(struct mac_cache_data *data, uint32_t dp_key) > +{ > + return mac_cache_threshold_find__(data, dp_key, false); > +} > + > +struct mac_cache_threshold * > +mac_cache_threshold_find_scope(struct mac_cache_data *data, > + uint32_t binding_key) > +{ > + return mac_cache_threshold_find__(data, binding_key, true); > +} > + > +static struct mac_cache_threshold * > +mac_cache_threshold_find__(struct mac_cache_data *data, uint32_t key, > + bool is_scope) > { > struct mac_cache_threshold *threshold; > - HMAP_FOR_EACH_WITH_HASH (threshold, hmap_node, dp_key, > &data->thresholds) { > - if (threshold->dp_key == dp_key) { > + HMAP_FOR_EACH_WITH_HASH (threshold, hmap_node, > + hash_2words(key, is_scope), > + &data->thresholds) { > + if (threshold->dp_key == key && threshold->is_scope == is_scope) { > return threshold; > } > } > @@ -151,7 +197,8 @@ mac_cache_thresholds_sync(struct mac_cache_data *data, > { > struct mac_cache_threshold *threshold; > HMAP_FOR_EACH_SAFE (threshold, hmap_node, &data->thresholds) { > - if (!get_local_datapath(local_datapaths, threshold->dp_key)) { > + if (!threshold->is_scope && > + !get_local_datapath(local_datapaths, threshold->dp_key)) { > mac_cache_threshold_remove(&data->thresholds, threshold); > } > } > @@ -179,6 +226,26 @@ mac_binding_add(struct hmap *map, struct > mac_binding_data mb_data, > > mb->data = mb_data; > mb->sbrec = smb; > + mb->shared_sbrec = NULL; > + mb->timestamp = timestamp; > + mb->arp_attempts = 0; > + mac_binding_update_log("Added", &mb_data, false, NULL, 0, 0); > +} > + > +void > +mac_binding_add_shared(struct hmap *map, struct mac_binding_data mb_data, > + const struct sbrec_shared_mac_binding *smb, > + long long timestamp) > +{ > + struct mac_binding *mb = mac_binding_find(map, &mb_data); > + if (!mb) { > + mb = xmalloc(sizeof *mb); > + hmap_insert(map, &mb->hmap_node, mac_binding_data_hash(&mb_data)); > + } > + > + mb->data = mb_data; > + mb->sbrec = NULL; > + mb->shared_sbrec = smb; > mb->timestamp = timestamp; > mb->arp_attempts = 0; > mac_binding_update_log("Added", &mb_data, false, NULL, 0, 0); > @@ -242,6 +309,21 @@ mac_binding_data_from_sbrec(struct mac_binding_data > *data, > return true; > } > > +bool > +mac_binding_data_from_shared_sbrec( > + struct mac_binding_data *data, > + const struct sbrec_shared_mac_binding *mb) > +{ > + if (!mac_binding_data_parse(data, mb->scope->binding_key, 0, > + mb->ip, mb->mac)) { > + return false; > + } > + > + data->cookie = mb->header_.uuid.parts[0]; > + data->is_scope = true; > + return true; > +} > + > void > mac_bindings_clear(struct hmap *map) > { > @@ -261,10 +343,12 @@ mac_binding_data_to_string(const struct > mac_binding_data *data, > return; > } > ds_put_format(out_data, "cookie: 0x%08"PRIx64", " > + "namespace: %s, " > "datapath-key: %"PRIu32", " > "port-key: %"PRIu32", " > "ip: %s, mac: " ETH_ADDR_FMT, > - data->cookie, data->dp_key, data->port_key, > + data->cookie, data->is_scope ? "scope" : "datapath", > + data->dp_key, data->port_key, > ip, ETH_ADDR_ARGS(data->mac)); > } > > @@ -362,6 +446,8 @@ mac_binding_stats_process_flow_stats(struct vector > *stats_vec, > * mac_binding_data_from_sbrec. */ > .port_key = 0, > .dp_key = ntohll(ofp_stats->match.flow.metadata), > + .is_scope = > + ofp_stats->match.flow.regs[MFF_LOG_INPORT - MFF_REG0] == > 0, > .mac = ofp_stats->match.flow.dl_src > }, > }; > @@ -419,16 +505,20 @@ mac_binding_stats_run(struct vector *stats_vec, > uint64_t *req_delay, > continue; > } > > - struct mac_cache_threshold *threshold = > - mac_cache_threshold_find(cache_data, mb->data.dp_key); > - if (timewall_now < mb->sbrec->timestamp) { > + int64_t timestamp = mb->data.is_scope > + ? mb->shared_sbrec->timestamp > + : mb->sbrec->timestamp; > + struct mac_cache_threshold *threshold = mb->data.is_scope > + ? mac_cache_threshold_find_scope(cache_data, mb->data.dp_key) > + : mac_cache_threshold_find(cache_data, mb->data.dp_key); > + if (timewall_now < timestamp) { > mac_binding_update_log("Not updating with future timestamp", > &mb->data, true, threshold, > stats->idle_age_ms, 0); > continue; > } > > - uint64_t since_updated_ms = timewall_now - mb->sbrec->timestamp; > + uint64_t since_updated_ms = timewall_now - timestamp; > > /* If "idle_age" is under threshold it means that the mac binding > is > * used on this chassis. */ > @@ -437,7 +527,9 @@ mac_binding_stats_run(struct vector *stats_vec, > uint64_t *req_delay, > mac_binding_update_log("Queuing timestamp update for > active", > &mb->data, true, threshold, > stats->idle_age_ms, > since_updated_ms); > - uuidset_insert(pending, &mb->sbrec->header_.uuid); > + uuidset_insert(pending, mb->data.is_scope > + ? &mb->shared_sbrec->header_.uuid > + : &mb->sbrec->header_.uuid); > } else { > /* Postponing the update to avoid sending database > transactions > * too frequently. */ > @@ -473,6 +565,11 @@ mac_binding_stats_drain(struct ovsdb_idl_txn *txn, > struct uuidset *pending, > > const struct sbrec_mac_binding *mb = > sbrec_mac_binding_get_for_uuid(idl, &node->uuid); > + const struct sbrec_shared_mac_binding *shared_mb = > + sbrec_shared_mac_binding_get_for_uuid(idl, &node->uuid); > + if (shared_mb) { > + sbrec_shared_mac_binding_set_timestamp(shared_mb, > timewall_now); > + } > if (mb) { > sbrec_mac_binding_set_timestamp(mb, timewall_now); > > @@ -690,7 +787,8 @@ buffered_packets_lookup_run(struct cmap *bp_map, const > struct hmap *recent_mbs, > struct ovsdb_idl_index *sbrec_pb_by_key, > struct ovsdb_idl_index *sbrec_dp_by_key, > struct ovsdb_idl_index *sbrec_pb_by_name, > - struct ovsdb_idl_index *sbrec_mb_by_lport_ip) > { > + struct ovsdb_idl_index *sbrec_mb_by_lport_ip, > + struct ovsdb_idl_index > *shared_mb_by_scope_ip) { > struct ds ip = DS_EMPTY_INITIALIZER; > long long now = time_msec(); > bool updated = false; > @@ -707,14 +805,24 @@ buffered_packets_lookup_run(struct cmap *bp_map, > const struct hmap *recent_mbs, > > struct eth_addr mac = eth_addr_zero; > > - struct mac_binding *mb = mac_binding_find(recent_mbs, > &bp->mb_data); > + struct mac_binding_data lookup_data = bp->mb_data; > + const struct sbrec_port_binding *pb = buffered_packets_get_pb( > + bp, sbrec_pb_by_key, sbrec_dp_by_key, sbrec_pb_by_name); > + if (pb && pb->mac_binding_scope) { > + lookup_data.dp_key = pb->mac_binding_scope->binding_key; > + lookup_data.port_key = 0; > + lookup_data.is_scope = true; > + } > + > + struct mac_binding *mb = mac_binding_find(recent_mbs, > &lookup_data); > if (mb) { > mac = mb->data.mac; > } else if (now >= bp->lookup_at_ms) { > /* Check if we can do a full lookup. */ > buffered_packets_db_lookup(bp, &ip, &mac, sbrec_pb_by_key, > sbrec_dp_by_key, sbrec_pb_by_name, > - sbrec_mb_by_lport_ip); > + sbrec_mb_by_lport_ip, > + shared_mb_by_scope_ip); > /* Schedule next lookup even if we found the MAC address, > * if the address was found this struct will be deleted > anyway. */ > > @@ -794,6 +902,7 @@ mac_binding_data_hash(const struct mac_binding_data > *mb_data) > > hash = hash_add(hash, mb_data->port_key); > hash = hash_add(hash, mb_data->dp_key); > + hash = hash_add(hash, mb_data->is_scope); > hash = hash_add_in6_addr(hash, &mb_data->ip); > > return hash_finish(hash, 24); > @@ -806,6 +915,7 @@ mac_binding_data_equals(const struct mac_binding_data > *a, > return a->cookie == b->cookie && > a->port_key == b->port_key && > a->dp_key == b->dp_key && > + a->is_scope == b->is_scope && > ipv6_addr_equals(&a->ip, &b->ip); > } > > @@ -845,6 +955,41 @@ mac_cache_threshold_get_value_ms(const struct > sbrec_datapath_binding *dp) > return mb_value ? mb_value * 1000 : fdb_value * 1000; > } > > +static uint64_t > +mac_cache_scope_threshold_get_value_ms( > + const struct sbrec_mac_binding_scope *scope) > +{ > + const char *config = smap_get(&scope->options, > + "mac_binding_age_threshold"); > + if (!config) { > + return 0; > + } > + > + uint64_t min_value = UINT64_MAX; > + char *thresholds = xstrdup(config); > + char *save_ptr = NULL; > + for (char *entry = strtok_r(thresholds, ";", &save_ptr); entry; > + entry = strtok_r(NULL, ";", &save_ptr)) { > + const char *value_str = strrchr(entry, ':'); > + value_str = value_str ? value_str + 1 : entry; > + > + unsigned int value; > + if (!str_to_uint(value_str, 10, &value)) { > + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); > + VLOG_WARN_RL(&rl, "Invalid MAC binding aging threshold '%s' " > + "for scope '%s'", entry, scope->name); > + free(thresholds); > + return 0; > + } > + if (value) { > + min_value = MIN(min_value, value); > + } > + } > + free(thresholds); > + > + return min_value == UINT64_MAX ? 0 : min_value * 1000; > +} > + > static void > mac_cache_threshold_remove(struct hmap *thresholds, > struct mac_cache_threshold *threshold) > @@ -898,34 +1043,56 @@ buffered_packets_db_lookup(struct buffered_packets > *bp, struct ds *ip, > struct ovsdb_idl_index *sbrec_pb_by_key, > struct ovsdb_idl_index *sbrec_dp_by_key, > struct ovsdb_idl_index *sbrec_pb_by_name, > - struct ovsdb_idl_index *sbrec_mb_by_lport_ip) { > - const struct sbrec_port_binding *pb = > - lport_lookup_by_key(sbrec_dp_by_key, sbrec_pb_by_key, > - bp->mb_data.dp_key, bp->mb_data.port_key); > + struct ovsdb_idl_index *sbrec_mb_by_lport_ip, > + struct ovsdb_idl_index *shared_mb_by_scope_ip) > { > + const struct sbrec_port_binding *pb = buffered_packets_get_pb( > + bp, sbrec_pb_by_key, sbrec_dp_by_key, sbrec_pb_by_name); > if (!pb) { > return; > } > > - if (!strcmp(pb->type, "chassisredirect")) { > - const char *dgp_name = > - smap_get_def(&pb->options, "distributed-port", ""); > - pb = lport_lookup_by_name(sbrec_pb_by_name, dgp_name); > - if (!pb) { > - return; > + ipv6_format_mapped(&bp->mb_data.ip, ip); > + if (pb->mac_binding_scope) { > + const struct sbrec_shared_mac_binding *smb = > + shared_mac_binding_lookup(shared_mb_by_scope_ip, > + pb->mac_binding_scope, > + ds_cstr_ro(ip)); > + ds_clear(ip); > + if (smb) { > + eth_addr_from_string(smb->mac, mac); > } > + return; > } > > - ipv6_format_mapped(&bp->mb_data.ip, ip); > const struct sbrec_mac_binding *smb = > - mac_binding_lookup(sbrec_mb_by_lport_ip, pb->logical_port, > - ds_cstr_ro(ip)); > + mac_binding_lookup(sbrec_mb_by_lport_ip, pb->logical_port, > + ds_cstr_ro(ip)); > ds_clear(ip); > > - if (!smb) { > - return; > + if (smb) { > + eth_addr_from_string(smb->mac, mac); > + } > +} > + > +static const struct sbrec_port_binding * > +buffered_packets_get_pb(const struct buffered_packets *bp, > + struct ovsdb_idl_index *sbrec_pb_by_key, > + struct ovsdb_idl_index *sbrec_dp_by_key, > + struct ovsdb_idl_index *sbrec_pb_by_name) > +{ > + const struct sbrec_port_binding *pb = > + lport_lookup_by_key(sbrec_dp_by_key, sbrec_pb_by_key, > + bp->mb_data.dp_key, bp->mb_data.port_key); > + if (!pb) { > + return NULL; > } > > - eth_addr_from_string(smb->mac, mac); > + if (!strcmp(pb->type, "chassisredirect")) { > + const char *dgp_name = > + smap_get_def(&pb->options, "distributed-port", ""); > + pb = lport_lookup_by_name(sbrec_pb_by_name, dgp_name); > + } > + return pb; > } > > void > @@ -947,6 +1114,7 @@ mac_binding_probe_stats_process_flow_stats( > * mac_binding_data_from_sbrec. */ > .port_key = 0, > .dp_key = ntohll(ofp_stats->match.flow.metadata), > + .is_scope = false, > .mac = ofp_stats->match.flow.dl_src > }, > }; > @@ -962,6 +1130,101 @@ mac_binding_probe_stats_process_flow_stats( > vector_push(stats_vec, &stats); > } > > +void > +shared_mac_binding_probe_stats_process_flow_stats( > + struct vector *stats_vec, > + struct ofputil_flow_stats *ofp_stats) > +{ > + size_t old_size = vector_len(stats_vec); > + > + mac_binding_probe_stats_process_flow_stats(stats_vec, ofp_stats); > + if (vector_len(stats_vec) > old_size) { > + struct mac_cache_stats *stats = vector_get_ptr(stats_vec, > old_size); > + stats->data.mb.is_scope = true; > + } > +} > + > +static bool > +mac_binding_probe_get_local_address(const struct sbrec_port_binding *pb, > + const struct in6_addr *target, > + struct lport_addresses *laddr, > + struct in6_addr *local) > +{ > + if (!pb->datapath || !pb->n_mac || > + !extract_lsp_addresses(pb->mac[0], laddr)) { > + return false; > + } > + > + *local = in6addr_any; > + if (IN6_IS_ADDR_V4MAPPED(target)) { > + ovs_be32 ip4 = in6_addr_get_mapped_ipv4(target); > + for (size_t i = 0; i < laddr->n_ipv4_addrs; i++) { > + struct ipv4_netaddr address = laddr->ipv4_addrs[i]; > + if (address.network == (ip4 & address.mask)) { > + *local = in6_addr_mapped_ipv4(address.addr); > + break; > + } > + } > + } else { > + for (size_t i = 0; i < laddr->n_ipv6_addrs; i++) { > + struct ipv6_netaddr address = laddr->ipv6_addrs[i]; > + struct in6_addr neigh_prefix = > + ipv6_addr_bitand(target, &address.mask); > + if (ipv6_addr_equals(&address.network, &neigh_prefix)) { > + *local = address.addr; > + break; > + } > + } > + } > + > + if (ipv6_addr_equals(local, &in6addr_any)) { > + destroy_lport_addresses(laddr); > + return false; > + } > + return true; > +} > + > +static const struct sbrec_port_binding * > +mac_binding_probe_get_port(const struct mac_binding *mb, > + const struct mac_binding_probe_data > *probe_data, > + struct lport_addresses *laddr, > + struct in6_addr *local) > +{ > + if (!mb->data.is_scope) { > + const struct sbrec_port_binding *pb = lport_lookup_by_name( > + probe_data->sbrec_port_binding_by_name, > + mb->sbrec->logical_port); > + if (!pb || !lport_pb_is_local( > + probe_data->sbrec_port_binding_by_name, > + probe_data->chassis, pb)) { > + return NULL; > + } > + return mac_binding_probe_get_local_address( > + pb, &mb->data.ip, laddr, local) ? pb : NULL; > + } > + > + struct sbrec_port_binding *target = sbrec_port_binding_index_init_row( > + probe_data->sbrec_port_binding_by_mac_binding_scope); > + sbrec_port_binding_index_set_mac_binding_scope( > + target, mb->shared_sbrec->scope); > + > + const struct sbrec_port_binding *pb; > + const struct sbrec_port_binding *found = NULL; > + SBREC_PORT_BINDING_FOR_EACH_EQUAL ( > + pb, target, probe_data->sbrec_port_binding_by_mac_binding_scope) { > + if (strcmp(pb->type, "chassisredirect") && > + lport_pb_is_local(probe_data->sbrec_port_binding_by_name, > + probe_data->chassis, pb) && > + mac_binding_probe_get_local_address( > + pb, &mb->data.ip, laddr, local)) { > + found = pb; > + break; > + } > + } > + sbrec_port_binding_index_destroy_row(target); > + return found; > +} > + > void > mac_binding_probe_stats_run(struct vector *stats_vec, uint64_t *req_delay, > void *data, struct uuidset *pending > OVS_UNUSED, > @@ -980,9 +1243,13 @@ mac_binding_probe_stats_run(struct vector > *stats_vec, uint64_t *req_delay, > continue; > } > > - struct mac_cache_threshold *threshold = > - mac_cache_threshold_find(cache_data, mb->data.dp_key); > - if (timewall_now < mb->sbrec->timestamp) { > + struct mac_cache_threshold *threshold = mb->data.is_scope > + ? mac_cache_threshold_find_scope(cache_data, mb->data.dp_key) > + : mac_cache_threshold_find(cache_data, mb->data.dp_key); > + int64_t timestamp = mb->data.is_scope > + ? mb->shared_sbrec->timestamp > + : mb->sbrec->timestamp; > + if (timewall_now < timestamp) { > mac_binding_update_log("Not sending ARP/ND request with > future " > "timestamp", &mb->data, true, > threshold, > stats->idle_age_ms, 0); > @@ -990,8 +1257,7 @@ mac_binding_probe_stats_run(struct vector *stats_vec, > uint64_t *req_delay, > continue; > } > > - uint64_t since_updated_ms = timewall_now - mb->sbrec->timestamp; > - const struct sbrec_mac_binding *sbrec = mb->sbrec; > + uint64_t since_updated_ms = timewall_now - timestamp; > > if (stats->idle_age_ms > threshold->value) { > mac_binding_update_log("Not sending ARP/ND request for > non-active", > @@ -1002,7 +1268,9 @@ mac_binding_probe_stats_run(struct vector > *stats_vec, uint64_t *req_delay, > > if (since_updated_ms < threshold->cooldown_period || > uuidset_contains(probe_data->mac_binding_pending, > - &sbrec->header_.uuid)) { > + mb->data.is_scope > + ? &mb->shared_sbrec->header_.uuid > + : &mb->sbrec->header_.uuid)) { > mac_binding_update_log( > "Not sending ARP/ND request for recently/to be > updated", > &mb->data, true, threshold, stats->idle_age_ms, > @@ -1011,66 +1279,33 @@ mac_binding_probe_stats_run(struct vector > *stats_vec, uint64_t *req_delay, > continue; > } > > - const struct sbrec_port_binding *pb = > - lport_lookup_by_name(probe_data->sbrec_port_binding_by_name, > - sbrec->logical_port); > + struct lport_addresses laddr; > + struct in6_addr local; > + const struct sbrec_port_binding *pb = mac_binding_probe_get_port( > + mb, probe_data, &laddr, &local); > if (!pb) { > - continue; > - } > - > - if (!lport_pb_is_local(probe_data->sbrec_port_binding_by_name, > - probe_data->chassis, pb)) { > mac_binding_update_log("Not sending ARP/ND request for > non-local", > &mb->data, true, threshold, > stats->idle_age_ms, since_updated_ms); > continue; > } > > - struct lport_addresses laddr; > - if (!extract_lsp_addresses(pb->mac[0], &laddr)) { > - continue; > - } > + struct eth_addr eth_dst = > + mb->arp_attempts < PROBE_MULICAST_THRESHOLD > + ? mb->data.mac > + : eth_addr_zero; > > - struct in6_addr local = in6addr_any; > - if (IN6_IS_ADDR_V4MAPPED(&mb->data.ip)) { > - ovs_be32 ip4 = in6_addr_get_mapped_ipv4(&mb->data.ip); > - for (size_t i = 0; i < laddr.n_ipv4_addrs; i++) { > - struct ipv4_netaddr address = laddr.ipv4_addrs[i]; > - if (address.network == (ip4 & address.mask)) { > - local = in6_addr_mapped_ipv4(address.addr); > - break; > - } > - } > - } else { > - for (size_t i = 0; i < laddr.n_ipv6_addrs; i++) { > - struct ipv6_netaddr address = laddr.ipv6_addrs[i]; > - struct in6_addr neigh_prefix = > - ipv6_addr_bitand(&mb->data.ip, &address.mask); > - if (ipv6_addr_equals(&address.network, &neigh_prefix)) { > - local = address.addr; > - break; > - } > - } > - } > - > - if (!ipv6_addr_equals(&local, &in6addr_any)) { > - struct eth_addr eth_dst = > - mb->arp_attempts < PROBE_MULICAST_THRESHOLD > - ? mb->data.mac > - : eth_addr_zero; > - > - mac_binding_update_log("Sending ARP/ND request for active", > - &mb->data, true, threshold, > - stats->idle_age_ms, since_updated_ms); > + mac_binding_update_log("Sending ARP/ND request for active", > + &mb->data, true, threshold, > + stats->idle_age_ms, since_updated_ms); > > - send_self_originated_neigh_packet(probe_data->swconn, > - sbrec->datapath->tunnel_key, > - pb->tunnel_key, laddr.ea, > - eth_dst, &local, > - &mb->data.ip, > - OFTABLE_LOCAL_OUTPUT); > - mb->arp_attempts++; > - } > + send_self_originated_neigh_packet(probe_data->swconn, > + pb->datapath->tunnel_key, > + pb->tunnel_key, laddr.ea, > + eth_dst, &local, > + &mb->data.ip, > + OFTABLE_LOCAL_OUTPUT); > + mb->arp_attempts++; > > destroy_lport_addresses(&laddr); > } > diff --git a/controller/mac-cache.h b/controller/mac-cache.h > index f27998e40..9eeb847d1 100644 > --- a/controller/mac-cache.h > +++ b/controller/mac-cache.h > @@ -44,8 +44,9 @@ struct mac_cache_data { > > struct mac_cache_threshold { > struct hmap_node hmap_node; > - /* Datapath tunnel key. */ > + /* Datapath tunnel key or scope binding key. */ > uint32_t dp_key; > + bool is_scope; > /* Aging threshold in ms. */ > uint64_t value; > /* Statistics dump period. */ > @@ -59,6 +60,7 @@ struct mac_binding_data { > uint64_t cookie; > uint32_t port_key; > uint32_t dp_key; > + bool is_scope; > struct in6_addr ip; > /* Value. */ > struct eth_addr mac; > @@ -69,6 +71,7 @@ struct mac_binding_probe_data { > struct uuidset *mac_binding_pending; > struct rconn *swconn; > struct ovsdb_idl_index *sbrec_port_binding_by_name; > + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope; > const struct sbrec_chassis *chassis; > }; > > @@ -78,6 +81,7 @@ struct mac_binding { > struct mac_binding_data data; > /* Reference to the SB MAC binding record (Might be NULL). */ > const struct sbrec_mac_binding *sbrec; > + const struct sbrec_shared_mac_binding *shared_sbrec; > /* User specified timestamp (in ms) */ > long long timestamp; > /* Number of re-ARP attempts for given entry. */ > @@ -148,6 +152,10 @@ void mac_cache_threshold_replace(struct > mac_cache_data *data, > const struct hmap *local_datapaths); > struct mac_cache_threshold * > mac_cache_threshold_find(struct mac_cache_data *data, uint32_t dp_key); > +void mac_cache_threshold_add_scope( > + struct mac_cache_data *, const struct sbrec_mac_binding_scope *); > +struct mac_cache_threshold *mac_cache_threshold_find_scope( > + struct mac_cache_data *, uint32_t binding_key); > void mac_cache_thresholds_sync(struct mac_cache_data *data, > const struct hmap *local_datapaths); > void mac_cache_thresholds_clear(struct mac_cache_data *data); > @@ -163,6 +171,7 @@ mac_binding_data_init(struct mac_binding_data *data, > .cookie = 0, > .dp_key = (dp_key), > .port_key = (port_key), > + .is_scope = false, > .ip = (ip), > .mac = (mac), > }; > @@ -170,6 +179,9 @@ mac_binding_data_init(struct mac_binding_data *data, > > void mac_binding_add(struct hmap *map, struct mac_binding_data mb_data, > const struct sbrec_mac_binding *, long long > timestamp); > +void mac_binding_add_shared( > + struct hmap *, struct mac_binding_data, > + const struct sbrec_shared_mac_binding *, long long timestamp); > > void mac_binding_remove(struct hmap *map, struct mac_binding *mb); > > @@ -181,6 +193,8 @@ bool mac_binding_data_parse(struct mac_binding_data > *data, > const char *ip_str, const char *mac_str); > bool mac_binding_data_from_sbrec(struct mac_binding_data *data, > const struct sbrec_mac_binding *mb); > +bool mac_binding_data_from_shared_sbrec( > + struct mac_binding_data *, const struct sbrec_shared_mac_binding *); > > void mac_bindings_clear(struct hmap *map); > void mac_bindings_to_string(const struct hmap *map, struct ds *out_data); > @@ -234,7 +248,9 @@ bool buffered_packets_lookup_run(struct cmap *bp_map, > struct ovsdb_idl_index *sbrec_pb_by_key, > struct ovsdb_idl_index *sbrec_dp_by_key, > struct ovsdb_idl_index *sbrec_pb_by_name, > - struct ovsdb_idl_index > *sbrec_mb_by_lport_ip); > + struct ovsdb_idl_index > *sbrec_mb_by_lport_ip, > + struct ovsdb_idl_index > + *shared_mb_by_scope_ip); > > void buffered_packets_run(struct cmap *bp_map, struct vector *rpd); > > @@ -243,6 +259,9 @@ void buffered_packets_map_destroy(struct cmap *bp_map); > void mac_binding_probe_stats_process_flow_stats( > struct vector *stats_vec, > struct ofputil_flow_stats *ofp_stats); > +void shared_mac_binding_probe_stats_process_flow_stats( > + struct vector *stats_vec, > + struct ofputil_flow_stats *ofp_stats); > > void mac_binding_probe_stats_run(struct vector *stats_vec, uint64_t > *req_delay, > void *data, struct uuidset *pending, > diff --git a/controller/neighbor-of.c b/controller/neighbor-of.c > index d48fe4422..b79038ca0 100644 > --- a/controller/neighbor-of.c > +++ b/controller/neighbor-of.c > @@ -18,25 +18,28 @@ > #include "lflow.h" > #include "neighbor-of.h" > #include "openvswitch/match.h" > +#include "openvswitch/vlog.h" > #include "ovn/logical-fields.h" > > -void > -consider_neighbor_flow(const struct sbrec_port_binding *pb, > - const struct uuid *neighbor_uuid, > - const struct in6_addr *ip, struct eth_addr mac, > - struct ovn_desired_flow_table *flow_table, > - enum neigh_of_rule_prio priority, > - bool needs_usage_tracking) > +VLOG_DEFINE_THIS_MODULE(neighbor_of); > + > +static void > +consider_neighbor_flow__(uint32_t dp_key, uint32_t port_key, > + const struct uuid *neighbor_uuid, > + const struct in6_addr *ip, struct eth_addr mac, > + struct ovn_desired_flow_table *flow_table, > + uint8_t binding_table, uint8_t lookup_table, > + enum neigh_of_rule_prio priority, > + bool needs_usage_tracking, bool > clear_on_mismatch) > { > struct match get_arp_match = MATCH_CATCHALL_INITIALIZER; > struct match lookup_arp_match = MATCH_CATCHALL_INITIALIZER; > struct match mb_cache_use_match = MATCH_CATCHALL_INITIALIZER; > struct match lookup_arp_for_stats_match = MATCH_CATCHALL_INITIALIZER; > > - match_set_dl_src(&lookup_arp_match, mac); > - match_set_metadata(&lookup_arp_match, > htonll(pb->datapath->tunnel_key)); > + match_set_metadata(&lookup_arp_match, htonll(dp_key)); > match_set_reg(&lookup_arp_match, MFF_LOG_INPORT - MFF_REG0, > - pb->tunnel_key); > + port_key); > > if (IN6_IS_ADDR_V4MAPPED(ip)) { > ovs_be32 ip_addr = in6_addr_get_mapped_ipv4(ip); > @@ -44,6 +47,7 @@ consider_neighbor_flow(const struct sbrec_port_binding > *pb, > > match_set_dl_type(&lookup_arp_match, htons(ETH_TYPE_ARP)); > lookup_arp_for_stats_match = lookup_arp_match; > + match_set_dl_src(&lookup_arp_for_stats_match, mac); > > match_set_reg(&lookup_arp_match, 0, ntohl(ip_addr)); > > @@ -67,31 +71,42 @@ consider_neighbor_flow(const struct sbrec_port_binding > *pb, > match_set_ipv6_src(&mb_cache_use_match, ip); > } > > - match_set_metadata(&get_arp_match, htonll(pb->datapath->tunnel_key)); > - match_set_reg(&get_arp_match, MFF_LOG_OUTPORT - MFF_REG0, > pb->tunnel_key); > + struct match lookup_ip_match = lookup_arp_match; > + match_set_dl_src(&lookup_arp_match, mac); > + > + match_set_metadata(&get_arp_match, htonll(dp_key)); > + match_set_reg(&get_arp_match, MFF_LOG_OUTPORT - MFF_REG0, port_key); > > match_set_dl_src(&mb_cache_use_match, mac); > match_set_reg(&mb_cache_use_match, MFF_LOG_INPORT - MFF_REG0, > - pb->tunnel_key); > - match_set_metadata(&mb_cache_use_match, > htonll(pb->datapath->tunnel_key)); > + port_key); > + match_set_metadata(&mb_cache_use_match, htonll(dp_key)); > > uint64_t stub[1024 / 8]; > struct ofpbuf ofpacts = OFPBUF_STUB_INITIALIZER(stub); > put_load_bytes(mac.ea, sizeof mac.ea, MFF_ETH_DST, 0, 48, > &ofpacts); > put_load(1, MFF_LOG_FLAGS, MLF_LOOKUP_MAC_BIT, 1, &ofpacts); > - ofctrl_add_flow(flow_table, OFTABLE_MAC_BINDING, priority, > + ofctrl_add_flow(flow_table, binding_table, priority, > neighbor_uuid->parts[0], > &get_arp_match, &ofpacts, > neighbor_uuid); > > ofpbuf_clear(&ofpacts); > put_load(1, MFF_LOG_FLAGS, MLF_LOOKUP_MAC_BIT, 1, &ofpacts); > - ofctrl_add_flow(flow_table, OFTABLE_MAC_LOOKUP, priority, > + ofctrl_add_flow(flow_table, lookup_table, priority, > neighbor_uuid->parts[0], > &lookup_arp_match, &ofpacts, > neighbor_uuid); > > + if (clear_on_mismatch) { > + ofpbuf_clear(&ofpacts); > + put_load(0, MFF_LOG_FLAGS, MLF_LOOKUP_MAC_BIT, 1, &ofpacts); > + ofctrl_add_flow(flow_table, lookup_table, priority - 1, > + neighbor_uuid->parts[0], &lookup_ip_match, > + &ofpacts, neighbor_uuid); > + } > + > if (needs_usage_tracking) { > ofpbuf_clear(&ofpacts); > if (IN6_IS_ADDR_V4MAPPED(ip)) { > @@ -107,3 +122,54 @@ consider_neighbor_flow(const struct > sbrec_port_binding *pb, > > ofpbuf_uninit(&ofpacts); > } > + > +void > +consider_neighbor_flow(const struct sbrec_port_binding *pb, > + const struct uuid *neighbor_uuid, > + const struct in6_addr *ip, struct eth_addr mac, > + struct ovn_desired_flow_table *flow_table, > + enum neigh_of_rule_prio priority, > + bool needs_usage_tracking) > +{ > + consider_neighbor_flow__(pb->datapath->tunnel_key, pb->tunnel_key, > + neighbor_uuid, ip, mac, flow_table, > + OFTABLE_MAC_BINDING, OFTABLE_MAC_LOOKUP, > + priority, needs_usage_tracking, false); > + > + if (priority == NEIGH_OF_STATIC_MAC_BINDING_HIGH_PRIO && > + pb->mac_binding_scope) { > + consider_neighbor_flow__(pb->datapath->tunnel_key, pb->tunnel_key, > + neighbor_uuid, ip, mac, flow_table, > + OFTABLE_MAC_BINDING_OVERRIDE, > + OFTABLE_MAC_LOOKUP_OVERRIDE, > + NEIGH_OF_DYNAMIC_MAC_BINDING_PRIO, > + false, true); > + } > +} > + > +void > +consider_shared_neighbor_flow(const struct sbrec_shared_mac_binding *mb, > + struct ovn_desired_flow_table *flow_table, > + bool needs_usage_tracking) > +{ > + struct eth_addr mac; > + struct in6_addr ip; > + > + if (!eth_addr_from_string(mb->mac, &mac)) { > + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); > + VLOG_WARN_RL(&rl, "bad 'mac' %s", mb->mac); > + return; > + } > + if (!ip46_parse(mb->ip, &ip)) { > + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); > + VLOG_WARN_RL(&rl, "bad 'ip' %s", mb->ip); > + return; > + } > + > + consider_neighbor_flow__(mb->scope->binding_key, 0, > + &mb->header_.uuid, &ip, mac, flow_table, > + OFTABLE_SHARED_MAC_BINDING, > + OFTABLE_SHARED_MAC_LOOKUP, > + NEIGH_OF_DYNAMIC_MAC_BINDING_PRIO, > + needs_usage_tracking, true); > +} > diff --git a/controller/neighbor-of.h b/controller/neighbor-of.h > index d91074a1e..c45168721 100644 > --- a/controller/neighbor-of.h > +++ b/controller/neighbor-of.h > @@ -44,4 +44,8 @@ consider_neighbor_flow(const struct sbrec_port_binding *, > enum neigh_of_rule_prio priority, > bool needs_usage_tracking); > > +void consider_shared_neighbor_flow( > + const struct sbrec_shared_mac_binding *, > + struct ovn_desired_flow_table *, bool needs_usage_tracking); > + > #endif /* NEIGHBOR_OF_H */ > diff --git a/controller/ovn-controller.8.xml > b/controller/ovn-controller.8.xml > index 2b90f25d9..78b6d5a9e 100644 > --- a/controller/ovn-controller.8.xml > +++ b/controller/ovn-controller.8.xml > @@ -894,6 +894,24 @@ > db="OVN_Southbound"/>, and <ref table="Learned_Route" > column="nexthop" > db="OVN_Southbound"/> columns. > </dd> > + > + <dt><ref table="Shared_MAC_Binding" db="OVN_Southbound"/></dt> > + <dd> > + <code>ovn-controller</code> creates and updates rows when > + <code>put_arp</code> and <code>put_nd</code> logical actions > learn on > + a port in a MAC binding scope, and when locally simulating > gratuitous > + ARP for scoped ports. It also creates, updates, and removes rows > + while synchronizing EVPN neighbors. It writes the > + <ref table="Shared_MAC_Binding" column="scope" > db="OVN_Southbound"/>, > + <ref table="Shared_MAC_Binding" column="ip" db="OVN_Southbound"/>, > + <ref table="Shared_MAC_Binding" column="mac" > db="OVN_Southbound"/>, and > + <ref table="Shared_MAC_Binding" column="timestamp" > + db="OVN_Southbound"/> columns. For scopes with aging enabled, it > + refreshes timestamps for active bindings and synchronized EVPN > + neighbors. Learned bindings can outlive the controller; > + <code>ovn-northd</code> ages them and removes bindings when their > + scope is withdrawn. > + </dd> > </dl> > > <h1>Runtime Management Commands</h1> > diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c > index 5343753ca..3c371cc6f 100644 > --- a/controller/ovn-controller.c > +++ b/controller/ovn-controller.c > @@ -262,6 +262,8 @@ update_sb_monitors(struct ovsdb_idl *ovnsb_idl, > struct ovsdb_idl_condition lf = OVSDB_IDL_CONDITION_INIT(&lf); > struct ovsdb_idl_condition ldpg = OVSDB_IDL_CONDITION_INIT(&ldpg); > struct ovsdb_idl_condition mb = OVSDB_IDL_CONDITION_INIT(&mb); > + struct ovsdb_idl_condition shared_mb = > + OVSDB_IDL_CONDITION_INIT(&shared_mb); > struct ovsdb_idl_condition fdb = OVSDB_IDL_CONDITION_INIT(&fdb); > struct ovsdb_idl_condition mg = OVSDB_IDL_CONDITION_INIT(&mg); > struct ovsdb_idl_condition dns = OVSDB_IDL_CONDITION_INIT(&dns); > @@ -298,6 +300,7 @@ update_sb_monitors(struct ovsdb_idl *ovnsb_idl, > ovsdb_idl_condition_add_clause_true(&pb); > ovsdb_idl_condition_add_clause_true(&lf); > ovsdb_idl_condition_add_clause_true(&mb); > + ovsdb_idl_condition_add_clause_true(&shared_mb); > ovsdb_idl_condition_add_clause_true(&fdb); > ovsdb_idl_condition_add_clause_true(&mg); > ovsdb_idl_condition_add_clause_true(&dns); > @@ -429,6 +432,23 @@ update_sb_monitors(struct ovsdb_idl *ovnsb_idl, > * request all of them. > */ > sbrec_logical_flow_add_clause_logical_dp_group(&lf, OVSDB_F_NE, > NULL); > + > + struct uuidset local_scopes = UUIDSET_INITIALIZER(&local_scopes); > + const struct sbrec_port_binding *pb_row; > + SBREC_PORT_BINDING_FOR_EACH (pb_row, ovnsb_idl) { > + if (pb_row->datapath && pb_row->mac_binding_scope && > + get_local_datapath(local_datapaths, > + pb_row->datapath->tunnel_key)) { > + uuidset_insert(&local_scopes, > + &pb_row->mac_binding_scope->header_.uuid); > + } > + } > + const struct uuidset_node *scope_node; > + UUIDSET_FOR_EACH (scope_node, &local_scopes) { > + sbrec_shared_mac_binding_add_clause_scope( > + &shared_mb, OVSDB_F_EQ, &scope_node->uuid); > + } > + uuidset_destroy(&local_scopes); > } > > out:; > @@ -437,6 +457,7 @@ out:; > sbrec_logical_flow_set_condition(ovnsb_idl, &lf), > sbrec_logical_dp_group_set_condition(ovnsb_idl, &ldpg), > sbrec_mac_binding_set_condition(ovnsb_idl, &mb), > + sbrec_shared_mac_binding_set_condition(ovnsb_idl, &shared_mb), > sbrec_fdb_set_condition(ovnsb_idl, &fdb), > sbrec_multicast_group_set_condition(ovnsb_idl, &mg), > sbrec_dns_set_condition(ovnsb_idl, &dns), > @@ -460,6 +481,7 @@ out:; > ovsdb_idl_condition_destroy(&lf); > ovsdb_idl_condition_destroy(&ldpg); > ovsdb_idl_condition_destroy(&mb); > + ovsdb_idl_condition_destroy(&shared_mb); > ovsdb_idl_condition_destroy(&fdb); > ovsdb_idl_condition_destroy(&mg); > ovsdb_idl_condition_destroy(&dns); > @@ -3273,6 +3295,81 @@ mac_binding_remove_sb(struct mac_cache_data *data, > mac_binding_remove(&data->mac_bindings, mb); > } > > +static void > +shared_mac_binding_add_sb( > + struct mac_cache_data *data, > + const struct sbrec_shared_mac_binding *smb) > +{ > + struct mac_binding_data mb_data; > + if (!mac_binding_data_from_shared_sbrec(&mb_data, smb)) { > + return; > + } > + > + mac_binding_add_shared(&data->mac_bindings, mb_data, smb, 0); > +} > + > +static void > +shared_mac_binding_remove_sb( > + struct mac_cache_data *data, > + const struct sbrec_shared_mac_binding *smb) > +{ > + struct mac_binding_data mb_data; > + if (!mac_binding_data_from_shared_sbrec(&mb_data, smb)) { > + return; > + } > + > + struct mac_binding *mb = mac_binding_find(&data->mac_bindings, > &mb_data); > + if (mb) { > + mac_binding_remove(&data->mac_bindings, mb); > + } > +} > + > +static bool > +mac_cache_scope_is_local(struct ovsdb_idl_index *pb_by_scope, > + const struct sbrec_mac_binding_scope *scope, > + const struct hmap *local_datapaths) > +{ > + struct sbrec_port_binding *target = > + sbrec_port_binding_index_init_row(pb_by_scope); > + sbrec_port_binding_index_set_mac_binding_scope(target, scope); > + > + const struct sbrec_port_binding *pb; > + bool is_local = false; > + SBREC_PORT_BINDING_FOR_EACH_EQUAL (pb, target, pb_by_scope) { > + if (pb->datapath && get_local_datapath( > + local_datapaths, pb->datapath->tunnel_key)) { > + is_local = true; > + break; > + } > + } > + sbrec_port_binding_index_destroy_row(target); > + return is_local; > +} > + > +static void > +mac_cache_mb_handle_for_scope( > + struct mac_cache_data *data, > + const struct sbrec_mac_binding_scope *scope, > + struct ovsdb_idl_index *shared_mb_by_scope) > +{ > + bool has_threshold = > + !!mac_cache_threshold_find_scope(data, scope->binding_key); > + struct sbrec_shared_mac_binding *target = > + sbrec_shared_mac_binding_index_init_row(shared_mb_by_scope); > + sbrec_shared_mac_binding_index_set_scope(target, scope); > + > + const struct sbrec_shared_mac_binding *mb; > + SBREC_SHARED_MAC_BINDING_FOR_EACH_EQUAL ( > + mb, target, shared_mb_by_scope) { > + if (has_threshold) { > + shared_mac_binding_add_sb(data, mb); > + } else { > + shared_mac_binding_remove_sb(data, mb); > + } > + } > + sbrec_shared_mac_binding_index_destroy_row(target); > +} > + > static void > fdb_add_sb(struct mac_cache_data *data, const struct sbrec_fdb *sfdb) > { > @@ -3377,6 +3474,13 @@ en_mac_cache_run(struct engine_node *node, void > *data) > engine_ovsdb_node_get_index( > engine_get_input("SB_fdb", node), > "dp_key"); > + const struct sbrec_mac_binding_scope_table *scope_table = > + EN_OVSDB_GET(engine_get_input("SB_mac_binding_scope", node)); > + struct ovsdb_idl_index *pb_by_scope = engine_ovsdb_node_get_index( > + engine_get_input("SB_port_binding", node), "mac_binding_scope"); > + struct ovsdb_idl_index *shared_mb_by_scope = > + engine_ovsdb_node_get_index( > + engine_get_input("SB_shared_mac_binding", node), "scope"); > > mac_cache_thresholds_clear(cache_data); > mac_bindings_clear(&cache_data->mac_bindings); > @@ -3396,9 +3500,73 @@ en_mac_cache_run(struct engine_node *node, void > *data) > sbrec_fdb_by_dp_key); > } > > + const struct sbrec_mac_binding_scope *scope; > + SBREC_MAC_BINDING_SCOPE_TABLE_FOR_EACH (scope, scope_table) { > + if (!mac_cache_scope_is_local(pb_by_scope, scope, > + &rt_data->local_datapaths)) { > + continue; > + } > + mac_cache_threshold_add_scope(cache_data, scope); > + mac_cache_mb_handle_for_scope(cache_data, scope, > + shared_mb_by_scope); > + } > + > return EN_UPDATED; > } > > +static enum engine_input_handler_result > +mac_cache_sb_shared_mac_binding_handler(struct engine_node *node, void > *data) > +{ > + struct mac_cache_data *cache_data = data; > + const struct sbrec_shared_mac_binding_table *mb_table = > + EN_OVSDB_GET(engine_get_input("SB_shared_mac_binding", node)); > + size_t previous_size = hmap_count(&cache_data->mac_bindings); > + > + const struct sbrec_shared_mac_binding *mb; > + SBREC_SHARED_MAC_BINDING_TABLE_FOR_EACH_TRACKED (mb, mb_table) { > + if (!sbrec_shared_mac_binding_is_new(mb) && > + (sbrec_shared_mac_binding_is_updated( > + mb, SBREC_SHARED_MAC_BINDING_COL_SCOPE) || > + sbrec_shared_mac_binding_is_updated( > + mb, SBREC_SHARED_MAC_BINDING_COL_IP))) { > + return EN_UNHANDLED; > + } > + if (!sbrec_shared_mac_binding_is_new(mb)) { > + shared_mac_binding_remove_sb(cache_data, mb); > + } > + if (!sbrec_shared_mac_binding_is_deleted(mb) && > + mac_cache_threshold_find_scope(cache_data, > + mb->scope->binding_key)) { > + shared_mac_binding_add_sb(cache_data, mb); > + } > + } > + > + return hmap_count(&cache_data->mac_bindings) != previous_size > + ? EN_HANDLED_UPDATED : EN_HANDLED_UNCHANGED; > +} > + > +static enum engine_input_handler_result > +mac_cache_sb_port_binding_handler(struct engine_node *node, > + void *data OVS_UNUSED) > +{ > + const struct sbrec_port_binding_table *pb_table = > + EN_OVSDB_GET(engine_get_input("SB_port_binding", node)); > + const struct sbrec_port_binding *pb; > + > + SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (pb, pb_table) { > + if (sbrec_port_binding_is_updated( > + pb, SBREC_PORT_BINDING_COL_MAC_BINDING_SCOPE) || > + (pb->mac_binding_scope && > + (sbrec_port_binding_is_updated( > + pb, SBREC_PORT_BINDING_COL_DATAPATH) || > + sbrec_port_binding_is_new(pb) || > + sbrec_port_binding_is_deleted(pb)))) { > + return EN_UNHANDLED; > + } > + } > + return EN_HANDLED_UNCHANGED; > +} > + > static enum engine_input_handler_result > mac_cache_sb_mac_binding_handler(struct engine_node *node, void *data) > { > @@ -3484,6 +3652,12 @@ mac_cache_runtime_data_handler(struct engine_node > *node, void *data OVS_UNUSED) > engine_ovsdb_node_get_index( > engine_get_input("SB_fdb", node), > "dp_key"); > + const struct sbrec_mac_binding_scope_table *scope_table = > + EN_OVSDB_GET(engine_get_input("SB_mac_binding_scope", node)); > + > + if (sbrec_mac_binding_scope_table_first(scope_table)) { > + return EN_UNHANDLED; > + } > > /* There are no tracked data. Fall back to full recompute. */ > if (!rt_data->tracked) { > @@ -3534,6 +3708,12 @@ mac_cache_sb_datapath_binding_handler(struct > engine_node *node, void *data) > engine_ovsdb_node_get_index( > engine_get_input("SB_fdb", node), > "dp_key"); > + const struct sbrec_mac_binding_scope_table *scope_table = > + EN_OVSDB_GET(engine_get_input("SB_mac_binding_scope", node)); > + > + if (sbrec_mac_binding_scope_table_first(scope_table)) { > + return EN_UNHANDLED; > + } > > size_t previous_mb_size = hmap_count(&cache_data->mac_bindings); > size_t previous_fdb_size = hmap_count(&cache_data->fdbs); > @@ -3970,6 +4150,11 @@ init_lflow_ctx(struct engine_node *node, > engine_get_input("SB_static_mac_binding", node), > "datapath"); > > + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope = > + engine_ovsdb_node_get_index( > + engine_get_input("SB_port_binding", node), > + "mac_binding_scope"); > + > const struct sbrec_port_binding_table *port_binding_table = > EN_OVSDB_GET(engine_get_input("SB_port_binding", node)); > > @@ -3991,6 +4176,9 @@ init_lflow_ctx(struct engine_node *node, > const struct sbrec_static_mac_binding_table *smb_table = > EN_OVSDB_GET(engine_get_input("SB_static_mac_binding", node)); > > + const struct sbrec_shared_mac_binding_table *shared_mb_table = > + EN_OVSDB_GET(engine_get_input("SB_shared_mac_binding", node)); > + > const struct ovsrec_open_vswitch_table *ovs_table = > EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node)); > > @@ -4041,6 +4229,8 @@ init_lflow_ctx(struct engine_node *node, > l_ctx_in->sbrec_mac_binding_by_datapath = > sbrec_mac_binding_by_datapath; > l_ctx_in->sbrec_static_mac_binding_by_datapath = > sbrec_static_mac_binding_by_datapath; > + l_ctx_in->sbrec_port_binding_by_mac_binding_scope = > + sbrec_port_binding_by_mac_binding_scope; > l_ctx_in->port_binding_table = port_binding_table; > l_ctx_in->mac_binding_table = mac_binding_table; > l_ctx_in->logical_flow_table = logical_flow_table; > @@ -4049,6 +4239,11 @@ init_lflow_ctx(struct engine_node *node, > l_ctx_in->fdb_table = fdb_table, > l_ctx_in->chassis = chassis; > l_ctx_in->static_mac_binding_table = smb_table; > + l_ctx_in->shared_mac_binding_table = shared_mb_table; > + l_ctx_in->sbrec_port_binding_by_datapath = > engine_ovsdb_node_get_index( > + engine_get_input("SB_port_binding", node), "datapath"); > + l_ctx_in->sbrec_shared_mac_binding_by_scope = > engine_ovsdb_node_get_index( > + engine_get_input("SB_shared_mac_binding", node), "scope"); > l_ctx_in->local_datapaths = &rt_data->local_datapaths; > l_ctx_in->addr_sets = addr_sets; > l_ctx_in->port_groups = port_groups; > @@ -4312,6 +4507,34 @@ lflow_output_sb_mac_binding_handler(struct > engine_node *node, void *data) > return EN_HANDLED_UPDATED; > } > > +static enum engine_input_handler_result > +lflow_output_sb_shared_mac_binding_handler(struct engine_node *node, > + void *data) > +{ > + struct ovsdb_idl_index *pb_by_scope = engine_ovsdb_node_get_index( > + engine_get_input("SB_port_binding", node), "mac_binding_scope"); > + const struct sbrec_shared_mac_binding_table *shared_mb_table = > + EN_OVSDB_GET(engine_get_input("SB_shared_mac_binding", node)); > + struct ed_type_runtime_data *rt_data = > + engine_get_input_data("runtime_data", node); > + struct ed_type_lflow_output *lfo = data; > + const struct ovsrec_open_vswitch_table *ovs_table = > + EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node)); > + const char *chassis_id = get_ovs_chassis_id(ovs_table); > + if (!chassis_id) { > + return EN_UNHANDLED; > + } > + struct ovsdb_idl_index *chassis_by_name = engine_ovsdb_node_get_index( > + engine_get_input("SB_chassis", node), "name"); > + const struct sbrec_chassis *chassis = > + chassis_lookup_by_name(chassis_by_name, chassis_id); > + > + lflow_handle_changed_shared_mac_bindings( > + pb_by_scope, shared_mb_table, &rt_data->local_datapaths, > + chassis, &lfo->flow_table); > + return EN_HANDLED_UPDATED; > +} > + > static enum engine_input_handler_result > lflow_output_sb_static_mac_binding_handler(struct engine_node *node, > void *data) > @@ -6083,6 +6306,10 @@ en_garp_rarp_run(struct engine_node *node, void > *data_) > engine_ovsdb_node_get_index( > engine_get_input("SB_mac_binding", node), > "lport_ip"); > + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip = > + engine_ovsdb_node_get_index( > + engine_get_input("SB_shared_mac_binding", node), > + "scope_ip"); > > struct ed_type_runtime_data *rt_data = > engine_get_input_data("runtime_data", node); > @@ -6093,6 +6320,7 @@ en_garp_rarp_run(struct engine_node *node, void > *data_) > .sbrec_port_binding_by_datapath = sbrec_port_binding_by_datapath, > .sbrec_port_binding_by_name = sbrec_port_binding_by_name, > .sbrec_mac_binding_by_lport_ip = sbrec_mac_binding_by_lport_ip, > + .shared_mac_binding_by_scope_ip = shared_mac_binding_by_scope_ip, > .chassis = chassis, > .active_tunnels = &rt_data->active_tunnels, > .local_datapaths = &rt_data->local_datapaths, > @@ -7191,6 +7419,12 @@ en_evpn_mac_binding_sync_run(struct engine_node > *node, void *data_) > engine_ovsdb_node_get_index(sb_mb_node, "lport_ip"); > const struct sbrec_mac_binding_table *mb_table = > EN_OVSDB_GET(sb_mb_node); > + struct engine_node *shared_mb_node = > + engine_get_input("SB_shared_mac_binding", node); > + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip = > + engine_ovsdb_node_get_index(shared_mb_node, "scope_ip"); > + const struct sbrec_shared_mac_binding_table *shared_mb_table = > + EN_OVSDB_GET(shared_mb_node); > > struct evpn_mb_sync_waker *waker = > engine_get_input_data("evpn_mac_binding_sync_waker", node); > @@ -7200,7 +7434,9 @@ en_evpn_mac_binding_sync_run(struct engine_node > *node, void *data_) > > evpn_mac_binding_sync_run(engine_get_context()->ovnsb_idl_txn, > sbrec_mac_binding_by_lport_ip, > + shared_mac_binding_by_scope_ip, > mb_table, > + shared_mb_table, > &rt_data->local_datapaths, > &earp_data->arps, > mac_cache_data, > @@ -7244,6 +7480,10 @@ > evpn_mac_binding_sync_sb_port_binding_handler(struct engine_node *node, > > const struct sbrec_port_binding *pb; > SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (pb, port_binding_table) { > + if (sbrec_port_binding_is_updated( > + pb, SBREC_PORT_BINDING_COL_MAC_BINDING_SCOPE)) { > + return EN_UNHANDLED; > + } > if (sbrec_port_binding_is_deleted(pb) && > uuidset_contains(&data->lsp_peers, &pb->header_.uuid)) { > return EN_UNHANDLED; > @@ -7253,23 +7493,27 @@ > evpn_mac_binding_sync_sb_port_binding_handler(struct engine_node *node, > uuidset_contains(&data->lsp_peers, &pb->header_.uuid) && > (sbrec_port_binding_is_updated(pb, > > SBREC_PORT_BINDING_COL_OPTIONS) || > - sbrec_port_binding_is_updated(pb, > SBREC_PORT_BINDING_COL_TYPE))) { > + sbrec_port_binding_is_updated(pb, > SBREC_PORT_BINDING_COL_TYPE) || > + sbrec_port_binding_is_updated(pb, > + > SBREC_PORT_BINDING_COL_CHASSIS))) { > return EN_UNHANDLED; > } > > - if (!sbrec_port_binding_is_new(pb)) { > + /* A gateway peer may not be usable until both ends are claimed. > + * Reconsider it on binding changes even if the first sync > skipped it > + * and therefore did not record it in lsp_peers. */ > + if (!sbrec_port_binding_is_new(pb) && > + !sbrec_port_binding_is_updated(pb, > + > SBREC_PORT_BINDING_COL_CHASSIS) && > + !sbrec_port_binding_is_updated(pb, > + > SBREC_PORT_BINDING_COL_OPTIONS) && > + !sbrec_port_binding_is_updated(pb, > SBREC_PORT_BINDING_COL_TYPE)) { > continue; > } > > struct local_datapath *ld = get_local_datapath( > &rt_data->local_datapaths, pb->datapath->tunnel_key); > - if (!ld || !ld->is_switch) { > - continue; > - } > - > - int64_t vni = ovn_smap_get_llong(&ld->datapath->external_ids, > - "dynamic-routing-vni", -1); > - if (!ovn_is_valid_vni(vni)) { > + if (!ld) { > continue; > } > > @@ -7287,7 +7531,14 @@ > evpn_mac_binding_sync_sb_port_binding_handler(struct engine_node *node, > struct local_datapath *peer_ld = > get_local_datapath(&rt_data->local_datapaths, > peer->datapath->tunnel_key); > - if (!peer_ld || peer_ld->is_switch) { > + if (!peer_ld || ld->is_switch == peer_ld->is_switch) { > + continue; > + } > + > + const struct local_datapath *switch_ld = ld->is_switch ? ld : > peer_ld; > + int64_t vni = > ovn_smap_get_llong(&switch_ld->datapath->external_ids, > + "dynamic-routing-vni", -1); > + if (!ovn_is_valid_vni(vni)) { > continue; > } > > @@ -7316,6 +7567,8 @@ evpn_mac_binding_sync_sb_port_binding_handler(struct > engine_node *node, > SB_NODE(logical_dp_group) \ > SB_NODE(port_binding) \ > SB_NODE(mac_binding) \ > + SB_NODE(mac_binding_scope) \ > + SB_NODE(shared_mac_binding) \ > SB_NODE(logical_flow) \ > SB_NODE(dhcp_options) \ > SB_NODE(dhcpv6_options) \ > @@ -7591,6 +7844,9 @@ inc_proc_ovn_controller_init( > > engine_add_input(&en_lflow_output, &en_sb_mac_binding, > lflow_output_sb_mac_binding_handler); > + engine_add_input(&en_lflow_output, &en_sb_shared_mac_binding, > + lflow_output_sb_shared_mac_binding_handler); > + engine_add_input(&en_lflow_output, &en_sb_mac_binding_scope, NULL); > This would cause any change to any MAC_Binding_Scope row force a recompute of lflow_output. I think that the only changes that require flow work are insert/delete where the scope is local. Should this include a change handler that filters on mac_binding_scope_is_local()? > engine_add_input(&en_lflow_output, &en_sb_static_mac_binding, > lflow_output_sb_static_mac_binding_handler); > engine_add_input(&en_lflow_output, &en_sb_logical_flow, > @@ -7653,12 +7909,15 @@ inc_proc_ovn_controller_init( > mac_cache_runtime_data_handler); > engine_add_input(&en_mac_cache, &en_sb_mac_binding, > mac_cache_sb_mac_binding_handler); > + engine_add_input(&en_mac_cache, &en_sb_shared_mac_binding, > + mac_cache_sb_shared_mac_binding_handler); > + engine_add_input(&en_mac_cache, &en_sb_mac_binding_scope, NULL); > engine_add_input(&en_mac_cache, &en_sb_fdb, > mac_cache_sb_fdb_handler); > engine_add_input(&en_mac_cache, &en_sb_datapath_binding, > mac_cache_sb_datapath_binding_handler); > engine_add_input(&en_mac_cache, &en_sb_port_binding, > - engine_noop_handler); > + mac_cache_sb_port_binding_handler); > > engine_add_input(&en_dns_cache, &en_sb_dns, > dns_cache_sb_dns_handler); > @@ -7672,6 +7931,9 @@ inc_proc_ovn_controller_init( > /* The mac_binding data is just used in an index to filter duplicates > when > * inserting data to the southbound. */ > engine_add_input(&en_garp_rarp, &en_sb_mac_binding, > engine_noop_handler); > + engine_add_input(&en_garp_rarp, &en_sb_shared_mac_binding, > + engine_noop_handler); > + engine_add_input(&en_garp_rarp, &en_sb_mac_binding_scope, NULL); > engine_add_input(&en_garp_rarp, &en_runtime_data, > garp_rarp_runtime_data_handler); > > @@ -7722,12 +7984,18 @@ inc_proc_ovn_controller_init( > /* MAC_Binding data is only used via an index for lookups. */ > engine_add_input(&en_evpn_mac_binding_sync, &en_sb_mac_binding, > engine_noop_handler); > + engine_add_input(&en_evpn_mac_binding_sync, &en_sb_shared_mac_binding, > + engine_noop_handler); > /* Runtime data is only used for local_datapaths access. */ > engine_add_input(&en_evpn_mac_binding_sync, &en_runtime_data, > engine_noop_handler); > /* MAC cache data is only used for aging threshold lookup. */ > engine_add_input(&en_evpn_mac_binding_sync, &en_mac_cache, > engine_noop_handler); > + /* Enabling scope aging must start EVPN timestamp refreshes even when > + * no refresh was scheduled under the previous policy. */ > + engine_add_input(&en_evpn_mac_binding_sync, &en_sb_mac_binding_scope, > + NULL); > engine_add_input(&en_evpn_mac_binding_sync, &en_sb_ro, > evpn_mac_binding_sync_sb_ro_handler); > engine_add_input(&en_evpn_mac_binding_sync, &en_sb_port_binding, > @@ -7793,6 +8061,13 @@ inc_proc_ovn_controller_init( > engine_ovsdb_node_add_index(&en_sb_port_binding, "key", > sbrec_port_binding_by_key); > > + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope = > + ovsdb_idl_index_create1( > + sb_idl_loop->idl, > + &sbrec_port_binding_col_mac_binding_scope); > + engine_ovsdb_node_add_index(&en_sb_port_binding, "mac_binding_scope", > + sbrec_port_binding_by_mac_binding_scope); > + > struct ovsdb_idl_index *sbrec_port_binding_by_datapath > = ovsdb_idl_index_create1(sb_idl_loop->idl, > &sbrec_port_binding_col_datapath); > @@ -7839,6 +8114,16 @@ inc_proc_ovn_controller_init( > engine_ovsdb_node_add_index(&en_sb_mac_binding, "lport_ip", > sbrec_mac_binding_by_lport_ip); > > + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip = > + shared_mac_binding_by_scope_ip_index_create(sb_idl_loop->idl); > + engine_ovsdb_node_add_index(&en_sb_shared_mac_binding, "scope_ip", > + shared_mac_binding_by_scope_ip); > + struct ovsdb_idl_index *shared_mac_binding_by_scope = > + ovsdb_idl_index_create1(sb_idl_loop->idl, > + &sbrec_shared_mac_binding_col_scope); > + engine_ovsdb_node_add_index(&en_sb_shared_mac_binding, "scope", > + shared_mac_binding_by_scope); > + > engine_ovsdb_node_add_index(&en_ovs_flow_sample_collector_set, "id", > ovsrec_flow_sample_collector_set_by_id); > engine_ovsdb_node_add_index(&en_ovs_port, "qos", ovsrec_port_by_qos); > @@ -8027,6 +8312,10 @@ main(int argc, char *argv[]) > struct ovsdb_idl_index *sbrec_port_binding_by_type > = ovsdb_idl_index_create1(ovnsb_idl_loop.idl, > &sbrec_port_binding_col_type); > + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope > + = ovsdb_idl_index_create1( > + ovnsb_idl_loop.idl, > + &sbrec_port_binding_col_mac_binding_scope); > struct ovsdb_idl_index *sbrec_port_binding_by_requested_chassis > = ovsdb_idl_index_create1(ovnsb_idl_loop.idl, > > &sbrec_port_binding_col_requested_chassis); > @@ -8035,6 +8324,8 @@ main(int argc, char *argv[]) > &sbrec_datapath_binding_col_tunnel_key); > struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip > = mac_binding_by_lport_ip_index_create(ovnsb_idl_loop.idl); > + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip > + = shared_mac_binding_by_scope_ip_index_create(ovnsb_idl_loop.idl); > struct ovsdb_idl_index *sbrec_ip_multicast > = ip_mcast_index_create(ovnsb_idl_loop.idl); > struct ovsdb_idl_index *sbrec_igmp_group > @@ -8057,6 +8348,8 @@ main(int argc, char *argv[]) > * values (it does read them to implement aging). Therefore we > * can disable change tracking and alerting for these columns. */ > ovsdb_idl_omit_alert(ovnsb_idl_loop.idl, > &sbrec_mac_binding_col_timestamp); > + ovsdb_idl_omit_alert(ovnsb_idl_loop.idl, > + &sbrec_shared_mac_binding_col_timestamp); > ovsdb_idl_omit_alert(ovnsb_idl_loop.idl, &sbrec_fdb_col_timestamp); > > /* Omit the external_ids column of all the tables except for - > @@ -8646,6 +8939,7 @@ main(int argc, char *argv[]) > sbrec_port_binding_by_key, > sbrec_port_binding_by_name, > sbrec_mac_binding_by_lport_ip, > + shared_mac_binding_by_scope_ip, > sbrec_igmp_group, > sbrec_ip_multicast, > sbrec_fdb_by_dp_key_mac, > @@ -8655,6 +8949,8 @@ main(int argc, char *argv[]) > ovnsb_idl_loop.idl), > sbrec_mac_binding_table_get( > ovnsb_idl_loop.idl), > + sbrec_shared_mac_binding_table_get( > + ovnsb_idl_loop.idl), > > sbrec_bfd_table_get(ovnsb_idl_loop.idl), > sbrec_ecmp_nexthop_table_get( > ovnsb_idl_loop.idl), > @@ -8672,10 +8968,12 @@ main(int argc, char *argv[]) > > sbrec_mirror_table_get(ovnsb_idl_loop.idl), > br_int, > &runtime_data->lbinding_data.bindings); > - /* Updating monitor conditions if runtime data or > - * logical datapath goups changed. */ > + /* Scope membership can change without changing > + * runtime data or logical datapath groups. */ > if (engine_node_changed(&en_runtime_data) > - || > engine_node_changed(&en_sb_logical_dp_group)) { > + || > engine_node_changed(&en_sb_logical_dp_group) > + || engine_node_changed(&en_sb_port_binding) > + || > engine_node_changed(&en_sb_mac_binding_scope)) { > Is this a scalability concern? update_sb_monitors() is would now run whenever en_sb_port_binding has any changes. The pipeline isn't very heavy but SB Port_Bindings are very frequent. > bool had_all_data = ovnsb_cond_seqno == > ovnsb_expected_cond_seqno; > ovnsb_expected_cond_seqno = > @@ -8728,6 +9026,7 @@ main(int argc, char *argv[]) > mac_cache_data = engine_get_data(&en_mac_cache); > if (mac_cache_data) { > statctrl_run(ovnsb_idl_txn, > sbrec_port_binding_by_name, > + > sbrec_port_binding_by_mac_binding_scope, > chassis, mac_cache_data); > } > > diff --git a/controller/pinctrl.c b/controller/pinctrl.c > index 5c9634b24..c27ad8686 100644 > --- a/controller/pinctrl.c > +++ b/controller/pinctrl.c > @@ -199,11 +199,13 @@ static void init_buffered_packets_map(void); > static void destroy_buffered_packets_map(void); > static void > run_buffered_binding(const struct sbrec_mac_binding_table > *mac_binding_table, > + const struct sbrec_shared_mac_binding_table *, > const struct hmap *local_datapaths, > struct ovsdb_idl_index *sbrec_port_binding_by_key, > struct ovsdb_idl_index > *sbrec_datapath_binding_by_key, > struct ovsdb_idl_index *sbrec_port_binding_by_name, > - struct ovsdb_idl_index > *sbrec_mac_binding_by_lport_ip); > + struct ovsdb_idl_index > *sbrec_mac_binding_by_lport_ip, > + struct ovsdb_idl_index *shared_mb_by_scope_ip); > > static void pinctrl_handle_put_mac_binding(const struct flow *md, > const struct flow *headers, > @@ -214,7 +216,9 @@ static void run_put_mac_bindings( > struct ovsdb_idl_txn *ovnsb_idl_txn, > struct ovsdb_idl_index *sbrec_datapath_binding_by_key, > struct ovsdb_idl_index *sbrec_port_binding_by_key, > - struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip); > + struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, > + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, > + struct ovsdb_idl_index *sbrec_port_binding_by_name); > static void wait_put_mac_bindings(void); > static void send_mac_binding_buffered_pkts(struct rconn *swconn); > > @@ -4207,12 +4211,14 @@ pinctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, > struct ovsdb_idl_index *sbrec_port_binding_by_key, > struct ovsdb_idl_index *sbrec_port_binding_by_name, > struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, > + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, > struct ovsdb_idl_index *sbrec_igmp_groups, > struct ovsdb_idl_index *sbrec_ip_multicast_opts, > struct ovsdb_idl_index *sbrec_fdb_by_dp_key_mac, > const struct sbrec_controller_event_table *ce_table, > const struct sbrec_service_monitor_table *svc_mon_table, > const struct sbrec_mac_binding_table *mac_binding_table, > + const struct sbrec_shared_mac_binding_table *shared_mb_table, > const struct sbrec_bfd_table *bfd_table, > const struct sbrec_ecmp_nexthop_table *ecmp_nh_table, > const struct sbrec_chassis *chassis, > @@ -4248,14 +4254,17 @@ pinctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, > sbrec_port_binding_by_key, chassis); > ovs_mutex_unlock(&pinctrl_mutex); > > - run_buffered_binding(mac_binding_table, local_datapaths, > + run_buffered_binding(mac_binding_table, shared_mb_table, > local_datapaths, > sbrec_port_binding_by_key, > sbrec_datapath_binding_by_key, > sbrec_port_binding_by_name, > - sbrec_mac_binding_by_lport_ip); > + sbrec_mac_binding_by_lport_ip, > + shared_mac_binding_by_scope_ip); > run_put_mac_bindings(ovnsb_idl_txn, sbrec_datapath_binding_by_key, > sbrec_port_binding_by_key, > - sbrec_mac_binding_by_lport_ip); > + sbrec_mac_binding_by_lport_ip, > + shared_mac_binding_by_scope_ip, > + sbrec_port_binding_by_name); > run_put_fdbs(ovnsb_idl_txn, sbrec_port_binding_by_key, > sbrec_datapath_binding_by_key, sbrec_fdb_by_dp_key_mac, > cur_cfg); > @@ -4907,6 +4916,8 @@ run_put_mac_binding(struct ovsdb_idl_txn > *ovnsb_idl_txn, > struct ovsdb_idl_index *sbrec_datapath_binding_by_key, > struct ovsdb_idl_index *sbrec_port_binding_by_key, > struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, > + struct ovsdb_idl_index *shared_mb_by_scope_ip, > + struct ovsdb_idl_index *sbrec_port_binding_by_name, > const struct mac_binding *mb) > { > /* Convert logical datapath and logical port key into lport. */ > @@ -4921,16 +4932,30 @@ run_put_mac_binding(struct ovsdb_idl_txn > *ovnsb_idl_txn, > return; > } > > - /* Convert ethernet argument to string form for database. */ > - char mac_string[ETH_ADDR_STRLEN + 1]; > - snprintf(mac_string, sizeof mac_string, > - ETH_ADDR_FMT, ETH_ADDR_ARGS(mb->data.mac)); > + const struct sbrec_port_binding *scope_pb = pb; > + if (!strcmp(scope_pb->type, "chassisredirect")) { > + const char *distributed_port = smap_get( > + &scope_pb->options, "distributed-port"); > + scope_pb = distributed_port > + ? lport_lookup_by_name(sbrec_port_binding_by_name, > + distributed_port) > + : NULL; > + } > > struct ds ip_s = DS_EMPTY_INITIALIZER; > ipv6_format_mapped(&mb->data.ip, &ip_s); > - mac_binding_add_to_sb(ovnsb_idl_txn, sbrec_mac_binding_by_lport_ip, > - pb->logical_port, pb->datapath, mb->data.mac, > - ds_cstr(&ip_s), false, NULL); > + if (scope_pb && scope_pb->mac_binding_scope) { > + shared_mac_binding_add_to_sb(ovnsb_idl_txn, > + shared_mb_by_scope_ip, > + scope_pb->mac_binding_scope, > + mb->data.mac, ds_cstr(&ip_s), > + false, NULL); > + } else { > + mac_binding_add_to_sb(ovnsb_idl_txn, > + sbrec_mac_binding_by_lport_ip, > + pb->logical_port, pb->datapath, > + mb->data.mac, ds_cstr(&ip_s), false, NULL); > + } > ds_destroy(&ip_s); > } > > @@ -4940,7 +4965,9 @@ static void > run_put_mac_bindings(struct ovsdb_idl_txn *ovnsb_idl_txn, > struct ovsdb_idl_index > *sbrec_datapath_binding_by_key, > struct ovsdb_idl_index *sbrec_port_binding_by_key, > - struct ovsdb_idl_index > *sbrec_mac_binding_by_lport_ip) > + struct ovsdb_idl_index > *sbrec_mac_binding_by_lport_ip, > + struct ovsdb_idl_index *shared_mb_by_scope_ip, > + struct ovsdb_idl_index *sbrec_port_binding_by_name) > { > long long now = time_msec(); > > @@ -4973,7 +5000,9 @@ run_put_mac_bindings(struct ovsdb_idl_txn > *ovnsb_idl_txn, > run_put_mac_binding(ovnsb_idl_txn, > sbrec_datapath_binding_by_key, > sbrec_port_binding_by_key, > - sbrec_mac_binding_by_lport_ip, mb); > + sbrec_mac_binding_by_lport_ip, > + shared_mb_by_scope_ip, > + sbrec_port_binding_by_name, mb); > mac_binding_remove(&put_mac_bindings, mb); > } > } > @@ -4981,11 +5010,13 @@ run_put_mac_bindings(struct ovsdb_idl_txn > *ovnsb_idl_txn, > > static void > run_buffered_binding(const struct sbrec_mac_binding_table > *mac_binding_table, > + const struct sbrec_shared_mac_binding_table > *shared_table, > const struct hmap *local_datapaths, > struct ovsdb_idl_index *sbrec_port_binding_by_key, > struct ovsdb_idl_index > *sbrec_datapath_binding_by_key, > struct ovsdb_idl_index *sbrec_port_binding_by_name, > - struct ovsdb_idl_index > *sbrec_mac_binding_by_lport_ip) > + struct ovsdb_idl_index > *sbrec_mac_binding_by_lport_ip, > + struct ovsdb_idl_index *shared_mb_by_scope_ip) > { > if (cmap_is_empty(&buffered_packets_map)) { > return; > @@ -5033,11 +5064,29 @@ run_buffered_binding(const struct > sbrec_mac_binding_table *mac_binding_table, > mac_binding_add(&recent_mbs, mb_data, smb, 0); > } > > + const struct sbrec_shared_mac_binding *shared_mb; > + SBREC_SHARED_MAC_BINDING_TABLE_FOR_EACH_TRACKED (shared_mb, > + shared_table) { > + if (sbrec_shared_mac_binding_is_deleted(shared_mb)) { > + continue; > + } > + > + struct mac_binding_data mb_data; > + if (!mac_binding_data_parse( > + &mb_data, shared_mb->scope->binding_key, 0, > + shared_mb->ip, shared_mb->mac)) { > + continue; > + } > + mb_data.is_scope = true; > + mac_binding_add_shared(&recent_mbs, mb_data, shared_mb, 0); > + } > + > if (buffered_packets_lookup_run(&buffered_packets_map, &recent_mbs, > sbrec_port_binding_by_key, > sbrec_datapath_binding_by_key, > sbrec_port_binding_by_name, > - sbrec_mac_binding_by_lport_ip)) { > + sbrec_mac_binding_by_lport_ip, > + shared_mb_by_scope_ip)) { > notify_pinctrl_handler(); > } > > diff --git a/controller/pinctrl.h b/controller/pinctrl.h > index a638fe29f..4b63d1241 100644 > --- a/controller/pinctrl.h > +++ b/controller/pinctrl.h > @@ -40,6 +40,7 @@ struct sbrec_bfd_table; > struct sbrec_ecmp_nexthop_table; > struct sbrec_port_binding; > struct sbrec_mac_binding_table; > +struct sbrec_shared_mac_binding_table; > > void pinctrl_init(void); > void pinctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, > @@ -47,12 +48,14 @@ void pinctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, > struct ovsdb_idl_index *sbrec_port_binding_by_key, > struct ovsdb_idl_index *sbrec_port_binding_by_name, > struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, > + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, > struct ovsdb_idl_index *sbrec_igmp_groups, > struct ovsdb_idl_index *sbrec_ip_multicast_opts, > struct ovsdb_idl_index *sbrec_fdb_by_dp_key_mac, > const struct sbrec_controller_event_table *, > const struct sbrec_service_monitor_table *, > const struct sbrec_mac_binding_table *, > + const struct sbrec_shared_mac_binding_table *, > const struct sbrec_bfd_table *, > const struct sbrec_ecmp_nexthop_table *, > const struct sbrec_chassis *chassis, > diff --git a/controller/statctrl.c b/controller/statctrl.c > index 77453319c..1362e3650 100644 > --- a/controller/statctrl.c > +++ b/controller/statctrl.c > @@ -47,6 +47,7 @@ enum stat_type { > STATS_MAC_BINDING = 0, > STATS_FDB, > STATS_MAC_BINDING_PROBE, > + STATS_SHARED_MAC_BINDING_PROBE, > STATS_MAX, > }; > > @@ -180,6 +181,19 @@ statctrl_init(void) > mac_binding_probe_stats_process_flow_stats, > mac_binding_probe_stats_run, NULL); > > + struct ofputil_flow_stats_request shared_mac_binding_probe_request = { > + .cookie = htonll(0), > + .cookie_mask = htonll(0), > + .out_port = OFPP_ANY, > + .out_group = OFPG_ANY, > + .table_id = OFTABLE_SHARED_MAC_BINDING, > + }; > + STATS_NODE(SHARED_MAC_BINDING_PROBE, > + shared_mac_binding_probe_request, > + struct mac_cache_stats, > + shared_mac_binding_probe_stats_process_flow_stats, > + mac_binding_probe_stats_run, NULL); > + > statctrl_ctx.thread = ovs_thread_create("ovn_statctrl", > statctrl_thread_handler, > &statctrl_ctx); > @@ -188,6 +202,7 @@ statctrl_init(void) > void > statctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, > struct ovsdb_idl_index *sbrec_port_binding_by_name, > + struct ovsdb_idl_index *sbrec_port_binding_by_scope, > const struct sbrec_chassis *chassis, > struct mac_cache_data *mac_cache_data) > { > @@ -199,6 +214,8 @@ statctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, > .cache_data = mac_cache_data, > .mac_binding_pending = > &statctrl_ctx.nodes[STATS_MAC_BINDING].pending, > .sbrec_port_binding_by_name = sbrec_port_binding_by_name, > + .sbrec_port_binding_by_mac_binding_scope = > + sbrec_port_binding_by_scope, > .swconn = statctrl_ctx.swconn, > .chassis = chassis, > }; > @@ -207,6 +224,7 @@ statctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, > [STATS_MAC_BINDING] = mac_cache_data, > [STATS_FDB] = mac_cache_data, > [STATS_MAC_BINDING_PROBE] = &mac_binding_probe_data, > + [STATS_SHARED_MAC_BINDING_PROBE] = &mac_binding_probe_data, > }; > > bool schedule_updated = false; > diff --git a/controller/statctrl.h b/controller/statctrl.h > index 3e56b4a54..5f927083c 100644 > --- a/controller/statctrl.h > +++ b/controller/statctrl.h > @@ -21,6 +21,7 @@ > void statctrl_init(void); > void statctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, > struct ovsdb_idl_index *sbrec_port_binding_by_name, > + struct ovsdb_idl_index *sbrec_port_binding_by_scope, > const struct sbrec_chassis *chassis, > struct mac_cache_data *mac_cache_data); > > diff --git a/lib/mac-binding-index.c b/lib/mac-binding-index.c > index 3e49b07f3..556f18b0f 100644 > --- a/lib/mac-binding-index.c > +++ b/lib/mac-binding-index.c > @@ -35,6 +35,14 @@ mac_binding_by_lport_ip_index_create(struct ovsdb_idl > *idl) > &sbrec_mac_binding_col_ip); > } > > +struct ovsdb_idl_index * > +shared_mac_binding_by_scope_ip_index_create(struct ovsdb_idl *idl) > +{ > + return ovsdb_idl_index_create2(idl, > + &sbrec_shared_mac_binding_col_scope, > + &sbrec_shared_mac_binding_col_ip); > +} > + > const struct sbrec_mac_binding * > mac_binding_lookup(struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, > const char *logical_port, const char *ip) { > @@ -101,3 +109,62 @@ mac_binding_add_to_sb(struct ovsdb_idl_txn > *ovnsb_idl_txn, > > return b; > } > + > +const struct sbrec_shared_mac_binding * > +shared_mac_binding_lookup( > + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, > + const struct sbrec_mac_binding_scope *scope, const char *ip) > +{ > + struct sbrec_shared_mac_binding *mb = > + sbrec_shared_mac_binding_index_init_row( > + shared_mac_binding_by_scope_ip); > + sbrec_shared_mac_binding_index_set_scope(mb, scope); > + sbrec_shared_mac_binding_index_set_ip(mb, ip); > + > + const struct sbrec_shared_mac_binding *retval = > + sbrec_shared_mac_binding_index_find( > + shared_mac_binding_by_scope_ip, mb); > + > + sbrec_shared_mac_binding_index_destroy_row(mb); > + return retval; > +} > + > +/* Update or add an IP-MAC binding in 'scope'. */ > +const struct sbrec_shared_mac_binding * > +shared_mac_binding_add_to_sb( > + struct ovsdb_idl_txn *ovnsb_idl_txn, > + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, > + const struct sbrec_mac_binding_scope *scope, struct eth_addr ea, > + const char *ip, bool update_only, > + const struct sbrec_shared_mac_binding *sb_mb) > +{ > + char mac_string[ETH_ADDR_STRLEN + 1]; > + snprintf(mac_string, sizeof mac_string, ETH_ADDR_FMT, > ETH_ADDR_ARGS(ea)); > + > + const struct sbrec_shared_mac_binding *b = sb_mb > + ? sb_mb > + : shared_mac_binding_lookup(shared_mac_binding_by_scope_ip, > + scope, ip); > + if (!b) { > + if (update_only) { > + return NULL; > + } > + > + /* Northd can withdraw a scope while a controller is learning. > + * Verify its existence so a concurrent deletion retries the > + * transaction instead of creating a dangling strong reference. */ > + sbrec_mac_binding_scope_verify_binding_key(scope); > + struct uuid uuid = uuid_random(); > + b = sbrec_shared_mac_binding_insert_persist_uuid(ovnsb_idl_txn, > + &uuid); > + sbrec_shared_mac_binding_set_scope(b, scope); > + sbrec_shared_mac_binding_set_ip(b, ip); > + } > + > + if (strcmp(b->mac, mac_string)) { > + sbrec_shared_mac_binding_set_mac(b, mac_string); > + sbrec_shared_mac_binding_set_timestamp(b, time_wall_msec()); > + } > + > + return b; > +} > diff --git a/lib/mac-binding-index.h b/lib/mac-binding-index.h > index 8832eda16..10360bbf9 100644 > --- a/lib/mac-binding-index.h > +++ b/lib/mac-binding-index.h > @@ -22,6 +22,8 @@ struct ovsdb_idl_index > *mac_binding_by_datapath_index_create( > struct ovsdb_idl *idl); > struct ovsdb_idl_index *mac_binding_by_lport_ip_index_create( > struct ovsdb_idl *idl); > +struct ovsdb_idl_index *shared_mac_binding_by_scope_ip_index_create( > + struct ovsdb_idl *idl); > > const struct sbrec_mac_binding * > mac_binding_lookup(struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, > @@ -34,4 +36,15 @@ const struct sbrec_mac_binding *mac_binding_add_to_sb( > struct eth_addr, const char *ip, bool update_only, > const struct sbrec_mac_binding *sb_mb); > > +const struct sbrec_shared_mac_binding *shared_mac_binding_lookup( > + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, > + const struct sbrec_mac_binding_scope *scope, const char *ip); > + > +const struct sbrec_shared_mac_binding *shared_mac_binding_add_to_sb( > + struct ovsdb_idl_txn *, > + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, > + const struct sbrec_mac_binding_scope *, struct eth_addr, > + const char *ip, bool update_only, > + const struct sbrec_shared_mac_binding *sb_mb); > + > #endif /* lib/mac-binding-index.h */ > diff --git a/tests/ovn-controller.at b/tests/ovn-controller.at > index a7b79fc67..298683908 100644 > --- a/tests/ovn-controller.at > +++ b/tests/ovn-controller.at > @@ -740,6 +740,7 @@ ct_commit_nat_v2: true > ct_commit_to_zone: true > ct_next_zone: true > ct_state_save: true > +shared_mac_binding: true > ]) > > OVN_CLEANUP([hv1]) > diff --git a/tests/ovn-inc-proc-graph-dump.at b/tests/ > ovn-inc-proc-graph-dump.at > index e77ef037f..ddc5e2d60 100644 > --- a/tests/ovn-inc-proc-graph-dump.at > +++ b/tests/ovn-inc-proc-graph-dump.at > @@ -364,6 +364,8 @@ digraph "Incremental-Processing-Engine" { > SB_multicast_group [[style=filled, shape=box, fillcolor=white, > label="SB_multicast_group"]]; > OVS_flow_sample_collector_set [[style=filled, shape=box, > fillcolor=white, label="OVS_flow_sample_collector_set"]]; > SB_mac_binding [[style=filled, shape=box, fillcolor=white, > label="SB_mac_binding"]]; > + SB_shared_mac_binding [[style=filled, shape=box, fillcolor=white, > label="SB_shared_mac_binding"]]; > + SB_mac_binding_scope [[style=filled, shape=box, fillcolor=white, > label="SB_mac_binding_scope"]]; > SB_static_mac_binding [[style=filled, shape=box, fillcolor=white, > label="SB_static_mac_binding"]]; > SB_logical_flow [[style=filled, shape=box, fillcolor=white, > label="SB_logical_flow"]]; > SB_logical_dp_group [[style=filled, shape=box, fillcolor=white, > label="SB_logical_dp_group"]]; > @@ -388,6 +390,8 @@ digraph "Incremental-Processing-Engine" { > OVS_bridge -> lflow_output [[label=""]]; > OVS_flow_sample_collector_set -> lflow_output > [[label="lflow_output_flow_sample_collector_set_handler"]]; > SB_mac_binding -> lflow_output > [[label="lflow_output_sb_mac_binding_handler"]]; > + SB_shared_mac_binding -> lflow_output > [[label="lflow_output_sb_shared_mac_binding_handler"]]; > + SB_mac_binding_scope -> lflow_output [[label=""]]; > SB_static_mac_binding -> lflow_output > [[label="lflow_output_sb_static_mac_binding_handler"]]; > SB_logical_flow -> lflow_output > [[label="lflow_output_sb_logical_flow_handler"]]; > SB_logical_dp_group -> lflow_output > [[label="engine_noop_handler"]]; > @@ -463,9 +467,11 @@ digraph "Incremental-Processing-Engine" { > mac_cache [[style=filled, shape=box, fillcolor=white, > label="mac_cache"]]; > runtime_data -> mac_cache > [[label="mac_cache_runtime_data_handler"]]; > SB_mac_binding -> mac_cache > [[label="mac_cache_sb_mac_binding_handler"]]; > + SB_shared_mac_binding -> mac_cache > [[label="mac_cache_sb_shared_mac_binding_handler"]]; > + SB_mac_binding_scope -> mac_cache [[label=""]]; > SB_fdb -> mac_cache [[label="mac_cache_sb_fdb_handler"]]; > SB_datapath_binding -> mac_cache > [[label="mac_cache_sb_datapath_binding_handler"]]; > - SB_port_binding -> mac_cache [[label="engine_noop_handler"]]; > + SB_port_binding -> mac_cache > [[label="mac_cache_sb_port_binding_handler"]]; > SB_ha_chassis_group [[style=filled, shape=box, fillcolor=white, > label="SB_ha_chassis_group"]]; > bfd_chassis [[style=filled, shape=box, fillcolor=white, > label="bfd_chassis"]]; > OVS_open_vswitch -> bfd_chassis [[label=""]]; > @@ -502,14 +508,18 @@ digraph "Incremental-Processing-Engine" { > SB_port_binding -> garp_rarp > [[label="garp_rarp_sb_port_binding_handler"]]; > SB_datapath_binding -> garp_rarp > [[label="garp_rarp_sb_datapath_binding_handler"]]; > SB_mac_binding -> garp_rarp [[label="engine_noop_handler"]]; > + SB_shared_mac_binding -> garp_rarp [[label="engine_noop_handler"]]; > + SB_mac_binding_scope -> garp_rarp [[label=""]]; > runtime_data -> garp_rarp > [[label="garp_rarp_runtime_data_handler"]]; > evpn_mac_binding_sync_waker [[style=filled, shape=box, > fillcolor=white, label="evpn_mac_binding_sync_waker"]]; > evpn_mac_binding_sync [[style=filled, shape=box, fillcolor=white, > label="evpn_mac_binding_sync"]]; > evpn_mac_binding_sync_waker -> evpn_mac_binding_sync [[label=""]]; > evpn_arp -> evpn_mac_binding_sync [[label=""]]; > SB_mac_binding -> evpn_mac_binding_sync > [[label="engine_noop_handler"]]; > + SB_shared_mac_binding -> evpn_mac_binding_sync > [[label="engine_noop_handler"]]; > runtime_data -> evpn_mac_binding_sync > [[label="engine_noop_handler"]]; > mac_cache -> evpn_mac_binding_sync [[label="engine_noop_handler"]]; > + SB_mac_binding_scope -> evpn_mac_binding_sync [[label=""]]; > sb_ro -> evpn_mac_binding_sync > [[label="evpn_mac_binding_sync_sb_ro_handler"]]; > SB_port_binding -> evpn_mac_binding_sync > [[label="evpn_mac_binding_sync_sb_port_binding_handler"]]; > SB_acl_id [[style=filled, shape=box, fillcolor=white, > label="SB_acl_id"]]; > diff --git a/tests/ovn-macros.at b/tests/ovn-macros.at > index 01e64da2a..9051faf71 100644 > --- a/tests/ovn-macros.at > +++ b/tests/ovn-macros.at > @@ -330,7 +330,8 @@ m4_define([CHECK_RELATED_PORTS_AFTER_RECOMPUTE], [ > # CHECK_AFTER_RECOMPUTE(hv, sbox, related_ports, ignored_dp) > # Check related ports (ignoring $related_ports) and FLOWS (ignoring flows > from $ignored_dp and from $ignored_tables) > # by comparing IP flows and flows after recompute. > -# We also ignore Flows from tables OFTABLE_MAC_BINDING, > OFTABLE_MAC_LOOKUP, OFTABLE_MAC_CACHE_USE. > +# Ignore dynamic neighbor binding, lookup, and cache-use tables, including > +# shared bindings, since learning and aging can change them between dumps. > m4_define([CHECK_AFTER_RECOMPUTE], [ > hv=$1 > sbox=$2 > @@ -401,7 +402,12 @@ m4_define([CHECK_AFTER_RECOMPUTE], [ > cat flow-diff-$hv | grep -v "table=$table" > tmp; mv tmp > flow-diff-$hv > done > > - cat flow-diff-$hv | grep -v "table=OFTABLE_MAC_BINDING" | grep -v > "table=OFTABLE_MAC_LOOKUP" | grep -v "table=OFTABLE_MAC_CACHE_USE" > tmp; > mv tmp flow-diff-$hv > + for table in OFTABLE_MAC_BINDING OFTABLE_MAC_LOOKUP \ > + OFTABLE_MAC_CACHE_USE OFTABLE_SHARED_MAC_BINDING \ > + OFTABLE_SHARED_MAC_LOOKUP; do > + grep -v "table=$table," flow-diff-$hv > tmp > + mv tmp flow-diff-$hv > + done > AT_CHECK([wc -l < flow-diff-$hv], [0], [0 > ]) > fi > diff --git a/tests/ovn.at b/tests/ovn.at > index ad503faee..ce2ed8933 100644 > --- a/tests/ovn.at > +++ b/tests/ovn.at > @@ -31467,7 +31467,7 @@ OVN_CHECK_PACKETS([hv2/vif1-tx.pcap], [expected]) > as hv1 ovs-appctl ofproto/trace br-int in_port=1 $packet > > # MAC binding entry should have generated > -AT_CHECK([ovn-sbctl find mac ip=10.0.0.2 mac='"00:00:00:00:03:02"' > logical_port=lrp-r1-join | grep 10\.0\.0\.2], [0], [ignore], []) > +AT_CHECK([ovn-sbctl find mac_binding ip=10.0.0.2 > mac='"00:00:00:00:03:02"' logical_port=lrp-r1-join | grep 10\.0\.0\.2], > [0], [ignore], []) > > OVN_CLEANUP([hv1],[hv2]) > > @@ -37025,6 +37025,304 @@ test_mac_binding_flows 150 00:00:11:22:33:88 0 > OVN_CLEANUP([hv1]) > AT_CLEANUP > > +OVN_FOR_EACH_NORTHD([ > +AT_SETUP([ovn -- shared MAC binding scopes]) > +AT_KEYWORDS([mac_binding]) > +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 > +check ovs-vsctl set open . \ > + external-ids:ovn-bridge-mappings=phys:br-phys > +check ovs-vsctl -- add-port br-phys ext0 -- \ > + set Interface ext0 options:tx_pcap=hv1/ext0-tx.pcap \ > + options:rxq_pcap=hv1/ext0-rx.pcap > + > +check ovn-nbctl ls-add public > +check ovn-nbctl lsp-add-localnet-port public ln phys > + > +check ovn-nbctl lr-add lr0 > +check ovn-nbctl lrp-add lr0 lr0-public \ > + 00:00:00:00:10:00 192.168.10.1/24 > +check ovn-nbctl lsp-add-router-port public public-lr0 lr0-public > +check ovn-nbctl lrp-set-gateway-chassis lr0-public hv1 > + > +scope=$(ovn-nbctl create MAC_Binding_Scope name=scope0 \ > + always_learn_from_arp_request=true) > +check ovn-nbctl set Logical_Router_Port lr0-public \ > + mac_binding_scope=$scope > + > +dnl Two routers on the same uplink must share a single learned binding. > +check ovn-nbctl lr-add lr2 > +check ovn-nbctl lrp-add lr2 lr2-public \ > + 00:00:00:00:10:02 192.168.10.2/24 > +check ovn-nbctl lsp-add-router-port public public-lr2 lr2-public > +check ovn-nbctl lrp-set-gateway-chassis lr2-public hv1 > +check ovn-nbctl set Logical_Router_Port lr2-public > mac_binding_scope=$scope > + > +wait_for_ports_up > +wait_row_count Chassis 1 name=hv1 other_config:shared-mac-binding=true > + > +dnl Missing feature flags on an existing chassis must be restored. > +check ovn-sbctl remove Chassis hv1 other_config shared-mac-binding > +wait_row_count Chassis 1 name=hv1 other_config:shared-mac-binding=true > + > +dnl Restoring the feature flag can withdraw and recreate the scope. Wait > +dnl for northd and the controller to finish before inspecting engine stats > +dnl or sending the one-shot GARP. > +wait_row_count sb:MAC_Binding_Scope 1 name=scope0 > +check ovn-nbctl --wait=hv sync > + > +dnl Unrelated scoped port updates must not recompute the MAC cache. > +check as hv1 ovn-appctl -t ovn-controller inc-engine/clear-stats > +check ovn-sbctl set Port_Binding lr0-public external_ids:unrelated=true > +check ovn-nbctl --wait=hv sync > +check_controller_engine_stats hv1 mac_cache norecompute nocompute > + > +dnl Enabling scope aging must notify EVPN even if no refresh timer was > +dnl scheduled while aging was disabled. > +check as hv1 ovn-appctl -t ovn-controller inc-engine/clear-stats > +check ovn-nbctl --wait=hv set MAC_Binding_Scope $scope \ > + mac_binding_age_threshold=30 > +dnl An SB acknowledgement can also run incremental handlers. Only the > +dnl scope-triggered recompute is required, not an exact compute count. > +AT_CHECK([as hv1 ovn-appctl -t ovn-controller inc-engine/show-stats \ > + evpn_mac_binding_sync | grep -Eq 'recompute: +[[1-9]][[0-9]]*']) > + > +sb_scope=$(fetch_column sb:MAC_Binding_Scope _uuid name=scope0) > +scope_key=$(printf "0x%x" \ > + $(fetch_column sb:MAC_Binding_Scope binding_key name=scope0)) > +check_column "$sb_scope" Port_Binding mac_binding_scope \ > + logical_port=lr0-public > + > +dnl A GARP learned through a scope member creates one shared row. > +garp=ffffffffffff0000000010fe08060001080006040001 > +garp=${garp}0000000010fec0a80afe000000000000c0a80afe > +check as hv1 ovs-appctl netdev-dummy/receive ext0 $garp > +wait_row_count Shared_MAC_Binding 1 ip=192.168.10.254 \ > + mac='"00:00:00:00:10:fe"' > +check_row_count MAC_Binding 0 ip=192.168.10.254 > + > +dnl The controller renders the row once in the shared namespace. > +OVS_WAIT_UNTIL([ > + test $(as hv1 ovs-ofctl dump-flows br-int \ > + table=OFTABLE_SHARED_MAC_BINDING | \ > + grep "metadata=${scope_key}" | grep "reg0=0xc0a80afe" | \ > + grep -c "actions=mod_dl_dst:00:00:00:00:10:fe") -eq 1 > +]) > +OVS_WAIT_UNTIL([ > + test $(as hv1 ovs-ofctl dump-flows br-int \ > + table=OFTABLE_SHARED_MAC_LOOKUP | \ > + grep "metadata=${scope_key}" | grep "reg0=0xc0a80afe" | \ > + grep -c "dl_src=00:00:00:00:10:fe") -eq 1 > +]) > + > +dnl Repeated traffic uses the cache rather than relearning the row. The > +dnl statistics drain must refresh Shared_MAC_Binding, not MAC_Binding. > +initial_timestamp=$(fetch_column Shared_MAC_Binding timestamp \ > + ip=192.168.10.254) > +OVS_WAIT_UNTIL([ > + as hv1 ovs-appctl netdev-dummy/receive ext0 $garp > + test "$(fetch_column Shared_MAC_Binding timestamp \ > + ip=192.168.10.254)" -gt "$initial_timestamp" > +]) > +check_row_count Shared_MAC_Binding 1 ip=192.168.10.254 > +check_row_count MAC_Binding 0 ip=192.168.10.254 > + > +dnl A regular static binding is a fallback, while an override is applied > +dnl after the shared lookup and remains local to its router port. > +lr0_key=$(printf "0x%x" \ > + $(fetch_column Datapath_Binding tunnel_key external_ids:name=lr0)) > +lr0_port_key=$(printf "0x%x" \ > + $(fetch_column Port_Binding tunnel_key logical_port=lr0-public)) > +check ovn-nbctl static-mac-binding-add lr0-public 192.168.10.254 \ > + 00:00:00:00:10:aa > +OVS_WAIT_UNTIL([ > + test $(as hv1 ovs-ofctl dump-flows br-int \ > + table=OFTABLE_MAC_BINDING | grep "reg0=0xc0a80afe" | \ > + grep -c "actions=mod_dl_dst:00:00:00:00:10:aa") -eq 1 > +]) > +check ovn-nbctl --may-exist static-mac-binding-add lr0-public \ > + 192.168.10.254 00:00:00:00:10:bb > +smb=$(fetch_column nb:Static_MAC_Binding _uuid ip=192.168.10.254) > +check ovn-nbctl set Static_MAC_Binding $smb override_dynamic_mac=true > +OVS_WAIT_UNTIL([ > + test $(as hv1 ovs-ofctl dump-flows br-int \ > + table=OFTABLE_MAC_BINDING_OVERRIDE | \ > + grep -E "metadata=${lr0_key}(,| )" | \ > + grep "reg15=${lr0_port_key}," | \ > + grep "reg0=0xc0a80afe" | \ > + grep -c "actions=mod_dl_dst:00:00:00:00:10:bb") -eq 1 > +]) > + > +dnl Trace the actual ARP resolution flows for both scope members. Only > +dnl lr0 uses the override; lr2 must still resolve the shared MAC address. > +arp_resolve=$(ovn-debug lflow-stage-to-oftable lr_in_arp_resolve) > +for router in lr0 lr2; do > + dp_key=$(fetch_column Datapath_Binding tunnel_key \ > + external_ids:name=$router) > + port_key=$(fetch_column Port_Binding tunnel_key \ > + logical_port=$router-public) > + if test "$router" = lr0; then > + expected_mac=00:00:00:00:10:bb > + else > + expected_mac=00:00:00:00:10:fe > + fi > + AT_CHECK([as hv1 ovs-appctl ofproto/trace-packet-out br-int \ > + "ip,metadata=$dp_key,reg15=$port_key,reg0=0xc0a80afe" \ > + "resubmit(,$arp_resolve)"], [0], [stdout]) > + AT_CHECK([grep '^Final flow:' stdout | \ > + grep -c "dl_dst=$expected_mac"], [0], [1 > +]) > +done > + > +dnl A scope on a remote gateway is still local when its router datapath is > +dnl local. Its shared bindings must be included by conditional > monitoring. > +check ovn-sbctl chassis-add hv2 geneve 192.168.0.2 \ > + -- set Chassis hv2 other_config:shared-mac-binding=true > + > +check ovn-nbctl ls-add internal > +check ovn-nbctl lsp-add internal vif1 > +check ovn-nbctl lsp-set-addresses vif1 \ > + "00:00:00:00:20:10 10.0.0.10" > + > +check ovn-nbctl lr-add lr1 > +check ovn-nbctl lrp-add lr1 lr1-internal \ > + 00:00:00:00:20:01 10.0.0.1/24 > +check ovn-nbctl lsp-add-router-port internal internal-lr1 lr1-internal > +check ovn-nbctl lrp-add lr1 lr1-public \ > + 00:00:00:00:30:01 192.168.20.1/24 > +check ovn-nbctl lsp-add-router-port public public-lr1 lr1-public > +check ovn-nbctl lrp-set-gateway-chassis lr1-public hv2 > + > +remote_scope=$(ovn-nbctl create MAC_Binding_Scope name=remote-scope \ > + mac_binding_age_threshold=300) > +check as hv1 ovs-vsctl add-port br-int vif1 -- \ > + set Interface vif1 external-ids:iface-id=vif1 > +wait_for_ports_up vif1 > +check ovn-nbctl --wait=hv sync > + > +dnl Assign a scope after the router datapath is already local. A > scope-only > +dnl port update must refresh the conditional monitor without a > runtime-data > +dnl change. > +check ovn-nbctl set Logical_Router_Port lr1-public \ > + mac_binding_scope=$remote_scope > +check ovn-nbctl --wait=sb sync > + > +remote_sb_scope=$(fetch_column sb:MAC_Binding_Scope _uuid \ > + name=remote-scope) > +remote_scope_key=$(printf "0x%x" \ > + $(fetch_column sb:MAC_Binding_Scope binding_key name=remote-scope)) > +hv1_chassis=$(fetch_column Chassis _uuid name=hv1) > +check_row_count Port_Binding 0 mac_binding_scope=$remote_sb_scope \ > + chassis=$hv1_chassis > + > +check ovn-nbctl --wait=hv sync > +now=$(date +%s)000 > +check_uuid ovn-sbctl create Shared_MAC_Binding scope=$remote_sb_scope \ > + ip=192.168.20.254 mac="00\:00\:00\:00\:20\:fe" timestamp=$now > +OVS_WAIT_UNTIL([ > + test $(as hv1 ovs-ofctl dump-flows br-int \ > + table=OFTABLE_SHARED_MAC_BINDING | \ > + grep "metadata=${remote_scope_key}" | grep "reg0=0xc0a814fe" | \ > + grep -c "actions=mod_dl_dst:00:00:00:00:20:fe") -eq 1 > +]) > + > +OVN_CLEANUP([hv1]) > +AT_CLEANUP > +]) > + > +OVN_FOR_EACH_NORTHD([ > +AT_SETUP([ovn -- shared MAC bindings on a newly local datapath]) > +AT_KEYWORDS([mac_binding]) > +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 > +check ovs-vsctl set open . external_ids:ovn-monitor-all=true > +wait_row_count Chassis 1 name=hv1 other_config:ovn-monitor-all=true > +check ovn-sbctl chassis-add hv2 geneve 192.168.0.2 \ > + -- set Chassis hv2 other_config:shared-mac-binding=true > + > +check ovn-nbctl \ > + -- ls-add public \ > + -- lsp-add-localnet-port public ln phys \ > + -- ls-add internal \ > + -- lsp-add internal vif1 \ > + -- lsp-set-addresses vif1 "00:00:00:00:20:10 10.0.0.10" \ > + -- lr-add lr0 \ > + -- lrp-add lr0 lr0-internal 00:00:00:00:20:01 10.0.0.1/24 \ > + -- lsp-add-router-port internal internal-lr0 lr0-internal \ > + -- lrp-add lr0 lr0-public 00:00:00:00:10:01 192.168.10.1/24 \ > + -- lsp-add-router-port public public-lr0 lr0-public \ > + -- lrp-set-gateway-chassis lr0-public hv2 > +scope=$(ovn-nbctl create MAC_Binding_Scope name=scope0) > +check ovn-nbctl --wait=hv set Logical_Router_Port lr0-public \ > + mac_binding_scope=$scope > +sb_scope=$(fetch_column sb:MAC_Binding_Scope _uuid name=scope0) > + > +dnl Monitor the bindings before any scope member datapath is local. > +scope_key=$(printf "0x%x" \ > + $(fetch_column sb:MAC_Binding_Scope binding_key name=scope0)) > +check_uuid ovn-sbctl create Shared_MAC_Binding scope=$sb_scope \ > + ip=192.168.10.254 mac="00\:00\:00\:00\:10\:fe" timestamp=0 > +check_uuid ovn-sbctl create Shared_MAC_Binding scope=$sb_scope \ > + ip='"fd00::fe"' mac="00\:00\:00\:00\:10\:fe" timestamp=0 > +check ovn-nbctl --wait=hv sync > +AT_CHECK([as hv1 ovs-ofctl dump-flows br-int \ > + table=OFTABLE_SHARED_MAC_BINDING | grep -c 'priority=100'], [1], [0 > +]) > + > +dnl Attaching a VIF makes the router local without changing either > binding. > +dnl The incremental path must render both shared tables without a > recompute. > +check as hv1 ovn-appctl -t ovn-controller inc-engine/clear-stats > +check as hv1 ovs-vsctl add-port br-int vif1 -- \ > + set Interface vif1 external-ids:iface-id=vif1 > +wait_for_ports_up vif1 > +check ovn-nbctl --wait=hv sync > +for table in OFTABLE_SHARED_MAC_BINDING OFTABLE_SHARED_MAC_LOOKUP; do > + if test "$table" = OFTABLE_SHARED_MAC_BINDING; then > + ipv6_match='reg4=0xfd000000,reg5=0,reg6=0,reg7=0xfe,' > + mac_match='actions=mod_dl_dst:00:00:00:00:10:fe' > + else > + ipv6_match='reg0=0xfd000000,reg1=0,reg2=0,reg3=0xfe,' > + mac_match='dl_src=00:00:00:00:10:fe' > + fi > + OVS_WAIT_UNTIL([ > + test $(as hv1 ovs-ofctl dump-flows br-int table=$table | \ > + grep -c 'priority=100') -eq 2 > + ]) > + for ip_match in 'reg0=0xc0a80afe,' "$ipv6_match"; do > + AT_CHECK([as hv1 ovs-ofctl dump-flows br-int table=$table | \ > + grep 'priority=100,' | \ > + grep -E "metadata=${scope_key}(,| )" | \ > + grep "$ip_match" | grep -c "$mac_match"], [0], [1 > +]) > + done > +done > +check_controller_engine_stats hv1 lflow_output norecompute compute > + > +dnl Check stable shared flows explicitly; cleanup ignores dynamic tables. > +as hv1 ovs-ofctl dump-flows br-int | ofctl_strip_all | \ > + grep -E > 'table=(OFTABLE_SHARED_MAC_BINDING|OFTABLE_SHARED_MAC_LOOKUP),' | \ > + sort > shared-before > +check as hv1 ovn-appctl -t ovn-controller recompute > +check ovn-nbctl --wait=hv sync > +as hv1 ovs-ofctl dump-flows br-int | ofctl_strip_all | \ > + grep -E > 'table=(OFTABLE_SHARED_MAC_BINDING|OFTABLE_SHARED_MAC_LOOKUP),' | \ > + sort > shared-after > +AT_CHECK([diff -u shared-before shared-after]) > + > +OVN_CLEANUP([hv1]) > +AT_CLEANUP > +]) > + > OVN_FOR_EACH_NORTHD([ > AT_SETUP([ovn -- lr mac_binding I-P update]) > AT_KEYWORDS([mac_binding]) > @@ -37857,7 +38155,7 @@ lr_key=$(fetch_column datapath_binding tunnel_key > external_ids:name=lr) > cookie=$(fetch_column mac_binding _uuid logical_port=lr-ls1 | cut -d'-' > -f1) > OVS_WAIT_FOR_OUTPUT_UNQUOTED([as hv1 ovn-appctl -t ovn-controller > debug/dump-mac-bindings], [0], [dnl > Local MAC bindings: > -cookie: 0x$cookie, datapath-key: $lr_key, port-key: 0, ip: 192.168.10.10, > mac: 00:00:00:00:10:10 > +cookie: 0x$cookie, namespace: datapath, datapath-key: $lr_key, port-key: > 0, ip: 192.168.10.10, mac: 00:00:00:00:10:10 > ]) > > dnl Remove router port. This deletes the mac binding in the same > transaction. > @@ -37883,7 +38181,7 @@ dnl Check local mac binding cache. > cookie=$(fetch_column mac_binding _uuid logical_port=lr-ls2 | cut -d'-' > -f1) > OVS_WAIT_FOR_OUTPUT_UNQUOTED([as hv1 ovn-appctl -t ovn-controller > debug/dump-mac-bindings], [0], [dnl > Local MAC bindings: > -cookie: 0x$cookie, datapath-key: $lr_key, port-key: 0, ip: 192.168.20.10, > mac: 00:00:00:00:20:10 > +cookie: 0x$cookie, namespace: datapath, datapath-key: $lr_key, port-key: > 0, ip: 192.168.20.10, mac: 00:00:00:00:20:10 > ]) > > dnl Change LRP tunnel key. > diff --git a/tests/system-ovn.at b/tests/system-ovn.at > index 3cb4b858a..4f89f32f1 100644 > --- a/tests/system-ovn.at > +++ b/tests/system-ovn.at > @@ -18717,6 +18717,49 @@ ovs-ofctl dump-flows br-int > table=OFTABLE_EVPN_ARP_LOOKUP | \ > grep priority | awk '{print $[7], $[8]}' | sort > evpn_side_after > AT_CHECK([diff -q evpn_side_before evpn_side_after]) > > +AS_BOX([Enable aging on existing EVPN shared bindings]) > +dnl Start with aging disabled so EVPN has no timestamp-refresh wake > pending. > +dnl Add a gateway after the EVPN neighbors already exist. Both l3gateway > +dnl ports must be claimed before their peer link is usable, so sync must > +dnl react to the later chassis updates without a forced recompute or a new > +dnl EVPN neighbor notification. > +dnl Suppress this temporary router's GARPs so they do not leave learned > +dnl private bindings in the original router after the scope is removed. > +scope=$(ovn-nbctl create MAC_Binding_Scope name=evpn-scope \ > + disable_garp_rarp=true) > +check ovn-nbctl --wait=hv \ > + -- lr-add lr-scope \ > + -- set Logical_Router lr-scope options:chassis=hv1 \ > + -- lrp-add lr-scope lr-scope-evpn \ > + f0:00:0f:16:01:02 172.16.1.2/24 172:16::2/64 \ > + -- lsp-add-router-port ls-evpn evpn-lr-scope lr-scope-evpn \ > + -- set Logical_Router_Port lr-scope-evpn mac_binding_scope=$scope > +sb_scope=$(fetch_column sb:MAC_Binding_Scope _uuid name=evpn-scope) > +wait_row_count Shared_MAC_Binding 1 scope=$sb_scope ip=172.16.1.50 > +wait_row_count Shared_MAC_Binding 1 scope=$sb_scope ip='172\:16\:\:50' > +mb4=$(fetch_column Shared_MAC_Binding _uuid \ > + scope=$sb_scope ip=172.16.1.50) > +mb6=$(fetch_column Shared_MAC_Binding _uuid \ > + scope=$sb_scope ip='172\:16\:\:50') > +timestamp4=$(ovn-sbctl get Shared_MAC_Binding $mb4 timestamp) > +timestamp6=$(ovn-sbctl get Shared_MAC_Binding $mb6 timestamp) > +check ovn-nbctl --wait=hv sync > + > +dnl Without changing any EVPN neighbor, enable aging and verify that the > +dnl same IPv4 and IPv6 rows are refreshed beyond their original lifetime. > +check ovn-nbctl --wait=hv set MAC_Binding_Scope $scope \ > + mac_binding_age_threshold=10 > +OVS_WAIT_UNTIL([ > + test "$(ovn-sbctl get Shared_MAC_Binding $mb4 timestamp)" \ > + -gt "$((timestamp4 + 10000))" && > + test "$(ovn-sbctl get Shared_MAC_Binding $mb6 timestamp)" \ > + -gt "$((timestamp6 + 10000))" > +]) > +check ovn-nbctl --wait=hv \ > + -- lsp-del evpn-lr-scope \ > + -- lr-del lr-scope \ > + -- destroy MAC_Binding_Scope $scope > + > dnl Verify side table flows are removed when EVPN entries are removed. > check ip neigh del dev $BR_NAME 172.16.1.50 > check ip neigh del dev $BR_NAME 172.16.1.60 > -- > 2.56.0 > > _______________________________________________ > dev mailing list > dev@openvswitch.org > https://mail.openvswitch.org/mailman/listinfo/ovs-dev This looks like a good series and I am working on a full review but those are some questions that immeditly stuck out. Thanks, Jacob Tanenbaum
diff --git a/controller/chassis.c b/controller/chassis.c index b82683064..325ef3558 100644 --- a/controller/chassis.c +++ b/controller/chassis.c @@ -424,6 +424,7 @@ chassis_build_other_config(const struct ovs_chassis_cfg *ovs_cfg, smap_replace(config, OVN_FEATURE_CT_LABEL_FLUSH, ovs_cfg->ct_label_flush ? "true" :"false"); smap_replace(config, OVN_FEATURE_CT_STATE_SAVE, "true"); + smap_replace(config, OVN_FEATURE_SHARED_MAC_BINDING, "true"); } /* @@ -597,6 +598,11 @@ chassis_other_config_changed(const struct ovs_chassis_cfg *ovs_cfg, return true; } + if (!smap_get_bool(&chassis_rec->other_config, + OVN_FEATURE_SHARED_MAC_BINDING, false)) { + return true; + } + return false; } @@ -779,6 +785,7 @@ update_supported_sset(struct sset *supported) sset_add(supported, OVN_FEATURE_CT_NEXT_ZONE); sset_add(supported, OVN_FEATURE_CT_LABEL_FLUSH); sset_add(supported, OVN_FEATURE_CT_STATE_SAVE); + sset_add(supported, OVN_FEATURE_SHARED_MAC_BINDING); } static void diff --git a/controller/evpn-mac-binding-sync.c b/controller/evpn-mac-binding-sync.c index be62c0f9a..535bb78ce 100644 --- a/controller/evpn-mac-binding-sync.c +++ b/controller/evpn-mac-binding-sync.c @@ -28,24 +28,36 @@ #include "ovn-util.h" #include "vec.h" -/* Hash a (logical_port, ip) pair. */ +/* Hash a private (logical_port, ip) or shared (scope, ip) pair. */ static uint32_t -evpn_mb_hash(const char *logical_port, const char *ip) +evpn_mb_hash(const struct sbrec_port_binding *router_pb, const char *ip) { - uint32_t hash = hash_string(logical_port, 0); + const struct sbrec_mac_binding_scope *scope = + router_pb->mac_binding_scope; + uint32_t hash = hash_boolean(!!scope, 0); + hash = scope + ? hash_add(hash, uuid_hash(&scope->header_.uuid)) + : hash_string(router_pb->logical_port, hash); return hash_string(ip, hash); } static struct evpn_mb_synced_entry * -evpn_mb_synced_find(const struct hmap *synced, const char *logical_port, +evpn_mb_synced_find(const struct hmap *synced, + const struct sbrec_port_binding *router_pb, const char *ip) { - uint32_t hash = evpn_mb_hash(logical_port, ip); + const struct sbrec_mac_binding_scope *scope = + router_pb->mac_binding_scope; + uint32_t hash = evpn_mb_hash(router_pb, ip); struct evpn_mb_synced_entry *entry; HMAP_FOR_EACH_WITH_HASH (entry, hmap_node, hash, synced) { - if (!strcmp(entry->logical_port, logical_port) && - !strcmp(entry->ip, ip)) { + bool same_binding = scope + ? entry->shared && uuid_equals(&entry->scope_uuid, + &scope->header_.uuid) + : !entry->shared && + !strcmp(entry->logical_port, router_pb->logical_port); + if (same_binding && !strcmp(entry->ip, ip)) { return entry; } } @@ -54,15 +66,20 @@ evpn_mb_synced_find(const struct hmap *synced, const char *logical_port, } static struct evpn_mb_synced_entry * -evpn_mb_synced_add(struct hmap *synced, const char *logical_port, +evpn_mb_synced_add(struct hmap *synced, + const struct sbrec_port_binding *router_pb, const char *ip) { + const struct sbrec_mac_binding_scope *scope = + router_pb->mac_binding_scope; struct evpn_mb_synced_entry *entry = xmalloc(sizeof *entry); *entry = (struct evpn_mb_synced_entry) { - .logical_port = xstrdup(logical_port), + .logical_port = scope ? NULL : xstrdup(router_pb->logical_port), + .scope_uuid = scope ? scope->header_.uuid : UUID_ZERO, + .shared = !!scope, .ip = xstrdup(ip), }; - hmap_insert(synced, &entry->hmap_node, evpn_mb_hash(logical_port, ip)); + hmap_insert(synced, &entry->hmap_node, evpn_mb_hash(router_pb, ip)); return entry; } @@ -87,15 +104,17 @@ evpn_mb_sync_waker_schedule(struct evpn_mb_sync_waker *waker, } } -/* Sync a single EVPN ARP entry to the SB MAC_Binding table for one - * router port. Caller must ensure 'ovnsb_idl_txn' is valid. +/* Sync a single EVPN ARP entry to the appropriate SB MAC binding table for + * one router port. Caller must ensure 'ovnsb_idl_txn' is valid. * Returns the remaining time (in ms) until the next timestamp * refresh is needed, or INT64_MAX if none. */ static int64_t sync_evpn_mb_for_router_port( struct ovsdb_idl_txn *ovnsb_idl_txn, struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, const struct sbrec_mac_binding_table *mb_table, + const struct sbrec_shared_mac_binding_table *shared_mb_table, const struct sbrec_port_binding *router_pb, const struct evpn_arp *arp, struct mac_cache_data *mac_cache_data, @@ -104,42 +123,73 @@ sync_evpn_mb_for_router_port( { char *ip_s = normalize_v46(&arp->ip); struct evpn_mb_synced_entry *existing = - evpn_mb_synced_find(&data->synced_entries, - router_pb->logical_port, ip_s); - - const struct sbrec_mac_binding *sb_mb = existing - ? sbrec_mac_binding_table_get_for_uuid(mb_table, &existing->mb_uuid) - : NULL; - - /* Insert or update the SB MAC_Binding row. */ - const struct sbrec_mac_binding *b = - mac_binding_add_to_sb(ovnsb_idl_txn, - sbrec_mac_binding_by_lport_ip, - router_pb->logical_port, - router_pb->datapath, - arp->mac, ip_s, false, - sb_mb); - - if (!existing) { - existing = evpn_mb_synced_add(&data->synced_entries, - router_pb->logical_port, ip_s); + evpn_mb_synced_find(&data->synced_entries, router_pb, ip_s); + + /* Multiple router ports can connect the same scope to this provider + * datapath. The first one processed owns the shared update for this + * iteration. */ + if (existing && !existing->stale) { + free(ip_s); + return INT64_MAX; + } + + const struct sbrec_shared_mac_binding *shared_binding = NULL; + const struct sbrec_mac_binding *private_binding = NULL; + long long timestamp; + if (router_pb->mac_binding_scope) { + const struct sbrec_shared_mac_binding *sb_mb = existing + ? sbrec_shared_mac_binding_table_get_for_uuid( + shared_mb_table, &existing->mb_uuid) + : NULL; + shared_binding = shared_mac_binding_add_to_sb( + ovnsb_idl_txn, shared_mac_binding_by_scope_ip, + router_pb->mac_binding_scope, arp->mac, ip_s, false, + sb_mb); + timestamp = shared_binding->timestamp; + if (!existing) { + existing = evpn_mb_synced_add(&data->synced_entries, + router_pb, ip_s); + } + existing->mb_uuid = shared_binding->header_.uuid; + } else { + const struct sbrec_mac_binding *sb_mb = existing + ? sbrec_mac_binding_table_get_for_uuid( + mb_table, &existing->mb_uuid) + : NULL; + + private_binding = mac_binding_add_to_sb( + ovnsb_idl_txn, sbrec_mac_binding_by_lport_ip, + router_pb->logical_port, router_pb->datapath, + arp->mac, ip_s, false, sb_mb); + timestamp = private_binding->timestamp; + if (!existing) { + existing = evpn_mb_synced_add(&data->synced_entries, + router_pb, ip_s); + } + existing->mb_uuid = private_binding->header_.uuid; } free(ip_s); - existing->mb_uuid = b->header_.uuid; existing->stale = false; /* Refresh timestamp to prevent aging. */ - struct mac_cache_threshold *threshold = - mac_cache_threshold_find(mac_cache_data, - router_pb->datapath->tunnel_key); + struct mac_cache_threshold *threshold = router_pb->mac_binding_scope + ? mac_cache_threshold_find_scope( + mac_cache_data, router_pb->mac_binding_scope->binding_key) + : mac_cache_threshold_find( + mac_cache_data, router_pb->datapath->tunnel_key); if (!threshold) { return INT64_MAX; } - uint64_t since_updated = timewall_now - b->timestamp; + uint64_t since_updated = timewall_now - timestamp; if (since_updated >= threshold->cooldown_period) { - sbrec_mac_binding_set_timestamp(b, timewall_now); + if (shared_binding) { + sbrec_shared_mac_binding_set_timestamp(shared_binding, + timewall_now); + } else { + sbrec_mac_binding_set_timestamp(private_binding, timewall_now); + } return threshold->cooldown_period; } @@ -150,7 +200,9 @@ void evpn_mac_binding_sync_run( struct ovsdb_idl_txn *ovnsb_idl_txn, struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, const struct sbrec_mac_binding_table *mb_table, + const struct sbrec_shared_mac_binding_table *shared_mb_table, const struct hmap *local_datapaths, const struct hmap *evpn_arps, struct mac_cache_data *mac_cache_data, @@ -191,7 +243,9 @@ evpn_mac_binding_sync_run( int64_t remaining = sync_evpn_mb_for_router_port(ovnsb_idl_txn, sbrec_mac_binding_by_lport_ip, + shared_mac_binding_by_scope_ip, mb_table, + shared_mb_table, remote_pb, arp, mac_cache_data, data, timewall_now); @@ -207,11 +261,20 @@ evpn_mac_binding_sync_run( continue; } - const struct sbrec_mac_binding *sb_mb = - sbrec_mac_binding_table_get_for_uuid( - mb_table, &synced_entry->mb_uuid); - if (sb_mb) { - sbrec_mac_binding_delete(sb_mb); + if (synced_entry->shared) { + const struct sbrec_shared_mac_binding *sb_mb = + sbrec_shared_mac_binding_table_get_for_uuid( + shared_mb_table, &synced_entry->mb_uuid); + if (sb_mb) { + sbrec_shared_mac_binding_delete(sb_mb); + } + } else { + const struct sbrec_mac_binding *sb_mb = + sbrec_mac_binding_table_get_for_uuid( + mb_table, &synced_entry->mb_uuid); + if (sb_mb) { + sbrec_mac_binding_delete(sb_mb); + } } evpn_mb_synced_remove(&data->synced_entries, synced_entry); diff --git a/controller/evpn-mac-binding-sync.h b/controller/evpn-mac-binding-sync.h index 249059d0e..0c70335c0 100644 --- a/controller/evpn-mac-binding-sync.h +++ b/controller/evpn-mac-binding-sync.h @@ -24,22 +24,24 @@ struct mac_cache_data; struct ovsdb_idl_index; struct ovsdb_idl_txn; struct sbrec_mac_binding_table; +struct sbrec_shared_mac_binding_table; -/* Tracks a MAC_Binding row that was written to SB by the EVPN sync. */ +/* Tracks a MAC_Binding or Shared_MAC_Binding row written by EVPN sync. */ struct evpn_mb_synced_entry { struct hmap_node hmap_node; - char *logical_port; /* Router port name. */ + char *logical_port; /* Router port name, if private. */ + struct uuid scope_uuid; /* Scope UUID, if shared. */ + bool shared; char *ip; /* Normalized IP string. */ - struct uuid mb_uuid; /* UUID of the SB MAC_Binding row. - * All-zeros when not yet synced. */ + struct uuid mb_uuid; /* UUID of the SB binding row. */ bool stale; /* Marked true at start of sync, * cleared when still desired. */ }; /* Persistent state for the en_evpn_mac_binding_sync engine node. */ struct ed_type_evpn_mac_binding_sync { - /* Contains 'struct evpn_mb_synced_entry'. Tracks which - * (logical_port, ip) pairs we have written to SB. */ + /* Contains 'struct evpn_mb_synced_entry'. Tracks private + * (logical_port, ip) and shared (scope, ip) pairs written to SB. */ struct hmap synced_entries; /* Contains LSP UUIDs belonging to synced entries peers. */ @@ -59,7 +61,9 @@ struct evpn_mb_sync_waker { void evpn_mac_binding_sync_run( struct ovsdb_idl_txn *ovnsb_idl_txn, struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, const struct sbrec_mac_binding_table *mb_table, + const struct sbrec_shared_mac_binding_table *shared_mb_table, const struct hmap *local_datapaths, const struct hmap *evpn_arps, struct mac_cache_data *mac_cache_data, diff --git a/controller/garp_rarp.c b/controller/garp_rarp.c index 9de8345c7..9f54fc907 100644 --- a/controller/garp_rarp.c +++ b/controller/garp_rarp.c @@ -355,17 +355,28 @@ send_garp_locally(const struct garp_rarp_ctx_in *r_ctx_in, continue; } - bool update_only = !smap_get_bool(&remote->datapath->external_ids, - "always_learn_from_arp_request", - true); + bool always_learn = remote->mac_binding_scope + ? smap_get_bool(&remote->mac_binding_scope->options, + "always_learn_from_arp_request", true) + : smap_get_bool(&remote->datapath->external_ids, + "always_learn_from_arp_request", true); + bool update_only = !always_learn; struct ds ip_s = DS_EMPTY_INITIALIZER; ip_format_masked(ip, OVS_BE32_MAX, &ip_s); - mac_binding_add_to_sb(r_ctx_in->ovnsb_idl_txn, - r_ctx_in->sbrec_mac_binding_by_lport_ip, - remote->logical_port, remote->datapath, - ea, ds_cstr(&ip_s), update_only, NULL); + if (remote->mac_binding_scope) { + shared_mac_binding_add_to_sb( + r_ctx_in->ovnsb_idl_txn, + r_ctx_in->shared_mac_binding_by_scope_ip, + remote->mac_binding_scope, ea, ds_cstr(&ip_s), + update_only, NULL); + } else { + mac_binding_add_to_sb(r_ctx_in->ovnsb_idl_txn, + r_ctx_in->sbrec_mac_binding_by_lport_ip, + remote->logical_port, remote->datapath, + ea, ds_cstr(&ip_s), update_only, NULL); + } ds_destroy(&ip_s); } } @@ -458,9 +469,16 @@ garp_rarp_is_enabled(struct ovsdb_idl_index *sbrec_port_binding_by_name, /* Check if GARP probing is disabled on the peer logical router. */ const struct sbrec_port_binding *peer = lport_get_peer( pb, sbrec_port_binding_by_name); - if (peer && smap_get_bool(&peer->datapath->external_ids, + if (peer) { + if (peer->mac_binding_scope) { + if (smap_get_bool(&peer->mac_binding_scope->options, "disable_garp_rarp", false)) { - return false; + return false; + } + } else if (smap_get_bool(&peer->datapath->external_ids, + "disable_garp_rarp", false)) { + return false; + } } return true; diff --git a/controller/garp_rarp.h b/controller/garp_rarp.h index f52262b99..2a21045b6 100644 --- a/controller/garp_rarp.h +++ b/controller/garp_rarp.h @@ -54,6 +54,7 @@ struct garp_rarp_ctx_in { struct ovsdb_idl_index *sbrec_port_binding_by_datapath; struct ovsdb_idl_index *sbrec_port_binding_by_name; struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip; + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip; const struct sbrec_chassis *chassis; const struct hmap *local_datapaths; const struct sset *active_tunnels; diff --git a/controller/lflow.c b/controller/lflow.c index 74848365f..a28d31836 100644 --- a/controller/lflow.c +++ b/controller/lflow.c @@ -1406,6 +1406,83 @@ add_neighbor_flows(struct ovsdb_idl_index *sbrec_port_binding_by_name, } } +static bool +mac_binding_scope_is_local( + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope, + const struct sbrec_mac_binding_scope *scope, + const struct hmap *local_datapaths, + const struct sbrec_chassis *chassis) +{ + if (!chassis) { + return false; + } + + struct sbrec_port_binding *target = sbrec_port_binding_index_init_row( + sbrec_port_binding_by_mac_binding_scope); + sbrec_port_binding_index_set_mac_binding_scope(target, scope); + + const struct sbrec_port_binding *pb; + bool is_local = false; + SBREC_PORT_BINDING_FOR_EACH_EQUAL ( + pb, target, sbrec_port_binding_by_mac_binding_scope) { + if (pb->datapath && get_local_datapath( + local_datapaths, pb->datapath->tunnel_key)) { + is_local = true; + break; + } + } + sbrec_port_binding_index_destroy_row(target); + return is_local; +} + +static void +consider_shared_neighbor_flow__( + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope, + const struct sbrec_shared_mac_binding *mb, + const struct hmap *local_datapaths, + const struct sbrec_chassis *chassis, + struct ovn_desired_flow_table *flow_table) +{ + if (mac_binding_scope_is_local( + sbrec_port_binding_by_mac_binding_scope, mb->scope, + local_datapaths, chassis)) { + consider_shared_neighbor_flow(mb, flow_table, true); + } +} + +static void +add_shared_neighbor_flows_for_scope( + struct ovsdb_idl_index *shared_mb_by_scope, + const struct sbrec_mac_binding_scope *scope, + struct ovn_desired_flow_table *flow_table) +{ + struct sbrec_shared_mac_binding *target = + sbrec_shared_mac_binding_index_init_row(shared_mb_by_scope); + sbrec_shared_mac_binding_index_set_scope(target, scope); + const struct sbrec_shared_mac_binding *mb; + SBREC_SHARED_MAC_BINDING_FOR_EACH_EQUAL (mb, target, shared_mb_by_scope) { + consider_shared_neighbor_flow(mb, flow_table, true); + } + sbrec_shared_mac_binding_index_destroy_row(target); +} + +static void +add_shared_neighbor_flows( + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope, + const struct sbrec_shared_mac_binding_table *shared_mac_binding_table, + const struct hmap *local_datapaths, + const struct sbrec_chassis *chassis, + struct ovn_desired_flow_table *flow_table) +{ + const struct sbrec_shared_mac_binding *mb; + SBREC_SHARED_MAC_BINDING_TABLE_FOR_EACH (mb, + shared_mac_binding_table) { + consider_shared_neighbor_flow__( + sbrec_port_binding_by_mac_binding_scope, mb, + local_datapaths, chassis, flow_table); + } +} + /* Builds the "learn()" action to be triggered by packets initiating a * hairpin session. * @@ -1957,6 +2034,31 @@ lflow_handle_changed_static_mac_bindings( } } +void +lflow_handle_changed_shared_mac_bindings( + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope, + const struct sbrec_shared_mac_binding_table *shared_mac_binding_table, + const struct hmap *local_datapaths, + const struct sbrec_chassis *chassis, + struct ovn_desired_flow_table *flow_table) +{ + const struct sbrec_shared_mac_binding *mb; + SBREC_SHARED_MAC_BINDING_TABLE_FOR_EACH_TRACKED ( + mb, shared_mac_binding_table) { + if (sbrec_shared_mac_binding_is_deleted(mb)) { + ofctrl_remove_flows(flow_table, &mb->header_.uuid); + continue; + } + + if (!sbrec_shared_mac_binding_is_new(mb)) { + ofctrl_remove_flows(flow_table, &mb->header_.uuid); + } + consider_shared_neighbor_flow__( + sbrec_port_binding_by_mac_binding_scope, mb, + local_datapaths, chassis, flow_table); + } +} + static void consider_fdb_flows(const struct sbrec_fdb *fdb, const struct hmap *local_datapaths, @@ -2046,6 +2148,11 @@ lflow_run(struct lflow_ctx_in *l_ctx_in, struct lflow_ctx_out *l_ctx_out) l_ctx_in->static_mac_binding_table, l_ctx_in->local_datapaths, l_ctx_out->flow_table); + add_shared_neighbor_flows( + l_ctx_in->sbrec_port_binding_by_mac_binding_scope, + l_ctx_in->shared_mac_binding_table, + l_ctx_in->local_datapaths, l_ctx_in->chassis, + l_ctx_out->flow_table); add_lb_hairpin_flows(l_ctx_in->local_lbs, l_ctx_in->local_datapaths, l_ctx_out->flow_table); @@ -2163,6 +2270,30 @@ lflow_add_flows_for_datapath(const struct sbrec_datapath_binding *dp, } sbrec_mac_binding_index_destroy_row(mb_index_row); + /* Shared rows may already be monitored when this datapath becomes local. + * Install its scopes' bindings even if no shared row has changed. */ + struct ovsdb_idl_index *pb_by_dp = + l_ctx_in->sbrec_port_binding_by_datapath; + struct ovsdb_idl_index *mb_by_scope = + l_ctx_in->sbrec_shared_mac_binding_by_scope; + struct sbrec_port_binding *pb_index_row = + sbrec_port_binding_index_init_row(pb_by_dp); + sbrec_port_binding_index_set_datapath(pb_index_row, dp); + struct uuidset scopes = UUIDSET_INITIALIZER(&scopes); + const struct sbrec_port_binding *pb; + SBREC_PORT_BINDING_FOR_EACH_EQUAL (pb, pb_index_row, pb_by_dp) { + const struct sbrec_mac_binding_scope *scope = pb->mac_binding_scope; + if (!scope || uuidset_find(&scopes, &scope->header_.uuid)) { + continue; + } + uuidset_insert(&scopes, &scope->header_.uuid); + + add_shared_neighbor_flows_for_scope(mb_by_scope, scope, + l_ctx_out->flow_table); + } + uuidset_destroy(&scopes); + sbrec_port_binding_index_destroy_row(pb_index_row); + struct sbrec_static_mac_binding *smb_index_row = sbrec_static_mac_binding_index_init_row( l_ctx_in->sbrec_static_mac_binding_by_datapath); @@ -2239,6 +2370,10 @@ lflow_handle_changed_port_bindings(struct lflow_ctx_in *l_ctx_in, const struct sbrec_port_binding *pb; SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (pb, l_ctx_in->port_binding_table) { + if (sbrec_port_binding_is_updated( + pb, SBREC_PORT_BINDING_COL_MAC_BINDING_SCOPE)) { + return false; + } if (!sbrec_port_binding_is_new(pb) && !sbrec_port_binding_is_deleted(pb)) { continue; diff --git a/controller/lflow.h b/controller/lflow.h index c20dedec7..bb12cf544 100644 --- a/controller/lflow.h +++ b/controller/lflow.h @@ -126,6 +126,9 @@ struct lflow_ctx_in { struct ovsdb_idl_index *sbrec_fdb_by_dp_key; struct ovsdb_idl_index *sbrec_mac_binding_by_datapath; struct ovsdb_idl_index *sbrec_static_mac_binding_by_datapath; + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope; + struct ovsdb_idl_index *sbrec_port_binding_by_datapath; + struct ovsdb_idl_index *sbrec_shared_mac_binding_by_scope; const struct sbrec_port_binding_table *port_binding_table; const struct sbrec_datapath_binding_table *dp_binding_table; const struct sbrec_mac_binding_table *mac_binding_table; @@ -135,6 +138,7 @@ struct lflow_ctx_in { const struct sbrec_fdb_table *fdb_table; const struct sbrec_chassis *chassis; const struct sbrec_static_mac_binding_table *static_mac_binding_table; + const struct sbrec_shared_mac_binding_table *shared_mac_binding_table; const struct hmap *local_datapaths; const struct shash *addr_sets; const struct shash *port_groups; @@ -194,6 +198,12 @@ void lflow_handle_changed_static_mac_bindings( const struct sbrec_static_mac_binding_table *smb_table, const struct hmap *local_datapaths, struct ovn_desired_flow_table *); +void lflow_handle_changed_shared_mac_bindings( + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope, + const struct sbrec_shared_mac_binding_table *, + const struct hmap *local_datapaths, + const struct sbrec_chassis *, + struct ovn_desired_flow_table *); bool lflow_handle_changed_lbs(struct lflow_ctx_in *l_ctx_in, struct lflow_ctx_out *l_ctx_out, const struct uuidset *deleted_lbs, diff --git a/controller/mac-cache.c b/controller/mac-cache.c index b25115f19..d9dc94eca 100644 --- a/controller/mac-cache.c +++ b/controller/mac-cache.c @@ -54,11 +54,17 @@ static inline bool fdb_data_equals(const struct fdb_data *a, const struct fdb_data *b); static uint64_t mac_cache_threshold_get_value_ms(const struct sbrec_datapath_binding *dp); +static uint64_t mac_cache_scope_threshold_get_value_ms( + const struct sbrec_mac_binding_scope *); static void mac_cache_threshold_remove(struct hmap *thresholds, struct mac_cache_threshold *threshold); static void mac_cache_update_req_delay(struct hmap *thresholds, uint64_t *req_delay); +static struct mac_cache_threshold *mac_cache_threshold_find__( + struct mac_cache_data *, uint32_t, bool); +static void mac_cache_threshold_add__(struct mac_cache_data *, uint32_t, + uint64_t, bool); static struct buffered_packets * buffered_packets_find(struct cmap *bp_map, @@ -73,26 +79,49 @@ buffered_packets_db_lookup(struct buffered_packets *bp, struct ovsdb_idl_index *sbrec_pb_by_key, struct ovsdb_idl_index *sbrec_dp_by_key, struct ovsdb_idl_index *sbrec_pb_by_name, - struct ovsdb_idl_index *sbrec_mb_by_lport_ip); + struct ovsdb_idl_index *sbrec_mb_by_lport_ip, + struct ovsdb_idl_index *shared_mb_by_scope_ip); + +static const struct sbrec_port_binding * +buffered_packets_get_pb(const struct buffered_packets *bp, + struct ovsdb_idl_index *sbrec_pb_by_key, + struct ovsdb_idl_index *sbrec_dp_by_key, + struct ovsdb_idl_index *sbrec_pb_by_name); /* Thresholds. */ void mac_cache_threshold_add(struct mac_cache_data *data, const struct sbrec_datapath_binding *dp) +{ + mac_cache_threshold_add__(data, dp->tunnel_key, + mac_cache_threshold_get_value_ms(dp), false); +} + +void +mac_cache_threshold_add_scope(struct mac_cache_data *data, + const struct sbrec_mac_binding_scope *scope) +{ + mac_cache_threshold_add__(data, scope->binding_key, + mac_cache_scope_threshold_get_value_ms(scope), + true); +} + +static void +mac_cache_threshold_add__(struct mac_cache_data *data, uint32_t key, + uint64_t value, bool is_scope) { struct mac_cache_threshold *threshold = - mac_cache_threshold_find(data, dp->tunnel_key); + mac_cache_threshold_find__(data, key, is_scope); if (threshold) { return; } - - uint64_t value = mac_cache_threshold_get_value_ms(dp); if (!value) { return; } threshold = xmalloc(sizeof *threshold); - threshold->dp_key = dp->tunnel_key; + threshold->dp_key = key; + threshold->is_scope = is_scope; threshold->value = value; threshold->dump_period = (3 * value) / 16; threshold->cooldown_period = (3 * value) / 16; @@ -110,7 +139,8 @@ mac_cache_threshold_add(struct mac_cache_data *data, ovs_assert(2 * (threshold->cooldown_period + threshold->dump_period) < (9 * value) / 10); - hmap_insert(&data->thresholds, &threshold->hmap_node, dp->tunnel_key); + hmap_insert(&data->thresholds, &threshold->hmap_node, + hash_2words(key, is_scope)); } void @@ -134,10 +164,26 @@ mac_cache_threshold_replace(struct mac_cache_data *data, struct mac_cache_threshold * mac_cache_threshold_find(struct mac_cache_data *data, uint32_t dp_key) +{ + return mac_cache_threshold_find__(data, dp_key, false); +} + +struct mac_cache_threshold * +mac_cache_threshold_find_scope(struct mac_cache_data *data, + uint32_t binding_key) +{ + return mac_cache_threshold_find__(data, binding_key, true); +} + +static struct mac_cache_threshold * +mac_cache_threshold_find__(struct mac_cache_data *data, uint32_t key, + bool is_scope) { struct mac_cache_threshold *threshold; - HMAP_FOR_EACH_WITH_HASH (threshold, hmap_node, dp_key, &data->thresholds) { - if (threshold->dp_key == dp_key) { + HMAP_FOR_EACH_WITH_HASH (threshold, hmap_node, + hash_2words(key, is_scope), + &data->thresholds) { + if (threshold->dp_key == key && threshold->is_scope == is_scope) { return threshold; } } @@ -151,7 +197,8 @@ mac_cache_thresholds_sync(struct mac_cache_data *data, { struct mac_cache_threshold *threshold; HMAP_FOR_EACH_SAFE (threshold, hmap_node, &data->thresholds) { - if (!get_local_datapath(local_datapaths, threshold->dp_key)) { + if (!threshold->is_scope && + !get_local_datapath(local_datapaths, threshold->dp_key)) { mac_cache_threshold_remove(&data->thresholds, threshold); } } @@ -179,6 +226,26 @@ mac_binding_add(struct hmap *map, struct mac_binding_data mb_data, mb->data = mb_data; mb->sbrec = smb; + mb->shared_sbrec = NULL; + mb->timestamp = timestamp; + mb->arp_attempts = 0; + mac_binding_update_log("Added", &mb_data, false, NULL, 0, 0); +} + +void +mac_binding_add_shared(struct hmap *map, struct mac_binding_data mb_data, + const struct sbrec_shared_mac_binding *smb, + long long timestamp) +{ + struct mac_binding *mb = mac_binding_find(map, &mb_data); + if (!mb) { + mb = xmalloc(sizeof *mb); + hmap_insert(map, &mb->hmap_node, mac_binding_data_hash(&mb_data)); + } + + mb->data = mb_data; + mb->sbrec = NULL; + mb->shared_sbrec = smb; mb->timestamp = timestamp; mb->arp_attempts = 0; mac_binding_update_log("Added", &mb_data, false, NULL, 0, 0); @@ -242,6 +309,21 @@ mac_binding_data_from_sbrec(struct mac_binding_data *data, return true; } +bool +mac_binding_data_from_shared_sbrec( + struct mac_binding_data *data, + const struct sbrec_shared_mac_binding *mb) +{ + if (!mac_binding_data_parse(data, mb->scope->binding_key, 0, + mb->ip, mb->mac)) { + return false; + } + + data->cookie = mb->header_.uuid.parts[0]; + data->is_scope = true; + return true; +} + void mac_bindings_clear(struct hmap *map) { @@ -261,10 +343,12 @@ mac_binding_data_to_string(const struct mac_binding_data *data, return; } ds_put_format(out_data, "cookie: 0x%08"PRIx64", " + "namespace: %s, " "datapath-key: %"PRIu32", " "port-key: %"PRIu32", " "ip: %s, mac: " ETH_ADDR_FMT, - data->cookie, data->dp_key, data->port_key, + data->cookie, data->is_scope ? "scope" : "datapath", + data->dp_key, data->port_key, ip, ETH_ADDR_ARGS(data->mac)); } @@ -362,6 +446,8 @@ mac_binding_stats_process_flow_stats(struct vector *stats_vec, * mac_binding_data_from_sbrec. */ .port_key = 0, .dp_key = ntohll(ofp_stats->match.flow.metadata), + .is_scope = + ofp_stats->match.flow.regs[MFF_LOG_INPORT - MFF_REG0] == 0, .mac = ofp_stats->match.flow.dl_src }, }; @@ -419,16 +505,20 @@ mac_binding_stats_run(struct vector *stats_vec, uint64_t *req_delay, continue; } - struct mac_cache_threshold *threshold = - mac_cache_threshold_find(cache_data, mb->data.dp_key); - if (timewall_now < mb->sbrec->timestamp) { + int64_t timestamp = mb->data.is_scope + ? mb->shared_sbrec->timestamp + : mb->sbrec->timestamp; + struct mac_cache_threshold *threshold = mb->data.is_scope + ? mac_cache_threshold_find_scope(cache_data, mb->data.dp_key) + : mac_cache_threshold_find(cache_data, mb->data.dp_key); + if (timewall_now < timestamp) { mac_binding_update_log("Not updating with future timestamp", &mb->data, true, threshold, stats->idle_age_ms, 0); continue; } - uint64_t since_updated_ms = timewall_now - mb->sbrec->timestamp; + uint64_t since_updated_ms = timewall_now - timestamp; /* If "idle_age" is under threshold it means that the mac binding is * used on this chassis. */ @@ -437,7 +527,9 @@ mac_binding_stats_run(struct vector *stats_vec, uint64_t *req_delay, mac_binding_update_log("Queuing timestamp update for active", &mb->data, true, threshold, stats->idle_age_ms, since_updated_ms); - uuidset_insert(pending, &mb->sbrec->header_.uuid); + uuidset_insert(pending, mb->data.is_scope + ? &mb->shared_sbrec->header_.uuid + : &mb->sbrec->header_.uuid); } else { /* Postponing the update to avoid sending database transactions * too frequently. */ @@ -473,6 +565,11 @@ mac_binding_stats_drain(struct ovsdb_idl_txn *txn, struct uuidset *pending, const struct sbrec_mac_binding *mb = sbrec_mac_binding_get_for_uuid(idl, &node->uuid); + const struct sbrec_shared_mac_binding *shared_mb = + sbrec_shared_mac_binding_get_for_uuid(idl, &node->uuid); + if (shared_mb) { + sbrec_shared_mac_binding_set_timestamp(shared_mb, timewall_now); + } if (mb) { sbrec_mac_binding_set_timestamp(mb, timewall_now); @@ -690,7 +787,8 @@ buffered_packets_lookup_run(struct cmap *bp_map, const struct hmap *recent_mbs, struct ovsdb_idl_index *sbrec_pb_by_key, struct ovsdb_idl_index *sbrec_dp_by_key, struct ovsdb_idl_index *sbrec_pb_by_name, - struct ovsdb_idl_index *sbrec_mb_by_lport_ip) { + struct ovsdb_idl_index *sbrec_mb_by_lport_ip, + struct ovsdb_idl_index *shared_mb_by_scope_ip) { struct ds ip = DS_EMPTY_INITIALIZER; long long now = time_msec(); bool updated = false; @@ -707,14 +805,24 @@ buffered_packets_lookup_run(struct cmap *bp_map, const struct hmap *recent_mbs, struct eth_addr mac = eth_addr_zero; - struct mac_binding *mb = mac_binding_find(recent_mbs, &bp->mb_data); + struct mac_binding_data lookup_data = bp->mb_data; + const struct sbrec_port_binding *pb = buffered_packets_get_pb( + bp, sbrec_pb_by_key, sbrec_dp_by_key, sbrec_pb_by_name); + if (pb && pb->mac_binding_scope) { + lookup_data.dp_key = pb->mac_binding_scope->binding_key; + lookup_data.port_key = 0; + lookup_data.is_scope = true; + } + + struct mac_binding *mb = mac_binding_find(recent_mbs, &lookup_data); if (mb) { mac = mb->data.mac; } else if (now >= bp->lookup_at_ms) { /* Check if we can do a full lookup. */ buffered_packets_db_lookup(bp, &ip, &mac, sbrec_pb_by_key, sbrec_dp_by_key, sbrec_pb_by_name, - sbrec_mb_by_lport_ip); + sbrec_mb_by_lport_ip, + shared_mb_by_scope_ip); /* Schedule next lookup even if we found the MAC address, * if the address was found this struct will be deleted anyway. */ @@ -794,6 +902,7 @@ mac_binding_data_hash(const struct mac_binding_data *mb_data) hash = hash_add(hash, mb_data->port_key); hash = hash_add(hash, mb_data->dp_key); + hash = hash_add(hash, mb_data->is_scope); hash = hash_add_in6_addr(hash, &mb_data->ip); return hash_finish(hash, 24); @@ -806,6 +915,7 @@ mac_binding_data_equals(const struct mac_binding_data *a, return a->cookie == b->cookie && a->port_key == b->port_key && a->dp_key == b->dp_key && + a->is_scope == b->is_scope && ipv6_addr_equals(&a->ip, &b->ip); } @@ -845,6 +955,41 @@ mac_cache_threshold_get_value_ms(const struct sbrec_datapath_binding *dp) return mb_value ? mb_value * 1000 : fdb_value * 1000; } +static uint64_t +mac_cache_scope_threshold_get_value_ms( + const struct sbrec_mac_binding_scope *scope) +{ + const char *config = smap_get(&scope->options, + "mac_binding_age_threshold"); + if (!config) { + return 0; + } + + uint64_t min_value = UINT64_MAX; + char *thresholds = xstrdup(config); + char *save_ptr = NULL; + for (char *entry = strtok_r(thresholds, ";", &save_ptr); entry; + entry = strtok_r(NULL, ";", &save_ptr)) { + const char *value_str = strrchr(entry, ':'); + value_str = value_str ? value_str + 1 : entry; + + unsigned int value; + if (!str_to_uint(value_str, 10, &value)) { + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); + VLOG_WARN_RL(&rl, "Invalid MAC binding aging threshold '%s' " + "for scope '%s'", entry, scope->name); + free(thresholds); + return 0; + } + if (value) { + min_value = MIN(min_value, value); + } + } + free(thresholds); + + return min_value == UINT64_MAX ? 0 : min_value * 1000; +} + static void mac_cache_threshold_remove(struct hmap *thresholds, struct mac_cache_threshold *threshold) @@ -898,34 +1043,56 @@ buffered_packets_db_lookup(struct buffered_packets *bp, struct ds *ip, struct ovsdb_idl_index *sbrec_pb_by_key, struct ovsdb_idl_index *sbrec_dp_by_key, struct ovsdb_idl_index *sbrec_pb_by_name, - struct ovsdb_idl_index *sbrec_mb_by_lport_ip) { - const struct sbrec_port_binding *pb = - lport_lookup_by_key(sbrec_dp_by_key, sbrec_pb_by_key, - bp->mb_data.dp_key, bp->mb_data.port_key); + struct ovsdb_idl_index *sbrec_mb_by_lport_ip, + struct ovsdb_idl_index *shared_mb_by_scope_ip) { + const struct sbrec_port_binding *pb = buffered_packets_get_pb( + bp, sbrec_pb_by_key, sbrec_dp_by_key, sbrec_pb_by_name); if (!pb) { return; } - if (!strcmp(pb->type, "chassisredirect")) { - const char *dgp_name = - smap_get_def(&pb->options, "distributed-port", ""); - pb = lport_lookup_by_name(sbrec_pb_by_name, dgp_name); - if (!pb) { - return; + ipv6_format_mapped(&bp->mb_data.ip, ip); + if (pb->mac_binding_scope) { + const struct sbrec_shared_mac_binding *smb = + shared_mac_binding_lookup(shared_mb_by_scope_ip, + pb->mac_binding_scope, + ds_cstr_ro(ip)); + ds_clear(ip); + if (smb) { + eth_addr_from_string(smb->mac, mac); } + return; } - ipv6_format_mapped(&bp->mb_data.ip, ip); const struct sbrec_mac_binding *smb = - mac_binding_lookup(sbrec_mb_by_lport_ip, pb->logical_port, - ds_cstr_ro(ip)); + mac_binding_lookup(sbrec_mb_by_lport_ip, pb->logical_port, + ds_cstr_ro(ip)); ds_clear(ip); - if (!smb) { - return; + if (smb) { + eth_addr_from_string(smb->mac, mac); + } +} + +static const struct sbrec_port_binding * +buffered_packets_get_pb(const struct buffered_packets *bp, + struct ovsdb_idl_index *sbrec_pb_by_key, + struct ovsdb_idl_index *sbrec_dp_by_key, + struct ovsdb_idl_index *sbrec_pb_by_name) +{ + const struct sbrec_port_binding *pb = + lport_lookup_by_key(sbrec_dp_by_key, sbrec_pb_by_key, + bp->mb_data.dp_key, bp->mb_data.port_key); + if (!pb) { + return NULL; } - eth_addr_from_string(smb->mac, mac); + if (!strcmp(pb->type, "chassisredirect")) { + const char *dgp_name = + smap_get_def(&pb->options, "distributed-port", ""); + pb = lport_lookup_by_name(sbrec_pb_by_name, dgp_name); + } + return pb; } void @@ -947,6 +1114,7 @@ mac_binding_probe_stats_process_flow_stats( * mac_binding_data_from_sbrec. */ .port_key = 0, .dp_key = ntohll(ofp_stats->match.flow.metadata), + .is_scope = false, .mac = ofp_stats->match.flow.dl_src }, }; @@ -962,6 +1130,101 @@ mac_binding_probe_stats_process_flow_stats( vector_push(stats_vec, &stats); } +void +shared_mac_binding_probe_stats_process_flow_stats( + struct vector *stats_vec, + struct ofputil_flow_stats *ofp_stats) +{ + size_t old_size = vector_len(stats_vec); + + mac_binding_probe_stats_process_flow_stats(stats_vec, ofp_stats); + if (vector_len(stats_vec) > old_size) { + struct mac_cache_stats *stats = vector_get_ptr(stats_vec, old_size); + stats->data.mb.is_scope = true; + } +} + +static bool +mac_binding_probe_get_local_address(const struct sbrec_port_binding *pb, + const struct in6_addr *target, + struct lport_addresses *laddr, + struct in6_addr *local) +{ + if (!pb->datapath || !pb->n_mac || + !extract_lsp_addresses(pb->mac[0], laddr)) { + return false; + } + + *local = in6addr_any; + if (IN6_IS_ADDR_V4MAPPED(target)) { + ovs_be32 ip4 = in6_addr_get_mapped_ipv4(target); + for (size_t i = 0; i < laddr->n_ipv4_addrs; i++) { + struct ipv4_netaddr address = laddr->ipv4_addrs[i]; + if (address.network == (ip4 & address.mask)) { + *local = in6_addr_mapped_ipv4(address.addr); + break; + } + } + } else { + for (size_t i = 0; i < laddr->n_ipv6_addrs; i++) { + struct ipv6_netaddr address = laddr->ipv6_addrs[i]; + struct in6_addr neigh_prefix = + ipv6_addr_bitand(target, &address.mask); + if (ipv6_addr_equals(&address.network, &neigh_prefix)) { + *local = address.addr; + break; + } + } + } + + if (ipv6_addr_equals(local, &in6addr_any)) { + destroy_lport_addresses(laddr); + return false; + } + return true; +} + +static const struct sbrec_port_binding * +mac_binding_probe_get_port(const struct mac_binding *mb, + const struct mac_binding_probe_data *probe_data, + struct lport_addresses *laddr, + struct in6_addr *local) +{ + if (!mb->data.is_scope) { + const struct sbrec_port_binding *pb = lport_lookup_by_name( + probe_data->sbrec_port_binding_by_name, + mb->sbrec->logical_port); + if (!pb || !lport_pb_is_local( + probe_data->sbrec_port_binding_by_name, + probe_data->chassis, pb)) { + return NULL; + } + return mac_binding_probe_get_local_address( + pb, &mb->data.ip, laddr, local) ? pb : NULL; + } + + struct sbrec_port_binding *target = sbrec_port_binding_index_init_row( + probe_data->sbrec_port_binding_by_mac_binding_scope); + sbrec_port_binding_index_set_mac_binding_scope( + target, mb->shared_sbrec->scope); + + const struct sbrec_port_binding *pb; + const struct sbrec_port_binding *found = NULL; + SBREC_PORT_BINDING_FOR_EACH_EQUAL ( + pb, target, probe_data->sbrec_port_binding_by_mac_binding_scope) { + if (strcmp(pb->type, "chassisredirect") && + lport_pb_is_local(probe_data->sbrec_port_binding_by_name, + probe_data->chassis, pb) && + mac_binding_probe_get_local_address( + pb, &mb->data.ip, laddr, local)) { + found = pb; + break; + } + } + sbrec_port_binding_index_destroy_row(target); + return found; +} + void mac_binding_probe_stats_run(struct vector *stats_vec, uint64_t *req_delay, void *data, struct uuidset *pending OVS_UNUSED, @@ -980,9 +1243,13 @@ mac_binding_probe_stats_run(struct vector *stats_vec, uint64_t *req_delay, continue; } - struct mac_cache_threshold *threshold = - mac_cache_threshold_find(cache_data, mb->data.dp_key); - if (timewall_now < mb->sbrec->timestamp) { + struct mac_cache_threshold *threshold = mb->data.is_scope + ? mac_cache_threshold_find_scope(cache_data, mb->data.dp_key) + : mac_cache_threshold_find(cache_data, mb->data.dp_key); + int64_t timestamp = mb->data.is_scope + ? mb->shared_sbrec->timestamp + : mb->sbrec->timestamp; + if (timewall_now < timestamp) { mac_binding_update_log("Not sending ARP/ND request with future " "timestamp", &mb->data, true, threshold, stats->idle_age_ms, 0); @@ -990,8 +1257,7 @@ mac_binding_probe_stats_run(struct vector *stats_vec, uint64_t *req_delay, continue; } - uint64_t since_updated_ms = timewall_now - mb->sbrec->timestamp; - const struct sbrec_mac_binding *sbrec = mb->sbrec; + uint64_t since_updated_ms = timewall_now - timestamp; if (stats->idle_age_ms > threshold->value) { mac_binding_update_log("Not sending ARP/ND request for non-active", @@ -1002,7 +1268,9 @@ mac_binding_probe_stats_run(struct vector *stats_vec, uint64_t *req_delay, if (since_updated_ms < threshold->cooldown_period || uuidset_contains(probe_data->mac_binding_pending, - &sbrec->header_.uuid)) { + mb->data.is_scope + ? &mb->shared_sbrec->header_.uuid + : &mb->sbrec->header_.uuid)) { mac_binding_update_log( "Not sending ARP/ND request for recently/to be updated", &mb->data, true, threshold, stats->idle_age_ms, @@ -1011,66 +1279,33 @@ mac_binding_probe_stats_run(struct vector *stats_vec, uint64_t *req_delay, continue; } - const struct sbrec_port_binding *pb = - lport_lookup_by_name(probe_data->sbrec_port_binding_by_name, - sbrec->logical_port); + struct lport_addresses laddr; + struct in6_addr local; + const struct sbrec_port_binding *pb = mac_binding_probe_get_port( + mb, probe_data, &laddr, &local); if (!pb) { - continue; - } - - if (!lport_pb_is_local(probe_data->sbrec_port_binding_by_name, - probe_data->chassis, pb)) { mac_binding_update_log("Not sending ARP/ND request for non-local", &mb->data, true, threshold, stats->idle_age_ms, since_updated_ms); continue; } - struct lport_addresses laddr; - if (!extract_lsp_addresses(pb->mac[0], &laddr)) { - continue; - } + struct eth_addr eth_dst = + mb->arp_attempts < PROBE_MULICAST_THRESHOLD + ? mb->data.mac + : eth_addr_zero; - struct in6_addr local = in6addr_any; - if (IN6_IS_ADDR_V4MAPPED(&mb->data.ip)) { - ovs_be32 ip4 = in6_addr_get_mapped_ipv4(&mb->data.ip); - for (size_t i = 0; i < laddr.n_ipv4_addrs; i++) { - struct ipv4_netaddr address = laddr.ipv4_addrs[i]; - if (address.network == (ip4 & address.mask)) { - local = in6_addr_mapped_ipv4(address.addr); - break; - } - } - } else { - for (size_t i = 0; i < laddr.n_ipv6_addrs; i++) { - struct ipv6_netaddr address = laddr.ipv6_addrs[i]; - struct in6_addr neigh_prefix = - ipv6_addr_bitand(&mb->data.ip, &address.mask); - if (ipv6_addr_equals(&address.network, &neigh_prefix)) { - local = address.addr; - break; - } - } - } - - if (!ipv6_addr_equals(&local, &in6addr_any)) { - struct eth_addr eth_dst = - mb->arp_attempts < PROBE_MULICAST_THRESHOLD - ? mb->data.mac - : eth_addr_zero; - - mac_binding_update_log("Sending ARP/ND request for active", - &mb->data, true, threshold, - stats->idle_age_ms, since_updated_ms); + mac_binding_update_log("Sending ARP/ND request for active", + &mb->data, true, threshold, + stats->idle_age_ms, since_updated_ms); - send_self_originated_neigh_packet(probe_data->swconn, - sbrec->datapath->tunnel_key, - pb->tunnel_key, laddr.ea, - eth_dst, &local, - &mb->data.ip, - OFTABLE_LOCAL_OUTPUT); - mb->arp_attempts++; - } + send_self_originated_neigh_packet(probe_data->swconn, + pb->datapath->tunnel_key, + pb->tunnel_key, laddr.ea, + eth_dst, &local, + &mb->data.ip, + OFTABLE_LOCAL_OUTPUT); + mb->arp_attempts++; destroy_lport_addresses(&laddr); } diff --git a/controller/mac-cache.h b/controller/mac-cache.h index f27998e40..9eeb847d1 100644 --- a/controller/mac-cache.h +++ b/controller/mac-cache.h @@ -44,8 +44,9 @@ struct mac_cache_data { struct mac_cache_threshold { struct hmap_node hmap_node; - /* Datapath tunnel key. */ + /* Datapath tunnel key or scope binding key. */ uint32_t dp_key; + bool is_scope; /* Aging threshold in ms. */ uint64_t value; /* Statistics dump period. */ @@ -59,6 +60,7 @@ struct mac_binding_data { uint64_t cookie; uint32_t port_key; uint32_t dp_key; + bool is_scope; struct in6_addr ip; /* Value. */ struct eth_addr mac; @@ -69,6 +71,7 @@ struct mac_binding_probe_data { struct uuidset *mac_binding_pending; struct rconn *swconn; struct ovsdb_idl_index *sbrec_port_binding_by_name; + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope; const struct sbrec_chassis *chassis; }; @@ -78,6 +81,7 @@ struct mac_binding { struct mac_binding_data data; /* Reference to the SB MAC binding record (Might be NULL). */ const struct sbrec_mac_binding *sbrec; + const struct sbrec_shared_mac_binding *shared_sbrec; /* User specified timestamp (in ms) */ long long timestamp; /* Number of re-ARP attempts for given entry. */ @@ -148,6 +152,10 @@ void mac_cache_threshold_replace(struct mac_cache_data *data, const struct hmap *local_datapaths); struct mac_cache_threshold * mac_cache_threshold_find(struct mac_cache_data *data, uint32_t dp_key); +void mac_cache_threshold_add_scope( + struct mac_cache_data *, const struct sbrec_mac_binding_scope *); +struct mac_cache_threshold *mac_cache_threshold_find_scope( + struct mac_cache_data *, uint32_t binding_key); void mac_cache_thresholds_sync(struct mac_cache_data *data, const struct hmap *local_datapaths); void mac_cache_thresholds_clear(struct mac_cache_data *data); @@ -163,6 +171,7 @@ mac_binding_data_init(struct mac_binding_data *data, .cookie = 0, .dp_key = (dp_key), .port_key = (port_key), + .is_scope = false, .ip = (ip), .mac = (mac), }; @@ -170,6 +179,9 @@ mac_binding_data_init(struct mac_binding_data *data, void mac_binding_add(struct hmap *map, struct mac_binding_data mb_data, const struct sbrec_mac_binding *, long long timestamp); +void mac_binding_add_shared( + struct hmap *, struct mac_binding_data, + const struct sbrec_shared_mac_binding *, long long timestamp); void mac_binding_remove(struct hmap *map, struct mac_binding *mb); @@ -181,6 +193,8 @@ bool mac_binding_data_parse(struct mac_binding_data *data, const char *ip_str, const char *mac_str); bool mac_binding_data_from_sbrec(struct mac_binding_data *data, const struct sbrec_mac_binding *mb); +bool mac_binding_data_from_shared_sbrec( + struct mac_binding_data *, const struct sbrec_shared_mac_binding *); void mac_bindings_clear(struct hmap *map); void mac_bindings_to_string(const struct hmap *map, struct ds *out_data); @@ -234,7 +248,9 @@ bool buffered_packets_lookup_run(struct cmap *bp_map, struct ovsdb_idl_index *sbrec_pb_by_key, struct ovsdb_idl_index *sbrec_dp_by_key, struct ovsdb_idl_index *sbrec_pb_by_name, - struct ovsdb_idl_index *sbrec_mb_by_lport_ip); + struct ovsdb_idl_index *sbrec_mb_by_lport_ip, + struct ovsdb_idl_index + *shared_mb_by_scope_ip); void buffered_packets_run(struct cmap *bp_map, struct vector *rpd); @@ -243,6 +259,9 @@ void buffered_packets_map_destroy(struct cmap *bp_map); void mac_binding_probe_stats_process_flow_stats( struct vector *stats_vec, struct ofputil_flow_stats *ofp_stats); +void shared_mac_binding_probe_stats_process_flow_stats( + struct vector *stats_vec, + struct ofputil_flow_stats *ofp_stats); void mac_binding_probe_stats_run(struct vector *stats_vec, uint64_t *req_delay, void *data, struct uuidset *pending, diff --git a/controller/neighbor-of.c b/controller/neighbor-of.c index d48fe4422..b79038ca0 100644 --- a/controller/neighbor-of.c +++ b/controller/neighbor-of.c @@ -18,25 +18,28 @@ #include "lflow.h" #include "neighbor-of.h" #include "openvswitch/match.h" +#include "openvswitch/vlog.h" #include "ovn/logical-fields.h" -void -consider_neighbor_flow(const struct sbrec_port_binding *pb, - const struct uuid *neighbor_uuid, - const struct in6_addr *ip, struct eth_addr mac, - struct ovn_desired_flow_table *flow_table, - enum neigh_of_rule_prio priority, - bool needs_usage_tracking) +VLOG_DEFINE_THIS_MODULE(neighbor_of); + +static void +consider_neighbor_flow__(uint32_t dp_key, uint32_t port_key, + const struct uuid *neighbor_uuid, + const struct in6_addr *ip, struct eth_addr mac, + struct ovn_desired_flow_table *flow_table, + uint8_t binding_table, uint8_t lookup_table, + enum neigh_of_rule_prio priority, + bool needs_usage_tracking, bool clear_on_mismatch) { struct match get_arp_match = MATCH_CATCHALL_INITIALIZER; struct match lookup_arp_match = MATCH_CATCHALL_INITIALIZER; struct match mb_cache_use_match = MATCH_CATCHALL_INITIALIZER; struct match lookup_arp_for_stats_match = MATCH_CATCHALL_INITIALIZER; - match_set_dl_src(&lookup_arp_match, mac); - match_set_metadata(&lookup_arp_match, htonll(pb->datapath->tunnel_key)); + match_set_metadata(&lookup_arp_match, htonll(dp_key)); match_set_reg(&lookup_arp_match, MFF_LOG_INPORT - MFF_REG0, - pb->tunnel_key); + port_key); if (IN6_IS_ADDR_V4MAPPED(ip)) { ovs_be32 ip_addr = in6_addr_get_mapped_ipv4(ip); @@ -44,6 +47,7 @@ consider_neighbor_flow(const struct sbrec_port_binding *pb, match_set_dl_type(&lookup_arp_match, htons(ETH_TYPE_ARP)); lookup_arp_for_stats_match = lookup_arp_match; + match_set_dl_src(&lookup_arp_for_stats_match, mac); match_set_reg(&lookup_arp_match, 0, ntohl(ip_addr)); @@ -67,31 +71,42 @@ consider_neighbor_flow(const struct sbrec_port_binding *pb, match_set_ipv6_src(&mb_cache_use_match, ip); } - match_set_metadata(&get_arp_match, htonll(pb->datapath->tunnel_key)); - match_set_reg(&get_arp_match, MFF_LOG_OUTPORT - MFF_REG0, pb->tunnel_key); + struct match lookup_ip_match = lookup_arp_match; + match_set_dl_src(&lookup_arp_match, mac); + + match_set_metadata(&get_arp_match, htonll(dp_key)); + match_set_reg(&get_arp_match, MFF_LOG_OUTPORT - MFF_REG0, port_key); match_set_dl_src(&mb_cache_use_match, mac); match_set_reg(&mb_cache_use_match, MFF_LOG_INPORT - MFF_REG0, - pb->tunnel_key); - match_set_metadata(&mb_cache_use_match, htonll(pb->datapath->tunnel_key)); + port_key); + match_set_metadata(&mb_cache_use_match, htonll(dp_key)); uint64_t stub[1024 / 8]; struct ofpbuf ofpacts = OFPBUF_STUB_INITIALIZER(stub); put_load_bytes(mac.ea, sizeof mac.ea, MFF_ETH_DST, 0, 48, &ofpacts); put_load(1, MFF_LOG_FLAGS, MLF_LOOKUP_MAC_BIT, 1, &ofpacts); - ofctrl_add_flow(flow_table, OFTABLE_MAC_BINDING, priority, + ofctrl_add_flow(flow_table, binding_table, priority, neighbor_uuid->parts[0], &get_arp_match, &ofpacts, neighbor_uuid); ofpbuf_clear(&ofpacts); put_load(1, MFF_LOG_FLAGS, MLF_LOOKUP_MAC_BIT, 1, &ofpacts); - ofctrl_add_flow(flow_table, OFTABLE_MAC_LOOKUP, priority, + ofctrl_add_flow(flow_table, lookup_table, priority, neighbor_uuid->parts[0], &lookup_arp_match, &ofpacts, neighbor_uuid); + if (clear_on_mismatch) { + ofpbuf_clear(&ofpacts); + put_load(0, MFF_LOG_FLAGS, MLF_LOOKUP_MAC_BIT, 1, &ofpacts); + ofctrl_add_flow(flow_table, lookup_table, priority - 1, + neighbor_uuid->parts[0], &lookup_ip_match, + &ofpacts, neighbor_uuid); + } + if (needs_usage_tracking) { ofpbuf_clear(&ofpacts); if (IN6_IS_ADDR_V4MAPPED(ip)) { @@ -107,3 +122,54 @@ consider_neighbor_flow(const struct sbrec_port_binding *pb, ofpbuf_uninit(&ofpacts); } + +void +consider_neighbor_flow(const struct sbrec_port_binding *pb, + const struct uuid *neighbor_uuid, + const struct in6_addr *ip, struct eth_addr mac, + struct ovn_desired_flow_table *flow_table, + enum neigh_of_rule_prio priority, + bool needs_usage_tracking) +{ + consider_neighbor_flow__(pb->datapath->tunnel_key, pb->tunnel_key, + neighbor_uuid, ip, mac, flow_table, + OFTABLE_MAC_BINDING, OFTABLE_MAC_LOOKUP, + priority, needs_usage_tracking, false); + + if (priority == NEIGH_OF_STATIC_MAC_BINDING_HIGH_PRIO && + pb->mac_binding_scope) { + consider_neighbor_flow__(pb->datapath->tunnel_key, pb->tunnel_key, + neighbor_uuid, ip, mac, flow_table, + OFTABLE_MAC_BINDING_OVERRIDE, + OFTABLE_MAC_LOOKUP_OVERRIDE, + NEIGH_OF_DYNAMIC_MAC_BINDING_PRIO, + false, true); + } +} + +void +consider_shared_neighbor_flow(const struct sbrec_shared_mac_binding *mb, + struct ovn_desired_flow_table *flow_table, + bool needs_usage_tracking) +{ + struct eth_addr mac; + struct in6_addr ip; + + if (!eth_addr_from_string(mb->mac, &mac)) { + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); + VLOG_WARN_RL(&rl, "bad 'mac' %s", mb->mac); + return; + } + if (!ip46_parse(mb->ip, &ip)) { + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1); + VLOG_WARN_RL(&rl, "bad 'ip' %s", mb->ip); + return; + } + + consider_neighbor_flow__(mb->scope->binding_key, 0, + &mb->header_.uuid, &ip, mac, flow_table, + OFTABLE_SHARED_MAC_BINDING, + OFTABLE_SHARED_MAC_LOOKUP, + NEIGH_OF_DYNAMIC_MAC_BINDING_PRIO, + needs_usage_tracking, true); +} diff --git a/controller/neighbor-of.h b/controller/neighbor-of.h index d91074a1e..c45168721 100644 --- a/controller/neighbor-of.h +++ b/controller/neighbor-of.h @@ -44,4 +44,8 @@ consider_neighbor_flow(const struct sbrec_port_binding *, enum neigh_of_rule_prio priority, bool needs_usage_tracking); +void consider_shared_neighbor_flow( + const struct sbrec_shared_mac_binding *, + struct ovn_desired_flow_table *, bool needs_usage_tracking); + #endif /* NEIGHBOR_OF_H */ diff --git a/controller/ovn-controller.8.xml b/controller/ovn-controller.8.xml index 2b90f25d9..78b6d5a9e 100644 --- a/controller/ovn-controller.8.xml +++ b/controller/ovn-controller.8.xml @@ -894,6 +894,24 @@ db="OVN_Southbound"/>, and <ref table="Learned_Route" column="nexthop" db="OVN_Southbound"/> columns. </dd> + + <dt><ref table="Shared_MAC_Binding" db="OVN_Southbound"/></dt> + <dd> + <code>ovn-controller</code> creates and updates rows when + <code>put_arp</code> and <code>put_nd</code> logical actions learn on + a port in a MAC binding scope, and when locally simulating gratuitous + ARP for scoped ports. It also creates, updates, and removes rows + while synchronizing EVPN neighbors. It writes the + <ref table="Shared_MAC_Binding" column="scope" db="OVN_Southbound"/>, + <ref table="Shared_MAC_Binding" column="ip" db="OVN_Southbound"/>, + <ref table="Shared_MAC_Binding" column="mac" db="OVN_Southbound"/>, and + <ref table="Shared_MAC_Binding" column="timestamp" + db="OVN_Southbound"/> columns. For scopes with aging enabled, it + refreshes timestamps for active bindings and synchronized EVPN + neighbors. Learned bindings can outlive the controller; + <code>ovn-northd</code> ages them and removes bindings when their + scope is withdrawn. + </dd> </dl> <h1>Runtime Management Commands</h1> diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index 5343753ca..3c371cc6f 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -262,6 +262,8 @@ update_sb_monitors(struct ovsdb_idl *ovnsb_idl, struct ovsdb_idl_condition lf = OVSDB_IDL_CONDITION_INIT(&lf); struct ovsdb_idl_condition ldpg = OVSDB_IDL_CONDITION_INIT(&ldpg); struct ovsdb_idl_condition mb = OVSDB_IDL_CONDITION_INIT(&mb); + struct ovsdb_idl_condition shared_mb = + OVSDB_IDL_CONDITION_INIT(&shared_mb); struct ovsdb_idl_condition fdb = OVSDB_IDL_CONDITION_INIT(&fdb); struct ovsdb_idl_condition mg = OVSDB_IDL_CONDITION_INIT(&mg); struct ovsdb_idl_condition dns = OVSDB_IDL_CONDITION_INIT(&dns); @@ -298,6 +300,7 @@ update_sb_monitors(struct ovsdb_idl *ovnsb_idl, ovsdb_idl_condition_add_clause_true(&pb); ovsdb_idl_condition_add_clause_true(&lf); ovsdb_idl_condition_add_clause_true(&mb); + ovsdb_idl_condition_add_clause_true(&shared_mb); ovsdb_idl_condition_add_clause_true(&fdb); ovsdb_idl_condition_add_clause_true(&mg); ovsdb_idl_condition_add_clause_true(&dns); @@ -429,6 +432,23 @@ update_sb_monitors(struct ovsdb_idl *ovnsb_idl, * request all of them. */ sbrec_logical_flow_add_clause_logical_dp_group(&lf, OVSDB_F_NE, NULL); + + struct uuidset local_scopes = UUIDSET_INITIALIZER(&local_scopes); + const struct sbrec_port_binding *pb_row; + SBREC_PORT_BINDING_FOR_EACH (pb_row, ovnsb_idl) { + if (pb_row->datapath && pb_row->mac_binding_scope && + get_local_datapath(local_datapaths, + pb_row->datapath->tunnel_key)) { + uuidset_insert(&local_scopes, + &pb_row->mac_binding_scope->header_.uuid); + } + } + const struct uuidset_node *scope_node; + UUIDSET_FOR_EACH (scope_node, &local_scopes) { + sbrec_shared_mac_binding_add_clause_scope( + &shared_mb, OVSDB_F_EQ, &scope_node->uuid); + } + uuidset_destroy(&local_scopes); } out:; @@ -437,6 +457,7 @@ out:; sbrec_logical_flow_set_condition(ovnsb_idl, &lf), sbrec_logical_dp_group_set_condition(ovnsb_idl, &ldpg), sbrec_mac_binding_set_condition(ovnsb_idl, &mb), + sbrec_shared_mac_binding_set_condition(ovnsb_idl, &shared_mb), sbrec_fdb_set_condition(ovnsb_idl, &fdb), sbrec_multicast_group_set_condition(ovnsb_idl, &mg), sbrec_dns_set_condition(ovnsb_idl, &dns), @@ -460,6 +481,7 @@ out:; ovsdb_idl_condition_destroy(&lf); ovsdb_idl_condition_destroy(&ldpg); ovsdb_idl_condition_destroy(&mb); + ovsdb_idl_condition_destroy(&shared_mb); ovsdb_idl_condition_destroy(&fdb); ovsdb_idl_condition_destroy(&mg); ovsdb_idl_condition_destroy(&dns); @@ -3273,6 +3295,81 @@ mac_binding_remove_sb(struct mac_cache_data *data, mac_binding_remove(&data->mac_bindings, mb); } +static void +shared_mac_binding_add_sb( + struct mac_cache_data *data, + const struct sbrec_shared_mac_binding *smb) +{ + struct mac_binding_data mb_data; + if (!mac_binding_data_from_shared_sbrec(&mb_data, smb)) { + return; + } + + mac_binding_add_shared(&data->mac_bindings, mb_data, smb, 0); +} + +static void +shared_mac_binding_remove_sb( + struct mac_cache_data *data, + const struct sbrec_shared_mac_binding *smb) +{ + struct mac_binding_data mb_data; + if (!mac_binding_data_from_shared_sbrec(&mb_data, smb)) { + return; + } + + struct mac_binding *mb = mac_binding_find(&data->mac_bindings, &mb_data); + if (mb) { + mac_binding_remove(&data->mac_bindings, mb); + } +} + +static bool +mac_cache_scope_is_local(struct ovsdb_idl_index *pb_by_scope, + const struct sbrec_mac_binding_scope *scope, + const struct hmap *local_datapaths) +{ + struct sbrec_port_binding *target = + sbrec_port_binding_index_init_row(pb_by_scope); + sbrec_port_binding_index_set_mac_binding_scope(target, scope); + + const struct sbrec_port_binding *pb; + bool is_local = false; + SBREC_PORT_BINDING_FOR_EACH_EQUAL (pb, target, pb_by_scope) { + if (pb->datapath && get_local_datapath( + local_datapaths, pb->datapath->tunnel_key)) { + is_local = true; + break; + } + } + sbrec_port_binding_index_destroy_row(target); + return is_local; +} + +static void +mac_cache_mb_handle_for_scope( + struct mac_cache_data *data, + const struct sbrec_mac_binding_scope *scope, + struct ovsdb_idl_index *shared_mb_by_scope) +{ + bool has_threshold = + !!mac_cache_threshold_find_scope(data, scope->binding_key); + struct sbrec_shared_mac_binding *target = + sbrec_shared_mac_binding_index_init_row(shared_mb_by_scope); + sbrec_shared_mac_binding_index_set_scope(target, scope); + + const struct sbrec_shared_mac_binding *mb; + SBREC_SHARED_MAC_BINDING_FOR_EACH_EQUAL ( + mb, target, shared_mb_by_scope) { + if (has_threshold) { + shared_mac_binding_add_sb(data, mb); + } else { + shared_mac_binding_remove_sb(data, mb); + } + } + sbrec_shared_mac_binding_index_destroy_row(target); +} + static void fdb_add_sb(struct mac_cache_data *data, const struct sbrec_fdb *sfdb) { @@ -3377,6 +3474,13 @@ en_mac_cache_run(struct engine_node *node, void *data) engine_ovsdb_node_get_index( engine_get_input("SB_fdb", node), "dp_key"); + const struct sbrec_mac_binding_scope_table *scope_table = + EN_OVSDB_GET(engine_get_input("SB_mac_binding_scope", node)); + struct ovsdb_idl_index *pb_by_scope = engine_ovsdb_node_get_index( + engine_get_input("SB_port_binding", node), "mac_binding_scope"); + struct ovsdb_idl_index *shared_mb_by_scope = + engine_ovsdb_node_get_index( + engine_get_input("SB_shared_mac_binding", node), "scope"); mac_cache_thresholds_clear(cache_data); mac_bindings_clear(&cache_data->mac_bindings); @@ -3396,9 +3500,73 @@ en_mac_cache_run(struct engine_node *node, void *data) sbrec_fdb_by_dp_key); } + const struct sbrec_mac_binding_scope *scope; + SBREC_MAC_BINDING_SCOPE_TABLE_FOR_EACH (scope, scope_table) { + if (!mac_cache_scope_is_local(pb_by_scope, scope, + &rt_data->local_datapaths)) { + continue; + } + mac_cache_threshold_add_scope(cache_data, scope); + mac_cache_mb_handle_for_scope(cache_data, scope, + shared_mb_by_scope); + } + return EN_UPDATED; } +static enum engine_input_handler_result +mac_cache_sb_shared_mac_binding_handler(struct engine_node *node, void *data) +{ + struct mac_cache_data *cache_data = data; + const struct sbrec_shared_mac_binding_table *mb_table = + EN_OVSDB_GET(engine_get_input("SB_shared_mac_binding", node)); + size_t previous_size = hmap_count(&cache_data->mac_bindings); + + const struct sbrec_shared_mac_binding *mb; + SBREC_SHARED_MAC_BINDING_TABLE_FOR_EACH_TRACKED (mb, mb_table) { + if (!sbrec_shared_mac_binding_is_new(mb) && + (sbrec_shared_mac_binding_is_updated( + mb, SBREC_SHARED_MAC_BINDING_COL_SCOPE) || + sbrec_shared_mac_binding_is_updated( + mb, SBREC_SHARED_MAC_BINDING_COL_IP))) { + return EN_UNHANDLED; + } + if (!sbrec_shared_mac_binding_is_new(mb)) { + shared_mac_binding_remove_sb(cache_data, mb); + } + if (!sbrec_shared_mac_binding_is_deleted(mb) && + mac_cache_threshold_find_scope(cache_data, + mb->scope->binding_key)) { + shared_mac_binding_add_sb(cache_data, mb); + } + } + + return hmap_count(&cache_data->mac_bindings) != previous_size + ? EN_HANDLED_UPDATED : EN_HANDLED_UNCHANGED; +} + +static enum engine_input_handler_result +mac_cache_sb_port_binding_handler(struct engine_node *node, + void *data OVS_UNUSED) +{ + const struct sbrec_port_binding_table *pb_table = + EN_OVSDB_GET(engine_get_input("SB_port_binding", node)); + const struct sbrec_port_binding *pb; + + SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (pb, pb_table) { + if (sbrec_port_binding_is_updated( + pb, SBREC_PORT_BINDING_COL_MAC_BINDING_SCOPE) || + (pb->mac_binding_scope && + (sbrec_port_binding_is_updated( + pb, SBREC_PORT_BINDING_COL_DATAPATH) || + sbrec_port_binding_is_new(pb) || + sbrec_port_binding_is_deleted(pb)))) { + return EN_UNHANDLED; + } + } + return EN_HANDLED_UNCHANGED; +} + static enum engine_input_handler_result mac_cache_sb_mac_binding_handler(struct engine_node *node, void *data) { @@ -3484,6 +3652,12 @@ mac_cache_runtime_data_handler(struct engine_node *node, void *data OVS_UNUSED) engine_ovsdb_node_get_index( engine_get_input("SB_fdb", node), "dp_key"); + const struct sbrec_mac_binding_scope_table *scope_table = + EN_OVSDB_GET(engine_get_input("SB_mac_binding_scope", node)); + + if (sbrec_mac_binding_scope_table_first(scope_table)) { + return EN_UNHANDLED; + } /* There are no tracked data. Fall back to full recompute. */ if (!rt_data->tracked) { @@ -3534,6 +3708,12 @@ mac_cache_sb_datapath_binding_handler(struct engine_node *node, void *data) engine_ovsdb_node_get_index( engine_get_input("SB_fdb", node), "dp_key"); + const struct sbrec_mac_binding_scope_table *scope_table = + EN_OVSDB_GET(engine_get_input("SB_mac_binding_scope", node)); + + if (sbrec_mac_binding_scope_table_first(scope_table)) { + return EN_UNHANDLED; + } size_t previous_mb_size = hmap_count(&cache_data->mac_bindings); size_t previous_fdb_size = hmap_count(&cache_data->fdbs); @@ -3970,6 +4150,11 @@ init_lflow_ctx(struct engine_node *node, engine_get_input("SB_static_mac_binding", node), "datapath"); + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope = + engine_ovsdb_node_get_index( + engine_get_input("SB_port_binding", node), + "mac_binding_scope"); + const struct sbrec_port_binding_table *port_binding_table = EN_OVSDB_GET(engine_get_input("SB_port_binding", node)); @@ -3991,6 +4176,9 @@ init_lflow_ctx(struct engine_node *node, const struct sbrec_static_mac_binding_table *smb_table = EN_OVSDB_GET(engine_get_input("SB_static_mac_binding", node)); + const struct sbrec_shared_mac_binding_table *shared_mb_table = + EN_OVSDB_GET(engine_get_input("SB_shared_mac_binding", node)); + const struct ovsrec_open_vswitch_table *ovs_table = EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node)); @@ -4041,6 +4229,8 @@ init_lflow_ctx(struct engine_node *node, l_ctx_in->sbrec_mac_binding_by_datapath = sbrec_mac_binding_by_datapath; l_ctx_in->sbrec_static_mac_binding_by_datapath = sbrec_static_mac_binding_by_datapath; + l_ctx_in->sbrec_port_binding_by_mac_binding_scope = + sbrec_port_binding_by_mac_binding_scope; l_ctx_in->port_binding_table = port_binding_table; l_ctx_in->mac_binding_table = mac_binding_table; l_ctx_in->logical_flow_table = logical_flow_table; @@ -4049,6 +4239,11 @@ init_lflow_ctx(struct engine_node *node, l_ctx_in->fdb_table = fdb_table, l_ctx_in->chassis = chassis; l_ctx_in->static_mac_binding_table = smb_table; + l_ctx_in->shared_mac_binding_table = shared_mb_table; + l_ctx_in->sbrec_port_binding_by_datapath = engine_ovsdb_node_get_index( + engine_get_input("SB_port_binding", node), "datapath"); + l_ctx_in->sbrec_shared_mac_binding_by_scope = engine_ovsdb_node_get_index( + engine_get_input("SB_shared_mac_binding", node), "scope"); l_ctx_in->local_datapaths = &rt_data->local_datapaths; l_ctx_in->addr_sets = addr_sets; l_ctx_in->port_groups = port_groups; @@ -4312,6 +4507,34 @@ lflow_output_sb_mac_binding_handler(struct engine_node *node, void *data) return EN_HANDLED_UPDATED; } +static enum engine_input_handler_result +lflow_output_sb_shared_mac_binding_handler(struct engine_node *node, + void *data) +{ + struct ovsdb_idl_index *pb_by_scope = engine_ovsdb_node_get_index( + engine_get_input("SB_port_binding", node), "mac_binding_scope"); + const struct sbrec_shared_mac_binding_table *shared_mb_table = + EN_OVSDB_GET(engine_get_input("SB_shared_mac_binding", node)); + struct ed_type_runtime_data *rt_data = + engine_get_input_data("runtime_data", node); + struct ed_type_lflow_output *lfo = data; + const struct ovsrec_open_vswitch_table *ovs_table = + EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node)); + const char *chassis_id = get_ovs_chassis_id(ovs_table); + if (!chassis_id) { + return EN_UNHANDLED; + } + struct ovsdb_idl_index *chassis_by_name = engine_ovsdb_node_get_index( + engine_get_input("SB_chassis", node), "name"); + const struct sbrec_chassis *chassis = + chassis_lookup_by_name(chassis_by_name, chassis_id); + + lflow_handle_changed_shared_mac_bindings( + pb_by_scope, shared_mb_table, &rt_data->local_datapaths, + chassis, &lfo->flow_table); + return EN_HANDLED_UPDATED; +} + static enum engine_input_handler_result lflow_output_sb_static_mac_binding_handler(struct engine_node *node, void *data) @@ -6083,6 +6306,10 @@ en_garp_rarp_run(struct engine_node *node, void *data_) engine_ovsdb_node_get_index( engine_get_input("SB_mac_binding", node), "lport_ip"); + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip = + engine_ovsdb_node_get_index( + engine_get_input("SB_shared_mac_binding", node), + "scope_ip"); struct ed_type_runtime_data *rt_data = engine_get_input_data("runtime_data", node); @@ -6093,6 +6320,7 @@ en_garp_rarp_run(struct engine_node *node, void *data_) .sbrec_port_binding_by_datapath = sbrec_port_binding_by_datapath, .sbrec_port_binding_by_name = sbrec_port_binding_by_name, .sbrec_mac_binding_by_lport_ip = sbrec_mac_binding_by_lport_ip, + .shared_mac_binding_by_scope_ip = shared_mac_binding_by_scope_ip, .chassis = chassis, .active_tunnels = &rt_data->active_tunnels, .local_datapaths = &rt_data->local_datapaths, @@ -7191,6 +7419,12 @@ en_evpn_mac_binding_sync_run(struct engine_node *node, void *data_) engine_ovsdb_node_get_index(sb_mb_node, "lport_ip"); const struct sbrec_mac_binding_table *mb_table = EN_OVSDB_GET(sb_mb_node); + struct engine_node *shared_mb_node = + engine_get_input("SB_shared_mac_binding", node); + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip = + engine_ovsdb_node_get_index(shared_mb_node, "scope_ip"); + const struct sbrec_shared_mac_binding_table *shared_mb_table = + EN_OVSDB_GET(shared_mb_node); struct evpn_mb_sync_waker *waker = engine_get_input_data("evpn_mac_binding_sync_waker", node); @@ -7200,7 +7434,9 @@ en_evpn_mac_binding_sync_run(struct engine_node *node, void *data_) evpn_mac_binding_sync_run(engine_get_context()->ovnsb_idl_txn, sbrec_mac_binding_by_lport_ip, + shared_mac_binding_by_scope_ip, mb_table, + shared_mb_table, &rt_data->local_datapaths, &earp_data->arps, mac_cache_data, @@ -7244,6 +7480,10 @@ evpn_mac_binding_sync_sb_port_binding_handler(struct engine_node *node, const struct sbrec_port_binding *pb; SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (pb, port_binding_table) { + if (sbrec_port_binding_is_updated( + pb, SBREC_PORT_BINDING_COL_MAC_BINDING_SCOPE)) { + return EN_UNHANDLED; + } if (sbrec_port_binding_is_deleted(pb) && uuidset_contains(&data->lsp_peers, &pb->header_.uuid)) { return EN_UNHANDLED; @@ -7253,23 +7493,27 @@ evpn_mac_binding_sync_sb_port_binding_handler(struct engine_node *node, uuidset_contains(&data->lsp_peers, &pb->header_.uuid) && (sbrec_port_binding_is_updated(pb, SBREC_PORT_BINDING_COL_OPTIONS) || - sbrec_port_binding_is_updated(pb, SBREC_PORT_BINDING_COL_TYPE))) { + sbrec_port_binding_is_updated(pb, SBREC_PORT_BINDING_COL_TYPE) || + sbrec_port_binding_is_updated(pb, + SBREC_PORT_BINDING_COL_CHASSIS))) { return EN_UNHANDLED; } - if (!sbrec_port_binding_is_new(pb)) { + /* A gateway peer may not be usable until both ends are claimed. + * Reconsider it on binding changes even if the first sync skipped it + * and therefore did not record it in lsp_peers. */ + if (!sbrec_port_binding_is_new(pb) && + !sbrec_port_binding_is_updated(pb, + SBREC_PORT_BINDING_COL_CHASSIS) && + !sbrec_port_binding_is_updated(pb, + SBREC_PORT_BINDING_COL_OPTIONS) && + !sbrec_port_binding_is_updated(pb, SBREC_PORT_BINDING_COL_TYPE)) { continue; } struct local_datapath *ld = get_local_datapath( &rt_data->local_datapaths, pb->datapath->tunnel_key); - if (!ld || !ld->is_switch) { - continue; - } - - int64_t vni = ovn_smap_get_llong(&ld->datapath->external_ids, - "dynamic-routing-vni", -1); - if (!ovn_is_valid_vni(vni)) { + if (!ld) { continue; } @@ -7287,7 +7531,14 @@ evpn_mac_binding_sync_sb_port_binding_handler(struct engine_node *node, struct local_datapath *peer_ld = get_local_datapath(&rt_data->local_datapaths, peer->datapath->tunnel_key); - if (!peer_ld || peer_ld->is_switch) { + if (!peer_ld || ld->is_switch == peer_ld->is_switch) { + continue; + } + + const struct local_datapath *switch_ld = ld->is_switch ? ld : peer_ld; + int64_t vni = ovn_smap_get_llong(&switch_ld->datapath->external_ids, + "dynamic-routing-vni", -1); + if (!ovn_is_valid_vni(vni)) { continue; } @@ -7316,6 +7567,8 @@ evpn_mac_binding_sync_sb_port_binding_handler(struct engine_node *node, SB_NODE(logical_dp_group) \ SB_NODE(port_binding) \ SB_NODE(mac_binding) \ + SB_NODE(mac_binding_scope) \ + SB_NODE(shared_mac_binding) \ SB_NODE(logical_flow) \ SB_NODE(dhcp_options) \ SB_NODE(dhcpv6_options) \ @@ -7591,6 +7844,9 @@ inc_proc_ovn_controller_init( engine_add_input(&en_lflow_output, &en_sb_mac_binding, lflow_output_sb_mac_binding_handler); + engine_add_input(&en_lflow_output, &en_sb_shared_mac_binding, + lflow_output_sb_shared_mac_binding_handler); + engine_add_input(&en_lflow_output, &en_sb_mac_binding_scope, NULL); engine_add_input(&en_lflow_output, &en_sb_static_mac_binding, lflow_output_sb_static_mac_binding_handler); engine_add_input(&en_lflow_output, &en_sb_logical_flow, @@ -7653,12 +7909,15 @@ inc_proc_ovn_controller_init( mac_cache_runtime_data_handler); engine_add_input(&en_mac_cache, &en_sb_mac_binding, mac_cache_sb_mac_binding_handler); + engine_add_input(&en_mac_cache, &en_sb_shared_mac_binding, + mac_cache_sb_shared_mac_binding_handler); + engine_add_input(&en_mac_cache, &en_sb_mac_binding_scope, NULL); engine_add_input(&en_mac_cache, &en_sb_fdb, mac_cache_sb_fdb_handler); engine_add_input(&en_mac_cache, &en_sb_datapath_binding, mac_cache_sb_datapath_binding_handler); engine_add_input(&en_mac_cache, &en_sb_port_binding, - engine_noop_handler); + mac_cache_sb_port_binding_handler); engine_add_input(&en_dns_cache, &en_sb_dns, dns_cache_sb_dns_handler); @@ -7672,6 +7931,9 @@ inc_proc_ovn_controller_init( /* The mac_binding data is just used in an index to filter duplicates when * inserting data to the southbound. */ engine_add_input(&en_garp_rarp, &en_sb_mac_binding, engine_noop_handler); + engine_add_input(&en_garp_rarp, &en_sb_shared_mac_binding, + engine_noop_handler); + engine_add_input(&en_garp_rarp, &en_sb_mac_binding_scope, NULL); engine_add_input(&en_garp_rarp, &en_runtime_data, garp_rarp_runtime_data_handler); @@ -7722,12 +7984,18 @@ inc_proc_ovn_controller_init( /* MAC_Binding data is only used via an index for lookups. */ engine_add_input(&en_evpn_mac_binding_sync, &en_sb_mac_binding, engine_noop_handler); + engine_add_input(&en_evpn_mac_binding_sync, &en_sb_shared_mac_binding, + engine_noop_handler); /* Runtime data is only used for local_datapaths access. */ engine_add_input(&en_evpn_mac_binding_sync, &en_runtime_data, engine_noop_handler); /* MAC cache data is only used for aging threshold lookup. */ engine_add_input(&en_evpn_mac_binding_sync, &en_mac_cache, engine_noop_handler); + /* Enabling scope aging must start EVPN timestamp refreshes even when + * no refresh was scheduled under the previous policy. */ + engine_add_input(&en_evpn_mac_binding_sync, &en_sb_mac_binding_scope, + NULL); engine_add_input(&en_evpn_mac_binding_sync, &en_sb_ro, evpn_mac_binding_sync_sb_ro_handler); engine_add_input(&en_evpn_mac_binding_sync, &en_sb_port_binding, @@ -7793,6 +8061,13 @@ inc_proc_ovn_controller_init( engine_ovsdb_node_add_index(&en_sb_port_binding, "key", sbrec_port_binding_by_key); + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope = + ovsdb_idl_index_create1( + sb_idl_loop->idl, + &sbrec_port_binding_col_mac_binding_scope); + engine_ovsdb_node_add_index(&en_sb_port_binding, "mac_binding_scope", + sbrec_port_binding_by_mac_binding_scope); + struct ovsdb_idl_index *sbrec_port_binding_by_datapath = ovsdb_idl_index_create1(sb_idl_loop->idl, &sbrec_port_binding_col_datapath); @@ -7839,6 +8114,16 @@ inc_proc_ovn_controller_init( engine_ovsdb_node_add_index(&en_sb_mac_binding, "lport_ip", sbrec_mac_binding_by_lport_ip); + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip = + shared_mac_binding_by_scope_ip_index_create(sb_idl_loop->idl); + engine_ovsdb_node_add_index(&en_sb_shared_mac_binding, "scope_ip", + shared_mac_binding_by_scope_ip); + struct ovsdb_idl_index *shared_mac_binding_by_scope = + ovsdb_idl_index_create1(sb_idl_loop->idl, + &sbrec_shared_mac_binding_col_scope); + engine_ovsdb_node_add_index(&en_sb_shared_mac_binding, "scope", + shared_mac_binding_by_scope); + engine_ovsdb_node_add_index(&en_ovs_flow_sample_collector_set, "id", ovsrec_flow_sample_collector_set_by_id); engine_ovsdb_node_add_index(&en_ovs_port, "qos", ovsrec_port_by_qos); @@ -8027,6 +8312,10 @@ main(int argc, char *argv[]) struct ovsdb_idl_index *sbrec_port_binding_by_type = ovsdb_idl_index_create1(ovnsb_idl_loop.idl, &sbrec_port_binding_col_type); + struct ovsdb_idl_index *sbrec_port_binding_by_mac_binding_scope + = ovsdb_idl_index_create1( + ovnsb_idl_loop.idl, + &sbrec_port_binding_col_mac_binding_scope); struct ovsdb_idl_index *sbrec_port_binding_by_requested_chassis = ovsdb_idl_index_create1(ovnsb_idl_loop.idl, &sbrec_port_binding_col_requested_chassis); @@ -8035,6 +8324,8 @@ main(int argc, char *argv[]) &sbrec_datapath_binding_col_tunnel_key); struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip = mac_binding_by_lport_ip_index_create(ovnsb_idl_loop.idl); + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip + = shared_mac_binding_by_scope_ip_index_create(ovnsb_idl_loop.idl); struct ovsdb_idl_index *sbrec_ip_multicast = ip_mcast_index_create(ovnsb_idl_loop.idl); struct ovsdb_idl_index *sbrec_igmp_group @@ -8057,6 +8348,8 @@ main(int argc, char *argv[]) * values (it does read them to implement aging). Therefore we * can disable change tracking and alerting for these columns. */ ovsdb_idl_omit_alert(ovnsb_idl_loop.idl, &sbrec_mac_binding_col_timestamp); + ovsdb_idl_omit_alert(ovnsb_idl_loop.idl, + &sbrec_shared_mac_binding_col_timestamp); ovsdb_idl_omit_alert(ovnsb_idl_loop.idl, &sbrec_fdb_col_timestamp); /* Omit the external_ids column of all the tables except for - @@ -8646,6 +8939,7 @@ main(int argc, char *argv[]) sbrec_port_binding_by_key, sbrec_port_binding_by_name, sbrec_mac_binding_by_lport_ip, + shared_mac_binding_by_scope_ip, sbrec_igmp_group, sbrec_ip_multicast, sbrec_fdb_by_dp_key_mac, @@ -8655,6 +8949,8 @@ main(int argc, char *argv[]) ovnsb_idl_loop.idl), sbrec_mac_binding_table_get( ovnsb_idl_loop.idl), + sbrec_shared_mac_binding_table_get( + ovnsb_idl_loop.idl), sbrec_bfd_table_get(ovnsb_idl_loop.idl), sbrec_ecmp_nexthop_table_get( ovnsb_idl_loop.idl), @@ -8672,10 +8968,12 @@ main(int argc, char *argv[]) sbrec_mirror_table_get(ovnsb_idl_loop.idl), br_int, &runtime_data->lbinding_data.bindings); - /* Updating monitor conditions if runtime data or - * logical datapath goups changed. */ + /* Scope membership can change without changing + * runtime data or logical datapath groups. */ if (engine_node_changed(&en_runtime_data) - || engine_node_changed(&en_sb_logical_dp_group)) { + || engine_node_changed(&en_sb_logical_dp_group) + || engine_node_changed(&en_sb_port_binding) + || engine_node_changed(&en_sb_mac_binding_scope)) { bool had_all_data = ovnsb_cond_seqno == ovnsb_expected_cond_seqno; ovnsb_expected_cond_seqno = @@ -8728,6 +9026,7 @@ main(int argc, char *argv[]) mac_cache_data = engine_get_data(&en_mac_cache); if (mac_cache_data) { statctrl_run(ovnsb_idl_txn, sbrec_port_binding_by_name, + sbrec_port_binding_by_mac_binding_scope, chassis, mac_cache_data); } diff --git a/controller/pinctrl.c b/controller/pinctrl.c index 5c9634b24..c27ad8686 100644 --- a/controller/pinctrl.c +++ b/controller/pinctrl.c @@ -199,11 +199,13 @@ static void init_buffered_packets_map(void); static void destroy_buffered_packets_map(void); static void run_buffered_binding(const struct sbrec_mac_binding_table *mac_binding_table, + const struct sbrec_shared_mac_binding_table *, const struct hmap *local_datapaths, struct ovsdb_idl_index *sbrec_port_binding_by_key, struct ovsdb_idl_index *sbrec_datapath_binding_by_key, struct ovsdb_idl_index *sbrec_port_binding_by_name, - struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip); + struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, + struct ovsdb_idl_index *shared_mb_by_scope_ip); static void pinctrl_handle_put_mac_binding(const struct flow *md, const struct flow *headers, @@ -214,7 +216,9 @@ static void run_put_mac_bindings( struct ovsdb_idl_txn *ovnsb_idl_txn, struct ovsdb_idl_index *sbrec_datapath_binding_by_key, struct ovsdb_idl_index *sbrec_port_binding_by_key, - struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip); + struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, + struct ovsdb_idl_index *sbrec_port_binding_by_name); static void wait_put_mac_bindings(void); static void send_mac_binding_buffered_pkts(struct rconn *swconn); @@ -4207,12 +4211,14 @@ pinctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, struct ovsdb_idl_index *sbrec_port_binding_by_key, struct ovsdb_idl_index *sbrec_port_binding_by_name, struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, struct ovsdb_idl_index *sbrec_igmp_groups, struct ovsdb_idl_index *sbrec_ip_multicast_opts, struct ovsdb_idl_index *sbrec_fdb_by_dp_key_mac, const struct sbrec_controller_event_table *ce_table, const struct sbrec_service_monitor_table *svc_mon_table, const struct sbrec_mac_binding_table *mac_binding_table, + const struct sbrec_shared_mac_binding_table *shared_mb_table, const struct sbrec_bfd_table *bfd_table, const struct sbrec_ecmp_nexthop_table *ecmp_nh_table, const struct sbrec_chassis *chassis, @@ -4248,14 +4254,17 @@ pinctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, sbrec_port_binding_by_key, chassis); ovs_mutex_unlock(&pinctrl_mutex); - run_buffered_binding(mac_binding_table, local_datapaths, + run_buffered_binding(mac_binding_table, shared_mb_table, local_datapaths, sbrec_port_binding_by_key, sbrec_datapath_binding_by_key, sbrec_port_binding_by_name, - sbrec_mac_binding_by_lport_ip); + sbrec_mac_binding_by_lport_ip, + shared_mac_binding_by_scope_ip); run_put_mac_bindings(ovnsb_idl_txn, sbrec_datapath_binding_by_key, sbrec_port_binding_by_key, - sbrec_mac_binding_by_lport_ip); + sbrec_mac_binding_by_lport_ip, + shared_mac_binding_by_scope_ip, + sbrec_port_binding_by_name); run_put_fdbs(ovnsb_idl_txn, sbrec_port_binding_by_key, sbrec_datapath_binding_by_key, sbrec_fdb_by_dp_key_mac, cur_cfg); @@ -4907,6 +4916,8 @@ run_put_mac_binding(struct ovsdb_idl_txn *ovnsb_idl_txn, struct ovsdb_idl_index *sbrec_datapath_binding_by_key, struct ovsdb_idl_index *sbrec_port_binding_by_key, struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, + struct ovsdb_idl_index *shared_mb_by_scope_ip, + struct ovsdb_idl_index *sbrec_port_binding_by_name, const struct mac_binding *mb) { /* Convert logical datapath and logical port key into lport. */ @@ -4921,16 +4932,30 @@ run_put_mac_binding(struct ovsdb_idl_txn *ovnsb_idl_txn, return; } - /* Convert ethernet argument to string form for database. */ - char mac_string[ETH_ADDR_STRLEN + 1]; - snprintf(mac_string, sizeof mac_string, - ETH_ADDR_FMT, ETH_ADDR_ARGS(mb->data.mac)); + const struct sbrec_port_binding *scope_pb = pb; + if (!strcmp(scope_pb->type, "chassisredirect")) { + const char *distributed_port = smap_get( + &scope_pb->options, "distributed-port"); + scope_pb = distributed_port + ? lport_lookup_by_name(sbrec_port_binding_by_name, + distributed_port) + : NULL; + } struct ds ip_s = DS_EMPTY_INITIALIZER; ipv6_format_mapped(&mb->data.ip, &ip_s); - mac_binding_add_to_sb(ovnsb_idl_txn, sbrec_mac_binding_by_lport_ip, - pb->logical_port, pb->datapath, mb->data.mac, - ds_cstr(&ip_s), false, NULL); + if (scope_pb && scope_pb->mac_binding_scope) { + shared_mac_binding_add_to_sb(ovnsb_idl_txn, + shared_mb_by_scope_ip, + scope_pb->mac_binding_scope, + mb->data.mac, ds_cstr(&ip_s), + false, NULL); + } else { + mac_binding_add_to_sb(ovnsb_idl_txn, + sbrec_mac_binding_by_lport_ip, + pb->logical_port, pb->datapath, + mb->data.mac, ds_cstr(&ip_s), false, NULL); + } ds_destroy(&ip_s); } @@ -4940,7 +4965,9 @@ static void run_put_mac_bindings(struct ovsdb_idl_txn *ovnsb_idl_txn, struct ovsdb_idl_index *sbrec_datapath_binding_by_key, struct ovsdb_idl_index *sbrec_port_binding_by_key, - struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip) + struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, + struct ovsdb_idl_index *shared_mb_by_scope_ip, + struct ovsdb_idl_index *sbrec_port_binding_by_name) { long long now = time_msec(); @@ -4973,7 +5000,9 @@ run_put_mac_bindings(struct ovsdb_idl_txn *ovnsb_idl_txn, run_put_mac_binding(ovnsb_idl_txn, sbrec_datapath_binding_by_key, sbrec_port_binding_by_key, - sbrec_mac_binding_by_lport_ip, mb); + sbrec_mac_binding_by_lport_ip, + shared_mb_by_scope_ip, + sbrec_port_binding_by_name, mb); mac_binding_remove(&put_mac_bindings, mb); } } @@ -4981,11 +5010,13 @@ run_put_mac_bindings(struct ovsdb_idl_txn *ovnsb_idl_txn, static void run_buffered_binding(const struct sbrec_mac_binding_table *mac_binding_table, + const struct sbrec_shared_mac_binding_table *shared_table, const struct hmap *local_datapaths, struct ovsdb_idl_index *sbrec_port_binding_by_key, struct ovsdb_idl_index *sbrec_datapath_binding_by_key, struct ovsdb_idl_index *sbrec_port_binding_by_name, - struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip) + struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, + struct ovsdb_idl_index *shared_mb_by_scope_ip) { if (cmap_is_empty(&buffered_packets_map)) { return; @@ -5033,11 +5064,29 @@ run_buffered_binding(const struct sbrec_mac_binding_table *mac_binding_table, mac_binding_add(&recent_mbs, mb_data, smb, 0); } + const struct sbrec_shared_mac_binding *shared_mb; + SBREC_SHARED_MAC_BINDING_TABLE_FOR_EACH_TRACKED (shared_mb, + shared_table) { + if (sbrec_shared_mac_binding_is_deleted(shared_mb)) { + continue; + } + + struct mac_binding_data mb_data; + if (!mac_binding_data_parse( + &mb_data, shared_mb->scope->binding_key, 0, + shared_mb->ip, shared_mb->mac)) { + continue; + } + mb_data.is_scope = true; + mac_binding_add_shared(&recent_mbs, mb_data, shared_mb, 0); + } + if (buffered_packets_lookup_run(&buffered_packets_map, &recent_mbs, sbrec_port_binding_by_key, sbrec_datapath_binding_by_key, sbrec_port_binding_by_name, - sbrec_mac_binding_by_lport_ip)) { + sbrec_mac_binding_by_lport_ip, + shared_mb_by_scope_ip)) { notify_pinctrl_handler(); } diff --git a/controller/pinctrl.h b/controller/pinctrl.h index a638fe29f..4b63d1241 100644 --- a/controller/pinctrl.h +++ b/controller/pinctrl.h @@ -40,6 +40,7 @@ struct sbrec_bfd_table; struct sbrec_ecmp_nexthop_table; struct sbrec_port_binding; struct sbrec_mac_binding_table; +struct sbrec_shared_mac_binding_table; void pinctrl_init(void); void pinctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, @@ -47,12 +48,14 @@ void pinctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, struct ovsdb_idl_index *sbrec_port_binding_by_key, struct ovsdb_idl_index *sbrec_port_binding_by_name, struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, struct ovsdb_idl_index *sbrec_igmp_groups, struct ovsdb_idl_index *sbrec_ip_multicast_opts, struct ovsdb_idl_index *sbrec_fdb_by_dp_key_mac, const struct sbrec_controller_event_table *, const struct sbrec_service_monitor_table *, const struct sbrec_mac_binding_table *, + const struct sbrec_shared_mac_binding_table *, const struct sbrec_bfd_table *, const struct sbrec_ecmp_nexthop_table *, const struct sbrec_chassis *chassis, diff --git a/controller/statctrl.c b/controller/statctrl.c index 77453319c..1362e3650 100644 --- a/controller/statctrl.c +++ b/controller/statctrl.c @@ -47,6 +47,7 @@ enum stat_type { STATS_MAC_BINDING = 0, STATS_FDB, STATS_MAC_BINDING_PROBE, + STATS_SHARED_MAC_BINDING_PROBE, STATS_MAX, }; @@ -180,6 +181,19 @@ statctrl_init(void) mac_binding_probe_stats_process_flow_stats, mac_binding_probe_stats_run, NULL); + struct ofputil_flow_stats_request shared_mac_binding_probe_request = { + .cookie = htonll(0), + .cookie_mask = htonll(0), + .out_port = OFPP_ANY, + .out_group = OFPG_ANY, + .table_id = OFTABLE_SHARED_MAC_BINDING, + }; + STATS_NODE(SHARED_MAC_BINDING_PROBE, + shared_mac_binding_probe_request, + struct mac_cache_stats, + shared_mac_binding_probe_stats_process_flow_stats, + mac_binding_probe_stats_run, NULL); + statctrl_ctx.thread = ovs_thread_create("ovn_statctrl", statctrl_thread_handler, &statctrl_ctx); @@ -188,6 +202,7 @@ statctrl_init(void) void statctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, struct ovsdb_idl_index *sbrec_port_binding_by_name, + struct ovsdb_idl_index *sbrec_port_binding_by_scope, const struct sbrec_chassis *chassis, struct mac_cache_data *mac_cache_data) { @@ -199,6 +214,8 @@ statctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, .cache_data = mac_cache_data, .mac_binding_pending = &statctrl_ctx.nodes[STATS_MAC_BINDING].pending, .sbrec_port_binding_by_name = sbrec_port_binding_by_name, + .sbrec_port_binding_by_mac_binding_scope = + sbrec_port_binding_by_scope, .swconn = statctrl_ctx.swconn, .chassis = chassis, }; @@ -207,6 +224,7 @@ statctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, [STATS_MAC_BINDING] = mac_cache_data, [STATS_FDB] = mac_cache_data, [STATS_MAC_BINDING_PROBE] = &mac_binding_probe_data, + [STATS_SHARED_MAC_BINDING_PROBE] = &mac_binding_probe_data, }; bool schedule_updated = false; diff --git a/controller/statctrl.h b/controller/statctrl.h index 3e56b4a54..5f927083c 100644 --- a/controller/statctrl.h +++ b/controller/statctrl.h @@ -21,6 +21,7 @@ void statctrl_init(void); void statctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn, struct ovsdb_idl_index *sbrec_port_binding_by_name, + struct ovsdb_idl_index *sbrec_port_binding_by_scope, const struct sbrec_chassis *chassis, struct mac_cache_data *mac_cache_data); diff --git a/lib/mac-binding-index.c b/lib/mac-binding-index.c index 3e49b07f3..556f18b0f 100644 --- a/lib/mac-binding-index.c +++ b/lib/mac-binding-index.c @@ -35,6 +35,14 @@ mac_binding_by_lport_ip_index_create(struct ovsdb_idl *idl) &sbrec_mac_binding_col_ip); } +struct ovsdb_idl_index * +shared_mac_binding_by_scope_ip_index_create(struct ovsdb_idl *idl) +{ + return ovsdb_idl_index_create2(idl, + &sbrec_shared_mac_binding_col_scope, + &sbrec_shared_mac_binding_col_ip); +} + const struct sbrec_mac_binding * mac_binding_lookup(struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, const char *logical_port, const char *ip) { @@ -101,3 +109,62 @@ mac_binding_add_to_sb(struct ovsdb_idl_txn *ovnsb_idl_txn, return b; } + +const struct sbrec_shared_mac_binding * +shared_mac_binding_lookup( + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, + const struct sbrec_mac_binding_scope *scope, const char *ip) +{ + struct sbrec_shared_mac_binding *mb = + sbrec_shared_mac_binding_index_init_row( + shared_mac_binding_by_scope_ip); + sbrec_shared_mac_binding_index_set_scope(mb, scope); + sbrec_shared_mac_binding_index_set_ip(mb, ip); + + const struct sbrec_shared_mac_binding *retval = + sbrec_shared_mac_binding_index_find( + shared_mac_binding_by_scope_ip, mb); + + sbrec_shared_mac_binding_index_destroy_row(mb); + return retval; +} + +/* Update or add an IP-MAC binding in 'scope'. */ +const struct sbrec_shared_mac_binding * +shared_mac_binding_add_to_sb( + struct ovsdb_idl_txn *ovnsb_idl_txn, + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, + const struct sbrec_mac_binding_scope *scope, struct eth_addr ea, + const char *ip, bool update_only, + const struct sbrec_shared_mac_binding *sb_mb) +{ + char mac_string[ETH_ADDR_STRLEN + 1]; + snprintf(mac_string, sizeof mac_string, ETH_ADDR_FMT, ETH_ADDR_ARGS(ea)); + + const struct sbrec_shared_mac_binding *b = sb_mb + ? sb_mb + : shared_mac_binding_lookup(shared_mac_binding_by_scope_ip, + scope, ip); + if (!b) { + if (update_only) { + return NULL; + } + + /* Northd can withdraw a scope while a controller is learning. + * Verify its existence so a concurrent deletion retries the + * transaction instead of creating a dangling strong reference. */ + sbrec_mac_binding_scope_verify_binding_key(scope); + struct uuid uuid = uuid_random(); + b = sbrec_shared_mac_binding_insert_persist_uuid(ovnsb_idl_txn, + &uuid); + sbrec_shared_mac_binding_set_scope(b, scope); + sbrec_shared_mac_binding_set_ip(b, ip); + } + + if (strcmp(b->mac, mac_string)) { + sbrec_shared_mac_binding_set_mac(b, mac_string); + sbrec_shared_mac_binding_set_timestamp(b, time_wall_msec()); + } + + return b; +} diff --git a/lib/mac-binding-index.h b/lib/mac-binding-index.h index 8832eda16..10360bbf9 100644 --- a/lib/mac-binding-index.h +++ b/lib/mac-binding-index.h @@ -22,6 +22,8 @@ struct ovsdb_idl_index *mac_binding_by_datapath_index_create( struct ovsdb_idl *idl); struct ovsdb_idl_index *mac_binding_by_lport_ip_index_create( struct ovsdb_idl *idl); +struct ovsdb_idl_index *shared_mac_binding_by_scope_ip_index_create( + struct ovsdb_idl *idl); const struct sbrec_mac_binding * mac_binding_lookup(struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip, @@ -34,4 +36,15 @@ const struct sbrec_mac_binding *mac_binding_add_to_sb( struct eth_addr, const char *ip, bool update_only, const struct sbrec_mac_binding *sb_mb); +const struct sbrec_shared_mac_binding *shared_mac_binding_lookup( + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, + const struct sbrec_mac_binding_scope *scope, const char *ip); + +const struct sbrec_shared_mac_binding *shared_mac_binding_add_to_sb( + struct ovsdb_idl_txn *, + struct ovsdb_idl_index *shared_mac_binding_by_scope_ip, + const struct sbrec_mac_binding_scope *, struct eth_addr, + const char *ip, bool update_only, + const struct sbrec_shared_mac_binding *sb_mb); + #endif /* lib/mac-binding-index.h */ diff --git a/tests/ovn-controller.at b/tests/ovn-controller.at index a7b79fc67..298683908 100644 --- a/tests/ovn-controller.at +++ b/tests/ovn-controller.at @@ -740,6 +740,7 @@ ct_commit_nat_v2: true ct_commit_to_zone: true ct_next_zone: true ct_state_save: true +shared_mac_binding: true ]) OVN_CLEANUP([hv1]) diff --git a/tests/ovn-inc-proc-graph-dump.at b/tests/ovn-inc-proc-graph-dump.at index e77ef037f..ddc5e2d60 100644 --- a/tests/ovn-inc-proc-graph-dump.at +++ b/tests/ovn-inc-proc-graph-dump.at @@ -364,6 +364,8 @@ digraph "Incremental-Processing-Engine" { SB_multicast_group [[style=filled, shape=box, fillcolor=white, label="SB_multicast_group"]]; OVS_flow_sample_collector_set [[style=filled, shape=box, fillcolor=white, label="OVS_flow_sample_collector_set"]]; SB_mac_binding [[style=filled, shape=box, fillcolor=white, label="SB_mac_binding"]]; + SB_shared_mac_binding [[style=filled, shape=box, fillcolor=white, label="SB_shared_mac_binding"]]; + SB_mac_binding_scope [[style=filled, shape=box, fillcolor=white, label="SB_mac_binding_scope"]]; SB_static_mac_binding [[style=filled, shape=box, fillcolor=white, label="SB_static_mac_binding"]]; SB_logical_flow [[style=filled, shape=box, fillcolor=white, label="SB_logical_flow"]]; SB_logical_dp_group [[style=filled, shape=box, fillcolor=white, label="SB_logical_dp_group"]]; @@ -388,6 +390,8 @@ digraph "Incremental-Processing-Engine" { OVS_bridge -> lflow_output [[label=""]]; OVS_flow_sample_collector_set -> lflow_output [[label="lflow_output_flow_sample_collector_set_handler"]]; SB_mac_binding -> lflow_output [[label="lflow_output_sb_mac_binding_handler"]]; + SB_shared_mac_binding -> lflow_output [[label="lflow_output_sb_shared_mac_binding_handler"]]; + SB_mac_binding_scope -> lflow_output [[label=""]]; SB_static_mac_binding -> lflow_output [[label="lflow_output_sb_static_mac_binding_handler"]]; SB_logical_flow -> lflow_output [[label="lflow_output_sb_logical_flow_handler"]]; SB_logical_dp_group -> lflow_output [[label="engine_noop_handler"]]; @@ -463,9 +467,11 @@ digraph "Incremental-Processing-Engine" { mac_cache [[style=filled, shape=box, fillcolor=white, label="mac_cache"]]; runtime_data -> mac_cache [[label="mac_cache_runtime_data_handler"]]; SB_mac_binding -> mac_cache [[label="mac_cache_sb_mac_binding_handler"]]; + SB_shared_mac_binding -> mac_cache [[label="mac_cache_sb_shared_mac_binding_handler"]]; + SB_mac_binding_scope -> mac_cache [[label=""]]; SB_fdb -> mac_cache [[label="mac_cache_sb_fdb_handler"]]; SB_datapath_binding -> mac_cache [[label="mac_cache_sb_datapath_binding_handler"]]; - SB_port_binding -> mac_cache [[label="engine_noop_handler"]]; + SB_port_binding -> mac_cache [[label="mac_cache_sb_port_binding_handler"]]; SB_ha_chassis_group [[style=filled, shape=box, fillcolor=white, label="SB_ha_chassis_group"]]; bfd_chassis [[style=filled, shape=box, fillcolor=white, label="bfd_chassis"]]; OVS_open_vswitch -> bfd_chassis [[label=""]]; @@ -502,14 +508,18 @@ digraph "Incremental-Processing-Engine" { SB_port_binding -> garp_rarp [[label="garp_rarp_sb_port_binding_handler"]]; SB_datapath_binding -> garp_rarp [[label="garp_rarp_sb_datapath_binding_handler"]]; SB_mac_binding -> garp_rarp [[label="engine_noop_handler"]]; + SB_shared_mac_binding -> garp_rarp [[label="engine_noop_handler"]]; + SB_mac_binding_scope -> garp_rarp [[label=""]]; runtime_data -> garp_rarp [[label="garp_rarp_runtime_data_handler"]]; evpn_mac_binding_sync_waker [[style=filled, shape=box, fillcolor=white, label="evpn_mac_binding_sync_waker"]]; evpn_mac_binding_sync [[style=filled, shape=box, fillcolor=white, label="evpn_mac_binding_sync"]]; evpn_mac_binding_sync_waker -> evpn_mac_binding_sync [[label=""]]; evpn_arp -> evpn_mac_binding_sync [[label=""]]; SB_mac_binding -> evpn_mac_binding_sync [[label="engine_noop_handler"]]; + SB_shared_mac_binding -> evpn_mac_binding_sync [[label="engine_noop_handler"]]; runtime_data -> evpn_mac_binding_sync [[label="engine_noop_handler"]]; mac_cache -> evpn_mac_binding_sync [[label="engine_noop_handler"]]; + SB_mac_binding_scope -> evpn_mac_binding_sync [[label=""]]; sb_ro -> evpn_mac_binding_sync [[label="evpn_mac_binding_sync_sb_ro_handler"]]; SB_port_binding -> evpn_mac_binding_sync [[label="evpn_mac_binding_sync_sb_port_binding_handler"]]; SB_acl_id [[style=filled, shape=box, fillcolor=white, label="SB_acl_id"]]; diff --git a/tests/ovn-macros.at b/tests/ovn-macros.at index 01e64da2a..9051faf71 100644 --- a/tests/ovn-macros.at +++ b/tests/ovn-macros.at @@ -330,7 +330,8 @@ m4_define([CHECK_RELATED_PORTS_AFTER_RECOMPUTE], [ # CHECK_AFTER_RECOMPUTE(hv, sbox, related_ports, ignored_dp) # Check related ports (ignoring $related_ports) and FLOWS (ignoring flows from $ignored_dp and from $ignored_tables) # by comparing IP flows and flows after recompute. -# We also ignore Flows from tables OFTABLE_MAC_BINDING, OFTABLE_MAC_LOOKUP, OFTABLE_MAC_CACHE_USE. +# Ignore dynamic neighbor binding, lookup, and cache-use tables, including +# shared bindings, since learning and aging can change them between dumps. m4_define([CHECK_AFTER_RECOMPUTE], [ hv=$1 sbox=$2 @@ -401,7 +402,12 @@ m4_define([CHECK_AFTER_RECOMPUTE], [ cat flow-diff-$hv | grep -v "table=$table" > tmp; mv tmp flow-diff-$hv done - cat flow-diff-$hv | grep -v "table=OFTABLE_MAC_BINDING" | grep -v "table=OFTABLE_MAC_LOOKUP" | grep -v "table=OFTABLE_MAC_CACHE_USE" > tmp; mv tmp flow-diff-$hv + for table in OFTABLE_MAC_BINDING OFTABLE_MAC_LOOKUP \ + OFTABLE_MAC_CACHE_USE OFTABLE_SHARED_MAC_BINDING \ + OFTABLE_SHARED_MAC_LOOKUP; do + grep -v "table=$table," flow-diff-$hv > tmp + mv tmp flow-diff-$hv + done AT_CHECK([wc -l < flow-diff-$hv], [0], [0 ]) fi diff --git a/tests/ovn.at b/tests/ovn.at index ad503faee..ce2ed8933 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -31467,7 +31467,7 @@ OVN_CHECK_PACKETS([hv2/vif1-tx.pcap], [expected]) as hv1 ovs-appctl ofproto/trace br-int in_port=1 $packet # MAC binding entry should have generated -AT_CHECK([ovn-sbctl find mac ip=10.0.0.2 mac='"00:00:00:00:03:02"' logical_port=lrp-r1-join | grep 10\.0\.0\.2], [0], [ignore], []) +AT_CHECK([ovn-sbctl find mac_binding ip=10.0.0.2 mac='"00:00:00:00:03:02"' logical_port=lrp-r1-join | grep 10\.0\.0\.2], [0], [ignore], []) OVN_CLEANUP([hv1],[hv2]) @@ -37025,6 +37025,304 @@ test_mac_binding_flows 150 00:00:11:22:33:88 0 OVN_CLEANUP([hv1]) AT_CLEANUP +OVN_FOR_EACH_NORTHD([ +AT_SETUP([ovn -- shared MAC binding scopes]) +AT_KEYWORDS([mac_binding]) +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 +check ovs-vsctl set open . \ + external-ids:ovn-bridge-mappings=phys:br-phys +check ovs-vsctl -- add-port br-phys ext0 -- \ + set Interface ext0 options:tx_pcap=hv1/ext0-tx.pcap \ + options:rxq_pcap=hv1/ext0-rx.pcap + +check ovn-nbctl ls-add public +check ovn-nbctl lsp-add-localnet-port public ln phys + +check ovn-nbctl lr-add lr0 +check ovn-nbctl lrp-add lr0 lr0-public \ + 00:00:00:00:10:00 192.168.10.1/24 +check ovn-nbctl lsp-add-router-port public public-lr0 lr0-public +check ovn-nbctl lrp-set-gateway-chassis lr0-public hv1 + +scope=$(ovn-nbctl create MAC_Binding_Scope name=scope0 \ + always_learn_from_arp_request=true) +check ovn-nbctl set Logical_Router_Port lr0-public \ + mac_binding_scope=$scope + +dnl Two routers on the same uplink must share a single learned binding. +check ovn-nbctl lr-add lr2 +check ovn-nbctl lrp-add lr2 lr2-public \ + 00:00:00:00:10:02 192.168.10.2/24 +check ovn-nbctl lsp-add-router-port public public-lr2 lr2-public +check ovn-nbctl lrp-set-gateway-chassis lr2-public hv1 +check ovn-nbctl set Logical_Router_Port lr2-public mac_binding_scope=$scope + +wait_for_ports_up +wait_row_count Chassis 1 name=hv1 other_config:shared-mac-binding=true + +dnl Missing feature flags on an existing chassis must be restored. +check ovn-sbctl remove Chassis hv1 other_config shared-mac-binding +wait_row_count Chassis 1 name=hv1 other_config:shared-mac-binding=true + +dnl Restoring the feature flag can withdraw and recreate the scope. Wait +dnl for northd and the controller to finish before inspecting engine stats +dnl or sending the one-shot GARP. +wait_row_count sb:MAC_Binding_Scope 1 name=scope0 +check ovn-nbctl --wait=hv sync + +dnl Unrelated scoped port updates must not recompute the MAC cache. +check as hv1 ovn-appctl -t ovn-controller inc-engine/clear-stats +check ovn-sbctl set Port_Binding lr0-public external_ids:unrelated=true +check ovn-nbctl --wait=hv sync +check_controller_engine_stats hv1 mac_cache norecompute nocompute + +dnl Enabling scope aging must notify EVPN even if no refresh timer was +dnl scheduled while aging was disabled. +check as hv1 ovn-appctl -t ovn-controller inc-engine/clear-stats +check ovn-nbctl --wait=hv set MAC_Binding_Scope $scope \ + mac_binding_age_threshold=30 +dnl An SB acknowledgement can also run incremental handlers. Only the +dnl scope-triggered recompute is required, not an exact compute count. +AT_CHECK([as hv1 ovn-appctl -t ovn-controller inc-engine/show-stats \ + evpn_mac_binding_sync | grep -Eq 'recompute: +[[1-9]][[0-9]]*']) + +sb_scope=$(fetch_column sb:MAC_Binding_Scope _uuid name=scope0) +scope_key=$(printf "0x%x" \ + $(fetch_column sb:MAC_Binding_Scope binding_key name=scope0)) +check_column "$sb_scope" Port_Binding mac_binding_scope \ + logical_port=lr0-public + +dnl A GARP learned through a scope member creates one shared row. +garp=ffffffffffff0000000010fe08060001080006040001 +garp=${garp}0000000010fec0a80afe000000000000c0a80afe +check as hv1 ovs-appctl netdev-dummy/receive ext0 $garp +wait_row_count Shared_MAC_Binding 1 ip=192.168.10.254 \ + mac='"00:00:00:00:10:fe"' +check_row_count MAC_Binding 0 ip=192.168.10.254 + +dnl The controller renders the row once in the shared namespace. +OVS_WAIT_UNTIL([ + test $(as hv1 ovs-ofctl dump-flows br-int \ + table=OFTABLE_SHARED_MAC_BINDING | \ + grep "metadata=${scope_key}" | grep "reg0=0xc0a80afe" | \ + grep -c "actions=mod_dl_dst:00:00:00:00:10:fe") -eq 1 +]) +OVS_WAIT_UNTIL([ + test $(as hv1 ovs-ofctl dump-flows br-int \ + table=OFTABLE_SHARED_MAC_LOOKUP | \ + grep "metadata=${scope_key}" | grep "reg0=0xc0a80afe" | \ + grep -c "dl_src=00:00:00:00:10:fe") -eq 1 +]) + +dnl Repeated traffic uses the cache rather than relearning the row. The +dnl statistics drain must refresh Shared_MAC_Binding, not MAC_Binding. +initial_timestamp=$(fetch_column Shared_MAC_Binding timestamp \ + ip=192.168.10.254) +OVS_WAIT_UNTIL([ + as hv1 ovs-appctl netdev-dummy/receive ext0 $garp + test "$(fetch_column Shared_MAC_Binding timestamp \ + ip=192.168.10.254)" -gt "$initial_timestamp" +]) +check_row_count Shared_MAC_Binding 1 ip=192.168.10.254 +check_row_count MAC_Binding 0 ip=192.168.10.254 + +dnl A regular static binding is a fallback, while an override is applied +dnl after the shared lookup and remains local to its router port. +lr0_key=$(printf "0x%x" \ + $(fetch_column Datapath_Binding tunnel_key external_ids:name=lr0)) +lr0_port_key=$(printf "0x%x" \ + $(fetch_column Port_Binding tunnel_key logical_port=lr0-public)) +check ovn-nbctl static-mac-binding-add lr0-public 192.168.10.254 \ + 00:00:00:00:10:aa +OVS_WAIT_UNTIL([ + test $(as hv1 ovs-ofctl dump-flows br-int \ + table=OFTABLE_MAC_BINDING | grep "reg0=0xc0a80afe" | \ + grep -c "actions=mod_dl_dst:00:00:00:00:10:aa") -eq 1 +]) +check ovn-nbctl --may-exist static-mac-binding-add lr0-public \ + 192.168.10.254 00:00:00:00:10:bb +smb=$(fetch_column nb:Static_MAC_Binding _uuid ip=192.168.10.254) +check ovn-nbctl set Static_MAC_Binding $smb override_dynamic_mac=true +OVS_WAIT_UNTIL([ + test $(as hv1 ovs-ofctl dump-flows br-int \ + table=OFTABLE_MAC_BINDING_OVERRIDE | \ + grep -E "metadata=${lr0_key}(,| )" | \ + grep "reg15=${lr0_port_key}," | \ + grep "reg0=0xc0a80afe" | \ + grep -c "actions=mod_dl_dst:00:00:00:00:10:bb") -eq 1 +]) + +dnl Trace the actual ARP resolution flows for both scope members. Only +dnl lr0 uses the override; lr2 must still resolve the shared MAC address. +arp_resolve=$(ovn-debug lflow-stage-to-oftable lr_in_arp_resolve) +for router in lr0 lr2; do + dp_key=$(fetch_column Datapath_Binding tunnel_key \ + external_ids:name=$router) + port_key=$(fetch_column Port_Binding tunnel_key \ + logical_port=$router-public) + if test "$router" = lr0; then + expected_mac=00:00:00:00:10:bb + else + expected_mac=00:00:00:00:10:fe + fi + AT_CHECK([as hv1 ovs-appctl ofproto/trace-packet-out br-int \ + "ip,metadata=$dp_key,reg15=$port_key,reg0=0xc0a80afe" \ + "resubmit(,$arp_resolve)"], [0], [stdout]) + AT_CHECK([grep '^Final flow:' stdout | \ + grep -c "dl_dst=$expected_mac"], [0], [1 +]) +done + +dnl A scope on a remote gateway is still local when its router datapath is +dnl local. Its shared bindings must be included by conditional monitoring. +check ovn-sbctl chassis-add hv2 geneve 192.168.0.2 \ + -- set Chassis hv2 other_config:shared-mac-binding=true + +check ovn-nbctl ls-add internal +check ovn-nbctl lsp-add internal vif1 +check ovn-nbctl lsp-set-addresses vif1 \ + "00:00:00:00:20:10 10.0.0.10" + +check ovn-nbctl lr-add lr1 +check ovn-nbctl lrp-add lr1 lr1-internal \ + 00:00:00:00:20:01 10.0.0.1/24 +check ovn-nbctl lsp-add-router-port internal internal-lr1 lr1-internal +check ovn-nbctl lrp-add lr1 lr1-public \ + 00:00:00:00:30:01 192.168.20.1/24 +check ovn-nbctl lsp-add-router-port public public-lr1 lr1-public +check ovn-nbctl lrp-set-gateway-chassis lr1-public hv2 + +remote_scope=$(ovn-nbctl create MAC_Binding_Scope name=remote-scope \ + mac_binding_age_threshold=300) +check as hv1 ovs-vsctl add-port br-int vif1 -- \ + set Interface vif1 external-ids:iface-id=vif1 +wait_for_ports_up vif1 +check ovn-nbctl --wait=hv sync + +dnl Assign a scope after the router datapath is already local. A scope-only +dnl port update must refresh the conditional monitor without a runtime-data +dnl change. +check ovn-nbctl set Logical_Router_Port lr1-public \ + mac_binding_scope=$remote_scope +check ovn-nbctl --wait=sb sync + +remote_sb_scope=$(fetch_column sb:MAC_Binding_Scope _uuid \ + name=remote-scope) +remote_scope_key=$(printf "0x%x" \ + $(fetch_column sb:MAC_Binding_Scope binding_key name=remote-scope)) +hv1_chassis=$(fetch_column Chassis _uuid name=hv1) +check_row_count Port_Binding 0 mac_binding_scope=$remote_sb_scope \ + chassis=$hv1_chassis + +check ovn-nbctl --wait=hv sync +now=$(date +%s)000 +check_uuid ovn-sbctl create Shared_MAC_Binding scope=$remote_sb_scope \ + ip=192.168.20.254 mac="00\:00\:00\:00\:20\:fe" timestamp=$now +OVS_WAIT_UNTIL([ + test $(as hv1 ovs-ofctl dump-flows br-int \ + table=OFTABLE_SHARED_MAC_BINDING | \ + grep "metadata=${remote_scope_key}" | grep "reg0=0xc0a814fe" | \ + grep -c "actions=mod_dl_dst:00:00:00:00:20:fe") -eq 1 +]) + +OVN_CLEANUP([hv1]) +AT_CLEANUP +]) + +OVN_FOR_EACH_NORTHD([ +AT_SETUP([ovn -- shared MAC bindings on a newly local datapath]) +AT_KEYWORDS([mac_binding]) +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 +check ovs-vsctl set open . external_ids:ovn-monitor-all=true +wait_row_count Chassis 1 name=hv1 other_config:ovn-monitor-all=true +check ovn-sbctl chassis-add hv2 geneve 192.168.0.2 \ + -- set Chassis hv2 other_config:shared-mac-binding=true + +check ovn-nbctl \ + -- ls-add public \ + -- lsp-add-localnet-port public ln phys \ + -- ls-add internal \ + -- lsp-add internal vif1 \ + -- lsp-set-addresses vif1 "00:00:00:00:20:10 10.0.0.10" \ + -- lr-add lr0 \ + -- lrp-add lr0 lr0-internal 00:00:00:00:20:01 10.0.0.1/24 \ + -- lsp-add-router-port internal internal-lr0 lr0-internal \ + -- lrp-add lr0 lr0-public 00:00:00:00:10:01 192.168.10.1/24 \ + -- lsp-add-router-port public public-lr0 lr0-public \ + -- lrp-set-gateway-chassis lr0-public hv2 +scope=$(ovn-nbctl create MAC_Binding_Scope name=scope0) +check ovn-nbctl --wait=hv set Logical_Router_Port lr0-public \ + mac_binding_scope=$scope +sb_scope=$(fetch_column sb:MAC_Binding_Scope _uuid name=scope0) + +dnl Monitor the bindings before any scope member datapath is local. +scope_key=$(printf "0x%x" \ + $(fetch_column sb:MAC_Binding_Scope binding_key name=scope0)) +check_uuid ovn-sbctl create Shared_MAC_Binding scope=$sb_scope \ + ip=192.168.10.254 mac="00\:00\:00\:00\:10\:fe" timestamp=0 +check_uuid ovn-sbctl create Shared_MAC_Binding scope=$sb_scope \ + ip='"fd00::fe"' mac="00\:00\:00\:00\:10\:fe" timestamp=0 +check ovn-nbctl --wait=hv sync +AT_CHECK([as hv1 ovs-ofctl dump-flows br-int \ + table=OFTABLE_SHARED_MAC_BINDING | grep -c 'priority=100'], [1], [0 +]) + +dnl Attaching a VIF makes the router local without changing either binding. +dnl The incremental path must render both shared tables without a recompute. +check as hv1 ovn-appctl -t ovn-controller inc-engine/clear-stats +check as hv1 ovs-vsctl add-port br-int vif1 -- \ + set Interface vif1 external-ids:iface-id=vif1 +wait_for_ports_up vif1 +check ovn-nbctl --wait=hv sync +for table in OFTABLE_SHARED_MAC_BINDING OFTABLE_SHARED_MAC_LOOKUP; do + if test "$table" = OFTABLE_SHARED_MAC_BINDING; then + ipv6_match='reg4=0xfd000000,reg5=0,reg6=0,reg7=0xfe,' + mac_match='actions=mod_dl_dst:00:00:00:00:10:fe' + else + ipv6_match='reg0=0xfd000000,reg1=0,reg2=0,reg3=0xfe,' + mac_match='dl_src=00:00:00:00:10:fe' + fi + OVS_WAIT_UNTIL([ + test $(as hv1 ovs-ofctl dump-flows br-int table=$table | \ + grep -c 'priority=100') -eq 2 + ]) + for ip_match in 'reg0=0xc0a80afe,' "$ipv6_match"; do + AT_CHECK([as hv1 ovs-ofctl dump-flows br-int table=$table | \ + grep 'priority=100,' | \ + grep -E "metadata=${scope_key}(,| )" | \ + grep "$ip_match" | grep -c "$mac_match"], [0], [1 +]) + done +done +check_controller_engine_stats hv1 lflow_output norecompute compute + +dnl Check stable shared flows explicitly; cleanup ignores dynamic tables. +as hv1 ovs-ofctl dump-flows br-int | ofctl_strip_all | \ + grep -E 'table=(OFTABLE_SHARED_MAC_BINDING|OFTABLE_SHARED_MAC_LOOKUP),' | \ + sort > shared-before +check as hv1 ovn-appctl -t ovn-controller recompute +check ovn-nbctl --wait=hv sync +as hv1 ovs-ofctl dump-flows br-int | ofctl_strip_all | \ + grep -E 'table=(OFTABLE_SHARED_MAC_BINDING|OFTABLE_SHARED_MAC_LOOKUP),' | \ + sort > shared-after +AT_CHECK([diff -u shared-before shared-after]) + +OVN_CLEANUP([hv1]) +AT_CLEANUP +]) + OVN_FOR_EACH_NORTHD([ AT_SETUP([ovn -- lr mac_binding I-P update]) AT_KEYWORDS([mac_binding]) @@ -37857,7 +38155,7 @@ lr_key=$(fetch_column datapath_binding tunnel_key external_ids:name=lr) cookie=$(fetch_column mac_binding _uuid logical_port=lr-ls1 | cut -d'-' -f1) OVS_WAIT_FOR_OUTPUT_UNQUOTED([as hv1 ovn-appctl -t ovn-controller debug/dump-mac-bindings], [0], [dnl Local MAC bindings: -cookie: 0x$cookie, datapath-key: $lr_key, port-key: 0, ip: 192.168.10.10, mac: 00:00:00:00:10:10 +cookie: 0x$cookie, namespace: datapath, datapath-key: $lr_key, port-key: 0, ip: 192.168.10.10, mac: 00:00:00:00:10:10 ]) dnl Remove router port. This deletes the mac binding in the same transaction. @@ -37883,7 +38181,7 @@ dnl Check local mac binding cache. cookie=$(fetch_column mac_binding _uuid logical_port=lr-ls2 | cut -d'-' -f1) OVS_WAIT_FOR_OUTPUT_UNQUOTED([as hv1 ovn-appctl -t ovn-controller debug/dump-mac-bindings], [0], [dnl Local MAC bindings: -cookie: 0x$cookie, datapath-key: $lr_key, port-key: 0, ip: 192.168.20.10, mac: 00:00:00:00:20:10 +cookie: 0x$cookie, namespace: datapath, datapath-key: $lr_key, port-key: 0, ip: 192.168.20.10, mac: 00:00:00:00:20:10 ]) dnl Change LRP tunnel key. diff --git a/tests/system-ovn.at b/tests/system-ovn.at index 3cb4b858a..4f89f32f1 100644 --- a/tests/system-ovn.at +++ b/tests/system-ovn.at @@ -18717,6 +18717,49 @@ ovs-ofctl dump-flows br-int table=OFTABLE_EVPN_ARP_LOOKUP | \ grep priority | awk '{print $[7], $[8]}' | sort > evpn_side_after AT_CHECK([diff -q evpn_side_before evpn_side_after]) +AS_BOX([Enable aging on existing EVPN shared bindings]) +dnl Start with aging disabled so EVPN has no timestamp-refresh wake pending. +dnl Add a gateway after the EVPN neighbors already exist. Both l3gateway +dnl ports must be claimed before their peer link is usable, so sync must +dnl react to the later chassis updates without a forced recompute or a new +dnl EVPN neighbor notification. +dnl Suppress this temporary router's GARPs so they do not leave learned +dnl private bindings in the original router after the scope is removed. +scope=$(ovn-nbctl create MAC_Binding_Scope name=evpn-scope \ + disable_garp_rarp=true) +check ovn-nbctl --wait=hv \ + -- lr-add lr-scope \ + -- set Logical_Router lr-scope options:chassis=hv1 \ + -- lrp-add lr-scope lr-scope-evpn \ + f0:00:0f:16:01:02 172.16.1.2/24 172:16::2/64 \ + -- lsp-add-router-port ls-evpn evpn-lr-scope lr-scope-evpn \ + -- set Logical_Router_Port lr-scope-evpn mac_binding_scope=$scope +sb_scope=$(fetch_column sb:MAC_Binding_Scope _uuid name=evpn-scope) +wait_row_count Shared_MAC_Binding 1 scope=$sb_scope ip=172.16.1.50 +wait_row_count Shared_MAC_Binding 1 scope=$sb_scope ip='172\:16\:\:50' +mb4=$(fetch_column Shared_MAC_Binding _uuid \ + scope=$sb_scope ip=172.16.1.50) +mb6=$(fetch_column Shared_MAC_Binding _uuid \ + scope=$sb_scope ip='172\:16\:\:50') +timestamp4=$(ovn-sbctl get Shared_MAC_Binding $mb4 timestamp) +timestamp6=$(ovn-sbctl get Shared_MAC_Binding $mb6 timestamp) +check ovn-nbctl --wait=hv sync + +dnl Without changing any EVPN neighbor, enable aging and verify that the +dnl same IPv4 and IPv6 rows are refreshed beyond their original lifetime. +check ovn-nbctl --wait=hv set MAC_Binding_Scope $scope \ + mac_binding_age_threshold=10 +OVS_WAIT_UNTIL([ + test "$(ovn-sbctl get Shared_MAC_Binding $mb4 timestamp)" \ + -gt "$((timestamp4 + 10000))" && + test "$(ovn-sbctl get Shared_MAC_Binding $mb6 timestamp)" \ + -gt "$((timestamp6 + 10000))" +]) +check ovn-nbctl --wait=hv \ + -- lsp-del evpn-lr-scope \ + -- lr-del lr-scope \ + -- destroy MAC_Binding_Scope $scope + dnl Verify side table flows are removed when EVPN entries are removed. check ip neigh del dev $BR_NAME 172.16.1.50 check ip neigh del dev $BR_NAME 172.16.1.60
Learn scoped neighbors into Shared_MAC_Binding and install one set of lookup flows per scope. Preserve private fallback, static overrides, conditional monitoring, and packet-buffer release after cold resolution. Use shared bindings for GARP and EVPN synchronization, and probe and refresh active bindings through the batched statistics update path. Verify scope existence before inserting bindings so concurrent scope withdrawal retries instead of failing referential integrity checks. Test two member routers learning one binding, timestamp refresh, feature negotiation, static precedence, and remote-gateway conditional monitoring. Assisted-by: OpenAI Codex Signed-off-by: Tim Rozet <trozet@nvidia.com> --- controller/chassis.c | 7 + controller/evpn-mac-binding-sync.c | 147 +++++++--- controller/evpn-mac-binding-sync.h | 16 +- controller/garp_rarp.c | 36 ++- controller/garp_rarp.h | 1 + controller/lflow.c | 135 ++++++++++ controller/lflow.h | 10 + controller/mac-cache.c | 417 ++++++++++++++++++++++------- controller/mac-cache.h | 23 +- controller/neighbor-of.c | 98 +++++-- controller/neighbor-of.h | 4 + controller/ovn-controller.8.xml | 18 ++ controller/ovn-controller.c | 327 +++++++++++++++++++++- controller/pinctrl.c | 81 ++++-- controller/pinctrl.h | 3 + controller/statctrl.c | 18 ++ controller/statctrl.h | 1 + lib/mac-binding-index.c | 67 +++++ lib/mac-binding-index.h | 13 + tests/ovn-controller.at | 1 + tests/ovn-inc-proc-graph-dump.at | 12 +- tests/ovn-macros.at | 10 +- tests/ovn.at | 304 ++++++++++++++++++++- tests/system-ovn.at | 43 +++ 24 files changed, 1590 insertions(+), 202 deletions(-)