Skip to content

Commit

Permalink
northd: Fix non-functional incremental processing of port groups.
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Maximets <[email protected]>
  • Loading branch information
igsilya committed Aug 11, 2024
1 parent f0a3681 commit eea36c9
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 87 deletions.
3 changes: 3 additions & 0 deletions northd/en-lflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
85 changes: 55 additions & 30 deletions northd/en-ls-stateful.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,40 +49,45 @@ 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);
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;
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -282,18 +294,19 @@ 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)
{
struct ls_stateful_record *ls_stateful_rec =
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;
}
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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,
};
Expand Down
Loading

0 comments on commit eea36c9

Please sign in to comment.