cleaned up and commented test_nat.py; added check for connectivity before running test
This commit is contained in:
@@ -15,7 +15,7 @@ class testMultiTest( unittest.TestCase ):
|
||||
"Verify pingall (0% dropped) and hX-eth0 interface for each host (ifconfig)"
|
||||
p = pexpect.spawn( 'python -m mininet.examples.multitest' )
|
||||
p.expect( '(\d+)% dropped' )
|
||||
dropped = int( p.match.group(1) )
|
||||
dropped = int( p.match.group( 1 ) )
|
||||
self.assertEqual( dropped, 0 )
|
||||
ifCount = 0
|
||||
while True:
|
||||
|
||||
@@ -1,44 +1,32 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""TEST"""
|
||||
"""
|
||||
Test for nat.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
#from time import sleep
|
||||
from mininet.log import setLogLevel
|
||||
#from mininet.net import Mininet
|
||||
#from mininet.node import CPULimitedHost
|
||||
#from mininet.link import TCLink
|
||||
from mininet.util import quietRun
|
||||
|
||||
#from mininet.examples.simpleperf import SingleSwitchTopo
|
||||
destIP = '8.8.8.8' # Google DNS
|
||||
|
||||
class testNAT( unittest.TestCase ):
|
||||
"Test ping with single switch topology (common code)."
|
||||
|
||||
prompt = 'mininet>'
|
||||
|
||||
# skip if 8.8.8.8 unreachable
|
||||
@unittest.skipIf( '0 received' in quietRun( 'ping -c 1 %s' % destIP ),
|
||||
'Destination IP is not reachable' )
|
||||
def testNAT( self ):
|
||||
"Attempt to ping an IP on the Internet and verify 0% packet loss"
|
||||
p = pexpect.spawn( 'python -m mininet.examples.nat' )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'h1 ping -c 1 8.8.8.8' )
|
||||
p.sendline( 'h1 ping -c 1 %s' % destIP )
|
||||
p.expect ( '(\d+)% packet loss' )
|
||||
percent = int( p.match.group( 1 ) ) if p.match else -1
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'exit' )
|
||||
p.wait()
|
||||
self.assertEqual( percent, 0 )
|
||||
'''
|
||||
def testTopo( self ):
|
||||
topo = SingleSwitchTopo(n=4)
|
||||
net = Mininet(topo=topo,
|
||||
host=CPULimitedHost, link=TCLink)
|
||||
net.start()
|
||||
h1, h4 = net.get('h1', 'h4')
|
||||
h1.cmd( 'ping -c 1 %s' % h4.IP() )
|
||||
net.stop()
|
||||
'''
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'warning' )
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user