Statistics
| Branch: | Tag: | Revision:

mininet / examples / test / test_intfoptions.py @ 37bdf14b

History | View | Annotate | Download (1.46 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 = .8
17
        opts = [ "Results: \['([\d\.]+) .bits/sec",
18
                 "Results: \['10M', '([\d\.]+) .bits/sec",
19
                 "h(\d+)->h(\d+): (\d)/(\d), rtt min/avg/max/mdev ([\d\.]+)/([\d\.]+)/([\d\.]+)/([\d\.]+) ms",
20
                 pexpect.EOF ]
21
        while True:
22
            index = p.expect( opts, timeout=600 )
23
            if index == 0:
24
                bw = float( p.match.group( 1 ) )
25
                self.assertGreaterEqual( bw, float( 5 * tolerance ) )
26
                self.assertLessEqual( bw, float( 5 + 5 * ( 1 - tolerance ) ) )
27
            elif index == 1:
28
                BW = 10
29
                measuredBw = float( p.match.group( 1 ) )
30
                loss = ( measuredBw / BW ) * 100
31
                self.assertGreaterEqual( loss, 50 * tolerance )
32
                self.assertLessEqual( loss,  50 + 50 * ( 1 - tolerance ) )
33
            elif index == 2:
34
                delay = float( p.match.group( 6 ) )
35
                self.assertGreaterEqual( delay, 15 * tolerance )
36
                self.assertLessEqual( delay,  15 + 15 * ( 1 - tolerance ) )
37
            else:
38
                break
39

    
40

    
41
if __name__ == '__main__':
42
    unittest.main()