Create common parent for extensions families
[bgpcep.git] / bgp / extensions / inet / src / test / java / org / opendaylight / protocol / bgp / inet / IPv6RIBSupportTest.java
diff --git a/bgp/extensions/inet/src/test/java/org/opendaylight/protocol/bgp/inet/IPv6RIBSupportTest.java b/bgp/extensions/inet/src/test/java/org/opendaylight/protocol/bgp/inet/IPv6RIBSupportTest.java
new file mode 100644 (file)
index 0000000..ffe084c
--- /dev/null
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.inet;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
+import java.util.Collection;
+import java.util.Collections;
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.bgp.rib.rib.loc.rib.tables.routes.Ipv6RoutesCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.bgp.rib.rib.loc.rib.tables.routes.Ipv6RoutesCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.prefixes.DestinationIpv6Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.prefixes.destination.ipv6.Ipv6Prefixes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.prefixes.destination.ipv6.Ipv6PrefixesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.routes.Ipv6Routes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.routes.Ipv6RoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.routes.ipv6.routes.Ipv6Route;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.routes.ipv6.routes.Ipv6RouteBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.routes.ipv6.routes.Ipv6RouteKey;
+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;
+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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
+
+public final class IPv6RIBSupportTest extends AbstractRIBSupportTest<Ipv6RoutesCase, Ipv6Routes, Ipv6Route,
+        Ipv6RouteKey> {
+    private IPv6RIBSupport ribSupport;
+    private static final PathId PATH_ID = new PathId(1L);
+    private static final Ipv6Prefix PREFIX = new Ipv6Prefix("2001:db8:1:2::/64");
+    private static final Ipv6RouteKey ROUTE_KEY = new Ipv6RouteKey(PATH_ID, PREFIX.getValue());
+    private static final Ipv6Prefixes IPV6_PREFIXES = new Ipv6PrefixesBuilder().setPathId(PATH_ID)
+            .setPrefix(PREFIX).build();
+    private static final DestinationIpv6Case REACH_NLRI = new DestinationIpv6CaseBuilder()
+            .setDestinationIpv6(new DestinationIpv6Builder()
+                    .setIpv6Prefixes(Lists.newArrayList(IPV6_PREFIXES)).build()).build();
+
+    private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update
+            .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6Case UNREACH_NLRI =
+            new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update
+                    .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6CaseBuilder()
+                    .setDestinationIpv6(new DestinationIpv6Builder()
+                            .setIpv6Prefixes(Collections.singletonList(IPV6_PREFIXES)).build()).build();
+
+    private static final Ipv6Route ROUTE = new Ipv6RouteBuilder()
+            .setRouteKey(PREFIX.getValue())
+            .setAttributes(ATTRIBUTES)
+            .setPathId(PATH_ID)
+            .setPrefix(PREFIX).build();
+    private static final Ipv6Routes ROUTES = new Ipv6RoutesBuilder()
+            .setIpv6Route(Collections.singletonList(ROUTE)).build();
+    private static final Ipv6Routes EMPTY_ROUTES = new Ipv6RoutesBuilder()
+            .setIpv6Route(Collections.emptyList()).build();
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        this.ribSupport = IPv6RIBSupport.getInstance(this.mappingService);
+        setUpTestCustomizer(this.ribSupport);
+    }
+
+    @Test
+    public void testDeleteRoutes() {
+        this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI));
+        final InstanceIdentifier<Ipv6Route> instanceIdentifier =
+                this.deletedRoutes.get(0);
+        assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(Ipv6Route.class));
+    }
+
+    @Test
+    public void testPutRoutes() {
+        this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes());
+        final Ipv6Route route = (Ipv6Route) this.insertedRoutes.get(0).getValue();
+        assertEquals(ROUTE, route);
+    }
+
+
+    @Test
+    public void testEmptyRoute() {
+        final Routes empty = new Ipv6RoutesCaseBuilder().setIpv6Routes(EMPTY_ROUTES).build();
+        assertEquals(createEmptyTable(empty), this.ribSupport.emptyTable());
+    }
+
+    @Test
+    public void testBuildMpUnreachNlriUpdate() {
+        final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES);
+        assertEquals(UNREACH_NLRI, update.getAttributes().augmentation(Attributes2.class)
+                .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType());
+        assertNull(update.getAttributes().augmentation(Attributes1.class));
+    }
+
+    @Test
+    public void testBuildMpReachNlriUpdate() {
+        final Update update = this.ribSupport.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES);
+        assertEquals(REACH_NLRI, update.getAttributes().augmentation(Attributes1.class)
+                .getMpReachNlri().getAdvertizedRoutes().getDestinationType());
+        assertNull(update.getAttributes().augmentation(Attributes2.class));
+    }
+
+    @Test
+    public void testCacheableNlriObjects() {
+        assertEquals(ImmutableSet.of(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet
+                .rev180329.Ipv6Prefix.class), this.ribSupport.cacheableNlriObjects());
+    }
+
+    @Test
+    public void testCacheableAttributeObjects() {
+        assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects());
+    }
+
+    @Test
+    public void testRouteIdAddPath() {
+        final Ipv6RouteKey expected = new Ipv6RouteKey(new PathId(1L), PREFIX.getValue());
+        assertEquals(expected, this.ribSupport.createRouteListKey(expected.getPathId().getValue(), PREFIX.getValue()));
+    }
+
+    @Test
+    public void testRoutePath() {
+        final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES);
+        assertEquals(getRoutePath().node(prefixNii),
+                this.ribSupport.routePath(getTablePath().node(Routes.QNAME), prefixNii));
+    }
+
+    @Test
+    public void testRouteAttributesIdentifier() {
+        assertEquals(new NodeIdentifier(QName.create(Ipv6Routes.QNAME,
+                Attributes.QNAME.getLocalName().intern())), this.ribSupport.routeAttributesIdentifier());
+    }
+
+    @Test
+    public void testRoutesCaseClass() {
+        assertEquals(Ipv6RoutesCase.class, this.ribSupport.routesCaseClass());
+    }
+
+    @Test
+    public void testRoutesContainerClass() {
+        assertEquals(Ipv6Routes.class, this.ribSupport.routesContainerClass());
+    }
+
+    @Test
+    public void testRoutesListClass() {
+        assertEquals(Ipv6Route.class, this.ribSupport.routesListClass());
+    }
+
+    @Test
+    public void testChangedRoutes() {
+        final Routes emptyCase = new Ipv6RoutesCaseBuilder().build();
+        DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(),
+                createRoutes(emptyCase)).getRootNode();
+        Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
+
+        final Routes emptyRoutes = new Ipv6RoutesCaseBuilder().setIpv6Routes(new Ipv6RoutesBuilder().build()).build();
+        tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
+        Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty());
+
+        final Routes routes = new Ipv6RoutesCaseBuilder().setIpv6Routes(ROUTES).build();
+        tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
+        final Collection<DataTreeCandidateNode> result = this.ribSupport.changedRoutes(tree);
+        Assert.assertFalse(result.isEmpty());
+    }
+}