def parse(cls, data): route = dict() offset = 8 route['rd'] = MPLSVPN.parse_rd(data[0:offset]) route['eth_tag_id'] = struct.unpack('!I', data[offset: offset+4])[0] offset += 4 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+ip_addr_len / 8]), 16))) return route
def parse(cls, data): route = dict() offset = 8 route['rd'] = MPLSVPN.parse_rd(data[0:offset]) # esi route['esi'] = int(binascii.b2a_hex(data[offset: offset+10]), 16) offset += 10 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+ip_addr_len / 8]), 16))) return route
def parse(cls, value, iswithdraw=False): route = dict() offset = 8 route['rd'] = MPLSVPN.parse_rd(value[0:offset]) route['eth_tag_id'] = struct.unpack('!I', value[offset:offset + 4])[0] offset += 4 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:int(offset + ip_addr_len / 8)]), 16))) return route
def parse(cls, data): route = dict() offset = 8 route['rd'] = MPLSVPN.parse_rd(data[0:offset]) route['eth_tag_id'] = struct.unpack('!I', data[offset:offset + 4])[0] offset += 4 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 + ip_addr_len / 8]), 16))) return route
def parse(cls, value, iswithdraw=False): route = dict() offset = 8 route['rd'] = MPLSVPN.parse_rd(value[0:offset]) # esi route['esi'] = int(binascii.b2a_hex(value[offset:offset + 10]), 16) offset += 10 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 + ip_addr_len / 8]), 16))) return route
def test_parse_and_construct_rd_type2(self): rd_bin = b'\x00\x02\x00\x01\x00\x00\x00\x02' rd_parsed = '65536:2' self.assertEqual(rd_parsed, MPLSVPN.parse_rd(rd_bin)) self.assertEqual(rd_bin, MPLSVPN.construct_rd(rd_parsed))
def test_parse_and_construct_rd_type1(self): rd_bin = b'\x00\x01\xac\x11\x00\x03\x00\x02' rd_parsed = '172.17.0.3:2' self.assertEqual(rd_parsed, MPLSVPN.parse_rd(rd_bin)) self.assertEqual(rd_bin, MPLSVPN.construct_rd(rd_parsed))
def test_parse_and_construct_rd_type0(self): # for rd type 0 rd_bin = b'\x00\x00\xfd\xea\x00\x00\x00\x01' rd_parsed = '65002:1' self.assertEqual(rd_parsed, MPLSVPN.parse_rd(rd_bin)) self.assertEqual(rd_bin, MPLSVPN.construct_rd(rd_parsed))