4 Simple example of setting network and CPU parameters
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
13 from mininet.topo import Topo
14 from mininet.net import Mininet
15 from mininet.node import CPULimitedHost
16 from mininet.link import TCLink
17 from mininet.util import dumpNodeConnections
18 from mininet.log import setLogLevel, info
22 # It would be nice if we didn't have to do this:
23 # pylint: disable=arguments-differ
25 class SingleSwitchTopo( Topo ):
26 "Single switch connected to n hosts."
27 def build( self, n=2, lossy=True ):
28 switch = self.addSwitch('s1')
30 # Each host gets 50%/n of system CPU
31 host = self.addHost('h%s' % (h + 1),
34 # 10 Mbps, 5ms delay, 10% packet loss
35 self.addLink(host, switch,
36 bw=10, delay='5ms', loss=10, use_htb=True)
38 # 10 Mbps, 5ms delay, no packet loss
39 self.addLink(host, switch,
40 bw=10, delay='5ms', loss=0, use_htb=True)
43 def perfTest( lossy=True ):
44 "Create network and run simple performance test"
45 topo = SingleSwitchTopo( n=4, lossy=lossy )
46 net = Mininet( topo=topo,
47 host=CPULimitedHost, link=TCLink,
50 info( "Dumping host connections\n" )
51 dumpNodeConnections(net.hosts)
52 info( "Testing bandwidth between h1 and h4\n" )
53 h1, h4 = net.getNodeByName('h1', 'h4')
54 net.iperf( ( h1, h4 ), l4Type='UDP' )
57 if __name__ == '__main__':
59 # Prevent test_simpleperf from failing due to packet loss
60 perfTest( lossy=( 'testmode' not in argv ) )