bridge: Add controller status to Controller table.
[openvswitch] / vswitchd / bridge.c
index fb8ce5f19ac7ea1ae3da588206c835c0c8565668..1065d6eaf8177a50deb64807a8c13b194823f59d 100644 (file)
@@ -1120,6 +1120,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)) {
@@ -1136,6 +1143,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
@@ -1275,6 +1318,42 @@ 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);
+
+        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);
+    }
+
+    ofproto_free_ofproto_controller_info(&info);
+}
+
 void
 bridge_run(void)
 {
@@ -1350,6 +1429,7 @@ bridge_run(void)
                         iface_refresh_status(iface);
                     }
                 }
+                bridge_refresh_controller_status(br);
             }
             refresh_system_stats(cfg);
             ovsdb_idl_txn_commit(txn);