Reduce number of parameters for path selection 84/68784/2
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Sun, 7 Jan 2018 21:35:25 +0000 (22:35 +0100)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Tue, 27 Feb 2018 08:04:42 +0000 (09:04 +0100)
-enforce findbug.

Change-Id: Idc9cb566e31b81c7d87cf544016525122487393b
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
24 files changed:
bgp/path-selection-mode/pom.xml
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/RouteEntry.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathAbstractRouteEntry.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/ComplexRouteEntry.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntry.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/ComplexRouteEntry.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntry.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseAbstractRouteEntry.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseComplexRouteEntry.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseSimpleRouteEntry.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractRouteEntry.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/RouteEntryUtil.java
bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/AbstractRouteEntryTest.java
bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntryTest.java
bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntryTest.java
bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseRouteEntryTest.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RouteEntryDependenciesContainerImpl.java [new file with mode: 0644]
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RouteEntryInfoImpl.java [new file with mode: 0644]
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/AddPathRibSupport.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/MultiPathAbstractRIBSupport.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/RouteEntryDependenciesContainer.java [new file with mode: 0644]
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/RouteEntryInfo.java [new file with mode: 0644]
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/RouteEntryKey.java [new file with mode: 0644]

index 2541e0a80249ab671ba9d7df55818d708e4bb5bc..1e728045feb6d6666056f83ec40914f711900b5a 100644 (file)
                     <failOnError>false</failOnError>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>findbugs-maven-plugin</artifactId>
+                <configuration>
+                    <failOnError>true</failOnError>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
index 7535b7407a5d40dc81296dcf634b4cc055ee9ed3..8d19c2fdb393b7664f8169fdb8fd644a79783575 100644 (file)
@@ -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
index d6854b0b20e9c244ddd4d502d798aef568bf381c..9111159e6c0379b49224161a69120e76f7968b9d 100644 (file)
@@ -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<AddPathBestPath> {
 
     private static final Logger LOG = LoggerFactory.getLogger(AddPathAbstractRouteEntry.class);
     private List<AddPathBestPath> 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<AddPathBestPath> 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) {
index 2c829c4ad95349a5d246d5654336bb54400d77a0..8082a5bd4aa041c520f662532a605154f2c35a7c 100644 (file)
@@ -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();
index 4d01b8bba99d12a2db6ac847f70c3934e5c5234a..475925aca3325a7a88d118c3a3a5e55d33502d15 100644 (file)
@@ -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);
     }
 
index 747496abd30e3d8a89bfe100064d127d757dd65e..29153f4854946039bd8f73f6ed612d652408403c 100644 (file)
@@ -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);
     }
 
index 673baa487516bc9714a47a9e8068880c125d2cf2..7beb3ee44cd800bc514cde18231a4bf651703a82 100644 (file)
@@ -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);
     }
 
index 4cae936af56f007ce20a079998ebefb2d5857fc5..812373b01cfddf476110a3e29fab815f73e2c7f8 100644 (file)
@@ -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<BaseBestPath> {
     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) {
index 4195a5c6e12f4d295dbf9baa99ed15a7446e7467..3cd3c2743092e353af9ae959ce14051afaec0f80 100644 (file)
@@ -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);
index 2c1aa24191a7b90b3fad5bc31162e013d0473be8..fa3b1d66d34cc1fc1ea590f491d8588157b39915 100644 (file)
@@ -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);
     }
 }
index ec2a4a0256edb2bf81c0a750cbab896e49183f7a..ba5220ef211332893460c22acfed1b07ef76166d 100644 (file)
@@ -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<T extends BestPath> 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) {
index 2753d9d6e25c9602723bee48bfb051ccd27c6946..4a8512da94ba613ad8468f13fbde21d71a97c18c 100644 (file)
@@ -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<NodeIdentifierWithPredicates, MapEntryNode> 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<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder
-                = Builders.mapEntryBuilder();
-        mapEntryBuilder.withNodeIdentifier((NodeIdentifierWithPredicates) routeId);
+                =
+                Builders.mapEntryBuilder();
+        mapEntryBuilder.withNodeIdentifier(routeId);
         mapEntryBuilder.addChild(path.getAttributes());
         mapValues.getValue().forEach(mapEntryBuilder::addChild);
         return mapEntryBuilder.build();
index d128436e93303df5e0b1fc543df68065b66c8e07..058219fc13f2a2927177220838376ce8766786e2 100644 (file)
@@ -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<YangInstanceIdentifier> 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() {
index 4f8f4af71c5d8262fc4e8340527538fc12587053..3d31690e10f02f56dbf7e27ded1180b8fcc1d7b3 100644 (file)
@@ -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<YangInstanceIdentifier, Long> 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));
index e941a17dd91d9b7494e860dba130f5d0a343ca77..3fda25c575949df4cb0b31fe364b909654a65d6a 100644 (file)
@@ -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<YangInstanceIdentifier, Long> 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<YangInstanceIdentifier, Long> 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));
index 3accb42d0386fd6be57139b3ebd149825a1bed2f..97483d3c05d18925263dd0b051fe226420b3a5c5 100644 (file)
@@ -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<YangInstanceIdentifier, Long> 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<YangInstanceIdentifier, Long> 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());
     }
 }
index 4c68e9a8ecf14c022a3fdc20dd91acc5e74fa9e1..eb59dd7ab467fcfd878a7b2b812bb3f322c1e39d 100644 (file)
@@ -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<Boolean> ATTRIBUTES_UPTODATE_TRUE = ImmutableNodes
             .leafNode(QName.create(Attributes.QNAME, "uptodate"), Boolean.TRUE);
 
-    private final Map<PathArgument, RouteEntry> routeEntries = new HashMap<>();
+    private final Map<NodeIdentifierWithPredicates, RouteEntry> 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<LocRibWriter> 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<RouteUpdateKey, RouteEntry> routes) {
+            final Map<RouteUpdateKey, RouteEntry> 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<DataTreeCandidateNode> 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<NormalizedNode<?, ?>> maybeData = route.getDataAfter();
             final Optional<NormalizedNode<?, ?>> 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 (file)
index 0000000..c3ce714
--- /dev/null
@@ -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 (file)
index 0000000..90a6a25
--- /dev/null
@@ -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;
+    }
+}
index 242534f6ef998c0f709eadfac0b7c41850cd8e62..9c6e4721b8f4d6679165b88f106ae882dcc6d037 100644 (file)
@@ -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;
     }
 }
index 2264e3873b6c0d9a45fd7a5a9892cd183d3be2a9..67c50972e517a3b194ba0dc373874a22b3bb520d 100644 (file)
@@ -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<QName, Object> 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 (file)
index 0000000..9819f21
--- /dev/null
@@ -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 (file)
index 0000000..aa2d045
--- /dev/null
@@ -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 (file)
index 0000000..bfe533d
--- /dev/null
@@ -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();
+}