Skip to content

Commit

Permalink
northd I-P: Sync SB load balancers in a separate engine node.
Browse files Browse the repository at this point in the history
Similar to the commit [1], a new sub-engine node "sync_to_sb_lb"
is added with-in the "sync_to_sb" to sync the SB load balancers.
Its main input nodes are "northd" (to access the "lbs" hmap built
by this node) and "sb_load_balancer" to access the SB load balancer.
"sync_to_sb_lb" doesn't add any handlers and falls back to full
recompute all the time.

[1] - ccafcc2("northd I-P: Add a new engine node 'en_sync_to_sb' to sync SB tables.")

Acked-by: Han Zhou <hzhou@ovn.org>
Reviewed-by: Ales Musil <amusil@redhat.com>
Acked-by: Mark Michelson <mmichels@redhat.com>
Signed-off-by: Numan Siddique <numans@ovn.org>
  • Loading branch information
numansiddique committed Sep 8, 2023
1 parent bfc3965 commit 5e5aeaa
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 8 deletions.
2 changes: 0 additions & 2 deletions northd/en-northd.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ northd_get_input_data(struct engine_node *node,
EN_OVSDB_GET(engine_get_input("SB_chassis", node));
input_data->sbrec_fdb_table =
EN_OVSDB_GET(engine_get_input("SB_fdb", node));
input_data->sbrec_load_balancer_table =
EN_OVSDB_GET(engine_get_input("SB_load_balancer", node));
input_data->sbrec_service_monitor_table =
EN_OVSDB_GET(engine_get_input("SB_service_monitor", node));
input_data->sbrec_dns_table =
Expand Down
43 changes: 43 additions & 0 deletions northd/en-sync-sb.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,49 @@ sync_to_sb_addr_set_nb_port_group_handler(struct engine_node *node,
return true;
}

/* sync_to_sb_lb engine node functions.
* This engine node syncs the SB load balancers.
*/
void *
en_sync_to_sb_lb_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
return NULL;
}

void
en_sync_to_sb_lb_run(struct engine_node *node, void *data OVS_UNUSED)
{
const struct sbrec_load_balancer_table *sb_load_balancer_table =
EN_OVSDB_GET(engine_get_input("SB_load_balancer", node));
const struct engine_context *eng_ctx = engine_get_context();
struct northd_data *northd_data = engine_get_input_data("northd", node);

sync_lbs(eng_ctx->ovnsb_idl_txn, sb_load_balancer_table,
&northd_data->ls_datapaths, &northd_data->lbs);
engine_set_node_state(node, EN_UPDATED);
}

void
en_sync_to_sb_lb_cleanup(void *data OVS_UNUSED)
{

}

bool
sync_to_sb_lb_northd_handler(struct engine_node *node, void *data OVS_UNUSED)
{
struct northd_data *nd = engine_get_input_data("northd", node);
if (nd->change_tracked) {
/* There are only NB LSP related changes and these can be safely
* ignore and returned true. However in case the northd engine
* tracking data includes other changes, we need to do additional
* checks before safely ignoring. */
return true;
}
return false;
}

/* static functions. */
static void
sync_addr_set(struct ovsdb_idl_txn *ovnsb_txn, const char *name,
Expand Down
6 changes: 6 additions & 0 deletions northd/en-sync-sb.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ bool sync_to_sb_addr_set_nb_address_set_handler(struct engine_node *,
bool sync_to_sb_addr_set_nb_port_group_handler(struct engine_node *,
void *data);


void *en_sync_to_sb_lb_init(struct engine_node *, struct engine_arg *);
void en_sync_to_sb_lb_run(struct engine_node *, void *data);
void en_sync_to_sb_lb_cleanup(void *data);
bool sync_to_sb_lb_northd_handler(struct engine_node *, void *data OVS_UNUSED);

#endif /* end of EN_SYNC_SB_H */
9 changes: 7 additions & 2 deletions northd/inc-proc-northd.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ static ENGINE_NODE(sync_to_sb_addr_set, "sync_to_sb_addr_set");
static ENGINE_NODE_WITH_CLEAR_TRACK_DATA(port_group, "port_group");
static ENGINE_NODE(fdb_aging, "fdb_aging");
static ENGINE_NODE(fdb_aging_waker, "fdb_aging_waker");
static ENGINE_NODE(sync_to_sb_lb, "sync_to_sb_lb");

void inc_proc_northd_init(struct ovsdb_idl_loop *nb,
struct ovsdb_idl_loop *sb)
Expand All @@ -165,7 +166,6 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb,
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_load_balancer, NULL);
engine_add_input(&en_northd, &en_sb_fdb, NULL);
engine_add_input(&en_northd, &en_sb_static_mac_binding, NULL);
engine_add_input(&en_northd, &en_sb_chassis_template_var, NULL);
Expand Down Expand Up @@ -216,14 +216,19 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb,
* table too (because of the explicit dependency in the schema). */
engine_add_input(&en_port_group, &en_northd, engine_noop_handler);

engine_add_input(&en_sync_to_sb_lb, &en_northd,
sync_to_sb_lb_northd_handler);
engine_add_input(&en_sync_to_sb_lb, &en_sb_load_balancer, NULL);

/* en_sync_to_sb engine node syncs the SB database tables from
* the NB database tables.
* Right now this engine syncs the SB Address_Set table, Port_Group table
* and SB Meter/Meter_Band tables.
* SB Meter/Meter_Band tables and SB Load_Balancer table.
*/
engine_add_input(&en_sync_to_sb, &en_sync_to_sb_addr_set, NULL);
engine_add_input(&en_sync_to_sb, &en_port_group, NULL);
engine_add_input(&en_sync_to_sb, &en_sync_meters, NULL);
engine_add_input(&en_sync_to_sb, &en_sync_to_sb_lb, NULL);

engine_add_input(&en_sync_from_sb, &en_northd,
sync_from_sb_northd_handler);
Expand Down
4 changes: 1 addition & 3 deletions northd/northd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4580,7 +4580,7 @@ ovn_dp_group_get_or_create(struct ovsdb_idl_txn *ovnsb_txn,
/* Syncs relevant load balancers (applied to logical switches) to the
* Southbound database.
*/
static void
void
sync_lbs(struct ovsdb_idl_txn *ovnsb_txn,
const struct sbrec_load_balancer_table *sbrec_load_balancer_table,
struct ovn_datapaths *ls_datapaths, struct hmap *lbs)
Expand Down Expand Up @@ -17251,8 +17251,6 @@ ovnnb_db_run(struct northd_input *input_data,
ovn_update_ipv6_options(&data->lr_ports);
ovn_update_ipv6_prefix(&data->lr_ports);

sync_lbs(ovnsb_txn, input_data->sbrec_load_balancer_table,
&data->ls_datapaths, &data->lbs);
sync_mirrors(ovnsb_txn, input_data->nbrec_mirror_table,
input_data->sbrec_mirror_table);
sync_dns_entries(ovnsb_txn, input_data->sbrec_dns_table,
Expand Down
5 changes: 4 additions & 1 deletion northd/northd.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "ovsdb-idl.h"

#include "lib/ovn-sb-idl.h"
#include "lib/ovn-util.h"
#include "lib/ovs-atomic.h"
#include "lib/sset.h"
Expand Down Expand Up @@ -45,7 +46,6 @@ struct northd_input {
const struct sbrec_ha_chassis_group_table *sbrec_ha_chassis_group_table;
const struct sbrec_chassis_table *sbrec_chassis_table;
const struct sbrec_fdb_table *sbrec_fdb_table;
const struct sbrec_load_balancer_table *sbrec_load_balancer_table;
const struct sbrec_service_monitor_table *sbrec_service_monitor_table;
const struct sbrec_dns_table *sbrec_dns_table;
const struct sbrec_ip_multicast_table *sbrec_ip_multicast_table;
Expand Down Expand Up @@ -350,4 +350,7 @@ const char *northd_get_svc_monitor_mac(void);

const struct ovn_datapath *northd_get_datapath_for_port(
const struct hmap *ls_ports, const char *port_name);
void sync_lbs(struct ovsdb_idl_txn *, const struct sbrec_load_balancer_table *,
struct ovn_datapaths *ls_datapaths, struct hmap *lbs);

#endif /* NORTHD_H */
23 changes: 23 additions & 0 deletions tests/ovn-northd.at
Original file line number Diff line number Diff line change
Expand Up @@ -9954,6 +9954,29 @@ AT_CHECK([ovn-sbctl lflow-list sw | grep ls_out_pre_lb | grep priority=110 | gre
AT_CLEANUP
])


# This test checks the compute/recompute stats of sync_to_sb_lb engine node
OVN_FOR_EACH_NORTHD_NO_HV([
AT_SETUP([sync_to_sb_lb incremental processing])
ovn_start

check ovn-nbctl ls-add sw
check ovn-nbctl lsp-add sw p1

check ovn-nbctl --wait=sb sync
check as northd ovn-appctl -t NORTHD_TYPE inc-engine/clear-stats

check ovn-nbctl --wait=sb lsp-set-options p1 foo=bar
sb_lb_recomp=$(as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats sync_to_sb_lb recompute)
AT_CHECK([test x$sb_lb_recomp = x0])

check ovn-nbctl --wait=sb lsp-set-type p1 external
sb_lb_recomp=$(as northd ovn-appctl -t NORTHD_TYPE inc-engine/show-stats sync_to_sb_lb recompute)
AT_CHECK([test x$sb_lb_recomp != x0])

AT_CLEANUP
])

OVN_FOR_EACH_NORTHD_NO_HV([
AT_SETUP([LSP incremental processing])
ovn_start
Expand Down

0 comments on commit 5e5aeaa

Please sign in to comment.