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.inet;
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 java.util.Collection;
16 import java.util.Collections;
18 import org.junit.Assert;
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.Ipv6Prefix;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.bgp.rib.rib.loc.rib.tables.routes.Ipv6RoutesCase;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.bgp.rib.rib.loc.rib.tables.routes.Ipv6RoutesCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.prefixes.DestinationIpv6Builder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.prefixes.destination.ipv6.Ipv6Prefixes;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.prefixes.destination.ipv6.Ipv6PrefixesBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.routes.Ipv6Routes;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.routes.Ipv6RoutesBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.routes.ipv6.routes.Ipv6Route;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.routes.ipv6.routes.Ipv6RouteBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.routes.ipv6.routes.Ipv6RouteKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6Case;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6CaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
41 import org.opendaylight.yangtools.yang.common.QName;
42 import org.opendaylight.yangtools.yang.common.Uint32;
43 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
44 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
45 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
46 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
48 public final class IPv6RIBSupportTest extends AbstractRIBSupportTest<Ipv6RoutesCase, Ipv6Routes, Ipv6Route,
50 private IPv6RIBSupport ribSupport;
51 private static final PathId PATH_ID = new PathId(Uint32.ONE);
52 private static final Ipv6Prefix PREFIX = new Ipv6Prefix("2001:db8:1:2::/64");
53 private static final Ipv6RouteKey ROUTE_KEY = new Ipv6RouteKey(PATH_ID, PREFIX.getValue());
54 private static final Ipv6Prefixes IPV6_PREFIXES = new Ipv6PrefixesBuilder().setPathId(PATH_ID)
55 .setPrefix(PREFIX).build();
56 private static final DestinationIpv6Case REACH_NLRI = new DestinationIpv6CaseBuilder()
57 .setDestinationIpv6(new DestinationIpv6Builder()
58 .setIpv6Prefixes(Lists.newArrayList(IPV6_PREFIXES)).build()).build();
60 private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update
61 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6Case UNREACH_NLRI =
62 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update
63 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6CaseBuilder()
64 .setDestinationIpv6(new DestinationIpv6Builder()
65 .setIpv6Prefixes(Collections.singletonList(IPV6_PREFIXES)).build()).build();
67 private static final Ipv6Route ROUTE = new Ipv6RouteBuilder()
68 .setRouteKey(PREFIX.getValue())
69 .setAttributes(ATTRIBUTES)
71 .setPrefix(PREFIX).build();
72 private static final Ipv6Routes ROUTES = new Ipv6RoutesBuilder().setIpv6Route(Map.of(ROUTE.key(), ROUTE)).build();
75 public void setUp() throws Exception {
77 this.ribSupport = IPv6RIBSupport.getInstance(this.adapter.currentSerializer());
78 setUpTestCustomizer(this.ribSupport);
82 public void testDeleteRoutes() {
83 this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI));
84 final InstanceIdentifier<Ipv6Route> instanceIdentifier =
85 this.deletedRoutes.get(0);
86 assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(Ipv6Route.class));
90 public void testPutRoutes() {
91 this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes());
92 final Ipv6Route route = (Ipv6Route) this.insertedRoutes.get(0).getValue();
93 assertEquals(ROUTE, route);
98 public void testEmptyRoute() {
99 assertEquals(createEmptyTable(), this.ribSupport.emptyTable());
103 public void testBuildMpUnreachNlriUpdate() {
104 final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES);
105 assertEquals(UNREACH_NLRI, update.getAttributes().augmentation(Attributes2.class)
106 .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType());
107 assertNull(update.getAttributes().augmentation(Attributes1.class));
111 public void testBuildMpReachNlriUpdate() {
112 final Update update = this.ribSupport.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES);
113 assertEquals(REACH_NLRI, update.getAttributes().augmentation(Attributes1.class)
114 .getMpReachNlri().getAdvertizedRoutes().getDestinationType());
115 assertNull(update.getAttributes().augmentation(Attributes2.class));
119 public void testCacheableNlriObjects() {
120 assertEquals(ImmutableSet.of(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet
121 .rev180329.Ipv6Prefix.class), this.ribSupport.cacheableNlriObjects());
125 public void testCacheableAttributeObjects() {
126 assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects());
130 public void testRouteIdAddPath() {
131 final Ipv6RouteKey expected = new Ipv6RouteKey(new PathId(Uint32.ONE), PREFIX.getValue());
132 assertEquals(expected, this.ribSupport.createRouteListKey(expected.getPathId(), PREFIX.getValue()));
136 public void testRoutePath() {
137 final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES);
138 assertEquals(getRoutePath().node(prefixNii),
139 this.ribSupport.routePath(getTablePath(), prefixNii));
143 public void testRouteAttributesIdentifier() {
144 assertEquals(new NodeIdentifier(QName.create(Ipv6Routes.QNAME,
145 Attributes.QNAME.getLocalName().intern())), this.ribSupport.routeAttributesIdentifier());
149 public void testRoutesCaseClass() {
150 assertEquals(Ipv6RoutesCase.class, this.ribSupport.routesCaseClass());
154 public void testRoutesContainerClass() {
155 assertEquals(Ipv6Routes.class, this.ribSupport.routesContainerClass());
159 public void testRoutesListClass() {
160 assertEquals(Ipv6Route.class, this.ribSupport.routesListClass());
164 public void testChangedRoutes() {
165 final Routes emptyCase = new Ipv6RoutesCaseBuilder().build();
166 DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(),
167 createRoutes(emptyCase)).getRootNode();
168 Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
170 final Routes emptyRoutes = new Ipv6RoutesCaseBuilder().setIpv6Routes(new Ipv6RoutesBuilder().build()).build();
171 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
172 Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
174 final Routes routes = new Ipv6RoutesCaseBuilder().setIpv6Routes(ROUTES).build();
175 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
176 final Collection<DataTreeCandidateNode> result = this.ribSupport.changedRoutes(tree);
177 Assert.assertFalse(result.isEmpty());