From: Claudio D. Gasparini Date: Thu, 9 Jun 2016 18:36:00 +0000 (+0200) Subject: BUG-6020: Implement Ribsupport for extensions X-Git-Tag: release/boron~109 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=d8052134e97e30be776380be762f79cd6f0de4f2;p=bgpcep.git BUG-6020: Implement Ribsupport for extensions +Linkstate +Evpn +L3VPN +BGP-LU +BGP-FS Change-Id: I966ef06d5e48286e0de03edc74a749c69f4f27b5 Signed-off-by: Claudio D. Gasparini --- diff --git a/bgp/evpn/pom.xml b/bgp/evpn/pom.xml index 46a8bba66e..6dd0f7f184 100644 --- a/bgp/evpn/pom.xml +++ b/bgp/evpn/pom.xml @@ -52,6 +52,12 @@ ${project.groupId} bgp-rib-spi + + ${project.groupId} + bgp-rib-spi + test + test-jar + ${project.groupId} bgp-parser-api @@ -103,6 +109,11 @@ mockito-core test + + org.opendaylight.controller + sal-binding-broker-impl + test + diff --git a/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/EvpnRibSupport.java b/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/EvpnRibSupport.java index 7db5692a49..d39be19a05 100644 --- a/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/EvpnRibSupport.java +++ b/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/EvpnRibSupport.java @@ -23,7 +23,7 @@ import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupport; import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.EvpnSubsequentAddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.L2vpnAddressFamily; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.application.rib.tables.routes.EvpnRoutesCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.bgp.rib.rib.loc.rib.tables.routes.EvpnRoutesCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.destination.EvpnDestination; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.EvpnRoutes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.EvpnRoute; diff --git a/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/EvpnRibSupportTest.java b/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/EvpnRibSupportTest.java index e0d0f6bfbb..2e6dc976ea 100644 --- a/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/EvpnRibSupportTest.java +++ b/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/EvpnRibSupportTest.java @@ -7,102 +7,186 @@ */ package org.opendaylight.protocol.bgp.evpn.impl; -/** - * TODO: Remove, instead use Common Rib Support test - */ -public class EvpnRibSupportTest { -/* - private static final NodeIdentifier RD_NID = NodeIdentifier.create(QName.create(EvpnChoice.QNAME, "route-distinguisher").intern()); - private static final NodeIdentifier ROUTES_NODE_ID = new NodeIdentifier(Routes.QNAME); - private static final Ipv4Address ipv4 = new Ipv4Address("42.42.42.42"); - private static final NodeIdentifier DESTINATION_NID = NodeIdentifier.create(EvpnDestination.QNAME); - private final EvpnRibSupport evpnRibSupport = EvpnRibSupport.getInstance(); - private final List evpnList = new ArrayList<>(); - private List routes; - @Mock - private DOMDataWriteTransaction tx; - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - routes = new ArrayList<>(); - Mockito.doAnswer(new Answer() { - @Override - public Object answer(final InvocationOnMock invocation) throws Throwable { - final Object[] args = invocation.getArguments(); - EvpnRibSupportTest.this.routes.add((YangInstanceIdentifier) args[1]); - return args[1]; - } - }).when(this.tx).put(Mockito.any(LogicalDatastoreType.class), Mockito.any(YangInstanceIdentifier.class), Mockito.any(NormalizedNode.class)); +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.RD; +import static org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest.ETHERNET_AD_ROUTE_CASE; +import static org.opendaylight.protocol.bgp.evpn.impl.nlri.EthADRParserTest.ETHERNET_AD_ROUTE_CASE_KEY; +import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID; + +import com.google.common.collect.ImmutableSet; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.util.Collection; +import java.util.Collections; +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.protocol.bgp.evpn.impl.nlri.EvpnNlriParser; +import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.EvpnSubsequentAddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.L2vpnAddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.bgp.rib.rib.loc.rib.tables.routes.EvpnRoutesCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.bgp.rib.rib.loc.rib.tables.routes.EvpnRoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.destination.EvpnDestination; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.destination.EvpnDestinationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.EvpnRoutes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.EvpnRoutesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.EvpnRoute; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.EvpnRouteBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.evpn.routes.evpn.routes.EvpnRouteKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationEvpnCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationEvpnCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.evpn._case.DestinationEvpnBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Attributes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.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.ChoiceNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates; + +public final class EvpnRibSupportTest extends AbstractRIBSupportTest { + private static final EvpnRibSupport RIB_SUPPORT = EvpnRibSupport.getInstance(); + private static final EvpnRoute ROUTE; + private static final EvpnRouteKey ROUTE_KEY; + private static final EvpnDestination EVPN_DESTINATION = new EvpnDestinationBuilder().setRouteDistinguisher(RD).setEvpnChoice(ETHERNET_AD_ROUTE_CASE).build(); + private static final DestinationEvpnCase REACH_NLRI = new DestinationEvpnCaseBuilder().setDestinationEvpn(new DestinationEvpnBuilder() + .setEvpnDestination(Collections.singletonList(EVPN_DESTINATION)).build()).build(); + private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationEvpnCase UNREACH_NLRI = + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type. + DestinationEvpnCaseBuilder().setDestinationEvpn(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev160321.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.evpn._case. + DestinationEvpnBuilder().setEvpnDestination(Collections.singletonList(EVPN_DESTINATION)).build()).build(); + + private static final EvpnRoutes EVPN_ROUTES; + static { + final BGPActivator act = new BGPActivator(); + final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext(); + act.start(context); + final ByteBuf buffer = Unpooled.buffer(); + EvpnNlriParser.serializeNlri(Collections.singletonList(new EvpnDestinationBuilder().setRouteDistinguisher(RD).setEvpnChoice(ETHERNET_AD_ROUTE_CASE_KEY).build()), buffer); + final byte[] arrayKey = ByteArray.readAllBytes(buffer); + ROUTE_KEY = new EvpnRouteKey(arrayKey); + ROUTE = new EvpnRouteBuilder().setRouteKey(arrayKey).setAttributes(ATTRIBUTES).setRouteDistinguisher(RD).setEvpnChoice(ETHERNET_AD_ROUTE_CASE).build(); + EVPN_ROUTES = new EvpnRoutesBuilder().setEvpnRoute(Collections.singletonList(ROUTE)).build(); + } - Mockito.doAnswer(new Answer() { - @Override - public Object answer(final InvocationOnMock invocation) throws Throwable { - final Object[] args = invocation.getArguments(); - EvpnRibSupportTest.this.routes.remove(args[1]); - return args[1]; - } - }).when(this.tx).delete(Mockito.any(LogicalDatastoreType.class), Mockito.any(YangInstanceIdentifier.class)); + + @Override + public void setUp() throws Exception { + super.setUp(); + setUpTestCustomizer(RIB_SUPPORT); } + @Test + public void testDeleteRoutes() { + RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = (InstanceIdentifier) this.deletedRoutes.get(0); + assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(EvpnRoute.class)); + } @Test - public void testbuildReach() throws BGPParsingException { - final CNextHop hop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(ipv4).build()).build(); - final MpReachNlri result = evpnRibSupport.buildReach(evpnList, hop); - assertEquals(L2vpnAddressFamily.class, result.getAfi()); - assertEquals(EvpnSubsequentAddressFamily.class, result.getSafi()); - assertEquals(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("42.42.42.42")).build()).build(), result.getCNextHop()); + public void testPutRoutes() { + RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + final EvpnRoute route = (EvpnRoute) this.insertedRoutes.get(0).getValue(); + assertEquals(ROUTE, route); } + @Test - public void testBuildUnreach() { - final MpUnreachNlri result = evpnRibSupport.buildUnreach(evpnList); - assertEquals(L2vpnAddressFamily.class, result.getAfi()); - assertEquals(EvpnSubsequentAddressFamily.class, result.getSafi()); + public void testEmptyRoute() throws Exception { + final Routes empty = new EvpnRoutesCaseBuilder().setEvpnRoutes(new EvpnRoutesBuilder().setEvpnRoute(Collections.emptyList()).build()).build(); + final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + assertEquals(createRoutes(empty), emptyRoutes); } @Test - public void testDestRoutesEthADRModel() { - ESIActivator.registerEsiTypeParsers(new ArrayList<>()); - NlriActivator.registerNlriParsers(new ArrayList<>()); + public void testBuildMpUnreachNlriUpdate() { + final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(EVPN_ROUTES), ATTRIBUTES); + assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); + assertNull(update.getAttributes().getAugmentation(Attributes1.class)); + } - final DataContainerNodeAttrBuilder evpnBI = ImmutableUnkeyedListEntryNodeBuilder.create(); - evpnBI.withNodeIdentifier(EVPN_NID); - evpnBI.withChild(EthADRParserTest.createEthADRModel()); - evpnBI.withChild(createValueBuilder(RD_MODEL, RD_NID).build()); + @Test + public void testBuildMpReachNlriUpdate() { + final Update update = RIB_SUPPORT.buildUpdate(createRoutes(EVPN_ROUTES), Collections.emptyList(), ATTRIBUTES); + assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri().getAdvertizedRoutes().getDestinationType()); + assertNull(update.getAttributes().getAugmentation(Attributes2.class)); + } - final UnkeyedListNode routes = ImmutableUnkeyedListNodeBuilder.create().withNodeIdentifier(DESTINATION_NID).addChild(evpnBI.build()).build(); - final ContainerNode destination = ImmutableContainerNodeBuilder.create().addChild(routes).withNodeIdentifier(DESTINATION_NID).build(); - final ContainerNode attributes = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(Attributes.QNAME)).build(); + @Test + public void testIsComplexRoute() { + Assert.assertTrue(RIB_SUPPORT.isComplexRoute()); + } - final YangInstanceIdentifier yangIdentifier = YangInstanceIdentifier.of(Routes.QNAME); - evpnRibSupport.putDestinationRoutes(tx, yangIdentifier, destination, attributes, ROUTES_NODE_ID); - Assert.assertEquals(1, this.routes.size()); + @Test + public void testCacheableNlriObjects() { + Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + } - evpnRibSupport.deleteDestinationRoutes(tx, yangIdentifier, destination, ROUTES_NODE_ID); - Assert.assertEquals(0, this.routes.size()); + @Test + public void testCacheableAttributeObjects() { + Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); } @Test - public void testDestRoutesMacIp() { - ESIActivator.registerEsiTypeParsers(new ArrayList<>()); - NlriActivator.registerNlriParsers(new ArrayList<>()); + public void testRouteIdAddPath() { + Assert.assertNull(RIB_SUPPORT.getRouteIdAddPath(AbstractRIBSupportTest.PATH_ID, null)); + } - final DataContainerNodeAttrBuilder evpnBI = ImmutableUnkeyedListEntryNodeBuilder.create(); - evpnBI.withNodeIdentifier(EVPN_NID); - evpnBI.withChild(createMACIpAdvChoice()); - evpnBI.withChild(createValueBuilder(RD_MODEL, RD_NID).build()); + @Test + public void testRoutePath() { + final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(EVPN_ROUTES); + Assert.assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + } + + @Test + public void testExtractPathId() { + Assert.assertEquals((Long) NON_PATH_ID, RIB_SUPPORT.extractPathId(null)); + } + + @Test + public void testRouteAttributesIdentifier() { + Assert.assertEquals(new NodeIdentifier(QName.create(EvpnRoutes.QNAME, Attributes.QNAME.getLocalName().intern())), RIB_SUPPORT + .routeAttributesIdentifier()); + } + + @Test + public void testRoutesCaseClass() { + Assert.assertEquals(EvpnRoutesCase.class, RIB_SUPPORT.routesCaseClass()); + } - final UnkeyedListNode routes = ImmutableUnkeyedListNodeBuilder.create().withNodeIdentifier(DESTINATION_NID).addChild(evpnBI.build()).build(); - final ContainerNode destination = ImmutableContainerNodeBuilder.create().addChild(routes).withNodeIdentifier(DESTINATION_NID).build(); - final ContainerNode attributes = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(Attributes.QNAME)).build(); + @Test + public void testRoutesContainerClass() { + Assert.assertEquals(EvpnRoutes.class, RIB_SUPPORT.routesContainerClass()); + } - final YangInstanceIdentifier yangIdentifier = YangInstanceIdentifier.of(Routes.QNAME); - evpnRibSupport.putDestinationRoutes(tx, yangIdentifier, destination, attributes, ROUTES_NODE_ID); - Assert.assertEquals(1, this.routes.size()); + @Test + public void testRoutesListClass() { + Assert.assertEquals(EvpnRoute.class, RIB_SUPPORT.routesListClass()); + } - evpnRibSupport.deleteDestinationRoutes(tx, yangIdentifier, destination, ROUTES_NODE_ID); - Assert.assertEquals(0, this.routes.size()); - }*/ + @Test + public void testChangedRoutes() { + final Routes emptyCase = new EvpnRoutesCaseBuilder().build(); + DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode(); + Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + + final Routes emptyRoutes = new EvpnRoutesCaseBuilder().setEvpnRoutes(new EvpnRoutesBuilder().build()).build(); + tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); + Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + + final Routes routes = new EvpnRoutesCaseBuilder().setEvpnRoutes(EVPN_ROUTES).build(); + tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode(); + final Collection result = RIB_SUPPORT.changedRoutes(tree); + Assert.assertFalse(result.isEmpty()); + } } \ No newline at end of file diff --git a/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthADRParserTest.java b/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthADRParserTest.java index cdce14ed5f..f090bb0bc3 100644 --- a/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthADRParserTest.java +++ b/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/nlri/EthADRParserTest.java @@ -51,7 +51,8 @@ public class EthADRParserTest { (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x01, (byte) 0x02 }; static final EthernetTagId ETI = new EthernetTagIdBuilder().setVlanId(VLAN).build(); - private static final EthernetADRouteCase ETHERNET_AD_ROUTE_CASE_KEY = new EthernetADRouteCaseBuilder().setEthernetADRoute(new EthernetADRouteBuilder().setEsi(LAN_AUT_GEN_CASE).setEthernetTagId(ETI).build()).build(); + public static final EthernetADRouteCase ETHERNET_AD_ROUTE_CASE_KEY = new EthernetADRouteCaseBuilder() + .setEthernetADRoute(new EthernetADRouteBuilder().setEsi(LAN_AUT_GEN_CASE).setEthernetTagId(ETI).build()).build(); public static final EthernetADRouteCase ETHERNET_AD_ROUTE_CASE = new EthernetADRouteCaseBuilder().setEthernetADRoute(new EthernetADRouteBuilder() .setEsi(LAN_AUT_GEN_CASE).setEthernetTagId(ETI).setMplsLabel(MPLS_LABEL).build()).build(); static final byte[] WRONG_VALUE = {(byte) 0x00}; diff --git a/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv4RIBSupportTest.java b/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv4RIBSupportTest.java new file mode 100644 index 0000000000..8ed751211d --- /dev/null +++ b/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv4RIBSupportTest.java @@ -0,0 +1,203 @@ +/* + * 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.flowspec; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.bgp.rib.rib.loc.rib.tables.routes.FlowspecRoutesCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.bgp.rib.rib.loc.rib.tables.routes.FlowspecRoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.Flowspec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.FlowspecBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv4.flowspec.flowspec.type.DestinationPrefixCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv4.flowspec.flowspec.type.DestinationPrefixCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.DestinationFlowspec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv4.DestinationFlowspecBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.ipv4.route.FlowspecRoute; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.ipv4.route.FlowspecRouteBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.ipv4.route.FlowspecRouteKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.routes.FlowspecRoutes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.routes.FlowspecRoutesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.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.ChoiceNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates; + +public class FlowspecIpv4RIBSupportTest extends AbstractRIBSupportTest { + + private static final FlowspecIpv4RIBSupport RIB_SUPPORT; + private static final FlowspecRoute ROUTE; + private static final FlowspecRoutes ROUTES; + private static final FlowspecRouteKey ROUTE_KEY; + private static final PathId PATH_ID = new PathId(1L); + + private static final DestinationPrefixCase DEST_PREFIX = new DestinationPrefixCaseBuilder().setDestinationPrefix(new Ipv4Prefix("10.0.1.0/32")).build(); + private static final List FLOW_LIST = Collections.singletonList(new FlowspecBuilder().setFlowspecType(DEST_PREFIX).build()); + private final static DestinationFlowspec DEST_FLOW = new DestinationFlowspecBuilder().setFlowspec(FLOW_LIST).setPathId(PATH_ID).build(); + private static final DestinationFlowspecCase REACH_NLRI = new DestinationFlowspecCaseBuilder().setDestinationFlowspec(DEST_FLOW).build(); + private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update + .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCase UNREACH_NLRI = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update + .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCaseBuilder().setDestinationFlowspec(DEST_FLOW).build(); + + static { + final SimpleFlowspecExtensionProviderContext fs_context = new SimpleFlowspecExtensionProviderContext(); + final FlowspecActivator activator = new FlowspecActivator(fs_context); + final BGPActivator act = new BGPActivator(fs_context, activator); + final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext(); + act.start(context); + RIB_SUPPORT = FlowspecIpv4RIBSupport.getInstance(fs_context); + + final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser( + fs_context.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC)); + + ROUTE_KEY = new FlowspecRouteKey(PATH_ID, parser.stringNlri(FLOW_LIST)); + ROUTE = new FlowspecRouteBuilder().setKey(ROUTE_KEY).setPathId(PATH_ID).setFlowspec(FLOW_LIST) + .setAttributes(new AttributesBuilder().build()).build(); + ROUTES = new FlowspecRoutesBuilder().setFlowspecRoute(Collections.singletonList(ROUTE)).build(); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + setUpTestCustomizer(RIB_SUPPORT); + } + + @Test + public void testDeleteRoutes() { + RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = (InstanceIdentifier) this.deletedRoutes.get(0); + assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(FlowspecRoute.class)); + } + + @Test + public void testPutRoutes() { + RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + final FlowspecRoute route = (FlowspecRoute) this.insertedRoutes.get(0).getValue(); + assertEquals(ROUTE, route); + } + + @Test + public void testEmptyRoute() throws Exception { + final Routes empty = new FlowspecRoutesCaseBuilder().setFlowspecRoutes( + new FlowspecRoutesBuilder().setFlowspecRoute(Collections.emptyList()).build()).build(); + final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + assertEquals(createRoutes(empty), emptyRoutes); + } + + @Test + public void testBuildMpUnreachNlriUpdate() { + final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); + assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class) + .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); + assertNull(update.getAttributes().getAugmentation(Attributes1.class)); + } + + @Test + public void testBuildMpReachNlriUpdate() { + final Update update = RIB_SUPPORT.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES); + assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri().getAdvertizedRoutes().getDestinationType()); + assertNull(update.getAttributes().getAugmentation(Attributes2.class)); + } + + @Test + public void testIsComplexRoute() { + Assert.assertTrue(RIB_SUPPORT.isComplexRoute()); + } + + @Test + public void testCacheableNlriObjects() { + Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + } + + @Test + public void testCacheableAttributeObjects() { + Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + } + + @Test + public void testRouteIdAddPath() { + final NodeIdentifierWithPredicates expected = createRouteNIWP(ROUTES); + final NodeIdentifierWithPredicates prefixNii = new NodeIdentifierWithPredicates(RIB_SUPPORT.routeQName(), + ImmutableMap.of(RIB_SUPPORT.routeKeyQName(), ROUTE_KEY.getRouteKey())); + Assert.assertEquals(expected, RIB_SUPPORT.getRouteIdAddPath(AbstractRIBSupportTest.PATH_ID, prefixNii)); + } + + @Test + public void testRoutePath() { + final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES); + Assert.assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + } + + @Test + public void testExtractPathId() { + Assert.assertEquals((Long) NON_PATH_ID, RIB_SUPPORT.extractPathId(null)); + } + + @Test + public void testRouteAttributesIdentifier() { + Assert.assertEquals(new NodeIdentifier(QName.create(FlowspecRoutes.QNAME, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Attributes.QNAME.getLocalName().intern())), + RIB_SUPPORT.routeAttributesIdentifier()); + } + + @Test + public void testRoutesCaseClass() { + Assert.assertEquals(FlowspecRoutesCase.class, RIB_SUPPORT.routesCaseClass()); + } + + @Test + public void testRoutesContainerClass() { + Assert.assertEquals(FlowspecRoutes.class, RIB_SUPPORT.routesContainerClass()); + } + + @Test + public void testRoutesListClass() { + Assert.assertEquals(FlowspecRoute.class, RIB_SUPPORT.routesListClass()); + } + + @Test + public void testChangedRoutes() { + final Routes emptyCase = new FlowspecRoutesCaseBuilder().build(); + DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode(); + Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + + final Routes emptyRoutes = new FlowspecRoutesCaseBuilder().setFlowspecRoutes(new FlowspecRoutesBuilder().build()).build(); + tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); + Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + + final Routes routes = new FlowspecRoutesCaseBuilder().setFlowspecRoutes(new FlowspecRoutesBuilder() + .setFlowspecRoute(Collections.singletonList(ROUTE)).build()).build(); + tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode(); + final Collection result = RIB_SUPPORT.changedRoutes(tree); + Assert.assertFalse(result.isEmpty()); + } +} \ No newline at end of file diff --git a/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv6RIBSupportTest.java b/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv6RIBSupportTest.java new file mode 100644 index 0000000000..b2361c4d1c --- /dev/null +++ b/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv6RIBSupportTest.java @@ -0,0 +1,203 @@ +/* + * 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.flowspec; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.bgp.rib.rib.loc.rib.tables.routes.FlowspecIpv6RoutesCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.bgp.rib.rib.loc.rib.tables.routes.FlowspecIpv6RoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.Flowspec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.FlowspecBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.group.ipv6.flowspec.flowspec.type.DestinationIpv6PrefixCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.DestinationFlowspec; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.destination.ipv6.DestinationFlowspecBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.ipv6.route.FlowspecRoute; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.ipv6.route.FlowspecRouteBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.ipv6.route.FlowspecRouteKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.ipv6.routes.FlowspecIpv6Routes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.flowspec.ipv6.routes.FlowspecIpv6RoutesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecIpv6Case; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationFlowspecIpv6CaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.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.ChoiceNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates; + +public class FlowspecIpv6RIBSupportTest extends AbstractRIBSupportTest { + + private static final FlowspecIpv6RIBSupport RIB_SUPPORT; + private static final FlowspecRoute ROUTE; + private static final FlowspecRouteKey ROUTE_KEY; + private static final PathId PATH_ID = new PathId(1L); + + private static final DestinationIpv6PrefixCase DEST_PREFIX = new DestinationIpv6PrefixCaseBuilder().setDestinationPrefix(new Ipv6Prefix("2001:db8:1:2::/64")).build(); + private static final List FLOW_LIST = Collections.singletonList(new FlowspecBuilder().setFlowspecType(DEST_PREFIX).build()); + private final static DestinationFlowspec DEST_FLOW = new DestinationFlowspecBuilder().setFlowspec(FLOW_LIST).setPathId(PATH_ID).build(); + private static final DestinationFlowspecIpv6Case REACH_NLRI = new DestinationFlowspecIpv6CaseBuilder().setDestinationFlowspec(DEST_FLOW).build(); + private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update + .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecIpv6Case UNREACH_NLRI = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.update + .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecIpv6CaseBuilder().setDestinationFlowspec(DEST_FLOW).build(); + private static final FlowspecIpv6Routes ROUTES; + static { + final SimpleFlowspecExtensionProviderContext fs_context = new SimpleFlowspecExtensionProviderContext(); + final FlowspecActivator activator = new FlowspecActivator(fs_context); + final BGPActivator act = new BGPActivator(fs_context, activator); + final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext(); + act.start(context); + RIB_SUPPORT = FlowspecIpv6RIBSupport.getInstance(fs_context); + + final SimpleFlowspecIpv6NlriParser parser = new SimpleFlowspecIpv6NlriParser( + fs_context.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC)); + + ROUTE_KEY = new FlowspecRouteKey(PATH_ID, parser.stringNlri(FLOW_LIST)); + ROUTE = new FlowspecRouteBuilder().setKey(ROUTE_KEY).setPathId(PATH_ID).setFlowspec(FLOW_LIST) + .setAttributes(new AttributesBuilder().build()).build(); + ROUTES = new FlowspecIpv6RoutesBuilder().setFlowspecRoute(Collections.singletonList(ROUTE)).build(); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + setUpTestCustomizer(RIB_SUPPORT); + } + + @Test + public void testDeleteRoutes() { + RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = (InstanceIdentifier) this.deletedRoutes.get(0); + assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(FlowspecRoute.class)); + } + + @Test + public void testPutRoutes() { + RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + final FlowspecRoute route = (FlowspecRoute) this.insertedRoutes.get(0).getValue(); + assertEquals(ROUTE, route); + } + + @Test + public void testEmptyRoute() throws Exception { + final Routes empty = new FlowspecIpv6RoutesCaseBuilder().setFlowspecIpv6Routes( + new FlowspecIpv6RoutesBuilder().setFlowspecRoute(Collections.emptyList()).build()).build(); + final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + assertEquals(createRoutes(empty), emptyRoutes); + } + + @Test + public void testBuildMpUnreachNlriUpdate() { + final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); + assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class) + .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); + assertNull(update.getAttributes().getAugmentation(Attributes1.class)); + } + + @Test + public void testBuildMpReachNlriUpdate() { + final Update update = RIB_SUPPORT.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES); + assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri().getAdvertizedRoutes().getDestinationType()); + assertNull(update.getAttributes().getAugmentation(Attributes2.class)); + } + + @Test + public void testIsComplexRoute() { + Assert.assertTrue(RIB_SUPPORT.isComplexRoute()); + } + + @Test + public void testCacheableNlriObjects() { + Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + } + + @Test + public void testCacheableAttributeObjects() { + Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + } + + @Test + public void testRouteIdAddPath() { + final NodeIdentifierWithPredicates expected = createRouteNIWP(new FlowspecIpv6RoutesBuilder(). + setFlowspecRoute(Collections.singletonList(ROUTE)).build()); + final NodeIdentifierWithPredicates prefixNii = new NodeIdentifierWithPredicates(RIB_SUPPORT.routeQName(), + ImmutableMap.of(RIB_SUPPORT.routeKeyQName(), ROUTE_KEY.getRouteKey())); + Assert.assertEquals(expected, RIB_SUPPORT.getRouteIdAddPath(AbstractRIBSupportTest.PATH_ID, prefixNii)); + } + + @Test + public void testRoutePath() { + final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES); + Assert.assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + } + + @Test + public void testExtractPathId() { + Assert.assertEquals((Long) NON_PATH_ID, RIB_SUPPORT.extractPathId(null)); + } + + @Test + public void testRouteAttributesIdentifier() { + Assert.assertEquals(new NodeIdentifier(QName.create(FlowspecIpv6Routes.QNAME, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Attributes.QNAME.getLocalName().intern())), + RIB_SUPPORT.routeAttributesIdentifier()); + } + + @Test + public void testRoutesCaseClass() { + Assert.assertEquals(FlowspecIpv6RoutesCase.class, RIB_SUPPORT.routesCaseClass()); + } + + @Test + public void testRoutesContainerClass() { + Assert.assertEquals(FlowspecIpv6Routes.class, RIB_SUPPORT.routesContainerClass()); + } + + @Test + public void testRoutesListClass() { + Assert.assertEquals(FlowspecRoute.class, RIB_SUPPORT.routesListClass()); + } + + @Test + public void testChangedRoutes() { + final Routes emptyCase = new FlowspecIpv6RoutesCaseBuilder().build(); + DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode(); + Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + + final Routes emptyRoutes = new FlowspecIpv6RoutesCaseBuilder().setFlowspecIpv6Routes(new FlowspecIpv6RoutesBuilder().build()).build(); + tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); + Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + + final Routes routes = new FlowspecIpv6RoutesCaseBuilder().setFlowspecIpv6Routes(new FlowspecIpv6RoutesBuilder() + .setFlowspecRoute(Collections.singletonList(ROUTE)).build()).build(); + tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode(); + final Collection result = RIB_SUPPORT.changedRoutes(tree); + Assert.assertFalse(result.isEmpty()); + } +} \ No newline at end of file diff --git a/bgp/l3vpn/pom.xml b/bgp/l3vpn/pom.xml index 1cdaff5bd1..134b30879c 100644 --- a/bgp/l3vpn/pom.xml +++ b/bgp/l3vpn/pom.xml @@ -80,6 +80,22 @@ junit junit + + ${project.groupId} + bgp-rib-spi + test-jar + test + + + org.opendaylight.yangtools + mockito-configuration + test + + + org.opendaylight.controller + sal-binding-broker-impl + test + diff --git a/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/AbstractVpnNlriParser.java b/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/AbstractVpnNlriParser.java index 6dfe0fa8f7..4c5b156198 100644 --- a/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/AbstractVpnNlriParser.java +++ b/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/AbstractVpnNlriParser.java @@ -48,7 +48,7 @@ public abstract class AbstractVpnNlriParser implements NlriParser, NlriSerialize protected abstract AdvertizedRoutes getAdvertizedRoutesByDestination(List dst); - static void serializeNlri(final List dests, final ByteBuf buffer) { + public static void serializeNlri(final List dests, final ByteBuf buffer) { final ByteBuf nlriByteBuf = Unpooled.buffer(); for (final VpnDestination dest : dests) { final List labelStack = dest.getLabelStack(); diff --git a/bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/VpnIpv4NlriParserTest.java b/bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/VpnIpv4NlriParserTest.java index 9623d68dcb..91e1f7f5ed 100644 --- a/bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/VpnIpv4NlriParserTest.java +++ b/bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/VpnIpv4NlriParserTest.java @@ -48,11 +48,11 @@ public class VpnIpv4NlriParserTest { 0, 1, 1, 2, 3, 4, 1, 2, (byte) 0x22, (byte) 0x01, (byte) 0x16, }; - private static final IpPrefix IPv4_PREFIX = new IpPrefix(new Ipv4Prefix("34.1.22.0/24")); - private static final List LABEL_STACK = Lists.newArrayList( + static final IpPrefix IPv4_PREFIX = new IpPrefix(new Ipv4Prefix("34.1.22.0/24")); + static final List LABEL_STACK = Lists.newArrayList( new LabelStackBuilder().setLabelValue(new MplsLabel(355L)).build()); - private static final RouteDistinguisher DISTINGUISHER = RouteDistinguisherBuilder.getDefaultInstance("1.2.3.4:258"); - private static final VpnDestination VPN = new VpnDestinationBuilder().setRouteDistinguisher(DISTINGUISHER).setPrefix(IPv4_PREFIX).setLabelStack(LABEL_STACK).build(); + static final RouteDistinguisher DISTINGUISHER = RouteDistinguisherBuilder.getDefaultInstance("1.2.3.4:258"); + static final VpnDestination IPV4_VPN = new VpnDestinationBuilder().setRouteDistinguisher(DISTINGUISHER).setPrefix(IPv4_PREFIX).setLabelStack(LABEL_STACK).build(); @Test public void testMpReachNlri() throws BGPParsingException { @@ -61,7 +61,7 @@ public class VpnIpv4NlriParserTest { mpBuilder.setAdvertizedRoutes( new AdvertizedRoutesBuilder().setDestinationType( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev160210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationVpnIpv4CaseBuilder().setVpnIpv4Destination( - new VpnIpv4DestinationBuilder().setVpnDestination(Lists.newArrayList(VPN)).build() + new VpnIpv4DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV4_VPN)).build() ).build() ).build() ).build(); @@ -89,7 +89,7 @@ public class VpnIpv4NlriParserTest { mpBuilder.setWithdrawnRoutes( new WithdrawnRoutesBuilder().setDestinationType( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev160210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv4CaseBuilder().setVpnIpv4Destination( - new VpnIpv4DestinationBuilder().setVpnDestination(Lists.newArrayList(VPN)).build() + new VpnIpv4DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV4_VPN)).build() ).build() ).build() ).build(); diff --git a/bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/VpnIpv4RIBSupportTest.java b/bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/VpnIpv4RIBSupportTest.java new file mode 100644 index 0000000000..e6f4550c71 --- /dev/null +++ b/bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/VpnIpv4RIBSupportTest.java @@ -0,0 +1,193 @@ +/* + * 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.ipv4; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.opendaylight.protocol.bgp.l3vpn.ipv4.VpnIpv4NlriParserTest.DISTINGUISHER; +import static org.opendaylight.protocol.bgp.l3vpn.ipv4.VpnIpv4NlriParserTest.IPV4_VPN; +import static org.opendaylight.protocol.bgp.l3vpn.ipv4.VpnIpv4NlriParserTest.IPv4_PREFIX; +import static org.opendaylight.protocol.bgp.l3vpn.ipv4.VpnIpv4NlriParserTest.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 io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.util.Collection; +import java.util.Collections; +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.protocol.bgp.l3vpn.AbstractVpnNlriParser; +import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev160210.bgp.rib.rib.loc.rib.tables.routes.VpnIpv4RoutesCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev160210.bgp.rib.rib.loc.rib.tables.routes.VpnIpv4RoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev160210.l3vpn.ipv4.destination.VpnIpv4DestinationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev160210.l3vpn.ipv4.routes.VpnIpv4Routes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev160210.l3vpn.ipv4.routes.VpnIpv4RoutesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev160210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationVpnIpv4Case; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev160210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationVpnIpv4CaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev160413.l3vpn.ip.route.VpnRoute; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev160413.l3vpn.ip.route.VpnRouteBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev160413.l3vpn.ip.route.VpnRouteKey; +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.ChoiceNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates; + +public class VpnIpv4RIBSupportTest extends AbstractRIBSupportTest { + private static final VpnIpv4RIBSupport RIB_SUPPORT = new VpnIpv4RIBSupport(); + + private static final DestinationVpnIpv4Case REACH_NLRI = new DestinationVpnIpv4CaseBuilder().setVpnIpv4Destination( + new VpnIpv4DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV4_VPN)).build()).build(); + + private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev160210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type. + DestinationVpnIpv4Case UNREACH_NLRI = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev160210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type. + DestinationVpnIpv4CaseBuilder().setVpnIpv4Destination(new VpnIpv4DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV4_VPN)).build()).build(); + + private static final VpnRoute ROUTE; + private static final VpnIpv4Routes ROUTES; + private static final VpnRouteKey ROUTE_KEY; + + static { + final BgpIpv4Activator act = new BgpIpv4Activator(); + final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext(); + act.start(context); + final ByteBuf buffer = Unpooled.buffer(); + AbstractVpnNlriParser.serializeNlri(Collections.singletonList(IPV4_VPN), buffer); + final byte[] arrayKey = ByteArray.readAllBytes(buffer); + ROUTE_KEY = new VpnRouteKey(arrayKey); + ROUTE = new VpnRouteBuilder().setPathId(new PathId(NON_PATH_ID)).setAttributes(ATTRIBUTES).setPrefix(IPv4_PREFIX) + .setLabelStack(LABEL_STACK).setRouteDistinguisher(DISTINGUISHER).setKey(ROUTE_KEY).build(); + ROUTES = new VpnIpv4RoutesBuilder().setVpnRoute(Collections.singletonList(ROUTE)).build(); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + setUpTestCustomizer(RIB_SUPPORT); + } + + @Test + public void testDeleteRoutes() { + RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = (InstanceIdentifier) this.deletedRoutes.get(0); + assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(VpnRoute.class)); + } + + @Test + public void testPutRoutes() { + RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + final VpnRoute route = (VpnRoute) this.insertedRoutes.get(0).getValue(); + assertEquals(ROUTE, route); + } + + + @Test + public void testEmptyRoute() throws Exception { + final Routes empty = new VpnIpv4RoutesCaseBuilder().setVpnIpv4Routes(new VpnIpv4RoutesBuilder().setVpnRoute(Collections.emptyList()).build()).build(); + final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + assertEquals(createRoutes(empty), emptyRoutes); + } + + @Test + public void testBuildMpUnreachNlriUpdate() { + final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); + assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class) + .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); + assertNull(update.getAttributes().getAugmentation(Attributes1.class)); + } + + @Test + public void testBuildMpReachNlriUpdate() { + final Update update = RIB_SUPPORT.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES); + assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri().getAdvertizedRoutes().getDestinationType()); + assertNull(update.getAttributes().getAugmentation(Attributes2.class)); + } + + @Test + public void testIsComplexRoute() { + Assert.assertTrue(RIB_SUPPORT.isComplexRoute()); + } + + @Test + public void testCacheableNlriObjects() { + Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + } + + @Test + public void testCacheableAttributeObjects() { + Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + } + + @Test + public void testRouteIdAddPath() { + Assert.assertNull(RIB_SUPPORT.getRouteIdAddPath(AbstractRIBSupportTest.PATH_ID, null)); + } + + @Test + public void testRoutePath() { + final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES); + Assert.assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + } + + @Test + public void testExtractPathId() { + Assert.assertEquals((Long) NON_PATH_ID, RIB_SUPPORT.extractPathId(null)); + } + + @Test + public void testRouteAttributesIdentifier() { + Assert.assertEquals(new NodeIdentifier(QName.create(VpnIpv4Routes.QNAME, Attributes.QNAME.getLocalName().intern())), RIB_SUPPORT + .routeAttributesIdentifier()); + } + + @Test + public void testRoutesCaseClass() { + Assert.assertEquals(VpnIpv4RoutesCase.class, RIB_SUPPORT.routesCaseClass()); + } + + @Test + public void testRoutesContainerClass() { + Assert.assertEquals(VpnIpv4Routes.class, RIB_SUPPORT.routesContainerClass()); + } + + @Test + public void testRoutesListClass() { + Assert.assertEquals(VpnRoute.class, RIB_SUPPORT.routesListClass()); + } + + @Test + public void testChangedRoutes() { + final Routes emptyCase = new VpnIpv4RoutesCaseBuilder().build(); + DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode(); + Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + + final Routes emptyRoutes = new VpnIpv4RoutesCaseBuilder().setVpnIpv4Routes(new VpnIpv4RoutesBuilder().build()).build(); + tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); + Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + + final Routes routes = new VpnIpv4RoutesCaseBuilder().setVpnIpv4Routes(ROUTES).build(); + tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode(); + final Collection result = RIB_SUPPORT.changedRoutes(tree); + Assert.assertFalse(result.isEmpty()); + } +} \ No newline at end of file diff --git a/bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/VpnIpv6NlriParserTest.java b/bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/VpnIpv6NlriParserTest.java index 90e1c1e563..c8ed8dd39a 100644 --- a/bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/VpnIpv6NlriParserTest.java +++ b/bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/VpnIpv6NlriParserTest.java @@ -51,11 +51,11 @@ public class VpnIpv6NlriParserTest { 0, 1, 1, 2, 3, 4, 1, 2, // route distinguisher (byte) 0x20, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x56, (byte) 0x89 // specify the IPv6 prefix here }; - private static final IpPrefix IPv6_PREFIX = new IpPrefix(new Ipv6Prefix("2001:2345:5689::/48")); - private static final List LABEL_STACK = Lists.newArrayList( + static final IpPrefix IPv6_PREFIX = new IpPrefix(new Ipv6Prefix("2001:2345:5689::/48")); + static final List LABEL_STACK = Lists.newArrayList( new LabelStackBuilder().setLabelValue(new MplsLabel(355L)).build()); - private static final RouteDistinguisher DISTINGUISHER = RouteDistinguisherBuilder.getDefaultInstance("1.2.3.4:258"); - private static final VpnDestination VPN = new VpnDestinationBuilder().setRouteDistinguisher(DISTINGUISHER).setPrefix(IPv6_PREFIX).setLabelStack(LABEL_STACK).build(); + static final RouteDistinguisher DISTINGUISHER = RouteDistinguisherBuilder.getDefaultInstance("1.2.3.4:258"); + static final VpnDestination IPV6_VPN = new VpnDestinationBuilder().setRouteDistinguisher(DISTINGUISHER).setPrefix(IPv6_PREFIX).setLabelStack(LABEL_STACK).build(); @Test public void testMpReachNlri() throws BGPParsingException { @@ -63,7 +63,7 @@ public class VpnIpv6NlriParserTest { mpBuilder.setAfi(Ipv6AddressFamily.class); mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev160331.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationVpnIpv6CaseBuilder().setVpnIpv6Destination( - new VpnIpv6DestinationBuilder().setVpnDestination(Lists.newArrayList(VPN)).build() + new VpnIpv6DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV6_VPN)).build() ).build() ).build() ).build(); @@ -91,7 +91,7 @@ public class VpnIpv6NlriParserTest { mpBuilder.setWithdrawnRoutes( new WithdrawnRoutesBuilder().setDestinationType( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev160331.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv6CaseBuilder().setVpnIpv6Destination( - new VpnIpv6DestinationBuilder().setVpnDestination(Lists.newArrayList(VPN)).build() + new VpnIpv6DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV6_VPN)).build() ).build() ).build() ).build(); diff --git a/bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/VpnIpv6RIBSupportTest.java b/bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/VpnIpv6RIBSupportTest.java new file mode 100644 index 0000000000..b35701f6d5 --- /dev/null +++ b/bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/VpnIpv6RIBSupportTest.java @@ -0,0 +1,193 @@ +/* + * 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.ipv6; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.opendaylight.protocol.bgp.l3vpn.ipv6.VpnIpv6NlriParserTest.DISTINGUISHER; +import static org.opendaylight.protocol.bgp.l3vpn.ipv6.VpnIpv6NlriParserTest.IPV6_VPN; +import static org.opendaylight.protocol.bgp.l3vpn.ipv6.VpnIpv6NlriParserTest.IPv6_PREFIX; +import static org.opendaylight.protocol.bgp.l3vpn.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 io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.util.Collection; +import java.util.Collections; +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.protocol.bgp.l3vpn.AbstractVpnNlriParser; +import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev160331.bgp.rib.rib.loc.rib.tables.routes.VpnIpv6RoutesCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev160331.bgp.rib.rib.loc.rib.tables.routes.VpnIpv6RoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev160331.l3vpn.ipv6.destination.VpnIpv6DestinationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev160331.l3vpn.ipv6.routes.VpnIpv6Routes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev160331.l3vpn.ipv6.routes.VpnIpv6RoutesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev160331.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.rev160331.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationVpnIpv6CaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev160413.l3vpn.ip.route.VpnRoute; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev160413.l3vpn.ip.route.VpnRouteBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev160413.l3vpn.ip.route.VpnRouteKey; +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.ChoiceNode; +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 static final VpnIpv6RIBSupport RIB_SUPPORT = new VpnIpv6RIBSupport(); + + 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.rev160331.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.rev160331.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type. + DestinationVpnIpv6CaseBuilder().setVpnIpv6Destination(new VpnIpv6DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV6_VPN)).build()).build(); + + private static final VpnRoute ROUTE; + private static final VpnIpv6Routes ROUTES; + private static final VpnRouteKey ROUTE_KEY; + + static { + final BgpIpv6Activator act = new BgpIpv6Activator(); + final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext(); + act.start(context); + final ByteBuf buffer = Unpooled.buffer(); + AbstractVpnNlriParser.serializeNlri(Collections.singletonList(IPV6_VPN), buffer); + final byte[] arrayKey = ByteArray.readAllBytes(buffer); + ROUTE_KEY = new VpnRouteKey(arrayKey); + ROUTE = new VpnRouteBuilder().setPathId(new PathId(NON_PATH_ID)).setAttributes(ATTRIBUTES).setPrefix(IPv6_PREFIX) + .setLabelStack(LABEL_STACK).setRouteDistinguisher(DISTINGUISHER).setKey(ROUTE_KEY).build(); + ROUTES = new VpnIpv6RoutesBuilder().setVpnRoute(Collections.singletonList(ROUTE)).build(); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + setUpTestCustomizer(RIB_SUPPORT); + } + + @Test + public void testDeleteRoutes() { + RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = (InstanceIdentifier) this.deletedRoutes.get(0); + assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(VpnRoute.class)); + } + + @Test + public void testPutRoutes() { + RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + final VpnRoute route = (VpnRoute) this.insertedRoutes.get(0).getValue(); + assertEquals(ROUTE, route); + } + + + @Test + public void testEmptyRoute() throws Exception { + final Routes empty = new VpnIpv6RoutesCaseBuilder().setVpnIpv6Routes(new VpnIpv6RoutesBuilder().setVpnRoute(Collections.emptyList()).build()).build(); + final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + assertEquals(createRoutes(empty), emptyRoutes); + } + + @Test + public void testBuildMpUnreachNlriUpdate() { + final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); + assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class) + .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); + assertNull(update.getAttributes().getAugmentation(Attributes1.class)); + } + + @Test + public void testBuildMpReachNlriUpdate() { + final Update update = RIB_SUPPORT.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES); + assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri().getAdvertizedRoutes().getDestinationType()); + assertNull(update.getAttributes().getAugmentation(Attributes2.class)); + } + + @Test + public void testIsComplexRoute() { + Assert.assertTrue(RIB_SUPPORT.isComplexRoute()); + } + + @Test + public void testCacheableNlriObjects() { + Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + } + + @Test + public void testCacheableAttributeObjects() { + Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + } + + @Test + public void testRouteIdAddPath() { + Assert.assertNull(RIB_SUPPORT.getRouteIdAddPath(AbstractRIBSupportTest.PATH_ID, null)); + } + + @Test + public void testRoutePath() { + final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES); + Assert.assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + } + + @Test + public void testExtractPathId() { + Assert.assertEquals((Long) NON_PATH_ID, RIB_SUPPORT.extractPathId(null)); + } + + @Test + public void testRouteAttributesIdentifier() { + Assert.assertEquals(new NodeIdentifier(QName.create(VpnIpv6Routes.QNAME, Attributes.QNAME.getLocalName().intern())), RIB_SUPPORT + .routeAttributesIdentifier()); + } + + @Test + public void testRoutesCaseClass() { + Assert.assertEquals(VpnIpv6RoutesCase.class, RIB_SUPPORT.routesCaseClass()); + } + + @Test + public void testRoutesContainerClass() { + Assert.assertEquals(VpnIpv6Routes.class, RIB_SUPPORT.routesContainerClass()); + } + + @Test + public void testRoutesListClass() { + Assert.assertEquals(VpnRoute.class, RIB_SUPPORT.routesListClass()); + } + + @Test + public void testChangedRoutes() { + final Routes emptyCase = new VpnIpv6RoutesCaseBuilder().build(); + DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode(); + Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + + final Routes emptyRoutes = new VpnIpv6RoutesCaseBuilder().setVpnIpv6Routes(new VpnIpv6RoutesBuilder().build()).build(); + tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); + Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + + final Routes routes = new VpnIpv6RoutesCaseBuilder().setVpnIpv6Routes(ROUTES).build(); + tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode(); + final Collection result = RIB_SUPPORT.changedRoutes(tree); + Assert.assertFalse(result.isEmpty()); + } +} \ No newline at end of file diff --git a/bgp/labeled-unicast/src/test/java/org/opendaylight/protocol/bgp/labeled/unicast/LabeledUnicastIpv4RIBSupportTest.java b/bgp/labeled-unicast/src/test/java/org/opendaylight/protocol/bgp/labeled/unicast/LabeledUnicastIpv4RIBSupportTest.java new file mode 100644 index 0000000000..9f74825be8 --- /dev/null +++ b/bgp/labeled-unicast/src/test/java/org/opendaylight/protocol/bgp/labeled/unicast/LabeledUnicastIpv4RIBSupportTest.java @@ -0,0 +1,206 @@ +/* + * 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.labeled.unicast; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastRoutesCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastRoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.LabelStack; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.LabelStackBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.destination.CLabeledUnicastDestination; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.destination.CLabeledUnicastDestinationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.routes.LabeledUnicastRoutes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.routes.LabeledUnicastRoutesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.routes.list.LabeledUnicastRoute; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.routes.list.LabeledUnicastRouteBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.routes.list.LabeledUnicastRouteKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLabeledUnicastCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLabeledUnicastCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel; +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.ChoiceNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates; + +public class LabeledUnicastIpv4RIBSupportTest extends AbstractRIBSupportTest { + + private static final IpPrefix IPv4_PREFIX = new IpPrefix(new Ipv4Prefix("34.1.22.0/24")); + private static final LabeledUnicastIpv4RIBSupport RIB_SUPPORT = LabeledUnicastIpv4RIBSupport.getInstance(); + private static final LabeledUnicastRoute ROUTE; + private static final LabeledUnicastRoutes ROUTES; + private static final LabeledUnicastRouteKey ROUTE_KEY; + private static final byte[] LABEL_KEY; + private static final PathId PATH_ID = new PathId(1L); + private static final List LABEL_STACK = Lists.newArrayList(new LabelStackBuilder().setLabelValue(new MplsLabel(355L)).build()); + private static final List LABELED_DESTINATION_LIST = Collections.singletonList(new CLabeledUnicastDestinationBuilder() + .setPathId(PATH_ID).setLabelStack(LABEL_STACK).setPrefix(IPv4_PREFIX).build()); + private static final DestinationLabeledUnicastCase REACH_NLRI = new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast( + new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(LABELED_DESTINATION_LIST).build()).build(); + private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type. + DestinationLabeledUnicastCase UNREACH_NLRI = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type. + DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination. + type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(LABELED_DESTINATION_LIST).build()).build(); + + static { + final BGPActivator act = new BGPActivator(); + final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext(); + act.start(context); + final ByteBuf buffer = Unpooled.buffer(); + LUNlriParser.serializeNlri(LABELED_DESTINATION_LIST, buffer); + LABEL_KEY = ByteArray.readAllBytes(buffer); + ROUTE_KEY = new LabeledUnicastRouteKey(PATH_ID, LABEL_KEY); + ROUTE = new LabeledUnicastRouteBuilder().setKey(ROUTE_KEY).setPrefix(IPv4_PREFIX).setPathId(PATH_ID).setLabelStack(LABEL_STACK) + .setAttributes(new AttributesBuilder().build()).build(); + ROUTES = new LabeledUnicastRoutesBuilder().setLabeledUnicastRoute(Collections.singletonList(ROUTE)).build(); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + setUpTestCustomizer(RIB_SUPPORT); + } + + @Test + public void testDeleteRoutes() { + RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = (InstanceIdentifier) this.deletedRoutes.get(0); + assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(LabeledUnicastRoute.class)); + } + + @Test + public void testPutRoutes() { + RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + final LabeledUnicastRoute route = (LabeledUnicastRoute) this.insertedRoutes.get(0).getValue(); + assertEquals(ROUTE, route); + } + + @Test + public void testEmptyRoute() throws Exception { + final Routes empty = new LabeledUnicastRoutesCaseBuilder().setLabeledUnicastRoutes( + new LabeledUnicastRoutesBuilder().setLabeledUnicastRoute(Collections.emptyList()).build()).build(); + final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + assertEquals(createRoutes(empty), emptyRoutes); + } + + @Test + public void testBuildMpUnreachNlriUpdate() { + final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); + assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class) + .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); + assertNull(update.getAttributes().getAugmentation(Attributes1.class)); + } + + @Test + public void testBuildMpReachNlriUpdate() { + final Update update = RIB_SUPPORT.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES); + assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri().getAdvertizedRoutes().getDestinationType()); + assertNull(update.getAttributes().getAugmentation(Attributes2.class)); + } + + @Test + public void testIsComplexRoute() { + Assert.assertTrue(RIB_SUPPORT.isComplexRoute()); + } + + @Test + public void testCacheableNlriObjects() { + Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + } + + @Test + public void testCacheableAttributeObjects() { + Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + } + + @Test + public void testRouteIdAddPath() { + final NodeIdentifierWithPredicates expected = createRouteNIWP(ROUTES); + final NodeIdentifierWithPredicates prefixNii = new NodeIdentifierWithPredicates(RIB_SUPPORT.routeQName(), + ImmutableMap.of(RIB_SUPPORT.routeKeyQName(), LABEL_KEY)); + Assert.assertEquals(expected, RIB_SUPPORT.getRouteIdAddPath(AbstractRIBSupportTest.PATH_ID, prefixNii)); + } + + @Test + public void testRoutePath() { + final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES); + Assert.assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + } + + @Test + public void testExtractPathId() { + Assert.assertEquals((Long) NON_PATH_ID, RIB_SUPPORT.extractPathId(null)); + } + + @Test + public void testRouteAttributesIdentifier() { + Assert.assertEquals(new NodeIdentifier(QName.create(LabeledUnicastRoutes.QNAME, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Attributes.QNAME.getLocalName().intern())), + RIB_SUPPORT.routeAttributesIdentifier()); + } + + @Test + public void testRoutesCaseClass() { + Assert.assertEquals(LabeledUnicastRoutesCase.class, RIB_SUPPORT.routesCaseClass()); + } + + @Test + public void testRoutesContainerClass() { + Assert.assertEquals(LabeledUnicastRoutes.class, RIB_SUPPORT.routesContainerClass()); + } + + @Test + public void testRoutesListClass() { + Assert.assertEquals(LabeledUnicastRoute.class, RIB_SUPPORT.routesListClass()); + } + + @Test + public void testChangedRoutes() { + final Routes emptyCase = new LabeledUnicastRoutesCaseBuilder().build(); + DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode(); + Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + + final Routes emptyRoutes = new LabeledUnicastRoutesCaseBuilder().setLabeledUnicastRoutes(new LabeledUnicastRoutesBuilder().build()).build(); + tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); + Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + + final Routes routes = new LabeledUnicastRoutesCaseBuilder().setLabeledUnicastRoutes(ROUTES).build(); + tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode(); + final Collection result = RIB_SUPPORT.changedRoutes(tree); + Assert.assertFalse(result.isEmpty()); + } +} \ No newline at end of file diff --git a/bgp/labeled-unicast/src/test/java/org/opendaylight/protocol/bgp/labeled/unicast/LabeledUnicastIpv6RIBSupportTest.java b/bgp/labeled-unicast/src/test/java/org/opendaylight/protocol/bgp/labeled/unicast/LabeledUnicastIpv6RIBSupportTest.java new file mode 100644 index 0000000000..134d20117d --- /dev/null +++ b/bgp/labeled-unicast/src/test/java/org/opendaylight/protocol/bgp/labeled/unicast/LabeledUnicastIpv6RIBSupportTest.java @@ -0,0 +1,207 @@ +/* + * 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.labeled.unicast; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastIpv6RoutesCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastIpv6RoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.LabelStack; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.LabelStackBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.destination.CLabeledUnicastDestination; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.destination.CLabeledUnicastDestinationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.ipv6.routes.LabeledUnicastIpv6Routes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.ipv6.routes.LabeledUnicastIpv6RoutesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.routes.list.LabeledUnicastRoute; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.routes.list.LabeledUnicastRouteBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.routes.list.LabeledUnicastRouteKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6LabeledUnicastCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel; +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.ChoiceNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates; + +public class LabeledUnicastIpv6RIBSupportTest extends AbstractRIBSupportTest { + + private static final IpPrefix IPv6_PREFIX = new IpPrefix(new Ipv6Prefix("102:304:500::/40")); + private static final LabeledUnicastIpv6RIBSupport RIB_SUPPORT = LabeledUnicastIpv6RIBSupport.getInstance(); + private static final LabeledUnicastRoute ROUTE; + private static final LabeledUnicastIpv6Routes ROUTES; + private static final LabeledUnicastRouteKey ROUTE_KEY; + private static final byte[] LABEL_KEY; + private static final PathId PATH_ID = new PathId(1L); + private static final List LABEL_STACK = Lists.newArrayList(new LabelStackBuilder().setLabelValue(new MplsLabel(355L)).build()); + private static final List LABELED_DESTINATION_LIST = Collections.singletonList(new CLabeledUnicastDestinationBuilder() + .setPathId(PATH_ID).setLabelStack(LABEL_STACK).setPrefix(IPv6_PREFIX).build()); + private static final DestinationIpv6LabeledUnicastCase REACH_NLRI = new DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast( + new DestinationIpv6LabeledUnicastBuilder().setCLabeledUnicastDestination(LABELED_DESTINATION_LIST).build()).build(); + private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type. + DestinationIpv6LabeledUnicastCase UNREACH_NLRI = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type. + DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml + .ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled.unicast._case. + DestinationIpv6LabeledUnicastBuilder().setCLabeledUnicastDestination(LABELED_DESTINATION_LIST).build()).build(); + + static { + final BGPActivator act = new BGPActivator(); + final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext(); + act.start(context); + final ByteBuf buffer = Unpooled.buffer(); + LUNlriParser.serializeNlri(LABELED_DESTINATION_LIST, buffer); + LABEL_KEY = ByteArray.readAllBytes(buffer); + ROUTE_KEY = new LabeledUnicastRouteKey(PATH_ID, LABEL_KEY); + ROUTE = new LabeledUnicastRouteBuilder().setKey(ROUTE_KEY).setPrefix(IPv6_PREFIX).setPathId(PATH_ID).setLabelStack(LABEL_STACK) + .setAttributes(new AttributesBuilder().build()).build(); + ROUTES = new LabeledUnicastIpv6RoutesBuilder().setLabeledUnicastRoute(Collections.singletonList(ROUTE)).build(); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + setUpTestCustomizer(RIB_SUPPORT); + } + + @Test + public void testDeleteRoutes() { + RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = (InstanceIdentifier) this.deletedRoutes.get(0); + assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(LabeledUnicastRoute.class)); + } + + @Test + public void testPutRoutes() { + RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + final LabeledUnicastRoute route = (LabeledUnicastRoute) this.insertedRoutes.get(0).getValue(); + assertEquals(ROUTE, route); + } + + @Test + public void testEmptyRoute() throws Exception { + final Routes empty = new LabeledUnicastIpv6RoutesCaseBuilder().setLabeledUnicastIpv6Routes( + new LabeledUnicastIpv6RoutesBuilder().setLabeledUnicastRoute(Collections.emptyList()).build()).build(); + final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + assertEquals(createRoutes(empty), emptyRoutes); + } + + @Test + public void testBuildMpUnreachNlriUpdate() { + final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); + assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class) + .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); + assertNull(update.getAttributes().getAugmentation(Attributes1.class)); + } + + @Test + public void testBuildMpReachNlriUpdate() { + final Update update = RIB_SUPPORT.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES); + assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri().getAdvertizedRoutes().getDestinationType()); + assertNull(update.getAttributes().getAugmentation(Attributes2.class)); + } + + @Test + public void testIsComplexRoute() { + Assert.assertTrue(RIB_SUPPORT.isComplexRoute()); + } + + @Test + public void testCacheableNlriObjects() { + Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + } + + @Test + public void testCacheableAttributeObjects() { + Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + } + + @Test + public void testRouteIdAddPath() { + final NodeIdentifierWithPredicates expected = createRouteNIWP(ROUTES); + final NodeIdentifierWithPredicates prefixNii = new NodeIdentifierWithPredicates(RIB_SUPPORT.routeQName(), + ImmutableMap.of(RIB_SUPPORT.routeKeyQName(), LABEL_KEY)); + Assert.assertEquals(expected, RIB_SUPPORT.getRouteIdAddPath(AbstractRIBSupportTest.PATH_ID, prefixNii)); + } + + @Test + public void testRoutePath() { + final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES); + Assert.assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + } + + @Test + public void testExtractPathId() { + Assert.assertEquals((Long) NON_PATH_ID, RIB_SUPPORT.extractPathId(null)); + } + + @Test + public void testRouteAttributesIdentifier() { + Assert.assertEquals(new NodeIdentifier(QName.create(LabeledUnicastIpv6Routes.QNAME, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Attributes.QNAME.getLocalName().intern())), + RIB_SUPPORT.routeAttributesIdentifier()); + } + + @Test + public void testRoutesCaseClass() { + Assert.assertEquals(LabeledUnicastIpv6RoutesCase.class, RIB_SUPPORT.routesCaseClass()); + } + + @Test + public void testRoutesContainerClass() { + Assert.assertEquals(LabeledUnicastIpv6Routes.class, RIB_SUPPORT.routesContainerClass()); + } + + @Test + public void testRoutesListClass() { + Assert.assertEquals(LabeledUnicastRoute.class, RIB_SUPPORT.routesListClass()); + } + + @Test + public void testChangedRoutes() { + final Routes emptyCase = new LabeledUnicastIpv6RoutesCaseBuilder().build(); + DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode(); + Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + + final Routes emptyRoutes = new LabeledUnicastIpv6RoutesCaseBuilder().setLabeledUnicastIpv6Routes(new LabeledUnicastIpv6RoutesBuilder().build()).build(); + tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); + Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + + final Routes routes = new LabeledUnicastIpv6RoutesCaseBuilder().setLabeledUnicastIpv6Routes(ROUTES).build(); + tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode(); + final Collection result = RIB_SUPPORT.changedRoutes(tree); + Assert.assertFalse(result.isEmpty()); + } +} \ No newline at end of file diff --git a/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateRIBSupportTest.java b/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateRIBSupportTest.java index 993d44d0de..6133474715 100644 --- a/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateRIBSupportTest.java +++ b/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateRIBSupportTest.java @@ -7,143 +7,217 @@ */ package org.opendaylight.protocol.bgp.linkstate; -/** - * TODO: Remove, instead use Common Rib Support test - */ -public class LinkstateRIBSupportTest { -/* - private static final Ipv4Address ipv4 = new Ipv4Address("42.42.42.42"); - private static final NodeIdentifier ROUTES_NODE_ID = new NodeIdentifier(Routes.QNAME); - final LinkstateRIBSupport link = LinkstateRIBSupport.getInstance(); - final List linkList = new ArrayList<>(); - private List routes; - - @Mock - private DOMDataWriteTransaction tx; - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - routes = new ArrayList<>(); - Mockito.doAnswer(new Answer() { - @Override - public Object answer(final InvocationOnMock invocation) throws Throwable { - final Object[] args = invocation.getArguments(); - LinkstateRIBSupportTest.this.routes.add((YangInstanceIdentifier) args[1]); - return args[1]; - } - }).when(this.tx).put(Mockito.any(LogicalDatastoreType.class), Mockito.any(YangInstanceIdentifier.class), Mockito.any(NormalizedNode.class)); +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID; + +import com.google.common.collect.ImmutableSet; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.math.BigInteger; +import java.util.Collection; +import java.util.Collections; +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser; +import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest; +import org.opendaylight.protocol.util.ByteArray; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.AreaIdentifier; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.DomainIdentifier; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Identifier; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.RouteDistinguisher; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.bgp.rib.rib.loc.rib.tables.routes.LinkstateRoutesCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.bgp.rib.rib.loc.rib.tables.routes.LinkstateRoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.isis.lan.identifier.IsIsRouterIdentifierBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestination; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestinationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.node._case.NodeDescriptorsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.LinkstateRoutes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.LinkstateRoutesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.LinkstateRoute; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.LinkstateRouteBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.LinkstateRouteKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisPseudonodeCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonodeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier; +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.ChoiceNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates; + +public final class LinkstateRIBSupportTest extends AbstractRIBSupportTest { + + private static final LinkstateRIBSupport RIB_SUPPORT = LinkstateRIBSupport.getInstance(); + private static final LinkstateRoute ROUTE; + private static final LinkstateRoutes ROUTES; + private static final LinkstateRouteKey ROUTE_KEY; + + private static final NodeCase OBJECT_TYPE2 = new NodeCaseBuilder().setNodeDescriptors(new NodeDescriptorsBuilder() + .setAreaId(new AreaIdentifier(2697513L)).setAsNumber(new AsNumber(72L)).setCRouterIdentifier(new IsisPseudonodeCaseBuilder() + .setIsisPseudonode(new IsisPseudonodeBuilder().setIsIsRouterIdentifier(new IsIsRouterIdentifierBuilder() + .setIsoSystemId(new IsoSystemIdentifier(new byte[]{0, 0, 0, 0, 0, (byte) 0x39})).build()).setPsn((short) 5).build()).build()) + .setDomainId(new DomainIdentifier(28282828L)).build()).build(); + + private static final RouteDistinguisher RD = new RouteDistinguisher(BigInteger.ONE); + private static final Identifier ID = new Identifier(BigInteger.ONE); + private static final CLinkstateDestination LINKSTATE_DESTINATION = new CLinkstateDestinationBuilder() + .setDistinguisher(RD) + .setIdentifier(ID) + .setObjectType(OBJECT_TYPE2) + .setProtocolId(ProtocolId.IsisLevel1).build(); + + private static final DestinationLinkstateCase REACH_NLRI = new DestinationLinkstateCaseBuilder().setDestinationLinkstate(new DestinationLinkstateBuilder() + .setCLinkstateDestination(Collections.singletonList(LINKSTATE_DESTINATION)).build()).build(); + private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase UNREACH_NLRI = + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn + .routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(new org.opendaylight.yang.gen.v1.urn.opendaylight + .params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate + ._case.DestinationLinkstateBuilder().setCLinkstateDestination(Collections.singletonList(LINKSTATE_DESTINATION)).build()).build(); + + static { + final BGPActivator act = new BGPActivator(); + final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext(); + act.start(context); + assertEquals(LinkstateAddressFamily.class, context.getAddressFamilyRegistry().classForFamily(16388)); + assertEquals(LinkstateSubsequentAddressFamily.class, context.getSubsequentAddressFamilyRegistry().classForFamily(71)); + final ByteBuf buffer = Unpooled.buffer(); + LinkstateNlriParser.serializeNlri(LINKSTATE_DESTINATION, buffer); + final byte[] arrayKey = ByteArray.readAllBytes(buffer); + ROUTE_KEY = new LinkstateRouteKey(arrayKey); + ROUTE = new LinkstateRouteBuilder().setKey(ROUTE_KEY).setDistinguisher(RD).setIdentifier(ID).setObjectType(OBJECT_TYPE2) + .setProtocolId(ProtocolId.IsisLevel1).setAttributes(new AttributesBuilder().build()).build(); + ROUTES = new LinkstateRoutesBuilder().setLinkstateRoute(Collections.singletonList(ROUTE)).build(); + } - Mockito.doAnswer(new Answer() { - @Override - public Object answer(final InvocationOnMock invocation) throws Throwable { - final Object[] args = invocation.getArguments(); - LinkstateRIBSupportTest.this.routes.remove(args[1]); - return args[1]; - } - }).when(this.tx).delete(Mockito.any(LogicalDatastoreType.class), Mockito.any(YangInstanceIdentifier.class)); + @Override + public void setUp() throws Exception { + super.setUp(); + setUpTestCustomizer(RIB_SUPPORT); } @Test - public void testbuildReach() throws BGPParsingException { - final CNextHop hop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(ipv4).build()).build(); - final MpReachNlri result = link.buildReach(linkList, hop); - assertEquals(LinkstateAddressFamily.class, result.getAfi()); - assertEquals(LinkstateSubsequentAddressFamily.class, result.getSafi()); - assertEquals(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("42.42.42.42")).build()).build(), result.getCNextHop()); + public void testDeleteRoutes() { + RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = (InstanceIdentifier) this.deletedRoutes.get(0); + assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(LinkstateRoute.class)); } @Test - public void testBuildUnreach() { - final MpUnreachNlri result = link.buildUnreach(linkList); - assertEquals(LinkstateAddressFamily.class, result.getAfi()); - assertEquals(LinkstateSubsequentAddressFamily.class, result.getSafi()); + public void testPutRoutes() { + RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + final LinkstateRoute route = (LinkstateRoute) this.insertedRoutes.get(0).getValue(); + assertEquals(ROUTE, route); } @Test - public void testDestinationRoutes() { - final YangInstanceIdentifier yangIdentifier = YangInstanceIdentifier.of(Routes.QNAME); - - final NodeNlriParser nodeParser = new NodeNlriParser(); - SimpleNlriTypeRegistry.getInstance().registerNlriTypeSerializer(NodeCase.class, nodeParser); - - final DataContainerNodeAttrBuilder linkstateBI = ImmutableUnkeyedListEntryNodeBuilder.create(); - linkstateBI.withNodeIdentifier(new NodeIdentifier(CLinkstateDestination.QNAME)); - - final ImmutableLeafNodeBuilder protocolId = new ImmutableLeafNodeBuilder<>(); - protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID); - protocolId.withValue("isis-level2"); - linkstateBI.addChild(protocolId.build()); - - final ImmutableLeafNodeBuilder identifier = new ImmutableLeafNodeBuilder<>(); - identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID); - identifier.withValue(BigInteger.ONE); - linkstateBI.addChild(identifier.build()); - - final DataContainerNodeBuilder objectType = Builders.choiceBuilder(); - objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID); - - final DataContainerNodeAttrBuilder nodeDescriptors = Builders.containerBuilder(); - nodeDescriptors.withNodeIdentifier(LinkstateNlriParser.NODE_DESCRIPTORS_NID); - - final ImmutableLeafNodeBuilder asNumber = new ImmutableLeafNodeBuilder<>(); - asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID); - asNumber.withValue(72L); - nodeDescriptors.addChild(asNumber.build()); - - final ImmutableLeafNodeBuilder areaID = new ImmutableLeafNodeBuilder<>(); - areaID.withNodeIdentifier(NodeNlriParser.AREA_NID); - areaID.withValue(2697513L); - nodeDescriptors.addChild(areaID.build()); - - final ImmutableLeafNodeBuilder domainID = new ImmutableLeafNodeBuilder<>(); - domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID); - domainID.withValue(0x28282828L); - nodeDescriptors.addChild(domainID.build()); + public void testEmptyRoute() throws Exception { + final Routes empty = new LinkstateRoutesCaseBuilder().setLinkstateRoutes( + new LinkstateRoutesBuilder().setLinkstateRoute(Collections.emptyList()).build()).build(); + final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + assertEquals(createRoutes(empty), emptyRoutes); + } - final DataContainerNodeBuilder crouterId = Builders.choiceBuilder(); - crouterId.withNodeIdentifier(new NodeIdentifier(CRouterIdentifier.QNAME)); + @Test + public void testBuildMpUnreachNlriUpdate() { + final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); + assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class) + .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); + assertNull(update.getAttributes().getAugmentation(Attributes1.class)); + } - final DataContainerNodeAttrBuilder isisNode = Builders.containerBuilder(); - isisNode.withNodeIdentifier(NodeNlriParser.ISIS_PSEUDONODE_NID); + @Test + public void testBuildMpReachNlriUpdate() { + final Update update = RIB_SUPPORT.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES); + assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri().getAdvertizedRoutes().getDestinationType()); + assertNull(update.getAttributes().getAugmentation(Attributes2.class)); + } - final ImmutableLeafNodeBuilder isoSystemID = new ImmutableLeafNodeBuilder<>(); - isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID); - isoSystemID.withValue(new byte[]{0, 0, 0, 0, 0, (byte) 0x39}); + @Test + public void testIsComplexRoute() { + Assert.assertTrue(RIB_SUPPORT.isComplexRoute()); + } - final DataContainerNodeAttrBuilder isisRouter = Builders.containerBuilder(); - isisRouter.withNodeIdentifier(NodeNlriParser.ISIS_ROUTER_NID); - isisRouter.addChild(isoSystemID.build()); + @Test + public void testCacheableNlriObjects() { + Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + } - isisNode.addChild(isisRouter.build()); - isisNode.addChild(Builders.leafBuilder().withNodeIdentifier(NodeNlriParser.PSN_NID).withValue((short) 5).build()); - crouterId.addChild(isisNode.build()); + @Test + public void testCacheableAttributeObjects() { + Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + } - nodeDescriptors.addChild(crouterId.build()); - objectType.addChild(nodeDescriptors.build()); - linkstateBI.addChild(objectType.build()); + @Test + public void testRouteIdAddPath() { + Assert.assertNull(RIB_SUPPORT.getRouteIdAddPath(AbstractRIBSupportTest.PATH_ID, null)); + } - final UnkeyedListNode routes = ImmutableUnkeyedListNodeBuilder.create() - .withNodeIdentifier(new NodeIdentifier(CLinkstateDestination.QNAME)) - .addChild(linkstateBI.build()) - .build(); + @Test + public void testRoutePath() { + final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES); + Assert.assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + } - final ContainerNode destination = ImmutableContainerNodeBuilder.create(). - addChild(routes) - .withNodeIdentifier(new NodeIdentifier(CLinkstateDestination.QNAME)) - .build(); + @Test + public void testExtractPathId() { + Assert.assertEquals((Long) NON_PATH_ID, RIB_SUPPORT.extractPathId(null)); + } - final ContainerNode attributes = ImmutableContainerNodeBuilder.create() - .withNodeIdentifier(new NodeIdentifier(Attributes.QNAME)) - .build(); + @Test + public void testRouteAttributesIdentifier() { + Assert.assertEquals(new NodeIdentifier(QName.create(LinkstateRoutes.QNAME, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Attributes.QNAME.getLocalName().intern())), + RIB_SUPPORT.routeAttributesIdentifier()); + } - link.putDestinationRoutes(tx, yangIdentifier, destination, attributes, ROUTES_NODE_ID); + @Test + public void testRoutesCaseClass() { + Assert.assertEquals(LinkstateRoutesCase.class, RIB_SUPPORT.routesCaseClass()); + } - Assert.assertEquals(1, this.routes.size()); + @Test + public void testRoutesContainerClass() { + Assert.assertEquals(LinkstateRoutes.class, RIB_SUPPORT.routesContainerClass()); + } - link.deleteDestinationRoutes(tx, yangIdentifier, destination, ROUTES_NODE_ID); + @Test + public void testRoutesListClass() { + Assert.assertEquals(LinkstateRoute.class, RIB_SUPPORT.routesListClass()); + } - Assert.assertEquals(0, this.routes.size()); + @Test + public void testChangedRoutes() { + final Routes emptyCase = new LinkstateRoutesCaseBuilder().build(); + DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode(); + Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + + final Routes emptyRoutes = new LinkstateRoutesCaseBuilder().setLinkstateRoutes(new LinkstateRoutesBuilder().build()).build(); + tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); + Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + + final Routes routes = new LinkstateRoutesCaseBuilder().setLinkstateRoutes(ROUTES).build(); + tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode(); + final Collection result = RIB_SUPPORT.changedRoutes(tree); + Assert.assertFalse(result.isEmpty()); } -*/ } \ No newline at end of file diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBSupportTest.java b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBSupportTest.java index ce0a888344..6c62d95ff6 100644 --- a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBSupportTest.java +++ b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBSupportTest.java @@ -55,6 +55,7 @@ import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.util.BindingReflections; +import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; @@ -157,15 +158,21 @@ public abstract class AbstractRIBSupportTest { protected final YangInstanceIdentifier getRoutePath() { final InstanceIdentifier routesIId = routesIId(); - return this.mappingService.toYangInstanceIdentifier(routesIId).node(BindingReflections.findQName(this.abstractRIBSupport.routesListClass())); + return this.mappingService.toYangInstanceIdentifier(routesIId).node(getRouteListQname()); } protected final Collection createRoutes(final DataObject routes) { Preconditions.checkArgument(routes.getImplementedInterface().equals(this.abstractRIBSupport.routesContainerClass())); final InstanceIdentifier routesIId = routesIId(); final Map.Entry> normalizedNode = this.mappingService.toNormalizedNode(routesIId, routes); - return ((MapNode) ((ContainerNode) normalizedNode.getValue()) - .getChild(new NodeIdentifier(BindingReflections.findQName(this.abstractRIBSupport.routesListClass()))).get()).getValue(); + final ContainerNode container = ((ContainerNode) normalizedNode.getValue()); + final NodeIdentifier routeNid = new NodeIdentifier(getRouteListQname()); + return ((MapNode) container.getChild(routeNid).get()).getValue(); + } + + private QName getRouteListQname() { + return QName.create(BindingReflections.findQName(this.abstractRIBSupport.routesContainerClass()), + BindingReflections.findQName(this.abstractRIBSupport.routesListClass()).intern().getLocalName()); } protected final NodeIdentifierWithPredicates createRouteNIWP(final DataObject routes) {