datapath: s/ODPAT_/ODP_ACTION_ATTR_/ to fit new naming scheme.
[sliver-openvswitch.git] / vswitchd / bridge.c
index 20cbee5..fab6194 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008, 2009, 2010 Nicira Networks
+/* Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -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. */
 
@@ -370,34 +373,22 @@ bridge_configure_once(const struct ovsrec_open_vswitch *cfg)
     svec_init(&dpif_types);
     dp_enumerate_types(&dpif_types);
     for (i = 0; i < dpif_types.n; i++) {
-        struct dpif *dpif;
-        int retval;
         size_t j;
 
         dp_enumerate_names(dpif_types.names[i], &dpif_names);
 
-        /* For each dpif... */
+        /* Delete each dpif whose name is not in 'bridge_names'. */
         for (j = 0; j < dpif_names.n; j++) {
-            retval = dpif_open(dpif_names.names[j], dpif_types.names[i], &dpif);
-            if (!retval) {
-                struct svec all_names;
-                size_t k;
-
-                /* ...check whether any of its names is in 'bridge_names'. */
-                svec_init(&all_names);
-                dpif_get_all_names(dpif, &all_names);
-                for (k = 0; k < all_names.n; k++) {
-                    if (svec_contains(&bridge_names, all_names.names[k])) {
-                        goto found;
-                    }
+            if (!svec_contains(&bridge_names, dpif_names.names[j])) {
+                struct dpif *dpif;
+                int retval;
+
+                retval = dpif_open(dpif_names.names[j], dpif_types.names[i],
+                                   &dpif);
+                if (!retval) {
+                    dpif_delete(dpif);
+                    dpif_close(dpif);
                 }
-
-                /* No.  Delete the dpif. */
-                dpif_delete(dpif);
-
-            found:
-                svec_destroy(&all_names);
-                dpif_close(dpif);
             }
         }
     }
@@ -603,38 +594,35 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg)
      * that port already belongs to a different datapath, so we must do all
      * port deletions before any port additions. */
     LIST_FOR_EACH (br, node, &all_bridges) {
-        struct odp_port *dpif_ports;
-        size_t n_dpif_ports;
+        struct dpif_port_dump dump;
         struct shash want_ifaces;
+        struct dpif_port dpif_port;
 
-        dpif_port_list(br->dpif, &dpif_ports, &n_dpif_ports);
         bridge_get_all_ifaces(br, &want_ifaces);
-        for (i = 0; i < n_dpif_ports; i++) {
-            const struct odp_port *p = &dpif_ports[i];
-            if (!shash_find(&want_ifaces, p->devname)
-                && strcmp(p->devname, br->name)) {
-                int retval = dpif_port_del(br->dpif, p->port);
+        DPIF_PORT_FOR_EACH (&dpif_port, &dump, br->dpif) {
+            if (!shash_find(&want_ifaces, dpif_port.name)
+                && strcmp(dpif_port.name, br->name)) {
+                int retval = dpif_port_del(br->dpif, dpif_port.port_no);
                 if (retval) {
                     VLOG_ERR("failed to remove %s interface from %s: %s",
-                             p->devname, dpif_name(br->dpif),
+                             dpif_port.name, dpif_name(br->dpif),
                              strerror(retval));
                 }
             }
         }
         shash_destroy(&want_ifaces);
-        free(dpif_ports);
     }
     LIST_FOR_EACH (br, node, &all_bridges) {
-        struct odp_port *dpif_ports;
-        size_t n_dpif_ports;
         struct shash cur_ifaces, want_ifaces;
+        struct dpif_port_dump dump;
+        struct dpif_port dpif_port;
 
         /* Get the set of interfaces currently in this datapath. */
-        dpif_port_list(br->dpif, &dpif_ports, &n_dpif_ports);
         shash_init(&cur_ifaces);
-        for (i = 0; i < n_dpif_ports; i++) {
-            const char *name = dpif_ports[i].devname;
-            shash_add_once(&cur_ifaces, name, &dpif_ports[i]);
+        DPIF_PORT_FOR_EACH (&dpif_port, &dump, br->dpif) {
+            struct dpif_port *port_info = xmalloc(sizeof *port_info);
+            dpif_port_clone(port_info, &dpif_port);
+            shash_add(&cur_ifaces, dpif_port.name, port_info);
         }
 
         /* Get the set of interfaces we want on this datapath. */
@@ -644,10 +632,13 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg)
         SHASH_FOR_EACH (node, &want_ifaces) {
             const char *if_name = node->name;
             struct iface *iface = node->data;
-            struct odp_port *dpif_port = shash_find_data(&cur_ifaces, if_name);
-            const char *type = iface ? iface->type : "internal";
+            struct dpif_port *dpif_port;
+            const char *type;
             int error;
 
+            type = iface ? iface->type : "internal";
+            dpif_port = shash_find_data(&cur_ifaces, if_name);
+
             /* If we have a port or a netdev already, and it's not the type we
              * want, then delete the port (if any) and close the netdev (if
              * any). */
@@ -655,7 +646,7 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg)
                 || (iface && iface->netdev
                     && strcmp(type, netdev_get_type(iface->netdev)))) {
                 if (dpif_port) {
-                    error = ofproto_port_del(br->ofproto, dpif_port->port);
+                    error = ofproto_port_del(br->ofproto, dpif_port->port_no);
                     if (error) {
                         continue;
                     }
@@ -725,13 +716,18 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg)
                 shash_from_ovs_idl_map(iface->cfg->key_options,
                                        iface->cfg->value_options,
                                        iface->cfg->n_options, &args);
-                netdev_reconfigure(iface->netdev, &args);
+                netdev_set_config(iface->netdev, &args);
                 shash_destroy(&args);
             }
         }
-        free(dpif_ports);
-        shash_destroy(&cur_ifaces);
         shash_destroy(&want_ifaces);
+
+        SHASH_FOR_EACH (node, &cur_ifaces) {
+            struct dpif_port *port_info = node->data;
+            dpif_port_destroy(port_info);
+            free(port_info);
+        }
+        shash_destroy(&cur_ifaces);
     }
     sflow_bridge_number = 0;
     LIST_FOR_EACH (br, node, &all_bridges) {
@@ -1117,6 +1113,13 @@ iface_refresh_status(struct iface *iface)
 {
     struct shash sh;
 
+    enum netdev_flags flags;
+    uint32_t current;
+    int64_t bps;
+    int mtu;
+    int64_t mtu_64;
+    int error;
+
     shash_init(&sh);
 
     if (!netdev_get_status(iface->netdev, &sh)) {
@@ -1133,6 +1136,42 @@ iface_refresh_status(struct iface *iface)
     }
 
     shash_destroy_free_data(&sh);
+
+    error = netdev_get_flags(iface->netdev, &flags);
+    if (!error) {
+        ovsrec_interface_set_admin_state(iface->cfg, flags & NETDEV_UP ? "up" : "down");
+    }
+    else {
+        ovsrec_interface_set_admin_state(iface->cfg, NULL);
+    }
+
+    error = netdev_get_features(iface->netdev, &current, NULL, NULL, NULL);
+    if (!error) {
+        ovsrec_interface_set_duplex(iface->cfg,
+                                    netdev_features_is_full_duplex(current)
+                                    ? "full" : "half");
+        /* warning: uint64_t -> int64_t conversion */
+        bps = netdev_features_to_bps(current);
+        ovsrec_interface_set_link_speed(iface->cfg, &bps, 1);
+    }
+    else {
+        ovsrec_interface_set_duplex(iface->cfg, NULL);
+        ovsrec_interface_set_link_speed(iface->cfg, NULL, 0);
+    }
+
+
+    ovsrec_interface_set_link_state(iface->cfg,
+                                    netdev_get_carrier(iface->netdev)
+                                    ? "up" : "down");
+
+    error = netdev_get_mtu(iface->netdev, &mtu);
+    if (!error) {
+        mtu_64 = mtu;
+        ovsrec_interface_set_mtu(iface->cfg, &mtu_64, 1);
+    }
+    else {
+        ovsrec_interface_set_mtu(iface->cfg, NULL, 0);
+    }
 }
 
 static void
@@ -1272,6 +1311,49 @@ refresh_system_stats(const struct ovsrec_open_vswitch *cfg)
                         &datum);
 }
 
+static inline const char *
+nx_role_to_str(enum nx_role role)
+{
+    switch (role) {
+    case NX_ROLE_OTHER:
+        return "other";
+    case NX_ROLE_MASTER:
+        return "master";
+    case NX_ROLE_SLAVE:
+        return "slave";
+    default:
+        return "*** INVALID ROLE ***";
+    }
+}
+
+static void
+bridge_refresh_controller_status(const struct bridge *br)
+{
+    struct shash info;
+    const struct ovsrec_controller *cfg;
+
+    ofproto_get_ofproto_controller_info(br->ofproto, &info);
+
+    OVSREC_CONTROLLER_FOR_EACH(cfg, idl) {
+        struct ofproto_controller_info *cinfo =
+            shash_find_data(&info, cfg->target);
+
+        if (cinfo) {
+            ovsrec_controller_set_is_connected(cfg, cinfo->is_connected);
+            ovsrec_controller_set_role(cfg, nx_role_to_str(cinfo->role));
+            ovsrec_controller_set_status(cfg, (char **) cinfo->pairs.keys,
+                                         (char **) cinfo->pairs.values,
+                                         cinfo->pairs.n);
+        } else {
+            ovsrec_controller_set_is_connected(cfg, false);
+            ovsrec_controller_set_role(cfg, NULL);
+            ovsrec_controller_set_status(cfg, NULL, NULL, 0);
+        }
+    }
+
+    ofproto_free_ofproto_controller_info(&info);
+}
+
 void
 bridge_run(void)
 {
@@ -1296,6 +1378,20 @@ bridge_run(void)
     /* (Re)configure if necessary. */
     database_changed = ovsdb_idl_run(idl);
     cfg = ovsrec_open_vswitch_first(idl);
+#ifdef HAVE_OPENSSL
+    /* Re-configure SSL.  We do this on every trip through the main loop,
+     * instead of just when the database changes, because the contents of the
+     * key and certificate files can change without the database changing.
+     *
+     * We do this before bridge_reconfigure() because that function might
+     * initiate SSL connections and thus requires SSL to be configured. */
+    if (cfg && cfg->ssl) {
+        const struct ovsrec_ssl *ssl = cfg->ssl;
+
+        stream_ssl_set_key_and_cert(ssl->private_key, ssl->certificate);
+        stream_ssl_set_ca_cert_file(ssl->ca_cert, ssl->bootstrap_ca_cert);
+    }
+#endif
     if (database_changed || datapath_destroyed) {
         if (cfg) {
             struct ovsdb_idl_txn *txn = ovsdb_idl_txn_create(idl);
@@ -1315,18 +1411,6 @@ bridge_run(void)
         }
     }
 
-#ifdef HAVE_OPENSSL
-    /* Re-configure SSL.  We do this on every trip through the main loop,
-     * instead of just when the database changes, because the contents of the
-     * key and certificate files can change without the database changing. */
-    if (cfg && cfg->ssl) {
-        const struct ovsrec_ssl *ssl = cfg->ssl;
-
-        stream_ssl_set_key_and_cert(ssl->private_key, ssl->certificate);
-        stream_ssl_set_ca_cert_file(ssl->ca_cert, ssl->bootstrap_ca_cert);
-    }
-#endif
-
     /* Refresh system and interface stats if necessary. */
     if (time_msec() >= stats_timer) {
         if (cfg) {
@@ -1347,6 +1431,7 @@ bridge_run(void)
                         iface_refresh_status(iface);
                     }
                 }
+                bridge_refresh_controller_status(br);
             }
             refresh_system_stats(cfg);
             ovsdb_idl_txn_commit(txn);
@@ -1938,8 +2023,8 @@ bridge_get_all_ifaces(const struct bridge *br, struct shash *ifaces)
 static void
 bridge_fetch_dp_ifaces(struct bridge *br)
 {
-    struct odp_port *dpif_ports;
-    size_t n_dpif_ports;
+    struct dpif_port_dump dump;
+    struct dpif_port dpif_port;
     size_t i, j;
 
     /* Reset all interface numbers. */
@@ -1952,19 +2037,17 @@ bridge_fetch_dp_ifaces(struct bridge *br)
     }
     hmap_clear(&br->ifaces);
 
-    dpif_port_list(br->dpif, &dpif_ports, &n_dpif_ports);
-    for (i = 0; i < n_dpif_ports; i++) {
-        struct odp_port *p = &dpif_ports[i];
-        struct iface *iface = iface_lookup(br, p->devname);
+    DPIF_PORT_FOR_EACH (&dpif_port, &dump, br->dpif) {
+        struct iface *iface = iface_lookup(br, dpif_port.name);
         if (iface) {
             if (iface->dp_ifidx >= 0) {
                 VLOG_WARN("%s reported interface %s twice",
-                          dpif_name(br->dpif), p->devname);
-            } else if (iface_from_dp_ifidx(br, p->port)) {
+                          dpif_name(br->dpif), dpif_port.name);
+            } else if (iface_from_dp_ifidx(br, dpif_port.port_no)) {
                 VLOG_WARN("%s reported interface %"PRIu16" twice",
-                          dpif_name(br->dpif), p->port);
+                          dpif_name(br->dpif), dpif_port.port_no);
             } else {
-                iface->dp_ifidx = p->port;
+                iface->dp_ifidx = dpif_port.port_no;
                 hmap_insert(&br->ifaces, &iface->dp_ifidx_node,
                             hash_int(iface->dp_ifidx, 0));
             }
@@ -1975,7 +2058,6 @@ bridge_fetch_dp_ifaces(struct bridge *br)
                               : -1));
         }
     }
-    free(dpif_ports);
 }
 \f
 /* Bridge packet processing functions. */
@@ -1990,7 +2072,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)];
 }
 
@@ -2033,13 +2115,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) {
@@ -2073,8 +2155,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",
@@ -2212,18 +2294,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;
 
-                    bond_link_status_update(iface, carrier);
-                    port_update_bond_compat(port);
+                    iface = port_lookup_iface(port, devname);
+                    if (iface) {
+                        bool up = netdev_get_carrier(iface->netdev);
+
+                        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++) {
@@ -2257,7 +2357,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) {
@@ -2523,16 +2631,16 @@ compose_actions(struct bridge *br, const struct flow *flow, uint16_t vlan,
         const struct dst *dst = &set.dsts[i];
         if (dst->vlan != cur_vlan) {
             if (dst->vlan == OFP_VLAN_NONE) {
-                nl_msg_put_flag(actions, ODPAT_STRIP_VLAN);
+                nl_msg_put_flag(actions, ODP_ACTION_ATTR_STRIP_VLAN);
             } else {
                 ovs_be16 tci;
                 tci = htons(dst->vlan & VLAN_VID_MASK);
                 tci |= flow->vlan_tci & htons(VLAN_PCP_MASK);
-                nl_msg_put_be16(actions, ODPAT_SET_DL_TCI, tci);
+                nl_msg_put_be16(actions, ODP_ACTION_ATTR_SET_DL_TCI, tci);
             }
             cur_vlan = dst->vlan;
         }
-        nl_msg_put_u32(actions, ODPAT_OUTPUT, dst->dp_ifidx);
+        nl_msg_put_u32(actions, ODP_ACTION_ATTR_OUTPUT, dst->dp_ifidx);
     }
     dst_set_free(&set);
 }
@@ -2826,10 +2934,10 @@ bridge_account_flow_ofhook_cb(const struct flow *flow, tag_type tags,
         return;
     }
     NL_ATTR_FOR_EACH_UNSAFE (a, left, actions, actions_len) {
-        if (nl_attr_type(a) == ODPAT_OUTPUT) {
+        if (nl_attr_type(a) == ODP_ACTION_ATTR_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);
@@ -2855,7 +2963,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);
@@ -2884,13 +2992,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();
@@ -3005,7 +3113,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 "
@@ -3049,7 +3157,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
@@ -3274,7 +3382,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) {
@@ -3322,12 +3430,20 @@ 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");
+
+    if (port->miimon) {
+        ds_put_format(&ds, "bond-miimon-interval: %lld\n",
+                      port->bond_miimon_interval);
+    }
+
     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());
     }
@@ -3348,7 +3464,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;
         }
 
@@ -3411,7 +3527,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;
     }
@@ -3655,8 +3771,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;
@@ -3682,16 +3799,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->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_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->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. */
@@ -3866,7 +4006,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];
@@ -3881,16 +4021,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);
+            }
         }
     }
 }
@@ -3902,7 +4044,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;
     }