Statistics
| Branch: | Tag: | Revision:

mininet / examples / test / test_intfOptions.py @ 706229da

History | View | Annotate | Download (1.66 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
                 "(\d+) packets transmitted, (\d+) received, (\d+)% packet loss, time (\d+)ms",
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
                loss = int( p.match.group( 3 ) )
29
                msg = ( "testing packet loss at 50%\n",
30
                        "this test will sometimes fail\n",
31
                        "ran 20 pings accross network\n",
32
                        "packet loss is %d%%\n\n"
33
                        % loss )
34
                self.assertGreaterEqual( loss, 50 * .8, msg )
35
                self.assertLessEqual( loss,  50 + 50 * ( 1 - tolerance ), msg )
36
            elif index == 2:
37
                delay = float( p.match.group( 6 ) )
38
                self.assertGreaterEqual( delay, 15 * .8 )
39
                self.assertLessEqual( delay,  15 + 15 * ( 1 - tolerance ) )
40
            else:
41
                break
42

    
43

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