From 84ea8d7f901ed10e49b0cd8fcdeeebde0f6274a7 Mon Sep 17 00:00:00 2001 From: Cody Burkard Date: Wed, 2 Jul 2014 15:22:19 -0700 Subject: [PATCH 1/8] added waitConnected attribute to mininet class --- bin/mn | 2 ++ mininet/net.py | 31 +++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/bin/mn b/bin/mn index 71c76ec..a86d758 100755 --- a/bin/mn +++ b/bin/mn @@ -261,12 +261,14 @@ class MininetRunner( object ): if test == 'none': pass elif test == 'all': + mn.waitConnected() mn.start() mn.ping() mn.iperf() elif test == 'cli': CLI( mn ) elif test != 'build': + mn.waitConnected() getattr( mn, test )() if self.options.post: diff --git a/mininet/net.py b/mininet/net.py index 8edaee3..f068bdc 100755 --- a/mininet/net.py +++ b/mininet/net.py @@ -94,7 +94,7 @@ from time import sleep from itertools import chain, groupby 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.link import Link, Intf from mininet.util import quietRun, fixLimits, numCores, ensureRoot @@ -112,7 +112,7 @@ class Mininet( object ): build=True, xterms=False, cleanup=False, ipBase='10.0.0.0/8', inNamespace=False, autoSetMacs=False, autoStaticArp=False, autoPinCpus=False, - listenPort=None ): + listenPort=None, waitConnected=False ): """Create Mininet object. topo: Topo (topology) object or None switch: default Switch class @@ -163,6 +163,33 @@ class Mininet( object ): if topo and build: self.build() + if waitConnected: + self.waitConnected() + + def waitConnected( self ): + """wait for each switch to connect to a controller, + up to 5 seconds + returns: True if all switches are connected""" + info( '***waiting for switches to connect\n' ) + time = 0 + while time < 5: + connected = True + for switch in self.switches: + if not switch.connected(): + connected = False + sleep( .1 ) + time += .1 + break + if connected: + break + if time >= 5: + 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 ): """Add host. name: name of host to add From 8e2443ada408bcfbd98bfa2193e5b903990b0df5 Mon Sep 17 00:00:00 2001 From: Cody Burkard Date: Tue, 8 Jul 2014 13:08:48 -0700 Subject: [PATCH 2/8] improved waitConnected algorithm and set default wait time to wait forever --- mininet/net.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mininet/net.py b/mininet/net.py index f068bdc..d2e9b59 100755 --- a/mininet/net.py +++ b/mininet/net.py @@ -90,6 +90,7 @@ import os import re import select import signal +import copy from time import sleep from itertools import chain, groupby @@ -166,23 +167,25 @@ class Mininet( object ): if waitConnected: self.waitConnected() - def waitConnected( self ): + def waitConnected( self, timeout=None ): """wait for each switch to connect to a controller, up to 5 seconds returns: True if all switches are connected""" info( '***waiting for switches to connect\n' ) time = 0 - while time < 5: + remaining = copy.copy( self.switches ) + while time < timeout or timeout == None: connected = True - for switch in self.switches: + for switch in remaining: if not switch.connected(): connected = False - sleep( .1 ) - time += .1 - break + sleep( .5 ) + time += .5 + else: + remaining.remove( switch ) if connected: break - if time >= 5: + if time >= timeout and not timeout == None: warn( 'Timed out after %d seconds\n' % time ) for switch in self.switches: if not switch.connected(): From 6845fd833975554dd11f724e7aba540a5a94d50e Mon Sep 17 00:00:00 2001 From: Cody Burkard Date: Tue, 8 Jul 2014 14:40:59 -0700 Subject: [PATCH 3/8] added documentation for waitConnected timeout --- mininet/net.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mininet/net.py b/mininet/net.py index d2e9b59..e86a07d 100755 --- a/mininet/net.py +++ b/mininet/net.py @@ -170,6 +170,7 @@ class Mininet( object ): def waitConnected( self, timeout=None ): """wait for each switch to connect to a controller, up to 5 seconds + timeout: max time to wait for switches to connect. returns: True if all switches are connected""" info( '***waiting for switches to connect\n' ) time = 0 From 4797b42005f0503c12f4ceebac3137bfe8aac901 Mon Sep 17 00:00:00 2001 From: Cody Burkard Date: Tue, 8 Jul 2014 17:29:37 -0700 Subject: [PATCH 4/8] conforming to style, and fixing documentation --- mininet/net.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mininet/net.py b/mininet/net.py index e86a07d..784f20e 100755 --- a/mininet/net.py +++ b/mininet/net.py @@ -170,7 +170,7 @@ class Mininet( object ): def waitConnected( self, timeout=None ): """wait for each switch to connect to a controller, up to 5 seconds - timeout: max time to wait for switches to connect. + 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 @@ -186,7 +186,7 @@ class Mininet( object ): remaining.remove( switch ) if connected: break - if time >= timeout and not timeout == None: + 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(): From 73f477be9dcbf0c02540d5afcb0b60c99da7e52b Mon Sep 17 00:00:00 2001 From: Cody Burkard Date: Tue, 8 Jul 2014 18:19:11 -0700 Subject: [PATCH 5/8] added waitConnect to linearbandwidth example. --- examples/linearbandwidth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/linearbandwidth.py b/examples/linearbandwidth.py index 3fd06c7..8e866a7 100755 --- a/examples/linearbandwidth.py +++ b/examples/linearbandwidth.py @@ -76,7 +76,7 @@ def linearBandwidthTest( lengths ): print "*** testing", datapath, "datapath" Switch = switches[ datapath ] results[ datapath ] = [] - net = Mininet( topo=topo, switch=Switch ) + net = Mininet( topo=topo, switch=Switch, waitConnected=True ) net.start() print "*** testing basic connectivity" for n in lengths: From c23c992f144146822fbf641d23f7d787ababbe59 Mon Sep 17 00:00:00 2001 From: Cody Burkard Date: Tue, 8 Jul 2014 19:36:42 -0700 Subject: [PATCH 6/8] fixed waitConnected performance and moved waitConnected call to mn.start --- mininet/net.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mininet/net.py b/mininet/net.py index 784f20e..0a31c68 100755 --- a/mininet/net.py +++ b/mininet/net.py @@ -149,6 +149,7 @@ class Mininet( object ): self.numCores = numCores() self.nextCore = 0 # next core for pinning hosts to CPUs self.listenPort = listenPort + self.waitConn = waitConnected self.hosts = [] self.switches = [] @@ -164,8 +165,6 @@ class Mininet( object ): if topo and build: self.build() - if waitConnected: - self.waitConnected() def waitConnected( self, timeout=None ): """wait for each switch to connect to a controller, @@ -180,12 +179,12 @@ class Mininet( object ): for switch in remaining: if not switch.connected(): connected = False - sleep( .5 ) - time += .5 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: @@ -432,6 +431,8 @@ class Mininet( object ): info( switch.name + ' ') switch.start( self.controllers ) info( '\n' ) + if self.waitConn: + self.waitConnected() def stop( self ): "Stop the controller(s), switches and hosts" From 3a52ad2f530242cd368f5fb900ff254b7d4e8b00 Mon Sep 17 00:00:00 2001 From: Cody Burkard Date: Wed, 9 Jul 2014 19:24:22 -0700 Subject: [PATCH 7/8] fixed linearbandwidth and waitconnected --- examples/linearbandwidth.py | 4 ++-- mininet/net.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/linearbandwidth.py b/examples/linearbandwidth.py index 8e866a7..dee5490 100755 --- a/examples/linearbandwidth.py +++ b/examples/linearbandwidth.py @@ -24,7 +24,7 @@ of switches, this example demonstrates: """ 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.log import lg from mininet.util import irange @@ -76,7 +76,7 @@ def linearBandwidthTest( lengths ): print "*** testing", datapath, "datapath" Switch = switches[ datapath ] results[ datapath ] = [] - net = Mininet( topo=topo, switch=Switch, waitConnected=True ) + net = Mininet( topo=topo, switch=Switch, controller=Controller, waitConnected=True ) net.start() print "*** testing basic connectivity" for n in lengths: diff --git a/mininet/net.py b/mininet/net.py index 0a31c68..a5b9a34 100755 --- a/mininet/net.py +++ b/mininet/net.py @@ -432,7 +432,7 @@ class Mininet( object ): switch.start( self.controllers ) info( '\n' ) if self.waitConn: - self.waitConnected() + self.waitConnected( ) def stop( self ): "Stop the controller(s), switches and hosts" From 5a9c74be03ba61d6764cd70fffb673ed4abc2ba8 Mon Sep 17 00:00:00 2001 From: Cody Burkard Date: Thu, 10 Jul 2014 11:07:50 -0700 Subject: [PATCH 8/8] fixed last commit --- mininet/net.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mininet/net.py b/mininet/net.py index a5b9a34..0a31c68 100755 --- a/mininet/net.py +++ b/mininet/net.py @@ -432,7 +432,7 @@ class Mininet( object ): switch.start( self.controllers ) info( '\n' ) if self.waitConn: - self.waitConnected( ) + self.waitConnected() def stop( self ): "Stop the controller(s), switches and hosts"