[ovs-dev] [PATCH 06/18] ofproto: Make set_pvconns() aware of OpenFlow versions

Simon Horman horms at verge.net.au
Thu Oct 18 05:58:06 UTC 2012


Paramatise the allowed OpenFlow verion for snoops.
This is in preparation for making the allow OpenFlow verions to
be configured.

Signed-off-by: Simon Horman <horms at verge.net.au>
---
 ofproto/connmgr.c |   20 +++++++++-----------
 ofproto/connmgr.h |    2 +-
 ofproto/ofproto.c |    2 +-
 ofproto/ofproto.h |    8 +++++++-
 vswitchd/bridge.c |   24 ++++++++++++++++++------
 5 files changed, 36 insertions(+), 20 deletions(-)

diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c
index 17d9fb5..4db038d 100644
--- a/ofproto/connmgr.c
+++ b/ofproto/connmgr.c
@@ -405,7 +405,7 @@ static struct ofconn *find_controller_by_target(struct connmgr *,
                                                 const char *target);
 static void update_fail_open(struct connmgr *);
 static int set_pvconns(struct pvconn ***pvconnsp, size_t *n_pvconnsp,
-                       const struct sset *);
+                       const struct shash *);
 
 /* Returns true if 'mgr' has any configured primary controllers.
  *
@@ -588,7 +588,7 @@ connmgr_reconnect(const struct connmgr *mgr)
  * A "snoop" is a pvconn to which every OpenFlow message to or from the most
  * important controller on 'mgr' is mirrored. */
 int
-connmgr_set_snoops(struct connmgr *mgr, const struct sset *snoops)
+connmgr_set_snoops(struct connmgr *mgr, const struct shash *snoops)
 {
     return set_pvconns(&mgr->snoops, &mgr->n_snoops, snoops);
 }
@@ -708,11 +708,11 @@ update_fail_open(struct connmgr *mgr)
 
 static int
 set_pvconns(struct pvconn ***pvconnsp, size_t *n_pvconnsp,
-            const struct sset *sset)
+            const struct shash *shash)
 {
     struct pvconn **pvconns = *pvconnsp;
     size_t n_pvconns = *n_pvconnsp;
-    const char *name;
+    struct shash_node *node;
     int retval = 0;
     size_t i;
 
@@ -721,20 +721,18 @@ set_pvconns(struct pvconn ***pvconnsp, size_t *n_pvconnsp,
     }
     free(pvconns);
 
-    pvconns = xmalloc(sset_count(sset) * sizeof *pvconns);
+    pvconns = xmalloc(shash_count(shash) * sizeof *pvconns);
     n_pvconns = 0;
-    SSET_FOR_EACH (name, sset) {
-        struct ofputil_version_bitmap ovb = OFPUTIL_VERSION_BITMAP_INITIALIZER;
+    SHASH_FOR_EACH (node, shash) {
+        const struct ofproto_name_and_versions *nv = node->data;
         struct pvconn *pvconn;
         int error;
 
-        ofputil_version_bitmap_set1(&ovb, OFP10_VERSION);
-        error = pvconn_open(name, &ovb, &pvconn, 0);
-        ofputil_version_bitmap_free_data(&ovb);
+        error = pvconn_open(nv->name, nv->allowed_versions, &pvconn, 0);
         if (!error) {
             pvconns[n_pvconns++] = pvconn;
         } else {
-            VLOG_ERR("failed to listen on %s: %s", name, strerror(error));
+            VLOG_ERR("failed to listen on %s: %s", nv->name, strerror(error));
             if (!retval) {
                 retval = error;
             }
diff --git a/ofproto/connmgr.h b/ofproto/connmgr.h
index 9a080f2..3a508ca 100644
--- a/ofproto/connmgr.h
+++ b/ofproto/connmgr.h
@@ -88,7 +88,7 @@ void connmgr_set_controllers(struct connmgr *,
                              const struct ofproto_controller[], size_t n);
 void connmgr_reconnect(const struct connmgr *);
 
-int connmgr_set_snoops(struct connmgr *, const struct sset *snoops);
+int connmgr_set_snoops(struct connmgr *mgr, const struct shash *snoops);
 bool connmgr_has_snoops(const struct connmgr *);
 void connmgr_get_snoops(const struct connmgr *, struct sset *snoops);
 
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 2fb2fc8..568f9bb 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -606,7 +606,7 @@ ofproto_set_desc(struct ofproto *p,
 }
 
 int
-ofproto_set_snoops(struct ofproto *ofproto, const struct sset *snoops)
+ofproto_set_snoops(struct ofproto *ofproto, const struct shash *snoops)
 {
     return connmgr_set_snoops(ofproto->connmgr, snoops);
 }
diff --git a/ofproto/ofproto.h b/ofproto/ofproto.h
index 5599cd6..2128e07 100644
--- a/ofproto/ofproto.h
+++ b/ofproto/ofproto.h
@@ -28,6 +28,7 @@
 #include "sset.h"
 #include "stp.h"
 #include "tag.h"
+#include "lib/ofp-util.h"
 
 #ifdef  __cplusplus
 extern "C" {
@@ -132,6 +133,11 @@ struct ofproto_controller {
     uint8_t dscp;               /* DSCP value for controller connection. */
 };
 
+struct ofproto_name_and_versions {
+    char *name;
+    struct ofputil_version_bitmap *allowed_versions;
+};
+
 #define DEFAULT_MFR_DESC "Nicira, Inc."
 #define DEFAULT_HW_DESC "Open vSwitch"
 #define DEFAULT_SW_DESC VERSION
@@ -217,7 +223,7 @@ void ofproto_set_desc(struct ofproto *,
                       const char *mfr_desc, const char *hw_desc,
                       const char *sw_desc, const char *serial_desc,
                       const char *dp_desc);
-int ofproto_set_snoops(struct ofproto *, const struct sset *snoops);
+int ofproto_set_snoops(struct ofproto *ofproto, const struct shash *snoops);
 int ofproto_set_netflow(struct ofproto *,
                         const struct netflow_options *nf_options);
 int ofproto_set_sflow(struct ofproto *, const struct ofproto_sflow_options *);
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index a481f06..3267fe4 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -36,6 +36,7 @@
 #include "meta-flow.h"
 #include "netdev.h"
 #include "ofp-print.h"
+#include "ofp-util.h"
 #include "ofpbuf.h"
 #include "ofproto/ofproto.h"
 #include "poll-loop.h"
@@ -2661,6 +2662,11 @@ bridge_configure_remotes(struct bridge *br,
     size_t n_ocs;
     size_t i;
 
+    struct ofputil_version_bitmap allowed_versions =
+        OFPUTIL_VERSION_BITMAP_INITIALIZER;
+
+    ofputil_version_bitmap_set1(&allowed_versions, OFP10_VERSION);
+
     /* Check if we should disable in-band control on this bridge. */
     disable_in_band = smap_get_bool(&br->cfg->other_config, "disable-in-band",
                                     false);
@@ -2731,14 +2737,20 @@ bridge_configure_remotes(struct bridge *br,
 
     /* Configure OpenFlow controller connection snooping. */
     if (!ofproto_has_snoops(br->ofproto)) {
-        struct sset snoops;
-
-        sset_init(&snoops);
-        sset_add_and_free(&snoops, xasprintf("punix:%s/%s.snoop",
-                                             ovs_rundir(), br->name));
+        struct shash snoops;
+        struct ofproto_name_and_versions nv = {
+            .name = xasprintf("punix:%s/%s.snoop", ovs_rundir(), br->name),
+            .allowed_versions = &allowed_versions,
+        };
+
+        shash_init(&snoops);
+        shash_add(&snoops, nv.name, &nv);
         ofproto_set_snoops(br->ofproto, &snoops);
-        sset_destroy(&snoops);
+        shash_destroy(&snoops);
+        free(nv.name);
     }
+
+    ofputil_version_bitmap_free_data(&allowed_versions);
 }
 
 static void
-- 
1.7.10.4




More information about the dev mailing list