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;
22 import org.junit.Assert;
23 import org.junit.Test;
24 import org.opendaylight.protocol.bgp.evpn.impl.nlri.EvpnNlriParser;
25 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
26 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
27 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest;
28 import org.opendaylight.protocol.util.ByteArray;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.bgp.rib.rib.loc.rib.tables.routes.EvpnRoutesCase;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.bgp.rib.rib.loc.rib.tables.routes.EvpnRoutesCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.evpn.destination.EvpnDestination;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.evpn.destination.EvpnDestinationBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.evpn.routes.EvpnRoutes;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.evpn.routes.EvpnRoutesBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.evpn.routes.evpn.routes.EvpnRoute;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.evpn.routes.evpn.routes.EvpnRouteBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.evpn.routes.evpn.routes.EvpnRouteKey;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationEvpnCase;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationEvpnCaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.evpn._case.DestinationEvpnBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes2;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.Attributes;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.Routes;
46 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
47 import org.opendaylight.yangtools.yang.common.QName;
48 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
49 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
50 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
51 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
52 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
54 public final class EvpnRibSupportTest extends AbstractRIBSupportTest {
55 private static final EvpnRibSupport RIB_SUPPORT = EvpnRibSupport.getInstance();
56 private static final EvpnRoute ROUTE;
57 private static final EvpnRouteKey ROUTE_KEY;
58 private static final EvpnDestination EVPN_DESTINATION = new EvpnDestinationBuilder().setRouteDistinguisher(RD)
59 .setEvpnChoice(ETHERNET_AD_ROUTE_CASE).build();
60 private static final DestinationEvpnCase REACH_NLRI = new DestinationEvpnCaseBuilder()
61 .setDestinationEvpn(new DestinationEvpnBuilder()
62 .setEvpnDestination(Collections.singletonList(EVPN_DESTINATION)).build()).build();
63 private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.update
64 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationEvpnCase UNREACH_NLRI =
65 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.update.attributes
66 .mp.unreach.nlri.withdrawn.routes.destination.type.DestinationEvpnCaseBuilder()
67 .setDestinationEvpn(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn
68 .rev171213.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
69 .destination.evpn._case.DestinationEvpnBuilder()
70 .setEvpnDestination(Collections.singletonList(EVPN_DESTINATION)).build()).build();
72 private static final EvpnRoutes EVPN_ROUTES;
75 final BGPActivator act = new BGPActivator();
76 final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
78 final ByteBuf buffer = Unpooled.buffer();
79 EvpnNlriParser.serializeNlri(Collections.singletonList(new EvpnDestinationBuilder()
80 .setRouteDistinguisher(RD).setEvpnChoice(ETHERNET_AD_ROUTE_CASE_KEY).build()), buffer);
81 ROUTE_KEY = new EvpnRouteKey(ByteArray.encodeBase64(buffer));
82 ROUTE = new EvpnRouteBuilder().setRouteKey(ROUTE_KEY.getRouteKey())
83 .setAttributes(ATTRIBUTES).setRouteDistinguisher(RD).setEvpnChoice(ETHERNET_AD_ROUTE_CASE).build();
84 EVPN_ROUTES = new EvpnRoutesBuilder().setEvpnRoute(Collections.singletonList(ROUTE)).build();
89 public void setUp() throws Exception {
91 setUpTestCustomizer(RIB_SUPPORT);
95 public void testDeleteRoutes() {
96 RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI));
97 @SuppressWarnings("unchecked") final InstanceIdentifier<EvpnRoute> instanceIdentifier =
98 (InstanceIdentifier<EvpnRoute>) this.deletedRoutes.get(0);
99 assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(EvpnRoute.class));
103 public void testPutRoutes() {
104 RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes());
105 final EvpnRoute route = (EvpnRoute) this.insertedRoutes.get(0).getValue();
106 assertEquals(ROUTE, route);
111 public void testEmptyRoute() throws Exception {
112 final Routes empty = new EvpnRoutesCaseBuilder().setEvpnRoutes(
113 new EvpnRoutesBuilder().setEvpnRoute(Collections.emptyList()).build()).build();
114 final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes();
115 assertEquals(createRoutes(empty), emptyRoutes);
119 public void testBuildMpUnreachNlriUpdate() {
120 final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(EVPN_ROUTES), ATTRIBUTES);
121 assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri()
122 .getWithdrawnRoutes().getDestinationType());
123 assertNull(update.getAttributes().getAugmentation(Attributes1.class));
127 public void testBuildMpReachNlriUpdate() {
128 final Update update = RIB_SUPPORT.buildUpdate(createRoutes(EVPN_ROUTES), Collections.emptyList(), ATTRIBUTES);
129 assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri()
130 .getAdvertizedRoutes().getDestinationType());
131 assertNull(update.getAttributes().getAugmentation(Attributes2.class));
135 public void testIsComplexRoute() {
136 Assert.assertTrue(RIB_SUPPORT.isComplexRoute());
140 public void testCacheableNlriObjects() {
141 assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects());
145 public void testCacheableAttributeObjects() {
146 assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects());
150 public void testRouteIdAddPath() {
151 Assert.assertNull(RIB_SUPPORT.getRouteIdAddPath(AbstractRIBSupportTest.PATH_ID, null));
155 public void testRoutePath() {
156 final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(EVPN_ROUTES);
157 assertEquals(getRoutePath().node(prefixNii),
158 RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii));
162 public void testExtractPathId() {
163 assertEquals((Long) NON_PATH_ID, RIB_SUPPORT.extractPathId(null));
167 public void testRouteAttributesIdentifier() {
168 assertEquals(new NodeIdentifier(QName.create(EvpnRoutes.QNAME,
169 Attributes.QNAME.getLocalName().intern())), RIB_SUPPORT.routeAttributesIdentifier());
173 public void testRoutesCaseClass() {
174 assertEquals(EvpnRoutesCase.class, RIB_SUPPORT.routesCaseClass());
178 public void testRoutesContainerClass() {
179 assertEquals(EvpnRoutes.class, RIB_SUPPORT.routesContainerClass());
183 public void testRoutesListClass() {
184 assertEquals(EvpnRoute.class, RIB_SUPPORT.routesListClass());
188 public void testChangedRoutes() {
189 final Routes emptyCase = new EvpnRoutesCaseBuilder().build();
190 DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(),
191 createRoutes(emptyCase)).getRootNode();
192 Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty());
194 final Routes emptyRoutes = new EvpnRoutesCaseBuilder().setEvpnRoutes(new EvpnRoutesBuilder().build()).build();
195 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
196 Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty());
198 final Routes routes = new EvpnRoutesCaseBuilder().setEvpnRoutes(EVPN_ROUTES).build();
199 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
200 final Collection<DataTreeCandidateNode> result = RIB_SUPPORT.changedRoutes(tree);
201 Assert.assertFalse(result.isEmpty());