Skip to content

Commit

Permalink
northd: Add lr_lb_nat_data handler for lflow engine node.
Browse files Browse the repository at this point in the history
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 Oct 24, 2023
1 parent f0a5ad0 commit 65833ec
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 190 deletions.
30 changes: 30 additions & 0 deletions northd/en-lflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,36 @@ lflow_port_group_handler(struct engine_node *node, void *data OVS_UNUSED)
return true;
}

bool
lflow_lr_lb_nat_data_handler(struct engine_node *node, void *data)
{
struct ed_type_lr_lb_nat_data *lr_lb_nat_data =
engine_get_input_data("lr_lb_nat_data", node);

if (!lr_lb_nat_data->tracked
|| lr_lb_nat_data->tracked_data.vip_nats_changed
|| !hmapx_is_empty(&lr_lb_nat_data->tracked_data.deleted)) {
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_lr_lb_nat_data_changes(eng_ctx->ovnsb_idl_txn,
&lr_lb_nat_data->tracked_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
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ void *en_lflow_init(struct engine_node *node, struct engine_arg *arg);
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_lb_nat_data_handler(struct engine_node *, void *data);

#endif /* EN_LFLOW_H */
41 changes: 34 additions & 7 deletions northd/en-lr-lb-nat-data.c
Original file line number Diff line number Diff line change
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_lr_lb_nat_data);
Expand Down Expand Up @@ -77,7 +78,7 @@ static void remove_lrouter_lb_reachable_ips(struct lr_lb_nat_data_record *,
enum lb_neighbor_responder_mode,
const struct sset *lb_ips_v4,
const struct sset *lb_ips_v6);
static void lr_lb_nat_data_build_vip_nats(struct lr_lb_nat_data_record *);
static bool lr_lb_nat_data_build_vip_nats(struct lr_lb_nat_data_record *);

const struct lr_lb_nat_data_record *
lr_lb_nat_data_table_find(
Expand Down Expand Up @@ -123,6 +124,7 @@ en_lr_lb_nat_data_clear_tracked_data(void *data_)
}

hmapx_clear(&data->tracked_data.crupdated);
data->tracked_data.vip_nats_changed = false;
data->tracked = false;
}

Expand Down Expand Up @@ -189,14 +191,17 @@ lr_lb_nat_data_lb_data_handler(struct engine_node *node, void *data_)
const struct lr_nat_record *lrnat_rec = lr_nat_table_find(
input_data.lr_nats, od->nbr);
ovs_assert(lrnat_rec);

lr_lbnat_rec = lr_lb_nat_data_record_create(&data->lr_lbnats,
lrnat_rec,
input_data.lb_datapaths_map,
input_data.lbgrp_datapaths_map);

/* Add the lr_lbnat_rec rec to the tracking data. */
hmapx_add(&data->tracked_data.crupdated, lr_lbnat_rec);

if (!sset_is_empty(&lr_lbnat_rec->vip_nats)) {
data->tracked_data.vip_nats_changed = true;
}
continue;
}

Expand Down Expand Up @@ -305,7 +310,9 @@ lr_lb_nat_data_lb_data_handler(struct engine_node *node, void *data_)
* vip nats and re-evaluate 'has_lb_vip'. */
HMAPX_FOR_EACH (hmapx_node, &data->tracked_data.crupdated) {
lr_lbnat_rec = hmapx_node->data;
lr_lb_nat_data_build_vip_nats(lr_lbnat_rec);
if (lr_lb_nat_data_build_vip_nats(lr_lbnat_rec)) {
data->tracked_data.vip_nats_changed = true;
}
lr_lbnat_rec->has_lb_vip = od_has_lb_vip(lr_lbnat_rec->od);
}

Expand Down Expand Up @@ -344,8 +351,13 @@ lr_lb_nat_data_lr_nat_handler(struct engine_node *node, void *data_)
lrnat_rec,
input_data.lb_datapaths_map,
input_data.lbgrp_datapaths_map);
if (!sset_is_empty(&lr_lbnat_rec->vip_nats)) {
data->tracked_data.vip_nats_changed = true;
}
} else {
lr_lb_nat_data_build_vip_nats(lr_lbnat_rec);
if (lr_lb_nat_data_build_vip_nats(lr_lbnat_rec)) {
data->tracked_data.vip_nats_changed = true;
}
}

/* Add the lr_lbnat_rec rec to the tracking data. */
Expand Down Expand Up @@ -424,6 +436,7 @@ lr_lb_nat_data_record_create(struct lr_lb_nat_data_table *table,
lr_lbnat_rec->od = lrnat_rec->od;
lr_lb_nat_data_record_init(lr_lbnat_rec, lb_datapaths_map,
lbgrp_datapaths_map);
lr_lbnat_rec->lflow_ref = lflow_ref_alloc(lr_lbnat_rec->od->nbr->name);

hmap_insert(&table->entries, &lr_lbnat_rec->key_node,
uuid_hash(&lr_lbnat_rec->od->nbr->header_.uuid));
Expand All @@ -437,6 +450,7 @@ lr_lb_nat_data_record_destroy(struct lr_lb_nat_data_record *lr_lbnat_rec)
ovn_lb_ip_set_destroy(lr_lbnat_rec->lb_ips);
lr_lbnat_rec->lb_ips = NULL;
sset_destroy(&lr_lbnat_rec->vip_nats);
lflow_ref_destroy(lr_lbnat_rec->lflow_ref);
free(lr_lbnat_rec);
}

Expand Down Expand Up @@ -503,7 +517,7 @@ lr_lb_nat_data_record_init(struct lr_lb_nat_data_record *lr_lbnat_rec,

sset_init(&lr_lbnat_rec->vip_nats);

if (!nbr->n_nat) {
if (nbr->n_nat) {
lr_lb_nat_data_build_vip_nats(lr_lbnat_rec);
}

Expand Down Expand Up @@ -617,10 +631,13 @@ remove_lrouter_lb_reachable_ips(struct lr_lb_nat_data_record *lr_lbnat_rec,
}
}

static void
/* Builds the vip nats and returns true if the lr_lbnat_rec->vip_nats
* changed, false otherwise. */
static bool
lr_lb_nat_data_build_vip_nats(struct lr_lb_nat_data_record *lr_lbnat_rec)
{
sset_clear(&lr_lbnat_rec->vip_nats);
struct sset old_vip_nats = SSET_INITIALIZER(&old_vip_nats);
sset_swap(&lr_lbnat_rec->vip_nats, &old_vip_nats);
const char *external_ip;
SSET_FOR_EACH (external_ip, &lr_lbnat_rec->lrnat_rec->external_ips) {
bool is_vip_nat = false;
Expand All @@ -636,4 +653,14 @@ lr_lb_nat_data_build_vip_nats(struct lr_lb_nat_data_record *lr_lbnat_rec)
sset_add(&lr_lbnat_rec->vip_nats, external_ip);
}
}

bool vip_nats_changed =
sset_count(&lr_lbnat_rec->vip_nats) != sset_count(&old_vip_nats);
if (!vip_nats_changed) {
vip_nats_changed = !sset_equals(&lr_lbnat_rec->vip_nats,
&old_vip_nats);
}
sset_destroy(&old_vip_nats);

return vip_nats_changed;
}
7 changes: 7 additions & 0 deletions northd/en-lr-lb-nat-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

struct ovn_datapath;
struct lr_nat_record;
struct lflow_ref;

struct lr_lb_nat_data_record {
struct hmap_node key_node; /* Index on 'nbr->header_.uuid'. */
Expand All @@ -46,6 +47,8 @@ struct lr_lb_nat_data_record {

/* sset of vips which are also part of lr nats. */
struct sset vip_nats;

struct lflow_ref *lflow_ref;
};

struct lr_lb_nat_data_table {
Expand All @@ -65,6 +68,10 @@ struct lr_lb_nat_data_tracked_data {

/* Deleted logical router with LB data. */
struct hmapx deleted; /* Stores 'struct lr_lb_nat_data_record'. */

/* Indicates if any router's NATs changed which were also LB vips
* or vice versa. */
bool vip_nats_changed;
};

struct ed_type_lr_lb_nat_data {
Expand Down
5 changes: 3 additions & 2 deletions northd/inc-proc-northd.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,11 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb,
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_sb_logical_dp_group, NULL);
engine_add_input(&en_lflow, &en_ls_lbacls, 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_lb_nat_data, NULL);
engine_add_input(&en_lflow, &en_ls_lbacls, NULL);
engine_add_input(&en_lflow, &en_lr_lb_nat_data,
lflow_lr_lb_nat_data_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
Loading

0 comments on commit 65833ec

Please sign in to comment.