[ovs-dev] [PATCH 2/4] ovs-vswitchd: Add support for setting OpenFlow datapath descriptions

Justin Pettit jpettit at nicira.com
Sat Jan 30 00:48:27 UTC 2010


---
 ofproto/ofproto.c               |   10 +++---
 ofproto/ofproto.h               |    6 +++
 vswitchd/bridge.c               |   76 +++++++++++++++++++++++++++++++++++++++
 vswitchd/ovs-vswitchd.conf.5.in |   27 +++++++++++++-
 4 files changed, 113 insertions(+), 6 deletions(-)

diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index b25d441..d67f775 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -302,11 +302,11 @@ ofproto_create(const char *datapath, const struct ofhooks *ofhooks, void *aux,
     p = xcalloc(1, sizeof *p);
     p->fallback_dpid = pick_fallback_dpid();
     p->datapath_id = p->fallback_dpid;
-    p->manufacturer = xstrdup("Nicira Networks, Inc.");
-    p->hardware = xstrdup("Reference Implementation");
-    p->software = xstrdup(VERSION BUILDNR);
-    p->serial = xstrdup("None");
-    p->dp_desc = xstrdup("None");
+    p->manufacturer = xstrdup(DEFAULT_MFR_DESC);
+    p->hardware = xstrdup(DEFAULT_HW_DESC);
+    p->software = xstrdup(DEFAULT_SW_DESC);
+    p->serial = xstrdup(DEFAULT_SERIAL_DESC);
+    p->dp_desc = xstrdup(DEFAULT_DP_DESC);
 
     /* Initialize datapath. */
     p->dpif = dpif;
diff --git a/ofproto/ofproto.h b/ofproto/ofproto.h
index 2165a0a..95c8f8b 100644
--- a/ofproto/ofproto.h
+++ b/ofproto/ofproto.h
@@ -51,6 +51,12 @@ struct ofproto_sflow_options {
     char *control_ip;
 };
 
+#define DEFAULT_MFR_DESC "Nicira Networks, Inc."
+#define DEFAULT_HW_DESC "Reference Implementation"
+#define DEFAULT_SW_DESC VERSION BUILDNR
+#define DEFAULT_SERIAL_DESC "None"
+#define DEFAULT_DP_DESC "None"
+
 int ofproto_create(const char *datapath, const struct ofhooks *, void *aux,
                    struct ofproto **ofprotop);
 void ofproto_destroy(struct ofproto *);
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 3b7ec51..9678b1b 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -162,6 +162,13 @@ struct bridge {
     /* OpenFlow switch processing. */
     struct ofproto *ofproto;    /* OpenFlow switch. */
 
+    /* Description strings. */
+    char *mfr_desc;             /* Manufacturer. */
+    char *hw_desc;              /* Hardware. */
+    char *sw_desc;              /* Software version. */
+    char *serial_desc;          /* Serial number. */
+    char *dp_desc;              /* Datapath description. */
+
     /* Kernel datapath information. */
     struct dpif *dpif;          /* Datapath. */
     struct port_array ifaces;   /* Indexed by kernel datapath port number. */
@@ -1243,6 +1250,73 @@ check_duplicate_ifaces(struct bridge *br, struct iface *iface, void *ifaces_)
 }
 
 static void
+bridge_update_desc(struct bridge *br)
+{
+    bool changed = false;
+    const char *desc;
+
+    desc = cfg_get_string(0, "bridge.%s.mfr-desc", br->name);
+    if (desc != br->mfr_desc) {
+        free(br->mfr_desc);
+        if (desc) {
+            br->mfr_desc = xstrdup(desc);
+        } else {
+            br->mfr_desc = xstrdup(DEFAULT_MFR_DESC);
+        }
+        changed = true;
+    }
+
+    desc = cfg_get_string(0, "bridge.%s.hw-desc", br->name);
+    if (desc != br->hw_desc) {
+        free(br->hw_desc);
+        if (desc) {
+            br->hw_desc = xstrdup(desc);
+        } else {
+            br->hw_desc = xstrdup(DEFAULT_HW_DESC);
+        }
+        changed = true;
+    }
+
+    desc = cfg_get_string(0, "bridge.%s.sw-desc", br->name);
+    if (desc != br->sw_desc) {
+        free(br->sw_desc);
+        if (desc) {
+            br->sw_desc = xstrdup(desc);
+        } else {
+            br->sw_desc = xstrdup(DEFAULT_SW_DESC);
+        }
+        changed = true;
+    }
+
+    desc = cfg_get_string(0, "bridge.%s.serial-desc", br->name);
+    if (desc != br->serial_desc) {
+        free(br->serial_desc);
+        if (desc) {
+            br->serial_desc = xstrdup(desc);
+        } else {
+            br->serial_desc = xstrdup(DEFAULT_SERIAL_DESC);
+        }
+        changed = true;
+    }
+
+    desc = cfg_get_string(0, "bridge.%s.dp-desc", br->name);
+    if (desc != br->dp_desc) {
+        free(br->dp_desc);
+        if (desc) {
+            br->dp_desc = xstrdup(desc);
+        } else {
+            br->dp_desc = xstrdup(DEFAULT_DP_DESC);
+        }
+        changed = true;
+    }
+
+    if (changed) {
+        ofproto_set_desc(br->ofproto, br->mfr_desc, br->hw_desc,
+                br->sw_desc, br->serial_desc, br->dp_desc);
+    }
+}
+
+static void
 bridge_reconfigure_one(struct bridge *br)
 {
     struct svec old_ports, new_ports, ifaces;
@@ -1356,6 +1430,8 @@ bridge_reconfigure_one(struct bridge *br)
     svec_destroy(&old_snoops);
 
     mirror_reconfigure(br);
+
+    bridge_update_desc(br);
 }
 
 static void
diff --git a/vswitchd/ovs-vswitchd.conf.5.in b/vswitchd/ovs-vswitchd.conf.5.in
index e2305e2..5b63dd2 100644
--- a/vswitchd/ovs-vswitchd.conf.5.in
+++ b/vswitchd/ovs-vswitchd.conf.5.in
@@ -492,7 +492,7 @@ set \fBsflow.\fIbridge\fB.agent\fR to the name of a network device, in
 which case the IP address set on that device is used.  If no IP
 address can be determined either way, sFlow is disabled.
 .SS "Remote Management"
-A \fBovs\-vswitchd\fR instance may be remotely managed by a controller that
+An \fBovs\-vswitchd\fR instance may be remotely managed by a controller that
 supports the OpenFlow Management Protocol, such as NOX.  This
 functionality is enabled by setting the key \fBmgmt.controller\fR to one 
 of the following values:
@@ -763,6 +763,31 @@ as part of the SSL certificate chain.  The SSL protocol does not
 require the controller to send the CA certificate, but
 \fBcontroller\fR(8) can be configured to do so with the
 \fB--peer-ca-cert\fR option.
+.SS "OpenFlow Description"
+An OpenFlow datapath may be queried for information about the switch
+manufacturer, hardware revision, software revision, serial number, and a
+description of the datapath.  By default, \fBovs\-vswitchd\fR contains
+very generic descriptions for all these values.  These may be overridden
+with the following keys:
+.TP
+\fBbridge.\fIname\fB.mfr-desc=\fIdesc\fR
+Set the description of the switch's manufacturer to \fIdesc\fR, which
+may contain up to 255 ASCII characters.
+.IP "\fBbridge.\fIname\fB.hw-desc=\fIdesc\fR
+Set the description of the switch's hardware revision to \fIdesc\fR, which
+may contain up to 255 ASCII characters.
+.IP "\fBbridge.\fIname\fB.sw-desc=\fIdesc\fR
+Set the description of the switch's software revision to \fIdesc\fR, which
+may contain up to 255 ASCII characters.
+.IP "\fBbridge.\fIname\fB.serial-desc=\fIdesc\fR
+Set the description of the switch's serial number to \fIdesc\fR, which
+may contain up to 31 ASCII characters.
+.IP "\fBbridge.\fIname\fB.dp-desc=\fIdesc\fR
+Set the description of the datapath to \fIdesc\fR, which may contain up to 
+255 ASCII characters.  Note that this field is intended for debugging
+purposes and is not guaranteed to be unique and should not be used as
+the primary identifier of the datapath.
+
 .SS "OpenFlow Management Connections"
 By default, each bridge \fIname\fR listens for OpenFlow management
 connections on a Unix domain socket named
-- 
1.5.5





More information about the dev mailing list