def test_100_evpn_mac_hash_equal(self):
        # Two indistinct EVPN NLRI should
        # hash to the same value, and be equal

        nlri1 = exa.EVPNMAC(TEST_RD, exa.ESI(), exa.EthernetTag(111),
                            exa.MAC("01:02:03:04:05:06"), 6 * 8,
                            exa.Labels([42], True), exa.IP.create("1.1.1.1"))

        nlri2 = exa.EVPNMAC(TEST_RD, exa.ESI(), exa.EthernetTag(111),
                            exa.MAC("01:02:03:04:05:06"), 6 * 8,
                            exa.Labels([42], True), exa.IP.create("1.1.1.1"))

        self.assertEqual(hash(nlri1), hash(nlri2))
        self.assertEqual(nlri1, nlri2)
Exemple #2
0
    def generate_vif_bgp_route(self, mac_address, ip_prefix, plen, label, rd):
        # Generate BGP route and advertise it...

        if ip_prefix:
            assert (plen == 32)

        if self._vxlan_dp_driver():
            mpls_label_field = exa.Labels([], raw_labels=[self.instance_label])
        else:
            mpls_label_field = exa.Labels([self.instance_label])

        # label parameter ignored, we need to use instance label
        nlri = exa.EVPNMAC(rd, exa.ESI(), exa.EthernetTag(),
                           exa.MAC(mac_address), 6 * 8, mpls_label_field,
                           exa.IP.create(ip_prefix) if ip_prefix else None,
                           None,
                           exa.IP.create(self.dp_driver.get_local_address()))

        return engine.RouteEntry(nlri)
    def generate_vif_bgp_route(self, mac_address, ip_prefix, plen, label, rd):
        # Generate BGP route and advertise it...

        assert(plen == 32)

        # label parameter ignored, we need to use instance label
        nlri = exa.EVPNMAC(
            rd, exa.ESI(), exa.EthernetTag(), exa.MAC(mac_address), 6*8,
            exa.Labels([self.instance_label]),
            exa.IP.create(ip_prefix), None,
            exa.IP.create(self.dp_driver.get_local_address()))

        return engine.RouteEntry(nlri)
    def test_101_evpn_hash_equal_somefieldsvary(self):
        # Two EVPN MAC NLRIs differing by their ESI or label or RD,
        # or nexthop, but otherwise identical should hash to the same value,
        # and be equal

        nlri0 = exa.EVPNMAC(TEST_RD, exa.ESI(), exa.EthernetTag(111),
                            exa.MAC("01:02:03:04:05:06"), 6 * 8,
                            exa.Labels([42], True), exa.IP.create("1.1.1.1"))

        # Esi
        nlri1 = exa.EVPNMAC(
            TEST_RD, exa.ESI(b''.join(six.int2byte(1) for _ in range(0, 10))),
            exa.EthernetTag(111), exa.MAC("01:02:03:04:05:06"), 6 * 8,
            exa.Labels([42], True), exa.IP.create("1.1.1.1"))

        # label
        nlri2 = exa.EVPNMAC(TEST_RD, exa.ESI(), exa.EthernetTag(111),
                            exa.MAC("01:02:03:04:05:06"), 6 * 8,
                            exa.Labels([4444], True), exa.IP.create("1.1.1.1"))

        # IP: different IPs, but same MACs: different route
        nlri3 = exa.EVPNMAC(TEST_RD, exa.ESI(), exa.EthernetTag(111),
                            exa.MAC("01:02:03:04:05:06"), 6 * 8,
                            exa.Labels([42], True), exa.IP.create("2.2.2.2"))

        # with a next hop...
        nlri4 = exa.EVPNMAC(TEST_RD, exa.ESI(), exa.EthernetTag(111),
                            exa.MAC("01:02:03:04:05:06"), 6 * 8,
                            exa.Labels([42], True), exa.IP.create("1.1.1.1"),
                            exa.IP.pton("10.10.10.10"))
        nlri5 = exa.EVPNMAC(TEST_RD, exa.ESI(), exa.EthernetTag(111),
                            exa.MAC("01:02:03:04:05:06"), 6 * 8,
                            exa.Labels([42], True), exa.IP.create("1.1.1.1"),
                            exa.IP.pton("11.11.11.11"))

        self.assertEqual(hash(nlri0), hash(nlri1))
        self.assertEqual(hash(nlri0), hash(nlri2))
        self.assertEqual(hash(nlri0), hash(nlri4))
        self.assertEqual(nlri0, nlri1)
        self.assertEqual(nlri0, nlri2)
        self.assertEqual(nlri0, nlri4)
        self.assertEqual(nlri1, nlri2)
        self.assertEqual(nlri1, nlri4)
        self.assertEqual(nlri2, nlri4)
        self.assertEqual(nlri4, nlri5)

        self.assertNotEqual(hash(nlri0), hash(nlri3))
        self.assertNotEqual(nlri0, nlri3)
        self.assertNotEqual(nlri1, nlri3)
        self.assertNotEqual(nlri2, nlri3)
        self.assertNotEqual(nlri3, nlri4)
Exemple #5
0
def IPVPNRouteFactory(afi, prefix, label, rd, nexthop):
    packed_prefix, mask = prefix_to_packed_ip_mask(prefix)

    return IPVPN.new(afi, exa.SAFI(exa.SAFI.mpls_vpn), packed_prefix, mask,
                     exa.Labels([label], True), rd, nexthop)