Run pings and monitor multiple hosts using pmonitor
( N=3, seconds=10 )
| 12 | |
| 13 | |
| 14 | def pmonitorTest( N=3, seconds=10 ): |
| 15 | "Run pings and monitor multiple hosts using pmonitor" |
| 16 | topo = SingleSwitchTopo( N ) |
| 17 | net = Mininet( topo, waitConnected=True ) |
| 18 | net.start() |
| 19 | hosts = net.hosts |
| 20 | info( "Starting test...\n" ) |
| 21 | server = hosts[ 0 ] |
| 22 | popens = {} |
| 23 | for h in hosts: |
| 24 | popens[ h ] = h.popen('ping', server.IP() ) |
| 25 | info( "Monitoring output for", seconds, "seconds\n" ) |
| 26 | endTime = time() + seconds |
| 27 | for h, line in pmonitor( popens, timeoutms=500 ): |
| 28 | if h: |
| 29 | info( '<%s>: %s' % ( h.name, line ) ) |
| 30 | if time() >= endTime: |
| 31 | for p in popens.values(): |
| 32 | p.send_signal( SIGINT ) |
| 33 | net.stop() |
| 34 | |
| 35 | |
| 36 | if __name__ == '__main__': |
no test coverage detected