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
9 package org.opendaylight.protocol.bgp.rib.impl;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNull;
15 import com.google.common.collect.ImmutableMap;
16 import com.google.common.collect.ImmutableSet;
17 import com.google.common.collect.Iterables;
18 import com.google.common.collect.Lists;
19 import java.util.Collection;
20 import java.util.Collections;
21 import org.junit.Assert;
22 import org.junit.Test;
23 import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.bgp.rib.rib.loc.rib.tables.routes.Ipv6RoutesCase;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.bgp.rib.rib.loc.rib.tables.routes.Ipv6RoutesCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.DestinationIpv6Builder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.destination.ipv6.Ipv6Prefixes;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.destination.ipv6.Ipv6PrefixesBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.routes.Ipv6Routes;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.routes.Ipv6RoutesBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.routes.ipv6.routes.Ipv6Route;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.routes.ipv6.routes.Ipv6RouteBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.routes.ipv6.routes.Ipv6RouteKey;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6Case;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6CaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes;
43 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
44 import org.opendaylight.yangtools.yang.common.QName;
45 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
46 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
47 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
48 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
49 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
50 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
52 public final class IPv6RIBSupportTest extends AbstractRIBSupportTest {
53 private static final IPv6RIBSupport RIB_SUPPORT = IPv6RIBSupport.getInstance();
54 private static final PathId PATH_ID = new PathId(1L);
55 private static final Ipv6Prefix PREFIX = new Ipv6Prefix("2001:db8:1:2::/64");
56 private static final Ipv6RouteKey ROUTE_KEY = new Ipv6RouteKey(PATH_ID, PREFIX);
57 private static final Ipv6Prefixes IPV6_PREFIXES = new Ipv6PrefixesBuilder().setPathId(PATH_ID)
58 .setPrefix(PREFIX).build();
59 private static final DestinationIpv6Case REACH_NLRI = new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder()
60 .setIpv6Prefixes(Lists.newArrayList(IPV6_PREFIXES)).build()).build();
62 private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update
63 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6Case UNREACH_NLRI =
64 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update
65 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6CaseBuilder().setDestinationIpv6(
66 new DestinationIpv6Builder().setIpv6Prefixes(Lists.newArrayList(IPV6_PREFIXES)).build()).build();
68 private static final Ipv6Route ROUTE = new Ipv6RouteBuilder().setAttributes(ATTRIBUTES).setPathId(PATH_ID).setPrefix(PREFIX).build();
69 private static final Ipv6Routes ROUTES = new Ipv6RoutesBuilder().setIpv6Route(Collections.singletonList(ROUTE)).build();
70 private static final Ipv6Routes EMPTY_ROUTES = new Ipv6RoutesBuilder().setIpv6Route(Collections.emptyList()).build();
73 public void setUp() throws Exception {
75 setUpTestCustomizer(RIB_SUPPORT);
79 public void testDeleteRoutes() {
80 RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI));
81 final InstanceIdentifier<Ipv6Route> instanceIdentifier = (InstanceIdentifier<Ipv6Route>) this.deletedRoutes.get(0);
82 assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(Ipv6Route.class));
86 public void testPutRoutes() {
87 RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes());
88 final Ipv6Route route = (Ipv6Route) this.insertedRoutes.get(0).getValue();
89 assertEquals(ROUTE, route);
94 public void testEmptyRoute() throws Exception {
95 final Routes empty = new Ipv6RoutesCaseBuilder().setIpv6Routes(EMPTY_ROUTES).build();
96 final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes();
97 assertEquals(createRoutes(empty), emptyRoutes);
101 public void testBuildMpUnreachNlriUpdate() {
102 final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES);
103 assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getWithdrawnRoutes().getDestinationType());
104 assertNull(update.getAttributes().getAugmentation(Attributes1.class));
108 public void testBuildMpReachNlriUpdate() {
109 final Update update = RIB_SUPPORT.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES);
110 assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri().getAdvertizedRoutes().getDestinationType());
111 assertNull(update.getAttributes().getAugmentation(Attributes2.class));
115 public void testIsComplexRoute() {
116 Assert.assertFalse(RIB_SUPPORT.isComplexRoute());
120 public void testCacheableNlriObjects() {
121 Assert.assertEquals(ImmutableSet.of(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.Ipv6Prefix.class),
122 RIB_SUPPORT.cacheableNlriObjects());
126 public void testCacheableAttributeObjects() {
127 Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects());
131 public void testRouteIdAddPath() {
132 final NodeIdentifierWithPredicates expected = createRouteNIWP(ROUTES);
133 final NodeIdentifierWithPredicates prefixNii = new NodeIdentifierWithPredicates(RIB_SUPPORT.routeQName(), ImmutableMap.of(RIB_SUPPORT.routeKeyQName(), PREFIX.getValue()));
134 Assert.assertEquals(expected, RIB_SUPPORT.getRouteIdAddPath(AbstractRIBSupportTest.PATH_ID, prefixNii));
138 public void testRoutePath() {
139 final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES);
140 Assert.assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii));
145 public void testExtractPathId() {
146 final NormalizedNode<?, ?> route = Iterables.getOnlyElement(createRoutes(ROUTES));
147 Assert.assertEquals(PATH_ID.getValue(), RIB_SUPPORT.extractPathId(route));
151 public void testRouteAttributesIdentifier() {
152 Assert.assertEquals(new NodeIdentifier(QName.create(Ipv6Routes.QNAME, Attributes.QNAME.getLocalName().intern())), RIB_SUPPORT
153 .routeAttributesIdentifier());
157 public void testRoutesCaseClass() {
158 Assert.assertEquals(Ipv6RoutesCase.class, RIB_SUPPORT.routesCaseClass());
162 public void testRoutesContainerClass() {
163 Assert.assertEquals(Ipv6Routes.class, RIB_SUPPORT.routesContainerClass());
167 public void testRoutesListClass() {
168 Assert.assertEquals(Ipv6Route.class, RIB_SUPPORT.routesListClass());
172 public void testChangedRoutes() {
173 final Routes emptyCase = new Ipv6RoutesCaseBuilder().build();
174 DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode();
175 Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty());
177 final Routes emptyRoutes = new Ipv6RoutesCaseBuilder().setIpv6Routes(new Ipv6RoutesBuilder().build()).build();
178 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
179 Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty());
181 final Routes routes = new Ipv6RoutesCaseBuilder().setIpv6Routes(ROUTES).build();
182 tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
183 final Collection<DataTreeCandidateNode> result = RIB_SUPPORT.changedRoutes(tree);
184 Assert.assertFalse(result.isEmpty());