[ovs-dev] [PATCH 3/5] ofp-print: Sort queues before printing in OFPT_QUEUE_GET_CONFIG_REPLY.
Ben Pfaff
blp at ovn.org
Fri May 27 00:17:39 UTC 2016
Otherwise the ordering tends to vary across endianness.
Signed-off-by: Ben Pfaff <blp at ovn.org>
---
lib/ofp-print.c | 60 ++++++++++++++++++++++++++++++++++++++++--------------
tests/ofp-print.at | 8 ++++----
tests/ofproto.at | 4 ++--
3 files changed, 51 insertions(+), 21 deletions(-)
diff --git a/lib/ofp-print.c b/lib/ofp-print.c
index b21d76f..5e49c60 100644
--- a/lib/ofp-print.c
+++ b/lib/ofp-print.c
@@ -1197,40 +1197,70 @@ print_queue_rate(struct ds *string, const char *name, unsigned int rate)
}
}
+/* qsort comparison function. */
+static int
+compare_queues(const void *a_, const void *b_)
+{
+ const struct ofputil_queue_config *a = a_;
+ const struct ofputil_queue_config *b = b_;
+
+ uint16_t ap = ofp_to_u16(a->port);
+ uint16_t bp = ofp_to_u16(b->port);
+ if (ap != bp) {
+ return ap < bp ? -1 : 1;
+ }
+
+ uint32_t aq = a->queue;
+ uint32_t bq = b->queue;
+ return aq < bq ? -1 : aq > bq;
+}
+
static void
ofp_print_queue_get_config_reply(struct ds *string,
const struct ofp_header *oh)
{
struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
- ofp_port_t port = 0;
- ds_put_char(string, ' ');
- for (;;) {
- struct ofputil_queue_config queue;
- int retval;
+ struct ofputil_queue_config *queues = NULL;
+ size_t allocated_queues = 0;
+ size_t n = 0;
- retval = ofputil_pull_queue_get_config_reply(&b, &queue);
+ int retval = 0;
+ for (;;) {
+ if (n >= allocated_queues) {
+ queues = x2nrealloc(queues, &allocated_queues, sizeof *queues);
+ }
+ retval = ofputil_pull_queue_get_config_reply(&b, &queues[n]);
if (retval) {
- if (retval != EOF) {
- ofp_print_error(string, retval);
- }
- ds_chomp(string, ' ');
break;
}
+ n++;
+ }
+
+ qsort(queues, n, sizeof *queues, compare_queues);
- if (queue.port != port) {
- port = queue.port;
+ ds_put_char(string, ' ');
+
+ ofp_port_t port = 0;
+ for (const struct ofputil_queue_config *q = queues; q < &queues[n]; q++) {
+ if (q->port != port) {
+ port = q->port;
ds_put_cstr(string, "port=");
ofputil_format_port(port, string);
ds_put_char(string, '\n');
}
- ds_put_format(string, "queue %"PRIu32":", queue.queue);
- print_queue_rate(string, "min_rate", queue.min_rate);
- print_queue_rate(string, "max_rate", queue.max_rate);
+ ds_put_format(string, "queue %"PRIu32":", q->queue);
+ print_queue_rate(string, "min_rate", q->min_rate);
+ print_queue_rate(string, "max_rate", q->max_rate);
ds_put_char(string, '\n');
}
+
+ if (retval != EOF) {
+ ofp_print_error(string, retval);
+ }
+ ds_chomp(string, ' ');
}
static void
diff --git a/tests/ofp-print.at b/tests/ofp-print.at
index 8e97434..11337b5 100644
--- a/tests/ofp-print.at
+++ b/tests/ofp-print.at
@@ -2565,8 +2565,8 @@ AT_CHECK([ovs-ofctl ofp-print "01 15 00 40 00 00 00 01 \
00 00 44 44 00 08 00 00 \
"], [0], [dnl
OFPT_QUEUE_GET_CONFIG_REPLY (xid=0x1): port=1
-queue 21845: min_rate:50.0% max_rate:75.0%
queue 17476:
+queue 21845: min_rate:50.0% max_rate:75.0%
])
AT_CLEANUP
@@ -2580,8 +2580,8 @@ AT_CHECK([ovs-ofctl ofp-print "02 17 00 40 00 00 00 01 \
00 00 44 44 00 08 00 00 \
"], [0], [dnl
OFPT_QUEUE_GET_CONFIG_REPLY (OF1.1) (xid=0x1): port=1
-queue 21845: min_rate:50.0% max_rate:75.0%
queue 17476:
+queue 21845: min_rate:50.0% max_rate:75.0%
])
AT_CLEANUP
@@ -2595,8 +2595,8 @@ AT_CHECK([ovs-ofctl ofp-print "03 17 00 50 00 00 00 01 \
00 00 44 44 00 08 00 01 00 10 00 00 00 00 00 00 \
"], [0], [dnl
OFPT_QUEUE_GET_CONFIG_REPLY (OF1.2) (xid=0x1): port=1
-queue 21845: min_rate:50.0% max_rate:75.0%
queue 17476:
+queue 21845: min_rate:50.0% max_rate:75.0%
])
AT_CLEANUP
@@ -2610,8 +2610,8 @@ AT_CHECK([ovs-ofctl ofp-print "04 17 00 50 00 00 00 01 \
00 00 44 44 00 08 00 01 00 10 00 00 00 00 00 00 \
"], [0], [dnl
OFPT_QUEUE_GET_CONFIG_REPLY (OF1.3) (xid=0x1): port=1
-queue 21845: min_rate:50.0% max_rate:75.0%
queue 17476:
+queue 21845: min_rate:50.0% max_rate:75.0%
])
AT_CLEANUP
diff --git a/tests/ofproto.at b/tests/ofproto.at
index f8c0d07..1ddee43 100644
--- a/tests/ofproto.at
+++ b/tests/ofproto.at
@@ -294,10 +294,10 @@ add_of_ports br0 1 2
AT_CHECK([ovs-ofctl -O OpenFlow14 queue-get-config br0 any | strip_xids], [0],
[OFPST_QUEUE_DESC reply (OF1.4): port=1
queue 0:
-port=LOCAL
-queue 0:
port=2
queue 0:
+port=LOCAL
+queue 0:
])
AT_CHECK([ovs-ofctl -O OpenFlow14 queue-get-config br0 1 | strip_xids], [0],
--
2.1.3
More information about the dev
mailing list