Skip to content

Commit

Permalink
lib: Add helpers for OpenFlow version command line options
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Horman <[email protected]>
[[email protected] renamed some functions and options and revised
 the documentation]
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
horms authored and blp committed Nov 27, 2012
1 parent 2e1ae20 commit 020c938
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/automake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
36 changes: 36 additions & 0 deletions lib/ofp-version-opt.c
Original file line number Diff line number Diff line change
@@ -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);
}
25 changes: 25 additions & 0 deletions lib/ofp-version-opt.h
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions lib/ofp-version.man
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 020c938

Please sign in to comment.