Initial pep8 compliant drivers
diff --git a/TestON/drivers/common/cli/emulator/lincoedriver.py b/TestON/drivers/common/cli/emulator/lincoedriver.py
index 944eded..d275df0 100644
--- a/TestON/drivers/common/cli/emulator/lincoedriver.py
+++ b/TestON/drivers/common/cli/emulator/lincoedriver.py
@@ -53,12 +53,12 @@
self.name = self.options[ 'name' ]
self.handle = \
super( LincOEDriver, self ).connect(
- user_name=self.user_name,
- ip_address=self.ip_address,
+ userName=self.userName,
+ ipAddress=self.ipAddress,
port=None,
pwd=self.pwd )
- self.ssh_handle = self.handle
+ self.sshHandle = self.handle
if self.handle:
main.log.info( "Handle successfully created" )
@@ -67,40 +67,18 @@
self.handle.sendline( "cd " + self.home )
self.handle.expect( "oe$" )
- #self.handle.sendline( "pgrep -g linc" )
- # self.handle.expect( "\$" )
print "handle = ", self.handle.before
return main.TRUE
- """
- main.log.info( "Building Linc-OE" )
- self.handle.sendline( "make rel" )
- i = self.handle.expect( [ "ERROR","linc-oe\$" ],timeout=60 )
- if i == 0:
- self.handle.sendline( "sudo pkill -9 epmd" )
- self.handle.expect( "\$" )
- self.handle.sendline( "make rel" )
- x = self.handle.expect( [ "\$",pexpect.EOF,pexpect.TIMEOUT ] )
- main.log.info( "make rel returned: "+ str( x ) )
- else:
-
- main.log.info( self.name+": Starting Linc-OE CLI.. This may take a while" )
- time.sleep( 30 )
- self.handle.sendline( "sudo ./rel/linc/bin/linc console" )
- j = self.handle.expect( [ "linc@",pexpect.EOF,pexpect.TIMEOUT ] )
- if j == 0:
- main.log.info( "Linc-OE CLI started" )
- return main.TRUE
- """
else:
main.log.error( self.name +
": Connection failed to the host " +
- self.user_name + "@" + self.ip_address )
+ self.userName + "@" + self.ipAddress )
main.log.error( self.name +
": Failed to connect to Linc-OE" )
return main.FALSE
- def start_console( self ):
+ def startConsole( self ):
import time
main.log.info(
self.name +
@@ -108,7 +86,7 @@
time.sleep( 30 )
self.handle.sendline( "sudo ./rel/linc/bin/linc console" )
j = self.handle.expect( [ "linc@", pexpect.EOF, pexpect.TIMEOUT ] )
- start_result = self.handle.before
+ startResult = self.handle.before
if j == 0:
main.log.info( "Linc-OE CLI started" )
return main.TRUE
@@ -116,9 +94,9 @@
main.log.error(
self.name +
": Connection failed to the host " +
- self.user_name +
+ self.userName +
"@" +
- self.ip_address )
+ self.ipAddress )
main.log.error( self.name +
": Failed to connect to Linc-OE" )
return main.FALSE
@@ -134,8 +112,6 @@
"\$" ] )
if i == 0:
- # If error, try to resolve the most common error
- #( epmd running and cannot compile )
self.handle.sendline( "sudo pkill -9 epmd" )
self.handle.sendline( "make rel" )
self.handle.expect( "\$" )
@@ -153,12 +129,12 @@
main.exit()
except:
main.log.info( self.name + " :::::::" )
- main.log.error( traceback.print_exc() )
+ main.log.error( traceback.printExc() )
main.log.info( self.name + " :::::::" )
main.cleanup()
main.exit()
- def set_interface_up( self, intfs ):
+ def setInterfaceUp( self, intfs ):
"""
Specify interface to bring up.
When Linc-OE is started, tap interfaces should
@@ -179,17 +155,17 @@
main.exit()
except:
main.log.info( self.name + " :::::::" )
- main.log.error( traceback.print_exc() )
+ main.log.error( traceback.printExc() )
main.log.info( self.name + " :::::::" )
main.cleanup()
main.exit()
- def start_switch( self, sw_id ):
+ def startSwitch( self, swId ):
"""
Start a logical switch using switch id
"""
try:
- self.handle.sendline( "linc:start_switch(" + str( sw_id ) + ")." )
+ self.handle.sendline( "linc:start_switch(" + str( swId ) + ")." )
self.handle.expect( "linc@" )
handle = self.handle.before
@@ -201,17 +177,17 @@
main.exit()
except:
main.log.info( self.name + " :::::::" )
- main.log.error( traceback.print_exc() )
+ main.log.error( traceback.printExc() )
main.log.info( self.name + " :::::::" )
main.cleanup()
main.exit()
- def stop_switch( self, sw_id ):
+ def stopSwitch( self, swId ):
"""
Stop a logical switch using switch id
"""
try:
- self.handle.sendline( "linc:stop_switch(" + str( sw_id ) + ")." )
+ self.handle.sendline( "linc:stop_switch(" + str( swId ) + ")." )
self.handle.expect( "linc@" )
handle = self.handle.before
@@ -223,18 +199,18 @@
main.exit()
except:
main.log.info( self.name + " :::::::" )
- main.log.error( traceback.print_exc() )
+ main.log.error( traceback.printExc() )
main.log.info( self.name + " :::::::" )
main.cleanup()
main.exit()
- def get_datapath_id( self, sw_id ):
+ def getDatapathId( self, swId ):
"""
Get datapath id of a specific switch by switch id
"""
try:
self.handle.sendline( "linc_logic:get_datapath_id(" +
- str( sw_id ) + ")." )
+ str( swId ) + ")." )
self.handle.expect( "linc@" )
handle = self.handle.before
@@ -246,17 +222,17 @@
main.exit()
except:
main.log.info( self.name + " :::::::" )
- main.log.error( traceback.print_exc() )
+ main.log.error( traceback.printExc() )
main.log.info( self.name + " :::::::" )
main.cleanup()
main.exit()
- def list_ports( self, sw_id ):
+ def listPorts( self, swId ):
"""
List all ports of a switch by switch id
"""
try:
- self.handle.sendline( "linc:ports(" + str( sw_id ) + ")." )
+ self.handle.sendline( "linc:ports(" + str( swId ) + ")." )
self.handle.expect( "linc@" )
handle = self.handle.before
@@ -268,18 +244,18 @@
main.exit()
except:
main.log.info( self.name + " :::::::" )
- main.log.error( traceback.print_exc() )
+ main.log.error( traceback.printExc() )
main.log.info( self.name + " :::::::" )
main.cleanup()
main.exit()
- def port_up( self, sw_id, pt_id ):
+ def portUp( self, swId, ptId ):
"""
Bring port up using switch id and port id
"""
try:
self.handle.sendline( "linc:port_up(" +
- str( sw_id ) + ", " + str( pt_id ) + ")." )
+ str( swId ) + ", " + str( ptId ) + ")." )
self.handle.expect( "linc@" )
handle = self.handle.before
@@ -291,18 +267,18 @@
main.exit()
except:
main.log.info( self.name + " :::::::" )
- main.log.error( traceback.print_exc() )
+ main.log.error( traceback.printExc() )
main.log.info( self.name + " :::::::" )
main.cleanup()
main.exit()
- def port_down( self, sw_id, pt_id ):
+ def portDown( self, swId, ptId ):
"""
Bring port down using switch id and port id
"""
try:
self.handle.sendline( "linc:port_down(" +
- str( sw_id ) + ", " + str( pt_id ) + ")." )
+ str( swId ) + ", " + str( ptId ) + ")." )
self.handle.expect( "linc@" )
handle = self.handle.before
@@ -314,7 +290,7 @@
main.exit()
except:
main.log.info( self.name + " :::::::" )
- main.log.error( traceback.print_exc() )
+ main.log.error( traceback.printExc() )
main.log.info( self.name + " :::::::" )
main.cleanup()
main.exit()
@@ -361,7 +337,7 @@
main.exit()
except:
main.log.info( self.name + " :::::::" )
- main.log.error( traceback.print_exc() )
+ main.log.error( traceback.printExc() )
main.log.info( self.name + " :::::::" )
main.cleanup()
main.exit()
diff --git a/TestON/drivers/common/cli/emulator/mininetclidriver.py b/TestON/drivers/common/cli/emulator/mininetclidriver.py
index bc0fcc5..020c659 100644
--- a/TestON/drivers/common/cli/emulator/mininetclidriver.py
+++ b/TestON/drivers/common/cli/emulator/mininetclidriver.py
@@ -51,12 +51,12 @@
self.handle = super(
MininetCliDriver,
self ).connect(
- user_name=self.user_name,
- ip_address=self.ip_address,
+ userName=self.userName,
+ ipAddress=self.ipAddress,
port=None,
pwd=self.pwd )
- self.ssh_handle = self.handle
+ self.sshHandle = self.handle
if self.handle:
main.log.info(
@@ -133,13 +133,13 @@
main.log.error(
self.name +
": Connection failed to the host " +
- self.user_name +
+ self.userName +
"@" +
- self.ip_address )
+ self.ipAddress )
main.log.error( self.name + ": Failed to connect to the Mininet" )
return main.FALSE
- def num_switches_n_links( self, topoType, depth, fanout ):
+ def numSwitchesN_links( 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:
@@ -149,36 +149,36 @@
while( k <= depth - 1 ):
count = count + pow( fanout, k )
k = k + 1
- num_switches = count
+ 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
- num_links = count * fanout
+ numLinks = count * fanout
# print "num_switches for %s(%d,%d) = %d and links=%d" %(
- # topoType,depth,fanout,num_switches,num_links )
+ # topoType,depth,fanout,numSwitches,numLinks )
elif topoType == 'linear':
- # In linear topology, if fanout or num_hosts_per_sw is not given,
+ # In linear topology, if fanout or numHostsPerSw is not given,
# by default it is 1
if fanout is None:
fanout = 1
- num_switches = depth
- num_hosts_per_sw = fanout
- total_num_hosts = num_switches * num_hosts_per_sw
- num_links = total_num_hosts + ( num_switches - 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, num_switches, num_links )
+ ( topoType, depth, fanout, numSwitches, numLinks )
topoDict = {}
topoDict = {
- "num_switches": int( num_switches ),
- "num_corelinks": int( num_links ) }
+ "num_switches": int( numSwitches ),
+ "num_corelinks": int( numLinks ) }
return topoDict
- def calculate_sw_and_links( self ):
- topoDict = self.num_switches_n_links( *topoArgList )
+ def calculateSwAndLinks( self ):
+ topoDict = self.numSwitchesN_links( *topoArgList )
return topoDict
def pingall( self, timeout=300 ):
@@ -212,13 +212,13 @@
# NOTE: mininet's pingall rounds, so we will check the number of
# passed and number of failed
pattern = "Results\:\s0\%\sdropped\s\(" +\
- "(?P<passed>[\d]+)/(?P=passed)"
+ "(?P<passed>[\d]+)/(?P=passed)"
if re.search( pattern, response ):
main.log.info( self.name + ": All hosts are reachable" )
return main.TRUE
else:
main.log.error( self.name + ": Unable to reach all the hosts" )
- main.log.info( "Pingall ouput: " + str( response ) )
+ main.log.info( "Pingall output: " + str( response ) )
# NOTE: Send ctrl-c to make sure pingall is done
self.handle.send( "\x03" )
self.handle.expect( "Interrupt" )
@@ -233,7 +233,7 @@
"""
Uses the fping package for faster pinging...
*requires fping to be installed on machine running mininet"""
- args = utilities.parse_args( [ "SRC", "TARGET" ], **pingParams )
+ args = utilities.parseArgs( [ "SRC", "TARGET" ], **pingParams )
command = args[ "SRC" ] + \
" fping -i 100 -t 20 -C 1 -q " + args[ "TARGET" ]
self.handle.sendline( command )
@@ -255,7 +255,7 @@
"""
Ping from one mininet host to another
Currently the only supported Params: SRC and TARGET"""
- args = utilities.parse_args( [ "SRC", "TARGET" ], **pingParams )
+ args = utilities.parseArgs( [ "SRC", "TARGET" ], **pingParams )
command = args[ "SRC" ] + " ping " + \
args[ "TARGET" ] + " -c 1 -i 1 -W 8"
try:
@@ -282,13 +282,13 @@
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.last_result = main.TRUE
+ main.lastResult = main.TRUE
return main.TRUE
else:
main.log.error(
self.name +
": PACKET LOST, HOST IS NOT REACHABLE" )
- main.last_result = main.FALSE
+ main.lastResult = main.FALSE
return main.FALSE
def checkIP( self, host ):
@@ -453,15 +453,15 @@
main.exit()
pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})'
- mac_address_search = re.search( pattern, response, re.I )
- mac_address = mac_address_search.group().split( " " )[ 1 ]
+ macAddressSearch = re.search( pattern, response, re.I )
+ macAddress = macAddressSearch.group().split( " " )[ 1 ]
main.log.info(
self.name +
": Mac-Address of Host " +
host +
" is " +
- mac_address )
- return mac_address
+ macAddress )
+ return macAddress
else:
main.log.error( self.name + ": Connection failed to the host" )
@@ -479,19 +479,19 @@
main.exit()
pattern = r'HWaddr\s([0-9A-F]{2}[:-]){5}([0-9A-F]{2})'
- mac_address_search = re.search( pattern, response, re.I )
- if mac_address_search is None:
+ macAddressSearch = re.search( pattern, response, re.I )
+ if macAddressSearch is None:
main.log.info( "No mac address found in %s" % response )
return main.FALSE
- mac_address = mac_address_search.group().split( " " )[ 1 ]
+ macAddress = macAddressSearch.group().split( " " )[ 1 ]
main.log.info(
"Mac-Address of " +
host +
":" +
interface +
" is " +
- mac_address )
- return mac_address
+ macAddress )
+ return macAddress
else:
main.log.error( "Connection failed to the host" )
@@ -512,14 +512,14 @@
main.exit()
pattern = "inet\saddr:(\d+\.\d+\.\d+\.\d+)"
- ip_address_search = re.search( pattern, response )
+ ipAddressSearch = re.search( pattern, response )
main.log.info(
self.name +
": IP-Address of Host " +
host +
" is " +
- ip_address_search.group( 1 ) )
- return ip_address_search.group( 1 )
+ ipAddressSearch.group( 1 ) )
+ return ipAddressSearch.group( 1 )
else:
main.log.error( self.name + ": Connection failed to the host" )
@@ -695,17 +695,17 @@
if re.search( ',\s0\%\spacket\sloss', response ):
main.log.info( self.name + ": Ping between two hosts SUCCESSFUL" )
- main.last_result = main.TRUE
+ main.lastResult = main.TRUE
return main.TRUE
else:
main.log.error( self.name + ": PACKET LOST, HOSTS NOT REACHABLE" )
- main.last_result = main.FALSE
+ 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 )
+ args = utilities.parseArgs( [ "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 ""
@@ -733,7 +733,7 @@
"""
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 )
+ args = utilities.parseArgs( [ "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) + '")'
@@ -753,7 +753,7 @@
"""
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 )
+ args = utilities.parseArgs( [ "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) + '")'
@@ -773,7 +773,7 @@
"""
Run dpctl command on all switches."""
main.log.info( 'Run dpctl command on all switches' )
- args = utilities.parse_args( [ "CMD", "ARGS" ], **dpctlargs )
+ args = utilities.parseArgs( [ "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 )
@@ -789,17 +789,17 @@
main.exit()
return main.TRUE
- def get_version( self ):
- file_input = path + '/lib/Mininet/INSTALL'
- version = super( Mininet, self ).get_version()
+ def getVersion( self ):
+ fileInput = path + '/lib/Mininet/INSTALL'
+ version = super( Mininet, self ).getVersion()
pattern = 'Mininet\s\w\.\w\.\w\w*'
- for line in open( file_input, 'r' ).readlines():
+ for line in open( fileInput, 'r' ).readlines():
result = re.match( pattern, line )
if result:
version = result.group( 0 )
return version
- def get_sw_controller( self, sw ):
+ def getSwController( self, sw ):
"""
Parameters:
sw: The name of an OVS switch. Example "s1"
@@ -822,17 +822,17 @@
main.cleanup()
main.exit()
- def assign_sw_controller( self, **kwargs ):
+ def assignSwController( self, **kwargs ):
"""
count is only needed if there is more than 1 controller"""
- args = utilities.parse_args( [ "COUNT" ], **kwargs )
+ args = utilities.parseArgs( [ "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 )
+ args = utilities.parseArgs( argstring.split( "," ), **kwargs )
sw = args[ "SW" ] if args[ "SW" ] is not None else ""
ptcpA = int( args[ "PORT1" ] ) + \
@@ -843,7 +843,7 @@
str( sw ) + " " + ptcpB + " "
for j in range( count ):
i = j + 1
- args = utilities.parse_args(
+ args = utilities.parseArgs(
[ "IP" + str( i ), "PORT" + str( i ) ], **kwargs )
ip = args[
"IP" +
@@ -867,12 +867,12 @@
main.exit()
except:
main.log.info( self.name + ":" * 50 )
- main.log.error( traceback.print_exc() )
+ main.log.error( traceback.printExc() )
main.log.info( ":" * 50 )
main.cleanup()
main.exit()
- def delete_sw_controller( self, sw ):
+ def deleteSwController( self, sw ):
"""
Removes the controller target from sw"""
command = "sh ovs-vsctl del-controller " + str( sw )
@@ -889,7 +889,7 @@
else:
main.log.info( response )
- def add_switch( self, sw, **kwargs ):
+ def addSwitch( self, sw, **kwargs ):
"""
adds a switch to the mininet topology
NOTE: this uses a custom mn function
@@ -924,7 +924,7 @@
main.cleanup()
main.exit()
- def del_switch( self, sw ):
+ def delSwitch( self, sw ):
"""
delete a switch from the mininet topology
NOTE: this uses a custom mn function
@@ -954,7 +954,7 @@
main.cleanup()
main.exit()
- def add_link( self, node1, node2 ):
+ def addLink( self, node1, node2 ):
"""
add a link to the mininet topology
NOTE: this uses a custom mn function
@@ -986,7 +986,7 @@
main.cleanup()
main.exit()
- def del_link( self, node1, node2 ):
+ def delLink( self, node1, node2 ):
"""
delete a link from the mininet topology
NOTE: this uses a custom mn function
@@ -1017,7 +1017,7 @@
main.cleanup()
main.exit()
- def add_host( self, hostname, **kwargs ):
+ def addHost( self, hostname, **kwargs ):
"""
Add a host to the mininet topology
NOTE: this uses a custom mn function
@@ -1055,7 +1055,7 @@
main.cleanup()
main.exit()
- def del_host( self, hostname ):
+ def delHost( self, hostname ):
"""
delete a host from the mininet topology
NOTE: this uses a custom mn function
@@ -1154,10 +1154,10 @@
else:
main.log.error( "Connection failed to the Mininet host" )
- def check_flows( self, sw, dump_format=None ):
- if dump_format:
+ def checkFlows( self, sw, dumpFormat=None ):
+ if dumpFormat:
command = "sh ovs-ofctl -F " + \
- dump_format + " dump-flows " + str( sw )
+ dumpFormat + " dump-flows " + str( sw )
else:
command = "sh ovs-ofctl dump-flows " + str( sw )
try:
@@ -1174,7 +1174,7 @@
else:
main.log.info( response )
- def start_tcpdump( self, filename, intf="eth0", port="port 6633" ):
+ def startTcpdump( self, filename, intf="eth0", port="port 6633" ):
"""
Runs tpdump on an intferface and saves the file
intf can be specified, or the default eth0 is used"""
@@ -1228,12 +1228,12 @@
main.exit()
except:
main.log.info( self.name + ":" * 50 )
- main.log.error( traceback.print_exc() )
+ main.log.error( traceback.printExc() )
main.log.info( ":" * 50 )
main.cleanup()
main.exit()
- def stop_tcpdump( self ):
+ def stopTcpdump( self ):
"pkills tcpdump"
try:
self.handle.sendline( "sh sudo pkill tcpdump" )
@@ -1247,28 +1247,28 @@
main.exit()
except:
main.log.info( self.name + ":" * 50 )
- main.log.error( traceback.print_exc() )
+ main.log.error( traceback.printExc() )
main.log.info( ":" * 50 )
main.cleanup()
main.exit()
- def compare_switches( self, topo, switches_json ):
+ def compareSwitches( self, topo, switchesJson ):
"""
Compare mn and onos switches
topo: sts TestONTopology object
- switches_json: parsed json object from the onos devices api
+ switchesJson: parsed json object from the onos devices api
This uses the sts TestONTopology object"""
- # main.log.debug( "Switches_json string: ", switches_json )
+ # 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( '\'',
- '' ),
+ ports.append( { 'of_port': port.portNo,
+ 'mac': str( port.hwAddr ).replace( '\'',
+ '' ),
'name': port.name } )
output[ 'switches' ].append( {
"name": switch.name,
@@ -1277,12 +1277,12 @@
# print "mn"
# print json.dumps( output,
- # sort_keys=True,
+ # sortKeys=True,
# indent=4,
# separators=( ',', ': ' ) )
# print "onos"
- # print json.dumps( switches_json,
- # sort_keys=True,
+ # print json.dumps( switchesJson,
+ # sortKeys=True,
# indent=4,
# separators=( ',', ': ' ) )
@@ -1293,12 +1293,12 @@
mnDPIDs.sort()
# print "List of Mininet switch DPID's"
# print mnDPIDs
- if switches_json == "": # if rest call fails
+ if switchesJson == "": # if rest call fails
main.log.error(
self.name +
".compare_switches(): Empty JSON object given from ONOS" )
return main.FALSE
- onos = switches_json
+ onos = switchesJson
onosDPIDs = []
for switch in onos:
if switch[ 'available' ]:
@@ -1316,7 +1316,7 @@
# print onosDPIDs
if mnDPIDs != onosDPIDs:
- switch_results = main.FALSE
+ 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 ) )
@@ -1324,14 +1324,14 @@
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
- switch_results = main.TRUE
- return switch_results
+ switchResults = main.TRUE
+ return switchResults
- def compare_ports( self, topo, ports_json ):
+ def comparePorts( self, topo, portsJson ):
"""
Compare mn and onos ports
topo: sts TestONTopology object
- ports_json: parsed json object from the onos ports api
+ portsJson: parsed json object from the onos ports api
Dependencies:
1. This uses the sts TestONTopology object
@@ -1341,109 +1341,109 @@
# FIXME: this does not look for extra ports in ONOS, only checks that
# ONOS has what is in MN
from numpy import uint64
- ports_results = main.TRUE
+ 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='' )
- tmp_port = {}
- tmp_port[ 'of_port' ] = port.port_no
- tmp_port[ 'mac' ] = str( port.hw_addr ).replace( '\'', '' )
- tmp_port[ 'name' ] = port.name
- tmp_port[ 'enabled' ] = port.enabled
+ # print port.hwAddr.toStr( separator='' )
+ tmpPort = {}
+ tmpPort[ 'of_port' ] = port.portNo
+ tmpPort[ 'mac' ] = str( port.hwAddr ).replace( '\'', '' )
+ tmpPort[ 'name' ] = port.name
+ tmpPort[ 'enabled' ] = port.enabled
- ports.append( tmp_port )
- tmp_switch = {}
- tmp_switch[ 'name' ] = switch.name
- tmp_switch[ 'dpid' ] = str( switch.dpid ).zfill( 16 )
- tmp_switch[ 'ports' ] = ports
+ ports.append( tmpPort )
+ tmpSwitch = {}
+ tmpSwitch[ 'name' ] = switch.name
+ tmpSwitch[ 'dpid' ] = str( switch.dpid ).zfill( 16 )
+ tmpSwitch[ 'ports' ] = ports
- output[ 'switches' ].append( tmp_switch )
+ output[ 'switches' ].append( tmpSwitch )
# PORTS
- for mn_switch in output[ 'switches' ]:
- mn_ports = []
- onos_ports = []
- switch_result = main.TRUE
- for port in mn_switch[ 'ports' ]:
+ for mnSwitch in output[ 'switches' ]:
+ mnPorts = []
+ onosPorts = []
+ switchResult = main.TRUE
+ for port in mnSwitch[ 'ports' ]:
if port[ 'enabled' ]:
- mn_ports.append( port[ 'of_port' ] )
- for onos_switch in ports_json:
+ mnPorts.append( port[ 'of_port' ] )
+ for onosSwitch in portsJson:
# print "Iterating through a new switch as seen by ONOS"
- # print onos_switch
- if onos_switch[ 'device' ][ 'available' ]:
- if onos_switch[ 'device' ][ 'id' ].replace(
+ # print onosSwitch
+ if onosSwitch[ 'device' ][ 'available' ]:
+ if onosSwitch[ 'device' ][ 'id' ].replace(
':',
'' ).replace(
"of",
- '' ) == mn_switch[ 'dpid' ]:
- for port in onos_switch[ 'ports' ]:
+ '' ) == mnSwitch[ 'dpid' ]:
+ for port in onosSwitch[ 'ports' ]:
if port[ 'isEnabled' ]:
if port[ 'port' ] == 'local':
- # onos_ports.append( 'local' )
- onos_ports.append( long( uint64( -2 ) ) )
+ # onosPorts.append( 'local' )
+ onosPorts.append( long( uint64( -2 ) ) )
else:
- onos_ports.append( int( port[ 'port' ] ) )
+ onosPorts.append( int( port[ 'port' ] ) )
break
- mn_ports.sort( key=float )
- onos_ports.sort( key=float )
- # print "\nPorts for Switch %s:" % ( mn_switch[ 'name' ] )
- # print "\tmn_ports[] = ", mn_ports
- # print "\tonos_ports[] = ", onos_ports
- mn_ports_log = mn_ports
- onos_ports_log = onos_ports
- mn_ports = [ x for x in mn_ports ]
- onos_ports = [ x for x in onos_ports ]
+ 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 mn_port in mn_ports_log:
- if mn_port in onos_ports:
+ 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
- mn_ports.remove( mn_port )
- onos_ports.remove( mn_port )
+ 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 mn_ports:
- mn_ports.remove( 65534 )
- if long( uint64( -2 ) ) in onos_ports:
- onos_ports.remove( long( uint64( -2 ) ) )
- if len( mn_ports ): # the ports of this switch don't match
- switch_result = main.FALSE
- main.log.warn( "Ports in MN but not ONOS: " + str( mn_ports ) )
- if len( onos_ports ): # the ports of this switch don't match
- switch_result = main.FALSE
+ 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( onos_ports ) )
- if switch_result == main.FALSE:
+ str( onosPorts ) )
+ if switchResult == main.FALSE:
main.log.report(
"The list of ports for switch %s(%s) does not match:" %
- ( mn_switch[ 'name' ], mn_switch[ 'dpid' ] ) )
- main.log.warn( "mn_ports[] = " + str( mn_ports_log ) )
- main.log.warn( "onos_ports[] = " + str( onos_ports_log ) )
- ports_results = ports_results and switch_result
- return ports_results
+ ( 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 compare_links( self, topo, links_json ):
+ def compareLinks( self, topo, linksJson ):
"""
Compare mn and onos links
topo: sts TestONTopology object
- links_json: parsed json object from the onos links api
+ 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
- link_results = main.TRUE
+ linkResults = main.TRUE
output = { "switches": [] }
- onos = links_json
+ onos = linksJson
# iterate through the MN topology and pull out switches and and port
# info
for switch in topo.graph.switches:
@@ -1451,10 +1451,10 @@
# 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( '\'',
- '' ),
+ # print port.hwAddr.toStr( separator='' )
+ ports.append( { 'of_port': port.portNo,
+ 'mac': str( port.hwAddr ).replace( '\'',
+ '' ),
'name': port.name } )
output[ 'switches' ].append( {
"name": switch.name,
@@ -1462,33 +1462,33 @@
"ports": ports } )
# LINKS
- mn_links = [
- link for link in topo.patch_panel.network_links if (
+ mnLinks = [
+ link for link in topo.patchPanel.networkLinks if (
link.port1.enabled and link.port2.enabled ) ]
- if 2 * len( mn_links ) == len( onos ):
- link_results = main.TRUE
+ if 2 * len( mnLinks ) == len( onos ):
+ linkResults = main.TRUE
else:
- link_results = main.FALSE
+ linkResults = main.FALSE
main.log.report(
"Mininet has %i bidirectional links and " +
"ONOS has %i unidirectional links" %
- ( len( mn_links ), len( onos ) ) )
+ ( len( mnLinks ), len( onos ) ) )
# 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 up_network_links and down_network_links to be
+ # wait for upNetworkLinks and downNetworkLinks to be
# fully implemented.
- for link in mn_links:
+ for link in mnLinks:
# print "Link: %s" % link
# TODO: Find a more efficient search method
node1 = None
port1 = None
node2 = None
port2 = None
- first_dir = main.FALSE
- second_dir = main.FALSE
+ firstDir = main.FALSE
+ secondDir = main.FALSE
for switch in output[ 'switches' ]:
# print "Switch: %s" % switch[ 'name' ]
if switch[ 'name' ] == link.node1.name:
@@ -1506,26 +1506,26 @@
if node1 is not None and node2 is not None:
break
- for onos_link in onos:
- onos_node1 = onos_link[ 'src' ][ 'device' ].replace(
+ for onosLink in onos:
+ onosNode1 = onosLink[ 'src' ][ 'device' ].replace(
":",
'' ).replace(
"of",
'' )
- onos_node2 = onos_link[ 'dst' ][ 'device' ].replace(
+ onosNode2 = onosLink[ 'dst' ][ 'device' ].replace(
":",
'' ).replace(
"of",
'' )
- onos_port1 = onos_link[ 'src' ][ 'port' ]
- onos_port2 = onos_link[ 'dst' ][ 'port' ]
+ onosPort1 = onosLink[ 'src' ][ 'port' ]
+ onosPort2 = onosLink[ 'dst' ][ 'port' ]
# check onos link from node1 to node2
- if str( onos_node1 ) == str( node1 ) and str(
- onos_node2 ) == str( node2 ):
- if int( onos_port1 ) == int( port1 ) and int(
- onos_port2 ) == int( port2 ):
- first_dir = main.TRUE
+ 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 ' +
@@ -1537,17 +1537,17 @@
node2,
port2 ) +
' ONOS has the values %s/%s -> %s/%s' %
- ( onos_node1,
- onos_port1,
- onos_node2,
- onos_port2 ) )
+ ( onosNode1,
+ onosPort1,
+ onosNode2,
+ onosPort2 ) )
# check onos link from node2 to node1
- elif ( str( onos_node1 ) == str( node2 ) and
- str( onos_node2 ) == str( node1 ) ):
- if ( int( onos_port1 ) == int( port2 )
- and int( onos_port2 ) == int( port1 ) ):
- second_dir = main.TRUE
+ 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 ' +
@@ -1559,24 +1559,24 @@
node1,
port1 ) +
' ONOS has the values %s/%s -> %s/%s' %
- ( onos_node2,
- onos_port2,
- onos_node1,
- onos_port1 ) )
+ ( onosNode2,
+ onosPort2,
+ onosNode1,
+ onosPort1 ) )
else: # this is not the link you're looking for
pass
- if not first_dir:
+ if not firstDir:
main.log.report(
'ONOS does not have the link %s/%s -> %s/%s' %
( node1, port1, node2, port2 ) )
- if not second_dir:
+ if not secondDir:
main.log.report(
'ONOS does not have the link %s/%s -> %s/%s' %
( node2, port2, node1, port1 ) )
- link_results = link_results and first_dir and second_dir
- return link_results
+ linkResults = linkResults and firstDir and secondDir
+ return linkResults
- def get_hosts( self ):
+ def getHosts( self ):
"""
Returns a list of all hosts
Don't ask questions just use it"""
@@ -1586,19 +1586,19 @@
self.handle.sendline( "py [ host.name for host in net.hosts ]" )
self.handle.expect( "mininet>" )
- handle_py = self.handle.before
- handle_py = handle_py.split( "]\r\n", 1 )[ 1 ]
- handle_py = handle_py.rstrip()
+ handlePy = self.handle.before
+ handlePy = handlePy.split( "]\r\n", 1 )[ 1 ]
+ handlePy = handlePy.rstrip()
self.handle.sendline( "" )
self.handle.expect( "mininet>" )
- host_str = handle_py.replace( "]", "" )
- host_str = host_str.replace( "'", "" )
- host_str = host_str.replace( "[", "" )
- host_list = host_str.split( "," )
+ hostStr = handlePy.replace( "]", "" )
+ hostStr = hostStr.replace( "'", "" )
+ hostStr = hostStr.replace( "[", "" )
+ hostList = hostStr.split( "," )
- return host_list
+ return hostList
def update( self ):
"""
diff --git a/TestON/drivers/common/cli/emulator/remotemininetdriver.py b/TestON/drivers/common/cli/emulator/remotemininetdriver.py
index a8aedea..051d4ad 100644
--- a/TestON/drivers/common/cli/emulator/remotemininetdriver.py
+++ b/TestON/drivers/common/cli/emulator/remotemininetdriver.py
@@ -32,9 +32,10 @@
class RemoteMininetDriver( Emulator ):
"""
- RemoteMininetCliDriver is the basic driver which will handle the Mininet functions
- The main different between this and the MininetCliDriver is that this one does not build the mininet.
- It assumes that there is already a mininet running on the target.
+ RemoteMininetCliDriver is the basic driver which will handle the Mininet
+ functions. The main different between this and the MininetCliDriver is that
+ this one does not build the mininet. It assumes that there is already a
+ mininet running on the target.
"""
def __init__( self ):
super( Emulator, self ).__init__()
@@ -43,9 +44,9 @@
self.flag = 0
def connect( self, **connectargs ):
- #,user_name, ip_address, pwd,options ):
- # Here the main is the TestON instance after creating all the log
- # handles.
+ """,userName, ipAddress, pwd,options ):
+ Here the main is the TestON instance after creating all the log
+ handles."""
for key in connectargs:
vars( self )[ key ] = connectargs[ key ]
@@ -53,12 +54,12 @@
self.handle = super(
RemoteMininetDriver,
self ).connect(
- user_name=self.user_name,
- ip_address=self.ip_address,
+ userName=self.userName,
+ ipAddress=self.ipAddress,
port=None,
pwd=self.pwd )
- self.ssh_handle = self.handle
+ self.sshHandle = self.handle
# Copying the readme file to process the
if self.handle:
@@ -67,32 +68,20 @@
else:
main.log.error(
"Connection failed to the host " +
- self.user_name +
+ self.userName +
"@" +
- self.ip_address )
+ self.ipAddress )
main.log.error( "Failed to connect to the Mininet" )
return main.FALSE
-#*************************************************************************
-#*************************************************************************
-# checkForLoss will determine if any of the pings had any packets lost during the course of
-# the pingLong.
-#*************************************************************************
-#*************************************************************************
-
def checkForLoss( self, pingList ):
"""
Returns main.FALSE for 0% packet loss and
Returns main.ERROR if "found multiple mininet" is found and
Returns main.TRUE else
"""
- # TODO: maybe we want to return the % loss instead? This way we can set an acceptible loss %.
- # EX: 393 packets transmitted, 380 received, 3% packet loss, time 78519ms
- # we may need to return a float to get around rounding errors
-
self.handle.sendline( "" )
self.handle.expect( "\$" )
- # Clear any output waiting in the bg from killing pings
self.handle.sendline( "" )
self.handle.expect( "\$" )
self.handle.sendline( "cat " + pingList )
@@ -110,16 +99,18 @@
def pingLong( self, **pingParams ):
"""
- Starts a continuous ping on the mininet host outputing to a file in the /tmp dir.
+ Starts a continuous ping on the mininet host outputing
+ to a file in the /tmp dir.
"""
self.handle.sendline( "" )
self.handle.expect( "\$" )
- args = utilities.parse_args(
+ args = utilities.parseArgs(
[ "SRC", "TARGET", "PINGTIME" ], **pingParams )
precmd = "sudo rm /tmp/ping." + args[ "SRC" ]
self.execute( cmd=precmd, prompt="(.*)", timeout=10 )
- command = "sudo mininet/util/m " + args[ "SRC" ] + " ping " + args[
- "TARGET" ] + " -i .2 -w " + str( args[ 'PINGTIME' ] ) + " -D > /tmp/ping." + args[ "SRC" ] + " &"
+ command = "sudo mininet/util/m " + args[ "SRC" ] + " ping " +\
+ args[ "TARGET" ] + " -i .2 -w " + str( args[ 'PINGTIME' ] ) +\
+ " -D > /tmp/ping." + args[ "SRC" ] + " &"
main.log.info( command )
self.execute( cmd=command, prompt="(.*)", timeout=10 )
self.handle.sendline( "" )
@@ -128,11 +119,12 @@
def pingstatus( self, **pingParams ):
"""
- Tails the respective ping output file and check that there is a moving "64 bytes"
+ Tails the respective ping output file and check that
+ there is a moving "64 bytes"
"""
self.handle.sendline( "" )
self.handle.expect( "\$" )
- args = utilities.parse_args( [ "SRC" ], **pingParams )
+ args = utilities.parseArgs( [ "SRC" ], **pingParams )
self.handle.sendline( "tail /tmp/ping." + args[ "SRC" ] )
self.handle.expect( "tail" )
self.handle.expect( "\$" )
@@ -195,13 +187,11 @@
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[ "CONTROLLER" ] + " " +args [ "TARGET" ]
+ args = utilities.parseArgs( [ "SRC", "TARGET" ], **pingParams )
command = args[ "SRC" ] + " ping " + \
args[ "TARGET" ] + " -c 1 -i 1 -W 8"
try:
main.log.warn( "Sending: " + command )
- #response = self.execute( cmd=command,prompt="mininet",timeout=10 )
self.handle.sendline( command )
i = self.handle.expect( [ command, pexpect.TIMEOUT ] )
if i == 1:
@@ -222,18 +212,15 @@
main.cleanup()
main.exit()
main.log.info( self.name + ": Ping Response: " + response )
- # if utilities.assert_matches(
- # expect=',\s0\%\spacket\sloss',actual=response,onpass="No Packet
- # loss",onfail="Host is not reachable" ):
if re.search( ',\s0\%\spacket\sloss', response ):
main.log.info( self.name + ": no packets lost, host is reachable" )
- main.last_result = main.TRUE
+ main.lastResult = main.TRUE
return main.TRUE
else:
main.log.error(
self.name +
": PACKET LOST, HOST IS NOT REACHABLE" )
- main.last_result = main.FALSE
+ main.lastResult = main.FALSE
return main.FALSE
def pingHost( self, **pingParams ):
@@ -242,25 +229,22 @@
"""
self.handle.sendline( "" )
self.handle.expect( "\$" )
- args = utilities.parse_args( [ "SRC", "TARGET" ], **pingParams )
- #command = "mininet/util/m " + args[ "SRC" ] + " ping "+args [ "TARGET" ]+" -c 4 -W 1 -i .2"
+ args = utilities.parseArgs( [ "SRC", "TARGET" ], **pingParams )
command = "mininet/util/m " + \
args[ "SRC" ] + " ping " + args[ "TARGET" ] + " -c 4 -W 1 -i .2"
main.log.info( command )
response = self.execute( cmd=command, prompt="rtt", timeout=10 )
- # self.handle.sendline( "" )
- # self.handle.expect( "\$" )
- if utilities.assert_matches(
+ if utilities.assertMatches(
expect=',\s0\%\spacket\sloss',
actual=response,
onpass="No Packet loss",
onfail="Host is not reachable" ):
main.log.info( "NO PACKET LOSS, HOST IS REACHABLE" )
- main.last_result = main.TRUE
+ main.lastResult = main.TRUE
return main.TRUE
else:
main.log.error( "PACKET LOST, HOST IS NOT REACHABLE" )
- main.last_result = main.FALSE
+ main.lastResult = main.FALSE
return main.FALSE
def checknum( self, num ):
@@ -290,7 +274,7 @@
else:
main.log.error( "Connection failed to the host" )
- def start_tcpdump(
+ def startTcpdump(
self,
filename,
intf="eth0",
@@ -314,23 +298,19 @@
" &" )
self.handle.sendline( "" )
self.handle.sendline( "" )
- i = self.handle.expect(
- [ 'No\ssuch\device', 'listening\son', pexpect.TIMEOUT, "\$" ], timeout=10 )
+ i = self.handle.expect( [ 'No\ssuch\device', 'listening\son',
+ pexpect.TIMEOUT, "\$" ], timeout=10 )
main.log.warn( self.handle.before + self.handle.after )
if i == 0:
- main.log.error(
- self.name +
- ": tcpdump - No such device exists. tcpdump attempted on: " +
- intf )
+ 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 )
+ 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 )
@@ -345,15 +325,13 @@
main.exit()
except:
main.log.info(
- self.name +
- ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
- main.log.error( traceback.print_exc() )
- main.log.info(
- ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
+ self.name + ":" * 60 )
+ main.log.error( traceback.printExc() )
+ main.log.info( ":" * 80 )
main.cleanup()
main.exit()
- def stop_tcpdump( self ):
+ def stopTcpdump( self ):
"pkills tcpdump"
try:
self.handle.sendline( "sudo pkill tcpdump" )
@@ -367,19 +345,17 @@
main.exit()
except:
main.log.info(
- self.name +
- ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
- main.log.error( traceback.print_exc() )
- main.log.info(
- ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" )
+ self.name + ":" * 60 )
+ main.log.error( traceback.printExc() )
+ main.log.info( ":" * 80 )
main.cleanup()
main.exit()
- def run_optical_mn_script( self ):
+ def runOpticalMnScript( self ):
"""
This function is only meant for Packet Optical.
- It runs the python script "optical.py" to create the packet layer( mn )
- topology
+ It runs the python script "optical.py" to create the
+ packet layer( mn ) topology
"""
try:
self.handle.sendline( "" )
@@ -411,17 +387,20 @@
response = main.FALSE
return response
- def get_flowTable( self, protoVersion, sw ):
- # TODO document usage
- # TODO add option to look at cookies. ignoreing them for now
+ def getFlowTable( self, protoVersion, sw ):
+ """
+ TODO document usage
+ TODO add option to look at cookies. ignoreing them for now
+
+ print "get_flowTable(" + str( protoVersion ) +" " + str( sw ) +")"
+ NOTE: Use format to force consistent flow table output across
+ versions"""
self.handle.sendline( "cd" )
self.handle.expect( [ "\$", pexpect.EOF, pexpect.TIMEOUT ] )
- # print "get_flowTable(" + str( protoVersion ) +" " + str( sw ) +")"
- # NOTE: Use format to force consistent flow table output across
- # versions
if protoVersion == 1.0:
command = "sudo ovs-ofctl dump-flows " + sw + \
- " -F OpenFlow10-table_id | awk '{OFS=\",\" ; print $1 $3 $6 $7 $8}' | cut -d ',' -f 2- | sort -n -k1 -r"
+ " -F OpenFlow10-table_id | awk '{OFS=\",\" ; print $1 $3 $6 \
+ $7 $8}' | cut -d ',' -f 2- | sort -n -k1 -r"
self.handle.sendline( command )
self.handle.expect( [ "k1 -r", pexpect.EOF, pexpect.TIMEOUT ] )
self.handle.expect(
@@ -431,7 +410,8 @@
return response
elif protoVersion == 1.3:
command = "sudo ovs-ofctl dump-flows " + sw + \
- " -O OpenFlow13 | awk '{OFS=\",\" ; print $1 $3 $6 $7}' | cut -d ',' -f 2- | sort -n -k1 -r"
+ " -O OpenFlow13 | awk '{OFS=\",\" ; print $1 $3 $6 $7}'\
+ | cut -d ',' -f 2- | sort -n -k1 -r"
self.handle.sendline( command )
self.handle.expect( [ "k1 -r", pexpect.EOF, pexpect.TIMEOUT ] )
self.handle.expect(
@@ -445,10 +425,10 @@
str(
type( protoVersion ) ) +
") '" +
- str(protoVersion) +
+ str( protoVersion ) +
"'" )
- def flow_comp( self, flow1, flow2 ):
+ def flowComp( self, flow1, flow2 ):
if flow1 == flow2:
return main.TRUE
else:
@@ -459,27 +439,23 @@
main.log.info( flow2 )
return main.FALSE
- def setIpTablesOUTPUT(
- self,
- dst_ip,
- dst_port,
- action='add',
- packet_type='tcp',
- rule='DROP' ):
+ def setIpTablesOUTPUT( self, dstIp, dstPort, action='add',
+ packetType='tcp', rule='DROP' ):
"""
Description:
- add or remove iptables rule to DROP ( default ) packets from specific IP and PORT
+ add or remove iptables rule to DROP ( default )
+ packets from specific IP and PORT
Usage:
* specify action ( 'add' or 'remove' )
when removing, pass in the same argument as you would add. It will
delete that specific rule.
- * specify the destination ip to block with dst_ip
- * specify destination port to block to dst_port
+ * specify the destination ip to block with dstIp
+ * specify destination port to block to dstPort
* optional packet type to block ( default tcp )
* optional iptables rule ( default DROP )
WARNING:
- * This function uses root privilege iptables command which may result in
- unwanted network errors. USE WITH CAUTION
+ * This function uses root privilege iptables command which may result
+ in unwanted network errors. USE WITH CAUTION
"""
import re
import time
@@ -488,14 +464,15 @@
# The strict checking methods of this driver function is intentional
# to discourage any misuse or error of iptables, which can cause
# severe network errors
- #*************
+ # *************
- # NOTE: Sleep needed to give some time for rule to be added and registered
+ # NOTE: Sleep needed to give some time
+ # for rule to be added and registered
# to the instance
time.sleep( 5 )
- action_type = action.lower()
- if action_type != 'add' and action_type != 'remove':
+ actionType = action.lower()
+ if actionType != 'add' and actionType != 'remove':
main.log.error(
"Invalid action type. 'add' or 'remove' table rule" )
if rule != 'DROP' and rule != 'ACCEPT' and rule != 'LOG':
@@ -507,27 +484,28 @@
else:
# If there is no existing rule in the iptables, we will see an
- #'iptables:'... message. We expect to see this message.
+ # 'iptables:'... message. We expect to see this message.
# Otherwise, if there IS an existing rule, we will get the prompt
# back, hence why we expect $ for remove type. We want to remove
# an already existing rule
- if action_type == 'add':
- # NOTE: "iptables:" expect is a result of return from the command
- # iptables -C ...
- # Any changes by the iptables command return string
- # will result in failure of the function. ( deemed unlikely
- # at the time of writing this function )
+ if actionType == 'add':
+ # NOTE: "iptables:" expect is a result of
+ # return from the command
+ # iptables -C ...
+ # Any changes by the iptables command return string
+ # will result in failure of the function. ( deemed unlikely
+ # at the time of writing this function )
# Check for existing rules on current input
self.handle.sendline( "" )
self.handle.expect( "\$" )
self.handle.sendline(
"sudo iptables -C OUTPUT -p " +
- str( packet_type ) +
+ str( packetType ) +
" -d " +
- str( dst_ip ) +
+ str( dstIp ) +
" --dport " +
- str( dst_port ) +
+ str( dstPort ) +
" -j " +
str( rule ) )
i = self.handle.expect( [ "iptables:", "\$" ] )
@@ -536,61 +514,61 @@
print "after: "
print self.handle.after
- elif action_type == 'remove':
+ elif actionType == 'remove':
# Check for existing rules on current input
self.handle.sendline( "" )
self.handle.expect( "\$" )
self.handle.sendline(
"sudo iptables -C OUTPUT -p " +
- str( packet_type ) +
+ str( packetType ) +
" -d " +
- str( dst_ip ) +
+ str( dstIp ) +
" --dport " +
- str( dst_port ) +
+ str( dstPort ) +
" -j " +
str( rule ) )
self.handle.expect( "\$" )
print "before: "
print self.handle.before
- actual_string = self.handle.after
- expect_string = "iptables:"
+ actualString = self.handle.after
+ expectString = "iptables:"
print "Actual String:"
- print actual_string
+ print actualString
- if re.search( expect_string, actual_string ):
- match_result = main.TRUE
+ if re.search( expectString, actualString ):
+ matchResult = main.TRUE
else:
- match_result = main.FALSE
- # If match_result is main.TRUE, it means there is no matching rule.
+ matchResult = main.FALSE
+ # If matchResult is main.TRUE, it means there is no matching rule.
- # If tables does not exist and expected prompt is returned, go ahead and
- # add iptables rule
- if match_result == main.TRUE:
+ # If tables does not exist and expected prompt is returned,
+ # go ahead and add iptables rule
+ if matchResult == main.TRUE:
# Ensure action type is add
- if action_type == 'add':
- #-A is the 'append' action of iptables
- action_add = '-A'
+ if actionType == 'add':
+ # -A is the 'append' action of iptables
+ actionAdd = '-A'
try:
self.handle.sendline( "" )
self.handle.sendline(
"sudo iptables " +
- action_add +
+ actionAdd +
" OUTPUT -p " +
- str( packet_type ) +
+ str( packetType ) +
" -d " +
- str( dst_ip ) +
+ str( dstIp ) +
" --dport " +
- str( dst_port ) +
+ str( dstPort ) +
" -j " +
str( rule ) )
- info_string = "Rules added to " + str( self.name )
- info_string += "iptable rule added to block IP: " + \
- str( dst_ip )
- info_string += "Port: " + \
- str( dst_port ) + " Rule: " + str( rule )
+ infoString = "Rules added to " + str( self.name )
+ infoString += "iptable rule added to block IP: " + \
+ str( dstIp )
+ infoString += "Port: " + \
+ str( dstPort ) + " Rule: " + str( rule )
- main.log.info( info_string )
+ main.log.info( infoString )
self.handle.expect(
[ "\$", pexpect.EOF, pexpect.TIMEOUT ] )
@@ -599,40 +577,41 @@
self.name +
": Timeout exception in setIpTables function" )
except:
- main.log.error( traceback.print_exc() )
+ main.log.error( traceback.printExc() )
main.cleanup()
main.exit()
else:
main.log.error(
"Given rule already exists, but attempted to add it" )
- # If match_result is 0, it means there IS a matching rule provided
- elif match_result == main.FALSE:
+ # If matchResult is 0, it means there IS a matching rule provided
+ elif matchResult == main.FALSE:
# Ensure action type is remove
- if action_type == 'remove':
- #-D is the 'delete' rule of iptables
- action_remove = '-D'
+ if actionType == 'remove':
+ # -D is the 'delete' rule of iptables
+ actionRemove = '-D'
try:
self.handle.sendline( "" )
# Delete a specific rule specified into the function
self.handle.sendline(
"sudo iptables " +
- action_remove +
+ actionRemove +
" OUTPUT -p " +
- str( packet_type ) +
+ str( packetType ) +
" -d " +
- str( dst_ip ) +
+ str( dstIp ) +
" --dport " +
- str( dst_port ) +
+ str( dstPort ) +
" -j " +
str( rule ) )
- info_string = "Rules removed from " + str( self.name )
- info_string += " iptables rule removed from blocking IP: " + \
- str( dst_ip )
- info_string += " Port: " + \
- str( dst_port ) + " Rule: " + str( rule )
+ infoString = "Rules removed from " + str( self.name )
+ infoString += " iptables rule removed \
+ from blocking IP: " + \
+ str( dstIp )
+ infoString += " Port: " + \
+ str( dstPort ) + " Rule: " + str( rule )
- main.log.info( info_string )
+ main.log.info( infoString )
self.handle.expect(
[ "\$", pexpect.EOF, pexpect.TIMEOUT ] )
@@ -641,12 +620,13 @@
self.name +
": Timeout exception in setIpTables function" )
except:
- main.log.error( traceback.print_exc() )
+ main.log.error( traceback.printExc() )
main.cleanup()
main.exit()
else:
main.log.error(
- "Given rule does not exist, but attempted to remove it" )
+ "Given rule does not exist,\
+ but attempted to remove it" )
else:
# NOTE: If a bad usage of this function occurs, exit the entire
# test