Skip to content

Commit a53a8ef

Browse files
hormsblp
authored andcommitted
ovs-ofctl: Add option to set allowed OpenFlow versions
--protocols allows configuration of the versions that may be used when establishing an OpenFlow connection. The default is 'OpenFlow10' which is consistent with the behaviour prior to this patch. The useful values at this time are: 'OpenFlow10', 'OpenFlow12', 'OpenFlow13', Values may be combined in a comma delimited list. e.g.: --protocols 'OpenFlow10,OpenFlow12,OpenFlow13' Signed-off-by: Simon Horman <horms@verge.net.au> Signed-off-by: Ben Pfaff <blp@nicira.com>
1 parent b060d38 commit a53a8ef

3 files changed

Lines changed: 34 additions & 23 deletions

File tree

manpages.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,14 @@ utilities/ovs-ofctl.8: \
134134
utilities/ovs-ofctl.8.in \
135135
lib/common.man \
136136
lib/daemon.man \
137+
lib/ofp-version.man \
137138
lib/ssl.man \
138139
lib/vconn-active.man \
139140
lib/vlog.man
140141
utilities/ovs-ofctl.8.in:
141142
lib/common.man:
142143
lib/daemon.man:
144+
lib/ofp-version.man:
143145
lib/ssl.man:
144146
lib/vconn-active.man:
145147
lib/vlog.man:

utilities/ovs-ofctl.8.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,8 @@ passing through the flow.
13431343
\fB\-\-strict\fR
13441344
Uses strict matching when running flow modification commands.
13451345
.
1346+
.so lib/ofp-version.man
1347+
.
13461348
.IP "\fB\-F \fIformat\fR[\fB,\fIformat\fR...]"
13471349
.IQ "\fB\-\-flow\-format=\fIformat\fR[\fB,\fIformat\fR...]"
13481350
\fBovs\-ofctl\fR supports the following individual flow formats, any

utilities/ovs-ofctl.c

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "ofp-parse.h"
4545
#include "ofp-print.h"
4646
#include "ofp-util.h"
47+
#include "ofp-version-opt.h"
4748
#include "ofpbuf.h"
4849
#include "ofproto/ofproto.h"
4950
#include "openflow/nicira-ext.h"
@@ -147,6 +148,7 @@ parse_options(int argc, char *argv[])
147148
OPT_SORT,
148149
OPT_RSORT,
149150
DAEMON_OPTION_ENUMS,
151+
OFP_VERSION_OPTION_ENUMS,
150152
VLOG_OPTION_ENUMS
151153
};
152154
static struct option long_options[] = {
@@ -160,8 +162,8 @@ parse_options(int argc, char *argv[])
160162
{"sort", optional_argument, NULL, OPT_SORT},
161163
{"rsort", optional_argument, NULL, OPT_RSORT},
162164
{"help", no_argument, NULL, 'h'},
163-
{"version", no_argument, NULL, 'V'},
164165
DAEMON_LONG_OPTIONS,
166+
OFP_VERSION_LONG_OPTIONS,
165167
VLOG_LONG_OPTIONS,
166168
STREAM_SSL_LONG_OPTIONS,
167169
{NULL, 0, NULL, 0},
@@ -210,10 +212,6 @@ parse_options(int argc, char *argv[])
210212
case 'h':
211213
usage();
212214

213-
case 'V':
214-
ovs_print_version(OFP10_VERSION, OFP10_VERSION);
215-
exit(EXIT_SUCCESS);
216-
217215
case OPT_STRICT:
218216
strict = true;
219217
break;
@@ -235,6 +233,7 @@ parse_options(int argc, char *argv[])
235233
break;
236234

237235
DAEMON_OPTION_HANDLERS
236+
OFP_VERSION_OPTION_HANDLERS
238237
VLOG_OPTION_HANDLERS
239238
STREAM_SSL_OPTION_HANDLERS
240239

@@ -292,6 +291,7 @@ usage(void)
292291
program_name, program_name);
293292
vconn_usage(true, false, false);
294293
daemon_usage();
294+
ofp_version_usage();
295295
vlog_usage();
296296
printf("\nOther options:\n"
297297
" --strict use strict match for flow commands\n"
@@ -339,7 +339,8 @@ open_vconn_socket(const char *name, struct vconn **vconnp)
339339
char *vconn_name = xasprintf("unix:%s", name);
340340
int error;
341341

342-
error = vconn_open(vconn_name, 0, vconnp, DSCP_DEFAULT);
342+
error = vconn_open(vconn_name, get_allowed_ofp_versions(), vconnp,
343+
DSCP_DEFAULT);
343344
if (error && error != ENOENT) {
344345
ovs_fatal(0, "%s: failed to open socket (%s)", name,
345346
strerror(error));
@@ -368,7 +369,8 @@ open_vconn__(const char *name, const char *default_suffix,
368369
free(datapath_type);
369370

370371
if (strchr(name, ':')) {
371-
run(vconn_open_block(name, 0, vconnp), "connecting to %s", name);
372+
run(vconn_open_block(name, get_allowed_ofp_versions(), vconnp),
373+
"connecting to %s", name);
372374
} else if (!open_vconn_socket(name, vconnp)) {
373375
/* Fall Through. */
374376
} else if (!open_vconn_socket(bridge_path, vconnp)) {
@@ -412,25 +414,27 @@ send_openflow_buffer(struct vconn *vconn, struct ofpbuf *buffer)
412414
}
413415

414416
static void
415-
dump_transaction(const char *vconn_name, struct ofpbuf *request)
417+
dump_transaction(struct vconn *vconn, struct ofpbuf *request)
416418
{
417-
struct vconn *vconn;
418419
struct ofpbuf *reply;
419420

420421
ofpmsg_update_length(request);
421-
open_vconn(vconn_name, &vconn);
422-
run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
422+
run(vconn_transact(vconn, request, &reply), "talking to %s",
423+
vconn_get_name(vconn));
423424
ofp_print(stdout, reply->data, reply->size, verbosity + 1);
424425
ofpbuf_delete(reply);
425-
vconn_close(vconn);
426426
}
427427

428428
static void
429429
dump_trivial_transaction(const char *vconn_name, enum ofpraw raw)
430430
{
431431
struct ofpbuf *request;
432-
request = ofpraw_alloc(raw, OFP10_VERSION, 0);
433-
dump_transaction(vconn_name, request);
432+
struct vconn *vconn;
433+
434+
open_vconn(vconn_name, &vconn);
435+
request = ofpraw_alloc(raw, vconn_get_version(vconn), 0);
436+
dump_transaction(vconn, request);
437+
vconn_close(vconn);
434438
}
435439

436440
static void
@@ -534,7 +538,8 @@ fetch_switch_config(struct vconn *vconn, struct ofp_switch_config *config_)
534538
struct ofpbuf *reply;
535539
enum ofptype type;
536540

537-
request = ofpraw_alloc(OFPRAW_OFPT_GET_CONFIG_REQUEST, OFP10_VERSION, 0);
541+
request = ofpraw_alloc(OFPRAW_OFPT_GET_CONFIG_REQUEST,
542+
vconn_get_version(vconn), 0);
538543
run(vconn_transact(vconn, request, &reply),
539544
"talking to %s", vconn_get_name(vconn));
540545

@@ -553,7 +558,7 @@ set_switch_config(struct vconn *vconn, const struct ofp_switch_config *config)
553558
{
554559
struct ofpbuf *request;
555560

556-
request = ofpraw_alloc(OFPRAW_OFPT_SET_CONFIG, OFP10_VERSION, 0);
561+
request = ofpraw_alloc(OFPRAW_OFPT_SET_CONFIG, vconn_get_version(vconn), 0);
557562
ofpbuf_put(request, config, sizeof *config);
558563

559564
transact_noreply(vconn, request);
@@ -568,15 +573,15 @@ ofctl_show(int argc OVS_UNUSED, char *argv[])
568573
struct ofpbuf *reply;
569574
bool trunc;
570575

571-
request = ofpraw_alloc(OFPRAW_OFPT_FEATURES_REQUEST, OFP10_VERSION, 0);
572576
open_vconn(vconn_name, &vconn);
577+
request = ofpraw_alloc(OFPRAW_OFPT_FEATURES_REQUEST,
578+
vconn_get_version(vconn), 0);
573579
run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
574580

575581
trunc = ofputil_switch_features_ports_trunc(reply);
576582
ofp_print(stdout, reply->data, reply->size, verbosity + 1);
577583

578584
ofpbuf_delete(reply);
579-
vconn_close(vconn);
580585

581586
if (trunc) {
582587
/* The Features Reply may not contain all the ports, so send a
@@ -586,6 +591,7 @@ ofctl_show(int argc OVS_UNUSED, char *argv[])
586591
OFPRAW_OFPST_PORT_DESC_REQUEST);
587592
}
588593
dump_trivial_transaction(vconn_name, OFPRAW_OFPT_GET_CONFIG_REQUEST);
594+
vconn_close(vconn);
589595
}
590596

591597
static void
@@ -615,8 +621,9 @@ fetch_port_by_features(const char *vconn_name,
615621
bool found = false;
616622

617623
/* Fetch the switch's ofp_switch_features. */
618-
request = ofpraw_alloc(OFPRAW_OFPT_FEATURES_REQUEST, OFP10_VERSION, 0);
619624
open_vconn(vconn_name, &vconn);
625+
request = ofpraw_alloc(OFPRAW_OFPT_FEATURES_REQUEST,
626+
vconn_get_version(vconn), 0);
620627
run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
621628
vconn_close(vconn);
622629

@@ -1621,8 +1628,8 @@ ofctl_ping(int argc, char *argv[])
16211628
const struct ofp_header *rpy_hdr;
16221629
enum ofptype type;
16231630

1624-
request = ofpraw_alloc(OFPRAW_OFPT_ECHO_REQUEST, OFP10_VERSION,
1625-
payload);
1631+
request = ofpraw_alloc(OFPRAW_OFPT_ECHO_REQUEST,
1632+
vconn_get_version(vconn), payload);
16261633
random_bytes(ofpbuf_put_uninit(request, payload), payload);
16271634

16281635
xgettimeofday(&start);
@@ -1676,8 +1683,8 @@ ofctl_benchmark(int argc OVS_UNUSED, char *argv[])
16761683
for (i = 0; i < count; i++) {
16771684
struct ofpbuf *request, *reply;
16781685

1679-
request = ofpraw_alloc(OFPRAW_OFPT_ECHO_REQUEST, OFP10_VERSION,
1680-
payload_size);
1686+
request = ofpraw_alloc(OFPRAW_OFPT_ECHO_REQUEST,
1687+
vconn_get_version(vconn), payload_size);
16811688
ofpbuf_put_zeros(request, payload_size);
16821689
run(vconn_transact(vconn, request, &reply), "transact");
16831690
ofpbuf_delete(reply);

0 commit comments

Comments
 (0)