[ONOS-7356] Decouple Scapy from TestON tests
- Create MininetScapyCliDriver for mininet based scapy tests
- Move scapy related setup to a single test case in FUNCflow and
FUNCgroup
Change-Id: I02e628b1fda6e6f6f7cafde420749ddda88e898f
diff --git a/TestON/drivers/common/cli/emulator/mininetscapyclidriver.py b/TestON/drivers/common/cli/emulator/mininetscapyclidriver.py
new file mode 100644
index 0000000..4874c02
--- /dev/null
+++ b/TestON/drivers/common/cli/emulator/mininetscapyclidriver.py
@@ -0,0 +1,257 @@
+#!/usr/bin/env python
+"""
+2015-2016
+Copyright 2016 Open Networking Foundation (ONF)
+
+Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
+the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
+or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
+
+TestON is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+( at your option ) any later version.
+
+TestON is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with TestON. If not, see <http://www.gnu.org/licenses/>.
+
+MininetScapyCliDriver is for controlling scapy hosts running in Mininet
+
+TODO: Add Explanation on how to install scapy
+"""
+import pexpect
+import re
+import sys
+import types
+import os
+from drivers.common.cli.emulator.scapyclidriver import ScapyCliDriver
+
+
+class MininetScapyCliDriver( ScapyCliDriver ):
+ """
+ MininetScapyCliDriver is for controlling scapy hosts running in Mininet
+ """
+ def __init__( self ):
+ super( MininetScapyCliDriver, self ).__init__()
+ self.handle = self
+ self.name = None
+ self.home = None
+ self.wrapped = sys.modules[ __name__ ]
+ self.flag = 0
+ self.hostPrompt = "~#"
+ self.scapyPrompt = ">>>"
+
+ def connect( self, **connectargs ):
+ """
+ Here the main is the TestON instance after creating
+ all the log handles.
+ """
+ try:
+ for key in connectargs:
+ vars( self )[ key ] = connectargs[ key ]
+ self.home = self.options[ 'home' ] if 'home' in self.options.keys() else "~/mininet"
+ self.name = self.options[ 'name' ]
+ self.ifaceName = self.options[ 'ifaceName' ] if 'ifaceName' in self.options.keys() else self.name + "-eth0"
+
+ try:
+ if os.getenv( str( self.ip_address ) ) is not None:
+ self.ip_address = os.getenv( str( self.ip_address ) )
+ else:
+ main.log.info( self.name +
+ ": Trying to connect to " +
+ self.ip_address )
+
+ except KeyError:
+ main.log.info( "Invalid host name," +
+ " connecting to local host instead" )
+ self.ip_address = 'localhost'
+ except Exception as inst:
+ main.log.error( "Uncaught exception: " + str( inst ) )
+
+ self.handle = super(
+ ScapyCliDriver,
+ self ).connect(
+ user_name=self.user_name,
+ ip_address=self.ip_address,
+ port=None,
+ pwd=self.pwd )
+
+ if self.handle:
+ main.log.info( "Connection successful to the host " +
+ self.user_name +
+ "@" +
+ self.ip_address )
+ return main.TRUE
+ else:
+ main.log.error( "Connection failed to the host " +
+ self.user_name +
+ "@" +
+ self.ip_address )
+ main.log.error( "Failed to connect to the Mininet Host" )
+ return main.FALSE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanAndExit()
+ except Exception:
+ main.log.exception( self.name + ": Uncaught exception!" )
+ main.cleanAndExit()
+
+ def disconnect( self ):
+ """
+ Called at the end of the test to stop the scapy component and
+ disconnect the handle.
+ """
+ self.handle.sendline( '' )
+ i = self.handle.expect( [ 'mininet>', pexpect.EOF, pexpect.TIMEOUT ],
+ timeout=2 )
+ response = main.TRUE
+ if i == 0:
+ response = self.stopNet()
+ elif i == 1:
+ return main.TRUE
+ # print "Disconnecting Mininet"
+ if self.handle:
+ self.handle.sendline( "exit" )
+ self.handle.expect( "exit" )
+ self.handle.expect( "(.*)" )
+ else:
+ main.log.error( "Connection failed to the host" )
+ return response
+
+ def stopNet( self, fileName="", timeout=5 ):
+ """
+ Stops mininet.
+ Returns main.TRUE if the mininet successfully stops and
+ main.FALSE if the pexpect handle does not exist.
+
+ Will cleanup and exit the test if scapy fails to stop
+ """
+ main.log.info( self.name + ": Stopping scapy..." )
+ response = ''
+ if self.handle:
+ try:
+ self.handle.sendline( "" )
+ i = self.handle.expect( [ '>>>',
+ self.prompt,
+ pexpect.EOF,
+ pexpect.TIMEOUT ],
+ timeout )
+ if i == 0:
+ main.log.info( "Exiting scapy..." )
+ response = self.execute(
+ cmd="exit",
+ prompt="(.*)",
+ timeout=120 )
+ main.log.info( self.name + ": Stopped" )
+ response = main.TRUE
+
+ if i == 1:
+ main.log.info( " Mininet trying to exit while not " +
+ "in the mininet prompt" )
+ elif i == 2:
+ main.log.error( "Something went wrong exiting mininet" )
+ elif i == 3: # timeout
+ main.log.error( "Something went wrong exiting mininet " +
+ "TIMEOUT" )
+
+ if fileName:
+ self.handle.sendline( "" )
+ self.handle.expect( self.prompt )
+ self.handle.sendline(
+ "sudo kill -9 \`ps -ef | grep \"" +
+ fileName +
+ "\" | grep -v grep | awk '{print $2}'\`" )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanAndExit()
+ else:
+ main.log.error( self.name + ": Connection failed to the host" )
+ response = main.FALSE
+ return response
+
+ def createHostComponent( self, name ):
+ """
+ Creates a new mininet cli component with the same parameters as self.
+ This new component is intended to be used to login to the hosts created
+ by mininet.
+
+ Arguments:
+ name - The string of the name of this component. The new component
+ will be assigned to main.<name> .
+ In addition, main.<name>.name = str( name )
+ """
+ try:
+ # look to see if this component already exists
+ getattr( main, name )
+ except AttributeError:
+ # namespace is clear, creating component
+ main.componentDictionary[ name ] = main.componentDictionary[ self.name ].copy()
+ main.componentDictionary[ name ][ 'connect_order' ] = str( int( main.componentDictionary[ name ][ 'connect_order' ] ) + 1 )
+ main.componentInit( name )
+ except Exception:
+ main.log.exception( self.name + ": Uncaught exception!" )
+ main.cleanAndExit()
+ else:
+ # namespace is not clear!
+ main.log.error( name + " component already exists!" )
+ main.cleanAndExit()
+
+ def removeHostComponent( self, name ):
+ """
+ Remove host component
+ Arguments:
+ name - The string of the name of the component to delete.
+ """
+ try:
+ # Get host component
+ component = getattr( main, name )
+ except AttributeError:
+ main.log.error( "Component " + name + " does not exist." )
+ return main.FALSE
+ try:
+ # Disconnect from component
+ component.disconnect()
+ # Delete component
+ delattr( main, name )
+ # Delete component from ComponentDictionary
+ del( main.componentDictionary[ name ] )
+ return main.TRUE
+ except Exception:
+ main.log.exception( self.name + ": Uncaught exception!" )
+ main.cleanAndExit()
+
+ def startHostCli( self, host=None ):
+ """
+ Use the mininet m utility to connect to the host's cli
+ """
+ # These are fields that can be used by scapy packets. Initialized to None
+ self.hostIp = None
+ self.hostMac = None
+ try:
+ if not host:
+ host = self.name
+ self.handle.sendline( self.home + "/util/m " + host )
+ self.handle.sendline( "cd" )
+ self.handle.expect( self.hostPrompt )
+ self.handle.sendline( "" )
+ self.handle.expect( self.hostPrompt )
+ return main.TRUE
+ except pexpect.TIMEOUT:
+ main.log.exception( self.name + ": Command timed out" )
+ return main.FALSE
+ except pexpect.EOF:
+ main.log.exception( self.name + ": connection closed." )
+ main.cleanAndExit()
+ except Exception:
+ main.log.exception( self.name + ": Uncaught exception!" )
+ main.cleanAndExit()
+
+if __name__ != "__main__":
+ sys.modules[ __name__ ] = MininetScapyCliDriver()
diff --git a/TestON/drivers/common/cli/emulator/scapyclidriver.py b/TestON/drivers/common/cli/emulator/scapyclidriver.py
index 6ef63c4..418aa9e 100644
--- a/TestON/drivers/common/cli/emulator/scapyclidriver.py
+++ b/TestON/drivers/common/cli/emulator/scapyclidriver.py
@@ -45,8 +45,7 @@
self.wrapped = sys.modules[ __name__ ]
self.flag = 0
# TODO: Refactor driver to use these everywhere
- self.hostPrompt = "~#"
- self.bashPrompt = "\$"
+ self.hostPrompt = "\$"
self.scapyPrompt = ">>>"
def connect( self, **connectargs ):
@@ -56,15 +55,9 @@
try:
for key in connectargs:
vars( self )[ key ] = connectargs[ key ]
- self.home = "~/mininet"
+ self.home = self.options[ 'home' ] if 'home' in self.options.keys() else "~/"
self.name = self.options[ 'name' ]
- for key in self.options:
- if key == "home":
- self.home = self.options[ 'home' ]
- break
- if self.home is None or self.home == "":
- self.home = "~/mininet"
-
+ self.ifaceName = self.options[ 'ifaceName' ] if 'ifaceName' in self.options.keys() else self.name + "-eth0"
try:
if os.getenv( str( self.ip_address ) ) is not None:
self.ip_address = os.getenv( str( self.ip_address ) )
@@ -114,152 +107,19 @@
Called at the end of the test to stop the scapy component and
disconnect the handle.
"""
- self.handle.sendline( '' )
- i = self.handle.expect( [ 'mininet>', pexpect.EOF, pexpect.TIMEOUT ],
- timeout=2 )
response = main.TRUE
- if i == 0:
- response = self.stopNet()
- elif i == 1:
- return main.TRUE
- # print "Disconnecting Mininet"
- if self.handle:
- self.handle.sendline( "exit" )
- self.handle.expect( "exit" )
- self.handle.expect( "(.*)" )
- else:
- main.log.error( "Connection failed to the host" )
- return response
-
- def stopNet( self, fileName="", timeout=5 ):
- """
- Stops mininet.
- Returns main.TRUE if the mininet successfully stops and
- main.FALSE if the pexpect handle does not exist.
-
- Will cleanup and exit the test if scapy fails to stop
- """
- main.log.info( self.name + ": Stopping scapy..." )
- response = ''
- if self.handle:
- try:
- self.handle.sendline( "" )
- i = self.handle.expect( [ '>>>',
- self.prompt,
- pexpect.EOF,
- pexpect.TIMEOUT ],
- timeout )
- if i == 0:
- main.log.info( "Exiting scapy..." )
- response = self.execute(
- cmd="exit",
- prompt="(.*)",
- timeout=120 )
- main.log.info( self.name + ": Stopped" )
- response = main.TRUE
-
- if i == 1:
- main.log.info( " Mininet trying to exit while not " +
- "in the mininet prompt" )
- elif i == 2:
- main.log.error( "Something went wrong exiting mininet" )
- elif i == 3: # timeout
- main.log.error( "Something went wrong exiting mininet " +
- "TIMEOUT" )
-
- if fileName:
- self.handle.sendline( "" )
- self.handle.expect( self.prompt )
- self.handle.sendline(
- "sudo kill -9 \`ps -ef | grep \"" +
- fileName +
- "\" | grep -v grep | awk '{print $2}'\`" )
- except pexpect.EOF:
- main.log.error( self.name + ": EOF exception found" )
- main.log.error( self.name + ": " + self.handle.before )
- main.cleanAndExit()
- else:
- main.log.error( self.name + ": Connection failed to the host" )
+ try:
+ if self.handle:
+ self.handle.sendline( "exit" )
+ self.handle.expect( "closed" )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ except Exception:
+ main.log.exception( self.name + ": Connection failed to the host" )
response = main.FALSE
return response
- def createHostComponent( self, name ):
- """
- Creates a new mininet cli component with the same parameters as self.
- This new component is intended to be used to login to the hosts created
- by mininet.
-
- Arguments:
- name - The string of the name of this component. The new component
- will be assigned to main.<name> .
- In addition, main.<name>.name = str( name )
- """
- try:
- # look to see if this component already exists
- getattr( main, name )
- except AttributeError:
- # namespace is clear, creating component
- main.componentDictionary[ name ] = main.componentDictionary[ self.name ].copy()
- main.componentDictionary[ name ][ 'connect_order' ] = str( int( main.componentDictionary[ name ][ 'connect_order' ] ) + 1 )
- main.componentInit( name )
- except Exception:
- main.log.exception( self.name + ": Uncaught exception!" )
- main.cleanAndExit()
- else:
- # namespace is not clear!
- main.log.error( name + " component already exists!" )
- main.cleanAndExit()
-
- def removeHostComponent( self, name ):
- """
- Remove host component
- Arguments:
- name - The string of the name of the component to delete.
- """
- try:
- # Get host component
- component = getattr( main, name )
- except AttributeError:
- main.log.error( "Component " + name + " does not exist." )
- return main.FALSE
- try:
- # Disconnect from component
- component.disconnect()
- # Delete component
- delattr( main, name )
- # Delete component from ComponentDictionary
- del( main.componentDictionary[ name ] )
- return main.TRUE
- except Exception:
- main.log.exception( self.name + ": Uncaught exception!" )
- main.cleanAndExit()
-
- def startHostCli( self, host=None ):
- """
- Use the mininet m utility to connect to the host's cli
- """
- # These are fields that can be used by scapy packets. Initialized to None
- self.hostIp = None
- self.hostMac = None
- try:
- if not host:
- host = self.name
- self.handle.sendline( self.home + "/util/m " + host )
- self.handle.sendline( "cd" )
- self.handle.expect( self.hostPrompt )
- self.handle.sendline( "" )
- self.handle.expect( self.hostPrompt )
- return main.TRUE
- except pexpect.TIMEOUT:
- main.log.exception( self.name + ": Command timed out" )
- return main.FALSE
- except pexpect.EOF:
- main.log.exception( self.name + ": connection closed." )
- main.cleanAndExit()
- except Exception:
- main.log.exception( self.name + ": Uncaught exception!" )
- main.cleanAndExit()
-
def startScapy( self, mplsPath="" ):
"""
Start the Scapy cli
@@ -847,7 +707,7 @@
Options:
ifaceName - the name of the interface to listen on. If none is given,
- defaults to <host name>-eth0
+ defaults to self.ifaceName which is <host name>-eth0
pktFilter - A string in Berkeley Packet Filter (BPF) format which
specifies which packets to sniff
sniffCount - The number of matching packets to capture before returning
@@ -856,7 +716,7 @@
"""
try:
# TODO: add all params, or use kwargs
- ifaceName = str( ifaceName ) if ifaceName else self.name + "-eth0"
+ ifaceName = str( ifaceName ) if ifaceName else self.ifaceName
# Set interface
self.handle.sendline( ' conf.iface = "' + ifaceName + '"' )
self.handle.expect( self.scapyPrompt )
@@ -946,7 +806,7 @@
Save host's MAC address
"""
try:
- ifaceName = str( ifaceName ) if ifaceName else self.name + "-eth0"
+ ifaceName = str( ifaceName ) if ifaceName else self.ifaceName
cmd = 'get_if_hwaddr("' + str( ifaceName ) + '")'
self.handle.sendline( cmd )
self.handle.expect( self.scapyPrompt )
diff --git a/TestON/tests/FUNC/FUNCbgpls/FUNCbgpls.topo b/TestON/tests/FUNC/FUNCbgpls/FUNCbgpls.topo
index c8b48a0..1dd294d 100755
--- a/TestON/tests/FUNC/FUNCbgpls/FUNCbgpls.topo
+++ b/TestON/tests/FUNC/FUNCbgpls/FUNCbgpls.topo
@@ -25,7 +25,7 @@
<host>OCN</host>
<user>sdn</user>
<password>rocks</password>
- <type>ScapyCliDriver</type>
+ <type>MininetScapyCliDriver</type>
<connect_order>2</connect_order>
<COMPONENTS>
<prompt></prompt>
diff --git a/TestON/tests/FUNC/FUNCflow/FUNCflow.params b/TestON/tests/FUNC/FUNCflow/FUNCflow.params
index 6eda334..f40372c 100755
--- a/TestON/tests/FUNC/FUNCflow/FUNCflow.params
+++ b/TestON/tests/FUNC/FUNCflow/FUNCflow.params
@@ -6,6 +6,8 @@
# 1 - Variable initialization and optional pull and build ONOS package
# 2 - install ONOS
# 10 - Start mininet and verify topology
+ # 11 - Start mininet scapy hosts
+ # 12 - Stop mininet and scapy hosts
# 66 - Testing Scapy
# 100 - Check logs for Errors and Warnings
# 1000 - Add flows with MAC selector
@@ -21,7 +23,7 @@
# 2000 - Add flows with ICMPv6 selector
# 3000 - Delete flows
- <testcases>1,2,10,1000,3000,1100,3000,1200,3000,1300,3000,1400,3000,1500,3000,1600,3000,1700,3000,1800,3000,1900,3000,2000,100</testcases>
+ <testcases>1,2,10,11,1000,3000,1100,3000,1200,3000,1300,3000,1400,3000,1500,3000,1600,3000,1700,3000,1800,3000,1900,3000,2000,12,100</testcases>
<GRAPH>
<nodeCluster>VM</nodeCluster>
@@ -82,4 +84,8 @@
<delFlow>10</delFlow>
</SLEEP>
+ <SCAPY>
+ <HOSTNAMES>h1,h2,h3,h4,h5,h6</HOSTNAMES>
+ </SCAPY>
+
</PARAMS>
diff --git a/TestON/tests/FUNC/FUNCflow/FUNCflow.py b/TestON/tests/FUNC/FUNCflow/FUNCflow.py
index 7f2f01c..f161202 100644
--- a/TestON/tests/FUNC/FUNCflow/FUNCflow.py
+++ b/TestON/tests/FUNC/FUNCflow/FUNCflow.py
@@ -59,6 +59,8 @@
main.delFlowSleep = int( main.params[ 'SLEEP' ][ 'delFlow' ] )
main.debug = main.params[ 'DEBUG' ]
main.swDPID = main.params[ 'TEST' ][ 'swDPID' ]
+ main.scapyHostNames = main.params[ 'SCAPY' ][ 'HOSTNAMES' ].split( ',' )
+ main.scapyHosts = [] # List of scapy hosts for iterating
main.debug = True if "on" in main.debug else False
@@ -145,17 +147,77 @@
main.topoRelated.compareTopos( main.Mininet1 )
+ def CASE11( self, main ):
+ """
+ Start Scapy with Mininet
+ """
+ main.case( "Starting scapy with Mininet" )
+ main.step( "Creating Host component" )
+ 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="Successfully created Scapy Components",
+ onfail="Failed to discover Scapy Components" )
+
+ def CASE12( self, main ):
+ """
+ Stop mininet and remove scapy host
+ """
+ try:
+ from tests.dependencies.utils import Utils
+ except ImportError:
+ main.log.error( "Utils not found exiting the test" )
+ main.cleanAndExit()
+ try:
+ main.Utils
+ except ( NameError, AttributeError ):
+ main.Utils = Utils()
+ main.log.report( "Stop Mininet and Scapy" )
+ main.case( "Stop Mininet and Scapy" )
+ main.caseExplanation = "Stopping the current mininet topology " +\
+ "to start up fresh"
+ main.step( "Stopping and Removing Scapy Host Components" )
+ scapyResult = main.TRUE
+ for host in main.scapyHosts:
+ scapyResult = scapyResult and host.stopScapy()
+ main.log.info( "Stopped Scapy Host: {0}".format( host.name ) )
+
+ for host in main.scapyHosts:
+ scapyResult = scapyResult and main.Scapy.removeHostComponent( host.name )
+ main.log.info( "Removed Scapy Host Component: {0}".format( host.name ) )
+
+ main.scapyHosts = []
+
+ utilities.assert_equals( expect=main.TRUE,
+ actual=scapyResult,
+ onpass="Successfully stopped scapy and removed host components",
+ onfail="Failed to stop mininet and scapy" )
+
+ mininetResult = main.Utils.mininetCleanup( main.Mininet1 )
+ # Exit if topology did not load properly
+ if not ( mininetResult and scapyResult ):
+ main.cleanAndExit()
+
def CASE66( self, main ):
"""
Testing scapy
"""
main.case( "Testing scapy" )
- main.step( "Creating Host1 component" )
- main.Scapy.createHostComponent( "h1" )
- main.Scapy.createHostComponent( "h2" )
- hosts = [ main.h1, main.h2 ]
- for host in hosts:
- host.startHostCli()
+ for host in main.scapyHosts:
+ host.stopScapy()
host.startScapy()
host.updateSelf()
main.log.debug( host.name )
@@ -210,12 +272,6 @@
onpass="Pass",
onfail="Fail" )
- main.step( "Clean up host components" )
- for host in hosts:
- host.stopScapy()
- main.Mininet1.removeHostComponent( "h1" )
- main.Mininet1.removeHostComponent( "h2" )
-
def CASE1000( self, main ):
"""
Add flows with MAC selectors and verify the flows
@@ -229,15 +285,13 @@
"send a packet that only specifies the MAC src and dst."
main.step( "Add flows with MAC addresses as the only selectors" )
-
- main.log.info( "Creating host components" )
- main.Scapy.createHostComponent( "h1" )
- main.Scapy.createHostComponent( "h2" )
- hosts = [ main.h1, main.h2 ]
- for host in hosts:
- host.startHostCli()
+ for host in main.scapyHosts:
+ host.stopScapy()
host.startScapy()
host.updateSelf()
+ main.log.debug( host.name )
+ main.log.debug( host.hostIp )
+ main.log.debug( host.hostMac )
# Add a flow that connects host1 on port1 to host2 on port2
# send output on port2
@@ -288,12 +342,6 @@
else:
main.h2.killFilter()
- main.log.info( "Clean up host components" )
- for host in hosts:
- host.stopScapy()
- main.Mininet1.removeHostComponent( "h1" )
- main.Mininet1.removeHostComponent( "h2" )
-
utilities.assert_equals( expect=main.TRUE,
actual=stepResult,
onpass="Successfully sent a packet",
@@ -312,15 +360,13 @@
"send a packet that only specifies the IP src and dst."
main.step( "Add flows with IPv4 addresses as the only selectors" )
-
- main.log.info( "Creating host components" )
- main.Scapy.createHostComponent( "h1" )
- main.Scapy.createHostComponent( "h2" )
- hosts = [ main.h1, main.h2 ]
- for host in hosts:
- host.startHostCli()
+ for host in main.scapyHosts:
+ host.stopScapy()
host.startScapy()
host.updateSelf()
+ main.log.debug( host.name )
+ main.log.debug( host.hostIp )
+ main.log.debug( host.hostMac )
# Add a flow that connects host1 on port1 to host2 on port2
# send output on port2
@@ -371,12 +417,6 @@
else:
main.h2.killFilter()
- main.log.info( "Clean up host components" )
- for host in hosts:
- host.stopScapy()
- main.Mininet1.removeHostComponent( "h1" )
- main.Mininet1.removeHostComponent( "h2" )
-
utilities.assert_equals( expect=main.TRUE,
actual=stepResult,
onpass="Successfully sent a packet",
@@ -394,17 +434,13 @@
"send a packet that only specifies the IP src and dst."
main.step( "Add flows with IPv6 addresses as the only selectors" )
-
- main.log.info( "Creating host components" )
- ctrl = main.Cluster.active( 0 )
- main.Scapy.createHostComponent( "h5" )
- main.Scapy.createHostComponent( "h6" )
- hosts = [ main.h5, main.h6 ]
-
- for host in hosts:
- host.startHostCli()
+ for host in main.scapyHosts:
+ host.stopScapy()
host.startScapy()
host.updateSelf( IPv6=True )
+ main.log.debug( host.name )
+ main.log.debug( host.hostIp )
+ main.log.debug( host.hostMac )
# Add a flow that connects host1 on port1 to host2 on port2
# send output on port2
@@ -454,12 +490,6 @@
else:
main.h6.killFilter()
- main.log.info( "Clean up host components" )
- for host in hosts:
- host.stopScapy()
- main.Mininet1.removeHostComponent( "h5" )
- main.Mininet1.removeHostComponent( "h6" )
-
utilities.assert_equals( expect=main.TRUE,
actual=stepResult,
onpass="Successfully sent a packet",
@@ -477,16 +507,13 @@
"specified, then verify the flow is added in ONOS, and finally " +\
"broadcast a packet with the correct VLAN tag."
- # We do this here to utilize the hosts information
- main.log.info( "Creating host components" )
- ctrl = main.Cluster.active( 0 )
- main.Scapy.createHostComponent( "h3" )
- main.Scapy.createHostComponent( "h4" )
- hosts = [ main.h3, main.h4 ]
- for host in hosts:
- host.startHostCli()
+ for host in main.scapyHosts:
+ host.stopScapy()
host.startScapy()
host.updateSelf()
+ main.log.debug( host.name )
+ main.log.debug( host.hostIp )
+ main.log.debug( host.hostMac )
main.step( "Add a flow with the VLAN tag as the only selector" )
@@ -539,12 +566,6 @@
else:
main.h4.killFilter()
- main.log.info( "Clean up host components" )
- for host in hosts:
- host.stopScapy()
- main.Mininet1.removeHostComponent( "h3" )
- main.Mininet1.removeHostComponent( "h4" )
-
utilities.assert_equals( expect=main.TRUE,
actual=stepResult,
onpass="Successfully sent a packet",
@@ -563,16 +584,15 @@
"send a packet via scapy that has a MPLS label."
main.step( "Add a flow with a MPLS selector" )
-
- main.log.info( "Creating host components" )
- ctrl = main.Cluster.active( 0 )
- main.Scapy.createHostComponent( "h1" )
- main.Scapy.createHostComponent( "h2" )
- hosts = [ main.h1, main.h2 ]
- for host in hosts:
- host.startHostCli()
+ for host in main.scapyHosts:
+ host.stopScapy()
host.startScapy( main.dependencyPath )
host.updateSelf()
+ main.log.debug( host.name )
+ main.log.debug( host.hostIp )
+ main.log.debug( host.hostMac )
+
+ ctrl = main.Cluster.active( 0 )
# ports
egress = 2
@@ -655,12 +675,6 @@
else:
main.h2.killFilter()
- main.log.info( "Clean up host components" )
- for host in hosts:
- host.stopScapy()
- main.Mininet1.removeHostComponent( "h1" )
- main.Mininet1.removeHostComponent( "h2" )
-
utilities.assert_equals( expect=main.TRUE,
actual=stepResult,
onpass="Successfully sent a packet",
@@ -680,14 +694,13 @@
main.step( "Add a flow with a TCP selector" )
ctrl = main.Cluster.active( 0 )
- main.log.info( "Creating host components" )
- main.Scapy.createHostComponent( "h1" )
- main.Scapy.createHostComponent( "h2" )
- hosts = [ main.h1, main.h2 ]
- for host in hosts:
- host.startHostCli()
+ for host in main.scapyHosts:
+ host.stopScapy()
host.startScapy()
host.updateSelf()
+ main.log.debug( host.name )
+ main.log.debug( host.hostIp )
+ main.log.debug( host.hostMac )
# Add a flow that connects host1 on port1 to host2 on port2
egress = 2
@@ -740,12 +753,6 @@
else:
main.h2.killFilter()
- main.log.info( "Clean up host components" )
- for host in hosts:
- host.stopScapy()
- main.Mininet1.removeHostComponent( "h1" )
- main.Mininet1.removeHostComponent( "h2" )
-
utilities.assert_equals( expect=main.TRUE,
actual=stepResult,
onpass="Successfully sent a packet",
@@ -765,14 +772,13 @@
main.step( "Add a flow with a UDP selector" )
ctrl = main.Cluster.active( 0 )
- main.log.info( "Creating host components" )
- main.Scapy.createHostComponent( "h1" )
- main.Scapy.createHostComponent( "h2" )
- hosts = [ main.h1, main.h2 ]
- for host in hosts:
- host.startHostCli()
+ for host in main.scapyHosts:
+ host.stopScapy()
host.startScapy()
host.updateSelf()
+ main.log.debug( host.name )
+ main.log.debug( host.hostIp )
+ main.log.debug( host.hostMac )
# Add a flow that connects host1 on port1 to host2 on port2
egress = 2
@@ -825,12 +831,6 @@
else:
main.h2.killFilter()
- main.log.info( "Clean up host components" )
- for host in hosts:
- host.stopScapy()
- main.Mininet1.removeHostComponent( "h1" )
- main.Mininet1.removeHostComponent( "h2" )
-
utilities.assert_equals( expect=main.TRUE,
actual=stepResult,
onpass="Successfully sent a packet",
@@ -850,14 +850,13 @@
main.step( "Add a flow with a ICMPv4 selector" )
- main.log.info( "Creating host components" )
- main.Scapy.createHostComponent( "h1" )
- main.Scapy.createHostComponent( "h2" )
- hosts = [ main.h1, main.h2 ]
- for host in hosts:
- host.startHostCli()
+ for host in main.scapyHosts:
+ host.stopScapy()
host.startScapy()
host.updateSelf()
+ main.log.debug( host.name )
+ main.log.debug( host.hostIp )
+ main.log.debug( host.hostMac )
# Add a flow that connects host1 on port1 to host2 on port2
egress = 2
@@ -907,12 +906,6 @@
else:
main.h2.killFilter()
- main.log.info( "Clean up host components" )
- for host in hosts:
- host.stopScapy()
- main.Mininet1.removeHostComponent( "h1" )
- main.Mininet1.removeHostComponent( "h2" )
-
utilities.assert_equals( expect=main.TRUE,
actual=stepResult,
onpass="Successfully sent a packet",
@@ -932,14 +925,13 @@
main.step( "Add a flow with a ICMPv6 selector" )
- main.log.info( "Creating host components" )
- main.Scapy.createHostComponent( "h5" )
- main.Scapy.createHostComponent( "h6" )
- hosts = [ main.h5, main.h6 ]
- for host in hosts:
- host.startHostCli()
+ for host in main.scapyHosts:
+ host.stopScapy()
host.startScapy()
host.updateSelf( IPv6=True )
+ main.log.debug( host.name )
+ main.log.debug( host.hostIp )
+ main.log.debug( host.hostMac )
# Add a flow that connects host1 on port1 to host2 on port2
egress = 6
@@ -989,12 +981,6 @@
else:
main.h6.killFilter()
- main.log.info( "Clean up host components" )
- for host in hosts:
- host.stopScapy()
- main.Mininet1.removeHostComponent( "h5" )
- main.Mininet1.removeHostComponent( "h6" )
-
utilities.assert_equals( expect=main.TRUE,
actual=stepResult,
onpass="Successfully sent a packet",
@@ -1047,14 +1033,14 @@
main.step( "Add flows with ARP addresses as the only selectors" )
- main.log.info( "Creating host components" )
- main.Scapy.createHostComponent( "h1" )
- main.Scapy.createHostComponent( "h2" )
- hosts = [ main.h1, main.h2 ]
- for host in hosts:
- host.startHostCli()
+ for host in main.scapyHosts:
+ host.stopScapy()
host.startScapy()
host.updateSelf()
+ main.log.debug( host.name )
+ main.log.debug( host.hostIp )
+ main.log.debug( host.hostMac )
+
ctrl = main.Cluster.active( 0 )
# Add a flow that connects host1 on port1 to host2 on port2
# send output on port2
@@ -1104,12 +1090,6 @@
else:
main.h2.killFilter()
- main.log.info( "Clean up host components" )
- for host in hosts:
- host.stopScapy()
- main.Mininet1.removeHostComponent( "h1" )
- main.Mininet1.removeHostComponent( "h2" )
-
utilities.assert_equals( expect=main.TRUE,
actual=stepResult,
onpass="Successfully sent a packet",
@@ -1129,14 +1109,13 @@
main.step( "Add a flow with a SCTP selector" )
- main.log.info( "Creating host components" )
- main.Scapy.createHostComponent( "h1" )
- main.Scapy.createHostComponent( "h2" )
- hosts = [ main.h1, main.h2 ]
- for host in hosts:
- host.startHostCli()
+ for host in main.scapyHosts:
+ host.stopScapy()
host.startScapy()
host.updateSelf()
+ main.log.debug( host.name )
+ main.log.debug( host.hostIp )
+ main.log.debug( host.hostMac )
# Add a flow that connects host1 on port1 to host2 on port2
egress = 2
@@ -1186,12 +1165,6 @@
else:
main.h2.killFilter()
- main.log.info( "Clean up host components" )
- for host in hosts:
- host.stopScapy()
- main.Mininet1.removeHostComponent( "h1" )
- main.Mininet1.removeHostComponent( "h2" )
-
utilities.assert_equals( expect=main.TRUE,
actual=stepResult,
onpass="Successfully sent a packet",
diff --git a/TestON/tests/FUNC/FUNCflow/FUNCflow.topo b/TestON/tests/FUNC/FUNCflow/FUNCflow.topo
index 41c97e3..6959073 100755
--- a/TestON/tests/FUNC/FUNCflow/FUNCflow.topo
+++ b/TestON/tests/FUNC/FUNCflow/FUNCflow.topo
@@ -36,7 +36,7 @@
<host>OCN</host>
<user>sdn</user>
<password>rocks</password>
- <type>ScapyCliDriver</type>
+ <type>MininetScapyCliDriver</type>
<connect_order>3</connect_order>
<COMPONENTS>
<prompt></prompt>
diff --git a/TestON/tests/FUNC/FUNCgroup/FUNCgroup.params b/TestON/tests/FUNC/FUNCgroup/FUNCgroup.params
index 90a5082..99a8e01 100644
--- a/TestON/tests/FUNC/FUNCgroup/FUNCgroup.params
+++ b/TestON/tests/FUNC/FUNCgroup/FUNCgroup.params
@@ -3,14 +3,15 @@
# CASE - Description
# 1 - Variable initialization and optional pull and build ONOS package
# 2 - install ONOS
- # 3 - Start mininet and verify topology
+ # 3 - Start mininet and scapy and verify topology
# 4 - Testing Scapy
# 5 - Testing GROUP with type "ALL"
# 6 - Deleting the Group and Flow
# 7 - Testing GROUP with type "INDIRECT"
# 8 - Deleting the group and flow
+ # 10 - Stop mininet and scapy
# 100 - Check logs for Errors and Warnings
- <testcases>1,2,3,5,6,7,6,100</testcases>
+ <testcases>1,2,3,5,6,7,6,10,100</testcases>
<GRAPH>
<nodeCluster>VM</nodeCluster>
@@ -68,4 +69,8 @@
<delGroup>10</delGroup>
</SLEEP>
+ <SCAPY>
+ <HOSTNAMES>h1,h2,h3,h4</HOSTNAMES>
+ </SCAPY>
+
</PARAMS>
diff --git a/TestON/tests/FUNC/FUNCgroup/FUNCgroup.py b/TestON/tests/FUNC/FUNCgroup/FUNCgroup.py
index 80ffe94..bbe759d 100644
--- a/TestON/tests/FUNC/FUNCgroup/FUNCgroup.py
+++ b/TestON/tests/FUNC/FUNCgroup/FUNCgroup.py
@@ -73,6 +73,8 @@
groupId = main.params[ 'TEST' ][ 'groupId' ]
priority = main.params[ 'TEST' ][ 'priority' ]
deviceId = main.params[ 'TEST' ][ 'swDPID' ]
+ main.scapyHostNames = main.params[ 'SCAPY' ][ 'HOSTNAMES' ].split( ',' )
+ main.scapyHosts = [] # List of scapy hosts for iterating
main.debug = True if "on" in main.debug else False
# -- INIT SECTION, ONLY RUNS ONCE -- #
@@ -153,17 +155,33 @@
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="Successfully created Scapy Components",
+ onfail="Failed to discover Scapy Components" )
+
def CASE4( self, main ):
"""
Testing scapy
"""
main.case( "Testing scapy" )
- main.step( "Creating Host1 component" )
- main.Scapy.createHostComponent( "h1" )
- main.Scapy.createHostComponent( "h2" )
- hosts = [ main.h1, main.h2 ]
- for host in hosts:
- host.startHostCli()
+ for host in main.scapyHosts:
+ host.stopScapy()
host.startScapy()
host.updateSelf()
main.log.debug( host.name )
@@ -218,12 +236,6 @@
onpass="Pass",
onfail="Fail" )
- main.step( "Clean up host components" )
- for host in hosts:
- host.stopScapy()
- main.Mininet1.removeHostComponent( "h1" )
- main.Mininet1.removeHostComponent( "h2" )
-
def CASE5( self, main ):
"""
Adding Group of type "ALL" using Rest api
@@ -307,17 +319,14 @@
Sends a packet using scapy
"""
main.step( "Testing Group by sending packet using Scapy" )
- main.log.info( "Creating host components" )
- main.Scapy.createHostComponent( "h1" )
- main.Scapy.createHostComponent( "h2" )
- main.Scapy.createHostComponent( "h3" )
- main.Scapy.createHostComponent( "h4" )
-
- hosts = [ main.h1, main.h2, main.h3, main.h4 ]
- for host in hosts:
- host.startHostCli()
+ for host in main.scapyHosts:
+ host.stopScapy()
host.startScapy()
host.updateSelf()
+ main.log.debug( host.name )
+ main.log.debug( host.hostIp )
+ main.log.debug( host.hostMac )
+
main.log.info( "Constructing Packet" )
main.h1.buildEther( dst=main.h1.hostMac )
main.h1.buildIP( dst=main.h1.hostIp )
@@ -354,14 +363,6 @@
main.log.info( "Failure!!!Packet sent to port 1 is not received at port 2,3 and 4" )
stepResult = main.FALSE
- main.log.info( "Clean up host components" )
- for host in hosts:
- host.stopScapy()
- main.Mininet1.removeHostComponent( "h1" )
- main.Mininet1.removeHostComponent( "h2" )
- main.Mininet1.removeHostComponent( "h3" )
- main.Mininet1.removeHostComponent( "h4" )
-
utilities.assert_equals( expect=main.TRUE,
actual=stepResult,
onpass="Packet sent to port 1 is received at port 2,3,4 ",
@@ -489,15 +490,14 @@
Sends a packet using scapy
"""
main.step( "Testing Group by sending packet using Scapy" )
- main.log.info( "Creating host components" )
- main.Scapy.createHostComponent( "h1" )
- main.Scapy.createHostComponent( "h2" )
-
- hosts = [ main.h1, main.h2 ]
- for host in hosts:
- host.startHostCli()
+ for host in main.scapyHosts:
+ host.stopScapy()
host.startScapy()
host.updateSelf()
+ main.log.debug( host.name )
+ main.log.debug( host.hostIp )
+ main.log.debug( host.hostMac )
+
main.log.info( "Constructing Packet" )
main.h1.buildEther( dst=main.h1.hostMac )
main.h1.buildIP( dst=main.h1.hostIp )
@@ -513,17 +513,50 @@
else:
main.h2.killFilter()
- main.log.info( "Clean up host components" )
- for host in hosts:
- host.stopScapy()
- main.Mininet1.removeHostComponent( "h1" )
- main.Mininet1.removeHostComponent( "h2" )
-
utilities.assert_equals( expect=main.TRUE,
actual=stepResultH2,
onpass="Packet sent to port 1 is received at port 2 successfully!!!",
onfail="Failure!!!Packet sent to port 1 is not received at port 2" )
+ def CASE10( self, main ):
+ """
+ Stop mininet and remove scapy host
+ """
+ try:
+ from tests.dependencies.utils import Utils
+ except ImportError:
+ main.log.error( "Utils not found exiting the test" )
+ main.cleanAndExit()
+ try:
+ main.Utils
+ except ( NameError, AttributeError ):
+ main.Utils = Utils()
+ main.log.report( "Stop Mininet and Scapy" )
+ main.case( "Stop Mininet and Scapy" )
+ main.caseExplanation = "Stopping the current mininet topology " +\
+ "to start up fresh"
+ main.step( "Stopping and Removing Scapy Host Components" )
+ scapyResult = main.TRUE
+ for host in main.scapyHosts:
+ scapyResult = scapyResult and host.stopScapy()
+ main.log.info( "Stopped Scapy Host: {0}".format( host.name ) )
+
+ for host in main.scapyHosts:
+ scapyResult = scapyResult and main.Scapy.removeHostComponent( host.name )
+ main.log.info( "Removed Scapy Host Component: {0}".format( host.name ) )
+
+ main.scapyHosts = []
+
+ utilities.assert_equals( expect=main.TRUE,
+ actual=scapyResult,
+ onpass="Successfully stopped scapy and removed host components",
+ onfail="Failed to stop mininet and scapy" )
+
+ mininetResult = main.Utils.mininetCleanup( main.Mininet1 )
+ # Exit if topology did not load properly
+ if not ( mininetResult and scapyResult ):
+ main.cleanAndExit()
+
def CASE100( self, main ):
"""
Report errors/warnings/exceptions
diff --git a/TestON/tests/FUNC/FUNCgroup/FUNCgroup.topo b/TestON/tests/FUNC/FUNCgroup/FUNCgroup.topo
index 41c97e3..6959073 100644
--- a/TestON/tests/FUNC/FUNCgroup/FUNCgroup.topo
+++ b/TestON/tests/FUNC/FUNCgroup/FUNCgroup.topo
@@ -36,7 +36,7 @@
<host>OCN</host>
<user>sdn</user>
<password>rocks</password>
- <type>ScapyCliDriver</type>
+ <type>MininetScapyCliDriver</type>
<connect_order>3</connect_order>
<COMPONENTS>
<prompt></prompt>
diff --git a/TestON/tests/FUNC/FUNCintent/FUNCintent.topo b/TestON/tests/FUNC/FUNCintent/FUNCintent.topo
index ff5eccd..b5e4f03 100755
--- a/TestON/tests/FUNC/FUNCintent/FUNCintent.topo
+++ b/TestON/tests/FUNC/FUNCintent/FUNCintent.topo
@@ -37,7 +37,7 @@
<host>OCN</host>
<user>sdn</user>
<password>rocks</password>
- <type>ScapyCliDriver</type>
+ <type>MininetScapyCliDriver</type>
<connect_order>3</connect_order>
<COMPONENTS>
<prompt></prompt>
diff --git a/TestON/tests/FUNC/FUNCintentRest/FUNCintentRest.topo b/TestON/tests/FUNC/FUNCintentRest/FUNCintentRest.topo
index 33bcf52..9f36491 100755
--- a/TestON/tests/FUNC/FUNCintentRest/FUNCintentRest.topo
+++ b/TestON/tests/FUNC/FUNCintentRest/FUNCintentRest.topo
@@ -37,7 +37,7 @@
<host>OCN</host>
<user>sdn</user>
<password>rocks</password>
- <type>ScapyCliDriver</type>
+ <type>MininetScapyCliDriver</type>
<connect_order>3</connect_order>
<COMPONENTS>
<prompt></prompt>