def test_6_same_nlri_same_attributes_order_multivalued(self):
        # Two routes with same NLRI but and same attributes should
        # hash to the same values and be equal, *even if* for a said
        # multivalued attributes, like extended community, the values
        # appear in a distinct order

        atts1 = exa.Attributes()
        ecoms1 = exa.ExtendedCommunities()
        ecoms1.communities.append(exa.RouteTarget(64512, 1))
        ecoms1.communities.append(
            exa.Encapsulation(exa.Encapsulation.Type.VXLAN))
        ecoms1.communities.append(exa.RouteTarget(64512, 2))
        atts1.add(ecoms1)

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

        entry1 = engine.RouteEntry(base.NLRI1, None, atts1)
        entry2 = engine.RouteEntry(base.NLRI1, None, atts2)

        self.assertEqual(hash(entry1), hash(entry2))
        self.assertEqual(entry1, entry2)
Example #2
0
    def test_7_matches(self):
        m1a = rtm.Match(exa.AFI(exa.AFI.ipv4),
                        exa.SAFI(exa.SAFI.mpls_vpn),
                        exa.RouteTarget(64512, 1))
        m1b = rtm.Match(exa.AFI(exa.AFI.ipv4),
                        exa.SAFI(exa.SAFI.mpls_vpn),
                        exa.RouteTarget(64512, 1))
        m1c = rtm.Match(exa.AFI(exa.AFI.ipv4),
                        exa.SAFI(exa.SAFI.mpls_vpn),
                        exa.RouteTarget(64512, 1, False))
        m2 = rtm.Match(exa.AFI(exa.AFI.ipv4),
                       exa.SAFI(exa.SAFI.mpls_vpn),
                       exa.RouteTarget(64512, 2))
        m3 = rtm.Match(exa.AFI(exa.AFI.ipv4),
                       exa.SAFI(exa.SAFI.mpls_vpn),
                       exa.RouteTarget(64513, 1))

        self.assertEqual(hash(m1a), hash(m1b))
        self.assertEqual(hash(m1a), hash(m1c))
        self.assertNotEqual(hash(m1a), hash(m2))
        self.assertNotEqual(hash(m1a), hash(m3))

        self.assertEqual(m1a, m1b)
        self.assertEqual(m1a, m1c)
        self.assertNotEqual(m1a, m2)
        self.assertNotEqual(m1a, m3)
Example #3
0
    def __cmp__(self, other):
        assert isinstance(other, Match)

        self_afi = self.afi or engine.Subscription.ANY_AFI
        self_safi = self.safi or engine.Subscription.ANY_SAFI
        self_rt = self.route_target or exa.RouteTarget(0, 0)

        other_afi = other.afi or engine.Subscription.ANY_AFI
        other_safi = other.safi or engine.Subscription.ANY_SAFI
        other_rt = other.route_target or exa.RouteTarget(0, 0)

        val = cmp((self_afi, self_safi, str(self_rt)),
                  (other_afi, other_safi, str(other_rt)))

        return val
    def test_11_rts(self):
        rt1a = exa.RouteTarget(64512, 1)
        rt1b = exa.RouteTarget(64512, 1)

        rt3 = exa.RouteTarget(64512, 2)
        rt4 = exa.RouteTarget(64513, 1)

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

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

        self.assertEqual(set([rt1a]), set([rt1b]))
        # self.assertEqual(set([rt1a]), set([rt2]))
        self.assertEqual(1, len(set([rt1a]).intersection(set([rt1b]))))
Example #5
0
def convert_route_targets(orig_list):
    assert isinstance(orig_list, list)
    list_ = []
    for rt in orig_list:
        if rt == '':
            continue
        try:
            asn, nn = rt.split(':')
            list_.append(exa.RouteTarget(int(asn), int(nn)))
        except Exception:
            raise Exception("Malformed route target: '%s'" % rt)
    return list_
    def test_10_ecoms(self):
        ecoms1 = exa.ExtendedCommunities()
        ecoms1.communities.append(
            exa.Encapsulation(exa.Encapsulation.Type.VXLAN))
        atts1 = exa.Attributes()
        atts1.add(ecoms1)

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

        self.assertFalse(atts1.sameValuesAs(atts2))
        self.assertFalse(atts2.sameValuesAs(atts1))
    def test_9_route_entry_rts_as_init_param(self):
        atts = exa.Attributes()
        ecoms = exa.ExtendedCommunities()
        ecoms.communities.append(
            exa.Encapsulation(exa.Encapsulation.Type.VXLAN))
        atts.add(exa.LocalPreference(20))
        atts.add(ecoms)

        rts = [exa.RouteTarget(64512, 1), exa.RouteTarget(64512, 2)]

        entry = engine.RouteEntry(base.NLRI1, rts, atts)

        self.assertIn(exa.RouteTarget(64512, 1), entry.route_targets)
        self.assertIn(exa.RouteTarget(64512, 2), entry.route_targets)

        ecoms = entry.attributes[
            exa.Attribute.CODE.EXTENDED_COMMUNITY].communities
        self.assertIn(exa.RouteTarget(64512, 1), ecoms)
        self.assertIn(exa.RouteTarget(64512, 2), ecoms)
        self.assertIn(exa.Encapsulation(exa.Encapsulation.Type.VXLAN), ecoms)
    def test_8_route_entry_set_rts(self):
        atts = exa.Attributes()
        ecoms = exa.ExtendedCommunities()
        ecoms.communities.append(exa.RouteTarget(64512, 1))
        ecoms.communities.append(exa.RouteTarget(64512, 2))
        ecoms.communities.append(
            exa.Encapsulation(exa.Encapsulation.Type.VXLAN))
        atts.add(exa.LocalPreference(20))
        atts.add(ecoms)

        entry = engine.RouteEntry(base.NLRI1, None, atts)

        # check that the route_entry object has the RTs we wanted
        self.assertIn(exa.RouteTarget(64512, 1), entry.route_targets)
        self.assertIn(exa.RouteTarget(64512, 2), entry.route_targets)

        # modify the route targets
        entry.set_route_targets(
            [exa.RouteTarget(64512, 3),
             exa.RouteTarget(64512, 1)])

        # check that the new RTs have replaced the old ones
        self.assertIn(exa.RouteTarget(64512, 1), entry.route_targets)
        self.assertIn(exa.RouteTarget(64512, 3), entry.route_targets)
        self.assertNotIn(exa.RouteTarget(64512, 2), entry.route_targets)

        # also need to check the RTs in the attributes
        ecoms = entry.attributes[
            exa.Attribute.CODE.EXTENDED_COMMUNITY].communities
        self.assertIn(exa.RouteTarget(64512, 1), ecoms)
        self.assertIn(exa.RouteTarget(64512, 3), ecoms)
        self.assertNotIn(exa.RouteTarget(64512, 2), ecoms)

        # check that other communities were preserved
        self.assertIn(exa.Encapsulation(exa.Encapsulation.Type.VXLAN), ecoms)
Example #9
0
from oslo_config import fixture as config_fixture
from oslo_log import log as logging
import testtools

from networking_bagpipe.bagpipe_bgp.common import config
from networking_bagpipe.bagpipe_bgp import engine
from networking_bagpipe.bagpipe_bgp.engine import exa
from networking_bagpipe.bagpipe_bgp.engine import exabgp_peer_worker


exabgp_peer_worker.setup_exabgp_env()

WAIT_TIME = 0.05

RT1 = exa.RouteTarget(64512, 10)
RT2 = exa.RouteTarget(64512, 20)
RT3 = exa.RouteTarget(64512, 30)
RT4 = exa.RouteTarget(64512, 40)
RT5 = exa.RouteTarget(64512, 50)


def _rt_to_string(rt):
    assert isinstance(rt, exa.RouteTarget)
    return "%s:%s" % (rt.asn, rt.number)


class TestNLRI(object):

    def __init__(self, desc):
        self.desc = desc