Skip to content

Commit

Permalink
vswitchd: Configuration of allowed OpenFlow versions
Browse files Browse the repository at this point in the history
Versions may be configured using the protocols column of
the bridge table. The protocols column is a set which accepts zero
or more of the values: 'OpenFlow10' and 'OpenFlow12'.

If the protocols column is empty, then OpenFlow10 is used.
This default is consistent with the behaviour of ovs-vswtichd
prior to this patch.

Signed-off-by: Simon Horman <[email protected]>
[[email protected] adjusted comments and documentation]
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
horms authored and blp committed Nov 19, 2012
1 parent eb12aa8 commit 7beaa08
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 6 deletions.
26 changes: 23 additions & 3 deletions lib/ofp-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ ofputil_protocols_from_string(const char *s)
return protocols;
}

static enum ofp_version
static int
ofputil_version_from_string(const char *s)
{
if (!strcasecmp(s, "OpenFlow10")) {
Expand All @@ -859,7 +859,7 @@ ofputil_version_from_string(const char *s)
if (!strcasecmp(s, "OpenFlow12")) {
return OFP12_VERSION;
}
VLOG_FATAL("Unknown OpenFlow version: \"%s\"", s);
return 0;
}

static bool
Expand All @@ -876,7 +876,7 @@ ofputil_versions_from_string(const char *s)

while (s[i]) {
size_t j;
enum ofp_version version;
int version;
char *key;

if (is_delimiter(s[i])) {
Expand All @@ -889,6 +889,9 @@ ofputil_versions_from_string(const char *s)
}
key = xmemdup0(s + i, j);
version = ofputil_version_from_string(key);
if (!version) {
VLOG_FATAL("Unknown OpenFlow version: \"%s\"", key);
}
free(key);
bitmap |= 1u << version;
i += j;
Expand All @@ -897,6 +900,23 @@ ofputil_versions_from_string(const char *s)
return bitmap;
}

uint32_t
ofputil_versions_from_strings(char ** const s, size_t count)
{
uint32_t bitmap = 0;

while (count--) {
int version = ofputil_version_from_string(s[count]);
if (!version) {
VLOG_WARN("Unknown OpenFlow version: \"%s\"", s[count]);
} else {
bitmap |= 1u << version;
}
}

return bitmap;
}

const char *
ofputil_version_to_string(enum ofp_version ofp_version)
{
Expand Down
1 change: 1 addition & 0 deletions lib/ofp-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ enum ofputil_protocol ofputil_protocols_from_string(const char *s);

const char *ofputil_version_to_string(enum ofp_version ofp_version);
uint32_t ofputil_versions_from_string(const char *s);
uint32_t ofputil_versions_from_strings(char ** const s, size_t count);

bool ofputil_decode_hello(const struct ofp_header *,
uint32_t *allowed_versions);
Expand Down
2 changes: 2 additions & 0 deletions tests/ovs-vsctl.at
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ name : "br0"
netflow : []
other_config : {}
ports : []
protocols : []
sflow : []
status : {}
stp_enable : false
Expand Down Expand Up @@ -1042,6 +1043,7 @@ name : "br0"
netflow : []
other_config : {}
ports : []
protocols : []
sflow : []
status : {}
stp_enable : false
Expand Down
16 changes: 15 additions & 1 deletion vswitchd/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "meta-flow.h"
#include "netdev.h"
#include "ofp-print.h"
#include "ofp-util.h"
#include "ofpbuf.h"
#include "ofproto/ofproto.h"
#include "poll-loop.h"
Expand Down Expand Up @@ -814,6 +815,18 @@ bridge_configure_datapath_id(struct bridge *br)
free(dpid_string);
}

/* Returns a bitmap of "enum ofputil_protocol"s that are allowed for use with
* 'br'. */
static uint32_t
bridge_get_allowed_versions(struct bridge *br)
{
if (!br->cfg->n_protocols)
return 0;

return ofputil_versions_from_strings(br->cfg->protocols,
br->cfg->n_protocols);
}

/* Set NetFlow configuration on 'br'. */
static void
bridge_configure_netflow(struct bridge *br)
Expand Down Expand Up @@ -2800,7 +2813,8 @@ bridge_configure_remotes(struct bridge *br,
n_ocs++;
}

ofproto_set_controllers(br->ofproto, ocs, n_ocs, 0);
ofproto_set_controllers(br->ofproto, ocs, n_ocs,
bridge_get_allowed_versions(br));
free(ocs[0].target); /* From bridge_ofproto_controller_for_mgmt(). */
free(ocs);

Expand Down
8 changes: 6 additions & 2 deletions vswitchd/vswitch.ovsschema
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{"name": "Open_vSwitch",
"version": "6.11.0",
"cksum": "3699219253 17163",
"version": "6.11.1",
"cksum": "2684374538 17324",
"tables": {
"Open_vSwitch": {
"columns": {
Expand Down Expand Up @@ -74,6 +74,10 @@
"type": {"key": {"type": "uuid",
"refTable": "Controller"},
"min": 0, "max": "unlimited"}},
"protocols": {
"type": {"key": {"type": "string",
"enum": ["set", ["OpenFlow10", "OpenFlow12"]]},
"min": 0, "max": "unlimited"}},
"fail_mode": {
"type": {"key": {"type": "string",
"enum": ["set", ["standalone", "secure"]]},
Expand Down
6 changes: 6 additions & 0 deletions vswitchd/vswitch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@
QoS configured, or if the port does not have a queue with the specified
ID, the default queue is used instead.
</column>

<column name="protocols">
List of OpenFlow protocols that may be used when negotiating a
connection with a controller. A default value of
<code>OpenFlow10</code> will be used if this column is empty.
</column>
</group>

<group title="Spanning Tree Configuration">
Expand Down

0 comments on commit 7beaa08

Please sign in to comment.