- struct bridge *br = br_;
- struct iface *iface;
- struct port *port;
-
- iface = iface_from_dp_ifidx(br, ofp_port_to_odp_port(opp->port_no));
- if (!iface) {
- return;
- }
- port = iface->port;
-
- if (reason == OFPPR_DELETE) {
- VLOG_WARN("bridge %s: interface %s deleted unexpectedly",
- br->name, iface->name);
- iface_destroy(iface);
- if (!port->n_ifaces) {
- VLOG_WARN("bridge %s: port %s has no interfaces, dropping",
- br->name, port->name);
- port_destroy(port);
- }
-
- bridge_flush(br);
- } else {
- if (port->n_ifaces > 1) {
- bool up = !(opp->state & OFPPS_LINK_DOWN);
- bond_link_status_update(iface, up);
- port_update_bond_compat(port);
- }
- }
-}
-
-static bool
-bridge_normal_ofhook_cb(const flow_t *flow, const struct ofpbuf *packet,
- struct odp_actions *actions, tag_type *tags,
- uint16_t *nf_output_iface, void *br_)
-{
- struct bridge *br = br_;
-
- COVERAGE_INC(bridge_process_flow);
- return process_flow(br, flow, packet, actions, tags, nf_output_iface);
-}
-
-static void
-bridge_account_flow_ofhook_cb(const flow_t *flow,
- const union odp_action *actions,
- size_t n_actions, unsigned long long int n_bytes,
- void *br_)
-{
- struct bridge *br = br_;
- struct port *in_port;
- const union odp_action *a;
-
- /* Feed information from the active flows back into the learning table
- * to ensure that table is always in sync with what is actually flowing
- * through the datapath. */
- in_port = port_from_dp_ifidx(br, flow->in_port);
- if (in_port) {
- int vlan = flow_get_vlan(br, flow, in_port, false);
- if (vlan >= 0) {
- update_learning_table(br, flow, vlan, in_port);
- }
- }
-
- if (!br->has_bonded_ports) {
- return;
- }
-
- for (a = actions; a < &actions[n_actions]; a++) {
- if (a->type == ODPAT_OUTPUT) {
- struct port *out_port = port_from_dp_ifidx(br, a->output.port);
- if (out_port && out_port->n_ifaces >= 2) {
- struct bond_entry *e = lookup_bond_entry(out_port,
- flow->dl_src);
- e->tx_bytes += n_bytes;
- }
- }
- }
-}
-
-static void
-bridge_account_checkpoint_ofhook_cb(void *br_)
-{
- struct bridge *br = br_;
- size_t i;
-
- if (!br->has_bonded_ports) {
- return;
- }
-
- /* The current ofproto implementation calls this callback at least once a
- * second, so this timer implementation is sufficient. */
- if (time_msec() < br->bond_next_rebalance) {
- return;
- }
- br->bond_next_rebalance = time_msec() + 10000;
-
- for (i = 0; i < br->n_ports; i++) {
- struct port *port = br->ports[i];
- if (port->n_ifaces > 1) {
- bond_rebalance_port(port);
- }
- }
-}
-
-static struct ofhooks bridge_ofhooks = {
- bridge_port_changed_ofhook_cb,
- bridge_normal_ofhook_cb,
- bridge_account_flow_ofhook_cb,
- bridge_account_checkpoint_ofhook_cb,
-};
-\f
-/* Bonding functions. */
-
-/* Statistics for a single interface on a bonded port, used for load-based
- * bond rebalancing. */
-struct slave_balance {
- struct iface *iface; /* The interface. */
- uint64_t tx_bytes; /* Sum of hashes[*]->tx_bytes. */
-
- /* All the "bond_entry"s that are assigned to this interface, in order of
- * increasing tx_bytes. */
- struct bond_entry **hashes;
- size_t n_hashes;
-};
-
-/* 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. */
-static int
-compare_bond_entries(const void *a_, const void *b_)
-{
- const struct bond_entry *const *ap = a_;
- const struct bond_entry *const *bp = b_;
- const struct bond_entry *a = *ap;
- const struct bond_entry *b = *bp;
- if (a->iface_idx != b->iface_idx) {
- return a->iface_idx > b->iface_idx ? 1 : -1;
- } else if (a->tx_bytes != b->tx_bytes) {
- return a->tx_bytes > b->tx_bytes ? 1 : -1;
- } else {
- return 0;
- }
-}
-
-/* Sorts slave_balances so that enabled ports come first, and otherwise in
- * *descending* order by number of bytes transmitted. */
-static int
-compare_slave_balance(const void *a_, const void *b_)
-{
- const struct slave_balance *a = a_;
- const struct slave_balance *b = b_;
- if (a->iface->enabled != b->iface->enabled) {
- return a->iface->enabled ? -1 : 1;
- } else if (a->tx_bytes != b->tx_bytes) {
- return a->tx_bytes > b->tx_bytes ? -1 : 1;
- } else {
- return 0;
- }
-}
-
-static void
-swap_bals(struct slave_balance *a, struct slave_balance *b)
-{
- struct slave_balance tmp = *a;
- *a = *b;
- *b = tmp;
-}
-
-/* Restores the 'n_bals' slave_balance structures in 'bals' to sorted order
- * given that 'p' (and only 'p') might be in the wrong location.
- *
- * This function invalidates 'p', since it might now be in a different memory
- * location. */
-static void
-resort_bals(struct slave_balance *p,
- struct slave_balance bals[], size_t n_bals)
-{
- if (n_bals > 1) {
- for (; p > bals && p->tx_bytes > p[-1].tx_bytes; p--) {
- swap_bals(p, p - 1);
- }
- for (; p < &bals[n_bals - 1] && p->tx_bytes < p[1].tx_bytes; p++) {
- swap_bals(p, p + 1);
- }
- }
-}
-
-static void
-log_bals(const struct slave_balance *bals, size_t n_bals, struct port *port)
-{
- if (VLOG_IS_DBG_ENABLED()) {
- struct ds ds = DS_EMPTY_INITIALIZER;
- const struct slave_balance *b;
-
- for (b = bals; b < bals + n_bals; b++) {
- size_t i;
-
- if (b > bals) {
- ds_put_char(&ds, ',');
- }
- ds_put_format(&ds, " %s %"PRIu64"kB",
- b->iface->name, b->tx_bytes / 1024);
-
- if (!b->iface->enabled) {
- ds_put_cstr(&ds, " (disabled)");
- }
- if (b->n_hashes > 0) {
- ds_put_cstr(&ds, " (");
- for (i = 0; i < b->n_hashes; i++) {
- const struct bond_entry *e = b->hashes[i];
- if (i > 0) {
- ds_put_cstr(&ds, " + ");
- }
- ds_put_format(&ds, "h%td: %"PRIu64"kB",
- e - port->bond_hash, e->tx_bytes / 1024);
- }
- ds_put_cstr(&ds, ")");
- }
- }
- VLOG_DBG("bond %s:%s", port->name, ds_cstr(&ds));
- ds_destroy(&ds);
- }
-}
-
-/* Shifts 'hash' from 'from' to 'to' within 'port'. */
-static void
-bond_shift_load(struct slave_balance *from, struct slave_balance *to,
- int hash_idx)
-{
- struct bond_entry *hash = from->hashes[hash_idx];
- struct port *port = from->iface->port;
- uint64_t delta = hash->tx_bytes;
-
- 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)",
- port->name, delta / 1024, hash - port->bond_hash,
- from->iface->name, to->iface->name,
- (from->tx_bytes - delta) / 1024,
- (to->tx_bytes + delta) / 1024);
-
- /* Delete element from from->hashes.
- *
- * We don't bother to add the element to to->hashes because not only would
- * it require more work, the only purpose it would be to allow that hash to
- * be migrated to another slave in this rebalancing run, and there is no
- * point in doing that. */
- if (hash_idx == 0) {
- from->hashes++;
- } else {
- memmove(from->hashes + hash_idx, from->hashes + hash_idx + 1,
- (from->n_hashes - (hash_idx + 1)) * sizeof *from->hashes);
- }
- from->n_hashes--;
-
- /* Shift load away from 'from' to 'to'. */
- from->tx_bytes -= delta;
- to->tx_bytes += delta;
-
- /* Arrange for flows to be revalidated. */
- ofproto_revalidate(port->bridge->ofproto, hash->iface_tag);
- hash->iface_idx = to->iface->port_ifidx;
- hash->iface_tag = tag_create_random();
-}
-
-static void
-bond_rebalance_port(struct port *port)
-{
- struct slave_balance bals[DP_MAX_PORTS];
- size_t n_bals;
- struct bond_entry *hashes[BOND_MASK + 1];
- struct slave_balance *b, *from, *to;
- struct bond_entry *e;
- size_t i;
-
- /* 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
- * loaded slave.
- *
- * The code is a bit tricky: to avoid dynamically allocating a 'hashes'
- * array for each slave_balance structure, we sort our local array of
- * hashes in order by slave, so that all of the hashes for a given slave
- * become contiguous in memory, and then we point each 'hashes' members of
- * a slave_balance structure to the start of a contiguous group. */
- n_bals = port->n_ifaces;
- for (b = bals; b < &bals[n_bals]; b++) {
- b->iface = port->ifaces[b - bals];
- b->tx_bytes = 0;
- b->hashes = NULL;
- b->n_hashes = 0;
- }
- for (i = 0; i <= BOND_MASK; i++) {
- hashes[i] = &port->bond_hash[i];
- }
- qsort(hashes, BOND_MASK + 1, sizeof *hashes, compare_bond_entries);
- for (i = 0; i <= BOND_MASK; i++) {
- e = hashes[i];
- if (e->iface_idx >= 0 && e->iface_idx < port->n_ifaces) {
- b = &bals[e->iface_idx];
- b->tx_bytes += e->tx_bytes;
- if (!b->hashes) {
- b->hashes = &hashes[i];
- }
- b->n_hashes++;
- }
- }
- qsort(bals, n_bals, sizeof *bals, compare_slave_balance);
- log_bals(bals, n_bals, port);
-
- /* Discard slaves that aren't enabled (which were sorted to the back of the
- * array earlier). */
- while (!bals[n_bals - 1].iface->enabled) {
- n_bals--;
- if (!n_bals) {
- return;
- }
- }
-
- /* Shift load from the most-loaded slaves to the least-loaded slaves. */
- to = &bals[n_bals - 1];
- for (from = bals; from < to; ) {
- uint64_t overload = from->tx_bytes - to->tx_bytes;
- if (overload < to->tx_bytes >> 5 || overload < 100000) {
- /* The extra load on 'from' (and all less-loaded slaves), compared
- * to that of 'to' (the least-loaded slave), is less than ~3%, or
- * it is less than ~1Mbps. No point in rebalancing. */
- break;
- } else if (from->n_hashes == 1) {
- /* 'from' only carries a single MAC hash, so we can't shift any
- * load away from it, even though we want to. */
- from++;
- } else {
- /* 'from' is carrying significantly more load than 'to', and that
- * load is split across at least two different hashes. Pick a hash
- * to migrate to 'to' (the least-loaded slave), given that doing so
- * must decrease the ratio of the load on the two slaves by at
- * least 0.1.
- *
- * The sort order we use means that we prefer to shift away the
- * smallest hashes instead of the biggest ones. There is little
- * reason behind this decision; we could use the opposite sort
- * order to shift away big hashes ahead of small ones. */
- size_t i;
- bool order_swapped;
-
- for (i = 0; i < from->n_hashes; i++) {
- double old_ratio, new_ratio;
- uint64_t delta = from->hashes[i]->tx_bytes;
-
- if (delta == 0 || from->tx_bytes - delta == 0) {
- /* Pointless move. */
- continue;
- }
-
- order_swapped = from->tx_bytes - delta < to->tx_bytes + delta;
-
- if (to->tx_bytes == 0) {
- /* Nothing on the new slave, move it. */
- break;
- }
-
- old_ratio = (double)from->tx_bytes / to->tx_bytes;
- new_ratio = (double)(from->tx_bytes - delta) /
- (to->tx_bytes + delta);
-
- if (new_ratio == 0) {
- /* Should already be covered but check to prevent division
- * by zero. */
- continue;
- }
-
- if (new_ratio < 1) {
- new_ratio = 1 / new_ratio;
- }
-
- if (old_ratio - new_ratio > 0.1) {
- /* Would decrease the ratio, move it. */
- break;
- }
- }
- if (i < from->n_hashes) {
- bond_shift_load(from, to, i);
- port->bond_compat_is_stale = true;
-
- /* If the result of the migration changed the relative order of
- * 'from' and 'to' swap them back to maintain invariants. */
- if (order_swapped) {
- swap_bals(from, to);
- }
-
- /* Re-sort 'bals'. Note that this may make 'from' and 'to'
- * point to different slave_balance structures. It is only
- * valid to do these two operations in a row at all because we
- * know that 'from' will not move past 'to' and vice versa. */
- resort_bals(from, bals, n_bals);
- resort_bals(to, bals, n_bals);
- } else {
- from++;
- }
- }
- }
-
- /* Implement exponentially weighted moving average. A weight of 1/2 causes
- * historical data to decay to <1% in 7 rebalancing runs. */
- for (e = &port->bond_hash[0]; e <= &port->bond_hash[BOND_MASK]; e++) {
- e->tx_bytes /= 2;
- }
-}
-
-static void
-bond_send_learning_packets(struct port *port)
-{
- struct bridge *br = port->bridge;
- struct mac_entry *e;
- struct ofpbuf packet;
- int error, n_packets, n_errors;
-
- if (!port->n_ifaces || port->active_iface < 0) {
- return;
- }
-
- ofpbuf_init(&packet, 128);
- error = n_packets = n_errors = 0;
- LIST_FOR_EACH (e, struct mac_entry, lru_node, &br->ml->lrus) {
- union ofp_action actions[2], *a;
- uint16_t dp_ifidx;
- tag_type tags = 0;
- flow_t flow;
- int retval;
-
- if (e->port == port->port_idx
- || !choose_output_iface(port, e->mac, &dp_ifidx, &tags)) {
- continue;
- }
-
- /* Compose actions. */
- memset(actions, 0, sizeof actions);
- a = actions;
- if (e->vlan) {
- a->vlan_vid.type = htons(OFPAT_SET_VLAN_VID);
- a->vlan_vid.len = htons(sizeof *a);
- a->vlan_vid.vlan_vid = htons(e->vlan);
- a++;
- }
- a->output.type = htons(OFPAT_OUTPUT);
- a->output.len = htons(sizeof *a);
- a->output.port = htons(odp_port_to_ofp_port(dp_ifidx));
- a++;
-
- /* Send packet. */
- n_packets++;
- compose_benign_packet(&packet, "Open vSwitch Bond Failover", 0xf177,
- e->mac);
- flow_extract(&packet, ODPP_NONE, &flow);
- retval = ofproto_send_packet(br->ofproto, &flow, actions, a - actions,
- &packet);
- if (retval) {
- error = retval;
- n_errors++;
- }
- }
- ofpbuf_uninit(&packet);
-
- if (n_errors) {
- static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
- VLOG_WARN_RL(&rl, "bond %s: %d errors sending %d gratuitous learning "
- "packets, last error was: %s",
- port->name, n_errors, n_packets, strerror(error));
- } else {
- VLOG_DBG("bond %s: sent %d gratuitous learning packets",
- port->name, n_packets);
- }
-}
-\f
-/* Bonding unixctl user interface functions. */
-
-static void
-bond_unixctl_list(struct unixctl_conn *conn,
- const char *args UNUSED, void *aux UNUSED)
-{
- struct ds ds = DS_EMPTY_INITIALIZER;
- const struct bridge *br;
-
- ds_put_cstr(&ds, "bridge\tbond\tslaves\n");
-
- LIST_FOR_EACH (br, struct bridge, node, &all_bridges) {
- size_t i;
-
- for (i = 0; i < br->n_ports; i++) {
- const struct port *port = br->ports[i];
- if (port->n_ifaces > 1) {
- size_t j;
-
- ds_put_format(&ds, "%s\t%s\t", br->name, port->name);
- for (j = 0; j < port->n_ifaces; j++) {
- const struct iface *iface = port->ifaces[j];
- if (j) {
- ds_put_cstr(&ds, ", ");
- }
- ds_put_cstr(&ds, iface->name);
- }
- ds_put_char(&ds, '\n');
- }
- }
- }
- unixctl_command_reply(conn, 200, ds_cstr(&ds));
- ds_destroy(&ds);
-}
-
-static struct port *
-bond_find(const char *name)
-{
- const struct bridge *br;
-
- LIST_FOR_EACH (br, struct bridge, node, &all_bridges) {
- size_t i;
-
- for (i = 0; i < br->n_ports; i++) {
- struct port *port = br->ports[i];
- if (!strcmp(port->name, name) && port->n_ifaces > 1) {
- return port;
- }
- }
- }
- return NULL;
-}
-
-static void
-bond_unixctl_show(struct unixctl_conn *conn,
- const char *args, void *aux UNUSED)
-{
- struct ds ds = DS_EMPTY_INITIALIZER;
- const struct port *port;
- size_t j;
-
- port = bond_find(args);
- if (!port) {
- unixctl_command_reply(conn, 501, "no such bond");
- return;
- }
-
- 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->bridge->bond_next_rebalance - time_msec());
- for (j = 0; j < port->n_ifaces; j++) {
- const struct iface *iface = port->ifaces[j];
- struct bond_entry *be;
-
- /* Basic info. */
- ds_put_format(&ds, "slave %s: %s\n",
- iface->name, iface->enabled ? "enabled" : "disabled");
- if (j == port->active_iface) {
- ds_put_cstr(&ds, "\tactive slave\n");
- }
- if (iface->delay_expires != LLONG_MAX) {
- ds_put_format(&ds, "\t%s expires in %lld ms\n",
- iface->enabled ? "downdelay" : "updelay",
- iface->delay_expires - time_msec());
- }
-
- /* Hashes. */
- for (be = port->bond_hash; be <= &port->bond_hash[BOND_MASK]; be++) {
- int hash = be - port->bond_hash;
- struct mac_entry *me;
-
- if (be->iface_idx != j) {
- continue;
- }
-
- ds_put_format(&ds, "\thash %d: %"PRIu64" kB load\n",
- hash, be->tx_bytes / 1024);
-
- /* MACs. */
- LIST_FOR_EACH (me, struct mac_entry, lru_node,
- &port->bridge->ml->lrus) {
- uint16_t dp_ifidx;
- tag_type tags = 0;
- if (bond_hash(me->mac) == hash
- && me->port != port->port_idx
- && choose_output_iface(port, me->mac, &dp_ifidx, &tags)
- && dp_ifidx == iface->dp_ifidx)
- {
- ds_put_format(&ds, "\t\t"ETH_ADDR_FMT"\n",
- ETH_ADDR_ARGS(me->mac));
- }
- }
- }
- }
- unixctl_command_reply(conn, 200, ds_cstr(&ds));
- ds_destroy(&ds);
-}
-
-static void
-bond_unixctl_migrate(struct unixctl_conn *conn, const char *args_,
- void *aux UNUSED)
-{
- char *args = (char *) args_;
- char *save_ptr = NULL;
- char *bond_s, *hash_s, *slave_s;
- uint8_t mac[ETH_ADDR_LEN];
- struct port *port;
- struct iface *iface;
- struct bond_entry *entry;
- int hash;
-
- bond_s = strtok_r(args, " ", &save_ptr);
- hash_s = strtok_r(NULL, " ", &save_ptr);
- slave_s = strtok_r(NULL, " ", &save_ptr);
- if (!slave_s) {
- unixctl_command_reply(conn, 501,
- "usage: bond/migrate BOND HASH SLAVE");
- return;
- }
-
- port = bond_find(bond_s);
- if (!port) {
- unixctl_command_reply(conn, 501, "no such bond");
- return;
- }
-
- if (sscanf(hash_s, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(mac))
- == ETH_ADDR_SCAN_COUNT) {
- hash = bond_hash(mac);
- } else if (strspn(hash_s, "0123456789") == strlen(hash_s)) {
- hash = atoi(hash_s) & BOND_MASK;
- } else {
- unixctl_command_reply(conn, 501, "bad hash");
- return;
- }
-
- iface = port_lookup_iface(port, slave_s);
- if (!iface) {
- unixctl_command_reply(conn, 501, "no such slave");
- return;
- }
-
- if (!iface->enabled) {
- unixctl_command_reply(conn, 501, "cannot migrate to disabled slave");
- return;
- }
-
- entry = &port->bond_hash[hash];
- ofproto_revalidate(port->bridge->ofproto, entry->iface_tag);
- entry->iface_idx = iface->port_ifidx;
- entry->iface_tag = tag_create_random();
- port->bond_compat_is_stale = true;
- unixctl_command_reply(conn, 200, "migrated");
-}
-
-static void
-bond_unixctl_set_active_slave(struct unixctl_conn *conn, const char *args_,
- void *aux UNUSED)
-{
- char *args = (char *) args_;
- char *save_ptr = NULL;
- char *bond_s, *slave_s;
- struct port *port;
- struct iface *iface;
-
- bond_s = strtok_r(args, " ", &save_ptr);
- slave_s = strtok_r(NULL, " ", &save_ptr);
- if (!slave_s) {
- unixctl_command_reply(conn, 501,
- "usage: bond/set-active-slave BOND SLAVE");
- return;
- }
-
- port = bond_find(bond_s);
- if (!port) {
- unixctl_command_reply(conn, 501, "no such bond");
- return;
- }
-
- iface = port_lookup_iface(port, slave_s);
- if (!iface) {
- unixctl_command_reply(conn, 501, "no such slave");
- return;
- }
-
- if (!iface->enabled) {
- unixctl_command_reply(conn, 501, "cannot make disabled slave active");
- return;
- }
-
- if (port->active_iface != iface->port_ifidx) {
- ofproto_revalidate(port->bridge->ofproto, port->active_iface_tag);
- port->active_iface = iface->port_ifidx;
- port->active_iface_tag = tag_create_random();
- VLOG_INFO("port %s: active interface is now %s",
- port->name, iface->name);
- bond_send_learning_packets(port);
- unixctl_command_reply(conn, 200, "done");
- } else {
- unixctl_command_reply(conn, 200, "no change");
- }
-}
-
-static void
-enable_slave(struct unixctl_conn *conn, const char *args_, bool enable)
-{
- char *args = (char *) args_;
- char *save_ptr = NULL;
- char *bond_s, *slave_s;
- struct port *port;
- struct iface *iface;
-
- bond_s = strtok_r(args, " ", &save_ptr);
- slave_s = strtok_r(NULL, " ", &save_ptr);
- if (!slave_s) {
- unixctl_command_reply(conn, 501,
- "usage: bond/enable/disable-slave BOND SLAVE");
- return;
- }
-
- port = bond_find(bond_s);
- if (!port) {
- unixctl_command_reply(conn, 501, "no such bond");
- return;
- }
-
- iface = port_lookup_iface(port, slave_s);
- if (!iface) {
- unixctl_command_reply(conn, 501, "no such slave");
- return;
- }
-
- bond_enable_slave(iface, enable);
- unixctl_command_reply(conn, 501, enable ? "enabled" : "disabled");
-}
-
-static void
-bond_unixctl_enable_slave(struct unixctl_conn *conn, const char *args,
- void *aux UNUSED)
-{
- enable_slave(conn, args, true);
-}
-
-static void
-bond_unixctl_disable_slave(struct unixctl_conn *conn, const char *args,
- void *aux UNUSED)
-{
- enable_slave(conn, args, false);
-}
-
-static void
-bond_unixctl_hash(struct unixctl_conn *conn, const char *args,
- void *aux UNUSED)
-{
- uint8_t mac[ETH_ADDR_LEN];
- uint8_t hash;
- char *hash_cstr;
-
- if (sscanf(args, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(mac))
- == ETH_ADDR_SCAN_COUNT) {
- hash = bond_hash(mac);
-
- hash_cstr = xasprintf("%u", hash);
- unixctl_command_reply(conn, 200, hash_cstr);
- free(hash_cstr);
- } else {
- unixctl_command_reply(conn, 501, "invalid mac");
- }
-}
-
-static void
-bond_init(void)
-{
- unixctl_command_register("bond/list", bond_unixctl_list, NULL);
- unixctl_command_register("bond/show", bond_unixctl_show, NULL);
- unixctl_command_register("bond/migrate", bond_unixctl_migrate, NULL);
- unixctl_command_register("bond/set-active-slave",
- bond_unixctl_set_active_slave, NULL);
- unixctl_command_register("bond/enable-slave", bond_unixctl_enable_slave,
- NULL);
- unixctl_command_register("bond/disable-slave", bond_unixctl_disable_slave,
- NULL);
- unixctl_command_register("bond/hash", bond_unixctl_hash, NULL);
-}
-\f
-/* Port functions. */
-
-static struct port *
-port_create(struct bridge *br, const char *name)
-{
- struct port *port;
-
- port = xzalloc(sizeof *port);
- port->bridge = br;
- port->port_idx = br->n_ports;
- port->vlan = -1;
- port->trunks = NULL;
- port->name = xstrdup(name);
- port->active_iface = -1;
-
- if (br->n_ports >= br->allocated_ports) {
- br->ports = x2nrealloc(br->ports, &br->allocated_ports,
- sizeof *br->ports);
- }
- br->ports[br->n_ports++] = port;
-
- VLOG_INFO("created port %s on bridge %s", port->name, br->name);
- bridge_flush(br);
-
- return port;
-}
-
-static void
-port_reconfigure(struct port *port, const struct ovsrec_port *cfg)
-{
- struct shash old_ifaces, new_ifaces;