Signed-off-by: Simon Horman <ho...@verge.net.au> ---
v4 * Initial post --- lib/ofp-util.c | 29 ++++++++++++++++++++++++----- lib/ofp-util.h | 5 +++-- utilities/ovs-ofctl.c | 27 +++++++++++++++++---------- 3 files changed, 44 insertions(+), 17 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 6d2710e..3cbacda 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -399,11 +399,12 @@ dump_stats_transaction(const char *vconn_name, struct ofpbuf *request) } static void -dump_trivial_stats_transaction(const char *vconn_name, uint8_t stats_type) +dump_trivial_stats_transaction(const char *vconn_name, uint8_t stats_type, + uint8_t ofp_version) { struct ofpbuf *request; - ofputil_make_stats_request(0, stats_type, 0, &request); + ofputil_make_stats_request(0, ofp_version, stats_type, 0, &request); dump_stats_transaction(vconn_name, request); } @@ -499,6 +500,7 @@ do_show(int argc OVS_UNUSED, char *argv[]) make_openflow(sizeof(struct ofp_header), vconn_get_version(vconn), OFPT_FEATURES_REQUEST, &request); open_vconn(vconn_name, &vconn); + run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name); trunc = ofputil_switch_features_ports_trunc(reply); @@ -512,7 +514,8 @@ do_show(int argc OVS_UNUSED, char *argv[]) /* The Features Reply may not contain all the ports, so send a * Port Description stats request, which doesn't have size * constraints. */ - dump_trivial_stats_transaction(vconn_name, OFPST_PORT_DESC); + dump_trivial_stats_transaction(vconn_name, OFPST_PORT_DESC, + ofp_version); } dump_trivial_transaction(vconn_name, ofp_version, OFPT_GET_CONFIG_REQUEST); } @@ -520,13 +523,13 @@ do_show(int argc OVS_UNUSED, char *argv[]) static void do_dump_desc(int argc OVS_UNUSED, char *argv[]) { - dump_trivial_stats_transaction(argv[1], OFPST_DESC); + dump_trivial_stats_transaction(argv[1], OFPST_DESC, OFP10_VERSION); } static void do_dump_tables(int argc OVS_UNUSED, char *argv[]) { - dump_trivial_stats_transaction(argv[1], OFPST_TABLE); + dump_trivial_stats_transaction(argv[1], OFPST_TABLE, OFP10_VERSION); } static bool @@ -593,10 +596,12 @@ fetch_port_by_stats(const char *vconn_name, bool done = false; bool found = false; - ofputil_make_stats_request(0, OFPST_PORT_DESC, 0, &request); + open_vconn(vconn_name, &vconn); + + ofputil_make_stats_request(0, vconn_get_version(vconn), + OFPST_PORT_DESC, 0, &request); send_xid = ((struct ofp_header *) request->data)->xid; - open_vconn(vconn_name, &vconn); send_openflow_buffer(vconn, request); while (!done) { ovs_be32 recv_xid; @@ -786,7 +791,8 @@ do_queue_stats(int argc, char *argv[]) struct ofp10_queue_stats_request *req; struct ofpbuf *request; - 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])); @@ -1197,7 +1203,8 @@ do_dump_ports(int argc, char *argv[]) struct ofpbuf *request; uint16_t port; - 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(argv[1], request); @@ -1206,7 +1213,7 @@ do_dump_ports(int argc, char *argv[]) static void do_dump_ports_desc(int argc OVS_UNUSED, char *argv[]) { - dump_trivial_stats_transaction(argv[1], OFPST_PORT_DESC); + dump_trivial_stats_transaction(argv[1], OFPST_PORT_DESC, OFP10_VERSION); } static void -- 1.7.10.2.484.gcd07cc5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev