81d0a5c723b1a90dcf5654809a086111e8fbc56c
[bgpcep.git] / bgp / l3vpn / src / test / java / org / opendaylight / protocol / bgp / l3vpn / mcast / L3vpnMcastIpv6RIBSupportTest.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.protocol.bgp.l3vpn.mcast;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.assertTrue;
15
16 import com.google.common.collect.ImmutableSet;
17 import java.util.Collection;
18 import java.util.Collections;
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.bgp.rib.rib.loc.rib.tables.routes.L3vpnMcastRoutesIpv6Case;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.bgp.rib.rib.loc.rib.tables.routes.L3vpnMcastRoutesIpv6CaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.destination.L3vpnMcastDestination;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.destination.L3vpnMcastDestinationBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.routes.L3vpnMcastRoute;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.routes.L3vpnMcastRouteBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.routes.L3vpnMcastRouteKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.routes.ipv6.L3vpnMcastRoutesIpv6;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.routes.ipv6.L3vpnMcastRoutesIpv6Builder;
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.DestinationL3vpnMcastIpv6AdvertizedCase;
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.DestinationL3vpnMcastIpv6AdvertizedCaseBuilder;
35 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.ipv6.advertized._case.DestinationIpv6L3vpnMcastBuilder;
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.DestinationL3vpnMcastIpv6WithdrawnCase;
37 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.DestinationL3vpnMcastIpv6WithdrawnCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Attributes;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.RdIpv4;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.RouteDistinguisher;
46 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
47 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
48 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
49 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
50 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
51 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
52 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
53
54 public class L3vpnMcastIpv6RIBSupportTest extends AbstractRIBSupportTest<L3vpnMcastRoutesIpv6Case, L3vpnMcastRoutesIpv6,
55         L3vpnMcastRoute, L3vpnMcastRouteKey> {
56     private static final PathId PATH_ID = new PathId(0L);
57     private static final IpPrefix IPV6_PREFIX = new IpPrefix(new Ipv6Prefix("2001:db8:1:1::/64"));
58     private static final RouteDistinguisher RD = new RouteDistinguisher(new RdIpv4("1.2.3.4:258"));
59     private static final L3vpnMcastRouteKey ROUTE_KEY
60             = new L3vpnMcastRouteKey(PATH_ID, "gAABAQIDBAECIAENuAABAAEAAAAAAAAAAEAAAAAAAAAA");
61     private static final L3vpnMcastRoute ROUTE = new L3vpnMcastRouteBuilder()
62             .setRouteKey(ROUTE_KEY.getRouteKey())
63             .setPathId(ROUTE_KEY.getPathId())
64             .setAttributes(ATTRIBUTES)
65             .setRouteDistinguisher(RD)
66             .setPrefix(IPV6_PREFIX)
67             .build();
68     private static final L3vpnMcastRoutesIpv6 MCAST_L3VPN_ROUTES
69             = new L3vpnMcastRoutesIpv6Builder().setL3vpnMcastRoute(Collections.singletonList(ROUTE)).build();
70
71     private static final L3vpnMcastDestination MCAST_L3VPN_DESTINATION = new L3vpnMcastDestinationBuilder()
72             .setRouteDistinguisher(RD)
73             .setPrefix(IPV6_PREFIX)
74             .setPathId(PATH_ID)
75             .build();
76     private static final DestinationL3vpnMcastIpv6AdvertizedCase REACH_NLRI
77             = new DestinationL3vpnMcastIpv6AdvertizedCaseBuilder()
78             .setDestinationIpv6L3vpnMcast(new DestinationIpv6L3vpnMcastBuilder()
79                     .setL3vpnMcastDestination(Collections.singletonList(MCAST_L3VPN_DESTINATION)).build()).build();
80     private static final DestinationL3vpnMcastIpv6WithdrawnCase UNREACH_NLRI
81             = new DestinationL3vpnMcastIpv6WithdrawnCaseBuilder()
82             .setDestinationIpv6L3vpnMcast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
83                     .l3vpn.mcast.rev180417.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
84                     .destination.l3vpn.mcast.ipv6.withdrawn._case.DestinationIpv6L3vpnMcastBuilder()
85                     .setL3vpnMcastDestination(Collections.singletonList(MCAST_L3VPN_DESTINATION)).build()).build();
86
87     private L3VpnMcastIpv6RIBSupport ribSupport;
88
89     @Override
90     public void setUp() throws Exception {
91         super.setUp();
92         ribSupport = L3VpnMcastIpv6RIBSupport.getInstance(this.mappingService);
93         setUpTestCustomizer(ribSupport);
94     }
95
96     @Test
97     public void testDeleteRoutes() {
98         final ContainerNode withdraw = createNlriWithDrawnRoute(UNREACH_NLRI);
99         this.ribSupport.deleteRoutes(this.tx, getTablePath(), withdraw);
100         final InstanceIdentifier<L3vpnMcastRoute> instanceIdentifier = this.deletedRoutes.get(0);
101         assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(L3vpnMcastRoute.class));
102     }
103
104     @Test
105     public void testPutRoutes() {
106         this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes());
107         final L3vpnMcastRoute route = (L3vpnMcastRoute) this.insertedRoutes.get(0).getValue();
108         assertEquals(ROUTE, route);
109     }
110
111
112     @Test
113     public void testEmptyRoute() {
114         final Routes empty = new L3vpnMcastRoutesIpv6CaseBuilder()
115                 .setL3vpnMcastRoutesIpv6(new L3vpnMcastRoutesIpv6Builder()
116                         .setL3vpnMcastRoute(Collections.emptyList()).build()).build();
117         Assert.assertEquals(createEmptyTable(empty), this.ribSupport.emptyTable());
118     }
119
120     @Test
121     public void testBuildMpUnreachNlriUpdate() {
122         final Collection<MapEntryNode> routes = createRoutes(MCAST_L3VPN_ROUTES);
123         final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), routes, ATTRIBUTES);
124         assertEquals(UNREACH_NLRI, update.getAttributes().augmentation(Attributes2.class).getMpUnreachNlri()
125                 .getWithdrawnRoutes().getDestinationType());
126         assertNull(update.getAttributes().augmentation(Attributes1.class));
127     }
128
129     @Test
130     public void testBuildMpReachNlriUpdate() {
131         final Collection<MapEntryNode> routes = createRoutes(MCAST_L3VPN_ROUTES);
132         final Update update = this.ribSupport.buildUpdate(routes, Collections.emptyList(), ATTRIBUTES);
133         assertEquals(REACH_NLRI, update.getAttributes().augmentation(Attributes1.class).getMpReachNlri()
134                 .getAdvertizedRoutes().getDestinationType());
135         assertNull(update.getAttributes().augmentation(Attributes2.class));
136     }
137
138     @Test
139     public void testCacheableNlriObjects() {
140         Assert.assertEquals(ImmutableSet.of(L3vpnMcastRoutesIpv6Case.class), this.ribSupport.cacheableNlriObjects());
141     }
142
143     @Test
144     public void testCacheableAttributeObjects() {
145         Assert.assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects());
146     }
147
148     @Test
149     public void testRouteIdAddPath() {
150         Assert.assertEquals(ROUTE_KEY, this.ribSupport.createRouteListKey(ROUTE_KEY.getPathId().getValue(),
151                 ROUTE_KEY.getRouteKey()));
152     }
153
154     @Test
155     public void testRoutePath() {
156         final YangInstanceIdentifier.NodeIdentifierWithPredicates prefixNii = createRouteNIWP(MCAST_L3VPN_ROUTES);
157         final YangInstanceIdentifier expected = getRoutePath().node(prefixNii);
158         final YangInstanceIdentifier actual = this.ribSupport.routePath(getTablePath().node(Routes.QNAME), prefixNii);
159         assertEquals(expected, actual);
160     }
161
162     @Test
163     public void testRouteAttributesIdentifier() {
164         Assert.assertEquals(new YangInstanceIdentifier.NodeIdentifier(
165                         Attributes.QNAME.withModule(BindingReflections.getQNameModule(L3vpnMcastRoutesIpv6Case.class))),
166                 this.ribSupport.routeAttributesIdentifier());
167     }
168
169     @Test
170     public void testRoutesCaseClass() {
171         Assert.assertEquals(L3vpnMcastRoutesIpv6Case.class, this.ribSupport.routesCaseClass());
172     }
173
174     @Test
175     public void testRoutesContainerClass() {
176         Assert.assertEquals(L3vpnMcastRoutesIpv6.class, this.ribSupport.routesContainerClass());
177     }
178
179     @Test
180     public void testRoutesListClass() {
181         Assert.assertEquals(L3vpnMcastRoute.class, this.ribSupport.routesListClass());
182     }
183
184     @Test
185     public void testChangedRoutes() {
186         final Routes emptyCase = new L3vpnMcastRoutesIpv6CaseBuilder().build();
187         DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(),
188                 createRoutes(emptyCase)).getRootNode();
189         assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
190
191         final Routes emptyRoutes
192                 = new L3vpnMcastRoutesIpv6CaseBuilder()
193                 .setL3vpnMcastRoutesIpv6(new L3vpnMcastRoutesIpv6Builder().build()).build();
194         tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
195         assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
196
197         final Routes routes = new L3vpnMcastRoutesIpv6CaseBuilder().setL3vpnMcastRoutesIpv6(MCAST_L3VPN_ROUTES).build();
198         tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
199         final Collection<DataTreeCandidateNode> result = this.ribSupport.changedRoutes(tree);
200         assertFalse(result.isEmpty());
201     }
202 }