[ovs-dev] [PATCH 05/12] ovs-ofpctl: Enable queue-stats for Open Flow 1.1 & 1.2
Simon Horman
horms at verge.net.au
Mon Sep 17 00:26:52 UTC 2012
Signed-off-by: Simon Horman <horms at verge.net.au>
---
v13
* Move encoder into helper functions
v12
* No change
v11
* No change
v10
* Manual rebase
* Make use of enum ofp_version
v9
* Omitted
v8
* Omitted
v7
* Omitted
v6
* The queue_id variable in do_dump_aggregate() should be uint32_t not
uint16_t.
v5
* Initial Post
---
lib/ofp-util.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++-
lib/ofp-util.h | 3 +++
utilities/ovs-ofctl.c | 17 ++++++--------
3 files changed, 70 insertions(+), 11 deletions(-)
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index 54ae709..cc82a10 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -4129,7 +4129,7 @@ oqs10_to_oqs11(const struct ofp10_queue_stats *in,
/* Convert a struct ofp11_queue_stats to a struct ofp10_queue_stats.
* The former may be used as a neutral format as is able to
* encode both ofp*_queue_stats variants.
- * Returns 0 success, an enum ofperr on error */
+ * Returns 0 on success, an enum ofperr otherwise. */
static enum ofperr
oqs11_to_oqs10(const struct ofp11_queue_stats *in,
struct ofp10_queue_stats *out)
@@ -4227,6 +4227,65 @@ oqsr10_to_oqsr11(const struct ofp10_queue_stats_request *in,
out->queue_id = in->queue_id;
}
+/* Convert a struct ofp11_queue_stats_request to a struct
+ * ofp10_queue_stats_request.
+ * The former may be used as a neutral format as is able to
+ * encode both ofp*_queue_stats_request variants.
+ * Returns 0 on success, an enum ofperr otherwise. */
+static enum ofperr
+oqsr11_to_oqsr10(const struct ofp11_queue_stats_request *in,
+ struct ofp10_queue_stats_request *out)
+{
+ enum ofperr error;
+ uint16_t ofp10_port;
+
+ error = ofputil_port_from_ofp11(in->port_no, &ofp10_port);
+ if (error) {
+ return error;
+ }
+ out->port_no = htons(ofp10_port);
+ out->queue_id = in->queue_id;
+ return 0;
+}
+
+/* Encode a queue status.
+ * The encoded message will be fore Open Flow version 'ofp_version'.
+ * Returns encoded queue status, NULL on error. */
+struct ofpbuf *
+ofputil_encode_queue_stats_request(enum ofp_version ofp_version,
+ const struct ofp11_queue_stats_request *oqs)
+{
+ struct ofpbuf *request;
+
+ switch (ofp_version) {
+ case OFP12_VERSION:
+ case OFP11_VERSION: {
+ struct ofp11_queue_stats_request *req;
+
+ request = ofpraw_alloc(OFPRAW_OFPST11_QUEUE_REQUEST, ofp_version, 0);
+ req = ofpbuf_put_uninit(request, sizeof *req);
+ memcpy(req, oqs, sizeof *req);
+ break;
+ }
+
+ case OFP10_VERSION: {
+ struct ofp10_queue_stats_request *req;
+
+ request = ofpraw_alloc(OFPRAW_OFPST10_QUEUE_REQUEST, ofp_version, 0);
+ req = ofpbuf_put_uninit(request, sizeof *req);
+ if (oqsr11_to_oqsr10(oqs, req)) {
+ return NULL;
+ }
+ break;
+ }
+
+ default:
+ NOT_REACHED();
+ }
+
+ return request;
+}
+
/* Parse a struct one element of a port status request message into a
* struct ofp11_queue_stats_request. struct ofp11_queue_stats_request is
* used as a neutral format as is able to encode both
diff --git a/lib/ofp-util.h b/lib/ofp-util.h
index 3036e47..5c5ae51 100644
--- a/lib/ofp-util.h
+++ b/lib/ofp-util.h
@@ -640,6 +640,9 @@ ofptutil_decode_queue_stat(enum ofp_version ofp_version,
struct ofp11_queue_stats *qs_storage);
enum ofperr ofputil_append_queue_stat(struct list *replies,
struct ofp11_queue_stats *ofqs11);
+struct ofpbuf *
+ofputil_encode_queue_stats_request(enum ofp_version ofp_version,
+ const struct ofp11_queue_stats_request *oqs);
const struct ofp11_queue_stats_request *
ofptutil_decode_queue_stat_request(const struct ofp_header *oh,
struct ofp11_queue_stats_request
diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index bb261e0..bf827ec 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -970,28 +970,25 @@ ofctl_dump_aggregate(int argc, char *argv[])
static void
ofctl_queue_stats(int argc, char *argv[])
{
- struct ofp10_queue_stats_request *req;
struct ofpbuf *request;
struct vconn *vconn;
+ struct ofp11_queue_stats_request oqs;
open_vconn(argv[1], &vconn);
- request = ofpraw_alloc(OFPRAW_OFPST10_QUEUE_REQUEST,
- vconn_get_version(vconn), 0);
- req = ofpbuf_put_zeros(request, sizeof *req);
if (argc > 2 && argv[2][0] && strcasecmp(argv[2], "all")) {
- req->port_no = htons(str_to_port_no(vconn, argv[2]));
+ oqs.port_no = ofputil_port_to_ofp11(str_to_port_no(vconn, argv[2]));
} else {
- req->port_no = htons(OFPP_ALL);
+ oqs.port_no = ofputil_port_to_ofp11(OFPP_ALL);
}
if (argc > 3 && argv[3][0] && strcasecmp(argv[3], "all")) {
- req->queue_id = htonl(atoi(argv[3]));
+ oqs.queue_id = htonl(atoi(argv[3]));
} else {
- req->queue_id = htonl(OFPQ_ALL);
+ oqs.queue_id = htonl(OFPQ_ALL);
}
- memset(req->pad, 0, sizeof req->pad);
-
+ request = ofputil_encode_queue_stats_request(vconn_get_version(vconn),
+ &oqs);
dump_stats_transaction(vconn, request);
vconn_close(vconn);
}
--
1.7.10.4
More information about the dev
mailing list