4 Test for linuxrouter.py
8 from mininet.util import pexpect
9 from mininet.util import quietRun
11 class testLinuxRouter( unittest.TestCase ):
15 def testPingall( self ):
16 "Test connectivity between hosts"
17 p = pexpect.spawn( 'python -m mininet.examples.linuxrouter' )
18 p.expect( self.prompt )
19 p.sendline( 'pingall' )
20 p.expect ( '(\d+)% dropped' )
21 percent = int( p.match.group( 1 ) ) if p.match else -1
22 p.expect( self.prompt )
25 self.assertEqual( percent, 0 )
27 def testRouterPing( self ):
28 "Test connectivity from h1 to router"
29 p = pexpect.spawn( 'python -m mininet.examples.linuxrouter' )
30 p.expect( self.prompt )
31 p.sendline( 'h1 ping -c 1 r0' )
32 p.expect ( '(\d+)% packet loss' )
33 percent = int( p.match.group( 1 ) ) if p.match else -1
34 p.expect( self.prompt )
37 self.assertEqual( percent, 0 )
40 "Verify that the TTL is decremented"
41 p = pexpect.spawn( 'python -m mininet.examples.linuxrouter' )
42 p.expect( self.prompt )
43 p.sendline( 'h1 ping -c 1 h2' )
44 p.expect ( 'ttl=(\d+)' )
45 ttl = int( p.match.group( 1 ) ) if p.match else -1
46 p.expect( self.prompt )
49 self.assertEqual( ttl, 63 ) # 64 - 1
51 if __name__ == '__main__':