[ovs-dev] [PATCH 08/48] ofp-util: Make make_openflow_xid() aware of different OpenFlow versions.
Simon Horman
horms at verge.net.au
Mon Jun 25 06:44:11 UTC 2012
Signed-off-by: Simon Horman <horms at verge.net.au>
---
v4
* Initial post
---
lib/ofp-errors.c | 5 +++--
lib/ofp-util.c | 16 ++++++++++------
lib/ofp-util.h | 2 +-
ofproto/ofproto.c | 9 +++++++--
4 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/lib/ofp-errors.c b/lib/ofp-errors.c
index e1349b0..5d2fb47 100644
--- a/lib/ofp-errors.c
+++ b/lib/ofp-errors.c
@@ -176,14 +176,15 @@ ofperr_encode_msg__(enum ofperr error, const struct ofperr_domain *domain,
pair = ofperr_get_pair__(error, domain);
if (!ofperr_is_nx_extension(error)) {
- oem = make_openflow_xid(data_len + sizeof *oem, OFPT_ERROR, xid, &buf);
+ oem = make_openflow_xid(data_len + sizeof *oem, OFP10_VERSION,
+ OFPT_ERROR, xid, &buf);
oem->type = htons(pair->type);
oem->code = htons(pair->code);
} else {
struct nx_vendor_error *nve;
oem = make_openflow_xid(data_len + sizeof *oem + sizeof *nve,
- OFPT_ERROR, xid, &buf);
+ OFP10_VERSION, OFPT_ERROR, xid, &buf);
oem->type = htons(NXET_VENDOR);
oem->code = htons(NXVC_VENDOR_ERROR);
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index c09f5ea..af053d3 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -2221,14 +2221,16 @@ ofputil_encode_flow_removed(const struct ofputil_flow_removed *fr,
enum ofputil_protocol protocol)
{
struct ofpbuf *msg;
+ uint8_t ofp_version = ofputil_protocol_to_ofp_version(protocol);
switch (protocol) {
+
case OFPUTIL_P_OF10:
case OFPUTIL_P_OF10_TID: {
struct ofp_flow_removed *ofr;
- ofr = make_openflow_xid(sizeof *ofr, OFPT_FLOW_REMOVED, htonl(0),
- &msg);
+ ofr = make_openflow_xid(sizeof *ofr, ofp_version,
+ OFPT_FLOW_REMOVED, htonl(0), &msg);
ofputil_cls_rule_to_ofp10_match(&fr->rule, &ofr->match);
ofr->cookie = fr->cookie;
ofr->priority = htons(fr->rule.priority);
@@ -2858,7 +2860,9 @@ ofputil_encode_switch_features(const struct ofputil_switch_features *features,
struct ofp_switch_features *osf;
struct ofpbuf *b;
- osf = make_openflow_xid(sizeof *osf, OFPT_FEATURES_REPLY, xid, &b);
+ osf = make_openflow_xid(sizeof *osf,
+ ofputil_protocol_to_ofp_version(protocol),
+ OFPT_FEATURES_REPLY, xid, &b);
osf->header.version = ofputil_protocol_to_ofp_version(protocol);
osf->datapath_id = htonll(features->datapath_id);
osf->n_buffers = htonl(features->n_buffers);
@@ -3100,11 +3104,11 @@ make_nxmsg(size_t openflow_len, uint32_t subtype, struct ofpbuf **bufferp)
*
* Returns the header. */
void *
-make_openflow_xid(size_t openflow_len, uint8_t type, ovs_be32 xid,
- struct ofpbuf **bufferp)
+make_openflow_xid(size_t openflow_len, uint8_t version, uint8_t type,
+ ovs_be32 xid, struct ofpbuf **bufferp)
{
*bufferp = ofpbuf_new(openflow_len);
- return put_openflow_xid(openflow_len, OFP10_VERSION, type, xid, *bufferp);
+ return put_openflow_xid(openflow_len, version, type, xid, *bufferp);
}
/* Similar to make_openflow_xid() but creates a Nicira vendor extension message
diff --git a/lib/ofp-util.h b/lib/ofp-util.h
index 80b2065..ef798eb 100644
--- a/lib/ofp-util.h
+++ b/lib/ofp-util.h
@@ -521,7 +521,7 @@ void *make_openflow(size_t openflow_len, uint8_t version, uint8_t type,
struct ofpbuf **);
void *make_nxmsg(size_t openflow_len, uint32_t subtype, struct ofpbuf **);
-void *make_openflow_xid(size_t openflow_len, uint8_t type,
+void *make_openflow_xid(size_t openflow_len, uint8_t version, uint8_t type,
ovs_be32 xid, struct ofpbuf **);
void *make_nxmsg_xid(size_t openflow_len, uint32_t subtype, ovs_be32 xid,
struct ofpbuf **);
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 9ce9159..745266e 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -1935,9 +1935,12 @@ handle_get_config_request(struct ofconn *ofconn, const struct ofp_header *oh)
struct ofp_switch_config *osc;
enum ofp_config_flags flags;
struct ofpbuf *buf;
+ enum ofputil_protocol protocol = ofconn_get_protocol(ofconn);
/* Send reply. */
- osc = make_openflow_xid(sizeof *osc, OFPT_GET_CONFIG_REPLY, oh->xid, &buf);
+ osc = make_openflow_xid(sizeof *osc,
+ ofputil_protocol_to_ofp_version(protocol),
+ OFPT_GET_CONFIG_REPLY, oh->xid, &buf);
flags = ofproto->frag_handling;
if (ofconn_get_invalid_ttl_to_controller(ofconn)) {
flags |= OFPC_INVALID_TTL_TO_CONTROLLER;
@@ -3273,12 +3276,14 @@ static enum ofperr
handle_barrier_request(struct ofconn *ofconn, const struct ofp_header *oh)
{
struct ofpbuf *buf;
+ enum ofputil_protocol protocol = ofconn_get_protocol(ofconn);
if (ofconn_has_pending_opgroups(ofconn)) {
return OFPROTO_POSTPONE;
}
- make_openflow_xid(sizeof *oh, OFPT10_BARRIER_REPLY, oh->xid, &buf);
+ make_openflow_xid(sizeof *oh, ofputil_protocol_to_ofp_version(protocol),
+ OFPT10_BARRIER_REPLY, oh->xid, &buf);
ofconn_send_reply(ofconn, buf);
return 0;
}
--
1.7.10.2.484.gcd07cc5
More information about the dev
mailing list