2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.evpn.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNull;
12 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.RD;
13 import static org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest.ETHERNET_AD_ROUTE_CASE;
14 import static org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest.ETHERNET_AD_ROUTE_CASE_KEY;
15 import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID;
17 import com.google.common.collect.ImmutableSet;
18 import io.netty.buffer.ByteBuf;
19 import io.netty.buffer.Unpooled;
20 import java.util.Collection;
21 import java.util.Collections;
23 import org.junit.Assert;
24 import org.junit.Test;
25 import org.opendaylight.protocol.bgp.evpn.impl.nlri.EvpnNlriParser;
26 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
27 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
28 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest;
29 import org.opendaylight.protocol.util.ByteArray;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.bgp.rib.rib.loc.rib.tables.routes.EvpnRoutesCase;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.bgp.rib.rib.loc.rib.tables.routes.EvpnRoutesCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.destination.EvpnDestination;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.destination.EvpnDestinationBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.routes.EvpnRoutes;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.routes.EvpnRoutesBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.routes.evpn.routes.EvpnRoute;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.routes.evpn.routes.EvpnRouteBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.routes.evpn.routes.EvpnRouteKey;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationEvpnCase;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationEvpnCaseBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.evpn._case.DestinationEvpnBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Attributes;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
48 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
49 import org.opendaylight.yangtools.yang.common.QName;
50 import org.opendaylight.yangtools.yang.common.Uint32;
51 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
52 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
53 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
54 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
56 public final class EvpnRibSupportTest extends AbstractRIBSupportTest<EvpnRoutesCase, EvpnRoutes, EvpnRoute,
58 private EvpnRibSupport ribSupport;
59 private static final EvpnRoute ROUTE;
60 private static final EvpnRouteKey ROUTE_KEY;
61 private static final EvpnDestination EVPN_DESTINATION = new EvpnDestinationBuilder()
62 .setRouteDistinguisher(RD)
63 .setEvpnChoice(ETHERNET_AD_ROUTE_CASE)
64 .setPathId(NON_PATH_ID)
66 private static final DestinationEvpnCase REACH_NLRI = new DestinationEvpnCaseBuilder()
67 .setDestinationEvpn(new DestinationEvpnBuilder()
68 .setEvpnDestination(Collections.singletonList(EVPN_DESTINATION)).build()).build();
69 private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.update
70 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationEvpnCase UNREACH_NLRI =
71 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.update.attributes
72 .mp.unreach.nlri.withdrawn.routes.destination.type.DestinationEvpnCaseBuilder()
73 .setDestinationEvpn(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
74 .bgp.evpn.rev200120.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
75 .destination.evpn._case.DestinationEvpnBuilder()
76 .setEvpnDestination(Collections.singletonList(EVPN_DESTINATION))
80 private static final EvpnRoutes EVPN_ROUTES;
83 final BGPActivator act = new BGPActivator();
84 final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
86 final ByteBuf buffer = Unpooled.buffer();
87 EvpnNlriParser.serializeNlri(Collections.singletonList(new EvpnDestinationBuilder()
88 .setRouteDistinguisher(RD).setEvpnChoice(ETHERNET_AD_ROUTE_CASE_KEY).build()), buffer);
89 ROUTE_KEY = new EvpnRouteKey(new PathId(Uint32.ZERO), ByteArray.encodeBase64(buffer));
90 ROUTE = new EvpnRouteBuilder().setRouteKey(ROUTE_KEY.getRouteKey())
91 .setPathId(ROUTE_KEY.getPathId())
92 .setAttributes(ATTRIBUTES).setRouteDistinguisher(RD).setEvpnChoice(ETHERNET_AD_ROUTE_CASE).build();
93 EVPN_ROUTES = new EvpnRoutesBuilder().setEvpnRoute(Map.of(ROUTE.key(), ROUTE)).build();
98 public void setUp() throws Exception {
100 this.ribSupport = EvpnRibSupport.getInstance(this.adapter.currentSerializer());
101 setUpTestCustomizer(this.ribSupport);
105 public void testDeleteRoutes() {
106 this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI));
107 final InstanceIdentifier<EvpnRoute> instanceIdentifier = this.deletedRoutes.get(0);
108 assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(EvpnRoute.class));
112 public void testPutRoutes() {
113 this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes());
114 final EvpnRoute route = (EvpnRoute) this.insertedRoutes.get(0).getValue();
115 assertEquals(ROUTE, route);
120 public void testEmptyRoute() {
121 assertEquals(createEmptyTable(), this.ribSupport.emptyTable());
125 public void testBuildMpUnreachNlriUpdate() {
126 final Update update = this.ribSupport.buildUpdate(Collections.emptyList(),
127 createRoutes(EVPN_ROUTES), ATTRIBUTES);
128 assertEquals(UNREACH_NLRI, update.getAttributes().augmentation(Attributes2.class).getMpUnreachNlri()
129 .getWithdrawnRoutes().getDestinationType());
130 assertNull(update.getAttributes().augmentation(Attributes1.class));
134 public void testBuildMpReachNlriUpdate() {
135 final Update update = this.ribSupport.buildUpdate(
136 createRoutes(EVPN_ROUTES), Collections.emptyList(), ATTRIBUTES);
137 assertEquals(REACH_NLRI, update.getAttributes().augmentation(Attributes1.class).getMpReachNlri()
138 .getAdvertizedRoutes().getDestinationType());
139 assertNull(update.getAttributes().augmentation(Attributes2.class));
143 public void testCacheableNlriObjects() {
144 assertEquals(ImmutableSet.of(), this.ribSupport.cacheableNlriObjects());
148 public void testCacheableAttributeObjects() {
149 assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects());
153 public void testRouteIdAddPath() {
154 assertEquals(ROUTE_KEY, this.ribSupport.createRouteListKey(ROUTE_KEY.getPathId(), ROUTE_KEY.getRouteKey()));
158 public void testRoutePath() {
159 final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(EVPN_ROUTES);
160 assertEquals(getRoutePath().node(prefixNii),
161 this.ribSupport.routePath(getTablePath(), prefixNii));
165 public void testRouteAttributesIdentifier() {
166 assertEquals(new NodeIdentifier(QName.create(EvpnRoutes.QNAME,
167 Attributes.QNAME.getLocalName().intern())), this.ribSupport.routeAttributesIdentifier());
171 public void testRoutesCaseClass() {
172 assertEquals(EvpnRoutesCase.class, this.ribSupport.routesCaseClass());
176 public void testRoutesContainerClass() {
177 assertEquals(EvpnRoutes.class, this.ribSupport.routesContainerClass());
181 public void testRoutesListClass() {
182 assertEquals(EvpnRoute.class, this.ribSupport.routesListClass());
186 public void testChangedRoutes() {
187 final Routes emptyCase = new EvpnRoutesCaseBuilder().build();
188 DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(),
189 createRoutes(emptyCase)).getRootNode();
190 Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
192 final Routes emptyRoutes = new EvpnRoutesCaseBuilder().setEvpnRoutes(new EvpnRoutesBuilder().build()).build();
193 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
194 Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
196 final Routes routes = new EvpnRoutesCaseBuilder().setEvpnRoutes(EVPN_ROUTES).build();
197 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
198 final Collection<DataTreeCandidateNode> result = this.ribSupport.changedRoutes(tree);
199 Assert.assertFalse(result.isEmpty());