From eea36c94409e7c6930bc375359415e4ee633b0a9 Mon Sep 17 00:00:00 2001 From: Ilya Maximets Date: Sun, 11 Aug 2024 02:37:08 +0200 Subject: [PATCH] northd: Fix non-functional incremental processing of port groups. Signed-off-by: Ilya Maximets --- northd/en-lflow.c | 3 ++ northd/en-ls-stateful.c | 85 ++++++++++++++++++++++++++--------------- northd/en-port-group.c | 76 ++++++++++++++++++++---------------- northd/en-port-group.h | 26 +++++++------ northd/northd.c | 51 +++++++++++++++++++------ northd/northd.h | 3 ++ 6 files changed, 157 insertions(+), 87 deletions(-) diff --git a/northd/en-lflow.c b/northd/en-lflow.c index f9d7f24596..aa0ac8166d 100644 --- a/northd/en-lflow.c +++ b/northd/en-lflow.c @@ -58,6 +58,9 @@ lflow_get_input_data(struct engine_node *node, struct ecmp_nexthop_data *nexthop_data = engine_get_input_data("ecmp_nexthop", node); + lflow_input->nbrec_port_group_table = + EN_OVSDB_GET(engine_get_input("NB_port_group", node)); + lflow_input->sbrec_logical_flow_table = EN_OVSDB_GET(engine_get_input("SB_logical_flow", node)); lflow_input->sbrec_multicast_group_table = diff --git a/northd/en-ls-stateful.c b/northd/en-ls-stateful.c index 44f74ea08e..ba2f1e1cb1 100644 --- a/northd/en-ls-stateful.c +++ b/northd/en-ls-stateful.c @@ -49,33 +49,37 @@ static void ls_stateful_table_init(struct ls_stateful_table *); static void ls_stateful_table_clear(struct ls_stateful_table *); static void ls_stateful_table_destroy(struct ls_stateful_table *); static struct ls_stateful_record *ls_stateful_table_find_( - const struct ls_stateful_table *, const struct nbrec_logical_switch *); + const struct ls_stateful_table *, const struct uuid *nbs_uuid); static void ls_stateful_table_build(struct ls_stateful_table *, + const struct nbrec_port_group_table *, const struct ovn_datapaths *ls_datapaths, const struct ls_port_group_table *); -static struct ls_stateful_input ls_stateful_get_input_data( - struct engine_node *); - static struct ls_stateful_record *ls_stateful_record_create( struct ls_stateful_table *, + const struct nbrec_port_group_table *, const struct ovn_datapath *, const struct ls_port_group_table *); static void ls_stateful_record_destroy(struct ls_stateful_record *); static void ls_stateful_record_init( struct ls_stateful_record *, + const struct nbrec_port_group_table *, const struct ovn_datapath *, const struct ls_port_group *, const struct ls_port_group_table *); static void ls_stateful_record_reinit( struct ls_stateful_record *, + const struct nbrec_port_group_table *, const struct ovn_datapath *, const struct ls_port_group *, const struct ls_port_group_table *); static bool ls_has_lb_vip(const struct ovn_datapath *); static void ls_stateful_record_set_acl_flags( - struct ls_stateful_record *, const struct ovn_datapath *, - const struct ls_port_group *, const struct ls_port_group_table *); + struct ls_stateful_record *, + const struct nbrec_port_group_table *, + const struct ovn_datapath *, + const struct ls_port_group *, + const struct ls_port_group_table *); static bool ls_stateful_record_set_acl_flags_(struct ls_stateful_record *, struct nbrec_acl **, size_t n_acls); @@ -83,6 +87,7 @@ static struct ls_stateful_input ls_stateful_get_input_data( struct engine_node *); struct ls_stateful_input { + const struct nbrec_port_group_table *nbrec_port_group_table; const struct ls_port_group_table *ls_port_groups; const struct ovn_datapaths *ls_datapaths; }; @@ -122,8 +127,10 @@ en_ls_stateful_run(struct engine_node *node, void *data_) stopwatch_start(LS_STATEFUL_RUN_STOPWATCH_NAME, time_msec()); ls_stateful_table_clear(&data->table); - ls_stateful_table_build(&data->table, input_data.ls_datapaths, - input_data.ls_port_groups); + ls_stateful_table_build(&data->table, + input_data.nbrec_port_group_table, + input_data.ls_datapaths, + input_data.ls_port_groups); stopwatch_stop(LS_STATEFUL_RUN_STOPWATCH_NAME, time_msec()); engine_set_node_state(node, EN_UPDATED); @@ -161,9 +168,11 @@ ls_stateful_northd_handler(struct engine_node *node, void *data_) const struct ovn_datapath *od = hmapx_node->data; struct ls_stateful_record *ls_stateful_rec = ls_stateful_table_find_( - &data->table, od->nbs); + &data->table, &od->nbs->header_.uuid); ovs_assert(ls_stateful_rec); - ls_stateful_record_reinit(ls_stateful_rec, od, NULL, + ls_stateful_record_reinit(ls_stateful_rec, + input_data.nbrec_port_group_table, + od, NULL, input_data.ls_port_groups); /* Add the ls_stateful_rec to the tracking data. */ @@ -198,7 +207,7 @@ ls_stateful_port_group_handler(struct engine_node *node, void *data_) LS_PORT_GROUP_TABLE_FOR_EACH (ls_pg, input_data.ls_port_groups) { struct ls_stateful_record *ls_stateful_rec = - ls_stateful_table_find_(&data->table, ls_pg->nbs); + ls_stateful_table_find_(&data->table, &ls_pg->nbs_uuid); ovs_assert(ls_stateful_rec); const struct ovn_datapath *od = ovn_datapaths_find_by_index(input_data.ls_datapaths, @@ -208,7 +217,9 @@ ls_stateful_port_group_handler(struct engine_node *node, void *data_) bool had_acls = ls_stateful_rec->has_acls; bool modified = false; - ls_stateful_record_reinit(ls_stateful_rec, od, ls_pg, + ls_stateful_record_reinit(ls_stateful_rec, + input_data.nbrec_port_group_table, + od, ls_pg, input_data.ls_port_groups); if ((had_stateful_acl != ls_stateful_rec->has_stateful_acl) @@ -256,24 +267,25 @@ ls_stateful_table_clear(struct ls_stateful_table *table) static void ls_stateful_table_build(struct ls_stateful_table *table, + const struct nbrec_port_group_table *nb_pg_table, const struct ovn_datapaths *ls_datapaths, const struct ls_port_group_table *ls_pgs) { const struct ovn_datapath *od; HMAP_FOR_EACH (od, key_node, &ls_datapaths->datapaths) { - ls_stateful_record_create(table, od, ls_pgs); + ls_stateful_record_create(table, nb_pg_table, od, ls_pgs); } } static struct ls_stateful_record * ls_stateful_table_find_(const struct ls_stateful_table *table, - const struct nbrec_logical_switch *nbs) + const struct uuid *nbs_uuid) { struct ls_stateful_record *ls_stateful_rec; HMAP_FOR_EACH_WITH_HASH (ls_stateful_rec, key_node, - uuid_hash(&nbs->header_.uuid), &table->entries) { - if (uuid_equals(&ls_stateful_rec->nbs_uuid, &nbs->header_.uuid)) { + uuid_hash(nbs_uuid), &table->entries) { + if (uuid_equals(&ls_stateful_rec->nbs_uuid, nbs_uuid)) { return ls_stateful_rec; } } @@ -282,6 +294,7 @@ ls_stateful_table_find_(const struct ls_stateful_table *table, static struct ls_stateful_record * ls_stateful_record_create(struct ls_stateful_table *table, + const struct nbrec_port_group_table *nb_pg_table, const struct ovn_datapath *od, const struct ls_port_group_table *ls_pgs) { @@ -289,11 +302,11 @@ ls_stateful_record_create(struct ls_stateful_table *table, xzalloc(sizeof *ls_stateful_rec); ls_stateful_rec->ls_index = od->index; ls_stateful_rec->nbs_uuid = od->nbs->header_.uuid; - ls_stateful_record_init(ls_stateful_rec, od, NULL, ls_pgs); + ls_stateful_record_init(ls_stateful_rec, nb_pg_table, od, NULL, ls_pgs); ls_stateful_rec->lflow_ref = lflow_ref_create(); hmap_insert(&table->entries, &ls_stateful_rec->key_node, - uuid_hash(&od->nbs->header_.uuid)); + uuid_hash(&ls_stateful_rec->nbs_uuid)); return ls_stateful_rec; } @@ -307,21 +320,24 @@ ls_stateful_record_destroy(struct ls_stateful_record *ls_stateful_rec) static void ls_stateful_record_init(struct ls_stateful_record *ls_stateful_rec, - const struct ovn_datapath *od, - const struct ls_port_group *ls_pg, - const struct ls_port_group_table *ls_pgs) + const struct nbrec_port_group_table *nb_pg_table, + const struct ovn_datapath *od, + const struct ls_port_group *ls_pg, + const struct ls_port_group_table *ls_pgs) { ls_stateful_rec->has_lb_vip = ls_has_lb_vip(od); - ls_stateful_record_set_acl_flags(ls_stateful_rec, od, ls_pg, ls_pgs); + ls_stateful_record_set_acl_flags(ls_stateful_rec, nb_pg_table, + od, ls_pg, ls_pgs); } static void ls_stateful_record_reinit(struct ls_stateful_record *ls_stateful_rec, + const struct nbrec_port_group_table *nb_pg_table, const struct ovn_datapath *od, const struct ls_port_group *ls_pg, const struct ls_port_group_table *ls_pgs) { - ls_stateful_record_init(ls_stateful_rec, od, ls_pg, ls_pgs); + ls_stateful_record_init(ls_stateful_rec, nb_pg_table, od, ls_pg, ls_pgs); } static bool @@ -359,10 +375,12 @@ ls_has_lb_vip(const struct ovn_datapath *od) } static void -ls_stateful_record_set_acl_flags(struct ls_stateful_record *ls_stateful_rec, - const struct ovn_datapath *od, - const struct ls_port_group *ls_pg, - const struct ls_port_group_table *ls_pgs) +ls_stateful_record_set_acl_flags( + struct ls_stateful_record *ls_stateful_rec, + const struct nbrec_port_group_table *nb_pg_table, + const struct ovn_datapath *od, + const struct ls_port_group *ls_pg, + const struct ls_port_group_table *ls_pgs) { ls_stateful_rec->has_stateful_acl = false; ls_stateful_rec->max_acl_tier = 0; @@ -374,7 +392,7 @@ ls_stateful_record_set_acl_flags(struct ls_stateful_record *ls_stateful_rec, } if (!ls_pg) { - ls_pg = ls_port_group_table_find(ls_pgs, od->nbs); + ls_pg = ls_port_group_table_find(ls_pgs, &od->nbs->header_.uuid); } if (!ls_pg) { @@ -383,9 +401,14 @@ ls_stateful_record_set_acl_flags(struct ls_stateful_record *ls_stateful_rec, const struct ls_port_group_record *ls_pg_rec; HMAP_FOR_EACH (ls_pg_rec, key_node, &ls_pg->nb_pgs) { + const struct nbrec_port_group *nb_pg; + + nb_pg = nbrec_port_group_table_get_for_uuid( + nb_pg_table, &ls_pg_rec->nb_pg_uuid); + ovs_assert(nb_pg); + if (ls_stateful_record_set_acl_flags_(ls_stateful_rec, - ls_pg_rec->nb_pg->acls, - ls_pg_rec->nb_pg->n_acls)) { + nb_pg->acls, nb_pg->n_acls)) { return; } } @@ -434,6 +457,8 @@ ls_stateful_get_input_data(struct engine_node *node) engine_get_input_data("port_group", node); return (struct ls_stateful_input) { + .nbrec_port_group_table = + EN_OVSDB_GET(engine_get_input("NB_port_group", node)), .ls_port_groups = &pg_data->ls_port_groups, .ls_datapaths = &northd_data->ls_datapaths, }; diff --git a/northd/en-port-group.c b/northd/en-port-group.c index 0de9dc5f67..000c325fea 100644 --- a/northd/en-port-group.c +++ b/northd/en-port-group.c @@ -21,6 +21,7 @@ #include "en-port-group.h" #include "lib/stopwatch-names.h" +#include "lib/uuidset.h" #include "northd.h" VLOG_DEFINE_THIS_MODULE(en_port_group); @@ -51,7 +52,7 @@ static struct ls_port_group_record *ls_port_group_record_create( const struct nbrec_port_group *); static struct ls_port_group_record *ls_port_group_record_find( - struct ls_port_group *, const struct nbrec_port_group *nb_pg); + struct ls_port_group *, const struct uuid *nb_pg_uuid); static void ls_port_group_record_destroy( struct ls_port_group *, @@ -96,13 +97,13 @@ ls_port_group_table_destroy(struct ls_port_group_table *table) struct ls_port_group * ls_port_group_table_find(const struct ls_port_group_table *table, - const struct nbrec_logical_switch *nbs) + const struct uuid *nbs_uuid) { struct ls_port_group *ls_pg; - HMAP_FOR_EACH_WITH_HASH (ls_pg, key_node, uuid_hash(&nbs->header_.uuid), + HMAP_FOR_EACH_WITH_HASH (ls_pg, key_node, uuid_hash(nbs_uuid), &table->entries) { - if (nbs == ls_pg->nbs) { + if (uuid_equals(nbs_uuid, &ls_pg->nbs_uuid)) { return ls_pg; } } @@ -130,6 +131,7 @@ ls_port_group_table_build( void ls_port_group_table_sync( const struct ls_port_group_table *ls_port_groups, + const struct nbrec_port_group_table *nbrec_port_group_table, const struct sbrec_port_group_table *sbrec_port_group_table, struct ovsdb_idl_txn *ovnsb_txn) { @@ -147,8 +149,13 @@ ls_port_group_table_sync( struct ls_port_group_record *ls_pg_rec; HMAP_FOR_EACH (ls_pg_rec, key_node, &ls_pg->nb_pgs) { - get_sb_port_group_name(ls_pg_rec->nb_pg->name, - ls_pg->sb_datapath_key, + const struct nbrec_port_group *nb_pg; + + nb_pg = nbrec_port_group_table_get_for_uuid( + nbrec_port_group_table, &ls_pg_rec->nb_pg_uuid); + ovs_assert(nb_pg); + + get_sb_port_group_name(nb_pg->name, ls_pg->sb_datapath_key, &sb_name); const char *sb_pg_name_cstr = ds_cstr(&sb_name); sb_port_group = shash_find_and_delete(&sb_port_groups, @@ -182,12 +189,12 @@ ls_port_group_create(struct ls_port_group_table *ls_port_groups, struct ls_port_group *ls_pg = xmalloc(sizeof *ls_pg); *ls_pg = (struct ls_port_group) { - .nbs = nbs, + .nbs_uuid = nbs->header_.uuid, .sb_datapath_key = dp->tunnel_key, .nb_pgs = HMAP_INITIALIZER(&ls_pg->nb_pgs), }; hmap_insert(&ls_port_groups->entries, &ls_pg->key_node, - uuid_hash(&nbs->header_.uuid)); + uuid_hash(&ls_pg->nbs_uuid)); return ls_pg; } @@ -222,7 +229,7 @@ ls_port_group_process(struct ls_port_group_table *ls_port_groups, bool ls_pg_rec_created = false; struct port_group_ls_record *pg_ls = - port_group_ls_table_find(port_group_lses, nb_pg); + port_group_ls_table_find(port_group_lses, &nb_pg->header_.uuid); if (!pg_ls) { pg_ls = port_group_ls_record_create(port_group_lses, nb_pg); } else { @@ -253,21 +260,20 @@ ls_port_group_process(struct ls_port_group_table *ls_port_groups, } struct ls_port_group *ls_pg = - ls_port_group_table_find(ls_port_groups, od->nbs); + ls_port_group_table_find(ls_port_groups, &od->nbs->header_.uuid); if (!ls_pg) { ls_pg = ls_port_group_create(ls_port_groups, od->nbs, od->sb); } struct ls_port_group_record *ls_pg_rec = - ls_port_group_record_find(ls_pg, nb_pg); + ls_port_group_record_find(ls_pg, &nb_pg->header_.uuid); if (!ls_pg_rec) { ls_pg_rec = ls_port_group_record_create(ls_pg, nb_pg); ls_pg_rec_created = true; } sset_add(&ls_pg_rec->ports, port_name); - hmapx_add(&pg_ls->switches, - CONST_CAST(struct nbrec_logical_switch *, od->nbs)); + uuidset_insert(&pg_ls->switches, &od->nbs->header_.uuid); if (updated_ls_port_groups) { hmapx_add(updated_ls_port_groups, ls_pg); } @@ -300,18 +306,18 @@ ls_port_group_record_clear(struct ls_port_group_table *ls_to_port_groups, struct port_group_ls_record *pg_ls, struct hmapx *cleared_ls_port_groups) { - struct hmapx_node *node; + struct uuidset_node *node; - HMAPX_FOR_EACH (node, &pg_ls->switches) { - const struct nbrec_logical_switch *nbs = node->data; + UUIDSET_FOR_EACH (node, &pg_ls->switches) { + const struct uuid *nbs_uuid = &node->uuid; struct ls_port_group *ls_pg = - ls_port_group_table_find(ls_to_port_groups, nbs); + ls_port_group_table_find(ls_to_port_groups, nbs_uuid); ovs_assert(ls_pg); /* Clear ports in the port group record. */ struct ls_port_group_record *ls_pg_rec = - ls_port_group_record_find(ls_pg, pg_ls->nb_pg); + ls_port_group_record_find(ls_pg, &pg_ls->nb_pg_uuid); ovs_assert(ls_pg_rec); sset_clear(&ls_pg_rec->ports); @@ -340,23 +346,23 @@ ls_port_group_record_create(struct ls_port_group *ls_pg, { struct ls_port_group_record *ls_pg_rec = xmalloc(sizeof *ls_pg_rec); *ls_pg_rec = (struct ls_port_group_record) { - .nb_pg = nb_pg, + .nb_pg_uuid = nb_pg->header_.uuid, .ports = SSET_INITIALIZER(&ls_pg_rec->ports), }; hmap_insert(&ls_pg->nb_pgs, &ls_pg_rec->key_node, - uuid_hash(&nb_pg->header_.uuid)); + uuid_hash(&ls_pg_rec->nb_pg_uuid)); return ls_pg_rec; } static struct ls_port_group_record * ls_port_group_record_find(struct ls_port_group *ls_pg, - const struct nbrec_port_group *nb_pg) + const struct uuid *nb_pg_uuid) { - size_t hash = uuid_hash(&nb_pg->header_.uuid); + size_t hash = uuid_hash(nb_pg_uuid); struct ls_port_group_record *ls_pg_rec; HMAP_FOR_EACH_WITH_HASH (ls_pg_rec, key_node, hash, &ls_pg->nb_pgs) { - if (ls_pg_rec->nb_pg == nb_pg) { + if (uuid_equals(&ls_pg_rec->nb_pg_uuid, nb_pg_uuid)) { return ls_pg_rec; } } @@ -401,13 +407,13 @@ port_group_ls_table_destroy(struct port_group_ls_table *table) struct port_group_ls_record * port_group_ls_table_find(const struct port_group_ls_table *table, - const struct nbrec_port_group *nb_pg) + const struct uuid *nb_pg_uuid) { struct port_group_ls_record *pg_ls; - HMAP_FOR_EACH_WITH_HASH (pg_ls, key_node, uuid_hash(&nb_pg->header_.uuid), + HMAP_FOR_EACH_WITH_HASH (pg_ls, key_node, uuid_hash(nb_pg_uuid), &table->entries) { - if (nb_pg == pg_ls->nb_pg) { + if (uuid_equals(nb_pg_uuid, &pg_ls->nb_pg_uuid)) { return pg_ls; } } @@ -421,11 +427,11 @@ port_group_ls_record_create(struct port_group_ls_table *table, struct port_group_ls_record *pg_ls = xmalloc(sizeof *pg_ls); *pg_ls = (struct port_group_ls_record) { - .nb_pg = nb_pg, - .switches = HMAPX_INITIALIZER(&pg_ls->switches), + .nb_pg_uuid = nb_pg->header_.uuid, + .switches = UUIDSET_INITIALIZER(&pg_ls->switches), }; hmap_insert(&table->entries, &pg_ls->key_node, - uuid_hash(&nb_pg->header_.uuid)); + uuid_hash(&pg_ls->nb_pg_uuid)); return pg_ls; } @@ -434,7 +440,7 @@ port_group_ls_record_destroy(struct port_group_ls_table *table, struct port_group_ls_record *pg_ls) { if (pg_ls) { - hmapx_destroy(&pg_ls->switches); + uuidset_destroy(&pg_ls->switches); hmap_remove(&table->entries, &pg_ls->key_node); free(pg_ls); } @@ -501,6 +507,7 @@ en_port_group_run(struct engine_node *node, void *data_) input_data.ls_ports); ls_port_group_table_sync(&data->ls_port_groups, + input_data.nbrec_port_group_table, input_data.sbrec_port_group_table, eng_ctx->ovnsb_idl_txn); @@ -557,9 +564,12 @@ port_group_nb_port_group_handler(struct engine_node *node, void *data_) struct ls_port_group_record *ls_pg_rec; HMAP_FOR_EACH (ls_pg_rec, key_node, &ls_pg->nb_pgs) { - get_sb_port_group_name(ls_pg_rec->nb_pg->name, - ls_pg->sb_datapath_key, - &sb_pg_name); + nb_pg = nbrec_port_group_table_get_for_uuid( + nb_pg_table, &ls_pg_rec->nb_pg_uuid); + ovs_assert(nb_pg); + + get_sb_port_group_name(nb_pg->name, ls_pg->sb_datapath_key, + &sb_pg_name); const char *sb_pg_name_cstr = ds_cstr(&sb_pg_name); const struct sbrec_port_group *sb_pg = diff --git a/northd/en-port-group.h b/northd/en-port-group.h index 54014062ce..3b1487f30c 100644 --- a/northd/en-port-group.h +++ b/northd/en-port-group.h @@ -25,6 +25,7 @@ #include "openvswitch/hmap.h" #include "sset.h" +#include "uuidset.h" /* Per logical switch port group information. */ struct ls_port_group_table { @@ -32,20 +33,20 @@ struct ls_port_group_table { }; struct ls_port_group { - struct hmap_node key_node; /* Index on 'nbs->header_.uuid'. */ + struct hmap_node key_node; /* Index on 'nbs_uuid'. */ - const struct nbrec_logical_switch *nbs; - int64_t sb_datapath_key; /* SB.Datapath_Binding.tunnel_key. */ + struct uuid nbs_uuid; /* UUID of a Logical_Switch record. */ + int64_t sb_datapath_key; /* SB.Datapath_Binding.tunnel_key. */ /* Port groups with ports attached to 'nbs'. */ struct hmap nb_pgs; /* Stores struct ls_port_group_record. */ }; struct ls_port_group_record { - struct hmap_node key_node; /* Index on 'nb_pg->header_.uuid'. */ + struct hmap_node key_node; /* Index on 'nb_pg_uuid'. */ - const struct nbrec_port_group *nb_pg; - struct sset ports; /* Subset of 'nb_pg' ports in this record. */ + struct uuid nb_pg_uuid; /* UUID of a NB.Port_Group record. */ + struct sset ports; /* Subset of ports in this record. */ }; #define LS_PORT_GROUP_TABLE_FOR_EACH(LS_PG, TABLE) \ @@ -56,7 +57,7 @@ void ls_port_group_table_clear(struct ls_port_group_table *); void ls_port_group_table_destroy(struct ls_port_group_table *); struct ls_port_group *ls_port_group_table_find( const struct ls_port_group_table *, - const struct nbrec_logical_switch *); + const struct uuid *nbs_uuid); /* Per port group map of datapaths with ports in the group. */ struct port_group_ls_table { @@ -64,12 +65,12 @@ struct port_group_ls_table { }; struct port_group_ls_record { - struct hmap_node key_node; /* Index on 'pg->header_.uuid'. */ + struct hmap_node key_node; /* Index on 'nb_pg_uuid'. */ - const struct nbrec_port_group *nb_pg; + struct uuid nb_pg_uuid; /* UUID of a NB.Port_Group record. */ - /* Map of 'struct nbrec_logical_switch *' with ports in the group. */ - struct hmapx switches; + /* Set of UUIDs of NB.Port_Group.ports records. */ + struct uuidset switches; }; void port_group_ls_table_init(struct port_group_ls_table *); @@ -78,7 +79,7 @@ void port_group_ls_table_destroy(struct port_group_ls_table *); struct port_group_ls_record *port_group_ls_table_find( const struct port_group_ls_table *, - const struct nbrec_port_group *); + const struct uuid *nb_pg_uuid); void ls_port_group_table_build( struct ls_port_group_table *ls_port_groups, @@ -86,6 +87,7 @@ void ls_port_group_table_build( const struct nbrec_port_group_table *, const struct hmap *ls_ports); void ls_port_group_table_sync(const struct ls_port_group_table *ls_port_groups, + const struct nbrec_port_group_table *, const struct sbrec_port_group_table *, struct ovsdb_idl_txn *ovnsb_txn); diff --git a/northd/northd.c b/northd/northd.c index 5ad30d854b..10935574cb 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -6050,6 +6050,7 @@ build_stateless_filter(const struct ovn_datapath *od, static void build_stateless_filters(const struct ovn_datapath *od, + const struct nbrec_port_group_table *nb_pg_table, const struct ls_port_group_table *ls_port_groups, struct lflow_table *lflows, struct lflow_ref *lflow_ref) @@ -6062,15 +6063,21 @@ build_stateless_filters(const struct ovn_datapath *od, } const struct ls_port_group *ls_pg = - ls_port_group_table_find(ls_port_groups, od->nbs); + ls_port_group_table_find(ls_port_groups, &od->nbs->header_.uuid); if (!ls_pg) { return; } const struct ls_port_group_record *ls_pg_rec; HMAP_FOR_EACH (ls_pg_rec, key_node, &ls_pg->nb_pgs) { - for (size_t i = 0; i < ls_pg_rec->nb_pg->n_acls; i++) { - const struct nbrec_acl *acl = ls_pg_rec->nb_pg->acls[i]; + const struct nbrec_port_group *nb_pg; + + nb_pg = nbrec_port_group_table_get_for_uuid( + nb_pg_table, &ls_pg_rec->nb_pg_uuid); + ovs_assert(nb_pg); + + for (size_t i = 0; i < nb_pg->n_acls; i++) { + const struct nbrec_acl *acl = nb_pg->acls[i]; if (!strcmp(acl->action, "allow-stateless")) { build_stateless_filter(od, acl, lflows, lflow_ref); @@ -6103,6 +6110,7 @@ static void build_ls_stateful_rec_pre_acls( const struct ls_stateful_record *ls_stateful_rec, const struct ovn_datapath *od, + const struct nbrec_port_group_table *nb_pg_table, const struct ls_port_group_table *ls_port_groups, struct lflow_table *lflows, struct lflow_ref *lflow_ref) @@ -6128,7 +6136,8 @@ build_ls_stateful_rec_pre_acls( } /* stateless filters always take precedence over stateful ACLs. */ - build_stateless_filters(od, ls_port_groups, lflows, lflow_ref); + build_stateless_filters(od, nb_pg_table, ls_port_groups, + lflows, lflow_ref); /* Ingress and Egress Pre-ACL Table (Priority 110). * @@ -6173,7 +6182,8 @@ build_ls_stateful_rec_pre_acls( } else if (ls_stateful_rec->has_lb_vip) { /* We'll build stateless filters if there are LB rules so that * the stateless flows are not tracked in pre-lb. */ - build_stateless_filters(od, ls_port_groups, lflows, lflow_ref); + build_stateless_filters(od, nb_pg_table, ls_port_groups, + lflows, lflow_ref); } } @@ -7447,6 +7457,7 @@ static void build_acls(const struct ls_stateful_record *ls_stateful_rec, const struct ovn_datapath *od, struct lflow_table *lflows, + const struct nbrec_port_group_table *nb_pg_table, const struct ls_port_group_table *ls_port_groups, const struct shash *meter_groups, const struct sampling_app_table *sampling_apps, @@ -7648,12 +7659,18 @@ build_acls(const struct ls_stateful_record *ls_stateful_rec, } const struct ls_port_group *ls_pg = - ls_port_group_table_find(ls_port_groups, od->nbs); + ls_port_group_table_find(ls_port_groups, &od->nbs->header_.uuid); if (ls_pg) { const struct ls_port_group_record *ls_pg_rec; HMAP_FOR_EACH (ls_pg_rec, key_node, &ls_pg->nb_pgs) { - for (size_t i = 0; i < ls_pg_rec->nb_pg->n_acls; i++) { - const struct nbrec_acl *acl = ls_pg_rec->nb_pg->acls[i]; + const struct nbrec_port_group *nb_pg; + + nb_pg = nbrec_port_group_table_get_for_uuid( + nb_pg_table, &ls_pg_rec->nb_pg_uuid); + ovs_assert(nb_pg); + + for (size_t i = 0; i < nb_pg->n_acls; i++) { + const struct nbrec_acl *acl = nb_pg->acls[i]; build_acl_log_related_flows(od, lflows, acl, has_stateful, meter_groups, &match, &actions, @@ -16786,19 +16803,20 @@ build_lr_stateful_flows(const struct lr_stateful_record *lr_stateful_rec, static void build_ls_stateful_flows(const struct ls_stateful_record *ls_stateful_rec, const struct ovn_datapath *od, + const struct nbrec_port_group_table *nb_pg_table, const struct ls_port_group_table *ls_pgs, const struct shash *meter_groups, const struct sampling_app_table *sampling_apps, const struct chassis_features *features, struct lflow_table *lflows) { - build_ls_stateful_rec_pre_acls(ls_stateful_rec, od, ls_pgs, lflows, - ls_stateful_rec->lflow_ref); + build_ls_stateful_rec_pre_acls(ls_stateful_rec, od, nb_pg_table, ls_pgs, + lflows, ls_stateful_rec->lflow_ref); build_ls_stateful_rec_pre_lb(ls_stateful_rec, od, lflows, ls_stateful_rec->lflow_ref); build_acl_hints(ls_stateful_rec, od, lflows, ls_stateful_rec->lflow_ref); - build_acls(ls_stateful_rec, od, lflows, ls_pgs, meter_groups, + build_acls(ls_stateful_rec, od, lflows, nb_pg_table, ls_pgs, meter_groups, sampling_apps, features, ls_stateful_rec->lflow_ref); build_lb_hairpin(ls_stateful_rec, od, lflows, ls_stateful_rec->lflow_ref); } @@ -16828,6 +16846,7 @@ struct lswitch_flow_build_info { struct hmap *route_policies; struct simap *route_tables; struct simap *nexthops_table; + const struct nbrec_port_group_table *nb_pg_table; }; /* Helper function to combine all lflow generation which is iterated by @@ -17121,6 +17140,7 @@ build_lflows_thread(void *arg) ovs_assert(uuid_equals(&ls_stateful_rec->nbs_uuid, &od->nbs->header_.uuid)); build_ls_stateful_flows(ls_stateful_rec, od, + lsi->nb_pg_table, lsi->ls_port_groups, lsi->meter_groups, lsi->sampling_apps, @@ -17200,6 +17220,7 @@ build_lswitch_and_lrouter_flows( const struct chassis_features *features, const char *svc_monitor_mac, const struct sampling_app_table *sampling_apps, + const struct nbrec_port_group_table *nb_pg_table, struct hmap *parsed_routes, struct hmap *route_policies, struct simap *route_tables, @@ -17242,6 +17263,7 @@ build_lswitch_and_lrouter_flows( lsiv[index].route_tables = route_tables; lsiv[index].route_policies = route_policies; lsiv[index].nexthops_table = nexthops_table; + lsiv[index].nb_pg_table = nb_pg_table; ds_init(&lsiv[index].match); ds_init(&lsiv[index].actions); @@ -17289,6 +17311,7 @@ build_lswitch_and_lrouter_flows( .match = DS_EMPTY_INITIALIZER, .actions = DS_EMPTY_INITIALIZER, .nexthops_table = nexthops_table, + .nb_pg_table = nb_pg_table, }; /* Combined build - all lflow generation from lswitch and lrouter @@ -17358,7 +17381,9 @@ build_lswitch_and_lrouter_flows( * same NB Logical switch. */ ovs_assert(uuid_equals(&ls_stateful_rec->nbs_uuid, &od->nbs->header_.uuid)); - build_ls_stateful_flows(ls_stateful_rec, od, lsi.ls_port_groups, + build_ls_stateful_flows(ls_stateful_rec, od, + lsi.nb_pg_table, + lsi.ls_port_groups, lsi.meter_groups, lsi.sampling_apps, lsi.features, @@ -17453,6 +17478,7 @@ void build_lflows(struct ovsdb_idl_txn *ovnsb_txn, input_data->features, input_data->svc_monitor_mac, input_data->sampling_apps, + input_data->nbrec_port_group_table, input_data->parsed_routes, input_data->route_policies, input_data->route_tables, @@ -17879,6 +17905,7 @@ lflow_handle_ls_stateful_changes(struct ovsdb_idl_txn *ovnsb_txn, /* Generate new lflows. */ build_ls_stateful_flows(ls_stateful_rec, od, + lflow_input->nbrec_port_group_table, lflow_input->ls_port_groups, lflow_input->meter_groups, lflow_input->sampling_apps, diff --git a/northd/northd.h b/northd/northd.h index 6e0258ff4d..0deb39fd48 100644 --- a/northd/northd.h +++ b/northd/northd.h @@ -195,6 +195,9 @@ struct ecmp_nexthop_data { struct lr_nat_table; struct lflow_input { + /* Northbound table references. */ + const struct nbrec_port_group_table *nbrec_port_group_table; + /* Southbound table references */ const struct sbrec_logical_flow_table *sbrec_logical_flow_table; const struct sbrec_multicast_group_table *sbrec_multicast_group_table;