Skip to content
Snippets Groups Projects
Commit b9b1f2e7 authored by Brian O'Connor's avatar Brian O'Connor
Browse files

cleaned up and commented test_nat.py; added check for connectivity before running test

parent cdd5210b
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ def testMultiTest( self ): ...@@ -15,7 +15,7 @@ def testMultiTest( self ):
"Verify pingall (0% dropped) and hX-eth0 interface for each host (ifconfig)" "Verify pingall (0% dropped) and hX-eth0 interface for each host (ifconfig)"
p = pexpect.spawn( 'python -m mininet.examples.multitest' ) p = pexpect.spawn( 'python -m mininet.examples.multitest' )
p.expect( '(\d+)% dropped' ) p.expect( '(\d+)% dropped' )
dropped = int( p.match.group(1) ) dropped = int( p.match.group( 1 ) )
self.assertEqual( dropped, 0 ) self.assertEqual( dropped, 0 )
ifCount = 0 ifCount = 0
while True: while True:
......
#!/usr/bin/env python #!/usr/bin/env python
"""TEST""" """
Test for nat.py
"""
import unittest import unittest
import pexpect import pexpect
#from time import sleep from mininet.util import quietRun
from mininet.log import setLogLevel
#from mininet.net import Mininet
#from mininet.node import CPULimitedHost
#from mininet.link import TCLink
#from mininet.examples.simpleperf import SingleSwitchTopo destIP = '8.8.8.8' # Google DNS
class testNAT( unittest.TestCase ): class testNAT( unittest.TestCase ):
"Test ping with single switch topology (common code)."
prompt = 'mininet>' 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 ): 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 = pexpect.spawn( 'python -m mininet.examples.nat' )
p.expect( self.prompt ) 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' ) p.expect ( '(\d+)% packet loss' )
percent = int( p.match.group( 1 ) ) if p.match else -1 percent = int( p.match.group( 1 ) ) if p.match else -1
p.expect( self.prompt ) p.expect( self.prompt )
p.sendline( 'exit' ) p.sendline( 'exit' )
p.wait() p.wait()
self.assertEqual( percent, 0 ) 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__': if __name__ == '__main__':
setLogLevel( 'warning' )
unittest.main() unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment