[ovs-dev] [PATCH 2/8] ofp-util: Flow Dump Protocol for OpenFlow 12

Simon Horman horms at verge.net.au
Mon Nov 19 05:59:29 UTC 2012


Allow only OpenFlow 12 as a flow dump protocol for OpenFlow12.
Allow OpenFlow10 and NXM as flow dump protocols for other OpenFlow versions.
This only changes the behaviour prior to this patch in the case of OpenFlow12
which seemed broken as an attempt would be made to set NXM as the
flow dump format using an OpenFlow 1.0 message even though an OpenFlow 1.2
connection had been negotiated..

Signed-off-by: Simon Horman <horms at verge.net.au>

---

v5
* Rebase

v4
* Rebase
---
 lib/ofp-util.c        |   24 +++++++++++++++++++-----
 lib/ofp-util.h        |    5 ++---
 utilities/ovs-ofctl.c |    8 ++++++--
 3 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index d4c240d..b0b44d9 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -587,11 +587,25 @@ static const struct proto_abbrev proto_abbrevs[] = {
 };
 #define N_PROTO_ABBREVS ARRAY_SIZE(proto_abbrevs)
 
-enum ofputil_protocol ofputil_flow_dump_protocols[] = {
-    OFPUTIL_P_OF10_NXM,
-    OFPUTIL_P_OF10_STD,
-};
-size_t ofputil_n_flow_dump_protocols = ARRAY_SIZE(ofputil_flow_dump_protocols);
+/* Protocols to use for flow dumps, from most to least preferred. */
+const enum ofputil_protocol *
+ofputil_get_flow_dump_protocols(enum ofputil_protocol current, size_t *count)
+{
+    if (current == OFPUTIL_P_OF12_OXM) {
+        static const enum ofputil_protocol of12_proto[] = {
+            OFPUTIL_P_OF12_OXM,
+        };
+        *count = ARRAY_SIZE(of12_proto);
+        return of12_proto;
+    } else {
+        static const enum ofputil_protocol of10_proto[] = {
+            OFPUTIL_P_OF10_NXM,
+            OFPUTIL_P_OF10_STD,
+        };
+        *count = ARRAY_SIZE(of10_proto);
+        return of10_proto;
+    }
+}
 
 /* Returns the ofputil_protocol that is initially in effect on an OpenFlow
  * connection that has negotiated the given 'version'.  'version' should
diff --git a/lib/ofp-util.h b/lib/ofp-util.h
index d87554d..690413a 100644
--- a/lib/ofp-util.h
+++ b/lib/ofp-util.h
@@ -95,9 +95,8 @@ enum ofputil_protocol {
                        OFPUTIL_P_OF12_OXM)
 };
 
-/* Protocols to use for flow dumps, from most to least preferred. */
-extern enum ofputil_protocol ofputil_flow_dump_protocols[];
-extern size_t ofputil_n_flow_dump_protocols;
+const enum ofputil_protocol *
+ofputil_get_flow_dump_protocols(enum ofputil_protocol current, size_t *count);
 
 enum ofputil_protocol
 ofputil_protocol_from_ofp_version(enum ofp_version version);
diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index 08c3aa9..6564bdb 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -788,9 +788,13 @@ set_protocol_for_flow_dump(struct vconn *vconn,
 {
     char *usable_s;
     int i;
+    size_t n_dump_protocols;
+    const enum ofputil_protocol *dump_protocols;
 
-    for (i = 0; i < ofputil_n_flow_dump_protocols; i++) {
-        enum ofputil_protocol f = ofputil_flow_dump_protocols[i];
+    dump_protocols = ofputil_get_flow_dump_protocols(cur_protocol,
+                                                     &n_dump_protocols);
+    for (i = 0; i < n_dump_protocols; i++) {
+        enum ofputil_protocol f = dump_protocols[i];
         if (f & usable_protocols & allowed_protocols
             && try_set_protocol(vconn, f, &cur_protocol)) {
             return f;
-- 
1.7.10.4




More information about the dev mailing list