Statistics
| Branch: | Tag: | Revision:

mininet / examples / popen.py @ 896c4cbc

History | View | Annotate | Download (1023 Bytes)

1 237a3c54 Bob Lantz
#!/usr/bin/python
2
3
"""
4 50cebe67 Bob Lantz
This example monitors a number of hosts using host.popen() and
5
pmonitor()
6 237a3c54 Bob Lantz
"""
7
8
from mininet.net import Mininet
9
from mininet.node import CPULimitedHost
10
from mininet.topo import SingleSwitchTopo
11
from mininet.log import setLogLevel
12 50cebe67 Bob Lantz
from mininet.util import custom, pmonitor
13 237a3c54 Bob Lantz
14 50cebe67 Bob Lantz
def monitorhosts( hosts=5, sched='cfs' ):
15
    "Start a bunch of pings and monitor them using popen"
16
    mytopo = SingleSwitchTopo( hosts )
17
    cpu = .5 / hosts
18
    myhost = custom( CPULimitedHost, cpu=cpu, sched=sched )
19
    net = Mininet( topo=mytopo, host=myhost )
20 237a3c54 Bob Lantz
    net.start()
21 50cebe67 Bob Lantz
    # Start a bunch of pings
22
    popens = {}
23
    last = net.hosts[ -1 ]
24
    for host in net.hosts:
25
        popens[ host ] = host.popen( "ping -c5 %s" % last.IP() )
26
        last = host
27
    # Monitor them and print output
28
    for host, line in pmonitor( popens ):
29
        if host:
30
            print "<%s>: %s" % ( host.name, line.strip() )
31
    # Done
32 237a3c54 Bob Lantz
    net.stop()
33
34
if __name__ == '__main__':
35
    setLogLevel( 'info' )
36 50cebe67 Bob Lantz
    monitorhosts( hosts=5 )