Skip to content

Commit

Permalink
northd: Add ls_stateful handler for lflow engine node.
Browse files Browse the repository at this point in the history
Acked-by: Dumitru Ceara <dceara@redhat.com>
Acked-by: Han Zhou <hzhou@ovn.org>
Signed-off-by: Numan Siddique <numans@ovn.org>
(cherry picked from commit 00cda5a)
  • Loading branch information
numansiddique committed Feb 2, 2024
1 parent 2f64686 commit 6bd5661
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 38 deletions.
26 changes: 26 additions & 0 deletions northd/en-lflow.c
Expand Up @@ -190,6 +190,32 @@ lflow_lr_stateful_handler(struct engine_node *node, void *data)
return true;
}

bool
lflow_ls_stateful_handler(struct engine_node *node, void *data)
{
struct ed_type_ls_stateful *ls_sful_data =
engine_get_input_data("ls_stateful", node);

if (!ls_stateful_has_tracked_data(&ls_sful_data->trk_data)) {
return false;
}

const struct engine_context *eng_ctx = engine_get_context();
struct lflow_data *lflow_data = data;
struct lflow_input lflow_input;

lflow_get_input_data(node, &lflow_input);
if (!lflow_handle_ls_stateful_changes(eng_ctx->ovnsb_idl_txn,
&ls_sful_data->trk_data,
&lflow_input,
lflow_data->lflow_table)) {
return false;
}

engine_set_node_state(node, EN_UPDATED);
return true;
}

void *en_lflow_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
Expand Down
1 change: 1 addition & 0 deletions northd/en-lflow.h
Expand Up @@ -21,5 +21,6 @@ void en_lflow_cleanup(void *data);
bool lflow_northd_handler(struct engine_node *, void *data);
bool lflow_port_group_handler(struct engine_node *, void *data);
bool lflow_lr_stateful_handler(struct engine_node *, void *data);
bool lflow_ls_stateful_handler(struct engine_node *node, void *data);

#endif /* EN_LFLOW_H */
9 changes: 6 additions & 3 deletions northd/en-ls-stateful.c
Expand Up @@ -39,6 +39,7 @@
#include "lib/ovn-sb-idl.h"
#include "lib/ovn-util.h"
#include "lib/stopwatch-names.h"
#include "lflow-mgr.h"
#include "northd.h"

VLOG_DEFINE_THIS_MODULE(en_ls_stateful);
Expand Down Expand Up @@ -289,6 +290,7 @@ ls_stateful_record_create(struct ls_stateful_table *table,
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_rec->lflow_ref = lflow_ref_create();

hmap_insert(&table->entries, &ls_stateful_rec->key_node,
uuid_hash(&od->nbs->header_.uuid));
Expand All @@ -299,14 +301,15 @@ ls_stateful_record_create(struct ls_stateful_table *table,
static void
ls_stateful_record_destroy(struct ls_stateful_record *ls_stateful_rec)
{
lflow_ref_destroy(ls_stateful_rec->lflow_ref);
free(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 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);
Expand Down
26 changes: 26 additions & 0 deletions northd/en-ls-stateful.h
Expand Up @@ -31,6 +31,8 @@
#include "lib/ovn-util.h"
#include "lib/stopwatch-names.h"

struct lflow_ref;

struct ls_stateful_record {
struct hmap_node key_node;

Expand All @@ -45,6 +47,30 @@ struct ls_stateful_record {
bool has_lb_vip;
bool has_acls;
uint64_t max_acl_tier;

/* 'lflow_ref' is used to reference logical flows generated for
* this ls_stateful record.
*
* This data is initialized and destroyed by the en_ls_stateful node,
* but populated and used only by the en_lflow node. Ideally this data
* should be maintained as part of en_lflow's data. However, it would
* be less efficient and more complex:
*
* 1. It would require an extra search (using the index) to find the
* lflows.
*
* 2. Building the index needs to be thread-safe, using either a global
* lock which is obviously less efficient, or hash-based lock array which
* is more complex.
*
* Adding the lflow_ref here is more straightforward. The drawback is that
* we need to keep in mind that this data belongs to en_lflow node, so
* never access it from any other nodes.
*
* Note: lflow_ref is not thread safe. Only one thread should
* access ls_stateful_record->lflow_ref at any given time.
*/
struct lflow_ref *lflow_ref;
};

struct ls_stateful_table {
Expand Down
2 changes: 1 addition & 1 deletion northd/inc-proc-northd.c
Expand Up @@ -228,11 +228,11 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb,
engine_add_input(&en_lflow, &en_sb_logical_flow, NULL);
engine_add_input(&en_lflow, &en_sb_multicast_group, NULL);
engine_add_input(&en_lflow, &en_sb_igmp_group, NULL);
engine_add_input(&en_lflow, &en_ls_stateful, NULL);
engine_add_input(&en_lflow, &en_sb_logical_dp_group, NULL);
engine_add_input(&en_lflow, &en_northd, lflow_northd_handler);
engine_add_input(&en_lflow, &en_port_group, lflow_port_group_handler);
engine_add_input(&en_lflow, &en_lr_stateful, lflow_lr_stateful_handler);
engine_add_input(&en_lflow, &en_ls_stateful, lflow_ls_stateful_handler);

engine_add_input(&en_sync_to_sb_addr_set, &en_nb_address_set,
sync_to_sb_addr_set_nb_address_set_handler);
Expand Down
61 changes: 56 additions & 5 deletions northd/northd.c
Expand Up @@ -15849,12 +15849,15 @@ build_ls_stateful_flows(const struct ls_stateful_record *ls_stateful_rec,
const struct shash *meter_groups,
struct lflow_table *lflows)
{
build_ls_stateful_rec_pre_acls(ls_stateful_rec, od, ls_pgs, lflows, NULL);
build_ls_stateful_rec_pre_lb(ls_stateful_rec, od, lflows, NULL);
build_acl_hints(ls_stateful_rec, od, features, lflows, NULL);
build_ls_stateful_rec_pre_acls(ls_stateful_rec, od, 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, features, lflows,
ls_stateful_rec->lflow_ref);
build_acls(ls_stateful_rec, od, features, lflows, ls_pgs,
meter_groups, NULL);
build_lb_hairpin(ls_stateful_rec, od, lflows, NULL);
meter_groups, ls_stateful_rec->lflow_ref);
build_lb_hairpin(ls_stateful_rec, od, lflows, ls_stateful_rec->lflow_ref);
}

struct lswitch_flow_build_info {
Expand Down Expand Up @@ -16025,6 +16028,7 @@ build_lflows_thread(void *arg)
* - op->lflow_ref
* - lb_dps->lflow_ref
* - lr_stateful_rec->lflow_ref
* - ls_stateful_rec->lflow_ref
* are not accessed by multiple threads at the same time. */
while (!stop_parallel_processing()) {
wait_for_work(control);
Expand Down Expand Up @@ -16532,6 +16536,7 @@ void
lflow_reset_northd_refs(struct lflow_input *lflow_input)
{
const struct lr_stateful_record *lr_stateful_rec;
struct ls_stateful_record *ls_stateful_rec;
struct ovn_lb_datapaths *lb_dps;
struct ovn_port *op;

Expand All @@ -16540,6 +16545,11 @@ lflow_reset_northd_refs(struct lflow_input *lflow_input)
lflow_ref_clear(lr_stateful_rec->lflow_ref);
}

LS_STATEFUL_TABLE_FOR_EACH (ls_stateful_rec,
lflow_input->ls_stateful_table) {
lflow_ref_clear(ls_stateful_rec->lflow_ref);
}

HMAP_FOR_EACH (op, key_node, lflow_input->ls_ports) {
lflow_ref_clear(op->lflow_ref);
lflow_ref_clear(op->stateful_lflow_ref);
Expand Down Expand Up @@ -16859,6 +16869,47 @@ lflow_handle_lr_stateful_changes(struct ovsdb_idl_txn *ovnsb_txn,
return handled;
}

bool
lflow_handle_ls_stateful_changes(struct ovsdb_idl_txn *ovnsb_txn,
struct ls_stateful_tracked_data *trk_data,
struct lflow_input *lflow_input,
struct lflow_table *lflows)
{
struct hmapx_node *hmapx_node;

HMAPX_FOR_EACH (hmapx_node, &trk_data->crupdated) {
struct ls_stateful_record *ls_stateful_rec = hmapx_node->data;
const struct ovn_datapath *od =
ovn_datapaths_find_by_index(lflow_input->ls_datapaths,
ls_stateful_rec->ls_index);
ovs_assert(od->nbs && uuid_equals(&od->nbs->header_.uuid,
&ls_stateful_rec->nbs_uuid));

lflow_ref_unlink_lflows(ls_stateful_rec->lflow_ref);

/* Generate new lflows. */
build_ls_stateful_flows(ls_stateful_rec, od,
lflow_input->ls_port_groups,
lflow_input->features,
lflow_input->meter_groups,
lflows);

/* Sync the new flows to SB. */
bool handled = lflow_ref_sync_lflows(
ls_stateful_rec->lflow_ref, lflows, ovnsb_txn,
lflow_input->ls_datapaths,
lflow_input->lr_datapaths,
lflow_input->ovn_internal_version_changed,
lflow_input->sbrec_logical_flow_table,
lflow_input->sbrec_logical_dp_group_table);
if (!handled) {
return false;
}
}

return true;
}

static bool
mirror_needs_update(const struct nbrec_mirror *nb_mirror,
const struct sbrec_mirror *sb_mirror)
Expand Down
5 changes: 5 additions & 0 deletions northd/northd.h
Expand Up @@ -678,6 +678,7 @@ void northd_indices_create(struct northd_data *data,

struct lflow_table;
struct lr_stateful_tracked_data;
struct ls_stateful_tracked_data;

void build_lflows(struct ovsdb_idl_txn *ovnsb_txn,
struct lflow_input *input_data,
Expand All @@ -696,6 +697,10 @@ bool lflow_handle_lr_stateful_changes(struct ovsdb_idl_txn *,
struct lr_stateful_tracked_data *,
struct lflow_input *,
struct lflow_table *lflows);
bool lflow_handle_ls_stateful_changes(struct ovsdb_idl_txn *,
struct ls_stateful_tracked_data *,
struct lflow_input *,
struct lflow_table *lflows);
bool northd_handle_sb_port_binding_changes(
const struct sbrec_port_binding_table *, struct hmap *ls_ports,
struct hmap *lr_ports);
Expand Down

0 comments on commit 6bd5661

Please sign in to comment.