Merge del-br into cmd, and add reconnectms param
With newer versions of OVS, this allows us to set up a switch with a single OVS command (if reconnectms is zero.) If reconnectms is specified, then it slows things down slightly (but not much.)
This commit is contained in:
+13
-8
@@ -1054,19 +1054,21 @@ class OVSSwitch( Switch ):
|
|||||||
"Open vSwitch switch. Depends on ovs-vsctl."
|
"Open vSwitch switch. Depends on ovs-vsctl."
|
||||||
|
|
||||||
def __init__( self, name, failMode='secure', datapath='kernel',
|
def __init__( self, name, failMode='secure', datapath='kernel',
|
||||||
inband=False, protocols=None, **params ):
|
inband=False, protocols=None,
|
||||||
"""Init.
|
reconnectms=1000, **params ):
|
||||||
name: name for switch
|
"""name: name for switch
|
||||||
failMode: controller loss behavior (secure|open)
|
failMode: controller loss behavior (secure|open)
|
||||||
datapath: userspace or kernel mode (kernel|user)
|
datapath: userspace or kernel mode (kernel|user)
|
||||||
inband: use in-band control (False)
|
inband: use in-band control (False)
|
||||||
protocols: use specific OpenFlow version(s) (e.g. OpenFlow13)
|
protocols: use specific OpenFlow version(s) (e.g. OpenFlow13)
|
||||||
Unspecified (or old OVS version) uses OVS default"""
|
Unspecified (or old OVS version) uses OVS default
|
||||||
|
reconnectms: max reconnect timeout in ms (0/None for default)"""
|
||||||
Switch.__init__( self, name, **params )
|
Switch.__init__( self, name, **params )
|
||||||
self.failMode = failMode
|
self.failMode = failMode
|
||||||
self.datapath = datapath
|
self.datapath = datapath
|
||||||
self.inband = inband
|
self.inband = inband
|
||||||
self.protocols = protocols
|
self.protocols = protocols
|
||||||
|
self.reconnectms = reconnectms
|
||||||
self._uuids = [] # controller UUIDs
|
self._uuids = [] # controller UUIDs
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -1165,8 +1167,6 @@ class OVSSwitch( Switch ):
|
|||||||
if self.inNamespace:
|
if self.inNamespace:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
'OVS kernel switch does not work in a namespace' )
|
'OVS kernel switch does not work in a namespace' )
|
||||||
# Annoyingly, --if-exists option seems not to work
|
|
||||||
self.cmd( 'ovs-vsctl del-br', self )
|
|
||||||
int( self.dpid, 16 ) # DPID must be a hex string
|
int( self.dpid, 16 ) # DPID must be a hex string
|
||||||
# Interfaces and controllers
|
# Interfaces and controllers
|
||||||
intfs = ' '.join( '-- add-port %s %s ' % ( self, intf ) +
|
intfs = ' '.join( '-- add-port %s %s ' % ( self, intf ) +
|
||||||
@@ -1181,7 +1181,8 @@ class OVSSwitch( Switch ):
|
|||||||
clist += ' ptcp:%s' % self.listenPort
|
clist += ' ptcp:%s' % self.listenPort
|
||||||
# Construct big ovs-vsctl command for new versions of OVS
|
# Construct big ovs-vsctl command for new versions of OVS
|
||||||
if not self.isOldOVS():
|
if not self.isOldOVS():
|
||||||
cmd = ( 'ovs-vsctl add-br %s ' % self +
|
cmd = ( 'ovs-vsctl --if-exists del-br %s ' % self +
|
||||||
|
'-- add-br %s ' % self +
|
||||||
'-- set Bridge %s ' % self +
|
'-- set Bridge %s ' % self +
|
||||||
'other_config:datapath-id=%s ' % self.dpid +
|
'other_config:datapath-id=%s ' % self.dpid +
|
||||||
'-- set-fail-mode %s %s ' % ( self, self.failMode ) +
|
'-- set-fail-mode %s %s ' % ( self, self.failMode ) +
|
||||||
@@ -1189,6 +1190,8 @@ class OVSSwitch( Switch ):
|
|||||||
'-- set-controller %s %s ' % ( self, clist ) )
|
'-- set-controller %s %s ' % ( self, clist ) )
|
||||||
# Construct ovs-vsctl commands for old versions of OVS
|
# Construct ovs-vsctl commands for old versions of OVS
|
||||||
else:
|
else:
|
||||||
|
# Annoyingly, --if-exists option seems not to work
|
||||||
|
self.cmd( 'ovs-vsctl del-br', self )
|
||||||
self.cmd( 'ovs-vsctl add-br', self )
|
self.cmd( 'ovs-vsctl add-br', self )
|
||||||
for intf in self.intfList():
|
for intf in self.intfList():
|
||||||
if not intf.IP():
|
if not intf.IP():
|
||||||
@@ -1207,7 +1210,9 @@ class OVSSwitch( Switch ):
|
|||||||
# Do it!!
|
# Do it!!
|
||||||
self.cmd( cmd )
|
self.cmd( cmd )
|
||||||
# Reconnect quickly to controllers (1s vs. 15s max_backoff)
|
# Reconnect quickly to controllers (1s vs. 15s max_backoff)
|
||||||
uuids = [ '-- set Controller %s max_backoff=1000' % uuid
|
if self.reconnectms:
|
||||||
|
uuids = [ '-- set Controller %s max_backoff=%d' %
|
||||||
|
( uuid, self.reconnectms )
|
||||||
for uuid in self.controllerUUIDs() ]
|
for uuid in self.controllerUUIDs() ]
|
||||||
if uuids:
|
if uuids:
|
||||||
self.cmd( 'ovs-vsctl', *uuids )
|
self.cmd( 'ovs-vsctl', *uuids )
|
||||||
|
|||||||
Reference in New Issue
Block a user