lib: Add helpers for OpenFlow version command line options
authorSimon Horman <horms@verge.net.au>
Tue, 27 Nov 2012 18:12:26 +0000 (10:12 -0800)
committerBen Pfaff <blp@nicira.com>
Tue, 27 Nov 2012 18:13:16 +0000 (10:13 -0800)
Signed-off-by: Simon Horman <horms@verge.net.au>
[blp@nicira.com renamed some functions and options and revised
 the documentation]
Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/automake.mk
lib/ofp-version-opt.c [new file with mode: 0644]
lib/ofp-version-opt.h [new file with mode: 0644]
lib/ofp-version.man [new file with mode: 0644]

index f6b2aa1b09a3d267b7322d3e131e04c483c9a439..740f33f5b2a07c74d68ddf0a490fb5dce590eeee 100644 (file)
@@ -111,6 +111,8 @@ lib_libopenvswitch_a_SOURCES = \
        lib/ofp-util.c \
        lib/ofp-util.def \
        lib/ofp-util.h \
+       lib/ofp-version-opt.h \
+       lib/ofp-version-opt.c \
        lib/ofpbuf.c \
        lib/ofpbuf.h \
        lib/ovsdb-data.c \
@@ -287,6 +289,7 @@ MAN_FRAGMENTS += \
        lib/daemon-syn.man \
        lib/leak-checker.man \
        lib/memory-unixctl.man \
+       lib/ofp-version.man \
        lib/ovs.tmac \
        lib/ssl-bootstrap.man \
        lib/ssl-bootstrap-syn.man \
diff --git a/lib/ofp-version-opt.c b/lib/ofp-version-opt.c
new file mode 100644 (file)
index 0000000..1801e9f
--- /dev/null
@@ -0,0 +1,36 @@
+#include <config.h>
+#include "ofp-util.h"
+#include "ofp-version-opt.h"
+#include "vlog.h"
+#include "dynamic-string.h"
+
+VLOG_DEFINE_THIS_MODULE(ofp_version);
+
+static uint32_t allowed_versions = 0;
+
+uint32_t
+get_allowed_ofp_versions(void)
+{
+    return allowed_versions ? allowed_versions : OFPUTIL_DEFAULT_VERSIONS;
+}
+
+void
+set_allowed_ofp_versions(const char *string)
+{
+    allowed_versions = ofputil_versions_from_string(string);
+}
+
+void
+ofp_version_usage(void)
+{
+    struct ds msg = DS_EMPTY_INITIALIZER;
+
+    ofputil_format_version_bitmap_names(&msg, OFPUTIL_DEFAULT_VERSIONS);
+    printf(
+        "\nOpen Flow Version options:\n"
+        "  -V, --version           display version information\n"
+        "  --allowed-ofp-versions  list of allowed Open Flow versions\n"
+        "                          (default: %s)\n",
+        ds_cstr(&msg));
+    ds_destroy(&msg);
+}
diff --git a/lib/ofp-version-opt.h b/lib/ofp-version-opt.h
new file mode 100644 (file)
index 0000000..78e3135
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef OFP_VERSION_H
+#define OFP_VERSION_H 1
+
+#include <openflow/openflow-common.h>
+#include "util.h"
+#include "ofp-util.h"
+
+#define OFP_VERSION_LONG_OPTIONS                                \
+        {"version",     no_argument, NULL, 'V'},                \
+        {"protocols", required_argument, NULL, 'O'}
+
+#define OFP_VERSION_OPTION_HANDLERS                             \
+        case 'V':                                               \
+            ovs_print_version(OFP10_VERSION, OFP13_VERSION);    \
+            exit(EXIT_SUCCESS);                                 \
+                                                                \
+        case 'O':                                               \
+            set_allowed_ofp_versions(optarg);                   \
+            break;
+
+uint32_t get_allowed_ofp_versions(void);
+void set_allowed_ofp_versions(const char *string);
+void ofp_version_usage(void);
+
+#endif
diff --git a/lib/ofp-version.man b/lib/ofp-version.man
new file mode 100644 (file)
index 0000000..54fa166
--- /dev/null
@@ -0,0 +1,33 @@
+.de IQ
+.  br
+.  ns
+.  IP "\\$1"
+..
+.IP "\fB\-O \fR[\fIversion\fR[\fB,\fIversion\fR]...]\fR"
+.IQ "\fB\-\-protocols=\fR[\fIversion\fR[\fB,\fIversion\fR]...]\fR"
+Sets the OpenFlow protocol versions that are allowed when establishing
+an OpenFlow session.
+.
+.IP
+The following versions are considered to be ready for general use.
+These protocol versions are enabled by default:
+.
+.RS
+.IP \(bu
+\fBOpenFlow10\fR, for OpenFlow 1.0.
+.RE
+.
+.IP
+Support for the following protocol versions is provided for testing
+and development purposes.  They are not enabled by default:
+.
+.RS
+.IP \(bu
+\fBOpenFlow11\fR, for OpenFlow 1.1.
+.
+.IP \(bu
+\fBOpenFlow12\fR, for OpenFlow 1.2.
+.
+.IP \(bu
+\fBOpenFlow13\fR, for OpenFlow 1.3.
+.RE