[openib-general] Diags/ibtracert: Add switch-map option to ibtracert
Hal Rosenstock
halr at voltaire.com
Wed Jan 31 09:02:35 PST 2007
Diags/ibtracert: Add switch-map option to ibtracert
Signed-off-by: Ira K. Weiny <weiny2 at llnl.gov>
Signed-off-by: Hal Rosenstock <halr at voltaire.com>
diff --git a/diags/man/ibtracert.8 b/diags/man/ibtracert.8
index c1632ac..28f18b6 100644
--- a/diags/man/ibtracert.8
+++ b/diags/man/ibtracert.8
@@ -1,11 +1,11 @@
-.TH IBTRACERT 8 "July 25, 2006" "OpenIB" "OpenIB Diagnostics"
+.TH IBTRACERT 8 "January 31, 2007" "OpenIB" "OpenIB Diagnostics"
.SH NAME
ibtracert\- trace InfiniBand path
.SH SYNOPSIS
.B ibtracert
-[\-d(ebug)] [-v(erbose)] [\-D(irect)] [\-G(uids)] [-n(o_info)] [-m mlid] [-s smlid] [\-C ca_name] [\-P ca_port] [\-t(imeout) timeout_ms] [\-V(ersion)] [\-h(elp)] [<dest dr_path|lid|guid> [<startlid> [<endlid>]]]
+[\-d(ebug)] [-v(erbose)] [\-D(irect)] [\-G(uids)] [-n(o_info)] [-m mlid] [-s smlid] [\-C ca_name] [\-P ca_port] [\-t(imeout) timeout_ms] [\-V(ersion)] [\-\-switch\-map <switch-map>] [\-h(elp)] [<dest dr_path|lid|guid> [<startlid> [<endlid>]]]
.SH DESCRIPTION
.PP
@@ -23,6 +23,10 @@ simple format; don't show additional inf
.TP
\fB\-m\fR
show the multicast trace of the specified mlid
+.TP
+\fB\-\-switch\-map\fR <switch-map>
+Specify a switch map. The switch map file maps GUIDs to more user friendly
+names. See ibnetdiscover for switch map file format.
.SH COMMON OPTIONS
@@ -101,3 +105,6 @@ ibtracert -m 0xc000 4 16 # show multi
.TP
Hal Rosenstock
.RI < halr at voltaire.com >
+.TP
+Ira Weiny
+.RI < weiny2 at llnl.gov >
diff --git a/diags/src/ibtracert.c b/diags/src/ibtracert.c
index c69ff4e..34da658 100644
--- a/diags/src/ibtracert.c
+++ b/diags/src/ibtracert.c
@@ -35,6 +35,7 @@
# include <config.h>
#endif /* HAVE_CONFIG_H */
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -43,6 +44,7 @@
#include <getopt.h>
#include <netinet/in.h>
#include <inttypes.h>
+#include <errno.h>
#define __BUILD_VERSION_TAG__ 1.2
#include <common.h>
@@ -65,6 +67,8 @@ static int force;
static FILE *f;
static char *argv0 = "ibtracert";
+static char *switch_map = NULL;
+static FILE *switch_map_fp = NULL;
#undef DEBUG
#define DEBUG if (ibdebug || verbose) IBWARN
@@ -146,6 +150,68 @@ clean_nodedesc(char *nodedesc)
return (nodedesc);
}
+/** =========================================================================
+ */
+static void
+open_switch_map(void)
+{
+ if (switch_map) {
+ switch_map_fp = fopen(switch_map, "r");
+ if (switch_map_fp == NULL) {
+ fprintf(stderr,
+ "WARNING failed to open switch map \"%s\" (%s)\n"
+ " Switch names will default to node descriptions\n",
+ switch_map, strerror(errno));
+ }
+ }
+}
+
+static void
+close_switch_map(void)
+{
+ if (switch_map_fp)
+ fclose(switch_map_fp);
+}
+
+static char *
+lookup_switch_name(Node *node)
+{
+#define NAME_LEN (256)
+ char *line = NULL;
+ size_t len = 0;
+ uint64_t guid = 0;
+ char *rc = NULL;
+ int line_count = 0;
+ uint64_t target_guid = node->nodeguid;
+
+ if (switch_map_fp == NULL)
+ goto done;
+
+ rewind(switch_map_fp);
+ for (line_count = 1;
+ getline(&line, &len, switch_map_fp) != -1;
+ line_count++) {
+ line[len-1] = '\0';
+ if (line[0] == '#') { goto next_one; }
+ char *guid_str = strtok(line, "\"#");
+ char *name = strtok(NULL, "\"#");
+ if (!guid_str || !name) { goto next_one; }
+ guid = strtoull(guid_str, NULL, 0);
+ if (target_guid == guid) {
+ rc = strdup(name);
+ free(line);
+ goto done;
+ }
+next_one:
+ free (line);
+ line = NULL;
+ }
+done:
+ if (rc == NULL)
+ rc = strdup(clean_nodedesc(node->nodedesc));
+ return (rc);
+}
+
static int
get_node(Node *node, Port *port, ib_portid_t *portid)
{
@@ -234,13 +300,20 @@ dump_endnode(int dump, char *prompt, Nod
return;
}
- nodename = clean_nodedesc(node->nodedesc);
+ if (node->type == IB_NODE_SWITCH)
+ nodename = lookup_switch_name(node);
+ else
+ nodename = clean_nodedesc(node->nodedesc);
+
fprintf(f, "%s %s {0x%016" PRIx64 "} portnum %d lid 0x%x-0x%x \"%s\"\n",
prompt,
(node->type <= IB_NODE_MAX ? node_type_str[node->type] : "???"),
node->nodeguid, node->type == IB_NODE_SWITCH ? 0 : port->portnum,
port->lid, port->lid + (1 << port->lmc) - 1,
nodename);
+
+ if (nodename && (node->type == IB_NODE_SWITCH))
+ free(nodename);
}
static void
@@ -251,7 +324,11 @@ dump_route(int dump, Node *node, int out
if (!dump && !verbose)
return;
- nodename = clean_nodedesc(node->nodedesc);
+ if (node->type == IB_NODE_SWITCH)
+ nodename = lookup_switch_name(node);
+ else
+ nodename = clean_nodedesc(node->nodedesc);
+
if (dump == 1)
fprintf(f, "[%d] -> {0x%016" PRIx64 "}[%d]\n",
outport, port->portguid, port->portnum);
@@ -262,6 +339,9 @@ dump_route(int dump, Node *node, int out
port->portguid, port->portnum,
port->lid, port->lid + (1 << port->lmc) - 1,
nodename);
+
+ if (nodename && (node->type == IB_NODE_SWITCH))
+ free(nodename);
}
static int
@@ -660,14 +740,18 @@ dump_mcpath(Node *node, int dumplevel)
if (node->upnode)
dump_mcpath(node->upnode, dumplevel);
- nodename = clean_nodedesc(node->nodedesc);
+ if (node->type == IB_NODE_SWITCH)
+ nodename = lookup_switch_name(node);
+ else
+ nodename = clean_nodedesc(node->nodedesc);
+
if (!node->dist) {
printf("From %s 0x%" PRIx64 " port %d lid 0x%x-0x%x \"%s\"\n",
(node->type <= IB_NODE_MAX ? node_type_str[node->type] : "???"),
node->nodeguid, node->ports->portnum, node->ports->lid,
node->ports->lid + (1 << node->ports->lmc) - 1,
nodename);
- return;
+ goto free_name;
}
if (node->dist) {
@@ -691,6 +775,10 @@ dump_mcpath(Node *node, int dumplevel)
node->nodeguid, node->ports->portnum, node->ports->lid,
node->ports->lid + (1 << node->ports->lmc) - 1,
nodename);
+
+free_name:
+ if (nodename && (node->type == IB_NODE_SWITCH))
+ free(nodename);
}
static void
@@ -704,7 +792,7 @@ usage(void)
basename++;
fprintf(stderr, "Usage: %s [-d(ebug) -v(erbose) -D(irect) -G(uids) -n(o_info) -C ca_name -P ca_port "
- "-s smlid -t(imeout) timeout_ms -m mlid] <src-addr> <dest-addr>\n",
+ "-s smlid -t(imeout) timeout_ms -m mlid --switch-map switch-map ] <src-addr> <dest-addr>\n",
basename);
fprintf(stderr, "\n\tUnicast examples:\n");
fprintf(stderr, "\t\t%s 4 16\t\t\t# show path between lids 4 and 16\n", basename);
@@ -747,6 +835,7 @@ main(int argc, char **argv)
{ "Version", 0, 0, 'V'},
{ "help", 0, 0, 'h'},
{ "usage", 0, 0, 'u'},
+ { "switch-map", 1, 0, 1},
{ }
};
@@ -759,6 +848,9 @@ main(int argc, char **argv)
if ( ch == -1 )
break;
switch(ch) {
+ case 1:
+ switch_map = strdup(optarg);
+ break;
case 'C':
ca = optarg;
break;
@@ -815,6 +907,7 @@ main(int argc, char **argv)
usage();
madrpc_init(ca, ca_port, mgmt_classes, 3);
+ open_switch_map();
if (ib_resolve_portid_str(&src_portid, argv[0], dest_type, sm_id) < 0)
IBERROR("can't resolve source port %s", argv[0]);
@@ -852,5 +945,7 @@ main(int argc, char **argv)
/* dump multicast path */
dump_mcpath(endnode, dumplevel);
+
+ close_switch_map();
exit(0);
}
More information about the general
mailing list