コード例 #1
0
def cmd_saquery(argv, o):
    """Issue a SubnAdmGetTable() request to the SA for an attribute
       Usage: %prog [OPTIONS] [ITEM] [ARG] [MEMBER=VALUE]*

       This command performs a search at the SA for ITEM things that match
       the pattern. Each SA search is specified by setting matching parameters
       in the request. The search to perform can be specified via an option
       or via the ITEM argument. If an option is specified then ITEM is ignored.

       Each search type supports an optional quick matching ARG which is type
       specific. The ARG sets fields to match. After ARG is a series of
       MEMBER=VALUE lines which specify named fields to match. eg
       nodeInfo.portGUID=0017:77ff:feb6:2ca4 will match NodeRecords with
       that port GUID.

       There are also several option shortcuts that are equivalent to the above
       with different field names.

       Supported ITEM:
       """
    # FIXME: selector/*
    LibIBOpts.setup(o, address=False)
    o.add_option("-p",
                 action="store_const",
                 dest="kind",
                 const=IBA.SAPathRecord)
    o.add_option("-N",
                 action="store_const",
                 dest="kind",
                 const=IBA.SANodeRecord)
    o.add_option("-g",
                 action="store_const",
                 dest="kind",
                 const=IBA.SAMCMemberRecord)
    o.add_option("-m",
                 action="store_const",
                 dest="kind",
                 const=IBA.SAMCMemberRecord)
    o.add_option("-x",
                 action="store_const",
                 dest="kind",
                 const=IBA.SALinkRecord)
    o.add_option("-c",
                 action="store_const",
                 dest="kind",
                 const=IBA.MADClassPortInfo)
    o.add_option("-I",
                 action="store_const",
                 dest="kind",
                 const=IBA.SAInformInfoRecord)

    o.add_option("--get",
                 action="store_true",
                 dest="use_get",
                 help="Use a SubnAdmGet() method instead of SubnAdmGetTable()")
    o.add_option("--no-defaults",
                 action="store_true",
                 dest="no_defaults",
                 help="Do not set default values for any queries")

    o.add_option("--dlid", action="store", dest="X_DLID")
    o.add_option("--slid", action="store", dest="X_SLID")
    o.add_option("--mlid", action="store", dest="X_MLID")
    o.add_option("--sgid", action="store", dest="X_SGID")
    o.add_option("--dgid", action="store", dest="X_DGID")
    o.add_option("--gid", action="store", dest="X_portGID")
    o.add_option("--mgid", action="store", dest="X_MGID")
    o.add_option("-r", "--reversible", action="store", dest="X_reversible")
    o.add_option("-n", "--numb_path", action="store", dest="X_numbPath")
    o.add_option("--pkey", action="store", dest="X_PKey")
    o.add_option("-Q", "--qos_class", action="store", dest="X_QOSClass")
    o.add_option("--sl", action="store", dest="X_SL")
    o.add_option("-M", "--mtu", action="store", dest="X_MTU")
    o.add_option("-R", "--rate", action="store", dest="X_rate")
    o.add_option("--pkt_lifetime", action="store", dest="X_packetLifeTime")
    o.add_option("-q", "--qkey", action="store", dest="X_QKey")
    o.add_option("-T", "--tclass", action="store", dest="X_TClass")
    o.add_option("-f", "--flow_label", action="store", dest="X_flowLabel")
    o.add_option("-H", "--hop_limit", action="store", dest="X_hopLimit")
    o.add_option("--scope", action="store", dest="X_scope")
    o.add_option("-J", "--join_state", action="store", dest="X_joinState")
    o.add_option("-X", "--proxy_join", action="store", dest="X_proxyJoin")

    (args, values) = o.parse_args(argv)
    lib = LibIBOpts(o, args)

    global _format_args
    _format_args = copy.copy(lib.format_args)
    # We cannot handle dump output because of how dotted output is mangled
    # to match the libib tools.
    _format_args["format"] = "dotted"
    _format_args["header"] = False
    if _format_args["format"] != "dotted":
        out = sys.stdout
    else:
        out = Indentor(sys.stdout)

    if args.kind is None:
        if len(values) < 1:
            args.kind = IBA.SANodeRecord
        else:
            args.kind = tmpl_op(values[0])[1]
            del values[0]

    to_set = []
    for elm in range(len(values) - 1, -1, -1):
        I = values[elm]
        idx = I.find("=")
        if idx == -1:
            del values[elm + 1:]
            break
        to_set.insert(0, (I[:idx], I[idx + 1:]))
    else:
        del values[:]

    query = args.kind()
    query_cm = IBA.ComponentMask(query)
    if len(values) >= 1:
        # The first value(s) are a kind specific thing, parsed with the kind
        # helper.
        for v in OPS.itervalues():
            if v[1] == args.kind and len(v) >= 3:
                try:
                    v[2](query_cm, values)
                except ValueError:
                    raise CmdError("Argument %r did not match %s" %
                                   (values[0], v[2].__doc__))

    if values:
        raise CmdError("Arguments %r are not understood." % (values))

    # Parse command line options that set members.
    for I in dir(args):
        if not I.startswith("X_"):
            continue
        arg = getattr(args, I)
        if arg is not None:
            to_set.append((I[2:], arg))

    if to_set and getattr(query, "COMPONENT_MASK", None) is None:
        raise CmdError("Cannot set member queries with type %s" %
                       (query.__class__.__name__))

    # Set member arguments using introspection.
    for n, v in to_set:
        if n not in query.COMPONENT_MASK:
            raise CmdError("Cannot set member %s on %s. Try one of %s" %
                           (n, query.__class__.__name__, ", ".join(
                               query.COMPONENT_MASK.iterkeys())))
        set_mad_attr(query_cm, n, v)

    with lib.get_umad(gmp=True) as umad:
        path = umad.end_port.sa_path

        # Special help for PathRecords, spec says SGID and numbPath are mandatory for GetTable.
        if args.kind == IBA.SAPathRecord and not args.use_get and not args.no_defaults:
            if not (query_cm.component_mask &
                    (1 << query.COMPONENT_MASK["numbPath"])):
                query_cm.numbPath = 1
            if not (query_cm.component_mask &
                    (1 << query.COMPONENT_MASK["SGID"])):
                query_cm.SGID = umad.parent.default_gid

        # Diagnostic output to show what the query argument is.
        if o.verbosity >= 1:
            cm = query_cm.component_mask
            ret = []
            for k, v in query.COMPONENT_MASK.iteritems():
                if cm & (1 << v):
                    ret.append((v, k, eval("query_cm.%s" % (k))))
            ret.sort()
            if ret:
                print "Performing query on %s with component mask:" % (
                    query.__class__.__name__)
                for v, k, arg in ret:
                    print "  %2u %s = %r" % (v, k, arg)

        name_map = _format_args.get("name_map", {})
        try:
            if getattr(query, "MAD_SUBNADMGETTABLE",
                       None) is None or args.use_get:
                ret = umad.SubnAdmGet(query_cm, path)
                n = ret.__class__.__name__
                print "%s:" % (name_map.get(n, n))
                do_print(out, ret)
            else:
                ret = umad.SubnAdmGetTable(query_cm, path)
                for I in ret:
                    n = I.__class__.__name__
                    print "%s dump:" % (name_map.get(n, n))
                    do_print(out, I)
        except rdma.MADClassError as err:
            if err.code != IBA.MAD_STATUS_SA_NO_RECORDS:
                raise
            print "No Records."
    return True
コード例 #2
0
    def SubnGet(self,payload,path,attributeModifier=0):
        ID = payload.MAD_ATTRIBUTE_ID;
        meth = payload.MAD_SUBNGET;
        if ID == IBA.SMPGUIDInfo.MAD_ATTRIBUTE_ID:
            req = IBA.ComponentMask(IBA.SAGUIDInfoRecord());
            req.LID = self.get_path_lid(path);
            req.blockNum = attributeModifier;
            return self._subn_adm_do(req,self.sa_path,0,
                                     req.MAD_SUBNADMGET,
                                     lambda x:x.GUIDInfo);
        if ID == IBA.SMPLinearForwardingTable.MAD_ATTRIBUTE_ID:
            req = IBA.ComponentMask(IBA.SALinearForwardingTableRecord());
            req.LID = self.get_path_lid(path);
            req.blockNum = attributeModifier;
            return self._subn_adm_do(req,self.sa_path,0,
                                     req.MAD_SUBNADMGET,
                                     (lambda x:x.linearForwardingTable,
                                      self._sa_error));
        if ID == IBA.SMPMulticastForwardingTable.MAD_ATTRIBUTE_ID:
            req = IBA.ComponentMask(IBA.SAMulticastForwardingTableRecord());
            req.LID = self.get_path_lid(path);
            req.blockNum = attributeModifier & ((1<<9)-1);
            req.position = (attributeModifier >> 12) & 0xF;
            return self._subn_adm_do(req,self.sa_path,0,
                                     req.MAD_SUBNADMGET,
                                     (lambda x:x.multicastForwardingTable,
                                      self._sa_error));
        if ID == IBA.SMPNodeDescription.MAD_ATTRIBUTE_ID:
            req = IBA.ComponentMask(IBA.SANodeRecord());
            req.LID = self.get_path_lid(path);
            return self._subn_adm_do(req,self.sa_path,0,
                                     req.MAD_SUBNADMGET,
                                     self._finish_nodedesc);
        if ID == IBA.SMPNodeInfo.MAD_ATTRIBUTE_ID:
            req = IBA.ComponentMask(IBA.SANodeRecord());
            req.LID = self.get_path_lid(path);
            return self._subn_adm_do(req,self.sa_path,0,
                                     req.MAD_SUBNADMGET,
                                     self._finish_nodeinfo);

        if ID == IBA.SMPPKeyTable.MAD_ATTRIBUTE_ID:
            req = IBA.ComponentMask(IBA.SAPKeyTableRecord());
            req.LID = self.get_path_lid(path);
            nt = getattr(path,"_cached_node_type",None);
            if nt is None or nt == IBA.NODE_SWITCH:
                req.portNum = attributeModifier >> 16;
            req.blockNum = attributeModifier & 0xFFFF;
            return self._subn_adm_do(req,self.sa_path,0,
                                     req.MAD_SUBNADMGET,
                                     (lambda x:x.PKeyTable,
                                      self._sa_error));

        if ID == IBA.SMPPortInfo.MAD_ATTRIBUTE_ID:
            req = IBA.ComponentMask(IBA.SAPortInfoRecord());
            req.endportLID = self.get_path_lid(path);
            if (attributeModifier == 0 and
                getattr(path,"_cached_node_type",None) != IBA.NODE_SWITCH):
                # This can mean 'whatever port' or it can mean 'switch port 0'
                # If we don't know the node type then do a get table and
                # figure it out.
                return self._subn_adm_do(req,self.sa_path,0,
                                         req.MAD_SUBNADMGETTABLE,
                                         self._finish_port_info_attr0);

            req.portNum = attributeModifier;
            return self._subn_adm_do(req,self.sa_path,0,
                                     req.MAD_SUBNADMGET,
                                     lambda x:x.portInfo);
        if ID == IBA.SMPSLToVLMappingTable.MAD_ATTRIBUTE_ID:
            req = IBA.ComponentMask(IBA.SASLToVLMappingTableRecord());
            req.LID = self.get_path_lid(path);
            req.inputPortNum = (attributeModifier >> 8) & 0xFF;
            req.outputPortNum = attributeModifier & 0xFF;
            return self._subn_adm_do(req,self.sa_path,0,
                                     req.MAD_SUBNADMGET,
                                     (lambda x:x.SLToVLMappingTable,
                                      self._sa_error));
        if ID == IBA.SMPSMInfo.MAD_ATTRIBUTE_ID:
            req = IBA.ComponentMask(IBA.SASMInfoRecord());
            req.LID = self.get_path_lid(path);
            return self._subn_adm_do(req,self.sa_path,0,
                                     req.MAD_SUBNADMGET,
                                     lambda x:x.SMInfo);
        if ID == IBA.SMPSwitchInfo.MAD_ATTRIBUTE_ID:
            req = IBA.ComponentMask(IBA.SASwitchInfoRecord());
            req.LID = self.get_path_lid(path);
            return self._subn_adm_do(req,self.sa_path,0,
                                     req.MAD_SUBNADMGET,
                                     lambda x:x.switchInfo);
        if ID == IBA.SMPVLArbitrationTable.MAD_ATTRIBUTE_ID:
            req = IBA.ComponentMask(IBA.SAVLArbitrationTableRecord());
            req.LID = self.get_path_lid(path);
            req.outputPortNum = attributeModifier & 0xFFFF;
            req.blockNum = (attributeModifier >> 16) & 0xFFFF;
            return self._subn_adm_do(req,self.sa_path,0,
                                     req.MAD_SUBNADMGET,
                                     (lambda x:x.VLArbitrationTable,
                                      self._sa_error));

        return self._parent.SubnGet(payload,path,attributeModifier);
コード例 #3
0
ファイル: discovery.py プロジェクト: tubbytani/python-rdma
def topo_peer_SMP(sched,sbn,port,get_desc=True,path=None,
                  peer_path=None):
    """Coroutine to fetch a single connected peer. This updates
    :attr:`rdma.subnet.Subnet.topology`. It also fetches a port info to setup
    LID routing.

    *peer_path* is the path out *port*, created by
     :meth:`rdma.subnet.Subnet.advance_dr`.

    This does nothing if the information is already loaded."""
    peer_port = sbn.topology.get(port);
    if peer_port is None:
        portIdx = port.port_id;

        if peer_path is None:
            if path is None:
                path = sbn.get_path_smp(sched,port.to_end_port());
            peer_path = sbn.advance_dr(path,portIdx);

        if port.pinf is None:
            yield subnet_pinf_SMP(sched,sbn,portIdx,path);

        if (port.pinf.portState == IBA.PORT_STATE_DOWN or
            portIdx == 0):
            return

        # Resolve the DR path using the SA and update our topology information
        # as well.
        use_sa = isinstance(sched,rdma.satransactor.SATransactor);
        if use_sa:
            if path is None:
                path = sbn.get_path_smp(sched,port.to_end_port());
            req = IBA.ComponentMask(IBA.SALinkRecord());
            req.fromLID = yield sched.prepare_path_lid(path);
            req.fromPort = portIdx;
            rep = yield sched.SubnAdmGet(req);
            peer_path._cached_resolved_dlid = rep.toLID;
            peer_port = sbn.get_port(portIdx=rep.toPort,LID=rep.toLID,
                                     path=peer_path);

        peer_node,peer_zport = yield subnet_ninf_SMP(sched,sbn,peer_path,
                                                     get_desc,use_sa);
        get_desc = False;
        if not use_sa:
            lpn = getattr(peer_path,"_cached_subnet_localPortNum",
                          peer_node.ninf.localPortNum);
            peer_port = sbn.get_port(portIdx=lpn,
                                     path=peer_path);

        sbn.topology[port] = peer_port;
        sbn.topology[peer_port] = port;
    else:
        peer_node = peer_port.parent;
        peer_zport = peer_port.to_end_port();
        peer_path = sbn.get_path_smp(sched,peer_zport);

    if get_desc and peer_node.desc is None:
        sched.queue(peer_node.get_desc(sched,peer_path));

    if sbn.lid_routed and peer_zport.LID is None:
        yield subnet_pinf_SMP(sched,sbn,0,peer_path);