def print_switch(sbn,args,switch): guid = (switch.ports[0].portGUID if args.port_guid else switch.ninf.nodeGUID); first = True; port0 = switch.get_port(0) for port,idx in switch.iterports(): if idx == 0: continue; pinf = port.pinf; if args.only_down: if pinf.portPhysicalState == IBA.PHYS_PORT_STATE_LINK_UP: continue; if first and not args.line_mode: print "Switch %s %s:"%(guid, IBA_describe.dstr(switch.desc,True)); first = False; if pinf.portPhysicalState != IBA.PHYS_PORT_STATE_LINK_UP: link = "%s/%s"%( IBA_describe.link_state(pinf.portState), IBA_describe.phys_link_state(pinf.portPhysicalState)); else: link = "%2ux %s %s/%s"%( IBA_describe.link_width(pinf.linkWidthActive), IBA_describe.link_speed(pinf.linkSpeedActive), IBA_describe.link_state(pinf.portState), IBA_describe.phys_link_state(pinf.portPhysicalState)); if args.additional: additional = " (HOQ:%u VL_Stall:%u)"%(pinf.HOQLife,pinf.VLStallCount); else: additional = ""; lhs = "%3d %4d[ ] ==(%s)%s"%(port0.LID,idx,link,additional); err = [] peer_port = sbn.topology.get(port); if peer_port is None: rhs = '[ ] "" ( )'; else: rhs = "%3d %4d[ ] %s"%( peer_port.to_end_port().LID,idx, IBA_describe.dstr(peer_port.parent.desc,True)); if better_possible(pinf.linkWidthSupported,peer_port.pinf.linkWidthSupported, pinf.linkWidthEnabled): err.append("Could be %sx"%( IBA_describe.link_width(1<<int(math.floor(math.log(pinf.linkWidthSupported,2)))))); if better_possible(pinf.linkSpeedSupported,peer_port.pinf.linkSpeedSupported, pinf.linkSpeedEnabled): err.append("Could be %s"%( IBA_describe.link_speed(1<<int(math.floor(math.log(pinf.linkSpeedSupported,2)))))); err = ",".join(err); if err: err = " (%s)"%(err); if args.line_mode: print "%s %s %-40s==> %s%s"%(guid, IBA_describe.dstr(switch.desc,True), lhs,rhs,err); else: print " %-40s==> %s%s"%(lhs,rhs,err);
def summary(sched, sbn, node): if isinstance(node, rdma.subnet.CA): print '%-8s: %s ports %u "%s"' % ("Ca", node.ninf.nodeGUID, node.ninf.numPorts, IBA_describe.dstr(node.desc)) elif isinstance(node, rdma.subnet.Switch): zport = node.ports[0] pinf = zport.pinf for port in node.ports: if port.pinf is not None: pinf = port.pinf break if pinf is None: path = sbn.get_path_smp(sched, zport) pinf = yield sched.SubnGet(IBA.SMPPortInfo, path) sbn.get_port_pinf(pinf, path=path, portIdx=0) print '%-8s: %s ports %u "%s" base port 0 lid %u lmc %u' % ( "Switch", node.ninf.nodeGUID, node.ninf.numPorts, IBA_describe.dstr(node.desc), zport.LID, pinf.LMC) elif isinstance(node, rdma.subnet.Router): print '%-8s: %s ports %u "%s"' % ("Router", node.ninf.nodeGUID, node.ninf.numPorts, IBA_describe.dstr(node.desc)) else: print '%-8s: %s ports %u "%s"' % ( "??%u" % (node.ninf.nodeType), node.ninf.nodeGUID, node.ninf.numPorts, IBA_describe.dstr(node.desc))
def summary(sched,sbn,node): if isinstance(node,rdma.subnet.CA): print '%-8s: %s ports %u "%s"'%( "Ca",node.ninf.nodeGUID,node.ninf.numPorts, IBA_describe.dstr(node.desc)); elif isinstance(node,rdma.subnet.Switch): zport = node.ports[0]; pinf = zport.pinf; for port in node.ports: if port.pinf is not None: pinf = port.pinf; break; if pinf is None: path = sbn.get_path_smp(sched,zport); pinf = yield sched.SubnGet(IBA.SMPPortInfo,path); sbn.get_port_pinf(pinf,path=path,portIdx=0); print '%-8s: %s ports %u "%s" base port 0 lid %u lmc %u'%( "Switch",node.ninf.nodeGUID,node.ninf.numPorts, IBA_describe.dstr(node.desc), zport.LID,pinf.LMC); elif isinstance(node,rdma.subnet.Router): print '%-8s: %s ports %u "%s"'%( "Router",node.ninf.nodeGUID,node.ninf.numPorts, IBA_describe.dstr(node.desc)); else: print '%-8s: %s ports %u "%s"'%( "??%u"%(node.ninf.nodeType),node.ninf.nodeGUID,node.ninf.numPorts, IBA_describe.dstr(node.desc));
def show_ca(dev): print "CA %r"%(dev.name); print "\tCA type: %s"%(dev.hca_type); print "\tNumber of ports: %s"%(len(dev.end_ports)); print "\tFirmware version: %s"%(IBA_describe.dstr(dev.fw_ver)); print "\tHardware version: %s"%(IBA_describe.dstr(dev.hw_ver)); print "\tNode GUID: %s"%(dev.node_guid); print "\tSystem image GUID: %s"%(dev.sys_image_guid);
def show_ca(dev): print "CA %r" % (dev.name) print "\tCA type: %s" % (dev.hca_type) print "\tNumber of ports: %s" % (len(dev.end_ports)) print "\tFirmware version: %s" % (IBA_describe.dstr(dev.fw_ver)) print "\tHardware version: %s" % (IBA_describe.dstr(dev.hw_ver)) print "\tNode GUID: %s" % (dev.node_guid) print "\tSystem image GUID: %s" % (dev.sys_image_guid)
def print_ibnetdiscover_single(sbn,node): ninf = node.ninf; print '''vendid=0x%x devid=0x%x sysimgguid=%s'''%(ninf.vendorID,ninf.deviceID,ninf.systemImageGUID) is_switch = False; if isinstance(node,rdma.subnet.CA): print '''caguid=%s Ca\t%u %s\t# "%s"'''%(ninf.nodeGUID,ninf.numPorts,as_node_name(node), IBA_describe.dstr(node.desc)); elif isinstance(node,rdma.subnet.Switch): is_switch = True; port = node.ports[0]; print '''switchguid=%s(%s) Switch\t%u %s\t# "%s" base port 0 lid %u lmc %u'''%\ (ninf.nodeGUID,port.portGUID,ninf.numPorts,as_node_name(node), IBA_describe.dstr(node.desc),port.LID or 0,port.pinf.LMC); elif isinstance(node,rdma.subnet.Router): print '''rtguid=%s Rt\t%u %s\t# "%s"'''%(ninf.nodeGUID,ninf.numPorts,as_node_name(node), IBA_describe.dstr(node.desc)); else: print '''nodeguid=%s ??%u\t%u %s\t# "%s"'''%(ninf.nodeGUID,ninf.nodeType,ninf.numPorts,as_node_name(node), IBA_describe.dstr(node.desc)); for port,idx in node.iterports(): peer = sbn.topology.get(port); if peer is None: continue; if port.pinf.linkSpeedExtActive == 0: if is_switch: print '[%s]\t%s\t# "%s" lid %u %ux%s'%( idx,as_port_name(peer),IBA_describe.dstr(peer.parent.desc), peer.to_end_port().LID or 0, IBA_describe.link_width(port.pinf.linkWidthActive), IBA_describe.link_speed(port.pinf.linkSpeedActive)); else: print '[%s](%s)\t%s\t# lid %u lmc %u "%s" %ux%s'%( idx,port.portGUID,as_port_name(peer), port.LID or 0,port.pinf.LMC, IBA_describe.dstr(peer.parent.desc), IBA_describe.link_width(port.pinf.linkWidthActive), IBA_describe.link_speed(port.pinf.linkSpeedActive)); else: if is_switch: print '[%s]\t%s\t# "%s" lid %u %ux%s'%( idx,as_port_name(peer),IBA_describe.dstr(peer.parent.desc), peer.to_end_port().LID or 0, IBA_describe.link_width(port.pinf.linkWidthActive), IBA_describe.link_speed_ext(port.pinf.linkSpeedExtActive)); else: print '[%s](%s)\t%s\t# lid %u lmc %u "%s" %ux%s'%( idx,port.portGUID,as_port_name(peer), port.LID or 0,port.pinf.LMC, IBA_describe.dstr(peer.parent.desc), IBA_describe.link_width(port.pinf.linkWidthActive), IBA_describe.link_speed_ext(port.pinf.linkSpeedExtActive));
def cmd_set_nodedesc(argv,o): """Set or display the node description for CAs. Usage: %prog [-v] [NAME] By default all CAs are altered, use -C or -P to select a single CA.""" o.add_option("-v",dest="view_all",action="store_true", help="Increase the verbosity level of diagnostic messages, each -v increases by 1.") o.add_option("-C","--Ca",dest="CA", help="RDMA device to use. Specify a device name or node GUID"); o.add_option("-P","--Port",dest="port", help="RDMA end port to use. Specify a GID, port GUID, DEVICE/PORT or port number."); (args,values) = o.parse_args(argv); dev = None if args.CA is not None: dev = rdma.get_device(args.CA); if dev is None and args.port is not None: dev = rdma.get_end_port(args.port).parent; if args.view_all or len(values) <= 0: for I in rdma.get_devices(): if dev is not None and I != dev: continue; print "%s: %s"%(I.name,IBA_describe.dstr(I.node_desc)) else: name = values[0].decode(); name = name.encode("utf-8"); for I in rdma.get_devices(): if dev is not None and I != dev: continue; with open(os.path.join(I._dir,"node_desc"),"w") as F: F.write(name); return True;
def print_header(ninf,pinf,desc,portIdx,failed,kind): if lib.args.verbosity >= 1 or failed or warnings: if desc: desc = " (%s) "%(IBA_describe.dstr(desc)); else: desc = ' '; if kind & KIND_PORT: print "Port check lid %u%sport %u:"%(pinf.LID,desc,portIdx), if kind & KIND_PERF: if portIdx == 0xFF: print "Error check lid %u%sall ports:"%(pinf.LID,desc), else: print "Error check lid %u%sport %u:"%(pinf.LID,desc,portIdx), if kind & KIND_CLEAR: if portIdx == 0xFF: print "Clear counters lid %u%sall ports:"%(pinf.LID,desc), else: print "Clear counters lid %u%sport %u:"%(pinf.LID,desc,portIdx), if kind & KIND_NODE: if ninf.nodeType == IBA.NODE_SWITCH: print "# Checking %s: nodeguid %s lid %s"%( IBA_describe.node_type(ninf.nodeType), ninf.nodeGUID,pinf.LID); else: print "# Checking %s: nodeguid %s lid %s port %u"%( IBA_describe.node_type(ninf.nodeType), ninf.nodeGUID,pinf.LID,portIdx); print "Node check lid %u:"%(pinf.LID), if failed is not None: print (red("FAILED") if failed else blue("WARNING") if warnings else green("OK")); for I in warnings: print blue("#warn: %s"%(I)); return not (failed or warnings);
def print_ibnetdiscover_single(sbn, node): ninf = node.ninf print '''vendid=0x%x devid=0x%x sysimgguid=%s''' % (ninf.vendorID, ninf.deviceID, ninf.systemImageGUID) is_switch = False if isinstance(node, rdma.subnet.CA): print '''caguid=%s Ca\t%u %s\t# "%s"''' % (ninf.nodeGUID, ninf.numPorts, as_node_name(node), IBA_describe.dstr(node.desc)) elif isinstance(node, rdma.subnet.Switch): is_switch = True port = node.ports[0] print '''switchguid=%s(%s) Switch\t%u %s\t# "%s" base port 0 lid %u lmc %u'''%\ (ninf.nodeGUID,port.portGUID,ninf.numPorts,as_node_name(node), IBA_describe.dstr(node.desc),port.LID or 0,port.pinf.LMC) elif isinstance(node, rdma.subnet.Router): print '''rtguid=%s Rt\t%u %s\t# "%s"''' % (ninf.nodeGUID, ninf.numPorts, as_node_name(node), IBA_describe.dstr(node.desc)) else: print '''nodeguid=%s ??%u\t%u %s\t# "%s"''' % (ninf.nodeGUID, ninf.nodeType, ninf.numPorts, as_node_name(node), IBA_describe.dstr(node.desc)) for port, idx in node.iterports(): peer = sbn.topology.get(port) if peer is None: continue if port.pinf.linkSpeedExtActive == 0: if is_switch: print '[%s]\t%s\t# "%s" lid %u %ux%s' % ( idx, as_port_name(peer), IBA_describe.dstr( peer.parent.desc), peer.to_end_port().LID or 0, IBA_describe.link_width(port.pinf.linkWidthActive), IBA_describe.link_speed(port.pinf.linkSpeedActive)) else: print '[%s](%s)\t%s\t# lid %u lmc %u "%s" %ux%s' % ( idx, port.portGUID, as_port_name(peer), port.LID or 0, port.pinf.LMC, IBA_describe.dstr(peer.parent.desc), IBA_describe.link_width(port.pinf.linkWidthActive), IBA_describe.link_speed(port.pinf.linkSpeedActive)) else: if is_switch: print '[%s]\t%s\t# "%s" lid %u %ux%s' % ( idx, as_port_name(peer), IBA_describe.dstr( peer.parent.desc), peer.to_end_port().LID or 0, IBA_describe.link_width(port.pinf.linkWidthActive), IBA_describe.link_speed_ext(port.pinf.linkSpeedExtActive)) else: print '[%s](%s)\t%s\t# lid %u lmc %u "%s" %ux%s' % ( idx, port.portGUID, as_port_name(peer), port.LID or 0, port.pinf.LMC, IBA_describe.dstr(peer.parent.desc), IBA_describe.link_width(port.pinf.linkWidthActive), IBA_describe.link_speed_ext(port.pinf.linkSpeedExtActive))
def step(out_port, nport): nport_ep = nport.to_end_port() print "[%u] -> %s port %s[%u] lid %u/%u %s" % ( out_port.port_id, IBA_describe.node_type( nport.parent.ninf.nodeType), nport_ep.portGUID, nport.port_id, nport_ep.LID, 16 - nport_ep.pinf.LMC, IBA_describe.dstr(nport.parent.desc, quotes=True))
def step(out_port,nport): nport_ep = nport.to_end_port(); print "[%u] -> %s port %s[%u] lid %u/%u %s"%( out_port.port_id, IBA_describe.node_type(nport.parent.ninf.nodeType), nport_ep.portGUID, nport.port_id, nport_ep.LID,16 - nport_ep.pinf.LMC, IBA_describe.dstr(nport.parent.desc,quotes=True));
def display_nodes(val): ports = set() for I in val: port = sbn.lids[I] if port is not None and (args.all_nodes == False or isinstance( port.parent, rdma.subnet.CA)): ports.add(port) ports = list(ports) ports.sort(key=lambda x: x.parent.desc) if o.verbosity >= 1: for I in ports: print ' %s lid %u "%s"' % (I.portGUID, I.LID, IBA_describe.dstr(I.parent.desc)) else: for I in ports: print ' %s' % (IBA_describe.dstr(I.parent.desc))
def display_nodes(val): ports = set(); for I in val: port = sbn.lids[I]; if port is not None and (args.all_nodes == False or isinstance(port.parent,rdma.subnet.CA)): ports.add(port); ports = list(ports); ports.sort(key=lambda x:x.parent.desc); if o.verbosity >= 1: for I in ports: print ' %s lid %u "%s"'%(I.portGUID,I.LID, IBA_describe.dstr(I.parent.desc)); else: for I in ports: print ' %s'%(IBA_describe.dstr(I.parent.desc));
def summary2(node): if isinstance(node, rdma.subnet.CA): kind = "Ca" elif isinstance(node, rdma.subnet.Switch): kind = "Switch" elif isinstance(node, rdma.subnet.Router): kind = "Router" else: kind = "??%u" % (node.ninf.nodeType) print '%-8s: %s ports %u devid 0x%x vendid 0x%x "%s"' % ( kind, node.ninf.nodeGUID, node.ninf.numPorts, node.ninf.deviceID, node.ninf.vendorID, IBA_describe.dstr(node.desc))
def summary2(node): if isinstance(node,rdma.subnet.CA): kind = "Ca"; elif isinstance(node,rdma.subnet.Switch): kind = "Switch"; elif isinstance(node,rdma.subnet.Router): kind = "Router"; else: kind = "??%u"%(node.ninf.nodeType); print '%-8s: %s ports %u devid 0x%x vendid 0x%x "%s"'%( kind,node.ninf.nodeGUID,node.ninf.numPorts, node.ninf.deviceID,node.ninf.vendorID, IBA_describe.dstr(node.desc));
def print_header(ninf, pinf, desc, portIdx, failed, kind): if lib.args.verbosity >= 1 or failed or warnings: if desc: desc = " (%s) " % (IBA_describe.dstr(desc)) else: desc = ' ' if kind & KIND_PORT: print "Port check lid %u%sport %u:" % (pinf.LID, desc, portIdx), if kind & KIND_PERF: if portIdx == 0xFF: print "Error check lid %u%sall ports:" % (pinf.LID, desc), else: print "Error check lid %u%sport %u:" % (pinf.LID, desc, portIdx), if kind & KIND_CLEAR: if portIdx == 0xFF: print "Clear counters lid %u%sall ports:" % (pinf.LID, desc), else: print "Clear counters lid %u%sport %u:" % (pinf.LID, desc, portIdx), if kind & KIND_NODE: if ninf.nodeType == IBA.NODE_SWITCH: print "# Checking %s: nodeguid %s lid %s" % ( IBA_describe.node_type( ninf.nodeType), ninf.nodeGUID, pinf.LID) else: print "# Checking %s: nodeguid %s lid %s port %u" % ( IBA_describe.node_type( ninf.nodeType), ninf.nodeGUID, pinf.LID, portIdx) print "Node check lid %u:" % (pinf.LID), if failed is not None: print( red("FAILED") if failed else blue("WARNING") if warnings else green("OK")) for I in warnings: print blue("#warn: %s" % (I)) return not (failed or warnings)
def cmd_ibfindnodesusing(argv,o): """Display the LFT forwarding tables relative to a single link. Usage: %prog TARGET PORT Use -v to display GUID and LID information for the routed end ports.""" LibIBOpts.setup(o,address=True,discovery=True); o.add_option("-a","--all",action="store_true",dest="all_nodes", help="Display all routed end ports, not just CAs"); (args,values) = o.parse_args(argv,expected_values=2); lib = LibIBOpts(o,args,values,2,(tmpl_target,tmpl_int)); args.do_mfdb = False; args.do_lfdb = True; args.port = values[1]; def display_nodes(val): ports = set(); for I in val: port = sbn.lids[I]; if port is not None and (args.all_nodes == False or isinstance(port.parent,rdma.subnet.CA)): ports.add(port); ports = list(ports); ports.sort(key=lambda x:x.parent.desc); if o.verbosity >= 1: for I in ports: print ' %s lid %u "%s"'%(I.portGUID,I.LID, IBA_describe.dstr(I.parent.desc)); else: for I in ports: print ' %s'%(IBA_describe.dstr(I.parent.desc)); with lib.get_umad_for_target(values[0]) as umad: path = lib.path; sched = lib.get_sched(umad,path); sbn = lib.get_subnet(sched); if isinstance(path,rdma.path.IBDRPath): sbn.lid_routed = False; sbn.paths = {}; sched.run(queue=get_switch(sched,sbn,args,path)); switch = sbn.path_to_port(path=path).parent; if args.port <= 0 or args.port > switch.ninf.numPorts: raise CmdError("Port %u is invalid, switch has %u ports"%( args.port,switch,ninf.numPorts)); print switch.desc port = switch.get_port(args.port); eport = port.to_end_port(); LIDs = set(LID for LID,port in enumerate(switch.lfdb) if port == args.port) sched.run(queue=rdma.discovery.topo_peer_SMP(sched,sbn,port)); pport = sbn.topology.get(port); if pport is None: raise CmdError("No link on port %u"%(args.port)); peport = pport.to_end_port(); pnode = pport.parent; if isinstance(pnode,rdma.subnet.Switch): ppath = sbn.get_path_smp(sched,pport.to_end_port()); sched.run(queue=pnode.get_switch_inf(sched,ppath)); sched.run(queue=pnode.get_switch_fdb(sched,True,False,ppath)); pportIdx = pnode.ports.index(pport); LIDs.update(LID for LID,port in enumerate(pnode.lfdb) if port == pportIdx); sched.run(queue=rdma.discovery.subnet_ninf_LIDS_SMP(sched,sbn,list(LIDs), True)); print '%s %u "%s" ==>> %s %u "%s"'%(eport.portGUID, switch.ports.index(port), IBA_describe.dstr(switch.desc), peport.portGUID, pnode.ports.index(pport), IBA_describe.dstr(pnode.desc)); display_nodes(LID for LID,port in enumerate(switch.lfdb) if port == args.port); print print '%s %u "%s" <<== %s %u "%s"'%(eport.portGUID, switch.ports.index(port), IBA_describe.dstr(switch.desc), peport.portGUID, pnode.ports.index(pport), IBA_describe.dstr(pnode.desc)); if not isinstance(pnode,rdma.subnet.Switch): print " ** Not a switch **"; else: display_nodes(LID for LID,port in enumerate(pnode.lfdb) if port == pportIdx); return lib.done();
def do_print(out,s): """Special printing for some things to look like libib.""" if isinstance(s,IBA.SANodeRecord): ninf = s.nodeInfo; desc = s.nodeDescription; s.nodeInfo = None; s.nodeDescription = None; if _format_args.get("name_map") is not None: args = copy.copy(_format_args); args["column"] = 24; else: args = _format_args; s.printer(out,**args); ninf.printer(out,**args); print >> out,"NodeDescription%s%s"%( "."*(args.get("column",33) - 15), IBA_describe.dstr(IBA_describe.description(desc.nodeString))); elif isinstance(s,IBA.SAPortInfoRecord): pinf = s.portInfo; s.portInfo = None; print "\tRID:" s.printer(out,**_format_args); print "\tPortInfo dump:" if _format_args.get("name_map") is not None: args = copy.copy(_format_args); args["name_map"] = libib_name_map_smpquery; args["colon"] = True; args["column"] = 33; else: args = _format_args; pinf.printer(out,**args); elif isinstance(s,IBA.SASwitchInfoRecord): sinf = s.switchInfo; s.switchInfo = None; print "\tRID:" s.printer(out,**_format_args); print "\tSwitchInfo dump:" if _format_args.get("name_map") is not None: args = copy.copy(_format_args); args["name_map"] = libib_name_map_smpquery; args["colon"] = True; args["column"] = 33; else: args = _format_args; sinf.printer(out,**args); elif isinstance(s,IBA.SAMulticastForwardingTableRecord): ft = s.multicastForwardingTable.portMaskBlock; s.multicastForwardingTable = None; s.printer(out,**_format_args); print >> out,"MFT:" print >> out,"MLID\tPort Mask" for I,v in enumerate(ft): print >> out,"0x%x\t0x%x"%(IBA.LID_MULTICAST + I + s.blockNum*32,v); elif isinstance(s,IBA.SALinearForwardingTableRecord): ft = s.linearForwardingTable.portBlock; s.linearForwardingTable = None; s.printer(out,**_format_args); print >> out,"LFT:" print >> out,"LID\tPort Number" for I,v in enumerate(ft): print >> out,"%u\t%u"%(I + s.blockNum*64,v); elif isinstance(s,IBA.SAPKeyTableRecord): pk = s.PKeyTable.PKeyBlock; s.PKeyTable = None; s.printer(out,**_format_args); print >> out,"PKey Table:" for num,I in enumerate(pk): if num % 8 == 0: if num != 0: print >> out; print >> out,"0x%04x"%(I), print >> out; elif isinstance(s,IBA.SAVLArbitrationTableRecord): vl = s.VLArbitrationTable.VLWeightBlock; s.VLArbitrationTable = None; s.printer(out,**_format_args); print >> out, "VL :" + "|".join(("%2u"%((I >> 8) & 0xF)) for I in vl[:16]) + "|"; print >> out, "Weight:" + "|".join(("%2u"%(I & 0xFF)) for I in vl[:16]) + "|"; print >> out, "VL :" + "|".join(("%2u"%((I >> 8) & 0xF)) for I in vl[16:]) + "|"; print >> out, "Weight:" + "|".join(("%2u"%(I & 0xFF)) for I in vl[16:]) + "|"; else: s.printer(out,**_format_args);
def cmd_ibfindnodesusing(argv, o): """Display the LFT forwarding tables relative to a single link. Usage: %prog TARGET PORT Use -v to display GUID and LID information for the routed end ports.""" LibIBOpts.setup(o, address=True, discovery=True) o.add_option("-a", "--all", action="store_true", dest="all_nodes", help="Display all routed end ports, not just CAs") (args, values) = o.parse_args(argv, expected_values=2) lib = LibIBOpts(o, args, values, 2, (tmpl_target, tmpl_int)) args.do_mfdb = False args.do_lfdb = True args.port = values[1] def display_nodes(val): ports = set() for I in val: port = sbn.lids[I] if port is not None and (args.all_nodes == False or isinstance( port.parent, rdma.subnet.CA)): ports.add(port) ports = list(ports) ports.sort(key=lambda x: x.parent.desc) if o.verbosity >= 1: for I in ports: print ' %s lid %u "%s"' % (I.portGUID, I.LID, IBA_describe.dstr(I.parent.desc)) else: for I in ports: print ' %s' % (IBA_describe.dstr(I.parent.desc)) with lib.get_umad_for_target(values[0]) as umad: path = lib.path sched = lib.get_sched(umad, path) sbn = lib.get_subnet(sched) if isinstance(path, rdma.path.IBDRPath): sbn.lid_routed = False sbn.paths = {} sched.run(queue=get_switch(sched, sbn, args, path)) switch = sbn.path_to_port(path=path).parent if args.port <= 0 or args.port > switch.ninf.numPorts: raise CmdError("Port %u is invalid, switch has %u ports" % (args.port, switch, ninf.numPorts)) print switch.desc port = switch.get_port(args.port) eport = port.to_end_port() LIDs = set(LID for LID, port in enumerate(switch.lfdb) if port == args.port) sched.run(queue=rdma.discovery.topo_peer_SMP(sched, sbn, port)) pport = sbn.topology.get(port) if pport is None: raise CmdError("No link on port %u" % (args.port)) peport = pport.to_end_port() pnode = pport.parent if isinstance(pnode, rdma.subnet.Switch): ppath = sbn.get_path_smp(sched, pport.to_end_port()) sched.run(queue=pnode.get_switch_inf(sched, ppath)) sched.run(queue=pnode.get_switch_fdb(sched, True, False, ppath)) pportIdx = pnode.ports.index(pport) LIDs.update(LID for LID, port in enumerate(pnode.lfdb) if port == pportIdx) sched.run(queue=rdma.discovery.subnet_ninf_LIDS_SMP( sched, sbn, list(LIDs), True)) print '%s %u "%s" ==>> %s %u "%s"' % ( eport.portGUID, switch.ports.index(port), IBA_describe.dstr(switch.desc), peport.portGUID, pnode.ports.index(pport), IBA_describe.dstr(pnode.desc)) display_nodes(LID for LID, port in enumerate(switch.lfdb) if port == args.port) print print '%s %u "%s" <<== %s %u "%s"' % ( eport.portGUID, switch.ports.index(port), IBA_describe.dstr(switch.desc), peport.portGUID, pnode.ports.index(pport), IBA_describe.dstr(pnode.desc)) if not isinstance(pnode, rdma.subnet.Switch): print " ** Not a switch **" else: display_nodes(LID for LID, port in enumerate(pnode.lfdb) if port == pportIdx) return lib.done()
def print_switch(sbn, args, switch): guid = (switch.ports[0].portGUID if args.port_guid else switch.ninf.nodeGUID) first = True port0 = switch.get_port(0) for port, idx in switch.iterports(): if idx == 0: continue pinf = port.pinf if args.only_down: if pinf.portPhysicalState == IBA.PHYS_PORT_STATE_LINK_UP: continue if args.only_up: if pinf.portPhysicalState == IBA.PHYS_PORT_STATE_POLLING: continue if first and not args.line_mode: print "Switch %s %s:" % (guid, IBA_describe.dstr( switch.desc, True)) first = False if pinf.portPhysicalState != IBA.PHYS_PORT_STATE_LINK_UP: link = "%s/%s" % (IBA_describe.link_state(pinf.portState), IBA_describe.phys_link_state( pinf.portPhysicalState)) else: if pinf.linkSpeedExtActive == 0: link = "%2ux %s %s/%s" % ( IBA_describe.link_width(pinf.linkWidthActive), IBA_describe.link_speed(pinf.linkSpeedActive), IBA_describe.link_state(pinf.portState), IBA_describe.phys_link_state(pinf.portPhysicalState)) else: link = "%2ux %s %s/%s" % ( IBA_describe.link_width(pinf.linkWidthActive), IBA_describe.link_speed_ext(pinf.linkSpeedExtActive), IBA_describe.link_state(pinf.portState), IBA_describe.phys_link_state(pinf.portPhysicalState)) if args.additional: additional = " (HOQ:%u VL_Stall:%u)" % (pinf.HOQLife, pinf.VLStallCount) else: additional = "" lhs = "%3d %4d[ ] ==(%s)%s" % (port0.LID, idx, link, additional) err = [] peer_port = sbn.topology.get(port) if peer_port is None: rhs = '[ ] "" ( )' else: rhs = "%3d %4d[ ] %s" % ( peer_port.to_end_port().LID, peer_port.port_id, IBA_describe.dstr(peer_port.parent.desc, True)) if better_possible(pinf.linkWidthSupported, peer_port.pinf.linkWidthSupported, pinf.linkWidthEnabled): err.append("Could be %sx" % (IBA_describe.link_width(1 << int( math.floor(math.log(pinf.linkWidthSupported, 2)))))) if (pinf.linkSpeedExtSupported != 0 and peer_port.pinf.linkSpeedExtSupported): if better_possible(pinf.linkSpeedExtSupported, peer_port.pinf.linkSpeedExtSupported, pinf.linkSpeedExtEnabled): err.append( "Could be %s" % (IBA_describe.link_speed_ext(1 << int( math.floor(math.log(pinf.linkSpeedExtSupported, 2)))))) else: if better_possible(pinf.linkSpeedSupported, peer_port.pinf.linkSpeedSupported, pinf.linkSpeedEnabled): err.append( "Could be %s" % (IBA_describe.link_speed(1 << int( math.floor(math.log(pinf.linkSpeedSupported, 2))))) ) err = ",".join(err) if err: err = " (%s)" % (err) if args.line_mode: print "%s %s %-40s==> %s%s" % ( guid, IBA_describe.dstr(switch.desc, True), lhs, rhs, err) else: print " %-40s==> %s%s" % (lhs, rhs, err)
def cmd_ibtracert(argv, o): """Show the route a path will take in the network Usage: %prog {TARGET}|{SOURCE TARGET} If SOURCE is not specified then the local end port is used. When tracing a multicast path the entire multicast spanning tree for the MLID is loaded, and the route that goes between start/end is printed""" LibIBOpts.setup(o, address=True, discovery=True) o.add_option("-r", "--reverse", action="store_true", dest="reverse", help="Swap source and target") o.add_option("-m", "--mlid", action="store", dest="mlid", type=int, help="Report on a multicast path") (args, values) = o.parse_args(argv) lib = LibIBOpts(o, args, values, 2, (tmpl_target, tmpl_target)) if len(values) <= 0: raise CmdError("Too few arguments") with lib.get_umad_for_target() as umad: sched = lib.get_sched(umad) sbn = lib.get_subnet(sched, ["all_SwitchInfo"]) # Index 0 is the source, 1 is the target, 2 is the first source if len(values) == 1: paths = [ rdma.path.IBPath(sched.end_port, SLID=sched.end_port.lid, DLID=sched.end_port.lid), values[0] ] spath, dpath = paths # If the target has source information then copy it in to the # source path. if dpath.SLID != 0: spath.DLID = dpath.SLID if dpath.SGID is not None: spath.DGID = dpath.SGID else: paths = list(values) if args.reverse: paths.reverse() # Resolve the paths to something usable paths = [resolve_path(umad, sbn, I) for I in paths] sched.run(mqueue=(rdma.discovery.subnet_get_port(sched, sbn, I) for I in paths)) ports = [sbn.path_to_port(I) for I in paths] # If we are starting at something other than a switch port, or our # local port then we need to have the connected switch port because we # cannot DR from a CA port. Simplest way to get this is to # trace to the target from the local port. sport = ports[0] dport = ports[1] if (not isinstance(sport.parent, rdma.subnet.Switch) and sport not in sbn.topology and sport.LID != paths[0].end_port.lid and not isinstance(paths[0], rdma.path.IBDRPath) and not isinstance(sched, rdma.satransactor.SATransactor)): if sbn.lid_routed: lpath = rdma.path.IBPath(sched.end_port, SLID=sched.end_port.lid, DLID=sched.end_port.lid, dqpn=0, sqpn=0, qkey=IBA.IB_DEFAULT_QP0_QKEY) else: lpath = rdma.path.IBDRPath(sched.end_port) if lib.debug >= 1: print "D: Figuring out route from local port to source" paths.append(lpath) sched.run(queue=rdma.discovery.subnet_get_port(sched, sbn, lpath)) lport = sbn.path_to_port(lpath) ports.append(lport) paths[0] = trace(umad, sched, sbn, lport, lpath, sport, paths[0], lambda x, y: None) # The target must be LID routed. if dport.LID == 0: raise CmdError("Target port %s does not have a valid LID" % (ports[2].portGUID)) if isinstance(paths[1], rdma.path.IBDRPath): paths[1] = rdma.path.IBPath(sched.end_port, DLID=ports[1].LID, dqpn=0, sqpn=0, qkey=IBA.IB_DEFAULT_QP0_QKEY) if lib.debug >= 1: for n, path, port in zip(("SRC", "DST", "START"), paths, ports): print "D: %s is %s (%s)" % (n, path, port.portGUID) print "From %s %s portnum %u LID %u/%u %s" % ( IBA_describe.node_type(sport.parent.ninf.nodeType), sport.portGUID, sport.port_id, sport.LID, 16 - sport.pinf.LMC, IBA_describe.dstr(sport.parent.desc, quotes=True)) def step(out_port, nport): nport_ep = nport.to_end_port() print "[%u] -> %s port %s[%u] lid %u/%u %s" % ( out_port.port_id, IBA_describe.node_type( nport.parent.ninf.nodeType), nport_ep.portGUID, nport.port_id, nport_ep.LID, 16 - nport_ep.pinf.LMC, IBA_describe.dstr(nport.parent.desc, quotes=True)) if args.mlid is not None: if args.mlid < IBA.LID_MULTICAST: raise CmdError("Multicast LID %r is invalid" % (args.mlid)) topo = fetch_mcast(sched, sbn, sport, paths[0], args.mlid) if lib.debug >= 1: print "D: Multicast spanning tree topology contains %u entries" % ( len(topo)) lst = trace_mcast(topo, ports[0], ports[1]) step(ports[0], topo[ports[0]]) for I in lst: step(I, topo[I]) else: trace(umad, sched, sbn, ports[0], paths[0], ports[1], paths[1], step) print "To %s %s portnum %u LID %u/%u %s" % ( IBA_describe.node_type(dport.parent.ninf.nodeType), dport.portGUID, dport.port_id, paths[1].DLID, 16 - dport.pinf.LMC, IBA_describe.dstr(dport.parent.desc, quotes=True)) return lib.done()
def cmd_ibtracert(argv,o): """Show the route a path will take in the network Usage: %prog {TARGET}|{SOURCE TARGET} If SOURCE is not specified then the local end port is used. When tracing a multicast path the entire multicast spanning tree for the MLID is loaded, and the route that goes between start/end is printed""" LibIBOpts.setup(o,address=True,discovery=True); o.add_option("-r","--reverse",action="store_true",dest="reverse", help="Swap source and target"); o.add_option("-m","--mlid",action="store",dest="mlid", type=int, help="Report on a multicast path"); (args,values) = o.parse_args(argv); lib = LibIBOpts(o,args,values,2,(tmpl_target,tmpl_target)); if len(values) <= 0: raise CmdError("Too few arguments"); with lib.get_umad_for_target() as umad: sched = lib.get_sched(umad); sbn = lib.get_subnet(sched,["all_SwitchInfo"]); # Index 0 is the source, 1 is the target, 2 is the first source if len(values) == 1: paths = [rdma.path.IBPath(sched.end_port, SLID=sched.end_port.lid, DLID=sched.end_port.lid), values[0]]; spath,dpath = paths; # If the target has source information then copy it in to the # source path. if dpath.SLID != 0: spath.DLID = dpath.SLID; if dpath.SGID is not None: spath.DGID = dpath.SGID; else: paths = list(values); if args.reverse: paths.reverse(); # Resolve the paths to something usable paths = [resolve_path(umad,sbn,I) for I in paths]; sched.run(mqueue=(rdma.discovery.subnet_get_port(sched,sbn,I) for I in paths)); ports = [sbn.path_to_port(I) for I in paths]; # If we are starting at something other than a switch port, or our # local port then we need to have the connected switch port because we # cannot DR from a CA port. Simplest way to get this is to # trace to the target from the local port. sport = ports[0]; dport = ports[1]; if (not isinstance(sport.parent,rdma.subnet.Switch) and sport not in sbn.topology and sport.LID != paths[0].end_port.lid and not isinstance(paths[0],rdma.path.IBDRPath) and not isinstance(sched,rdma.satransactor.SATransactor)): if sbn.lid_routed: lpath = rdma.path.IBPath(sched.end_port,SLID=sched.end_port.lid, DLID=sched.end_port.lid, dqpn=0,sqpn=0,qkey=IBA.IB_DEFAULT_QP0_QKEY); else: lpath = rdma.path.IBDRPath(sched.end_port); if lib.debug >= 1: print "D: Figuring out route from local port to source" paths.append(lpath); sched.run(queue=rdma.discovery.subnet_get_port(sched,sbn,lpath)); lport = sbn.path_to_port(lpath); ports.append(lport); paths[0] = trace(umad,sched,sbn,lport,lpath,sport,paths[0], lambda x,y: None) # The target must be LID routed. if dport.LID == 0: raise CmdError("Target port %s does not have a valid LID"%( ports[2].portGUID)); if isinstance(paths[1],rdma.path.IBDRPath): paths[1] = rdma.path.IBPath(sched.end_port, DLID=ports[1].LID, dqpn=0,sqpn=0, qkey=IBA.IB_DEFAULT_QP0_QKEY); if lib.debug >= 1: for n,path,port in zip(("SRC","DST","START"),paths,ports): print "D: %s is %s (%s)"%(n,path,port.portGUID); print "From %s %s portnum %u LID %u/%u %s"%( IBA_describe.node_type(sport.parent.ninf.nodeType), sport.portGUID,sport.port_id, sport.LID,16-sport.pinf.LMC, IBA_describe.dstr(sport.parent.desc,quotes=True)); def step(out_port,nport): nport_ep = nport.to_end_port(); print "[%u] -> %s port %s[%u] lid %u/%u %s"%( out_port.port_id, IBA_describe.node_type(nport.parent.ninf.nodeType), nport_ep.portGUID, nport.port_id, nport_ep.LID,16 - nport_ep.pinf.LMC, IBA_describe.dstr(nport.parent.desc,quotes=True)); if args.mlid is not None: if args.mlid < IBA.LID_MULTICAST: raise CmdError("Multicast LID %r is invalid"%(args.mlid)); topo = fetch_mcast(sched,sbn,sport,paths[0],args.mlid); if lib.debug >= 1: print "D: Multicast spanning tree topology contains %u entries"%(len(topo)) lst = trace_mcast(topo,ports[0],ports[1]); step(ports[0],topo[ports[0]]); for I in lst: step(I,topo[I]); else: trace(umad,sched,sbn,ports[0],paths[0],ports[1],paths[1],step); print "To %s %s portnum %u LID %u/%u %s"%( IBA_describe.node_type(dport.parent.ninf.nodeType), dport.portGUID,dport.port_id, paths[1].DLID,16-dport.pinf.LMC, IBA_describe.dstr(dport.parent.desc,quotes=True)); return lib.done();
def do_print(out, s): """Special printing for some things to look like libib.""" if isinstance(s, IBA.SANodeRecord): ninf = s.nodeInfo desc = s.nodeDescription s.nodeInfo = None s.nodeDescription = None if _format_args.get("name_map") is not None: args = copy.copy(_format_args) args["column"] = 24 else: args = _format_args s.printer(out, **args) ninf.printer(out, **args) print >> out, "NodeDescription%s%s" % ( "." * (args.get("column", 33) - 15), IBA_describe.dstr(IBA_describe.description(desc.nodeString))) elif isinstance(s, IBA.SAPortInfoRecord): pinf = s.portInfo s.portInfo = None print "\tRID:" s.printer(out, **_format_args) print "\tPortInfo dump:" if _format_args.get("name_map") is not None: args = copy.copy(_format_args) args["name_map"] = libib_name_map_smpquery args["colon"] = True args["column"] = 33 else: args = _format_args pinf.printer(out, **args) elif isinstance(s, IBA.SASwitchInfoRecord): sinf = s.switchInfo s.switchInfo = None print "\tRID:" s.printer(out, **_format_args) print "\tSwitchInfo dump:" if _format_args.get("name_map") is not None: args = copy.copy(_format_args) args["name_map"] = libib_name_map_smpquery args["colon"] = True args["column"] = 33 else: args = _format_args sinf.printer(out, **args) elif isinstance(s, IBA.SAMulticastForwardingTableRecord): ft = s.multicastForwardingTable.portMaskBlock s.multicastForwardingTable = None s.printer(out, **_format_args) print >> out, "MFT:" print >> out, "MLID\tPort Mask" for I, v in enumerate(ft): print >> out, "0x%x\t0x%x" % (IBA.LID_MULTICAST + I + s.blockNum * 32, v) elif isinstance(s, IBA.SALinearForwardingTableRecord): ft = s.linearForwardingTable.portBlock s.linearForwardingTable = None s.printer(out, **_format_args) print >> out, "LFT:" print >> out, "LID\tPort Number" for I, v in enumerate(ft): print >> out, "%u\t%u" % (I + s.blockNum * 64, v) elif isinstance(s, IBA.SAPKeyTableRecord): pk = s.PKeyTable.PKeyBlock s.PKeyTable = None s.printer(out, **_format_args) print >> out, "PKey Table:" for num, I in enumerate(pk): if num % 8 == 0: if num != 0: print >> out print >> out, "0x%04x" % (I), print >> out elif isinstance(s, IBA.SAVLArbitrationTableRecord): vl = s.VLArbitrationTable.VLWeightBlock s.VLArbitrationTable = None s.printer(out, **_format_args) print >> out, "VL :" + "|".join( ("%2u" % ((I >> 8) & 0xF)) for I in vl[:16]) + "|" print >> out, "Weight:" + "|".join( ("%2u" % (I & 0xFF)) for I in vl[:16]) + "|" print >> out, "VL :" + "|".join( ("%2u" % ((I >> 8) & 0xF)) for I in vl[16:]) + "|" print >> out, "Weight:" + "|".join( ("%2u" % (I & 0xFF)) for I in vl[16:]) + "|" else: s.printer(out, **_format_args)