Files
mininet/examples/popen.py
T
lantz b7c412073a CI matrix build + 20.04 fixes (#990)
Ubuntu 20.04 fixes:
- fixes sshd test
- speeds up examples/{treeping64,tree1024}.py
- debugging hacks/output for testLinkChange
- removes cfs from examples/popen.py
- improves nat in nodelib (netplan fixes?)
- makes some tests executable
- waits for switches to connect in tests to
  avoid race conditions
-- adds mn -w option and wait CLI command
Changes:
- REMOVES default "-v" argument for Controller()
  and adds verbose(=False) option; avoiding logging
  makes it faster
- CHANGES waitConnected to wait for 5 seconds
  as documented; we may wish to implement an argument
  to -w to set this timeout
Issues?
- There may still be an issue with the ovs-netplan-clean
  service causing the boot to hang ;-(
2021-01-03 20:00:33 -08:00

34 lines
888 B
Python
Executable File

#!/usr/bin/python
"""
This example monitors a number of hosts using host.popen() and
pmonitor()
"""
from mininet.net import Mininet
from mininet.topo import SingleSwitchTopo
from mininet.log import setLogLevel, info
from mininet.util import pmonitor
def monitorhosts( hosts=5 ):
"Start a bunch of pings and monitor them using popen"
mytopo = SingleSwitchTopo( hosts )
net = Mininet( topo=mytopo, waitConnected=True )
net.start()
# Start a bunch of pings
popens = {}
last = net.hosts[ -1 ]
for host in net.hosts:
popens[ host ] = host.popen( "ping -c5 %s" % last.IP() )
last = host
# Monitor them and print output
for host, line in pmonitor( popens ):
if host:
info( "<%s>: %s" % ( host.name, line ) )
# Done
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
monitorhosts( hosts=5 )