示例#1
0
 def test_construct_segement_lists(self):
     data_dict = {
         "0":
         "old",
         "128": [{
             "9":
             10,
             "1": [{
                 "1": {
                     "label": 2000
                 }
             }, {
                 "3": {
                     "node": "10.1.1.1",
                     "SID": {
                         "label": 2000,
                         "TC": 0,
                         "S": 0,
                         "TTL": 255
                     }
                 }
             }]
         }]
     }
     data_hex_1 = b'\x80\x00\x1d\x00\x09\x06\x00\x00\x00\x00\x00\x0a\x01\x06\x00\x00\x00\x7d\x00' \
                  b'\xff\x03\x0a\x00\x00\x0a\x01\x01\x01\x00\x7d\x00\xff\x07\x02\x00\x00'
     data_hex_2 = b'\x07\x02\x00\x00\x80\x00\x1d\x00\x09\x06\x00\x00\x00\x00\x00\x0a\x01\x06\x00' \
                  b'\x00\x00\x7d\x00\xff\x03\x0a\x00\x00\x0a\x01\x01\x01\x00\x7d\x00\xff'
     self.assertTrue(
         TunnelEncaps.construct(data_dict)[7:] in [data_hex_1, data_hex_2])
示例#2
0
 def test_construct_weight(self):
     data_dict = {"9": 10, "1": []}
     segment_list = dict([(int(l), r) for (l, r) in data_dict.items()])
     weight_hex = b'\x09\x06\x00\x00\x00\x00\x00\x0a'
     sid_hex = b''
     self.assertEqual((weight_hex, sid_hex),
                      TunnelEncaps.construct_weight_and_seg(segment_list))
示例#3
0
 def test_construct_remote_endpoint_ipv4(self):
     data_dict = {
         "0": "new",
         "6": {
             "asn": 300,
             'afi': 'ipv4',
             'address': '1.1.1.1'
         }
     }
     data_hex = b'\x06\x0a\x00\x00\x01\x2c\x00\x01\x01\x01\x01\x01'
     self.assertEqual(data_hex, TunnelEncaps.construct(data_dict)[12:])
示例#4
0
 def test_construct_remote_endpoint_ipv6(self):
     data_dict = {
         "0": "new",
         "6": {
             "asn": 300,
             'afi': 'ipv6',
             'address': 'ABCD:EF01:2345:6789:ABCD:EF01:2345:6789'
         }
     }
     data_hex = b'\x06\x16\x00\x00\x01\x2c\x00\x02\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef' \
                b'\x01\x23\x45\x67\x89'
     self.assertEqual(data_hex, TunnelEncaps.construct(data_dict)[12:])
示例#5
0
 def test_construct_seg(self):
     data_dict = {
         "1": [{
             "1": {
                 "label": 2000
             }
         }, {
             "3": {
                 "node": "10.1.1.1",
                 "SID": {
                     "label": 2000,
                     "TC": 0,
                     "S": 0,
                     "TTL": 255
                 }
             }
         }]
     }
     segment_list = dict([(int(l), r) for (l, r) in data_dict.items()])
     weight_hex = b''
     sid_hex = b'\x01\x06\x00\x00\x00\x7d\x00\xff\x03\x0a\x00\x00\x0a\x01\x01\x01\x00\x7d\x00\xff'
     self.assertEqual((weight_hex, sid_hex),
                      TunnelEncaps.construct_weight_and_seg(segment_list))
示例#6
0
 def test_construct_new_preference(self):
     data_dict = {"0": "new", "12": 100}
     data_hex = b'\x0c\x06\x00\x00\x00\x00\x00\x64'
     self.assertEqual(data_hex, TunnelEncaps.construct(data_dict)[7:15])
示例#7
0
 def test_construct_new_binding_sid(self):
     data_dict = {"0": "new", "13": 25102}
     data_hex = b'\x0d\x06\x00\x00\x06\x20\xe0\x00'
     self.assertEqual(data_hex, TunnelEncaps.construct(data_dict)[7:])
示例#8
0
 def test_construct_old_binding_sid(self):
     data_dict = {"0": "old", "7": 25102}
     data_hex = b'\x07\x06\x00\x00\x06\x20\xe0\x00'
     self.assertEqual(data_hex, TunnelEncaps.construct(data_dict)[7:])
示例#9
0
 def test_construct_optional_label_sid(self):
     option_sid = 16384255
     data_dict = {"label": 4000, "TC": 0, "S": 0, "TTL": 255}
     self.assertEqual(option_sid,
                      TunnelEncaps.construct_optional_label_sid(data_dict))
示例#10
0
 def test_construct_old_preference(self):
     data_dict = {"0": "old", "6": 100}
     data_hex = b'\x06\x06\x00\x00\x00\x00\x00\x64'
     self.assertEqual(data_hex, TunnelEncaps.construct(data_dict)[8:16])
示例#11
0
    def construct_attributes(attr_dict, asn4=False):
        """
        construts BGP Update attirubte.

        :param attr_dict: bgp attribute dictionary
        :param asn4: support 4 bytes asn or not
        """
        attr_raw_hex = b''
        for type_code, value in attr_dict.items():
            if type_code == bgp_cons.BGPTYPE_ORIGIN:
                origin_hex = Origin.construct(value=value)
                attr_raw_hex += origin_hex

            elif type_code == bgp_cons.BGPTYPE_AS_PATH:
                aspath_hex = ASPath.construct(value=value, asn4=asn4)
                attr_raw_hex += aspath_hex

            elif type_code == bgp_cons.BGPTYPE_NEXT_HOP:
                nexthop_hex = NextHop.construct(value=value)
                attr_raw_hex += nexthop_hex

            elif type_code == bgp_cons.BGPTYPE_MULTI_EXIT_DISC:
                med_hex = MED.construct(value=value)
                attr_raw_hex += med_hex

            elif type_code == bgp_cons.BGPTYPE_LOCAL_PREF:
                localpre_hex = LocalPreference.construct(value=value)
                attr_raw_hex += localpre_hex

            elif type_code == bgp_cons.BGPTYPE_ATOMIC_AGGREGATE:
                atomicaggregate_hex = AtomicAggregate.construct(value=value)
                attr_raw_hex += atomicaggregate_hex

            elif type_code == bgp_cons.BGPTYPE_AGGREGATOR:
                aggregator_hex = Aggregator.construct(value=value, asn4=asn4)
                attr_raw_hex += aggregator_hex

            elif type_code == bgp_cons.BGPTYPE_COMMUNITIES:
                community_hex = Community.construct(value=value)
                attr_raw_hex += community_hex

            elif type_code == bgp_cons.BGPTYPE_ORIGINATOR_ID:
                originatorid_hex = OriginatorID.construct(value=value)
                attr_raw_hex += originatorid_hex

            elif type_code == bgp_cons.BGPTYPE_CLUSTER_LIST:
                clusterlist_hex = ClusterList.construct(value=value)
                attr_raw_hex += clusterlist_hex

            elif type_code == bgp_cons.BGPTYPE_MP_REACH_NLRI:
                mpreach_hex = MpReachNLRI().construct(value=value)
                attr_raw_hex += mpreach_hex
            elif type_code == bgp_cons.BGPTYPE_MP_UNREACH_NLRI:
                mpunreach_hex = MpUnReachNLRI.construct(value=value)
                attr_raw_hex += mpunreach_hex
            elif type_code == bgp_cons.BGPTYPE_EXTENDED_COMMUNITY:
                community_ext_hex = ExtCommunity.construct(value=value)
                attr_raw_hex += community_ext_hex
            elif type_code == bgp_cons.BGPTYPE_PMSI_TUNNEL:
                evpn_overlay = EVPN.signal_evpn_overlay(attr_dict)
                attr_raw_hex += PMSITunnel.construct(value=value,
                                                     evpn_overlay=evpn_overlay)
            elif type_code == bgp_cons.BGPTYPE_TUNNEL_ENCAPS_ATTR:
                tunnelencap_hex = TunnelEncaps.construct(value=value)
                attr_raw_hex += tunnelencap_hex
            elif type_code == bgp_cons.BGPTYPE_LARGE_COMMUNITY:
                large_community_ext_hex = LargeCommunity.construct(value=value)
                attr_raw_hex += large_community_ext_hex

        return attr_raw_hex
示例#12
0
 def test_construct_policy_name(self):
     data_dict = {"0": "new", "129": "test"}
     data_hex = data_hex = b'\x81\x00\x05\x00\x74\x65\x73\x74'
     self.assertEqual(data_hex, TunnelEncaps.construct(data_dict)[12:])
示例#13
0
 def test_construct_priority(self):
     data_dict = {"0": "new", "15": 200}
     data_hex = data_hex = b'\x0f\x02\xc8\x00'
     self.assertEqual(data_hex, TunnelEncaps.construct(data_dict)[12:])
示例#14
0
 def test_construct_enlp(self):
     data_dict = {"0": "new", "14": 1}
     data_hex = b'\x0e\x03\x00\x00\x01'
     self.assertEqual(data_hex, TunnelEncaps.construct(data_dict)[12:])