Statistics
| Branch: | Tag: | Revision:

mininet / examples / test / test_linearbandwidth.py @ c5da46f1

History | View | Annotate | Download (1.29 KB)

1
#!/usr/bin/env python
2

    
3
"""
4
Test for linearbandwidth.py
5
"""
6

    
7
import unittest
8
import pexpect
9
import sys
10

    
11
class testLinearBandwidth( unittest.TestCase ):
12

    
13
    @unittest.skipIf( '-quick' in sys.argv, 'long test' )
14
    def testLinearBandwidth( self ):
15
        "Verify that bandwidth is monotonically decreasing as # of hops increases"
16
        p = pexpect.spawn( 'python -m mininet.examples.linearbandwidth' )
17
        count = 0
18
        opts = [ '\*\*\* Linear network results', 
19
                 '(\d+)\s+([\d\.]+) (.bits)', 
20
                 pexpect.EOF ]
21
        while True:
22
            index = p.expect( opts, timeout=600 )
23
            if index == 0:
24
                previous_bw = 10 ** 10 # 10 Gbits
25
                count += 1
26
            elif index == 1:
27
                n = int( p.match.group( 1 ) )
28
                bw = float( p.match.group( 2 ) )
29
                unit = p.match.group( 3 )
30
                if unit[ 0 ] == 'K':
31
                    bw *= 10 ** 3
32
                elif unit[ 0 ] == 'M':
33
                    bw *= 10 ** 6
34
                elif unit[ 0 ] == 'G':
35
                    bw *= 10 ** 9
36
                self.assertTrue( bw < previous_bw )
37
                previous_bw = bw
38
            else:
39
                break
40

    
41
        self.assertTrue( count > 0 )
42

    
43
if __name__ == '__main__':
44
    unittest.main()