promote waitListening to util.py

This commit is contained in:
cody burkard
2014-09-27 04:30:16 -07:00
parent c0d8fc0d37
commit cf5bbd597a
3 changed files with 24 additions and 21 deletions
+1 -13
View File
@@ -7,23 +7,11 @@ cpu.py: test iperf bandwidth for varying cpu limits
from mininet.net import Mininet from mininet.net import Mininet
from mininet.node import CPULimitedHost from mininet.node import CPULimitedHost
from mininet.topolib import TreeTopo from mininet.topolib import TreeTopo
from mininet.util import custom from mininet.util import custom, waitListening
from mininet.log import setLogLevel, output from mininet.log import setLogLevel, output
from time import sleep from time import sleep
def waitListening(client, server, port):
"Wait until server is listening on port"
if not client.cmd('which telnet'):
raise Exception('Could not find telnet')
cmd = ('sh -c "echo A | telnet -e A %s %s"' %
(server.IP(), port))
while 'Connected' not in client.cmd(cmd):
output('waiting for', server,
'to listen on port', port, '\n')
sleep(.5)
def bwtest( cpuLimits, period_us=100000, seconds=5 ): def bwtest( cpuLimits, period_us=100000, seconds=5 ):
"""Example/test of link and CPU bandwidth limits """Example/test of link and CPU bandwidth limits
cpu: cpu limit as fraction of overall CPU time""" cpu: cpu limit as fraction of overall CPU time"""
+4 -8
View File
@@ -24,6 +24,7 @@ from mininet.log import lg
from mininet.node import Node from mininet.node import Node
from mininet.topolib import TreeTopo from mininet.topolib import TreeTopo
from mininet.link import Link from mininet.link import Link
from mininet.util import waitListening
def TreeNet( depth=1, fanout=2, **kwargs ): def TreeNet( depth=1, fanout=2, **kwargs ):
"Convenience function for creating tree networks." "Convenience function for creating tree networks."
@@ -59,15 +60,10 @@ def sshd( network, cmd='/usr/sbin/sshd', opts='-D',
connectToRootNS( network, switch, ip, routes ) connectToRootNS( network, switch, ip, routes )
for host in network.hosts: for host in network.hosts:
host.cmd( cmd + ' ' + opts + '&' ) host.cmd( cmd + ' ' + opts + '&' )
client = network.switches[ 0 ]
# wait until each host's sshd has started up # wait until each host's sshd has started up
remaining = list( network.hosts ) for server in network.hosts:
while True: waitListening( client, server, 22, timeout=5 )
for host in tuple( remaining ):
if 'sshd is running' in host.cmd( 'service ssh status' ):
remaining.remove( host )
if not remaining:
break
print print
print "*** Hosts are running sshd at the following addresses:" print "*** Hosts are running sshd at the following addresses:"
+19
View File
@@ -538,3 +538,22 @@ def ensureRoot():
print "*** Mininet must run as root." print "*** Mininet must run as root."
exit( 1 ) exit( 1 )
return return
def waitListening( client, server, port, timeout=None ):
"Wait until server is listening on port"
if not client.cmd( 'which telnet' ):
raise Exception('Could not find telnet' )
cmd = ( 'sh -c "echo A | telnet -e A %s %s"' %
( server.IP(), port ) )
time = 0
while 'Connected' not in client.cmd( cmd ):
if timeout:
if time >= timeout:
error( 'could not connect to %s on port %d\n'
% ( client, port ) )
break
output('waiting for', server,
'to listen on port', port, '\n')
sleep( .5 )
time += .5