BUG-4827: Fix minor bugs on Add Path Selection Mode 93/36993/7
authorClaudio D. Gasparini <cgaspari@cisco.com>
Fri, 1 Apr 2016 08:40:26 +0000 (10:40 +0200)
committerClaudio D. Gasparini <cgaspari@cisco.com>
Mon, 4 Apr 2016 12:37:35 +0000 (12:37 +0000)
Fix minor bugs on Add Path Selection Mode.
PathId should increment only if route didn't exist previously.

Change-Id: I3c06eade75d1d87f5d0808e0b210975ae61b6490
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
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/all/paths/AbstractAllPathsRouteEntry.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/AbstractNPathsRouteEntry.java

index b34491d77c4bacee181f54df65674c14a53d0a4b..610ac0d9ce734df62aec211759b2a9fd7e465d63 100644 (file)
@@ -53,7 +53,6 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry {
     private long pathIdCounter = 0L;
 
     private int addRoute(final RouteKey key, final ContainerNode attributes) {
-        this.pathIdCounter++;
         int offset = this.offsets.offsetOf(key);
         if (offset < 0) {
             final OffsetMap<RouteKey> newOffsets = this.offsets.with(key);
@@ -63,10 +62,9 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry {
             this.values = newAttributes;
             this.offsets = newOffsets;
             this.pathsId = newPathsId;
+            this.offsets.setValue(this.pathsId, offset, this.pathIdCounter++);
         }
-
         this.offsets.setValue(this.values, offset, attributes);
-        this.offsets.setValue(this.pathsId, offset, this.pathIdCounter);
         LOG.trace("Added route from {} attributes {}", key.getRouteId(), attributes);
         return offset;
     }
@@ -88,7 +86,7 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry {
         this.values = this.offsets.removeValue(this.values, offset);
         this.pathsId = this.offsets.removeValue(this.pathsId, offset);
         this.offsets = this.offsets.without(key);
-        return this.offsets.size() == 0;
+        return isEmpty();
     }
 
     @Override
@@ -194,6 +192,10 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry {
         return this.offsets;
     }
 
+    public final boolean isEmpty() {
+        return this.offsets.isEmty();
+    }
+
     protected void selectBest(final RouteKey key, final AddPathSelector selector) {
         final int offset = this.offsets.offsetOf(key);
         final ContainerNode attributes = this.offsets.getValue(this.values, offset);
index 782ca5563248b4906d629118e9185ee046aec5a2..0378ff2430f6a98b6e1c2f590af2c2b72641b407 100644 (file)
@@ -28,7 +28,7 @@ abstract class AbstractAllPathsRouteEntry extends AddPathAbstractRouteEntry {
         final List<AddPathBestPath> newBestPathList = new ArrayList<>();
         final List<RouteKey> keyList = this.offsets.getRouteKeysList();
 
-        if(!keyList.isEmpty()) {
+        if (!keyList.isEmpty()) {
             /* we set the best path first on List for not supported Add path cases*/
             final AddPathBestPath newBest = selectBest(localAs, keyList);
             newBestPathList.add(newBest);
@@ -47,7 +47,7 @@ abstract class AbstractAllPathsRouteEntry extends AddPathAbstractRouteEntry {
         }
 
         this.bestPathRemoved = new ArrayList<>(this.bestPath);
-        if (this.bestPathRemoved.removeAll(newBestPathList) || !this.bestPath.equals(newBestPathList)) {
+        if (this.bestPathRemoved.removeAll(newBestPathList) && !this.bestPathRemoved.isEmpty() || !this.bestPath.equals(newBestPathList)) {
             this.bestPath = newBestPathList;
             LOG.trace("Actual Best {}, removed best {}", this.bestPath, this.bestPathRemoved);
             return true;
index 82731dc45fde67843e7477d16443742b66c4d445..05cd878d12b36d73d7f387fc4c01f6337cd0bae5 100644 (file)
@@ -37,7 +37,7 @@ abstract class AbstractNPathsRouteEntry extends AddPathAbstractRouteEntry {
         }
 
         this.bestPathRemoved = new ArrayList<>(this.bestPath);
-        if (this.bestPathRemoved.removeAll(newBestPathList) || !this.bestPath.equals(newBestPathList)) {
+        if (this.bestPathRemoved.removeAll(newBestPathList) && !this.bestPathRemoved.isEmpty() || !this.bestPath.equals(newBestPathList)) {
             this.bestPath = newBestPathList;
             LOG.trace("Actual Best {}, removed best {}", this.bestPath, this.bestPathRemoved);
             return true;