コード例 #1
0
ファイル: test_mpls_vpn.py プロジェクト: c0ns0le/yabgp
 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))
コード例 #2
0
ファイル: evpn.py プロジェクト: c0ns0le/yabgp
 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
コード例 #3
0
ファイル: evpn.py プロジェクト: gautamgitspace/yabgp
 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
コード例 #4
0
ファイル: evpn.py プロジェクト: gautamgitspace/yabgp
 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
コード例 #5
0
ファイル: evpn.py プロジェクト: c0ns0le/yabgp
 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
コード例 #6
0
ファイル: evpn.py プロジェクト: c0ns0le/yabgp
 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
コード例 #7
0
ファイル: evpn.py プロジェクト: xinwu/yabgp
 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
コード例 #8
0
ファイル: evpn.py プロジェクト: c0ns0le/yabgp
 def construct(cls, data):
     # rd
     data_hex = b''
     data_hex += MPLSVPN.construct_rd(data['rd'])
     data_hex += struct.pack('!I', data['eth_tag_id'])
     # 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'
     return data_hex
コード例 #9
0
ファイル: evpn.py プロジェクト: xinwu/yabgp
 def construct(cls, value, iswithdraw=False):
     # rd
     value_hex = b''
     value_hex += MPLSVPN.construct_rd(value['rd'])
     value_hex += struct.pack('!I', value['eth_tag_id'])
     # 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'
     return value_hex
コード例 #10
0
ファイル: evpn.py プロジェクト: c0ns0le/yabgp
 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
コード例 #11
0
ファイル: evpn.py プロジェクト: gautamgitspace/yabgp
 def construct(cls, value, iswithdraw=False):
     # rd
     value_hex = b''
     value_hex += MPLSVPN.construct_rd(value['rd'])
     value_hex += struct.pack('!I', value['eth_tag_id'])
     # 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'
     return value_hex
コード例 #12
0
 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'])
     # 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'
     return data_hex
コード例 #13
0
ファイル: evpn.py プロジェクト: c0ns0le/yabgp
 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
コード例 #14
0
 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
コード例 #15
0
 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
コード例 #16
0
 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
コード例 #17
0
ファイル: evpn.py プロジェクト: c0ns0le/yabgp
 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
コード例 #18
0
ファイル: test_mpls_vpn.py プロジェクト: zhangqi887/yabgp
    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))
コード例 #19
0
ファイル: test_mpls_vpn.py プロジェクト: c0ns0le/yabgp
 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))
コード例 #20
0
ファイル: test_mpls_vpn.py プロジェクト: c0ns0le/yabgp
    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))
コード例 #21
0
ファイル: test_mpls_vpn.py プロジェクト: c0ns0le/yabgp
 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))
コード例 #22
0
ファイル: test_mpls_vpn.py プロジェクト: zhangqi887/yabgp
 def test_construct_mpls_label_stack(self):
     label_bin = b'\x00\x01\x41'
     self.assertEqual(label_bin,
                      MPLSVPN.construct_mpls_label_stack(labels=[20]))
コード例 #23
0
ファイル: test_mpls_vpn.py プロジェクト: zhangqi887/yabgp
 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))
コード例 #24
0
ファイル: test_mpls_vpn.py プロジェクト: c0ns0le/yabgp
 def test_construct_mpls_label_stack(self):
     label_bin = b'\x00\x01\x41'
     self.assertEqual(label_bin, MPLSVPN.construct_mpls_label_stack(labels=[20]))
コード例 #25
0
ファイル: test_mpls_vpn.py プロジェクト: zhangqi887/yabgp
 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))