Skip to content

Commit

Permalink
northd: I-P for logical switch creation in en_northd engine node.
Browse files Browse the repository at this point in the history
This patch handles the logical switch creation incrementally
in the northd engine node.  The dependent engine nodes - ls_stateful,
lflow and few others still fall back to full recompute, which
will be handled in separate patches.

Reported-at: https://issues.redhat.com/browse/FDP-754
Signed-off-by: Numan Siddique <numans@ovn.org>
Signed-off-by: 0-day Robot <robot@bytheb.org>
  • Loading branch information
numansiddique authored and ovsrobot committed Jan 10, 2025
1 parent 719c602 commit 6fa5a8a
Show file tree
Hide file tree
Showing 11 changed files with 467 additions and 45 deletions.
23 changes: 23 additions & 0 deletions lib/ovn-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define OVN_UTIL_H 1

#include "ovsdb-idl.h"
#include "lib/bitmap.h"
#include "lib/packets.h"
#include "lib/sset.h"
#include "lib/svec.h"
Expand Down Expand Up @@ -472,6 +473,28 @@ void sorted_array_apply_diff(const struct sorted_array *a1,
bool add),
const void *arg);

static inline unsigned long *
ovn_bitmap_realloc(unsigned long *bitmap, size_t n_bits_old,
size_t n_bits_new)
{
ovs_assert(n_bits_new >= n_bits_old);

if (bitmap_n_bytes(n_bits_old) == bitmap_n_bytes(n_bits_new)) {
return bitmap;
}

bitmap = xrealloc(bitmap, bitmap_n_bytes(n_bits_new));

/* Set the unitialized bits to 0 as xrealloc doesn't initialize the
* added memory. */
size_t i;
for (i = BITMAP_N_LONGS(n_bits_old); i < BITMAP_N_LONGS(n_bits_new); i++) {
bitmap[i] = 0;
}

return bitmap;
}

/* Utilities around properly handling exit command. */
struct ovn_exit_args {
struct unixctl_conn **conns;
Expand Down
4 changes: 4 additions & 0 deletions northd/en-lflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ lflow_northd_handler(struct engine_node *node,
return false;
}

if (northd_has_lswitchs_in_tracked_data(&northd_data->trk_data)) {
return false;
}

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

Expand Down
4 changes: 4 additions & 0 deletions northd/en-ls-stateful.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ ls_stateful_northd_handler(struct engine_node *node, void *data_)
return false;
}

if (northd_has_lswitchs_in_tracked_data(&northd_data->trk_data)) {
return false;
}

if (!northd_has_ls_lbs_in_tracked_data(&northd_data->trk_data) &&
!northd_has_ls_acls_in_tracked_data(&northd_data->trk_data)) {
return true;
Expand Down
19 changes: 19 additions & 0 deletions northd/en-northd.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,25 @@ northd_nb_logical_switch_handler(struct engine_node *node,
return true;
}

bool
northd_sb_datapath_binding_handler(struct engine_node *node,
void *data)
{
struct northd_data *nd = data;

struct northd_input input_data;

northd_get_input_data(node, &input_data);

if (!northd_handle_sb_datapath_binding_changes(
input_data.sbrec_datapath_binding_table, &nd->ls_datapaths,
&nd->lr_datapaths)) {
return false;
}

return true;
}

bool
northd_sb_port_binding_handler(struct engine_node *node,
void *data)
Expand Down
1 change: 1 addition & 0 deletions northd/en-northd.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ bool northd_global_config_handler(struct engine_node *, void *data OVS_UNUSED);
bool northd_nb_logical_switch_handler(struct engine_node *, void *data);
bool northd_nb_logical_router_handler(struct engine_node *, void *data);
bool northd_sb_port_binding_handler(struct engine_node *, void *data);
bool northd_sb_datapath_binding_handler(struct engine_node *, void *data);
bool northd_lb_data_handler(struct engine_node *, void *data);
bool northd_sb_fdb_change_handler(struct engine_node *node, void *data);
void *en_routes_init(struct engine_node *node OVS_UNUSED,
Expand Down
8 changes: 6 additions & 2 deletions northd/inc-proc-northd.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,8 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb,
engine_add_input(&en_northd, &en_sb_chassis, NULL);
engine_add_input(&en_northd, &en_sb_mirror, NULL);
engine_add_input(&en_northd, &en_sb_meter, NULL);
engine_add_input(&en_northd, &en_sb_datapath_binding, NULL);
engine_add_input(&en_northd, &en_sb_dns, NULL);
engine_add_input(&en_northd, &en_sb_ha_chassis_group, NULL);
engine_add_input(&en_northd, &en_sb_ip_multicast, NULL);
engine_add_input(&en_northd, &en_sb_service_monitor, NULL);
engine_add_input(&en_northd, &en_sb_static_mac_binding, NULL);
engine_add_input(&en_northd, &en_sb_chassis_template_var, NULL);
Expand All @@ -215,6 +213,8 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb,
engine_add_input(&en_northd, &en_sb_mac_binding,
engine_noop_handler);

engine_add_input(&en_northd, &en_sb_datapath_binding,
northd_sb_datapath_binding_handler);
engine_add_input(&en_northd, &en_sb_port_binding,
northd_sb_port_binding_handler);
engine_add_input(&en_northd, &en_nb_logical_switch,
Expand All @@ -223,6 +223,10 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb,
northd_nb_logical_router_handler);
engine_add_input(&en_northd, &en_lb_data, northd_lb_data_handler);

/* No need for an explicit handler for the SB datapath and
* SB IP Multicast changes.*/
engine_add_input(&en_northd, &en_sb_ip_multicast, engine_noop_handler);

engine_add_input(&en_lr_nat, &en_northd, lr_nat_northd_handler);

engine_add_input(&en_lr_stateful, &en_northd, lr_stateful_northd_handler);
Expand Down
44 changes: 42 additions & 2 deletions northd/lb.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ static struct nbrec_load_balancer_health_check *
ovn_lb_get_health_check(const struct nbrec_load_balancer *nbrec_lb,
const char *vip_port_str, bool template);

static void ovn_lb_datapaths_realloc_ls_map(struct ovn_lb_datapaths *,
size_t n_ls_datapaths);
static void ovn_lb_datapaths_realloc_lr_map(struct ovn_lb_datapaths *,
size_t n_lr_datapaths);

struct ovn_lb_ip_set *
ovn_lb_ip_set_create(void)
{
Expand Down Expand Up @@ -564,6 +569,8 @@ ovn_lb_datapaths_create(const struct ovn_northd_lb *lb, size_t n_ls_datapaths,
lb_dps->lb = lb;
lb_dps->nb_ls_map = bitmap_allocate(n_ls_datapaths);
lb_dps->nb_lr_map = bitmap_allocate(n_lr_datapaths);
lb_dps->ls_map_size = n_ls_datapaths;
lb_dps->lr_map_size = n_lr_datapaths;
lb_dps->lflow_ref = lflow_ref_create();

return lb_dps;
Expand All @@ -580,9 +587,12 @@ ovn_lb_datapaths_destroy(struct ovn_lb_datapaths *lb_dps)

void
ovn_lb_datapaths_add_lr(struct ovn_lb_datapaths *lb_dps, size_t n,
struct ovn_datapath **ods)
struct ovn_datapath **ods,
size_t n_lr_datapaths)
{
ovn_lb_datapaths_realloc_lr_map(lb_dps, n_lr_datapaths);
for (size_t i = 0; i < n; i++) {
ovs_assert(ods[i]->index < lb_dps->lr_map_size);
if (!bitmap_is_set(lb_dps->nb_lr_map, ods[i]->index)) {
bitmap_set1(lb_dps->nb_lr_map, ods[i]->index);
lb_dps->n_nb_lr++;
Expand All @@ -592,9 +602,12 @@ ovn_lb_datapaths_add_lr(struct ovn_lb_datapaths *lb_dps, size_t n,

void
ovn_lb_datapaths_add_ls(struct ovn_lb_datapaths *lb_dps, size_t n,
struct ovn_datapath **ods)
struct ovn_datapath **ods,
size_t n_ls_datapaths)
{
ovn_lb_datapaths_realloc_ls_map(lb_dps, n_ls_datapaths);
for (size_t i = 0; i < n; i++) {
ovs_assert(ods[i]->index < lb_dps->ls_map_size);
if (!bitmap_is_set(lb_dps->nb_ls_map, ods[i]->index)) {
bitmap_set1(lb_dps->nb_ls_map, ods[i]->index);
lb_dps->n_nb_ls++;
Expand Down Expand Up @@ -626,6 +639,8 @@ ovn_lb_group_datapaths_create(const struct ovn_lb_group *lb_group,
lb_group_dps->lb_group = lb_group;
lb_group_dps->ls = xmalloc(max_ls_datapaths * sizeof *lb_group_dps->ls);
lb_group_dps->lr = xmalloc(max_lr_datapaths * sizeof *lb_group_dps->lr);
lb_group_dps->max_lr = max_ls_datapaths;
lb_group_dps->max_lr = max_lr_datapaths;

return lb_group_dps;
}
Expand All @@ -652,3 +667,28 @@ ovn_lb_group_datapaths_find(const struct hmap *lb_group_dps_map,
}
return NULL;
}

/* Static functions. */
static void
ovn_lb_datapaths_realloc_ls_map(struct ovn_lb_datapaths *lb_dps,
size_t n_ls_datapaths)
{
if (n_ls_datapaths > lb_dps->ls_map_size) {
lb_dps->nb_ls_map = ovn_bitmap_realloc(lb_dps->nb_ls_map,
lb_dps->ls_map_size,
n_ls_datapaths);
lb_dps->ls_map_size = n_ls_datapaths;
}
}

static void
ovn_lb_datapaths_realloc_lr_map(struct ovn_lb_datapaths *lb_dps,
size_t n_lr_datapaths)
{
if (n_lr_datapaths > lb_dps->lr_map_size) {
lb_dps->nb_lr_map = ovn_bitmap_realloc(lb_dps->nb_lr_map,
lb_dps->lr_map_size,
n_lr_datapaths);
lb_dps->lr_map_size = n_lr_datapaths;
}
}
36 changes: 27 additions & 9 deletions northd/lb.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,13 @@ struct ovn_lb_datapaths {
struct hmap_node hmap_node;

const struct ovn_northd_lb *lb;
size_t n_nb_ls;
unsigned long *nb_ls_map;
size_t ls_map_size;
size_t n_nb_ls;

size_t n_nb_lr;
unsigned long *nb_lr_map;
size_t lr_map_size;
size_t n_nb_lr;

/* Reference of lflows generated for this load balancer.
*
Expand Down Expand Up @@ -175,20 +177,24 @@ struct ovn_lb_datapaths *ovn_lb_datapaths_find(const struct hmap *,
void ovn_lb_datapaths_destroy(struct ovn_lb_datapaths *);

void ovn_lb_datapaths_add_lr(struct ovn_lb_datapaths *, size_t n,
struct ovn_datapath **);
struct ovn_datapath **,
size_t n_lr_datapaths);
void ovn_lb_datapaths_add_ls(struct ovn_lb_datapaths *, size_t n,
struct ovn_datapath **);

struct ovn_datapath **,
size_t n_ls_datapaths);
struct ovn_lb_group_datapaths {
struct hmap_node hmap_node;

const struct ovn_lb_group *lb_group;

/* Datapaths to which 'lb_group' is applied. */
size_t n_ls;
struct ovn_datapath **ls;
size_t n_lr;
size_t max_ls;
size_t n_ls;

struct ovn_datapath **lr;
size_t max_lr;
size_t n_lr;
};

struct ovn_lb_group_datapaths *ovn_lb_group_datapaths_create(
Expand All @@ -201,16 +207,28 @@ struct ovn_lb_group_datapaths *ovn_lb_group_datapaths_find(

static inline void
ovn_lb_group_datapaths_add_ls(struct ovn_lb_group_datapaths *lbg_dps, size_t n,
struct ovn_datapath **ods)
struct ovn_datapath **ods,
size_t n_ls_datapaths)
{
if (n_ls_datapaths > lbg_dps->max_ls) {
lbg_dps->ls = xrealloc(lbg_dps->ls,
n_ls_datapaths * sizeof *lbg_dps->ls);
lbg_dps->max_ls = n_ls_datapaths;
}
memcpy(&lbg_dps->ls[lbg_dps->n_ls], ods, n * sizeof *ods);
lbg_dps->n_ls += n;
}

static inline void
ovn_lb_group_datapaths_add_lr(struct ovn_lb_group_datapaths *lbg_dps,
struct ovn_datapath *lr)
struct ovn_datapath *lr,
size_t n_lr_datapaths)
{
if (n_lr_datapaths > lbg_dps->max_lr) {
lbg_dps->lr = xrealloc(lbg_dps->lr,
n_lr_datapaths * sizeof *lbg_dps->lr);
lbg_dps->max_lr = n_lr_datapaths;
}
lbg_dps->lr[lbg_dps->n_lr++] = lr;
}

Expand Down
Loading

0 comments on commit 6fa5a8a

Please sign in to comment.