From 020c93874e22c1c7492c30fe76a8e496571ede13 Mon Sep 17 00:00:00 2001 From: Simon Horman Date: Tue, 27 Nov 2012 10:12:26 -0800 Subject: [PATCH] lib: Add helpers for OpenFlow version command line options Signed-off-by: Simon Horman [blp@nicira.com renamed some functions and options and revised the documentation] Signed-off-by: Ben Pfaff --- lib/automake.mk | 3 +++ lib/ofp-version-opt.c | 36 ++++++++++++++++++++++++++++++++++++ lib/ofp-version-opt.h | 25 +++++++++++++++++++++++++ lib/ofp-version.man | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 lib/ofp-version-opt.c create mode 100644 lib/ofp-version-opt.h create mode 100644 lib/ofp-version.man diff --git a/lib/automake.mk b/lib/automake.mk index f6b2aa1b..740f33f5 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -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 index 00000000..1801e9f7 --- /dev/null +++ b/lib/ofp-version-opt.c @@ -0,0 +1,36 @@ +#include +#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 index 00000000..78e31352 --- /dev/null +++ b/lib/ofp-version-opt.h @@ -0,0 +1,25 @@ +#ifndef OFP_VERSION_H +#define OFP_VERSION_H 1 + +#include +#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 index 00000000..54fa1664 --- /dev/null +++ b/lib/ofp-version.man @@ -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 -- 2.30.2