[ovs-dev] [PATCH 12/63] ofp-util: Make ofputil_make_stats_request() aware of different OpenFlow versions
Simon Horman
horms at verge.net.au
Wed Jun 27 08:19:48 UTC 2012
Signed-off-by: Simon Horman <horms at verge.net.au>
---
v5
* Manual rebase
v4
* Initial post
---
lib/ofp-util.c | 29 ++++++++++++++++++++++++-----
lib/ofp-util.h | 5 +++--
utilities/ovs-ofctl.c | 12 ++++++++----
3 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index 6613015..69fa0e2 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -1862,6 +1862,7 @@ ofputil_encode_flow_stats_request(const struct ofputil_flow_stats_request *fsr,
enum ofputil_protocol protocol)
{
struct ofpbuf *msg;
+ uint8_t ofp_version = ofputil_protocol_to_ofp_version(protocol);
switch (protocol) {
case OFPUTIL_P_OF10:
@@ -1870,7 +1871,8 @@ ofputil_encode_flow_stats_request(const struct ofputil_flow_stats_request *fsr,
int type;
type = fsr->aggregate ? OFPST_AGGREGATE : OFPST_FLOW;
- ofsr = ofputil_make_stats_request(sizeof *ofsr, type, 0, &msg);
+ ofsr = ofputil_make_stats_request(sizeof *ofsr, ofp_version,
+ type, 0, &msg);
ofputil_cls_rule_to_ofp10_match(&fsr->match, &ofsr->match);
ofsr->table_id = fsr->table_id;
ofsr->out_port = htons(fsr->out_port);
@@ -1884,7 +1886,8 @@ ofputil_encode_flow_stats_request(const struct ofputil_flow_stats_request *fsr,
int subtype;
subtype = fsr->aggregate ? NXST_AGGREGATE : NXST_FLOW;
- ofputil_make_stats_request(sizeof *nfsr, OFPST_VENDOR, subtype, &msg);
+ ofputil_make_stats_request(sizeof *nfsr, ofp_version,
+ OFPST_VENDOR, subtype, &msg);
match_len = nx_put_match(msg, false, &fsr->match,
fsr->cookie, fsr->cookie_mask);
@@ -3235,8 +3238,9 @@ put_stats__(ovs_be32 xid, uint8_t ofp_version, uint8_t ofp_type,
* Appends 'body_len' bytes of zeroes to the reply as the body and returns the
* first byte of the body. */
void *
-ofputil_make_stats_request(size_t body_len, uint16_t ofpst_type,
- uint32_t nxst_subtype, struct ofpbuf **bufferp)
+ofputil_make_stats_request(size_t body_len, uint8_t ofp_version,
+ uint16_t ofpst_type, uint32_t nxst_subtype,
+ struct ofpbuf **bufferp)
{
enum {
HEADER_LEN = MAX(MAX(sizeof(struct ofp10_stats_msg),
@@ -3244,9 +3248,24 @@ ofputil_make_stats_request(size_t body_len, uint16_t ofpst_type,
sizeof(struct nicira10_stats_msg))
};
struct ofpbuf *msg;
+ uint8_t ofp_type;
+
+ switch (ofp_version) {
+ case OFP12_VERSION:
+ case OFP11_VERSION:
+ ofp_type = OFPT11_STATS_REQUEST;
+ break;
+
+ case OFP10_VERSION:
+ ofp_type = OFPT10_STATS_REQUEST;
+ break;
+
+ default:
+ NOT_REACHED();
+ }
msg = *bufferp = ofpbuf_new(HEADER_LEN + body_len);
- put_stats__(alloc_xid(), OFP10_VERSION, OFPT10_STATS_REQUEST,
+ put_stats__(alloc_xid(), ofp_version, ofp_type,
htons(ofpst_type), htonl(nxst_subtype), msg);
return ofpbuf_put_zeros(msg, body_len);
diff --git a/lib/ofp-util.h b/lib/ofp-util.h
index 99c2f5e..b171cf0 100644
--- a/lib/ofp-util.h
+++ b/lib/ofp-util.h
@@ -538,8 +538,9 @@ void *put_nxmsg_xid(size_t openflow_len, uint32_t subtype, ovs_be32 xid,
void update_openflow_length(struct ofpbuf *);
/* Encoding OpenFlow stats messages. */
-void *ofputil_make_stats_request(size_t body_len, uint16_t type,
- uint32_t subtype, struct ofpbuf **);
+void *ofputil_make_stats_request(size_t body_len, uint8_t ofp_version,
+ uint16_t type, uint32_t subtype,
+ struct ofpbuf **);
void *ofputil_make_stats_reply(size_t body_len,
const struct ofp_header *request,
struct ofpbuf **);
diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index 58f1928..472e42c 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -403,7 +403,8 @@ dump_trivial_stats_transaction(const char *vconn_name, uint8_t stats_type)
struct vconn *vconn;
open_vconn(vconn_name, &vconn);
- ofputil_make_stats_request(0, stats_type, 0, &request);
+ ofputil_make_stats_request(0, vconn_get_version(vconn),
+ stats_type, 0, &request);
dump_stats_transaction(vconn, request);
vconn_close(vconn);
}
@@ -595,7 +596,8 @@ fetch_port_by_stats(const char *vconn_name,
open_vconn(vconn_name, &vconn);
- ofputil_make_stats_request(0, OFPST_PORT_DESC, 0, &request);
+ ofputil_make_stats_request(0, vconn_get_version(vconn),
+ OFPST_PORT_DESC, 0, &request);
send_xid = ((struct ofp_header *) request->data)->xid;
send_openflow_buffer(vconn, request);
@@ -790,7 +792,8 @@ do_queue_stats(int argc, char *argv[])
open_vconn(argv[1], &vconn);
- req = ofputil_make_stats_request(sizeof *req, OFPST_QUEUE, 0, &request);
+ req = ofputil_make_stats_request(sizeof *req, OFP10_VERSION,
+ OFPST_QUEUE, 0, &request);
if (argc > 2 && argv[2][0] && strcasecmp(argv[2], "all")) {
req->port_no = htons(str_to_port_no(argv[1], argv[2]));
@@ -1205,7 +1208,8 @@ do_dump_ports(int argc, char *argv[])
open_vconn(argv[1], &vconn);
- req = ofputil_make_stats_request(sizeof *req, OFPST_PORT, 0, &request);
+ req = ofputil_make_stats_request(sizeof *req, OFP10_VERSION,
+ OFPST_PORT, 0, &request);
port = argc > 2 ? str_to_port_no(argv[1], argv[2]) : OFPP_NONE;
req->port_no = htons(port);
dump_stats_transaction(vconn, request);
--
1.7.10.2.484.gcd07cc5
More information about the dev
mailing list