/* * 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.l3vpn.unicast.ipv6; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.opendaylight.protocol.bgp.l3vpn.unicast.ipv6.VpnIpv6NlriParserTest.DISTINGUISHER; import static org.opendaylight.protocol.bgp.l3vpn.unicast.ipv6.VpnIpv6NlriParserTest.IPV6PREFIX; import static org.opendaylight.protocol.bgp.l3vpn.unicast.ipv6.VpnIpv6NlriParserTest.IPV6_VPN; import static org.opendaylight.protocol.bgp.l3vpn.unicast.ipv6.VpnIpv6NlriParserTest.LABEL_STACK; import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import java.util.Collection; import java.util.Collections; import java.util.Map; import org.junit.Assert; import org.junit.Test; import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.bgp.rib.rib.loc.rib.tables.routes.VpnIpv6RoutesCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.bgp.rib.rib.loc.rib.tables.routes.VpnIpv6RoutesCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.l3vpn.ipv6.destination.VpnIpv6DestinationBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.l3vpn.ipv6.routes.VpnIpv6Routes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.l3vpn.ipv6.routes.VpnIpv6RoutesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationVpnIpv6Case; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationVpnIpv6CaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev180329.l3vpn.ip.route.VpnRoute; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev180329.l3vpn.ip.route.VpnRouteBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev180329.l3vpn.ip.route.VpnRouteKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.Uint32; 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 class VpnIpv6RIBSupportTest extends AbstractRIBSupportTest { private VpnIpv6RIBSupport ribSupport; private static final DestinationVpnIpv6Case REACH_NLRI = new DestinationVpnIpv6CaseBuilder() .setVpnIpv6Destination(new VpnIpv6DestinationBuilder() .setVpnDestination(Lists.newArrayList(IPV6_VPN)).build()).build(); private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.update .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv6Case UNREACH_NLRI = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.update .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv6CaseBuilder() .setVpnIpv6Destination(new VpnIpv6DestinationBuilder() .setVpnDestination(Collections.singletonList(IPV6_VPN)).build()).build(); private static final VpnRouteKey ROUTE_KEY = new VpnRouteKey(new PathId(Uint32.ZERO), "cAABAQIDBAECIAEjRVaJ"); private static final VpnRoute ROUTE = new VpnRouteBuilder().setPathId(NON_PATH_ID) .setAttributes(ATTRIBUTES).setPrefix(IPV6PREFIX) .setLabelStack(LABEL_STACK).setRouteDistinguisher(DISTINGUISHER).withKey(ROUTE_KEY).build(); private static final VpnIpv6Routes ROUTES = new VpnIpv6RoutesBuilder() .setVpnRoute(Map.of(ROUTE.key(), ROUTE)).build(); @Override public void setUp() throws Exception { super.setUp(); this.ribSupport = new VpnIpv6RIBSupport(this.adapter.currentSerializer()); setUpTestCustomizer(this.ribSupport); } @Test public void testDeleteRoutes() { this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); final InstanceIdentifier instanceIdentifier = this.deletedRoutes.get(0); assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(VpnRoute.class)); } @Test public void testPutRoutes() { this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); final VpnRoute route = (VpnRoute) this.insertedRoutes.get(0).getValue(); assertEquals(ROUTE, route); } @Test public void testEmptyRoute() { assertEquals(createEmptyTable(), 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(), this.ribSupport.cacheableNlriObjects()); } @Test public void testCacheableAttributeObjects() { assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects()); } @Test public void testRoutePath() { final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES); assertEquals(getRoutePath().node(prefixNii), this.ribSupport.routePath(getTablePath(), prefixNii)); } @Test public void testRouteAttributesIdentifier() { assertEquals(new NodeIdentifier(QName.create(VpnIpv6Routes.QNAME, Attributes.QNAME.getLocalName().intern())), this.ribSupport.routeAttributesIdentifier()); } @Test public void testRoutesCaseClass() { assertEquals(VpnIpv6RoutesCase.class, this.ribSupport.routesCaseClass()); } @Test public void testRoutesContainerClass() { assertEquals(VpnIpv6Routes.class, this.ribSupport.routesContainerClass()); } @Test public void testRoutesListClass() { assertEquals(VpnRoute.class, this.ribSupport.routesListClass()); } @Test public void testChangedRoutes() { final Routes emptyCase = new VpnIpv6RoutesCaseBuilder().build(); DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode(); Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); final Routes emptyRoutes = new VpnIpv6RoutesCaseBuilder() .setVpnIpv6Routes(new VpnIpv6RoutesBuilder().build()).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); final Routes routes = new VpnIpv6RoutesCaseBuilder().setVpnIpv6Routes(ROUTES).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode(); final Collection result = this.ribSupport.changedRoutes(tree); Assert.assertFalse(result.isEmpty()); } }