def construct(cls, value, iswithdraw=False): # rd value_hex = b'' value_hex += MPLSVPN.construct_rd(value['rd']) # esi value_hex += b'\x00\x00' + struct.pack('!d', value['esi']) # ethernet tag value_hex += struct.pack('!I', value['eth_tag_id']) value_hex += MPLSVPN.construct_mpls_label_stack(value['label']) return value_hex
def construct(cls, data): # rd data_hex = b'' data_hex += MPLSVPN.construct_rd(data['rd']) # esi data_hex += b'\x00\x00' + struct.pack('!d', data['esi']) # ethernet tag data_hex += struct.pack('!I', data['eth_tag_id']) data_hex += MPLSVPN.construct_mpls_label_stack(data['label']) return data_hex
def construct(cls, data): # rd data_hex = b'' data_hex += MPLSVPN.construct_rd(data['rd']) # esi data_hex += b'\x00\x00' + struct.pack('!d', data['esi']) # ethernet tag data_hex += struct.pack('!I', data['eth_tag_id']) # mac address len and address mac_hex = b''.join([struct.pack('!B', (int(i, 16))) for i in data['mac'].split("-")]) data_hex += struct.pack('!B', len(mac_hex) * 8) + mac_hex # ip address len and address if data.get('ip'): ip_hex = netaddr.IPAddress(data['ip']).packed data_hex += struct.pack('!B', len(ip_hex) * 8) + ip_hex else: data_hex += b'\x00' if data.get('label'): data_hex += MPLSVPN.construct_mpls_label_stack(data['label']) return data_hex
def construct(cls, value, iswithdraw=False): # rd value_hex = b'' value_hex += MPLSVPN.construct_rd(value['rd']) # esi value_hex += b'\x00\x00' + struct.pack('!d', value['esi']) # ethernet tag value_hex += struct.pack('!I', value['eth_tag_id']) # mac address len and address mac_hex = b''.join([struct.pack('!B', (int(i, 16))) for i in value['mac'].split("-")]) value_hex += struct.pack('!B', len(mac_hex) * 8) + mac_hex # ip address len and address if value.get('ip'): ip_hex = netaddr.IPAddress(value['ip']).packed value_hex += struct.pack('!B', len(ip_hex) * 8) + ip_hex else: value_hex += b'\x00' if value.get('label'): value_hex += MPLSVPN.construct_mpls_label_stack(value['label']) return value_hex
def construct(cls, value, iswithdraw=False): # rd value_hex = b'' value_hex += MPLSVPN.construct_rd(value['rd']) # esi value_hex += b'\x00\x00' + struct.pack('!d', value['esi']) # ethernet tag value_hex += struct.pack('!I', value['eth_tag_id']) # mac address len and address mac_hex = b''.join( [struct.pack('!B', (int(i, 16))) for i in value['mac'].split("-")]) value_hex += struct.pack('!B', len(mac_hex) * 8) + mac_hex # ip address len and address if value.get('ip'): ip_hex = netaddr.IPAddress(value['ip']).packed value_hex += struct.pack('!B', len(ip_hex) * 8) + ip_hex else: value_hex += b'\x00' if value.get('label'): value_hex += MPLSVPN.construct_mpls_label_stack(value['label']) return value_hex
def construct(cls, data): # rd data_hex = b'' data_hex += MPLSVPN.construct_rd(data['rd']) # esi data_hex += b'\x00\x00' + struct.pack('!d', data['esi']) # ethernet tag data_hex += struct.pack('!I', data['eth_tag_id']) # mac address len and address mac_hex = b''.join( [struct.pack('!B', (int(i, 16))) for i in data['mac'].split("-")]) data_hex += struct.pack('!B', len(mac_hex) * 8) + mac_hex # ip address len and address if data.get('ip'): ip_hex = netaddr.IPAddress(data['ip']).packed data_hex += struct.pack('!B', len(ip_hex) * 8) + ip_hex else: data_hex += b'\x00' if data.get('label'): data_hex += MPLSVPN.construct_mpls_label_stack(data['label']) return data_hex
def test_construct_mpls_label_stack(self): label_bin = b'\x00\x01\x41' self.assertEqual(label_bin, MPLSVPN.construct_mpls_label_stack(labels=[20]))