Skip to content

Commit

Permalink
ovn-controller: Pass around pointers to individual tables.
Browse files Browse the repository at this point in the history
We're working to make ovn-controller compute more incrementally, to reduce
CPU usage.  To make it easier to keep track of dependencies, it makes sense
to pass around pointers to fine-grained resources instead of an entire
database at a time.  This commit introduces a way to pass individual tables
around and starts using that feature in ovn-controller.

CC: Han Zhou <zhouhan@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Han Zhou <hzhou8@ebay.com>
  • Loading branch information
blp committed Jun 11, 2018
1 parent 83293dd commit 0eb1e37
Show file tree
Hide file tree
Showing 22 changed files with 318 additions and 137 deletions.
9 changes: 6 additions & 3 deletions ovn/controller/bfd.c
Expand Up @@ -246,8 +246,11 @@ bfd_calculate_chassis(struct controller_ctx *ctx,
}

void
bfd_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
const struct sbrec_chassis *chassis_rec, const struct hmap *local_datapaths,
bfd_run(struct controller_ctx *ctx,
const struct ovsrec_interface_table *interface_table,
const struct ovsrec_bridge *br_int,
const struct sbrec_chassis *chassis_rec,
const struct hmap *local_datapaths,
const struct chassis_index *chassis_index)
{

Expand All @@ -274,7 +277,7 @@ bfd_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,

/* Enable or disable bfd */
const struct ovsrec_interface *iface;
OVSREC_INTERFACE_FOR_EACH (iface, ctx->ovs_idl) {
OVSREC_INTERFACE_TABLE_FOR_EACH (iface, interface_table) {
if (sset_contains(&tunnels, iface->name)) {
interface_set_bfd(
iface, sset_contains(&bfd_ifaces, iface->name));
Expand Down
5 changes: 4 additions & 1 deletion ovn/controller/bfd.h
Expand Up @@ -21,11 +21,14 @@ struct controller_ctx;
struct hmap;
struct ovsdb_idl;
struct ovsrec_bridge;
struct ovsrec_interface_table;
struct sbrec_chassis;
struct sset;

void bfd_register_ovs_idl(struct ovsdb_idl *);
void bfd_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
void bfd_run(struct controller_ctx *ctx,
const struct ovsrec_interface_table *interface_table,
const struct ovsrec_bridge *br_int,
const struct sbrec_chassis *chassis_rec,
const struct hmap *local_datapaths, const struct chassis_index *);
void bfd_calculate_active_tunnels(const struct ovsrec_bridge *br_int,
Expand Down
29 changes: 19 additions & 10 deletions ovn/controller/binding.c
Expand Up @@ -200,10 +200,11 @@ get_qos_params(const struct sbrec_port_binding *pb, struct hmap *queue_map)
}

static const struct ovsrec_qos *
get_noop_qos(struct controller_ctx *ctx)
get_noop_qos(struct controller_ctx *ctx,
const struct ovsrec_qos_table *qos_table)
{
const struct ovsrec_qos *qos;
OVSREC_QOS_FOR_EACH (qos, ctx->ovs_idl) {
OVSREC_QOS_TABLE_FOR_EACH (qos, qos_table) {
if (!strcmp(qos->type, "linux-noop")) {
return qos;
}
Expand All @@ -218,21 +219,24 @@ get_noop_qos(struct controller_ctx *ctx)
}

static bool
set_noop_qos(struct controller_ctx *ctx, struct sset *egress_ifaces)
set_noop_qos(struct controller_ctx *ctx,
const struct ovsrec_port_table *port_table,
const struct ovsrec_qos_table *qos_table,
struct sset *egress_ifaces)
{
if (!ctx->ovs_idl_txn) {
return false;
}

const struct ovsrec_qos *noop_qos = get_noop_qos(ctx);
const struct ovsrec_qos *noop_qos = get_noop_qos(ctx, qos_table);
if (!noop_qos) {
return false;
}

const struct ovsrec_port *port;
size_t count = 0;

OVSREC_PORT_FOR_EACH (port, ctx->ovs_idl) {
OVSREC_PORT_TABLE_FOR_EACH (port, port_table) {
if (sset_contains(egress_ifaces, port->name)) {
ovsrec_port_set_qos(port, noop_qos);
count++;
Expand Down Expand Up @@ -524,7 +528,11 @@ consider_localnet_port(const struct sbrec_port_binding *binding_rec,
}

void
binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
binding_run(struct controller_ctx *ctx,
const struct ovsrec_port_table *port_table,
const struct ovsrec_qos_table *qos_table,
const struct sbrec_port_binding_table *port_binding_table,
const struct ovsrec_bridge *br_int,
const struct sbrec_chassis *chassis_rec,
const struct chassis_index *chassis_index,
const struct sset *active_tunnels,
Expand All @@ -549,7 +557,7 @@ binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
/* Run through each binding record to see if it is resident on this
* chassis and update the binding accordingly. This includes both
* directly connected logical ports and children of those ports. */
SBREC_PORT_BINDING_FOR_EACH(binding_rec, ctx->ovnsb_idl) {
SBREC_PORT_BINDING_TABLE_FOR_EACH (binding_rec, port_binding_table) {
consider_local_datapath(ctx, chassis_index,
active_tunnels, chassis_rec, binding_rec,
sset_is_empty(&egress_ifaces) ? NULL :
Expand All @@ -561,14 +569,14 @@ binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
/* Run through each binding record to see if it is a localnet port
* on local datapaths discovered from above loop, and update the
* corresponding local datapath accordingly. */
SBREC_PORT_BINDING_FOR_EACH (binding_rec, ctx->ovnsb_idl) {
SBREC_PORT_BINDING_TABLE_FOR_EACH (binding_rec, port_binding_table) {
if (!strcmp(binding_rec->type, "localnet")) {
consider_localnet_port(binding_rec, local_datapaths);
}
}

if (!sset_is_empty(&egress_ifaces)
&& set_noop_qos(ctx, &egress_ifaces)) {
&& set_noop_qos(ctx, port_table, qos_table, &egress_ifaces)) {
const char *entry;
SSET_FOR_EACH (entry, &egress_ifaces) {
setup_qos(entry, &qos_map);
Expand All @@ -584,6 +592,7 @@ binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
* required. */
bool
binding_cleanup(struct controller_ctx *ctx,
const struct sbrec_port_binding_table *port_binding_table,
const struct sbrec_chassis *chassis_rec)
{
if (!ctx->ovnsb_idl_txn) {
Expand All @@ -600,7 +609,7 @@ binding_cleanup(struct controller_ctx *ctx,

const struct sbrec_port_binding *binding_rec;
bool any_changes = false;
SBREC_PORT_BINDING_FOR_EACH(binding_rec, ctx->ovnsb_idl) {
SBREC_PORT_BINDING_TABLE_FOR_EACH (binding_rec, port_binding_table) {
if (binding_rec->chassis == chassis_rec) {
sbrec_port_binding_set_chassis(binding_rec, NULL);
any_changes = true;
Expand Down
13 changes: 11 additions & 2 deletions ovn/controller/binding.h
Expand Up @@ -24,16 +24,25 @@ struct chassis_index;
struct hmap;
struct ovsdb_idl;
struct ovsrec_bridge;
struct ovsrec_port_table;
struct ovsrec_qos_table;
struct sbrec_chassis;
struct sbrec_port_binding_table;
struct sset;

void binding_register_ovs_idl(struct ovsdb_idl *);
void binding_run(struct controller_ctx *, const struct ovsrec_bridge *br_int,
void binding_run(struct controller_ctx *,
const struct ovsrec_port_table *,
const struct ovsrec_qos_table *,
const struct sbrec_port_binding_table *,
const struct ovsrec_bridge *br_int,
const struct sbrec_chassis *,
const struct chassis_index *,
const struct sset *active_tunnels,
struct hmap *local_datapaths,
struct sset *local_lports, struct sset *local_lport_ids);
bool binding_cleanup(struct controller_ctx *, const struct sbrec_chassis *);
bool binding_cleanup(struct controller_ctx *,
const struct sbrec_port_binding_table *,
const struct sbrec_chassis *);

#endif /* ovn/binding.h */
9 changes: 6 additions & 3 deletions ovn/controller/chassis.c
Expand Up @@ -75,7 +75,10 @@ get_cms_options(const struct smap *ext_ids)
/* Returns this chassis's Chassis record, if it is available and is currently
* amenable to a transaction. */
const struct sbrec_chassis *
chassis_run(struct controller_ctx *ctx, const char *chassis_id,
chassis_run(struct controller_ctx *ctx,
const struct ovsrec_open_vswitch_table *ovs_table,
const struct sbrec_chassis_table *chassis_table,
const char *chassis_id,
const struct ovsrec_bridge *br_int)
{
if (!ctx->ovnsb_idl_txn) {
Expand All @@ -86,7 +89,7 @@ chassis_run(struct controller_ctx *ctx, const char *chassis_id,
const char *encap_type, *encap_ip;
static bool inited = false;

cfg = ovsrec_open_vswitch_first(ctx->ovs_idl);
cfg = ovsrec_open_vswitch_table_first(ovs_table);
if (!cfg) {
VLOG_INFO("No Open_vSwitch row defined.");
return NULL;
Expand Down Expand Up @@ -136,7 +139,7 @@ chassis_run(struct controller_ctx *ctx, const char *chassis_id,
const char *iface_types_str = ds_cstr(&iface_types);

const struct sbrec_chassis *chassis_rec
= get_chassis(ctx->ovnsb_idl, chassis_id);
= get_chassis(chassis_table, chassis_id);
const char *encap_csum = smap_get_def(&cfg->external_ids,
"ovn-encap-csum", "true");
if (chassis_rec) {
Expand Down
9 changes: 6 additions & 3 deletions ovn/controller/chassis.h
Expand Up @@ -21,12 +21,15 @@
struct controller_ctx;
struct ovsdb_idl;
struct ovsrec_bridge;
struct ovsrec_open_vswitch_table;
struct sbrec_chassis;
struct sbrec_chassis_table;

void chassis_register_ovs_idl(struct ovsdb_idl *);
const struct sbrec_chassis *chassis_run(struct controller_ctx *,
const char *chassis_id,
const struct ovsrec_bridge *br_int);
const struct sbrec_chassis *chassis_run(
struct controller_ctx *, const struct ovsrec_open_vswitch_table *,
const struct sbrec_chassis_table *,
const char *chassis_id, const struct ovsrec_bridge *br_int);
bool chassis_cleanup(struct controller_ctx *, const struct sbrec_chassis *);

#endif /* ovn/chassis.h */
9 changes: 6 additions & 3 deletions ovn/controller/encaps.c
Expand Up @@ -153,7 +153,10 @@ preferred_encap(const struct sbrec_chassis *chassis_rec)
}

void
encaps_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
encaps_run(struct controller_ctx *ctx,
const struct ovsrec_bridge_table *bridge_table,
const struct ovsrec_bridge *br_int,
const struct sbrec_chassis_table *chassis_table,
const char *chassis_id)
{
if (!ctx->ovs_idl_txn || !br_int) {
Expand All @@ -177,7 +180,7 @@ encaps_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
/* Collect all port names into tc.port_names.
*
* Collect all the OVN-created tunnels into tc.tunnel_hmap. */
OVSREC_BRIDGE_FOR_EACH(br, ctx->ovs_idl) {
OVSREC_BRIDGE_TABLE_FOR_EACH (br, bridge_table) {
for (size_t i = 0; i < br->n_ports; i++) {
const struct ovsrec_port *port = br->ports[i];
sset_add(&tc.port_names, port->name);
Expand All @@ -198,7 +201,7 @@ encaps_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
}
}

SBREC_CHASSIS_FOR_EACH(chassis_rec, ctx->ovnsb_idl) {
SBREC_CHASSIS_TABLE_FOR_EACH (chassis_rec, chassis_table) {
if (strcmp(chassis_rec->name, chassis_id)) {
/* Create tunnels to the other chassis. */
const struct sbrec_encap *encap = preferred_encap(chassis_rec);
Expand Down
7 changes: 6 additions & 1 deletion ovn/controller/encaps.h
Expand Up @@ -21,10 +21,15 @@
struct controller_ctx;
struct ovsdb_idl;
struct ovsrec_bridge;
struct ovsrec_bridge_table;
struct sbrec_chassis_table;

void encaps_register_ovs_idl(struct ovsdb_idl *);
void encaps_run(struct controller_ctx *,
const struct ovsrec_bridge *br_int, const char *chassis_id);
const struct ovsrec_bridge_table *,
const struct ovsrec_bridge *br_int,
const struct sbrec_chassis_table *,
const char *chassis_id);
bool encaps_cleanup(struct controller_ctx *,
const struct ovsrec_bridge *br_int);

Expand Down
49 changes: 30 additions & 19 deletions ovn/controller/lflow.c
Expand Up @@ -137,40 +137,45 @@ is_switch(const struct sbrec_datapath_binding *ldp)

/* Adds the logical flows from the Logical_Flow table to flow tables. */
static void
add_logical_flows(struct controller_ctx *ctx,
const struct chassis_index *chassis_index,
const struct hmap *local_datapaths,
const struct sbrec_chassis *chassis,
const struct shash *addr_sets,
const struct shash *port_groups,
const struct sset *active_tunnels,
const struct sset *local_lport_ids,
struct hmap *flow_table,
struct ovn_extend_table *group_table,
struct ovn_extend_table *meter_table)
add_logical_flows(
struct controller_ctx *ctx,
const struct sbrec_dhcp_options_table *dhcp_options_table,
const struct sbrec_dhcpv6_options_table *dhcpv6_options_table,
const struct sbrec_logical_flow_table *logical_flow_table,
const struct chassis_index *chassis_index,
const struct hmap *local_datapaths,
const struct sbrec_chassis *chassis,
const struct shash *addr_sets,
const struct shash *port_groups,
const struct sset *active_tunnels,
const struct sset *local_lport_ids,
struct hmap *flow_table,
struct ovn_extend_table *group_table,
struct ovn_extend_table *meter_table)
{
uint32_t conj_id_ofs = 1;
const struct sbrec_logical_flow *lflow;

struct hmap dhcp_opts = HMAP_INITIALIZER(&dhcp_opts);
struct hmap dhcpv6_opts = HMAP_INITIALIZER(&dhcpv6_opts);
const struct sbrec_dhcp_options *dhcp_opt_row;
SBREC_DHCP_OPTIONS_FOR_EACH(dhcp_opt_row, ctx->ovnsb_idl) {
SBREC_DHCP_OPTIONS_TABLE_FOR_EACH (dhcp_opt_row, dhcp_options_table) {
dhcp_opt_add(&dhcp_opts, dhcp_opt_row->name, dhcp_opt_row->code,
dhcp_opt_row->type);
}


const struct sbrec_dhcpv6_options *dhcpv6_opt_row;
SBREC_DHCPV6_OPTIONS_FOR_EACH(dhcpv6_opt_row, ctx->ovnsb_idl) {
SBREC_DHCPV6_OPTIONS_TABLE_FOR_EACH (dhcpv6_opt_row,
dhcpv6_options_table) {
dhcp_opt_add(&dhcpv6_opts, dhcpv6_opt_row->name, dhcpv6_opt_row->code,
dhcpv6_opt_row->type);
}

struct hmap nd_ra_opts = HMAP_INITIALIZER(&nd_ra_opts);
nd_ra_opts_init(&nd_ra_opts);

SBREC_LOGICAL_FLOW_FOR_EACH (lflow, ctx->ovnsb_idl) {
SBREC_LOGICAL_FLOW_TABLE_FOR_EACH (lflow, logical_flow_table) {
consider_logical_flow(ctx, chassis_index, lflow, local_datapaths,
chassis, &dhcp_opts, &dhcpv6_opts, &nd_ra_opts,
addr_sets, port_groups, active_tunnels,
Expand Down Expand Up @@ -428,10 +433,11 @@ consider_neighbor_flow(struct controller_ctx *ctx,
* southbound database. */
static void
add_neighbor_flows(struct controller_ctx *ctx,
const struct sbrec_mac_binding_table *mac_binding_table,
struct hmap *flow_table)
{
const struct sbrec_mac_binding *b;
SBREC_MAC_BINDING_FOR_EACH (b, ctx->ovnsb_idl) {
SBREC_MAC_BINDING_TABLE_FOR_EACH (b, mac_binding_table) {
consider_neighbor_flow(ctx, b, flow_table);
}
}
Expand All @@ -440,6 +446,10 @@ add_neighbor_flows(struct controller_ctx *ctx,
* into OpenFlow flows. See ovn-architecture(7) for more information. */
void
lflow_run(struct controller_ctx *ctx,
const struct sbrec_dhcp_options_table *dhcp_options_table,
const struct sbrec_dhcpv6_options_table *dhcpv6_options_table,
const struct sbrec_logical_flow_table *logical_flow_table,
const struct sbrec_mac_binding_table *mac_binding_table,
const struct sbrec_chassis *chassis,
const struct chassis_index *chassis_index,
const struct hmap *local_datapaths,
Expand All @@ -453,10 +463,11 @@ lflow_run(struct controller_ctx *ctx,
{
COVERAGE_INC(lflow_run);

add_logical_flows(ctx, chassis_index, local_datapaths, chassis, addr_sets,
port_groups, active_tunnels, local_lport_ids,
flow_table, group_table, meter_table);
add_neighbor_flows(ctx, flow_table);
add_logical_flows(ctx, dhcp_options_table, dhcpv6_options_table,
logical_flow_table, chassis_index, local_datapaths,
chassis, addr_sets, port_groups, active_tunnels,
local_lport_ids, flow_table, group_table, meter_table);
add_neighbor_flows(ctx, mac_binding_table, flow_table);
}

void
Expand Down
8 changes: 8 additions & 0 deletions ovn/controller/lflow.h
Expand Up @@ -40,6 +40,10 @@ struct controller_ctx;
struct ovn_extend_table;
struct hmap;
struct sbrec_chassis;
struct sbrec_dhcp_options_table;
struct sbrec_dhcpv6_options_table;
struct sbrec_logical_flow_table;
struct sbrec_mac_binding_table;
struct simap;
struct sset;
struct uuid;
Expand All @@ -63,6 +67,10 @@ struct uuid;

void lflow_init(void);
void lflow_run(struct controller_ctx *,
const struct sbrec_dhcp_options_table *,
const struct sbrec_dhcpv6_options_table *,
const struct sbrec_logical_flow_table *,
const struct sbrec_mac_binding_table *,
const struct sbrec_chassis *chassis,
const struct chassis_index *,
const struct hmap *local_datapaths,
Expand Down

0 comments on commit 0eb1e37

Please sign in to comment.