Merge branch 'devl/newFunctionality' of https://github.com/OPENNETWORKINGLAB/ONLabTest into devl/newFunctionality
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index b4e7154..3b5a5c7 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -1,3 +1,4 @@
+
#!/usr/bin/env python
"""
Created on 26-Oct-2012
@@ -1131,7 +1132,7 @@
return main.TRUE
except pexpect.EOF:
main.log.error( self.name + ": EOF exception found" )
- main.log.error( self.name + ": " + self.handle.before )
+ main.log.error(self.name + ": " + self.handle.before )
main.cleanup()
main.exit()
@@ -1950,6 +1951,64 @@
main.cleanup()
main.exit()
+ def assignVLAN( self, host, intf, vlan):
+ """
+ Add vlan tag to a host.
+ Dependencies:
+ This class depends on the "vlan" package
+ $ sudo apt-get install vlan
+ Configuration:
+ Load the 8021q module into the kernel
+ $sudo modprobe 8021q
+
+ To make this setup permanent:
+ $ sudo su -c 'echo "8021q" >> /etc/modules'
+ """
+ if self.handle:
+ try:
+ # get the ip address of the host
+ main.log.info("Get the ip address of the host")
+ ipaddr = self.getIPAddress(host)
+ print repr(ipaddr)
+
+ # remove IP from interface intf
+ # Ex: h1 ifconfig h1-eth0 inet 0
+ main.log.info("Remove IP from interface ")
+ cmd2 = host + " ifconfig " + intf + " " + " inet 0 "
+ self.handle.sendline( cmd2 )
+ self.handle.expect( "mininet>" )
+ response = self.handle.before
+ main.log.info ( "====> %s ", response)
+
+
+ # create VLAN interface
+ # Ex: h1 vconfig add h1-eth0 100
+ main.log.info("Create Vlan")
+ cmd3 = host + " vconfig add " + intf + " " + vlan
+ self.handle.sendline( cmd3 )
+ self.handle.expect( "mininet>" )
+ response = self.handle.before
+ main.log.info( "====> %s ", response )
+
+ # assign the host's IP to the VLAN interface
+ # Ex: h1 ifconfig h1-eth0.100 inet 10.0.0.1
+ main.log.info("Assign the host IP to the vlan interface")
+ vintf = intf + "." + vlan
+ cmd4 = host + " ifconfig " + vintf + " " + " inet " + ipaddr
+ self.handle.sendline( cmd4 )
+ self.handle.expect( "mininet>" )
+ response = self.handle.before
+ main.log.info ( "====> %s ", response)
+
+
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ return main.FALSE
+
if __name__ != "__main__":
import sys
sys.modules[ __name__ ] = MininetCliDriver()
+
+
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver_orig.py b/TestON/drivers/common/cli/emulator/mininetclidriver_orig.py
new file mode 100644
index 0000000..2d7c0a5
--- /dev/null
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver_orig.py
@@ -0,0 +1,1937 @@
+#!/usr/bin/env python
+"""
+Created on 26-Oct-2012
+
+author: Anil Kumar ( anilkumar.s@paxterrasolutions.com )
+
+
+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/>.
+
+
+MininetCliDriver is the basic driver which will handle the Mininet functions
+
+Some functions rely on STS module. To install this,
+ git clone https://github.com/jhall11/sts.git
+
+Some functions rely on a modified version of Mininet. These functions
+should all be noted in the comments. To get this MN version run these commands
+from within your Mininet folder:
+ git remote add jhall11 https://github.com/jhall11/mininet.git
+ git fetch jhall11
+ git checkout -b dynamic_topo remotes/jhall11/dynamic_topo
+ git pull
+
+
+ Note that you may need to run 'sudo make develop' if your mnexec.c file
+changed when switching branches."""
+import pexpect
+import re
+import sys
+sys.path.append( "../" )
+from math import pow
+from drivers.common.cli.emulatordriver import Emulator
+
+
+class MininetCliDriver( Emulator ):
+
+ """
+ MininetCliDriver is the basic driver which will handle
+ the Mininet functions"""
+ def __init__( self ):
+ super( Emulator, self ).__init__()
+ self.handle = self
+ self.name = None
+ self.wrapped = sys.modules[ __name__ ]
+ self.flag = 0
+
+ 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.name = self.options[ 'name' ]
+ self.handle = super(
+ MininetCliDriver,
+ 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 CLI" )
+ return main.FALSE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ except Exception:
+ main.log.exception( self.name + ": Uncaught exception!" )
+ main.cleanup()
+ main.exit()
+
+ def startNet( self, topoFile='', args='', timeout=120 ):
+ """
+ Starts Mininet accepts a topology(.py) file and/or an optional
+ argument ,to start the mininet, as a parameter.
+ Returns main.TRUE if the mininet starts successfully and
+ main.FALSE otherwise
+ """
+ if self.handle:
+ # make sure old networks are cleaned up
+ main.log.info( self.name +
+ ": Clearing any residual state or processes" )
+ self.handle.sendline( "sudo mn -c" )
+ i = self.handle.expect( [ 'password\sfor\s',
+ 'Cleanup\scomplete',
+ pexpect.EOF,
+ pexpect.TIMEOUT ],
+ timeout )
+ if i == 0:
+ # Sudo asking for password
+ main.log.info( self.name + ": Sending sudo password" )
+ self.handle.sendline( self.pwd )
+ i = self.handle.expect( [ '%s:' % self.user,
+ '\$',
+ pexpect.EOF,
+ pexpect.TIMEOUT ],
+ timeout )
+ if i == 1:
+ main.log.info( self.name + ": Clean" )
+ elif i == 2:
+ main.log.error( self.name + ": Connection terminated" )
+ elif i == 3: # timeout
+ main.log.error( self.name + ": Something while cleaning " +
+ "Mininet took too long... " )
+ # Craft the string to start mininet
+ cmdString = "sudo "
+ if topoFile is None or topoFile == '': # If no file is given
+ main.log.info( self.name + ": building fresh Mininet" )
+ cmdString += "mn "
+ if args is None or args == '':
+ # If no args given, use args from .topo file
+ args = self.options[ 'arg1' ] +\
+ " " + self.options[ 'arg2' ] +\
+ " --mac --controller " +\
+ self.options[ 'controller' ] + " " +\
+ self.options[ 'arg3' ]
+ else: # else only use given args
+ pass
+ # TODO: allow use of topo args and method args?
+ else: # Use given topology file
+ main.log.info( "Starting Mininet from topo file " + topoFile )
+ cmdString += topoFile + " "
+ if args is None:
+ args = ''
+ # TODO: allow use of args from .topo file?
+ cmdString += args
+ # Send the command and check if network started
+ self.handle.sendline( "" )
+ self.handle.expect( '\$' )
+ main.log.info( "Sending '" + cmdString + "' to " + self.name )
+ self.handle.sendline( cmdString )
+ while True:
+ i = self.handle.expect( [ 'mininet>',
+ 'Exception',
+ '\*\*\*',
+ pexpect.EOF,
+ pexpect.TIMEOUT ],
+ timeout )
+ if i == 0:
+ main.log.info( self.name + ": Mininet built" )
+ return main.TRUE
+ elif i == 1:
+ response = str( self.handle.before +
+ self.handle.after )
+ self.handle.expect( '\$' )
+ response += str( self.handle.before +
+ self.handle.after )
+ main.log.error(
+ self.name +
+ ": Launching Mininet failed: " + response )
+ return main.FALSE
+ elif i == 2:
+ self.handle.expect( [ "\n",
+ pexpect.EOF,
+ pexpect.TIMEOUT ],
+ timeout )
+ main.log.info( self.handle.before )
+ elif i == 3:
+ main.log.error( self.name + ": Connection timeout" )
+ return main.FALSE
+ elif i == 4: # timeout
+ main.log.error(
+ self.name +
+ ": Something took too long... " )
+ return main.FALSE
+ # Why did we hit this part?
+ main.log.error( "startNet did not return correctly" )
+ return main.FASLE
+ else: # if no handle
+ main.log.error( self.name + ": Connection failed to the host " +
+ self.user_name + "@" + self.ip_address )
+ main.log.error( self.name + ": Failed to connect to the Mininet" )
+ return main.FALSE
+
+ def numSwitchesNlinks( self, topoType, depth, fanout ):
+ if topoType == 'tree':
+ # In tree topology, if fanout arg is not given, by default it is 2
+ if fanout is None:
+ fanout = 2
+ k = 0
+ count = 0
+ while( k <= depth - 1 ):
+ count = count + pow( fanout, k )
+ k = k + 1
+ numSwitches = count
+ while( k <= depth - 2 ):
+ # depth-2 gives you only core links and not considering
+ # edge links as seen by ONOS. If all the links including
+ # edge links are required, do depth-1
+ count = count + pow( fanout, k )
+ k = k + 1
+ numLinks = count * fanout
+ # print "num_switches for %s(%d,%d) = %d and links=%d" %(
+ # topoType,depth,fanout,numSwitches,numLinks )
+
+ elif topoType == 'linear':
+ # In linear topology, if fanout or numHostsPerSw is not given,
+ # by default it is 1
+ if fanout is None:
+ fanout = 1
+ numSwitches = depth
+ numHostsPerSw = fanout
+ totalNumHosts = numSwitches * numHostsPerSw
+ numLinks = totalNumHosts + ( numSwitches - 1 )
+ print "num_switches for %s(%d,%d) = %d and links=%d" %\
+ ( topoType, depth, fanout, numSwitches, numLinks )
+ topoDict = { "num_switches": int( numSwitches ),
+ "num_corelinks": int( numLinks ) }
+ return topoDict
+
+ def calculateSwAndLinks( self ):
+ """
+ Calculate the number of switches and links in a topo."""
+ # TODO: combine this function and numSwitchesNlinks
+ argList = self.options[ 'arg1' ].split( "," )
+ topoArgList = argList[ 0 ].split( " " )
+ argList = map( int, argList[ 1: ] )
+ topoArgList = topoArgList[ 1: ] + argList
+
+ topoDict = self.numSwitchesNlinks( *topoArgList )
+ return topoDict
+
+ def pingall( self, timeout=300, shortCircuit=False, acceptableFailed=0):
+ """
+ Verifies the reachability of the hosts using pingall command.
+ Optional parameter timeout allows you to specify how long to
+ wait for pingall to complete
+ Optional:
+ timeout(seconds) - This is the pexpect timeout; The function will
+ timeout if the amount of time between failed
+ pings exceedes this time and pingall is still
+ running
+ shortCircuit - Break the pingall based on the number of failed hosts
+ ping
+ acceptableFailed - Set the number of acceptable failed pings for the
+ function to still return main.TRUE
+ Returns:
+ main.TRUE if pingall completes with no pings dropped
+ otherwise main.FALSE"""
+ try:
+ if self.handle:
+ main.log.info(
+ self.name +
+ ": Checking reachabilty to the hosts using pingall" )
+ response = ""
+ failedPings = 0
+ returnValue = main.TRUE
+ self.handle.sendline( "pingall" )
+ while True:
+ i = self.handle.expect( [ "mininet>","X",
+ pexpect.EOF,
+ pexpect.TIMEOUT ],
+ timeout )
+ if i == 0:
+ main.log.info( self.name + ": pingall finished")
+ response += self.handle.before
+ break
+ elif i == 1:
+ response += self.handle.before + self.handle.after
+ failedPings = failedPings + 1
+ if failedPings > acceptableFailed:
+ returnValue = main.FALSE
+ if shortCircuit:
+ main.log.error( self.name +
+ ": Aborting pingall - "
+ + str( failedPings ) +
+ " pings failed" )
+ break
+ elif i == 2:
+ main.log.error( self.name +
+ ": EOF exception found" )
+ main.log.error( self.name + ": " +
+ self.handle.before )
+ main.cleanup()
+ main.exit()
+ elif i == 3:
+ response += self.handle.before
+ main.log.error( self.name +
+ ": TIMEOUT exception found" )
+ main.log.error( self.name +
+ ": " +
+ str( response ) )
+ # NOTE: Send ctrl-c to make sure pingall is done
+ self.handle.sendline( "\x03" )
+ self.handle.expect( "Interrupt" )
+ self.handle.expect( "mininet>" )
+ break
+ pattern = "Results\:"
+ main.log.info( "Pingall output: " + str( response ) )
+ if re.search( pattern, response ):
+ main.log.info( self.name + ": Pingall finished with "
+ + str( failedPings ) + " failed pings" )
+ return returnValue
+ else:
+ # NOTE: Send ctrl-c to make sure pingall is done
+ self.handle.sendline( "\x03" )
+ self.handle.expect( "Interrupt" )
+ self.handle.expect( "mininet>" )
+ return main.FALSE
+ else:
+ main.log.error( self.name + ": Connection failed to the host" )
+ main.cleanup()
+ main.exit()
+ except pexpect.TIMEOUT:
+ if response:
+ main.log.info( "Pingall output: " + str( response ) )
+ main.log.error( self.name + ": pexpect.TIMEOUT found" )
+ return main.FALSE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+
+ def fpingHost( self, **pingParams ):
+ """
+ Uses the fping package for faster pinging...
+ *requires fping to be installed on machine running mininet"""
+ args = utilities.parse_args( [ "SRC", "TARGET" ], **pingParams )
+ command = args[ "SRC" ] + \
+ " fping -i 100 -t 20 -C 1 -q " + args[ "TARGET" ]
+ self.handle.sendline( command )
+ self.handle.expect(
+ [ args[ "TARGET" ], pexpect.EOF, pexpect.TIMEOUT ] )
+ self.handle.expect( [ "mininet", pexpect.EOF, pexpect.TIMEOUT ] )
+ response = self.handle.before
+ if re.search( ":\s-", response ):
+ main.log.info( self.name + ": Ping fail" )
+ return main.FALSE
+ elif re.search( ":\s\d{1,2}\.\d\d", response ):
+ main.log.info( self.name + ": Ping good!" )
+ return main.TRUE
+ main.log.info( self.name + ": Install fping on mininet machine... " )
+ main.log.info( self.name + ": \n---\n" + response )
+ return main.FALSE
+
+ def pingHost( self, **pingParams ):
+ """
+ Ping from one mininet host to another
+ Currently the only supported Params: SRC and TARGET"""
+ args = utilities.parse_args( [ "SRC", "TARGET" ], **pingParams )
+ command = args[ "SRC" ] + " ping " + \
+ args[ "TARGET" ] + " -c 1 -i 1 -W 8"
+ try:
+ main.log.info( "Sending: " + command )
+ self.handle.sendline( command )
+ i = self.handle.expect( [ command, pexpect.TIMEOUT ] )
+ if i == 1:
+ main.log.error(
+ self.name +
+ ": timeout when waiting for response from mininet" )
+ main.log.error( "response: " + str( self.handle.before ) )
+ i = self.handle.expect( [ "mininet>", pexpect.TIMEOUT ] )
+ if i == 1:
+ main.log.error(
+ self.name +
+ ": timeout when waiting for response from mininet" )
+ main.log.error( "response: " + str( self.handle.before ) )
+ response = self.handle.before
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ main.log.info( self.name + ": Ping Response: " + response )
+ if re.search( ',\s0\%\spacket\sloss', response ):
+ main.log.info( self.name + ": no packets lost, host is reachable" )
+ main.lastResult = main.TRUE
+ return main.TRUE
+ else:
+ main.log.error(
+ self.name +
+ ": PACKET LOST, HOST IS NOT REACHABLE" )
+ main.lastResult = main.FALSE
+ return main.FALSE
+
+ def checkIP( self, host ):
+ """
+ Verifies the host's ip configured or not."""
+ if self.handle:
+ try:
+ response = self.execute(
+ cmd=host +
+ " ifconfig",
+ prompt="mininet>",
+ timeout=10 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+
+ pattern = "inet\s(addr|Mask):([0-1]{1}[0-9]{1,2}|" +\
+ "2[0-4][0-9]|25[0-5]|[0-9]{1,2}).([0-1]{1}" +\
+ "[0-9]{1,2}|2[0-4][0-9]|25[0-5]|[0-9]{1,2})." +\
+ "([0-1]{1}[0-9]{1,2}|2[0-4][0-9]|25[0-5]|" +\
+ "[0-9]{1,2}).([0-1]{1}[0-9]{1,2}|2[0-4]" +\
+ "[0-9]|25[0-5]|[0-9]{1,2})"
+ # pattern = "inet addr:10.0.0.6"
+ if re.search( pattern, response ):
+ main.log.info( self.name + ": Host Ip configured properly" )
+ return main.TRUE
+ else:
+ main.log.error( self.name + ": Host IP not found" )
+ return main.FALSE
+ else:
+ main.log.error( self.name + ": Connection failed to the host" )
+
+ def verifySSH( self, **connectargs ):
+ # FIXME: Who uses this and what is the purpose? seems very specific
+ try:
+ response = self.execute(
+ cmd="h1 /usr/sbin/sshd -D&",
+ prompt="mininet>",
+ timeout=10 )
+ response = self.execute(
+ cmd="h4 /usr/sbin/sshd -D&",
+ prompt="mininet>",
+ timeout=10 )
+ for key in connectargs:
+ vars( self )[ key ] = connectargs[ key ]
+ response = self.execute(
+ cmd="xterm h1 h4 ",
+ prompt="mininet>",
+ timeout=10 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ import time
+ time.sleep( 20 )
+ if self.flag == 0:
+ self.flag = 1
+ return main.FALSE
+ else:
+ return main.TRUE
+
+ def moveHost( self, host, oldSw, newSw, ):
+ """
+ Moves a host from one switch to another on the fly
+ Note: The intf between host and oldSw when detached
+ using detach(), will still show up in the 'net'
+ cmd, because switch.detach() doesn't affect switch.intfs[]
+ (which is correct behavior since the interfaces
+ haven't moved).
+ """
+ if self.handle:
+ try:
+ # Bring link between oldSw-host down
+ cmd = "py net.configLinkStatus('" + oldSw + "'," + "'"+ host +\
+ "'," + "'down')"
+ print "cmd1= ", cmd
+ response = self.execute( cmd=cmd,
+ prompt="mininet>",
+ timeout=10 )
+
+ # Determine hostintf and Oldswitchintf
+ cmd = "px hintf,sintf = " + host + ".connectionsTo(" + oldSw +\
+ ")[0]"
+ print "cmd2= ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+
+ # Determine ip and mac address of the host-oldSw interface
+ cmd = "px ipaddr = hintf.IP()"
+ print "cmd3= ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+
+ cmd = "px macaddr = hintf.MAC()"
+ print "cmd3= ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+
+ # Detach interface between oldSw-host
+ cmd = "px " + oldSw + ".detach( sintf )"
+ print "cmd4= ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+
+ # Add link between host-newSw
+ cmd = "py net.addLink(" + host + "," + newSw + ")"
+ print "cmd5= ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+
+ # Determine hostintf and Newswitchintf
+ cmd = "px hintf,sintf = " + host + ".connectionsTo(" + newSw +\
+ ")[0]"
+ print "cmd6= ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+
+ # Attach interface between newSw-host
+ cmd = "px " + newSw + ".attach( sintf )"
+ print "cmd3= ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+
+ # Set ipaddress of the host-newSw interface
+ cmd = "px " + host + ".setIP( ip = ipaddr, intf = hintf)"
+ print "cmd7 = ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+
+ # Set macaddress of the host-newSw interface
+ cmd = "px " + host + ".setMAC( mac = macaddr, intf = hintf)"
+ print "cmd8 = ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+
+ cmd = "net"
+ print "cmd9 = ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+ print "output = ", self.handle.before
+
+ # Determine ipaddress of the host-newSw interface
+ cmd = host + " ifconfig"
+ print "cmd10= ", cmd
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+ print "ifconfig o/p = ", self.handle.before
+
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ return main.FALSE
+
+ def changeIP( self, host, intf, newIP, newNetmask ):
+ """
+ Changes the ip address of a host on the fly
+ Ex: h2 ifconfig h2-eth0 10.0.1.2 netmask 255.255.255.0"""
+ if self.handle:
+ try:
+ cmd = host + " ifconfig " + intf + " " + \
+ newIP + " " + 'netmask' + " " + newNetmask
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+ response = self.handle.before
+ main.log.info( "response = " + response )
+ main.log.info(
+ "Ip of host " +
+ host +
+ " changed to new IP " +
+ newIP )
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ return main.FALSE
+
+ def changeDefaultGateway( self, host, newGW ):
+ """
+ Changes the default gateway of a host
+ Ex: h1 route add default gw 10.0.1.2"""
+ if self.handle:
+ try:
+ cmd = host + " route add default gw " + newGW
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+ response = self.handle.before
+ main.log.info( "response = " + response )
+ main.log.info(
+ "Default gateway of host " +
+ host +
+ " changed to " +
+ newGW )
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ return main.FALSE
+
+ def addStaticMACAddress( self, host, GW, macaddr ):
+ """
+ Changes the mac address of a gateway host"""
+ if self.handle:
+ try:
+ # h1 arp -s 10.0.1.254 00:00:00:00:11:11
+ cmd = host + " arp -s " + GW + " " + macaddr
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+ response = self.handle.before
+ main.log.info( "response = " + response )
+ main.log.info(
+ "Mac address of gateway " +
+ GW +
+ " changed to " +
+ macaddr )
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ return main.FALSE
+
+ def verifyStaticGWandMAC( self, host ):
+ """
+ Verify if the static gateway and mac address assignment"""
+ if self.handle:
+ try:
+ # h1 arp -an
+ cmd = host + " arp -an "
+ self.handle.sendline( cmd )
+ self.handle.expect( "mininet>" )
+ response = self.handle.before
+ main.log.info( host + " arp -an = " + response )
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ return main.FALSE
+
+ def getMacAddress( self, host ):
+ """
+ Verifies the host's ip configured or not."""
+ if self.handle:
+ try:
+ response = self.execute(
+ cmd=host +
+ " ifconfig",
+ prompt="mininet>",
+ timeout=10 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+
+ pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})'
+ macAddressSearch = re.search( pattern, response, re.I )
+ macAddress = macAddressSearch.group().split( " " )[ 1 ]
+ main.log.info(
+ self.name +
+ ": Mac-Address of Host " +
+ host +
+ " is " +
+ macAddress )
+ return macAddress
+ else:
+ main.log.error( self.name + ": Connection failed to the host" )
+
+ def getInterfaceMACAddress( self, host, interface ):
+ """
+ Return the IP address of the interface on the given host"""
+ if self.handle:
+ try:
+ response = self.execute( cmd=host + " ifconfig " + interface,
+ prompt="mininet>", timeout=10 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+
+ pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})'
+ macAddressSearch = re.search( pattern, response, re.I )
+ if macAddressSearch is None:
+ main.log.info( "No mac address found in %s" % response )
+ return main.FALSE
+ macAddress = macAddressSearch.group().split( " " )[ 1 ]
+ main.log.info(
+ "Mac-Address of " +
+ host +
+ ":" +
+ interface +
+ " is " +
+ macAddress )
+ return macAddress
+ else:
+ main.log.error( "Connection failed to the host" )
+
+ def getIPAddress( self, host ):
+ """
+ Verifies the host's ip configured or not."""
+ if self.handle:
+ try:
+ response = self.execute(
+ cmd=host +
+ " ifconfig",
+ prompt="mininet>",
+ timeout=10 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+
+ pattern = "inet\saddr:(\d+\.\d+\.\d+\.\d+)"
+ ipAddressSearch = re.search( pattern, response )
+ main.log.info(
+ self.name +
+ ": IP-Address of Host " +
+ host +
+ " is " +
+ ipAddressSearch.group( 1 ) )
+ return ipAddressSearch.group( 1 )
+ else:
+ main.log.error( self.name + ": Connection failed to the host" )
+
+ def getSwitchDPID( self, switch ):
+ """
+ return the datapath ID of the switch"""
+ if self.handle:
+ cmd = "py %s.dpid" % switch
+ try:
+ response = self.execute(
+ cmd=cmd,
+ prompt="mininet>",
+ timeout=10 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ pattern = r'^(?P<dpid>\w)+'
+ result = re.search( pattern, response, re.MULTILINE )
+ if result is None:
+ main.log.info(
+ "Couldn't find DPID for switch %s, found: %s" %
+ ( switch, response ) )
+ return main.FALSE
+ return str( result.group( 0 ) ).lower()
+ else:
+ main.log.error( "Connection failed to the host" )
+
+ def getDPID( self, switch ):
+ if self.handle:
+ self.handle.sendline( "" )
+ self.expect( "mininet>" )
+ cmd = "py %s.dpid" % switch
+ try:
+ response = self.execute(
+ cmd=cmd,
+ prompt="mininet>",
+ timeout=10 )
+ self.handle.expect( "mininet>" )
+ response = self.handle.before
+ return response
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+
+ def getInterfaces( self, node ):
+ """
+ return information dict about interfaces connected to the node"""
+ if self.handle:
+ cmd = 'py "\\n".join(["name=%s,mac=%s,ip=%s,enabled=%s"' +\
+ ' % (i.name, i.MAC(), i.IP(), i.isUp())'
+ cmd += ' for i in %s.intfs.values()])' % node
+ try:
+ response = self.execute(
+ cmd=cmd,
+ prompt="mininet>",
+ timeout=10 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ return response
+ else:
+ main.log.error( "Connection failed to the node" )
+
+ def dump( self ):
+ main.log.info( self.name + ": Dump node info" )
+ try:
+ response = self.execute(
+ cmd='dump',
+ prompt='mininet>',
+ timeout=10 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ return response
+
+ def intfs( self ):
+ main.log.info( self.name + ": List interfaces" )
+ try:
+ response = self.execute(
+ cmd='intfs',
+ prompt='mininet>',
+ timeout=10 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ return response
+
+ def net( self ):
+ main.log.info( self.name + ": List network connections" )
+ try:
+ response = self.execute( cmd='net', prompt='mininet>', timeout=10 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ return response
+
+ def iperf( self, host1, host2 ):
+ main.log.info(
+ self.name +
+ ": Simple iperf TCP test between two hosts" )
+ try:
+ cmd1 = 'iperf ' + host1 + " " + host2
+ self.handle.sendline( cmd1 )
+ self.handle.expect( "mininet>" )
+ response = self.handle.before
+ if re.search( 'Results:', response ):
+ main.log.info( self.name + ": iperf test successful" )
+ return main.TRUE
+ else:
+ main.log.error( self.name + ": iperf test failed" )
+ return main.FALSE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+
+ def iperfudp( self ):
+ main.log.info(
+ self.name +
+ ": Simple iperf TCP test between two " +
+ "(optionally specified) hosts" )
+ try:
+ response = self.execute(
+ cmd='iperfudp',
+ prompt='mininet>',
+ timeout=10 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ return response
+
+ def nodes( self ):
+ main.log.info( self.name + ": List all nodes." )
+ try:
+ response = self.execute(
+ cmd='nodes',
+ prompt='mininet>',
+ timeout=10 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ return response
+
+ def pingpair( self ):
+ main.log.info( self.name + ": Ping between first two hosts" )
+ try:
+ response = self.execute(
+ cmd='pingpair',
+ prompt='mininet>',
+ timeout=20 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+
+ if re.search( ',\s0\%\spacket\sloss', response ):
+ main.log.info( self.name + ": Ping between two hosts SUCCESSFUL" )
+ main.lastResult = main.TRUE
+ return main.TRUE
+ else:
+ main.log.error( self.name + ": PACKET LOST, HOSTS NOT REACHABLE" )
+ main.lastResult = main.FALSE
+ return main.FALSE
+
+ def link( self, **linkargs ):
+ """
+ Bring link( s ) between two nodes up or down"""
+ args = utilities.parse_args( [ "END1", "END2", "OPTION" ], **linkargs )
+ end1 = args[ "END1" ] if args[ "END1" ] is not None else ""
+ end2 = args[ "END2" ] if args[ "END2" ] is not None else ""
+ option = args[ "OPTION" ] if args[ "OPTION" ] is not None else ""
+ main.log.info(
+ "Bring link between '" +
+ end1 +
+ "' and '" +
+ end2 +
+ "' '" +
+ option +
+ "'" )
+ command = "link " + \
+ str( end1 ) + " " + str( end2 ) + " " + str( option )
+ try:
+ self.handle.sendline( command )
+ self.handle.expect( "mininet>" )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ return main.TRUE
+
+ def yank( self, **yankargs ):
+ """
+ yank a mininet switch interface to a host"""
+ main.log.info( 'Yank the switch interface attached to a host' )
+ args = utilities.parse_args( [ "SW", "INTF" ], **yankargs )
+ sw = args[ "SW" ] if args[ "SW" ] is not None else ""
+ intf = args[ "INTF" ] if args[ "INTF" ] is not None else ""
+ command = "py " + str( sw ) + '.detach("' + str(intf) + '")'
+ try:
+ response = self.execute(
+ cmd=command,
+ prompt="mininet>",
+ timeout=10 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ return main.TRUE
+
+ def plug( self, **plugargs ):
+ """
+ plug the yanked mininet switch interface to a switch"""
+ main.log.info( 'Plug the switch interface attached to a switch' )
+ args = utilities.parse_args( [ "SW", "INTF" ], **plugargs )
+ sw = args[ "SW" ] if args[ "SW" ] is not None else ""
+ intf = args[ "INTF" ] if args[ "INTF" ] is not None else ""
+ command = "py " + str( sw ) + '.attach("' + str(intf) + '")'
+ try:
+ response = self.execute(
+ cmd=command,
+ prompt="mininet>",
+ timeout=10 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ return main.TRUE
+
+ def dpctl( self, **dpctlargs ):
+ """
+ Run dpctl command on all switches."""
+ main.log.info( 'Run dpctl command on all switches' )
+ args = utilities.parse_args( [ "CMD", "ARGS" ], **dpctlargs )
+ cmd = args[ "CMD" ] if args[ "CMD" ] is not None else ""
+ cmdargs = args[ "ARGS" ] if args[ "ARGS" ] is not None else ""
+ command = "dpctl " + cmd + " " + str( cmdargs )
+ try:
+ response = self.execute(
+ cmd=command,
+ prompt="mininet>",
+ timeout=10 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ return main.TRUE
+
+ def getVersion( self ):
+ #FIXME: What uses this? This should be refactored to get
+ # version from MN and not some other file
+ fileInput = path + '/lib/Mininet/INSTALL'
+ version = super( Mininet, self ).getVersion()
+ pattern = 'Mininet\s\w\.\w\.\w\w*'
+ for line in open( fileInput, 'r' ).readlines():
+ result = re.match( pattern, line )
+ if result:
+ version = result.group( 0 )
+ return version
+
+ def getSwController( self, sw ):
+ """
+ Parameters:
+ sw: The name of an OVS switch. Example "s1"
+ Return:
+ The output of the command from the mininet cli
+ or main.FALSE on timeout"""
+ command = "sh ovs-vsctl get-controller " + str( sw )
+ try:
+ response = self.execute(
+ cmd=command,
+ prompt="mininet>",
+ timeout=10 )
+ if response:
+ return response
+ else:
+ return main.FALSE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+
+ def assignSwController( self, **kwargs ):
+ """
+ count is only needed if there is more than 1 controller"""
+ args = utilities.parse_args( [ "COUNT" ], **kwargs )
+ count = args[ "COUNT" ] if args != {} else 1
+
+ argstring = "SW"
+ for j in range( count ):
+ argstring = argstring + ",IP" + \
+ str( j + 1 ) + ",PORT" + str( j + 1 )
+ args = utilities.parse_args( argstring.split( "," ), **kwargs )
+
+ sw = args[ "SW" ] if args[ "SW" ] is not None else ""
+ ptcpA = int( args[ "PORT1" ] ) + \
+ int( sw ) if args[ "PORT1" ] is not None else ""
+ ptcpB = "ptcp:" + str( ptcpA ) if ptcpA != "" else ""
+
+ command = "sh ovs-vsctl set-controller s" + \
+ str( sw ) + " " + ptcpB + " "
+ for j in range( count ):
+ i = j + 1
+ args = utilities.parse_args(
+ [ "IP" + str( i ), "PORT" + str( i ) ], **kwargs )
+ ip = args[
+ "IP" +
+ str( i ) ] if args[
+ "IP" +
+ str( i ) ] is not None else ""
+ port = args[
+ "PORT" +
+ str( i ) ] if args[
+ "PORT" +
+ str( i ) ] is not None else ""
+ tcp = "tcp:" + str( ip ) + ":" + str( port ) + \
+ " " if ip != "" else ""
+ command = command + tcp
+ try:
+ self.execute( cmd=command, prompt="mininet>", timeout=5 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ except Exception:
+ main.log.exception( self.name + ": Uncaught exception!" )
+ main.cleanup()
+ main.exit()
+
+ def deleteSwController( self, sw ):
+ """
+ Removes the controller target from sw"""
+ command = "sh ovs-vsctl del-controller " + str( sw )
+ try:
+ response = self.execute(
+ cmd=command,
+ prompt="mininet>",
+ timeout=10 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ else:
+ main.log.info( response )
+
+ def addSwitch( self, sw, **kwargs ):
+ """
+ adds a switch to the mininet topology
+ NOTE: This uses a custom mn function. MN repo should be on
+ dynamic_topo branch
+ NOTE: cannot currently specify what type of switch
+ required params:
+ sw = name of the new switch as a string
+ optional keywords:
+ dpid = "dpid"
+ returns: main.FALSE on an error, else main.TRUE
+ """
+ dpid = kwargs.get( 'dpid', '' )
+ command = "addswitch " + str( sw ) + " " + str( dpid )
+ try:
+ response = self.execute(
+ cmd=command,
+ prompt="mininet>",
+ timeout=10 )
+ if re.search( "already exists!", response ):
+ main.log.warn( response )
+ return main.FALSE
+ elif re.search( "Error", response ):
+ main.log.warn( response )
+ return main.FALSE
+ elif re.search( "usage:", response ):
+ main.log.warn( response )
+ return main.FALSE
+ else:
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+
+ def delSwitch( self, sw ):
+ """
+ delete a switch from the mininet topology
+ NOTE: This uses a custom mn function. MN repo should be on
+ dynamic_topo branch
+ required params:
+ sw = name of the switch as a string
+ returns: main.FALSE on an error, else main.TRUE"""
+ command = "delswitch " + str( sw )
+ try:
+ response = self.execute(
+ cmd=command,
+ prompt="mininet>",
+ timeout=10 )
+ if re.search( "no switch named", response ):
+ main.log.warn( response )
+ return main.FALSE
+ elif re.search( "Error", response ):
+ main.log.warn( response )
+ return main.FALSE
+ elif re.search( "usage:", response ):
+ main.log.warn( response )
+ return main.FALSE
+ else:
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+
+ def addLink( self, node1, node2 ):
+ """
+ add a link to the mininet topology
+ NOTE: This uses a custom mn function. MN repo should be on
+ dynamic_topo branch
+ NOTE: cannot currently specify what type of link
+ required params:
+ node1 = the string node name of the first endpoint of the link
+ node2 = the string node name of the second endpoint of the link
+ returns: main.FALSE on an error, else main.TRUE"""
+ command = "addlink " + str( node1 ) + " " + str( node2 )
+ try:
+ response = self.execute(
+ cmd=command,
+ prompt="mininet>",
+ timeout=10 )
+ if re.search( "doesnt exist!", response ):
+ main.log.warn( response )
+ return main.FALSE
+ elif re.search( "Error", response ):
+ main.log.warn( response )
+ return main.FALSE
+ elif re.search( "usage:", response ):
+ main.log.warn( response )
+ return main.FALSE
+ else:
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+
+ def delLink( self, node1, node2 ):
+ """
+ delete a link from the mininet topology
+ NOTE: This uses a custom mn function. MN repo should be on
+ dynamic_topo branch
+ required params:
+ node1 = the string node name of the first endpoint of the link
+ node2 = the string node name of the second endpoint of the link
+ returns: main.FALSE on an error, else main.TRUE"""
+ command = "dellink " + str( node1 ) + " " + str( node2 )
+ try:
+ response = self.execute(
+ cmd=command,
+ prompt="mininet>",
+ timeout=10 )
+ if re.search( "no node named", response ):
+ main.log.warn( response )
+ return main.FALSE
+ elif re.search( "Error", response ):
+ main.log.warn( response )
+ return main.FALSE
+ elif re.search( "usage:", response ):
+ main.log.warn( response )
+ return main.FALSE
+ else:
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+
+ def addHost( self, hostname, **kwargs ):
+ """
+ Add a host to the mininet topology
+ NOTE: This uses a custom mn function. MN repo should be on
+ dynamic_topo branch
+ NOTE: cannot currently specify what type of host
+ required params:
+ hostname = the string hostname
+ optional key-value params
+ switch = "switch name"
+ returns: main.FALSE on an error, else main.TRUE
+ """
+ switch = kwargs.get( 'switch', '' )
+ command = "addhost " + str( hostname ) + " " + str( switch )
+ try:
+ response = self.execute(
+ cmd=command,
+ prompt="mininet>",
+ timeout=10 )
+ if re.search( "already exists!", response ):
+ main.log.warn( response )
+ return main.FALSE
+ elif re.search( "doesnt exists!", response ):
+ main.log.warn( response )
+ return main.FALSE
+ elif re.search( "Error", response ):
+ main.log.warn( response )
+ return main.FALSE
+ elif re.search( "usage:", response ):
+ main.log.warn( response )
+ return main.FALSE
+ else:
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+
+ def delHost( self, hostname ):
+ """
+ delete a host from the mininet topology
+ NOTE: This uses a custom mn function. MN repo should be on
+ dynamic_topo branch
+ NOTE: this uses a custom mn function
+ required params:
+ hostname = the string hostname
+ returns: main.FALSE on an error, else main.TRUE"""
+ command = "delhost " + str( hostname )
+ try:
+ response = self.execute(
+ cmd=command,
+ prompt="mininet>",
+ timeout=10 )
+ if re.search( "no host named", response ):
+ main.log.warn( response )
+ return main.FALSE
+ elif re.search( "Error", response ):
+ main.log.warn( response )
+ return main.FALSE
+ elif re.search( "usage:", response ):
+ main.log.warn( response )
+ return main.FALSE
+ else:
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+
+ def disconnect( self ):
+ """
+ Called at the end of the test to stop the mininet and
+ disconnect the handle.
+ """
+ self.handle.sendline('')
+ i = self.handle.expect( [ 'mininet>', pexpect.EOF, pexpect.TIMEOUT ],
+ timeout=2)
+ if i == 0:
+ self.stopNet()
+ elif i == 1:
+ return main.TRUE
+ response = 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 mininet fails to stop
+ """
+
+ main.log.info( self.name + ": Stopping mininet..." )
+ response = ''
+ if self.handle:
+ try:
+ self.handle.sendline("")
+ i = self.handle.expect( [ 'mininet>',
+ '\$',
+ pexpect.EOF,
+ pexpect.TIMEOUT ],
+ timeout )
+ if i == 0:
+ main.log.info( "Exiting mininet..." )
+
+ response = self.execute(
+ cmd="exit",
+ prompt="(.*)",
+ timeout=120 )
+ main.log.info( self.name + ": Stopped")
+ self.handle.sendline( "sudo mn -c" )
+ 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.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.cleanup()
+ main.exit()
+ else:
+ main.log.error( self.name + ": Connection failed to the host" )
+ response = main.FALSE
+ return response
+
+ def arping( self, src, dest, destmac ):
+ self.handle.sendline( '' )
+ self.handle.expect( [ "mininet", pexpect.EOF, pexpect.TIMEOUT ] )
+
+ self.handle.sendline( src + ' arping ' + dest )
+ try:
+ self.handle.expect( [ destmac, pexpect.EOF, pexpect.TIMEOUT ] )
+ main.log.info( self.name + ": ARP successful" )
+ self.handle.expect( [ "mininet", pexpect.EOF, pexpect.TIMEOUT ] )
+ return main.TRUE
+ except Exception:
+ main.log.warn( self.name + ": ARP FAILURE" )
+ self.handle.expect( [ "mininet", pexpect.EOF, pexpect.TIMEOUT ] )
+ return main.FALSE
+
+ def decToHex( self, num ):
+ return hex( num ).split( 'x' )[ 1 ]
+
+ def getSwitchFlowCount( self, switch ):
+ """
+ return the Flow Count of the switch"""
+ if self.handle:
+ cmd = "sh ovs-ofctl dump-aggregate %s" % switch
+ try:
+ response = self.execute(
+ cmd=cmd,
+ prompt="mininet>",
+ timeout=10 )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + " " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ pattern = "flow_count=(\d+)"
+ result = re.search( pattern, response, re.MULTILINE )
+ if result is None:
+ main.log.info(
+ "Couldn't find flows on switch %s, found: %s" %
+ ( switch, response ) )
+ return main.FALSE
+ return result.group( 1 )
+ else:
+ main.log.error( "Connection failed to the Mininet host" )
+
+ def checkFlows( self, sw, dumpFormat=None ):
+ if dumpFormat:
+ command = "sh ovs-ofctl -F " + \
+ dumpFormat + " dump-flows " + str( sw )
+ else:
+ command = "sh ovs-ofctl dump-flows " + str( sw )
+ try:
+ response = self.execute(
+ cmd=command,
+ prompt="mininet>",
+ timeout=10 )
+ return response
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+
+ def startTcpdump( self, filename, intf="eth0", port="port 6633" ):
+ """
+ Runs tpdump on an interface and saves the file
+ intf can be specified, or the default eth0 is used"""
+ try:
+ self.handle.sendline( "" )
+ self.handle.expect( "mininet>" )
+ self.handle.sendline(
+ "sh sudo tcpdump -n -i " +
+ intf +
+ " " +
+ port +
+ " -w " +
+ filename.strip() +
+ " &" )
+ self.handle.sendline( "" )
+ i = self.handle.expect( [ 'No\ssuch\device',
+ 'listening\son',
+ pexpect.TIMEOUT,
+ "mininet>" ],
+ timeout=10 )
+ main.log.warn( self.handle.before + self.handle.after )
+ self.handle.sendline( "" )
+ self.handle.expect( "mininet>" )
+ if i == 0:
+ main.log.error(
+ self.name +
+ ": tcpdump - No such device exists. " +
+ "tcpdump attempted on: " +
+ intf )
+ return main.FALSE
+ elif i == 1:
+ main.log.info( self.name + ": tcpdump started on " + intf )
+ return main.TRUE
+ elif i == 2:
+ main.log.error(
+ self.name +
+ ": tcpdump command timed out! Check interface name," +
+ " given interface was: " +
+ intf )
+ return main.FALSE
+ elif i == 3:
+ main.log.info( self.name + ": " + self.handle.before )
+ return main.TRUE
+ else:
+ main.log.error( self.name + ": tcpdump - unexpected response" )
+ return main.FALSE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ except Exception:
+ main.log.exception( self.name + ": Uncaught exception!" )
+ main.cleanup()
+ main.exit()
+
+ def stopTcpdump( self ):
+ """
+ pkills tcpdump"""
+ try:
+ self.handle.sendline( "sh sudo pkill tcpdump" )
+ self.handle.expect( "mininet>" )
+ self.handle.sendline( "" )
+ self.handle.expect( "mininet>" )
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+ except Exception:
+ main.log.exception( self.name + ": Uncaught exception!" )
+ main.cleanup()
+ main.exit()
+
+ def compareSwitches( self, topo, switchesJson ):
+ """
+ Compare mn and onos switches
+ topo: sts TestONTopology object
+ switchesJson: parsed json object from the onos devices api
+
+ This uses the sts TestONTopology object"""
+ # main.log.debug( "Switches_json string: ", switchesJson )
+ output = { "switches": [] }
+ # iterate through the MN topology and pull out switches and and port
+ # info
+ for switch in topo.graph.switches:
+ ports = []
+ for port in switch.ports.values():
+ ports.append( { 'of_port': port.port_no,
+ 'mac': str( port.hw_addr ).replace( '\'', '' ),
+ 'name': port.name } )
+ output[ 'switches' ].append( {
+ "name": switch.name,
+ "dpid": str( switch.dpid ).zfill( 16 ),
+ "ports": ports } )
+
+ # print "mn"
+ # print json.dumps( output,
+ # sort_keys=True,
+ # indent=4,
+ # separators=( ',', ': ' ) )
+ # print "onos"
+ # print json.dumps( switchesJson,
+ # sort_keys=True,
+ # indent=4,
+ # separators=( ',', ': ' ) )
+
+ # created sorted list of dpid's in MN and ONOS for comparison
+ mnDPIDs = []
+ for switch in output[ 'switches' ]:
+ mnDPIDs.append( switch[ 'dpid' ].lower() )
+ mnDPIDs.sort()
+ # print "List of Mininet switch DPID's"
+ # print mnDPIDs
+ if switchesJson == "": # if rest call fails
+ main.log.error(
+ self.name +
+ ".compare_switches(): Empty JSON object given from ONOS" )
+ return main.FALSE
+ onos = switchesJson
+ onosDPIDs = []
+ for switch in onos:
+ if switch[ 'available' ]:
+ onosDPIDs.append(
+ switch[ 'id' ].replace(
+ ":",
+ '' ).replace(
+ "of",
+ '' ).lower() )
+ # else:
+ # print "Switch is unavailable:"
+ # print switch
+ onosDPIDs.sort()
+ # print "List of ONOS switch DPID's"
+ # print onosDPIDs
+
+ if mnDPIDs != onosDPIDs:
+ switchResults = main.FALSE
+ main.log.report( "Switches in MN but not in ONOS:" )
+ list1 = [ switch for switch in mnDPIDs if switch not in onosDPIDs ]
+ main.log.report( str( list1 ) )
+ main.log.report( "Switches in ONOS but not in MN:" )
+ list2 = [ switch for switch in onosDPIDs if switch not in mnDPIDs ]
+ main.log.report( str( list2 ) )
+ else: # list of dpid's match in onos and mn
+ switchResults = main.TRUE
+ return switchResults
+
+ def comparePorts( self, topo, portsJson ):
+ """
+ Compare mn and onos ports
+ topo: sts TestONTopology object
+ portsJson: parsed json object from the onos ports api
+
+ Dependencies:
+ 1. This uses the sts TestONTopology object
+ 2. numpy - "sudo pip install numpy"
+
+ """
+ # FIXME: this does not look for extra ports in ONOS, only checks that
+ # ONOS has what is in MN
+ from numpy import uint64
+ portsResults = main.TRUE
+ output = { "switches": [] }
+ # iterate through the MN topology and pull out switches and and port
+ # info
+ for switch in topo.graph.switches:
+ ports = []
+ for port in switch.ports.values():
+ # print port.hw_addr.toStr( separator='' )
+ tmpPort = { 'of_port': port.port_no,
+ 'mac': str( port.hw_addr ).replace( '\'', '' ),
+ 'name': port.name,
+ 'enabled': port.enabled }
+
+ ports.append( tmpPort )
+ tmpSwitch = { 'name': switch.name,
+ 'dpid': str( switch.dpid ).zfill( 16 ),
+ 'ports': ports }
+
+ output[ 'switches' ].append( tmpSwitch )
+
+ # PORTS
+ for mnSwitch in output[ 'switches' ]:
+ mnPorts = []
+ onosPorts = []
+ switchResult = main.TRUE
+ for port in mnSwitch[ 'ports' ]:
+ if port[ 'enabled' ]:
+ mnPorts.append( port[ 'of_port' ] )
+ for onosSwitch in portsJson:
+ # print "Iterating through a new switch as seen by ONOS"
+ # print onosSwitch
+ if onosSwitch[ 'device' ][ 'available' ]:
+ if onosSwitch[ 'device' ][ 'id' ].replace(
+ ':',
+ '' ).replace(
+ "of",
+ '' ) == mnSwitch[ 'dpid' ]:
+ for port in onosSwitch[ 'ports' ]:
+ if port[ 'isEnabled' ]:
+ if port[ 'port' ] == 'local':
+ # onosPorts.append( 'local' )
+ onosPorts.append( long( uint64( -2 ) ) )
+ else:
+ onosPorts.append( int( port[ 'port' ] ) )
+ break
+ mnPorts.sort( key=float )
+ onosPorts.sort( key=float )
+ # print "\nPorts for Switch %s:" % ( mnSwitch[ 'name' ] )
+ # print "\tmn_ports[] = ", mnPorts
+ # print "\tonos_ports[] = ", onosPorts
+ mnPortsLog = mnPorts
+ onosPortsLog = onosPorts
+ mnPorts = [ x for x in mnPorts ]
+ onosPorts = [ x for x in onosPorts ]
+
+ # TODO: handle other reserved port numbers besides LOCAL
+ # NOTE: Reserved ports
+ # Local port: -2 in Openflow, ONOS shows 'local', we store as
+ # long( uint64( -2 ) )
+ for mnPort in mnPortsLog:
+ if mnPort in onosPorts:
+ # don't set results to true here as this is just one of
+ # many checks and it might override a failure
+ mnPorts.remove( mnPort )
+ onosPorts.remove( mnPort )
+ # NOTE: OVS reports this as down since there is no link
+ # So ignoring these for now
+ # TODO: Come up with a better way of handling these
+ if 65534 in mnPorts:
+ mnPorts.remove( 65534 )
+ if long( uint64( -2 ) ) in onosPorts:
+ onosPorts.remove( long( uint64( -2 ) ) )
+ if len( mnPorts ): # the ports of this switch don't match
+ switchResult = main.FALSE
+ main.log.warn( "Ports in MN but not ONOS: " + str( mnPorts ) )
+ if len( onosPorts ): # the ports of this switch don't match
+ switchResult = main.FALSE
+ main.log.warn(
+ "Ports in ONOS but not MN: " +
+ str( onosPorts ) )
+ if switchResult == main.FALSE:
+ main.log.report(
+ "The list of ports for switch %s(%s) does not match:" %
+ ( mnSwitch[ 'name' ], mnSwitch[ 'dpid' ] ) )
+ main.log.warn( "mn_ports[] = " + str( mnPortsLog ) )
+ main.log.warn( "onos_ports[] = " + str( onosPortsLog ) )
+ portsResults = portsResults and switchResult
+ return portsResults
+
+ def compareLinks( self, topo, linksJson ):
+ """
+ Compare mn and onos links
+ topo: sts TestONTopology object
+ linksJson: parsed json object from the onos links api
+
+ This uses the sts TestONTopology object"""
+ # FIXME: this does not look for extra links in ONOS, only checks that
+ # ONOS has what is in MN
+ output = { "switches": [] }
+ onos = linksJson
+ # iterate through the MN topology and pull out switches and and port
+ # info
+ for switch in topo.graph.switches:
+ # print "Iterating though switches as seen by Mininet"
+ # print switch
+ ports = []
+ for port in switch.ports.values():
+ # print port.hw_addr.toStr( separator='' )
+ ports.append( { 'of_port': port.port_no,
+ 'mac': str( port.hw_addr ).replace( '\'', '' ),
+ 'name': port.name } )
+ output[ 'switches' ].append( {
+ "name": switch.name,
+ "dpid": str( switch.dpid ).zfill( 16 ),
+ "ports": ports } )
+ # LINKS
+
+ mnLinks = [
+ link for link in topo.patch_panel.network_links if (
+ link.port1.enabled and link.port2.enabled ) ]
+ if 2 * len( mnLinks ) == len( onos ):
+ linkResults = main.TRUE
+ else:
+ linkResults = main.FALSE
+ main.log.report(
+ "Mininet has " + str( len( mnLinks ) ) +
+ " bidirectional links and ONOS has " +
+ str( len( onos ) ) + " unidirectional links" )
+
+ # iterate through MN links and check if an ONOS link exists in
+ # both directions
+ # NOTE: Will currently only show mn links as down if they are
+ # cut through STS. We can either do everything through STS or
+ # wait for upNetworkLinks and downNetworkLinks to be
+ # fully implemented.
+ for link in mnLinks:
+ # print "Link: %s" % link
+ # TODO: Find a more efficient search method
+ node1 = None
+ port1 = None
+ node2 = None
+ port2 = None
+ firstDir = main.FALSE
+ secondDir = main.FALSE
+ for switch in output[ 'switches' ]:
+ # print "Switch: %s" % switch[ 'name' ]
+ if switch[ 'name' ] == link.node1.name:
+ node1 = switch[ 'dpid' ]
+ for port in switch[ 'ports' ]:
+ if str( port[ 'name' ] ) == str( link.port1 ):
+ port1 = port[ 'of_port' ]
+ if node1 is not None and node2 is not None:
+ break
+ if switch[ 'name' ] == link.node2.name:
+ node2 = switch[ 'dpid' ]
+ for port in switch[ 'ports' ]:
+ if str( port[ 'name' ] ) == str( link.port2 ):
+ port2 = port[ 'of_port' ]
+ if node1 is not None and node2 is not None:
+ break
+
+ for onosLink in onos:
+ onosNode1 = onosLink[ 'src' ][ 'device' ].replace(
+ ":",
+ '' ).replace(
+ "of",
+ '' )
+ onosNode2 = onosLink[ 'dst' ][ 'device' ].replace(
+ ":",
+ '' ).replace(
+ "of",
+ '' )
+ onosPort1 = onosLink[ 'src' ][ 'port' ]
+ onosPort2 = onosLink[ 'dst' ][ 'port' ]
+
+ # check onos link from node1 to node2
+ if str( onosNode1 ) == str( node1 ) and str(
+ onosNode2 ) == str( node2 ):
+ if int( onosPort1 ) == int( port1 ) and int(
+ onosPort2 ) == int( port2 ):
+ firstDir = main.TRUE
+ else:
+ main.log.warn(
+ 'The port numbers do not match for ' +
+ str( link ) +
+ ' between ONOS and MN. When checking ONOS for ' +
+ 'link %s/%s -> %s/%s' %
+ ( node1,
+ port1,
+ node2,
+ port2 ) +
+ ' ONOS has the values %s/%s -> %s/%s' %
+ ( onosNode1,
+ onosPort1,
+ onosNode2,
+ onosPort2 ) )
+
+ # check onos link from node2 to node1
+ elif ( str( onosNode1 ) == str( node2 ) and
+ str( onosNode2 ) == str( node1 ) ):
+ if ( int( onosPort1 ) == int( port2 )
+ and int( onosPort2 ) == int( port1 ) ):
+ secondDir = main.TRUE
+ else:
+ main.log.warn(
+ 'The port numbers do not match for ' +
+ str( link ) +
+ ' between ONOS and MN. When checking ONOS for ' +
+ 'link %s/%s -> %s/%s' %
+ ( node2,
+ port2,
+ node1,
+ port1 ) +
+ ' ONOS has the values %s/%s -> %s/%s' %
+ ( onosNode2,
+ onosPort2,
+ onosNode1,
+ onosPort1 ) )
+ else: # this is not the link you're looking for
+ pass
+ if not firstDir:
+ main.log.report(
+ 'ONOS does not have the link %s/%s -> %s/%s' %
+ ( node1, port1, node2, port2 ) )
+ if not secondDir:
+ main.log.report(
+ 'ONOS does not have the link %s/%s -> %s/%s' %
+ ( node2, port2, node1, port1 ) )
+ linkResults = linkResults and firstDir and secondDir
+ return linkResults
+
+ def compareHosts( self, topo, hostsJson ):
+ """
+ Compare mn and onos Hosts.
+ Since Mininet hosts are quiet, ONOS will only know of them when they
+ speak. For this reason, we will only check that the hosts in ONOS
+ stores are in Mininet, and not vice versa.
+ topo: sts TestONTopology object
+ hostsJson: parsed json object from the onos hosts api
+
+ This uses the sts TestONTopology object"""
+ import json
+ hostResults = main.TRUE
+ hosts = []
+ # iterate through the MN topology and pull out hosts
+ for mnHost in topo.graph.hosts:
+ interfaces = []
+ for intf in mnHost.interfaces:
+ interfaces.append( {
+ "name": intf.name, # str
+ "ips": [ str( ip ) for ip in intf.ips ], # list of IPAddrs
+ # hw_addr is of type EthAddr, Not JSON serializable
+ "hw_addr": str( intf.hw_addr ) } )
+ hosts.append( {
+ "name": mnHost.name, # str
+ "interfaces": interfaces } ) # list
+ for onosHost in hostsJson:
+ onosMAC = onosHost[ 'mac' ].lower()
+ match = False
+ for mnHost in hosts:
+ for mnIntf in mnHost[ 'interfaces' ]:
+ if onosMAC == mnIntf[ 'hw_addr' ].lower() :
+ match = True
+ for ip in mnIntf[ 'ips' ]:
+ if ip in onosHost[ 'ips' ]:
+ pass # all is well
+ else:
+ # misssing ip
+ main.log.error( "ONOS host " + onosHost[ 'id' ]
+ + " has a different IP than " +
+ "the Mininet host." )
+ output = json.dumps(
+ onosHost,
+ sort_keys=True,
+ indent=4,
+ separators=( ',', ': ' ) )
+ main.log.info( output )
+ hostResults = main.FALSE
+ if not match:
+ hostResults = main.FALSE
+ main.log.error( "ONOS host " + onosHost[ 'id' ] + " has no " +
+ "corresponding Mininet host." )
+ output = json.dumps( onosHost,
+ sort_keys=True,
+ indent=4,
+ separators=( ',', ': ' ) )
+ main.log.info( output )
+ return hostResults
+
+ def getHosts( self ):
+ """
+ Returns a list of all hosts
+ Don't ask questions just use it"""
+ self.handle.sendline( "" )
+ self.handle.expect( "mininet>" )
+
+ self.handle.sendline( "py [ host.name for host in net.hosts ]" )
+ self.handle.expect( "mininet>" )
+
+ handlePy = self.handle.before
+ handlePy = handlePy.split( "]\r\n", 1 )[ 1 ]
+ handlePy = handlePy.rstrip()
+
+ self.handle.sendline( "" )
+ self.handle.expect( "mininet>" )
+
+ hostStr = handlePy.replace( "]", "" )
+ hostStr = hostStr.replace( "'", "" )
+ hostStr = hostStr.replace( "[", "" )
+ hostList = hostStr.split( "," )
+
+ return hostList
+
+ def update( self ):
+ """
+ updates the port address and status information for
+ each port in mn"""
+ # TODO: Add error checking. currently the mininet command has no output
+ main.log.info( "Updating MN port information" )
+ try:
+ self.handle.sendline( "" )
+ self.handle.expect( "mininet>" )
+
+ self.handle.sendline( "update" )
+ self.handle.expect( "update" )
+ self.handle.expect( "mininet>" )
+
+ self.handle.sendline( "" )
+ self.handle.expect( "mininet>" )
+
+ return main.TRUE
+ except pexpect.EOF:
+ main.log.error( self.name + ": EOF exception found" )
+ main.log.error( self.name + ": " + self.handle.before )
+ main.cleanup()
+ main.exit()
+
+if __name__ != "__main__":
+ import sys
+ sys.modules[ __name__ ] = MininetCliDriver()
diff --git a/TestON/tests/PingallExample/PingallExample.params b/TestON/tests/PingallExample/PingallExample.params
index 1e4cfc1..6d23beb 100644
--- a/TestON/tests/PingallExample/PingallExample.params
+++ b/TestON/tests/PingallExample/PingallExample.params
@@ -1,12 +1,61 @@
<PARAMS>
- <testcases>1,2,3</testcases>
+ <testcases>1,2,25,26</testcases>
<ENV>
- <cellName>SingleHA</cellName>
+ <cellName>test1</cellName>
</ENV>
- <Git>xe</Git>
+ <Git>False</Git>
<CTRL>
- <ip1>10.128.30.11</ip1>
+ <ip1>10.128.40.70</ip1>
<port1>6633</port1>
</CTRL>
+
+ <VPING>
+ <source1V1>
+ <vhost>h1</vhost>
+ <vintf>eth0</vintf>
+ </source1V1>
+ <source1V2>
+ <vhost>h3</vhost>
+ <vintf>eth0</vintf>
+ </source1V2>
+ <source1Vnone>
+ <vhost>h4</vhost>
+ <vintf>eth0</vintf>
+ </source1Vnone>
+ <source1V1Int>
+ <vhost>h6</vhost>
+ <vintf>eth0</vintf>
+ </source1V1Int>
+
+ <target1V1>
+ <vhost>h7</vhost>
+ <vintf>eth0</vintf>
+ </target1V1>
+ <target2V1>
+ <vhost>h8</vhost>
+ <vintf>eth0</vintf>
+ </target2V1>
+ <target1V2>
+ <vhost>h9</vhost>
+ <vintf>eth0</vintf>
+ </target1V2>
+
+ <target1Vnone>
+ <vhost>h11</vhost>
+ <vintf>eth0</vintf>
+ </target1Vnone>
+ <target1V1Int>
+ <vhost>h14</vhost>
+ <vintf>eth0</vintf>
+ </target1V1Int>
+
+ </VPING>
+ <VTAGS>
+ <tag1>100</tag1>
+ <tag2>200</tag2>
+ <tag3>300</tag3>
+ <tag4>400</tag4>
+ </VTAGS>
+
</PARAMS>
diff --git a/TestON/tests/PingallExample/PingallExample.py b/TestON/tests/PingallExample/PingallExample.py
index c03b0f1..c8d02a8 100644
--- a/TestON/tests/PingallExample/PingallExample.py
+++ b/TestON/tests/PingallExample/PingallExample.py
@@ -163,9 +163,176 @@
main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
# uninstall onos-app-fwd
- main.step( "Deactivate reactive forwarding app" )
- main.ONOScli1.deactivateApp( "org.onosproject.fwd" )
+ # main.step( "Deactivate reactive forwarding app" )
+ #main.ONOScli1.deactivateApp( "org.onosproject.fwd" )
utilities.assert_equals( expect=main.TRUE, actual=pingResult,
onpass="All hosts are reachable",
onfail="Some pings failed" )
+
+ def CASE25( self, main ):
+ """
+ Activate fwd app
+ Ping selected hosts
+ Assign selected hosts vlans
+ Ping to test vlans
+ Deactivate fwd app
+ """
+ import time
+
+ main.log.report( "This testcase creates different vlan hosts " +
+ " and verifies that only hosts that belong " +
+ " to the same vlan can ping each others")
+ main.log.report( "___________________________________________________" )
+ main.case( "Creating vlans and performing ping between hosts" )
+
+ main.step( "Activate reactive forwarding app" )
+ main.ONOScli1.activateApp( "org.onosproject.fwd" )
+
+ main.step( "Activate reactive forwarding app" )
+ main.ONOScli1.activateApp( "org.onosproject.fwd" )
+
+ main.step( "Verify host pinging in Mininet before creating vlans" )
+ source1V1 = main.params[ 'VPING' ][ 'source1V1' ]['vhost']
+ source1V2 = main.params[ 'VPING' ][ 'source1V2' ]['vhost']
+ source1Vnone = main.params[ 'VPING' ][ 'source1Vnone' ]['vhost']
+ target1V1 = main.params[ 'VPING' ][ 'target1V1' ]['vhost']
+ target2V1 = main.params[ 'VPING' ][ 'target2V1' ]['vhost']
+ target1V2 = main.params[ 'VPING' ][ 'target1V2' ]['vhost']
+ target1Vnone = main.params[ 'VPING' ][ 'target1Vnone' ]['vhost']
+
+ targetIP1V1 = main.Mininet1.getIPAddress(target1V1)
+ targetIP2V1 = main.Mininet1.getIPAddress(target2V1)
+ targetIP1V2 = main.Mininet1.getIPAddress(target1V2)
+ targetIP1Vnone = main.Mininet1.getIPAddress(target1Vnone)
+
+ for i in range(0,2):
+ ping1V1 = main.Mininet1.pingHost( src = source1V1, target = targetIP1V1)
+ ping2V1 = main.Mininet1.pingHost( src = source1V1, target = targetIP2V1)
+ ping1V2 = main.Mininet1.pingHost( src = source1V2, target = targetIP1V2)
+ pingV1V2 = main.Mininet1.pingHost( src = source1V1, target = targetIP1V2)
+ pingV2V1 = main.Mininet1.pingHost( src = source1V2, target = targetIP1V1)
+ pingV1Vnone = main.Mininet1.pingHost ( src = source1V1, target = targetIP1Vnone)
+ pingVnoneV2 = main.Mininet1.pingHost ( src = source1Vnone, target = targetIP1V2)
+
+ pingResultBeforeVlan = ping1V1 and ping2V1 and ping1V2 and pingV1V2 \
+ and pingV2V1 and pingV1Vnone and pingVnoneV2
+
+
+ if pingResultBeforeVlan == main.TRUE:
+ main.log.report("Ping succeeded before vlans are created")
+
+ main.step( "Create vlan hosts in mininet" )
+ v1Tag = main.params[ 'VTAGS' ][ 'tag1' ]
+ v2Tag = main.params[ 'VTAGS' ][ 'tag2' ]
+ intfSource1V1 = source1V1 + "-" + main.params[ 'VPING' ][ 'source1V1' ][ 'vintf' ]
+ intfSource1V2 = source1V2 + "-" + main.params[ 'VPING' ][ 'source1V2' ][ 'vintf' ]
+ intfTarget1V1 = target1V1 + "-" + main.params[ 'VPING' ][ 'target1V1' ][ 'vintf' ]
+ intfTarget2V1 = target2V1 + "-" + main.params[ 'VPING' ][ 'target2V1' ][ 'vintf' ]
+ intfTarget1V2 = target1V2 + "-" + main.params[ 'VPING' ][ 'target1V2' ][ 'vintf' ]
+
+ main.Mininet1.assignVLAN(source1V1, intfSource1V1, v1Tag)
+ main.Mininet1.assignVLAN(target1V1, intfTarget1V1, v1Tag)
+ main.Mininet1.assignVLAN(target2V1, intfTarget2V1, v1Tag)
+ main.Mininet1.assignVLAN(source1V2, intfSource1V2, v2Tag)
+ main.Mininet1.assignVLAN(target1V2, intfTarget1V2, v2Tag)
+
+ main.step( "Verify host pinging in Mininet after creating vlans" )
+
+ ping1V1 = main.Mininet1.pingHost( src = source1V1, target = targetIP1V1)
+ ping2V1 = main.Mininet1.pingHost( src = source1V1, target = targetIP2V1)
+ ping1V2 = main.Mininet1.pingHost( src = source1V2, target = targetIP1V2)
+ pingV1V2 = main.Mininet1.pingHost( src = source1V1, target = targetIP1V2)
+ pingV2V1 = main.Mininet1.pingHost( src = source1V2, target = targetIP1V1)
+ pingV1Vnone = main.Mininet1.pingHost ( src = source1V1, target = targetIP1Vnone)
+ pingVnoneV2 = main.Mininet1.pingHost ( src = source1Vnone, target = targetIP1V2)
+
+
+ pingExpectedTrue = ping1V1 and ping2V1 and ping1V2
+ pingResultAfterVlan = pingExpectedTrue and not pingV1V2 \
+ and not pingV2V1 and not pingV1Vnone and not pingVnoneV2
+
+ if pingResultAfterVlan == main.TRUE:
+ main.log.report("Ping results are as expected after vlans are created")
+ testCaseResult = main.TRUE
+ if pingResultAfterVlan == main.FALSE:
+ main.log.report("Ping results are not expected after vlans are created")
+ testCaseResult = main.FALSE
+
+ case25Result = testCaseResult
+ utilities.assert_equals( expect=main.TRUE, actual=case25Result,
+ onpass="Vlan verification is successfull",
+ onfail="Vlan verification failed" )
+ if pingResultBeforeVlan == main.FALSE:
+ main.log.report("Ping failed before vlans are created")
+ case25Result = main.FALSE
+ utilities.assert_equals( expect=main.TRUE, actual=case25Result,
+ onpass="Test case 25 can be verified",
+ onfail="Test case 25 cannot be verified because " +
+ "there are ping failures before assigning host vlans" )
+
+ main.step( "Deactivate reactive forwarding app" )
+ main.ONOScli1.deactivateApp( "org.onosproject.fwd" )
+
+ def CASE26( self, main ):
+ """
+ This test case verifies that hosts belonging to the same vlan,
+ can ping each other with proactive forwarding (after adding host intent):
+ - Deactivate app fwd
+ - Assign vlan tag to selected hosts
+ - Add host intent between the selected hosts
+ - Ping the selected hosts to verify proactive forwarding with vlan hosts
+ """
+ import time
+
+ main.log.report( "This testcase creates vlan hosts, " +
+ " add host intent, " +
+ " then ping the hosts")
+ main.log.report( "___________________________________________________" )
+ main.case( "Creating vlans and performing ping between hosts" )
+
+ main.step( "Deactivate reactive forwarding app" )
+ main.ONOScli1.deactivateApp( "org.onosproject.fwd" )
+
+ main.step( "Assign vlan hosts in mininet" )
+
+ source1V1 = main.params[ 'VPING' ][ 'source1V1Int' ]['vhost']
+ target1V1 = main.params[ 'VPING' ][ 'target1V1Int' ]['vhost']
+
+ intfSource1V1 = source1V1 + "-" + main.params[ 'VPING' ][ 'source1V1Int' ][ 'vintf' ]
+ intfTarget1V1 = target1V1 + "-" + main.params[ 'VPING' ][ 'target1V1Int' ][ 'vintf' ]
+
+ vTag = main.params[ 'VTAGS' ][ 'tag3' ]
+
+ main.Mininet1.assignVLAN(source1V1, intfSource1V1, vTag)
+ main.Mininet1.assignVLAN(target1V1, intfTarget1V1, vTag)
+
+ main.step( "Add host intent" )
+ mac1 = main.Mininet1.getMacAddress(source1V1)
+ mac2 = main.Mininet1.getMacAddress(target1V1)
+ id1 = mac1 + "/" + vTag
+ id2 = mac2 + "/" + vTag
+ hthIntentResult = main.ONOScli1.addHostIntent( id1 , id2 )
+ if hthIntentResult:
+ main.step( "Ping hosts after installing host intent" )
+ #time.sleep(10)
+ targetIPV1 = main.Mininet1.getIPAddress(target1V1)
+ for i in range(0,3):
+ ping1V1 = main.Mininet1.pingHost( src = source1V1, target = targetIPV1)
+
+ if ping1V1 == main.TRUE:
+ main.log.report(" Vlan hosts can ping each other successfully "+
+ " after add host intent.")
+
+ if ping1V1 == main.FALSE:
+ main.log.report("Vlan hosts failed to ping each other "+
+ " after add host intent. ")
+
+ else:
+ main.log.report(" add host intent failed between vlan hosts ")
+
+ case26Result = hthIntentResult and ping1V1
+ utilities.assert_equals( expect=main.TRUE, actual=case26Result,
+ onpass="Test case 26 is successfull",
+ onfail="Test case 26 has failed" )
+
diff --git a/TestON/tests/PingallExample/PingallExample.topo b/TestON/tests/PingallExample/PingallExample.topo
index 3eda540..8a9f99f 100644
--- a/TestON/tests/PingallExample/PingallExample.topo
+++ b/TestON/tests/PingallExample/PingallExample.topo
@@ -2,16 +2,18 @@
<COMPONENT>
<ONOSbench>
- <host>10.128.30.10</host>
+ <host>10.128.40.70</host>
<user>admin</user>
<password></password>
<type>OnosDriver</type>
<connect_order>1</connect_order>
- <COMPONENTS> </COMPONENTS>
+ <COMPONENTS>
+ <home>~/ONOS</home>
+ </COMPONENTS>
</ONOSbench>
<ONOScli1>
- <host>10.128.30.10</host>
+ <host>10.128.40.70</host>
<user>admin</user>
<password></password>
<type>OnosCliDriver</type>
@@ -20,7 +22,7 @@
</ONOScli1>
<ONOS1>
- <host>10.128.30.11</host>
+ <host>10.128.40.70</host>
<user>admin</user>
<password></password>
<type>OnosDriver</type>
@@ -29,7 +31,7 @@
</ONOS1>
<Mininet1>
- <host>10.128.30.9</host>
+ <host>10.128.40.70</host>
<user>admin</user>
<password></password>
<type>MininetCliDriver</type>
diff --git a/TestON/tests/PingallExample/PingallExample_orig.py b/TestON/tests/PingallExample/PingallExample_orig.py
new file mode 100644
index 0000000..c03b0f1
--- /dev/null
+++ b/TestON/tests/PingallExample/PingallExample_orig.py
@@ -0,0 +1,171 @@
+"""
+Description: This test is an example of a simple single node ONOS test
+
+List of test cases:
+CASE1: Compile ONOS and push it to the test machine
+CASE2: Assign mastership to controller
+CASE3: Pingall
+"""
+class PingallExample:
+
+ def __init__( self ):
+ self.default = ''
+
+ def CASE1( self, main ):
+ """
+ CASE1 is to compile ONOS and push it to the test machines
+
+ Startup sequence:
+ git pull
+ mvn clean install
+ onos-package
+ cell <name>
+ onos-verify-cell
+ onos-install -f
+ onos-wait-for-start
+ """
+ desc = "ONOS Single node cluster restart HA test - initialization"
+ main.log.report( desc )
+ main.case( "Setting up test environment" )
+
+ # load some vairables from the params file
+ PULLCODE = False
+ if main.params[ 'Git' ] == 'True':
+ PULLCODE = True
+ cellName = main.params[ 'ENV' ][ 'cellName' ]
+
+ ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
+
+ main.step( "Applying cell variable to environment" )
+ cellResult = main.ONOSbench.setCell( cellName )
+ verifyResult = main.ONOSbench.verifyCell()
+
+ main.log.report( "Uninstalling ONOS" )
+ main.ONOSbench.onosUninstall( ONOS1Ip )
+
+ cleanInstallResult = main.TRUE
+ gitPullResult = main.TRUE
+
+ main.step( "Compiling the latest version of ONOS" )
+ if PULLCODE:
+ main.step( "Git checkout and pull master" )
+ main.ONOSbench.gitCheckout( "master" )
+ gitPullResult = main.ONOSbench.gitPull()
+
+ main.step( "Using mvn clean & install" )
+ cleanInstallResult = main.TRUE
+ if gitPullResult == main.TRUE:
+ cleanInstallResult = main.ONOSbench.cleanInstall()
+ else:
+ main.log.warn( "Did not pull new code so skipping mvn " +
+ "clean install" )
+ main.ONOSbench.getVersion( report=True )
+
+ cellResult = main.ONOSbench.setCell( cellName )
+ verifyResult = main.ONOSbench.verifyCell()
+ main.step( "Creating ONOS package" )
+ packageResult = main.ONOSbench.onosPackage()
+
+ main.step( "Installing ONOS package" )
+ onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
+ node=ONOS1Ip )
+
+ main.step( "Checking if ONOS is up yet" )
+ for i in range( 2 ):
+ onos1Isup = main.ONOSbench.isup( ONOS1Ip )
+ if onos1Isup:
+ break
+ if not onos1Isup:
+ main.log.report( "ONOS1 didn't start!" )
+
+ # TODO: if it becomes an issue, we can retry this step a few times
+
+ cliResult = main.ONOScli1.startOnosCli( ONOS1Ip )
+
+ case1Result = ( cleanInstallResult and packageResult and
+ cellResult and verifyResult and
+ onos1InstallResult and
+ onos1Isup and cliResult )
+
+ utilities.assert_equals( expect=main.TRUE, actual=case1Result,
+ onpass="Test startup successful",
+ onfail="Test startup NOT successful" )
+
+ if case1Result == main.FALSE:
+ main.cleanup()
+ main.exit()
+
+ # Starting the mininet using the old way
+ main.step( "Starting Mininet ..." )
+ netIsUp = main.Mininet1.startNet()
+ if netIsUp:
+ main.log.info("Mininet CLI is up")
+ else:
+ main.log.info("Mininet CLI is down")
+
+ def CASE2( self, main ):
+ """
+ Assign mastership to controller
+ """
+ import re
+
+ main.log.report( "Assigning switches to controller" )
+ main.case( "Assigning Controller" )
+ main.step( "Assign switches to controller" )
+
+ ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
+ ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
+
+ for i in range( 1, 14 ):
+ main.Mininet1.assignSwController(
+ sw=str( i ),
+ ip1=ONOS1Ip,
+ port1=ONOS1Port )
+
+ mastershipCheck = main.TRUE
+ for i in range( 1, 14 ):
+ response = main.Mininet1.getSwController( "s" + str( i ) )
+ try:
+ main.log.info( str( response ) )
+ except Exception:
+ main.log.info( repr( response ) )
+ if re.search( "tcp:" + ONOS1Ip, response ):
+ mastershipCheck = mastershipCheck and main.TRUE
+ else:
+ mastershipCheck = main.FALSE
+ if mastershipCheck == main.TRUE:
+ main.log.report( "Switch mastership assigned correctly" )
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=mastershipCheck,
+ onpass="Switch mastership assigned correctly",
+ onfail="Switches not assigned correctly to controllers" )
+
+ def CASE3( self, main ):
+ """
+ Install forwarding app, Pingall and unistall the app
+ """
+ import time
+
+ main.log.report( "Run Pingall" )
+ main.case( "Run Pingall" )
+
+ # install onos-app-fwd
+ main.step( "Activate reactive forwarding app" )
+ main.ONOScli1.activateApp( "org.onosproject.fwd" )
+
+ # REACTIVE FWD test
+ main.step( "Run the pingall command in Mininet" )
+ pingResult = main.FALSE
+ time1 = time.time()
+ pingResult = main.Mininet1.pingall()
+ time2 = time.time()
+ main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
+
+ # uninstall onos-app-fwd
+ main.step( "Deactivate reactive forwarding app" )
+ main.ONOScli1.deactivateApp( "org.onosproject.fwd" )
+
+ utilities.assert_equals( expect=main.TRUE, actual=pingResult,
+ onpass="All hosts are reachable",
+ onfail="Some pings failed" )
diff --git a/TestON/tests/SingleFunc/MultiFunc.topo b/TestON/tests/SingleFunc/MultiFunc.topo
new file mode 100755
index 0000000..f8c2eab
--- /dev/null
+++ b/TestON/tests/SingleFunc/MultiFunc.topo
@@ -0,0 +1,57 @@
+<TOPOLOGY>
+ <COMPONENT>
+
+ <ONOSbench>
+ <host>10.128.10.20</host>
+ <user>admin</user>
+ <password>onos_test</password>
+ <type>OnosDriver</type>
+ <connect_order>1</connect_order>
+ <COMPONENTS> </COMPONENTS>
+ </ONOSbench>
+
+ <ONOScli1>
+ <host>10.128.10.21</host>
+ <user>sdn</user>
+ <password>sdn</password>
+ <type>OnosCliDriver</type>
+ <connect_order>2</connect_order>
+ <COMPONENTS> </COMPONENTS>
+ </ONOScli1>
+
+ <ONOScli2>
+ <host>10.128.10.22</host>
+ <user>admin</user>
+ <password>onos_test</password>
+ <type>OnosCliDriver</type>
+ <connect_order>3</connect_order>
+ <COMPONENTS> </COMPONENTS>
+ </ONOScli2>
+
+ <ONOScli3>
+ <host>10.128.10.23</host>
+ <user>admin</user>
+ <password>onos_test</password>
+ <type>OnosCliDriver</type>
+ <connect_order>4</connect_order>
+ <COMPONENTS> </COMPONENTS>
+ </ONOScli3>
+
+
+ <Mininet1>
+ <host>10.128.10.11</host>
+ <user>admin</user>
+ <password>onos_test</password>
+ <type>MininetCliDriver</type>
+ <connect_order>5</connect_order>
+ <COMPONENTS>
+ #Specify the Option for mininet
+ <arg1> --custom ~/mininet/custom/topo-HA.py </arg1>
+ <arg2> --topo mytopo </arg2>
+ <arg3> --switch ovs,protocols=OpenFlow13 </arg3>
+ <controller> remote </controller>
+ </COMPONENTS>
+ </Mininet1>
+
+ </COMPONENT>
+</TOPOLOGY>
diff --git a/TestON/tests/SingleFunc/SingleFunc.params b/TestON/tests/SingleFunc/SingleFunc.params
new file mode 100755
index 0000000..58427cc
--- /dev/null
+++ b/TestON/tests/SingleFunc/SingleFunc.params
@@ -0,0 +1,20 @@
+<PARAMS>
+
+ <testcases>10,11</testcases>
+ <ENV>
+ <cellName>single_func</cellName>
+ </ENV>
+ <GIT>
+ <pull>False</pull>
+ <branch>master</branch>
+ </GIT>
+ <CTRL>
+ <ip1>10.128.10.21</ip1>
+ <port1>6633</port1>
+ </CTRL>
+ <MININET>
+ <switch>7</switch>
+ <topo>~/mininet/custom/newFuncTopo.py</topo>
+ </MININET>
+
+</PARAMS>
diff --git a/TestON/tests/SingleFunc/SingleFunc.py b/TestON/tests/SingleFunc/SingleFunc.py
new file mode 100644
index 0000000..b971d8c
--- /dev/null
+++ b/TestON/tests/SingleFunc/SingleFunc.py
@@ -0,0 +1,166 @@
+
+# Testing the basic functionality of ONOS Next
+# For sanity and driver functionality excercises only.
+
+import time
+import json
+
+time.sleep( 1 )
+
+class SingleFunc:
+
+ def __init__( self ):
+ self.default = ''
+
+ def CASE10( self, main ):
+ import time
+ import os
+ """
+ Startup sequence:
+ cell <name>
+ onos-verify-cell
+ onos-remove-raft-log
+ git pull
+ mvn clean install
+ onos-package
+ onos-install -f
+ onos-wait-for-start
+ """
+ #Local variables
+ cellName = main.params[ 'ENV' ][ 'cellName' ]
+ main.ONOS1ip = os.environ[ 'OC1' ]
+ main.ONOS1port = main.params[ 'CTRL' ][ 'port1' ]
+ main.numSwitch = int( main.params[ 'MININET' ][ 'switch' ] )
+ gitBranch = main.params[ 'GIT' ][ 'branch' ]
+ topology = main.params[ 'MININET' ][ 'topo' ]
+ PULLCODE = False
+ if main.params[ 'GIT' ][ 'pull' ] == 'True':
+ PULLCODE = True
+ main.case( "Setting up test environment" )
+
+ main.step( "Apply cell to environment" )
+ cellResult = main.ONOSbench.setCell( cellName )
+ verifyResult = main.ONOSbench.verifyCell()
+ stepResult = cellResult and verifyResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=stepResult,
+ onpass="Successfully applied cell to " + \
+ "environment",
+ onfail="Failed to apply cell to environment " )
+ """main.step( "Removing raft logs" )
+ removeRaftResult = main.ONOSbench.onosRemoveRaftLogs()
+ stepResult = removeRaftResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=stepResult,
+ onpass="Successfully removed raft logs",
+ onfail="Failed to remove raft logs" )
+ """
+ if PULLCODE:
+ main.step( "Git checkout and pull " + gitBranch )
+ main.ONOSbench.gitCheckout( gitBranch )
+ gitPullResult = main.ONOSbench.gitPull()
+ if gitPullResult == main.ERROR:
+ main.log.error( "Error pulling git branch" )
+ main.step( "Using mvn clean & install" )
+ cleanInstallResult = main.ONOSbench.cleanInstall()
+ stepResult = cleanInstallResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=stepResult,
+ onpass="Successfully compiled latest ONOS",
+ onfail="Failed to compile latest ONOS" )
+ else:
+ main.log.warn( "Did not pull new code so skipping mvn " +
+ "clean install" )
+
+ main.step( "Creating ONOS package" )
+ packageResult = main.ONOSbench.onosPackage()
+ stepResult = packageResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=stepResult,
+ onpass="Successfully created ONOS package",
+ onfail="Failed to create ONOS package" )
+
+ main.step( "Uninstalling ONOS package" )
+ onosUninstallResult = main.ONOSbench.onosUninstall(
+ nodeIp=main.ONOS1ip )
+ stepResult = onosUninstallResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=stepResult,
+ onpass="Successfully uninstalled ONOS package",
+ onfail="Failed to uninstall ONOS package" )
+ time.sleep( 5 )
+ main.step( "Installing ONOS package" )
+ onosInstallResult = main.ONOSbench.onosInstall( node=main.ONOS1ip )
+ stepResult = onosInstallResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=stepResult,
+ onpass="Successfully installed ONOS package",
+ onfail="Failed to install ONOS package" )
+
+ main.step( "Starting ONOS service" )
+ stopResult = main.TRUE
+ startResult = main.TRUE
+ onosIsUp = main.ONOSbench.isup()
+ if onosIsUp == main.TRUE:
+ main.log.report( "ONOS instance is up and ready" )
+ else:
+ main.log.report( "ONOS instance may not be up, stop and " +
+ "start ONOS again " )
+ stopResult = main.ONOSbench.onosStop( main.ONOS1ip )
+ startResult = main.ONOSbench.onosStart( main.ONOS1ip )
+ stepResult = onosIsUp and stopResult and startResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=stepResult,
+ onpass="ONOS service is ready",
+ onfail="ONOS service did not start properly" )
+
+ main.step( "Starting Mininet Topology" )
+ topoResult = main.Mininet1.startNet( topoFile=topology )
+ stepResult = topoResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=stepResult,
+ onpass="Successfully loaded topology",
+ onfail="Failed to load topology" )
+ # Exit if topology did not load properly
+ if not topoResult:
+ main.cleanup()
+ main.exit()
+
+ main.step( "Start ONOS cli" )
+ cliResult = main.ONOScli1.startOnosCli( ONOSIp=main.ONOS1ip )
+ stepResult = cliResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=stepResult,
+ onpass="Successfully start ONOS cli",
+ onfail="Failed to start ONOS cli" )
+
+ def CASE11( self, main ):
+ """
+ Assign mastership to controllers
+ """
+ import re
+ main.log.report( "Assigning switches to controllers" )
+ main.log.case( "Assigning swithes to controllers" )
+
+ main.step( "Assigning switches to controllers" )
+ assignResult = main.TRUE
+ for i in range( 1, ( main.numSwitch + 1 ) ):
+ main.Mininet1.assignSwController( sw=str( i ),
+ count=1,
+ ip1=main.ONOS1ip,
+ port1=main.ONOS1port )
+ for i in range( 1, ( main.numSwitch + 1 ) ):
+ response = main.Mininet1.getSwController( "s" + str( i ) )
+ print( "Response is " + str( response ) )
+ if re.search( "tcp:" + main.ONOS1ip, response ):
+ assignResult = assignResult and main.TRUE
+ else:
+ assignResult = main.FALSE
+ stepResult = assignResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=stepResult,
+ onpass="Successfully assigned switches" +
+ "to controller",
+ onfail="Failed to assign switches to " +
+ "controller" )
+
diff --git a/TestON/tests/SingleFunc/SingleFunc.topo b/TestON/tests/SingleFunc/SingleFunc.topo
new file mode 100755
index 0000000..d92bb7a
--- /dev/null
+++ b/TestON/tests/SingleFunc/SingleFunc.topo
@@ -0,0 +1,52 @@
+<TOPOLOGY>
+ <COMPONENT>
+
+ <ONOSbench>
+ <host>10.128.10.20</host>
+ <user>admin</user>
+ <password>onos_test</password>
+ <type>OnosDriver</type>
+ <connect_order>1</connect_order>
+ <COMPONENTS>
+ <home>~/ONOS</home>
+ </COMPONENTS>
+ </ONOSbench>
+
+ <ONOScli1>
+ <host>10.128.10.20</host>
+ <user>admin</user>
+ <password>onos_test</password>
+ <type>OnosCliDriver</type>
+ <connect_order>2</connect_order>
+ <COMPONENTS> </COMPONENTS>
+ </ONOScli1>
+
+ <ONOScli2>
+ <host>10.128.10.20</host>
+ <user>admin</user>
+ <password>onos_test</password>
+ <type>OnosCliDriver</type>
+ <connect_order>3</connect_order>
+ <COMPONENTS> </COMPONENTS>
+ </ONOScli2>
+
+ <ONOScli3>
+ <host>10.128.10.20</host>
+ <user>admin</user>
+ <password>onos_test</password>
+ <type>OnosCliDriver</type>
+ <connect_order>4</connect_order>
+ <COMPONENTS> </COMPONENTS>
+ </ONOScli3>
+
+ <Mininet1>
+ <host>10.128.10.20</host>
+ <user>admin</user>
+ <password>onos_test</password>
+ <type>MininetCliDriver</type>
+ <connect_order>5</connect_order>
+ <COMPONENTS> </COMPONENTS>
+ </Mininet1>
+
+ </COMPONENT>
+</TOPOLOGY>
diff --git a/TestON/tests/SingleFunc/SingleFunc2.py b/TestON/tests/SingleFunc/SingleFunc2.py
new file mode 100644
index 0000000..af88686
--- /dev/null
+++ b/TestON/tests/SingleFunc/SingleFunc2.py
@@ -0,0 +1,661 @@
+
+# Testing the basic functionality of ONOS Next
+# For sanity and driver functionality excercises only.
+
+import time
+# import sys
+# import os
+# import re
+import json
+
+time.sleep( 1 )
+
+class IpOptical:
+
+ def __init__( self ):
+ self.default = ''
+
+ def CASE1( self, main ):
+ import time
+ """
+ Startup sequence:
+ cell <name>
+ onos-verify-cell
+ onos-remove-raft-log
+ git pull
+ mvn clean install
+ onos-package
+ onos-install -f
+ onos-wait-for-start
+ """
+ cellName = main.params[ 'ENV' ][ 'cellName' ]
+ ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
+
+ main.case( "Setting up test environment" )
+ main.log.report(
+ "This testcase is testing setting up test environment" )
+ main.log.report( "__________________________________" )
+
+ main.step( "Applying cell variable to environment" )
+ cellResult = main.ONOSbench.setCell( cellName )
+ verifyResult = main.ONOSbench.verifyCell()
+
+ main.step( "Removing raft logs before a clen installation of ONOS" )
+ main.ONOSbench.onosRemoveRaftLogs()
+
+ main.step( "Git checkout and get version" )
+ #main.ONOSbench.gitCheckout( "master" )
+ gitPullResult = main.ONOSbench.gitPull()
+ main.log.info( "git_pull_result = " + str( gitPullResult ))
+ main.ONOSbench.getVersion( report=True )
+
+ if gitPullResult == 1:
+ main.step( "Using mvn clean & install" )
+ main.ONOSbench.cleanInstall()
+ elif gitPullResult == 0:
+ main.log.report(
+ "Git Pull Failed, look into logs for detailed reason" )
+ main.cleanup()
+ main.exit()
+
+ main.step( "Creating ONOS package" )
+ packageResult = main.ONOSbench.onosPackage()
+
+ main.step( "Uninstalling ONOS package" )
+ ONOSip1 = main.params[ 'CTRL' ][ 'ip1' ]
+ onosUninstallResult = main.ONOSbench.onosUninstall( nodeIp = ONOSip1)
+ if onosUninstallResult:
+ main.log.report( "Uninstalling ONOS package successful" )
+ else:
+ main.log.report( "Uninstalled ONOS package unsucessful" )
+ time.sleep( 5 )
+ main.step( "Installing ONOS package" )
+ onosInstallResult = main.ONOSbench.onosInstall( node = ONOSip1 )
+ if onosInstallResult == main.TRUE:
+ main.log.report( "Installing ONOS package successful" )
+ else:
+ main.log.report( "Installing ONOS package failed" )
+
+ onos1Isup = main.ONOSbench.isup()
+ if onos1Isup == main.TRUE:
+ main.log.report( "ONOS instance is up and ready" )
+ else:
+ main.log.report( "ONOS instance may not be up" )
+
+ main.step( "Starting ONOS service" )
+ startResult = main.ONOSbench.onosStart( ONOS1Ip )
+
+ main.ONOS2.startOnosCli( ONOSIp=main.params[ 'CTRL' ][ 'ip1' ] )
+ main.step( "Starting Mininet CLI..." )
+
+ case1Result = ( packageResult and
+ cellResult and verifyResult
+ and onosInstallResult and
+ onos1Isup and startResult )
+ utilities.assert_equals( expect=main.TRUE, actual=case1Result,
+ onpass="Test startup successful",
+ onfail="Test startup NOT successful" )
+
+ def CASE20( self ):
+ """
+ Exit from mininet cli
+ reinstall ONOS
+ """
+ import time
+ cellName = main.params[ 'ENV' ][ 'cellName' ]
+ ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
+
+ main.log.report( "This testcase exits the mininet cli and reinstalls" +
+ "ONOS to switch over to Packet Optical topology" )
+ main.log.report( "_____________________________________________" )
+ main.case( "Disconnecting mininet and restarting ONOS" )
+
+ main.step( "Disconnecting mininet and restarting ONOS" )
+ step1Result = main.TRUE
+ mininetDisconnect = main.Mininet1.disconnect()
+ print "mininetDisconnect = ", mininetDisconnect
+ step1Result = mininetDisconnect
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step1Result,
+ onpass="Mininet disconnect successfully",
+ onfail="Mininet failed to disconnect")
+ """
+ main.step( "Removing raft logs before a clean installation of ONOS" )
+ step2Result = main.TRUE
+ removeRaftLogsResult = main.ONOSbench.onosRemoveRaftLogs()
+ step2Result = removeRaftLogsResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step2Result,
+ onpass="Raft logs removed successfully",
+ onfail="Failed to remove raft logs")
+ """
+ main.step( "Applying cell variable to environment" )
+ step3Result = main.TRUE
+ setCellResult = main.ONOSbench.setCell( cellName )
+ verifyCellResult = main.ONOSbench.verifyCell()
+ step3Result = setCellResult and verifyCellResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step3Result,
+ onpass="Cell applied successfully",
+ onfail="Failed to apply cell")
+
+ main.step( "Uninstalling ONOS package" )
+ step4Result = main.TRUE
+ ONOSip1 = main.params[ 'CTRL' ][ 'ip1' ]
+ onosUninstallResult = main.ONOSbench.onosUninstall( nodeIp = ONOSip1)
+ step4Result = onosUninstallResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step4Result,
+ onpass="Successfully uninstalled ONOS",
+ onfail="Failed to uninstall ONOS")
+
+ time.sleep( 5 )
+ main.step( "Installing ONOS package" )
+ step5Result = main.TRUE
+ onosInstallResult = main.ONOSbench.onosInstall( node = ONOSip1 )
+ step5Result = onosInstallResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step5Result,
+ onpass="Successfully installed ONOS",
+ onfail="Failed to install ONOS")
+
+ onos1Isup = main.ONOSbench.isup()
+ if onos1Isup == main.TRUE:
+ main.log.report( "ONOS instance is up and ready" )
+ else:
+ main.log.report( "ONOS instance may not be up" )
+
+ main.step( "Starting ONOS service" )
+ step6Result = main.TRUE
+ startResult = main.ONOSbench.onosStart( ONOS1Ip )
+ step6Result = startResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step6Result,
+ onpass="Successfully started ONOS",
+ onfail="Failed to start ONOS")
+
+ main.step( "Starting ONOS cli" )
+ step7Result = main.TRUE
+ cliResult = main.ONOS2.startOnosCli( ONOSIp=main.params[ 'CTRL' ][ 'ip1' ] )
+ step7Result = cliResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step7Result,
+ onpass="Successfully started ONOS cli",
+ onfail="Failed to start ONOS cli")
+
+ case20Result = step1Result and step3Result and\
+ step4Result and step5Result and step6Result and\
+ step7Result
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=case20Result,
+ onpass= "Exiting functionality mininet topology and reinstalling" +
+ " ONOS successful",
+ onfail= "Exiting functionality mininet topology and reinstalling" +
+ " ONOS failed" )
+
+ def CASE21( self, main ):
+ """
+ On ONOS bench, run this command:
+ sudo -E python ~/onos/tools/test/topos/opticalTest.py -OC1
+ which spawns packet optical topology and copies the links
+ json file to the onos instance.
+ Note that in case of Packet Optical, the links are not learnt
+ from the topology, instead the links are learnt
+ from the json config file
+ """
+ import time
+ main.log.report(
+ "This testcase starts the packet layer topology and REST" )
+ main.log.report( "_____________________________________________" )
+ main.case( "Starting LINC-OE and other components" )
+
+ main.step( "Activate optical app" )
+ step1Result = main.TRUE
+ activateOpticalResult = main.ONOS2.activateApp( "org.onosproject.optical" )
+ step1Result = activateOpticalResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step1Result,
+ onpass="Successfully activated optical app",
+ onfail="Failed to activate optical app")
+
+ appCheck = main.ONOS2.appToIDCheck()
+ if appCheck != main.TRUE:
+ main.log.warn( main.ONOS2.apps() )
+ main.log.warn( main.ONOS2.appIDs() )
+
+ main.step( "Starting mininet and LINC-OE" )
+ step2Result = main.TRUE
+ time.sleep( 10 )
+ opticalMnScript = main.LincOE2.runOpticalMnScript(ctrllerIP = main.params[ 'CTRL' ][ 'ip1' ])
+ step2Result = opticalMnScript
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step2Result,
+ onpass="Started the topology successfully ",
+ onfail="Failed to start the topology")
+
+ case21Result = step1Result and step2Result
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=case21Result,
+ onpass="Packet optical topology spawned successsfully",
+ onfail="Packet optical topology spawning failed" )
+
+ def CASE22( self, main ):
+ """
+ Curretly we use, 10 optical switches(ROADM's) and
+ 6 packet layer mininet switches each with one host.
+ Therefore, the roadmCount variable = 10,
+ packetLayerSWCount variable = 6, hostCount=6 and
+ links=42.
+ All this is hardcoded in the testcase. If the topology changes,
+ these hardcoded values need to be changed
+ """
+ import time
+ main.log.report(
+ "This testcase compares the optical+packet topology against what" +
+ " is expected" )
+ main.case( "Topology comparision" )
+
+ main.step( "Starts new ONOS cli" )
+ step1Result = main.TRUE
+ cliResult = main.ONOS3.startOnosCli( ONOSIp=main.params[ 'CTRL' ]\
+ [ 'ip1' ] )
+ step1Result = cliResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step1Result,
+ onpass="Successfully starts a new cli",
+ onfail="Failed to start new cli" )
+
+ main.step( "Compare topology" )
+ step2Result = main.TRUE
+ devicesResult = main.ONOS3.devices( jsonFormat=False )
+ print "devices_result :\n", devicesResult
+ devicesLinewise = devicesResult.split( "\n" )
+ roadmCount = 0
+ packetLayerSWCount = 0
+ for line in devicesLinewise:
+ components = line.split( "," )
+ availability = components[ 1 ].split( "=" )[ 1 ]
+ type = components[ 3 ].split( "=" )[ 1 ]
+ if availability == 'true' and type == 'ROADM':
+ roadmCount += 1
+ elif availability == 'true' and type == 'SWITCH':
+ packetLayerSWCount += 1
+ if roadmCount == 10:
+ print "Number of Optical Switches = %d and is" % roadmCount +\
+ " correctly detected"
+ main.log.info(
+ "Number of Optical Switches = " +
+ str( roadmCount ) +
+ " and is correctly detected" )
+ opticalSWResult = main.TRUE
+ else:
+ print "Number of Optical Switches = %d and is wrong" % roadmCount
+ main.log.info(
+ "Number of Optical Switches = " +
+ str( roadmCount ) +
+ " and is wrong" )
+ opticalSWResult = main.FALSE
+ if packetLayerSWCount == 6:
+ print "Number of Packet layer or mininet Switches = %d "\
+ % packetLayerSWCount + "and is correctly detected"
+ main.log.info(
+ "Number of Packet layer or mininet Switches = " +
+ str( packetLayerSWCount ) +
+ " and is correctly detected" )
+ packetSWResult = main.TRUE
+ else:
+ print "Number of Packet layer or mininet Switches = %d and"\
+ % packetLayerSWCount + " is wrong"
+ main.log.info(
+ "Number of Packet layer or mininet Switches = " +
+ str( packetLayerSWCount ) +
+ " and is wrong" )
+ packetSWResult = main.FALSE
+ # sleeps for sometime so the state of the switches will be active
+ time.sleep( 30 )
+ print "_________________________________"
+ linksResult = main.ONOS3.links( jsonFormat=False )
+ print "links_result = ", linksResult
+ print "_________________________________"
+ linkActiveCount = linksResult.count("state=ACTIVE")
+ main.log.info( "linkActiveCount = " + str( linkActiveCount ))
+ if linkActiveCount == 42:
+ linkActiveResult = main.TRUE
+ main.log.info(
+ "Number of links in ACTIVE state are correct")
+ else:
+ linkActiveResult = main.FALSE
+ main.log.info(
+ "Number of links in ACTIVE state are wrong")
+ step2Result = opticalSWResult and packetSWResult and \
+ linkActiveResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step2Result,
+ onpass="Successfully loaded packet optical topology",
+ onfail="Failed to load packet optical topology" )
+
+ case22Result = step1Result and step2Result
+
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=case22Result,
+ onpass="Packet optical topology discovery successful",
+ onfail="Packet optical topology discovery failed" )
+
+ def CASE23( self, main ):
+ import time
+ """
+ Add bidirectional point intents between 2 packet layer( mininet )
+ devices and
+ ping mininet hosts
+ """
+ main.log.report(
+ "This testcase adds bidirectional point intents between 2 " +
+ "packet layer( mininet ) devices and ping mininet hosts" )
+ main.case( "Install point intents between 2 packet layer device and " +
+ "ping the hosts" )
+
+ main.step( "Adding point intents" )
+ step1Result = main.TRUE
+ intentsId = []
+ pIntent1 = main.ONOS3.addPointIntent(
+ "of:0000ffffffff0001/1",
+ "of:0000ffffffff0005/1" )
+ pIntent2 = main.ONOS3.addPointIntent(
+ "of:0000ffffffff0005/1",
+ "of:0000ffffffff0001/1" )
+ intentsId.append( pIntent1 )
+ intentsId.append( pIntent2 )
+ main.log.info( "Checking intents state")
+ checkStateResult = main.ONOS3.checkIntentState( intentsId = intentsId )
+ time.sleep( 30 )
+ main.log.info( "Checking flows state")
+ checkFlowResult = main.ONOS3.checkFlowsState()
+ # Sleep for 30 seconds to provide time for the intent state to change
+ time.sleep( 30 )
+ main.log.info( "Checking intents state one more time")
+ checkStateResult = main.ONOS3.checkIntentState( intentsId = intentsId )
+ step1Result = checkStateResult and checkFlowResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step1Result,
+ onpass="Successfully added point intents",
+ onfail="Failed to add point intents")
+
+ main.step( "Ping h1 and h5" )
+ step2Result = main.TRUE
+ main.log.info( "\n\nh1 is Pinging h5" )
+ pingResult = main.LincOE2.pingHostOptical( src="h1", target="h5" )
+ step2Result = pingResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step2Result,
+ onpass="Successfully pinged h1 and h5",
+ onfail="Failed to ping between h1 and h5")
+
+ case23Result = step1Result and step2Result
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=case23Result,
+ onpass="Point intents are installed properly",
+ onfail="Failed to install point intents" )
+
+ def CASE24( self, main ):
+ import time
+ import json
+ """
+ LINC uses its own switch IDs. You can use the following
+ command on the LINC console to find the mapping between
+ DPIDs and LINC IDs.
+ rp(application:get_all_key(linc)).
+
+ Test Rerouting of Packet Optical by bringing a port down
+ ( port 20 ) of a switch( switchID=1, or LincOE switchID =9 ),
+ so that link
+ ( between switch1 port20 - switch5 port50 ) is inactive
+ and do a ping test. If rerouting is successful,
+ ping should pass. also check the flows
+ """
+ main.log.report(
+ "This testcase tests rerouting and pings mininet hosts" )
+ main.case( "Test rerouting and pings mininet hosts" )
+
+ main.step( "Attach to the Linc-OE session" )
+ step1Result = main.TRUE
+ attachConsole = main.LincOE1.attachLincOESession()
+ step1Result = attachConsole
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step1Result,
+ onpass="Successfully attached Linc-OE session",
+ onfail="Failed to attached Linc-OE session")
+
+ main.step( "Bring a port down and verify the link state" )
+ step2Result = main.TRUE
+ main.LincOE1.portDown( swId="9", ptId="20" )
+ linksNonjson = main.ONOS3.links( jsonFormat=False )
+ main.log.info( "links = " + linksNonjson )
+ linkInactiveCount = linksNonjson.count( "state=INACTIVE" )
+ main.log.info( "linkInactiveCount = " + str( linkInactiveCount ))
+ if linkInactiveCount == 2:
+ main.log.info(
+ "Number of links in INACTIVE state are correct")
+ else:
+ main.log.info(
+ "Number of links in INACTIVE state are wrong")
+ links = main.ONOS3.links()
+ main.log.info( "links = " + links )
+ linksResult = json.loads( links )
+ linksStateResult = main.FALSE
+ for item in linksResult:
+ if item[ 'src' ][ 'device' ] == "of:0000ffffffffff01" and item[
+ 'src' ][ 'port' ] == "20":
+ if item[ 'dst' ][ 'device' ] == "of:0000ffffffffff05" and item[
+ 'dst' ][ 'port' ] == "50":
+ linksState = item[ 'state' ]
+ if linksState == "INACTIVE":
+ main.log.info(
+ "Links state is inactive as expected due to one" +
+ " of the ports being down" )
+ main.log.report(
+ "Links state is inactive as expected due to one" +
+ " of the ports being down" )
+ linksStateResult = main.TRUE
+ break
+ else:
+ main.log.info(
+ "Links state is not inactive as expected" )
+ main.log.report(
+ "Links state is not inactive as expected" )
+ linksStateResult = main.FALSE
+ time.sleep( 10 )
+ checkFlowsState = main.ONOS3.checkFlowsState()
+ step2Result = linksStateResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step2Result,
+ onpass="Successfuly brought down a link",
+ onfail="Failed to bring down a link")
+
+ main.step( "Verify Rerouting by a ping test" )
+ step3Result = main.TRUE
+ main.log.info( "\n\nh1 is Pinging h5" )
+ pingResult = main.LincOE2.pingHostOptical( src="h1", target="h5" )
+ step3Result = pingResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step3Result,
+ onpass="Successfully pinged h1 and h5",
+ onfail="Failed to ping between h1 and h5")
+
+ main.step( "Bring the downed port up and verify the link state" )
+ step4Result = main.TRUE
+ main.LincOE1.portUp( swId="9", ptId="20" )
+ linksNonjson = main.ONOS3.links( jsonFormat=False )
+ main.log.info( "links = " + linksNonjson )
+ linkInactiveCount = linksNonjson.count( "state=INACTIVE" )
+ main.log.info( "linkInactiveCount = " + str( linkInactiveCount ))
+ if linkInactiveCount == 0:
+ main.log.info(
+ "Number of links in INACTIVE state are correct")
+ else:
+ main.log.info(
+ "Number of links in INACTIVE state are wrong")
+ step4Result = main.FALSE
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step4Result,
+ onpass="Successfully brought the port up",
+ onfail="Failed to bring the port up")
+
+ case24Result = step1Result and step2Result and step3Result \
+ and step4Result
+ utilities.assert_equals( expect=main.TRUE,
+ actual=case24Result,
+ onpass="Packet optical rerouting successful",
+ onfail="Packet optical rerouting failed" )
+
+ def CASE10( self ):
+ main.log.report(
+ "This testcase uninstalls the reactive forwarding app" )
+ main.log.report( "__________________________________" )
+ main.case( "Uninstalling reactive forwarding app" )
+ main.step( "Uninstalling reactive forwarding app" )
+ step1Result = main.TRUE
+ # Unistall onos-app-fwd app to disable reactive forwarding
+ main.log.info( "deactivate reactive forwarding app" )
+ appUninstallResult = main.ONOS2.deactivateApp( "org.onosproject.fwd" )
+ appCheck = main.ONOS2.appToIDCheck()
+ if appCheck != main.TRUE:
+ main.log.warn( main.ONOS2.apps() )
+ main.log.warn( main.ONOS2.appIDs() )
+ step1Result = appUninstallResult
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step1Result,
+ onpass="Successfully deactivate reactive forwarding app",
+ onfail="Failed to deactivate reactive forwarding app")
+ # After reactive forwarding is disabled, the reactive flows on
+ # switches timeout in 10-15s
+ # So sleep for 15s
+ time.sleep( 15 )
+ flows = main.ONOS2.flows()
+ main.log.info( flows )
+
+ case10Result = step1Result
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=case10Result,
+ onpass="Reactive forwarding app uninstallation successful",
+ onfail="Reactive forwarding app uninstallation failed" )
+
+ def CASE25( self ):
+ """
+ Add host intents between 2 packet layer host
+ """
+ import time
+ import json
+ main.log.report( "Adding host intents between 2 optical layer host" )
+ main.case( "Test add host intents between optical layer host" )
+
+ main.step( "Discover host using arping" )
+ step1Result = main.TRUE
+ main.hostMACs = []
+ main.hostId = []
+ #Listing host MAC addresses
+ for i in range( 1 , 7 ):
+ main.hostMACs.append( "00:00:00:00:00:" +
+ str( hex( i )[ 2: ] ).zfill( 2 ).upper() )
+ for macs in main.hostMACs:
+ main.hostId.append( macs + "/-1" )
+ host1 = main.hostId[ 0 ]
+ host2 = main.hostId[ 1 ]
+ # Use arping to discover the hosts
+ main.LincOE2.arping( host = "h1" )
+ main.LincOE2.arping( host = "h2" )
+ time.sleep( 5 )
+ hostsDict = main.ONOS3.hosts()
+ if not len( hostsDict ):
+ step1Result = main.FALSE
+ # Adding host intent
+ utilities.assert_equals(
+ expect=main.TRUE,
+ actual=step1Result,
+ onpass="Hosts discovered",
+ onfail="Failed to discover hosts")
+
+ main.step( "Adding host intents to h1 and h2" )
+ step2Result = main.TRUE
+ intentsId = []
+ intent1 = main.ONOS3.addHostIntent( hostIdOne = host1,
+ hostIdTwo = host2 )
+ intentsId.append( intent1 )
+ time.sleep( 5 )
+ intent2 = main.ONOS3.addHostIntent( hostIdOne = host2,
+ hostIdTwo = host1 )
+ intentsId.append( intent2 )
+ # Checking intents state before pinging
+ main.log.info( "Checking intents state" )
+ time.sleep( 15 )
+ intentResult = main.ONOS3.checkIntentState( intentsId = intentsId )
+ #check intent state again if intents are not in installed state
+ if not intentResult:
+ intentResult = main.ONOS3.checkIntentState( intentsId = intentsId )
+ step2Result = intentResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=step2Result,
+ onpass="All intents are in INSTALLED state ",
+ onfail="Some of the intents are not in " +
+ "INSTALLED state " )
+
+ # pinging h1 to h2 and then ping h2 to h1
+ main.step( "Pinging h1 and h2" )
+ step3Result = main.TRUE
+ pingResult = main.TRUE
+ pingResult = main.LincOE2.pingHostOptical( src="h1", target="h2" )
+ pingResult = pingResult and main.LincOE2.pingHostOptical( src="h2",
+ target="h1" )
+ step3Result = pingResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=step3Result,
+ onpass="Pinged successfully between h1 and h2",
+ onfail="Pinged failed between h1 and h2" )
+ # Removed all added host intents
+ main.step( "Removing host intents" )
+ step4Result = main.TRUE
+ removeResult = main.TRUE
+ # Check remaining intents
+ intentsJson = json.loads( main.ONOS3.intents() )
+ main.ONOS3.removeIntent( intentId=intent1, purge=True )
+ main.ONOS3.removeIntent( intentId=intent2, purge=True )
+ for intents in intentsJson:
+ main.ONOS3.removeIntent( intentId=intents.get( 'id' ),
+ app='org.onosproject.optical',
+ purge=True )
+ print json.loads( main.ONOS3.intents() )
+ if len( json.loads( main.ONOS3.intents() ) ):
+ removeResult = main.FALSE
+ step4Result = removeResult
+ utilities.assert_equals( expect=main.TRUE,
+ actual=step4Result,
+ onpass="Successfully removed host intents",
+ onfail="Failed to remove host intents" )
+ case25Result = step1Result and step2Result and step3Result and \
+ step4Result
+ utilities.assert_equals( expect=main.TRUE,
+ actual=case25Result,
+ onpass="Add host intent successful",
+ onfail="Add host intent failed" )
diff --git a/TestON/tests/SingleFunc/__init__.py b/TestON/tests/SingleFunc/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/TestON/tests/SingleFunc/__init__.py
diff --git a/TestON/tests/SingleFunc/lala.py b/TestON/tests/SingleFunc/lala.py
new file mode 100644
index 0000000..372f8c7
--- /dev/null
+++ b/TestON/tests/SingleFunc/lala.py
@@ -0,0 +1,8 @@
+ main.log.report()
+ main.log.case()
+ main.step()
+
+ utilities.assert_equals( expect=main.TRUE,
+ actual=stepResult,
+ onpass="",
+ onfail="" )