ovs-vsctl: Try connecting only once for active connections by default.
[sliver-openvswitch.git] / vswitchd / bridge.c
index ab0ecd6..9449879 100644 (file)
@@ -318,7 +318,7 @@ void
 bridge_init(const char *remote)
 {
     /* Create connection to database. */
-    idl = ovsdb_idl_create(remote, &ovsrec_idl_class, true);
+    idl = ovsdb_idl_create(remote, &ovsrec_idl_class, true, true);
     idl_seqno = ovsdb_idl_get_seqno(idl);
     ovsdb_idl_set_lock(idl, "ovs_vswitchd");
     ovsdb_idl_verify_write_only(idl);
@@ -345,6 +345,7 @@ bridge_init(const char *remote)
     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_mac_in_use);
     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);
@@ -1698,6 +1699,7 @@ iface_refresh_status(struct iface *iface)
     int64_t bps;
     int mtu;
     int64_t mtu_64;
+    uint8_t mac[ETH_ADDR_LEN];
     int error;
 
     if (iface_is_synthetic(iface)) {
@@ -1721,8 +1723,7 @@ iface_refresh_status(struct iface *iface)
                                     netdev_features_is_full_duplex(current)
                                     ? "full" : "half");
         ovsrec_interface_set_link_speed(iface->cfg, &bps, 1);
-    }
-    else {
+    } else {
         ovsrec_interface_set_duplex(iface->cfg, NULL);
         ovsrec_interface_set_link_speed(iface->cfg, NULL, 0);
     }
@@ -1731,10 +1732,19 @@ iface_refresh_status(struct iface *iface)
     if (!error) {
         mtu_64 = mtu;
         ovsrec_interface_set_mtu(iface->cfg, &mtu_64, 1);
-    }
-    else {
+    } else {
         ovsrec_interface_set_mtu(iface->cfg, NULL, 0);
     }
+
+    error = netdev_get_etheraddr(iface->netdev, mac);
+    if (!error) {
+        char mac_string[32];
+
+        sprintf(mac_string, ETH_ADDR_FMT, ETH_ADDR_ARGS(mac));
+        ovsrec_interface_set_mac_in_use(iface->cfg, mac_string);
+    } else {
+        ovsrec_interface_set_mac_in_use(iface->cfg, NULL);
+    }
 }
 
 /* Writes 'iface''s CFM statistics to the database. 'iface' must not be
@@ -1743,57 +1753,47 @@ static void
 iface_refresh_cfm_stats(struct iface *iface)
 {
     const struct ovsrec_interface *cfg = iface->cfg;
-    int fault, opup, error;
-    const uint64_t *rmps;
-    size_t n_rmps;
-    int health;
-
-    fault = ofproto_port_get_cfm_fault(iface->port->bridge->ofproto,
-                                       iface->ofp_port);
-    if (fault >= 0) {
+    struct ofproto_cfm_status status;
+
+    if (!ofproto_port_get_cfm_status(iface->port->bridge->ofproto,
+                                    iface->ofp_port, &status)) {
+        ovsrec_interface_set_cfm_fault(cfg, NULL, 0);
+        ovsrec_interface_set_cfm_fault_status(cfg, NULL, 0);
+        ovsrec_interface_set_cfm_remote_opstate(cfg, NULL);
+        ovsrec_interface_set_cfm_health(cfg, NULL, 0);
+        ovsrec_interface_set_cfm_remote_mpids(cfg, NULL, 0);
+    } else {
         const char *reasons[CFM_FAULT_N_REASONS];
-        bool fault_bool = fault;
+        int64_t cfm_health = status.health;
+        bool faulted = status.faults != 0;
         size_t i, j;
 
+        ovsrec_interface_set_cfm_fault(cfg, &faulted, 1);
+
         j = 0;
         for (i = 0; i < CFM_FAULT_N_REASONS; i++) {
             int reason = 1 << i;
-            if (fault & reason) {
+            if (status.faults & reason) {
                 reasons[j++] = cfm_fault_reason_to_str(reason);
             }
         }
-
-        ovsrec_interface_set_cfm_fault(cfg, &fault_bool, 1);
         ovsrec_interface_set_cfm_fault_status(cfg, (char **) reasons, j);
-    } else {
-        ovsrec_interface_set_cfm_fault(cfg, NULL, 0);
-        ovsrec_interface_set_cfm_fault_status(cfg, NULL, 0);
-    }
 
-    opup = ofproto_port_get_cfm_opup(iface->port->bridge->ofproto,
-                                     iface->ofp_port);
-    if (opup >= 0) {
-        ovsrec_interface_set_cfm_remote_opstate(cfg, opup ? "up" : "down");
-    } else {
-        ovsrec_interface_set_cfm_remote_opstate(cfg, NULL);
-    }
-
-    error = ofproto_port_get_cfm_remote_mpids(iface->port->bridge->ofproto,
-                                              iface->ofp_port, &rmps, &n_rmps);
-    if (error >= 0) {
-        ovsrec_interface_set_cfm_remote_mpids(cfg, (const int64_t *)rmps,
-                                              n_rmps);
-    } else {
-        ovsrec_interface_set_cfm_remote_mpids(cfg, NULL, 0);
-    }
+        if (status.remote_opstate >= 0) {
+            const char *remote_opstate = status.remote_opstate ? "up" : "down";
+            ovsrec_interface_set_cfm_remote_opstate(cfg, remote_opstate);
+        } else {
+            ovsrec_interface_set_cfm_remote_opstate(cfg, NULL);
+        }
 
-    health = ofproto_port_get_cfm_health(iface->port->bridge->ofproto,
-                                        iface->ofp_port);
-    if (health >= 0) {
-        int64_t cfm_health = health;
-        ovsrec_interface_set_cfm_health(cfg, &cfm_health, 1);
-    } else {
-        ovsrec_interface_set_cfm_health(cfg, NULL, 0);
+        ovsrec_interface_set_cfm_remote_mpids(cfg,
+                                              (const int64_t *)status.rmps,
+                                              status.n_rmps);
+        if (cfm_health >= 0) {
+            ovsrec_interface_set_cfm_health(cfg, &cfm_health, 1);
+        } else {
+            ovsrec_interface_set_cfm_health(cfg, NULL, 0);
+        }
     }
 }
 
@@ -3342,6 +3342,7 @@ iface_clear_db_record(const struct ovsrec_interface *if_cfg)
         ovsrec_interface_set_duplex(if_cfg, NULL);
         ovsrec_interface_set_link_speed(if_cfg, NULL, 0);
         ovsrec_interface_set_link_state(if_cfg, NULL);
+        ovsrec_interface_set_mac_in_use(if_cfg, NULL);
         ovsrec_interface_set_mtu(if_cfg, NULL, 0);
         ovsrec_interface_set_cfm_fault(if_cfg, NULL, 0);
         ovsrec_interface_set_cfm_fault_status(if_cfg, NULL, 0);