From: Robert Varga Date: Fri, 14 Dec 2018 02:23:38 +0000 (+0100) Subject: Pass PathIds to StaleBestRoute X-Git-Tag: release/neon~56 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=25ef3d478a6c6291503a8526dad11b884d7b3e19;p=bgpcep.git Pass PathIds to StaleBestRoute At the end of the day, StaleBestRoute needs to be refactored so that we have two implementations: one for addpath, one for non-addpath selection. As a first step, make sure callers allocate PathIds and pass them to StaleBestRoute. Change-Id: Ief9a0280eec1bfa99530f3aedef8451a98ac35df Signed-off-by: Robert Varga --- diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathAbstractRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathAbstractRouteEntry.java index 172dfd562f..c73d63c235 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathAbstractRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathAbstractRouteEntry.java @@ -12,6 +12,7 @@ import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID; 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; @@ -110,18 +111,26 @@ public abstract class AddPathAbstractRouteEntry> removeStalePaths(final RIBSupport ribSupport, final String routeKey) { - if ((this.bestPathRemoved == null || this.bestPathRemoved.isEmpty()) && this.removedPathsId == null) { - return Optional.empty(); + final List 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 stalePaths = Collections.emptyList(); - if (this.bestPathRemoved != null && !this.bestPathRemoved.isEmpty()) { - stalePaths = this.bestPathRemoved.stream().map(AddPathBestPath::getPathId).collect(Collectors.toList()); - this.bestPathRemoved = null; + + List removedPaths; + if (removedPathsId != null) { + removedPaths = Lists.transform(removedPathsId, AddPathAbstractRouteEntry::pathIdObj); + this.removedPathsId = null; + } else { + removedPaths = Collections.emptyList(); } - final StaleBestPathRoute 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 diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseRouteEntry.java index 701f4dc931..3a2f531bb0 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseRouteEntry.java @@ -7,6 +7,8 @@ */ 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; @@ -110,7 +112,8 @@ final class BaseRouteEntry, if (this.removedBestPath == null) { return Optional.empty(); } - final StaleBestPathRoute stale = new StaleBestPathRoute<>(ribSupport, routeKey); + final StaleBestPathRoute stale = new StaleBestPathRoute<>(ribSupport, routeKey, + Collections.singletonList(NON_PATH_ID), Collections.emptyList(), true); this.removedBestPath = null; return Optional.of(stale); } diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/StaleBestPathRoute.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/StaleBestPathRoute.java index 43b2543d37..f20cd5d401 100644 --- a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/StaleBestPathRoute.java +++ b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/StaleBestPathRoute.java @@ -5,15 +5,11 @@ * 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; @@ -42,15 +38,15 @@ public final class StaleBestPathRoute ribSupport, final String routeKey, - final List staleRoutesPathIds, - final List withdrawalRoutePathIds, + final List staleRoutesPathIds, + final List 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(); @@ -58,11 +54,6 @@ public final class StaleBestPathRoute ribSupport, final String routeKey) { - this(ribSupport, routeKey, Collections.singletonList(NON_PATH_ID_VALUE), - Collections.emptyList(), true); - } - public I getNonAddPathRouteKeyIdentifier() { return this.nonAddPathRouteKeyIdentifier; } @@ -93,8 +84,4 @@ public final class StaleBestPathRoute