cleaned up and commented test_nat.py; added check for connectivity before running test
This commit is contained in:
@@ -1,44 +1,32 @@
|
|||||||
#!/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()
|
||||||
|
|||||||
Reference in New Issue
Block a user