Fix default dpid which should be 12 digits for reference user switch.

This commit is contained in:
Bob Lantz
2012-05-10 22:36:20 -07:00
parent 4c3ff8f184
commit 0d94548a09
+4 -1
View File
@@ -725,6 +725,7 @@ class Switch( Node ):
an OpenFlow switch.""" an OpenFlow switch."""
portBase = 1 # Switches start with port 1 in OpenFlow portBase = 1 # Switches start with port 1 in OpenFlow
dpidLen = 16 # digits in dpid passed to switch
def __init__( self, name, dpid=None, opts='', listenPort=None, **params): def __init__( self, name, dpid=None, opts='', listenPort=None, **params):
"""dpid: dpid for switch (or None to derive from name, e.g. s1 -> 1) """dpid: dpid for switch (or None to derive from name, e.g. s1 -> 1)
@@ -742,7 +743,7 @@ class Switch( Node ):
try: try:
dpid = int( re.findall( '\d+', self.name )[ 0 ] ) dpid = int( re.findall( '\d+', self.name )[ 0 ] )
dpid = hex( dpid )[ 2: ] dpid = hex( dpid )[ 2: ]
dpid = '0' * ( 16 - len( dpid ) ) + dpid dpid = '0' * ( self.dpidLen - len( dpid ) ) + dpid
return dpid return dpid
except IndexError: except IndexError:
raise Exception( 'Unable to derive default datapath ID - ' raise Exception( 'Unable to derive default datapath ID - '
@@ -776,6 +777,8 @@ class Switch( Node ):
class UserSwitch( Switch ): class UserSwitch( Switch ):
"User-space switch." "User-space switch."
dpidLen = 12
def __init__( self, name, **kwargs ): def __init__( self, name, **kwargs ):
"""Init. """Init.
name: name for the switch""" name: name for the switch"""