Example #1
0
    def test99_EVPNMACCreatePackUnpack(self):
        '''Test pack/unpack for E-VPN MAC routes'''
        nlri = EVPNMAC(RouteDistinguisher.fromElements("42.42.42.42",
                                                       5), ESI(),
                       EthernetTag(111), MAC("01:02:03:04:05:06"), 6 * 8,
                       Labels([42], True), IP.create("1.1.1.1"))

        packed = nlri.pack()

        unpacked, leftover = EVPN.unpack_nlri(AFI(AFI.l2vpn), SAFI(SAFI.evpn),
                                              packed, OUT.UNSET, None)

        self.assertEqual(0, len(leftover))

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

        self.assertTrue(isinstance(unpacked, EVPNMAC))

        self.assertEqual("42.42.42.42:5", unpacked.rd._str())
        self.assertEqual(ESI.DEFAULT, unpacked.esi.esi)
        self.assertEqual(EthernetTag(111), unpacked.etag)
        self.assertEqual(MAC("01:02:03:04:05:06"), unpacked.mac)

        self.assertEqual(IP.create("1.1.1.1"), unpacked.ip)

        self.assertEqual(1, len(unpacked.label.labels))
        self.assertEqual(42, unpacked.label.labels[0])
Example #2
0
    def test0_IPVPNHashEqual(self):
        '''
        Two indistinct VPN NLRIs should
        hash to the same value, and be equal
        '''
        rd = RouteDistinguisher.fromElements("42.42.42.42", 5)

        packedPrefix, mask = prefixToPackedIPMask("1.1.1.1/32")

        nlri1 = IPVPN.new(AFI(AFI.ipv4), SAFI(SAFI.mpls_vpn),
                          packedPrefix, mask, Labels([42], True), rd,
                          IP.pton("45.45.45.45"), OUT.ANNOUNCE)

        nlri2 = IPVPN.new(AFI(AFI.ipv4), SAFI(SAFI.mpls_vpn),
                          packedPrefix, mask, Labels([42], True), rd,
                          IP.pton("45.45.45.45"), OUT.ANNOUNCE)

        self.assertEqual(hash(nlri1), hash(nlri2))
        self.assertEqual(nlri1, nlri2)
Example #3
0
    def test98_RTCWildcardPackUnpack(self):
        '''Test pack/unpack for RTC routes'''

        nlri = RTC.new(AFI(AFI.ipv4), SAFI(SAFI.rtc), 0, None)

        packed = nlri.pack()
        unpacked, leftover = RTC.unpack_nlri(AFI(AFI.ipv4),
                                             SAFI(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(0, unpacked.origin)

        self.assertIsNone(unpacked.rt)
Example #4
0
    def test2_IPVPNHashEqual(self):
        '''
        Two VPN NLRI distinct only by their *nexthop* should
        hash to the same value, and be equal
        '''
        packedPrefix, mask = prefixToPackedIPMask("1.1.1.1/32")

        nlri1 = IPVPN.new(AFI(AFI.ipv4), SAFI(SAFI.mpls_vpn), packedPrefix,
                          mask, Labels([42], True),
                          RouteDistinguisher.fromElements("42.42.42.42", 5),
                          IP.pton("45.45.45.45"), OUT.ANNOUNCE)

        nlri2 = IPVPN.new(AFI(AFI.ipv4), SAFI(SAFI.mpls_vpn), packedPrefix,
                          mask, Labels([42], True),
                          RouteDistinguisher.fromElements("42.42.42.42", 5),
                          IP.pton("77.77.77.77"), OUT.ANNOUNCE)

        self.assertEqual(hash(nlri1), hash(nlri2))
        self.assertTrue(nlri1.eq(nlri2))
        self.assertNotEqual(nlri1, nlri2)
Example #5
0
    def test200_IPVPNCreatePackUnpack(self):
        '''Test pack/unpack for IPVPN routes'''
        nlri = IPVPN.new(AFI(AFI.ipv4), SAFI(SAFI.mpls_vpn),
                         IP.pton("1.2.3.0"), 24, Labels([42], True),
                         RouteDistinguisher.fromElements("42.42.42.42", 5))

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

        self.assertEqual(0, len(leftover))

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

        self.assertTrue(isinstance(unpacked, IPVPN))

        self.assertEqual("1.2.3.0/24", unpacked.cidr.prefix())
        self.assertEqual(1, len(unpacked.labels.labels))
        self.assertEqual(42, unpacked.labels.labels[0])
        self.assertEqual("42.42.42.42:5", unpacked.rd._str())
Example #6
0
    def test99_RTCCreatePackUnpack(self):
        '''Test pack/unpack for RTC routes'''

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

        packed = nlri.pack()
        unpacked, leftover = RTC.unpack_nlri(AFI(AFI.ipv4),
                                             SAFI(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)
Example #7
0
    def test99_EVPNMulticastCreatePackUnpack(self):
        '''Test pack/unpack for E-VPN Multicast routes'''

        nlri = EVPNMulticast(RouteDistinguisher.fromElements("42.42.42.42", 5),
                             EthernetTag(111), IP.create("1.1.1.1"))

        packed = nlri.pack()

        unpacked, leftover = EVPN.unpack_nlri(AFI(AFI.l2vpn), SAFI(SAFI.evpn),
                                              packed, OUT.UNSET, None)

        self.assertEqual(0, len(leftover))

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

        self.assertTrue(isinstance(unpacked, EVPNMulticast))

        self.assertEqual("42.42.42.42:5", unpacked.rd._str())
        self.assertEqual(EthernetTag(111), unpacked.etag)
        self.assertEqual(IP.create("1.1.1.1"), unpacked.ip)