diff options
author | Ben Pfaff <blp@nicira.com> | 2012-02-10 13:30:23 -0800 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2012-03-07 13:59:02 -0800 |
commit | 27527aa09ce456796eeea728cef9528aa5612b70 (patch) | |
tree | fe9f12d78b25a5520a25b6cec7e3dd5b2727ea20 /lib/vconn.c | |
parent | 032f3fbd856864cdcbdf505d404e826999b8a2ae (diff) |
Introduce ofputil_protocol, to abstract the protocol in use on a connection.
Open vSwitch already handles a few different protocol variations, but it
does so in a nonuniform manner:
- OpenFlow 1.0 and NXM flow formats are distinguished using the NXFF_*
constant values from nicira-ext.h.
- The "flow_mod_table_id" feature setting is maintained in ofproto as
part of an OpenFlow connection's (ofconn's) state.
There's no way to easily communicate this state among components. It's
not much of a problem yet, but as more protocol support is added it seems
better to have an abstract, uniform way to represent protocol versions and
variants. This commit implements that by introducing a new type
"enum ofputil_protocol". Each ofputil_protocol value represents a variant
of a protocol version. Each value is a separate bit, so a single enum
can also represent a set of protocols, which is often useful as well.
Reviewed-by: Simon Horman <horms@verge.net.au>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/vconn.c')
-rw-r--r-- | lib/vconn.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/vconn.c b/lib/vconn.c index 5da50262..93d6388c 100644 --- a/lib/vconn.c +++ b/lib/vconn.c @@ -353,6 +353,17 @@ vconn_get_local_port(const struct vconn *vconn) return vconn->local_port; } +/* Returns the OpenFlow version negotiated with the peer, or -1 if version + * negotiation is not yet complete. + * + * A vconn that has successfully connected (that is, vconn_connect() or + * vconn_send() or vconn_recv() has returned 0) always negotiated a version. */ +int +vconn_get_version(const struct vconn *vconn) +{ + return vconn->version; +} + static void vcs_connecting(struct vconn *vconn) { @@ -471,7 +482,7 @@ vconn_connect(struct vconn *vconn) { enum vconn_state last_state; - assert(vconn->min_version >= 0); + assert(vconn->min_version > 0); do { last_state = vconn->state; switch (vconn->state) { @@ -538,14 +549,14 @@ do_recv(struct vconn *vconn, struct ofpbuf **msgp) } oh = ofpbuf_at_assert(*msgp, 0, sizeof *oh); - if (oh->version != vconn->version + if ((oh->version != vconn->version || oh->version == 0) && oh->type != OFPT_HELLO && oh->type != OFPT_ERROR && oh->type != OFPT_ECHO_REQUEST && oh->type != OFPT_ECHO_REPLY && oh->type != OFPT_VENDOR) { - if (vconn->version < 0) { + if (vconn->version == 0) { VLOG_ERR_RL(&bad_ofmsg_rl, "%s: received OpenFlow message type %"PRIu8" " "before version negotiation complete", @@ -995,8 +1006,8 @@ vconn_init(struct vconn *vconn, struct vconn_class *class, int connect_status, : !connect_status ? VCS_SEND_HELLO : VCS_DISCONNECTED); vconn->error = connect_status; - vconn->version = -1; - vconn->min_version = -1; + vconn->version = 0; + vconn->min_version = 0; vconn->remote_ip = 0; vconn->remote_port = 0; vconn->local_ip = 0; |