Statistics
| Branch: | Tag: | Revision:

mininet / examples / test / test_linearbandwidth.py @ c5da46f1

History | View | Annotate | Download (1.29 KB)

1 a46fae06 Brian O'Connor
#!/usr/bin/env python
2
3 1d555e72 Brian O'Connor
"""
4
Test for linearbandwidth.py
5
"""
6 a46fae06 Brian O'Connor
7
import unittest
8
import pexpect
9 c5da46f1 Brian O'Connor
import sys
10 a46fae06 Brian O'Connor
11
class testLinearBandwidth( unittest.TestCase ):
12
13 c5da46f1 Brian O'Connor
    @unittest.skipIf( '-quick' in sys.argv, 'long test' )
14 a46fae06 Brian O'Connor
    def testLinearBandwidth( self ):
15 1d555e72 Brian O'Connor
        "Verify that bandwidth is monotonically decreasing as # of hops increases"
16 a46fae06 Brian O'Connor
        p = pexpect.spawn( 'python -m mininet.examples.linearbandwidth' )
17 1d555e72 Brian O'Connor
        count = 0
18
        opts = [ '\*\*\* Linear network results', 
19
                 '(\d+)\s+([\d\.]+) (.bits)', 
20
                 pexpect.EOF ]
21 a46fae06 Brian O'Connor
        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()