Update and rename MantenerFIFO to MantenerFIFO.md
[vsorcdistro/.git] / mininet / examples / test / test_controlnet.py
1 #!/usr/bin/env python
2
3 """
4 Test for controlnet.py
5 """
6
7 import unittest
8 from mininet.util import pexpect
9
10 class testControlNet( unittest.TestCase ):
11
12     prompt = 'mininet>'
13
14     def testPingall( self ):
15         "Simple pingall test that verifies 0% packet drop in data network"
16         p = pexpect.spawn( 'python -m mininet.examples.controlnet' )
17         p.expect( self.prompt )
18         p.sendline( 'pingall' )
19         p.expect ( '(\d+)% dropped' )
20         percent = int( p.match.group( 1 ) ) if p.match else -1
21         self.assertEqual( percent, 0 )
22         p.expect( self.prompt )
23         p.sendline( 'exit' )
24         p.wait()
25
26     def testFailover( self ):
27         "Kill controllers and verify that switch, s1, fails over properly"
28         count = 1
29         p = pexpect.spawn( 'python -m mininet.examples.controlnet' )
30         p.expect( self.prompt )
31         lp = pexpect.spawn( 'tail -f /tmp/s1-ofp.log' )
32         lp.expect( 'tcp:\d+\.\d+\.\d+\.(\d+):\d+: connected' )
33         ip = int( lp.match.group( 1 ) )
34         self.assertEqual( count, ip )
35         count += 1
36         for c in [ 'c0', 'c1' ]:
37             p.sendline( '%s ifconfig %s-eth0 down' % ( c, c) )
38             p.expect( self.prompt )
39             lp.expect( 'tcp:\d+\.\d+\.\d+\.(\d+):\d+: connected' )
40             ip = int( lp.match.group( 1 ) )
41             self.assertEqual( count, ip )
42             count += 1
43         p.sendline( 'exit' )
44         p.wait()
45
46 if __name__ == '__main__':
47     unittest.main()