From patchwork Thu Oct 22 21:24:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 1386432 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CHL3m3Ldrz9sSs for ; Fri, 23 Oct 2020 08:24:52 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 57FEA2039E; Thu, 22 Oct 2020 21:24:50 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0QWWF3lr+qUX; Thu, 22 Oct 2020 21:24:43 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 6BFEB20511; Thu, 22 Oct 2020 21:24:40 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5FE3DC1AD6; Thu, 22 Oct 2020 21:24:40 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 76EF6C0051 for ; Thu, 22 Oct 2020 21:24:39 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 9FB07878A7 for ; Thu, 22 Oct 2020 21:24:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yWhV4qCIlLYB for ; Thu, 22 Oct 2020 21:24:36 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by hemlock.osuosl.org (Postfix) with ESMTPS id 05A478788C for ; Thu, 22 Oct 2020 21:24:35 +0000 (UTC) Received: from sigfpe.attlocal.net (75-54-222-30.lightspeed.rdcyca.sbcglobal.net [75.54.222.30]) (Authenticated sender: blp@ovn.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id B367B100008; Thu, 22 Oct 2020 21:24:33 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Thu, 22 Oct 2020 14:24:22 -0700 Message-Id: <20201022212422.1913373-5-blp@ovn.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201022212422.1913373-1-blp@ovn.org> References: <20201022212422.1913373-1-blp@ovn.org> MIME-Version: 1.0 Cc: Ben Pfaff Subject: [ovs-dev] [PATCH ovn 5/5] ovn-sbctl: Sort flows in "dump-flows" output by datapath name. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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 --- 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 *