Statistics
| Branch: | Tag: | Revision:

mininet / examples / simpleperf.py @ 5365831d

History | View | Annotate | Download (1.84 KB)

1
#!/usr/bin/python
2

    
3
"""
4
Simple example of setting network and CPU parameters
5

6
NOTE: link params limit BW, add latency, and loss.
7
There is a high chance that pings WILL fail and that
8
iperf will hang indefinitely if the TCP handshake fails
9
to complete.
10
"""
11

    
12
from mininet.topo import Topo
13
from mininet.net import Mininet
14
from mininet.node import CPULimitedHost
15
from mininet.link import TCLink
16
from mininet.util import dumpNodeConnections
17
from mininet.log import setLogLevel
18

    
19
from sys import argv
20

    
21
class SingleSwitchTopo(Topo):
22
    "Single switch connected to n hosts."
23
    def __init__(self, n=2, lossy=True, **opts):
24
        Topo.__init__(self, **opts)
25
        switch = self.addSwitch('s1')
26
        for h in range(n):
27
            # Each host gets 50%/n of system CPU
28
            host = self.addHost('h%s' % (h + 1),
29
                                cpu=.5 / n)
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

    
39

    
40
def perfTest( lossy=True ):
41
    "Create network and run simple performance test"
42
    topo = SingleSwitchTopo( n=4, lossy=lossy )
43
    net = Mininet( topo=topo,
44
                   host=CPULimitedHost, link=TCLink,
45
                   autoStaticArp=True )
46
    net.start()
47
    print "Dumping host connections"
48
    dumpNodeConnections(net.hosts)
49
    print "Testing bandwidth between h1 and h4"
50
    h1, h4 = net.getNodeByName('h1', 'h4')
51
    net.iperf( ( h1, h4 ), l4Type='UDP' )
52
    net.stop()
53

    
54
if __name__ == '__main__':
55
    setLogLevel( 'info' )
56
    # Prevent test_simpleperf from failing due to packet loss
57
    perfTest( lossy=( 'testmode' not in argv ) )