From f55b911d6d34821b19df198828f6d9dcc0a1949f Mon Sep 17 00:00:00 2001 From: "Claudio D. Gasparini" Date: Tue, 15 May 2018 13:36:45 +0200 Subject: [PATCH] Provide codec Serializer via RibSupport - provide access to BindingToNormalizedNodeCodec under ribsupport - clean up Change-Id: Ibee3e1550211c9d88c24eb9ae2e741ee77f7d948 Signed-off-by: Claudio D. Gasparini --- bgp/evpn/pom.xml | 11 ++ .../bgp/evpn/impl/EvpnRibSupport.java | 40 ++++-- .../protocol/bgp/evpn/impl/RIBActivator.java | 7 +- .../bgp/evpn/impl/EvpnRibSupportTest.java | 44 +++---- .../bgp/evpn/impl/RIBActivatorTest.java | 5 +- bgp/flowspec/pom.xml | 5 + .../flowspec/AbstractFlowspecRIBSupport.java | 26 ++-- .../bgp/flowspec/FlowspecIpv4RIBSupport.java | 42 +++++-- .../bgp/flowspec/FlowspecIpv6RIBSupport.java | 42 +++++-- .../protocol/bgp/flowspec/RIBActivator.java | 23 ++-- .../AbstractFlowspecL3vpnRIBSupport.java | 18 ++- .../ipv4/FlowspecL3vpnIpv4RIBSupport.java | 42 +++++-- .../ipv6/FlowspecL3vpnIpv6RIBSupport.java | 43 +++++-- .../flowspec/FlowspecIpv4RIBSupportTest.java | 111 ++++++++-------- .../flowspec/FlowspecIpv6RIBSupportTest.java | 119 ++++++++++-------- .../FlowspecL3vpnIpv4RIBSupportTest.java | 91 ++++++++------ .../FlowspecL3vpnIpv6RIBSupportTest.java | 100 ++++++++------- bgp/inet/pom.xml | 11 ++ .../bgp/inet/AbstractIPRibSupport.java | 20 ++- .../protocol/bgp/inet/IPv4RIBSupport.java | 41 ++++-- .../protocol/bgp/inet/IPv6RIBSupport.java | 39 ++++-- .../protocol/bgp/inet/RIBActivator.java | 9 +- .../protocol/bgp/inet/IPv4RIBSupportTest.java | 42 +++---- .../protocol/bgp/inet/IPv6RIBSupportTest.java | 43 +++---- bgp/l3vpn/pom.xml | 11 ++ .../bgp/l3vpn/AbstractVpnRIBSupport.java | 17 +-- .../bgp/l3vpn/ipv4/RibIpv4Activator.java | 14 ++- .../bgp/l3vpn/ipv4/VpnIpv4RIBSupport.java | 39 ++++-- .../bgp/l3vpn/ipv6/RibIpv6Activator.java | 14 +-- .../bgp/l3vpn/ipv6/VpnIpv6RIBSupport.java | 38 ++++-- .../bgp/l3vpn/ipv4/VpnIpv4RIBSupportTest.java | 43 ++++--- .../bgp/l3vpn/ipv6/VpnIpv6RIBSupportTest.java | 42 +++---- bgp/labeled-unicast/pom.xml | 5 + .../AbstractLabeledUnicastRIBSupport.java | 31 +++-- .../unicast/LabeledUnicastIpv4RIBSupport.java | 56 ++++++--- .../unicast/LabeledUnicastIpv6RIBSupport.java | 56 ++++++--- .../bgp/labeled/unicast/RIBActivator.java | 11 +- .../LabeledUnicastIpv4RIBSupportTest.java | 92 ++++++++------ .../LabeledUnicastIpv6RIBSupportTest.java | 87 +++++++------ bgp/linkstate/pom.xml | 5 + .../linkstate/impl/LinkstateRIBSupport.java | 43 +++++-- .../bgp/linkstate/impl/RIBActivator.java | 11 +- .../protocol/bgp/linkstate/ActivatorTest.java | 14 ++- .../linkstate/LinkstateRIBSupportTest.java | 42 +++---- .../bgp/rib/impl/EffectiveRibInWriter.java | 2 +- .../bgp/rib/impl/AbstractAddPathTest.java | 32 +---- .../bgp/rib/impl/AbstractRIBTestSetup.java | 2 +- .../bgp/rib/impl/AddPathAllPathsTest.java | 2 +- .../bgp/rib/impl/AddPathBasePathsTest.java | 2 +- .../bgp/rib/impl/AddPathNPathsTest.java | 2 +- .../bgp/rib/impl/ParserToSalTest.java | 4 +- .../impl/SynchronizationAndExceptionTest.java | 4 +- bgp/rib-spi/pom.xml | 15 ++- ...AbstractRIBExtensionProviderActivator.java | 11 +- .../bgp/rib/spi/AbstractRIBSupport.java | 57 ++++++--- .../spi/RIBExtensionProviderActivator.java | 5 +- .../protocol/bgp/rib/spi/RIBSupport.java | 29 +++-- ...viceLoaderRIBExtensionConsumerContext.java | 11 +- ...eRIBExtensionProviderContextActivator.java | 8 +- .../opendaylight/blueprint/bgp-rib-spi.xml | 4 +- bgp/rib-spi/src/main/yang/bgp-test.yang | 92 ++++++++++++++ .../bgp/rib/spi/AbstractRIBActivatorTest.java | 24 ++++ .../bgp/rib/spi/AbstractRIBSupportTest.java | 48 ++++--- .../protocol/bgp/rib/spi/RIBSupportTest.java | 81 ++++++------ .../bgp/rib/spi/RIBSupportTestImp.java | 81 ++++++++++++ ...ExtensionProviderContextActivatorTest.java | 11 +- .../bgp/rib/spi/SimpleRIBExtensionTest.java | 26 +++- .../ipv4/routes/ipv4/routes/Ipv4Prefixes.java | 16 --- .../ipv4/routes/ipv4/routes/Ipv4Route.java | 17 --- .../ipv4/routes/ipv4/routes/Ipv4Routes.java | 17 --- .../routes/ipv4/routes/Ipv4RoutesCase.java | 18 --- .../routes/ipv4/routes/RIBSupportTestImp.java | 77 ------------ .../bmp/impl/app/BmpMonitorImplTest.java | 48 +++---- 73 files changed, 1455 insertions(+), 936 deletions(-) create mode 100644 bgp/rib-spi/src/main/yang/bgp-test.yang create mode 100644 bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBActivatorTest.java create mode 100644 bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/RIBSupportTestImp.java delete mode 100644 bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Prefixes.java delete mode 100644 bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Route.java delete mode 100644 bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Routes.java delete mode 100644 bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4RoutesCase.java delete mode 100644 bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/RIBSupportTestImp.java diff --git a/bgp/evpn/pom.xml b/bgp/evpn/pom.xml index 1f210985c2..6a72a69f31 100644 --- a/bgp/evpn/pom.xml +++ b/bgp/evpn/pom.xml @@ -111,6 +111,17 @@ bgp-parser-impl test + + org.opendaylight.controller + sal-binding-broker-impl + test + + + org.opendaylight.controller + sal-binding-broker-impl + test + test-jar + 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 7f5e6e7363..6ed881dc7f 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 @@ -15,6 +15,7 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.evpn.impl.nlri.EvpnNlriParser; import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil; import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupport; @@ -22,7 +23,7 @@ import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EvpnSubsequentAddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.L2vpnAddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.bgp.rib.rib.loc.rib.tables.routes.EvpnRoutesCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.bgp.rib.rib.peer.effective.rib.in.tables.routes.EvpnRoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.bgp.rib.rib.loc.rib.tables.routes.EvpnRoutesCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.destination.EvpnDestination; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.EvpnRoutes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.evpn.routes.EvpnRoutesBuilder; @@ -35,7 +36,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes; 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; @@ -48,17 +48,30 @@ import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -final class EvpnRibSupport extends AbstractRIBSupport { - private static final EvpnRibSupport SINGLETON = new EvpnRibSupport(); +final class EvpnRibSupport extends AbstractRIBSupport { private static final Logger LOG = LoggerFactory.getLogger(EvpnRibSupport.class); + private static final NodeIdentifier NLRI_ROUTES_LIST = NodeIdentifier.create(EvpnDestination.QNAME); + private static final EvpnRoutes EMPTY_CONTAINER + = new EvpnRoutesBuilder().setEvpnRoute(Collections.emptyList()).build(); + private static final EvpnRoutesCase EMPTY_CASE = + new EvpnRoutesCaseBuilder().setEvpnRoutes(EMPTY_CONTAINER).build(); + private static EvpnRibSupport SINGLETON; - private EvpnRibSupport() { - super(EvpnRoutesCase.class, EvpnRoutes.class, EvpnRoute.class, L2vpnAddressFamily.class, - EvpnSubsequentAddressFamily.class, DestinationEvpn.QNAME); + private EvpnRibSupport(final BindingNormalizedNodeSerializer mappingService) { + super(mappingService, + EvpnRoutesCase.class, + EvpnRoutes.class, + EvpnRoute.class, + L2vpnAddressFamily.class, + EvpnSubsequentAddressFamily.class, + DestinationEvpn.QNAME); } - static EvpnRibSupport getInstance() { + static synchronized EvpnRibSupport getInstance(final BindingNormalizedNodeSerializer mappingService) { + if (SINGLETON == null) { + SINGLETON = new EvpnRibSupport(mappingService); + } return SINGLETON; } @@ -121,12 +134,17 @@ final class EvpnRibSupport extends AbstractRIBSupport { } else { builder = new EvpnRouteBuilder(); } - return builder.setKey(new EvpnRouteKey(new PathId(pathId), routeKey)).setAttributes(attributes).build(); + return builder.setKey(createRouteListKey(pathId, routeKey)).setAttributes(attributes).build(); + } + + @Override + public EvpnRoutesCase emptyRoutesCase() { + return EMPTY_CASE; } @Override - public Routes emptyRoutesContainer() { - return new EvpnRoutesCaseBuilder().setEvpnRoutes(new EvpnRoutesBuilder().build()).build(); + public EvpnRoutes emptyRoutesContainer() { + return EMPTY_CONTAINER; } @Override diff --git a/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/RIBActivator.java b/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/RIBActivator.java index c7a1008879..2efa90fa16 100644 --- a/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/RIBActivator.java +++ b/bgp/evpn/src/main/java/org/opendaylight/protocol/bgp/evpn/impl/RIBActivator.java @@ -10,6 +10,7 @@ package org.opendaylight.protocol.bgp.evpn.impl; import java.util.Collections; import java.util.List; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBExtensionProviderActivator; import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EvpnSubsequentAddressFamily; @@ -18,9 +19,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn public final class RIBActivator extends AbstractRIBExtensionProviderActivator { @Override - protected List startRIBExtensionProviderImpl(final RIBExtensionProviderContext context) { + protected List startRIBExtensionProviderImpl( + final RIBExtensionProviderContext context, + final BindingNormalizedNodeSerializer mappingService) { return Collections.singletonList(context.registerRIBSupport(L2vpnAddressFamily.class, EvpnSubsequentAddressFamily.class, - EvpnRibSupport.getInstance())); + EvpnRibSupport.getInstance(mappingService))); } } \ No newline at end of file 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 bb81a87d7f..57b5f2cf00 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 @@ -52,8 +52,8 @@ 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(); +public final class EvpnRibSupportTest extends AbstractRIBSupportTest { + private EvpnRibSupport ribSupport; private static final EvpnRoute ROUTE; private static final EvpnRouteKey ROUTE_KEY; private static final EvpnDestination EVPN_DESTINATION = new EvpnDestinationBuilder() @@ -93,20 +93,20 @@ public final class EvpnRibSupportTest extends AbstractRIBSupportTest { @Override public void setUp() throws Exception { super.setUp(); - setUpTestCustomizer(RIB_SUPPORT); + this.ribSupport = EvpnRibSupport.getInstance(this.mappingService); + setUpTestCustomizer(this.ribSupport); } @Test public void testDeleteRoutes() { - RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); - @SuppressWarnings("unchecked") final InstanceIdentifier instanceIdentifier = - (InstanceIdentifier) this.deletedRoutes.get(0); + this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = this.deletedRoutes.get(0); assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(EvpnRoute.class)); } @Test public void testPutRoutes() { - RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); final EvpnRoute route = (EvpnRoute) this.insertedRoutes.get(0).getValue(); assertEquals(ROUTE, route); } @@ -116,13 +116,14 @@ public final class EvpnRibSupportTest extends AbstractRIBSupportTest { public void testEmptyRoute() { final Routes empty = new EvpnRoutesCaseBuilder().setEvpnRoutes( new EvpnRoutesBuilder().setEvpnRoute(Collections.emptyList()).build()).build(); - final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + final ChoiceNode emptyRoutes = this.ribSupport.emptyRoutes(); assertEquals(createRoutes(empty), emptyRoutes); } @Test public void testBuildMpUnreachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(EVPN_ROUTES), ATTRIBUTES); + final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), + createRoutes(EVPN_ROUTES), ATTRIBUTES); assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri() .getWithdrawnRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes1.class)); @@ -130,7 +131,8 @@ public final class EvpnRibSupportTest extends AbstractRIBSupportTest { @Test public void testBuildMpReachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(createRoutes(EVPN_ROUTES), Collections.emptyList(), ATTRIBUTES); + final Update update = this.ribSupport.buildUpdate( + createRoutes(EVPN_ROUTES), Collections.emptyList(), ATTRIBUTES); assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri() .getAdvertizedRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes2.class)); @@ -138,17 +140,17 @@ public final class EvpnRibSupportTest extends AbstractRIBSupportTest { @Test public void testCacheableNlriObjects() { - assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableNlriObjects()); } @Test public void testCacheableAttributeObjects() { - assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects()); } @Test public void testRouteIdAddPath() { - assertEquals(ROUTE_KEY, RIB_SUPPORT.createRouteListKey(ROUTE_KEY.getPathId().getValue(), + assertEquals(ROUTE_KEY, this.ribSupport.createRouteListKey(ROUTE_KEY.getPathId().getValue(), ROUTE_KEY.getRouteKey())); } @@ -156,28 +158,28 @@ public final class EvpnRibSupportTest extends AbstractRIBSupportTest { public void testRoutePath() { final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(EVPN_ROUTES); assertEquals(getRoutePath().node(prefixNii), - RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + this.ribSupport.routePath(getTablePath().node(Routes.QNAME), prefixNii)); } @Test public void testRouteAttributesIdentifier() { assertEquals(new NodeIdentifier(QName.create(EvpnRoutes.QNAME, - Attributes.QNAME.getLocalName().intern())), RIB_SUPPORT.routeAttributesIdentifier()); + Attributes.QNAME.getLocalName().intern())), this.ribSupport.routeAttributesIdentifier()); } @Test public void testRoutesCaseClass() { - assertEquals(EvpnRoutesCase.class, RIB_SUPPORT.routesCaseClass()); + assertEquals(EvpnRoutesCase.class, this.ribSupport.routesCaseClass()); } @Test public void testRoutesContainerClass() { - assertEquals(EvpnRoutes.class, RIB_SUPPORT.routesContainerClass()); + assertEquals(EvpnRoutes.class, this.ribSupport.routesContainerClass()); } @Test public void testRoutesListClass() { - assertEquals(EvpnRoute.class, RIB_SUPPORT.routesListClass()); + assertEquals(EvpnRoute.class, this.ribSupport.routesListClass()); } @Test @@ -185,15 +187,15 @@ public final class EvpnRibSupportTest extends AbstractRIBSupportTest { final Routes emptyCase = new EvpnRoutesCaseBuilder().build(); DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode(); - Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + Assert.assertTrue(this.ribSupport.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()); + Assert.assertTrue(this.ribSupport.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); + final Collection result = this.ribSupport.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/RIBActivatorTest.java b/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/RIBActivatorTest.java index 8233978388..c362427b7d 100644 --- a/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/RIBActivatorTest.java +++ b/bgp/evpn/src/test/java/org/opendaylight/protocol/bgp/evpn/impl/RIBActivatorTest.java @@ -11,18 +11,19 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import org.junit.Test; +import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBActivatorTest; import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext; import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.EvpnSubsequentAddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.L2vpnAddressFamily; -public class RIBActivatorTest { +public class RIBActivatorTest extends AbstractRIBActivatorTest { @Test public void testRIBActivator() { final RIBActivator ribAct = new RIBActivator(); final RIBExtensionProviderContext context = new SimpleRIBExtensionProviderContext(); assertNull(context.getRIBSupport(L2vpnAddressFamily.class, EvpnSubsequentAddressFamily.class)); - ribAct.startRIBExtensionProvider(context); + ribAct.startRIBExtensionProvider(context, this.mappingService); assertNotNull(context.getRIBSupport(L2vpnAddressFamily.class, EvpnSubsequentAddressFamily.class)); ribAct.close(); } diff --git a/bgp/flowspec/pom.xml b/bgp/flowspec/pom.xml index a8ba4250da..2ef3ba0580 100644 --- a/bgp/flowspec/pom.xml +++ b/bgp/flowspec/pom.xml @@ -150,6 +150,11 @@ mdsal-binding-dom-adapter test + + org.opendaylight.controller + sal-binding-broker-impl + test + diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecRIBSupport.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecRIBSupport.java index ed1cb6eecb..2343bdf00c 100644 --- a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecRIBSupport.java +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/AbstractFlowspecRIBSupport.java @@ -14,6 +14,7 @@ import com.google.common.collect.Iterables; import java.util.Collection; import java.util.Optional; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil; import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupport; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId; @@ -33,20 +34,25 @@ import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; @Beta -public abstract class AbstractFlowspecRIBSupport extends AbstractRIBSupport { +public abstract class AbstractFlowspecRIBSupport< + T extends AbstractFlowspecNlriParser, + C extends Routes & DataObject, + S extends DataObject, + R extends Route, + I extends Identifier> extends AbstractRIBSupport { protected final T nlriParser; protected AbstractFlowspecRIBSupport( - final Class cazeClass, - final Class containerClass, - final Class listClass, - final Class afiClass, - final Class safiClass, - final QName dstContainerClassQName, - final T nlriParser + final BindingNormalizedNodeSerializer mappingService, + final Class cazeClass, + final Class containerClass, + final Class listClass, + final Class afiClass, + final Class safiClass, + final QName dstContainerClassQName, + final T nlriParser ) { - super(cazeClass, containerClass, listClass, afiClass, safiClass, dstContainerClassQName); + super(mappingService, cazeClass, containerClass, listClass, afiClass, safiClass, dstContainerClassQName); this.nlriParser = requireNonNull(nlriParser); } diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv4RIBSupport.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv4RIBSupport.java index 369eae6267..6715b97e1c 100644 --- a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv4RIBSupport.java +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/FlowspecIpv4RIBSupport.java @@ -7,9 +7,11 @@ */ package org.opendaylight.protocol.bgp.flowspec; +import java.util.Collections; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.FlowspecSubsequentAddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.loc.rib.tables.routes.FlowspecRoutesCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.peer.effective.rib.in.tables.routes.FlowspecRoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.loc.rib.tables.routes.FlowspecRoutesCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.ipv4.DestinationFlowspec; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.ipv4.route.FlowspecRoute; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.ipv4.route.FlowspecRouteBuilder; @@ -18,14 +20,25 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flow import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.routes.FlowspecRoutesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily; -public final class FlowspecIpv4RIBSupport extends AbstractFlowspecRIBSupport { +public final class FlowspecIpv4RIBSupport + extends AbstractFlowspecRIBSupport { + private static final FlowspecRoutes EMPTY_CONTAINER + = new FlowspecRoutesBuilder().setFlowspecRoute(Collections.emptyList()).build(); + private static final FlowspecRoutesCase EMPTY_CASE + = new FlowspecRoutesCaseBuilder().setFlowspecRoutes(EMPTY_CONTAINER).build(); + private static FlowspecIpv4RIBSupport SINGLETON; - public FlowspecIpv4RIBSupport(SimpleFlowspecExtensionProviderContext context) { + private FlowspecIpv4RIBSupport( + SimpleFlowspecExtensionProviderContext context, + final BindingNormalizedNodeSerializer mappingService) { super( + mappingService, FlowspecRoutesCase.class, FlowspecRoutes.class, FlowspecRoute.class, @@ -38,9 +51,13 @@ public final class FlowspecIpv4RIBSupport extends AbstractFlowspecRIBSupport { +public final class FlowspecIpv6RIBSupport + extends AbstractFlowspecRIBSupport { + private static final FlowspecIpv6Routes EMPTY_CONTAINER + = new FlowspecIpv6RoutesBuilder().setFlowspecRoute(Collections.emptyList()).build(); + private static final FlowspecIpv6RoutesCase EMPTY_CASE = new FlowspecIpv6RoutesCaseBuilder() + .setFlowspecIpv6Routes(EMPTY_CONTAINER).build(); + private static FlowspecIpv6RIBSupport SINGLETON; - public FlowspecIpv6RIBSupport(SimpleFlowspecExtensionProviderContext context) { + private FlowspecIpv6RIBSupport( + SimpleFlowspecExtensionProviderContext context, + final BindingNormalizedNodeSerializer mappingService) { super( + mappingService, FlowspecIpv6RoutesCase.class, FlowspecIpv6Routes.class, FlowspecRoute.class, @@ -38,8 +51,13 @@ public final class FlowspecIpv6RIBSupport extends AbstractFlowspecRIBSupport startRIBExtensionProviderImpl(final RIBExtensionProviderContext context) { - final List regs = new ArrayList<>(); - regs.add(context.registerRIBSupport(Ipv4AddressFamily.class, - FlowspecSubsequentAddressFamily.class, FlowspecIpv4RIBSupport.getInstance(this.fsContext))); - regs.add(context.registerRIBSupport(Ipv6AddressFamily.class, - FlowspecSubsequentAddressFamily.class, FlowspecIpv6RIBSupport.getInstance(this.fsContext))); - regs.add(context.registerRIBSupport(Ipv4AddressFamily.class, - FlowspecL3vpnSubsequentAddressFamily.class, FlowspecL3vpnIpv4RIBSupport.getInstance(this.fsContext))); - regs.add(context.registerRIBSupport(Ipv6AddressFamily.class, - FlowspecL3vpnSubsequentAddressFamily.class, FlowspecL3vpnIpv6RIBSupport.getInstance(this.fsContext))); + protected List startRIBExtensionProviderImpl( + final RIBExtensionProviderContext context, + final BindingNormalizedNodeSerializer mappingService) { + final List regs = new ArrayList<>(4); + regs.add(context.registerRIBSupport(Ipv4AddressFamily.class, FlowspecSubsequentAddressFamily.class, + FlowspecIpv4RIBSupport.getInstance(this.fsContext, mappingService))); + regs.add(context.registerRIBSupport(Ipv6AddressFamily.class, FlowspecSubsequentAddressFamily.class, + FlowspecIpv6RIBSupport.getInstance(this.fsContext, mappingService))); + regs.add(context.registerRIBSupport(Ipv4AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class, + FlowspecL3vpnIpv4RIBSupport.getInstance(this.fsContext, mappingService))); + regs.add(context.registerRIBSupport(Ipv6AddressFamily.class, FlowspecL3vpnSubsequentAddressFamily.class, + FlowspecL3vpnIpv6RIBSupport.getInstance(this.fsContext, mappingService))); return regs; } } diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/AbstractFlowspecL3vpnRIBSupport.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/AbstractFlowspecL3vpnRIBSupport.java index 4babd12d35..8ef8feee01 100644 --- a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/AbstractFlowspecL3vpnRIBSupport.java +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/AbstractFlowspecL3vpnRIBSupport.java @@ -9,6 +9,7 @@ package org.opendaylight.protocol.bgp.flowspec.l3vpn; import com.google.common.collect.Iterables; import java.util.Collection; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.flowspec.AbstractFlowspecRIBSupport; import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.FlowspecL3vpnSubsequentAddressFamily; @@ -24,18 +25,23 @@ import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; public abstract class AbstractFlowspecL3vpnRIBSupport - - extends AbstractFlowspecRIBSupport { + + extends AbstractFlowspecRIBSupport { protected AbstractFlowspecL3vpnRIBSupport( - final Class cazeClass, - final Class containerClass, - final Class listClass, + final BindingNormalizedNodeSerializer mappingService, + final Class cazeClass, + final Class containerClass, + final Class listClass, final QName dstContainerClassQName, final Class afiClass, final T flowspecNlriParser ) { - super(cazeClass, containerClass, listClass, afiClass, FlowspecL3vpnSubsequentAddressFamily.class, + super(mappingService, cazeClass, containerClass, listClass, afiClass, FlowspecL3vpnSubsequentAddressFamily.class, dstContainerClassQName, flowspecNlriParser); } diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv4/FlowspecL3vpnIpv4RIBSupport.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv4/FlowspecL3vpnIpv4RIBSupport.java index 49d0efe5cc..2a3e80395d 100644 --- a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv4/FlowspecL3vpnIpv4RIBSupport.java +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv4/FlowspecL3vpnIpv4RIBSupport.java @@ -7,10 +7,12 @@ */ package org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv4; +import java.util.Collections; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecExtensionProviderContext; import org.opendaylight.protocol.bgp.flowspec.l3vpn.AbstractFlowspecL3vpnRIBSupport; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv4RoutesCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.peer.effective.rib.in.tables.routes.FlowspecL3vpnIpv4RoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv4RoutesCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.destination.ipv4.DestinationFlowspecL3vpnIpv4; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv4.route.FlowspecL3vpnRoute; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv4.route.FlowspecL3vpnRouteBuilder; @@ -19,14 +21,25 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flow import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv4.routes.FlowspecL3vpnIpv4RoutesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily; -public final class FlowspecL3vpnIpv4RIBSupport extends AbstractFlowspecL3vpnRIBSupport { +public final class FlowspecL3vpnIpv4RIBSupport + extends AbstractFlowspecL3vpnRIBSupport { + private static final FlowspecL3vpnIpv4Routes EMPTY_CONTAINER + = new FlowspecL3vpnIpv4RoutesBuilder().setFlowspecL3vpnRoute(Collections.emptyList()).build(); + private static final FlowspecL3vpnIpv4RoutesCase EMPTY_CASE = new FlowspecL3vpnIpv4RoutesCaseBuilder() + .setFlowspecL3vpnIpv4Routes(EMPTY_CONTAINER).build(); + private static FlowspecL3vpnIpv4RIBSupport SINGLETON; - public FlowspecL3vpnIpv4RIBSupport(final SimpleFlowspecExtensionProviderContext context) { + private FlowspecL3vpnIpv4RIBSupport( + final SimpleFlowspecExtensionProviderContext context, + final BindingNormalizedNodeSerializer mappingService) { super( + mappingService, FlowspecL3vpnIpv4RoutesCase.class, FlowspecL3vpnIpv4Routes.class, FlowspecL3vpnRoute.class, @@ -38,8 +51,13 @@ public final class FlowspecL3vpnIpv4RIBSupport extends AbstractFlowspecL3vpnRIBS ); } - public static FlowspecL3vpnIpv4RIBSupport getInstance(final SimpleFlowspecExtensionProviderContext context) { - return new FlowspecL3vpnIpv4RIBSupport(context); + public static synchronized FlowspecL3vpnIpv4RIBSupport getInstance( + final SimpleFlowspecExtensionProviderContext context, + final BindingNormalizedNodeSerializer mappingService) { + if(SINGLETON == null){ + SINGLETON = new FlowspecL3vpnIpv4RIBSupport(context, mappingService); + } + return SINGLETON; } @Override @@ -61,8 +79,12 @@ public final class FlowspecL3vpnIpv4RIBSupport extends AbstractFlowspecL3vpnRIBS } @Override - public Routes emptyRoutesContainer() { - return new FlowspecL3vpnIpv4RoutesCaseBuilder() - .setFlowspecL3vpnIpv4Routes(new FlowspecL3vpnIpv4RoutesBuilder().build()).build(); + public FlowspecL3vpnIpv4RoutesCase emptyRoutesCase() { + return EMPTY_CASE; + } + + @Override + public FlowspecL3vpnIpv4Routes emptyRoutesContainer() { + return EMPTY_CONTAINER; } } diff --git a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv6/FlowspecL3vpnIpv6RIBSupport.java b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv6/FlowspecL3vpnIpv6RIBSupport.java index c08687792e..893c64f6ae 100644 --- a/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv6/FlowspecL3vpnIpv6RIBSupport.java +++ b/bgp/flowspec/src/main/java/org/opendaylight/protocol/bgp/flowspec/l3vpn/ipv6/FlowspecL3vpnIpv6RIBSupport.java @@ -7,10 +7,12 @@ */ package org.opendaylight.protocol.bgp.flowspec.l3vpn.ipv6; +import java.util.Collections; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.flowspec.SimpleFlowspecExtensionProviderContext; import org.opendaylight.protocol.bgp.flowspec.l3vpn.AbstractFlowspecL3vpnRIBSupport; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv6RoutesCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.peer.effective.rib.in.tables.routes.FlowspecL3vpnIpv6RoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv6RoutesCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.destination.ipv6.DestinationFlowspecL3vpnIpv6; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv6.route.FlowspecL3vpnRoute; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv6.route.FlowspecL3vpnRouteBuilder; @@ -19,13 +21,25 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flow import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.l3vpn.ipv6.routes.FlowspecL3vpnIpv6RoutesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily; -public final class FlowspecL3vpnIpv6RIBSupport extends AbstractFlowspecL3vpnRIBSupport { - private FlowspecL3vpnIpv6RIBSupport(SimpleFlowspecExtensionProviderContext context) { +public final class FlowspecL3vpnIpv6RIBSupport + extends AbstractFlowspecL3vpnRIBSupport { + private static final FlowspecL3vpnIpv6Routes EMPTY_CONTAINER + = new FlowspecL3vpnIpv6RoutesBuilder().setFlowspecL3vpnRoute(Collections.emptyList()).build(); + private static final FlowspecL3vpnIpv6RoutesCase EMPTY_CASE = new FlowspecL3vpnIpv6RoutesCaseBuilder() + .setFlowspecL3vpnIpv6Routes(EMPTY_CONTAINER).build(); + private static FlowspecL3vpnIpv6RIBSupport SINGLETON; + + private FlowspecL3vpnIpv6RIBSupport( + final SimpleFlowspecExtensionProviderContext context, + final BindingNormalizedNodeSerializer mappingService) { super( + mappingService, FlowspecL3vpnIpv6RoutesCase.class, FlowspecL3vpnIpv6Routes.class, FlowspecL3vpnRoute.class, @@ -37,8 +51,13 @@ public final class FlowspecL3vpnIpv6RIBSupport extends AbstractFlowspecL3vpnRIBS ); } - public static FlowspecL3vpnIpv6RIBSupport getInstance(final SimpleFlowspecExtensionProviderContext context) { - return new FlowspecL3vpnIpv6RIBSupport(context); + public static synchronized FlowspecL3vpnIpv6RIBSupport getInstance( + final SimpleFlowspecExtensionProviderContext context, + final BindingNormalizedNodeSerializer mappingService) { + if (SINGLETON == null) { + SINGLETON = new FlowspecL3vpnIpv6RIBSupport(context, mappingService); + } + return SINGLETON; } @Override @@ -60,8 +79,12 @@ public final class FlowspecL3vpnIpv6RIBSupport extends AbstractFlowspecL3vpnRIBS } @Override - public Routes emptyRoutesContainer() { - return new FlowspecL3vpnIpv6RoutesCaseBuilder() - .setFlowspecL3vpnIpv6Routes(new FlowspecL3vpnIpv6RoutesBuilder().build()).build(); + public FlowspecL3vpnIpv6RoutesCase emptyRoutesCase() { + return EMPTY_CASE; + } + + @Override + public FlowspecL3vpnIpv6Routes emptyRoutesContainer() { + return EMPTY_CONTAINER; } } 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 index 41d3afd9f9..8b162cb72d 100644 --- 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 @@ -50,70 +50,74 @@ 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 { +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 FlowspecIpv4RIBSupport ribSupport; + private FlowspecRoute route; + private FlowspecRoutes routes; + private FlowspecRouteKey routeKey; 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 static final 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 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 static final 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.rev180329.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.rev180329.update - .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCaseBuilder().setDestinationFlowspec(DEST_FLOW).build(); + .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.rev180329.update + .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecCaseBuilder() + .setDestinationFlowspec(DEST_FLOW).build(); - static { + @Override + public void setUp() throws Exception { + super.setUp(); final SimpleFlowspecExtensionProviderContext fsContext = new SimpleFlowspecExtensionProviderContext(); final FlowspecActivator activator = new FlowspecActivator(fsContext); final BGPActivator act = new BGPActivator(activator); final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext(); act.start(context); - RIB_SUPPORT = FlowspecIpv4RIBSupport.getInstance(fsContext); + this.ribSupport = FlowspecIpv4RIBSupport.getInstance(fsContext, this.mappingService); final SimpleFlowspecIpv4NlriParser parser = new SimpleFlowspecIpv4NlriParser( - fsContext.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(); - } + fsContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, + SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC)); - @Override - public void setUp() throws Exception { - super.setUp(); - setUpTestCustomizer(RIB_SUPPORT); + this.routeKey = new FlowspecRouteKey(PATH_ID, parser.stringNlri(FLOW_LIST)); + this.route = new FlowspecRouteBuilder().setKey(this.routeKey).setPathId(PATH_ID).setFlowspec(FLOW_LIST) + .setAttributes(new AttributesBuilder().build()).build(); + this.routes = new FlowspecRoutesBuilder().setFlowspecRoute(Collections.singletonList(this.route)).build(); + setUpTestCustomizer(this.ribSupport); } @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)); + this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = this.deletedRoutes.get(0); + assertEquals(this.routeKey, instanceIdentifier.firstKeyOf(FlowspecRoute.class)); } @Test public void testPutRoutes() { - RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); final FlowspecRoute route = (FlowspecRoute) this.insertedRoutes.get(0).getValue(); - assertEquals(ROUTE, route); + assertEquals(this.route, route); } @Test - public void testEmptyRoute() throws Exception { + public void testEmptyRoute() { final Routes empty = new FlowspecRoutesCaseBuilder().setFlowspecRoutes( new FlowspecRoutesBuilder().setFlowspecRoute(Collections.emptyList()).build()).build(); - final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + final ChoiceNode emptyRoutes = this.ribSupport.emptyRoutes(); assertEquals(createRoutes(empty), emptyRoutes); } @Test public void testBuildMpUnreachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); + final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), createRoutes(routes), ATTRIBUTES); assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class) .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes1.class)); @@ -121,68 +125,73 @@ public class FlowspecIpv4RIBSupportTest extends AbstractRIBSupportTest { @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()); + final Update update = this.ribSupport.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 testCacheableNlriObjects() { - Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableNlriObjects()); } @Test public void testCacheableAttributeObjects() { - Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects()); } @Test public void testRouteIdAddPath() { - Assert.assertEquals(ROUTE_KEY, RIB_SUPPORT.createRouteListKey(1L, ROUTE_KEY.getRouteKey())); + assertEquals(this.routeKey, this.ribSupport.createRouteListKey(1L, this.routeKey.getRouteKey())); } @Test public void testRoutePath() { - final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES); - Assert.assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(this.routes); + assertEquals(getRoutePath().node(prefixNii), + this.ribSupport.routePath(getTablePath().node(Routes.QNAME), prefixNii)); } @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.rev180329.rib.tables.Attributes.QNAME.getLocalName().intern())), - RIB_SUPPORT.routeAttributesIdentifier()); + assertEquals(new NodeIdentifier(QName.create(FlowspecRoutes.QNAME, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables + .Attributes.QNAME.getLocalName().intern())), + this.ribSupport.routeAttributesIdentifier()); } @Test public void testRoutesCaseClass() { - Assert.assertEquals(FlowspecRoutesCase.class, RIB_SUPPORT.routesCaseClass()); + assertEquals(FlowspecRoutesCase.class, this.ribSupport.routesCaseClass()); } @Test public void testRoutesContainerClass() { - Assert.assertEquals(FlowspecRoutes.class, RIB_SUPPORT.routesContainerClass()); + assertEquals(FlowspecRoutes.class, this.ribSupport.routesContainerClass()); } @Test public void testRoutesListClass() { - Assert.assertEquals(FlowspecRoute.class, RIB_SUPPORT.routesListClass()); + assertEquals(FlowspecRoute.class, this.ribSupport.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()); + DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), + createRoutes(emptyCase)).getRootNode(); + Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); - final Routes emptyRoutes = new FlowspecRoutesCaseBuilder().setFlowspecRoutes(new FlowspecRoutesBuilder().build()).build(); + final Routes emptyRoutes + = new FlowspecRoutesCaseBuilder().setFlowspecRoutes(new FlowspecRoutesBuilder().build()).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); - Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); final Routes routes = new FlowspecRoutesCaseBuilder().setFlowspecRoutes(new FlowspecRoutesBuilder() - .setFlowspecRoute(Collections.singletonList(ROUTE)).build()).build(); + .setFlowspecRoute(Collections.singletonList(this.route)).build()).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode(); - final Collection result = RIB_SUPPORT.changedRoutes(tree); + final Collection result = this.ribSupport.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 index 6ad362ef1f..9dfd4bed30 100644 --- 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 @@ -50,69 +50,73 @@ 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 { +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 static final 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 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 static final 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.rev180329.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.rev180329.update - .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecIpv6CaseBuilder().setDestinationFlowspec(DEST_FLOW).build(); - private static final FlowspecIpv6Routes ROUTES; - static { + .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.rev180329.update + .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecIpv6CaseBuilder() + .setDestinationFlowspec(DEST_FLOW).build(); + private FlowspecRoute route; + private FlowspecRouteKey routeKey; + private FlowspecIpv6Routes routes; + private FlowspecIpv6RIBSupport ribSupport; + + @Override + public void setUp() throws Exception { + super.setUp(); final SimpleFlowspecExtensionProviderContext fsContext = new SimpleFlowspecExtensionProviderContext(); final FlowspecActivator activator = new FlowspecActivator(fsContext); final BGPActivator act = new BGPActivator(activator); final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext(); act.start(context); - RIB_SUPPORT = FlowspecIpv6RIBSupport.getInstance(fsContext); final SimpleFlowspecIpv6NlriParser parser = new SimpleFlowspecIpv6NlriParser( - fsContext.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); + fsContext.getFlowspecTypeRegistry(SimpleFlowspecExtensionProviderContext.AFI.IPV4, + SimpleFlowspecExtensionProviderContext.SAFI.FLOWSPEC)); + this.routeKey = new FlowspecRouteKey(PATH_ID, parser.stringNlri(FLOW_LIST)); + this.route = new FlowspecRouteBuilder().setKey(this.routeKey).setPathId(PATH_ID).setFlowspec(FLOW_LIST) + .setAttributes(new AttributesBuilder().build()).build(); + this.routes = new FlowspecIpv6RoutesBuilder().setFlowspecRoute(Collections.singletonList(this.route)).build(); + this.ribSupport = FlowspecIpv6RIBSupport.getInstance(fsContext, this.mappingService); + setUpTestCustomizer(this.ribSupport); } @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)); + this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = this.deletedRoutes.get(0); + assertEquals(this.routeKey, instanceIdentifier.firstKeyOf(FlowspecRoute.class)); } @Test public void testPutRoutes() { - RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); final FlowspecRoute route = (FlowspecRoute) this.insertedRoutes.get(0).getValue(); - assertEquals(ROUTE, route); + assertEquals(this.route, route); } @Test - public void testEmptyRoute() throws Exception { + public void testEmptyRoute() { final Routes empty = new FlowspecIpv6RoutesCaseBuilder().setFlowspecIpv6Routes( new FlowspecIpv6RoutesBuilder().setFlowspecRoute(Collections.emptyList()).build()).build(); - final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + final ChoiceNode emptyRoutes = this.ribSupport.emptyRoutes(); assertEquals(createRoutes(empty), emptyRoutes); } @Test public void testBuildMpUnreachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); + final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), + createRoutes(this.routes), ATTRIBUTES); assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class) .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes1.class)); @@ -120,68 +124,75 @@ public class FlowspecIpv6RIBSupportTest extends AbstractRIBSupportTest { @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()); + final Update update = this.ribSupport.buildUpdate(createRoutes(this.routes), + Collections.emptyList(), ATTRIBUTES); + assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri() + .getAdvertizedRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes2.class)); } @Test public void testCacheableNlriObjects() { - Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableNlriObjects()); } @Test public void testCacheableAttributeObjects() { - Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects()); } @Test public void testRouteIdAddPath() { - Assert.assertEquals(ROUTE_KEY, RIB_SUPPORT.createRouteListKey(1L, ROUTE_KEY.getRouteKey())); + assertEquals(this.routeKey, this.ribSupport.createRouteListKey(1L, this.routeKey.getRouteKey())); } @Test public void testRoutePath() { - final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES); - Assert.assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(this.routes); + assertEquals(getRoutePath().node(prefixNii), + this.ribSupport.routePath(getTablePath().node(Routes.QNAME), prefixNii)); } @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.rev180329.rib.tables.Attributes.QNAME.getLocalName().intern())), - RIB_SUPPORT.routeAttributesIdentifier()); + assertEquals(new NodeIdentifier(QName.create(FlowspecIpv6Routes.QNAME, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Attributes + .QNAME.getLocalName().intern())), + this.ribSupport.routeAttributesIdentifier()); } @Test public void testRoutesCaseClass() { - Assert.assertEquals(FlowspecIpv6RoutesCase.class, RIB_SUPPORT.routesCaseClass()); + assertEquals(FlowspecIpv6RoutesCase.class, this.ribSupport.routesCaseClass()); } @Test public void testRoutesContainerClass() { - Assert.assertEquals(FlowspecIpv6Routes.class, RIB_SUPPORT.routesContainerClass()); + assertEquals(FlowspecIpv6Routes.class, this.ribSupport.routesContainerClass()); } @Test public void testRoutesListClass() { - Assert.assertEquals(FlowspecRoute.class, RIB_SUPPORT.routesListClass()); + assertEquals(FlowspecRoute.class, this.ribSupport.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()); + DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), + createRoutes(emptyCase)).getRootNode(); + Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); - final Routes emptyRoutes = new FlowspecIpv6RoutesCaseBuilder().setFlowspecIpv6Routes(new FlowspecIpv6RoutesBuilder().build()).build(); + final Routes emptyRoutes = new FlowspecIpv6RoutesCaseBuilder() + .setFlowspecIpv6Routes(new FlowspecIpv6RoutesBuilder().build()).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); - Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); - final Routes routes = new FlowspecIpv6RoutesCaseBuilder().setFlowspecIpv6Routes(new FlowspecIpv6RoutesBuilder() - .setFlowspecRoute(Collections.singletonList(ROUTE)).build()).build(); + final Routes routes = new FlowspecIpv6RoutesCaseBuilder() + .setFlowspecIpv6Routes(new FlowspecIpv6RoutesBuilder() + .setFlowspecRoute(Collections.singletonList(this.route)).build()).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode(); - final Collection result = RIB_SUPPORT.changedRoutes(tree); + final Collection result = this.ribSupport.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/FlowspecL3vpnIpv4RIBSupportTest.java b/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecL3vpnIpv4RIBSupportTest.java index 7ac2539eb6..17f21666c7 100644 --- a/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecL3vpnIpv4RIBSupportTest.java +++ b/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecL3vpnIpv4RIBSupportTest.java @@ -45,33 +45,37 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.RouteDistinguisher; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; 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; 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 FlowspecL3vpnIpv4RIBSupportTest extends AbstractRIBSupportTest { +public class FlowspecL3vpnIpv4RIBSupportTest extends AbstractRIBSupportTest { - private static final FlowspecL3vpnIpv4RIBSupport RIB_SUPPORT; private static final FlowspecL3vpnRoute ROUTE; private static final FlowspecL3vpnRouteKey ROUTE_KEY; private static final PathId PATH_ID = new PathId(1L); private static final RouteDistinguisher RD = new RouteDistinguisher(new RdTwoOctetAs("0:5:3")); - private static final DestinationPrefixCase DEST_PREFIX = new DestinationPrefixCaseBuilder() - .setDestinationPrefix(new Ipv4Prefix("172.17.1.0/24")).build(); - private static final List FLOW_LIST = Collections.singletonList(new FlowspecBuilder().setFlowspecType(DEST_PREFIX).build()); - private static final DestinationFlowspecL3vpnIpv4 DEST_FLOW = new DestinationFlowspecL3vpnIpv4Builder().setRouteDistinguisher(RD) - .setFlowspec(FLOW_LIST).setPathId(PATH_ID).build(); - private static final DestinationFlowspecL3vpnIpv4Case REACH_NLRI = new DestinationFlowspecL3vpnIpv4CaseBuilder().setDestinationFlowspecL3vpnIpv4(DEST_FLOW).build(); - private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type. - DestinationFlowspecL3vpnIpv4Case UNREACH_NLRI = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type. - DestinationFlowspecL3vpnIpv4CaseBuilder().setDestinationFlowspecL3vpnIpv4(DEST_FLOW).build(); + .setDestinationPrefix(new Ipv4Prefix("172.17.1.0/24")).build(); + private static final List FLOW_LIST + = Collections.singletonList(new FlowspecBuilder().setFlowspecType(DEST_PREFIX).build()); + private static final DestinationFlowspecL3vpnIpv4 DEST_FLOW + = new DestinationFlowspecL3vpnIpv4Builder().setRouteDistinguisher(RD) + .setFlowspec(FLOW_LIST).setPathId(PATH_ID).build(); + private static final DestinationFlowspecL3vpnIpv4Case REACH_NLRI + = new DestinationFlowspecL3vpnIpv4CaseBuilder().setDestinationFlowspecL3vpnIpv4(DEST_FLOW).build(); + private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update + .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv4Case UNREACH_NLRI + = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update + .attributes.mp.unreach.nlri.withdrawn.routes.destination.type. + DestinationFlowspecL3vpnIpv4CaseBuilder().setDestinationFlowspecL3vpnIpv4(DEST_FLOW).build(); + private FlowspecL3vpnIpv4RIBSupport ribSupport; static { - final SimpleFlowspecExtensionProviderContext providerContext = new SimpleFlowspecExtensionProviderContext(); - RIB_SUPPORT = FlowspecL3vpnIpv4RIBSupport.getInstance(providerContext); - ROUTE_KEY = new FlowspecL3vpnRouteKey(PATH_ID, "[l3vpn with route-distinguisher 0:5:3] all packets to 172.17.1.0/24"); + ROUTE_KEY = new FlowspecL3vpnRouteKey(PATH_ID, + "[l3vpn with route-distinguisher 0:5:3] all packets to 172.17.1.0/24"); ROUTE = new FlowspecL3vpnRouteBuilder().setKey(ROUTE_KEY).setPathId(PATH_ID).setFlowspec(FLOW_LIST) .setAttributes(new AttributesBuilder().build()).setRouteDistinguisher(RD).build(); } @@ -79,19 +83,21 @@ public class FlowspecL3vpnIpv4RIBSupportTest extends AbstractRIBSupportTest { @Override public void setUp() throws Exception { super.setUp(); - setUpTestCustomizer(RIB_SUPPORT); + this.ribSupport = FlowspecL3vpnIpv4RIBSupport + .getInstance(new SimpleFlowspecExtensionProviderContext(), this.mappingService); + setUpTestCustomizer(this.ribSupport); } @Test public void testDeleteRoutes() { - RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); - final InstanceIdentifier instanceIdentifier = (InstanceIdentifier) this.deletedRoutes.get(0); + this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = this.deletedRoutes.get(0); assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(FlowspecL3vpnRoute.class)); } @Test public void testPutRoutes() { - RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); final FlowspecL3vpnRoute route = (FlowspecL3vpnRoute) this.insertedRoutes.get(0).getValue(); assertEquals(ROUTE, route); } @@ -100,13 +106,13 @@ public class FlowspecL3vpnIpv4RIBSupportTest extends AbstractRIBSupportTest { public void testEmptyRoute() throws Exception { final Routes empty = new FlowspecL3vpnIpv4RoutesCaseBuilder().setFlowspecL3vpnIpv4Routes( new FlowspecL3vpnIpv4RoutesBuilder().setFlowspecL3vpnRoute(Collections.emptyList()).build()).build(); - final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + final ChoiceNode emptyRoutes = this.ribSupport.emptyRoutes(); assertEquals(createRoutes(empty), emptyRoutes); } @Test public void testBuildMpUnreachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes( + final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), createRoutes( new FlowspecL3vpnIpv4RoutesBuilder().setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()), ATTRIBUTES); assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class) .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); @@ -115,7 +121,7 @@ public class FlowspecL3vpnIpv4RIBSupportTest extends AbstractRIBSupportTest { @Test public void testBuildMpReachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(createRoutes( + final Update update = this.ribSupport.buildUpdate(createRoutes( new FlowspecL3vpnIpv4RoutesBuilder().setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()), Collections.emptyList(), ATTRIBUTES); final AdvertizedRoutes advertised = update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri().getAdvertizedRoutes(); assertEquals(REACH_NLRI, advertised.getDestinationType()); @@ -124,61 +130,68 @@ public class FlowspecL3vpnIpv4RIBSupportTest extends AbstractRIBSupportTest { @Test public void testCacheableNlriObjects() { - Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableNlriObjects()); } @Test public void testCacheableAttributeObjects() { - Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects()); } @Test public void testRouteIdAddPath() { - Assert.assertEquals(ROUTE_KEY, RIB_SUPPORT.createRouteListKey(1L, ROUTE_KEY.getRouteKey())); + assertEquals(ROUTE_KEY, this.ribSupport.createRouteListKey(1L, ROUTE_KEY.getRouteKey())); } @Test public void testRoutePath() { - final YangInstanceIdentifier.NodeIdentifierWithPredicates prefixNii = createRouteNIWP(new FlowspecL3vpnIpv4RoutesBuilder().setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()); - Assert.assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + final NodeIdentifierWithPredicates prefixNii + = createRouteNIWP(new FlowspecL3vpnIpv4RoutesBuilder() + .setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()); + assertEquals(getRoutePath().node(prefixNii), + this.ribSupport.routePath(getTablePath().node(Routes.QNAME), prefixNii)); } @Test public void testRouteAttributesIdentifier() { - Assert.assertEquals(new YangInstanceIdentifier.NodeIdentifier(QName.create(FlowspecL3vpnIpv4Routes.QNAME, - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Attributes.QNAME.getLocalName().intern())), - RIB_SUPPORT.routeAttributesIdentifier()); + assertEquals(new NodeIdentifier(QName.create(FlowspecL3vpnIpv4Routes.QNAME, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables + .Attributes.QNAME.getLocalName().intern())), + this.ribSupport.routeAttributesIdentifier()); } @Test public void testRoutesCaseClass() { - Assert.assertEquals(FlowspecL3vpnIpv4RoutesCase.class, RIB_SUPPORT.routesCaseClass()); + assertEquals(FlowspecL3vpnIpv4RoutesCase.class, this.ribSupport.routesCaseClass()); } @Test public void testRoutesContainerClass() { - Assert.assertEquals(FlowspecL3vpnIpv4Routes.class, RIB_SUPPORT.routesContainerClass()); + assertEquals(FlowspecL3vpnIpv4Routes.class, this.ribSupport.routesContainerClass()); } @Test public void testRoutesListClass() { - Assert.assertEquals(FlowspecL3vpnRoute.class, RIB_SUPPORT.routesListClass()); + assertEquals(FlowspecL3vpnRoute.class, this.ribSupport.routesListClass()); } @Test public void testChangedRoutes() { final Routes emptyCase = new FlowspecL3vpnIpv4RoutesCaseBuilder().build(); - DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode(); - Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), + createRoutes(emptyCase)).getRootNode(); + Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); - final Routes emptyRoutes = new FlowspecL3vpnIpv4RoutesCaseBuilder().setFlowspecL3vpnIpv4Routes(new FlowspecL3vpnIpv4RoutesBuilder().build()).build(); + final Routes emptyRoutes = new FlowspecL3vpnIpv4RoutesCaseBuilder() + .setFlowspecL3vpnIpv4Routes(new FlowspecL3vpnIpv4RoutesBuilder().build()).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); - Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); - final Routes routes = new FlowspecL3vpnIpv4RoutesCaseBuilder().setFlowspecL3vpnIpv4Routes(new FlowspecL3vpnIpv4RoutesBuilder() + final Routes routes = new FlowspecL3vpnIpv4RoutesCaseBuilder() + .setFlowspecL3vpnIpv4Routes(new FlowspecL3vpnIpv4RoutesBuilder() .setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode(); - final Collection result = RIB_SUPPORT.changedRoutes(tree); + final Collection result = this.ribSupport.changedRoutes(tree); Assert.assertFalse(result.isEmpty()); } } diff --git a/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecL3vpnIpv6RIBSupportTest.java b/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecL3vpnIpv6RIBSupportTest.java index c5f1e1f102..c2da8610ff 100644 --- a/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecL3vpnIpv6RIBSupportTest.java +++ b/bgp/flowspec/src/test/java/org/opendaylight/protocol/bgp/flowspec/FlowspecL3vpnIpv6RIBSupportTest.java @@ -50,48 +50,54 @@ 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 FlowspecL3vpnIpv6RIBSupportTest extends AbstractRIBSupportTest { +public class FlowspecL3vpnIpv6RIBSupportTest extends AbstractRIBSupportTest { - private static final FlowspecL3vpnIpv6RIBSupport RIB_SUPPORT; private static final FlowspecL3vpnRoute ROUTE; private static final FlowspecL3vpnRouteKey ROUTE_KEY; private static final PathId PATH_ID = new PathId(1L); private static final RouteDistinguisher RD = new RouteDistinguisher(new RdTwoOctetAs("0:5:3")); - 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 static final DestinationFlowspecL3vpnIpv6 DEST_FLOW = new DestinationFlowspecL3vpnIpv6Builder().setRouteDistinguisher(RD) - .setFlowspec(FLOW_LIST).setPathId(PATH_ID).build(); - private static final DestinationFlowspecL3vpnIpv6Case REACH_NLRI = new DestinationFlowspecL3vpnIpv6CaseBuilder().setDestinationFlowspecL3vpnIpv6(DEST_FLOW).build(); - private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type. - DestinationFlowspecL3vpnIpv6Case UNREACH_NLRI = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type. - DestinationFlowspecL3vpnIpv6CaseBuilder().setDestinationFlowspecL3vpnIpv6(DEST_FLOW).build(); + .setDestinationPrefix(new Ipv6Prefix("2001:db8:1:2::/64")).build(); + private static final List FLOW_LIST + = Collections.singletonList(new FlowspecBuilder().setFlowspecType(DEST_PREFIX).build()); + private static final DestinationFlowspecL3vpnIpv6 DEST_FLOW + = new DestinationFlowspecL3vpnIpv6Builder().setRouteDistinguisher(RD) + .setFlowspec(FLOW_LIST).setPathId(PATH_ID).build(); + private static final DestinationFlowspecL3vpnIpv6Case REACH_NLRI + = new DestinationFlowspecL3vpnIpv6CaseBuilder().setDestinationFlowspecL3vpnIpv6(DEST_FLOW).build(); + private static final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update + .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv6Case UNREACH_NLRI + = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.update + .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationFlowspecL3vpnIpv6CaseBuilder() + .setDestinationFlowspecL3vpnIpv6(DEST_FLOW).build(); static { - final SimpleFlowspecExtensionProviderContext providerContext = new SimpleFlowspecExtensionProviderContext(); - RIB_SUPPORT = FlowspecL3vpnIpv6RIBSupport.getInstance(providerContext); - ROUTE_KEY = new FlowspecL3vpnRouteKey(PATH_ID, "[l3vpn with route-distinguisher 0:5:3] all packets to 2001:db8:1:2::/64"); + ROUTE_KEY = new FlowspecL3vpnRouteKey(PATH_ID, + "[l3vpn with route-distinguisher 0:5:3] all packets to 2001:db8:1:2::/64"); ROUTE = new FlowspecL3vpnRouteBuilder().setKey(ROUTE_KEY).setPathId(PATH_ID).setFlowspec(FLOW_LIST) - .setAttributes(new AttributesBuilder().build()).setRouteDistinguisher(RD).build(); + .setAttributes(new AttributesBuilder().build()).setRouteDistinguisher(RD).build(); } + private FlowspecL3vpnIpv6RIBSupport ribSupport; + @Override public void setUp() throws Exception { super.setUp(); - setUpTestCustomizer(RIB_SUPPORT); + this.ribSupport = FlowspecL3vpnIpv6RIBSupport + .getInstance(new SimpleFlowspecExtensionProviderContext(), this.mappingService); + setUpTestCustomizer(this.ribSupport); } @Test public void testDeleteRoutes() { - RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); - final InstanceIdentifier instanceIdentifier = (InstanceIdentifier) this.deletedRoutes.get(0); + this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = this.deletedRoutes.get(0); assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(FlowspecL3vpnRoute.class)); } @Test public void testPutRoutes() { - RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); final FlowspecL3vpnRoute route = (FlowspecL3vpnRoute) this.insertedRoutes.get(0).getValue(); assertEquals(ROUTE, route); } @@ -100,14 +106,15 @@ public class FlowspecL3vpnIpv6RIBSupportTest extends AbstractRIBSupportTest { public void testEmptyRoute() { final Routes empty = new FlowspecL3vpnIpv6RoutesCaseBuilder().setFlowspecL3vpnIpv6Routes( new FlowspecL3vpnIpv6RoutesBuilder().setFlowspecL3vpnRoute(Collections.emptyList()).build()).build(); - final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + final ChoiceNode emptyRoutes = this.ribSupport.emptyRoutes(); assertEquals(createRoutes(empty), emptyRoutes); } @Test public void testBuildMpUnreachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes( - new FlowspecL3vpnIpv6RoutesBuilder().setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()), ATTRIBUTES); + final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), createRoutes( + new FlowspecL3vpnIpv6RoutesBuilder() + .setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()), ATTRIBUTES); assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class) .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes1.class)); @@ -115,70 +122,79 @@ public class FlowspecL3vpnIpv6RIBSupportTest extends AbstractRIBSupportTest { @Test public void testBuildMpReachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(createRoutes( - new FlowspecL3vpnIpv6RoutesBuilder().setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()), Collections.emptyList(), ATTRIBUTES); - final AdvertizedRoutes advertised = update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri().getAdvertizedRoutes(); + final Update update = this.ribSupport.buildUpdate(createRoutes( + new FlowspecL3vpnIpv6RoutesBuilder().setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()), + Collections.emptyList(), ATTRIBUTES); + final AdvertizedRoutes advertised + = update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri().getAdvertizedRoutes(); assertEquals(REACH_NLRI, advertised.getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes2.class)); } @Test public void testCacheableNlriObjects() { - Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + Assert.assertEquals(ImmutableSet.of(), this.ribSupport.cacheableNlriObjects()); } @Test public void testCacheableAttributeObjects() { - Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + Assert.assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects()); } @Test public void testRouteIdAddPath() { - Assert.assertEquals(ROUTE_KEY, RIB_SUPPORT.createRouteListKey(1L, ROUTE_KEY.getRouteKey())); + Assert.assertEquals(ROUTE_KEY, this.ribSupport.createRouteListKey(1L, ROUTE_KEY.getRouteKey())); } @Test public void testRoutePath() { - final YangInstanceIdentifier.NodeIdentifierWithPredicates prefixNii = createRouteNIWP(new FlowspecL3vpnIpv6RoutesBuilder().setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()); - Assert.assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + final YangInstanceIdentifier.NodeIdentifierWithPredicates prefixNii + = createRouteNIWP(new FlowspecL3vpnIpv6RoutesBuilder() + .setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()); + Assert.assertEquals(getRoutePath().node(prefixNii), + this.ribSupport.routePath(getTablePath().node(Routes.QNAME), prefixNii)); } @Test public void testRouteAttributesIdentifier() { Assert.assertEquals(new YangInstanceIdentifier.NodeIdentifier(QName.create(FlowspecL3vpnIpv6Routes.QNAME, - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Attributes.QNAME.getLocalName().intern())), - RIB_SUPPORT.routeAttributesIdentifier()); + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables + .Attributes.QNAME.getLocalName().intern())), + this.ribSupport.routeAttributesIdentifier()); } @Test public void testRoutesCaseClass() { - Assert.assertEquals(FlowspecL3vpnIpv6RoutesCase.class, RIB_SUPPORT.routesCaseClass()); + Assert.assertEquals(FlowspecL3vpnIpv6RoutesCase.class, this.ribSupport.routesCaseClass()); } @Test public void testRoutesContainerClass() { - Assert.assertEquals(FlowspecL3vpnIpv6Routes.class, RIB_SUPPORT.routesContainerClass()); + Assert.assertEquals(FlowspecL3vpnIpv6Routes.class, this.ribSupport.routesContainerClass()); } @Test public void testRoutesListClass() { - Assert.assertEquals(FlowspecL3vpnRoute.class, RIB_SUPPORT.routesListClass()); + Assert.assertEquals(FlowspecL3vpnRoute.class, this.ribSupport.routesListClass()); } @Test public void testChangedRoutes() { final Routes emptyCase = new FlowspecL3vpnIpv6RoutesCaseBuilder().build(); - DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode(); - Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), + createRoutes(emptyCase)).getRootNode(); + Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); - final Routes emptyRoutes = new FlowspecL3vpnIpv6RoutesCaseBuilder().setFlowspecL3vpnIpv6Routes(new FlowspecL3vpnIpv6RoutesBuilder().build()).build(); + final Routes emptyRoutes = new FlowspecL3vpnIpv6RoutesCaseBuilder() + .setFlowspecL3vpnIpv6Routes(new FlowspecL3vpnIpv6RoutesBuilder().build()).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); - Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); - final Routes routes = new FlowspecL3vpnIpv6RoutesCaseBuilder().setFlowspecL3vpnIpv6Routes(new FlowspecL3vpnIpv6RoutesBuilder() - .setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()).build(); + final Routes routes = new FlowspecL3vpnIpv6RoutesCaseBuilder() + .setFlowspecL3vpnIpv6Routes(new FlowspecL3vpnIpv6RoutesBuilder() + .setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode(); - final Collection result = RIB_SUPPORT.changedRoutes(tree); + final Collection result = this.ribSupport.changedRoutes(tree); Assert.assertFalse(result.isEmpty()); } } \ No newline at end of file diff --git a/bgp/inet/pom.xml b/bgp/inet/pom.xml index 476dec6abb..e27bb43689 100644 --- a/bgp/inet/pom.xml +++ b/bgp/inet/pom.xml @@ -101,6 +101,17 @@ bgp-parser-impl test + + org.opendaylight.controller + sal-binding-broker-impl + test + + + org.opendaylight.controller + sal-binding-broker-impl + test + test-jar + diff --git a/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/AbstractIPRibSupport.java b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/AbstractIPRibSupport.java index d39c6727c9..a976e2f9f7 100644 --- a/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/AbstractIPRibSupport.java +++ b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/AbstractIPRibSupport.java @@ -12,6 +12,7 @@ import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableSet; import java.util.Optional; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil; import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupport; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route; @@ -35,19 +36,26 @@ import org.slf4j.LoggerFactory; /** * Common {@link org.opendaylight.protocol.bgp.rib.spi.RIBSupport} class for IPv4 and IPv6 addresses. */ -abstract class AbstractIPRibSupport - extends AbstractRIBSupport { +abstract class AbstractIPRibSupport< + C extends Routes & DataObject, + S extends DataObject, + R extends Route, + N extends Identifier> + extends AbstractRIBSupport { private static final Logger LOG = LoggerFactory.getLogger(AbstractIPRibSupport.class); private final NodeIdentifier prefixNid; private final NodeIdentifier nlriRoutesList; private final ImmutableCollection> cacheableNlriObjects; - AbstractIPRibSupport(final Class prefixClass, + AbstractIPRibSupport( + final BindingNormalizedNodeSerializer mappingService, + final Class prefixClass, final Class addressFamilyClass, - final Class cazeClass, - final Class containerClass, final Class listClass, + final Class cazeClass, + final Class containerClass, + final Class listClass, final QName destinationQname, final QName prefixesQname) { - super(cazeClass, containerClass, listClass, addressFamilyClass, + super(mappingService, cazeClass, containerClass, listClass, addressFamilyClass, UnicastSubsequentAddressFamily.class, destinationQname); this.nlriRoutesList = new NodeIdentifier(prefixesQname); this.cacheableNlriObjects = ImmutableSet.of(prefixClass); diff --git a/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/IPv4RIBSupport.java b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/IPv4RIBSupport.java index eea9ca9c42..d350c864a9 100644 --- a/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/IPv4RIBSupport.java +++ b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/IPv4RIBSupport.java @@ -9,11 +9,13 @@ package org.opendaylight.protocol.bgp.inet; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.bgp.rib.rib.loc.rib.tables.routes.Ipv4RoutesCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.bgp.rib.rib.peer.effective.rib.in.tables.routes.Ipv4RoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.bgp.rib.rib.loc.rib.tables.routes.Ipv4RoutesCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.DestinationIpv4; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.DestinationIpv4Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.destination.ipv4.Ipv4Prefixes; @@ -28,7 +30,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes; @@ -36,16 +37,29 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes; /** * Class supporting IPv4 unicast RIBs. */ -final class IPv4RIBSupport extends AbstractIPRibSupport { +final class IPv4RIBSupport extends AbstractIPRibSupport { - private static final IPv4RIBSupport SINGLETON = new IPv4RIBSupport(); + private static final Ipv4Routes EMPTY_CONTAINER + = new Ipv4RoutesBuilder().setIpv4Route(Collections.emptyList()).build(); + private static final Ipv4RoutesCase EMPTY_CASE = new Ipv4RoutesCaseBuilder().setIpv4Routes(EMPTY_CONTAINER).build(); + private static IPv4RIBSupport SINGLETON = null; - private IPv4RIBSupport() { - super(Ipv4PrefixAndPathId.class, Ipv4AddressFamily.class, - Ipv4RoutesCase.class, Ipv4Routes.class, Ipv4Route.class, DestinationIpv4.QNAME, Ipv4Prefixes.QNAME); + private IPv4RIBSupport(final BindingNormalizedNodeSerializer mappingService) { + super( + mappingService, + Ipv4PrefixAndPathId.class, + Ipv4AddressFamily.class, + Ipv4RoutesCase.class, + Ipv4Routes.class, + Ipv4Route.class, + DestinationIpv4.QNAME, + Ipv4Prefixes.QNAME); } - static IPv4RIBSupport getInstance() { + static synchronized IPv4RIBSupport getInstance(final BindingNormalizedNodeSerializer mappingService) { + if (SINGLETON == null) { + SINGLETON = new IPv4RIBSupport(mappingService); + } return SINGLETON; } @@ -83,13 +97,18 @@ final class IPv4RIBSupport extends AbstractIPRibSupport } else { builder = new Ipv4RouteBuilder(); } - builder.setKey(new Ipv4RouteKey(new PathId(pathId), routeKey)).setAttributes(attributes); + builder.setKey(createRouteListKey(pathId, routeKey)).setAttributes(attributes); return builder.build(); } @Override - public Routes emptyRoutesContainer() { - return new Ipv4RoutesCaseBuilder().setIpv4Routes(new Ipv4RoutesBuilder().build()).build(); + public Ipv4RoutesCase emptyRoutesCase() { + return EMPTY_CASE; + } + + @Override + public Ipv4Routes emptyRoutesContainer() { + return EMPTY_CONTAINER; } @Override diff --git a/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/IPv6RIBSupport.java b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/IPv6RIBSupport.java index adb499a92b..15559f05e4 100644 --- a/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/IPv6RIBSupport.java +++ b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/IPv6RIBSupport.java @@ -9,11 +9,13 @@ package org.opendaylight.protocol.bgp.inet; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.bgp.rib.rib.loc.rib.tables.routes.Ipv6RoutesCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.bgp.rib.rib.peer.effective.rib.in.tables.routes.Ipv6RoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.bgp.rib.rib.loc.rib.tables.routes.Ipv6RoutesCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.prefixes.DestinationIpv6; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.prefixes.DestinationIpv6Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv6.prefixes.destination.ipv6.Ipv6Prefixes; @@ -27,7 +29,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes; @@ -35,17 +36,28 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes; /** * Class supporting IPv6 unicast RIBs. */ -final class IPv6RIBSupport extends AbstractIPRibSupport { +final class IPv6RIBSupport extends AbstractIPRibSupport { - private static final IPv6RIBSupport SINGLETON = new IPv6RIBSupport(); + private static final Ipv6Routes EMPTY_CONTAINER + = new Ipv6RoutesBuilder().setIpv6Route(Collections.emptyList()).build(); + private static final Ipv6RoutesCase EMPTY_CASE = new Ipv6RoutesCaseBuilder().setIpv6Routes(EMPTY_CONTAINER).build(); + private static IPv6RIBSupport SINGLETON; - private IPv6RIBSupport() { - super(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.Ipv6Prefix.class, - Ipv6AddressFamily.class, Ipv6RoutesCase.class, Ipv6Routes.class, Ipv6Route.class, - DestinationIpv6.QNAME, Ipv6Prefixes.QNAME); + private IPv6RIBSupport(final BindingNormalizedNodeSerializer mappingService) { + super(mappingService, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.Ipv6Prefix.class, + Ipv6AddressFamily.class, + Ipv6RoutesCase.class, + Ipv6Routes.class, + Ipv6Route.class, + DestinationIpv6.QNAME, + Ipv6Prefixes.QNAME); } - static IPv6RIBSupport getInstance() { + static synchronized IPv6RIBSupport getInstance(final BindingNormalizedNodeSerializer mappingService) { + if (SINGLETON == null) { + SINGLETON = new IPv6RIBSupport(mappingService); + } return SINGLETON; } @@ -86,8 +98,13 @@ final class IPv6RIBSupport extends AbstractIPRibSupport } @Override - public Routes emptyRoutesContainer() { - return new Ipv6RoutesCaseBuilder().setIpv6Routes(new Ipv6RoutesBuilder().build()).build(); + public Ipv6RoutesCase emptyRoutesCase() { + return EMPTY_CASE; + } + + @Override + public Ipv6Routes emptyRoutesContainer() { + return EMPTY_CONTAINER; } @Override diff --git a/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/RIBActivator.java b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/RIBActivator.java index 1cfa29e4dc..66672b3d8a 100644 --- a/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/RIBActivator.java +++ b/bgp/inet/src/main/java/org/opendaylight/protocol/bgp/inet/RIBActivator.java @@ -9,6 +9,7 @@ package org.opendaylight.protocol.bgp.inet; import com.google.common.collect.Lists; import java.util.List; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBExtensionProviderActivator; import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily; @@ -18,11 +19,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type public final class RIBActivator extends AbstractRIBExtensionProviderActivator { @Override - protected List startRIBExtensionProviderImpl(final RIBExtensionProviderContext context) { + protected List startRIBExtensionProviderImpl( + final RIBExtensionProviderContext context, + final BindingNormalizedNodeSerializer mappingService) { return Lists.newArrayList( context.registerRIBSupport(Ipv4AddressFamily.class, - UnicastSubsequentAddressFamily.class, IPv4RIBSupport.getInstance()), + UnicastSubsequentAddressFamily.class, IPv4RIBSupport.getInstance(mappingService)), context.registerRIBSupport(Ipv6AddressFamily.class, - UnicastSubsequentAddressFamily.class, IPv6RIBSupport.getInstance())); + UnicastSubsequentAddressFamily.class, IPv6RIBSupport.getInstance(mappingService))); } } diff --git a/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/IPv4RIBSupportTest.java b/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/IPv4RIBSupportTest.java index 9356075d47..87d7d07594 100644 --- a/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/IPv4RIBSupportTest.java +++ b/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/IPv4RIBSupportTest.java @@ -46,8 +46,8 @@ 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 IPv4RIBSupportTest extends AbstractRIBSupportTest { - private static final IPv4RIBSupport RIB_SUPPORT = IPv4RIBSupport.getInstance(); +public final class IPv4RIBSupportTest extends AbstractRIBSupportTest { + private IPv4RIBSupport ribSupport; private static final PathId PATH_ID = new PathId(1L); private static final Ipv4Prefix PREFIX = new Ipv4Prefix("1.2.3.4/32"); private static final Ipv4RouteKey ROUTE_KEY = new Ipv4RouteKey(PATH_ID, PREFIX.getValue()); @@ -77,20 +77,20 @@ public final class IPv4RIBSupportTest extends AbstractRIBSupportTest { @Override public void setUp() throws Exception { super.setUp(); - setUpTestCustomizer(RIB_SUPPORT); + this.ribSupport = IPv4RIBSupport.getInstance(this.mappingService); + setUpTestCustomizer(this.ribSupport); } @Test public void testDeleteRoutes() { - RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); - @SuppressWarnings("unchecked") final InstanceIdentifier instanceIdentifier = - (InstanceIdentifier) this.deletedRoutes.get(0); + this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = this.deletedRoutes.get(0); assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(Ipv4Route.class)); } @Test public void testPutRoutes() { - RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); final Ipv4Route route = (Ipv4Route) this.insertedRoutes.get(0).getValue(); assertEquals(ROUTE, route); } @@ -99,13 +99,13 @@ public final class IPv4RIBSupportTest extends AbstractRIBSupportTest { @Test public void testEmptyRoute() { final Routes empty = new Ipv4RoutesCaseBuilder().setIpv4Routes(EMPTY_ROUTES).build(); - final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + final ChoiceNode emptyRoutes = this.ribSupport.emptyRoutes(); assertEquals(createRoutes(empty), emptyRoutes); } @Test public void testBuildMpUnreachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); + final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class).getMpUnreachNlri() .getWithdrawnRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes1.class)); @@ -113,7 +113,7 @@ public final class IPv4RIBSupportTest extends AbstractRIBSupportTest { @Test public void testBuildMpReachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES); + final Update update = this.ribSupport.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES); assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri() .getAdvertizedRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes2.class)); @@ -122,46 +122,46 @@ public final class IPv4RIBSupportTest extends AbstractRIBSupportTest { @Test public void testCacheableNlriObjects() { assertEquals(ImmutableSet.of(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp - .message.rev180329.Ipv4PrefixAndPathId.class), RIB_SUPPORT.cacheableNlriObjects()); + .message.rev180329.Ipv4PrefixAndPathId.class), this.ribSupport.cacheableNlriObjects()); } @Test public void testCacheableAttributeObjects() { - assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects()); } @Test public void testRouteIdAddPath() { final Ipv4RouteKey expected = new Ipv4RouteKey(new PathId(1L), PREFIX.getValue()); - assertEquals(expected, RIB_SUPPORT.createRouteListKey(expected.getPathId().getValue(), PREFIX.getValue())); + assertEquals(expected, this.ribSupport.createRouteListKey(expected.getPathId().getValue(), PREFIX.getValue())); } @Test public void testRoutePath() { final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES); - assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath() + assertEquals(getRoutePath().node(prefixNii), this.ribSupport.routePath(getTablePath() .node(Routes.QNAME), prefixNii)); } @Test public void testRouteAttributesIdentifier() { assertEquals(new NodeIdentifier(QName.create(Ipv4Routes.QNAME, Attributes.QNAME.getLocalName().intern())), - RIB_SUPPORT.routeAttributesIdentifier()); + this.ribSupport.routeAttributesIdentifier()); } @Test public void testRoutesCaseClass() { - assertEquals(Ipv4RoutesCase.class, RIB_SUPPORT.routesCaseClass()); + assertEquals(Ipv4RoutesCase.class, this.ribSupport.routesCaseClass()); } @Test public void testRoutesContainerClass() { - assertEquals(Ipv4Routes.class, RIB_SUPPORT.routesContainerClass()); + assertEquals(Ipv4Routes.class, this.ribSupport.routesContainerClass()); } @Test public void testRoutesListClass() { - assertEquals(Ipv4Route.class, RIB_SUPPORT.routesListClass()); + assertEquals(Ipv4Route.class, this.ribSupport.routesListClass()); } @Test @@ -169,15 +169,15 @@ public final class IPv4RIBSupportTest extends AbstractRIBSupportTest { final Routes emptyCase = new Ipv4RoutesCaseBuilder().build(); DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode(); - assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); final Routes emptyRoutes = new Ipv4RoutesCaseBuilder().setIpv4Routes(new Ipv4RoutesBuilder().build()).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); - assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); final Routes routes = new Ipv4RoutesCaseBuilder().setIpv4Routes(ROUTES).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode(); - final Collection result = RIB_SUPPORT.changedRoutes(tree); + final Collection result = this.ribSupport.changedRoutes(tree); Assert.assertFalse(result.isEmpty()); } } diff --git a/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/IPv6RIBSupportTest.java b/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/IPv6RIBSupportTest.java index 64bc2431aa..9db3fcb146 100644 --- a/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/IPv6RIBSupportTest.java +++ b/bgp/inet/src/test/java/org/opendaylight/protocol/bgp/inet/IPv6RIBSupportTest.java @@ -45,8 +45,8 @@ 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 IPv6RIBSupportTest extends AbstractRIBSupportTest { - private static final IPv6RIBSupport RIB_SUPPORT = IPv6RIBSupport.getInstance(); +public final class IPv6RIBSupportTest extends AbstractRIBSupportTest { + private IPv6RIBSupport ribSupport; private static final PathId PATH_ID = new PathId(1L); private static final Ipv6Prefix PREFIX = new Ipv6Prefix("2001:db8:1:2::/64"); private static final Ipv6RouteKey ROUTE_KEY = new Ipv6RouteKey(PATH_ID, PREFIX.getValue()); @@ -76,20 +76,21 @@ public final class IPv6RIBSupportTest extends AbstractRIBSupportTest { @Override public void setUp() throws Exception { super.setUp(); - setUpTestCustomizer(RIB_SUPPORT); + this.ribSupport = IPv6RIBSupport.getInstance(this.mappingService); + setUpTestCustomizer(this.ribSupport); } @Test public void testDeleteRoutes() { - RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); - @SuppressWarnings("unchecked") final InstanceIdentifier instanceIdentifier = - (InstanceIdentifier) this.deletedRoutes.get(0); + this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = + this.deletedRoutes.get(0); assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(Ipv6Route.class)); } @Test public void testPutRoutes() { - RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); final Ipv6Route route = (Ipv6Route) this.insertedRoutes.get(0).getValue(); assertEquals(ROUTE, route); } @@ -98,13 +99,13 @@ public final class IPv6RIBSupportTest extends AbstractRIBSupportTest { @Test public void testEmptyRoute() { final Routes empty = new Ipv6RoutesCaseBuilder().setIpv6Routes(EMPTY_ROUTES).build(); - final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + final ChoiceNode emptyRoutes = this.ribSupport.emptyRoutes(); assertEquals(createRoutes(empty), emptyRoutes); } @Test public void testBuildMpUnreachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); + final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class) .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes1.class)); @@ -112,7 +113,7 @@ public final class IPv6RIBSupportTest extends AbstractRIBSupportTest { @Test public void testBuildMpReachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES); + final Update update = this.ribSupport.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES); assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class) .getMpReachNlri().getAdvertizedRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes2.class)); @@ -121,46 +122,46 @@ public final class IPv6RIBSupportTest extends AbstractRIBSupportTest { @Test public void testCacheableNlriObjects() { assertEquals(ImmutableSet.of(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet - .rev180329.Ipv6Prefix.class), RIB_SUPPORT.cacheableNlriObjects()); + .rev180329.Ipv6Prefix.class), this.ribSupport.cacheableNlriObjects()); } @Test public void testCacheableAttributeObjects() { - assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects()); } @Test public void testRouteIdAddPath() { final Ipv6RouteKey expected = new Ipv6RouteKey(new PathId(1L), PREFIX.getValue()); - assertEquals(expected, RIB_SUPPORT.createRouteListKey(expected.getPathId().getValue(), PREFIX.getValue())); + assertEquals(expected, this.ribSupport.createRouteListKey(expected.getPathId().getValue(), PREFIX.getValue())); } @Test public void testRoutePath() { final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES); assertEquals(getRoutePath().node(prefixNii), - RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + this.ribSupport.routePath(getTablePath().node(Routes.QNAME), prefixNii)); } @Test public void testRouteAttributesIdentifier() { assertEquals(new NodeIdentifier(QName.create(Ipv6Routes.QNAME, - Attributes.QNAME.getLocalName().intern())), RIB_SUPPORT.routeAttributesIdentifier()); + Attributes.QNAME.getLocalName().intern())), this.ribSupport.routeAttributesIdentifier()); } @Test public void testRoutesCaseClass() { - assertEquals(Ipv6RoutesCase.class, RIB_SUPPORT.routesCaseClass()); + assertEquals(Ipv6RoutesCase.class, this.ribSupport.routesCaseClass()); } @Test public void testRoutesContainerClass() { - assertEquals(Ipv6Routes.class, RIB_SUPPORT.routesContainerClass()); + assertEquals(Ipv6Routes.class, this.ribSupport.routesContainerClass()); } @Test public void testRoutesListClass() { - assertEquals(Ipv6Route.class, RIB_SUPPORT.routesListClass()); + assertEquals(Ipv6Route.class, this.ribSupport.routesListClass()); } @Test @@ -168,15 +169,15 @@ public final class IPv6RIBSupportTest extends AbstractRIBSupportTest { final Routes emptyCase = new Ipv6RoutesCaseBuilder().build(); DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode(); - Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); final Routes emptyRoutes = new Ipv6RoutesCaseBuilder().setIpv6Routes(new Ipv6RoutesBuilder().build()).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); - Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); final Routes routes = new Ipv6RoutesCaseBuilder().setIpv6Routes(ROUTES).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode(); - final Collection result = RIB_SUPPORT.changedRoutes(tree); + final Collection result = this.ribSupport.changedRoutes(tree); Assert.assertFalse(result.isEmpty()); } } diff --git a/bgp/l3vpn/pom.xml b/bgp/l3vpn/pom.xml index 6630cab5ea..240533af46 100644 --- a/bgp/l3vpn/pom.xml +++ b/bgp/l3vpn/pom.xml @@ -100,6 +100,17 @@ mdsal-binding-dom-adapter test + + org.opendaylight.controller + sal-binding-broker-impl + test + + + org.opendaylight.controller + sal-binding-broker-impl + test + test-jar + diff --git a/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/AbstractVpnRIBSupport.java b/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/AbstractVpnRIBSupport.java index 39e7b0796e..fa7b981b29 100644 --- a/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/AbstractVpnRIBSupport.java +++ b/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/AbstractVpnRIBSupport.java @@ -17,6 +17,7 @@ import java.util.Optional; import java.util.stream.Collectors; import org.opendaylight.bgp.concepts.RouteDistinguisherUtil; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.labeled.unicast.LUNlriParser; import org.opendaylight.protocol.bgp.labeled.unicast.LabeledUnicastIpv4RIBSupport; import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil; @@ -26,7 +27,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.AddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.MplsLabeledVpnSubsequentAddressFamily; @@ -51,7 +51,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public abstract class AbstractVpnRIBSupport extends AbstractRIBSupport { +public abstract class AbstractVpnRIBSupport + extends AbstractRIBSupport { private static final Logger LOG = LoggerFactory.getLogger(AbstractVpnRIBSupport.class); private final NodeIdentifier nlriRoutesListNid; private final NodeIdentifier labelStackNid; @@ -65,12 +66,14 @@ public abstract class AbstractVpnRIBSupport extends AbstractRIBSupport cazeClass, - final Class containerClass, final Class listClass, - final Class afiClass, final QName vpnDstContainerClassQname) { - super(cazeClass, containerClass, listClass, afiClass, + protected AbstractVpnRIBSupport( + final BindingNormalizedNodeSerializer mappingService, + final Class cazeClass, + final Class containerClass, + final Class afiClass, + final QName vpnDstContainerClassQname) { + super(mappingService, cazeClass, containerClass, VpnRoute.class, afiClass, MplsLabeledVpnSubsequentAddressFamily.class, vpnDstContainerClassQname); final QName classQname = BindingReflections.findQName(containerClass).intern(); final QName vpnDstClassQname = QName.create(classQname, VpnDestination.QNAME.getLocalName()); diff --git a/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/RibIpv4Activator.java b/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/RibIpv4Activator.java index 34b28747ad..2e4fa0a5cc 100644 --- a/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/RibIpv4Activator.java +++ b/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/RibIpv4Activator.java @@ -7,8 +7,9 @@ */ package org.opendaylight.protocol.bgp.l3vpn.ipv4; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBExtensionProviderActivator; import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily; @@ -17,11 +18,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type public class RibIpv4Activator extends AbstractRIBExtensionProviderActivator { @Override - protected List startRIBExtensionProviderImpl(final RIBExtensionProviderContext context) { - final List regs = new ArrayList<>(); - regs.add(context.registerRIBSupport(Ipv4AddressFamily.class, - MplsLabeledVpnSubsequentAddressFamily.class, new VpnIpv4RIBSupport())); - return regs; + protected List startRIBExtensionProviderImpl( + final RIBExtensionProviderContext context, + final BindingNormalizedNodeSerializer mappingService) { + + return Collections.singletonList(context.registerRIBSupport(Ipv4AddressFamily.class, + MplsLabeledVpnSubsequentAddressFamily.class, VpnIpv4RIBSupport.getInstance(mappingService))); } } diff --git a/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/VpnIpv4RIBSupport.java b/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/VpnIpv4RIBSupport.java index e5457458e9..7783fb73e1 100644 --- a/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/VpnIpv4RIBSupport.java +++ b/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/ipv4/VpnIpv4RIBSupport.java @@ -7,32 +7,48 @@ */ package org.opendaylight.protocol.bgp.l3vpn.ipv4; +import java.util.Collections; import java.util.List; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.l3vpn.AbstractVpnRIBSupport; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev180329.bgp.rib.rib.loc.rib.tables.routes.VpnIpv4RoutesCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev180329.bgp.rib.rib.peer.effective.rib.in.tables.routes.VpnIpv4RoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev180329.bgp.rib.rib.loc.rib.tables.routes.VpnIpv4RoutesCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev180329.l3vpn.ipv4.destination.VpnIpv4Destination; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev180329.l3vpn.ipv4.destination.VpnIpv4DestinationBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev180329.l3vpn.ipv4.routes.VpnIpv4Routes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev180329.l3vpn.ipv4.routes.VpnIpv4RoutesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev180329.l3vpn.ip.destination.type.VpnDestination; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev180329.l3vpn.ip.route.VpnRoute; -final class VpnIpv4RIBSupport extends AbstractVpnRIBSupport { +final class VpnIpv4RIBSupport extends AbstractVpnRIBSupport { + private static final VpnIpv4Routes EMPTY_CONTAINER + = new VpnIpv4RoutesBuilder().setVpnRoute(Collections.emptyList()).build(); + private static final VpnIpv4RoutesCase EMPTY_CASE + = new VpnIpv4RoutesCaseBuilder().setVpnIpv4Routes(EMPTY_CONTAINER).build(); + private static VpnIpv4RIBSupport SINGLETON; + /** * Default constructor. Requires the QName of the container augmented under the routes choice * node in instantiations of the rib grouping. It is assumed that this container is defined by * the same model which populates it with route grouping instantiation, and by extension with * the route attributes container. */ - VpnIpv4RIBSupport() { - super(VpnIpv4RoutesCase.class, VpnIpv4Routes.class, VpnRoute.class, - Ipv4AddressFamily.class, VpnIpv4Destination.QNAME); + private VpnIpv4RIBSupport(final BindingNormalizedNodeSerializer mappingService) { + super(mappingService, + VpnIpv4RoutesCase.class, + VpnIpv4Routes.class, + Ipv4AddressFamily.class, + VpnIpv4Destination.QNAME); + } + + public static synchronized VpnIpv4RIBSupport getInstance(final BindingNormalizedNodeSerializer mappingService) { + if (SINGLETON == null) { + SINGLETON = new VpnIpv4RIBSupport(mappingService); + } + return SINGLETON; } @Override @@ -55,7 +71,12 @@ final class VpnIpv4RIBSupport extends AbstractVpnRIBSupport { } @Override - public Routes emptyRoutesContainer() { - return new VpnIpv4RoutesCaseBuilder().setVpnIpv4Routes(new VpnIpv4RoutesBuilder().build()).build(); + public VpnIpv4RoutesCase emptyRoutesCase() { + return EMPTY_CASE; + } + + @Override + public VpnIpv4Routes emptyRoutesContainer() { + return EMPTY_CONTAINER; } } diff --git a/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/RibIpv6Activator.java b/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/RibIpv6Activator.java index 9bdb6c3e1f..e74f119fec 100644 --- a/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/RibIpv6Activator.java +++ b/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/RibIpv6Activator.java @@ -7,8 +7,9 @@ */ package org.opendaylight.protocol.bgp.l3vpn.ipv6; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBExtensionProviderActivator; import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily; @@ -17,11 +18,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type public class RibIpv6Activator extends AbstractRIBExtensionProviderActivator { @Override - protected List startRIBExtensionProviderImpl(final RIBExtensionProviderContext context) { - final List regs = new ArrayList<>(); - regs.add(context.registerRIBSupport(Ipv6AddressFamily.class, - MplsLabeledVpnSubsequentAddressFamily.class, new VpnIpv6RIBSupport())); - return regs; + protected List startRIBExtensionProviderImpl( + final RIBExtensionProviderContext context, + final BindingNormalizedNodeSerializer mappingService) { + return Collections.singletonList((context.registerRIBSupport(Ipv6AddressFamily.class, + MplsLabeledVpnSubsequentAddressFamily.class, VpnIpv6RIBSupport.getInstance(mappingService)))); } - } diff --git a/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/VpnIpv6RIBSupport.java b/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/VpnIpv6RIBSupport.java index 22000bcded..a5db5d5e54 100644 --- a/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/VpnIpv6RIBSupport.java +++ b/bgp/l3vpn/src/main/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/VpnIpv6RIBSupport.java @@ -7,23 +7,28 @@ */ package org.opendaylight.protocol.bgp.l3vpn.ipv6; +import java.util.Collections; import java.util.List; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.l3vpn.AbstractVpnRIBSupport; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.bgp.rib.rib.loc.rib.tables.routes.VpnIpv6RoutesCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.bgp.rib.rib.peer.effective.rib.in.tables.routes.VpnIpv6RoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.bgp.rib.rib.loc.rib.tables.routes.VpnIpv6RoutesCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.l3vpn.ipv6.destination.VpnIpv6Destination; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.l3vpn.ipv6.destination.VpnIpv6DestinationBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.l3vpn.ipv6.routes.VpnIpv6Routes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev180329.l3vpn.ipv6.routes.VpnIpv6RoutesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev180329.l3vpn.ip.destination.type.VpnDestination; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.rev180329.l3vpn.ip.route.VpnRoute; -final class VpnIpv6RIBSupport extends AbstractVpnRIBSupport { +final class VpnIpv6RIBSupport extends AbstractVpnRIBSupport { + private static final VpnIpv6Routes EMPTY_CONTAINER + = new VpnIpv6RoutesBuilder().setVpnRoute(Collections.emptyList()).build(); + private static final VpnIpv6RoutesCase EMPTY_CASE + = new VpnIpv6RoutesCaseBuilder().setVpnIpv6Routes(EMPTY_CONTAINER).build(); + private static VpnIpv6RIBSupport SINGLETON; /** * Default constructor. Requires the QName of the container augmented under the routes choice @@ -31,9 +36,19 @@ final class VpnIpv6RIBSupport extends AbstractVpnRIBSupport { * the same model which populates it with route grouping instantiation, and by extension with * the route attributes container. */ - VpnIpv6RIBSupport() { - super(VpnIpv6RoutesCase.class, VpnIpv6Routes.class, VpnRoute.class, - Ipv6AddressFamily.class, VpnIpv6Destination.QNAME); + private VpnIpv6RIBSupport(final BindingNormalizedNodeSerializer mappingService) { + super(mappingService, + VpnIpv6RoutesCase.class, + VpnIpv6Routes.class, + Ipv6AddressFamily.class, + VpnIpv6Destination.QNAME); + } + + public static synchronized VpnIpv6RIBSupport getInstance(final BindingNormalizedNodeSerializer mappingService) { + if (SINGLETON == null) { + SINGLETON = new VpnIpv6RIBSupport(mappingService); + } + return SINGLETON; } @Override @@ -56,7 +71,12 @@ final class VpnIpv6RIBSupport extends AbstractVpnRIBSupport { } @Override - public Routes emptyRoutesContainer() { - return new VpnIpv6RoutesCaseBuilder().setVpnIpv6Routes(new VpnIpv6RoutesBuilder().build()).build(); + public VpnIpv6RoutesCase emptyRoutesCase() { + return EMPTY_CASE; + } + + @Override + public VpnIpv6Routes emptyRoutesContainer() { + return EMPTY_CONTAINER; } } 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 index 018b33ab26..6d84d4a2ad 100644 --- 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 @@ -47,8 +47,8 @@ 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(); +public class VpnIpv4RIBSupportTest extends AbstractRIBSupportTest { + private VpnIpv4RIBSupport ribSupport; private static final DestinationVpnIpv4Case REACH_NLRI = new DestinationVpnIpv4CaseBuilder().setVpnIpv4Destination( new VpnIpv4DestinationBuilder().setVpnDestination(Collections.singletonList(IPV4_VPN)).build()).build(); @@ -70,21 +70,20 @@ public class VpnIpv4RIBSupportTest extends AbstractRIBSupportTest { @Override public void setUp() throws Exception { super.setUp(); - setUpTestCustomizer(RIB_SUPPORT); + this.ribSupport = VpnIpv4RIBSupport.getInstance(this.mappingService); + setUpTestCustomizer(this.ribSupport); } @Test public void testDeleteRoutes() { - RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); - @SuppressWarnings("unchecked") - final InstanceIdentifier instanceIdentifier = - (InstanceIdentifier) this.deletedRoutes.get(0); + this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = this.deletedRoutes.get(0); assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(VpnRoute.class)); } @Test public void testPutRoutes() { - RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); final VpnRoute route = (VpnRoute) this.insertedRoutes.get(0).getValue(); assertEquals(ROUTE, route); } @@ -94,13 +93,13 @@ public class VpnIpv4RIBSupportTest extends AbstractRIBSupportTest { public void testEmptyRoute() { final Routes empty = new VpnIpv4RoutesCaseBuilder().setVpnIpv4Routes(new VpnIpv4RoutesBuilder() .setVpnRoute(Collections.emptyList()).build()).build(); - final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + final ChoiceNode emptyRoutes = this.ribSupport.emptyRoutes(); assertEquals(createRoutes(empty), emptyRoutes); } @Test public void testBuildMpUnreachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); + final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class) .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes1.class)); @@ -108,7 +107,7 @@ public class VpnIpv4RIBSupportTest extends AbstractRIBSupportTest { @Test public void testBuildMpReachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES); + final Update update = this.ribSupport.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES); assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri() .getAdvertizedRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes2.class)); @@ -116,45 +115,45 @@ public class VpnIpv4RIBSupportTest extends AbstractRIBSupportTest { @Test public void testCacheableNlriObjects() { - assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableNlriObjects()); } @Test public void testCacheableAttributeObjects() { - assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects()); } @Test public void testRouteIdAddPath() { - Assert.assertEquals(ROUTE_KEY, RIB_SUPPORT.createRouteListKey(0L, ROUTE_KEY.getRouteKey())); + Assert.assertEquals(ROUTE_KEY, this.ribSupport.createRouteListKey(0L, ROUTE_KEY.getRouteKey())); } @Test public void testRoutePath() { final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES); - assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT + assertEquals(getRoutePath().node(prefixNii), ribSupport .routePath(getTablePath().node(Routes.QNAME), prefixNii)); } @Test public void testRouteAttributesIdentifier() { assertEquals(new NodeIdentifier(QName.create(VpnIpv4Routes.QNAME, - Attributes.QNAME.getLocalName().intern())), RIB_SUPPORT.routeAttributesIdentifier()); + Attributes.QNAME.getLocalName().intern())), this.ribSupport.routeAttributesIdentifier()); } @Test public void testRoutesCaseClass() { - assertEquals(VpnIpv4RoutesCase.class, RIB_SUPPORT.routesCaseClass()); + assertEquals(VpnIpv4RoutesCase.class, this.ribSupport.routesCaseClass()); } @Test public void testRoutesContainerClass() { - assertEquals(VpnIpv4Routes.class, RIB_SUPPORT.routesContainerClass()); + assertEquals(VpnIpv4Routes.class, this.ribSupport.routesContainerClass()); } @Test public void testRoutesListClass() { - assertEquals(VpnRoute.class, RIB_SUPPORT.routesListClass()); + assertEquals(VpnRoute.class, this.ribSupport.routesListClass()); } @Test @@ -162,16 +161,16 @@ public class VpnIpv4RIBSupportTest extends AbstractRIBSupportTest { final Routes emptyCase = new VpnIpv4RoutesCaseBuilder().build(); DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode(); - assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); final Routes emptyRoutes = new VpnIpv4RoutesCaseBuilder().setVpnIpv4Routes( new VpnIpv4RoutesBuilder().build()).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); - assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + assertTrue(this.ribSupport.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); + final Collection result = this.ribSupport.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/VpnIpv6RIBSupportTest.java b/bgp/l3vpn/src/test/java/org/opendaylight/protocol/bgp/l3vpn/ipv6/VpnIpv6RIBSupportTest.java index c3037cc347..8731dfd5b4 100644 --- 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 @@ -47,8 +47,8 @@ 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(); +public class VpnIpv6RIBSupportTest extends AbstractRIBSupportTest { + private VpnIpv6RIBSupport ribSupport; private static final DestinationVpnIpv6Case REACH_NLRI = new DestinationVpnIpv6CaseBuilder() .setVpnIpv6Destination(new VpnIpv6DestinationBuilder() @@ -70,20 +70,20 @@ public class VpnIpv6RIBSupportTest extends AbstractRIBSupportTest { @Override public void setUp() throws Exception { super.setUp(); - setUpTestCustomizer(RIB_SUPPORT); + this.ribSupport = VpnIpv6RIBSupport.getInstance(this.mappingService); + setUpTestCustomizer(this.ribSupport); } @Test public void testDeleteRoutes() { - RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); - @SuppressWarnings("unchecked") final InstanceIdentifier instanceIdentifier = - (InstanceIdentifier) this.deletedRoutes.get(0); + this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = this.deletedRoutes.get(0); assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(VpnRoute.class)); } @Test public void testPutRoutes() { - RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); final VpnRoute route = (VpnRoute) this.insertedRoutes.get(0).getValue(); assertEquals(ROUTE, route); } @@ -92,13 +92,13 @@ public class VpnIpv6RIBSupportTest extends AbstractRIBSupportTest { public void testEmptyRoute() { final Routes empty = new VpnIpv6RoutesCaseBuilder().setVpnIpv6Routes(new VpnIpv6RoutesBuilder() .setVpnRoute(Collections.emptyList()).build()).build(); - final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + final ChoiceNode emptyRoutes = this.ribSupport.emptyRoutes(); assertEquals(createRoutes(empty), emptyRoutes); } @Test public void testBuildMpUnreachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); + final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class) .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes1.class)); @@ -106,7 +106,7 @@ public class VpnIpv6RIBSupportTest extends AbstractRIBSupportTest { @Test public void testBuildMpReachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES); + final Update update = this.ribSupport.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES); assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class).getMpReachNlri() .getAdvertizedRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes2.class)); @@ -114,45 +114,45 @@ public class VpnIpv6RIBSupportTest extends AbstractRIBSupportTest { @Test public void testCacheableNlriObjects() { - assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableNlriObjects()); } @Test public void testCacheableAttributeObjects() { - assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects()); } @Test public void testRouteIdAddPath() { - Assert.assertEquals(ROUTE_KEY, RIB_SUPPORT.createRouteListKey(0L, ROUTE_KEY.getRouteKey())); + Assert.assertEquals(ROUTE_KEY, this.ribSupport.createRouteListKey(0L, ROUTE_KEY.getRouteKey())); } @Test public void testRoutePath() { final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES); assertEquals(getRoutePath().node(prefixNii), - RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + this.ribSupport.routePath(getTablePath().node(Routes.QNAME), prefixNii)); } @Test public void testRouteAttributesIdentifier() { assertEquals(new NodeIdentifier(QName.create(VpnIpv6Routes.QNAME, - Attributes.QNAME.getLocalName().intern())), RIB_SUPPORT.routeAttributesIdentifier()); + Attributes.QNAME.getLocalName().intern())), this.ribSupport.routeAttributesIdentifier()); } @Test public void testRoutesCaseClass() { - assertEquals(VpnIpv6RoutesCase.class, RIB_SUPPORT.routesCaseClass()); + assertEquals(VpnIpv6RoutesCase.class, this.ribSupport.routesCaseClass()); } @Test public void testRoutesContainerClass() { - assertEquals(VpnIpv6Routes.class, RIB_SUPPORT.routesContainerClass()); + assertEquals(VpnIpv6Routes.class, this.ribSupport.routesContainerClass()); } @Test public void testRoutesListClass() { - assertEquals(VpnRoute.class, RIB_SUPPORT.routesListClass()); + assertEquals(VpnRoute.class, this.ribSupport.routesListClass()); } @Test @@ -160,16 +160,16 @@ public class VpnIpv6RIBSupportTest extends AbstractRIBSupportTest { final Routes emptyCase = new VpnIpv6RoutesCaseBuilder().build(); DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode(); - Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); final Routes emptyRoutes = new VpnIpv6RoutesCaseBuilder() .setVpnIpv6Routes(new VpnIpv6RoutesBuilder().build()).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); - Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); final Routes routes = new VpnIpv6RoutesCaseBuilder().setVpnIpv6Routes(ROUTES).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode(); - final Collection result = RIB_SUPPORT.changedRoutes(tree); + final Collection result = this.ribSupport.changedRoutes(tree); Assert.assertFalse(result.isEmpty()); } } \ No newline at end of file diff --git a/bgp/labeled-unicast/pom.xml b/bgp/labeled-unicast/pom.xml index 321e16a0de..3ee85418e0 100644 --- a/bgp/labeled-unicast/pom.xml +++ b/bgp/labeled-unicast/pom.xml @@ -147,6 +147,11 @@ sal-binding-api test + + org.opendaylight.controller + sal-binding-broker-impl + test + org.opendaylight.controller sal-binding-broker-impl diff --git a/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/AbstractLabeledUnicastRIBSupport.java b/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/AbstractLabeledUnicastRIBSupport.java index bba522f616..0342cf6a1b 100644 --- a/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/AbstractLabeledUnicastRIBSupport.java +++ b/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/AbstractLabeledUnicastRIBSupport.java @@ -17,10 +17,12 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil; import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupport; import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.LabeledUnicastSubsequentAddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.LabelStack; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.LabelStackBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.destination.CLabeledUnicastDestination; @@ -30,10 +32,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labe import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.list.LabeledUnicastRouteKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.AddressFamily; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.SubsequentAddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.common.QName; @@ -50,8 +50,10 @@ import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -abstract class AbstractLabeledUnicastRIBSupport - extends AbstractRIBSupport { +abstract class AbstractLabeledUnicastRIBSupport< + C extends Routes & DataObject, + S extends DataObject> + extends AbstractRIBSupport { private static final NodeIdentifier LABEL_STACK_NID = NodeIdentifier.create(QName.create(CLabeledUnicastDestination.QNAME, "label-stack").intern()); private static final NodeIdentifier LV_NID @@ -64,20 +66,25 @@ abstract class AbstractLabeledUnicastRIBSupport * node in instantiations of the rib grouping. It is assumed that this container is defined by * the same model which populates it with route grouping instantiation, and by extension with * the route attributes container. - * @param cazeClass Binding class of the AFI/SAFI-specific case statement, must not be null + * @param mappingService Binding Normalized Node Serializer + * @param cazeClass Binding class of the AFI/SAFI-specific case statement, must not be null * @param containerClass Binding class of the container in routes choice, must not be null. - * @param listClass Binding class of the route list, nust not be null; * @param addressFamilyClass address Family Class - * @param safiClass SubsequentAddressFamily * @param destinationQname destination Qname */ - AbstractLabeledUnicastRIBSupport(final Class cazeClass, - final Class containerClass, - final Class listClass, + AbstractLabeledUnicastRIBSupport( + final BindingNormalizedNodeSerializer mappingService, + final Class cazeClass, + final Class containerClass, final Class addressFamilyClass, - final Class safiClass, final QName destinationQname) { - super(cazeClass, containerClass, listClass, addressFamilyClass, safiClass, destinationQname); + super(mappingService, + cazeClass, + containerClass, + LabeledUnicastRoute.class, + addressFamilyClass, + LabeledUnicastSubsequentAddressFamily.class, + destinationQname); } @Override diff --git a/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LabeledUnicastIpv4RIBSupport.java b/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LabeledUnicastIpv4RIBSupport.java index 1527cfcaab..acc98b5950 100644 --- a/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LabeledUnicastIpv4RIBSupport.java +++ b/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LabeledUnicastIpv4RIBSupport.java @@ -8,52 +8,68 @@ package org.opendaylight.protocol.bgp.labeled.unicast; import java.util.Collection; +import java.util.Collections; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.LabeledUnicastSubsequentAddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastRoutesCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.peer.effective.rib.in.tables.routes.LabeledUnicastRoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastRoutesCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.LabeledUnicastRoutes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.LabeledUnicastRoutesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.list.LabeledUnicastRoute; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.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.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicast; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.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.multiprotocol.rev180329.destination.DestinationType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -public final class LabeledUnicastIpv4RIBSupport extends AbstractLabeledUnicastRIBSupport { - private static final LabeledUnicastIpv4RIBSupport SINGLETON = new LabeledUnicastIpv4RIBSupport(); +public final class LabeledUnicastIpv4RIBSupport + extends AbstractLabeledUnicastRIBSupport { + private static final LabeledUnicastRoutes EMPTY_CONTAINER + = new LabeledUnicastRoutesBuilder().setLabeledUnicastRoute(Collections.emptyList()).build(); + private static final LabeledUnicastRoutesCase EMPTY_CASE + = new LabeledUnicastRoutesCaseBuilder().setLabeledUnicastRoutes(EMPTY_CONTAINER).build(); + private static LabeledUnicastIpv4RIBSupport SINGLETON; - private LabeledUnicastIpv4RIBSupport() { - super(LabeledUnicastRoutesCase.class, LabeledUnicastRoutes.class, LabeledUnicastRoute.class, - Ipv4AddressFamily.class, LabeledUnicastSubsequentAddressFamily.class, DestinationLabeledUnicast.QNAME); + private LabeledUnicastIpv4RIBSupport(final BindingNormalizedNodeSerializer mappingService) { + super(mappingService, + LabeledUnicastRoutesCase.class, + LabeledUnicastRoutes.class, + Ipv4AddressFamily.class, + DestinationLabeledUnicast.QNAME); } - static LabeledUnicastIpv4RIBSupport getInstance() { + static synchronized LabeledUnicastIpv4RIBSupport getInstance(final BindingNormalizedNodeSerializer mappingService) { + if (SINGLETON == null) { + SINGLETON = new LabeledUnicastIpv4RIBSupport(mappingService); + } return SINGLETON; } @Override protected DestinationType buildDestination(final Collection routes) { return new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast( - new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(extractRoutes(routes)).build()).build(); + new DestinationLabeledUnicastBuilder() + .setCLabeledUnicastDestination(extractRoutes(routes)).build()).build(); } @Override protected DestinationType buildWithdrawnDestination(final Collection routes) { - return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.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.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination( - extractRoutes(routes)).build()).build(); + return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329 + .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.rev180329.update.attributes.mp.unreach.nlri + .withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder() + .setCLabeledUnicastDestination(extractRoutes(routes)).build()).build(); } @Override - public IpPrefix extractPrefix(final DataContainerNode route, final NodeIdentifier prefixTypeNid) { + public IpPrefix extractPrefix( + final DataContainerNode route, + final NodeIdentifier prefixTypeNid) { if (route.getChild(prefixTypeNid).isPresent()) { final String prefixType = (String) route.getChild(prefixTypeNid).get().getValue(); return new IpPrefix(new Ipv4Prefix(prefixType)); @@ -62,8 +78,12 @@ public final class LabeledUnicastIpv4RIBSupport extends AbstractLabeledUnicastRI } @Override - public Routes emptyRoutesContainer() { - return new LabeledUnicastRoutesCaseBuilder() - .setLabeledUnicastRoutes(new LabeledUnicastRoutesBuilder().build()).build(); + public LabeledUnicastRoutesCase emptyRoutesCase() { + return EMPTY_CASE; + } + + @Override + public LabeledUnicastRoutes emptyRoutesContainer() { + return EMPTY_CONTAINER; } } diff --git a/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LabeledUnicastIpv6RIBSupport.java b/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LabeledUnicastIpv6RIBSupport.java index 96817ad181..63efd9fd2f 100644 --- a/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LabeledUnicastIpv6RIBSupport.java +++ b/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/LabeledUnicastIpv6RIBSupport.java @@ -9,48 +9,62 @@ package org.opendaylight.protocol.bgp.labeled.unicast; import java.util.Collection; +import java.util.Collections; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.LabeledUnicastSubsequentAddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastIpv6RoutesCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.peer.effective.rib.in.tables.routes.LabeledUnicastIpv6RoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastIpv6RoutesCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.ipv6.routes.LabeledUnicastIpv6Routes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.ipv6.routes.LabeledUnicastIpv6RoutesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.routes.list.LabeledUnicastRoute; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.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.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicast; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.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.multiprotocol.rev180329.destination.DestinationType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; -final class LabeledUnicastIpv6RIBSupport extends AbstractLabeledUnicastRIBSupport { - private static final LabeledUnicastIpv6RIBSupport SINGLETON = new LabeledUnicastIpv6RIBSupport(); +final class LabeledUnicastIpv6RIBSupport + extends AbstractLabeledUnicastRIBSupport { - private LabeledUnicastIpv6RIBSupport() { - super(LabeledUnicastIpv6RoutesCase.class, LabeledUnicastIpv6Routes.class, LabeledUnicastRoute.class, - Ipv4AddressFamily.class, LabeledUnicastSubsequentAddressFamily.class, DestinationIpv6LabeledUnicast.QNAME); + private static final LabeledUnicastIpv6Routes EMPTY_CONTAINER + = new LabeledUnicastIpv6RoutesBuilder().setLabeledUnicastRoute(Collections.emptyList()).build(); + private static final LabeledUnicastIpv6RoutesCase EMPTY_CASE + = new LabeledUnicastIpv6RoutesCaseBuilder().setLabeledUnicastIpv6Routes(EMPTY_CONTAINER).build(); + private static LabeledUnicastIpv6RIBSupport SINGLETON; + + private LabeledUnicastIpv6RIBSupport(final BindingNormalizedNodeSerializer mappingService) { + super(mappingService, + LabeledUnicastIpv6RoutesCase.class, + LabeledUnicastIpv6Routes.class, + Ipv6AddressFamily.class, + DestinationIpv6LabeledUnicast.QNAME); } - static LabeledUnicastIpv6RIBSupport getInstance() { + static synchronized LabeledUnicastIpv6RIBSupport getInstance(final BindingNormalizedNodeSerializer mappingService) { + if (SINGLETON == null) { + SINGLETON = new LabeledUnicastIpv6RIBSupport(mappingService); + } return SINGLETON; } @Override protected DestinationType buildDestination(final Collection routes) { return new DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast( - new DestinationIpv6LabeledUnicastBuilder().setCLabeledUnicastDestination(extractRoutes(routes)).build()).build(); + new DestinationIpv6LabeledUnicastBuilder() + .setCLabeledUnicastDestination(extractRoutes(routes)).build()).build(); } @Override protected DestinationType buildWithdrawnDestination(final Collection routes) { - return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.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.rev180329.update.attributes.mp - .unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder() + return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329 + .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.rev180329 + .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.ipv6 + .labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder() .setCLabeledUnicastDestination(extractRoutes(routes)).build()).build(); } @@ -65,8 +79,12 @@ final class LabeledUnicastIpv6RIBSupport extends AbstractLabeledUnicastRIBSuppor } @Override - public Routes emptyRoutesContainer() { - return new LabeledUnicastIpv6RoutesCaseBuilder() - .setLabeledUnicastIpv6Routes(new LabeledUnicastIpv6RoutesBuilder().build()).build(); + public LabeledUnicastIpv6RoutesCase emptyRoutesCase() { + return EMPTY_CASE; + } + + @Override + public LabeledUnicastIpv6Routes emptyRoutesContainer() { + return EMPTY_CONTAINER; } } diff --git a/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/RIBActivator.java b/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/RIBActivator.java index e33fe12a00..6144002145 100644 --- a/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/RIBActivator.java +++ b/bgp/labeled-unicast/src/main/java/org/opendaylight/protocol/bgp/labeled/unicast/RIBActivator.java @@ -9,6 +9,7 @@ package org.opendaylight.protocol.bgp.labeled.unicast; import java.util.ArrayList; import java.util.List; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBExtensionProviderActivator; import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.LabeledUnicastSubsequentAddressFamily; @@ -19,10 +20,14 @@ public class RIBActivator extends AbstractRIBExtensionProviderActivator { @Override protected List startRIBExtensionProviderImpl( - final RIBExtensionProviderContext context) { + final RIBExtensionProviderContext context, + final BindingNormalizedNodeSerializer mappingService + ) { final List regs = new ArrayList<>(2); - regs.add(context.registerRIBSupport(Ipv4AddressFamily.class, LabeledUnicastSubsequentAddressFamily.class, LabeledUnicastIpv4RIBSupport.getInstance())); - regs.add(context.registerRIBSupport(Ipv6AddressFamily.class, LabeledUnicastSubsequentAddressFamily.class, LabeledUnicastIpv6RIBSupport.getInstance())); + regs.add(context.registerRIBSupport(Ipv4AddressFamily.class, LabeledUnicastSubsequentAddressFamily.class, + LabeledUnicastIpv4RIBSupport.getInstance(mappingService))); + regs.add(context.registerRIBSupport(Ipv6AddressFamily.class, LabeledUnicastSubsequentAddressFamily.class, + LabeledUnicastIpv6RIBSupport.getInstance(mappingService))); return regs; } } 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 index 357ac2627a..b76a024f6c 100644 --- 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 @@ -55,24 +55,30 @@ 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 { +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 String 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.rev180329.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.rev180329.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.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination. - type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(LABELED_DESTINATION_LIST).build()).build(); + 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 + .rev180329.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.rev180329.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.rev180329.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(); @@ -82,42 +88,49 @@ public class LabeledUnicastIpv4RIBSupportTest extends AbstractRIBSupportTest { LUNlriParser.serializeNlri(LABELED_DESTINATION_LIST, false, buffer); LABEL_KEY = ByteArray.encodeBase64(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(); + 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(); } + private LabeledUnicastIpv4RIBSupport ribSupport; + @Override public void setUp() throws Exception { super.setUp(); - setUpTestCustomizer(RIB_SUPPORT); + this.ribSupport = LabeledUnicastIpv4RIBSupport.getInstance(this.mappingService); + setUpTestCustomizer(this.ribSupport); } @Test public void testDeleteRoutes() { - RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); - final InstanceIdentifier instanceIdentifier = (InstanceIdentifier) this.deletedRoutes.get(0); + this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final 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()); + this.ribSupport.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 { + public void testEmptyRoute() { final Routes empty = new LabeledUnicastRoutesCaseBuilder().setLabeledUnicastRoutes( new LabeledUnicastRoutesBuilder().setLabeledUnicastRoute(Collections.emptyList()).build()).build(); - final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + final ChoiceNode emptyRoutes = this.ribSupport.emptyRoutes(); assertEquals(createRoutes(empty), emptyRoutes); } @Test public void testBuildMpUnreachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); + final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class) .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes1.class)); @@ -125,67 +138,72 @@ public class LabeledUnicastIpv4RIBSupportTest extends AbstractRIBSupportTest { @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()); + final Update update = this.ribSupport.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 testCacheableNlriObjects() { - Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableNlriObjects()); } @Test public void testCacheableAttributeObjects() { - Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects()); } @Test public void testRouteIdAddPath() { - Assert.assertEquals(ROUTE_KEY, RIB_SUPPORT.createRouteListKey(1L, ROUTE_KEY.getRouteKey())); + assertEquals(ROUTE_KEY, this.ribSupport.createRouteListKey(1L, ROUTE_KEY.getRouteKey())); } @Test public void testRoutePath() { final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES); - Assert.assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + assertEquals(getRoutePath().node(prefixNii), + this.ribSupport.routePath(getTablePath().node(Routes.QNAME), prefixNii)); } @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.rev180329.rib.tables.Attributes.QNAME.getLocalName().intern())), - RIB_SUPPORT.routeAttributesIdentifier()); + assertEquals(new NodeIdentifier(QName.create(LabeledUnicastRoutes.QNAME, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables + .Attributes.QNAME.getLocalName().intern())), + this.ribSupport.routeAttributesIdentifier()); } @Test public void testRoutesCaseClass() { - Assert.assertEquals(LabeledUnicastRoutesCase.class, RIB_SUPPORT.routesCaseClass()); + assertEquals(LabeledUnicastRoutesCase.class, this.ribSupport.routesCaseClass()); } @Test public void testRoutesContainerClass() { - Assert.assertEquals(LabeledUnicastRoutes.class, RIB_SUPPORT.routesContainerClass()); + assertEquals(LabeledUnicastRoutes.class, this.ribSupport.routesContainerClass()); } @Test public void testRoutesListClass() { - Assert.assertEquals(LabeledUnicastRoute.class, RIB_SUPPORT.routesListClass()); + assertEquals(LabeledUnicastRoute.class, this.ribSupport.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()); + DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), + createRoutes(emptyCase)).getRootNode(); + Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); - final Routes emptyRoutes = new LabeledUnicastRoutesCaseBuilder().setLabeledUnicastRoutes(new LabeledUnicastRoutesBuilder().build()).build(); + final Routes emptyRoutes = new LabeledUnicastRoutesCaseBuilder() + .setLabeledUnicastRoutes(new LabeledUnicastRoutesBuilder().build()).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); - Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + Assert.assertTrue(this.ribSupport.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); + final Collection result = this.ribSupport.changedRoutes(tree); Assert.assertFalse(result.isEmpty()); } } 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 index 7a91e09366..7c32e4b62a 100644 --- 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 @@ -55,25 +55,33 @@ 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 { +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 String 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.rev180329.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.rev180329.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.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled.unicast._case. - DestinationIpv6LabeledUnicastBuilder().setCLabeledUnicastDestination(LABELED_DESTINATION_LIST).build()).build(); + 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.rev180329 + .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.rev180329.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.rev180329.update.attributes.mp + .unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled.unicast._case. + DestinationIpv6LabeledUnicastBuilder().setCLabeledUnicastDestination(LABELED_DESTINATION_LIST).build()) + .build(); + private LabeledUnicastIpv6RIBSupport ribSupport; static { final BGPActivator act = new BGPActivator(); @@ -83,7 +91,8 @@ public class LabeledUnicastIpv6RIBSupportTest extends AbstractRIBSupportTest { LUNlriParser.serializeNlri(LABELED_DESTINATION_LIST, false, buffer); LABEL_KEY = ByteArray.encodeBase64(buffer); ROUTE_KEY = new LabeledUnicastRouteKey(PATH_ID, LABEL_KEY); - ROUTE = new LabeledUnicastRouteBuilder().setKey(ROUTE_KEY).setPrefix(IPv6_PREFIX).setPathId(PATH_ID).setLabelStack(LABEL_STACK) + 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(); } @@ -91,19 +100,20 @@ public class LabeledUnicastIpv6RIBSupportTest extends AbstractRIBSupportTest { @Override public void setUp() throws Exception { super.setUp(); - setUpTestCustomizer(RIB_SUPPORT); + this.ribSupport = LabeledUnicastIpv6RIBSupport.getInstance(this.mappingService); + setUpTestCustomizer(this.ribSupport); } @Test public void testDeleteRoutes() { - RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); - final InstanceIdentifier instanceIdentifier = (InstanceIdentifier) this.deletedRoutes.get(0); + this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final 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()); + this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); final LabeledUnicastRoute route = (LabeledUnicastRoute) this.insertedRoutes.get(0).getValue(); assertEquals(ROUTE, route); } @@ -112,13 +122,13 @@ public class LabeledUnicastIpv6RIBSupportTest extends AbstractRIBSupportTest { public void testEmptyRoute() { final Routes empty = new LabeledUnicastIpv6RoutesCaseBuilder().setLabeledUnicastIpv6Routes( new LabeledUnicastIpv6RoutesBuilder().setLabeledUnicastRoute(Collections.emptyList()).build()).build(); - final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + final ChoiceNode emptyRoutes = this.ribSupport.emptyRoutes(); assertEquals(createRoutes(empty), emptyRoutes); } @Test public void testBuildMpUnreachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); + final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class) .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes1.class)); @@ -126,67 +136,72 @@ public class LabeledUnicastIpv6RIBSupportTest extends AbstractRIBSupportTest { @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()); + final Update update = this.ribSupport.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 testCacheableNlriObjects() { - Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableNlriObjects()); } @Test public void testCacheableAttributeObjects() { - Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects()); } @Test public void testRouteIdAddPath() { - Assert.assertEquals(ROUTE_KEY, RIB_SUPPORT.createRouteListKey(1L, ROUTE_KEY.getRouteKey())); + assertEquals(ROUTE_KEY, this.ribSupport.createRouteListKey(1L, ROUTE_KEY.getRouteKey())); } @Test public void testRoutePath() { final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES); - Assert.assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + assertEquals(getRoutePath().node(prefixNii), + this.ribSupport.routePath(getTablePath().node(Routes.QNAME), prefixNii)); } @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.rev180329.rib.tables.Attributes.QNAME.getLocalName().intern())), - RIB_SUPPORT.routeAttributesIdentifier()); + assertEquals(new NodeIdentifier(QName.create(LabeledUnicastIpv6Routes.QNAME, + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables + .Attributes.QNAME.getLocalName().intern())), + this.ribSupport.routeAttributesIdentifier()); } @Test public void testRoutesCaseClass() { - Assert.assertEquals(LabeledUnicastIpv6RoutesCase.class, RIB_SUPPORT.routesCaseClass()); + assertEquals(LabeledUnicastIpv6RoutesCase.class, this.ribSupport.routesCaseClass()); } @Test public void testRoutesContainerClass() { - Assert.assertEquals(LabeledUnicastIpv6Routes.class, RIB_SUPPORT.routesContainerClass()); + assertEquals(LabeledUnicastIpv6Routes.class, this.ribSupport.routesContainerClass()); } @Test public void testRoutesListClass() { - Assert.assertEquals(LabeledUnicastRoute.class, RIB_SUPPORT.routesListClass()); + assertEquals(LabeledUnicastRoute.class, this.ribSupport.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()); + DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), + createRoutes(emptyCase)).getRootNode(); + Assert.assertTrue(this.ribSupport.changedRoutes(tree).isEmpty()); - final Routes emptyRoutes = new LabeledUnicastIpv6RoutesCaseBuilder().setLabeledUnicastIpv6Routes(new LabeledUnicastIpv6RoutesBuilder().build()).build(); + final Routes emptyRoutes = new LabeledUnicastIpv6RoutesCaseBuilder() + .setLabeledUnicastIpv6Routes(new LabeledUnicastIpv6RoutesBuilder().build()).build(); tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode(); - Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + Assert.assertTrue(this.ribSupport.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); + final Collection result = this.ribSupport.changedRoutes(tree); Assert.assertFalse(result.isEmpty()); } } diff --git a/bgp/linkstate/pom.xml b/bgp/linkstate/pom.xml index ac7f404c42..75eb22fe1e 100644 --- a/bgp/linkstate/pom.xml +++ b/bgp/linkstate/pom.xml @@ -167,6 +167,11 @@ mdsal-binding-dom-adapter test + + org.opendaylight.controller + sal-binding-broker-impl + test + org.hamcrest hamcrest-core diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/LinkstateRIBSupport.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/LinkstateRIBSupport.java index 629ffea206..09b3eceacf 100644 --- a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/LinkstateRIBSupport.java +++ b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/LinkstateRIBSupport.java @@ -11,10 +11,12 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.protocol.bgp.linkstate.impl.nlri.LinkstateNlriParser; import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry; import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil; @@ -23,7 +25,7 @@ import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkstateAddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkstateSubsequentAddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.bgp.rib.rib.loc.rib.tables.routes.LinkstateRoutesCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.bgp.rib.rib.peer.effective.rib.in.tables.routes.LinkstateRoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.bgp.rib.rib.loc.rib.tables.routes.LinkstateRoutesCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.destination.CLinkstateDestination; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.routes.LinkstateRoutes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.routes.LinkstateRoutesBuilder; @@ -36,7 +38,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; @@ -48,18 +49,33 @@ import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public final class LinkstateRIBSupport extends AbstractRIBSupport { +public final class LinkstateRIBSupport + extends AbstractRIBSupport { private static final Logger LOG = LoggerFactory.getLogger(LinkstateRIBSupport.class); - private static final LinkstateRIBSupport SINGLETON = new LinkstateRIBSupport(); + + private static final LinkstateRoutes EMPTY_CONTAINER + = new LinkstateRoutesBuilder().setLinkstateRoute(Collections.emptyList()).build(); + private static final LinkstateRoutesCase EMPTY_CASE + = new LinkstateRoutesCaseBuilder().setLinkstateRoutes(EMPTY_CONTAINER).build(); + private static LinkstateRIBSupport SINGLETON; private final YangInstanceIdentifier.NodeIdentifier nlriRoutesList = new YangInstanceIdentifier.NodeIdentifier(CLinkstateDestination.QNAME); - private LinkstateRIBSupport() { - super(LinkstateRoutesCase.class, LinkstateRoutes.class, LinkstateRoute.class, LinkstateAddressFamily.class, - LinkstateSubsequentAddressFamily.class, DestinationLinkstate.QNAME); + private LinkstateRIBSupport(final BindingNormalizedNodeSerializer mappingService) { + super( + mappingService, + LinkstateRoutesCase.class, + LinkstateRoutes.class, + LinkstateRoute.class, + LinkstateAddressFamily.class, + LinkstateSubsequentAddressFamily.class, + DestinationLinkstate.QNAME); } - public static LinkstateRIBSupport getInstance() { + public synchronized static LinkstateRIBSupport getInstance(final BindingNormalizedNodeSerializer mappingService) { + if(SINGLETON == null){ + SINGLETON = new LinkstateRIBSupport(mappingService); + } return SINGLETON; } @@ -129,12 +145,17 @@ public final class LinkstateRIBSupport extends AbstractRIBSupport startRIBExtensionProviderImpl(final RIBExtensionProviderContext context) { - return Lists.newArrayList((AutoCloseable) context.registerRIBSupport(LinkstateAddressFamily.class, - LinkstateSubsequentAddressFamily.class, LinkstateRIBSupport.getInstance())); + protected List startRIBExtensionProviderImpl( + final RIBExtensionProviderContext context, + final BindingNormalizedNodeSerializer mappingService) { + return Collections.singletonList(context.registerRIBSupport(LinkstateAddressFamily.class, + LinkstateSubsequentAddressFamily.class, LinkstateRIBSupport.getInstance(mappingService))); } } diff --git a/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/ActivatorTest.java b/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/ActivatorTest.java index 9374e6343c..6a29d8b9d5 100644 --- a/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/ActivatorTest.java +++ b/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/ActivatorTest.java @@ -16,17 +16,18 @@ import org.opendaylight.protocol.bgp.linkstate.impl.BGPActivator; import org.opendaylight.protocol.bgp.linkstate.impl.RIBActivator; import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext; import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext; +import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBActivatorTest; import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext; import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext; import org.opendaylight.protocol.rsvp.parser.spi.pojo.ServiceLoaderRSVPExtensionProviderContext; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkstateAddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkstateSubsequentAddressFamily; -public class ActivatorTest { - +public class ActivatorTest extends AbstractRIBActivatorTest { @Test - public void testActivator() throws Exception { - final BGPActivator act = new BGPActivator(true, ServiceLoaderRSVPExtensionProviderContext.getSingletonInstance().getRsvpRegistry()); + public void testActivator() { + final BGPActivator act = new BGPActivator(true, + ServiceLoaderRSVPExtensionProviderContext.getSingletonInstance().getRsvpRegistry()); final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext(); assertNull(context.getAddressFamilyRegistry().classForFamily(16388)); assertNull(context.getSubsequentAddressFamilyRegistry().classForFamily(71)); @@ -34,7 +35,8 @@ public class ActivatorTest { act.start(context); assertEquals(LinkstateAddressFamily.class, context.getAddressFamilyRegistry().classForFamily(16388)); - assertEquals(LinkstateSubsequentAddressFamily.class, context.getSubsequentAddressFamilyRegistry().classForFamily(71)); + assertEquals(LinkstateSubsequentAddressFamily.class, + context.getSubsequentAddressFamilyRegistry().classForFamily(71)); act.close(); } @@ -46,7 +48,7 @@ public class ActivatorTest { assertNull(context.getRIBSupport(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class)); - ribAct.startRIBExtensionProvider(context); + ribAct.startRIBExtensionProvider(context, this.mappingService); assertNotNull(context.getRIBSupport(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class)); 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 eaadf79e8f..a3ea8f8426 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 @@ -68,9 +68,9 @@ 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 { +public final class LinkstateRIBSupportTest extends AbstractRIBSupportTest { - private static final LinkstateRIBSupport RIB_SUPPORT = LinkstateRIBSupport.getInstance(); + private LinkstateRIBSupport ribSupport; private static final LinkstateRoute ROUTE; private static final LinkstateRoutes ROUTES; private static final LinkstateRouteKey ROUTE_KEY; @@ -118,20 +118,20 @@ public final class LinkstateRIBSupportTest extends AbstractRIBSupportTest { @Override public void setUp() throws Exception { super.setUp(); - setUpTestCustomizer(RIB_SUPPORT); + this.ribSupport = LinkstateRIBSupport.getInstance(this.mappingService); + setUpTestCustomizer(ribSupport); } @Test public void testDeleteRoutes() { - RIB_SUPPORT.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); - final InstanceIdentifier instanceIdentifier - = (InstanceIdentifier) this.deletedRoutes.get(0); + this.ribSupport.deleteRoutes(this.tx, getTablePath(), createNlriWithDrawnRoute(UNREACH_NLRI)); + final InstanceIdentifier instanceIdentifier = this.deletedRoutes.get(0); assertEquals(ROUTE_KEY, instanceIdentifier.firstKeyOf(LinkstateRoute.class)); } @Test public void testPutRoutes() { - RIB_SUPPORT.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); + this.ribSupport.putRoutes(this.tx, getTablePath(), createNlriAdvertiseRoute(REACH_NLRI), createAttributes()); final LinkstateRoute route = (LinkstateRoute) this.insertedRoutes.get(0).getValue(); assertEquals(ROUTE, route); } @@ -140,13 +140,13 @@ public final class LinkstateRIBSupportTest extends AbstractRIBSupportTest { public void testEmptyRoute() { final Routes empty = new LinkstateRoutesCaseBuilder().setLinkstateRoutes( new LinkstateRoutesBuilder().setLinkstateRoute(Collections.emptyList()).build()).build(); - final ChoiceNode emptyRoutes = RIB_SUPPORT.emptyRoutes(); + final ChoiceNode emptyRoutes = this.ribSupport.emptyRoutes(); assertEquals(createRoutes(empty), emptyRoutes); } @Test public void testBuildMpUnreachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); + final Update update = this.ribSupport.buildUpdate(Collections.emptyList(), createRoutes(ROUTES), ATTRIBUTES); assertEquals(UNREACH_NLRI, update.getAttributes().getAugmentation(Attributes2.class) .getMpUnreachNlri().getWithdrawnRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes1.class)); @@ -154,7 +154,7 @@ public final class LinkstateRIBSupportTest extends AbstractRIBSupportTest { @Test public void testBuildMpReachNlriUpdate() { - final Update update = RIB_SUPPORT.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES); + final Update update = this.ribSupport.buildUpdate(createRoutes(ROUTES), Collections.emptyList(), ATTRIBUTES); assertEquals(REACH_NLRI, update.getAttributes().getAugmentation(Attributes1.class) .getMpReachNlri().getAdvertizedRoutes().getDestinationType()); assertNull(update.getAttributes().getAugmentation(Attributes2.class)); @@ -162,46 +162,46 @@ public final class LinkstateRIBSupportTest extends AbstractRIBSupportTest { @Test public void testCacheableNlriObjects() { - Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableNlriObjects()); + Assert.assertEquals(ImmutableSet.of(), this.ribSupport.cacheableNlriObjects()); } @Test public void testCacheableAttributeObjects() { - Assert.assertEquals(ImmutableSet.of(), RIB_SUPPORT.cacheableAttributeObjects()); + Assert.assertEquals(ImmutableSet.of(), this.ribSupport.cacheableAttributeObjects()); } @Test public void testRouteIdAddPath() { - Assert.assertEquals(ROUTE_KEY, RIB_SUPPORT.createRouteListKey(ROUTE_KEY.getPathId().getValue(), + Assert.assertEquals(ROUTE_KEY, this.ribSupport.createRouteListKey(ROUTE_KEY.getPathId().getValue(), ROUTE_KEY.getRouteKey())); } @Test public void testRoutePath() { final NodeIdentifierWithPredicates prefixNii = createRouteNIWP(ROUTES); - Assert.assertEquals(getRoutePath().node(prefixNii), RIB_SUPPORT.routePath(getTablePath().node(Routes.QNAME), prefixNii)); + Assert.assertEquals(getRoutePath().node(prefixNii), this.ribSupport.routePath(getTablePath().node(Routes.QNAME), prefixNii)); } @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.rev180329.rib.tables.Attributes.QNAME.getLocalName().intern())), - RIB_SUPPORT.routeAttributesIdentifier()); + this.ribSupport.routeAttributesIdentifier()); } @Test public void testRoutesCaseClass() { - Assert.assertEquals(LinkstateRoutesCase.class, RIB_SUPPORT.routesCaseClass()); + Assert.assertEquals(LinkstateRoutesCase.class, this.ribSupport.routesCaseClass()); } @Test public void testRoutesContainerClass() { - Assert.assertEquals(LinkstateRoutes.class, RIB_SUPPORT.routesContainerClass()); + Assert.assertEquals(LinkstateRoutes.class, this.ribSupport.routesContainerClass()); } @Test public void testRoutesListClass() { - Assert.assertEquals(LinkstateRoute.class, RIB_SUPPORT.routesListClass()); + Assert.assertEquals(LinkstateRoute.class, this.ribSupport.routesListClass()); } @Test @@ -209,16 +209,16 @@ public final class LinkstateRIBSupportTest extends AbstractRIBSupportTest { final Routes emptyCase = new LinkstateRoutesCaseBuilder().build(); DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode(); - Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty()); + Assert.assertTrue(this.ribSupport.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()); + Assert.assertTrue(this.ribSupport.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); + final Collection result = this.ribSupport.changedRoutes(tree); Assert.assertFalse(result.isEmpty()); } } \ No newline at end of file diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java index 5ca99912d7..94d1294d16 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java @@ -228,7 +228,7 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn if (table.getDataBefore() == null) { tx.put(LogicalDatastoreType.OPERATIONAL, tablePath, new TablesBuilder() .setAfi(tableKey.getAfi()).setSafi(tableKey.getSafi()) - .setRoutes(this.registry.getRIBSupport(tableKey).emptyRoutesContainer()) + .setRoutes(this.registry.getRIBSupport(tableKey).emptyRoutesCase()) .setAttributes(newTable.getAttributes()).build()); } diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractAddPathTest.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractAddPathTest.java index 967f62584f..63de26aed2 100644 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractAddPathTest.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractAddPathTest.java @@ -23,18 +23,11 @@ import java.util.List; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; -import javassist.ClassPool; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.mockito.Mock; import org.mockito.Mockito; -import org.opendaylight.mdsal.binding.dom.adapter.BindingToNormalizedNodeCodec; -import org.opendaylight.mdsal.binding.dom.codec.gen.impl.StreamWriterGenerator; -import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry; -import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy; -import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; -import org.opendaylight.mdsal.binding.generator.util.JavassistUtils; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration; @@ -57,7 +50,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.DestinationIpv4Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.destination.ipv4.Ipv4PrefixesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes.Ipv4Route; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4Case; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4CaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.NotifyBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Open; @@ -86,12 +78,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.SendReceive; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.AddPathCapabilityBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.MultiprotocolCapability; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.MultiprotocolCapabilityBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.add.path.capability.AddressFamiliesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlri; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlriBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.BgpRib; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole; @@ -105,8 +94,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.Notification; -import org.opendaylight.yangtools.yang.binding.util.BindingReflections; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; public abstract class AbstractAddPathTest extends DefaultRibPoliciesMockTest { private static final int RETRY_TIMER = 10; @@ -138,10 +125,8 @@ public abstract class AbstractAddPathTest extends DefaultRibPoliciesMockTest { static final Set AFI_SAFIS_ADVERTIZED = Collections.singleton(TABLES_KEY); private BGPExtensionProviderContext context; private static final InstanceIdentifier BGP_IID = InstanceIdentifier.create(BgpRib.class); - protected SchemaContext schemaContext; @Mock protected ClusterSingletonServiceProvider clusterSingletonServiceProvider; - BindingToNormalizedNodeCodec mappingService; BGPDispatcherImpl serverDispatcher; RIBExtensionProviderContext ribExtension; private RIBActivator ribActivator; @@ -159,28 +144,13 @@ public abstract class AbstractAddPathTest extends DefaultRibPoliciesMockTest { this.ribActivator = new RIBActivator(); this.ribExtension = new SimpleRIBExtensionProviderContext(); - this.ribActivator.startRIBExtensionProvider(this.ribExtension); + this.ribActivator.startRIBExtensionProvider(this.ribExtension, this.mappingService); this.bgpActivator = new BGPActivator(); this.inetActivator = new org.opendaylight.protocol.bgp.inet.BGPActivator(); this.context = new SimpleBGPExtensionProviderContext(); this.bgpActivator.start(this.context); this.inetActivator.start(this.context); - - this.mappingService = new BindingToNormalizedNodeCodec( - GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), - new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create( - JavassistUtils.forClassPool(ClassPool.getDefault())))); - final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create(); - moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(BgpParameters.class)); - moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(MultiprotocolCapability.class)); - moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(DestinationIpv4Case.class)); - moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(AdvertizedRoutes.class)); - moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(BgpRib.class)); - moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(Attributes1.class)); - moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(MpReachNlri.class)); - this.mappingService.onGlobalContextUpdated(moduleInfoBackedContext.tryToCreateSchemaContext().get()); - this.schemaContext = moduleInfoBackedContext.getSchemaContext(); if (!Epoll.isAvailable()) { this.worker = new NioEventLoopGroup(); this.boss = new NioEventLoopGroup(); diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractRIBTestSetup.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractRIBTestSetup.java index 6afb452412..3cd4f09eb6 100644 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractRIBTestSetup.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractRIBTestSetup.java @@ -171,7 +171,7 @@ public class AbstractRIBTestSetup extends DefaultRibPoliciesMockTest { localTables.add(new BgpTableTypeImpl(AFI, SAFI)); this.a1 = new RIBActivator(); - this.a1.startRIBExtensionProvider(context); + this.a1.startRIBExtensionProvider(context, this.mappingService); final CodecsRegistryImpl codecsRegistry = CodecsRegistryImpl.create(this.codecFactory, GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy()); diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathAllPathsTest.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathAllPathsTest.java index eaa429271e..dde75a677f 100644 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathAllPathsTest.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathAllPathsTest.java @@ -60,7 +60,7 @@ public class AddPathAllPathsTest extends AbstractAddPathTest { getDomBroker(), getDataBroker(), this.policies, this.peerTracker, TABLES_TYPE, pathTables); this.ribImpl.instantiateServiceInstance(); - this.ribImpl.onGlobalContextUpdated(this.schemaContext); + this.ribImpl.onGlobalContextUpdated(this.schemaService.getGlobalContext()); final ChannelFuture channelFuture = this.serverDispatcher.createServer(new InetSocketAddress(RIB_ID, PORT)); waitFutureSuccess(channelFuture); this.serverChannel = channelFuture.channel(); diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathBasePathsTest.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathBasePathsTest.java index a4f66d67e7..d8a3cb4331 100644 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathBasePathsTest.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathBasePathsTest.java @@ -46,7 +46,7 @@ public class AddPathBasePathsTest extends AbstractAddPathTest { this.serverDispatcher, this.codecsRegistry, getDomBroker(), getDataBroker(), this.policies, this.peerTracker, TABLES_TYPE, pathTables); this.ribImpl.instantiateServiceInstance(); - this.ribImpl.onGlobalContextUpdated(this.schemaContext); + this.ribImpl.onGlobalContextUpdated(this.schemaService.getGlobalContext()); final ChannelFuture channelFuture = this.serverDispatcher.createServer(new InetSocketAddress(RIB_ID, PORT)); waitFutureSuccess(channelFuture); this.serverChannel = channelFuture.channel(); diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathNPathsTest.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathNPathsTest.java index e29d1b9e7e..9b70c277d0 100644 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathNPathsTest.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AddPathNPathsTest.java @@ -47,7 +47,7 @@ public class AddPathNPathsTest extends AbstractAddPathTest { this.peerTracker, TABLES_TYPE, pathTables); this.ribImpl.instantiateServiceInstance(); - this.ribImpl.onGlobalContextUpdated(this.schemaContext); + this.ribImpl.onGlobalContextUpdated(this.schemaService.getGlobalContext()); final ChannelFuture channelFuture = this.serverDispatcher.createServer(new InetSocketAddress(RIB_ID, PORT)); waitFutureSuccess(channelFuture); this.serverChannel = channelFuture.channel(); diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserToSalTest.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserToSalTest.java index 8ea3c0abcf..e7b045e84c 100755 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserToSalTest.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserToSalTest.java @@ -93,8 +93,8 @@ public class ParserToSalTest extends DefaultRibPoliciesMockTest { this.baseact = new RIBActivator(); this.lsact = new org.opendaylight.protocol.bgp.linkstate.impl.RIBActivator(); - this.baseact.startRIBExtensionProvider(this.ext1); - this.lsact.startRIBExtensionProvider(this.ext2); + this.baseact.startRIBExtensionProvider(this.ext1, this.mappingService); + this.lsact.startRIBExtensionProvider(this.ext2, this.mappingService); this.codecsRegistry = CodecsRegistryImpl.create(this.bindingCodecTreeFactory, GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy()); } diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationAndExceptionTest.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationAndExceptionTest.java index ca81605da1..2715bb6409 100644 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationAndExceptionTest.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationAndExceptionTest.java @@ -211,7 +211,7 @@ public class SynchronizationAndExceptionTest extends AbstractAddPathTest { this.serverDispatcher, this.codecsRegistry, this.domBroker, getDataBroker(), this.policies, this.peerTracker, ImmutableList.of(this.ipv4tt), pathTables); ribImpl.instantiateServiceInstance(); - ribImpl.onGlobalContextUpdated(this.schemaContext); + ribImpl.onGlobalContextUpdated(this.schemaService.getGlobalContext()); final BGPPeer bgpPeer = new BGPPeer(neighbor, ribImpl, PeerRole.Ibgp, null, AFI_SAFIS_ADVERTIZED, Collections.emptySet()); @@ -259,7 +259,7 @@ public class SynchronizationAndExceptionTest extends AbstractAddPathTest { this.serverDispatcher, this.codecsRegistry, this.domBroker, getDataBroker(), this.policies, this.peerTracker, ImmutableList.of(this.ipv4tt), pathTables); ribImpl.instantiateServiceInstance(); - ribImpl.onGlobalContextUpdated(this.schemaContext); + ribImpl.onGlobalContextUpdated(this.schemaService.getGlobalContext()); final BGPPeer bgpPeer = new BGPPeer(neighbor, ribImpl, PeerRole.Ibgp, null, AFI_SAFIS_ADVERTIZED, Collections.emptySet()); diff --git a/bgp/rib-spi/pom.xml b/bgp/rib-spi/pom.xml index b4d38e1000..a9d151bb3d 100644 --- a/bgp/rib-spi/pom.xml +++ b/bgp/rib-spi/pom.xml @@ -14,9 +14,9 @@ 4.0.0 org.opendaylight.bgpcep - bgpcep-parent + binding-parent 0.10.0-SNAPSHOT - ../../parent + ../../binding-parent bgp-rib-spi @@ -113,6 +113,17 @@ mdsal-binding-dom-adapter test + + org.opendaylight.controller + sal-binding-broker-impl + test + + + org.opendaylight.controller + sal-binding-broker-impl + test + test-jar + diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBExtensionProviderActivator.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBExtensionProviderActivator.java index b3a457888d..566ebf3b92 100644 --- a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBExtensionProviderActivator.java +++ b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBExtensionProviderActivator.java @@ -12,6 +12,7 @@ import static java.util.Objects.requireNonNull; import com.google.common.base.Preconditions; import java.util.List; import javax.annotation.concurrent.GuardedBy; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,13 +23,17 @@ public abstract class AbstractRIBExtensionProviderActivator implements AutoClose private List registrations; @GuardedBy("this") - protected abstract List startRIBExtensionProviderImpl(RIBExtensionProviderContext context); + protected abstract List startRIBExtensionProviderImpl( + RIBExtensionProviderContext context, + BindingNormalizedNodeSerializer mappingService); @Override - public final synchronized void startRIBExtensionProvider(final RIBExtensionProviderContext context) { + public final synchronized void startRIBExtensionProvider( + final RIBExtensionProviderContext context, + final BindingNormalizedNodeSerializer mappingService) { Preconditions.checkState(this.registrations == null); - this.registrations = requireNonNull(startRIBExtensionProviderImpl(context)); + this.registrations = requireNonNull(startRIBExtensionProviderImpl(context, mappingService)); } @Override diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBSupport.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBSupport.java index e299c92759..65a389c3ca 100644 --- a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBSupport.java +++ b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBSupport.java @@ -15,6 +15,7 @@ import java.util.Collections; import java.util.Optional; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.UpdateBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; @@ -32,8 +33,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.BgpRib; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.Rib; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.RibKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.LocRib; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.AddressFamily; @@ -65,8 +72,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Beta -public abstract class AbstractRIBSupport - implements RIBSupport { +public abstract class AbstractRIBSupport< + C extends Routes & DataObject, + S extends DataObject, + R extends Route, + I extends Identifier> + implements RIBSupport { public static final String ROUTE_KEY = "route-key"; private static final Logger LOG = LoggerFactory.getLogger(AbstractRIBSupport.class); private static final NodeIdentifier ADVERTISED_ROUTES = new NodeIdentifier(AdvertizedRoutes.QNAME); @@ -77,9 +88,9 @@ public abstract class AbstractRIBSupport private final NodeIdentifier routesContainerIdentifier; private final NodeIdentifier routesListIdentifier; private final NodeIdentifier routeAttributesIdentifier; - private final Class cazeClass; - private final Class containerClass; - private final Class listClass; + private final Class cazeClass; + private final Class containerClass; + private final Class listClass; private final ApplyRoute putRoute = new PutRoute(); private final ChoiceNode emptyRoutes; private final QName routeQname; @@ -91,13 +102,14 @@ public abstract class AbstractRIBSupport private final QName routeKeyQname; private final NodeIdentifier prefixTypeNid; private final NodeIdentifier rdNid; + private final BindingNormalizedNodeSerializer mappingService; /** * Default constructor. Requires the QName of the container augmented under the routes choice * node in instantiations of the rib grouping. It is assumed that this container is defined by * the same model which populates it with route grouping instantiation, and by extension with * the route attributes container. - * @param cazeClass Binding class of the AFI/SAFI-specific case statement, must not be null + * @param cazeClass Binding class of the AFI/SAFI-specific case statement, must not be null * @param containerClass Binding class of the container in routes choice, must not be null. * @param listClass Binding class of the route list, nust not be null; * @param afiClass address Family Class @@ -105,9 +117,10 @@ public abstract class AbstractRIBSupport * @param destinationQname destination Qname */ protected AbstractRIBSupport( - final Class cazeClass, - final Class containerClass, - final Class listClass, + final BindingNormalizedNodeSerializer mappingService, + final Class cazeClass, + final Class containerClass, + final Class listClass, final Class afiClass, final Class safiClass, final QName destinationQname) { @@ -116,14 +129,22 @@ public abstract class AbstractRIBSupport this.routeAttributesIdentifier = new NodeIdentifier(QName.create(qname, Attributes.QNAME.getLocalName().intern())); this.cazeClass = requireNonNull(cazeClass); + this.mappingService = requireNonNull(mappingService); this.containerClass = requireNonNull(containerClass); this.listClass = requireNonNull(listClass); this.routeQname = QName.create(qname, BindingReflections.findQName(listClass).intern().getLocalName()); this.routesListIdentifier = new NodeIdentifier(this.routeQname); - this.emptyRoutes = Builders.choiceBuilder().withNodeIdentifier(ROUTES) - .addChild(Builders.containerBuilder() - .withNodeIdentifier(routesContainerIdentifier()) - .withChild(ImmutableNodes.mapNodeBuilder(this.routeQname).build()).build()).build(); + + final TablesKey tk = new TablesKey(afiClass, safiClass); + //FIXME Use Route Iid instead of Tables. + final InstanceIdentifier routeIID = InstanceIdentifier.create(BgpRib.class) + .child(Rib.class, new RibKey(requireNonNull(new RibId("rib")))) + .child(LocRib.class) + .child(Tables.class, tk); + this.emptyRoutes = (ChoiceNode) ((MapEntryNode) this.mappingService + .toNormalizedNode(routeIID, new TablesBuilder().setKey(tk) + .setRoutes(emptyRoutesCase()).build()).getValue()) + .getChild(new NodeIdentifier(BindingReflections.findQName(Routes.class))).get(); this.afiClass = afiClass; this.safiClass = safiClass; this.destinationNid = new NodeIdentifier(destinationQname); @@ -135,17 +156,17 @@ public abstract class AbstractRIBSupport } @Override - public final Class routesCaseClass() { + public final Class routesCaseClass() { return this.cazeClass; } @Override - public final Class routesContainerClass() { + public final Class routesContainerClass() { return this.containerClass; } @Override - public final Class routesListClass() { + public final Class routesListClass() { return this.listClass; } @@ -330,7 +351,7 @@ public abstract class AbstractRIBSupport @Override public final InstanceIdentifier createRouteIdentifier( - final KeyedInstanceIdentifier tableIId, final N key) { + final KeyedInstanceIdentifier tableIId, final I key) { return tableIId.child((Class) routesContainerClass()).child(routesListClass(), key); } @@ -448,7 +469,7 @@ public abstract class AbstractRIBSupport } protected final RouteDistinguisher extractRouteDistinguisher( - final DataContainerNode route) { + final DataContainerNode route) { if (route.getChild(this.rdNid).isPresent()) { return RouteDistinguisherBuilder.getDefaultInstance((String) route.getChild(this.rdNid).get().getValue()); } diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/RIBExtensionProviderActivator.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/RIBExtensionProviderActivator.java index 7be48989dd..c23cde1eeb 100644 --- a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/RIBExtensionProviderActivator.java +++ b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/RIBExtensionProviderActivator.java @@ -8,9 +8,12 @@ package org.opendaylight.protocol.bgp.rib.spi; import javax.annotation.Nonnull; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; public interface RIBExtensionProviderActivator { - void startRIBExtensionProvider(@Nonnull RIBExtensionProviderContext context); + void startRIBExtensionProvider( + @Nonnull RIBExtensionProviderContext context, + @Nonnull BindingNormalizedNodeSerializer mappingService); void stopRIBExtensionProvider(); } diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/RIBSupport.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/RIBSupport.java index b0b0cd73a0..7b39b1eacf 100644 --- a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/RIBSupport.java +++ b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/RIBSupport.java @@ -40,7 +40,11 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNod * to register an implementation of this class and the RIB core then calls into it * to inquire about details specific to that particular model. */ -public interface RIBSupport extends AddPathRibSupport { +public interface RIBSupport< + C extends Routes & DataObject, + S extends DataObject, + R extends Route, + I extends Identifier> { /** * Return the table-type-specific empty routes container, as augmented into the * bgp-rib model under /rib/tables/routes choice node. This needs to include all @@ -66,7 +70,7 @@ public interface RIBSupport extends AddPa * @return Class */ @Nonnull - Class routesCaseClass(); + Class routesCaseClass(); /** * Return class object of the Routes Container statement. @@ -74,7 +78,7 @@ public interface RIBSupport extends AddPa * @return Class */ @Nonnull - Class routesContainerClass(); + Class routesContainerClass(); /** * Return class object of the Routes List statement. @@ -82,7 +86,7 @@ public interface RIBSupport extends AddPa * @return Class */ @Nonnull - Class routesListClass(); + Class routesListClass(); @Nonnull default ImmutableCollection> cacheableAttributeObjects() { @@ -218,7 +222,7 @@ public interface RIBSupport extends AddPa @Nonnull InstanceIdentifier createRouteIdentifier( @Nonnull KeyedInstanceIdentifier tableKey, - @Nonnull N newRouteKey); + @Nonnull I newRouteKey); /** * Creates a route with new path Id and attributes. @@ -246,7 +250,18 @@ public interface RIBSupport extends AddPa * @return Protocol-specific case in the routes choice, may not be null. */ @Nonnull - Routes emptyRoutesContainer(); + C emptyRoutesCase(); + + /** + * Return the table-type-specific empty routes container, as augmented into the + * bgp-peer model under /peer/effect-rib-in/tables/routes choice node/routes container. This needs to include all + * the skeleton nodes under which the individual routes will be stored. + * + * @return Protocol-specific container in the routes, may not be null. + */ + @Nonnull + S emptyRoutesContainer(); + /** @@ -257,5 +272,5 @@ public interface RIBSupport extends AddPa * @return route list Key (RouteKey + pathId) */ @Nonnull - N createRouteListKey(@Nonnull long pathId, @Nonnull String routeKey); + I createRouteListKey(@Nonnull long pathId, @Nonnull String routeKey); } diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/ServiceLoaderRIBExtensionConsumerContext.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/ServiceLoaderRIBExtensionConsumerContext.java index e7c939974d..32928770be 100644 --- a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/ServiceLoaderRIBExtensionConsumerContext.java +++ b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/ServiceLoaderRIBExtensionConsumerContext.java @@ -11,6 +11,7 @@ import static java.util.Objects.requireNonNull; import com.google.common.annotations.VisibleForTesting; import java.util.ServiceLoader; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,20 +20,22 @@ public final class ServiceLoaderRIBExtensionConsumerContext extends SimpleRIBExt private static final Logger LOG = LoggerFactory.getLogger(ServiceLoaderRIBExtensionConsumerContext.class); private final ServiceLoader loader; - private ServiceLoaderRIBExtensionConsumerContext(final ServiceLoader loader) { + private ServiceLoaderRIBExtensionConsumerContext(final ServiceLoader loader, + final BindingNormalizedNodeSerializer mappingService) { this.loader = requireNonNull(loader); for (RIBExtensionProviderActivator a : loader) { - a.startRIBExtensionProvider(this); + a.startRIBExtensionProvider(this, mappingService); } } @VisibleForTesting - static ServiceLoaderRIBExtensionConsumerContext createConsumerContext() { + static ServiceLoaderRIBExtensionConsumerContext createConsumerContext( + final BindingNormalizedNodeSerializer mappingService) { final ServiceLoader loader = ServiceLoader.load(RIBExtensionProviderActivator.class); - return new ServiceLoaderRIBExtensionConsumerContext(loader); + return new ServiceLoaderRIBExtensionConsumerContext(loader, mappingService); } @Override diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionProviderContextActivator.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionProviderContextActivator.java index 02f22e5771..87a28e17dc 100644 --- a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionProviderContextActivator.java +++ b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionProviderContextActivator.java @@ -10,6 +10,7 @@ package org.opendaylight.protocol.bgp.rib.spi; import static java.util.Objects.requireNonNull; import java.util.List; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,18 +22,21 @@ public final class SimpleRIBExtensionProviderContextActivator implements AutoClo private final RIBExtensionProviderContext providerContext; private final List extensionActivators; + private final BindingNormalizedNodeSerializer mappingService; public SimpleRIBExtensionProviderContextActivator(final RIBExtensionProviderContext providerContext, - final List extensionActivators) { + final List extensionActivators, + final BindingNormalizedNodeSerializer mappingService) { this.providerContext = requireNonNull(providerContext); this.extensionActivators = requireNonNull(extensionActivators); + this.mappingService = requireNonNull(mappingService); } public void start() { LOG.info("Starting {} RIBExtensionProviderActivator instances", this.extensionActivators.size()); for (final RIBExtensionProviderActivator e : this.extensionActivators) { - e.startRIBExtensionProvider(this.providerContext); + e.startRIBExtensionProvider(this.providerContext, this.mappingService); } } diff --git a/bgp/rib-spi/src/main/resources/org/opendaylight/blueprint/bgp-rib-spi.xml b/bgp/rib-spi/src/main/resources/org/opendaylight/blueprint/bgp-rib-spi.xml index f7268d1b97..acbffe0e3f 100644 --- a/bgp/rib-spi/src/main/resources/org/opendaylight/blueprint/bgp-rib-spi.xml +++ b/bgp/rib-spi/src/main/resources/org/opendaylight/blueprint/bgp-rib-spi.xml @@ -13,13 +13,15 @@ META-INF/services/org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderActivator resources. --> - + + diff --git a/bgp/rib-spi/src/main/yang/bgp-test.yang b/bgp/rib-spi/src/main/yang/bgp-test.yang new file mode 100644 index 0000000000..1025d67f7c --- /dev/null +++ b/bgp/rib-spi/src/main/yang/bgp-test.yang @@ -0,0 +1,92 @@ +module bgp-test { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:bgp:test"; + prefix "bgp-inet"; + + import bgp-rib { prefix bgp-rib; revision-date 2018-03-29; } + import bgp-multiprotocol { prefix bgp-mp; revision-date 2018-03-29; } + import ietf-inet-types { prefix inet; revision-date 2013-07-15; } + import bgp-message { prefix bgp-msg; revision-date 2018-03-29; } + + organization "AT&T Services, Inc."; + contact "Claudio D. Gasparini "; + + description + "This module contains the base data model for test . + + Copyright (c) 2018 AT&T Intellectual Property. 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"; + + revision "2018-05-15" { + description "Initial test model"; + } + + grouping ipv4-prefixes { + container destination-ipv4 { + list ipv4-prefixes { + uses bgp-msg:ipv4-prefix-and-path-id; + } + } + } + + grouping ipv4-routes { + container ipv4-routes { + list ipv4-route { + key "route-key path-id"; + uses bgp-rib:route; + leaf prefix { + type inet:ipv4-prefix; + } + } + } + } + + augment "/bgp-msg:update/bgp-msg:attributes/bgp-mp:mp-reach-nlri/bgp-mp:advertized-routes/bgp-mp:destination-type" { + case destination-ipv4-case { + when "../../afi = ipv4"; + uses ipv4-prefixes; + } + } + + augment "/bgp-msg:update/bgp-msg:attributes/bgp-mp:mp-unreach-nlri/bgp-mp:withdrawn-routes/bgp-mp:destination-type" { + case destination-ipv4-case { + when "../../afi = ipv4"; + uses ipv4-prefixes; + } + } + + augment "/bgp-rib:application-rib/bgp-rib:tables/bgp-rib:routes" { + case ipv4-routes-case { + uses ipv4-routes; + } + } + + augment "/bgp-rib:bgp-rib/bgp-rib:rib/bgp-rib:loc-rib/bgp-rib:tables/bgp-rib:routes" { + case ipv4-routes-case { + uses ipv4-routes; + } + } + + augment "/bgp-rib:bgp-rib/bgp-rib:rib/bgp-rib:peer/bgp-rib:adj-rib-in/bgp-rib:tables/bgp-rib:routes" { + case ipv4-routes-case { + uses ipv4-routes; + } + } + + augment "/bgp-rib:bgp-rib/bgp-rib:rib/bgp-rib:peer/bgp-rib:effective-rib-in/bgp-rib:tables/bgp-rib:routes" { + case ipv4-routes-case { + uses ipv4-routes; + } + } + + augment "/bgp-rib:bgp-rib/bgp-rib:rib/bgp-rib:peer/bgp-rib:adj-rib-out/bgp-rib:tables/bgp-rib:routes" { + case ipv4-routes-case { + uses ipv4-routes; + } + } +} + diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBActivatorTest.java b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBActivatorTest.java new file mode 100644 index 0000000000..8516765478 --- /dev/null +++ b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AbstractRIBActivatorTest.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2018 AT&T Intellectual Property. 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.rib.spi; + +import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest; +import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTestCustomizer; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; + +public abstract class AbstractRIBActivatorTest extends AbstractConcurrentDataBrokerTest { + protected BindingNormalizedNodeSerializer mappingService; + + @Override + protected final AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() { + final AbstractDataBrokerTestCustomizer customizer = super.createDataBrokerTestCustomizer(); + this.mappingService = customizer.getBindingToNormalized(); + return customizer; + } +} 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 c4b60b43ad..c44e012fff 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 @@ -18,18 +18,14 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; -import javassist.ClassPool; -import org.junit.After; import org.junit.Before; import org.mockito.Mock; +import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest; +import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTestCustomizer; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; -import org.opendaylight.mdsal.binding.dom.adapter.BindingToNormalizedNodeCodec; -import org.opendaylight.mdsal.binding.dom.codec.gen.impl.StreamWriterGenerator; -import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry; -import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; -import org.opendaylight.mdsal.binding.generator.util.JavassistUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; @@ -45,6 +41,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.BgpRib; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.Rib; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.RibKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.LocRib; @@ -65,7 +62,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.MapNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -public abstract class AbstractRIBSupportTest { +public abstract class AbstractRIBSupportTest extends AbstractConcurrentDataBrokerTest { protected static final PathId PATH_ID = new PathId(1L); protected static final Attributes ATTRIBUTES = new AttributesBuilder().build(); private static final InstanceIdentifier RIB = InstanceIdentifier.builder(BgpRib.class) @@ -76,21 +73,23 @@ public abstract class AbstractRIBSupportTest { .augmentation(Attributes2.class).child(MpUnreachNlri.class); private static final InstanceIdentifier MP_REACH_IID = ATTRIBUTES_IID.augmentation(Attributes1.class) .child(MpReachNlri.class); - @Mock protected DOMDataWriteTransaction tx; - protected List> deletedRoutes; + protected List> deletedRoutes; protected List, DataObject>> insertedRoutes; - private BindingToNormalizedNodeCodec mappingService; + protected BindingNormalizedNodeSerializer mappingService; private AbstractRIBSupport abstractRIBSupport; private ModuleInfoBackedContext moduleInfoBackedContext; protected final void setUpTestCustomizer(final AbstractRIBSupport ribSupport) throws Exception { this.abstractRIBSupport = ribSupport; - this.moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(this.abstractRIBSupport - .routesContainerClass())); - this.mappingService.onGlobalContextUpdated(this.moduleInfoBackedContext.tryToCreateSchemaContext().get()); + this.moduleInfoBackedContext + .registerModuleInfo(BindingReflections.getModuleInfo(this.abstractRIBSupport.routesContainerClass())); + this.moduleInfoBackedContext + .registerModuleInfo(BindingReflections.getModuleInfo(this.abstractRIBSupport.routesCaseClass())); + this.moduleInfoBackedContext + .registerModuleInfo(BindingReflections.getModuleInfo(this.abstractRIBSupport.routesListClass())); } @Before @@ -106,20 +105,22 @@ public abstract class AbstractRIBSupportTest { doAnswer(invocation -> { final Object[] args = invocation.getArguments(); - AbstractRIBSupportTest.this.deletedRoutes.add(AbstractRIBSupportTest.this.mappingService - .fromYangInstanceIdentifier((YangInstanceIdentifier) args[1])); + AbstractRIBSupportTest.this.deletedRoutes.add((InstanceIdentifier) + this.mappingService.fromYangInstanceIdentifier((YangInstanceIdentifier) args[1])); return args[1]; }).when(this.tx).delete(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class)); this.deletedRoutes = new ArrayList<>(); this.insertedRoutes = new ArrayList<>(); - - this.mappingService = new BindingToNormalizedNodeCodec(GeneratedClassLoadingStrategy - .getTCCLClassLoadingStrategy(), - new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator - .create(JavassistUtils.forClassPool(ClassPool.getDefault())))); this.moduleInfoBackedContext = ModuleInfoBackedContext.create(); } + @Override + protected final AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() { + final AbstractDataBrokerTestCustomizer customizer = super.createDataBrokerTestCustomizer(); + this.mappingService = customizer.getBindingToNormalized(); + return customizer; + } + protected final ContainerNode createNlriWithDrawnRoute(final DestinationType destUnreach) { final MpUnreachNlri mpReach = new MpUnreachNlriBuilder().setWithdrawnRoutes(new WithdrawnRoutesBuilder() .setDestinationType(destUnreach).build()).build(); @@ -190,9 +191,4 @@ public abstract class AbstractRIBSupportTest { final Collection map = createRoutes(routes); return Iterables.getOnlyElement(map).getIdentifier(); } - - @After - public final void tearDown() { - this.mappingService.close(); - } } diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/RIBSupportTest.java b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/RIBSupportTest.java index 938266676d..7d3d3ac7cd 100644 --- a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/RIBSupportTest.java +++ b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/RIBSupportTest.java @@ -10,6 +10,7 @@ package org.opendaylight.protocol.bgp.rib.spi; import static junit.framework.TestCase.assertFalse; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doAnswer; @@ -22,19 +23,16 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Optional; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; +import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest; +import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTestCustomizer; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes.Ipv4Prefixes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes.Ipv4Route; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes.Ipv4Routes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes.Ipv4RoutesCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes.RIBSupportTestImp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.UpdateBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder; @@ -56,6 +54,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib. import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.test.rev180515.Ipv4Prefixes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.test.rev180515.bgp.rib.rib.loc.rib.tables.routes.Ipv4RoutesCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.test.rev180515.ipv4.routes.Ipv4Routes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.test.rev180515.ipv4.routes.ipv4.routes.Ipv4Route; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCase; @@ -74,13 +76,13 @@ import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; -public class RIBSupportTest { +public class RIBSupportTest extends AbstractConcurrentDataBrokerTest { private static final String ROUTE_KEY = "prefix"; private static final String PREFIX = "1.2.3.4/32"; private static final QName PATH_ID_QNAME = QName.create(Ipv4Route.QNAME, "path-id").intern(); private static final NodeIdentifierWithPredicates PREFIX_NII = new NodeIdentifierWithPredicates(Ipv4Route.QNAME, ImmutableMap.of(QName.create(Ipv4Route.QNAME, ROUTE_KEY).intern(), PREFIX)); - private static final RIBSupportTestImp ABSTRACT_RIB_SUPP_TEST = new RIBSupportTestImp(); + private RIBSupportTestImp ribSupportTestImp; private static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class); private static final YangInstanceIdentifier LOC_RIB_TARGET = YangInstanceIdentifier @@ -93,14 +95,16 @@ public class RIBSupportTest { private DataTreeCandidateNode subTree; private DOMDataWriteTransaction tx; private ContainerNode nlri; - private Map> routesMap; + private Map> routesMap = new HashMap<>(); private ContainerNode attributes; private MapEntryNode mapEntryNode; + private BindingToNormalizedNodeCodec mappingService; @Before - public void setUp() { - this.routesMap = new HashMap<>(); + public void setUp() throws Exception { + super.setup(); MockitoAnnotations.initMocks(this); + this.ribSupportTestImp = new RIBSupportTestImp(this.mappingService); this.emptyTree = Mockito.mock(DataTreeCandidateNode.class); this.emptySubTree = Mockito.mock(DataTreeCandidateNode.class); this.subTree = Mockito.mock(DataTreeCandidateNode.class); @@ -136,13 +140,13 @@ public class RIBSupportTest { doAnswer(invocation -> { final Object[] args = invocation.getArguments(); - RIBSupportTest.this.routesMap.remove(args[1]); + this.routesMap.remove(args[1]); return args[1]; }).when(this.tx).delete(Mockito.eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class)); doAnswer(invocation -> { final Object[] args = invocation.getArguments(); final NormalizedNode node1 = (NormalizedNode) args[2]; - RIBSupportTest.this.routesMap.put((YangInstanceIdentifier) args[1], node1); + this.routesMap.put((YangInstanceIdentifier) args[1], node1); return args[1]; }).when(this.tx).put(Mockito.eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class)); @@ -150,90 +154,97 @@ public class RIBSupportTest { this.mapEntryNode = Mockito.mock(MapEntryNode.class); } + @Override + protected final AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() { + final AbstractDataBrokerTestCustomizer customizer = super.createDataBrokerTestCustomizer(); + this.mappingService = customizer.getBindingToNormalized(); + return customizer; + } + @Test public void pathIdQName() { - assertEquals(PATH_ID_QNAME, ABSTRACT_RIB_SUPP_TEST.pathIdQName()); + assertEquals(PATH_ID_QNAME,this.ribSupportTestImp.pathIdQName()); } @Test public void routesCaseClass() { - assertEquals(Ipv4RoutesCase.class, ABSTRACT_RIB_SUPP_TEST.routesCaseClass()); + assertEquals(Ipv4RoutesCase.class,this.ribSupportTestImp.routesCaseClass()); } @Test public void routesContainerClass() { - assertEquals(Ipv4Routes.class, ABSTRACT_RIB_SUPP_TEST.routesContainerClass()); + assertEquals(Ipv4Routes.class,this.ribSupportTestImp.routesContainerClass()); } @Test public void routesListClass() { - assertEquals(Ipv4Route.class, ABSTRACT_RIB_SUPP_TEST.routesListClass()); + assertEquals(Ipv4Route.class,this.ribSupportTestImp.routesListClass()); } @Test public void routeQName() { - assertEquals(Ipv4Route.QNAME, ABSTRACT_RIB_SUPP_TEST.routeQName()); + assertEquals(Ipv4Route.QNAME,this.ribSupportTestImp.routeQName()); } @Test public void emptyRoutes() { final ChoiceNode emptyRoutes = Builders.choiceBuilder().withNodeIdentifier(ROUTES_IDENTIFIER) .addChild(Builders.containerBuilder().withNodeIdentifier(IPV4_ROUTES_IDENTIFIER) - .withChild(ImmutableNodes.mapNodeBuilder(ABSTRACT_RIB_SUPP_TEST.routeQName()) + .withChild(ImmutableNodes.mapNodeBuilder(ribSupportTestImp.routeQName()) .build()).build()).build(); - assertEquals(emptyRoutes, ABSTRACT_RIB_SUPP_TEST.emptyRoutes()); + assertEquals(emptyRoutes,this.ribSupportTestImp.emptyRoutes()); } @Test public void routeNid() { - assertEquals(new NodeIdentifier(Ipv4Route.QNAME), ABSTRACT_RIB_SUPP_TEST.routeNid()); + assertEquals(new NodeIdentifier(Ipv4Route.QNAME),this.ribSupportTestImp.routeNid()); } @Test public void getAfi() { - assertEquals(Ipv4AddressFamily.class, ABSTRACT_RIB_SUPP_TEST.getAfi()); + assertEquals(Ipv4AddressFamily.class,this.ribSupportTestImp.getAfi()); } @Test public void getSafi() { - assertEquals(UnicastSubsequentAddressFamily.class, ABSTRACT_RIB_SUPP_TEST.getSafi()); + assertEquals(UnicastSubsequentAddressFamily.class,this.ribSupportTestImp.getSafi()); } @Test public void routesContainerIdentifier() { - assertEquals(IPV4_ROUTES_IDENTIFIER, ABSTRACT_RIB_SUPP_TEST.routesContainerIdentifier()); + assertEquals(IPV4_ROUTES_IDENTIFIER,this.ribSupportTestImp.routesContainerIdentifier()); } @Test public void routeAttributesIdentifier() { assertEquals(new NodeIdentifier(QName.create(Ipv4Routes.QNAME, - Attributes.QNAME.getLocalName().intern())), ABSTRACT_RIB_SUPP_TEST.routeAttributesIdentifier()); + Attributes.QNAME.getLocalName().intern())),this.ribSupportTestImp.routeAttributesIdentifier()); } @Test public void routePath() { - Assert.assertEquals(LOC_RIB_TARGET.node(ROUTES_IDENTIFIER) + assertEquals(LOC_RIB_TARGET.node(ROUTES_IDENTIFIER) .node(Ipv4Routes.QNAME).node(Ipv4Route.QNAME).node(PREFIX_NII), - ABSTRACT_RIB_SUPP_TEST.routePath(LOC_RIB_TARGET.node(Routes.QNAME), PREFIX_NII)); + this.ribSupportTestImp.routePath(LOC_RIB_TARGET.node(Routes.QNAME), PREFIX_NII)); } @Test public void changedRoutes() { - Assert.assertTrue(ABSTRACT_RIB_SUPP_TEST.changedRoutes(this.emptyTree).isEmpty()); - Assert.assertTrue(ABSTRACT_RIB_SUPP_TEST.changedRoutes(this.emptySubTree).isEmpty()); - Assert.assertNotNull(ABSTRACT_RIB_SUPP_TEST.changedRoutes(this.subTree)); + assertTrue(ribSupportTestImp.changedRoutes(this.emptyTree).isEmpty()); + assertTrue(ribSupportTestImp.changedRoutes(this.emptySubTree).isEmpty()); + assertNotNull(ribSupportTestImp.changedRoutes(this.subTree)); } @Test public void putRoutes() { - ABSTRACT_RIB_SUPP_TEST.putRoutes(this.tx, LOC_RIB_TARGET, this.nlri, this.attributes); + this.ribSupportTestImp.putRoutes(this.tx, LOC_RIB_TARGET, this.nlri, this.attributes); assertFalse(this.routesMap.isEmpty()); } @Test public void deleteRoutes() { - ABSTRACT_RIB_SUPP_TEST.deleteRoutes(this.tx, LOC_RIB_TARGET, this.nlri); + this.ribSupportTestImp.deleteRoutes(this.tx, LOC_RIB_TARGET, this.nlri); assertTrue(this.routesMap.isEmpty()); } @@ -246,7 +257,7 @@ public class RIBSupportTest { final Collection routes = new HashSet<>(); assertEquals(new UpdateBuilder().setAttributes(new AttributesBuilder().build()).build(), - ABSTRACT_RIB_SUPP_TEST.buildUpdate(routes, routes, attr)); + this.ribSupportTestImp.buildUpdate(routes, routes, attr)); routes.add(this.mapEntryNode); final MpReachNlri mpReach = new MpReachNlriBuilder().setAfi(Ipv4AddressFamily.class) @@ -256,7 +267,7 @@ public class RIBSupportTest { final Attributes attMpR = new AttributesBuilder().addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mpReach).build()).build(); assertEquals(new UpdateBuilder().setAttributes(attMpR).build(), - ABSTRACT_RIB_SUPP_TEST.buildUpdate(routes, Collections.emptySet(), attr)); + this.ribSupportTestImp.buildUpdate(routes, Collections.emptySet(), attr)); final MpUnreachNlri mpUnreach = new MpUnreachNlriBuilder().setAfi(Ipv4AddressFamily.class) .setSafi(UnicastSubsequentAddressFamily.class) @@ -265,6 +276,6 @@ public class RIBSupportTest { final Attributes attMpU = new AttributesBuilder().addAugmentation(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(mpUnreach).build()).build(); assertEquals(new UpdateBuilder().setAttributes(attMpU).build(), - ABSTRACT_RIB_SUPP_TEST.buildUpdate(Collections.emptySet(), routes, attr)); + this.ribSupportTestImp.buildUpdate(Collections.emptySet(), routes, attr)); } } \ No newline at end of file diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/RIBSupportTestImp.java b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/RIBSupportTestImp.java new file mode 100644 index 0000000000..b5bd3ee65f --- /dev/null +++ b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/RIBSupportTestImp.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2018 AT&T Intellectual Property. 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.rib.spi; + +import com.google.common.collect.ImmutableMap; +import java.util.Collection; +import java.util.Collections; +import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.test.rev180515.Ipv4Prefixes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.test.rev180515.bgp.rib.rib.loc.rib.tables.routes.Ipv4RoutesCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.test.rev180515.bgp.rib.rib.loc.rib.tables.routes.Ipv4RoutesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.test.rev180515.ipv4.routes.Ipv4Routes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.test.rev180515.ipv4.routes.Ipv4RoutesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.test.rev180515.ipv4.routes.ipv4.routes.Ipv4Route; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.test.rev180515.ipv4.routes.ipv4.routes.Ipv4RouteKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; +import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; + +public final class RIBSupportTestImp extends AbstractRIBSupport { + private static final String ROUTE_KEY = "prefix"; + private static final String PREFIX = "1.2.3.4/32"; + + private static final NodeIdentifierWithPredicates PREFIX_NII = new NodeIdentifierWithPredicates(Ipv4Route.QNAME, + ImmutableMap.of(QName.create(Ipv4Route.QNAME, ROUTE_KEY).intern(), PREFIX)); + + public RIBSupportTestImp(final BindingNormalizedNodeSerializer mappingService) { + super(mappingService, Ipv4RoutesCase.class, Ipv4Routes.class, Ipv4Route.class, Ipv4AddressFamily.class, + UnicastSubsequentAddressFamily.class, Ipv4Prefixes.QNAME); + } + + @Override + protected DestinationType buildDestination(final Collection routes) { + return null; + } + + @Override + protected DestinationType buildWithdrawnDestination(final Collection routes) { + return null; + } + + @Override + protected void processDestination(final DOMDataWriteTransaction tx, final YangInstanceIdentifier routesPath, + final ContainerNode destination, final ContainerNode attributes, final ApplyRoute applyFunction) { + applyFunction.apply(tx, routesPath.node(Ipv4Route.QNAME), PREFIX_NII, destination, attributes); + } + + @Override + public Ipv4Route createRoute(final Ipv4Route route, final String routeKey, final long pathId, + final Attributes attributes) { + return null; + } + + @Override + public Ipv4RoutesCase emptyRoutesCase() { + return new Ipv4RoutesCaseBuilder().setIpv4Routes(emptyRoutesContainer()).build(); + } + + @Override + public Ipv4Routes emptyRoutesContainer() { + return new Ipv4RoutesBuilder().setIpv4Route(Collections.emptyList()).build(); + } + + @Override + public Ipv4RouteKey createRouteListKey(final long pathId, final String routeKey) { + return new Ipv4RouteKey(new PathId(pathId), routeKey); + } +} \ No newline at end of file diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionProviderContextActivatorTest.java b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionProviderContextActivatorTest.java index 7be665a242..331667f163 100644 --- a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionProviderContextActivatorTest.java +++ b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionProviderContextActivatorTest.java @@ -14,16 +14,17 @@ import static org.junit.Assert.assertTrue; import java.util.Collections; import java.util.List; import org.junit.Test; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; -public class SimpleRIBExtensionProviderContextActivatorTest { +public class SimpleRIBExtensionProviderContextActivatorTest extends AbstractRIBActivatorTest { private static boolean RIBACTIVATED; @Test - public void test() throws Exception { + public void test() { final List extensionActivators = Collections.singletonList(new RibActivator()); final SimpleRIBExtensionProviderContextActivator activator = new SimpleRIBExtensionProviderContextActivator(new SimpleRIBExtensionProviderContext(), - extensionActivators); + extensionActivators, this.mappingService); activator.start(); assertTrue(RIBACTIVATED); activator.close(); @@ -32,7 +33,9 @@ public class SimpleRIBExtensionProviderContextActivatorTest { private static class RibActivator extends AbstractRIBExtensionProviderActivator { @Override - protected List startRIBExtensionProviderImpl(final RIBExtensionProviderContext context) { + protected List startRIBExtensionProviderImpl( + final RIBExtensionProviderContext context, + final BindingNormalizedNodeSerializer mappingService) { RIBACTIVATED = true; return Collections.singletonList(() -> RIBACTIVATED = false); } diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionTest.java b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionTest.java index 8b93273719..13de212c60 100644 --- a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionTest.java +++ b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/SimpleRIBExtensionTest.java @@ -7,25 +7,37 @@ */ package org.opendaylight.protocol.bgp.rib.spi; -import com.google.common.collect.Lists; +import java.util.Collections; import java.util.List; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; +import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; +import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest; +import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTestCustomizer; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily; import org.opendaylight.yangtools.yang.binding.DataObject; -public class SimpleRIBExtensionTest { +public class SimpleRIBExtensionTest extends AbstractConcurrentDataBrokerTest { + private BindingToNormalizedNodeCodec codec; + + @Override + protected final AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() { + final AbstractDataBrokerTestCustomizer customizer = super.createDataBrokerTestCustomizer(); + this.codec = customizer.getBindingToNormalized(); + return customizer; + } @Test public void testExtensionProvider() { final ServiceLoaderRIBExtensionConsumerContext ctx = - ServiceLoaderRIBExtensionConsumerContext.createConsumerContext(); + ServiceLoaderRIBExtensionConsumerContext.createConsumerContext(this.codec); Assert.assertNull(ctx.getRIBSupport(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class)); final TestActivator act = new TestActivator(); - act.startRIBExtensionProvider(ctx); + act.startRIBExtensionProvider(ctx, this.codec); Assert.assertNotNull(ctx.getRIBSupport(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class)); act.close(); Assert.assertNull(ctx.getRIBSupport(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class)); @@ -34,12 +46,14 @@ public class SimpleRIBExtensionTest { private final class TestActivator extends AbstractRIBExtensionProviderActivator { @Override - protected List startRIBExtensionProviderImpl(final RIBExtensionProviderContext context) { + protected List startRIBExtensionProviderImpl( + final RIBExtensionProviderContext context, + final BindingNormalizedNodeSerializer mappingService) { final RIBSupport support = Mockito.mock(RIBSupport.class); Mockito.doReturn(Route.class).when(support).routesListClass(); Mockito.doReturn(DataObject.class).when(support).routesContainerClass(); Mockito.doReturn(DataObject.class).when(support).routesCaseClass(); - return Lists.newArrayList((AutoCloseable)context.registerRIBSupport(Ipv4AddressFamily.class, + return Collections.singletonList((AutoCloseable) context.registerRIBSupport(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, support)); } } diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Prefixes.java b/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Prefixes.java deleted file mode 100644 index e050ee87c7..0000000000 --- a/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Prefixes.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes; - -import org.opendaylight.yangtools.yang.common.QName; - -public interface Ipv4Prefixes { - QName QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet", - "2015-03-05", "ipv4-prefixes").intern(); -} diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Route.java b/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Route.java deleted file mode 100644 index 00070f29cd..0000000000 --- a/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Route.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route; -import org.opendaylight.yangtools.yang.common.QName; - -public interface Ipv4Route extends Route { - QName QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet", - "2015-03-05", "ipv4-route").intern(); -} diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Routes.java b/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Routes.java deleted file mode 100644 index d1f684550b..0000000000 --- a/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4Routes.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes; - -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.common.QName; - -public interface Ipv4Routes extends DataObject { - QName QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet", - "2015-03-05", "ipv4-routes").intern(); -} diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4RoutesCase.java b/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4RoutesCase.java deleted file mode 100644 index 510e73c6b1..0000000000 --- a/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/Ipv4RoutesCase.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes; - - -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes; -import org.opendaylight.yangtools.yang.common.QName; - -public interface Ipv4RoutesCase extends Routes { - QName QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet", - "2015-03-05", "ipv4-routes-case").intern(); -} diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/RIBSupportTestImp.java b/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/RIBSupportTestImp.java deleted file mode 100644 index a653da9994..0000000000 --- a/bgp/rib-spi/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bgp/inet/rev150305/ipv4/routes/ipv4/routes/RIBSupportTestImp.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes; - -import com.google.common.collect.ImmutableMap; -import java.util.Collection; -import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; -import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupport; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.destination.DestinationType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.tables.Routes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily; -import org.opendaylight.yangtools.yang.binding.Identifier; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; -import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; - -public final class RIBSupportTestImp extends AbstractRIBSupport { - private static final String ROUTE_KEY = "prefix"; - private static final String PREFIX = "1.2.3.4/32"; - - private static final NodeIdentifierWithPredicates PREFIX_NII = new NodeIdentifierWithPredicates(org.opendaylight - .yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes.Ipv4Route.QNAME, - ImmutableMap.of(QName.create(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet - .rev180329.ipv4.routes.ipv4.routes.Ipv4Route.QNAME, ROUTE_KEY).intern(), PREFIX)); - - public RIBSupportTestImp() { - super(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4 - .routes.Ipv4RoutesCase.class, - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4. - routes.Ipv4Routes.class, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp - .inet.rev180329.ipv4.routes.ipv4.routes.Ipv4Route.class, Ipv4AddressFamily.class, - UnicastSubsequentAddressFamily.class, org.opendaylight.yang.gen.v1.urn.opendaylight.params - .xml.ns.yang.bgp.inet.rev180329.ipv4.routes.ipv4.routes.Ipv4Prefixes.QNAME); - } - - @Override - protected DestinationType buildDestination(final Collection routes) { - return null; - } - - @Override - protected DestinationType buildWithdrawnDestination(final Collection routes) { - return null; - } - - @Override - protected void processDestination(final DOMDataWriteTransaction tx, final YangInstanceIdentifier routesPath, - final ContainerNode destination, final ContainerNode attributes, final ApplyRoute applyFunction) { - applyFunction.apply(tx, routesPath.node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang - .bgp.inet.rev180329.ipv4.routes.ipv4.routes.Ipv4Route.QNAME), PREFIX_NII, destination, attributes); - } - - @Override - public Route createRoute(final Route route, final String routeKey, final long pathId, final Attributes attributes) { - return null; - } - - @Override - public Routes emptyRoutesContainer() { - return null; - } - - @Override - public Identifier createRouteListKey(final long pathId, final String routeKey) { - return null; - } -} \ No newline at end of file diff --git a/bmp/bmp-impl/src/test/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitorImplTest.java b/bmp/bmp-impl/src/test/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitorImplTest.java index 55eb29449b..a9c15fed9a 100644 --- a/bmp/bmp-impl/src/test/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitorImplTest.java +++ b/bmp/bmp-impl/src/test/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitorImplTest.java @@ -35,22 +35,17 @@ import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import java.net.InetSocketAddress; import java.util.List; -import javassist.ClassPool; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec; import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest; +import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTestCustomizer; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; -import org.opendaylight.mdsal.binding.dom.adapter.BindingToNormalizedNodeCodec; -import org.opendaylight.mdsal.binding.dom.codec.gen.impl.StreamWriterGenerator; -import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry; -import org.opendaylight.mdsal.binding.generator.impl.GeneratedClassLoadingStrategy; -import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; -import org.opendaylight.mdsal.binding.generator.util.JavassistUtils; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration; @@ -74,22 +69,14 @@ import org.opendaylight.protocol.util.CheckUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.bmp.monitor.monitor.router.peer.pre.policy.rib.tables.routes.Ipv4RoutesCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4Case; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.BgpParameters; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.MultiprotocolCapability; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.AdjRibInType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.InitiationMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.PeerType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.RouteMirroringMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.StatsReportsMessage; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.peer.up.ReceivedOpen; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.peer.up.SentOpen; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev180329.stat.Tlvs; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev180329.BmpMonitor; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev180329.MonitorId; @@ -108,7 +95,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.moni import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev180329.routers.RouterKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.util.BindingReflections; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; @@ -150,6 +136,8 @@ public class BmpMonitorImplTest extends AbstractConcurrentDataBrokerTest { @Before public void setUp() throws Exception { + super.setup(); + MockitoAnnotations.initMocks(this); doAnswer(invocationOnMock -> { @@ -170,23 +158,10 @@ public class BmpMonitorImplTest extends AbstractConcurrentDataBrokerTest { doAnswer(invocationOnMock -> BmpMonitorImplTest.this.singletonService2.closeServiceInstance()) .when(this.singletonServiceRegistration2).close(); - this.mappingService = new BindingToNormalizedNodeCodec(GeneratedClassLoadingStrategy - .getTCCLClassLoadingStrategy(), - new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator - .create(JavassistUtils.forClassPool(ClassPool.getDefault())))); - final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create(); - moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(InitiationMessage.class)); - moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(CParameters1.class)); - moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(BgpParameters.class)); - moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(MultiprotocolCapability.class)); - moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(DestinationIpv4Case.class)); - moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(AdvertizedRoutes.class)); - moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(SentOpen.class)); - moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(ReceivedOpen.class)); - this.mappingService.onGlobalContextUpdated(moduleInfoBackedContext.tryToCreateSchemaContext().get()); + this.mappingService.onGlobalContextUpdated(getSchemaContext()); this.ribActivator = new RIBActivator(); this.ribExtension = new SimpleRIBExtensionProviderContext(); - this.ribActivator.startRIBExtensionProvider(this.ribExtension); + this.ribActivator.startRIBExtensionProvider(this.ribExtension, this.mappingService); this.bgpActivator = new BGPActivator(); final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext(); @@ -207,7 +182,7 @@ public class BmpMonitorImplTest extends AbstractConcurrentDataBrokerTest { new NodeIdentifier(BmpMonitor.QNAME)) .addChild(ImmutableNodes.mapNodeBuilder(Monitor.QNAME).build()).build(); wTx.merge(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.of(BmpMonitor.QNAME), parentNode); - wTx.submit(); + wTx.commit().get(); final BmpDeployerDependencies bmpDependecies = new BmpDeployerDependencies(getDataBroker(), getDomBroker(), this.ribExtension, this.mappingService.getCodecFactory(), getSchemaContext(), this.clusterSSProv); @@ -223,6 +198,13 @@ public class BmpMonitorImplTest extends AbstractConcurrentDataBrokerTest { }); } + @Override + protected final AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() { + final AbstractDataBrokerTestCustomizer customizer = super.createDataBrokerTestCustomizer(); + this.mappingService = customizer.getBindingToNormalized(); + return customizer; + } + @After public void tearDown() throws Exception { this.ribActivator.close(); @@ -487,7 +469,7 @@ public class BmpMonitorImplTest extends AbstractConcurrentDataBrokerTest { b.option(ChannelOption.SO_KEEPALIVE, true); b.handler(new ChannelInitializer() { @Override - protected void initChannel(final SocketChannel ch) throws Exception { + protected void initChannel(final SocketChannel ch) { ch.pipeline().addLast(hf.getDecoders()); ch.pipeline().addLast(hf.getEncoders()); } -- 2.36.6