Fix RouteEntry.{add,remove}Route() 26/78526/11
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 6 Dec 2018 21:30:03 +0000 (22:30 +0100)
committerClaudio David Gasparini <claudio.gasparini@pantheon.tech>
Mon, 10 Dec 2018 06:49:24 +0000 (06:49 +0000)
This API is interfacing with MD-SAL, where values are boxed,
hence these should be propagate as they are, not forcibly unboxed
in LocRibWriter.

This improves non-addpath performance, as we are simply skipping
the unboxing operation, since we do not care at all about pathIds.

Also hide RouteKey constructor and its accessor, as everything
aside of it being an identifier (hence immutable) is a purely
package-private matter.

Change-Id: Ica7612ec5e6df8d07eb16294c1efa5fb0428f884
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/path-selection-mode/pom.xml
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/RouteEntry.java
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/RouteKey.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseRouteEntry.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java

index 71ed2bf09cdc3fa3c977c1ffe8cc3c06366fe047..0c5c79bcb2acb810e75a731d673deddcc28b68a0 100644 (file)
             <groupId>org.opendaylight.mdsal.binding.model.ietf</groupId>
             <artifactId>rfc6991-ietf-inet-types</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>concepts</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.mdsal</groupId>
             <artifactId>yang-binding</artifactId>
index 30344b9d7d404b4ee8d449e29a3943f5d175d37e..eb52c75c50ec8a563b260a8a5180b68135e46255 100644 (file)
@@ -42,7 +42,7 @@ public interface RouteEntry<C extends Routes & DataObject & ChoiceIn<Tables>, S
      * @param remotePathId remote path Id received
      * @return return true if it was the last route on entry
      */
-    boolean removeRoute(@Nonnull UnsignedInteger routerId, long remotePathId);
+    boolean removeRoute(@Nonnull UnsignedInteger routerId, Long remotePathId);
 
     /**
      * Indicates whether best has changed.
@@ -60,8 +60,7 @@ public interface RouteEntry<C extends Routes & DataObject & ChoiceIn<Tables>, S
      * @param route        route Data change
      * @return returns the offset
      */
-    int addRoute(@Nonnull UnsignedInteger routerId, long remotePathId, @Nonnull R route);
-
+    int addRoute(@Nonnull UnsignedInteger routerId, Long remotePathId, @Nonnull R route);
 
     /**
      * Returns collections of present selected best path.
@@ -74,7 +73,6 @@ public interface RouteEntry<C extends Routes & DataObject & ChoiceIn<Tables>, S
             @Nonnull RIBSupport<C, S, R, I> ribSupport,
             @Nonnull RouteEntryInfo entryInfo);
 
-
     /**
      * Returns list of stale best path.
      *
index 5c6b7cf7e9284242c1902f9696fad1ffaf27d8df..d54695f093c25214e41ef5e8e5b7569ce2bbdc3b 100644 (file)
@@ -68,7 +68,7 @@ public abstract class AddPathAbstractRouteEntry<C extends Routes & DataObject &
     }
 
     @Override
-    public final int addRoute(final UnsignedInteger routerId, final long remotePathId, final R route) {
+    public final int addRoute(final UnsignedInteger routerId, final Long remotePathId, final R route) {
         final RouteKey key = new RouteKey(routerId, remotePathId);
         int offset = this.offsets.offsetOf(key);
         if (offset < 0) {
@@ -87,7 +87,7 @@ public abstract class AddPathAbstractRouteEntry<C extends Routes & DataObject &
     }
 
     @Override
-    public final boolean removeRoute(final UnsignedInteger routerId, final long remotePathId) {
+    public final boolean removeRoute(final UnsignedInteger routerId, final Long remotePathId) {
         final RouteKey key = new RouteKey(routerId, remotePathId);
         final int offset = getOffsets().offsetOf(key);
         final Long pathId = this.offsets.getValue(this.pathsId, offset);
index 27696d59d4e6daead48729e35e6e08daf9f34d0a..24bc8e793b04610072566c324d95e541082a02bd 100644 (file)
@@ -13,18 +13,19 @@ import com.google.common.base.MoreObjects;
 import com.google.common.primitives.UnsignedInteger;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.concepts.Immutable;
 
 @NonNullByDefault
-public final class RouteKey implements Comparable<RouteKey> {
+public final class RouteKey implements Comparable<RouteKey>, Immutable {
     private final UnsignedInteger routerId;
     private final long remotePathId;
 
-    public RouteKey(final UnsignedInteger routerId, final long remotePathId) {
+    RouteKey(final UnsignedInteger routerId, final Long remotePathId) {
         this.routerId = requireNonNull(routerId);
-        this.remotePathId = remotePathId;
+        this.remotePathId = remotePathId.longValue();
     }
 
-    public UnsignedInteger getRouterId() {
+    UnsignedInteger getRouterId() {
         return routerId;
     }
 
index a8be574a836d693593d0b6d5964c3ce0fde6ce54..22561e4fadfe3e2faf2fcf8e636d7403e7e8da78 100644 (file)
@@ -47,7 +47,7 @@ final class BaseRouteEntry<C extends Routes & DataObject & ChoiceIn<Tables>,
     }
 
     @Override
-    public boolean removeRoute(final UnsignedInteger routerId, final long remotePathId) {
+    public boolean removeRoute(final UnsignedInteger routerId, final Long remotePathId) {
         final int offset = this.offsets.offsetOf(routerId);
         this.values = this.offsets.removeValue(this.values, offset, (R[]) EMPTY_VALUES);
         this.offsets = this.offsets.without(routerId);
@@ -89,7 +89,7 @@ final class BaseRouteEntry<C extends Routes & DataObject & ChoiceIn<Tables>,
     }
 
     @Override
-    public int addRoute(final UnsignedInteger routerId, final long remotePathId, final R route) {
+    public int addRoute(final UnsignedInteger routerId, final Long remotePathId, final R route) {
         int offset = this.offsets.offsetOf(routerId);
         if (offset < 0) {
             final OffsetMap newOffsets = this.offsets.with(routerId);
index 5e03801026c463677e885be523ace22a1951405b..c0f45b9c29d80dadfd58860566ecc1aea4e5284c 100644 (file)
@@ -289,13 +289,12 @@ final class LocRibWriter<C extends Routes & DataObject & ChoiceIn<Tables>, S ext
     private void updateRoutesEntries(
             final Collection<? extends DataObjectModification<? extends DataObject>> collection,
             final UnsignedInteger routerId,
-            final Map<RouteUpdateKey, RouteEntry<C,S,R,I>> routes
-    ) {
+            final Map<RouteUpdateKey, RouteEntry<C,S,R,I>> routes) {
         for (final DataObjectModification<? extends DataObject> route : collection) {
             final R newRoute = (R) route.getDataAfter();
             final R oldRoute = (R) route.getDataBefore();
             String routeKey;
-            RouteEntry<C,S,R,I> entry;
+            RouteEntry<C, S, R, I> entry;
             if (newRoute != null) {
                 routeKey = newRoute.getRouteKey();
                 entry = this.routeEntries.get(routeKey);
@@ -304,16 +303,14 @@ final class LocRibWriter<C extends Routes & DataObject & ChoiceIn<Tables>, S ext
                     entry = createEntry(routeKey);
                 }
 
-                final long pathId = newRoute.getPathId().getValue();
-                entry.addRoute(routerId, pathId, newRoute);
+                entry.addRoute(routerId, newRoute.getPathId().getValue(), newRoute);
                 this.totalPathsCounter.increment();
             } else {
                 routeKey = oldRoute.getRouteKey();
                 entry = this.routeEntries.get(routeKey);
                 if(entry != null) {
                     this.totalPathsCounter.decrement();
-                    final long pathId = oldRoute.getPathId().getValue();
-                    if (entry.removeRoute(routerId, pathId)) {
+                    if (entry.removeRoute(routerId, oldRoute.getPathId().getValue())) {
                         this.routeEntries.remove(routeKey);
                         this.totalPrefixesCounter.decrement();
                         LOG.trace("Removed route from {}", routerId);