vswitchd: New column "link_resets".
[sliver-openvswitch.git] / vswitchd / bridge.c
index 4e2833e..d4335c1 100644 (file)
@@ -201,7 +201,6 @@ static void iface_configure_cfm(struct iface *);
 static void iface_refresh_cfm_stats(struct iface *);
 static void iface_refresh_stats(struct iface *);
 static void iface_refresh_status(struct iface *);
-static bool iface_get_carrier(const struct iface *);
 static bool iface_is_synthetic(const struct iface *);
 
 static void shash_from_ovs_idl_map(char **keys, char **values, size_t n,
@@ -239,6 +238,7 @@ bridge_init(const char *remote)
     ovsdb_idl_omit_alert(idl, &ovsrec_interface_col_duplex);
     ovsdb_idl_omit_alert(idl, &ovsrec_interface_col_link_speed);
     ovsdb_idl_omit_alert(idl, &ovsrec_interface_col_link_state);
+    ovsdb_idl_omit_alert(idl, &ovsrec_interface_col_link_resets);
     ovsdb_idl_omit_alert(idl, &ovsrec_interface_col_mtu);
     ovsdb_idl_omit_alert(idl, &ovsrec_interface_col_ofport);
     ovsdb_idl_omit_alert(idl, &ovsrec_interface_col_statistics);
@@ -1275,9 +1275,6 @@ iface_refresh_status(struct iface *iface)
         ovsrec_interface_set_link_speed(iface->cfg, NULL, 0);
     }
 
-    ovsrec_interface_set_link_state(iface->cfg,
-                                    iface_get_carrier(iface) ? "up" : "down");
-
     error = netdev_get_mtu(iface->netdev, &mtu);
     if (!error) {
         mtu_64 = mtu;
@@ -1320,20 +1317,6 @@ iface_refresh_cfm_stats(struct iface *iface)
     }
 }
 
-static bool
-iface_refresh_lacp_stats(struct iface *iface)
-{
-    struct ofproto *ofproto = iface->port->bridge->ofproto;
-    int old = iface->cfg->lacp_current ? *iface->cfg->lacp_current : -1;
-    int new = ofproto_port_is_lacp_current(ofproto, iface->ofp_port);
-
-    if (old != new) {
-        bool current = new;
-        ovsrec_interface_set_lacp_current(iface->cfg, &current, new >= 0);
-    }
-    return old != new;
-}
-
 static void
 iface_refresh_stats(struct iface *iface)
 {
@@ -1585,29 +1568,40 @@ bridge_run(void)
 
     if (time_msec() >= db_limiter) {
         struct ovsdb_idl_txn *txn;
-        bool changed = false;
 
         txn = ovsdb_idl_txn_create(idl);
         HMAP_FOR_EACH (br, node, &all_bridges) {
-            struct port *port;
+            struct iface *iface;
+
+            HMAP_FOR_EACH (iface, name_node, &br->iface_by_name) {
+                const char *link_state;
+                int64_t link_resets;
+                int current;
 
-            HMAP_FOR_EACH (port, hmap_node, &br->ports) {
-                struct iface *iface;
+                if (iface_is_synthetic(iface)) {
+                    continue;
+                }
 
-                LIST_FOR_EACH (iface, port_elem, &port->ifaces) {
-                    /* XXX: Eventually we need to remove the lacp_current flag
-                     * from the database so that we can completely get rid of
-                     * this rate limiter code. */
-                    changed = iface_refresh_lacp_stats(iface) || changed;
+                current = ofproto_port_is_lacp_current(br->ofproto,
+                                                       iface->ofp_port);
+                if (current >= 0) {
+                    bool bl = current;
+                    ovsrec_interface_set_lacp_current(iface->cfg, &bl, 1);
+                } else {
+                    ovsrec_interface_set_lacp_current(iface->cfg, NULL, 0);
                 }
+
+                link_state = netdev_get_carrier(iface->netdev) ? "up" : "down";
+                ovsrec_interface_set_link_state(iface->cfg, link_state);
+
+                link_resets = netdev_get_carrier_resets(iface->netdev);
+                ovsrec_interface_set_link_resets(iface->cfg, &link_resets, 1);
             }
         }
 
-        if (changed) {
+        if (ovsdb_idl_txn_commit(txn) != TXN_UNCHANGED) {
             db_limiter = time_msec() + DB_LIMIT_INTERVAL;
         }
-
-        ovsdb_idl_txn_commit(txn);
         ovsdb_idl_txn_destroy(txn);
     }
 
@@ -2700,17 +2694,6 @@ iface_configure_cfm(struct iface *iface)
     ofproto_port_set_cfm(iface->port->bridge->ofproto, iface->ofp_port, &s);
 }
 
-/* Read carrier or miimon status directly from 'iface''s netdev, according to
- * how 'iface''s port is configured.
- *
- * Returns true if 'iface' is up, false otherwise. */
-static bool
-iface_get_carrier(const struct iface *iface)
-{
-    /* XXX */
-    return netdev_get_carrier(iface->netdev);
-}
-
 /* Returns true if 'iface' is synthetic, that is, if we constructed it locally
  * instead of obtaining it from the database. */
 static bool