4 This example monitors a number of hosts using host.popen() and
9 from mininet.net import Mininet
10 from mininet.node import CPULimitedHost
11 from mininet.topo import SingleSwitchTopo
12 from mininet.log import setLogLevel, info
13 from mininet.util import custom, pmonitor
15 def monitorhosts( hosts=5, sched='cfs' ):
16 "Start a bunch of pings and monitor them using popen"
17 mytopo = SingleSwitchTopo( hosts )
19 myhost = custom( CPULimitedHost, cpu=cpu, sched=sched )
20 net = Mininet( topo=mytopo, host=myhost )
22 # Start a bunch of pings
24 last = net.hosts[ -1 ]
25 for host in net.hosts:
26 popens[ host ] = host.popen( "ping -c5 %s" % last.IP() )
28 # Monitor them and print output
29 for host, line in pmonitor( popens ):
31 info( "<%s>: %s" % ( host.name, line ) )
35 if __name__ == '__main__':
37 monitorhosts( hosts=5 )