Skip to content

Commit

Permalink
chassis-index: Use OVSDB index mechanism.
Browse files Browse the repository at this point in the history
It seems like a good idea to use the built-in indexing instead of doing it
by hand.

Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Han Zhou <[email protected]>
  • Loading branch information
blp committed Jun 12, 2018
1 parent d14e007 commit 789ddaf
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 191 deletions.
23 changes: 12 additions & 11 deletions ovn/controller/bfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ bfd_travel_gw_related_chassis(

static struct ovs_list *
bfd_find_ha_gateway_chassis(
struct ovsdb_idl_index *sbrec_chassis_by_name,
struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
const struct chassis_index *chassis_index,
const struct sbrec_datapath_binding *datapath)
{
struct sbrec_port_binding *target = sbrec_port_binding_index_init_row(
Expand All @@ -203,7 +203,7 @@ bfd_find_ha_gateway_chassis(
}

struct ovs_list *gateway_chassis = gateway_chassis_get_ordered(
pb, chassis_index);
sbrec_chassis_by_name, pb);
if (!gateway_chassis || ovs_list_is_short(gateway_chassis)) {
/* We don't need BFD for non-HA chassisredirect. */
gateway_chassis_destroy(gateway_chassis);
Expand All @@ -219,10 +219,10 @@ bfd_find_ha_gateway_chassis(

static void
bfd_calculate_chassis(
struct ovsdb_idl_index *sbrec_chassis_by_name,
struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
const struct sbrec_chassis *our_chassis,
const struct hmap *local_datapaths,
const struct chassis_index *chassis_index,
struct sset *bfd_chassis)
{
/* Identify all chassis nodes to which we need to enable bfd.
Expand All @@ -239,8 +239,9 @@ bfd_calculate_chassis(
bool our_chassis_is_gw_for_dp = false;
if (is_router) {
struct ovs_list *ha_gateway_chassis
= bfd_find_ha_gateway_chassis(sbrec_port_binding_by_datapath,
chassis_index, dp->datapath);
= bfd_find_ha_gateway_chassis(sbrec_chassis_by_name,
sbrec_port_binding_by_datapath,
dp->datapath);
if (ha_gateway_chassis) {
our_chassis_is_gw_for_dp = gateway_chassis_contains(
ha_gateway_chassis, our_chassis);
Expand All @@ -261,21 +262,21 @@ bfd_calculate_chassis(
}

void
bfd_run(struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
bfd_run(struct ovsdb_idl_index *sbrec_chassis_by_name,
struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
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)
const struct hmap *local_datapaths)
{

if (!chassis_rec) {
return;
}
struct sset bfd_chassis = SSET_INITIALIZER(&bfd_chassis);
bfd_calculate_chassis(sbrec_port_binding_by_datapath,
chassis_rec, local_datapaths, chassis_index,
&bfd_chassis);
bfd_calculate_chassis(sbrec_chassis_by_name,
sbrec_port_binding_by_datapath,
chassis_rec, local_datapaths, &bfd_chassis);
/* Identify tunnels ports(connected to remote chassis id) to enable bfd */
struct sset tunnels = SSET_INITIALIZER(&tunnels);
struct sset bfd_ifaces = SSET_INITIALIZER(&bfd_ifaces);
Expand Down
6 changes: 3 additions & 3 deletions ovn/controller/bfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#ifndef OVN_BFD_H
#define OVN_BFD_H 1

struct chassis_index;
struct controller_ctx;
struct hmap;
struct ovsdb_idl;
Expand All @@ -27,11 +26,12 @@ struct sbrec_chassis;
struct sset;

void bfd_register_ovs_idl(struct ovsdb_idl *);
void bfd_run(struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
void bfd_run(struct ovsdb_idl_index *sbrec_chassis_by_name,
struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
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 *);
const struct hmap *local_datapaths);
void bfd_calculate_active_tunnels(const struct ovsrec_bridge *br_int,
struct sset *active_tunnels);

Expand Down
13 changes: 7 additions & 6 deletions ovn/controller/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,10 @@ update_local_lport_ids(struct sset *local_lport_ids,

static void
consider_local_datapath(struct controller_ctx *ctx,
struct ovsdb_idl_index *sbrec_chassis_by_name,
struct ovsdb_idl_index *sbrec_datapath_binding_by_key,
struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
struct ovsdb_idl_index *sbrec_port_binding_by_name,
const struct chassis_index *chassis_index,
const struct sset *active_tunnels,
const struct sbrec_chassis *chassis_rec,
const struct sbrec_port_binding *binding_rec,
Expand Down Expand Up @@ -441,8 +441,8 @@ consider_local_datapath(struct controller_ctx *ctx,
binding_rec->datapath, false, local_datapaths);
}
} else if (!strcmp(binding_rec->type, "chassisredirect")) {
gateway_chassis = gateway_chassis_get_ordered(binding_rec,
chassis_index);
gateway_chassis = gateway_chassis_get_ordered(sbrec_chassis_by_name,
binding_rec);
if (gateway_chassis &&
gateway_chassis_contains(gateway_chassis, chassis_rec)) {

Expand Down Expand Up @@ -546,6 +546,7 @@ consider_localnet_port(const struct sbrec_port_binding *binding_rec,

void
binding_run(struct controller_ctx *ctx,
struct ovsdb_idl_index *sbrec_chassis_by_name,
struct ovsdb_idl_index *sbrec_datapath_binding_by_key,
struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
struct ovsdb_idl_index *sbrec_port_binding_by_name,
Expand All @@ -554,7 +555,6 @@ binding_run(struct controller_ctx *ctx,
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,
struct hmap *local_datapaths, struct sset *local_lports,
struct sset *local_lport_ids)
Expand All @@ -578,9 +578,10 @@ binding_run(struct controller_ctx *ctx,
* chassis and update the binding accordingly. This includes both
* directly connected logical ports and children of those ports. */
SBREC_PORT_BINDING_TABLE_FOR_EACH (binding_rec, port_binding_table) {
consider_local_datapath(ctx, sbrec_datapath_binding_by_key,
consider_local_datapath(ctx, sbrec_chassis_by_name,
sbrec_datapath_binding_by_key,
sbrec_port_binding_by_datapath,
sbrec_port_binding_by_name, chassis_index,
sbrec_port_binding_by_name,
active_tunnels, chassis_rec, binding_rec,
sset_is_empty(&egress_ifaces) ? NULL :
&qos_map, local_datapaths, &lport_to_iface,
Expand Down
3 changes: 1 addition & 2 deletions ovn/controller/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <stdbool.h>

struct controller_ctx;
struct chassis_index;
struct hmap;
struct ovsdb_idl;
struct ovsdb_idl_index;
Expand All @@ -33,6 +32,7 @@ struct sset;

void binding_register_ovs_idl(struct ovsdb_idl *);
void binding_run(struct controller_ctx *,
struct ovsdb_idl_index *sbrec_chassis_by_name,
struct ovsdb_idl_index *sbrec_datapath_binding_by_key,
struct ovsdb_idl_index *sbrec_port_binding_by_datapath,
struct ovsdb_idl_index *sbrec_port_binding_by_name,
Expand All @@ -41,7 +41,6 @@ void binding_run(struct controller_ctx *,
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);
Expand Down
6 changes: 3 additions & 3 deletions ovn/controller/gchassis.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ compare_chassis_prio_(const void *a_, const void *b_)
}

struct ovs_list*
gateway_chassis_get_ordered(const struct sbrec_port_binding *binding,
const struct chassis_index *chassis_index)
gateway_chassis_get_ordered(struct ovsdb_idl_index *sbrec_chassis_by_name,
const struct sbrec_port_binding *binding)
{
const char *redir_chassis_str;
const struct sbrec_chassis *redirect_chassis = NULL;
Expand All @@ -52,7 +52,7 @@ gateway_chassis_get_ordered(const struct sbrec_port_binding *binding,
redir_chassis_str = smap_get(&binding->options, "redirect-chassis");

if (redir_chassis_str) {
redirect_chassis = chassis_lookup_by_name(chassis_index,
redirect_chassis = chassis_lookup_by_name(sbrec_chassis_by_name,
redir_chassis_str);
if (!redirect_chassis) {
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
Expand Down
6 changes: 3 additions & 3 deletions ovn/controller/gchassis.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include "openvswitch/hmap.h"
#include "openvswitch/list.h"

struct chassis_index;
struct ovsdb_idl;
struct ovsdb_idl_index;
struct sbrec_chassis;
struct sbrec_gateway_chassis;
struct sbrec_port_binding;
Expand All @@ -44,8 +44,8 @@ struct gateway_chassis {

/* Gets, and orders by priority/name the list of Gateway_Chassis */
struct ovs_list *gateway_chassis_get_ordered(
const struct sbrec_port_binding *binding,
const struct chassis_index *chassis_index);
struct ovsdb_idl_index *sbrec_chassis_by_name,
const struct sbrec_port_binding *binding);

/* Checks if an specific chassis is contained in the gateway_chassis
* list */
Expand Down
28 changes: 15 additions & 13 deletions ovn/controller/lflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ struct lookup_port_aux {
};

struct condition_aux {
struct ovsdb_idl_index *sbrec_chassis_by_name;
struct ovsdb_idl_index *sbrec_port_binding_by_name;
const struct sbrec_chassis *chassis;
const struct sset *active_tunnels;
const struct chassis_index *chassis_index;
};

static void consider_logical_flow(
struct ovsdb_idl_index *sbrec_chassis_by_name,
struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath,
struct ovsdb_idl_index *sbrec_port_binding_by_name,
const struct chassis_index *,
const struct sbrec_logical_flow *,
const struct hmap *local_datapaths,
const struct sbrec_chassis *,
Expand Down Expand Up @@ -118,8 +118,8 @@ is_chassis_resident_cb(const void *c_aux_, const char *port_name)
return pb->chassis && pb->chassis == c_aux->chassis;
} else {
struct ovs_list *gateway_chassis;
gateway_chassis = gateway_chassis_get_ordered(pb,
c_aux->chassis_index);
gateway_chassis = gateway_chassis_get_ordered(
c_aux->sbrec_chassis_by_name, pb);
if (gateway_chassis) {
bool active = gateway_chassis_is_active(gateway_chassis,
c_aux->chassis,
Expand All @@ -141,12 +141,12 @@ 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 ovsdb_idl_index *sbrec_chassis_by_name,
struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath,
struct ovsdb_idl_index *sbrec_port_binding_by_name,
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,
Expand Down Expand Up @@ -180,9 +180,10 @@ add_logical_flows(
nd_ra_opts_init(&nd_ra_opts);

SBREC_LOGICAL_FLOW_TABLE_FOR_EACH (lflow, logical_flow_table) {
consider_logical_flow(sbrec_multicast_group_by_name_datapath,
consider_logical_flow(sbrec_chassis_by_name,
sbrec_multicast_group_by_name_datapath,
sbrec_port_binding_by_name,
chassis_index, lflow, local_datapaths,
lflow, local_datapaths,
chassis, &dhcp_opts, &dhcpv6_opts, &nd_ra_opts,
addr_sets, port_groups, active_tunnels,
local_lport_ids, &conj_id_ofs,
Expand All @@ -196,9 +197,9 @@ add_logical_flows(

static void
consider_logical_flow(
struct ovsdb_idl_index *sbrec_chassis_by_name,
struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath,
struct ovsdb_idl_index *sbrec_port_binding_by_name,
const struct chassis_index *chassis_index,
const struct sbrec_logical_flow *lflow,
const struct hmap *local_datapaths,
const struct sbrec_chassis *chassis,
Expand Down Expand Up @@ -294,10 +295,10 @@ consider_logical_flow(
.dp = lflow->logical_datapath
};
struct condition_aux cond_aux = {
.sbrec_chassis_by_name = sbrec_chassis_by_name,
.sbrec_port_binding_by_name = sbrec_port_binding_by_name,
.chassis = chassis,
.active_tunnels = active_tunnels,
.chassis_index = chassis_index
};
expr = expr_simplify(expr, is_chassis_resident_cb, &cond_aux);
expr = expr_normalize(expr);
Expand Down Expand Up @@ -459,14 +460,14 @@ add_neighbor_flows(struct ovsdb_idl_index *sbrec_port_binding_by_name,
/* Translates logical flows in the Logical_Flow table in the OVN_SB database
* into OpenFlow flows. See ovn-architecture(7) for more information. */
void
lflow_run(struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath,
lflow_run(struct ovsdb_idl_index *sbrec_chassis_by_name,
struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath,
struct ovsdb_idl_index *sbrec_port_binding_by_name,
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,
const struct shash *addr_sets,
const struct shash *port_groups,
Expand All @@ -478,9 +479,10 @@ lflow_run(struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath,
{
COVERAGE_INC(lflow_run);

add_logical_flows(sbrec_multicast_group_by_name_datapath,
add_logical_flows(sbrec_chassis_by_name,
sbrec_multicast_group_by_name_datapath,
sbrec_port_binding_by_name, dhcp_options_table,
dhcpv6_options_table, logical_flow_table, chassis_index,
dhcpv6_options_table, logical_flow_table,
local_datapaths, chassis, addr_sets, port_groups,
active_tunnels, local_lport_ids, flow_table, group_table,
meter_table);
Expand Down
5 changes: 2 additions & 3 deletions ovn/controller/lflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

#include <stdint.h>

struct chassis_index;
struct ovn_extend_table;
struct ovsdb_idl_index;
struct hmap;
Expand Down Expand Up @@ -66,14 +65,14 @@ struct uuid;
#define LOG_PIPELINE_LEN 24

void lflow_init(void);
void lflow_run(struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath,
void lflow_run(struct ovsdb_idl_index *sbrec_chassis_by_name,
struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath,
struct ovsdb_idl_index *sbrec_port_binding_by_name,
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,
const struct shash *addr_sets,
const struct shash *port_groups,
Expand Down
Loading

0 comments on commit 789ddaf

Please sign in to comment.