File: popen.py

package info (click to toggle)
mininet 2.3.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,588 kB
  • sloc: python: 11,181; ansic: 1,332; sh: 967; makefile: 87
file content (34 lines) | stat: -rwxr-xr-x 893 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env 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 )