}
}
+/* 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
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
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
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
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