Update and rename MantenerFIFO to MantenerFIFO.md
[vsorcdistro/.git] / mininet / examples / popen.py
1 #!/usr/bin/python
2
3 """
4 This example monitors a number of hosts using host.popen() and
5 pmonitor()
6 """
7
8
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
14
15 def monitorhosts( hosts=5, sched='cfs' ):
16     "Start a bunch of pings and monitor them using popen"
17     mytopo = SingleSwitchTopo( hosts )
18     cpu = .5 / hosts
19     myhost = custom( CPULimitedHost, cpu=cpu, sched=sched )
20     net = Mininet( topo=mytopo, host=myhost )
21     net.start()
22     # Start a bunch of pings
23     popens = {}
24     last = net.hosts[ -1 ]
25     for host in net.hosts:
26         popens[ host ] = host.popen( "ping -c5 %s" % last.IP() )
27         last = host
28     # Monitor them and print output
29     for host, line in pmonitor( popens ):
30         if host:
31             info( "<%s>: %s" % ( host.name, line ) )
32     # Done
33     net.stop()
34
35 if __name__ == '__main__':
36     setLogLevel( 'info' )
37     monitorhosts( hosts=5 )