blob: 1da4b66c1b2c7b990ffec14647bcfd5aa6f52934 [file] [log] [blame]
carlosmscabralf40ecd12013-02-01 18:15:58 -02001#!/usr/bin/python
2
3"""
4Simple example of setting network and CPU parameters
5
6NOTE: link params limit BW, add latency, and loss.
7There is a high chance that pings WILL fail and that
8iperf will hang indefinitely if the TCP handshake fails
9to complete.
10"""
11
12from mininet.topo import Topo
13from mininet.net import Mininet
14from mininet.node import CPULimitedHost
15from mininet.link import TCLink
16from mininet.util import dumpNodeConnections
17from mininet.log import setLogLevel
18
19class SingleSwitchTopo(Topo):
20 "Single switch connected to n hosts."
21 def __init__(self, n=2, **opts):
22 Topo.__init__(self, **opts)
23 switch = self.addSwitch('s1')
24 for h in range(n):
25 # Each host gets 50%/n of system CPU
26 host = self.addHost('h%s' % (h + 1),
27 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)
31
32def perfTest():
33 "Create network and run simple performance test"
34 topo = SingleSwitchTopo(n=4)
35 net = Mininet(topo=topo,
36 host=CPULimitedHost, link=TCLink)
37 net.start()
38 print "Dumping host connections"
39 dumpNodeConnections(net.hosts)
40 print "Testing network connectivity"
41 net.pingAll()
42 print "Testing bandwidth between h1 and h4"
43 h1, h4 = net.getNodeByName('h1', 'h4')
44 net.iperf((h1, h4))
45 net.stop()
46
47if __name__ == '__main__':
48 setLogLevel('info')
49 perfTest()