Merge pull request #325 from cdburkard/patches/userspace_connect
added waitConnected attribute to mininet class
This commit is contained in:
@@ -265,12 +265,14 @@ class MininetRunner( object ):
|
|||||||
if test == 'none':
|
if test == 'none':
|
||||||
pass
|
pass
|
||||||
elif test == 'all':
|
elif test == 'all':
|
||||||
|
mn.waitConnected()
|
||||||
mn.start()
|
mn.start()
|
||||||
mn.ping()
|
mn.ping()
|
||||||
mn.iperf()
|
mn.iperf()
|
||||||
elif test == 'cli':
|
elif test == 'cli':
|
||||||
CLI( mn )
|
CLI( mn )
|
||||||
elif test != 'build':
|
elif test != 'build':
|
||||||
|
mn.waitConnected()
|
||||||
getattr( mn, test )()
|
getattr( mn, test )()
|
||||||
|
|
||||||
if self.options.post:
|
if self.options.post:
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ of switches, this example demonstrates:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from mininet.net import Mininet
|
from mininet.net import Mininet
|
||||||
from mininet.node import UserSwitch, OVSKernelSwitch
|
from mininet.node import UserSwitch, OVSKernelSwitch, Controller
|
||||||
from mininet.topo import Topo
|
from mininet.topo import Topo
|
||||||
from mininet.log import lg
|
from mininet.log import lg
|
||||||
from mininet.util import irange
|
from mininet.util import irange
|
||||||
@@ -76,7 +76,7 @@ def linearBandwidthTest( lengths ):
|
|||||||
print "*** testing", datapath, "datapath"
|
print "*** testing", datapath, "datapath"
|
||||||
Switch = switches[ datapath ]
|
Switch = switches[ datapath ]
|
||||||
results[ datapath ] = []
|
results[ datapath ] = []
|
||||||
net = Mininet( topo=topo, switch=Switch )
|
net = Mininet( topo=topo, switch=Switch, controller=Controller, waitConnected=True )
|
||||||
net.start()
|
net.start()
|
||||||
print "*** testing basic connectivity"
|
print "*** testing basic connectivity"
|
||||||
for n in lengths:
|
for n in lengths:
|
||||||
|
|||||||
+34
-2
@@ -90,11 +90,12 @@ import os
|
|||||||
import re
|
import re
|
||||||
import select
|
import select
|
||||||
import signal
|
import signal
|
||||||
|
import copy
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from itertools import chain, groupby
|
from itertools import chain, groupby
|
||||||
|
|
||||||
from mininet.cli import CLI
|
from mininet.cli import CLI
|
||||||
from mininet.log import info, error, debug, output
|
from mininet.log import info, error, debug, output, warn
|
||||||
from mininet.node import Host, OVSKernelSwitch, Controller
|
from mininet.node import Host, OVSKernelSwitch, Controller
|
||||||
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
|
||||||
@@ -112,7 +113,7 @@ class Mininet( object ):
|
|||||||
build=True, xterms=False, cleanup=False, ipBase='10.0.0.0/8',
|
build=True, xterms=False, cleanup=False, ipBase='10.0.0.0/8',
|
||||||
inNamespace=False,
|
inNamespace=False,
|
||||||
autoSetMacs=False, autoStaticArp=False, autoPinCpus=False,
|
autoSetMacs=False, autoStaticArp=False, autoPinCpus=False,
|
||||||
listenPort=None ):
|
listenPort=None, waitConnected=False ):
|
||||||
"""Create Mininet object.
|
"""Create Mininet object.
|
||||||
topo: Topo (topology) object or None
|
topo: Topo (topology) object or None
|
||||||
switch: default Switch class
|
switch: default Switch class
|
||||||
@@ -148,6 +149,7 @@ class Mininet( object ):
|
|||||||
self.numCores = numCores()
|
self.numCores = numCores()
|
||||||
self.nextCore = 0 # next core for pinning hosts to CPUs
|
self.nextCore = 0 # next core for pinning hosts to CPUs
|
||||||
self.listenPort = listenPort
|
self.listenPort = listenPort
|
||||||
|
self.waitConn = waitConnected
|
||||||
|
|
||||||
self.hosts = []
|
self.hosts = []
|
||||||
self.switches = []
|
self.switches = []
|
||||||
@@ -163,6 +165,34 @@ class Mininet( object ):
|
|||||||
if topo and build:
|
if topo and build:
|
||||||
self.build()
|
self.build()
|
||||||
|
|
||||||
|
|
||||||
|
def waitConnected( self, timeout=None ):
|
||||||
|
"""wait for each switch to connect to a controller,
|
||||||
|
up to 5 seconds
|
||||||
|
timeout: time to wait, or None to wait indefinitely
|
||||||
|
returns: True if all switches are connected"""
|
||||||
|
info( '***waiting for switches to connect\n' )
|
||||||
|
time = 0
|
||||||
|
remaining = copy.copy( self.switches )
|
||||||
|
while time < timeout or timeout == None:
|
||||||
|
connected = True
|
||||||
|
for switch in remaining:
|
||||||
|
if not switch.connected():
|
||||||
|
connected = False
|
||||||
|
else:
|
||||||
|
remaining.remove( switch )
|
||||||
|
if connected:
|
||||||
|
break
|
||||||
|
sleep( .5 )
|
||||||
|
time += .5
|
||||||
|
if time >= timeout and timeout is not None:
|
||||||
|
warn( 'Timed out after %d seconds\n' % time )
|
||||||
|
for switch in self.switches:
|
||||||
|
if not switch.connected():
|
||||||
|
warn( 'Warning: %s is not connected to a controller\n'
|
||||||
|
% switch.name )
|
||||||
|
return connected
|
||||||
|
|
||||||
def addHost( self, name, cls=None, **params ):
|
def addHost( self, name, cls=None, **params ):
|
||||||
"""Add host.
|
"""Add host.
|
||||||
name: name of host to add
|
name: name of host to add
|
||||||
@@ -401,6 +431,8 @@ class Mininet( object ):
|
|||||||
info( switch.name + ' ')
|
info( switch.name + ' ')
|
||||||
switch.start( self.controllers )
|
switch.start( self.controllers )
|
||||||
info( '\n' )
|
info( '\n' )
|
||||||
|
if self.waitConn:
|
||||||
|
self.waitConnected()
|
||||||
|
|
||||||
def stop( self ):
|
def stop( self ):
|
||||||
"Stop the controller(s), switches and hosts"
|
"Stop the controller(s), switches and hosts"
|
||||||
|
|||||||
Reference in New Issue
Block a user