예제 #1
0
 def handle_uep(self, body):
     mgr_uuid = UUID(body.get('GENZ_A_UEP_MGR_UUID'))
     # Revisit: check mgr_uuid against self.mgr_uuid
     br_gcid = GCID(val=body.get('GENZ_A_UEP_BRIDGE_GCID'))
     br = self.comp_gcids[br_gcid]
     flags = body.get('GENZ_A_UEP_FLAGS')
     local = flags & 0x10  # Revisit: enum?
     ts_sec = body.get('GENZ_A_UEP_TS_SEC')
     ts_nsec = body.get('GENZ_A_UEP_TS_NSEC')
     # Revisit: do something with ts_sec/ts_nsec
     pkt = body.get('GENZ_A_UEP_PKT')  # dict, not genz.Packet
     if local:
         sender = br
     else:
         gc = pkt['GC']
         scid = pkt['SCID']
         sender_gcid = GCID(cid=scid,
                            sid=(pkt['SSID'] if gc else br.gcid.sid))
         sender = self.comp_gcids[sender_gcid]
     if pkt['IV']:
         iface = sender.interfaces[pkt['IfaceID']]
     else:
         iface = None
     if zephyr_conf.args.keyboard > 2:
         set_trace()
     # dispatch to event handler based on EventName
     return self.dispatch(pkt['EventName'], br, sender, iface, pkt)
예제 #2
0
def get_gcid(comp_path):
    gcid = comp_path / 'gcid'
    try:
        with gcid.open(mode='r') as f:
            return GCID(str=f.readline().rstrip())
    except FileNotFoundError:
        return INVALID_GCID
예제 #3
0
 def __init__(self,
              nl,
              map,
              path,
              fab_uuid=None,
              grand_plan=None,
              random_cids=False,
              accept_cids=False,
              verbosity=0):
     self.nl = nl
     self.map = map
     self.path = path
     self.fabnum = component_num(path)
     self.fab_uuid = fab_uuid
     self.mgr_uuid = uuid4()
     self.random_cids = random_cids
     self.accept_cids = accept_cids
     self.verbosity = verbosity
     self.bridges = []
     self.components = {}
     self.cuuid_serial = {}
     self.rand_list = []
     self.gcid = GCID(cid=1)  # Revisit: grand plan
     super().__init__()
     if self.verbosity:
         print('fabric: {}, num={}, fab_uuid={}, mgr_uuid={}'.format(
             path, self.fabnum, self.fab_uuid, self.mgr_uuid))
예제 #4
0
 def get_gcid(self, prefix='control'):
     gcid = None
     core_file = self.path / prefix / 'core@0x0/core'
     with core_file.open(mode='rb+') as f:
         data = bytearray(f.read())
         core = self.map.fileToStruct('core',
                                      data,
                                      fd=f.fileno(),
                                      verbosity=self.verbosity)
         if core.CV:
             gcid = GCID(val=core.CID0)  # Revisit: Subnets
     return gcid
예제 #5
0
 def get_peer_gcid(self, iface):
     genz = zephyr_conf.genz
     # Re-read PeerCID/PeerSID/PeerState
     self.comp.control_read(iface, genz.InterfaceStructure.PeerCID, sz=8)
     peer_state = genz.PeerState(iface.PeerState, iface)
     peer_cid = iface.PeerCID if peer_state.field.PeerCIDValid else None
     peer_sid = (iface.PeerSID
                 if peer_state.field.PeerSIDValid else self.comp.gcid.sid)
     try:
         peer_gcid = GCID(sid=peer_sid, cid=peer_cid)
     except TypeError:
         peer_gcid = None
     log.debug('{}: get_peer_gcid[{}]: PeerGCID={}'.format(
         self.comp.gcid, self.num, peer_gcid))
     return peer_gcid
예제 #6
0
 def assign_gcid(self, comp, ssdt_sz=4096):
     # Revisit: CID conficts between accepted & assigned are possible
     random_cids = self.random_cids
     if self.accept_cids:
         hw_gcid = comp.get_gcid()
         if hw_gcid is not None:
             self.gcid = hw_gcid
             random_cids = False
     if random_cids:
         if len(self.rand_list) == 0:
             self.rand_list = random.sample(range(1, ssdt_sz), ssdt_sz - 1)
             self.rand_index = 0
         self.gcid.cid = self.rand_list[self.rand_index]
     comp.gcid = GCID(val=self.gcid.val)
     if random_cids:
         self.rand_index += 1
     else:
         self.gcid.cid += 1
     return comp.gcid
예제 #7
0
 def assign_gcid(self, comp, ssdt_sz=4096, proposed_gcid=None):
     # Revisit: subnets
     # Revisit: CID conficts between accepted & assigned are possible
     random_cids = self.random_cids
     if self.refill_gcids:
         self.avail_gcids = (random.sample(range(1, ssdt_sz), ssdt_sz - 1)
                             if random_cids else list(range(1, ssdt_sz)))
         self.refill_gcids = False
     if proposed_gcid is not None:
         try:
             self.avail_gcids.remove(proposed_gcid.cid)
             comp.gcid = proposed_gcid
         except ValueError:
             comp.gcid = None
     else:
         try:
             cid = self.avail_gcids.pop(0)
             comp.gcid = GCID(cid=cid)
         except IndexError:
             comp.gcid = None
     if comp.gcid is not None:
         self.assigned_gcids.append(comp.gcid)
         self.nodes[comp]['gcids'] = [comp.gcid]
     return comp.gcid
예제 #8
0
def get_gcid(comp_path):
    gcid = comp_path / 'gcid'
    with gcid.open(mode='r') as f:
        return GCID(str=f.read().rstrip())
예제 #9
0
def main():
    global args
    global cols
    global genz
    parser = argparse.ArgumentParser()
    parser.add_argument('-k',
                        '--keyboard',
                        action='store_true',
                        help='break to interactive keyboard at certain points')
    parser.add_argument(
        '-c',
        '--cclass',
        action='store',
        default=None,
        nargs='+',
        help='select only components with this component class (cclass)')
    parser.add_argument('-f',
                        '--fabric',
                        action='store',
                        default=None,
                        nargs='+',
                        help='select only components with this fabric number')
    parser.add_argument('-g',
                        '--gcid',
                        action='store',
                        default=None,
                        nargs='+',
                        help='select only components with this GCID')
    parser.add_argument('-s',
                        '--serial',
                        action='store',
                        default=None,
                        nargs='+',
                        help='select only components with this serial number')
    parser.add_argument(
        '-u',
        '--cuuid',
        action='store',
        default=None,
        nargs='+',
        help='select only components with this class UUID (cuuid)')
    parser.add_argument('-v',
                        '--verbosity',
                        action='count',
                        default=0,
                        help='increase output verbosity')
    parser.add_argument('-F',
                        '--fake-root',
                        action='store',
                        help='fake root directory')
    parser.add_argument('-G',
                        '--genz-version',
                        choices=['1.1'],
                        default='1.1',
                        help='Gen-Z spec version of Control Space structures')
    parser.add_argument('-P',
                        '--post_mortem',
                        action='store_true',
                        help='enter debugger on uncaught exception')
    parser.add_argument(
        '-S',
        '--struct',
        action='store',
        help='input file representing a single control structure')
    args = parser.parse_args()
    if args.verbosity > 5:
        print('Gen-Z version = {}'.format(args.genz_version))
    genz = import_module('genz.genz_{}'.format(
        args.genz_version.replace('.', '_')))
    map = genz.ControlStructureMap()
    if args.keyboard:
        set_trace()
    if args.struct:
        fpath = Path(args.struct)
        struct = get_struct(fpath, map, verbosity=args.verbosity)
        print(struct)
        return
    try:
        match_fabrics = [] if args.fabric is None else [
            int(f, base=10) for f in args.fabric
        ]
    except ValueError:
        print('invalid fabric number: {}'.format(args.fabric))
        exit(1)
    try:
        match_gcids = [] if args.gcid is None else [
            GCID(str=g) for g in args.gcid
        ]
    except ValueError:
        print('invalid GCID: {}'.format(args.gcid))
        exit(1)
    try:
        match_serials = [] if args.serial is None else [
            int(s, base=0) for s in args.serial
        ]
    except ValueError:
        print('invalid serial number: {}'.format(args.serial))
        exit(1)
    try:
        match_cuuids = [] if args.cuuid is None else [
            UUID(u) for u in args.cuuid
        ]
    except ValueError:
        print('invalid class uuid: {}'.format(args.cuuid))
        exit(1)
    try:
        # Revisit: allow cclass names
        match_cclasses = [] if args.cclass is None else [
            int(c, base=0) for c in args.cclass
        ]
    except ValueError:
        print('invalid cclass number: {}'.format(args.cclass))
        exit(1)
    if args.fake_root is not None:
        sys_devices = Path(args.fake_root) / 'sys/devices'
    else:
        sys_devices = Path('/sys/devices')
    dev_fabrics = sys_devices.glob('genz*')  # locally-visible Gen-Z devices
    genz_fabrics = Path('/sys/bus/genz/fabrics')  # fabric components (FM-only)
    all_comps = {}
    for fab in dev_fabrics:
        comps = {}
        fabnum = component_num(fab)
        bridges = fab.glob('bridge*')  # local bridges
        for br_path in bridges:
            brnum = component_num(br_path)
            br = Comp(fabnum,
                      br_path,
                      map=map,
                      name='bridge{}'.format(brnum),
                      verbosity=args.verbosity)
            if args.keyboard:
                set_trace()
            selected = br.check_selected(args, match_cuuids, match_serials,
                                         match_fabrics, match_gcids,
                                         match_cclasses)
            if selected:
                comps[br.cuuid_sn] = br  # save br for later printing
        # end for br_path
        fab_comps = genz_fabrics.glob(
            'fabric{}/*:*/*:*:*'.format(fabnum))  # FM-visible components
        for comp_path in fab_comps:
            comp = Comp(fabnum, comp_path, map=map, verbosity=args.verbosity)
            if args.keyboard:
                set_trace()
            selected = comp.check_selected(args, match_cuuids, match_serials,
                                           match_fabrics, match_gcids,
                                           match_cclasses)
            if selected:
                if not comp.cuuid_sn in comps.keys():
                    comps[comp.cuuid_sn] = comp  # save comp for later printing
            if args.verbosity < 1:
                continue
        # end for comp
        os_comps = fab.glob('*:*/*:*:*')  # other OS-visible Gen-Z devices
        for comp_path in os_comps:
            comp = Comp(fabnum, comp_path, verbosity=args.verbosity)
            if args.keyboard:
                set_trace()
            selected = comp.check_selected(args, match_cuuids, match_serials,
                                           match_fabrics, match_gcids,
                                           match_cclasses)
            if not selected:
                continue
            if comp.cuuid_sn in comps.keys():
                # merge resources into existing Comp
                existing = comps[comp.cuuid_sn]
                existing.add_resources(
                    comp_path.glob('genz{}:*'.format(comp_path.name)))
            else:
                comp.add_resources(
                    comp_path.glob('genz{}:*'.format(comp_path.name)))
                comps[comp.cuuid_sn] = comp  # save comp for later printing
        # end for comp_path
        if args.keyboard:
            set_trace()
        # now we actually print things
        for comp in sorted(comps.values()):
            if comp.cuuid_sn not in all_comps.keys():
                drs = comp.ls_comp()
                for dr in drs:
                    _ = dr.ls_comp(ignore_dr=False)
        # end for comp
        all_comps |= comps
    # end for fab
    if args.keyboard:
        set_trace()
    return
예제 #10
0
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import contextlib
import argparse
import os
import ctypes
import re
from uuid import UUID
from pathlib import Path
from importlib import import_module
from genz.genz_common import GCID, CState
from pdb import set_trace, post_mortem
import traceback

INVALID_GCID = GCID(val=0xffffffff)
INVALID_UUID = UUID(int=0xffffffffffffffffffffffffffffffff)


def get_gcid(comp_path):
    gcid = comp_path / 'gcid'
    try:
        with gcid.open(mode='r') as f:
            return GCID(str=f.readline().rstrip())
    except FileNotFoundError:
        return INVALID_GCID


def get_cuuid(comp_path):
    cuuid = comp_path / 'c_uuid'
    try: