ib-mgmt: update to 518083dc46963eb5fb48855acbe2b351ce7361f8
[mirror/winof/.git] / tools / infiniband-diags / src / ibnetdiscover.c
1 /*
2  * Copyright (c) 2004-2008 Voltaire Inc.  All rights reserved.
3  * Copyright (c) 2007 Xsigo Systems Inc.  All rights reserved.
4  * Copyright (c) 2008 Lawrence Livermore National Lab.  All rights reserved.
5  *
6  * This software is available to you under a choice of one of two
7  * licenses.  You may choose to be licensed under the terms of the GNU
8  * General Public License (GPL) Version 2, available from the file
9  * COPYING in the main directory of this source tree, or the
10  * OpenIB.org BSD license below:
11  *
12  *     Redistribution and use in source and binary forms, with or
13  *     without modification, are permitted provided that the following
14  *     conditions are met:
15  *
16  *      - Redistributions of source code must retain the above
17  *        copyright notice, this list of conditions and the following
18  *        disclaimer.
19  *
20  *      - Redistributions in binary form must reproduce the above
21  *        copyright notice, this list of conditions and the following
22  *        disclaimer in the documentation and/or other materials
23  *        provided with the distribution.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32  * SOFTWARE.
33  *
34  */
35
36 #if HAVE_CONFIG_H
37 #  include <config.h>
38 #endif /* HAVE_CONFIG_H */
39
40 #define _GNU_SOURCE
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <unistd.h>
44 #include <time.h>
45 #include <string.h>
46 #include <getopt.h>
47 #include <inttypes.h>
48
49 #include <infiniband/umad.h>
50 #include <infiniband/mad.h>
51 #include <complib/cl_nodenamemap.h>
52 #include <infiniband/ibnetdisc.h>
53
54 #include "ibdiag_common.h"
55
56 #define LIST_CA_NODE     (1 << IB_NODE_CA)
57 #define LIST_SWITCH_NODE (1 << IB_NODE_SWITCH)
58 #define LIST_ROUTER_NODE (1 << IB_NODE_ROUTER)
59
60 struct ibmad_port *srcport;
61
62 static int timeout = 2000;              /* ms */
63 static FILE *f;
64
65 static char *node_name_map_file = NULL;
66 static nn_map_t *node_name_map = NULL;
67
68 /**
69  * Define our own conversion functions to maintain compatibility with the old
70  * ibnetdiscover which did not use the ibmad conversion functions.
71  */
72 char *dump_linkspeed_compat(uint32_t speed)
73 {
74         switch (speed) {
75         case 1:
76                 return ("SDR");
77                 break;
78         case 2:
79                 return ("DDR");
80                 break;
81         case 4:
82                 return ("QDR");
83                 break;
84         }
85         return ("???");
86 }
87
88 char *dump_linkwidth_compat(uint32_t width)
89 {
90         switch (width) {
91         case 1:
92                 return ("1x");
93                 break;
94         case 2:
95                 return ("4x");
96                 break;
97         case 4:
98                 return ("8x");
99                 break;
100         case 8:
101                 return ("12x");
102                 break;
103         }
104         return ("??");
105 }
106
107 static inline const char*
108 ports_nt_str_compat(ibnd_node_t *node)
109 {
110         switch(node->type) {
111         case IB_NODE_SWITCH: return "SW";
112         case IB_NODE_CA:     return "CA";
113         case IB_NODE_ROUTER: return "RT";
114         }
115         return "??";
116 }
117
118 char *
119 node_name(ibnd_node_t *node)
120 {
121         static char buf[256];
122
123         switch(node->type) {
124         case IB_NODE_SWITCH:
125                 sprintf(buf, "\"%s", "S");
126                 break;
127         case IB_NODE_CA:
128                 sprintf(buf, "\"%s", "H");
129                 break;
130         case IB_NODE_ROUTER:
131                 sprintf(buf, "\"%s", "R");
132                 break;
133         default:
134                 sprintf(buf, "\"%s", "?");
135                 break;
136         }
137         sprintf(buf+2, "-%016" PRIx64 "\"", node->guid);
138
139         return buf;
140 }
141
142 void
143 list_node(ibnd_node_t *node, void *user_data)
144 {
145         char *node_type;
146         char *nodename = remap_node_name(node_name_map, node->guid,
147                                          node->nodedesc);
148
149         switch(node->type) {
150         case IB_NODE_SWITCH:
151                 node_type = "Switch";
152                 break;
153         case IB_NODE_CA:
154                 node_type = "Ca";
155                 break;
156         case IB_NODE_ROUTER:
157                 node_type = "Router";
158                 break;
159         default:
160                 node_type = "???";
161                 break;
162         }
163         fprintf(f, "%s\t : 0x%016" PRIx64 " ports %d devid 0x%x vendid 0x%x \"%s\"\n",
164                 node_type, node->guid, node->numports,
165                 mad_get_field(node->info, 0, IB_NODE_DEVID_F),
166                 mad_get_field(node->info, 0, IB_NODE_VENDORID_F),
167                 nodename);
168
169         free(nodename);
170 }
171
172 void
173 list_nodes(ibnd_fabric_t *fabric, int list)
174 {
175         if (list & LIST_CA_NODE)
176                 ibnd_iter_nodes_type(fabric, list_node, IB_NODE_CA, NULL);
177         if (list & LIST_SWITCH_NODE)
178                 ibnd_iter_nodes_type(fabric, list_node, IB_NODE_SWITCH, NULL);
179         if (list & LIST_ROUTER_NODE)
180                 ibnd_iter_nodes_type(fabric, list_node, IB_NODE_ROUTER, NULL);
181 }
182
183 void
184 out_ids(ibnd_node_t *node, int group, char *chname)
185 {
186         uint64_t sysimgguid = mad_get_field64(node->info, 0, IB_NODE_SYSTEM_GUID_F);
187
188         fprintf(f, "\nvendid=0x%x\ndevid=0x%x\n",
189                 mad_get_field(node->info, 0, IB_NODE_VENDORID_F),
190                 mad_get_field(node->info, 0, IB_NODE_DEVID_F));
191         if (sysimgguid)
192                 fprintf(f, "sysimgguid=0x%" PRIx64, sysimgguid);
193         if (group && node->chassis && node->chassis->chassisnum) {
194                 fprintf(f, "\t\t# Chassis %d", node->chassis->chassisnum);
195                 if (chname)
196                         fprintf(f, " (%s)", clean_nodedesc(chname));
197                 if (ibnd_is_xsigo_tca(node->guid) && node->ports[1] &&
198                     node->ports[1]->remoteport)
199                         fprintf(f, " slot %d", node->ports[1]->remoteport->portnum);
200         }
201         fprintf(f, "\n");
202 }
203
204 uint64_t
205 out_chassis(ibnd_fabric_t *fabric, unsigned char chassisnum)
206 {
207         uint64_t guid;
208
209         fprintf(f, "\nChassis %u", chassisnum);
210         guid = ibnd_get_chassis_guid(fabric, chassisnum);
211         if (guid)
212                 fprintf(f, " (guid 0x%" PRIx64 ")", guid);
213         fprintf(f, "\n");
214         return guid;
215 }
216
217 void
218 out_switch(ibnd_node_t *node, int group, char *chname)
219 {
220         char *str;
221         char  str2[256];
222         char *nodename = NULL;
223
224         out_ids(node, group, chname);
225         fprintf(f, "switchguid=0x%" PRIx64, node->guid);
226         fprintf(f, "(%" PRIx64 ")", mad_get_field64(node->info, 0, IB_NODE_PORT_GUID_F));
227         if (group) {
228                 str = ibnd_get_chassis_type(node);
229                 if (str)
230                         fprintf(f, "%s ", str);
231                 str = ibnd_get_chassis_slot_str(node, str2, 256);
232                 if (str)
233                         fprintf(f, "%s", str);
234         }
235
236         nodename = remap_node_name(node_name_map, node->guid, node->nodedesc);
237
238         fprintf(f, "\nSwitch\t%d %s\t\t# \"%s\" %s port 0 lid %d lmc %d\n",
239                 node->numports, node_name(node), nodename,
240                 node->smaenhsp0 ? "enhanced" : "base",
241                 node->smalid, node->smalmc);
242
243         free(nodename);
244 }
245
246 void
247 out_ca(ibnd_node_t *node, int group, char *chname)
248 {
249         char *node_type;
250         char *node_type2;
251
252         out_ids(node, group, chname);
253         switch(node->type) {
254         case IB_NODE_CA:
255                 node_type = "ca";
256                 node_type2 = "Ca";
257                 break;
258         case IB_NODE_ROUTER:
259                 node_type = "rt";
260                 node_type2 = "Rt";
261                 break;
262         default:
263                 node_type = "???";
264                 node_type2 = "???";
265                 break;
266         }
267
268         fprintf(f, "%sguid=0x%" PRIx64 "\n", node_type, node->guid);
269         fprintf(f, "%s\t%d %s\t\t# \"%s\"",
270                 node_type2, node->numports, node_name(node),
271                 clean_nodedesc(node->nodedesc));
272         if (group && ibnd_is_xsigo_hca(node->guid))
273                 fprintf(f, " (scp)");
274         fprintf(f, "\n");
275 }
276
277 #define OUT_BUFFER_SIZE 16
278 static char *
279 out_ext_port(ibnd_port_t *port, int group)
280 {
281         static char mapping[OUT_BUFFER_SIZE];
282
283         if (group && port->ext_portnum != 0) {
284                 snprintf(mapping, OUT_BUFFER_SIZE,
285                         "[ext %d]", port->ext_portnum);
286                 return (mapping);
287         }
288
289         return (NULL);
290 }
291
292 void
293 out_switch_port(ibnd_port_t *port, int group)
294 {
295         char *ext_port_str = NULL;
296         char *rem_nodename = NULL;
297         uint32_t iwidth = mad_get_field(port->info, 0,
298                                         IB_PORT_LINK_WIDTH_ACTIVE_F);
299         uint32_t ispeed = mad_get_field(port->info, 0,
300                                         IB_PORT_LINK_SPEED_ACTIVE_F);
301
302         DEBUG("port %p:%d remoteport %p\n", port, port->portnum, port->remoteport);
303         fprintf(f, "[%d]", port->portnum);
304
305         ext_port_str = out_ext_port(port, group);
306         if (ext_port_str)
307                 fprintf(f, "%s", ext_port_str);
308
309         rem_nodename = remap_node_name(node_name_map,
310                                        port->remoteport->node->guid,
311                                        port->remoteport->node->nodedesc);
312
313         ext_port_str = out_ext_port(port->remoteport, group);
314         fprintf(f, "\t%s[%d]%s",
315                 node_name(port->remoteport->node), port->remoteport->portnum,
316                 ext_port_str ? ext_port_str : "");
317         if (port->remoteport->node->type != IB_NODE_SWITCH)
318                 fprintf(f, "(%" PRIx64 ") ", port->remoteport->guid);
319         fprintf(f, "\t\t# \"%s\" lid %d %s%s",
320                 rem_nodename,
321                 port->remoteport->node->type == IB_NODE_SWITCH ?
322                         port->remoteport->node->smalid :
323                         port->remoteport->base_lid,
324                         dump_linkwidth_compat(iwidth),
325                         dump_linkspeed_compat(ispeed));
326
327         if (ibnd_is_xsigo_tca(port->remoteport->guid))
328                 fprintf(f, " slot %d", port->portnum);
329         else if (ibnd_is_xsigo_hca(port->remoteport->guid))
330                 fprintf(f, " (scp)");
331         fprintf(f, "\n");
332
333         free(rem_nodename);
334 }
335
336 void
337 out_ca_port(ibnd_port_t *port, int group)
338 {
339         char *str = NULL;
340         char *rem_nodename = NULL;
341         uint32_t iwidth = mad_get_field(port->info, 0,
342                                         IB_PORT_LINK_WIDTH_ACTIVE_F);
343         uint32_t ispeed = mad_get_field(port->info, 0,
344                                         IB_PORT_LINK_SPEED_ACTIVE_F);
345
346         fprintf(f, "[%d]", port->portnum);
347         if (port->node->type != IB_NODE_SWITCH)
348                 fprintf(f, "(%" PRIx64 ") ", port->guid);
349         fprintf(f, "\t%s[%d]",
350                 node_name(port->remoteport->node), port->remoteport->portnum);
351         str = out_ext_port(port->remoteport, group);
352         if (str)
353                 fprintf(f, "%s", str);
354         if (port->remoteport->node->type != IB_NODE_SWITCH)
355                 fprintf(f, " (%" PRIx64 ") ", port->remoteport->guid);
356
357         rem_nodename = remap_node_name(node_name_map,
358                                        port->remoteport->node->guid,
359                                        port->remoteport->node->nodedesc);
360
361         fprintf(f, "\t\t# lid %d lmc %d \"%s\" lid %d %s%s\n",
362                 port->base_lid, port->lmc, rem_nodename,
363                 port->remoteport->node->type == IB_NODE_SWITCH ?
364                         port->remoteport->node->smalid :
365                         port->remoteport->base_lid,
366                 dump_linkwidth_compat(iwidth),
367                 dump_linkspeed_compat(ispeed));
368
369         free(rem_nodename);
370 }
371
372
373 struct iter_user_data {
374         int group;
375         int skip_chassis_nodes;
376 };
377
378 static void
379 switch_iter_func(ibnd_node_t *node, void *iter_user_data)
380 {
381         ibnd_port_t *port;
382         int p = 0;
383         struct iter_user_data *data = (struct iter_user_data *)iter_user_data;
384
385         DEBUG("SWITCH: node %p\n", node);
386
387         /* skip chassis based switches if flagged */
388         if (data->skip_chassis_nodes && node->chassis && node->chassis->chassisnum)
389                 return;
390
391         out_switch(node, data->group, NULL);
392         for (p = 1; p <= node->numports; p++) {
393                 port = node->ports[p];
394                 if (port && port->remoteport)
395                         out_switch_port(port, data->group);
396         }
397 }
398
399 static void
400 ca_iter_func(ibnd_node_t *node, void *iter_user_data)
401 {
402         ibnd_port_t *port;
403         int p = 0;
404         struct iter_user_data *data = (struct iter_user_data *)iter_user_data;
405
406         DEBUG("CA: node %p\n", node);
407         /* Now, skip chassis based CAs */
408         if (data->group && node->chassis && node->chassis->chassisnum)
409                 return;
410         out_ca(node, data->group, NULL);
411
412         for (p = 1; p <= node->numports; p++) {
413                 port = node->ports[p];
414                 if (port && port->remoteport)
415                         out_ca_port(port, data->group);
416         }
417 }
418
419 static void
420 router_iter_func(ibnd_node_t *node, void *iter_user_data)
421 {
422         ibnd_port_t *port;
423         int p = 0;
424         struct iter_user_data *data = (struct iter_user_data *)iter_user_data;
425
426         DEBUG("RT: node %p\n", node);
427         /* Now, skip chassis based RTs */
428         if (data->group && node->chassis &&
429             node->chassis->chassisnum)
430                 return;
431         out_ca(node, data->group, NULL);
432         for (p = 1; p <= node->numports; p++) {
433                 port = node->ports[p];
434                 if (port && port->remoteport)
435                         out_ca_port(port, data->group);
436         }
437 }
438
439 int
440 dump_topology(int group, ibnd_fabric_t *fabric)
441 {
442         ibnd_node_t *node;
443         ibnd_port_t *port;
444         int i = 0, p = 0;
445         time_t t = time(0);
446         uint64_t chguid;
447         char *chname = NULL;
448         struct iter_user_data iter_user_data;
449
450         fprintf(f, "#\n# Topology file: generated on %s#\n", ctime(&t));
451         fprintf(f, "# Max of %d hops discovered\n", fabric->maxhops_discovered);
452         fprintf(f, "# Initiated from node %016" PRIx64 " port %016" PRIx64 "\n",
453                 fabric->from_node->guid,
454                 mad_get_field64(fabric->from_node->info, 0, IB_NODE_PORT_GUID_F));
455
456         /* Make pass on switches */
457         if (group) {
458                 ibnd_chassis_t *ch = NULL;
459
460                 /* Chassis based switches first */
461                 for (ch = fabric->chassis; ch; ch = ch->next) {
462                         int n = 0;
463
464                         if (!ch->chassisnum)
465                                 continue;
466                         chguid = out_chassis(fabric, ch->chassisnum);
467
468                         chname = NULL;
469 /**
470  * Will this work for Xsigo?
471  */
472                         if (ibnd_is_xsigo_guid(chguid)) {
473                                 for (node = ch->nodes; node;
474                                                 node = node->next_chassis_node) {
475                                         if (ibnd_is_xsigo_hca(node->guid)) {
476                                                 chname = node->nodedesc;
477                                                 fprintf(f, "Hostname: %s\n", clean_nodedesc(node->nodedesc));
478                                         }
479                                 }
480                         }
481
482                         fprintf(f, "\n# Spine Nodes");
483                         for (n = 1; n <= SPINES_MAX_NUM; n++) {
484                                 if (ch->spinenode[n]) {
485                                         out_switch(ch->spinenode[n], group, chname);
486                                         for (p = 1; p <= ch->spinenode[n]->numports; p++) {
487                                                 port = ch->spinenode[n]->ports[p];
488                                                 if (port && port->remoteport)
489                                                         out_switch_port(port, group);
490                                         }
491                                 }
492                         }
493                         fprintf(f, "\n# Line Nodes");
494                         for (n = 1; n <= LINES_MAX_NUM; n++) {
495                                 if (ch->linenode[n]) {
496                                         out_switch(ch->linenode[n], group, chname);
497                                         for (p = 1; p <= ch->linenode[n]->numports; p++) {
498                                                 port = ch->linenode[n]->ports[p];
499                                                 if (port && port->remoteport)
500                                                         out_switch_port(port, group);
501                                         }
502                                 }
503                         }
504
505                         fprintf(f, "\n# Chassis Switches");
506                         for (node = ch->nodes; node;
507                              node = node->next_chassis_node) {
508                                 if (node->type == IB_NODE_SWITCH) {
509                                         out_switch(node, group, chname);
510                                         for (p = 1; p <= node->numports; p++) {
511                                                 port = node->ports[p];
512                                                 if (port && port->remoteport)
513                                                         out_switch_port(port, group);
514                                         }
515                                 }
516
517                         }
518
519                         fprintf(f, "\n# Chassis CAs");
520                         for (node = ch->nodes; node;
521                              node = node->next_chassis_node) {
522                                 if (node->type == IB_NODE_CA) {
523                                         out_ca(node, group, chname);
524                                         for (p = 1; p <= node->numports; p++) {
525                                                 port = node->ports[p];
526                                                 if (port && port->remoteport)
527                                                         out_ca_port(port, group);
528                                         }
529                                 }
530                         }
531
532                 }
533
534
535         } else { /* !group */
536                 iter_user_data.group = group;
537                 iter_user_data.skip_chassis_nodes = 0;
538                 ibnd_iter_nodes_type(fabric, switch_iter_func,
539                                      IB_NODE_SWITCH, &iter_user_data);
540         }
541
542         chname = NULL;
543         if (group) {
544                 iter_user_data.group = group;
545                 iter_user_data.skip_chassis_nodes = 1;
546
547                 fprintf(f, "\nNon-Chassis Nodes\n");
548
549                 ibnd_iter_nodes_type(fabric, switch_iter_func,
550                                      IB_NODE_SWITCH, &iter_user_data);
551         }
552
553         iter_user_data.group = group;
554         iter_user_data.skip_chassis_nodes = 0;
555         /* Make pass on CAs */
556         ibnd_iter_nodes_type(fabric, ca_iter_func, IB_NODE_CA, &iter_user_data);
557
558         /* Make pass on routers */
559         ibnd_iter_nodes_type(fabric, router_iter_func, IB_NODE_ROUTER,
560                              &iter_user_data);
561
562         return i;
563 }
564
565 void dump_ports_report (ibnd_node_t *node, void *user_data)
566 {
567         int p = 0;
568         ibnd_port_t *port = NULL;
569
570         /* for each port */
571         for (p = node->numports, port = node->ports[p]; p > 0;
572              port = node->ports[--p]) {
573                 uint32_t iwidth, ispeed;
574                 if (port == NULL)
575                         continue;
576                 iwidth = mad_get_field(port->info, 0, IB_PORT_LINK_WIDTH_ACTIVE_F);
577                 ispeed = mad_get_field(port->info, 0, IB_PORT_LINK_SPEED_ACTIVE_F);
578                 fprintf(stdout,
579                         "%2s %5d %2d 0x%016" PRIx64 " %s %s",
580                         ports_nt_str_compat(node),
581                         node->type == IB_NODE_SWITCH ?
582                                 node->smalid : port->base_lid,
583                         port->portnum, port->guid,
584                         dump_linkwidth_compat(iwidth),
585                         dump_linkspeed_compat(ispeed));
586                 if (port->remoteport)
587                         fprintf(stdout,
588                                 " - %2s %5d %2d 0x%016" PRIx64
589                                 " ( '%s' - '%s' )\n",
590                                 ports_nt_str_compat(port->remoteport->node),
591                                 port->remoteport->node->type == IB_NODE_SWITCH ?
592                                         port->remoteport->node->smalid :
593                                         port->remoteport->base_lid,
594                                 port->remoteport->portnum,
595                                 port->remoteport->guid, port->node->nodedesc,
596                                 port->remoteport->node->nodedesc);
597                 else
598                         fprintf(stdout, "%36s'%s'\n", "", port->node->nodedesc);
599         }
600 }
601
602 static int list, group, ports_report;
603
604 static int process_opt(void *context, int ch, char *optarg)
605 {
606         switch (ch) {
607         case 1:
608                 node_name_map_file = strdup(optarg);
609                 break;
610         case 's':
611                 ibnd_show_progress(1);
612                 break;
613         case 'l':
614                 list = LIST_CA_NODE | LIST_SWITCH_NODE | LIST_ROUTER_NODE;
615                 break;
616         case 'g':
617                 group = 1;
618                 break;
619         case 'S':
620                 list = LIST_SWITCH_NODE;
621                 break;
622         case 'H':
623                 list = LIST_CA_NODE;
624                 break;
625         case 'R':
626                 list = LIST_ROUTER_NODE;
627                 break;
628         case 'p':
629                 ports_report = 1;
630                 break;
631         default:
632                 return -1;
633         }
634
635         return 0;
636 }
637
638 int main(int argc, char **argv)
639 {
640         ibnd_fabric_t *fabric = NULL;
641
642         struct ibmad_port *ibmad_port;
643         int mgmt_classes[2] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS};
644
645         const struct ibdiag_opt opts[] = {
646                 { "show", 's', 0, NULL, "show more information" },
647                 { "list", 'l', 0, NULL, "list of connected nodes" },
648                 { "grouping", 'g', 0, NULL, "show grouping" },
649                 { "Hca_list", 'H', 0, NULL, "list of connected CAs" },
650                 { "Switch_list", 'S', 0, NULL, "list of connected switches" },
651                 { "Router_list", 'R', 0, NULL, "list of connected routers" },
652                 { "node-name-map", 1, 1, "<file>", "node name map file" },
653                 { "ports", 'p', 0, NULL, "obtain a ports report" },
654                 { 0 }
655         };
656         char usage_args[] = "[topology-file]";
657
658         ibdiag_process_opts(argc, argv, NULL, "sGDL", opts, process_opt,
659                             usage_args, NULL);
660
661         f = stdout;
662
663         argc -= optind;
664         argv += optind;
665
666         if (ibd_timeout)
667                 timeout = ibd_timeout;
668
669         if (ibverbose)
670                 ibnd_debug(1);
671
672         ibmad_port = mad_rpc_open_port(ibd_ca, ibd_ca_port, mgmt_classes, 2);
673         if (!ibmad_port)
674                 IBERROR("Failed to open %s port %d", ibd_ca, ibd_ca_port);
675
676         if (argc && !(f = fopen(argv[0], "w")))
677                 IBERROR("can't open file %s for writing", argv[0]);
678
679         node_name_map = open_node_name_map(node_name_map_file);
680
681         if ((fabric = ibnd_discover_fabric(ibmad_port, ibd_timeout, NULL, -1)) == NULL)
682                 IBERROR("discover failed\n");
683
684         if (ports_report)
685                 ibnd_iter_nodes(fabric,
686                                 dump_ports_report,
687                                 NULL);
688         else if (list)
689                 list_nodes(fabric, list);
690         else
691                 dump_topology(group, fabric);
692
693         ibnd_destroy_fabric(fabric);
694         close_node_name_map(node_name_map);
695         mad_rpc_close_port(ibmad_port);
696         exit(0);
697 }