From 05dbf82edb42ba1f9ef3dfa5aab9c7e5ad6ae81e Mon Sep 17 00:00:00 2001 From: Bob Lantz <rlantz@cs.stanford.edu> Date: Thu, 11 Dec 2014 16:32:15 -0800 Subject: [PATCH] Correctly set controller backoff for OVS. Also report connected in standalone/bridge mode Fixes #460 Conflicts: mininet/node.py --- mininet/node.py | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/mininet/node.py b/mininet/node.py index 9c303ae2..201e0904 100644 --- a/mininet/node.py +++ b/mininet/node.py @@ -1066,6 +1066,7 @@ def __init__( self, name, failMode='secure', datapath='kernel', self.datapath = datapath self.inband = inband self.protocols = protocols + self._uuids = [] # controller UUIDs @classmethod def setup( cls ): @@ -1124,22 +1125,25 @@ def detach( self, intf ): "Disconnect a data port" self.cmd( 'ovs-vsctl del-port', self, intf ) - def controllerUUIDs( self ): - "Return ovsdb UUIDs for our controllers" - uuids = [] - controllers = self.cmd( 'ovs-vsctl -- get Bridge', self, - 'Controller' ).strip() - if controllers.startswith( '[' ) and controllers.endswith( ']' ): - controllers = controllers[ 1 : -1 ] - uuids = [ c.strip() for c in controllers.split( ',' ) ] - return uuids + def controllerUUIDs( self, update=False ): + """Return ovsdb UUIDs for our controllers + update: update cached value""" + if not self._uuids or update: + controllers = self.cmd( 'ovs-vsctl -- get Bridge', self, + 'Controller' ).strip() + if controllers.startswith( '[' ) and controllers.endswith( ']' ): + controllers = controllers[ 1 : -1 ] + if controllers: + self._uuids = [ c.strip() for c in controllers.split( ',' ) ] + return self._uuids def connected( self ): "Are we connected to at least one of our controllers?" - results = [ 'true' in self.cmd( 'ovs-vsctl -- get Controller', - uuid, 'is_connected' ) - for uuid in self.controllerUUIDs() ] - return reduce( or_, results, False ) + for uuid in self.controllerUUIDs(): + if 'true' in self.cmd( 'ovs-vsctl -- get Controller', + uuid, 'is_connected' ): + return True + return self.failMode == 'standalone' def start( self, controllers ): "Start up a new OVS OpenFlow switch using ovs-vsctl" @@ -1184,15 +1188,14 @@ def start( self, controllers ): cmd += '-- set bridge %s datapath_type=netdev ' % self if self.protocols: cmd += '-- set bridge %s protocols=%s' % ( self, self.protocols ) - # Reconnect quickly to controllers (1s vs. 15s max_backoff) - for uuid in self.controllerUUIDs(): - if uuid.count( '-' ) != 4: - # Doesn't look like a UUID - continue - uuid = uuid.strip() - cmd += '-- set Controller %smax_backoff=1000 ' % uuid # Do it!! self.cmd( cmd ) + # Reconnect quickly to controllers (1s vs. 15s max_backoff) + uuids = [ '-- set Controller %s max_backoff=1000' % uuid + for uuid in self.controllerUUIDs() ] + if uuids: + self.cmd( 'ovs-vsctl', *uuids ) + # If necessary, restore TC config overwritten by OVS for intf in self.intfList(): self.TCReapply( intf ) -- GitLab