blob: 332822f30ca8c5f2036612c52c794988397fca5a [file] [log] [blame]
carlosmscabralf40ecd12013-02-01 18:15:58 -02001#!/usr/bin/python
2
3"""
4This example monitors a number of hosts using host.popen() and
5pmonitor()
6"""
7
8from mininet.net import Mininet
9from mininet.node import CPULimitedHost
10from mininet.topo import SingleSwitchTopo
11from mininet.log import setLogLevel
12from mininet.util import custom, pmonitor
13
14def monitorhosts( hosts=5, sched='cfs' ):
15 "Start a bunch of pings and monitor them using popen"
16 mytopo = SingleSwitchTopo( hosts )
17 cpu = .5 / hosts
18 myhost = custom( CPULimitedHost, cpu=cpu, sched=sched )
19 net = Mininet( topo=mytopo, host=myhost )
20 net.start()
21 # Start a bunch of pings
22 popens = {}
23 last = net.hosts[ -1 ]
24 for host in net.hosts:
25 popens[ host ] = host.popen( "ping -c5 %s" % last.IP() )
26 last = host
27 # Monitor them and print output
28 for host, line in pmonitor( popens ):
29 if host:
30 print "<%s>: %s" % ( host.name, line.strip() )
31 # Done
32 net.stop()
33
34if __name__ == '__main__':
35 setLogLevel( 'info' )
36 monitorhosts( hosts=5 )