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.labeled.unicast;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNull;
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;
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.Ipv6Prefix;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastIpv6RoutesCase;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastIpv6RoutesCaseBuilder;
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.ipv6.routes.LabeledUnicastIpv6Routes;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.ipv6.routes.LabeledUnicastIpv6RoutesBuilder;
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.DestinationIpv6LabeledUnicastCase;
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.DestinationIpv6LabeledUnicastCaseBuilder;
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.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder;
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;
58 public class LabeledUnicastIpv6RIBSupportTest extends AbstractRIBSupportTest<LabeledUnicastIpv6RoutesCase,
59 LabeledUnicastIpv6Routes, LabeledUnicastRoute, LabeledUnicastRouteKey> {
61 private static final IpPrefix IPV6_PREFIX = new IpPrefix(new Ipv6Prefix("102:304:500::/40"));
62 private static final LabeledUnicastRoute ROUTE;
63 private static final LabeledUnicastIpv6Routes 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(IPV6_PREFIX).build());
72 private static final DestinationIpv6LabeledUnicastCase REACH_NLRI
73 = new DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
74 new DestinationIpv6LabeledUnicastBuilder().setCLabeledUnicastDestination(LABELED_DESTINATION_LIST)
76 private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329
77 .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
78 .DestinationIpv6LabeledUnicastCase UNREACH_NLRI = new org.opendaylight.yang.gen.v1.urn.opendaylight.params
79 .xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination
80 .type.DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(new org.opendaylight
81 .yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp
82 .unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled.unicast._case
83 .DestinationIpv6LabeledUnicastBuilder().setCLabeledUnicastDestination(LABELED_DESTINATION_LIST).build())
85 private LabeledUnicastIpv6RIBSupport ribSupport;
88 final BGPActivator act = new BGPActivator();
89 final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
91 final ByteBuf buffer = Unpooled.buffer();
92 LUNlriParser.serializeNlri(LABELED_DESTINATION_LIST, false, buffer);
93 LABEL_KEY = ByteArray.encodeBase64(buffer);
94 ROUTE_KEY = new LabeledUnicastRouteKey(PATH_ID, LABEL_KEY);
95 ROUTE = new LabeledUnicastRouteBuilder().withKey(ROUTE_KEY)
96 .setPrefix(IPV6_PREFIX).setPathId(PATH_ID).setLabelStack(LABEL_STACK)
97 .setAttributes(new AttributesBuilder().build()).build();
98 ROUTES = new LabeledUnicastIpv6RoutesBuilder().setLabeledUnicastRoute(Map.of(ROUTE.key(), ROUTE)).build();
102 public void setUp() throws Exception {
104 this.ribSupport = new LabeledUnicastIpv6RIBSupport(this.adapter.currentSerializer());
105 setUpTestCustomizer(this.ribSupport);
109 public void testDeleteRoutes() {
110 this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI));
111 final InstanceIdentifier<LabeledUnicastRoute> instanceIdentifier = this.deletedRoutes.get(0);
112 assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(LabeledUnicastRoute.class));
116 public void testPutRoutes() {
117 this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes());
118 final LabeledUnicastRoute route = (LabeledUnicastRoute) this.insertedRoutes.get(0).getValue();
119 assertEquals(ROUTE, route);
123 public void testEmptyRoute() {
124 assertEquals(createEmptyTable(), this.ribSupport.emptyTable());
128 public void testBuildMpUnreachNlriUpdate() {
129 final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES);
130 assertEquals(UNREACH_NLRI, update.getAttributes().augmentation(Attributes2.class)
131 .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType());
132 assertNull(update.getAttributes().augmentation(Attributes1.class));
136 public void testBuildMpReachNlriUpdate() {
137 final Update update = this.ribSupport.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES);
138 assertEquals(REACH_NLRI, update.getAttributes().augmentation(Attributes1.class).getMpReachNlri()
139 .getAdvertizedRoutes().getDestinationType());
140 assertNull(update.getAttributes().augmentation(Attributes2.class));
144 public void testCacheableNlriObjects() {
145 assertEquals(ImmutableSet.of(), this.ribSupport.cacheableNlriObjects());
149 public void testCacheableAttributeObjects() {
150 assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects());
154 public void testRouteIdAddPath() {
155 assertEquals(ROUTE_KEY, this.ribSupport.createRouteListKey(ROUTE_KEY.getPathId(), ROUTE_KEY.getRouteKey()));
159 public void testRoutePath() {
160 final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES);
161 assertEquals(getRoutePath().node(prefixNii),
162 this.ribSupport.routePath(getTablePath(), prefixNii));
166 public void testRouteAttributesIdentifier() {
167 assertEquals(new NodeIdentifier(QName.create(LabeledUnicastIpv6Routes.QNAME,
168 org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables
169 .Attributes.QNAME.getLocalName().intern())),
170 this.ribSupport.routeAttributesIdentifier());
174 public void testRoutesCaseClass() {
175 assertEquals(LabeledUnicastIpv6RoutesCase.class, this.ribSupport.routesCaseClass());
179 public void testRoutesContainerClass() {
180 assertEquals(LabeledUnicastIpv6Routes.class, this.ribSupport.routesContainerClass());
184 public void testRoutesListClass() {
185 assertEquals(LabeledUnicastRoute.class, this.ribSupport.routesListClass());
189 public void testChangedRoutes() {
190 final Routes emptyCase = new LabeledUnicastIpv6RoutesCaseBuilder().build();
191 DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(),
192 createRoutes(emptyCase)).getRootNode();
193 Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
195 final Routes emptyRoutes = new LabeledUnicastIpv6RoutesCaseBuilder()
196 .setLabeledUnicastIpv6Routes(new LabeledUnicastIpv6RoutesBuilder().build()).build();
197 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
198 Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
200 final Routes routes = new LabeledUnicastIpv6RoutesCaseBuilder().setLabeledUnicastIpv6Routes(ROUTES).build();
201 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
202 final Collection<DataTreeCandidateNode> result = this.ribSupport.changedRoutes(tree);
203 Assert.assertFalse(result.isEmpty());