Cleanup deprecation warnings in bgp/extensions/labeled-unicast
[bgpcep.git] / bgp / extensions / labeled-unicast / src / test / java / org / opendaylight / protocol / bgp / labeled / unicast / LabeledUnicastIpv4RIBSupportTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  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.labeled.unicast;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNull;
12
13 import com.google.common.collect.ImmutableSet;
14 import com.google.common.collect.Lists;
15 import io.netty.buffer.ByteBuf;
16 import io.netty.buffer.Unpooled;
17 import java.util.Collection;
18 import java.util.Collections;
19 import java.util.List;
20 import java.util.Map;
21 import org.junit.Assert;
22 import org.junit.Test;
23 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
24 import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
25 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest;
26 import org.opendaylight.protocol.util.ByteArray;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastRoutesCase;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastRoutesCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.LabelStack;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.LabelStackBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.destination.CLabeledUnicastDestination;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.destination.CLabeledUnicastDestinationBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.LabeledUnicastRoutes;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.LabeledUnicastRoutesBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.list.LabeledUnicastRoute;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.list.LabeledUnicastRouteBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.list.LabeledUnicastRouteKey;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLabeledUnicastCase;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLabeledUnicastCaseBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel;
50 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
51 import org.opendaylight.yangtools.yang.common.QName;
52 import org.opendaylight.yangtools.yang.common.Uint32;
53 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
54 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
55 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
56 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
57
58 public class LabeledUnicastIpv4RIBSupportTest extends AbstractRIBSupportTest<LabeledUnicastRoutesCase,
59         LabeledUnicastRoutes, LabeledUnicastRoute, LabeledUnicastRouteKey> {
60
61     private static final IpPrefix IPV4_PREFIX = new IpPrefix(new Ipv4Prefix("34.1.22.0/24"));
62     private static final LabeledUnicastRoute ROUTE;
63     private static final LabeledUnicastRoutes ROUTES;
64     private static final LabeledUnicastRouteKey ROUTE_KEY;
65     private static final String LABEL_KEY;
66     private static final PathId PATH_ID = new PathId(Uint32.ONE);
67     private static final List<LabelStack> LABEL_STACK = Lists.newArrayList(new LabelStackBuilder()
68             .setLabelValue(new MplsLabel(Uint32.valueOf(355))).build());
69     private static final List<CLabeledUnicastDestination> LABELED_DESTINATION_LIST
70             = Collections.singletonList(new CLabeledUnicastDestinationBuilder()
71             .setPathId(PATH_ID).setLabelStack(LABEL_STACK).setPrefix(IPV4_PREFIX).build());
72     private static final DestinationLabeledUnicastCase REACH_NLRI = new DestinationLabeledUnicastCaseBuilder()
73             .setDestinationLabeledUnicast(new DestinationLabeledUnicastBuilder()
74                     .setCLabeledUnicastDestination(LABELED_DESTINATION_LIST).build()).build();
75     private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast
76             .rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
77             .DestinationLabeledUnicastCase UNREACH_NLRI = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml
78             .ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
79             .DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(new org.opendaylight.yang.gen.v1.urn
80             .opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn
81             .routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder()
82             .setCLabeledUnicastDestination(LABELED_DESTINATION_LIST).build()).build();
83
84     static {
85         final BGPActivator act = new BGPActivator();
86         final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
87         act.start(context);
88         final ByteBuf buffer = Unpooled.buffer();
89         LUNlriParser.serializeNlri(LABELED_DESTINATION_LIST, false, buffer);
90         LABEL_KEY = ByteArray.encodeBase64(buffer);
91         ROUTE_KEY = new LabeledUnicastRouteKey(PATH_ID, LABEL_KEY);
92         ROUTE = new LabeledUnicastRouteBuilder()
93                 .withKey(ROUTE_KEY)
94                 .setPrefix(IPV4_PREFIX)
95                 .setPathId(PATH_ID)
96                 .setLabelStack(LABEL_STACK)
97                 .setAttributes(new AttributesBuilder().build()).build();
98         ROUTES = new LabeledUnicastRoutesBuilder().setLabeledUnicastRoute(Map.of(ROUTE.key(), ROUTE)).build();
99     }
100
101     private LabeledUnicastIpv4RIBSupport ribSupport;
102
103     @Override
104     public void setUp() throws Exception {
105         super.setUp();
106         this.ribSupport = LabeledUnicastIpv4RIBSupport.getInstance(this.adapter.currentSerializer());
107         setUpTestCustomizer(this.ribSupport);
108     }
109
110     @Test
111     public void testDeleteRoutes() {
112         this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI));
113         final InstanceIdentifier<LabeledUnicastRoute> instanceIdentifier = this.deletedRoutes.get(0);
114         assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(LabeledUnicastRoute.class));
115     }
116
117     @Test
118     public void testPutRoutes() {
119         this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes());
120         final LabeledUnicastRoute route = (LabeledUnicastRoute) this.insertedRoutes.get(0).getValue();
121         assertEquals(ROUTE, route);
122     }
123
124     @Test
125     public void testEmptyRoute() {
126         assertEquals(createEmptyTable(), this.ribSupport.emptyTable());
127     }
128
129     @Test
130     public void testBuildMpUnreachNlriUpdate() {
131         final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES);
132         assertEquals(UNREACH_NLRI, update.getAttributes().augmentation(Attributes2.class)
133             .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType());
134         assertNull(update.getAttributes().augmentation(Attributes1.class));
135     }
136
137     @Test
138     public void testBuildMpReachNlriUpdate() {
139         final Update update = this.ribSupport.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES);
140         assertEquals(REACH_NLRI, update.getAttributes().augmentation(Attributes1.class).getMpReachNlri()
141                 .getAdvertizedRoutes().getDestinationType());
142         assertNull(update.getAttributes().augmentation(Attributes2.class));
143     }
144
145     @Test
146     public void testCacheableNlriObjects() {
147         assertEquals(ImmutableSet.of(), this.ribSupport.cacheableNlriObjects());
148     }
149
150     @Test
151     public void testCacheableAttributeObjects() {
152         assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects());
153     }
154
155     @Test
156     public void testRouteIdAddPath() {
157         assertEquals(ROUTE_KEY, this.ribSupport.createRouteListKey(ROUTE_KEY.getPathId(), ROUTE_KEY.getRouteKey()));
158     }
159
160     @Test
161     public void testRoutePath() {
162         final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES);
163         assertEquals(getRoutePath().node(prefixNii),
164                 this.ribSupport.routePath(getTablePath(), prefixNii));
165     }
166
167     @Test
168     public void testRouteAttributesIdentifier() {
169         assertEquals(new NodeIdentifier(QName.create(LabeledUnicastRoutes.QNAME,
170             org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables
171                     .Attributes.QNAME.getLocalName().intern())),
172             this.ribSupport.routeAttributesIdentifier());
173     }
174
175     @Test
176     public void testRoutesCaseClass() {
177         assertEquals(LabeledUnicastRoutesCase.class, this.ribSupport.routesCaseClass());
178     }
179
180     @Test
181     public void testRoutesContainerClass() {
182         assertEquals(LabeledUnicastRoutes.class, this.ribSupport.routesContainerClass());
183     }
184
185     @Test
186     public void testRoutesListClass() {
187         assertEquals(LabeledUnicastRoute.class, this.ribSupport.routesListClass());
188     }
189
190     @Test
191     public void testChangedRoutes() {
192         final Routes emptyCase = new LabeledUnicastRoutesCaseBuilder().build();
193         DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(),
194                 createRoutes(emptyCase)).getRootNode();
195         Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
196
197         final Routes emptyRoutes = new LabeledUnicastRoutesCaseBuilder()
198                 .setLabeledUnicastRoutes(new LabeledUnicastRoutesBuilder().build()).build();
199         tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
200         Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
201
202         final Routes routes = new LabeledUnicastRoutesCaseBuilder().setLabeledUnicastRoutes(ROUTES).build();
203         tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
204         final Collection<DataTreeCandidateNode> result = this.ribSupport.changedRoutes(tree);
205         Assert.assertFalse(result.isEmpty());
206     }
207 }