Buffered output. Added net.monitor() and node.readline()

Moved monitor() and readline() into net.py and node.py respectively,
which will hopefully be useful for monitoring large sets of hosts,
as is done in udpbwtest.py.

Changed iperf to use interactive command infrastructure (such as it
is), which may make it more reliable. Hopefully it's a bit clearer
as well, although it is slightly more complicated.
This commit is contained in:
Bob Lantz
2010-03-16 14:59:45 -07:00
parent 6ab1f1ff23
commit ec7b211c41
3 changed files with 66 additions and 56 deletions
+3 -34
View File
@@ -18,7 +18,6 @@ various Mininet configurations, this example:
import os
import re
import select
import sys
from time import time
@@ -30,37 +29,6 @@ from mininet.node import KernelSwitch
from mininet.topolib import TreeTopo
from mininet.util import quietRun
# Some useful stuff: buffered readline and host monitoring
def readline( host, buf ):
"Read a line from a host, buffering with buffer."
buf += host.read( 1024 )
if '\n' not in buf:
return None, buf
pos = buf.find( '\n' )
line = buf[ 0 : pos ]
rest = buf[ pos + 1: ]
return line, rest
def monitor( hosts, seconds ):
"Monitor a set of hosts and yield their output."
poller = select.poll()
Node = hosts[ 0 ] # so we can call class method fdToNode
buffers = {}
for host in hosts:
poller.register( host.stdout )
buffers[ host ] = ''
quitTime = time() + seconds
while time() < quitTime:
ready = poller.poll()
for fd, event in ready:
host = Node.fdToNode( fd )
if event & select.POLLIN:
line, buffers[ host ] = readline( host, buffers[ host ] )
if line:
yield host, line
yield None, ''
# bwtest support
def parsebwtest( line,
@@ -111,8 +79,9 @@ def udpbwtest( net, seconds ):
print
results = {}
print "*** Monitoring hosts"
output = monitor( hosts, seconds )
while True:
output = net.monitor( hosts )
quitTime = time() + seconds
while time() < quitTime:
host, line = output.next()
if host is None:
break