bond: Sort slaves in ovs-appctl bond/show.
authorEthan Jackson <ethan@nicira.com>
Thu, 15 Dec 2011 02:56:07 +0000 (18:56 -0800)
committerEthan Jackson <ethan@nicira.com>
Tue, 17 Jan 2012 02:14:55 +0000 (18:14 -0800)
This will simplify unit tests which appear in future commits.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
lib/bond.c

index 0daecf0dca16e580452e09c2a0b6a2a1e0ffcd03..79fc18c1ab6eb8d27ef1244ccbccf1b5bd5035ea 100644 (file)
@@ -32,6 +32,7 @@
 #include "ofpbuf.h"
 #include "packets.h"
 #include "poll-loop.h"
+#include "shash.h"
 #include "tag.h"
 #include "timeval.h"
 #include "unixctl.h"
@@ -937,7 +938,10 @@ bond_unixctl_list(struct unixctl_conn *conn,
 static void
 bond_print_details(struct ds *ds, const struct bond *bond)
 {
+    struct shash slave_shash = SHASH_INITIALIZER(&slave_shash);
+    const struct shash_node **sorted_slaves = NULL;
     const struct bond_slave *slave;
+    int i;
 
     ds_put_format(ds, "---- %s ----\n", bond->name);
     ds_put_format(ds, "bond_mode: %s\n",
@@ -962,8 +966,15 @@ bond_print_details(struct ds *ds, const struct bond *bond)
                   bond->lacp_negotiated ? "true" : "false");
 
     HMAP_FOR_EACH (slave, hmap_node, &bond->slaves) {
+        shash_add(&slave_shash, slave->name, slave);
+    }
+    sorted_slaves = shash_sort(&slave_shash);
+
+    for (i = 0; i < shash_count(&slave_shash); i++) {
         struct bond_entry *be;
 
+        slave = sorted_slaves[i]->data;
+
         /* Basic info. */
         ds_put_format(ds, "\nslave %s: %s\n",
                       slave->name, slave->enabled ? "enabled" : "disabled");
@@ -997,6 +1008,8 @@ bond_print_details(struct ds *ds, const struct bond *bond)
             /* XXX How can we list the MACs assigned to hashes of SLB bonds? */
         }
     }
+    shash_destroy(&slave_shash);
+    free(sorted_slaves);
     ds_put_cstr(ds, "\n");
 }