8 from mininet.util import pexpect
9 from mininet.util import quietRun
11 class testNATNet( unittest.TestCase ):
16 self.net = pexpect.spawn( 'python -m mininet.examples.natnet' )
17 self.net.expect( self.prompt )
19 def testPublicPing( self ):
20 "Attempt to ping the public server (h0) from h1 and h2"
21 self.net.sendline( 'h1 ping -c 1 h0' )
22 self.net.expect ( '(\d+)% packet loss' )
23 percent = int( self.net.match.group( 1 ) ) if self.net.match else -1
24 self.assertEqual( percent, 0 )
25 self.net.expect( self.prompt )
27 self.net.sendline( 'h2 ping -c 1 h0' )
28 self.net.expect ( '(\d+)% packet loss' )
29 percent = int( self.net.match.group( 1 ) ) if self.net.match else -1
30 self.assertEqual( percent, 0 )
31 self.net.expect( self.prompt )
33 def testPrivatePing( self ):
34 "Attempt to ping h1 and h2 from public server"
35 self.net.sendline( 'h0 ping -c 1 -t 1 h1' )
36 result = self.net.expect ( [ 'unreachable', 'loss' ] )
37 self.assertEqual( result, 0 )
38 self.net.expect( self.prompt )
40 self.net.sendline( 'h0 ping -c 1 -t 1 h2' )
41 result = self.net.expect ( [ 'unreachable', 'loss' ] )
42 self.assertEqual( result, 0 )
43 self.net.expect( self.prompt )
45 def testPrivateToPrivatePing( self ):
46 "Attempt to ping from NAT'ed host h1 to NAT'ed host h2"
47 self.net.sendline( 'h1 ping -c 1 -t 1 h2' )
48 result = self.net.expect ( [ '[Uu]nreachable', 'loss' ] )
49 self.assertEqual( result, 0 )
50 self.net.expect( self.prompt )
53 self.net.sendline( 'exit' )
56 if __name__ == '__main__':