summaryrefslogtreecommitdiff
path: root/lib/ofp-print.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@ovn.org>2016-05-26 15:14:54 -0700
committerBen Pfaff <blp@ovn.org>2016-06-03 13:18:22 -0700
commita28239c009bcb3389c036e4ebafe7c2dc3502c7f (patch)
treea6aa0678121258d13713c33e5230caaff2c982f0 /lib/ofp-print.c
parent3d75c66007c88f886864df02b86afaa3a440088a (diff)
downloadopenvswitch-a28239c009bcb3389c036e4ebafe7c2dc3502c7f.tar.gz
ofp-print: Sort queues before printing in OFPT_QUEUE_GET_CONFIG_REPLY.
Otherwise the ordering tends to vary across endianness. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Aaron Conole <aconole@redhat.com> Acked-by: Gerhard Stenzel <gstenzel@linux.vnet.ibm.com>
Diffstat (limited to 'lib/ofp-print.c')
-rw-r--r--lib/ofp-print.c60
1 files changed, 45 insertions, 15 deletions
diff --git a/lib/ofp-print.c b/lib/ofp-print.c
index b21d76f53..5e49c609e 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