2 * Copyright (c) 2018 AT&T Intellectual Property. 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.l3vpn.mcast;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertTrue;
15 import com.google.common.collect.ImmutableSet;
16 import java.util.Collection;
17 import java.util.Collections;
19 import org.junit.Test;
20 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.bgp.rib.rib.loc.rib.tables.routes.L3vpnMcastRoutesIpv4Case;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.bgp.rib.rib.loc.rib.tables.routes.L3vpnMcastRoutesIpv4CaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.destination.L3vpnMcastDestination;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.destination.L3vpnMcastDestinationBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.routes.L3vpnMcastRoute;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.routes.L3vpnMcastRouteBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.routes.L3vpnMcastRouteKey;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.routes.ipv4.L3vpnMcastRoutesIpv4;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.routes.ipv4.L3vpnMcastRoutesIpv4Builder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationL3vpnMcastIpv4AdvertizedCase;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationL3vpnMcastIpv4AdvertizedCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.l3vpn.mcast.ipv4.advertized._case.DestinationIpv4L3vpnMcastBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationL3vpnMcastIpv4WithdrawnCase;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationL3vpnMcastIpv4WithdrawnCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Attributes;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RdIpv4;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher;
45 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
46 import org.opendaylight.yangtools.yang.common.Uint32;
47 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
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.ContainerNode;
51 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
52 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
53 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
55 public class L3vpnMcastIpv4RIBSupportTest extends AbstractRIBSupportTest<L3vpnMcastRoutesIpv4Case ,L3vpnMcastRoutesIpv4,
56 L3vpnMcastRoute, L3vpnMcastRouteKey> {
57 private static final PathId PATH_ID = new PathId(Uint32.ZERO);
58 private static final IpPrefix IPV4_PREFIX = new IpPrefix(new Ipv4Prefix("34.1.22.0/24"));
59 private static final RouteDistinguisher RD = new RouteDistinguisher(new RdIpv4("1.2.3.4:258"));
60 private static final L3vpnMcastRouteKey ROUTE_KEY
61 = new L3vpnMcastRouteKey(PATH_ID, "IAABAQIDBAECGCIBFgAAAAA=");
62 private static final L3vpnMcastRoute ROUTE = new L3vpnMcastRouteBuilder()
63 .setRouteKey(ROUTE_KEY.getRouteKey())
64 .setPathId(ROUTE_KEY.getPathId())
65 .setAttributes(ATTRIBUTES)
66 .setRouteDistinguisher(RD)
67 .setPrefix(IPV4_PREFIX)
69 private static final L3vpnMcastRoutesIpv4 MCAST_L3VPN_ROUTES = new L3vpnMcastRoutesIpv4Builder()
70 .setL3vpnMcastRoute(Map.of(ROUTE.key(), ROUTE))
73 private static final L3vpnMcastDestination MCAST_L3VPN_DESTINATION = new L3vpnMcastDestinationBuilder()
74 .setRouteDistinguisher(RD)
75 .setPrefix(IPV4_PREFIX)
78 private static final DestinationL3vpnMcastIpv4AdvertizedCase REACH_NLRI
79 = new DestinationL3vpnMcastIpv4AdvertizedCaseBuilder()
80 .setDestinationIpv4L3vpnMcast(new DestinationIpv4L3vpnMcastBuilder()
81 .setL3vpnMcastDestination(Collections.singletonList(MCAST_L3VPN_DESTINATION)).build()).build();
82 private static final DestinationL3vpnMcastIpv4WithdrawnCase UNREACH_NLRI
83 = new DestinationL3vpnMcastIpv4WithdrawnCaseBuilder()
84 .setDestinationIpv4L3vpnMcast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
85 .l3vpn.mcast.rev180417.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
86 .destination.l3vpn.mcast.ipv4.withdrawn._case.DestinationIpv4L3vpnMcastBuilder()
87 .setL3vpnMcastDestination(Collections.singletonList(MCAST_L3VPN_DESTINATION)).build()).build();
89 private L3VpnMcastIpv4RIBSupport ribSupport;
92 public void setUp() throws Exception {
94 ribSupport = new L3VpnMcastIpv4RIBSupport(this.adapter.currentSerializer());
95 setUpTestCustomizer(ribSupport);
99 public void testDeleteRoutes() {
100 final ContainerNode withdraw = createNlriWithDrawnRoute(UNREACH_NLRI);
101 this.ribSupport.deleteRoutes(this.tx, getTablePath(), withdraw);
102 final InstanceIdentifier<L3vpnMcastRoute> instanceIdentifier = this.deletedRoutes.get(0);
103 assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(L3vpnMcastRoute.class));
107 public void testPutRoutes() {
108 this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes());
109 final L3vpnMcastRoute route = (L3vpnMcastRoute) this.insertedRoutes.get(0).getValue();
110 assertEquals(ROUTE, route);
114 public void testEmptyRoute() {
115 assertEquals(createEmptyTable(), this.ribSupport.emptyTable());
119 public void testBuildMpUnreachNlriUpdate() {
120 final Collection<MapEntryNode> routes = createRoutes(MCAST_L3VPN_ROUTES);
121 final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), routes, ATTRIBUTES);
122 assertEquals(UNREACH_NLRI, update.getAttributes().augmentation(Attributes2.class).getMpUnreachNlri()
123 .getWithdrawnRoutes().getDestinationType());
124 assertNull(update.getAttributes().augmentation(Attributes1.class));
128 public void testBuildMpReachNlriUpdate() {
129 final Collection<MapEntryNode> routes = createRoutes(MCAST_L3VPN_ROUTES);
130 final Update update = this.ribSupport.buildUpdate(routes, Collections.emptyList(), ATTRIBUTES);
131 assertEquals(REACH_NLRI, update.getAttributes().augmentation(Attributes1.class).getMpReachNlri()
132 .getAdvertizedRoutes().getDestinationType());
133 assertNull(update.getAttributes().augmentation(Attributes2.class));
137 public void testCacheableNlriObjects() {
138 assertEquals(ImmutableSet.of(L3vpnMcastRoutesIpv4Case.class), this.ribSupport.cacheableNlriObjects());
142 public void testCacheableAttributeObjects() {
143 assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects());
147 public void testRouteIdAddPath() {
148 assertEquals(ROUTE_KEY, this.ribSupport.createRouteListKey(ROUTE_KEY.getPathId(), ROUTE_KEY.getRouteKey()));
152 public void testRoutePath() {
153 final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(MCAST_L3VPN_ROUTES);
154 final YangInstanceIdentifier expected = getRoutePath().node(prefixNii);
155 final YangInstanceIdentifier actual = this.ribSupport.routePath(getTablePath(), prefixNii);
156 assertEquals(expected, actual);
160 public void testRouteAttributesIdentifier() {
161 assertEquals(new NodeIdentifier(Attributes.QNAME.bindTo(L3vpnMcastRoutesIpv4Case.QNAME.getModule())),
162 this.ribSupport.routeAttributesIdentifier());
166 public void testRoutesCaseClass() {
167 assertEquals(L3vpnMcastRoutesIpv4Case.class, this.ribSupport.routesCaseClass());
171 public void testRoutesContainerClass() {
172 assertEquals(L3vpnMcastRoutesIpv4.class, this.ribSupport.routesContainerClass());
176 public void testRoutesListClass() {
177 assertEquals(L3vpnMcastRoute.class, this.ribSupport.routesListClass());
181 public void testChangedRoutes() {
182 final Routes emptyCase = new L3vpnMcastRoutesIpv4CaseBuilder().build();
183 DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(),
184 createRoutes(emptyCase)).getRootNode();
185 assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
187 final Routes emptyRoutes
188 = new L3vpnMcastRoutesIpv4CaseBuilder()
189 .setL3vpnMcastRoutesIpv4(new L3vpnMcastRoutesIpv4Builder().build()).build();
190 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
191 assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
193 final Routes routes = new L3vpnMcastRoutesIpv4CaseBuilder().setL3vpnMcastRoutesIpv4(MCAST_L3VPN_ROUTES).build();
194 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
195 final Collection<DataTreeCandidateNode> result = this.ribSupport.changedRoutes(tree);
196 assertFalse(result.isEmpty());