second try
[vsorcdistro/.git] / mininet / examples / test / test_numberedports.py
1 #!/usr/bin/env python
2
3 """
4 Test for numberedports.py
5 """
6
7 import unittest
8 from mininet.util import pexpect
9 from collections import defaultdict
10 from mininet.node import OVSSwitch
11
12 class testNumberedports( unittest.TestCase ):
13
14     @unittest.skipIf( OVSSwitch.setup() or OVSSwitch.isOldOVS(), "old version of OVS" )
15     def testConsistency( self ):
16         """verify consistency between mininet and ovs ports"""
17         p = pexpect.spawn( 'python -m mininet.examples.numberedports' )
18         opts = [ 'Validating that s1-eth\d is actually on port \d ... Validated.',
19                  'Validating that s1-eth\d is actually on port \d ... WARNING',
20                  pexpect.EOF ]
21         correct_ports = True
22         count = 0
23         while True:
24             index = p.expect( opts )
25             if index == 0:
26                 count += 1
27             elif index == 1:
28                 correct_ports = False
29             elif index == 2:
30                 self.assertNotEqual( 0, count )
31                 break
32         self.assertTrue( correct_ports )
33
34     def testNumbering( self ):
35         """verify that all of the port numbers are printed correctly and consistent with their interface"""
36         p = pexpect.spawn( 'python -m mininet.examples.numberedports' )
37         opts = [ 's1-eth(\d+) :  (\d+)',
38                  pexpect.EOF ]
39         count_intfs = 0
40         while True:
41             index = p.expect( opts )
42             if index == 0:
43                 count_intfs += 1
44                 intfport = p.match.group( 1 )
45                 ofport = p.match.group( 2 )
46                 self.assertEqual( intfport, ofport )
47             elif index == 1:
48                 break
49                 self.assertNotEqual( 0, count_intfs )
50
51 if __name__ == '__main__':
52     unittest.main()