10 from mininet.util import pexpect
12 from mininet.log import setLogLevel
13 from mininet.node import Node
14 from mininet.link import Link
17 class testHwintf( unittest.TestCase ):
22 self.h3 = Node( 't0', ip='10.0.0.3/8' )
23 self.n0 = Node( 't1', inNamespace=False )
24 Link( self.h3, self.n0 )
25 self.h3.configDefault()
27 def testLocalPing( self ):
28 "Verify connectivity between virtual hosts using pingall"
29 p = pexpect.spawn( 'python -m mininet.examples.hwintf %s' % self.n0.intf() )
30 p.expect( self.prompt )
31 p.sendline( 'pingall' )
32 p.expect ( '(\d+)% dropped' )
33 percent = int( p.match.group( 1 ) ) if p.match else -1
34 self.assertEqual( percent, 0 )
35 p.expect( self.prompt )
39 def testExternalPing( self ):
40 "Verify connnectivity between virtual host and virtual-physical 'external' host "
41 p = pexpect.spawn( 'python -m mininet.examples.hwintf %s' % self.n0.intf() )
42 p.expect( self.prompt )
43 # test ping external to internal
44 expectStr = '(\d+) packets transmitted, (\d+) received'
45 m = re.search( expectStr, self.h3.cmd( 'ping -v -c 1 10.0.0.1' ) )
48 self.assertEqual( tx, rx )
49 # test ping internal to external
50 p.sendline( 'h1 ping -c 1 10.0.0.3')
52 tx = p.match.group( 1 )
53 rx = p.match.group( 2 )
54 self.assertEqual( tx, rx )
55 p.expect( self.prompt )
60 self.h3.stop( deleteIntfs=True )
61 self.n0.stop( deleteIntfs=True )
63 if __name__ == '__main__':
64 setLogLevel( 'warning' )