bridge: Store status of physical network interfaces in Interface table.
authorAndrew Evans <aevans@nicira.com>
Mon, 17 Jan 2011 23:37:13 +0000 (15:37 -0800)
committerAndrew Evans <aevans@nicira.com>
Wed, 19 Jan 2011 05:09:02 +0000 (21:09 -0800)
New columns in Interface table: admin_state, link_state, link_speed, duplex,
mtu.

New keys in status map in Interface table: driver_name, driver_version,
firmware_version.

Requested-by: Peter Balland <pballand@nicira.com>
Bug #4299.

lib/netdev-linux.c
vswitchd/bridge.c
vswitchd/vswitch.ovsschema
vswitchd/vswitch.xml

index 168cd01..72541c7 100644 (file)
@@ -2025,6 +2025,26 @@ netdev_linux_get_next_hop(const struct in_addr *host, struct in_addr *next_hop,
     return ENXIO;
 }
 
+static int
+netdev_linux_get_status(const struct netdev *netdev, struct shash *sh)
+{
+    struct ethtool_drvinfo drvinfo;
+    int error;
+
+    memset(&drvinfo, 0, sizeof drvinfo);
+    error = netdev_linux_do_ethtool(netdev_get_name(netdev),
+                                    (struct ethtool_cmd *)&drvinfo,
+                                    ETHTOOL_GDRVINFO,
+                                    "ETHTOOL_GDRVINFO");
+    if (!error) {
+        shash_add(sh, "driver_name", xstrdup(drvinfo.driver));
+        shash_add(sh, "driver_version", xstrdup(drvinfo.version));
+        shash_add(sh, "firmware_version", xstrdup(drvinfo.fw_version));
+    }
+
+    return error;
+}
+
 /* Looks up the ARP table entry for 'ip' on 'netdev'.  If one exists and can be
  * successfully retrieved, it stores the corresponding MAC address in 'mac' and
  * returns 0.  Otherwise, it returns a positive errno value; in particular,
@@ -2238,7 +2258,7 @@ netdev_linux_poll_remove(struct netdev_notifier *notifier_)
     netdev_linux_get_in6,                                       \
     netdev_linux_add_router,                                    \
     netdev_linux_get_next_hop,                                  \
-    NULL,                       /* get_status */                \
+    netdev_linux_get_status,                                    \
     netdev_linux_arp_lookup,                                    \
                                                                 \
     netdev_linux_update_flags,                                  \
index fb8ce5f..680c1ad 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
index 70e56f4..e078ce0 100644 (file)
@@ -1,6 +1,6 @@
 {"name": "Open_vSwitch",
- "version": "1.0.5",
- "cksum": "2737967217 14145",
+ "version": "1.0.6",
+ "cksum": "271866752 14882",
  "tables": {
    "Open_vSwitch": {
      "columns": {
          "ephemeral": true},
        "status": {
          "type": {"key": "string", "value": "string", "min": 0, "max": "unlimited"},
+         "ephemeral": true},
+       "admin_state": {
+         "type": {"key": {"type": "string",
+                          "enum": ["set", ["up", "down"]]},
+                  "min": 0, "max": 1},
+         "ephemeral": true},
+       "link_state": {
+         "type": {"key": {"type": "string",
+                          "enum": ["set", ["up", "down"]]},
+                  "min": 0, "max": 1},
+         "ephemeral": true},
+       "link_speed": {
+         "type": {"key": "integer", "min": 0, "max": 1},
+         "ephemeral": true},
+       "duplex": {
+         "type": {"key": {"type": "string",
+                          "enum": ["set", ["half", "full"]]},
+                  "min": 0, "max": 1},
+         "ephemeral": true},
+       "mtu": {
+         "type": {"key": "integer", "min": 0, "max": 1},
          "ephemeral": true}}},
    "Monitor": {
      "columns": {
index 53c2650..d92489c 100644 (file)
         Configuration options whose interpretation varies based on
         <ref column="type"/>.
       </column>
+    </group>
+
+    <group title="Interface Status">
+      <p>
+        Status information about interfaces attached to bridges, updated every
+        5 seconds.  Not all interfaces have all of these properties; virtual
+        interfaces don't have a link speed, for example.  Non-applicable
+        columns will have empty values.
+      </p>
+      <column name="admin_state">
+        <p>
+          The administrative state of the physical network link.
+        </p>
+      </column>
+
+      <column name="link_state">
+        <p>
+          The observed state of the physical network link;
+          i.e. whether a carrier is detected by the interface.
+        </p>
+      </column>
+
+      <column name="link_speed">
+        <p>
+          The negotiated speed of the physical network link.
+          Valid values are positive integers greater than 0.
+        </p>
+      </column>
+
+      <column name="duplex">
+        <p>
+          The duplex mode of the physical network link.
+        </p>
+      </column>
+
+      <column name="mtu">
+        <p>
+          The MTU (maximum transmission unit); i.e. the largest
+          amount of data that can fit into a single Ethernet frame.
+          The standard Ethernet MTU is 1500 bytes.  Some physical media
+          and many kinds of virtual interfaces can be configured with
+          higher MTUs.
+        </p>
+      </column>
 
       <column name="status">
         <p>
           Key-value pairs that report port status.  Supported status
-          values are <code>type</code>-dependent.
+          values are <code>type</code>-dependent; some interfaces may not have
+          a valid <code>driver_name</code>, for example.
         </p>
         <p>The currently defined key-value pairs are:</p>
+        <dl>
+          <dt><code>driver_name</code></dt>
+          <dd>The name of the device driver controlling the network
+            adapter.</dd>
+        </dl>
+        <dl>
+          <dt><code>driver_version</code></dt>
+          <dd>The version string of the device driver controlling the
+            network adapter.</dd>
+        </dl>
+        <dl>
+          <dt><code>firmware_version</code></dt>
+          <dd>The version string of the network adapter's firmware, if
+            available.</dd>
+        </dl>
         <dl>
           <dt><code>source_ip</code></dt>
           <dd>The source IP address used for an IPv4 tunnel end-point,
-            such as <code>gre</code> or <code>capwap</code>.  Not
-            supported by all implementations.</dd>
+            such as <code>gre</code> or <code>capwap</code>.</dd>
         </dl>
         <dl>
             <dt><code>tunnel_egress_iface</code></dt>