tag_type iface_tag; /* Tag associated with iface_idx. */
};
+enum bond_mode {
+ BM_SLB, /* Source Load Balance (Default). */
+ BM_AB /* Active Backup. */
+};
+
#define MAX_MIRRORS 32
typedef uint32_t mirror_mask_t;
#define MIRROR_MASK_C(X) UINT32_C(X)
size_t n_ifaces, allocated_ifaces;
/* Bonding info. */
- struct bond_entry *bond_hash; /* An array of (BOND_MASK + 1) elements. */
+ enum bond_mode bond_mode; /* Type of the bond. BM_SLB is the default. */
int active_iface; /* Ifidx on which bcasts accepted, or -1. */
tag_type active_iface_tag; /* Tag for bcast flows. */
tag_type no_ifaces_tag; /* Tag for flows when all ifaces disabled. */
bool bond_compat_is_stale; /* Need to call port_update_bond_compat()? */
bool bond_fake_iface; /* Fake a bond interface for legacy compat? */
long long int bond_next_fake_iface_update; /* Time of next update. */
+ struct netdev_monitor *monitor; /* Tracks carrier up/down status. */
+
+ /* SLB specific bonding info. */
+ struct bond_entry *bond_hash; /* An array of (BOND_MASK + 1) elements. */
int bond_rebalance_interval; /* Interval between rebalances, in ms. */
long long int bond_next_rebalance; /* Next rebalancing time. */
- struct netdev_monitor *monitor; /* Tracks carrier up/down status. */
/* Port mirroring info. */
mirror_mask_t src_mirrors; /* Mirrors triggered when packet received. */
static void shash_from_ovs_idl_map(char **keys, char **values, size_t n,
struct shash *);
+static void shash_to_ovs_idl_map(struct shash *,
+ char ***keys, char ***values, size_t *n);
+
/* Hooks into ofproto processing. */
static struct ofhooks bridge_ofhooks;
bond_init();
}
+void
+bridge_exit(void)
+{
+ struct bridge *br, *next_br;
+
+ LIST_FOR_EACH_SAFE (br, next_br, node, &all_bridges) {
+ bridge_destroy(br);
+ }
+ ovsdb_idl_destroy(idl);
+}
+
/* Performs configuration that is only necessary once at ovs-vswitchd startup,
* but for which the ovs-vswitchd configuration 'cfg' is required. */
static void
svec_destroy(&dpif_types);
}
-/* Initializes 'options' and fills it with the options for 'if_cfg'. Merges
- * keys from "options" and "other_config", preferring "options" keys over
- * "other_config" keys. */
-static void
-iface_get_options(const struct ovsrec_interface *if_cfg, struct shash *options)
-{
- size_t i;
-
- shash_from_ovs_idl_map(if_cfg->key_options, if_cfg->value_options,
- if_cfg->n_options, options);
-
- for (i = 0; i < if_cfg->n_other_config; i++) {
- char *key = if_cfg->key_other_config[i];
- char *value = if_cfg->value_other_config[i];
-
- if (!shash_find_data(options, key)) {
- shash_add(options, key, value);
- } else {
- VLOG_WARN("%s: ignoring \"other_config\" key %s that conflicts "
- "with \"options\" key %s", if_cfg->name, key, key);
- }
- }
-}
-
/* Callback for iterate_and_prune_ifaces(). */
static bool
check_iface(struct bridge *br, struct iface *iface, void *aux OVS_UNUSED)
shash_init(&args);
if (iface) {
- iface_get_options(iface->cfg, &args);
+ shash_from_ovs_idl_map(iface->cfg->key_options,
+ iface->cfg->value_options,
+ iface->cfg->n_options, &args);
}
error = netdev_open(&options, &netdev);
shash_destroy(&args);
struct shash args;
shash_init(&args);
- iface_get_options(iface->cfg, &args);
+ shash_from_ovs_idl_map(iface->cfg->key_options,
+ iface->cfg->value_options,
+ iface->cfg->n_options, &args);
netdev_reconfigure(iface->netdev, &args);
shash_destroy(&args);
}
return eth_addr_to_uint64(hash);
}
+static void
+iface_refresh_status(struct iface *iface)
+{
+ struct shash sh;
+
+ shash_init(&sh);
+
+ if (!netdev_get_status(iface->netdev, &sh)) {
+ size_t n;
+ char **keys, **values;
+
+ shash_to_ovs_idl_map(&sh, &keys, &values, &n);
+ ovsrec_interface_set_status(iface->cfg, keys, values, n);
+
+ free(keys);
+ free(values);
+ } else {
+ ovsrec_interface_set_status(iface->cfg, NULL, NULL, 0);
+ }
+
+ shash_destroy_free_data(&sh);
+}
+
static void
iface_refresh_cfm_stats(struct iface *iface)
{
struct iface *iface = port->ifaces[j];
iface_refresh_stats(iface);
iface_refresh_cfm_stats(iface);
+ iface_refresh_status(iface);
}
}
}
lookup_bond_entry(const struct port *port, const uint8_t mac[ETH_ADDR_LEN],
uint16_t vlan)
{
+ assert(port->bond_mode == BM_SLB);
return &port->bond_hash[bond_hash(mac, vlan)];
}
assert(port->n_ifaces);
if (port->n_ifaces == 1) {
iface = port->ifaces[0];
- } else {
+ } else if (port->bond_mode == BM_AB) {
+ if (port->active_iface < 0) {
+ *tags |= port->no_ifaces_tag;
+ return false;
+ }
+ iface = port->ifaces[port->active_iface];
+ } else if (port->bond_mode == BM_SLB){
struct bond_entry *e = lookup_bond_entry(port, dl_src, vlan);
if (e->iface_idx < 0 || e->iface_idx >= port->n_ifaces
|| !port->ifaces[e->iface_idx]->enabled) {
}
*tags |= e->iface_tag;
iface = port->ifaces[e->iface_idx];
+ } else {
+ NOT_REACHED();
}
*dp_ifidx = iface->dp_ifidx;
*tags |= iface->tag; /* Currently only used for bonding. */
NL_ATTR_FOR_EACH_UNSAFE (a, left, actions, actions_len) {
if (nl_attr_type(a) == ODPAT_OUTPUT) {
struct port *out_port = port_from_dp_ifidx(br, nl_attr_get_u32(a));
- if (out_port && out_port->n_ifaces >= 2) {
+ if (out_port && out_port->n_ifaces >= 2 &&
+ out_port->bond_mode == BM_SLB) {
uint16_t vlan = (flow->vlan_tci
? vlan_tci_to_vid(flow->vlan_tci)
: OFP_VLAN_NONE);
now = time_msec();
for (i = 0; i < br->n_ports; i++) {
struct port *port = br->ports[i];
- if (port->n_ifaces > 1 && now >= port->bond_next_rebalance) {
+ if (port->n_ifaces > 1 && port->bond_mode == BM_SLB
+ && now >= port->bond_next_rebalance) {
port->bond_next_rebalance = now + port->bond_rebalance_interval;
bond_rebalance_port(port);
}
size_t n_hashes;
};
+static const char *
+bond_mode_to_string(enum bond_mode bm) {
+ static char *bm_slb = "balance-slb";
+ static char *bm_ab = "active-backup";
+
+ switch (bm) {
+ case BM_SLB: return bm_slb;
+ case BM_AB: return bm_ab;
+ }
+
+ NOT_REACHED();
+ return NULL;
+}
+
/* Sorts pointers to pointers to bond_entries in ascending order by the
* interface to which they are assigned, and within a single interface in
* ascending order of bytes transmitted. */
struct port *port = from->iface->port;
uint64_t delta = hash->tx_bytes;
+ assert(port->bond_mode == BM_SLB);
+
VLOG_INFO("bond %s: shift %"PRIu64"kB of load (with hash %td) "
"from %s to %s (now carrying %"PRIu64"kB and "
"%"PRIu64"kB load, respectively)",
struct bond_entry *e;
size_t i;
+ assert(port->bond_mode == BM_SLB);
+
/* Sets up 'bals' to describe each of the port's interfaces, sorted in
* descending order of tx_bytes, so that bals[0] represents the most
* heavily loaded slave and bals[n_bals - 1] represents the least heavily
struct ds ds = DS_EMPTY_INITIALIZER;
const struct bridge *br;
- ds_put_cstr(&ds, "bridge\tbond\tslaves\n");
+ ds_put_cstr(&ds, "bridge\tbond\ttype\tslaves\n");
LIST_FOR_EACH (br, node, &all_bridges) {
size_t i;
if (port->n_ifaces > 1) {
size_t j;
- ds_put_format(&ds, "%s\t%s\t", br->name, port->name);
+ ds_put_format(&ds, "%s\t%s\t%s\t", br->name, port->name,
+ bond_mode_to_string(port->bond_mode));
for (j = 0; j < port->n_ifaces; j++) {
const struct iface *iface = port->ifaces[j];
if (j) {
return;
}
+ ds_put_format(&ds, "bond_mode: %s\n",
+ bond_mode_to_string(port->bond_mode));
ds_put_format(&ds, "updelay: %d ms\n", port->updelay);
ds_put_format(&ds, "downdelay: %d ms\n", port->downdelay);
- ds_put_format(&ds, "next rebalance: %lld ms\n",
- port->bond_next_rebalance - time_msec());
+
+ if (port->bond_mode == BM_SLB) {
+ ds_put_format(&ds, "next rebalance: %lld ms\n",
+ port->bond_next_rebalance - time_msec());
+ }
+
for (j = 0; j < port->n_ifaces; j++) {
const struct iface *iface = port->ifaces[j];
struct bond_entry *be;
iface->delay_expires - time_msec());
}
+ if (port->bond_mode != BM_SLB) {
+ continue;
+ }
+
/* Hashes. */
for (be = port->bond_hash; be <= &port->bond_hash[BOND_MASK]; be++) {
int hash = be - port->bond_hash;
return;
}
+ if (port->bond_mode != BM_SLB) {
+ unixctl_command_reply(conn, 501, "not an SLB bond");
+ return;
+ }
+
if (strspn(hash_s, "0123456789") == strlen(hash_s)) {
hash = atoi(hash_s) & BOND_MASK;
} else {
port->bond_next_rebalance = next_rebalance;
}
+ if (!port->cfg->bond_mode ||
+ !strcmp(port->cfg->bond_mode, bond_mode_to_string(BM_SLB))) {
+ port->bond_mode = BM_SLB;
+ } else if (!strcmp(port->cfg->bond_mode, bond_mode_to_string(BM_AB))) {
+ port->bond_mode = BM_AB;
+ } else {
+ port->bond_mode = BM_SLB;
+ VLOG_WARN("port %s: unknown bond_mode %s, defaulting to %s",
+ port->name, port->cfg->bond_mode,
+ bond_mode_to_string(port->bond_mode));
+ }
+
/* Add new interfaces and update 'cfg' member of existing ones. */
shash_init(&new_ifaces);
for (i = 0; i < cfg->n_interfaces; i++) {
free(port->bond_hash);
port->bond_hash = NULL;
port->bond_compat_is_stale = true;
- port->bond_fake_iface = false;
}
+
+ port->bond_fake_iface = false;
} else {
size_t i;
- if (!port->bond_hash) {
+ if (port->bond_mode == BM_SLB && !port->bond_hash) {
port->bond_hash = xcalloc(BOND_MASK + 1, sizeof *port->bond_hash);
for (i = 0; i <= BOND_MASK; i++) {
struct bond_entry *e = &port->bond_hash[i];
if (port->cfg->bond_fake_iface) {
port->bond_next_fake_iface_update = time_msec();
}
+ } else if (port->bond_mode != BM_SLB) {
+ free(port->bond_hash);
+ port->bond_hash = NULL;
}
port->bond_compat_is_stale = true;
port->bond_fake_iface = port->cfg->bond_fake_iface;
struct compat_bond bond;
size_t i;
- if (port->n_ifaces < 2) {
+ if (port->n_ifaces < 2 || port->bond_mode != BM_SLB) {
proc_net_compat_update_bond(port->name, NULL);
return;
}
bool del_active = port->active_iface == iface->port_ifidx;
struct iface *del;
+ if (port->monitor) {
+ netdev_monitor_remove(port->monitor, iface->netdev);
+ }
+
shash_find_and_delete_assert(&br->iface_by_name, iface->name);
if (iface->dp_ifidx >= 0) {
}
}
+/* Creates 'keys' and 'values' arrays from 'shash'.
+ *
+ * Sets 'keys' and 'values' to heap allocated arrays representing the key-value
+ * pairs in 'shash'. The caller takes ownership of 'keys' and 'values'. They
+ * are populated with with strings taken directly from 'shash' and thus have
+ * the same ownership of the key-value pairs in shash.
+ */
+static void
+shash_to_ovs_idl_map(struct shash *shash,
+ char ***keys, char ***values, size_t *n)
+{
+ size_t i, count;
+ char **k, **v;
+ struct shash_node *sn;
+
+ count = shash_count(shash);
+
+ k = xmalloc(count * sizeof *k);
+ v = xmalloc(count * sizeof *v);
+
+ i = 0;
+ SHASH_FOR_EACH(sn, shash) {
+ k[i] = sn->name;
+ v[i] = sn->data;
+ i++;
+ }
+
+ *n = count;
+ *keys = k;
+ *values = v;
+}
+
struct iface_delete_queues_cbdata {
struct netdev *netdev;
const struct ovsdb_datum *queues;