コード例 #1
0
 def test_construct_invalid_nexthop(self):
     # invalid next hop
     self.assertRaises(UpdateMessageError, NextHop.construct, '300.1.1')
     try:
         NextHop.construct(value='300.33.33.33')
     except UpdateMessageError as e:
         self.assertEqual(e.sub_error, ERR_MSG_UPDATE_INVALID_NEXTHOP)
コード例 #2
0
ファイル: test_nexthop.py プロジェクト: jumeng/yabgp
class TestNextHop(unittest.TestCase):

    def setUp(self):

        self.nexthop = NextHop()

    def tearDown(self):

        del self.nexthop

    def test_parse(self):

        next_hop = self.nexthop.parse(value='\x0a\x0a\x0a\x01')
        self.assertEqual(next_hop, '10.10.10.1')
        self.assertEqual(self.nexthop.parse(value='\x00\x00\x00\x00'), '0.0.0.0')
        self.assertEqual(self.nexthop.parse(value='\xff\xff\xff\xff'), '255.255.255.255')

    def test_parse_invalid_length(self):
        # invalid length
        self.assertRaises(UpdateMessageError, self.nexthop.parse,
                          '\x0a\x0a\x0a\x01\x01')
        try:
            self.nexthop.parse('\x0a\x0a\x0a\x01\x01')
        except UpdateMessageError as e:
            self.assertEqual(e.sub_error, ERR_MSG_UPDATE_ATTR_LEN)

    def test_construct(self):

        next_hop = self.nexthop.construct(value='10.10.10.1')
        self.assertEqual(next_hop, '\x40\x03\x04\x0a\x0a\x0a\x01')
        self.assertEqual(self.nexthop.construct('0.0.0.0'), '\x40\x03\x04\x00\x00\x00\x00')

    def test_construct_invalid_nexthop(self):
        # invalid next hop
        self.assertRaises(UpdateMessageError, self.nexthop.construct, '300.1.1')
        try:
            self.nexthop.construct(value='300.33.33.33')
        except UpdateMessageError as e:
            self.assertEqual(e.sub_error, ERR_MSG_UPDATE_INVALID_NEXTHOP)

    def test_construct_with_flags(self):
        nexthop = self.nexthop.construct(value='10.10.10.10')
        self.assertEqual(nexthop, '\x40\x03\x04\x0a\x0a\x0a\x0a')
コード例 #3
0
ファイル: update.py プロジェクト: jack8daniels2/yabgp
    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

        return attr_raw_hex
コード例 #4
0
ファイル: update.py プロジェクト: jack8daniels2/yabgp
    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

        return attr_raw_hex
コード例 #5
0
 def test_construct_with_flags(self):
     nexthop = NextHop.construct(value='10.10.10.10')
     self.assertEqual(nexthop, b'\x40\x03\x04\x0a\x0a\x0a\x0a')
コード例 #6
0
    def test_construct(self):

        next_hop = NextHop.construct(value='10.10.10.1')
        self.assertEqual(next_hop, b'\x40\x03\x04\x0a\x0a\x0a\x01')
        self.assertEqual(NextHop.construct('0.0.0.0'), b'\x40\x03\x04\x00\x00\x00\x00')
コード例 #7
0
ファイル: update.py プロジェクト: zhangqi887/yabgp
    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