Change iperf() to use waitListening()

This commit is contained in:
Bob Lantz
2015-02-03 21:44:21 -08:00
parent 3e4f254573
commit b2fe0778dc
2 changed files with 26 additions and 29 deletions
+13 -18
View File
@@ -102,8 +102,9 @@ from mininet.node import ( Node, Host, OVSKernelSwitch, DefaultController,
Controller ) Controller )
from mininet.nodelib import NAT from mininet.nodelib import NAT
from mininet.link import Link, Intf from mininet.link import Link, Intf
from mininet.util import quietRun, fixLimits, numCores, ensureRoot from mininet.util import ( quietRun, fixLimits, numCores, ensureRoot,
from mininet.util import macColonHex, ipStr, ipParse, netParse, ipAdd macColonHex, ipStr, ipParse, netParse, ipAdd,
waitListening )
from mininet.term import cleanUpScreens, makeTerms from mininet.term import cleanUpScreens, makeTerms
# Mininet version: should be consistent with README and LICENSE # Mininet version: should be consistent with README and LICENSE
@@ -729,27 +730,25 @@ class Mininet( object ):
# XXX This should be cleaned up # XXX This should be cleaned up
def iperf( self, hosts=None, l4Type='TCP', udpBw='10M', fmt=None, def iperf( self, hosts=None, l4Type='TCP', udpBw='10M', fmt=None,
seconds=5): seconds=5, port=5001):
"""Run iperf between two hosts. """Run iperf between two hosts.
hosts: list of hosts; if None, uses first and last hosts hosts: list of hosts; if None, uses first and last hosts
l4Type: string, one of [ TCP, UDP ] l4Type: string, one of [ TCP, UDP ]
udpBw: bandwidth target for UDP test udpBw: bandwidth target for UDP test
fmt: iperf format argument if any fmt: iperf format argument if any
seconds: iperf time to transmit seconds: iperf time to transmit
port: iperf port
returns: two-element array of [ server, client ] speeds returns: two-element array of [ server, client ] speeds
note: send() is buffered, so client rate can be much higher than note: send() is buffered, so client rate can be much higher than
the actual transmission rate; on an unloaded system, server the actual transmission rate; on an unloaded system, server
rate should be much closer to the actual receive rate""" rate should be much closer to the actual receive rate"""
if not quietRun( 'which telnet' ):
error( 'Cannot find telnet in $PATH - required for iperf test' )
return
hosts = hosts or [ self.hosts[ 0 ], self.hosts[ -1 ] ] hosts = hosts or [ self.hosts[ 0 ], self.hosts[ -1 ] ]
assert len( hosts ) == 2 assert len( hosts ) == 2
client, server = hosts client, server = hosts
output( '*** Iperf: testing ' + l4Type + ' bandwidth between ' ) output( '*** Iperf: testing', l4Type, 'bandwidth between',
output( "%s and %s\n" % ( client.name, server.name ) ) client, 'and', server, '\n' )
server.cmd( 'killall -9 iperf' ) server.cmd( 'killall -9 iperf' )
iperfArgs = 'iperf ' iperfArgs = 'iperf -p %d ' % port
bwArgs = '' bwArgs = ''
if l4Type == 'UDP': if l4Type == 'UDP':
iperfArgs += '-u ' iperfArgs += '-u '
@@ -758,20 +757,16 @@ class Mininet( object ):
raise Exception( 'Unexpected l4 type: %s' % l4Type ) raise Exception( 'Unexpected l4 type: %s' % l4Type )
if fmt: if fmt:
iperfArgs += '-f %s ' % fmt iperfArgs += '-f %s ' % fmt
server.sendCmd( iperfArgs + '-s', printPid=True ) server.sendCmd( iperfArgs + '-s' )
servout = ''
while server.lastPid is None:
servout += server.monitor()
if l4Type == 'TCP': if l4Type == 'TCP':
while 'Connected' not in client.cmd( if not waitListening( client, server.IP(), port ):
'sh -c "echo A | telnet -e A %s 5001"' % server.IP()): raise Exception( 'Could not connect to iperf on port %d'
info( 'Waiting for iperf to start up...' ) % port )
sleep(.5)
cliout = client.cmd( iperfArgs + '-t %d -c ' % seconds + cliout = client.cmd( iperfArgs + '-t %d -c ' % seconds +
server.IP() + ' ' + bwArgs ) server.IP() + ' ' + bwArgs )
debug( 'Client output: %s\n' % cliout ) debug( 'Client output: %s\n' % cliout )
server.sendInt() server.sendInt()
servout += server.waitOutput() servout = server.waitOutput()
debug( 'Server output: %s\n' % servout ) debug( 'Server output: %s\n' % servout )
result = [ self._parseIperf( servout ), self._parseIperf( cliout ) ] result = [ self._parseIperf( servout ), self._parseIperf( cliout ) ]
if l4Type == 'UDP': if l4Type == 'UDP':
+12 -10
View File
@@ -587,18 +587,20 @@ def waitListening( client=None, server='127.0.0.1', port=80, timeout=None ):
raise Exception('Could not find telnet' ) raise Exception('Could not find telnet' )
# pylint: disable=maybe-no-member # pylint: disable=maybe-no-member
serverIP = server if isinstance( server, basestring ) else server.IP() serverIP = server if isinstance( server, basestring ) else server.IP()
cmd = ( 'sh -c "echo A | telnet -e A %s %s"' % cmd = ( 'echo A | telnet -e A %s %s' % ( serverIP, port ) )
( serverIP, port ) )
time = 0 time = 0
while 'Connected' not in runCmd( cmd ): result = runCmd( cmd )
if timeout: while 'Connected' not in result:
print time if 'No route' in result:
if time >= timeout: rtable = runCmd( 'route' )
error( 'could not connect to %s on port %d\n' error( 'no route to %s:\n%s' % ( server, rtable ) )
% ( server, port ) )
return False return False
output('waiting for', server, if timeout and time >= timeout:
'to listen on port', port, '\n') error( 'could not connect to %s on port %d\n' % ( server, port ) )
return False
debug( 'waiting for', server, 'to listen on port', port, '\n' )
info( '.' )
sleep( .5 ) sleep( .5 )
time += .5 time += .5
result = runCmd( cmd )
return True return True