[ovs-dev] [PATCH 09/17] ofp-util: Add ofputil_protocols_{from, to}_string()

Simon Horman horms at verge.net.au
Thu Oct 4 02:41:24 UTC 2012


This is preparation for adding minimum and maximum OpenFlow versions as
command-line options for vswitchd and various utilities.

Signed-off-by: Simon Horman <horms at verge.net.au>
---
 lib/ofp-util.c |   30 ++++++++++++++++++++++++++++++
 lib/ofp-util.h |    3 +++
 2 files changed, 33 insertions(+)

diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index ca560cb..121c0c2 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -851,6 +851,36 @@ ofputil_protocols_from_string(const char *s)
     return protocols;
 }
 
+enum ofp_version
+ofputil_version_from_string(const char *s)
+{
+    if (!strcasecmp(s, "OpenFlow10")) {
+        return OFP10_VERSION;
+    }
+    if (!strcasecmp(s, "OpenFlow11")) {
+        return OFP11_VERSION;
+    }
+    if (!strcasecmp(s, "OpenFlow12")) {
+        return OFP12_VERSION;
+    }
+    VLOG_FATAL("Unknown OpenFlow version: \"%s\"", s);
+}
+
+const char *
+ofputil_version_to_string(enum ofp_version ofp_version)
+{
+    switch (ofp_version) {
+    case OFP10_VERSION:
+        return "OpenFlow10";
+    case OFP11_VERSION:
+        return "OpenFlow11";
+    case OFP12_VERSION:
+        return "OpenFlow12";
+    default:
+        NOT_REACHED();
+    }
+}
+
 bool
 ofputil_packet_in_format_is_valid(enum nx_packet_in_format packet_in_format)
 {
diff --git a/lib/ofp-util.h b/lib/ofp-util.h
index 1071c73..7a43086 100644
--- a/lib/ofp-util.h
+++ b/lib/ofp-util.h
@@ -100,6 +100,9 @@ char *ofputil_protocols_to_string(enum ofputil_protocol);
 enum ofputil_protocol ofputil_protocols_from_string(const char *);
 enum ofputil_protocol ofputil_usable_protocols(const struct match *);
 
+enum ofp_version ofputil_version_from_string(const char *s);
+const char *ofputil_version_to_string(enum ofp_version ofp_version);
+
 struct ofpbuf *ofputil_encode_set_protocol(enum ofputil_protocol current,
                                            enum ofputil_protocol want,
                                            enum ofputil_protocol *next);
-- 
1.7.10.4




More information about the dev mailing list