Revision 5365831d

View differences:

examples/simpleperf.py
16 16
from mininet.util import dumpNodeConnections
17 17
from mininet.log import setLogLevel
18 18

  
19
from sys import argv
20

  
19 21
class SingleSwitchTopo(Topo):
20 22
    "Single switch connected to n hosts."
21
    def __init__(self, n=2, **opts):
23
    def __init__(self, n=2, lossy=True, **opts):
22 24
        Topo.__init__(self, **opts)
23 25
        switch = self.addSwitch('s1')
24 26
        for h in range(n):
25 27
            # Each host gets 50%/n of system CPU
26 28
            host = self.addHost('h%s' % (h + 1),
27 29
                                cpu=.5 / n)
28
            # 10 Mbps, 5ms delay, 10% loss
29
            self.addLink(host, switch,
30
                         bw=10, delay='5ms', loss=10, use_htb=True)
30
            if lossy:
31
                # 10 Mbps, 5ms delay, 10% packet loss
32
                self.addLink(host, switch,
33
                             bw=10, delay='5ms', loss=10, use_htb=True)
34
            else:
35
                # 10 Mbps, 5ms delay, no packet loss
36
                self.addLink(host, switch,
37
                             bw=10, delay='5ms', loss=0, use_htb=True)
38

  
31 39

  
32
def perfTest():
40
def perfTest( lossy=True ):
33 41
    "Create network and run simple performance test"
34
    topo = SingleSwitchTopo( n=4 )
42
    topo = SingleSwitchTopo( n=4, lossy=lossy )
35 43
    net = Mininet( topo=topo,
36 44
                   host=CPULimitedHost, link=TCLink,
37 45
                   autoStaticArp=True )
......
44 52
    net.stop()
45 53

  
46 54
if __name__ == '__main__':
47
    setLogLevel('info')
48
    perfTest()
55
    setLogLevel( 'info' )
56
    # Prevent test_simpleperf from failing due to packet loss
57
    perfTest( lossy=( 'testmode' not in argv ) )
examples/test/test_simpleperf.py
16 16
    @unittest.skipIf( '-quick' in sys.argv, 'long test' )
17 17
    def testE2E( self ):
18 18
        "Run the example and verify iperf results"
19
        # 10 Mb/s, plus or minus 20% tolerance
19 20
        BW = 10
20
        TOLERANCE = .8
21
        expectedBw = BW * TOLERANCE
22
        p = pexpect.spawn( 'python -m mininet.examples.simpleperf' )
21
	TOLERANCE = .2 
22
        p = pexpect.spawn( 'python -m mininet.examples.simpleperf testmode' )
23 23
        # check iperf results
24 24
        p.expect( "Results: \['10M', '([\d\.]+) .bits/sec", timeout=480 )
25 25
        measuredBw = float( p.match.group( 1 ) )
26
        lowerBound = expectedBw * TOLERANCE
27
        upperBound = expectedBw + expectedBw * ( 1 - TOLERANCE )
26
        lowerBound = BW * ( 1 - TOLERANCE )
27
        upperBound = BW + ( 1 + TOLERANCE )
28 28
        self.assertGreaterEqual( measuredBw, lowerBound )
29 29
        self.assertLessEqual( measuredBw, upperBound )
30 30
        p.wait()

Also available in: Unified diff