MCPcopy Create free account
hub / github.com/mininet/mininet / defaultDpid

Method defaultDpid

mininet/node.py:933–949  ·  view source on GitHub ↗

Return correctly formatted dpid from dpid or switch name (s1 -> 1)

( self, dpid=None )

Source from the content-addressed store, hash-verified

931 self.controlIntf = Intf( 'lo', self, port=0 )
932
933 def defaultDpid( self, dpid=None ):
934 "Return correctly formatted dpid from dpid or switch name (s1 -> 1)"
935 if dpid:
936 # Remove any colons and make sure it's a good hex number
937 dpid = dpid.replace( ':', '' )
938 assert len( dpid ) <= self.dpidLen and int( dpid, 16 ) >= 0
939 else:
940 # Use hex of the first number in the switch name
941 nums = re.findall( r'\d+', self.name )
942 if nums:
943 dpid = hex( int( nums[ 0 ] ) )[ 2: ]
944 else:
945 self.terminate() # Python 3.6 crash workaround
946 raise Exception( 'Unable to derive default datapath ID - '
947 'please either specify a dpid or use a '
948 'canonical switch name such as s23.' )
949 return '0' * ( self.dpidLen - len( dpid ) ) + dpid
950
951 def defaultIntf( self ):
952 "Return control interface"

Callers 2

__init__Method · 0.95
testDefaultDpidMethod · 0.45

Calls 1

terminateMethod · 0.45

Tested by 1

testDefaultDpidMethod · 0.36