Update MRI projects for Aluminium
[bgpcep.git] / bgp / extensions / l3vpn / src / test / java / org / opendaylight / protocol / bgp / l3vpn / mcast / L3vpnMcastIpv4RIBSupportTest.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 package org.opendaylight.protocol.bgp.l3vpn.mcast;
9
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;
14
15 import com.google.common.collect.ImmutableSet;
16 import java.util.Collection;
17 import java.util.Collections;
18 import org.junit.Assert;
19 import org.junit.Test;
20 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
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.Ipv4Prefix;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.bgp.rib.rib.loc.rib.tables.routes.L3vpnMcastRoutesIpv4Case;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.bgp.rib.rib.loc.rib.tables.routes.L3vpnMcastRoutesIpv4CaseBuilder;
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.ipv4.L3vpnMcastRoutesIpv4;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.routes.ipv4.L3vpnMcastRoutesIpv4Builder;
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.DestinationL3vpnMcastIpv4AdvertizedCase;
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.DestinationL3vpnMcastIpv4AdvertizedCaseBuilder;
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.ipv4.advertized._case.DestinationIpv4L3vpnMcastBuilder;
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.DestinationL3vpnMcastIpv4WithdrawnCase;
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.DestinationL3vpnMcastIpv4WithdrawnCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.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.rev200120.RdIpv4;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher;
46 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
47 import org.opendaylight.yangtools.yang.common.Uint32;
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 L3vpnMcastIpv4RIBSupportTest extends AbstractRIBSupportTest<L3vpnMcastRoutesIpv4Case ,L3vpnMcastRoutesIpv4,
55         L3vpnMcastRoute, L3vpnMcastRouteKey> {
56     private static final PathId PATH_ID = new PathId(Uint32.ZERO);
57     private static final IpPrefix IPV4_PREFIX = new IpPrefix(new Ipv4Prefix("34.1.22.0/24"));
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, "IAABAQIDBAECGCIBFgAAAAA=");
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(IPV4_PREFIX)
67             .build();
68     private static final L3vpnMcastRoutesIpv4 MCAST_L3VPN_ROUTES
69             = new L3vpnMcastRoutesIpv4Builder().setL3vpnMcastRoute(Collections.singletonList(ROUTE)).build();
70
71     private static final L3vpnMcastDestination MCAST_L3VPN_DESTINATION = new L3vpnMcastDestinationBuilder()
72             .setRouteDistinguisher(RD)
73             .setPrefix(IPV4_PREFIX)
74             .setPathId(PATH_ID)
75             .build();
76     private static final DestinationL3vpnMcastIpv4AdvertizedCase REACH_NLRI
77             = new DestinationL3vpnMcastIpv4AdvertizedCaseBuilder()
78             .setDestinationIpv4L3vpnMcast(new DestinationIpv4L3vpnMcastBuilder()
79                     .setL3vpnMcastDestination(Collections.singletonList(MCAST_L3VPN_DESTINATION)).build()).build();
80     private static final DestinationL3vpnMcastIpv4WithdrawnCase UNREACH_NLRI
81             = new DestinationL3vpnMcastIpv4WithdrawnCaseBuilder()
82             .setDestinationIpv4L3vpnMcast(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.ipv4.withdrawn._case.DestinationIpv4L3vpnMcastBuilder()
85                     .setL3vpnMcastDestination(Collections.singletonList(MCAST_L3VPN_DESTINATION)).build()).build();
86
87     private L3VpnMcastIpv4RIBSupport ribSupport;
88
89     @Override
90     public void setUp() throws Exception {
91         super.setUp();
92         ribSupport = L3VpnMcastIpv4RIBSupport.getInstance(this.adapter.currentSerializer());
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         Assert.assertEquals(createEmptyTable(), this.ribSupport.emptyTable());
115     }
116
117     @Test
118     public void testBuildMpUnreachNlriUpdate() {
119         final Collection<MapEntryNode> routes = createRoutes(MCAST_L3VPN_ROUTES);
120         final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), routes, ATTRIBUTES);
121         assertEquals(UNREACH_NLRI, update.getAttributes().augmentation(Attributes2.class).getMpUnreachNlri()
122                 .getWithdrawnRoutes().getDestinationType());
123         assertNull(update.getAttributes().augmentation(Attributes1.class));
124     }
125
126     @Test
127     public void testBuildMpReachNlriUpdate() {
128         final Collection<MapEntryNode> routes = createRoutes(MCAST_L3VPN_ROUTES);
129         final Update update = this.ribSupport.buildUpdate(routes, Collections.emptyList(), ATTRIBUTES);
130         assertEquals(REACH_NLRI, update.getAttributes().augmentation(Attributes1.class).getMpReachNlri()
131                 .getAdvertizedRoutes().getDestinationType());
132         assertNull(update.getAttributes().augmentation(Attributes2.class));
133     }
134
135     @Test
136     public void testCacheableNlriObjects() {
137         Assert.assertEquals(ImmutableSet.of(L3vpnMcastRoutesIpv4Case.class), this.ribSupport.cacheableNlriObjects());
138     }
139
140     @Test
141     public void testCacheableAttributeObjects() {
142         Assert.assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects());
143     }
144
145     @Test
146     public void testRouteIdAddPath() {
147         Assert.assertEquals(ROUTE_KEY, this.ribSupport.createRouteListKey(ROUTE_KEY.getPathId(),
148             ROUTE_KEY.getRouteKey()));
149     }
150
151     @Test
152     public void testRoutePath() {
153         final YangInstanceIdentifier.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);
157     }
158
159     @Test
160     public void testRouteAttributesIdentifier() {
161         Assert.assertEquals(new YangInstanceIdentifier.NodeIdentifier(
162                         Attributes.QNAME.withModule(BindingReflections.getQNameModule(L3vpnMcastRoutesIpv4Case.class))),
163                 this.ribSupport.routeAttributesIdentifier());
164     }
165
166     @Test
167     public void testRoutesCaseClass() {
168         Assert.assertEquals(L3vpnMcastRoutesIpv4Case.class, this.ribSupport.routesCaseClass());
169     }
170
171     @Test
172     public void testRoutesContainerClass() {
173         Assert.assertEquals(L3vpnMcastRoutesIpv4.class, this.ribSupport.routesContainerClass());
174     }
175
176     @Test
177     public void testRoutesListClass() {
178         Assert.assertEquals(L3vpnMcastRoute.class, this.ribSupport.routesListClass());
179     }
180
181     @Test
182     public void testChangedRoutes() {
183         final Routes emptyCase = new L3vpnMcastRoutesIpv4CaseBuilder().build();
184         DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(),
185                 createRoutes(emptyCase)).getRootNode();
186         assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
187
188         final Routes emptyRoutes
189                 = new L3vpnMcastRoutesIpv4CaseBuilder()
190                 .setL3vpnMcastRoutesIpv4(new L3vpnMcastRoutesIpv4Builder().build()).build();
191         tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
192         assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
193
194         final Routes routes = new L3vpnMcastRoutesIpv4CaseBuilder().setL3vpnMcastRoutesIpv4(MCAST_L3VPN_ROUTES).build();
195         tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
196         final Collection<DataTreeCandidateNode> result = this.ribSupport.changedRoutes(tree);
197         assertFalse(result.isEmpty());
198     }
199 }