[ovs-dev] [PATCH ovn 5/5] ovn-sbctl: Sort flows in "dump-flows" output by datapath name.

Ben Pfaff blp at ovn.org
Thu Oct 22 21:24:22 UTC 2020


Sorting by datapath name before datapath uuid makes it easier to
compare output from different runs of a given test.

At the same time, get rid of macros that just made the code harder to
read and understand.

Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 utilities/ovn-sbctl.c | 59 +++++++++++++++++++++----------------------
 1 file changed, 29 insertions(+), 30 deletions(-)

diff --git a/utilities/ovn-sbctl.c b/utilities/ovn-sbctl.c
index f93384940862..85e448ec048c 100644
--- a/utilities/ovn-sbctl.c
+++ b/utilities/ovn-sbctl.c
@@ -706,37 +706,36 @@ pipeline_encode(const char *pl)
 }
 
 static int
-lflow_cmp(const void *lf1_, const void *lf2_)
+lflow_cmp(const void *a_, const void *b_)
 {
-    const struct sbrec_logical_flow *const *lf1p = lf1_;
-    const struct sbrec_logical_flow *const *lf2p = lf2_;
-    const struct sbrec_logical_flow *lf1 = *lf1p;
-    const struct sbrec_logical_flow *lf2 = *lf2p;
-
-    int pl1 = pipeline_encode(lf1->pipeline);
-    int pl2 = pipeline_encode(lf2->pipeline);
-
-#define CMP(expr) \
-    do { \
-        int res; \
-        res = (expr); \
-        if (res) { \
-            return res; \
-        } \
-    } while (0)
-
-    CMP(uuid_compare_3way(&lf1->logical_datapath->header_.uuid,
-                          &lf2->logical_datapath->header_.uuid));
-    CMP(pl1 - pl2);
-    CMP(lf1->table_id > lf2->table_id ? 1 :
-            (lf1->table_id < lf2->table_id ? -1 : 0));
-    CMP(lf1->priority > lf2->priority ? -1 :
-            (lf1->priority < lf2->priority ? 1 : 0));
-    CMP(strcmp(lf1->match, lf2->match));
-
-#undef CMP
-
-    return 0;
+    const struct sbrec_logical_flow *const *ap = a_;
+    const struct sbrec_logical_flow *const *bp = b_;
+    const struct sbrec_logical_flow *a = *ap;
+    const struct sbrec_logical_flow *b = *bp;
+
+    const struct sbrec_datapath_binding *adb = a->logical_datapath;
+    const struct sbrec_datapath_binding *bdb = b->logical_datapath;
+    const char *a_name = smap_get_def(&adb->external_ids, "name", "");
+    const char *b_name = smap_get_def(&bdb->external_ids, "name", "");
+    int cmp = strcmp(a_name, b_name);
+    if (cmp) {
+        return cmp;
+    }
+
+    cmp = uuid_compare_3way(&adb->header_.uuid, &bdb->header_.uuid);
+    if (cmp) {
+        return cmp;
+    }
+
+    int a_pipeline = pipeline_encode(a->pipeline);
+    int b_pipeline = pipeline_encode(b->pipeline);
+    return (a_pipeline > b_pipeline ? 1
+            : a_pipeline < b_pipeline ? -1
+            : a->table_id > b->table_id ? 1
+            : a->table_id < b->table_id ? -1
+            : a->priority > b->priority ? -1
+            : a->priority < b->priority ? 1
+            : strcmp(a->match, b->match));
 }
 
 static char *
-- 
2.26.2



More information about the dev mailing list