Statistics
| Branch: | Tag: | Revision:

mininet / examples / test / test_intfoptions.py @ 0fac568a

History | View | Annotate | Download (1.51 KB)

1
#!/usr/bin/env python
2

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

    
7
import unittest
8
import pexpect
9
import sys
10

    
11
class testIntfOptions( unittest.TestCase ):
12

    
13
    def testIntfOptions( self ):
14
        "verify that intf.config is correctly limiting traffic"
15
        p = pexpect.spawn( 'python -m mininet.examples.intfoptions ' )
16
        tolerance = .2  # plus or minus 20%
17
        opts = [ "Results: \['([\d\.]+) .bits/sec",
18
                 "Results: \['10M', '([\d\.]+) .bits/sec",
19
                 "h(\d+)->h(\d+): (\d)/(\d),"
20
                 "rtt min/avg/max/mdev ([\d\.]+)/([\d\.]+)/([\d\.]+)/([\d\.]+) ms",
21
                 pexpect.EOF ]
22
        while True:
23
            index = p.expect( opts, timeout=600 )
24
            if index == 0:
25
                BW = 5
26
                bw = float( p.match.group( 1 ) )
27
                self.assertGreaterEqual( bw, BW * ( 1 - tolerance ) )
28
                self.assertLessEqual( bw, BW * ( 1 + tolerance ) )
29
            elif index == 1:
30
                BW = 10
31
                measuredBw = float( p.match.group( 1 ) )
32
                loss = ( measuredBw / BW ) * 100
33
                self.assertGreaterEqual( loss, 50 * ( 1 - tolerance ) )
34
                self.assertLessEqual( loss,  50 * ( 1 + tolerance ) )
35
            elif index == 2:
36
                delay = float( p.match.group( 6 ) )
37
                self.assertGreaterEqual( delay, 15 * ( 1 - tolerance ) )
38
                self.assertLessEqual( delay,  15 * ( 1 + tolerance ) )
39
            else:
40
                break
41

    
42

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