summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
aa31950)
Use an enum for ofp_version in ofp-util and ofp-msg.
This in conjunction with the use of switch() statements
allows the compiler to warn when a new ofp_version isn't handled.
Signed-off-by: Simon Horman <horms@verge.net.au>
Signed-off-by: Ben Pfaff <blp@nicira.com>
/* The most significant bit being set in the version field indicates an
* experimental OpenFlow version.
*/
/* The most significant bit being set in the version field indicates an
* experimental OpenFlow version.
*/
-#define OFP10_VERSION 0x01
-#define OFP11_VERSION 0x02
-#define OFP12_VERSION 0x03
+enum ofp_version {
+ OFP10_VERSION = 0x01,
+ OFP11_VERSION = 0x02,
+ OFP12_VERSION = 0x03,
+};
#define OFP_MAX_TABLE_NAME_LEN 32
#define OFP_MAX_PORT_NAME_LEN 16
#define OFP_MAX_TABLE_NAME_LEN 32
#define OFP_MAX_PORT_NAME_LEN 16
static bool
ofphdrs_is_stat(const struct ofphdrs *hdrs)
{
static bool
ofphdrs_is_stat(const struct ofphdrs *hdrs)
{
- return (hdrs->version == OFP10_VERSION
- ? (hdrs->type == OFPT10_STATS_REQUEST ||
- hdrs->type == OFPT10_STATS_REPLY)
- : (hdrs->type == OFPT11_STATS_REQUEST ||
- hdrs->type == OFPT11_STATS_REPLY));
+ switch ((enum ofp_version) hdrs->version) {
+ case OFP10_VERSION:
+ return (hdrs->type == OFPT10_STATS_REQUEST ||
+ hdrs->type == OFPT10_STATS_REPLY);
+ case OFP11_VERSION:
+ case OFP12_VERSION:
+ return (hdrs->type == OFPT11_STATS_REQUEST ||
+ hdrs->type == OFPT11_STATS_REPLY);
+ }
+
+ return false;
return sizeof(struct nicira_header);
}
return sizeof(struct nicira_header);
}
- if (hdrs->version == OFP10_VERSION) {
+ switch ((enum ofp_version) hdrs->version) {
+ case OFP10_VERSION:
if (hdrs->type == OFPT10_STATS_REQUEST ||
hdrs->type == OFPT10_STATS_REPLY) {
return (hdrs->stat == OFPST_VENDOR
? sizeof(struct nicira10_stats_msg)
: sizeof(struct ofp10_stats_msg));
}
if (hdrs->type == OFPT10_STATS_REQUEST ||
hdrs->type == OFPT10_STATS_REPLY) {
return (hdrs->stat == OFPST_VENDOR
? sizeof(struct nicira10_stats_msg)
: sizeof(struct ofp10_stats_msg));
}
+ break;
+
+ case OFP11_VERSION:
+ case OFP12_VERSION:
if (hdrs->type == OFPT11_STATS_REQUEST ||
hdrs->type == OFPT11_STATS_REPLY) {
return (hdrs->stat == OFPST_VENDOR
? sizeof(struct nicira11_stats_msg)
: sizeof(struct ofp11_stats_msg));
}
if (hdrs->type == OFPT11_STATS_REQUEST ||
hdrs->type == OFPT11_STATS_REPLY) {
return (hdrs->stat == OFPST_VENDOR
? sizeof(struct nicira11_stats_msg)
: sizeof(struct ofp11_stats_msg));
}
}
return sizeof(struct ofp_header);
}
return sizeof(struct ofp_header);
enum ofperr error;
hdrs = instance->hdrs;
enum ofperr error;
hdrs = instance->hdrs;
- if (hdrs.version == OFP10_VERSION) {
+ switch ((enum ofp_version)hdrs.version) {
+ case OFP10_VERSION:
assert(hdrs.type == OFPT10_STATS_REQUEST);
hdrs.type = OFPT10_STATS_REPLY;
assert(hdrs.type == OFPT10_STATS_REQUEST);
hdrs.type = OFPT10_STATS_REPLY;
+ break;
+ case OFP11_VERSION:
+ case OFP12_VERSION:
assert(hdrs.type == OFPT11_STATS_REQUEST);
hdrs.type = OFPT11_STATS_REPLY;
assert(hdrs.type == OFPT11_STATS_REQUEST);
hdrs.type = OFPT11_STATS_REPLY;
+ break;
+ default:
+ NOT_REACHED();
}
error = ofpraw_from_ofphdrs(&reply_raw, &hdrs);
}
error = ofpraw_from_ofphdrs(&reply_raw, &hdrs);
static ovs_be16 *
ofpmp_flags__(const struct ofp_header *oh)
{
static ovs_be16 *
ofpmp_flags__(const struct ofp_header *oh)
{
- return (oh->version == OFP10_VERSION
- ? &((struct ofp10_stats_msg *) oh)->flags
- : &((struct ofp11_stats_msg *) oh)->flags);
+ switch ((enum ofp_version)oh->version) {
+ case OFP10_VERSION:
+ return &((struct ofp10_stats_msg *) oh)->flags;
+ case OFP11_VERSION:
+ case OFP12_VERSION:
+ return &((struct ofp11_stats_msg *) oh)->flags;
+ default:
+ NOT_REACHED();
+ }
}
/* Returns the OFPSF_* flags found in the OpenFlow stats header of 'oh', which
}
/* Returns the OFPSF_* flags found in the OpenFlow stats header of 'oh', which
* 1.0, 0x02 for OpenFlow 1.1). Returns 0 if 'version' is not supported or
* outside the valid range. */
enum ofputil_protocol
* 1.0, 0x02 for OpenFlow 1.1). Returns 0 if 'version' is not supported or
* outside the valid range. */
enum ofputil_protocol
-ofputil_protocol_from_ofp_version(int version)
+ofputil_protocol_from_ofp_version(enum ofp_version version)
- case OFP10_VERSION: return OFPUTIL_P_OF10;
- case OFP12_VERSION: return OFPUTIL_P_OF12;
- default: return 0;
+ case OFP10_VERSION:
+ return OFPUTIL_P_OF10;
+ case OFP12_VERSION:
+ return OFPUTIL_P_OF12;
+ case OFP11_VERSION:
+ default:
+ return 0;
}
}
/* Returns the OpenFlow protocol version number (e.g. OFP10_VERSION,
* OFP11_VERSION or OFP12_VERSION) that corresponds to 'protocol'. */
}
}
/* Returns the OpenFlow protocol version number (e.g. OFP10_VERSION,
* OFP11_VERSION or OFP12_VERSION) that corresponds to 'protocol'. */
ofputil_protocol_to_ofp_version(enum ofputil_protocol protocol)
{
switch (protocol) {
ofputil_protocol_to_ofp_version(enum ofputil_protocol protocol)
{
switch (protocol) {
-ofputil_get_phy_port_size(uint8_t ofp_version)
-{
- return ofp_version == OFP10_VERSION ? sizeof(struct ofp10_phy_port)
- : sizeof(struct ofp11_port);
+ofputil_get_phy_port_size(enum ofp_version ofp_version)
+{
+ switch (ofp_version) {
+ case OFP10_VERSION:
+ return sizeof(struct ofp10_phy_port);
+ case OFP11_VERSION:
+ case OFP12_VERSION:
+ return sizeof(struct ofp11_port);
+ default:
+ NOT_REACHED();
+ }
-ofputil_put_phy_port(uint8_t ofp_version, const struct ofputil_phy_port *pp,
- struct ofpbuf *b)
+ofputil_put_phy_port(enum ofp_version ofp_version,
+ const struct ofputil_phy_port *pp, struct ofpbuf *b)
- if (ofp_version == OFP10_VERSION) {
+ switch (ofp_version) {
+ case OFP10_VERSION: {
struct ofp10_phy_port *opp;
if (b->size + sizeof *opp <= UINT16_MAX) {
opp = ofpbuf_put_uninit(b, sizeof *opp);
ofputil_encode_ofp10_phy_port(pp, opp);
}
struct ofp10_phy_port *opp;
if (b->size + sizeof *opp <= UINT16_MAX) {
opp = ofpbuf_put_uninit(b, sizeof *opp);
ofputil_encode_ofp10_phy_port(pp, opp);
}
+ break;
+ }
+
+ case OFP11_VERSION:
+ case OFP12_VERSION: {
struct ofp11_port *op;
if (b->size + sizeof *op <= UINT16_MAX) {
op = ofpbuf_put_uninit(b, sizeof *op);
ofputil_encode_ofp11_port(pp, op);
}
struct ofp11_port *op;
if (b->size + sizeof *op <= UINT16_MAX) {
op = ofpbuf_put_uninit(b, sizeof *op);
ofputil_encode_ofp11_port(pp, op);
}
+ break;
+ }
+
+ default:
+ NOT_REACHED();
-ofputil_append_port_desc_stats_reply(uint8_t ofp_version,
+ofputil_append_port_desc_stats_reply(enum ofp_version ofp_version,
const struct ofputil_phy_port *pp,
struct list *replies)
{
const struct ofputil_phy_port *pp,
struct list *replies)
{
- if (ofp_version == OFP10_VERSION) {
+ switch (ofp_version) {
+ case OFP10_VERSION: {
struct ofp10_phy_port *opp;
opp = ofpmp_append(replies, sizeof *opp);
ofputil_encode_ofp10_phy_port(pp, opp);
struct ofp10_phy_port *opp;
opp = ofpmp_append(replies, sizeof *opp);
ofputil_encode_ofp10_phy_port(pp, opp);
+ break;
+ }
+
+ case OFP11_VERSION:
+ case OFP12_VERSION: {
struct ofp11_port *op;
op = ofpmp_append(replies, sizeof *op);
ofputil_encode_ofp11_port(pp, op);
struct ofp11_port *op;
op = ofpmp_append(replies, sizeof *op);
ofputil_encode_ofp11_port(pp, op);
+ break;
+ }
+
+ default:
+ NOT_REACHED();
{
struct ofp_switch_features *osf;
struct ofpbuf *b;
{
struct ofp_switch_features *osf;
struct ofpbuf *b;
+ enum ofp_version version;
+ enum ofpraw raw;
version = ofputil_protocol_to_ofp_version(protocol);
version = ofputil_protocol_to_ofp_version(protocol);
- b = ofpraw_alloc_xid(version == OFP10_VERSION
- ? OFPRAW_OFPT10_FEATURES_REPLY
- : OFPRAW_OFPT11_FEATURES_REPLY,
- version, xid, 0);
+ switch (version) {
+ case OFP10_VERSION:
+ raw = OFPRAW_OFPT10_FEATURES_REPLY;
+ break;
+ case OFP11_VERSION:
+ case OFP12_VERSION:
+ raw = OFPRAW_OFPT11_FEATURES_REPLY;
+ break;
+ default:
+ NOT_REACHED();
+ }
+ b = ofpraw_alloc_xid(raw, version, xid, 0);
osf = ofpbuf_put_zeros(b, sizeof *osf);
osf->datapath_id = htonll(features->datapath_id);
osf->n_buffers = htonl(features->n_buffers);
osf->n_tables = features->n_tables;
osf->capabilities = htonl(features->capabilities & OFPC_COMMON);
osf = ofpbuf_put_zeros(b, sizeof *osf);
osf->datapath_id = htonll(features->datapath_id);
osf->n_buffers = htonl(features->n_buffers);
osf->n_tables = features->n_tables;
osf->capabilities = htonl(features->capabilities & OFPC_COMMON);
- if (version == OFP10_VERSION) {
+ switch (version) {
+ case OFP10_VERSION:
if (features->capabilities & OFPUTIL_C_STP) {
osf->capabilities |= htonl(OFPC10_STP);
}
osf->actions = encode_action_bits(features->actions, of10_action_bits);
if (features->capabilities & OFPUTIL_C_STP) {
osf->capabilities |= htonl(OFPC10_STP);
}
osf->actions = encode_action_bits(features->actions, of10_action_bits);
+ break;
+ case OFP11_VERSION:
+ case OFP12_VERSION:
if (features->capabilities & OFPUTIL_C_GROUP_STATS) {
osf->capabilities |= htonl(OFPC11_GROUP_STATS);
}
osf->actions = encode_action_bits(features->actions, of11_action_bits);
if (features->capabilities & OFPUTIL_C_GROUP_STATS) {
osf->capabilities |= htonl(OFPC11_GROUP_STATS);
}
osf->actions = encode_action_bits(features->actions, of11_action_bits);
+ break;
+ default:
+ NOT_REACHED();
{
struct ofp_port_status *ops;
struct ofpbuf *b;
{
struct ofp_port_status *ops;
struct ofpbuf *b;
+ enum ofp_version version;
+ enum ofpraw raw;
version = ofputil_protocol_to_ofp_version(protocol);
version = ofputil_protocol_to_ofp_version(protocol);
- b = ofpraw_alloc_xid(version == OFP10_VERSION
- ? OFPRAW_OFPT10_PORT_STATUS
- : OFPRAW_OFPT11_PORT_STATUS,
- version, htonl(0), 0);
+ switch (version) {
+ case OFP10_VERSION:
+ raw = OFPRAW_OFPT10_PORT_STATUS;
+ break;
+
+ case OFP11_VERSION:
+ case OFP12_VERSION:
+ raw = OFPRAW_OFPT11_PORT_STATUS;
+ break;
+
+ default:
+ NOT_REACHED();
+ }
+
+ b = ofpraw_alloc_xid(raw, version, htonl(0), 0);
ops = ofpbuf_put_zeros(b, sizeof *ops);
ops->reason = ps->reason;
ofputil_put_phy_port(version, &ps->desc, b);
ops = ofpbuf_put_zeros(b, sizeof *ops);
ops->reason = ps->reason;
ofputil_put_phy_port(version, &ps->desc, b);
ofputil_encode_port_mod(const struct ofputil_port_mod *pm,
enum ofputil_protocol protocol)
{
ofputil_encode_port_mod(const struct ofputil_port_mod *pm,
enum ofputil_protocol protocol)
{
- uint8_t ofp_version = ofputil_protocol_to_ofp_version(protocol);
+ enum ofp_version ofp_version = ofputil_protocol_to_ofp_version(protocol);
- if (ofp_version == OFP10_VERSION) {
+ switch (ofp_version) {
+ case OFP10_VERSION: {
struct ofp10_port_mod *opm;
b = ofpraw_alloc(OFPRAW_OFPT10_PORT_MOD, ofp_version, 0);
struct ofp10_port_mod *opm;
b = ofpraw_alloc(OFPRAW_OFPT10_PORT_MOD, ofp_version, 0);
opm->config = htonl(pm->config & OFPPC10_ALL);
opm->mask = htonl(pm->mask & OFPPC10_ALL);
opm->advertise = netdev_port_features_to_ofp10(pm->advertise);
opm->config = htonl(pm->config & OFPPC10_ALL);
opm->mask = htonl(pm->mask & OFPPC10_ALL);
opm->advertise = netdev_port_features_to_ofp10(pm->advertise);
- } else if (ofp_version == OFP11_VERSION) {
+ break;
+ }
+
+ case OFP11_VERSION: {
struct ofp11_port_mod *opm;
b = ofpraw_alloc(OFPRAW_OFPT11_PORT_MOD, ofp_version, 0);
struct ofp11_port_mod *opm;
b = ofpraw_alloc(OFPRAW_OFPT11_PORT_MOD, ofp_version, 0);
opm->config = htonl(pm->config & OFPPC11_ALL);
opm->mask = htonl(pm->mask & OFPPC11_ALL);
opm->advertise = netdev_port_features_to_ofp11(pm->advertise);
opm->config = htonl(pm->config & OFPPC11_ALL);
opm->mask = htonl(pm->mask & OFPPC11_ALL);
opm->advertise = netdev_port_features_to_ofp11(pm->advertise);
+ break;
+ }
+
+ case OFP12_VERSION:
+ default:
* port and returns 0. If no ports remain to be decoded, returns EOF.
* On an error, returns a positive OFPERR_* value. */
int
* port and returns 0. If no ports remain to be decoded, returns EOF.
* On an error, returns a positive OFPERR_* value. */
int
-ofputil_pull_phy_port(uint8_t ofp_version, struct ofpbuf *b,
+ofputil_pull_phy_port(enum ofp_version ofp_version, struct ofpbuf *b,
struct ofputil_phy_port *pp)
{
struct ofputil_phy_port *pp)
{
- if (ofp_version == OFP10_VERSION) {
+ switch (ofp_version) {
+ case OFP10_VERSION: {
const struct ofp10_phy_port *opp = ofpbuf_try_pull(b, sizeof *opp);
return opp ? ofputil_decode_ofp10_phy_port(pp, opp) : EOF;
const struct ofp10_phy_port *opp = ofpbuf_try_pull(b, sizeof *opp);
return opp ? ofputil_decode_ofp10_phy_port(pp, opp) : EOF;
+ }
+ case OFP11_VERSION:
+ case OFP12_VERSION: {
const struct ofp11_port *op = ofpbuf_try_pull(b, sizeof *op);
return op ? ofputil_decode_ofp11_port(pp, op) : EOF;
}
const struct ofp11_port *op = ofpbuf_try_pull(b, sizeof *op);
return op ? ofputil_decode_ofp11_port(pp, op) : EOF;
}
+ default:
+ NOT_REACHED();
+ }
}
/* Given a buffer 'b' that contains an array of OpenFlow ports of type
}
/* Given a buffer 'b' that contains an array of OpenFlow ports of type
extern enum ofputil_protocol ofputil_flow_dump_protocols[];
extern size_t ofputil_n_flow_dump_protocols;
extern enum ofputil_protocol ofputil_flow_dump_protocols[];
extern size_t ofputil_n_flow_dump_protocols;
-enum ofputil_protocol ofputil_protocol_from_ofp_version(int version);
-uint8_t ofputil_protocol_to_ofp_version(enum ofputil_protocol);
+enum ofputil_protocol
+ofputil_protocol_from_ofp_version(enum ofp_version version);
+enum ofp_version ofputil_protocol_to_ofp_version(enum ofputil_protocol);
bool ofputil_protocol_is_valid(enum ofputil_protocol);
enum ofputil_protocol ofputil_protocol_set_tid(enum ofputil_protocol,
bool ofputil_protocol_is_valid(enum ofputil_protocol);
enum ofputil_protocol ofputil_protocol_set_tid(enum ofputil_protocol,
bool ofputil_switch_features_ports_trunc(struct ofpbuf *b);
/* phy_port helper functions. */
bool ofputil_switch_features_ports_trunc(struct ofpbuf *b);
/* phy_port helper functions. */
-int ofputil_pull_phy_port(uint8_t ofp_version, struct ofpbuf *,
+int ofputil_pull_phy_port(enum ofp_version ofp_version, struct ofpbuf *,
struct ofputil_phy_port *);
size_t ofputil_count_phy_ports(uint8_t ofp_version, struct ofpbuf *);
struct ofputil_phy_port *);
size_t ofputil_count_phy_ports(uint8_t ofp_version, struct ofpbuf *);
struct ofpbuf *ofputil_encode_flow_monitor_cancel(uint32_t id);
/* Encoding OpenFlow stats messages. */
struct ofpbuf *ofputil_encode_flow_monitor_cancel(uint32_t id);
/* Encoding OpenFlow stats messages. */
-void ofputil_append_port_desc_stats_reply(uint8_t ofp_version,
+void ofputil_append_port_desc_stats_reply(enum ofp_version ofp_version,
const struct ofputil_phy_port *pp,
struct list *replies);
const struct ofputil_phy_port *pp,
struct list *replies);
#include <assert.h>
#include "vconn.h"
#include <assert.h>
#include "vconn.h"
+#include "openflow/openflow-common.h"
\f
/* Active virtual connection to an OpenFlow device. */
\f
/* Active virtual connection to an OpenFlow device. */
struct vconn_class *class;
int state;
int error;
struct vconn_class *class;
int state;
int error;
- int min_version;
- int version;
+ enum ofp_version min_version;
+ enum ofp_version version;
ovs_be32 remote_ip;
ovs_be16 remote_port;
ovs_be32 local_ip;
ovs_be32 remote_ip;
ovs_be16 remote_port;
ovs_be32 local_ip;
-vconn_open_block(const char *name, int min_version, struct vconn **vconnp)
+vconn_open_block(const char *name, enum ofp_version min_version,
+ struct vconn **vconnp)
{
struct vconn *vconn;
int error;
{
struct vconn *vconn;
int error;
*
* A vconn that has successfully connected (that is, vconn_connect() or
* vconn_send() or vconn_recv() has returned 0) always negotiated a version. */
*
* A vconn that has successfully connected (that is, vconn_connect() or
* vconn_send() or vconn_recv() has returned 0) always negotiated a version. */
vconn_get_version(const struct vconn *vconn)
{
return vconn->version;
vconn_get_version(const struct vconn *vconn)
{
return vconn->version;
ovs_be16 vconn_get_remote_port(const struct vconn *);
ovs_be32 vconn_get_local_ip(const struct vconn *);
ovs_be16 vconn_get_local_port(const struct vconn *);
ovs_be16 vconn_get_remote_port(const struct vconn *);
ovs_be32 vconn_get_local_ip(const struct vconn *);
ovs_be16 vconn_get_local_port(const struct vconn *);
-int vconn_get_version(const struct vconn *);
+enum ofp_version vconn_get_version(const struct vconn *);
int vconn_connect(struct vconn *);
int vconn_recv(struct vconn *, struct ofpbuf **);
int vconn_send(struct vconn *, struct ofpbuf *);
int vconn_connect(struct vconn *);
int vconn_recv(struct vconn *, struct ofpbuf **);
int vconn_send(struct vconn *, struct ofpbuf *);
void vconn_run(struct vconn *);
void vconn_run_wait(struct vconn *);
void vconn_run(struct vconn *);
void vconn_run_wait(struct vconn *);
-int vconn_open_block(const char *name, int min_version, struct vconn **);
+int vconn_open_block(const char *name, enum ofp_version min_version,
+ struct vconn **);
int vconn_send_block(struct vconn *, struct ofpbuf *);
int vconn_recv_block(struct vconn *, struct ofpbuf **);
int vconn_send_block(struct vconn *, struct ofpbuf *);
int vconn_recv_block(struct vconn *, struct ofpbuf **);
const struct ofp_header *request)
{
struct ofproto *p = ofconn_get_ofproto(ofconn);
const struct ofp_header *request)
{
struct ofproto *p = ofconn_get_ofproto(ofconn);
+ enum ofp_version version;
struct ofport *port;
struct list replies;
ofpmp_init(&replies, request);
struct ofport *port;
struct list replies;
ofpmp_init(&replies, request);
+ version = ofputil_protocol_to_ofp_version(ofconn_get_protocol(ofconn));
HMAP_FOR_EACH (port, hmap_node, &p->ports) {
HMAP_FOR_EACH (port, hmap_node, &p->ports) {
- ofputil_append_port_desc_stats_reply(ofconn_get_protocol(ofconn),
- &port->pp, &replies);
+ ofputil_append_port_desc_stats_reply(version, &port->pp, &replies);
}
ofconn_send_replies(ofconn, &replies);
}
ofconn_send_replies(ofconn, &replies);