Statistics
| Branch: | Tag: | Revision:

mininet / examples / simpleperf.py @ e0bf8ece

History | View | Annotate | Download (1.47 KB)

1 d08d101e Bob Lantz
#!/usr/bin/python
2
3
"""
4
Simple example of setting network and CPU parameters
5 d7768ab2 Brandon Heller

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 d08d101e Bob Lantz
"""
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
class SingleSwitchTopo(Topo):
20 7cb340b7 Bob Lantz
    "Single switch connected to n hosts."
21
    def __init__(self, n=2, **opts):
22
        Topo.__init__(self, **opts)
23 ce15c4f6 Bob Lantz
        switch = self.addSwitch('s1')
24 7cb340b7 Bob Lantz
        for h in range(n):
25
            # Each host gets 50%/n of system CPU
26 ce15c4f6 Bob Lantz
            host = self.addHost('h%s' % (h + 1),
27 2e089b5e Brandon Heller
                                cpu=.5 / n)
28 7cb340b7 Bob Lantz
            # 10 Mbps, 5ms delay, 10% loss
29 ce15c4f6 Bob Lantz
            self.addLink(host, switch,
30 2e089b5e Brandon Heller
                         bw=10, delay='5ms', loss=10, use_htb=True)
31 d08d101e Bob Lantz
32
def perfTest():
33 7cb340b7 Bob Lantz
    "Create network and run simple performance test"
34 7eeaed99 cody burkard
    topo = SingleSwitchTopo( n=4 )
35
    net = Mininet( topo=topo,
36
                  host=CPULimitedHost, link=TCLink,
37
                  autoStaticArp=True )
38 7cb340b7 Bob Lantz
    net.start()
39
    print "Dumping host connections"
40
    dumpNodeConnections(net.hosts)
41
    print "Testing bandwidth between h1 and h4"
42
    h1, h4 = net.getNodeByName('h1', 'h4')
43 e0bf8ece Bob Lantz
    net.iperf( ( h1, h4 ), l4Type='UDP' )
44 7cb340b7 Bob Lantz
    net.stop()
45 d08d101e Bob Lantz
46
if __name__ == '__main__':
47 7cb340b7 Bob Lantz
    setLogLevel('info')
48
    perfTest()