X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=bgp%2Frib-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fbgp%2Frib%2Fimpl%2FEffectiveRibInWriter.java;h=993b34f6938e3bbabb38eb5893491d7e3bd3dbf8;hb=0fdeddbe3d072a88428599421191f0f60b2864e4;hp=aa0fdea0f4ff6aee4d563fec1784b89616206a4f;hpb=6bd5db95cc6b8614a5a1d0f750190fb7fd06776d;p=bgpcep.git 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 aa0fdea0f4..993b34f693 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 @@ -32,16 +32,15 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.LongAdder; -import javax.annotation.Nonnull; -import javax.annotation.concurrent.GuardedBy; -import javax.annotation.concurrent.NotThreadSafe; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.dom.api.ClusteredDOMDataTreeChangeListener; -import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService; -import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier; -import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; -import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; +import org.checkerframework.checker.lock.qual.GuardedBy; +import org.checkerframework.checker.lock.qual.Holding; import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener; +import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService; +import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; +import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction; +import org.opendaylight.mdsal.dom.api.DOMTransactionChain; import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer; import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunityUtil; import org.opendaylight.protocol.bgp.rib.impl.spi.RIB; @@ -57,16 +56,16 @@ import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryImportParameter import org.opendaylight.protocol.bgp.route.targetcontrain.spi.ClientRouteTargetContrainCache; import org.opendaylight.protocol.bgp.route.targetcontrain.spi.RouteTargetMembeshipUtil; import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.AfiSafiType; -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.attributes.Communities; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.Communities; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole; 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.route.target.constrain.rev180618.RouteTargetConstrainSubsequentAddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.route.target.constrain.rev180618.route.target.constrain.routes.route.target.constrain.routes.RouteTargetConstrainRoute; -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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.MplsLabeledVpnSubsequentAddressFamily; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.RouteTarget; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv6AddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.MplsLabeledVpnSubsequentAddressFamily; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteTarget; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; @@ -97,8 +96,10 @@ import org.slf4j.LoggerFactory; * 2) check if a route is admissible based on attributes attached to it, as well as the * advertising peer's role * 3) output admitting routes with edited attributes into /bgp-rib/rib/peer/effective-rib-in/tables/routes + * + *

+ * This class is NOT thread-safe. */ -@NotThreadSafe final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesInstalledCounters, AutoCloseable, ClusteredDOMDataTreeChangeListener { @@ -110,7 +111,7 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn private static final ImmutableList STALE_LLGR_COMMUNUTIES = ImmutableList.of( StaleCommunities.STALE_LLGR); private static final Attributes STALE_LLGR_ATTRIBUTES = new org.opendaylight.yang.gen.v1.urn.opendaylight.params - .xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder() + .xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder() .setCommunities(STALE_LLGR_COMMUNUTIES) .build(); private static final ChoiceNode EMPTY_ROUTES = Builders.choiceBuilder().withNodeIdentifier(ROUTES_NID).build(); @@ -171,14 +172,14 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn } @Override - public synchronized void onDataTreeChanged(@Nonnull final Collection changes) { + public synchronized void onDataTreeChanged(final Collection changes) { if (this.chain == null) { LOG.trace("Chain closed. Ignoring Changes : {}", changes); return; } LOG.trace("Data changed called to effective RIB. Change : {}", changes); - DOMDataWriteTransaction tx = null; + DOMDataTreeWriteTransaction tx = null; for (final DataTreeCandidate tc : changes) { final YangInstanceIdentifier rootPath = tc.getRootPath(); final DataTreeCandidateNode root = tc.getRootNode(); @@ -268,8 +269,8 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn return this.prefixesInstalled.values().stream().mapToLong(LongAdder::longValue).sum(); } - @GuardedBy("this") - private void changeDataTree(final DOMDataWriteTransaction tx, final YangInstanceIdentifier rootPath, + @Holding("this") + private void changeDataTree(final DOMDataTreeWriteTransaction tx, final YangInstanceIdentifier rootPath, final DataTreeCandidateNode root, final DataTreeCandidateNode table) { final PathArgument lastArg = table.getIdentifier(); verify(lastArg instanceof NodeIdentifierWithPredicates, "Unexpected type %s in path %s", lastArg.getClass(), @@ -305,14 +306,14 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn } } - private void deleteTable(final DOMDataWriteTransaction tx, final RIBSupportContext ribContext, + private void deleteTable(final DOMDataTreeWriteTransaction tx, final RIBSupportContext ribContext, final YangInstanceIdentifier effectiveTablePath, final DataTreeCandidateNode table) { LOG.debug("Delete Effective Table {}", effectiveTablePath); onDeleteTable(ribContext.getRibSupport(), effectiveTablePath, table.getDataBefore()); tx.delete(LogicalDatastoreType.OPERATIONAL, effectiveTablePath); } - private void modifyTable(final DOMDataWriteTransaction tx, final RIBSupportContext ribContext, + private void modifyTable(final DOMDataTreeWriteTransaction tx, final RIBSupportContext ribContext, final YangInstanceIdentifier effectiveTablePath, final DataTreeCandidateNode table) { LOG.debug("Modify Effective Table {}", effectiveTablePath); @@ -325,19 +326,18 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn return; } - final DataTreeCandidateNode modifiedAttrs = table.getModifiedChild(ATTRIBUTES_NID); - if (modifiedAttrs != null) { + table.getModifiedChild(ATTRIBUTES_NID).ifPresent(modifiedAttrs -> { final YangInstanceIdentifier effAttrsPath = effectiveTablePath.node(ATTRIBUTES_NID); final Optional> optAttrsAfter = modifiedAttrs.getDataAfter(); if (optAttrsAfter.isPresent()) { - tx.put(LogicalDatastoreType.OPERATIONAL, effAttrsPath, effectiveAttributes(optAttrsAfter)); + tx.put(LogicalDatastoreType.OPERATIONAL, effAttrsPath, effectiveAttributes( + NormalizedNodes.findNode(optAttrsAfter.get(), UPTODATE_NID))); } else { tx.delete(LogicalDatastoreType.OPERATIONAL, effAttrsPath); } - } + }); - final DataTreeCandidateNode modifiedRoutes = table.getModifiedChild(ROUTES_NID); - if (modifiedRoutes != null) { + table.getModifiedChild(ROUTES_NID).ifPresent(modifiedRoutes -> { final RIBSupport ribSupport = ribContext.getRibSupport(); switch (modifiedRoutes.getModificationType()) { case APPEARED: @@ -364,10 +364,10 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn LOG.warn("Ignoring modified routes {}", modifiedRoutes); break; } - } + }); } - private void writeTable(final DOMDataWriteTransaction tx, final RIBSupportContext ribContext, + private void writeTable(final DOMDataTreeWriteTransaction tx, final RIBSupportContext ribContext, final YangInstanceIdentifier effectiveTablePath, final DataTreeCandidateNode table) { LOG.debug("Write Effective Table {}", effectiveTablePath); onDeleteTable(ribContext.getRibSupport(), effectiveTablePath, table.getDataBefore()); @@ -404,7 +404,7 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn } } - private void deleteRoutesBefore(final DOMDataWriteTransaction tx, final RIBSupport ribSupport, + private void deleteRoutesBefore(final DOMDataTreeWriteTransaction tx, final RIBSupport ribSupport, final YangInstanceIdentifier effectiveTablePath, final DataTreeCandidateNode modifiedRoutes) { final Optional> maybeRoutesBefore = NormalizedNodes.findNode( modifiedRoutes.getDataBefore(), ribSupport.relativeRoutesPath()); @@ -413,7 +413,7 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn } } - private void writeRoutesAfter(final DOMDataWriteTransaction tx, final RIBSupport ribSupport, + private void writeRoutesAfter(final DOMDataTreeWriteTransaction tx, final RIBSupport ribSupport, final YangInstanceIdentifier effectiveTablePath, final Optional> routesAfter, final boolean longLivedStale) { final Optional> maybeRoutesAfter = NormalizedNodes.findNode(routesAfter, @@ -441,7 +441,7 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn CountersUtil.add(prefixesInstalled.get(tablesKey), tablesKey, -deletedRoutes.size()); } - private void processRoute(final DOMDataWriteTransaction tx, final RIBSupport ribSupport, + private void processRoute(final DOMDataTreeWriteTransaction tx, final RIBSupport ribSupport, final YangInstanceIdentifier routesPath, final DataTreeCandidateNode route, final boolean longLivedStale) { LOG.debug("Process route {}", route.getIdentifier()); final YangInstanceIdentifier routePath = ribSupport.routePath(routesPath, route.getIdentifier()); @@ -458,13 +458,14 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn case WRITE: writeRoute(tx, ribSupport, routePath, route.getDataBefore(), route.getDataAfter().get(), longLivedStale); + break; default: LOG.warn("Ignoring unhandled route {}", route); break; } } - private void deleteRoute(final DOMDataWriteTransaction tx, final RIBSupport ribSupport, + private void deleteRoute(final DOMDataTreeWriteTransaction tx, final RIBSupport ribSupport, final YangInstanceIdentifier routeIdPath, final NormalizedNode route) { handleRouteTarget(ModificationType.DELETE, ribSupport, routeIdPath, route); tx.delete(LogicalDatastoreType.OPERATIONAL, routeIdPath); @@ -473,7 +474,7 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn CountersUtil.decrement(this.prefixesInstalled.get(tablesKey), tablesKey); } - private void writeRoute(final DOMDataWriteTransaction tx, final RIBSupport ribSupport, + private void writeRoute(final DOMDataTreeWriteTransaction tx, final RIBSupport ribSupport, final YangInstanceIdentifier routePath, final Optional> routeBefore, final NormalizedNode routeAfter, final boolean longLivedStale) { final TablesKey tablesKey = ribSupport.getTablesKey(); @@ -567,7 +568,7 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn newCommunities = STALE_LLGR_COMMUNUTIES; } - return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329 + return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120 .path.attributes.AttributesBuilder(attrs).setCommunities(newCommunities).build(); }