Start a bunch of pings and monitor them using popen
( hosts=5 )
| 11 | from mininet.util import pmonitor |
| 12 | |
| 13 | def monitorhosts( hosts=5 ): |
| 14 | "Start a bunch of pings and monitor them using popen" |
| 15 | mytopo = SingleSwitchTopo( hosts ) |
| 16 | net = Mininet( topo=mytopo, waitConnected=True ) |
| 17 | net.start() |
| 18 | # Start a bunch of pings |
| 19 | popens = {} |
| 20 | last = net.hosts[ -1 ] |
| 21 | for host in net.hosts: |
| 22 | popens[ host ] = host.popen( "ping -c5 %s" % last.IP() ) |
| 23 | last = host |
| 24 | # Monitor them and print output |
| 25 | for host, line in pmonitor( popens ): |
| 26 | if host: |
| 27 | info( "<%s>: %s" % ( host.name, line ) ) |
| 28 | # Done |
| 29 | net.stop() |
| 30 | |
| 31 | |
| 32 | if __name__ == '__main__': |