Update and rename MantenerFIFO to MantenerFIFO.md
[vsorcdistro/.git] / mininet / examples / test / test_linearbandwidth.py
1 #!/usr/bin/env python
2
3 """
4 Test for linearbandwidth.py
5 """
6
7 import unittest
8 from mininet.util 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                 count += 1
25             elif index == 1:
26                 n = int( p.match.group( 1 ) )
27                 bw = float( p.match.group( 2 ) )
28                 unit = p.match.group( 3 )
29                 if unit[ 0 ] == 'K':
30                     bw *= 10 ** 3
31                 elif unit[ 0 ] == 'M':
32                     bw *= 10 ** 6
33                 elif unit[ 0 ] == 'G':
34                     bw *= 10 ** 9
35                 # check that we have a previous result to compare to
36                 if n != 1:
37                     info = ( 'bw: %.2e bits/s across %d switches, '
38                              'previous: %.2e bits/s across %d switches' %
39                              ( bw, n, previous_bw, previous_n ) )
40                     self.assertTrue( bw < previous_bw, info )
41                 previous_bw, previous_n = bw, n
42             else:
43                 break
44
45         # verify that we received results from at least one switch
46         self.assertTrue( count > 0 )
47
48 if __name__ == '__main__':
49     unittest.main()