From patchwork Thu May 4 20:01:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 758764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wJmCh3xfTz9s82 for ; Fri, 5 May 2017 06:02:40 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 8A847C20; Thu, 4 May 2017 20:01:24 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 5403FC14 for ; Thu, 4 May 2017 20:01:21 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id E97041FF for ; Thu, 4 May 2017 20:01:19 +0000 (UTC) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by relay8-d.mail.gandi.net (Postfix) with ESMTPS id C0CA9406C8; Thu, 4 May 2017 22:01:18 +0200 (CEST) Received: from mfilter9-d.gandi.net (mfilter9-d.gandi.net [217.70.178.138]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id A7ECF41C07F; Thu, 4 May 2017 22:01:18 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter9-d.gandi.net Received: from relay5-d.mail.gandi.net ([IPv6:::ffff:217.70.183.197]) by mfilter9-d.gandi.net (mfilter9-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id TPNcjuLcB57a; Thu, 4 May 2017 22:01:17 +0200 (CEST) X-Originating-IP: 208.91.2.3 Received: from sigabrt.benpfaff.org (unknown [208.91.2.3]) (Authenticated sender: blp@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 6505D41C07D; Thu, 4 May 2017 22:01:16 +0200 (CEST) From: Ben Pfaff To: dev@openvswitch.org Date: Thu, 4 May 2017 13:01:06 -0700 Message-Id: <20170504200108.14404-3-blp@ovn.org> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170504200108.14404-1-blp@ovn.org> References: <20170504200108.14404-1-blp@ovn.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ben Pfaff Subject: [ovs-dev] [PATCH v3 2/4] ovn-trace: Accept human-friendly logical port and datapath names. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org This allows the user to specify these names in a natural way, e.g. "ovn-trace myswitch 'inport == "myport"' instead of having to specify whatever UUID or other horrible name the CMS invented. Signed-off-by: Ben Pfaff --- ovn/utilities/ovn-trace.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/ovn/utilities/ovn-trace.c b/ovn/utilities/ovn-trace.c index f89dd6f18df5..fb5164ae88b2 100644 --- a/ovn/utilities/ovn-trace.c +++ b/ovn/utilities/ovn-trace.c @@ -338,6 +338,7 @@ struct ovntrace_datapath { struct uuid sb_uuid; struct uuid nb_uuid; char *name; + char *name2; uint32_t tunnel_key; struct ovs_list mcgroups; /* Contains "struct ovntrace_mcgroup"s. */ @@ -354,6 +355,7 @@ struct ovntrace_port { struct ovntrace_datapath *dp; struct uuid uuid; char *name; + char *friendly_name; char *type; uint16_t tunnel_key; struct ovntrace_port *peer; /* Patch ports only. */ @@ -432,7 +434,8 @@ ovntrace_datapath_find_by_name(const char *name) { struct ovntrace_datapath *dp; HMAP_FOR_EACH (dp, sb_uuid_node, &datapaths) { - if (!strcmp(name, dp->name)) { + if (!strcmp(name, dp->name) + || (dp->name2 && !strcmp(name, dp->name2))) { return dp; } } @@ -535,6 +538,8 @@ read_datapaths(void) ? xstrdup(name) : xasprintf(UUID_FMT, UUID_ARGS(&dp->nb_uuid))); + dp->name2 = nullable_xstrdup(smap_get(ids, "name2")); + dp->tunnel_key = sbdb->tunnel_key; ovs_list_init(&dp->mcgroups); @@ -569,6 +574,8 @@ read_ports(void) port->name = xstrdup(port_name); port->type = xstrdup(sbpb->type); port->tunnel_key = sbpb->tunnel_key; + port->friendly_name = nullable_xstrdup(smap_get(&sbpb->external_ids, + "name")); if (!strcmp(sbpb->type, "patch")) { const char *peer_name = smap_get(&sbpb->options, "peer"); @@ -882,6 +889,20 @@ ovntrace_port_lookup_by_name(const char *name) } const struct ovntrace_port *match = NULL; + + struct shash_node *node; + SHASH_FOR_EACH (node, &ports) { + const struct ovntrace_port *port = node->data; + + if (port->friendly_name && !strcmp(port->friendly_name, name)) { + if (match) { + VLOG_WARN("name \"%s\" matches multiple ports", name); + return NULL; + } + match = port; + } + } + if (uuid_is_partial_string(name) >= 4) { struct shash_node *node; SHASH_FOR_EACH (node, &ports) { @@ -891,7 +912,7 @@ ovntrace_port_lookup_by_name(const char *name) if (uuid_is_partial_match(&port->uuid, name) || (uuid_from_string(&name_uuid, port->name) && uuid_is_partial_match(&name_uuid, name))) { - if (match) { + if (match && match != port) { VLOG_WARN("name \"%s\" matches multiple ports", name); return NULL; } @@ -899,6 +920,7 @@ ovntrace_port_lookup_by_name(const char *name) } } } + return match; }