From 7ec819c1c9ca7e980887ed74608c9af0bb9717a1 Mon Sep 17 00:00:00 2001 From: "Claudio D. Gasparini" Date: Sun, 7 Jan 2018 22:35:25 +0100 Subject: [PATCH] Reduce number of parameters for path selection -enforce findbug. Change-Id: Idc9cb566e31b81c7d87cf544016525122487393b Signed-off-by: Claudio D. Gasparini --- bgp/path-selection-mode/pom.xml | 7 ++ .../protocol/bgp/mode/api/RouteEntry.java | 56 +++++------- .../impl/add/AddPathAbstractRouteEntry.java | 87 ++++++++++--------- .../impl/add/all/paths/ComplexRouteEntry.java | 11 ++- .../impl/add/all/paths/SimpleRouteEntry.java | 6 +- .../impl/add/n/paths/ComplexRouteEntry.java | 7 +- .../impl/add/n/paths/SimpleRouteEntry.java | 6 +- .../impl/base/BaseAbstractRouteEntry.java | 74 +++++++++------- .../mode/impl/base/BaseComplexRouteEntry.java | 5 +- .../mode/impl/base/BaseSimpleRouteEntry.java | 5 +- .../bgp/mode/spi/AbstractRouteEntry.java | 14 ++- .../protocol/bgp/mode/spi/RouteEntryUtil.java | 12 +-- .../bgp/mode/impl/AbstractRouteEntryTest.java | 20 +++++ .../add/all/paths/SimpleRouteEntryTest.java | 7 +- .../add/n/paths/SimpleRouteEntryTest.java | 28 +++--- .../mode/impl/base/BaseRouteEntryTest.java | 16 ++-- .../protocol/bgp/rib/impl/LocRibWriter.java | 46 +++++----- .../RouteEntryDependenciesContainerImpl.java | 53 +++++++++++ .../bgp/rib/impl/RouteEntryInfoImpl.java | 47 ++++++++++ .../bgp/rib/spi/AddPathRibSupport.java | 7 +- .../rib/spi/MultiPathAbstractRIBSupport.java | 7 +- .../RouteEntryDependenciesContainer.java | 53 +++++++++++ .../bgp/rib/spi/entry/RouteEntryInfo.java | 33 +++++++ .../bgp/rib/spi/entry/RouteEntryKey.java | 21 +++++ 24 files changed, 438 insertions(+), 190 deletions(-) create mode 100644 bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RouteEntryDependenciesContainerImpl.java create mode 100644 bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RouteEntryInfoImpl.java create mode 100644 bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/RouteEntryDependenciesContainer.java create mode 100644 bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/RouteEntryInfo.java create mode 100644 bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/RouteEntryKey.java diff --git a/bgp/path-selection-mode/pom.xml b/bgp/path-selection-mode/pom.xml index 2541e0a802..1e728045fe 100644 --- a/bgp/path-selection-mode/pom.xml +++ b/bgp/path-selection-mode/pom.xml @@ -102,6 +102,13 @@ false + + org.codehaus.mojo + findbugs-maven-plugin + + true + + org.apache.felix maven-bundle-plugin diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/RouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/RouteEntry.java index 7535b7407a..8d19c2fdb3 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/RouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/RouteEntry.java @@ -9,16 +9,14 @@ package org.opendaylight.protocol.bgp.mode.api; import com.google.common.primitives.UnsignedInteger; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; -import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker; import org.opendaylight.protocol.bgp.rib.spi.PeerExportGroup; -import org.opendaylight.protocol.bgp.rib.spi.RIBSupport; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.protocol.bgp.rib.spi.entry.RouteEntryDependenciesContainer; +import org.opendaylight.protocol.bgp.rib.spi.entry.RouteEntryInfo; 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.MapEntryNode; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; /** @@ -38,16 +36,6 @@ public interface RouteEntry { */ boolean removeRoute(UnsignedInteger routerId, Long remotePathId); - /** - * Create value. - * - * @param routeId router ID pathArgument - * @param path BestPath - * @return MapEntryNode - */ - @Deprecated - MapEntryNode createValue(PathArgument routeId, BestPath path); - /** * Indicates whether best has changed. * @@ -70,27 +58,25 @@ public interface RouteEntry { /** * Update LocRibOut and AdjRibsOut by removing stale best path and writing new best. * - * @param localTK local Table Key - * @param peerPT peer export policy - * @param locRibTarget YII local rib - * @param ribSupport rib support - * @param tx DOM transaction - * @param routeIdPA router ID pathArgument + * @param entryDependencies entry Dependencies container + * @param routeIdPA router ID pathArgument + * @param tx DOM transaction */ - void updateRoute(TablesKey localTK, ExportPolicyPeerTracker peerPT, YangInstanceIdentifier locRibTarget, - RIBSupport ribSupport, DOMDataWriteTransaction tx, PathArgument routeIdPA); + void updateBestPaths( + @Nonnull RouteEntryDependenciesContainer entryDependencies, + @Nonnull NodeIdentifierWithPredicates routeIdPA, + @Nonnull DOMDataWriteTransaction tx); /** - * Write Route on LocRibOut and AdjRibsOut. + * Initialize LocRibOut and AdjRibsOut for new peers with already present best paths. * - * @param peerId destination peerId - * @param routeId router ID path Argument - * @param rootPath YII root path - * @param peerGroup PeerExportGroup - * @param localTK local Table Key - * @param ribSupport rib support - * @param tx DOM transaction + * @param entryDependencies Route Entry Dependencies wrapper + * @param entryInfo Route Entry Info wrapper + * @param tx transaction */ - void writeRoute(PeerId peerId, PathArgument routeId, YangInstanceIdentifier rootPath, PeerExportGroup peerGroup, - TablesKey localTK, ExportPolicyPeerTracker peerPT, RIBSupport ribSupport, DOMDataWriteTransaction tx); + void initializeBestPaths( + @Nonnull RouteEntryDependenciesContainer entryDependencies, + @Nonnull RouteEntryInfo entryInfo, + @Nullable PeerExportGroup peerGroup, + @Nonnull DOMDataWriteTransaction tx); } \ No newline at end of file diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathAbstractRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathAbstractRouteEntry.java index d6854b0b20..9111159e6c 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathAbstractRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathAbstractRouteEntry.java @@ -16,17 +16,19 @@ import java.util.List; import java.util.Optional; import javax.annotation.concurrent.NotThreadSafe; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; -import org.opendaylight.protocol.bgp.mode.api.BestPath; import org.opendaylight.protocol.bgp.mode.spi.AbstractRouteEntry; import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker; import org.opendaylight.protocol.bgp.rib.spi.PeerExportGroup; import org.opendaylight.protocol.bgp.rib.spi.RIBSupport; import org.opendaylight.protocol.bgp.rib.spi.RouterIds; +import org.opendaylight.protocol.bgp.rib.spi.entry.RouteEntryDependenciesContainer; +import org.opendaylight.protocol.bgp.rib.spi.entry.RouteEntryInfo; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey; 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.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; @@ -43,7 +45,7 @@ import org.slf4j.LoggerFactory; * where individual object overhead becomes the dominating factor. */ @NotThreadSafe -public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry { +public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry { private static final Logger LOG = LoggerFactory.getLogger(AddPathAbstractRouteEntry.class); private List bestPath; @@ -119,14 +121,15 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry { } @Override - public void updateRoute(final TablesKey localTK, final ExportPolicyPeerTracker peerPT, - final YangInstanceIdentifier locRibTarget, final RIBSupport ribSupport, final DOMDataWriteTransaction tx, - final PathArgument routeIdPA) { + public void updateBestPaths(final RouteEntryDependenciesContainer entryDependencies, + final NodeIdentifierWithPredicates routeIdPA, final DOMDataWriteTransaction tx) { + final RIBSupport ribSupport = entryDependencies.getRibSupport(); + final ExportPolicyPeerTracker peerPT = entryDependencies.getExportPolicyPeerTracker(); if (this.bestPathRemoved != null) { this.bestPathRemoved.forEach(path -> { final PathArgument routeIdAddPath = ribSupport.getRouteIdAddPath(path.getPathId(), routeIdPA); final YangInstanceIdentifier pathAddPathTarget = ribSupport - .routePath(locRibTarget.node(ROUTES_IDENTIFIER), routeIdAddPath); + .routePath(entryDependencies.getLocRibTableTarget().node(ROUTES_IDENTIFIER), routeIdAddPath); fillLocRib(pathAddPathTarget, null, tx); }); this.bestPathRemoved = null; @@ -137,62 +140,65 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry { final PathArgument routeIdAddPathDefault = ribSupport.getRouteIdAddPath(NON_PATH_ID, routeIdPA); fillAdjRibsOut(true, null, null, null, routeIdAddPathDefault, routeIdAddPath, - RouterIds.createPeerId(removedPath.getRouteId()), peerPT, localTK, ribSupport, tx); + RouterIds.createPeerId(removedPath.getRouteId()), + peerPT, entryDependencies.getLocalTablesKey(), ribSupport, tx); }); this.removedPaths = null; } if (this.newBestPathToBeAdvertised != null) { - this.newBestPathToBeAdvertised.forEach(path -> addPathToDataStore(path, - isFirstBestPath(this.bestPath.indexOf(path)), routeIdPA, locRibTarget, ribSupport, peerPT, - localTK, tx)); + this.newBestPathToBeAdvertised.forEach(path -> addPathToDataStore(entryDependencies, path, + isFirstBestPath(this.bestPath.indexOf(path)), routeIdPA, + peerPT, tx)); this.newBestPathToBeAdvertised = null; } } @Override - public void writeRoute(final PeerId destPeer, final PathArgument routeId, final YangInstanceIdentifier rootPath, - final PeerExportGroup peerGroup, final TablesKey localTK, final ExportPolicyPeerTracker peerPT, - final RIBSupport ribSup, final DOMDataWriteTransaction tx) { - final boolean destPeerSupAddPath = peerPT.isAddPathSupportedByPeer(destPeer); + public void initializeBestPaths(final RouteEntryDependenciesContainer entryDependencies, + final RouteEntryInfo entryInfo, final PeerExportGroup peerGroup, final DOMDataWriteTransaction tx) { + final PeerId toPeer = entryInfo.getToPeerId(); + final ExportPolicyPeerTracker peerPT = entryDependencies.getExportPolicyPeerTracker(); + final boolean destPeerSupAddPath = peerPT.isAddPathSupportedByPeer(toPeer); if (this.bestPath != null) { - final PeerRole destPeerRole = getRoutePeerIdRole(peerPT, destPeer); - this.bestPath.stream().filter(path -> filterRoutes(path.getPeerId(), destPeer, peerPT, localTK, + final PeerRole destPeerRole = getRoutePeerIdRole(peerPT, toPeer); + final TablesKey localTk = entryDependencies.getLocalTablesKey(); + final RIBSupport ribSup = entryDependencies.getRibSupport(); + this.bestPath.stream().filter(path -> filterRoutes(path.getPeerId(), toPeer, peerPT, localTk, destPeerRole) && peersSupportsAddPathOrIsFirstBestPath(destPeerSupAddPath, - isFirstBestPath(this.bestPath.indexOf(path)))).forEach(path -> writeRoutePath(destPeer, routeId, - peerPT, peerGroup, destPeerSupAddPath, path, rootPath, localTK, ribSup, tx)); + isFirstBestPath(this.bestPath.indexOf(path)))) + .forEach(path -> writeRoutePath(entryInfo, peerPT, peerGroup, destPeerSupAddPath, + path, localTk, ribSup, tx)); } } - private void writeRoutePath(final PeerId destPeer, final PathArgument routeId, final ExportPolicyPeerTracker peerPT, - final PeerExportGroup peerGroup, final boolean destPeerSupAddPath, final BestPath path, - final YangInstanceIdentifier rootPath, final TablesKey localTK, final RIBSupport ribSup, - final DOMDataWriteTransaction tx) { + private void writeRoutePath(final RouteEntryInfo entryInfo, final ExportPolicyPeerTracker peerPT, + final PeerExportGroup peerGroup, final boolean destPeerSupAddPath, final AddPathBestPath path, + final TablesKey localTK, final RIBSupport ribSup, final DOMDataWriteTransaction tx) { + final NodeIdentifierWithPredicates routeId = entryInfo.getRouteId(); final ContainerNode effectiveAttributes = peerGroup - .effectiveAttributes(getRoutePeerIdRole(peerPT,path.getPeerId()), path.getAttributes()); - PathArgument routeIdAddPath; - if (destPeerSupAddPath) { - routeIdAddPath = ribSup.getRouteIdAddPath(path.getPathId(), routeId); - } else { - routeIdAddPath = ribSup.getRouteIdAddPath(NON_PATH_ID, routeId); - } - writeRoute(destPeer, getAdjRibOutYII(ribSup, rootPath, routeIdAddPath, localTK), effectiveAttributes, - createValue(routeIdAddPath, path), ribSup, tx); + .effectiveAttributes(getRoutePeerIdRole(peerPT, path.getPeerId()), path.getAttributes()); + final NodeIdentifierWithPredicates routeIdAddPath = ribSup + .getRouteIdAddPath(destPeerSupAddPath ? path.getPathId() : NON_PATH_ID, routeId); + + writeRoute(entryInfo.getToPeerId(), getAdjRibOutYII(ribSup, entryInfo.getRootPath(), routeIdAddPath, localTK), + effectiveAttributes, createValue(routeIdAddPath, path), ribSup, tx); } - private void addPathToDataStore(final BestPath path, final boolean isFirstBestPath, final PathArgument routeIdPA, - final YangInstanceIdentifier locRibTarget, final RIBSupport ribSup, final ExportPolicyPeerTracker peerPT, - final TablesKey localTK, final DOMDataWriteTransaction tx) { - final PathArgument routeIdAddPath = ribSup.getRouteIdAddPath(path.getPathId(), routeIdPA); - final PathArgument routeIdAddPathDefault = ribSup.getRouteIdAddPath(NON_PATH_ID, routeIdPA); - final YangInstanceIdentifier pathAddPathTarget = ribSup.routePath(locRibTarget.node(ROUTES_IDENTIFIER), - routeIdAddPath); + private void addPathToDataStore(final RouteEntryDependenciesContainer entryDependencies, final AddPathBestPath path, + final boolean isFirstBestPath, final NodeIdentifierWithPredicates routeIdPA, + final ExportPolicyPeerTracker peerPT, final DOMDataWriteTransaction tx) { + final RIBSupport ribSup = entryDependencies.getRibSupport(); + final NodeIdentifierWithPredicates routeIdAddPath = ribSup.getRouteIdAddPath(path.getPathId(), routeIdPA); + final NodeIdentifierWithPredicates routeIdAddPathDefault = ribSup.getRouteIdAddPath(NON_PATH_ID, routeIdPA); + final YangInstanceIdentifier pathAddPathTarget = ribSup.routePath(entryDependencies.getLocRibTableTarget() + .node(ROUTES_IDENTIFIER), routeIdAddPath); final MapEntryNode addPathValue = createValue(routeIdAddPath, path); final MapEntryNode defaultValue = createValue(routeIdAddPathDefault, path); LOG.trace("Selected best value {}", addPathValue); fillLocRib(pathAddPathTarget, addPathValue, tx); fillAdjRibsOut(isFirstBestPath, path.getAttributes(), defaultValue, addPathValue, routeIdAddPathDefault, - routeIdAddPath, path.getPeerId(), peerPT, localTK, ribSup, tx); + routeIdAddPath, path.getPeerId(), peerPT, entryDependencies.getLocalTablesKey(), ribSup, tx); } private void fillAdjRibsOut(final boolean isFirstBestPath, final ContainerNode attributes, @@ -277,7 +283,8 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry { protected boolean isBestPathNew(final List newBestPathList) { this.oldNonAddPathBestPathTheSame = isNonAddPathBestPathTheSame(newBestPathList); filterRemovedPaths(newBestPathList); - if (this.bestPathRemoved != null && !this.bestPathRemoved.isEmpty() || newBestPathList != null + if (this.bestPathRemoved != null && !this.bestPathRemoved.isEmpty() + || newBestPathList != null && !newBestPathList.equals(this.bestPath)) { this.newBestPathToBeAdvertised = new ArrayList<>(newBestPathList); if (this.bestPath != null) { diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/ComplexRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/ComplexRouteEntry.java index 2c829c4ad9..8082a5bd4a 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/ComplexRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/ComplexRouteEntry.java @@ -5,17 +5,15 @@ * 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.mode.impl.add.all.paths; import com.google.common.primitives.UnsignedInteger; -import org.opendaylight.protocol.bgp.mode.api.BestPath; import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath; import org.opendaylight.protocol.bgp.mode.impl.add.OffsetMap; import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey; import org.opendaylight.protocol.bgp.mode.spi.RouteEntryUtil; 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.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; @@ -33,15 +31,16 @@ final class ComplexRouteEntry extends AbstractAllPathsRouteEntry { } @Override - public MapEntryNode createValue(final PathArgument routeId, final BestPath path) { + public MapEntryNode createValue(final NodeIdentifierWithPredicates routeId, final AddPathBestPath path) { final OffsetMap map = getOffsets(); - final MapEntryNode mapValues = map.getValue(this.values, map.offsetOf(((AddPathBestPath) path).getRouteKey())); + final MapEntryNode mapValues = map.getValue(this.values, map.offsetOf(path.getRouteKey())); return RouteEntryUtil.createComplexRouteValue(routeId, path, mapValues); } @Override public int addRoute(final UnsignedInteger routerId, final Long remotePathId, - final NodeIdentifier attII, final NormalizedNode data) { + final NodeIdentifier attII, + final NormalizedNode data) { final OffsetMap oldMap = getOffsets(); final int offset = addRoute(new RouteKey(routerId, remotePathId), attII, data); final OffsetMap newMap = getOffsets(); diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntry.java index 4d01b8bba9..475925aca3 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntry.java @@ -9,11 +9,11 @@ package org.opendaylight.protocol.bgp.mode.impl.add.all.paths; import com.google.common.primitives.UnsignedInteger; -import org.opendaylight.protocol.bgp.mode.api.BestPath; +import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath; import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey; import org.opendaylight.protocol.bgp.mode.spi.RouteEntryUtil; -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.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; @@ -25,7 +25,7 @@ final class SimpleRouteEntry extends AbstractAllPathsRouteEntry { } @Override - public MapEntryNode createValue(final YangInstanceIdentifier.PathArgument routeId, final BestPath path) { + public MapEntryNode createValue(final NodeIdentifierWithPredicates routeId, final AddPathBestPath path) { return RouteEntryUtil.createSimpleRouteValue(routeId, path); } diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/ComplexRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/ComplexRouteEntry.java index 747496abd3..29153f4854 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/ComplexRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/ComplexRouteEntry.java @@ -8,13 +8,12 @@ package org.opendaylight.protocol.bgp.mode.impl.add.n.paths; import com.google.common.primitives.UnsignedInteger; -import org.opendaylight.protocol.bgp.mode.api.BestPath; import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath; import org.opendaylight.protocol.bgp.mode.impl.add.OffsetMap; import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey; import org.opendaylight.protocol.bgp.mode.spi.RouteEntryUtil; 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.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; @@ -36,9 +35,9 @@ final class ComplexRouteEntry extends AbstractNPathsRouteEntry { } @Override - public MapEntryNode createValue(final PathArgument routeId, final BestPath path) { + public MapEntryNode createValue(final NodeIdentifierWithPredicates routeId, final AddPathBestPath path) { final OffsetMap map = getOffsets(); - final MapEntryNode mapValues = map.getValue(this.values, map.offsetOf(((AddPathBestPath) path).getRouteKey())); + final MapEntryNode mapValues = map.getValue(this.values, map.offsetOf(path.getRouteKey())); return RouteEntryUtil.createComplexRouteValue(routeId, path, mapValues); } diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntry.java index 673baa4875..7beb3ee44c 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntry.java @@ -8,11 +8,11 @@ package org.opendaylight.protocol.bgp.mode.impl.add.n.paths; import com.google.common.primitives.UnsignedInteger; -import org.opendaylight.protocol.bgp.mode.api.BestPath; +import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath; import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey; import org.opendaylight.protocol.bgp.mode.spi.RouteEntryUtil; 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.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; @@ -28,7 +28,7 @@ final class SimpleRouteEntry extends AbstractNPathsRouteEntry { } @Override - public MapEntryNode createValue(final PathArgument routeId, final BestPath path) { + public MapEntryNode createValue(final NodeIdentifierWithPredicates routeId, final AddPathBestPath path) { return RouteEntryUtil.createSimpleRouteValue(routeId, path); } diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseAbstractRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseAbstractRouteEntry.java index 4cae936af5..812373b01c 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseAbstractRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseAbstractRouteEntry.java @@ -11,16 +11,18 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.primitives.UnsignedInteger; import javax.annotation.concurrent.NotThreadSafe; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; -import org.opendaylight.protocol.bgp.mode.api.BestPath; import org.opendaylight.protocol.bgp.mode.spi.AbstractRouteEntry; import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker; import org.opendaylight.protocol.bgp.rib.spi.PeerExportGroup; import org.opendaylight.protocol.bgp.rib.spi.RIBSupport; +import org.opendaylight.protocol.bgp.rib.spi.entry.RouteEntryDependenciesContainer; +import org.opendaylight.protocol.bgp.rib.spi.entry.RouteEntryInfo; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey; 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.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; @@ -30,7 +32,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; @NotThreadSafe -abstract class BaseAbstractRouteEntry extends AbstractRouteEntry { +abstract class BaseAbstractRouteEntry extends AbstractRouteEntry { private static final Logger LOG = LoggerFactory.getLogger(BaseAbstractRouteEntry.class); private static final ContainerNode[] EMPTY_ATTRIBUTES = new ContainerNode[0]; private OffsetMap offsets = OffsetMap.EMPTY; @@ -83,7 +85,8 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry { public int addRoute(final UnsignedInteger routerId, final Long remotePathId, final NodeIdentifier attributesIdentifier, final NormalizedNode data) { LOG.trace("Find {} in {}", attributesIdentifier, data); - final ContainerNode advertisedAttrs = (ContainerNode) NormalizedNodes + final ContainerNode advertisedAttrs + = (ContainerNode) NormalizedNodes .findNode(data, attributesIdentifier).orElse(null); int offset = this.offsets.offsetOf(routerId); if (offset < 0) { @@ -100,54 +103,60 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry { } @Override - public void updateRoute(final TablesKey localTK, final ExportPolicyPeerTracker peerPT, - final YangInstanceIdentifier locRibTarget, final RIBSupport ribSup, - final DOMDataWriteTransaction tx, final PathArgument routeIdPA) { + public void updateBestPaths(final RouteEntryDependenciesContainer entryDependencies, + final NodeIdentifierWithPredicates routeIdPA, final DOMDataWriteTransaction tx) { if (this.removedBestPath != null) { - removePathFromDataStore(this.removedBestPath, routeIdPA, locRibTarget, peerPT, localTK, ribSup, tx); + removePathFromDataStore(entryDependencies, routeIdPA, tx); this.removedBestPath = null; } if (this.bestPath != null) { - addPathToDataStore(this.bestPath, routeIdPA, locRibTarget, ribSup, peerPT, localTK, tx); + addPathToDataStore(entryDependencies, this.bestPath, routeIdPA, tx); } } @Override - public void writeRoute(final PeerId destPeer, final PathArgument routeId, final YangInstanceIdentifier rootPath, - final PeerExportGroup peerGroup, final TablesKey localTK, final ExportPolicyPeerTracker peerPT, - final RIBSupport ribSupport, final DOMDataWriteTransaction tx) { + public void initializeBestPaths(final RouteEntryDependenciesContainer entryDependencies, + final RouteEntryInfo entryInfo, final PeerExportGroup peerGroup, final DOMDataWriteTransaction tx) { if (this.bestPath != null) { + final ExportPolicyPeerTracker peerPT = entryDependencies.getExportPolicyPeerTracker(); + final TablesKey localTK = entryDependencies.getLocalTablesKey(); final BaseBestPath path = this.bestPath; - final PeerRole destPeerRole = getRoutePeerIdRole(peerPT, destPeer); - if (filterRoutes(path.getPeerId(), destPeer, peerPT, localTK, destPeerRole)) { - PathArgument routeIdDest = ribSupport.getRouteIdAddPath(path.getPathId(), routeId); + final PeerId toPeerId = entryInfo.getToPeerId(); + final PeerRole destPeerRole = getRoutePeerIdRole(peerPT, toPeerId); + if (filterRoutes(path.getPeerId(), toPeerId, peerPT, localTK, destPeerRole)) { + final NodeIdentifierWithPredicates routeId = entryInfo.getRouteId(); + final RIBSupport ribSupport = entryDependencies.getRibSupport(); + NodeIdentifierWithPredicates routeIdDest = ribSupport.getRouteIdAddPath(path.getPathId(), routeId); if (routeIdDest == null) { routeIdDest = routeId; } - final ContainerNode effAttrib = peerGroup.effectiveAttributes( - getRoutePeerIdRole(peerPT, path.getPeerId()), path.getAttributes()); - writeRoute(destPeer, getAdjRibOutYII(ribSupport, rootPath, routeIdDest, localTK), effAttrib, + final ContainerNode effAttrib = peerGroup.effectiveAttributes(getRoutePeerIdRole(peerPT, + path.getPeerId()), path.getAttributes()); + final YangInstanceIdentifier rootPath = entryInfo.getRootPath(); + writeRoute(toPeerId, getAdjRibOutYII(ribSupport, rootPath, routeIdDest, localTK), effAttrib, createValue(routeIdDest, path), ribSupport, tx); } } } - private void removePathFromDataStore(final BestPath path, final PathArgument routeIdPA, - final YangInstanceIdentifier locRibTarget, final ExportPolicyPeerTracker peerPT, - final TablesKey localTK, final RIBSupport ribSup, final DOMDataWriteTransaction tx) { - LOG.trace("Best Path removed {}", path); - PathArgument routeIdTarget = ribSup.getRouteIdAddPath(path.getPathId(), routeIdPA); + private void removePathFromDataStore(final RouteEntryDependenciesContainer entryDependencies, + final PathArgument routeIdPA, final DOMDataWriteTransaction tx) { + LOG.trace("Best Path removed {}", this.removedBestPath); + final YangInstanceIdentifier locRibTarget = entryDependencies.getLocRibTableTarget(); + final RIBSupport ribSup = entryDependencies.getRibSupport(); + PathArgument routeIdTarget = ribSup.getRouteIdAddPath(this.removedBestPath.getPathId(), routeIdPA); if (routeIdTarget == null) { routeIdTarget = routeIdPA; } fillLocRib(ribSup.routePath(locRibTarget.node(ROUTES_IDENTIFIER), routeIdTarget), null, tx); - fillAdjRibsOut(null, null, routeIdTarget, path.getPeerId(), peerPT, localTK, ribSup, tx); + fillAdjRibsOut(entryDependencies,null, null, routeIdTarget, this.removedBestPath.getPeerId(), tx); } - private void addPathToDataStore(final BestPath path, final PathArgument routeIdPA, - final YangInstanceIdentifier locRibTarget, final RIBSupport ribSup, final ExportPolicyPeerTracker peerPT, - final TablesKey localTK, final DOMDataWriteTransaction tx) { - PathArgument routeIdDest = ribSup.getRouteIdAddPath(path.getPathId(), routeIdPA); + private void addPathToDataStore(final RouteEntryDependenciesContainer entryDependencies, final BaseBestPath path, + final NodeIdentifierWithPredicates routeIdPA, final DOMDataWriteTransaction tx) { + final RIBSupport ribSup = entryDependencies.getRibSupport(); + final YangInstanceIdentifier locRibTarget = entryDependencies.getLocRibTableTarget(); + NodeIdentifierWithPredicates routeIdDest = ribSup.getRouteIdAddPath(path.getPathId(), routeIdPA); if (routeIdDest == null) { routeIdDest = routeIdPA; } @@ -158,7 +167,7 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry { final YangInstanceIdentifier pathAddPathTarget = ribSup.routePath(locRibTarget.node(ROUTES_IDENTIFIER), routeIdDest); fillLocRib(pathAddPathTarget, value, tx); - fillAdjRibsOut(path.getAttributes(), value, routeIdDest, path.getPeerId(), peerPT, localTK, ribSup, tx); + fillAdjRibsOut(entryDependencies, path.getAttributes(), value, routeIdDest, path.getPeerId(), tx); } final OffsetMap getOffsets() { @@ -166,9 +175,9 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry { } @VisibleForTesting - private void fillAdjRibsOut(final ContainerNode attributes, final MapEntryNode value, - final PathArgument routeId, final PeerId routePeerId, final ExportPolicyPeerTracker peerPT, - final TablesKey localTK, final RIBSupport ribSup, final DOMDataWriteTransaction tx) { + private void fillAdjRibsOut(final RouteEntryDependenciesContainer entryDependencies, + final ContainerNode attributes, final MapEntryNode value, + final PathArgument routeId, final PeerId routePeerId, final DOMDataWriteTransaction tx) { /* * We need to keep track of routers and populate adj-ribs-out, too. If we do not, we need to * expose from which client a particular route was learned from in the local RIB, and have @@ -178,6 +187,9 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry { * if we have two eBGP peers, for example, there is no reason why we should perform the translation * multiple times. */ + final ExportPolicyPeerTracker peerPT = entryDependencies.getExportPolicyPeerTracker(); + final TablesKey localTK = entryDependencies.getLocalTablesKey(); + final RIBSupport ribSup = entryDependencies.getRibSupport(); for (final PeerRole role : PeerRole.values()) { final PeerExportGroup peerGroup = peerPT.getPeerGroup(role); if (peerGroup != null) { diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseComplexRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseComplexRouteEntry.java index 4195a5c6e1..3cd3c27430 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseComplexRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseComplexRouteEntry.java @@ -8,10 +8,9 @@ package org.opendaylight.protocol.bgp.mode.impl.base; import com.google.common.primitives.UnsignedInteger; -import org.opendaylight.protocol.bgp.mode.api.BestPath; import org.opendaylight.protocol.bgp.mode.spi.RouteEntryUtil; 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.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; @@ -43,7 +42,7 @@ final class BaseComplexRouteEntry extends BaseAbstractRouteEntry { } @Override - public MapEntryNode createValue(final PathArgument routeId, final BestPath path) { + public MapEntryNode createValue(final NodeIdentifierWithPredicates routeId, final BaseBestPath path) { final OffsetMap map = getOffsets(); final MapEntryNode mapValues = map.getValue(this.values, map.offsetOf(path.getRouterId())); return RouteEntryUtil.createComplexRouteValue(routeId, path, mapValues); diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseSimpleRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseSimpleRouteEntry.java index 2c1aa24191..fa3b1d66d3 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseSimpleRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseSimpleRouteEntry.java @@ -8,9 +8,8 @@ package org.opendaylight.protocol.bgp.mode.impl.base; import com.google.common.primitives.UnsignedInteger; -import org.opendaylight.protocol.bgp.mode.api.BestPath; import org.opendaylight.protocol.bgp.mode.spi.RouteEntryUtil; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; final class BaseSimpleRouteEntry extends BaseAbstractRouteEntry { @@ -20,7 +19,7 @@ final class BaseSimpleRouteEntry extends BaseAbstractRouteEntry { } @Override - public MapEntryNode createValue(final PathArgument routeId, final BestPath path) { + public MapEntryNode createValue(final NodeIdentifierWithPredicates routeId, final BaseBestPath path) { return RouteEntryUtil.createSimpleRouteValue(routeId, path); } } diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractRouteEntry.java index ec2a4a0256..ba5220ef21 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractRouteEntry.java @@ -10,6 +10,7 @@ package org.opendaylight.protocol.bgp.mode.spi; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.protocol.bgp.mode.api.BestPath; import org.opendaylight.protocol.bgp.mode.api.RouteEntry; import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker; import org.opendaylight.protocol.bgp.rib.spi.PeerExportGroup; @@ -23,16 +24,27 @@ 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.rev171207.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; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; +import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public abstract class AbstractRouteEntry implements RouteEntry { +public abstract class AbstractRouteEntry implements RouteEntry { protected static final NodeIdentifier ROUTES_IDENTIFIER = new NodeIdentifier(Routes.QNAME); private static final Logger LOG = LoggerFactory.getLogger(AbstractRouteEntry.class); + /** + * Create value. + * + * @param routeId router ID pathArgument + * @param path BestPath + * @return MapEntryNode + */ + public abstract MapEntryNode createValue(NodeIdentifierWithPredicates routeId, T path); + protected static void fillLocRib(final YangInstanceIdentifier routeTarget, final NormalizedNode value, final DOMDataWriteTransaction tx) { if (value != null) { diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/RouteEntryUtil.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/RouteEntryUtil.java index 2753d9d6e2..4a8512da94 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/RouteEntryUtil.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/RouteEntryUtil.java @@ -10,7 +10,6 @@ package org.opendaylight.protocol.bgp.mode.spi; import org.opendaylight.protocol.bgp.mode.api.BestPath; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder; @@ -20,18 +19,19 @@ public final class RouteEntryUtil { throw new UnsupportedOperationException(); } - public static MapEntryNode createSimpleRouteValue(final PathArgument routeId, final BestPath path) { + public static MapEntryNode createSimpleRouteValue(final NodeIdentifierWithPredicates routeId, final BestPath path) { final DataContainerNodeAttrBuilder b = Builders.mapEntryBuilder(); - b.withNodeIdentifier((NodeIdentifierWithPredicates) routeId); + b.withNodeIdentifier(routeId); b.addChild(path.getAttributes()); return b.build(); } - public static MapEntryNode createComplexRouteValue(final PathArgument routeId, final BestPath path, + public static MapEntryNode createComplexRouteValue(final NodeIdentifierWithPredicates routeId, final BestPath path, final MapEntryNode mapValues) { final DataContainerNodeAttrBuilder mapEntryBuilder - = Builders.mapEntryBuilder(); - mapEntryBuilder.withNodeIdentifier((NodeIdentifierWithPredicates) routeId); + = + Builders.mapEntryBuilder(); + mapEntryBuilder.withNodeIdentifier(routeId); mapEntryBuilder.addChild(path.getAttributes()); mapValues.getValue().forEach(mapEntryBuilder::addChild); return mapEntryBuilder.build(); diff --git a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/AbstractRouteEntryTest.java b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/AbstractRouteEntryTest.java index d128436e93..058219fc13 100644 --- a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/AbstractRouteEntryTest.java +++ b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/AbstractRouteEntryTest.java @@ -34,6 +34,8 @@ import org.opendaylight.protocol.bgp.rib.spi.PeerExportGroup; import org.opendaylight.protocol.bgp.rib.spi.PeerExportGroup.PeerExporTuple; import org.opendaylight.protocol.bgp.rib.spi.RIBSupport; import org.opendaylight.protocol.bgp.rib.spi.RibSupportUtils; +import org.opendaylight.protocol.bgp.rib.spi.entry.RouteEntryDependenciesContainer; +import org.opendaylight.protocol.bgp.rib.spi.entry.RouteEntryInfo; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.routes.Ipv4Routes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.routes.ipv4.routes.Ipv4Route; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes; @@ -109,6 +111,10 @@ public abstract class AbstractRouteEntryTest { protected ExportPolicyPeerTracker peerPT; @Mock protected PeerExportGroup peg; + @Mock + protected RouteEntryDependenciesContainer entryDep; + @Mock + protected RouteEntryInfo entryInfo; protected List yiichanges; protected NormalizedNode attributes; protected YangInstanceIdentifier routePaYii; @@ -148,6 +154,20 @@ public abstract class AbstractRouteEntryTest { mockExportPolicies(); mockExportGroup(); mockTransactionChain(); + mockEntryDep(); + mockEntryInfo(); + } + + private void mockEntryInfo() { + doReturn(PEER_ID).when(this.entryInfo).getToPeerId(); + doReturn(PEER_YII2).when(this.entryInfo).getRootPath(); + } + + private void mockEntryDep() { + doReturn(this.ribSupport).when(this.entryDep).getRibSupport(); + doReturn(this.peerPT).when(this.entryDep).getExportPolicyPeerTracker(); + doReturn(TABLES_KEY).when(this.entryDep).getLocalTablesKey(); + doReturn(LOC_RIB_TARGET).when(this.entryDep).getLocRibTableTarget(); } private void mockTransactionChain() { diff --git a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntryTest.java b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntryTest.java index 4f8f4af71c..3d31690e10 100644 --- a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntryTest.java +++ b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntryTest.java @@ -37,9 +37,7 @@ public final class SimpleRouteEntryTest extends AbstractRouteEntryTest { .routeAttributesIdentifier(), this.attributes); assertFalse(this.testBARE.isEmpty()); assertTrue(this.testBARE.selectBest(AS)); - /** Add AddPath Route **/ - this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, - this.tx, ROUTE_ID_PA_ADD_PATH); + this.testBARE.updateBestPaths(this.entryDep, ROUTE_ID_PA_ADD_PATH, this.tx); final Map yiiCount = collectInfo(); assertEquals(3, yiiCount.size()); assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii)); @@ -53,8 +51,7 @@ public final class SimpleRouteEntryTest extends AbstractRouteEntryTest { assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii)); assertTrue(this.testBARE.removeRoute(ROUTER_ID, REMOTE_PATH_ID)); assertTrue(this.testBARE.selectBest(AS)); - this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, - this.tx, ROUTE_ID_PA_ADD_PATH); + this.testBARE.updateBestPaths(this.entryDep, ROUTE_ID_PA_ADD_PATH, this.tx); yiiCount = collectInfo(); assertEquals(0, yiiCount.size()); assertFalse(yiiCount.containsKey(this.routePaAddPathYii)); diff --git a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntryTest.java b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntryTest.java index e941a17dd9..3fda25c575 100644 --- a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntryTest.java +++ b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntryTest.java @@ -10,6 +10,7 @@ package org.opendaylight.protocol.bgp.mode.impl.add.n.paths; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; import java.util.Map; import org.junit.Before; @@ -28,7 +29,8 @@ public final class SimpleRouteEntryTest extends AbstractRouteEntryTest { @Test public void testSimpleRouteEntry() throws Exception { - this.testBARE = (SimpleRouteEntry) new AddPathBestNPathSelection(N_PATHS).createRouteEntry(false); + this.testBARE = (SimpleRouteEntry) new AddPathBestNPathSelection(N_PATHS) + .createRouteEntry(false); testWriteEmptyBestPath(); testAddRouteSelectBestAndWriteOnDS(); testRewriteSameRoute(); @@ -36,26 +38,30 @@ public final class SimpleRouteEntryTest extends AbstractRouteEntryTest { testRemoveRoute(); } + /** + * Add non Add Path Route. + */ @Test(expected = NullPointerException.class) public void testAddRouteSelectBestAndWriteOnDSs() { - /** Add non Add Path Route **/ this.testBARE.addRoute(ROUTER_ID, REMOTE_PATH_ID, this.ribSupport.routeAttributesIdentifier(), this.attributes); } private void testWriteEmptyBestPath() { - this.testBARE.writeRoute(PEER_ID, ROUTE_ID_PA, PEER_YII2, this.peg, TABLES_KEY, this.peerPT, this.ribSupport, - this.tx); + doReturn(ROUTE_ID_PA).when(this.entryInfo).getRouteId(); + + this.testBARE.initializeBestPaths(this.entryDep, this.entryInfo, this.peg, this.tx); assertEquals(0, this.yiichanges.size()); } + /** + * Add AddPath Route. + */ private void testAddRouteSelectBestAndWriteOnDS() { this.testBARE.addRoute(ROUTER_ID, REMOTE_PATH_ID, this.ribSupport.routeAttributesIdentifier(), this.attributes); assertFalse(this.testBARE.isEmpty()); assertTrue(this.testBARE.selectBest(AS)); - /** Add AddPath Route **/ - this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, this.tx, - ROUTE_ID_PA_ADD_PATH); + this.testBARE.updateBestPaths(this.entryDep, ROUTE_ID_PA_ADD_PATH, this.tx); final Map yiiCount = collectInfo(); assertEquals(3, yiiCount.size()); assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii)); @@ -70,8 +76,9 @@ public final class SimpleRouteEntryTest extends AbstractRouteEntryTest { private void testInitializePeerWithExistentRoute() { assertEquals(3, this.yiichanges.size()); - this.testBARE.writeRoute(PEER_ID, ROUTE_ID_PA_ADD_PATH, PEER_YII2, this.peg, TABLES_KEY, this.peerPT, - this.ribSupport, this.tx); + doReturn(ROUTE_ID_PA_ADD_PATH).when(this.entryInfo).getRouteId(); + + this.testBARE.initializeBestPaths(this.entryDep, this.entryInfo, this.peg, this.tx); assertEquals(5, this.yiichanges.size()); final Map yiiCount = collectInfo(); assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYiiPeer2)); @@ -84,8 +91,7 @@ public final class SimpleRouteEntryTest extends AbstractRouteEntryTest { assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii)); assertTrue(this.testBARE.removeRoute(ROUTER_ID, REMOTE_PATH_ID)); assertTrue(this.testBARE.selectBest(AS)); - this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, this.tx, - ROUTE_ID_PA_ADD_PATH); + this.testBARE.updateBestPaths(this.entryDep, ROUTE_ID_PA_ADD_PATH, this.tx); yiiCount = collectInfo(); assertEquals(2, yiiCount.size()); assertFalse(yiiCount.containsKey(this.routePaAddPathYii)); diff --git a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseRouteEntryTest.java b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseRouteEntryTest.java index 3accb42d03..97483d3c05 100644 --- a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseRouteEntryTest.java +++ b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseRouteEntryTest.java @@ -10,6 +10,7 @@ package org.opendaylight.protocol.bgp.mode.impl.base; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.mockito.Mockito.doReturn; import java.util.Map; import org.junit.Before; @@ -42,15 +43,15 @@ public class BaseRouteEntryTest extends AbstractRouteEntryTest { assertEquals(1, (long) yiiCount.get(this.routePaYii)); this.testBARE.removeRoute(ROUTER_ID, REMOTE_PATH_ID); this.testBARE.selectBest(AS); - this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, this.tx, ROUTE_ID_PA); + this.testBARE.updateBestPaths(this.entryDep, ROUTE_ID_PA, this.tx); yiiCount = collectInfo(); assertFalse(yiiCount.containsKey(this.routePaYii)); assertFalse(yiiCount.containsKey(this.routeAddRiboutAttYii)); } private void testInitializePeerWithExistentRoute() { - this.testBARE.writeRoute(PEER_ID, ROUTE_ID_PA, PEER_YII2, this.peg, TABLES_KEY, this.peerPT, this.ribSupport, - this.tx); + doReturn(ROUTE_ID_PA).when(this.entryInfo).getRouteId(); + this.testBARE.initializeBestPaths(this.entryDep, this.entryInfo, this.peg, this.tx); assertEquals(8, this.yiichanges.size()); Map yiiCount = collectInfo(); assertEquals(1, (long) yiiCount.get(this.routeRiboutYiiPeer2)); @@ -67,14 +68,13 @@ public class BaseRouteEntryTest extends AbstractRouteEntryTest { this.testBARE.addRoute(ROUTER_ID, REMOTE_PATH_ID, this.ribSupport.routeAttributesIdentifier(), this.attributes); assertFalse(this.testBARE.getOffsets().isEmpty()); this.testBARE.selectBest(AS); - this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, this.tx, ROUTE_ID_PA); + this.testBARE.updateBestPaths(this.entryDep, ROUTE_ID_PA, this.tx); Map yiiCount = collectInfo(); assertEquals(3, yiiCount.size()); assertEquals(1, (long) yiiCount.get(this.routePaYii)); assertEquals(1, (long) yiiCount.get(this.routeRiboutYii)); assertEquals(1, (long) yiiCount.get(this.routeRiboutAttYii)); - this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, this.tx, - ROUTE_ID_PA_ADD_PATH); + this.testBARE.updateBestPaths(this.entryDep, ROUTE_ID_PA_ADD_PATH, this.tx); yiiCount = collectInfo(); assertEquals(6, yiiCount.size()); assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii)); @@ -83,8 +83,8 @@ public class BaseRouteEntryTest extends AbstractRouteEntryTest { } private void testWriteEmptyBestPath() { - this.testBARE.writeRoute(PEER_ID, ROUTE_ID_PA, PEER_YII2, this.peg, TABLES_KEY, this.peerPT, this.ribSupport, - this.tx); + doReturn(ROUTE_ID_PA).when(this.entryInfo).getRouteId(); + this.testBARE.initializeBestPaths(this.entryDep, this.entryInfo, this.peg, this.tx); assertEquals(0, this.yiichanges.size()); } } diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java index 4c68e9a8ec..eb59dd7ab4 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java @@ -51,7 +51,6 @@ 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.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; @@ -62,40 +61,39 @@ import org.slf4j.LoggerFactory; @NotThreadSafe final class LocRibWriter implements AutoCloseable, TotalPrefixesCounter, TotalPathsCounter, - ClusteredDOMDataTreeChangeListener { + ClusteredDOMDataTreeChangeListener { private static final Logger LOG = LoggerFactory.getLogger(LocRibWriter.class); private static final LeafNode ATTRIBUTES_UPTODATE_TRUE = ImmutableNodes .leafNode(QName.create(Attributes.QNAME, "uptodate"), Boolean.TRUE); - private final Map routeEntries = new HashMap<>(); + private final Map routeEntries = new HashMap<>(); private final YangInstanceIdentifier locRibTarget; private final NodeIdentifierWithPredicates tableKey; private final ExportPolicyPeerTracker exportPolicyPeerTracker; private final NodeIdentifier attributesIdentifier; private final Long ourAs; private final RIBSupport ribSupport; - private final TablesKey localTablesKey; private final YangInstanceIdentifier target; private final DOMDataTreeChangeService service; private final PathSelectionMode pathSelectionMode; private final LongAdder totalPathsCounter = new LongAdder(); private final LongAdder totalPrefixesCounter = new LongAdder(); + private final RouteEntryDependenciesContainerImpl entryDep; private DOMTransactionChain chain; @GuardedBy("this") private ListenerRegistration reg; private LocRibWriter(final RIBSupportContextRegistry registry, final DOMTransactionChain chain, - final YangInstanceIdentifier target, final Long ourAs, final DOMDataTreeChangeService service, - final ExportPolicyPeerTracker exportPolicyPeerTracker, final TablesKey tablesKey, - final PathSelectionMode pathSelectionMode) { + final YangInstanceIdentifier target, final Long ourAs, final DOMDataTreeChangeService service, + final ExportPolicyPeerTracker exportPolicyPeerTracker, final TablesKey tablesKey, + final PathSelectionMode pathSelectionMode) { this.chain = requireNonNull(chain); this.target = requireNonNull(target); - this.tableKey = RibSupportUtils.toYangTablesKey(tablesKey); - this.localTablesKey = tablesKey; + this.tableKey = RibSupportUtils.toYangTablesKey(requireNonNull(tablesKey)); this.locRibTarget = YangInstanceIdentifier.create(target.node(LocRib.QNAME).node(Tables.QNAME) - .node(this.tableKey).getPathArguments()); + .node(this.tableKey).getPathArguments()); this.ourAs = requireNonNull(ourAs); this.service = requireNonNull(service); this.ribSupport = registry.getRIBSupportContext(tablesKey).getRibSupport(); @@ -103,6 +101,8 @@ final class LocRibWriter implements AutoCloseable, TotalPrefixesCounter, TotalPa this.exportPolicyPeerTracker = exportPolicyPeerTracker; this.pathSelectionMode = pathSelectionMode; + this.entryDep = new RouteEntryDependenciesContainerImpl(this.ribSupport, + tablesKey, this.locRibTarget, this.exportPolicyPeerTracker); init(); } @@ -110,11 +110,11 @@ final class LocRibWriter implements AutoCloseable, TotalPrefixesCounter, TotalPa final DOMDataWriteTransaction tx = this.chain.newWriteOnlyTransaction(); tx.merge(LogicalDatastoreType.OPERATIONAL, this.locRibTarget.node(Routes.QNAME), this.ribSupport.emptyRoutes()); tx.merge(LogicalDatastoreType.OPERATIONAL, this.locRibTarget.node(Attributes.QNAME) - .node(ATTRIBUTES_UPTODATE_TRUE.getNodeType()), ATTRIBUTES_UPTODATE_TRUE); + .node(ATTRIBUTES_UPTODATE_TRUE.getNodeType()), ATTRIBUTES_UPTODATE_TRUE); tx.submit(); final YangInstanceIdentifier tableId = this.target.node(Peer.QNAME).node(Peer.QNAME).node(EffectiveRibIn.QNAME) - .node(Tables.QNAME).node(this.tableKey); + .node(Tables.QNAME).node(this.tableKey); final DOMDataTreeIdentifier wildcard = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, tableId); this.reg = this.service.registerDataTreeChangeListener(wildcard, this); } @@ -153,7 +153,7 @@ final class LocRibWriter implements AutoCloseable, TotalPrefixesCounter, TotalPa } @Nonnull - private RouteEntry createEntry(final PathArgument routeId) { + private RouteEntry createEntry(final NodeIdentifierWithPredicates routeId) { final RouteEntry ret = this.pathSelectionMode.createRouteEntry(this.ribSupport.isComplexRoute()); this.routeEntries.put(routeId, ret); this.totalPrefixesCounter.increment(); @@ -199,8 +199,7 @@ final class LocRibWriter implements AutoCloseable, TotalPrefixesCounter, TotalPa } private void initializeTableWithExistentRoutes(final DataTreeCandidateNode table, final PeerId peerIdOfNewPeer, - final YangInstanceIdentifier rootPath, - final DOMDataWriteTransaction tx) { + final YangInstanceIdentifier rootPath, final DOMDataWriteTransaction tx) { if (!table.getDataBefore().isPresent() && this.exportPolicyPeerTracker.isTableSupported(peerIdOfNewPeer)) { this.exportPolicyPeerTracker.registerPeerAsInitialized(peerIdOfNewPeer); LOG.debug("Peer {} table has been created, inserting existent routes", peerIdOfNewPeer); @@ -209,14 +208,14 @@ final class LocRibWriter implements AutoCloseable, TotalPrefixesCounter, TotalPa } final PeerRole newPeerRole = this.exportPolicyPeerTracker.getRole(IdentifierUtils.peerPath(rootPath)); final PeerExportGroup peerGroup = this.exportPolicyPeerTracker.getPeerGroup(newPeerRole); - this.routeEntries.forEach((key, value) -> value.writeRoute(peerIdOfNewPeer, key, - rootPath.getParent().getParent().getParent(), peerGroup, this.localTablesKey, - this.exportPolicyPeerTracker, this.ribSupport, tx)); + this.routeEntries.forEach((key, value) -> value.initializeBestPaths(this.entryDep, + new RouteEntryInfoImpl(peerIdOfNewPeer, key, rootPath.getParent().getParent().getParent()), + peerGroup, tx)); } } private void updateNodes(final DataTreeCandidateNode table, final PeerId peerId, final DOMDataWriteTransaction tx, - final Map routes) { + final Map routes) { for (final DataTreeCandidateNode child : table.getChildNodes()) { LOG.debug("Modification type {}", child.getModificationType()); if (Attributes.QNAME.equals(child.getIdentifier().getNodeType())) { @@ -237,8 +236,8 @@ final class LocRibWriter implements AutoCloseable, TotalPrefixesCounter, TotalPa final UnsignedInteger routerId = RouterIds.routerIdForPeerId(peerId); final Collection modifiedRoutes = this.ribSupport.changedRoutes(child); for (final DataTreeCandidateNode route : modifiedRoutes) { - final NodeIdentifierWithPredicates routeId = (NodeIdentifierWithPredicates) - this.ribSupport.createRouteKeyPathArgument(route.getIdentifier()); + final NodeIdentifierWithPredicates routeId = this.ribSupport + .createRouteKeyPathArgument((NodeIdentifierWithPredicates) route.getIdentifier()); RouteEntry entry = this.routeEntries.get(routeId); final Optional> maybeData = route.getDataAfter(); final Optional> maybeDataBefore = route.getDataBefore(); @@ -251,7 +250,7 @@ final class LocRibWriter implements AutoCloseable, TotalPrefixesCounter, TotalPa this.totalPathsCounter.increment(); } else if (entry != null) { this.totalPathsCounter.decrement(); - if(entry.removeRoute(routerId, this.ribSupport.extractPathId(maybeDataBefore.get()))) { + if (entry.removeRoute(routerId, this.ribSupport.extractPathId(maybeDataBefore.get()))) { this.routeEntries.remove(routeId); this.totalPrefixesCounter.decrement(); LOG.trace("Removed route from {}", routerId); @@ -273,8 +272,7 @@ final class LocRibWriter implements AutoCloseable, TotalPrefixesCounter, TotalPa LOG.trace("Best path has not changed, continuing"); continue; } - entry.updateRoute(this.localTablesKey, this.exportPolicyPeerTracker, this.locRibTarget, - this.ribSupport, tx, e.getKey().getRouteId()); + entry.updateBestPaths(entryDep, e.getKey().getRouteId(), tx); } } diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RouteEntryDependenciesContainerImpl.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RouteEntryDependenciesContainerImpl.java new file mode 100644 index 0000000000..c3ce714bff --- /dev/null +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RouteEntryDependenciesContainerImpl.java @@ -0,0 +1,53 @@ +/* + * 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.impl; + +import static java.util.Objects.requireNonNull; + +import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker; +import org.opendaylight.protocol.bgp.rib.spi.RIBSupport; +import org.opendaylight.protocol.bgp.rib.spi.entry.RouteEntryDependenciesContainer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; + +public final class RouteEntryDependenciesContainerImpl implements RouteEntryDependenciesContainer { + private final RIBSupport ribSupport; + private final TablesKey tablesKey; + private final YangInstanceIdentifier locRibTarget; + private final ExportPolicyPeerTracker exportPolicyPeerTracker; + + public RouteEntryDependenciesContainerImpl( + final RIBSupport ribSupport, + final TablesKey tablesKey, + final YangInstanceIdentifier locRibTarget, final ExportPolicyPeerTracker exportPolicyPeerTracker) { + this.ribSupport = requireNonNull(ribSupport); + this.tablesKey = requireNonNull(tablesKey); + this.locRibTarget = requireNonNull(locRibTarget); + this.exportPolicyPeerTracker = requireNonNull(exportPolicyPeerTracker); + } + + @Override + public RIBSupport getRibSupport() { + return this.ribSupport; + } + + @Override + public TablesKey getLocalTablesKey() { + return this.tablesKey; + } + + @Override + public YangInstanceIdentifier getLocRibTableTarget() { + return this.locRibTarget; + } + + @Override + public ExportPolicyPeerTracker getExportPolicyPeerTracker() { + return exportPolicyPeerTracker; + } +} diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RouteEntryInfoImpl.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RouteEntryInfoImpl.java new file mode 100644 index 0000000000..90a6a25ecb --- /dev/null +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RouteEntryInfoImpl.java @@ -0,0 +1,47 @@ +/* + * 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.impl; + +import static java.util.Objects.requireNonNull; + +import javax.annotation.Nonnull; +import org.opendaylight.protocol.bgp.rib.spi.entry.RouteEntryInfo; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; + +public final class RouteEntryInfoImpl implements RouteEntryInfo { + private final PeerId peerId; + private final NodeIdentifierWithPredicates key; + private final YangInstanceIdentifier rootPath; + + public RouteEntryInfoImpl(final PeerId peerId, final NodeIdentifierWithPredicates key, + final YangInstanceIdentifier rootPath) { + this.peerId = requireNonNull(peerId); + this.key = requireNonNull(key); + this.rootPath = requireNonNull(rootPath); + } + + @Nonnull + @Override + public PeerId getToPeerId() { + return this.peerId; + } + + @Nonnull + @Override + public NodeIdentifierWithPredicates getRouteId() { + return this.key; + } + + @Nonnull + @Override + public YangInstanceIdentifier getRootPath() { + return this.rootPath; + } +} diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AddPathRibSupport.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AddPathRibSupport.java index 242534f6ef..9c6e4721b8 100644 --- a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AddPathRibSupport.java +++ b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AddPathRibSupport.java @@ -12,6 +12,7 @@ import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; @@ -40,7 +41,7 @@ interface AddPathRibSupport { * @return routeId PathArgument + pathId or Null in case Add-path is not supported */ @Nullable - default PathArgument getRouteIdAddPath(long pathId, @Nonnull PathArgument routeId) { + default NodeIdentifierWithPredicates getRouteIdAddPath(long pathId, @Nonnull PathArgument routeId) { return null; } @@ -51,7 +52,9 @@ interface AddPathRibSupport { * @param routeKeyPathArgument routeKey Path Argument * @return new route Key */ - default @Nonnull PathArgument createRouteKeyPathArgument(@Nonnull PathArgument routeKeyPathArgument) { + default @Nonnull + NodeIdentifierWithPredicates createRouteKeyPathArgument( + @Nonnull NodeIdentifierWithPredicates routeKeyPathArgument) { return routeKeyPathArgument; } } diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/MultiPathAbstractRIBSupport.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/MultiPathAbstractRIBSupport.java index 2264e3873b..67c50972e5 100644 --- a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/MultiPathAbstractRIBSupport.java +++ b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/MultiPathAbstractRIBSupport.java @@ -9,7 +9,6 @@ package org.opendaylight.protocol.bgp.rib.spi; import com.google.common.collect.ImmutableMap; -import javax.annotation.Nonnull; import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.Routes; @@ -76,14 +75,12 @@ public abstract class MultiPathAbstractRIBSupport extends AbstractRIBSupport { return pathId; } - @Nonnull - @Override - public final PathArgument getRouteIdAddPath(final long pathId, final PathArgument routeId) { + public final NodeIdentifierWithPredicates getRouteIdAddPath(final long pathId, final PathArgument routeId) { return PathIdUtil.createNidKey(pathId, routeId, routeQName(), pathIdQName(), routeKeyQName()); } @Override - public final PathArgument createRouteKeyPathArgument(final PathArgument routeKey) { + public final NodeIdentifierWithPredicates createRouteKeyPathArgument(final NodeIdentifierWithPredicates routeKey) { final ImmutableMap keyValues = ImmutableMap.of(routeKeyQName(), PathIdUtil.getObjectKey(routeKey, routeKeyQName())); return new NodeIdentifierWithPredicates(routeQName(), keyValues); diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/RouteEntryDependenciesContainer.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/RouteEntryDependenciesContainer.java new file mode 100644 index 0000000000..9819f21337 --- /dev/null +++ b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/RouteEntryDependenciesContainer.java @@ -0,0 +1,53 @@ +/* + * 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.entry; + +import javax.annotation.Nonnull; +import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker; +import org.opendaylight.protocol.bgp.rib.spi.RIBSupport; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; + +/** + * Container wrapper for all dependencies related to Route Entry, required for process and storage. + */ +public interface RouteEntryDependenciesContainer { + /** + * Returns rib support. + * + * @return RIBSupport + */ + @Nonnull + RIBSupport getRibSupport(); + + + /** + * Returns the table key(AFI/SAFI) corresponding to the Route Entry. + * + * @return TablesKey + */ + @Nonnull + TablesKey getLocalTablesKey(); + + + /** + * Returns the loc-rib table to be updated and to which corresponds this Route Entry. + * + * @return YangInstanceIdentifier containing the path to loc-rib table. + */ + @Nonnull + YangInstanceIdentifier getLocRibTableTarget(); + + /** + * Return the ExportPolicyPeerTracker which tracks peers. + * + * @return ExportPolicyPeerTracker + */ + @Nonnull + ExportPolicyPeerTracker getExportPolicyPeerTracker(); +} diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/RouteEntryInfo.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/RouteEntryInfo.java new file mode 100644 index 0000000000..aa2d045730 --- /dev/null +++ b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/RouteEntryInfo.java @@ -0,0 +1,33 @@ +/* + * 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.entry; + +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; + +/** + * RouteEntryInfo wrapper contains all related information from new best path. + */ +public interface RouteEntryInfo extends RouteEntryKey { + /** + * peer Id where best path will be advertized. + * + * @return PeerId + */ + @Nonnull + PeerId getToPeerId(); + + /** + * Peer path of peer to which best path will be advertized. + * + * @return Root Path + */ + @Nonnull + YangInstanceIdentifier getRootPath(); +} diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/RouteEntryKey.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/RouteEntryKey.java new file mode 100644 index 0000000000..bfe533d707 --- /dev/null +++ b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/RouteEntryKey.java @@ -0,0 +1,21 @@ +/* + * 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.entry; + +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; + +public interface RouteEntryKey { + /** + * Returns route containing prefix. + * + * @return Route key + */ + @Nonnull + NodeIdentifierWithPredicates getRouteId(); +} -- 2.36.6