blob: c581c27da97a9e1713133877b36b158307cd1cfe [file] [log] [blame]
carlosmscabralf40ecd12013-02-01 18:15:58 -02001#!/usr/bin/python
2
3"Monitor multiple hosts using popen()/pmonitor()"
4
5from mininet.net import Mininet
6from mininet.topo import SingleSwitchTopo
7from mininet.util import pmonitor
8from time import time
9from signal import SIGINT
10
11def pmonitorTest( N=3, seconds=10 ):
12 "Run pings and monitor multiple hosts using pmonitor"
13 topo = SingleSwitchTopo( N )
14 net = Mininet( topo )
15 net.start()
16 hosts = net.hosts
17 print "Starting test..."
18 server = hosts[ 0 ]
19 popens = {}
20 for h in hosts:
21 popens[ h ] = h.popen('ping', server.IP() )
22 print "Monitoring output for", seconds, "seconds"
23 endTime = time() + seconds
24 for h, line in pmonitor( popens, timeoutms=500 ):
25 if h:
26 print '%s: %s' % ( h.name, line ),
27 if time() >= endTime:
28 for p in popens.values():
29 p.send_signal( SIGINT )
30 net.stop()
31
32if __name__ == '__main__':
33 pmonitorTest()