def monitorTest(N=3, seconds=3):
 topo = SingleSwitchTopo(N)
 net = Mininet(topo)
 net.start()
 hosts = net.hosts
 info('Starting test...\n')
 server = hosts[0]
 (outfiles, errfiles) = ({}, {})
 for h in hosts:
  outfiles[h] = ('/tmp/%s.out' % h.name)
  errfiles[h] = ('/tmp/%s.err' % h.name)
  h.cmd('echo >', outfiles[h])
  h.cmd('echo >', errfiles[h])
  h.cmdPrint('ping', server.IP(), '>', outfiles[h], '2>', errfiles[h], '&')
 info('Monitoring output for', seconds, 'seconds\n')
 for (h, line) in monitorFiles(outfiles, seconds, timeoutms=500):
  if h:
   info(('%s: %s\n' % (h.name, line)))
 for h in hosts:
  h.cmd('kill %ping')
 net.stop()

def monitorTest ( N = 3 , seconds = 3 ) : topo = SingleSwitchTopo ( N ) net = Mininet ( topo ) net . start ( ) hosts = net . hosts info ( 'Starting test...\n' ) server = hosts [ 0 ] ( outfiles , errfiles ) = ( { } , { } ) for h in hosts : outfiles [ h ] = ( '/tmp/%s.out' % h . name ) errfiles [ h ] = ( '/tmp/%s.err' % h . name ) h . cmd ( 'echo >' , outfiles [ h ] ) h . cmd ( 'echo >' , errfiles [ h ] ) h . cmdPrint ( 'ping' , server . IP ( ) , '>' , outfiles [ h ] , '2>' , errfiles [ h ] , '&' ) info ( 'Monitoring output for' , seconds , 'seconds\n' ) for ( h , line ) in monitorFiles ( outfiles , seconds , timeoutms = 500 ) : if h : info ( ( '%s: %s\n' % ( h . name , line ) ) ) for h in hosts : h . cmd ( 'kill %ping' ) net . stop ( )
run pings and monitor multiple hosts .