[ovs-dev] [PATCH] bridge: store system interface status information in Interface table

Andrew Evans andrew at fivevalve.com
Sun Jan 16 07:25:08 UTC 2011


This patch adds columns to the Interface table to store state 
information about physical network interfaces. It adds code to the 
bridge to populate those colums when the Interface table is refreshed. 
It also stores certain other state information in the existing status 
map in the Interface table.

-Andrew
---
  lib/netdev-linux.c         |   23 ++++++++++++++-
  lib/netdev-provider.h      |    2 +-
  lib/netdev.c               |    4 +-
  lib/netdev.h               |    2 +-
  vswitchd/bridge.c          |   26 +++++++++++++++++
  vswitchd/vswitch.ovsschema |   19 +++++++++++-
  vswitchd/vswitch.xml       |   65 
++++++++++++++++++++++++++++++++++++++++++++
  7 files changed, 133 insertions(+), 8 deletions(-)

diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index 97f9a64..0c2fc7e 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -1140,7 +1140,7 @@ netdev_linux_get_stats(const struct netdev *netdev_,
   * bitmap of "enum ofp_port_features" bits, in host byte order.  
Returns 0 if
   * successful, otherwise a positive errno value. */
  static int
-netdev_linux_get_features(struct netdev *netdev,
+netdev_linux_get_features(const struct netdev *netdev,
                            uint32_t *current, uint32_t *advertised,
                            uint32_t *supported, uint32_t *peer)
  {
@@ -1964,6 +1964,25 @@ 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);
+    if (!(error = netdev_linux_do_ethtool(netdev_get_name(netdev),
+                                          (struct ethtool_cmd *)&drvinfo,
+                                          ETHTOOL_GDRVINFO,
+                                          "ETHTOOL_GDRVINFO"))) {
+        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,
@@ -2176,7 +2195,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,                                  \
diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h
index da0ad45..8c34a45 100644
--- a/lib/netdev-provider.h
+++ b/lib/netdev-provider.h
@@ -287,7 +287,7 @@ struct netdev_class {
       *
       * This function may be set to null if it would always return 
EOPNOTSUPP.
       */
-    int (*get_features)(struct netdev *netdev,
+    int (*get_features)(const struct netdev *netdev,
                          uint32_t *current, uint32_t *advertised,
                          uint32_t *supported, uint32_t *peer);

diff --git a/lib/netdev.c b/lib/netdev.c
index 0f22327..82227b6 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -618,11 +618,11 @@ netdev_get_ifindex(const struct netdev *netdev)
   * Some network devices may not implement support for this function.  
In such
   * cases this function will always return EOPNOTSUPP. */
  int
-netdev_get_features(struct netdev *netdev,
+netdev_get_features(const struct netdev *netdev,
                      uint32_t *current, uint32_t *advertised,
                      uint32_t *supported, uint32_t *peer)
  {
-    int (*get_features)(struct netdev *netdev,
+    int (*get_features)(const struct netdev *netdev,
                          uint32_t *current, uint32_t *advertised,
                          uint32_t *supported, uint32_t *peer);
      uint32_t dummy[4];
diff --git a/lib/netdev.h b/lib/netdev.h
index 50ad5a3..ee36d87 100644
--- a/lib/netdev.h
+++ b/lib/netdev.h
@@ -126,7 +126,7 @@ int netdev_get_etheraddr(const struct netdev *, 
uint8_t mac[6]);

  /* PHY interface. */
  bool netdev_get_carrier(const struct netdev *);
-int netdev_get_features(struct netdev *,
+int netdev_get_features(const struct netdev *,
                          uint32_t *current, uint32_t *advertised,
                          uint32_t *supported, uint32_t *peer);
  uint64_t netdev_features_to_bps(uint32_t features);
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index c15ef36..788c595 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -1117,6 +1117,10 @@ iface_refresh_status(struct iface *iface)
  {
      struct shash sh;

+    enum netdev_flags flags;
+    uint32_t current;
+    int mtu;
+
      shash_init(&sh);

      if (!netdev_get_status(iface->netdev, &sh)) {
@@ -1133,6 +1137,28 @@ iface_refresh_status(struct iface *iface)
      }

      shash_destroy_free_data(&sh);
+
+    if (!netdev_get_flags(iface->netdev, &flags)) {
+        ovsrec_interface_set_admin_state(iface->cfg, xstrdup(flags & 
NETDEV_UP
+                                                             ? "up" : 
"down"));
+    }
+
+    if (!netdev_get_features(iface->netdev, &current, NULL, NULL, NULL)) {
+        ovsrec_interface_set_duplex(iface->cfg,
+                                    
xstrdup(netdev_features_is_full_duplex(current)
+                                            ? "full" : "half"));
+
+        ovsrec_interface_set_link_speed(iface->cfg,
+                                        netdev_features_to_bps(current));
+    }
+
+    ovsrec_interface_set_link_state(iface->cfg,
+                                    
xstrdup(netdev_get_carrier(iface->netdev)
+                                            ? "up" : "down"));
+
+    if (!netdev_get_mtu(iface->netdev, &mtu)) {
+        ovsrec_interface_set_mtu(iface->cfg, mtu);
+    }
  }

  static void
diff --git a/vswitchd/vswitch.ovsschema b/vswitchd/vswitch.ovsschema
index beb8331..7480e13 100644
--- a/vswitchd/vswitch.ovsschema
+++ b/vswitchd/vswitch.ovsschema
@@ -1,6 +1,6 @@
  {"name": "Open_vSwitch",
- "version": "1.0.4",
- "cksum": "1999497811 14145",
+ "version": "1.0.5",
+ "cksum": "994349285 14532",
   "tables": {
     "Open_vSwitch": {
       "columns": {
@@ -171,6 +171,21 @@
           "ephemeral": true},
         "status": {
           "type": {"key": "string", "value": "string", "min": 0, "max": 
"unlimited"},
+         "ephemeral": true},
+       "admin_state": {
+         "type": "string",
+         "ephemeral": true},
+       "link_state": {
+         "type": "string",
+         "ephemeral": true},
+       "link_speed": {
+         "type": "integer",
+         "ephemeral": true},
+       "duplex": {
+         "type": "string",
+         "ephemeral": true},
+       "mtu": {
+         "type": "integer",
           "ephemeral": true}}},
     "Monitor": {
       "columns": {
diff --git a/vswitchd/vswitch.xml b/vswitchd/vswitch.xml
index 923d1be..774538c 100644
--- a/vswitchd/vswitch.xml
+++ b/vswitchd/vswitch.xml
@@ -973,6 +973,53 @@
<ref column="type"/>.
</column>

+ <column name="admin_state">
+ <p>
+          The administrative state of the physical network link.
+          Valid values are <code>down</code> and <code>up</code>.
+          This column is only valid for interfaces of the
+ <code>system</code> <ref column="type"/>.
+ </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.
+          Valid values are <code>down</code> and <code>up</code>.
+          This column is only valid for interfaces of the
+ <code>system</code> <ref column="type"/>.
+ </p>
+ </column>
+
+ <column name="link_speed">
+ <p>
+          The negotiated speed of the physical network link.
+          Valid values are positive integers greater than 0.
+          This column is only valid for interfaces of the
+ <code>system</code> <ref column="type"/>.
+ </p>
+ </column>
+
+ <column name="duplex">
+ <p>
+          The duplex mode of the physical network link.
+          Valid values are <code>half</code> and <code>full</code>.
+          This column is only valid for interfaces of the
+ <code>system</code> <ref column="type"/>.
+ </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.
+          Valid values are (positive integers in range of 0-???).
+          This column is only valid for interfaces of the
+ <code>system</code> <ref column="type"/>.
+ </p>
+ </column>
+
<column name="status">
<p>
            Key-value pairs that report port status.  Supported status
@@ -980,6 +1027,24 @@
</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.  This key is only valid for interfaces of the
+ <code>system</code> type.</dd>
+ </dl>
+ <dl>
+ <dt><code>driver_version</code></dt>
+ <dd>The version string of the device driver controlling the
+            network adapter.  This key is only valid for interfaces of the
+ <code>system</code> type.</dd>
+ </dl>
+ <dl>
+ <dt><code>firmware_version</code></dt>
+ <dd>The version string of the network adapter's firmware, if
+            available.  This key is only valid for interfaces of the
+ <code>system</code> type.</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
-- 
1.7.2.3





More information about the dev mailing list