Pass PathIds to StaleBestRoute 79/78779/6
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 14 Dec 2018 02:23:38 +0000 (03:23 +0100)
committerRobert Varga <nite@hq.sk>
Fri, 14 Dec 2018 19:40:39 +0000 (19:40 +0000)
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 <robert.varga@pantheon.tech>
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/base/BaseRouteEntry.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/entry/StaleBestPathRoute.java

index 172dfd562fd9cc2f8ecf684ffab98d3e2ce042d4..c73d63c23580c0221acdcd1327ca2a00661e1d39 100644 (file)
@@ -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<C extends Routes & DataObject &
     @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
index 701f4dc9319023a69613075ee1da89bb6c49a671..3a2f531bb0b5c4bf60e0be809aa69663fc130bbf 100644 (file)
@@ -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<C extends Routes & DataObject & ChoiceIn<Tables>,
         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);
     }
index 43b2543d37532c837bd82761cd2269252a5bfe70..f20cd5d4018a5a237f898744e532aa463e108363 100644 (file)
@@ -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<C extends Routes & DataObject & ChoiceIn<T
     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();
@@ -58,11 +54,6 @@ public final class StaleBestPathRoute<C extends Routes & DataObject & ChoiceIn<T
         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;
     }
@@ -93,8 +84,4 @@ public final class StaleBestPathRoute<C extends Routes & DataObject & ChoiceIn<T
     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);
-    }
 }