-enforce findbug.
Change-Id: Idc9cb566e31b81c7d87cf544016525122487393b
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
<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>
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;
/**
*/
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.
*
/**
* 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
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;
* 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;
}
@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;
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,
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) {
* 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;
}
@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();
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;
}
@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);
}
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;
}
@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);
}
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;
}
@Override
- public MapEntryNode createValue(final PathArgument routeId, final BestPath path) {
+ public MapEntryNode createValue(final NodeIdentifierWithPredicates routeId, final AddPathBestPath path) {
return RouteEntryUtil.createSimpleRouteValue(routeId, path);
}
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;
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;
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) {
}
@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;
}
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() {
}
@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
* 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) {
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;
}
@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);
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 {
}
@Override
- public MapEntryNode createValue(final PathArgument routeId, final BestPath path) {
+ public MapEntryNode createValue(final NodeIdentifierWithPredicates routeId, final BaseBestPath path) {
return RouteEntryUtil.createSimpleRouteValue(routeId, path);
}
}
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;
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) {
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;
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();
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;
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;
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() {
.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));
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));
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;
@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();
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));
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));
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));
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;
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));
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));
}
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());
}
}
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;
@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();
this.exportPolicyPeerTracker = exportPolicyPeerTracker;
this.pathSelectionMode = pathSelectionMode;
+ this.entryDep = new RouteEntryDependenciesContainerImpl(this.ribSupport,
+ tablesKey, this.locRibTarget, this.exportPolicyPeerTracker);
init();
}
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);
}
}
@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();
}
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);
}
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())) {
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();
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);
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);
}
}
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
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;
* @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;
}
* @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;
}
}
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;
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);
--- /dev/null
+/*
+ * 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();
+}
--- /dev/null
+/*
+ * 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();
+}
--- /dev/null
+/*
+ * 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();
+}