@@ -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 *
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@ovn.org> --- utilities/ovn-sbctl.c | 59 +++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 30 deletions(-)