*/
package org.opendaylight.protocol.bgp.mode.impl.add;
+import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID;
+
import com.google.common.collect.Lists;
import com.google.common.primitives.UnsignedInteger;
import java.util.ArrayList;
if (this.removedPaths != null) {
this.removedPaths.forEach(removedPath -> {
final PathArgument routeIdAddPath = ribSupport.getRouteIdAddPath(removedPath.getPathId(), routeIdPA);
- fillAdjRibsOut(true, null, null, null, routeIdPA, routeIdAddPath,
+ final PathArgument routeIdAddPathDefault = ribSupport.getRouteIdAddPath(NON_PATH_ID, routeIdPA);
+ fillAdjRibsOut(true, null, null, null,
+ routeIdAddPathDefault, routeIdAddPath,
RouterIds.createPeerId(removedPath.getRouteId()), peerPT, localTK, ribSupport, tx);
});
this.removedPaths = null;
final PeerExportGroup peerGroup, final boolean destPeerSupAddPath, final BestPath path,
final YangInstanceIdentifier rootPath, final TablesKey localTK, final RIBSupport ribSup,
final DOMDataWriteTransaction tx) {
- final PathArgument routeIdAddPath = ribSup.getRouteIdAddPath(path.getPathId(), routeId);
final ContainerNode effectiveAttributes = peerGroup
.effectiveAttributes(getRoutePeerIdRole(peerPT,path.getPeerId()), path.getAttributes());
+ PathArgument routeIdAddPath;
if (destPeerSupAddPath) {
- writeRoute(destPeer, getAdjRibOutYII(ribSup, rootPath, routeIdAddPath, localTK), effectiveAttributes,
- createValue(routeIdAddPath, path), ribSup, tx);
+ routeIdAddPath = ribSup.getRouteIdAddPath(path.getPathId(), routeId);
} else {
- writeRoute(destPeer, getAdjRibOutYII(ribSup, rootPath, routeId, localTK), effectiveAttributes,
- createValue(routeId, path), ribSup, tx);
+ routeIdAddPath = ribSup.getRouteIdAddPath(NON_PATH_ID, routeId);
}
+ writeRoute(destPeer, getAdjRibOutYII(ribSup, rootPath, 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);
final MapEntryNode addPathValue = createValue(routeIdAddPath, path);
- final MapEntryNode value = createValue(routeIdPA, path);
+ final MapEntryNode defaultValue = createValue(routeIdAddPathDefault, path);
LOG.trace("Selected best value {}", addPathValue);
fillLocRib(pathAddPathTarget, addPathValue, tx);
- fillAdjRibsOut(isFirstBestPath, path.getAttributes(), value, addPathValue, routeIdPA, routeIdAddPath,
- path.getPeerId(), peerPT, localTK,
- ribSup, tx);
+ fillAdjRibsOut(isFirstBestPath, path.getAttributes(), defaultValue, addPathValue, routeIdAddPathDefault,
+ routeIdAddPath, path.getPeerId(), peerPT, localTK, ribSup, tx);
}
private void fillAdjRibsOut(final boolean isFirstBestPath, final ContainerNode attributes,
- final NormalizedNode<?, ?> value, final MapEntryNode addPathValue, final PathArgument routeId,
+ final MapEntryNode defaultValue, final MapEntryNode addPathValue,
+ final PathArgument routeIdAddPathDefault,
final PathArgument routeIdAddPath, final PeerId routePeerId, final ExportPolicyPeerTracker peerPT,
final TablesKey localTK, final RIBSupport ribSup, final DOMDataWriteTransaction tx) {
/*
update(destPeer, getAdjRibOutYII(ribSup, rootPath, routeIdAddPath, localTK),
effectiveAttributes, addPathValue, ribSup, tx);
} else if (!this.oldNonAddPathBestPathTheSame) {
- update(destPeer, getAdjRibOutYII(ribSup, rootPath, routeId, localTK),
- effectiveAttributes, value, ribSup, tx);
+ update(destPeer, getAdjRibOutYII(ribSup, rootPath, routeIdAddPathDefault, localTK),
+ effectiveAttributes, defaultValue, ribSup, tx);
}
}
});
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.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
import org.slf4j.Logger;
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);
+ if (routeIdDest == null) {
+ routeIdDest = routeId;
+ }
final ContainerNode effAttrib = peerGroup.effectiveAttributes(
getRoutePeerIdRole(peerPT, path.getPeerId()), path.getAttributes());
- writeRoute(destPeer, getAdjRibOutYII(ribSupport, rootPath, routeId, localTK), effAttrib,
- createValue(routeId, path), ribSupport, tx);
+ writeRoute(destPeer, getAdjRibOutYII(ribSupport, rootPath, routeIdDest, localTK), effAttrib,
+ createValue(routeIdDest, path), ribSupport, tx);
}
}
}
final YangInstanceIdentifier locRibTarget, final ExportPolicyPeerTracker peerPT,
final TablesKey localTK, final RIBSupport ribSup, final DOMDataWriteTransaction tx) {
LOG.trace("Best Path removed {}", path);
- final PathArgument routeIdAddPath = ribSup.getRouteIdAddPath(path.getPathId(), routeIdPA);
- final YangInstanceIdentifier pathTarget = ribSup.routePath(locRibTarget.node(ROUTES_IDENTIFIER), routeIdPA);
- YangInstanceIdentifier pathAddPathTarget = null;
- if (routeIdAddPath != null) {
- pathAddPathTarget = ribSup.routePath(locRibTarget.node(ROUTES_IDENTIFIER), routeIdAddPath);
+ PathArgument routeIdTarget = ribSup.getRouteIdAddPath(path.getPathId(), routeIdPA);
+ if (routeIdTarget == null) {
+ routeIdTarget = routeIdPA;
}
- fillLocRib(pathAddPathTarget == null ? pathTarget : pathAddPathTarget, null, tx);
- fillAdjRibsOut(null, null, routeIdPA, path.getPeerId(), peerPT, localTK, ribSup, tx);
+ fillLocRib(ribSup.routePath(locRibTarget.node(ROUTES_IDENTIFIER), routeIdTarget), null, tx);
+ fillAdjRibsOut(null, null, routeIdTarget, path.getPeerId(), peerPT, localTK, ribSup, 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) {
- final PathArgument routeIdAddPath = ribSup.getRouteIdAddPath(path.getPathId(), routeIdPA);
- final YangInstanceIdentifier pathTarget = ribSup.routePath(locRibTarget.node(ROUTES_IDENTIFIER), routeIdPA);
- final NormalizedNode<?, ?> value = createValue(routeIdPA, path);
- NormalizedNode<?, ?> addPathValue = null;
- YangInstanceIdentifier pathAddPathTarget = null;
- if (routeIdAddPath == null) {
- LOG.trace("Selected best value {}", value);
- } else {
- pathAddPathTarget = ribSup.routePath(locRibTarget.node(ROUTES_IDENTIFIER), routeIdAddPath);
- addPathValue = createValue(routeIdAddPath, path);
- LOG.trace("Selected best value {}", addPathValue);
+ PathArgument routeIdDest = ribSup.getRouteIdAddPath(path.getPathId(), routeIdPA);
+ if (routeIdDest == null) {
+ routeIdDest = routeIdPA;
}
- fillLocRib(pathAddPathTarget == null ? pathTarget : pathAddPathTarget,
- addPathValue == null ? value : addPathValue, tx);
- fillAdjRibsOut(path.getAttributes(), value, routeIdPA, path.getPeerId(), peerPT, localTK, ribSup, tx);
+
+ final MapEntryNode value = createValue(routeIdDest, path);
+ LOG.trace("Selected best value {}", value);
+
+ 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);
}
final OffsetMap getOffsets() {
}
@VisibleForTesting
- private void fillAdjRibsOut(final ContainerNode attributes, final NormalizedNode<?, ?> value,
+ 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) {
/*
.node(RibSupportUtils.toYangTablesKey(localTK)).node(ROUTES_IDENTIFIER), routeId);
}
- protected PeerRole getRoutePeerIdRole(final ExportPolicyPeerTracker peerPT, final PeerId routePeerId) {
+ protected static PeerRole getRoutePeerIdRole(final ExportPolicyPeerTracker peerPT, final PeerId routePeerId) {
for (final PeerRole role : PeerRole.values()) {
final PeerExportGroup peerGroup = peerPT.getPeerGroup(role);
if (peerGroup != null && peerGroup.containsPeer(routePeerId)) {
if (!table.getDataBefore().isPresent() && this.exportPolicyPeerTracker.isTableSupported(peerIdOfNewPeer)) {
this.exportPolicyPeerTracker.registerPeerAsInitialized(peerIdOfNewPeer);
LOG.debug("Peer {} table has been created, inserting existent routes", peerIdOfNewPeer);
+ if (this.routeEntries.isEmpty()) {
+ return;
+ }
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,
}
private class ConfigLoaderImplRunnable implements Runnable {
+ @GuardedBy("this")
private final WatchService watchService;
ConfigLoaderImplRunnable(final WatchService watchService) {
@Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
- handleChanges(this.watchService);
+ handleChanges();
}
}
- private synchronized void handleChanges(final WatchService watch) {
+ private synchronized void handleChanges() {
final WatchKey key;
try {
- key = watch.take();
+ key = this.watchService.take();
} catch (final InterruptedException | ClosedWatchServiceException e) {
if (!ConfigLoaderImpl.this.closed) {
LOG.warn(INTERRUPTED, e);