示例#1
0
    def test11_RTs(self):
        rt1a = RouteTarget(64512, 1)
        rt1b = RouteTarget(64512, 1)
        rt3 = RouteTarget(64512, 2)
        rt4 = RouteTarget(64513, 1)

        self.assertEqual(hash(rt1a), hash(rt1b))
        self.assertNotEqual(hash(rt1a), hash(rt3))
        self.assertNotEqual(hash(rt1a), hash(rt4))

        self.assertEqual(rt1a, rt1b)
        self.assertNotEqual(rt1a, rt3)
        self.assertNotEqual(rt1a, rt4)

        self.assertEqual(set([rt1a]), set([rt1b]))
        self.assertEqual(1, len(set([rt1a]).intersection(set([rt1b]))))
示例#2
0
    def unpack_nlri(cls, afi, safi, bgp, action, addpath):

        length = bgp[0]

        if length == 0:
            return cls(afi, safi, action, ASN(0), None), bgp[1:]

        if length < 8 * 4:
            raise Exception("incorrect RT length: %d (should be >=32,<=96)" %
                            length)

        # We are reseting the flags on the RouteTarget extended
        # community, because they do not make sense for an RTC route

        return (
            cls(
                afi,
                safi,
                action,
                ASN(unpack('!L', bgp[1:5])[0]),
                RouteTarget.unpack(
                    bytes([RTC.resetFlags(bgp[5])]) + bgp[6:13]),
            ),
            bgp[13:],
        )
示例#3
0
    def test6_SameAttributesOrderMultivalued(self):
        atts1 = Attributes()
        eComs1 = ExtendedCommunities()
        eComs1.communities.append(RouteTarget(64512, 1))
        eComs1.communities.append(Encapsulation(Encapsulation.Type.VXLAN))
        eComs1.communities.append(RouteTarget(64512, 2))
        atts1.add(eComs1)

        atts2 = Attributes()
        eComs2 = ExtendedCommunities()
        eComs2.communities.append(RouteTarget(64512, 2))
        eComs2.communities.append(RouteTarget(64512, 1))
        eComs2.communities.append(Encapsulation(Encapsulation.Type.VXLAN))
        atts2.add(eComs2)

        self.assertEqual(hash(atts1), hash(atts2))
        self.assertEqual(atts1, atts2)
示例#4
0
    def unpack(cls, afi, safi, data, addpath, nexthop, action):
        length = ord(data[0])

        if length == 0:
            return 1, cls(afi, safi, action, NoNextHop, ASN(0), None)

        # We are reseting the flags on the RouteTarget extended
        # community, because they do not make sense for an RTC route

        return 13, cls(
            afi, safi, action, nexthop, ASN(unpack('!L', data[1:5])[0]),
            RouteTarget.unpack(RTC.resetFlags(data[5]) + data[6:13]))
示例#5
0
    def unpack_nlri(cls, afi, safi, bgp, action, addpath):

        length = ord(bgp[0])

        if length == 0:
            return 1, cls(afi, safi, action, ASN(0), None)

        # We are reseting the flags on the RouteTarget extended
        # community, because they do not make sense for an RTC route

        return cls(afi, safi, action, ASN(unpack('!L', bgp[1:5])[0]),
                   RouteTarget.unpack(RTC.resetFlags(bgp[5]) +
                                      bgp[6:13])), bgp[13:]
示例#6
0
    def test10_Ecoms(self):
        eComs1 = ExtendedCommunities()
        eComs1.communities.append(Encapsulation(Encapsulation.Type.VXLAN))
        atts1 = Attributes()
        atts1.add(eComs1)

        eComs2 = ExtendedCommunities()
        eComs2.communities.append(Encapsulation(Encapsulation.Type.VXLAN))
        eComs2.communities.append(RouteTarget(64512, 1))
        atts2 = Attributes()
        atts2.add(eComs2)

        self.assertFalse(atts1.sameValuesAs(atts2))
        self.assertFalse(atts2.sameValuesAs(atts1))
示例#7
0
文件: rtc.py 项目: tomwalsh/exabgp
	def unpack (cls, afi, safi, data, addpath, nexthop, action):
		length = ord(data[0])

		if length == 0:
			return 1,cls(afi,safi,action,NoNextHop,ASN(0),None)

		# XXX: Why are we reseting the flags on the RouteTarget extended community ?

		return 13,cls(
			afi, safi, action, nexthop,
			ASN(unpack('!L', data[1:5])[0]),
			RouteTarget.unpack(
				RTC.resetFlags(data[5])+data[6:13]
			)
		)
示例#8
0
文件: rtc.py 项目: earies/exabgp
	def unpack (cls, afi, safi, data, addpath, nexthop, action):
		length = ord(data[0])

		if length == 0:
			return 1,cls(afi,safi,action,NoNextHop,ASN(0),None)

		# We are reseting the flags on the RouteTarget extended
		# community, because they do not make sense for an RTC route

		return 13,cls(
			afi, safi, action, nexthop,
			ASN(unpack('!L', data[1:5])[0]),
			RouteTarget.unpack(
				RTC.resetFlags(data[5])+data[6:13]
			)
		)
示例#9
0
文件: rtc.py 项目: qz267/exabgp
	def unpack_nlri (cls, afi, safi, bgp, action, addpath):

		length = ord(bgp[0])

		if length == 0:
			return 1,cls(afi,safi,action,ASN(0),None)

		# We are reseting the flags on the RouteTarget extended
		# community, because they do not make sense for an RTC route

		return cls(
			afi, safi, action,
			ASN(unpack('!L', bgp[1:5])[0]),
			RouteTarget.unpack(
				RTC.resetFlags(bgp[5])+bgp[6:13]
			)
		),bgp[13:]
示例#10
0
文件: rtc.py 项目: CadeLaRen/exabgp
	def unpack_nlri (cls, afi, safi, bgp, action, addpath):

		length = ord(bgp[0])

		if length == 0:
			return cls(afi,safi,action,ASN(0),None),bgp[1:]

		if length < 8*4:
			raise Exception("incorrect RT lenght: %d (should be >=32,<=96)" % length)

		# We are reseting the flags on the RouteTarget extended
		# community, because they do not make sense for an RTC route

		return cls(
			afi, safi, action,
			ASN(unpack('!L', bgp[1:5])[0]),
			RouteTarget.unpack(
				RTC.resetFlags(bgp[5])+bgp[6:13]
			)
		),bgp[13:]
示例#11
0
    def test99_RTCCreatePackUnpack(self):
        '''Test pack/unpack for RTC routes'''

        nlri = RTC.new(AFI.ipv4, SAFI.rtc, 64512, RouteTarget(64577, 123))

        packed = nlri.pack()
        unpacked, leftover = RTC.unpack_nlri(AFI.ipv4, SAFI.mpls_vpn, packed,
                                             OUT.UNSET, None)

        self.assertEqual(0, len(leftover))

        # TODO: compare packed with a reference encoding verified
        # as conformant with RFC4684

        self.assertTrue(isinstance(unpacked, RTC))

        self.assertEqual(64512, unpacked.origin)

        self.assertTrue(isinstance(unpacked.rt, RouteTarget))
        self.assertEqual(64577, unpacked.rt.asn)
        self.assertEqual(123, unpacked.rt.number)
示例#12
0
 def test12_RTRecord(self):
     rt = RouteTarget(64512, 22)
     rt_record = RTRecord.from_rt(rt)