Use boxed Path IDs for AddPath 25/78525/15
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 6 Dec 2018 21:02:28 +0000 (22:02 +0100)
committerRobert Varga <nite@hq.sk>
Mon, 10 Dec 2018 14:43:44 +0000 (14:43 +0000)
AddPath entries are usually used to instantiate PathId objects,
which are forcing boxing. Since we are already keeping path IDs
in boxed format, this patch makes sure we take advantage of this.

Change-Id: Ia2566e48ef44313f5448bf4e23f4ff0f41c8a69b
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/add/AddPathBestPath.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathSelector.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/AllPathsRouteEntry.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseBestPath.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractBestPath.java

index 3b49d222d3141ad93be8051a0c2f355018fd6358..02aef5337285c33b48313cbe80bc4f431762677d 100644 (file)
@@ -67,7 +67,7 @@ public abstract class AddPathAbstractRouteEntry<C extends Routes & DataObject &
     private R createRoute(final RIBSupport<C, S, R, I> ribSup, final String routeKey, final AddPathBestPath path) {
         final OffsetMap map = getOffsets();
         final R route = map.getValue(this.values, map.offsetOf(path.getRouteKey()));
-        return ribSup.createRoute(route, ribSup.createRouteListKey(pathIdObj(path.getPathId()), routeKey),
+        return ribSup.createRoute(route, ribSup.createRouteListKey(pathIdObj(path.getPathIdLong()), routeKey),
             path.getAttributes());
     }
 
@@ -169,7 +169,7 @@ public abstract class AddPathAbstractRouteEntry<C extends Routes & DataObject &
     private void selectBest(final RouteKey key, final AddPathSelector selector) {
         final int offset = this.offsets.offsetOf(key);
         final R route = this.offsets.getValue(this.values, offset);
-        final long pathId = this.offsets.getValue(this.pathsId, offset);
+        final Long pathId = this.offsets.getValue(this.pathsId, offset);
         LOG.trace("Processing router key {} route {}", key, route);
         selector.processPath(route.getAttributes(), key, offset, pathId);
     }
@@ -232,7 +232,7 @@ public abstract class AddPathAbstractRouteEntry<C extends Routes & DataObject &
         });
     }
 
-    private static PathId pathIdObj(final long pathId) {
+    private static PathId pathIdObj(final Long pathId) {
         return pathId == NON_PATH_ID_VALUE ? NON_PATH_ID : new PathId(pathId);
     }
 }
index 7fc2a411fa16be612c672f20244c9253d1263b30..330fab90f6adada71847afb3313f6c953c90a88c 100644 (file)
@@ -19,28 +19,30 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.
 
 public final class AddPathBestPath extends AbstractBestPath {
     private final RouteKey routeKey;
-    private final int offsetPosition;
-    private final long pathId;
+    private final Long pathId;
+    private final int offset;
 
-    public AddPathBestPath(@Nonnull final BestPathState state, @Nonnull final RouteKey key, final int offsetPosition,
-            final long pathId) {
+    public AddPathBestPath(@Nonnull final BestPathState state, @Nonnull final RouteKey key, final @Nonnull Long pathId,
+            final int offset) {
         super(state);
         this.routeKey = requireNonNull(key);
-        this.offsetPosition = offsetPosition;
-        this.pathId = pathId;
+        this.pathId = requireNonNull(pathId);
+        this.offset = offset;
     }
 
     public RouteKey getRouteKey() {
         return this.routeKey;
     }
 
+    public int getOffset() {
+        return offset;
+    }
+
     @Override
     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
-        toStringHelper.add("routeKey", this.routeKey);
-        toStringHelper.add("state", this.state);
-        toStringHelper.add("offsetPosition", this.offsetPosition);
-        toStringHelper.add("pathId", this.pathId);
-        return toStringHelper;
+        return super.addToStringAttributes(toStringHelper.add("routeKey", this.routeKey)
+            .add("pathId", this.pathId)
+            .add("offset", offset));
     }
 
     @Override
@@ -72,7 +74,7 @@ public final class AddPathBestPath extends AbstractBestPath {
             return false;
         }
 
-        return this.pathId == other.pathId;
+        return this.pathId.equals(other.pathId);
     }
 
     @Override
@@ -89,4 +91,14 @@ public final class AddPathBestPath extends AbstractBestPath {
     public long getPathId() {
         return this.pathId;
     }
+
+    /**
+     * Return the boxed value equivalent of {@link #getPathId()}. This class uses boxed instances internally, hence
+     * this method exposes it.
+     *
+     * @return Path Id as a {@link Long}
+     */
+    public @Nonnull Long getPathIdLong() {
+        return this.pathId;
+    }
 }
index 86a3242b027c8a8652b0e41cb0b0ea98803f1b6b..61f3dad3acfd5c3dd1eee0de88013bd333a7368e 100644 (file)
@@ -20,14 +20,14 @@ public final class AddPathSelector extends AbstractBestPathSelector {
     private static final Logger LOG = LoggerFactory.getLogger(AddPathSelector.class);
 
     private RouteKey bestRouteKey;
-    private int bestOffsetPosition;
-    private long bestPathId;
+    private Long bestPathId;
+    private int bestOffset;
 
     public AddPathSelector(final long ourAs) {
         super(ourAs);
     }
 
-    void processPath(final Attributes attrs, final RouteKey key, final int offsetPosition, final long pathId) {
+    void processPath(final Attributes attrs, final RouteKey key, final int offsetPosition, final Long pathId) {
         // Consider only non-null attributes
         if (attrs != null) {
             final UnsignedInteger routerId = key.getRouterId();
@@ -45,7 +45,7 @@ public final class AddPathSelector extends AbstractBestPathSelector {
                 this.bestOriginatorId = originatorId;
                 this.bestState = state;
                 this.bestRouteKey = key;
-                this.bestOffsetPosition = offsetPosition;
+                this.bestOffset = offsetPosition;
                 this.bestPathId = pathId;
             }
         }
@@ -53,6 +53,6 @@ public final class AddPathSelector extends AbstractBestPathSelector {
 
     public AddPathBestPath result() {
         return this.bestRouteKey == null ? null : new AddPathBestPath(this.bestState, this.bestRouteKey,
-                this.bestOffsetPosition, this.bestPathId);
+            this.bestPathId, this.bestOffset);
     }
 }
index dc2ff974fb05333c968ac30e4ecb82ee35fb603b..3259c03551adb0a823da513b60dbb3b04773deb9 100644 (file)
@@ -47,8 +47,8 @@ final class AllPathsRouteEntry<C extends Routes & DataObject & ChoiceIn<Tables>,
                 final Route route = this.offsets.getValue(this.values, offset);
                 if (route != null) {
                     final BestPathState state = new BestPathStateImpl(route.getAttributes());
-                    final AddPathBestPath bestPath = new AddPathBestPath(state, key, offset,
-                            this.offsets.getValue(this.pathsId, offset));
+                    final AddPathBestPath bestPath = new AddPathBestPath(state, key,
+                            this.offsets.getValue(this.pathsId, offset), offset);
                     newBestPathList.add(bestPath);
                 }
             }
index 14052e424f848fed3162473cb6e466e66d389461..bfee17c448736a6060e473a4d02607570fbc02d9 100644 (file)
@@ -43,9 +43,7 @@ final class BaseBestPath extends AbstractBestPath {
 
     @Override
     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
-        toStringHelper.add("routerId", this.routerId);
-        toStringHelper.add("state", this.state);
-        return toStringHelper;
+        return super.addToStringAttributes(toStringHelper.add("routerId", this.routerId));
     }
 
     @Override
index 74e6baed38bd5b9d56a69618937101e56474e067..34fb49e924f26eb8ca44049c9daa11b81eb618db 100644 (file)
@@ -11,6 +11,7 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
 import org.opendaylight.protocol.bgp.mode.api.BestPath;
 import org.opendaylight.protocol.bgp.mode.api.BestPathState;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
@@ -22,7 +23,9 @@ public abstract class AbstractBestPath implements BestPath {
         this.state = requireNonNull(state);
     }
 
-    protected abstract MoreObjects.ToStringHelper addToStringAttributes(MoreObjects.ToStringHelper toStringHelper);
+    protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+        return toStringHelper.add("state", state);
+    }
 
     @VisibleForTesting
     public final BestPathState getState() {