Return correctly formatted dpid from dpid or switch name (s1 -> 1)
( self, dpid=None )
| 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" |