def getNetworkInterfaceLinkStatus(networkInterface): utils.displayText( 'red', 'TODO : testing an IP alias with ethtool always report : \'Link detected: yes\'. It cannot be used here.', 0) utils.terminateTest(1) command = ['/usr/bin/sudo', '/sbin/ethtool', networkInterface] commandStdout, commandStderr = utils.executeCommand(command) # get "Link detected:" myRe = re.search('Link detected: yes|no', commandStdout) linkDetected = re.sub('Link detected: ', '', myRe.group()) if linkDetected == 'yes': networkInterfaceStatus = 'up' elif linkDetected == 'no': networkInterfaceStatus = 'down' else: utils.displayText( 'red', '[KO] linkDetected (%s) is neither \'yes\', nor \'no\'' % linkDetected, 0) utils.terminateTest(1) return networkInterfaceStatus
def rebootAndReconfigureDmng(self): self.reboot() self.increaseMemoryForBetterOomResistance() self.activateUsb() self.renameNetworkInterfaces() if globals.aggregationsModes.count('kencast') != 0: self.writeToSerial('export LD_LIBRARY_PATH=/app/lib:/app/fazzt/lib:${LD_LIBRARY_PATH}', [], 10) if globals.useControlNetworkInterface: # -------------------------------------------------------------------------------------------------- utils.displayText('blue', 'setting up controlNetworkInterface, that will be used to drive the dmng (no traffic control on this interface)', 0) # -------------------------------------------------------------------------------------------------- interfaceName = self.controlNetworkInterface[0] self.networkInterfaceFirstInit(interfaceName) self.startSshServer() # -------------------------------------------------------------------------------------------------- utils.displayText('blue', 'configuring dmng\'s involved network interfaces', 0) # -------------------------------------------------------------------------------------------------- utils.displayText('blue', 'configuring %d ethAdapters' % globals.maxNbOfEthAdapters, 0) for i in range(globals.maxNbOfEthAdapters): interfaceName = self.ethAdaptersInterfacesList[i][0] self.networkInterfaceFirstInit(interfaceName) utils.displayText('blue', 'configuring %d usbEthAdapters' % globals.maxNbOfUsbEthAdapters, 0) for i in range(globals.maxNbOfUsbEthAdapters): interfaceName = self.usbEthAdaptersInterfacesList[i][0] self.networkInterfaceFirstInit(interfaceName) utils.displayText('blue', 'configuring %d wifiAdapters' % globals.maxNbOfWifiAdapters, 0) for i in range(globals.maxNbOfWifiAdapters): interfaceName = self.wifiAdaptersInterfacesList[i][0] self.networkInterfaceFirstInit(interfaceName)
def setForwardRules(): utils.displayText('cyan', 'setting forward rules...', 0) commandsList = [] # allow forward traffic for established connections commandsList.append([ '/usr/bin/sudo', '/sbin/iptables', '--append', 'FORWARD', '--match', 'state', '--state', 'RELATED,ESTABLISHED', '--jump', 'ACCEPT' ]) # allow all forward traffic on all interfaces commandsList.append([ '/usr/bin/sudo', '/sbin/iptables', '--append', 'FORWARD', '--jump', 'ACCEPT' ]) # for testing ssh commandsList.append([ '/usr/bin/sudo', '/sbin/iptables', '--append', 'FORWARD', '--in-interface', globals.aviwestLanIfc, '--destination', globals.linuxVmStudioIpAddressForSsh, '--protocol', 'tcp', '--destination-port', '22', '--jump', 'ACCEPT' ]) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command)
def setNetworkInterfaceState(self, interfaceName, requestedState): # check requestedState values if (requestedState != 'up') and (requestedState != 'down'): utils.displayText('red', '[KO] requestedState (%s) is neither \'up\', nor \'down\'' % requestedState, 0) utils.terminateTest(1) self.writeToSerial('ifconfig %s %s' % (interfaceName, requestedState), [], 10)
def startAviwestStreaming(self, timeWindow): self.writeToSerial( 'abus-send sst-tx.StreamConnect timewindow=%s' % timeWindow, [ 'New timewindow %d ms' % timeWindow, 'Aggreg WAIT_RESP->CONNECTED' ], 30) self.writeToSerial( 'while ! abus-send sst-tx.get CommandReady | grep CommandReady=true; do sleep 1; done', ['CommandReady=true'], 30) status = self.getAviwestConnectionStatus() if status != 'connected': utils.displayText( 'red', 'status is not the expected one (current status is : %s; expected status was : connected)' % status, 0) utils.terminateTest(1) self.writeToSerial('abus-send sst-tx.StreamStart', ['tx_aggreg_do_cmd: CONNECTED\(StreamStart\)'], 30) status = self.getAviwestConnectionStatus() if status != 'connected': utils.displayText( 'red', 'status is not the expected one (current status is : %s; expected status was : connected)' % status, 0) utils.terminateTest(1)
def deserializeObject(): utils.displayText("blue", "deserializing full object from %s" % globals.jsonFileName, 0) if os.path.isfile(globals.jsonFileName): with open(globals.jsonFileName, "r") as f: myJson = json.load(f) else: utils.displayText("red", "file %s does not exist, run combineParameters.py first" % globals.jsonFileName, 0) utils.terminateTest(1) # deserialize scenParameters only possible if globals.scenarioId has been set if globals.scenarioId != -1: scenParameters = myJson["%06d" % globals.scenarioId] globals.scenarioComment = scenParameters["scenarioComment"] globals.scenarioEvolution = scenParameters["scenarioEvolution"] globals.scenarioDuration = int(scenParameters["scenarioDuration"]) globals.actionMode = scenParameters["actionMode"] globals.overEncodedBitrate = int(scenParameters["overEncodedBitrate"]) globals.audioBitrate = int(scenParameters["audioBitrate"]) globals.videoBitrateMode = scenParameters["videoBitrateMode"] globals.videoBitrate = int(scenParameters["videoBitrate"]) globals.frameRate = int(scenParameters["frameRate"]) globals.gopDuration = int(scenParameters["gopDuration"]) globals.iFramesVsPandBFramesRatio = int(scenParameters["iFramesVsPandBFramesRatio"]) globals.timeWindow = int(scenParameters["timeWindow"]) globals.gatewayBandWidth = int(scenParameters["gateway"]["bandWidth"]) globals.gatewayFixedLatency = int(scenParameters["gateway"]["fixedLatency"]) globals.gatewayInstantJitter = int(scenParameters["gateway"]["jitter"]) globals.gatewayQueueLength = int(scenParameters["gateway"]["queueLength"]) globals.gatewayPacketsLoss = int(scenParameters["gateway"]["packetsLoss"]) globals.nbOfEthAdapters = int(scenParameters["nbOfEthAdapters"]) for i in range(globals.nbOfEthAdapters): globals.ethAdaptersFixedLatenciesList.append(scenParameters["ethAdapters"][i]["fixedLatency"]) globals.ethAdaptersJittersList.append(scenParameters["ethAdapters"][i]["jitter"]) globals.ethAdaptersBandWidthsList.append(scenParameters["ethAdapters"][i]["bandWidth"]) globals.ethAdaptersPacketLossList.append(scenParameters["ethAdapters"][i]["packetsLoss"]) globals.ethAdaptersQueueLengthList.append(scenParameters["ethAdapters"][i]["queueLength"]) globals.nbOfUsbEthAdapters = int(scenParameters["nbOfUsbEthAdapters"]) for i in range(globals.nbOfUsbEthAdapters): globals.usbEthAdaptersFixedLatenciesList.append(scenParameters["usbEthAdapters"][i]["fixedLatency"]) globals.usbEthAdaptersJittersList.append(scenParameters["usbEthAdapters"][i]["jitter"]) globals.usbEthAdaptersBandWidthsList.append(scenParameters["usbEthAdapters"][i]["bandWidth"]) globals.usbEthAdaptersPacketLossList.append(scenParameters["usbEthAdapters"][i]["packetsLoss"]) globals.usbEthAdaptersQueueLengthList.append(scenParameters["usbEthAdapters"][i]["queueLength"]) globals.nbOfWifiAdapters = int(scenParameters["nbOfWifiAdapters"]) for i in range(globals.nbOfWifiAdapters): globals.wifiAdaptersFixedLatenciesList.append(scenParameters["wifiAdapters"][i]["fixedLatency"]) globals.wifiAdaptersJittersList.append(scenParameters["wifiAdapters"][i]["jitter"]) globals.wifiAdaptersBandWidthsList.append(scenParameters["wifiAdapters"][i]["bandWidth"]) globals.wifiAdaptersPacketLossList.append(scenParameters["wifiAdapters"][i]["packetsLoss"]) globals.wifiAdaptersQueueLengthList.append(scenParameters["wifiAdapters"][i]["queueLength"]) globals.lastScenarioId = myJson["lastScenarioId"]
def driveLinkTrafficControl(interfaceName, filename, dmngObject='', threadName = ''): if globals.platformType == 'development': networkDeviceDriver = dmngObject.getNetworkDeviceDriver(interfaceName) if globals.platformType == 'validation': networkDeviceDriver = 'asix' # read filename content and build linkEvolution with open(filename, 'r') as fileHandle: csvFileContent = csv.reader(fileHandle, delimiter=',', quotechar='|') linkEvolution = [] newEntry = [] for line in csvFileContent: # ignore malformated, comments lines (beginning with #) and blank lines #utils.displayText('yellow', 'line : %s' % line, 0) #if not re.match('#(.*)', line): if len(line) == 6: #if not re.match('#*aaa(.*)', line): #if (not re.match('#*aaa(.*)', line)) and (len(line) == 6): newEntry.append(int(line[0])) newEntry.append(int(line[1])) newEntry.append(int(line[2])) newEntry.append(int(line[3])) newEntry.append(int(line[4])) newEntry.append(int(line[5])) linkEvolution.append(newEntry) newEntry = [] else: utils.displayText('yellow', 'malformated or blank lines in file : %s' % filename, 0) # set traffic control parameters for linkCommand in linkEvolution: # at the time instantTime, change traffic control parameters instantTime = int(linkCommand[0]) while True: currentTime = time.time() secondsElapsed = currentTime - globals.streamingStartTime #utils.displayText('yellow', 'secondsElapsed : %s' % secondsElapsed, 0) if (secondsElapsed >= instantTime): bandWidth = linkCommand[1] fixedLatency = linkCommand[2] instantJitter = linkCommand[3] queueLength = linkCommand[4] packetsLoss = linkCommand[5] utils.displayText('cyan', 'replacing traffic control parameters on %s after %.3f secs of test : bandWidth : %d; fixedLatency : %d; instantJitter : %d; queueLength : %d; packetsLoss : %d' % (interfaceName, secondsElapsed, bandWidth, fixedLatency, instantJitter, queueLength, packetsLoss), 0) commandsList = buildCommandsList(interfaceName, 'change', networkDeviceDriver, bandWidth, fixedLatency, instantJitter, packetsLoss, queueLength) if globals.platformType == 'development': for command in commandsList: commandString = ' '.join(command) dmngObject.writeToSerial(commandString, [], 10) if globals.platformType == 'validation': for command in commandsList: # insert /usr/bin/sudo before each command command.insert(0, '/usr/bin/sudo') commandStdout, commandStderr = executeCommandsList(commandsList) break
def initChains(): utils.displayText('cyan', 'initializing chains...', 0) commandsList = [] ''' commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--flush', 'INPUT']) commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--flush', 'OUTPUT']) commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--flush', 'FORWARD']) ''' commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--flush']) commandsList.append( ['/usr/bin/sudo', '/sbin/iptables', '--flush', '--table', 'nat']) commandsList.append( ['/usr/bin/sudo', '/sbin/iptables', '--flush', '--table', 'mangle']) commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--delete-chain']) commandsList.append([ '/usr/bin/sudo', '/sbin/iptables', '--delete-chain', '--table', 'nat' ]) commandsList.append([ '/usr/bin/sudo', '/sbin/iptables', '--delete-chain', '--table', 'mangle' ]) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command)
def setNatPostroutingRules(): utils.displayText('cyan', 'setting nat postrouting rules (source NAT)...', 0) commandsList = [] commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--out-interface', globals.aviwestLanIfc, '--jump', 'MASQUERADE']) # allow any kind of traffic to go back from studio to globals.dmngLanIfc if globals.platformType == 'development': commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--out-interface', globals.dmngLanIfc, '--jump', 'MASQUERADE']) if globals.platformType == 'validation': for index in range(0, len(networkInterfaces.usbEthAdaptersInterfacesListForDmngEthAdapter)): interfaceName = networkInterfaces.usbEthAdaptersInterfacesListForDmngEthAdapter[index][0] commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--out-interface', interfaceName, '--jump', 'MASQUERADE']) for index in range(0, len(networkInterfaces.usbEthAdaptersInterfacesListForDmngUsbEthAdapter)): interfaceName = networkInterfaces.usbEthAdaptersInterfacesListForDmngUsbEthAdapter[index][0] commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--out-interface', interfaceName, '--jump', 'MASQUERADE']) #commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--source', '192.168.56.0/255.255.255.0', '--out-interface', globals.aviwestLanIfc, '--jump', 'MASQUERADE']) #commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--source', '127.0.0.1/255.255.255.0', '--out-interface', globals.aviwestLanIfc, '--jump', 'MASQUERADE']) #commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--out-interface', globals.linuxVmStudioTrafficLanIfc, '--jump', 'MASQUERADE']) #commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--out-interface', globals.linuxVmStudioSshLanIfc, '--jump', 'MASQUERADE']) #commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--out-interface', globals.windowsVmStudioTrafficLanIfc, '--jump', 'MASQUERADE']) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command)
def startSshServer(self): utils.displayText('cyan', 'starting dmng\'s ssh server', 0) commandsList = [['/etc/init.d/S50sshd start', ['Starting sshd: OK'], 20]] for index in range(len(commandsList)): command = commandsList[index][0] expectedStringsList = commandsList[index][1] waitingTime = commandsList[index][2] self.writeToSerial(command, expectedStringsList, 60)
def setNatOutputRules(): utils.displayText('cyan', 'setting nat output rules rules...', 0) commandsList = [] commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'OUTPUT', '--jump', 'ACCEPT']) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command)
def setManglePreroutingRules(): utils.displayText('cyan', 'setting mangle prerouting rules...', 0) commandsList = [] commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--table', 'mangle', '--append', 'PREROUTING', '--jump', 'LOG', '--log-level 7', '--log-prefix', 'MANGLE-PREROUTING: ']) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command)
def getAppliVersion(self): utils.displayText('cyan', 'getting appli version', 0) serialOutputUntilTimeout = self.writeToSerial( 'cat /app/appli-version | awk \'{ print $1 }\'', ['[0-9]+.[0-9]+.[0-9]+-svn[0-9]+'], 30) myRe = re.search('[0-9]+.[0-9]+.[0-9]+-svn[0-9]+', serialOutputUntilTimeout) appliVersion = myRe.group() return appliVersion
def getUbootMode(self): utils.displayText('cyan', 'getting U-Boot mode', 0) serialOutputUntilTimeout = self.writeToSerial('fw_printenv bootmode', ['(bootmode=appli|test)|(# Error: "bootmode" not defined)'], 10) try: myRe = re.search('bootmode=appli|test', serialOutputUntilTimeout) ubootMode = re.sub('bootmode=', '', myRe.group()) except: ubootMode = 'not set' return ubootMode
def setDefaultPolicy(): utils.displayText('cyan', 'setting default policy...', 0) commandsList = [] commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--policy', 'INPUT', 'DROP']) commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--policy', 'OUTPUT', 'DROP']) commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--policy', 'FORWARD', 'DROP']) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command)
def setNetworkInterfaceState(self, interfaceName, requestedState): # check requestedState values if (requestedState != 'up') and (requestedState != 'down'): utils.displayText( 'red', '[KO] requestedState (%s) is neither \'up\', nor \'down\'' % requestedState, 0) utils.terminateTest(1) self.writeToSerial('ifconfig %s %s' % (interfaceName, requestedState), [], 10)
def startSshServer(self): utils.displayText('cyan', 'starting dmng\'s ssh server', 0) commandsList = [[ '/etc/init.d/S50sshd start', ['Starting sshd: OK'], 20 ]] for index in range(len(commandsList)): command = commandsList[index][0] expectedStringsList = commandsList[index][1] waitingTime = commandsList[index][2] self.writeToSerial(command, expectedStringsList, 60)
def getUbootMode(self): utils.displayText('cyan', 'getting U-Boot mode', 0) serialOutputUntilTimeout = self.writeToSerial( 'fw_printenv bootmode', ['(bootmode=appli|test)|(# Error: "bootmode" not defined)'], 10) try: myRe = re.search('bootmode=appli|test', serialOutputUntilTimeout) ubootMode = re.sub('bootmode=', '', myRe.group()) except: ubootMode = 'not set' return ubootMode
def kill(self): '''kill any instance of sst-rx self.host_name (through ssh on port self.port) ''' command = ['/usr/bin/ssh', '-T', '-p', '%d' % self.port, '%s' % self.host_name, '/usr/bin/killall sst-rx > /dev/null 2>&1'] commandString = ' '.join(command) if not globals.quiet: utils.displayText('normal', 'executing command : %s' % commandString, 0) p = subprocess.Popen(command, bufsize=-1, shell = False, stdin= None, stdout = subprocess.PIPE, stderr = subprocess.PIPE, env={'LANG':'en_GB.utf-8'}) p.communicate()
def writeToSerial(self, data, expectedStringsList, timeout): # compute command execution time if globals.verbose: commandStartTime = datetime.datetime.now() # only one concurrent access to the serial port : lock self.lock.acquire() # initializations serialOutputUntilTimeout = '' # security : timeout has to be greater than 0 if timeout == 0: timeout = 10 displayText('yellow', '[WARNING] timeout was set to 0, it has been set to 10', 0) # check execution result (return code) except for some commands (either the command does not return a reliable code, or we want to speed up execution time (tc commands)) # do not check execution result of command "fw_printenv bootmode", which can fail (if bootmode environment variable does not exist, which can be the case after an upgrade) if data != 'reboot' and \ data != 'admin' and \ data != 'ibis2010' and \ re.search('fw_printenv bootmode', data) == None and \ re.search('longwood', data) == None and \ re.search('wpa_supplicant', data) == None and \ re.search('/usr/bin/killall', data) == None and \ re.search('/sbin/tc qdisc del', data) == None and \ re.search('streamer -s', data) == None and \ re.search('tc qdisc', data) == None: data = data + '; ' + '/bin/echo returnCode=$?' expectedStringsList.append('returnCode=0') if not globals.quiet: utils.displayText('normal', 'sending command on serial %s : %s' % (self.ser.portstr, data) , 0) data = data + '\n' self.ser.write(data.encode('utf-8')) if len(expectedStringsList) > 0: serialOutputUntilTimeout = self.expectStringsOnSerial(expectedStringsList, timeout) else: serialOutputUntilTimeout = '' # only one concurrent access to the serial port : unlock self.lock.release() # compute command execution time if globals.verbose: commandEndTime = datetime.datetime.now() commandExecutionDuration = (commandEndTime - commandStartTime).seconds * 1000 + (commandEndTime - commandStartTime).microseconds / 1000 utils.displayText('green', '[OK] command executed successfully in %d milliseconds' % commandExecutionDuration, 0) return serialOutputUntilTimeout
def increaseMemoryForBetterOomResistance(self): value = 8192 utils.displayText('cyan', 'setting vm.min_free_kbytes to %d' % value, 0) # vm.min_free_kbytes : this is used to force the Linux VM to keep a minimum number of kilobytes free commandsList = [['sysctl -w vm.min_free_kbytes=%d' % value, ['vm.min_free_kbytes = %d' % value], 0]] for index in range(len(commandsList)): command = commandsList[index][0] expectedStringsList = commandsList[index][1] waitingTime = commandsList[index][2] self.writeToSerial(command, expectedStringsList, 60) utils.displayText('normal', 'waiting for command \'%s\' to complete' % command, waitingTime)
def setNatOutputRules(): utils.displayText('cyan', 'setting nat output rules rules...', 0) commandsList = [] commandsList.append([ '/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'OUTPUT', '--jump', 'ACCEPT' ]) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command)
def startAviwestStreaming(self, timeWindow): self.writeToSerial('abus-send sst-tx.StreamConnect timewindow=%s' % timeWindow, ['New timewindow %d ms' % timeWindow, 'Aggreg WAIT_RESP->CONNECTED'], 30) self.writeToSerial('while ! abus-send sst-tx.get CommandReady | grep CommandReady=true; do sleep 1; done', ['CommandReady=true'], 30) status = self.getAviwestConnectionStatus() if status != 'connected': utils.displayText('red', 'status is not the expected one (current status is : %s; expected status was : connected)' % status, 0) utils.terminateTest(1) self.writeToSerial('abus-send sst-tx.StreamStart', ['tx_aggreg_do_cmd: CONNECTED\(StreamStart\)'], 30) status = self.getAviwestConnectionStatus() if status != 'connected': utils.displayText('red', 'status is not the expected one (current status is : %s; expected status was : connected)' % status, 0) utils.terminateTest(1)
def startAviwestBwTest(self): self.writeToSerial('abus-send sst-tx.BandwidthTestConnect', ['Aggreg WAIT_RESP->CONNECTED'], 30) self.writeToSerial('while ! abus-send sst-tx.get CommandReady | grep CommandReady=true; do sleep 1; done', ['CommandReady=true'], 30) status = self.getAviwestConnectionStatus() if status != 'connected': utils.displayText('red', 'status is not the expected one (current status is : %s; expected status was : connected)' % status, 0) utils.terminateTest(1) self.writeToSerial('abus-send sst-tx.BandwidthTestStart', ['Aggreg CONNECTED->BW_TEST'], 30) status = self.getAviwestConnectionStatus() if status != 'connected': utils.displayText('red', 'status is not the expected one (current status is : %s; expected status was : connected)' % status, 0) utils.terminateTest(1)
def setNatPostroutingRules(): utils.displayText('cyan', 'setting nat postrouting rules (source NAT)...', 0) commandsList = [] commandsList.append([ '/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--out-interface', globals.aviwestLanIfc, '--jump', 'MASQUERADE' ]) # allow any kind of traffic to go back from studio to globals.dmngLanIfc if globals.platformType == 'development': commandsList.append([ '/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--out-interface', globals.dmngLanIfc, '--jump', 'MASQUERADE' ]) if globals.platformType == 'validation': for index in range( 0, len(networkInterfaces. usbEthAdaptersInterfacesListForDmngEthAdapter)): interfaceName = networkInterfaces.usbEthAdaptersInterfacesListForDmngEthAdapter[ index][0] commandsList.append([ '/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--out-interface', interfaceName, '--jump', 'MASQUERADE' ]) for index in range( 0, len(networkInterfaces. usbEthAdaptersInterfacesListForDmngUsbEthAdapter)): interfaceName = networkInterfaces.usbEthAdaptersInterfacesListForDmngUsbEthAdapter[ index][0] commandsList.append([ '/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--out-interface', interfaceName, '--jump', 'MASQUERADE' ]) #commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--source', '192.168.56.0/255.255.255.0', '--out-interface', globals.aviwestLanIfc, '--jump', 'MASQUERADE']) #commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--source', '127.0.0.1/255.255.255.0', '--out-interface', globals.aviwestLanIfc, '--jump', 'MASQUERADE']) #commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--out-interface', globals.linuxVmStudioTrafficLanIfc, '--jump', 'MASQUERADE']) #commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--out-interface', globals.linuxVmStudioSshLanIfc, '--jump', 'MASQUERADE']) #commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--append', 'POSTROUTING', '--out-interface', globals.windowsVmStudioTrafficLanIfc, '--jump', 'MASQUERADE']) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command)
def setManglePreroutingRules(): utils.displayText('cyan', 'setting mangle prerouting rules...', 0) commandsList = [] commandsList.append([ '/usr/bin/sudo', '/sbin/iptables', '--table', 'mangle', '--append', 'PREROUTING', '--jump', 'LOG', '--log-level 7', '--log-prefix', 'MANGLE-PREROUTING: ' ]) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command)
def setDefaultPolicy(): utils.displayText('cyan', 'setting default policy...', 0) commandsList = [] commandsList.append( ['/usr/bin/sudo', '/sbin/iptables', '--policy', 'INPUT', 'DROP']) commandsList.append( ['/usr/bin/sudo', '/sbin/iptables', '--policy', 'OUTPUT', 'DROP']) commandsList.append( ['/usr/bin/sudo', '/sbin/iptables', '--policy', 'FORWARD', 'DROP']) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command)
def stopKenCastBwTest(self): self.waitForKenCastConnectionStatus('connected') serialOutputUntilTimeout = self.writeToSerial('/app/fazzt/scripts/BandwidthTestStop.fzt', [], 30) myRe = re.search('[0-9]+', serialOutputUntilTimeout) # estimatedBitrate in kbps estimatedBitrate = int(myRe.group()) if globals.verbose: utils.displayText('yellow', 'estimatedBitrate : %s' % estimatedBitrate, 0) self.waitForKenCastConnectionStatus('connected') return estimatedBitrate
def setAllNetworkInterfacesState(self, requestedState): # check requestedState values if (requestedState != 'up') and (requestedState != 'down'): utils.displayText('red', '[KO] requestedState (%s) is neither \'up\', nor \'down\'' % requestedState, 0) utils.terminateTest(1) # do not modify controlNetworkInterface here... (when connected to the device through ssh, we do not want to disable this link) utils.displayText('cyan', 'setting up ethAdaptersInterfacesList in state %s' % requestedState, 0) for i in range(len(self.ethAdaptersInterfacesList)): interfaceName = self.ethAdaptersInterfacesList[i][0] self.setNetworkInterfaceState(interfaceName, requestedState) if (requestedState == 'up'): defaultGateway = self.ethAdaptersInterfacesList[i][5] self.setNetworkInterfaceDefaultGw(interfaceName, defaultGateway) utils.displayText('cyan', 'setting up usbEthAdaptersInterfacesList in state %s' % requestedState, 0) for i in range(len(self.usbEthAdaptersInterfacesList)): interfaceName = self.usbEthAdaptersInterfacesList[i][0] self.setNetworkInterfaceState(interfaceName, requestedState) if (requestedState == 'up'): defaultGateway = self.usbEthAdaptersInterfacesList[i][5] self.setNetworkInterfaceDefaultGw(interfaceName, defaultGateway) utils.displayText('cyan', 'setting up wifiAdaptersInterfacesList in state %s' % requestedState, 0) for i in range(len(self.wifiAdaptersInterfacesList)): interfaceName = self.wifiAdaptersInterfacesList[i][0] self.setNetworkInterfaceState(interfaceName, requestedState) if (requestedState == 'up'): defaultGateway = self.wifiAdaptersInterfacesList[i][5] self.setNetworkInterfaceDefaultGw(interfaceName, defaultGateway)
def setOutputRules(): utils.displayText('cyan', 'setting output rules...', 0) commandsList = [] # allow output traffic for established connections ##commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--append', 'OUTPUT', '--match', state, '--state', 'RELATED,ESTABLISHED', '--jump', 'ACCEPT']) commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--append', 'OUTPUT', '--match', 'state', '!', '--state', 'INVALID', '--jump', 'ACCEPT']) # allow everything for now (TODO) commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--append', 'OUTPUT', '--jump', 'ACCEPT']) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command)
def stopKenCastBwTest(self): self.waitForKenCastConnectionStatus('connected') serialOutputUntilTimeout = self.writeToSerial( '/app/fazzt/scripts/BandwidthTestStop.fzt', [], 30) myRe = re.search('[0-9]+', serialOutputUntilTimeout) # estimatedBitrate in kbps estimatedBitrate = int(myRe.group()) if globals.verbose: utils.displayText('yellow', 'estimatedBitrate : %s' % estimatedBitrate, 0) self.waitForKenCastConnectionStatus('connected') return estimatedBitrate
def deActivateUsb(self): utils.displayText('cyan', 'deactivating dmng\'s usb', 0) # when disabling usb, assume we have 9 usb-eth adapters to build the list of expected strings to expect commandsList = [ [ 'longwood -reset_ethernet_phy 1', [ 'unregister \'smsc75xx\' usb-ehci-omap.[0-9]-[0-9].[0-9], smsc75xx USB 2.0 Gigabit Ethernet' ] ], # TODO : understand why I get 'UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 in position 10: unexpected end of data' when using 'longwood -stat' command #['longwood -stat', ['USB HUB enable --> 1', 'Phy0 enable --> 1', 'Phy1 enable --> 0']], [ 'longwood -reset_ethernet_phy 0', [ 'unregister \'smsc75xx\' usb-ehci-omap.[0-9]-[0-9].[0-9], smsc75xx USB 2.0 Gigabit Ethernet' ] ], # TODO : understand why I get 'UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 in position 10: unexpected end of data' when using 'longwood -stat' command #['longwood -stat', ['USB HUB enable --> 1', 'Phy0 enable --> 0', 'Phy1 enable --> 0']], [ 'longwood -reset_usb_hubs', [ 'unregister \'asix\' usb-ehci-omap.[0-9]-[0-9].[0-9].[0-9], ASIX AX88772 USB 2.0 Ethernet', 'unregister \'asix\' usb-ehci-omap.[0-9]-[0-9].[0-9].[0-9], ASIX AX88772 USB 2.0 Ethernet', 'unregister \'asix\' usb-ehci-omap.[0-9]-[0-9].[0-9].[0-9], ASIX AX88772 USB 2.0 Ethernet', 'unregister \'asix\' usb-ehci-omap.[0-9]-[0-9].[0-9].[0-9], ASIX AX88772 USB 2.0 Ethernet', 'unregister \'asix\' usb-ehci-omap.[0-9]-[0-9].[0-9].[0-9], ASIX AX88772 USB 2.0 Ethernet', 'unregister \'asix\' usb-ehci-omap.[0-9]-[0-9].[0-9].[0-9], ASIX AX88772 USB 2.0 Ethernet', 'unregister \'asix\' usb-ehci-omap.[0-9]-[0-9].[0-9].[0-9], ASIX AX88772 USB 2.0 Ethernet', 'unregister \'asix\' usb-ehci-omap.[0-9]-[0-9].[0-9].[0-9], ASIX AX88772 USB 2.0 Ethernet', 'unregister \'asix\' usb-ehci-omap.[0-9]-[0-9].[0-9].[0-9], ASIX AX88772 USB 2.0 Ethernet' ] ] # TODO : understand why I get 'UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 in position 10: unexpected end of data' when using 'longwood -stat' command #['longwood -stat', ['USB HUB enable --> 0', 'Phy0 enable --> 0', 'Phy1 enable --> 0']] ] for index in range(len(commandsList)): command = commandsList[index][0] expectedStringsList = commandsList[index][1] self.writeToSerial(command, expectedStringsList, 20) utils.displayText( 'cyan', 'waiting a little bit to not be disturbed by asynchronous traces', 20)
def setState(networkInterface, requestedState): # check requestedState values if (requestedState != 'up') and (requestedState != 'down'): utils.displayText('red', '[KO] requestedState (%s) is neither \'up\', nor \'down\'' % requestedState, 0) utils.terminateTest(1) if requestedState == 'down': command = ['/usr/bin/sudo', '/sbin/ifdown', networkInterface] if requestedState == 'up': command = ['/usr/bin/sudo', '/sbin/ifup', networkInterface] commandStdout, commandStderr = utils.executeCommand(command) '''
def setForwardRules(): utils.displayText('cyan', 'setting forward rules...', 0) commandsList = [] # allow forward traffic for established connections commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--append', 'FORWARD', '--match', 'state', '--state', 'RELATED,ESTABLISHED', '--jump', 'ACCEPT']) # allow all forward traffic on all interfaces commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--append', 'FORWARD', '--jump', 'ACCEPT']) # for testing ssh commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--append', 'FORWARD', '--in-interface', globals.aviwestLanIfc, '--destination', globals.linuxVmStudioIpAddressForSsh, '--protocol', 'tcp', '--destination-port', '22', '--jump', 'ACCEPT']) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command)
def rebootAndReconfigureDmng(self): self.reboot() self.increaseMemoryForBetterOomResistance() self.activateUsb() self.renameNetworkInterfaces() if globals.aggregationsModes.count('kencast') != 0: self.writeToSerial( 'export LD_LIBRARY_PATH=/app/lib:/app/fazzt/lib:${LD_LIBRARY_PATH}', [], 10) if globals.useControlNetworkInterface: # -------------------------------------------------------------------------------------------------- utils.displayText( 'blue', 'setting up controlNetworkInterface, that will be used to drive the dmng (no traffic control on this interface)', 0) # -------------------------------------------------------------------------------------------------- interfaceName = self.controlNetworkInterface[0] self.networkInterfaceFirstInit(interfaceName) self.startSshServer() # -------------------------------------------------------------------------------------------------- utils.displayText('blue', 'configuring dmng\'s involved network interfaces', 0) # -------------------------------------------------------------------------------------------------- utils.displayText( 'blue', 'configuring %d ethAdapters' % globals.maxNbOfEthAdapters, 0) for i in range(globals.maxNbOfEthAdapters): interfaceName = self.ethAdaptersInterfacesList[i][0] self.networkInterfaceFirstInit(interfaceName) utils.displayText( 'blue', 'configuring %d usbEthAdapters' % globals.maxNbOfUsbEthAdapters, 0) for i in range(globals.maxNbOfUsbEthAdapters): interfaceName = self.usbEthAdaptersInterfacesList[i][0] self.networkInterfaceFirstInit(interfaceName) utils.displayText( 'blue', 'configuring %d wifiAdapters' % globals.maxNbOfWifiAdapters, 0) for i in range(globals.maxNbOfWifiAdapters): interfaceName = self.wifiAdaptersInterfacesList[i][0] self.networkInterfaceFirstInit(interfaceName)
def start(self): '''run command on self.host_name in background (through ssh on port self.port) @param command : command to launch @return process ID ''' commandsList = [] commandsList.append([ '/usr/bin/ssh', '-T', '-p', '%d' % self.port, '%s' % self.host_name, 'test -x %s' % globals.gatewaySstRxBinary ]) commandsList.append(['test', '-x', globals.sstRxBinary]) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command) command = [ '/usr/bin/ssh', '-T', '-p', '%d' % self.port, '%s' % self.host_name, '%s -v -T -L %s -l %s:%s' % (globals.gatewaySstRxBinary, globals.gatewaySstRxLogFile, globals.gatewaySstRxLogin, globals.gatewaySstRxPassword) ] commandString = ' '.join(command) if not globals.quiet: utils.displayText('normal', 'executing command : %s' % commandString, 0) self.ssh = subprocess.Popen(command, bufsize=-1, shell=False, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env={'LANG': 'en_GB.utf-8'}) if self.ssh == None: utils.displayText( 'red', '[KO] the following command failed : %s' % ' '.join(command), 0) utils.terminateTest(1)
def buildStudioSstTx(): '''buildStudioSstTx executable will be launched on dmng ''' if not os.path.isfile(globals.sourcesDirectory + '/' + '.svn/entries'): utils.displayText('red', 'globals.sourcesDirectory is not a svn working copy, call getNewAppliSvnWc first', 0) utils.terminateTest(1) commandsList = [] commandsList.append(['CROSS_COMPILE=arm-linux-', 'PATH=%s/ccache:%s:$PATH' % (armCompilerDirectory, armCompilerDirectory), 'make', 'init', '--directory', globals.sourcesDirectory]) commandsList.append(['CROSS_COMPILE=arm-linux-', 'PATH=%s/ccache:%s:$PATH' % (armCompilerDirectory, armCompilerDirectory), 'make', '--directory', globals.sourcesDirectory]) commandsList.append(['test', '-x', globals.sstTxBinary]) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command)
def setState(networkInterface, requestedState): # check requestedState values if (requestedState != 'up') and (requestedState != 'down'): utils.displayText( 'red', '[KO] requestedState (%s) is neither \'up\', nor \'down\'' % requestedState, 0) utils.terminateTest(1) if requestedState == 'down': command = ['/usr/bin/sudo', '/sbin/ifdown', networkInterface] if requestedState == 'up': command = ['/usr/bin/sudo', '/sbin/ifup', networkInterface] commandStdout, commandStderr = utils.executeCommand(command) '''
def increaseMemoryForBetterOomResistance(self): value = 8192 utils.displayText('cyan', 'setting vm.min_free_kbytes to %d' % value, 0) # vm.min_free_kbytes : this is used to force the Linux VM to keep a minimum number of kilobytes free commandsList = [[ 'sysctl -w vm.min_free_kbytes=%d' % value, ['vm.min_free_kbytes = %d' % value], 0 ]] for index in range(len(commandsList)): command = commandsList[index][0] expectedStringsList = commandsList[index][1] waitingTime = commandsList[index][2] self.writeToSerial(command, expectedStringsList, 60) utils.displayText( 'normal', 'waiting for command \'%s\' to complete' % command, waitingTime)
def initChains(): utils.displayText('cyan', 'initializing chains...', 0) commandsList = [] ''' commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--flush', 'INPUT']) commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--flush', 'OUTPUT']) commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--flush', 'FORWARD']) ''' commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--flush']) commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--flush', '--table', 'nat']) commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--flush', '--table', 'mangle']) commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--delete-chain']) commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--delete-chain', '--table', 'nat']) commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--delete-chain', '--table', 'mangle']) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command)
def getNewAppliSvnWc(svnRevision): '''getNewAppliSvnWc ''' # create globals.sourcesDirectory if it does not exist for a fresh checkout if os.path.exists(globals.sourcesDirectory): utils.displayText('cyan', 'deleting directory %s' % globals.sourcesDirectory, 0) shutil.rmtree(globals.sourcesDirectory) os.makedirs(globals.sourcesDirectory) commandsList = [] commandsList.append(['svn', 'checkout', '--revision', svnRevision, svnUrl, globals.sourcesDirectory]) #utils.displayText('cyan', 'updating %s to revision %s' % (globals.sourcesDirectory, svnRevision), 0) #commandsList.append(['svn', 'update', '--revision', svnRevision, globals.sourcesDirectory]) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command) utils.displayText('cyan', 'updating external references to revision %s' % svnRevision, 0) commandsList = [] externalReferencesCommandList = ['svn', 'update', '--revision', svnRevision] directoriesList = [] directoriesList.append(globals.sourcesDirectory + '/' + 'common') directoriesList.append(globals.sourcesDirectory + '/' + 'aggreg-sst/aggreg-sst') directoriesList.append(globals.sourcesDirectory + '/' + 'dmng-lib/dmng-lib/ibis-interface/src') directoriesList.append(globals.sourcesDirectory + '/' + 'dmng-lib/dmng-lib/ibis-interface/include') directoriesList.append(globals.sourcesDirectory + '/' + 'dmng-lib/dmng-lib/aacparser/src') directoriesList.append(globals.sourcesDirectory + '/' + 'dmng-lib/dmng-lib/aacparser/include') directoriesList.append(globals.sourcesDirectory + '/' + 'include/xcom.h') directoriesList.append(globals.sourcesDirectory + '/' + 'include/xconfig.h') directoriesList.append(globals.sourcesDirectory + '/' + 'gst-plugins/gst-plugins/xcom') directoriesList.append(globals.sourcesDirectory + '/' + 'gst-plugins/gst-plugins/mp4mux') directoriesList.append(globals.sourcesDirectory + '/' + 'gst-plugins/gst-plugins/awdsp') # append directories to externalReferencesCommandList for index in range(len(directoriesList)): externalReferencesCommandList.append(directoriesList[index]) commandsList.append(externalReferencesCommandList) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command)
def getEmailsAddressesList(): ''' to avoid specifying email addresses, make a link between login name and email addresses ''' userLogged = os.getlogin() emailsAddressesList = [] if userLogged == 'arnaud': emailsAddressesList.append('*****@*****.**') #emailsAddressesList.append('*****@*****.**') elif userLogged == 'sfillod': emailsAddressesList.append('*****@*****.**') else: utils.displayText('red', 'userLogged (%s) unknown' % userLogged, 0) sys.exit(1) #utils.terminateTest(1) return emailsAddressesList
def getEmailsAddressesList(): ''' to avoid specifying email addresses, make a link between login name and email addresses ''' userLogged = os.getlogin() emailsAddressesList = [] if userLogged == 'arnaud': emailsAddressesList.append('*****@*****.**') #emailsAddressesList.append('*****@*****.**') elif userLogged == 'sfillod': emailsAddressesList.append('*****@*****.**') else : utils.displayText('red', 'userLogged (%s) unknown' % userLogged, 0) sys.exit(1) #utils.terminateTest(1) return emailsAddressesList
def executeCommandsList(commandsList): for command in commandsList: ''' # get tcQdiscAction from commandsList (get qdisc position, guess action position (which comes next)) try: qdiscIndex = command.index('qdisc') except: utils.displayText('yellow', '[WARNING] \'qdisc\' not found in command (%s)' % command, 0) #utils.terminateTest(1) actionIndex = qdiscIndex + 1 tcQdiscAction = command[actionIndex] ''' commandString = ' '.join(command) if not globals.quiet: utils.displayText('normal', 'executing command : %s' % commandString, 0) p = subprocess.Popen(command, bufsize=-1, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env={'LANG': 'en_GB.utf-8'}) commandStdout, commandStderr = p.communicate() # decode commandStdout and commandStderr (bytes objects) to produce strings commandStdout = commandStdout.decode("utf-8") commandStderr = commandStderr.decode("utf-8") ''' # TODO : if tcQdiscAction is del : ignore any error which can be linked to the fact that no traffic control configuration was set. Maybe we could do something better here. if tcQdiscAction != 'del': if p.returncode != 0: utils.displayText('red', 'the following command failed : %s' % ' '.join(command), 0) if globals.verbose: utils.displayText('normal', 'commandStdout :', 0) utils.displayText('normal', commandStdout, 0) utils.displayText('normal', 'commandStderr :', 0) utils.displayText('normal', commandStderr, 0) utils.terminateTest(1) ''' return commandStdout, commandStderr
def getNetworkInterfaceLinkStatus(networkInterface): utils.displayText('red', 'TODO : testing an IP alias with ethtool always report : \'Link detected: yes\'. It cannot be used here.', 0) utils.terminateTest(1) command = ['/usr/bin/sudo', '/sbin/ethtool', networkInterface] commandStdout, commandStderr = utils.executeCommand(command) # get "Link detected:" myRe = re.search('Link detected: yes|no', commandStdout) linkDetected = re.sub('Link detected: ', '', myRe.group()) if linkDetected == 'yes': networkInterfaceStatus = 'up' elif linkDetected == 'no': networkInterfaceStatus = 'down' else: utils.displayText('red', '[KO] linkDetected (%s) is neither \'yes\', nor \'no\'' % linkDetected, 0) utils.terminateTest(1) return networkInterfaceStatus
def setOutputRules(): utils.displayText('cyan', 'setting output rules...', 0) commandsList = [] # allow output traffic for established connections ##commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--append', 'OUTPUT', '--match', state, '--state', 'RELATED,ESTABLISHED', '--jump', 'ACCEPT']) commandsList.append([ '/usr/bin/sudo', '/sbin/iptables', '--append', 'OUTPUT', '--match', 'state', '!', '--state', 'INVALID', '--jump', 'ACCEPT' ]) # allow everything for now (TODO) commandsList.append([ '/usr/bin/sudo', '/sbin/iptables', '--append', 'OUTPUT', '--jump', 'ACCEPT' ]) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command)
def activateUsb(self): utils.displayText('cyan', 'activating dmng\'s usb', 0) # when enabling usb, assume we have 9 usb-eth adapters to build the list of expected strings to expect commandsList = [ ['longwood -enable_usb_hubs', ['ASIX AX88772 USB 2.0 Ethernet', 'ASIX AX88772 USB 2.0 Ethernet', 'ASIX AX88772 USB 2.0 Ethernet', 'ASIX AX88772 USB 2.0 Ethernet', 'ASIX AX88772 USB 2.0 Ethernet', 'ASIX AX88772 USB 2.0 Ethernet', 'ASIX AX88772 USB 2.0 Ethernet', 'ASIX AX88772 USB 2.0 Ethernet', 'ASIX AX88772 USB 2.0 Ethernet']], # TODO : understand why I get 'UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 in position 10: unexpected end of data' when using 'longwood -stat' command #['longwood -stat', ['USB HUB enable --> 1', 'Phy0 enable --> 0', 'Phy1 enable --> 0']], ['longwood -enable_ethernet_phy 0', ['register \'smsc75xx\' at usb-ehci-omap.[0-9]-[0-9].[0-9], smsc75xx USB 2.0 Gigabit Ethernet']], # TODO : understand why I get 'UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 in position 10: unexpected end of data' when using 'longwood -stat' command #['longwood -stat', ['USB HUB enable --> 1', 'Phy0 enable --> 1', 'Phy1 enable --> 0']], ['longwood -enable_ethernet_phy 1', ['register \'smsc75xx\' at usb-ehci-omap.[0-9]-[0-9].[0-9], smsc75xx USB 2.0 Gigabit Ethernet']] # TODO : understand why I get 'UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 in position 10: unexpected end of data' when using 'longwood -stat' command #['longwood -stat', ['USB HUB enable --> 1', 'Phy0 enable --> 1', 'Phy1 enable --> 1']] ] for index in range(len(commandsList)): command = commandsList[index][0] expectedStringsList = commandsList[index][1] self.writeToSerial(command, expectedStringsList, 20) utils.displayText('cyan', 'waiting a little bit to not be disturbed by asynchronous traces', 20)
def stopAviwestBwTest(self): status = self.getAviwestConnectionStatus() if status != 'connected': utils.displayText( 'red', 'status is not the expected one (current status is : %s; expected status was : connected)' % status, 0) utils.terminateTest(1) serialOutputUntilTimeout = self.writeToSerial( 'abus-send sst-tx.BandwidthTestStop', ['bitrate='], 30) myRe = re.search('bitrate=[0-9]+', serialOutputUntilTimeout) # estimatedBitrate in kbps estimatedBitrate = int(re.sub('bitrate=', '', myRe.group())) estimatedBitrate = estimatedBitrate / 1000 if globals.verbose: utils.displayText('yellow', 'estimatedBitrate : %s' % estimatedBitrate, 0) self.writeToSerial( 'while ! abus-send sst-tx.get CommandReady | grep CommandReady=true; do sleep 1; done', ['CommandReady=true'], 30) status = self.getAviwestConnectionStatus() if status != 'connected': utils.displayText( 'red', 'status is not the expected one (current status is : %s; expected status was : connected)' % status, 0) utils.terminateTest(1) return estimatedBitrate
def startAviwestBwTest(self): self.writeToSerial('abus-send sst-tx.BandwidthTestConnect', ['Aggreg WAIT_RESP->CONNECTED'], 30) self.writeToSerial( 'while ! abus-send sst-tx.get CommandReady | grep CommandReady=true; do sleep 1; done', ['CommandReady=true'], 30) status = self.getAviwestConnectionStatus() if status != 'connected': utils.displayText( 'red', 'status is not the expected one (current status is : %s; expected status was : connected)' % status, 0) utils.terminateTest(1) self.writeToSerial('abus-send sst-tx.BandwidthTestStart', ['Aggreg CONNECTED->BW_TEST'], 30) status = self.getAviwestConnectionStatus() if status != 'connected': utils.displayText( 'red', 'status is not the expected one (current status is : %s; expected status was : connected)' % status, 0) utils.terminateTest(1)
def kill(self): '''kill any instance of sst-rx self.host_name (through ssh on port self.port) ''' command = [ '/usr/bin/ssh', '-T', '-p', '%d' % self.port, '%s' % self.host_name, '/usr/bin/killall sst-rx > /dev/null 2>&1' ] commandString = ' '.join(command) if not globals.quiet: utils.displayText('normal', 'executing command : %s' % commandString, 0) p = subprocess.Popen(command, bufsize=-1, shell=False, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env={'LANG': 'en_GB.utf-8'}) p.communicate()
def executeCommandsList(commandsList): for command in commandsList: ''' # get tcQdiscAction from commandsList (get qdisc position, guess action position (which comes next)) try: qdiscIndex = command.index('qdisc') except: utils.displayText('yellow', '[WARNING] \'qdisc\' not found in command (%s)' % command, 0) #utils.terminateTest(1) actionIndex = qdiscIndex + 1 tcQdiscAction = command[actionIndex] ''' commandString = ' '.join(command) if not globals.quiet: utils.displayText('normal', 'executing command : %s' % commandString, 0) p = subprocess.Popen(command, bufsize=-1, shell = False, stdout = subprocess.PIPE, stderr = subprocess.PIPE, env={'LANG':'en_GB.utf-8'}) commandStdout, commandStderr = p.communicate() # decode commandStdout and commandStderr (bytes objects) to produce strings commandStdout = commandStdout.decode("utf-8") commandStderr = commandStderr.decode("utf-8") ''' # TODO : if tcQdiscAction is del : ignore any error which can be linked to the fact that no traffic control configuration was set. Maybe we could do something better here. if tcQdiscAction != 'del': if p.returncode != 0: utils.displayText('red', 'the following command failed : %s' % ' '.join(command), 0) if globals.verbose: utils.displayText('normal', 'commandStdout :', 0) utils.displayText('normal', commandStdout, 0) utils.displayText('normal', 'commandStderr :', 0) utils.displayText('normal', commandStderr, 0) utils.terminateTest(1) ''' return commandStdout, commandStderr
def buildStudioSstRx(): '''buildStudioSstRx executable will be launched on studio-sst-rx (x86) ''' if not os.path.isfile(globals.sourcesDirectory + '/' + '.svn/entries'): utils.displayText('red', 'globals.sourcesDirectory is not a svn working copy, call getNewAppliSvnWc first', 0) utils.terminateTest(1) if os.path.isdir(globals.sstRxBuildDirectory): shutil.rmtree(globals.sstRxBuildDirectory) os.makedirs(globals.sstRxBuildDirectory) # make init mandatory here (to generated the configure file) os.chdir(globals.sourcesDirectory) commandsList = [] commandsList.append(['CROSS_COMPILE=arm-linux-', 'PATH=%s/ccache:%s:$PATH' % (armCompilerDirectory, armCompilerDirectory), 'make', 'init', '--directory', globals.sourcesDirectory]) #commandsList.append(['PATH=%s/ccache:%s:$PATH' % (armCompilerDirectory, armCompilerDirectory), 'make', 'init', '--directory', globals.sourcesDirectory]) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command) os.chdir(globals.sstRxBuildDirectory) commandsList = [] #commandsList.append(['PATH=%s/ccache:%s:$PATH' % (armCompilerDirectory, armCompilerDirectory), 'make', 'init', '--directory', globals.sourcesDirectory]) commandsList.append(['PATH=%s/ccache:%s:$PATH' % (armCompilerDirectory, armCompilerDirectory), '%s/aggreg-sst/aggreg-sst/configure --enable-maintainer-mode --enable-sst-rx-only --prefix=$(pwd)/inst' % globals.sourcesDirectory]) commandsList.append(['PATH=%s/ccache:%s:$PATH' % (armCompilerDirectory, armCompilerDirectory), 'make', '--directory', globals.sstRxBuildDirectory]) commandsList.append(['test', '-x', '%s/Build/_install/bin/sst-tx' % globals.sourcesDirectory]) commandsList.append(['PATH=%s/ccache:%s:$PATH' % (armCompilerDirectory, armCompilerDirectory), 'make', '--directory', '%s/aggreg-common' % globals.sstRxBuildDirectory]) commandsList.append(['PATH=%s/ccache:%s:$PATH' % (armCompilerDirectory, armCompilerDirectory), 'make', '--directory', '%s/aggreg-studio' % globals.sstRxBuildDirectory]) commandsList.append(['test -x %s' % globals.sstRxBinary]) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command)
def start(self): '''run command on self.host_name in background (through ssh on port self.port) @param command : command to launch @return process ID ''' commandsList = [] commandsList.append(['/usr/bin/ssh', '-T', '-p', '%d' % self.port, '%s' % self.host_name, 'test -x %s' % globals.gatewaySstRxBinary]) commandsList.append(['test', '-x', globals.sstRxBinary]) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command) command = ['/usr/bin/ssh', '-T', '-p', '%d' % self.port, '%s' % self.host_name, '%s -v -T -L %s -l %s:%s' % (globals.gatewaySstRxBinary, globals.gatewaySstRxLogFile, globals.gatewaySstRxLogin, globals.gatewaySstRxPassword)] commandString = ' '.join(command) if not globals.quiet: utils.displayText('normal', 'executing command : %s' % commandString, 0) self.ssh = subprocess.Popen(command, bufsize=-1, shell = False, stdin = None, stdout = subprocess.PIPE, stderr = subprocess.PIPE, env={'LANG':'en_GB.utf-8'}) if self.ssh == None: utils.displayText('red', '[KO] the following command failed : %s' % ' '.join(command), 0) utils.terminateTest(1)
def setAllNetworkInterfacesState(self, requestedState): # check requestedState values if (requestedState != 'up') and (requestedState != 'down'): utils.displayText( 'red', '[KO] requestedState (%s) is neither \'up\', nor \'down\'' % requestedState, 0) utils.terminateTest(1) # do not modify controlNetworkInterface here... (when connected to the device through ssh, we do not want to disable this link) utils.displayText( 'cyan', 'setting up ethAdaptersInterfacesList in state %s' % requestedState, 0) for i in range(len(self.ethAdaptersInterfacesList)): interfaceName = self.ethAdaptersInterfacesList[i][0] self.setNetworkInterfaceState(interfaceName, requestedState) if (requestedState == 'up'): defaultGateway = self.ethAdaptersInterfacesList[i][5] self.setNetworkInterfaceDefaultGw(interfaceName, defaultGateway) utils.displayText( 'cyan', 'setting up usbEthAdaptersInterfacesList in state %s' % requestedState, 0) for i in range(len(self.usbEthAdaptersInterfacesList)): interfaceName = self.usbEthAdaptersInterfacesList[i][0] self.setNetworkInterfaceState(interfaceName, requestedState) if (requestedState == 'up'): defaultGateway = self.usbEthAdaptersInterfacesList[i][5] self.setNetworkInterfaceDefaultGw(interfaceName, defaultGateway) utils.displayText( 'cyan', 'setting up wifiAdaptersInterfacesList in state %s' % requestedState, 0) for i in range(len(self.wifiAdaptersInterfacesList)): interfaceName = self.wifiAdaptersInterfacesList[i][0] self.setNetworkInterfaceState(interfaceName, requestedState) if (requestedState == 'up'): defaultGateway = self.wifiAdaptersInterfacesList[i][5] self.setNetworkInterfaceDefaultGw(interfaceName, defaultGateway)
def displayRules(): utils.displayText('cyan', 'current rules are the following...', 0) commandsList = [] commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--line-numbers', '--list', '--numeric', '--verbose']) commandsList.append(['/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--line-numbers', '--list', '--numeric', '--verbose']) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command) utils.displayText('normal', 'commandStdout :', 0) utils.displayText('normal', commandStdout, 0)
def displayRules(): utils.displayText('cyan', 'current rules are the following...', 0) commandsList = [] commandsList.append([ '/usr/bin/sudo', '/sbin/iptables', '--line-numbers', '--list', '--numeric', '--verbose' ]) commandsList.append([ '/usr/bin/sudo', '/sbin/iptables', '--table', 'nat', '--line-numbers', '--list', '--numeric', '--verbose' ]) for command in commandsList: commandStdout, commandStderr = utils.executeCommand(command) utils.displayText('normal', 'commandStdout :', 0) utils.displayText('normal', commandStdout, 0)
def executeCommands(self, commandsList): # execute commands in the ssh connection for command in commandsList: commandStartTime = datetime.datetime.now() commandExecutionResult = self.session.execute(command) commandStdout = commandExecutionResult.as_str() utils.displayText('normal', 'commandStdout : %s' % commandStdout, 0) commandEndTime = datetime.datetime.now() commandExecutionDuration = (commandEndTime - commandStartTime).seconds * 1000 + (commandEndTime - commandStartTime).microseconds / 1000 returnCode = commandExecutionResult.return_code if returnCode == 0: utils.displayText('green', '[OK] command "%s" executed in %.3d milliseconds successfully' % (command, commandExecutionDuration), 0) else: utils.displayText('red', '[KO] command "%s" executed in %.3d milliseconds but returned an error (returnCode : %s)' % (command, commandExecutionDuration, returnCode), 0) sys.exit(1)