[openib-general] Diags/ibnetdiscover: Add switch-map option to ibnetdiscover

Hal Rosenstock halr at voltaire.com
Wed Jan 31 09:01:56 PST 2007


Diags/ibnetdiscover: Add switch-map option to ibnetdiscover

Signed-off-by: Ira K. Weiny <weiny2 at llnl.gov>
Signed-off-by: Hal Rosenstock <halr at voltaire.com>

diff --git a/diags/man/ibnetdiscover.8 b/diags/man/ibnetdiscover.8
index 4960a8f..000edb5 100644
--- a/diags/man/ibnetdiscover.8
+++ b/diags/man/ibnetdiscover.8
@@ -1,11 +1,11 @@
-.TH IBNETDISCOVER 8 "October 16, 2006" "OpenIB" "OpenIB Diagnostics"
+.TH IBNETDISCOVER 8 "January 31, 2007" "OpenIB" "OpenIB Diagnostics"
 
 .SH NAME
 ibnetdiscover \- discover InfiniBand topology
 
 .SH SYNOPSIS
 .B ibnetdiscover
-[\-d(ebug)] [\-e(rr_show)] [\-v(erbose)] [\-s(how)] [\-l(ist)] [\-g(rouping)] [\-H(ca_list)] [\-S(witch_list)] [\-C ca_name] [\-P ca_port] [\-t(imeout) timeout_ms] [\-V(ersion)] [\-h(elp)] [<topology-file>]
+[\-d(ebug)] [\-e(rr_show)] [\-v(erbose)] [\-s(how)] [\-l(ist)] [\-g(rouping)] [\-H(ca_list)] [\-S(witch_list)] [\-C ca_name] [\-P ca_port] [\-t(imeout) timeout_ms] [\-V(ersion)] [\--switch-map <switch-map>] [\-h(elp)] [<topology-file>]
 
 .SH DESCRIPTION
 .PP
@@ -34,6 +34,10 @@ List of connected switches
 .TP
 \fB\-s\fR, \fB\-\-show\fR
 Show more information
+.TP
+\fB\-\-switch\-map\fR <switch-map>
+Specify a switch map.  The switch map file maps GUIDs to more user friendly
+names.  See file format below.
 
 .SH COMMON OPTIONS
 
@@ -89,7 +93,63 @@ by the following criteria:
 If a port and/or CA name is specified, the user request is  
 attempted to be fulfilled, and will fail if it is not possible.
 
+.SH SWITCH MAP FILE FORMAT
+The switch map is used to specify a user friendly name for switches in the
+output.  GUIDs are used to perform the lookup.
+
+.TP
+\fBGenerically:\fR
+
+# comment
+.br
+<guid> "<name>"
+
+.TP
+\fBExample:\fR
+
+# IB1
+.br
+# Line cards
+.br
+0x0008f104003f125c "IB1 (Rack 11 slot 1   ) ISR9288/ISR9096 Voltaire sLB-24D"
+.br
+0x0008f104003f125d "IB1 (Rack 11 slot 1   ) ISR9288/ISR9096 Voltaire sLB-24D"
+.br
+0x0008f104003f10d2 "IB1 (Rack 11 slot 2   ) ISR9288/ISR9096 Voltaire sLB-24D"
+.br
+0x0008f104003f10d3 "IB1 (Rack 11 slot 2   ) ISR9288/ISR9096 Voltaire sLB-24D"
+.br
+0x0008f104003f10bf "IB1 (Rack 11 slot 12  ) ISR9288/ISR9096 Voltaire sLB-24D"
+.br
+.br
+# Spines
+.br
+0x0008f10400400e2d "IB1 (Rack 11 spine 1   ) ISR9288 Voltaire sFB-12D"
+.br
+0x0008f10400400e2e "IB1 (Rack 11 spine 1   ) ISR9288 Voltaire sFB-12D"
+.br
+0x0008f10400400e2f "IB1 (Rack 11 spine 1   ) ISR9288 Voltaire sFB-12D"
+.br
+0x0008f10400400e31 "IB1 (Rack 11 spine 2   ) ISR9288 Voltaire sFB-12D"
+.br
+0x0008f10400400e32 "IB1 (Rack 11 spine 2   ) ISR9288 Voltaire sFB-12D"
+.br
+.br
+# GUID   Switch Name
+.br
+0x0008f10400411a08 "SW1  (Rack  3) ISR9024 Voltaire 9024D"
+.br
+0x0008f10400411a28 "SW2  (Rack  3) ISR9024 Voltaire 9024D"
+.br
+0x0008f10400411a34 "SW3  (Rack  3) ISR9024 Voltaire 9024D"
+.br
+0x0008f104004119d0 "SW4  (Rack  3) ISR9024 Voltaire 9024D"
+.br
+
 .SH AUTHOR
 .TP
 Hal Rosenstock
 .RI < halr at voltaire.com >
+.TP
+Ira Weiny
+.RI < weiny2 at llnl.gov >
diff --git a/diags/src/ibnetdiscover.c b/diags/src/ibnetdiscover.c
index ec47961..c0ed563 100644
--- a/diags/src/ibnetdiscover.c
+++ b/diags/src/ibnetdiscover.c
@@ -74,6 +74,9 @@ static FILE *f;
 
 static char *argv0 = "ibnetdiscover";
 
+static char *switch_map = NULL;
+static FILE *switch_map_fp = NULL;
+
 Node *nodesdist[MAXHOPS+1];     /* last is Ca list */
 Node *mynode;
 int maxhops_discovered = 0;
@@ -201,6 +204,68 @@ clean_nodedesc(char *nodedesc)
 	return (nodedesc);
 }
 
+/** =========================================================================
+ */
+static void
+open_switch_map(void)
+{
+	if (switch_map != NULL) {
+		switch_map_fp = fopen(switch_map, "r");
+		if (switch_map_fp == NULL) {
+			fprintf(stderr,
+				"WARNING failed to open switch map \"%s\" (%s)\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 void
 dump_endnode(ib_portid_t *path, char *prompt, Node *node, Port *port)
 {
@@ -454,7 +519,12 @@ void
 list_node(Node *node)
 {
 	char *node_type;
+	char *nodename = NULL;
 
+	if (node->type == SWITCH_NODE)
+		nodename = lookup_switch_name(node);
+	else
+		nodename = clean_nodedesc(node->nodedesc);
 	switch(node->type) {
 	case SWITCH_NODE:
 		node_type = "Switch";
@@ -472,7 +542,10 @@ list_node(Node *node)
 	fprintf(f, "%s\t : 0x%016" PRIx64 " ports %d devid 0x%x vendid 0x%x \"%s\"\n",
 		node_type,
 		node->nodeguid, node->numports, node->devid, node->vendid,
-		clean_nodedesc(node->nodedesc));
+		nodename);
+
+	if (nodename && (node->type == SWITCH_NODE))
+		free(nodename);
 }
 
 void
@@ -499,6 +572,7 @@ void
 out_switch(Node *node, int group)
 {
 	char *str;
+	char *nodename = NULL;
 
 	out_ids(node);
 	fprintf(f, "switchguid=0x%" PRIx64, node->nodeguid);
@@ -520,11 +594,17 @@ out_switch(Node *node, int group)
 		}
 	}
 
+	if (node->type == SWITCH_NODE)
+		nodename = lookup_switch_name(node);
+	else
+		nodename = clean_nodedesc(node->nodedesc);
 	fprintf(f, "\nSwitch\t%d %s\t\t# %s %s port 0 lid %d lmc %d\n",
 		node->numports, node_name(node),
-		clean_nodedesc(node->nodedesc),
+			nodename,
 		node->smaenhsp0 ? "enhanced" : "base",
 		node->smalid, node->smalmc);
+	if (nodename && (node->type == SWITCH_NODE))
+		free(nodename);
 }
 
 void
@@ -573,25 +653,37 @@ void
 out_switch_port(Port *port, int group)
 {
 	char *ext_port_str = NULL;
+	char *rem_nodename = NULL;
 
 	DEBUG("port %p:%d remoteport %p", port, port->portnum, port->remoteport);
 	fprintf(f, "[%d]", port->portnum);
+
 	ext_port_str = out_ext_port(port, group);
 	if (ext_port_str)
 		fprintf(f, "%s", ext_port_str);
+
+	if (port->remoteport->node->type == SWITCH_NODE)
+		rem_nodename = lookup_switch_name(port->remoteport->node);
+	else
+		rem_nodename = clean_nodedesc(port->remoteport->node->nodedesc);
+
 	ext_port_str = out_ext_port(port->remoteport, group);
 	fprintf(f, "\t%s[%d]%s\t\t# \"%s\" lid %d\n",
 		node_name(port->remoteport->node),
 		port->remoteport->portnum,
 		ext_port_str ? ext_port_str : "",
-		clean_nodedesc(port->remoteport->node->nodedesc),
+		rem_nodename,
 		port->remoteport->node->type == SWITCH_NODE ? port->remoteport->node->smalid : port->remoteport->lid);
+
+	if (rem_nodename && (port->remoteport->node->type == SWITCH_NODE))
+		free(rem_nodename);
 }
 
 void
 out_ca_port(Port *port, int group)
 {
 	char *str = NULL;
+	char *rem_nodename = NULL;
 
 	fprintf(f, "[%d]\t%s[%d]", port->portnum,
 		node_name(port->remoteport->node),
@@ -599,10 +691,16 @@ out_ca_port(Port *port, int group)
 	str = out_ext_port(port->remoteport, group);
 	if (str)
 		fprintf(f, "%s", str);
+
+	if (port->remoteport->node->type == SWITCH_NODE)
+		rem_nodename = lookup_switch_name(port->remoteport->node);
+	else
+		rem_nodename = clean_nodedesc(port->remoteport->node->nodedesc);
 	fprintf(f, "\t\t# lid %d lmc %d \"%s\" lid %d\n",
-		port->lid, port->lmc,
-		clean_nodedesc(port->remoteport->node->nodedesc),
+		port->lid, port->lmc, rem_nodename,
 		port->remoteport->node->type == SWITCH_NODE ? port->remoteport->node->smalid : port->remoteport->lid);
+	if (rem_nodename && (port->remoteport->node->type == SWITCH_NODE))
+		free(rem_nodename);
 }
 
 int
@@ -739,8 +837,9 @@ void
 usage(void)
 {
 	fprintf(stderr, "Usage: %s [-d(ebug)] -e(rr_show) -v(erbose) -s(how) -l(ist) -g(rouping) -H(ca_list) -S(witch_list) -V(ersion) -C ca_name -P ca_port "
-			"-t(imeout) timeout_ms] [<topology-file>]\n",
+			"-t(imeout) timeout_ms --switch-map switch-map] [<topology-file>]\n",
 			argv0);
+	fprintf(stderr, "       --switch-map <switch-map> specify a switch-map file\n");
 	exit(-1);
 }
 
@@ -768,6 +867,7 @@ main(int argc, char **argv)
 		{ "Hca_list", 0, 0, 'H'},
 		{ "Switch_list", 0, 0, 'S'},
 		{ "timeout", 1, 0, 't'},
+		{ "switch-map", 1, 0, 1},
 		{ "Version", 0, 0, 'V'},
 		{ "help", 0, 0, 'h'},
 		{ "usage", 0, 0, 'u'},
@@ -783,6 +883,9 @@ main(int argc, char **argv)
 		if ( ch == -1 )
 			break;
 		switch(ch) {
+		case 1:
+			switch_map = strdup(optarg);
+			break;
 		case 'C':
 			ca = optarg;
 			break;
@@ -836,6 +939,7 @@ main(int argc, char **argv)
 			IBERROR("can't open file %s for writing", argv[0]);
 
 	madrpc_init(ca, ca_port, mgmt_classes, 2);
+	open_switch_map();
 
 	if (discover(&my_portid) < 0)
 		IBERROR("discover");
@@ -845,5 +949,6 @@ main(int argc, char **argv)
 
 	dump_topology(list, group);
 
+	close_switch_map();
 	exit(0);
 }







More information about the general mailing list