summaryrefslogtreecommitdiff
path: root/ovn
diff options
context:
space:
mode:
authorBen Pfaff <blp@ovn.org>2017-05-04 10:44:25 -0700
committerBen Pfaff <blp@ovn.org>2017-05-04 13:20:17 -0700
commitd2fcad2f5a4784394ce8b93dd9ce6c3933a5a06c (patch)
treef33374b09abac771089fd13507fd7fdb913289d6 /ovn
parent06656e2034ba3d5d3ffa516e35b8a4c8b783c2f1 (diff)
downloadopenvswitch-d2fcad2f5a4784394ce8b93dd9ce6c3933a5a06c.tar.gz
ovn-trace: Add support for partial UUID matches for ports and datapaths.
This makes ovn-trace commands easier to type. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Andy Zhou <azhou@ovn.org>
Diffstat (limited to 'ovn')
-rw-r--r--ovn/utilities/ovn-trace.c55
1 files changed, 46 insertions, 9 deletions
diff --git a/ovn/utilities/ovn-trace.c b/ovn/utilities/ovn-trace.c
index 860fd4b26..f89dd6f18 100644
--- a/ovn/utilities/ovn-trace.c
+++ b/ovn/utilities/ovn-trace.c
@@ -352,6 +352,7 @@ struct ovntrace_datapath {
struct ovntrace_port {
struct ovntrace_datapath *dp;
+ struct uuid uuid;
char *name;
char *type;
uint16_t tunnel_key;
@@ -429,19 +430,25 @@ ovntrace_datapath_find_by_sb_uuid(const struct uuid *sb_uuid)
static const struct ovntrace_datapath *
ovntrace_datapath_find_by_name(const char *name)
{
- struct uuid uuid;
- bool is_uuid = uuid_from_string(&uuid, name);
-
struct ovntrace_datapath *dp;
HMAP_FOR_EACH (dp, sb_uuid_node, &datapaths) {
- if (!strcmp(name, dp->name)
- || (is_uuid
- && (uuid_equals(&uuid, &dp->sb_uuid) ||
- uuid_equals(&uuid, &dp->nb_uuid)))) {
+ if (!strcmp(name, dp->name)) {
return dp;
}
}
- return NULL;
+
+ struct ovntrace_datapath *match = NULL;
+ HMAP_FOR_EACH (dp, sb_uuid_node, &datapaths) {
+ if (uuid_is_partial_match(&dp->sb_uuid, name) >= 4 ||
+ uuid_is_partial_match(&dp->nb_uuid, name) >= 4) {
+ if (match) {
+ VLOG_WARN("name \"%s\" matches multiple datapaths", name);
+ return NULL;
+ }
+ match = dp;
+ }
+ }
+ return match;
}
static const struct ovntrace_port *
@@ -558,6 +565,7 @@ read_ports(void)
continue;
}
port->dp = dp;
+ port->uuid = sbpb->header_.uuid;
port->name = xstrdup(port_name);
port->type = xstrdup(sbpb->type);
port->tunnel_key = sbpb->tunnel_key;
@@ -865,6 +873,35 @@ read_db(void)
read_mac_bindings();
}
+static const struct ovntrace_port *
+ovntrace_port_lookup_by_name(const char *name)
+{
+ const struct ovntrace_port *port = shash_find_data(&ports, name);
+ if (port) {
+ return port;
+ }
+
+ const struct ovntrace_port *match = NULL;
+ if (uuid_is_partial_string(name) >= 4) {
+ struct shash_node *node;
+ SHASH_FOR_EACH (node, &ports) {
+ const struct ovntrace_port *port = node->data;
+
+ struct uuid name_uuid;
+ if (uuid_is_partial_match(&port->uuid, name)
+ || (uuid_from_string(&name_uuid, port->name)
+ && uuid_is_partial_match(&name_uuid, name))) {
+ if (match) {
+ VLOG_WARN("name \"%s\" matches multiple ports", name);
+ return NULL;
+ }
+ match = port;
+ }
+ }
+ }
+ return match;
+}
+
static bool
ovntrace_lookup_port(const void *dp_, const char *port_name,
unsigned int *portp)
@@ -876,7 +913,7 @@ ovntrace_lookup_port(const void *dp_, const char *port_name,
return true;
}
- const struct ovntrace_port *port = shash_find_data(&ports, port_name);
+ const struct ovntrace_port *port = ovntrace_port_lookup_by_name(port_name);
if (port) {
if (port->dp == dp) {
*portp = port->tunnel_key;