carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame^] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | "Monitor multiple hosts using popen()/pmonitor()" |
| 4 | |
| 5 | from mininet.net import Mininet |
| 6 | from mininet.topo import SingleSwitchTopo |
| 7 | from mininet.util import pmonitor |
| 8 | from time import time |
| 9 | from signal import SIGINT |
| 10 | |
| 11 | def 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 | |
| 32 | if __name__ == '__main__': |
| 33 | pmonitorTest() |