import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID_VALUE;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Override
public final Optional<StaleBestPathRoute<C, S, R, I>> removeStalePaths(final RIBSupport<C, S, R, I> ribSupport,
final String routeKey) {
- if ((this.bestPathRemoved == null || this.bestPathRemoved.isEmpty()) && this.removedPathsId == null) {
- return Optional.empty();
+ final List<PathId> stalePaths;
+ if (bestPathRemoved != null && !bestPathRemoved.isEmpty()) {
+ stalePaths = bestPathRemoved.stream().map(AddPathBestPath::getPathId)
+ .map(AddPathAbstractRouteEntry::pathIdObj).collect(Collectors.toList());
+ bestPathRemoved = null;
+ } else {
+ stalePaths = Collections.emptyList();
}
- List<Long> stalePaths = Collections.emptyList();
- if (this.bestPathRemoved != null && !this.bestPathRemoved.isEmpty()) {
- stalePaths = this.bestPathRemoved.stream().map(AddPathBestPath::getPathId).collect(Collectors.toList());
- this.bestPathRemoved = null;
+
+ List<PathId> removedPaths;
+ if (removedPathsId != null) {
+ removedPaths = Lists.transform(removedPathsId, AddPathAbstractRouteEntry::pathIdObj);
+ this.removedPathsId = null;
+ } else {
+ removedPaths = Collections.emptyList();
}
- final StaleBestPathRoute<C, S, R, I> stale = new StaleBestPathRoute<>(ribSupport, routeKey, stalePaths,
- this.removedPathsId, this.isNonAddPathBestPathNew);
- this.removedPathsId = null;
- return Optional.of(stale);
+
+ return stalePaths.isEmpty() && removedPaths.isEmpty() ? Optional.empty()
+ : Optional.of(new StaleBestPathRoute<>(ribSupport, routeKey, stalePaths,
+ removedPaths, this.isNonAddPathBestPathNew));
}
@Override
*/
package org.opendaylight.protocol.bgp.mode.impl.base;
+import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID;
+
import java.util.Collections;
import java.util.List;
import java.util.Optional;
if (this.removedBestPath == null) {
return Optional.empty();
}
- final StaleBestPathRoute<C, S, R, I> stale = new StaleBestPathRoute<>(ribSupport, routeKey);
+ final StaleBestPathRoute<C, S, R, I> stale = new StaleBestPathRoute<>(ribSupport, routeKey,
+ Collections.singletonList(NON_PATH_ID), Collections.emptyList(), true);
this.removedBestPath = null;
return Optional.of(stale);
}
* 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 static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID_VALUE;
-
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
-import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.PathId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
public StaleBestPathRoute(
final RIBSupport<C, S, R, I> ribSupport,
final String routeKey,
- final List<Long> staleRoutesPathIds,
- final List<Long> withdrawalRoutePathIds,
+ final List<PathId> staleRoutesPathIds,
+ final List<PathId> withdrawalRoutePathIds,
final boolean isNonAddPathBestPathNew) {
this.isNonAddPathBestPathNew = isNonAddPathBestPathNew;
- this.staleRouteKeyIdentifier = staleRoutesPathIds.stream().map(StaleBestPathRoute::pathIdObj)
+ this.staleRouteKeyIdentifier = staleRoutesPathIds.stream()
.map(pathId -> ribSupport.createRouteListKey(pathId, routeKey)).collect(Collectors.toList());
if (withdrawalRoutePathIds != null) {
- this.addPathRouteKeyIdentifier = withdrawalRoutePathIds.stream().map(StaleBestPathRoute::pathIdObj)
+ this.addPathRouteKeyIdentifier = withdrawalRoutePathIds.stream()
.map(pathId -> ribSupport.createRouteListKey(pathId, routeKey)).collect(Collectors.toList());
} else {
this.addPathRouteKeyIdentifier = Collections.emptyList();
this.nonAddPathRouteKeyIdentifier = ribSupport.createRouteListKey(routeKey);
}
- public StaleBestPathRoute(final RIBSupport<C, S, R, I> ribSupport, final String routeKey) {
- this(ribSupport, routeKey, Collections.singletonList(NON_PATH_ID_VALUE),
- Collections.emptyList(), true);
- }
-
public I getNonAddPathRouteKeyIdentifier() {
return this.nonAddPathRouteKeyIdentifier;
}
public boolean isNonAddPathBestPathNew() {
return this.isNonAddPathBestPathNew;
}
-
- private static PathId pathIdObj(final Long pathId) {
- return pathId == NON_PATH_ID_VALUE ? PathIdUtil.NON_PATH_ID : new PathId(pathId);
- }
}