From patchwork Fri Sep 4 20:21:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Pettit X-Patchwork-Id: 514755 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (unknown [IPv6:2600:3c00::f03c:91ff:fe6e:bdf7]) by ozlabs.org (Postfix) with ESMTP id 85F651402A3 for ; Sat, 5 Sep 2015 06:22:08 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 7F07B10C1B; Fri, 4 Sep 2015 13:22:07 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e3.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id CEC3810C1A for ; Fri, 4 Sep 2015 13:22:05 -0700 (PDT) Received: from bar2.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id 36FFB42031F for ; Fri, 4 Sep 2015 14:22:05 -0600 (MDT) X-ASG-Debug-ID: 1441398124-03dc53122071620001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar2.cudamail.com with ESMTP id U9Sc2nOgCoGvOJEH (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 04 Sep 2015 14:22:04 -0600 (MDT) X-Barracuda-Envelope-From: jpettit@nicira.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO mail-pa0-f45.google.com) (209.85.220.45) by mx1-pf2.cudamail.com with ESMTPS (RC4-SHA encrypted); 4 Sep 2015 20:22:04 -0000 Received-SPF: unknown (mx1-pf2.cudamail.com: Multiple SPF records returned) X-Barracuda-RBL-Trusted-Forwarder: 209.85.220.45 Received: by padhy16 with SMTP id hy16so31552125pad.1 for ; Fri, 04 Sep 2015 13:22:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=Qek3mMBkrKzq6Nm2DKeTcc04b0VmQ6wDckWjCavObtk=; b=AwK1aLhFApamRnrNStNduEIwIE1KX3LAvoNa3if9Edyb7bZH6TWuHlQQhfPIDlxkNu yLS+eKNB1CYn9Q3ijk2BxOCmE7PX730lSPiLws64hqgLvxWeyXfEGcYT0/2PhN6zVH1u 32i+kgUvGzSk8gOZXPu2oDXFyH7tm+3xTXmAkbDHzaQvdnVo+C7o/ljByH8qkeOTibGp EM9w6aX5Ol+ZCplPycaErOXDXob96UGWICC9fPF7KS9XKwm1Gxe97xn/D98rXIJfcoJw IqBK2WGTGGj0p+jmyQIlHM6SyjFyugGTIAm+KxotDsq9J8aPR7IDv0dPktoriOZUqdQc KZvA== X-Gm-Message-State: ALoCoQm7DYjIk6LsoS5Z5D+MOTSDQwdiDmMzRb8F04y65e5hhBrqidu25HggG6gnlLBqHTWt0PMm X-Received: by 10.66.158.137 with SMTP id wu9mr11996842pab.62.1441398122978; Fri, 04 Sep 2015 13:22:02 -0700 (PDT) Received: from localhost.localdomain ([208.91.2.4]) by smtp.gmail.com with ESMTPSA id gx1sm3477115pbc.29.2015.09.04.13.22.02 for (version=TLSv1/SSLv3 cipher=OTHER); Fri, 04 Sep 2015 13:22:02 -0700 (PDT) X-CudaMail-Envelope-Sender: jpettit@nicira.com X-Barracuda-Apparent-Source-IP: 208.91.2.4 From: Justin Pettit To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-E2-903063757 X-CudaMail-DTE: 090415 X-CudaMail-Originating-IP: 209.85.220.45 Date: Fri, 4 Sep 2015 13:21:59 -0700 X-ASG-Orig-Subj: [##CM-E2-903063757##][PATCHv2] ovn-nbctl: Sort output of most commands. Message-Id: <1441398119-39465-1-git-send-email-jpettit@nicira.com> X-Mailer: git-send-email 1.7.5.4 X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1441398124 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Subject: [ovs-dev] [PATCHv2] ovn-nbctl: Sort output of most commands. X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" This will be helpful for unit tests. Signed-off-by: Justin Pettit Acked-by: Ben Pfaff --- v1->v2: Actually sort the macs and port security addresses. --- ovn/utilities/ovn-nbctl.c | 51 ++++++++++++++++++++++++++++++++++++++------ 1 files changed, 44 insertions(+), 7 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 0bdb3a3..d095df1 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -25,8 +25,10 @@ #include "ovn/lib/ovn-nb-idl.h" #include "poll-loop.h" #include "process.h" +#include "smap.h" #include "stream.h" #include "stream-ssl.h" +#include "svec.h" #include "util.h" #include "openvswitch/vlog.h" @@ -217,11 +219,20 @@ do_lswitch_list(struct ovs_cmdl_context *ctx) { struct nbctl_context *nb_ctx = ctx->pvt; const struct nbrec_logical_switch *lswitch; + struct smap lswitches; + smap_init(&lswitches); NBREC_LOGICAL_SWITCH_FOR_EACH(lswitch, nb_ctx->idl) { - printf(UUID_FMT " (%s)\n", - UUID_ARGS(&lswitch->header_.uuid), lswitch->name); + smap_add_format(&lswitches, lswitch->name, UUID_FMT " (%s)", + UUID_ARGS(&lswitch->header_.uuid), lswitch->name); } + const struct smap_node **nodes = smap_sort(&lswitches); + for (size_t i = 0; i < smap_count(&lswitches); i++) { + const struct smap_node *node = nodes[i]; + printf("%s\n", node->value); + } + smap_destroy(&lswitches); + free(nodes); } static void @@ -408,17 +419,27 @@ do_lport_list(struct ovs_cmdl_context *ctx) struct nbctl_context *nb_ctx = ctx->pvt; const char *id = ctx->argv[1]; const struct nbrec_logical_switch *lswitch; + struct smap lports; + size_t i; lswitch = lswitch_by_name_or_uuid(nb_ctx, id); if (!lswitch) { return; } - for (size_t i = 0; i < lswitch->n_ports; i++) { + smap_init(&lports); + for (i = 0; i < lswitch->n_ports; i++) { const struct nbrec_logical_port *lport = lswitch->ports[i]; - printf(UUID_FMT " (%s)\n", - UUID_ARGS(&lport->header_.uuid), lport->name); + smap_add_format(&lports, lport->name, UUID_FMT " (%s)", + UUID_ARGS(&lport->header_.uuid), lport->name); } + const struct smap_node **nodes = smap_sort(&lports); + for (i = 0; i < smap_count(&lports); i++) { + const struct smap_node *node = nodes[i]; + printf("%s\n", node->value); + } + smap_destroy(&lports); + free(nodes); } static void @@ -532,6 +553,8 @@ do_lport_get_macs(struct ovs_cmdl_context *ctx) struct nbctl_context *nb_ctx = ctx->pvt; const char *id = ctx->argv[1]; const struct nbrec_logical_port *lport; + struct svec macs; + const char *mac; size_t i; lport = lport_by_name_or_uuid(nb_ctx, id); @@ -539,9 +562,15 @@ do_lport_get_macs(struct ovs_cmdl_context *ctx) return; } + svec_init(&macs); for (i = 0; i < lport->n_macs; i++) { - printf("%s\n", lport->macs[i]); + svec_add(&macs, lport->macs[i]); + } + svec_sort(&macs); + SVEC_FOR_EACH(i, mac, &macs) { + printf("%s\n", mac); } + svec_destroy(&macs); } static void @@ -566,6 +595,8 @@ do_lport_get_port_security(struct ovs_cmdl_context *ctx) struct nbctl_context *nb_ctx = ctx->pvt; const char *id = ctx->argv[1]; const struct nbrec_logical_port *lport; + struct svec addrs; + const char *addr; size_t i; lport = lport_by_name_or_uuid(nb_ctx, id); @@ -573,9 +604,15 @@ do_lport_get_port_security(struct ovs_cmdl_context *ctx) return; } + svec_init(&addrs); for (i = 0; i < lport->n_port_security; i++) { - printf("%s\n", lport->port_security[i]); + svec_add(&addrs, lport->port_security[i]); + } + svec_sort(&addrs); + SVEC_FOR_EACH(i, addr, &addrs) { + printf("%s\n", addr); } + svec_destroy(&addrs); } static void