def nftest_init(sim_loop=[], hw_config=None): global sim global ifaceArray global connections global sent_phy, sent_dma, expected_phy, expected_dma # handle simulation separately if not isHW(): sim = True simLib.init() ifaceArray = ['nf0', 'nf1', 'nf2', 'nf3'] for iface in ifaceArray: connections[iface] = 'phy_dummy' sent_phy[iface] = [] sent_dma[iface] = [] expected_phy[iface] = [] expected_dma[iface] = [] looped = [False, False, False, False] for iface in sim_loop: if not iface.startswith('nf'): print "Error1: Only nfX interfaces can be put in loopback" sys.exit(1) else: looped[int(iface[2])] = True portcfgfile = 'portconfig.sim' portcfg = open(portcfgfile, 'w') portcfg.write('LOOPBACK=') for loop_state in reversed(looped): if loop_state: portcfg.write('1') else: portcfg.write('0') portcfg.close() return 'sim' # running a hardware test, check connections else: if hw_config is None: print "Error: trying to run hardware test without specifying hardware configurations. Verify the keyword argument hw_config is being used in nftest_init" sys.exit(1) sim = False # validate connections and process loopback portConfig = 0 if '--conn' in sys.argv: specified_connections = {} # read specified connections lines = open(sys.argv[sys.argv.index('--conn') + 1], 'r').readlines() for line in lines: conn = line.strip().split(':') specified_connections[conn[0]] = conn[1] # find matching configuration for portConfig in range(len(hw_config)): conns = {} lines = open(hw_config[portConfig][0]).readlines() for line in lines: conn = line.strip().split(':') conns[conn[0]] = conn[1] # physical connections match if conns == specified_connections: connections = specified_connections # check if we've got disconnected interfaces for connection in connections: if connections[connection] == '': hwRegLib.phy_isolate(iface) # specify loopback for iface in hw_config[portConfig][1]: if iface.startswith('nf'): hwRegLib.phy_loopback(iface) else: print "Error2: Only nfX interfaces can be put in loopback" sys.exit(1) break # incompatible configuration elif portConfig == len(hw_config) - 1: print "Specified connections file incompatible with this test." sys.exit(1) else: portConfig = 0 # use the first valid_conn_file if not specified lines = open(hw_config[0][0], 'r').readlines() for line in lines: conn = line.strip().split(':') connections[conn[0]] = conn[1] # specify loopback if len(hw_config[0][1]) > 0: for iface in hw_config[0][1]: if iface.startswith('nf'): if isHW(): hwRegLib.phy_loopback(iface) else: looped[int(iface[2])] = True else: print "Error3: Only nfX interfaces can be put in loopback" sys.exit(1) # avoid duplicating interfaces ifaces = list( set(connections.keys() + connections.values() + list(hw_config[portConfig][1])) - set([''])) global iface_map # populate iface_map if '--map' in sys.argv: mapfile = open(sys.argv[sys.argv.index('--map') + 1], 'r') lines = mapfile.readlines() for line in lines: mapping = line.strip().split(':') iface_map[mapping[0]] = mapping[1] if mapping[0] in ifaces: ifaces.remove(mapping[0]) ifaces.append(mapping[1]) else: for iface in ifaces: iface_map[iface] = iface ifaceArray = ifaces for iface in ifaces: sent_phy[iface] = [] sent_dma[iface] = [] expected_phy[iface] = [] expected_dma[iface] = [] hwPktLib.init(ifaces) # print setup for inspection print 'Running test using the following physical connections:' for connection in connections.items(): try: print iface_map[connection[0]] + ':' + iface_map[connection[1]] except KeyError: print iface_map[ connection[0]] + ' initialized but not connected' if len(list(hw_config[portConfig][1])) > 0: print 'Ports in loopback:' for iface in list(hw_config[portConfig][1]): print iface_map[iface] print '------------------------------------------------------' return portConfig
def nftest_init(sim_loop = [], hw_config=None): global sim global ifaceArray global connections global sent_phy, sent_dma, expected_phy, expected_dma # handle simulation separately if not isHW(): sim = True simLib.init() ifaceArray = ['nf2c0', 'nf2c1', 'nf2c2', 'nf2c3'] for iface in ifaceArray: connections[iface] = 'phy_dummy' sent_phy[iface] = [] sent_dma[iface] = [] expected_phy[iface] = [] expected_dma[iface] = [] looped = [False, False, False, False] for iface in sim_loop: if not iface.startswith('nf2c'): print "Error: Only nf2cX interfaces can be put in loopback" sys.exit(1) else: looped[int(iface[4:5])] = True portcfgfile = 'portconfig.sim' portcfg = open(portcfgfile, 'w') portcfg.write('LOOPBACK=') for loop_state in reversed(looped): if loop_state: portcfg.write('1') else: portcfg.write('0') portcfg.close() return 'sim' # running a hardware test, check connections else: if hw_config is None: print "Error: trying to run hardware test without specifying hardware configurations. Verify the keyword argument hw_config is being used in nftest_init" sys.exit(1) sim = False # validate connections and process loopback portConfig = 0 if '--conn' in sys.argv: specified_connections = {} # read specified connections lines = open(sys.argv[sys.argv.index('--conn')+1], 'r').readlines() for line in lines: conn = line.strip().split(':') specified_connections[conn[0]] = conn[1] # find matching configuration for portConfig in range(len(hw_config)): conns = {} lines = open(hw_config[portConfig][0]).readlines() for line in lines: conn = line.strip().split(':') conns[conn[0]] = conn[1] # physical connections match if conns == specified_connections: connections = specified_connections # check if we've got disconnected interfaces for connection in connections: if connections[connection] == '': hwRegLib.phy_isolate(iface) # specify loopback for iface in hw_config[portConfig][1]: if iface.startswith('nf2c'): hwRegLib.phy_loopback(iface) else: print "Error: Only nf2cX interfaces can be put in loopback" sys.exit(1) break # incompatible configuration elif portConfig == len(hw_config) - 1: print "Specified connections file incompatible with this test." sys.exit(1) else: portConfig = 0 # use the first valid_conn_file if not specified lines = open(hw_config[0][0], 'r').readlines() for line in lines: conn = line.strip().split(':') connections[conn[0]] = conn[1] # specify loopback if len(hw_config[0][1]) > 0: for iface in hw_config[0][1]: if iface.startswith('nf2c'): if isHW(): hwRegLib.phy_loopback(iface) else: looped[int(iface[4:5])] = True else: print "Error: Only nf2cX interfaces can be put in loopback" sys.exit(1) # avoid duplicating interfaces ifaces = list(set(connections.keys() + connections.values() + list(hw_config[portConfig][1])) - set([''])) global iface_map # populate iface_map if '--map' in sys.argv: mapfile = open(sys.argv[sys.argv.index('--map')+1], 'r') lines = mapfile.readlines() for line in lines: mapping = line.strip().split(':') iface_map[mapping[0]] = mapping[1] if mapping[0] in ifaces: ifaces.remove(mapping[0]) ifaces.append(mapping[1]) else: for iface in ifaces: iface_map[iface] = iface ifaceArray = ifaces for iface in ifaces: sent_phy[iface] = [] sent_dma[iface] = [] expected_phy[iface] = [] expected_dma[iface] = [] hwPktLib.init(ifaces) # print setup for inspection print 'Running test using the following physical connections:' for connection in connections.items(): try: print iface_map[connection[0]] + ':' + iface_map[connection[1]] except KeyError: print iface_map[connection[0]] + ' initialized but not connected' if len(list(hw_config[portConfig][1])) > 0: print 'Ports in loopback:' for iface in list(hw_config[portConfig][1]): print iface_map[iface] print '------------------------------------------------------' return portConfig