X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=vswitchd%2Fbridge.c;h=7fa819cf6e821ff8962d45e6fa669dfa2298f1d9;hb=e05924baf0c757b579eef2b3743130ade4b1a93c;hp=8b07b3e0d2dbb0a4f2ec943a84eca63dfccc2ae2;hpb=be02e7c3712a927993d5ff00a98b824582e1f5e2;p=openvswitch diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 8b07b3e0..7fa819cf 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -118,9 +118,9 @@ struct bond_entry { tag_type iface_tag; /* Tag associated with iface_idx. */ }; -enum bond_type { - BT_SLB, /* Source Load Balance (Default). */ - BT_AB /* Active Backup. */ +enum bond_mode { + BM_SLB, /* Source Load Balance (Default). */ + BM_AB /* Active Backup. */ }; #define MAX_MIRRORS 32 @@ -160,13 +160,16 @@ struct port { size_t n_ifaces, allocated_ifaces; /* Bonding info. */ - enum bond_type bond_type; /* Type of the bond. BT_SLB is the default. */ + 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. */ int updelay, downdelay; /* Delay before iface goes up/down, in ms. */ bool bond_compat_is_stale; /* Need to call port_update_bond_compat()? */ bool bond_fake_iface; /* Fake a bond interface for legacy compat? */ + bool miimon; /* Use miimon instead of carrier? */ + long long int bond_miimon_interval; /* Miimon status refresh interval. */ + long long int bond_miimon_next_update; /* Time of next miimon update. */ long long int bond_next_fake_iface_update; /* Time of next update. */ struct netdev_monitor *monitor; /* Tracks carrier up/down status. */ @@ -288,6 +291,9 @@ static void iface_send_packet(struct iface *, struct ofpbuf *packet); 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; @@ -1110,11 +1116,26 @@ dpid_from_hash(const void *data, size_t n) } static void -iface_refresh_tunnel_egress(struct iface *iface) +iface_refresh_status(struct iface *iface) { - const char *name = netdev_get_tnl_iface(iface->netdev); + struct shash sh; + + shash_init(&sh); + + if (!netdev_get_status(iface->netdev, &sh)) { + size_t n; + char **keys, **values; - ovsrec_interface_set_tunnel_egress_iface(iface->cfg, name); + 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 @@ -1326,7 +1347,7 @@ bridge_run(void) struct iface *iface = port->ifaces[j]; iface_refresh_stats(iface); iface_refresh_cfm_stats(iface); - iface_refresh_tunnel_egress(iface); + iface_refresh_status(iface); } } } @@ -1972,7 +1993,7 @@ static struct bond_entry * lookup_bond_entry(const struct port *port, const uint8_t mac[ETH_ADDR_LEN], uint16_t vlan) { - assert(port->bond_type == BT_SLB); + assert(port->bond_mode == BM_SLB); return &port->bond_hash[bond_hash(mac, vlan)]; } @@ -2015,13 +2036,13 @@ choose_output_iface(const struct port *port, const uint8_t *dl_src, assert(port->n_ifaces); if (port->n_ifaces == 1) { iface = port->ifaces[0]; - } else if (port->bond_type == BT_AB) { + } 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_type == BT_SLB){ + } 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) { @@ -2055,8 +2076,8 @@ bond_link_status_update(struct iface *iface, bool carrier) /* Nothing to do. */ return; } - VLOG_INFO_RL(&rl, "interface %s: carrier %s", - iface->name, carrier ? "detected" : "dropped"); + VLOG_INFO_RL(&rl, "interface %s: link state %s", + iface->name, carrier ? "up" : "down"); if (carrier == iface->enabled) { iface->delay_expires = LLONG_MAX; VLOG_INFO_RL(&rl, "interface %s: will not be %s", @@ -2194,18 +2215,36 @@ bond_run(struct bridge *br) if (port->n_ifaces >= 2) { char *devname; - /* Track carrier going up and down on interfaces. */ - while (!netdev_monitor_poll(port->monitor, &devname)) { - struct iface *iface; + if (port->monitor) { + assert(!port->miimon); - iface = port_lookup_iface(port, devname); - if (iface) { - bool carrier = netdev_get_carrier(iface->netdev); + /* Track carrier going up and down on interfaces. */ + while (!netdev_monitor_poll(port->monitor, &devname)) { + struct iface *iface; + + iface = port_lookup_iface(port, devname); + if (iface) { + bool up = netdev_get_carrier(iface->netdev); - bond_link_status_update(iface, carrier); - port_update_bond_compat(port); + bond_link_status_update(iface, up); + port_update_bond_compat(port); + } + free(devname); + } + } else { + assert(port->miimon); + + if (time_msec() >= port->bond_miimon_next_update) { + for (j = 0; j < port->n_ifaces; j++) { + struct iface *iface = port->ifaces[j]; + bool up = netdev_get_miimon(iface->netdev); + + bond_link_status_update(iface, up); + port_update_bond_compat(port); + } + port->bond_miimon_next_update = time_msec() + + port->bond_miimon_interval; } - free(devname); } for (j = 0; j < port->n_ifaces; j++) { @@ -2239,7 +2278,15 @@ bond_wait(struct bridge *br) if (port->n_ifaces < 2) { continue; } - netdev_monitor_poll_wait(port->monitor); + + if (port->monitor) { + netdev_monitor_poll_wait(port->monitor); + } + + if (port->miimon) { + poll_timer_wait_until(port->bond_miimon_next_update); + } + for (j = 0; j < port->n_ifaces; j++) { struct iface *iface = port->ifaces[j]; if (iface->delay_expires != LLONG_MAX) { @@ -2811,7 +2858,7 @@ bridge_account_flow_ofhook_cb(const struct flow *flow, tag_type tags, 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 && - out_port->bond_type == BT_SLB) { + out_port->bond_mode == BM_SLB) { uint16_t vlan = (flow->vlan_tci ? vlan_tci_to_vid(flow->vlan_tci) : OFP_VLAN_NONE); @@ -2837,7 +2884,7 @@ bridge_account_checkpoint_ofhook_cb(void *br_) now = time_msec(); for (i = 0; i < br->n_ports; i++) { struct port *port = br->ports[i]; - if (port->n_ifaces > 1 && port->bond_type == BT_SLB + 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); @@ -2866,13 +2913,13 @@ struct slave_balance { }; static const char * -bond_type_to_string(enum bond_type bt) { - static char *bt_slb = "slb"; - static char *bt_ab = "active-backup"; +bond_mode_to_string(enum bond_mode bm) { + static char *bm_slb = "balance-slb"; + static char *bm_ab = "active-backup"; - switch (bt) { - case BT_SLB: return bt_slb; - case BT_AB: return bt_ab; + switch (bm) { + case BM_SLB: return bm_slb; + case BM_AB: return bm_ab; } NOT_REACHED(); @@ -2987,7 +3034,7 @@ bond_shift_load(struct slave_balance *from, struct slave_balance *to, struct port *port = from->iface->port; uint64_t delta = hash->tx_bytes; - assert(port->bond_type == BT_SLB); + 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 " @@ -3031,7 +3078,7 @@ bond_rebalance_port(struct port *port) struct bond_entry *e; size_t i; - assert(port->bond_type == BT_SLB); + 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 @@ -3256,7 +3303,7 @@ bond_unixctl_list(struct unixctl_conn *conn, size_t j; ds_put_format(&ds, "%s\t%s\t%s\t", br->name, port->name, - bond_type_to_string(port->bond_type)); + bond_mode_to_string(port->bond_mode)); for (j = 0; j < port->n_ifaces; j++) { const struct iface *iface = port->ifaces[j]; if (j) { @@ -3304,12 +3351,14 @@ bond_unixctl_show(struct unixctl_conn *conn, return; } - ds_put_format(&ds, "bond_type: %s\n", - bond_type_to_string(port->bond_type)); + ds_put_format(&ds, "bond_mode: %s\n", + bond_mode_to_string(port->bond_mode)); + ds_put_format(&ds, "bond-detect-mode: %s\n", + port->miimon ? "miimon" : "carrier"); ds_put_format(&ds, "updelay: %d ms\n", port->updelay); ds_put_format(&ds, "downdelay: %d ms\n", port->downdelay); - if (port->bond_type == BT_SLB) { + if (port->bond_mode == BM_SLB) { ds_put_format(&ds, "next rebalance: %lld ms\n", port->bond_next_rebalance - time_msec()); } @@ -3330,7 +3379,7 @@ bond_unixctl_show(struct unixctl_conn *conn, iface->delay_expires - time_msec()); } - if (port->bond_type != BT_SLB) { + if (port->bond_mode != BM_SLB) { continue; } @@ -3393,7 +3442,7 @@ bond_unixctl_migrate(struct unixctl_conn *conn, const char *args_, return; } - if (port->bond_type != BT_SLB) { + if (port->bond_mode != BM_SLB) { unixctl_command_reply(conn, 501, "not an SLB bond"); return; } @@ -3637,8 +3686,9 @@ port_del_ifaces(struct port *port, const struct ovsrec_port *cfg) static void port_reconfigure(struct port *port, const struct ovsrec_port *cfg) { + const char *detect_mode; struct shash new_ifaces; - long long int next_rebalance; + long long int next_rebalance, miimon_next_update; unsigned long *trunks; int vlan; size_t i; @@ -3664,16 +3714,39 @@ port_reconfigure(struct port *port, const struct ovsrec_port *cfg) port->bond_next_rebalance = next_rebalance; } - if (!port->cfg->bond_type || - !strcmp(port->cfg->bond_type, bond_type_to_string(BT_SLB))) { - port->bond_type = BT_SLB; - } else if (!strcmp(port->cfg->bond_type, bond_type_to_string(BT_AB))) { - port->bond_type = BT_AB; + detect_mode = get_port_other_config(cfg, "bond-detect-mode", + "carrier"); + + if (!strcmp(detect_mode, "carrier")) { + port->miimon = false; + } else if (!strcmp(detect_mode, "miimon")) { + port->miimon = true; } else { - port->bond_type = BT_SLB; - VLOG_WARN("port %s: unknown bond_type %s, defaulting to %s", - port->name, port->cfg->bond_type, - bond_type_to_string(port->bond_type)); + port->miimon = false; + VLOG_WARN("port %s: unsupported bond-detect-mode %s, defaulting to " + "carrier", port->name, detect_mode); + } + + port->bond_miimon_interval = atoi( + get_port_other_config(cfg, "bond-miimon-interval", "200")); + if (port->bond_miimon_interval < 100) { + port->bond_miimon_interval = 100; + } + miimon_next_update = time_msec() + port->bond_miimon_interval; + if (port->bond_miimon_next_update > miimon_next_update) { + port->bond_miimon_next_update = miimon_next_update; + } + + 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. */ @@ -3848,7 +3921,7 @@ port_update_bonding(struct port *port) } else { size_t i; - if (port->bond_type == BT_SLB && !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]; @@ -3863,16 +3936,18 @@ port_update_bonding(struct port *port) if (port->cfg->bond_fake_iface) { port->bond_next_fake_iface_update = time_msec(); } - } else if (port->bond_type != BT_SLB) { + } 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; - port->monitor = netdev_monitor_create(); - for (i = 0; i < port->n_ifaces; i++) { - netdev_monitor_add(port->monitor, port->ifaces[i]->netdev); + if (!port->miimon) { + port->monitor = netdev_monitor_create(); + for (i = 0; i < port->n_ifaces; i++) { + netdev_monitor_add(port->monitor, port->ifaces[i]->netdev); + } } } } @@ -3884,7 +3959,7 @@ port_update_bond_compat(struct port *port) struct compat_bond bond; size_t i; - if (port->n_ifaces < 2 || port->bond_type != BT_SLB) { + if (port->n_ifaces < 2 || port->bond_mode != BM_SLB) { proc_net_compat_update_bond(port->name, NULL); return; } @@ -4152,6 +4227,38 @@ shash_from_ovs_idl_map(char **keys, char **values, size_t n, } } +/* 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;