def CASE5(self, main): """ Run simple mininet to check connectivity of ONOS clusters. - It will do ping all - It will compare topos between mininet and ONOS. """ try: from tests.dependencies.topology import Topology except ImportError: main.log.error("Topology not found exiting the test") main.cleanAndExit() try: main.Topology except (NameError, AttributeError): main.Topology = Topology() main.case("Starting 2x2 Tree Mininet and compare the Topology") main.caseExplanation = "Starting 2x2 Mininet and assign ONOS controllers to switches." main.step("Starting Mininet") for ctrl in main.Cluster.runningNodes: main.mnTopo += " --controller remote,ip=" + ctrl.ipAddress startMnResult = main.Mininet1.startNet(mnCmd=main.mnTopo) utilities.assert_equals(expect=main.TRUE, actual=startMnResult, onpass="******", onfail="Failed to start Mininet") main.step("Pingall hosts to confirm ONOS discovery") pingResult = utilities.retry(f=main.Mininet1.pingall, retValue=main.FALSE, attempts=main.pingallRetry, sleep=main.pingallSleep) utilities.assert_equals(expect=main.TRUE, actual=pingResult, onpass="******", onfail="Failed to discover hosts") main.Topology.compareTopos(main.Mininet1, main.topoCheckRetry)
def CASE8(self, main): """ Compare Topo """ try: from tests.dependencies.topology import Topology except ImportError: main.log.error("Topology not found exiting the test") main.cleanAndExit() try: main.topoRelated except (NameError, AttributeError): main.topoRelated = Topology() main.topoRelated.compareTopos(main.Mininet1)
def compareTopo(main): """ Compare topology( devices, links, ports, hosts ) between ONOS and mininet using sts """ try: from tests.dependencies.topology import Topology except ImportError: main.log.error("Topology not found exiting the test") main.cleanAndExit() try: main.topoRelated except (NameError, AttributeError): main.topoRelated = Topology() return main.topoRelated.compareTopos(main.Mininet1)
def CASE3(self, main): """ Start Mininet """ import json import time try: from tests.dependencies.topology import Topology except ImportError: main.log.error("Topology not found exiting the test") main.cleanAndExit() try: main.topoRelated except (NameError, AttributeError): main.topoRelated = Topology() main.case( "Setup mininet and compare ONOS topology view to Mininet topology") main.caseExplanation = "Start mininet with custom topology and compare topology " +\ "elements between Mininet and ONOS" main.step("Setup Mininet Topology") topology = main.Mininet1.home + '/custom/' + main.topology stepResult = main.Mininet1.startNet(topoFile=topology) utilities.assert_equals(expect=main.TRUE, actual=stepResult, onpass="******", onfail="Failed to load topology") main.step("Assign switch to controller") stepResult = main.Mininet1.assignSwController( "s1", main.Cluster.active(0).ipAddress) utilities.assert_equals( expect=main.TRUE, actual=stepResult, onpass="******", onfail="Failed to assign switch to controller") time.sleep(main.startMNSleep) main.topoRelated.compareTopos(main.Mininet1)
def CASE23( self, main ): """ Compare ONOS Topology to Mininet Topology """ import json try: from tests.dependencies.topology import Topology except ImportError: main.log.error( "Topology not found exiting the test" ) main.cleanAndExit() try: main.topoRelated except ( NameError, AttributeError ): main.topoRelated = Topology() main.case( "Compare ONOS Topology view to Mininet topology" ) main.caseExplanation = "Compare topology elements between Mininet" +\ " and ONOS" main.log.info( "Gathering topology information from Mininet" ) devicesResults = main.FALSE # Overall Boolean for device correctness linksResults = main.FALSE # Overall Boolean for link correctness hostsResults = main.FALSE # Overall Boolean for host correctness deviceFails = [] # Nodes where devices are incorrect linkFails = [] # Nodes where links are incorrect hostFails = [] # Nodes where hosts are incorrect attempts = main.checkTopoAttempts # Remaining Attempts mnSwitches = main.switches mnLinks = main.links mnHosts = main.hosts main.step( "Comparing Mininet topology to ONOS topology" ) while ( attempts >= 0 ) and\ ( not devicesResults or not linksResults or not hostsResults ): time.sleep( 2 ) if not devicesResults: devices = main.topoRelated.getAll( "devices", False ) ports = main.topoRelated.getAll( "ports", False ) devicesResults = main.TRUE deviceFails = [] # Reset for each attempt if not linksResults: links = main.topoRelated.getAll( "links", False ) linksResults = main.TRUE linkFails = [] # Reset for each attempt if not hostsResults: hosts = main.topoRelated.getAll( "hosts", False ) hostsResults = main.TRUE hostFails = [] # Reset for each attempt # Check for matching topology on each node for controller in range( main.Cluster.numCtrls ): controllerStr = str( controller + 1 ) # ONOS node number # Compare Devices if devices[ controller ] and ports[ controller ] and\ "Error" not in devices[ controller ] and\ "Error" not in ports[ controller ]: try: deviceData = json.loads( devices[ controller ] ) portData = json.loads( ports[ controller ] ) except ( TypeError, ValueError ): main.log.error( "Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ) ) currentDevicesResult = main.FALSE else: if mnSwitches == len( deviceData ): currentDevicesResult = main.TRUE else: currentDevicesResult = main.FALSE main.log.error( "Node {} only sees {} device(s) but {} exist".format( controllerStr, len( deviceData ), mnSwitches ) ) else: currentDevicesResult = main.FALSE if not currentDevicesResult: deviceFails.append( controllerStr ) devicesResults = devicesResults and currentDevicesResult # Compare Links if links[ controller ] and "Error" not in links[ controller ]: try: linkData = json.loads( links[ controller ] ) except ( TypeError, ValueError ): main.log.error( "Could not load json:" + str( links[ controller ] ) ) currentLinksResult = main.FALSE else: if mnLinks == len( linkData ): currentLinksResult = main.TRUE else: currentLinksResult = main.FALSE main.log.error( "Node {} only sees {} link(s) but {} exist".format( controllerStr, len( linkData ), mnLinks ) ) else: currentLinksResult = main.FALSE if not currentLinksResult: linkFails.append( controllerStr ) linksResults = linksResults and currentLinksResult # Compare Hosts if hosts[ controller ] and "Error" not in hosts[ controller ]: try: hostData = json.loads( hosts[ controller ] ) except ( TypeError, ValueError ): main.log.error( "Could not load json:" + str( hosts[ controller ] ) ) currentHostsResult = main.FALSE else: if mnHosts == len( hostData ): currentHostsResult = main.TRUE else: currentHostsResult = main.FALSE main.log.error( "Node {} only sees {} host(s) but {} exist".format( controllerStr, len( hostData ), mnHosts ) ) else: currentHostsResult = main.FALSE if not currentHostsResult: hostFails.append( controllerStr ) hostsResults = hostsResults and currentHostsResult # Decrement Attempts Remaining attempts -= 1 utilities.assert_equals( expect=[], actual=deviceFails, onpass="******", onfail="ONOS incorrectly discovered devices on nodes: " + str( deviceFails ) ) utilities.assert_equals( expect=[], actual=linkFails, onpass="******", onfail="ONOS incorrectly discovered links on nodes: " + str( linkFails ) ) utilities.assert_equals( expect=[], actual=hostFails, onpass="******", onfail="ONOS incorrectly discovered hosts on nodes: " + str( hostFails ) ) if hostsResults and linksResults and devicesResults: topoResults = main.TRUE else: topoResults = main.FALSE utilities.assert_equals( expect=main.TRUE, actual=topoResults, onpass="******", onfail="ONOS incorrectly discovered the topology" )
def CASE11(self, main): """ Compare topo, and sending Arping package if the topology is same, then Pass. """ import json import time try: from tests.dependencies.topology import Topology except ImportError: main.log.error("Topology not found exiting the test") main.cleanAndExit() try: main.topoRelated except (NameError, AttributeError): main.topoRelated = Topology() # First capture main.postResult = True main.step("Grep information from the ONOS log") for i in range(3): # Calculate total time main.allinfo[0][ 'info' + str(i)]['totalTime'] = main.scaleTopoFunction.getInfoFromLog( main, main.searchTerm['start'], 'first', main.searchTerm['end'], 'last', index=i, funcMode='TD') # Calculate switch connection time main.allinfo[0]['info' + str( i)]['swConnection'] = main.scaleTopoFunction.getInfoFromLog( main, main.searchTerm['start'], 'first', main.searchTerm['start'], 'last', index=i, funcMode='TD') # Calculate the time from last switch connection to the last role request main.allinfo[0]['info' + str( i )]['lastSwToLastRr'] = main.scaleTopoFunction.compareTimeDiffWithRoleRequest( main, main.searchTerm['start'], 'last', index=i) # Calculate the time from the last role request to the last topology main.allinfo[0]['info' + str( i )]['lastRrToLastTopology'] = main.scaleTopoFunction.compareTimeDiffWithRoleRequest( main, main.searchTerm['end'], 'last', index=i) # Calculate the disconnecti rate main.allinfo[0]['info' + str( i)]['disconnectRate'] = main.scaleTopoFunction.getInfoFromLog( main, main.searchTerm['Disconnect'], 'num', main.searchTerm['start'], 'num', index=i, funcMode='DR') main.log.debug("The data is " + str(main.allinfo[0])) if -1 in main.allinfo[0]['info0'].values() or -1 in main.allinfo[0][ 'info1'].values() or -1 in main.allinfo[0]['info2'].values(): utilities.assert_equals( expect=main.TRUE, actual=main.FALSE, onpass="******", onfail="Something happened to ONOS. Skip the rest of the steps." ) main.postResult = False else: main.case("Verifying topology: TORUS %sx%s" % (main.currScale, main.currScale)) main.caseExplanation = "Pinging all hosts and comparing topology " +\ "elements between Mininet and ONOS" main.log.info("Gathering topology information") time.sleep(main.MNSleep) compareRetry = 0 main.step("Checking if ONOS is stable") main.scaleTopoFunction.checkingONOSStablility(main) if main.postResult: main.step("Comparing MN topology to ONOS topology") compareRetry = 0 while compareRetry < 2: stepResult = main.TRUE currentDevicesResult = main.TRUE currentLinksResult = main.TRUE # While loop for retry devices = main.topoRelated.getAll("devices") ports = main.topoRelated.getAll("ports") links = main.topoRelated.getAll("links") if None in devices or None in ports or None in links: main.log.warn("Something went wrong. Retrying...") time.sleep(20) stepResult = main.FALSE compareRetry += 1 continue mnSwitches = main.Mininet1.getSwitches( updateTimeout=main.basicMNTime + int(main.currScale) * main.MNupdateTime) main.log.info("Comparing switches...") devicePool = [] for controller in range(len(main.Cluster.active())): t = main.Thread( target=main.topoRelated.compareDevicePort, threadID=main.threadID, name="Compare-Device-Port", args=[ main.Mininet1, controller, mnSwitches, devices, ports ]) devicePool.append(t) t.start() main.threadID = main.threadID + 1 mnLinks = main.Mininet1.getLinks( timeout=main.basicMNTime + int(main.currScale) * main.MNLinksTime, updateTimeout=main.basicMNTime + int(main.currScale) * main.MNupdateTime) main.log.info("Comparing links...") linkPool = [] for controller in range(len(main.Cluster.active())): t = main.Thread(target=main.topoRelated.compareBase, threadID=main.threadID, name="Compare-Link-Result", args=[ links, controller, main.Mininet1.compareLinks, [mnSwitches, mnLinks] ]) linkPool.append(t) t.start() main.threadID = main.threadID + 1 for t in devicePool: t.join() currentDevicesResult = currentDevicesResult and t.result for t in linkPool: t.join() currentLinksResult = currentLinksResult and t.result stepResult = stepResult and currentDevicesResult and currentLinksResult if stepResult: break compareRetry += 1 utilities.assert_equals( expect=main.TRUE, actual=stepResult, onpass="******", onfail="ONOS Topology doesn't match Mininet") main.scaleTopoFunction.checkingONOSStablility(main) if stepResult and main.postResult: if main.hostDiscover: hostList = [] for i in range(1, int(main.currScale) + 1): for j in range(1, int(main.currScale) + 1): # Generate host list hoststr = "h" + str(i) + "x" + str(j) hostList.append(hoststr) for i in range(len(hostList)): main.topo.sendArpPackage(main, hostList[i]) time.sleep(20) totalHost = main.topo.getHostNum(main) if totalHost == int(main.currScale) * int( main.currScale): main.log.info("Discovered all hosts") stepResult = stepResult and main.TRUE else: main.log.warn( "Some hosts ware not discovered by ONOS... Topology doesn't match!" ) stepResult = main.FALSE utilities.assert_equals( expect=main.TRUE, actual=stepResult, onpass="******", onfail="ONOS Topology doesn't match Mininet") main.log.info( "Finished this iteration, continue to scale next topology." ) else: utilities.assert_equals( expect=main.TRUE, actual=main.FALSE, onpass="******", onfail= "Something happened to ONOS. Skip the rest of the steps." ) main.postResult = False
def CASE3(self, main): """ Start Mininet """ import json import time try: from tests.dependencies.topology import Topology except ImportError: main.log.error("Topology not found exiting the test") main.cleanAndExit() try: main.topoRelated except (NameError, AttributeError): main.topoRelated = Topology() main.case( "Setup mininet and compare ONOS topology view to Mininet topology") main.caseExplanation = "Start mininet with custom topology and compare topology " +\ "elements between Mininet and ONOS" main.step("Copy Mininet topology file") copyResult = main.ONOSbench.scp(main.Mininet1, main.dependencyPath + main.topology, main.Mininet1.home + '/custom/', direction="to") utilities.assert_equals(expect=main.TRUE, actual=copyResult, onpass="******", onfail="Failed to copy mininet topo file") main.step("Setup Mininet Topology") topology = main.Mininet1.home + '/custom/' + main.topology stepResult = main.Mininet1.startNet(topoFile=topology) utilities.assert_equals(expect=main.TRUE, actual=stepResult, onpass="******", onfail="Failed to load topology") main.step("Assign switch to controller") stepResult = main.Mininet1.assignSwController( "s1", main.Cluster.active(0).ipAddress) utilities.assert_equals( expect=main.TRUE, actual=stepResult, onpass="******", onfail="Failed to assign switch to controller") time.sleep(main.startMNSleep) main.topoRelated.compareTopos(main.Mininet1) main.step("Create hosts and start scapy") scapyResult = main.TRUE for hostName in main.scapyHostNames: main.Scapy.createHostComponent(hostName) main.scapyHosts.append(getattr(main, hostName)) main.step("Start scapy components") for host in main.scapyHosts: host.startHostCli() host.startScapy() host.updateSelf() main.log.debug(host.name) main.log.debug(host.hostIp) main.log.debug(host.hostMac) utilities.assert_equals(expect=main.TRUE, actual=scapyResult, onpass="******", onfail="Failed to discover Scapy Components")