ovs-vswitchd: Remove inline OpenFlow descriptions
authorJustin Pettit <jpettit@nicira.com>
Fri, 29 Jan 2010 23:31:52 +0000 (15:31 -0800)
committerJustin Pettit <jpettit@nicira.com>
Sat, 20 Feb 2010 10:22:29 +0000 (02:22 -0800)
Replace inline OpenFlow descriptions with #define.  Also, start work to
support setting them dynamically.

(This was originally working with the config file version of vswitchd,
but needs to be updated to work with the config db.)

ofproto/ofproto.c
ofproto/ofproto.h
vswitchd/bridge.c

index b962f61bff6324f9be8631df53ec180445f06167..764d4a82ac2d83ca09c3162367a2ad5f3e2747a3 100644 (file)
@@ -299,11 +299,11 @@ ofproto_create(const char *datapath, const char *datapath_type,
     p = xzalloc(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;
index 668cdffb6edf8c2f059f85f5184d75e03c67079b..7fa6ed266784b3332c0d4c8208d10f5eb178601f 100644 (file)
@@ -51,6 +51,12 @@ struct ofproto_sflow_options {
     char *control_ip;
 };
 
+#define DEFAULT_MFR_DESC "Nicira Networks, Inc."
+#define DEFAULT_HW_DESC "Open vSwitch"
+#define DEFAULT_SW_DESC VERSION BUILDNR
+#define DEFAULT_SERIAL_DESC "None"
+#define DEFAULT_DP_DESC "None"
+
 int ofproto_create(const char *datapath, const char *datapath_type,
                    const struct ofhooks *, void *aux,
                    struct ofproto **ofprotop);
index c2e89eb838de330afc06f2c0b4c0f25b9ad1a1b6..63b0c9b21fe8c1d378bb2f19bff5bb66496721cf 100644 (file)
@@ -163,6 +163,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. */
@@ -1298,6 +1305,75 @@ check_duplicate_ifaces(struct bridge *br, struct iface *iface, void *ifaces_)
     }
 }
 
+static void
+bridge_update_desc(struct bridge *br)
+{
+#if 0
+    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);
+    }
+#endif
+}
+
 static void
 bridge_reconfigure_one(const struct ovsrec_open_vswitch *ovs_cfg,
                        struct bridge *br)
@@ -1436,6 +1512,8 @@ bridge_reconfigure_one(const struct ovsrec_open_vswitch *ovs_cfg,
 #endif
 
     mirror_reconfigure(br);
+
+    bridge_update_desc(br);
 }
 
 static void