def test_4_same_nlri_distinct_attributes(self): # Two routes with same NLRI but distinct attributes should # not be equal atts1 = exa.Attributes() atts1.add(exa.LocalPreference(10)) atts2 = exa.Attributes() atts2.add(exa.LocalPreference(20)) entry1 = engine.RouteEntry(base.NLRI1, None, atts1) entry2 = engine.RouteEntry(base.NLRI1, None, atts2) self.assertNotEqual(entry1, entry2)
def test_5_same_nlri_same_attributes(self): # Two routes with same NLRI but and same attributes should # hash to the same values and be equal. atts1 = exa.Attributes() atts1.add(exa.LocalPreference(10)) atts2 = exa.Attributes() atts2.add(exa.LocalPreference(10)) entry1 = engine.RouteEntry(base.NLRI1, None, atts1) entry2 = engine.RouteEntry(base.NLRI1, None, atts2) self.assertEqual(hash(entry1), hash(entry2)) self.assertEqual(entry1, entry2)
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)
def synthesize_vif_bgp_route(self, mac_address, ip_prefix, plen, label, lb_consistent_hash_order, route_distinguisher=None, local_pref=None): rd = route_distinguisher if route_distinguisher else self.instance_rd route_entry = self.generate_vif_bgp_route(mac_address, ip_prefix, plen, label, rd) assert isinstance(route_entry, engine.RouteEntry) route_entry.attributes.add(self._gen_encap_extended_communities()) route_entry.set_route_targets(self.export_rts) ecommunities = exa.ExtendedCommunities() ecommunities.communities.append( exa.ConsistentHashSortOrder(lb_consistent_hash_order)) route_entry.attributes.add(ecommunities) route_entry.attributes.add( exa.LocalPreference(local_pref or DEFAULT_LOCAL_PREF)) self.log.debug("Synthesized Vif route entry: %s", route_entry) return route_entry
def _new_route_event(self, event_type, nlri, rts, source, nh, lp=0, replaced_route_entry=None, afi=exa.AFI(exa.AFI.ipv4), safi=exa.SAFI(exa.SAFI.mpls_vpn), **kwargs): attributes = exa.Attributes() attributes.add(exa.NextHop(nh)) attributes.add(exa.LocalPreference(lp)) if 'rtrecords' in kwargs: ecoms = exa.ExtendedCommunities() ecoms.communities += kwargs['rtrecords'] attributes.add(ecoms) route_event = engine.RouteEvent(event_type, engine.RouteEntry(nlri, rts, attributes, source), source) route_event.set_replaced_route(replaced_route_entry) LOG.info("*** Emitting event to %s: %s", self.event_target_worker, route_event) self.event_target_worker._on_event(route_event) return route_event
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)