def test_parse_mpls_label_stack(self): label_bin = b'\x00\x01\x41' self.assertEqual([20], MPLSVPN.parse_mpls_label_stack(label_bin)) label_bin = b'\x00\x01\x10\x00\x01\x31' self.assertEqual([17, 19], MPLSVPN.parse_mpls_label_stack(label_bin)) label_bin = b'\x80\x00\x00' self.assertEqual([524288], MPLSVPN.parse_mpls_label_stack(label_bin))
def parse(cls, value, iswithdraw=False): route = dict() # rd offset = 8 route['rd'] = cls.parse_rd(value[0:offset]) # esi route['esi'] = int(binascii.b2a_hex(value[offset:offset + 10]), 16) offset += 10 # ethernet tag id route['eth_tag_id'] = struct.unpack('!I', value[offset:offset + 4])[0] offset += 5 # mac address route['mac'] = str( netaddr.EUI(int(binascii.b2a_hex(value[offset:offset + 6]), 16))) offset += 6 ip_addr_len = ord(value[offset:offset + 1]) offset += 1 # ip address if ip_addr_len != 0: route['ip'] = str( netaddr.IPAddress( int( binascii.b2a_hex(value[offset:offset + int(ip_addr_len / 8)]), 16))) offset += int(ip_addr_len / 8) # label route['label'] = MPLSVPN.parse_mpls_label_stack(value[offset:]) return route
def parse(cls, data): route = dict() route['rd'] = cls.parse_rd(data[0:8]) offset = 8 route['esi'] = int(binascii.b2a_hex(data[offset: offset+10]), 16) offset += 10 # ethernet tag id route['eth_tag_id'] = struct.unpack('!I', data[offset: offset+4])[0] offset += 4 route['label'] = MPLSVPN.parse_mpls_label_stack(data[offset:]) return route
def parse(cls, value, iswithdraw=False): route = dict() route['rd'] = cls.parse_rd(value[0:8]) offset = 8 route['esi'] = int(binascii.b2a_hex(value[offset:offset + 10]), 16) offset += 10 # ethernet tag id route['eth_tag_id'] = struct.unpack('!I', value[offset:offset + 4])[0] offset += 4 route['label'] = MPLSVPN.parse_mpls_label_stack(value[offset:]) return route
def parse(cls, data): route = dict() # rd offset = 8 route['rd'] = cls.parse_rd(data[0:offset]) # esi route['esi'] = int(binascii.b2a_hex(data[offset: offset+10]), 16) offset += 10 # ethernet tag id route['eth_tag_id'] = struct.unpack('!I', data[offset: offset+4])[0] offset += 5 # mac address route['mac'] = str(netaddr.EUI(int(binascii.b2a_hex(data[offset: offset+6]), 16))) offset += 6 ip_addr_len = ord(data[offset: offset + 1]) offset += 1 # ip address if ip_addr_len != 0: route['ip'] = str(netaddr.IPAddress(int(binascii.b2a_hex(data[offset: offset + int(ip_addr_len / 8)]), 16))) offset += int(ip_addr_len / 8) # label route['label'] = MPLSVPN.parse_mpls_label_stack(data[offset:]) return route