示例#1
0
def subnet_ninf_SMP(sched,sbn,path,get_desc=True,use_sa=None,done_desc=None):
    """Coroutine to send SMPs to get :class:`~rdma.IBA.SMPNodeInfo` and
    :class:`~rdma.IBA.SMPNodeDescription`. The result of the co-routine
    is the same as :meth:`rdma.subnet.Subnet.get_node_ninf`. If *sched*
    is a :class:`rdma.satransactor.SATransactor` then the query is optimized
    into a combined node info/node description SA query."""
    if use_sa is None:
        use_sa = isinstance(sched,rdma.satransactor.SATransactor);

    if use_sa:
        req = IBA.ComponentMask(IBA.SANodeRecord());
        req.LID = yield sched.prepare_path_lid(path);
        ret = yield sched.SubnAdmGet(req);
        sched.result = sbn.get_node_ninf(ret.nodeInfo,path);
        sched.result[0].set_desc(ret.nodeDescription.nodeString);
        path._cached_node_type = ret.nodeInfo.nodeType;
    else:
        ninf = yield sched.SubnGet(IBA.SMPNodeInfo,path);
        result = sbn.get_node_ninf(ninf,path);
        sched.result = result;
        node,port = result

        if node.desc is not None or get_desc is False:
            return;
        if done_desc is not None:
            if node in done_desc:
                return;
            done_desc.add(node);
        sched.queue(node.get_desc(sched,path));
        sched.result = result;
示例#2
0
def set_mad_attr(attr, name, v):
    try:
        # Need to use eval because name could have dots in it.
        arg = eval("attr.%s" % (name))
    except AttributeError:
        raise CmdError("%r is not a valid attribute for %r" % (name, attr))
    try:
        if isinstance(arg, int) or isinstance(arg, long):
            v = int(v, 0)
        elif isinstance(arg, IBA.GID):
            v = IBA.GID(v)
        elif isinstance(arg, IBA.GUID):
            v = IBA.GUID(v)
        elif isinstance(arg, bytearray):
            v = v.decode("string_escape")
            if len(v) > len(arg):
                raise CmdError("String %r is too long, can only be up to %u" %
                               (v, len(arg)))
            if len(v) < len(arg):
                v = v + bytearray(len(arg) - len(v))
        elif isinstance(arg, list):
            raise CmdError("Lists currently cannot be set.")
        else:
            raise CmdError("Internal Error, I don't know what %s %r is." %
                           (type(arg), arg))
    except ValueError as err:
        raise CmdError("String %r did not parse: %s" % (v, err))
    exec "attr.%s = v" % (name)
 def describe(self):
     '''Return a short description of the RPC described by this format.'''
     kind = IBA.get_fmt_payload(*self.match);
     return '%s %s(%u.%u) %s(%u)'%(IBA.const_str('MAD_METHOD_',self.method,True),
                                   '??' if kind[0] is None else kind[0].__name__,
                                   self.mgmtClass,self.classVersion,
                                   '??' if kind[1] is None else kind[1].__name__,
                                   self.attributeID);
示例#4
0
 def describe(self):
     '''Return a short description of the RPC described by this format.'''
     kind = IBA.get_fmt_payload(*self.match);
     return '%s %s(%u.%u) %s(%u)'%(IBA.const_str('MAD_METHOD_',self.method,True),
                                   '??' if kind[0] is None else kind[0].__name__,
                                   self.mgmtClass,self.classVersion,
                                   '??' if kind[1] is None else kind[1].__name__,
                                   self.attributeID);
示例#5
0
 def _get_LFDB_SA(self, sched, path):
     """Coroutine to fetch the entire LFDB from the SA"""
     req = IBA.ComponentMask(IBA.SALinearForwardingTableRecord())
     req.LID = sched.get_path_lid(path)
     res = yield sched.SubnAdmGetTable(req)
     for I in res:
         idx = I.blockNum
         self.lfdb[idx * 64:idx * 64 + 64] = bytearray(
             I.linearForwardingTable.portBlock)
示例#6
0
def _subnet_fill_LIDs_SA(sched,sbn,LMC):
    """Coroutine to ask the SA for all the PortInfo's with LMC=LMC."""
    pinf = IBA.ComponentMask(IBA.SAPortInfoRecord())
    pinf.portInfo.LMC = LMC;
    res = yield sched.SubnAdmGetTable(pinf);
    if res:
        sbn.set_max_lid(max(I.endportLID for I in res));
    for I in res:
        assert I.endportLID == I.portInfo.LID;
        sbn.get_port_pinf(pinf,portIdx=I.portNum);
示例#7
0
def set_guid(lid,guid,slot):
    rec = IBA.SAGUIDInfoRecord();
    rec_cm = IBA.ComponentMask(rec);
    rec_cm.blockNum = slot//8;
    rec_cm.LID = lid;
    # ComponentMask does not handle this array correctly
    idx = slot - rec.blockNum*8;
    rec.GUIDInfo.GUIDBlock[idx] = IBA.GUID(guid);
    rec_cm.component_mask = rec_cm.component_mask | (1<<(rec.COMPONENT_MASK['GUIDInfo.GUIDBlock'] + idx));
    return rec_cm;
示例#8
0
 def test_fail(self):
     """Test valid get_end_port calls that fail."""
     devices = rdma.get_devices()
     dev = devices.first()
     self.assertRaises(rdma.RDMAError, rdma.get_end_port, IBA.GID("::"))
     self.assertRaises(rdma.RDMAError, rdma.get_end_port,
                       IBA.GUID("0000:0000:0000:0000"))
     self.assertRaises(rdma.RDMAError, rdma.get_end_port, "xxx")
     self.assertRaises(rdma.RDMAError, rdma.get_end_port,
                       "%s/99" % (dev.name))
示例#9
0
 def _subn_do(self,payload,path,attributeModifier,method):
     if isinstance(path,rdma.path.IBDRPath):
         fmt = IBA.SMPFormatDirected();
         fmt.drSLID = path.drSLID;
         fmt.drDLID = path.drDLID;
         fmt.initialPath[:len(path.drPath)] = path.drPath;
         fmt.hopCount = len(path.drPath)-1;
     else:
         fmt = IBA.SMPFormat();
     fmt.MKey = getattr(path,"MKey",0);
     return self._doMAD(fmt,payload,path,attributeModifier,method);
示例#10
0
 def _get_MFDB_SA(self, sched, path):
     """Coroutine to fetch the entire MFDB from the SA"""
     req = IBA.ComponentMask(IBA.SAMulticastForwardingTableRecord())
     req.LID = sched.get_path_lid(path)
     res = yield sched.SubnAdmGetTable(req)
     for inf in res:
         pos = inf.position
         idx = inf.blockNum
         for I, v in enumerate(inf.multicastForwardingTable.portMaskBlock):
             self.mfdb[idx * 32 +
                       I] = self.mfdb[idx * 32 + I] | (v << pos * 16)
示例#11
0
def subnet_ninf_GUID(sched,sbn,node_guid):
    """Coroutine to fetch a :class:`~rmda.IBA.SMPNodeInfo` record from the
    SA for a specific GUID and store it in *sbn*."""
    req = IBA.ComponentMask(IBA.SANodeRecord());
    req.nodeInfo.nodeGUID = node_guid;
    res = yield sched.SubnAdmGetTable(req);

    # The SM can return multiple records that match a nodeGUID, one for each port
    # on a CA. When it does this it must set the portGUID and localPortNum correctly
    # to match the LID in the RID.
    for I in res:
        np = sbn.get_node_ninf(I.nodeInfo,LID=I.LID);
        np[0].set_desc(I.nodeDescription.nodeString);
示例#12
0
 def ninf(self):
     try:
         return self.__dict__["ninf"];
     except KeyError:
         pass
     ninf = IBA.ComponentMask(IBA.SANodeRecord());
     ninf.LID = self.path.DLID;
     ninf = self.umad.SubnAdmGet(ninf);
     self.__dict__["ninf"] = ninf;
     if self.path.DGID is None:
         self.path.DGID = IBA.GID(prefix=IBA.GID_DEFAULT_PREFIX,
                                  guid=ninf.nodeInfo.portGUID);
     return ninf;
示例#13
0
    def test_odd_size(self):
        fmt = IBA.SMPFormatDirected()
        drPath = bytes("0" * 65)
        fmt.initialPath[:len(drPath)] = drPath
        test = bytearray(fmt.MAD_LENGTH)
        fmt.pack_into(test)
        assert (len(test) == 257)

        fmt2 = IBA.SMPFormatDirected(test)
        fmt.printer(sys.stdout)
        fmt.printer(sys.stdout, format="dotted")
        fmt2.printer(sys.stdout)
        fmt2.printer(sys.stdout, format="dotted")
示例#14
0
def _resolve_path_async(mad,path,reversible=False,properties=None):
    if path.end_port is None:
        path.end_port = mad.end_port;

    q = IBA.ComponentMask(IBA.SAPathRecord());
    if reversible:
        q.reversible = True;
    # FIXME: want to remove this line ...
    q.reversible = True;
    if path.SGID is not None:
        q.SGID = path.SGID;
    else:
        q.SGID = mad.end_port.default_gid;

    if path.DGID is not None:
        q.DGID = path.DGID;
    else:
        q.DLID = path.DLID;

    if properties:
        for k,v in properties.iteritems():
            setattr(q,k,v);

    try:
        rep = yield mad.SubnAdmGet(q);
    except rdma.MADClassError as err:
        if err.code == IBA.MAD_STATUS_SA_NO_RECORDS:
            raise SAPathNotFoundError("Failed getting path record for path %r."%(path),
                                      err);
        err.message("Failed getting path record for path %r."%(path));
        raise
    except rdma.MADError as err:
        err.message("Failed getting path record for path %r."%(path));
        raise

    path.DGID = rep.DGID;
    path.SGID = rep.SGID;
    path.DLID = rep.DLID;
    path.SLID = rep.SLID;
    path.flow_label = rep.flowLabel;
    path.hop_limit = rep.hopLimit;
    path.traffic_class = rep.TClass;
    path.pkey = rep.PKey;
    path.SL = rep.SL;
    path.MTU = rep.MTU;
    path.rate = rep.rate;
    path.has_grh = rep.hopLimit != 0;
    path.packet_life_time = rep.packetLifeTime;
    mad.result = path;
示例#15
0
def do_check_duplicates(sched, path, desc, pinf, port, sbn, **kwargs):
    """Coroutine to check that LIDs, port GUIDs and node GUIDs are not
    duplicated."""
    global all_lids
    global all_pguids
    global all_nguids

    for I in IBA.lid_lmc_range(pinf.LID, pinf.LMC):
        tport = all_lids.get(I)
        if tport is None:
            all_lids[I] = port
        else:
            if tport != port:
                raise CheckError("Duplicate LIDs found, %s %s, at %s" %
                                 (tport.portGUID, port.portGUID, desc))

    # Discovery will explode before it causes either of these..
    ng = port.parent.ninf.nodeGUID
    tnode = all_nguids.get(ng)
    if tnode is None:
        all_nguids[ng] = port.parent
    else:
        if tnode != port.parent:
            raise CheckError("Duplicate node GUIDs found, GUID %s at %s" %
                             (ng, desc))
    tport = all_pguids.get(port.portGUID)
    if tport is None:
        all_pguids[port.portGUID] = port
    else:
        if tport != port:
            raise CheckError("Duplicate port GUIDs found, GUID %s at %s" %
                             (port.portGUID, desc))
示例#16
0
def do_check_duplicates(sched,path,desc,pinf,port,sbn,**kwargs):
    """Coroutine to check that LIDs, port GUIDs and node GUIDs are not
    duplicated."""
    global all_lids
    global all_pguids
    global all_nguids

    for I in IBA.lid_lmc_range(pinf.LID,pinf.LMC):
        tport = all_lids.get(I);
        if tport is None:
            all_lids[I] = port;
        else:
            if tport != port:
                raise CheckError("Duplicate LIDs found, %s %s, at %s"%(
                    tport.portGUID,port.portGUID,desc));

    # Discovery will explode before it causes either of these..
    ng = port.parent.ninf.nodeGUID
    tnode = all_nguids.get(ng);
    if tnode is None:
        all_nguids[ng] = port.parent;
    else:
        if tnode != port.parent:
            raise CheckError("Duplicate node GUIDs found, GUID %s at %s"%(
                ng,desc));
    tport = all_pguids.get(port.portGUID);
    if tport is None:
        all_pguids[port.portGUID] = port;
    else:
        if tport != port:
            raise CheckError("Duplicate port GUIDs found, GUID %s at %s"%(
                port.portGUID,desc));
示例#17
0
def dumper_tracer(mt,kind,fmt=None,path=None,ret=None):
    """Logs full decoded packet dumps of what is happening to
    :data:`sys.stdout`.  Assign to
    :attr:`rdma.madtransactor.MADTransactor.trace_func`."""
    if kind == TRACE_COMPLETE:
        simple_tracer(mt,kind,fmt=fmt,path=path,ret=ret);
        print "D: Request",fmt.describe();
        fmt.printer(sys.stdout,header=False);
        if ret is not None:
            res = fmt.__class__(bytes(ret[0]));
            print "D: Reply",res.describe()
            res.printer(sys.stdout,header=False);
    if kind == TRACE_UNEXPECTED:
        simple_tracer(mt,kind,fmt=fmt,path=path,ret=ret);
        IBA.MADHeader(bytes(ret[0])).printer(sys.stdout);
    if kind == TRACE_RECEIVE:
        simple_tracer(mt,kind,fmt=fmt,path=path,ret=ret);
        if fmt is not None:
            print "D: Incoming request",fmt.describe();
            fmt.printer(sys.stdout,header=False);
    if kind == TRACE_REPLY:
        simple_tracer(mt,kind,fmt=fmt,path=path,ret=ret);
        if fmt is not None:
            print "D: Outgoing reply",fmt.describe();
            fmt.printer(sys.stdout,header=False);
示例#18
0
    def link_end_port(self,port,portIdx=None,nodeGUID=None,portGUID=None,
                      path=None,LID=None,LMC=0):
        """Use the provided information about *port* to update the database.

        Note: For switches *portIdx* must be 0."""
        assert(port == port.to_end_port());
        if (LID is None and path is not None and
            not isinstance(path,rdma.path.IBDRPath)):
            LID = path.DLID;

        node = port.parent;

        if portIdx is not None:
            node.set_port(portIdx,port);
        if portGUID is not None and port.portGUID is None:
            port.portGUID = portGUID;
            self.ports[portGUID] = port;
        if LID is not None:
            port.LID = LID;
            if LMC is None:
                LMC = 0;
            self.set_max_lid(LID + (1<<LMC)-1);
            for I in IBA.lid_lmc_range(LID,LMC):
                self.lids[I] = port;
        if path is not None:
            path._cached_subnet_end_port = port;
            # Since we know it, record the DGID into the path. This produces
            # error messages that include the DGID..
            if portGUID is not None and path.DGID is None:
                path.DGID = IBA.GID(prefix=IBA.GID_DEFAULT_PREFIX,
                                    guid=portGUID);
            if self.paths is not None:
                self.paths[port] = path;
        return port;
示例#19
0
    def _unpack_rcv(self):
        """Switch a UMAD AH back into an IBPath. Note this is only
        used for recv'd AH's where the meaning of the fields is altered.

        Our convention is that the path describes the packet headers as they
        existed on the wire, so this untwiddles things."""
        (sqpn,
         qkey,
         SLID,
         self.SL,
         DLID_bits,
         self.has_grh,
         DGID_index,
         self.hop_limit,
         self.traffic_class,
         self.SGID,
         flow_label,
         pkey_index) = \
         UMAD.ib_mad_addr_t.unpack(self._cached_umad_ah)
        self.sqpn = cpu_to_be32(sqpn)
        # There is no pkey validation for SMPs (see IBA figure 156), so the
        # pkey should always be the default NOTE: mtcha at least has been seen
        # to return random values for pkey_index on SMPs, which is why we need
        # this check.
        if self.dqpn != 0:
            self.pkey_index = pkey_index
        self.qkey = cpu_to_be32(qkey)
        self.DLID = DLID_bits | self.end_port.lid
        self.SLID = cpu_to_be16(SLID)
        if self.has_grh:
            self.SGID = IBA.GID(self.SGID, True)
            self.DGID = self.end_port.gids[DGID_index]
            self.flow_label = cpu_to_be32(flow_label)
        else:
            del self.SGID
示例#20
0
    def test_basic(self):
        print self.ctx.query_port();
        print self.ctx.query_device();
        pd = self.ctx.pd();
        print pd,repr(pd)
        cq = self.ctx.cq(100);
        print cq,repr(cq)
        try:
            cq.resize(200);
        except rdma.SysError as e:
            if e.errno != errno.ENOSYS:
                raise;
        self.assertEqual(cq.poll(),[]);
        comp = self.ctx.comp_channel();
        print comp,repr(comp)
        qp = pd.qp(ibv.IBV_QPT_UD,100,cq,100,cq);
        print qp,repr(qp)
        print qp.query(0xFFFF);
        mpath = rdma.path.IBPath(self.ctx.end_port,DLID=0xC000,
                                 DGID=IBA.GID("ff02::1"));
        qp.attach_mcast(mpath);
        qp.detach_mcast(mpath);
        buf = mmap.mmap(-1,4096);
        mr = pd.mr(buf,ibv.IBV_ACCESS_LOCAL_WRITE|ibv.IBV_ACCESS_REMOTE_WRITE);
        print mr,repr(mr)
        print "MR",mr.addr,mr.length,mr.lkey,mr.rkey
        self.assertRaises(TypeError,pd.ah,None);
        ah = pd.ah(self.end_port.sa_path);
        print ah,repr(ah)

        srq = pd.srq();
        print srq,repr(srq)
        print srq.query();
        srq.modify(100);
示例#21
0
def get_mad_path(mad,ep_addr,**kwargs):
    """Query the SA and return a path for *ep_addr*.

    This is a simplified query function to return MAD paths from the end port
    associated with *mad* to the destination *ep_addr*.  If *ep_addr* is a
    string then :func:`from_string` is called automatically, otherwise
    :func:`rdma.IBA.conv_ep_addr` is used. Thus this will accept a destination
    address string, an integer (DLID), :class:`~rdma.IBA.GID` (DGID) and
    :class:`~rdma.IBA.GUID` (DGID).

    This returns a single reversible path.

    If *mad* is an async instance then this routine returns a coroutine that
    will do the resolution, otherwise the new path is returned.

    :raises ValueError: If dest is not appropriate.
    :raises rdma.path.SAPathNotFoundError: If *ep_addr* was not found at the SA.
    :raises rdma.MADError: If the RPC failed in some way."""
    ty = type(ep_addr);
    if ty == str or ty == unicode:
        path = from_string(ep_addr,require_ep=mad.end_port);
        for k,v in kwargs.iteritems():
            setattr(path,k,v);
    else:
        ep_addr = IBA.conv_ep_addr(ep_addr);
        if isinstance(ep_addr,IBA.GID):
            path = IBPath(mad.end_port,DGID=ep_addr,**kwargs);
        else:
            path = IBPath(mad.end_port,DLID=ep_addr,**kwargs);

    return resolve_path(mad,path);
示例#22
0
def get_device(name=None):
    """Return a :class:`rdma.devices.Device` for the default device if name
    is ``None``, or for the device described by name.

    The device string format is one of:
      =========== ===================
      Format      Example
      =========== ===================
      device      mlx4_0
      Node GUID   0002:c903:0000:1491
      =========== ===================

    :rtype: :class:`rdma.devices.device`
    :raises rdma.RDMAError: If no matching device is found or name is invalid."""
    devices = get_devices()
    if len(devices) == 0:
        raise RDMAError("No RDMA devices found.")
    if name is None:
        return devices.first()

    # Port GUID
    import rdma.devices
    import rdma.IBA
    try:
        guid = IBA.GUID(name)
    except ValueError:
        pass
    else:
        return rdma.devices.find_node_guid(devices, guid)

    # Device name string
    try:
        return devices[name]
    except KeyError:
        raise RDMAError("RDMA device %r not found." % (name))
示例#23
0
def cmd_ibaddr(argv,o):
    """Display the GID and LID addresses for end ports.
       Usage: %prog [-glL] [TARGET]"""
    o.add_option("-l","--lid_show",action="store_true",dest="lid",
                 help="Show LID information");
    o.add_option("-L","--Lid_show",action="store_true",dest="lid",
                 help="Show LID information");
    o.add_option("-g","--gid_show",action="store_true",dest="gid",
                 help="Show GID information");
    LibIBOpts.setup(o);
    (args,values) = o.parse_args(argv);
    lib = LibIBOpts(o,args,values,1,(tmpl_target,));

    if not values:
        values = (None,);

    if args.lid is None and args.gid is None:
        args.lid = True;
        args.gid = True;

    with lib.get_umad_for_target(values[0]) as umad:
        path = lib.path;
        ninf = umad.SubnGet(IBA.SMPNodeInfo,path);
        path.DGID = IBA.GID(prefix=IBA.GID_DEFAULT_PREFIX,guid=ninf.portGUID);
        pinf = umad.SubnGet(IBA.SMPPortInfo,path,0);

        if args.gid:
            print "GID %s"%(path.DGID),
        if args.lid:
            print "LID start %u end %u"%(pinf.LID,pinf.LID + (1 << pinf.LMC)-1),
        print
    return lib.done();
示例#24
0
 def describe(self):
     '''Return a short description of the RPC described by this format.'''
     import rdma.IBA as IBA
     attr = IBA.ATTR_TO_STRUCT.get((self.__class__, self.attributeID))
     return '%s %s(%u.%u) %s(%u)' % (
         IBA.const_str('MAD_METHOD_', self.method, True),
         self.__class__.__name__, self.mgmtClass, self.classVersion,
         '??' if attr is None else attr.__name__, self.attributeID)
示例#25
0
def arg_pir(query, values):
    """[LID]/[PORT]"""
    s = fsplit(values[0], '/', 2)
    if s[0]:
        query.endportLID = IBA.conv_lid(s[0])
    if s[1]:
        query.portNum = int(s[1], 0)
    del values[0]
示例#26
0
def arg_pir(query,values):
    """[LID]/[PORT]"""
    s = fsplit(values[0],'/',2);
    if s[0]:
        query.endportLID = IBA.conv_lid(s[0]);
    if s[1]:
        query.portNum = int(s[1],0);
    del values[0];
示例#27
0
    def test_subnet(self):
        "Pickling Subnet objects"
        sbn = rdma.subnet.Subnet()

        pinf = IBA.SMPPortInfo()
        for I in range(1, 100):
            pinf.LID = I
            port = sbn.get_port_pinf(pinf, portIdx=0, LID=I)
            port.portGUID = IBA.GUID(0xDEADBEEF0000 | I)
            sbn.ports[port.portGUID] = port

        ret = pickle.dumps(sbn)
        tmp2 = pickle.loads(ret)

        self.assertEquals(len(sbn.all_nodes), len(tmp2.all_nodes))
        self.assertEquals(sorted(sbn.nodes.keys()), sorted(tmp2.nodes.keys()))
        self.assertEquals(sorted(sbn.ports.keys()), sorted(tmp2.ports.keys()))
示例#28
0
def arg_mft(query,values):
    """[lid]/[block]"""
    s = fsplit(values[0],'/',2);
    if s[0]:
        query.LID = IBA.conv_lid(s[0]);
    if s[1]:
        query.blockNum = int(s[1],0);
    del values[0];
示例#29
0
def arg_lft(query, values):
    """[lid]/[block]"""
    s = fsplit(values[0], '/', 2)
    if s[0]:
        query.LID = IBA.conv_lid(s[0])
    if s[1]:
        query.blockNum = int(s[1], 0)
    del values[0]
示例#30
0
 def describe(self):
     '''Return a short description of the RPC described by this format.'''
     import rdma.IBA as IBA
     attr = IBA.ATTR_TO_STRUCT.get((self.__class__,self.attributeID));
     return '%s %s(%u.%u) %s(%u)'%(IBA.const_str('MAD_METHOD_',self.method,True),
                                   self.__class__.__name__,
                                   self.mgmtClass,self.classVersion,
                                   '??' if attr is None else attr.__name__,
                                   self.attributeID);
示例#31
0
def arg_link(query, values):
    """[from_lid]/[from_port] [to_lid]/[to_port]"""
    s = fsplit(values[0], '/', 2)
    if s[0]:
        query.fromLID = IBA.conv_lid(s[0])
    if s[1]:
        query.fromPort = int(s[1], 0)
    del values[0]

    if not values:
        return

    s = fsplit(values[0], '/', 2)
    if s[0]:
        query.toLID = IBA.conv_lid(s[0])
    if s[1]:
        query.toPort = int(s[1], 0)
    del values[0]
示例#32
0
def subnet_ninf_SA(sched,sbn,node_type=None):
    """Coroutine to fetch all :class:`~rmda.IBA.SMPNodeInfo` records from the
    SA and store them in *sbn*."""
    req = IBA.ComponentMask(IBA.SANodeRecord());
    if node_type is not None:
        req.nodeInfo.nodeType = node_type;
    res = yield sched.SubnAdmGetTable(IBA.SANodeRecord());
    if res:
        sbn.set_max_lid(max(I.LID for I in res));
    for I in res:
        np = sbn.get_node_ninf(I.nodeInfo,LID=I.LID);
        np[0].set_desc(I.nodeDescription.nodeString);
    if node_type is None:
        sbn.loaded.add("all_NodeInfo");
        sbn.loaded.add("all_NodeDescription");
    else:
        sbn.loaded.add("all_NodeInfo %u"%(node_type));
        sbn.loaded.add("all_NodeDescription %u"%(node_type));
示例#33
0
 def _subn_adm_do(self,payload,path,attributeModifier,method,completer=None):
     if path is None:
         path = self.end_port.sa_path;
     fmt = IBA.SAFormat();
     if isinstance(payload,IBA.ComponentMask):
         fmt.componentMask = payload.component_mask;
         payload = payload.payload;
     fmt.SMKey = getattr(path,"SMKey",0);
     return self._doMAD(fmt,payload,path,attributeModifier,method,completer);
示例#34
0
def arg_link(query,values):
    """[from_lid]/[from_port] [to_lid]/[to_port]"""
    s = fsplit(values[0],'/',2);
    if s[0]:
        query.fromLID = IBA.conv_lid(s[0]);
    if s[1]:
        query.fromPort = int(s[1],0);
    del values[0];

    if not values:
        return;

    s = fsplit(values[0],'/',2);
    if s[0]:
        query.toLID = IBA.conv_lid(s[0]);
    if s[1]:
        query.toPort = int(s[1],0);
    del values[0];
示例#35
0
def find_port_gid(devices, gid):
    """Search the list *devices* for the end port with *gid*.

    :returns: (:class:`EndPort`,gid_index)
    :raises rdma.RDMAError: If no matching device is found."""
    # The link local prefix should always be valid
    if gid.prefix() == IBA.GUID(IBA.GID_DEFAULT_PREFIX):
        return find_port_guid(devices, gid.guid()), gid

    if gid.guid() == IBA.GUID(0):
        raise rdma.RDMAError("RDMA end port %r not found." % (gid))

    for I in devices:
        for J in I.end_ports:
            try:
                return (J, J.gids.index(gid))
            except ValueError:
                continue
    raise rdma.RDMAError("RDMA end port %r not found." % (gid))
示例#36
0
def arg_sl2vl(query,values):
    """[lid]/[in_port]/[out_port]"""
    s = fsplit(values[0],'/',3);
    if s[0]:
        query.LID = IBA.conv_lid(s[0]);
    if s[1]:
        query.inputPortNum = int(s[1],0);
    if s[2]:
        query.outputPortNum = int(s[2],0);
    del values[0];
示例#37
0
def arg_vlarb(query,values):
    """[lid]/[port]/[block]"""
    s = fsplit(values[0],'/',3);
    if s[0]:
        query.LID = IBA.conv_lid(s[0]);
    if s[1]:
        query.outputPortNum = int(s[1],0);
    if s[2]:
        query.blockNum = int(s[2],0);
    del values[0];
示例#38
0
def arg_sl2vl(query, values):
    """[lid]/[in_port]/[out_port]"""
    s = fsplit(values[0], '/', 3)
    if s[0]:
        query.LID = IBA.conv_lid(s[0])
    if s[1]:
        query.inputPortNum = int(s[1], 0)
    if s[2]:
        query.outputPortNum = int(s[2], 0)
    del values[0]
示例#39
0
 def __init__(self,req,code,**kwargs):
     import rdma.IBA as IBA;
     if isinstance(req,IBA.SAFormat):
         MADError.__init__(self,req=req,code=code,
                           msg="RPC %s got class specific error %s"%(
                 req.describe(),IBA.const_str("MAD_STATUS_SA_",code,True)),**kwargs);
     else:
         MADError.__init__(self,req=req,code=code,
                           msg="RPC %s got class specific error %u"%(
                 req.describe(),code),**kwargs);
示例#40
0
def arg_vlarb(query, values):
    """[lid]/[port]/[block]"""
    s = fsplit(values[0], '/', 3)
    if s[0]:
        query.LID = IBA.conv_lid(s[0])
    if s[1]:
        query.outputPortNum = int(s[1], 0)
    if s[2]:
        query.blockNum = int(s[2], 0)
    del values[0]
示例#41
0
    def parse_request(self,rbuf,path):
        """Parse a request packet into a format and data.

        :raises rdma.MADError: If the packet could not be parsed."""
        l = len(rbuf);
        if l <= IBA.MADHeader.MAD_LENGTH:
            raise rdma.MADError(req_buf=rbuf,path=path,
                                reply_status=0,
                                msg="Invalid request size.Got %u, expected at least %u"%(
                                    l,IBA.MADHeader.MAD_LENGTH));
        match = self.get_request_match_key(rbuf);
        if match[1] >> 8 != IBA.MAD_BASE_VERSION:
            raise rdma.MADError(req_buf=rbuf,path=path,
                                reply_status=IBA.MAD_STATUS_BAD_VERSION,
                                msg="Invalid base version, got key %r"%(match));
        kind = IBA.get_fmt_payload(*match);
        if kind[0] is None:
            for clsid,ver in IBA.CLASS_TO_STRUCT.iterkeys():
                if clsid == kind[0]:
                    raise rdma.MADError(req_buf=rbuf,path=path,
                                        reply_status=IBA.MAD_STATUS_BAD_VERSION,
                                        msg="Invalid class version, got key %r"%(match));
            raise rdma.MADError(req_buf=rbuf,path=path,
                                reply_status=IBA.MAD_STATUS_UNSUP_METHOD,
                                msg="Unsupported class ID, got key %r"%(match));
        if l != kind[0].MAD_LENGTH:
            raise rdma.MADError(req_buf=rbuf,path=path,
                                reply_status=0,
                                msg="Invalid request size.Got %u, expected %u"%(
                                    l,kind[0].MAD_LENGTH));

        # The try wrappers the unpack incase the MAD is busted somehow.
        try:
            fmt = kind[0](rbuf);
            if self.trace_func is not None:
                self.trace_func(self,TRACE_RECEIVE,fmt=fmt,path=path,
                                ret=(rbuf,path));
            if kind[1] is None:
                raise rdma.MADError(req=fmt,req_buf=rbuf,path=path,
                                    reply_status=IBA.MAD_STATUS_UNSUP_METHOD_ATTR_COMBO,
                                    msg="Unsupported attribute ID for %s, got key %r"%(
                                        fmt.describe(),match));
            return fmt,kind[1](fmt.data);
        except rdma.MADError:
            raise
        except:
            e = rdma.MADError(req_buf=rbuf,path=path,
                              reply_status=IBA.MAD_STATUS_INVALID_ATTR_OR_MODIFIER,
                              exc_info=sys.exc_info());
            raise rdma.MADError,e,e.exc_info[2]
示例#42
0
def cmd_decode_mad(argv,o):
    """Accept on stdin a hex dump of a MAD and pretty print it.
       Usage: %prog [-v]

       All spaces and newlines are removed from the input text, the
       result must be a single string of hex digits."""
    import libibtool.vendstruct
    libibtool.vendstruct.install_vend();
    o.add_option("-v","--verbosity",dest="verbosity",action="count",default=0,
                 help="Increase the verbosity level of diagnostic messages, each -v increases by 1.")
    o.add_option("-o","--offset",dest="offset",action="store",default=0,type=int,
                 help="Start at this offest before decoding.")
    o.add_option("-l",dest="lrh",action="store_true",
                 help="The data starts at the LRH, not the MAD header");
    o.add_option("--umad",dest="umad",action="store_true",
                 help="The data includes a kernel umad header, eg it is from /dev/infiniband/umadX");
    (args,values) = o.parse_args(argv,expected_values = 0);
    o.verbosity = args.verbosity;

    print "Input the MAD in HEX followed by Ctrl-D";
    inp = "".join(sys.stdin.readlines());
    if inp[0] == '"' or inp[0] == "'":
        bytes = inp.strip()[1:-1].decode("string_escape");
    else:
        inp = inp.replace(" ","").replace("\n","").replace("\r","").replace("\t","");
        if o.verbosity >= 2:
            print "Input HEX value is:\n  ",repr(inp);
        bytes = inp.decode("hex");
    bytes = bytes[args.offset:];
    if o.verbosity >= 2:
        print bytes.encode("hex");

    if args.umad:
        bytes = decode_umad(o,bytes);

    if args.lrh:
        bytes = decode_link(o,bytes);

    hdr = IBA.MADHeader(bytes);
    if o.verbosity >= 1:
        hdr.printer(sys.stdout);
    kind = IBA.get_fmt_payload(*rdma.madtransactor.MADTransactor.get_request_match_key(bytes));
    if kind[0] is None:
        if o.verbosity == 0:
            hdr.printer(sys.stdout);
        raise CmdError("Don't know what this mgmtClass/classVersion is.")
    fmt = kind[0](bytes);
    print fmt.__class__.__name__,fmt.describe();
    fmt.printer(sys.stdout,header=False);
示例#43
0
 def __setstate__(self,v):
     self.all_nodes = v[0];
     self.topology = v[1]
     self.loaded = v[2]
     self.lid_routed = v[3];
     self.nodes = dict((I.ninf.nodeGUID,I) for I in self.all_nodes
                       if I.ninf is not None)
     self.ports = {}
     max_lid = max(I.LID for I in self.iterend_ports())
     self.lids = [None]*max_lid;
     for I in self.iterend_ports():
         if I.portGUID is not None:
             self.ports[I.portGUID] = I;
         if I.pinf is not None:
             self.set_max_lid(I.pinf.LID + (1<<I.pinf.LMC)-1);
             for J in IBA.lid_lmc_range(I.pinf.LID,I.pinf.LMC):
                 self.lids[J] = I;
         elif I.LID is not None:
             self.set_max_lid(I.LID);
             self.lids[I.LID] = I;
示例#44
0
def arg_nr(query,values):
    """LID"""
    query.LID = IBA.conv_lid(values[0]);
    del values[0];