Remove duplicated code for Route Entry 03/71903/1
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Sat, 21 Apr 2018 21:36:47 +0000 (23:36 +0200)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Thu, 10 May 2018 05:18:35 +0000 (07:18 +0200)
Change-Id: Ia962719cbca89d7092e040506d125ead2106d8cb
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
14 files changed:
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/AllPathSelection.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/AllPathsRouteEntry.java [moved from bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/AbstractAllPathsRouteEntry.java with 84% similarity]
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/ComplexRouteEntry.java [deleted file]
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/AddPathBestNPathSelection.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/ComplexRouteEntry.java [deleted file]
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/NPathsRouteEntry.java [moved from bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/AbstractNPathsRouteEntry.java with 86% similarity]
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BasePathSelection.java
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseRouteEntry.java [moved from bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseAbstractRouteEntry.java with 89% similarity]
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/ComplexRouteEntry.java [deleted file]
bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractRouteEntry.java
bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/PathSelectionModeFactoryTest.java [deleted file]
bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/PathSelectionModeFactoryTest.java [deleted file]
bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BasePathSelectionModeFactoryTest.java [deleted file]

index eb04fd33be824a13d0ee75e59acf9e33cc3e4f48..9ec15c9387aa4fe31fe1ba2327fe125503cd454a 100644 (file)
@@ -53,7 +53,7 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry<AddPa
     private List<AddPathBestPath> bestPath;
     private List<AddPathBestPath> bestPathRemoved;
     protected OffsetMap offsets = OffsetMap.EMPTY;
-    protected Attributes[] values = EMPTY_ATTRIBUTES;
+    protected Route[] values = EMPTY_VALUES;
     protected Long[] pathsId =  EMPTY_PATHS_ID;
     private long pathIdCounter = 0L;
     private boolean oldNonAddPathBestPathTheSame;
@@ -82,33 +82,39 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry<AddPa
         }
     }
 
-    protected int addRoute(final RouteKey key, final Attributes attributes) {
+    @Override
+    public final Route createRoute(final RIBSupport ribSup, final String routeKey, final long pathId,
+            final AddPathBestPath path) {
+        final OffsetMap map = getOffsets();
+        final Route route = map.getValue(this.values, map.offsetOf(path.getRouteKey()));
+        return ribSup.createRoute(route, routeKey, pathId, path.getAttributes());
+    }
+
+    @Override
+    public final int addRoute(final UnsignedInteger routerId, final long remotePathId, final Route route) {
+        final RouteKey key = new RouteKey(routerId, remotePathId);
         int offset = this.offsets.offsetOf(key);
         if (offset < 0) {
             final OffsetMap newOffsets = this.offsets.with(key);
             offset = newOffsets.offsetOf(key);
-            final Attributes[] newAttributes = newOffsets.expand(this.offsets, this.values, offset);
+            final Route[] newRoute = newOffsets.expand(this.offsets, this.values, offset);
             final Long[] newPathsId = newOffsets.expand(this.offsets, this.pathsId, offset);
-            this.values = newAttributes;
+            this.values = newRoute;
             this.offsets = newOffsets;
             this.pathsId = newPathsId;
             this.offsets.setValue(this.pathsId, offset, ++this.pathIdCounter);
         }
-        this.offsets.setValue(this.values, offset, attributes);
-        LOG.trace("Added route from {} attributes {}", key.getRouteId(), attributes);
+        this.offsets.setValue(this.values, offset, route);
+        LOG.trace("Added route {} from {}", route, key.getRouteId());
         return offset;
     }
 
-    /**
-     * Remove route.
-     *
-     * @param key RouteKey of removed route
-     * @param offset Offset of removed route
-     * @return true if it was the last route
-     */
-    protected final boolean removeRoute(final RouteKey key, final int offset) {
+    @Override
+    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);
-        this.values = this.offsets.removeValue(this.values, offset, EMPTY_ATTRIBUTES);
+        this.values = this.offsets.removeValue(this.values, offset, EMPTY_VALUES);
         this.pathsId = this.offsets.removeValue(this.pathsId, offset, EMPTY_PATHS_ID);
         this.offsets = this.offsets.without(key);
         if (this.removedPaths == null) {
@@ -156,45 +162,38 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry<AddPa
     }
 
     @Override
-    public void initializeBestPaths(final RouteEntryDependenciesContainer entryDependencies,
+    public void initializeBestPaths(final RouteEntryDependenciesContainer routeEntryDep,
             final RouteEntryInfo entryInfo, final WriteTransaction tx) {
         if (this.bestPath != null) {
             final Peer toPeer = entryInfo.getToPeer();
-            final TablesKey localTk = entryDependencies.getLocalTablesKey();
+            final TablesKey localTk = routeEntryDep.getLocalTablesKey();
             final boolean destPeerSupAddPath = toPeer.supportsAddPathSupported(localTk);
             for (final AddPathBestPath path : this.bestPath) {
                 if (!filterRoutes(path.getPeerId(), toPeer, localTk)) {
                     continue;
                 }
-                writeRoutePath(entryInfo, destPeerSupAddPath, path, localTk, entryDependencies, tx);
+                final String routeKey = entryInfo.getRouteKey();
+                final RIBSupport ribSupport = routeEntryDep.getRibSupport();
+                final BGPRouteEntryExportParameters baseExp = new BGPRouteEntryExportParametersImpl(
+                        this.peerTracker.getPeer(path.getPeerId()), toPeer);
+                final Optional<Attributes> effAttrib = routeEntryDep.getRoutingPolicies()
+                        .applyExportPolicies(baseExp, path.getAttributes());
+                if (effAttrib.isPresent()) {
+                    Identifier routeIdentifier = ribSupport.createRouteListKey(destPeerSupAddPath
+                            ? path.getPathId() : NON_PATH_ID_VALUE, routeKey);
+                    final Route route = createRoute(ribSupport, routeKey, destPeerSupAddPath
+                            ? path.getPathId() : NON_PATH_ID_VALUE, path);
+                    InstanceIdentifier ribOutIId
+                            = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTk), routeIdentifier);
+
+                    LOG.debug("Write route {} to peer AdjRibsOut {}", route, toPeer.getPeerId());
+                    tx.put(LogicalDatastoreType.OPERATIONAL, ribOutIId, route);
+                    tx.put(LogicalDatastoreType.OPERATIONAL, ribOutIId.child(Attributes.class), effAttrib.get());
+                }
             }
         }
     }
 
-    @SuppressWarnings("unchecked")
-    private void writeRoutePath(final RouteEntryInfo entryInfo,
-            final boolean destPeerSupAddPath, final AddPathBestPath path,
-            final TablesKey localTK, final RouteEntryDependenciesContainer routeEntryDep, final WriteTransaction tx) {
-        final String routeKey = entryInfo.getRouteKey();
-        final RIBSupport ribSupport = routeEntryDep.getRibSupport();
-        final BGPRouteEntryExportParameters baseExp = new BGPRouteEntryExportParametersImpl(
-                this.peerTracker.getPeer(path.getPeerId()), entryInfo.getToPeer());
-        final Optional<Attributes> effAttrib = routeEntryDep.getRoutingPolicies()
-                .applyExportPolicies(baseExp, path.getAttributes());
-
-        Identifier routeIdentifier = ribSupport.createRouteListKey(destPeerSupAddPath
-                ? path.getPathId() : NON_PATH_ID_VALUE, routeKey);
-        final Peer toPeer = entryInfo.getToPeer();
-        final Route route = createRoute(ribSupport, routeKey, destPeerSupAddPath
-                ? path.getPathId() : NON_PATH_ID_VALUE, path);
-        InstanceIdentifier ribOutIId = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), routeIdentifier);
-        if (effAttrib.isPresent() && route != null) {
-            LOG.debug("Write route {} to peer AdjRibsOut {}", route, toPeer.getPeerId());
-            tx.put(LogicalDatastoreType.OPERATIONAL, ribOutIId, route);
-            tx.put(LogicalDatastoreType.OPERATIONAL, ribOutIId.child(Attributes.class), effAttrib.get());
-        }
-    }
-
     private void addPathToDataStore(
             final RouteEntryDependenciesContainer entryDep,
             final AddPathBestPath path,
@@ -293,10 +292,10 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry<AddPa
 
     private void selectBest(final RouteKey key, final AddPathSelector selector) {
         final int offset = this.offsets.offsetOf(key);
-        final Attributes attributes = this.offsets.getValue(this.values, offset);
+        final Route route = this.offsets.getValue(this.values, offset);
         final long pathId = this.offsets.getValue(this.pathsId, offset);
-        LOG.trace("Processing router key {} attributes {}", key, attributes);
-        selector.processPath(attributes, key, offset, pathId);
+        LOG.trace("Processing router key {} route {}", key, route);
+        selector.processPath(route.getAttributes(), key, offset, pathId);
     }
 
     /**
index ce76fa599f36d1c703360c5c7fcb7607ae7e26f6..3aecc5b59a97cbe47a6a9e21bd709a1e2d774a0b 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.protocol.bgp.mode.impl.add.all.paths;
 import static java.util.Objects.requireNonNull;
 
 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
-import org.opendaylight.protocol.bgp.mode.api.RouteEntry;
 import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
 
 public class AllPathSelection implements PathSelectionMode {
@@ -22,8 +21,8 @@ public class AllPathSelection implements PathSelectionMode {
     }
 
     @Override
-    public RouteEntry createRouteEntry() {
-        return new ComplexRouteEntry(this.peerTracker);
+    public org.opendaylight.protocol.bgp.mode.api.RouteEntry createRouteEntry() {
+        return new AllPathsRouteEntry(this.peerTracker);
     }
 
     @Override
@@ -19,15 +19,15 @@ import org.opendaylight.protocol.bgp.mode.impl.add.AddPathAbstractRouteEntry;
 import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath;
 import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey;
 import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
 
-abstract class AbstractAllPathsRouteEntry extends AddPathAbstractRouteEntry {
-    AbstractAllPathsRouteEntry(final BGPPeerTracker peerTracker) {
+final class AllPathsRouteEntry extends AddPathAbstractRouteEntry {
+    AllPathsRouteEntry(final BGPPeerTracker peerTracker) {
         super(peerTracker);
     }
 
     @Override
-    public final boolean selectBest(final long localAs) {
+    public boolean selectBest(final long localAs) {
         final List<AddPathBestPath> newBestPathList = new ArrayList<>();
         final List<RouteKey> keyList = this.offsets.getRouteKeysList();
 
@@ -39,10 +39,10 @@ abstract class AbstractAllPathsRouteEntry extends AddPathAbstractRouteEntry {
             /*we add the rest of path, regardless in what order they are, since this is all path case */
             for (final RouteKey key : keyList) {
                 final int offset = this.offsets.offsetOf(key);
-                final Attributes attributes = this.offsets.getValue(this.values, offset);
+                final Route route = this.offsets.getValue(this.values, offset);
                 requireNonNull(key.getRouteId(), "Router ID may not be null");
-                if (attributes != null) {
-                    final BestPathState state = new BestPathStateImpl(attributes);
+                if (route != null) {
+                    final BestPathState state = new BestPathStateImpl(route.getAttributes());
                     final AddPathBestPath bestPath = new AddPathBestPath(state, key, offset,
                             this.offsets.getValue(this.pathsId, offset));
                     newBestPathList.add(bestPath);
diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/ComplexRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/ComplexRouteEntry.java
deleted file mode 100644 (file)
index 2b9935d..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * 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.mode.impl.add.all.paths;
-
-import com.google.common.primitives.UnsignedInteger;
-import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath;
-import org.opendaylight.protocol.bgp.mode.impl.add.OffsetMap;
-import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey;
-import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
-import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
-
-final class ComplexRouteEntry extends AbstractAllPathsRouteEntry {
-    private Route[] values = EMPTY_VALUES;
-
-    ComplexRouteEntry(final BGPPeerTracker peerTracker) {
-        super(peerTracker);
-    }
-
-    @Override
-    public boolean removeRoute(final UnsignedInteger routerId, final long remotePathId) {
-        final RouteKey key = new RouteKey(routerId, remotePathId);
-        final OffsetMap map = getOffsets();
-        final int offset = map.offsetOf(key);
-        this.values = map.removeValue(this.values, offset, EMPTY_VALUES);
-        return removeRoute(key, offset);
-    }
-
-    @Override
-    public Route createRoute(final RIBSupport ribSup, final String routeKey, final long pathId,
-            final AddPathBestPath path) {
-        final OffsetMap map = getOffsets();
-        final Route route = map.getValue(this.values, map.offsetOf(path.getRouteKey()));
-        return ribSup.createRoute(route, routeKey, pathId, path.getAttributes());
-    }
-
-    @Override
-    public int addRoute(final UnsignedInteger routerId, final long remotePathId, final Route route) {
-        final OffsetMap oldMap = getOffsets();
-        final int offset = addRoute(new RouteKey(routerId, remotePathId), route.getAttributes());
-        final OffsetMap newMap = getOffsets();
-
-        if (!newMap.equals(oldMap)) {
-            this.values = newMap.expand(oldMap, this.values, offset);
-        }
-
-        newMap.setValue(this.values, offset, route);
-        return offset;
-    }
-}
index 6fae195141f202ab9dec61f9acb729ea6c0faa9b..20c3c814c5c56c1e370f8c88a1684de45db62afc 100644 (file)
@@ -30,6 +30,6 @@ public final class AddPathBestNPathSelection implements PathSelectionMode {
 
     @Override
     public RouteEntry createRouteEntry() {
-        return new ComplexRouteEntry(this.npaths, this.peerTracker);
+        return new NPathsRouteEntry(this.npaths, this.peerTracker);
     }
 }
\ No newline at end of file
diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/ComplexRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/ComplexRouteEntry.java
deleted file mode 100644 (file)
index 9bc4c38..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * 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.mode.impl.add.n.paths;
-
-import com.google.common.primitives.UnsignedInteger;
-import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath;
-import org.opendaylight.protocol.bgp.mode.impl.add.OffsetMap;
-import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey;
-import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
-import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
-
-final class ComplexRouteEntry extends AbstractNPathsRouteEntry {
-    private Route[] values = EMPTY_VALUES;
-
-    ComplexRouteEntry(final long npaths, final BGPPeerTracker peerTracker) {
-        super(npaths, peerTracker);
-    }
-
-    @Override
-    public boolean removeRoute(final UnsignedInteger routerId, final long remotePathId) {
-        final RouteKey key = new RouteKey(routerId, remotePathId);
-        final OffsetMap map = getOffsets();
-        final int offset = map.offsetOf(key);
-        this.values = map.removeValue(this.values, offset, EMPTY_VALUES);
-        return removeRoute(key, offset);
-    }
-
-    @Override
-    public Route createRoute(final RIBSupport ribSup, final String routeKey, final long pathId,
-            final AddPathBestPath path) {
-        final OffsetMap map = getOffsets();
-        final Route route = map.getValue(this.values, map.offsetOf(path.getRouteKey()));
-        return ribSup.createRoute(route, routeKey, pathId, path.getAttributes());
-    }
-
-    @Override
-    public int addRoute(final UnsignedInteger routerId, final long remotePathId, final Route route) {
-        final OffsetMap oldMap = getOffsets();
-        final int offset = addRoute(new RouteKey(routerId, remotePathId), route.getAttributes());
-        final OffsetMap newMap = getOffsets();
-
-        if (!newMap.equals(oldMap)) {
-            this.values = newMap.expand(oldMap, this.values, offset);
-        }
-
-        newMap.setValue(this.values, offset, route);
-        return offset;
-    }
-}
\ No newline at end of file
@@ -16,16 +16,16 @@ import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath;
 import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey;
 import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
 
-abstract class AbstractNPathsRouteEntry extends AddPathAbstractRouteEntry {
+final class NPathsRouteEntry extends AddPathAbstractRouteEntry {
     private final long npaths;
 
-    AbstractNPathsRouteEntry(final long npaths, final BGPPeerTracker peerTracker) {
+    NPathsRouteEntry(final long npaths, final BGPPeerTracker peerTracker) {
         super(peerTracker);
         this.npaths = npaths;
     }
 
     @Override
-    public final boolean selectBest(final long localAs) {
+    public boolean selectBest(final long localAs) {
         final List<AddPathBestPath> newBestPathList = new ArrayList<>();
         final List<RouteKey> keyList = this.offsets.getRouteKeysList();
         final long maxSearch = this.npaths < this.offsets.size()
index a67c4ce8ae963d1bf5683e1e813a312532a27a32..be7140b64d6e126a9aab899fbd71f23cd934cee6 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.protocol.bgp.mode.impl.base;
 import static java.util.Objects.requireNonNull;
 
 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
-import org.opendaylight.protocol.bgp.mode.api.RouteEntry;
 import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
 
 final class BasePathSelection implements PathSelectionMode {
@@ -22,8 +21,8 @@ final class BasePathSelection implements PathSelectionMode {
     }
 
     @Override
-    public RouteEntry createRouteEntry() {
-        return new ComplexRouteEntry(this.peerTracker);
+    public org.opendaylight.protocol.bgp.mode.api.RouteEntry createRouteEntry() {
+        return new BaseRouteEntry(this.peerTracker);
     }
 
     @Override
similarity index 89%
rename from bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseAbstractRouteEntry.java
rename to bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseRouteEntry.java
index b07a77618b7b095755a3e5082e711dd655b67e05..d5d28eb90cf3dddd1dadc9670af17960b83b23fd 100644 (file)
@@ -35,32 +35,34 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @NotThreadSafe
-abstract class BaseAbstractRouteEntry extends AbstractRouteEntry<BaseBestPath> {
-    private static final Logger LOG = LoggerFactory.getLogger(BaseAbstractRouteEntry.class);
+final class BaseRouteEntry extends AbstractRouteEntry<BaseBestPath> {
+    private static final Logger LOG = LoggerFactory.getLogger(BaseRouteEntry.class);
     private OffsetMap offsets = OffsetMap.EMPTY;
-    private Attributes[] values = EMPTY_ATTRIBUTES;
+    private Route[] values = EMPTY_VALUES;
     private BaseBestPath bestPath;
     private BaseBestPath removedBestPath;
 
-    BaseAbstractRouteEntry(final BGPPeerTracker peerTracker) {
+    BaseRouteEntry(final BGPPeerTracker peerTracker) {
         super(peerTracker);
     }
 
-    /**
-     * Remove route.
-     *
-     * @param routerId router ID in unsigned integer
-     * @param offset   of removed route
-     * @return true if its the last route
-     */
-    protected final boolean removeRoute(final UnsignedInteger routerId, final int offset) {
-        this.values = this.offsets.removeValue(this.values, offset, EMPTY_ATTRIBUTES);
+    @Override
+    public  boolean removeRoute(final UnsignedInteger routerId, final long remotePathId) {
+        final int offset = this.offsets.offsetOf(routerId);
+        this.values = this.offsets.removeValue(this.values, offset, EMPTY_VALUES);
         this.offsets = this.offsets.without(routerId);
         return this.offsets.isEmpty();
     }
 
     @Override
-    public final boolean selectBest(final long localAs) {
+    public Route createRoute(final RIBSupport ribSup, String routeKey, final long pathId,
+            final BaseBestPath path) {
+        final Route route = this.offsets.getValue(this.values, this.offsets.offsetOf(path.getRouterId()));
+        return ribSup.createRoute(route, routeKey, pathId, path.getAttributes());
+    }
+
+    @Override
+    public boolean selectBest(final long localAs) {
         /*
          * FIXME: optimize flaps by making sure we consider stability of currently-selected route.
          */
@@ -69,7 +71,7 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry<BaseBestPath> {
         // Select the best route.
         for (int i = 0; i < this.offsets.size(); ++i) {
             final UnsignedInteger routerId = this.offsets.getRouterKey(i);
-            final Attributes attributes = this.offsets.getValue(this.values, i);
+            final Attributes attributes = this.offsets.getValue(this.values, i).getAttributes();
             LOG.trace("Processing router id {} attributes {}", routerId, attributes);
             selector.processPath(routerId, attributes);
         }
@@ -89,7 +91,6 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry<BaseBestPath> {
 
     @Override
     public int addRoute(final UnsignedInteger routerId, final long remotePathId, final Route route) {
-        final Attributes advertisedAttrs = route.getAttributes();
         int offset = this.offsets.offsetOf(routerId);
         if (offset < 0) {
             final OffsetMap newOffsets = this.offsets.with(routerId);
@@ -99,8 +100,8 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry<BaseBestPath> {
             this.offsets = newOffsets;
         }
 
-        this.offsets.setValue(this.values, offset, advertisedAttrs);
-        LOG.trace("Added route from {} attributes {}", routerId, advertisedAttrs);
+        this.offsets.setValue(this.values, offset, route);
+        LOG.trace("Added route {} from {}", route, routerId);
         return offset;
     }
 
@@ -138,9 +139,11 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry<BaseBestPath> {
                 this.peerTracker.getPeer(this.bestPath.getPeerId()), toPeer);
         final Optional<Attributes> effAttrib = entryDep.getRoutingPolicies()
                 .applyExportPolicies(routeEntry, this.bestPath.getAttributes());
-        final Route route = createRoute(ribSupport, entryInfo.getRouteKey(), this.bestPath.getPathId(), this.bestPath);
-        InstanceIdentifier ribOutIId = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), routeIdentifier);
-        if (effAttrib.isPresent() && route != null) {
+        if (effAttrib.isPresent()) {
+            final Route route = createRoute(ribSupport,
+                    entryInfo.getRouteKey(), this.bestPath.getPathId(), this.bestPath);
+            InstanceIdentifier ribOutIId = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK),
+                    routeIdentifier);
             LOG.debug("Write route {} to peer AdjRibsOut {}", route, toPeer.getPeerId());
             tx.put(LogicalDatastoreType.OPERATIONAL, ribOutIId, route);
             tx.put(LogicalDatastoreType.OPERATIONAL, ribOutIId.child(Attributes.class), effAttrib.get());
@@ -177,10 +180,6 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry<BaseBestPath> {
                 entryDep, tx);
     }
 
-    final OffsetMap getOffsets() {
-        return this.offsets;
-    }
-
     @VisibleForTesting
     @SuppressWarnings("unchecked")
     private void fillAdjRibsOut(
diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/ComplexRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/ComplexRouteEntry.java
deleted file mode 100644 (file)
index 6cbbcb2..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * 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.mode.impl.base;
-
-import com.google.common.primitives.UnsignedInteger;
-import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
-import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
-
-final class ComplexRouteEntry extends BaseAbstractRouteEntry {
-    private Route[] values = EMPTY_VALUES;
-
-    ComplexRouteEntry(final BGPPeerTracker peerTracker) {
-        super(peerTracker);
-    }
-
-    @Override
-    public int addRoute(final UnsignedInteger routerId, final long remotePathId, final Route route) {
-        final OffsetMap oldMap = getOffsets();
-        final int offset = super.addRoute(routerId, remotePathId, route);
-        final OffsetMap newMap = getOffsets();
-
-        if (!newMap.equals(oldMap)) {
-            this.values = newMap.expand(oldMap, this.values, offset);
-        }
-
-        newMap.setValue(this.values, offset, route);
-        return offset;
-    }
-
-    @Override
-    public boolean removeRoute(final UnsignedInteger routerId, final long remotePathId) {
-        final OffsetMap map = getOffsets();
-        final int offset = map.offsetOf(routerId);
-        this.values = map.removeValue(this.values, offset, EMPTY_VALUES);
-        return removeRoute(routerId, offset);
-    }
-
-    @Override
-    public Route createRoute(final RIBSupport ribSup, String routeKey, final long pathId,
-            final BaseBestPath path) {
-        final OffsetMap map = getOffsets();
-        final Route route = map.getValue(this.values, map.offsetOf(path.getRouterId()));
-        return ribSup.createRoute(route, routeKey, pathId, path.getAttributes());
-    }
-}
index 8f060050d0e23b3e4914f77b06c4340f7b668423..3704386f3cf98775eb3510dab1902d285d19eb1c 100644 (file)
@@ -16,14 +16,12 @@ import org.opendaylight.protocol.bgp.mode.api.RouteEntry;
 import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
 import org.opendaylight.protocol.bgp.rib.spi.Peer;
 import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Route;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
 
 public abstract class AbstractRouteEntry<T extends BestPath> implements RouteEntry {
-    protected static final Attributes[] EMPTY_ATTRIBUTES = new Attributes[0];
     protected static final Route[] EMPTY_VALUES = new Route[0];
     protected final BGPPeerTracker peerTracker;
 
diff --git a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/PathSelectionModeFactoryTest.java b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/PathSelectionModeFactoryTest.java
deleted file mode 100644 (file)
index 41660bf..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * 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.mode.impl.add.all.paths;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
-import org.opendaylight.protocol.bgp.mode.impl.BGPPeerTrackerMock;
-
-public class PathSelectionModeFactoryTest extends BGPPeerTrackerMock {
-    @Test
-    public void testCreateBestPathSelectionStrategy() {
-        final PathSelectionMode psm = new AllPathSelection(this.peerTracker);
-        Assert.assertTrue(psm.createRouteEntry(true) instanceof ComplexRouteEntry);
-    }
-}
diff --git a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/PathSelectionModeFactoryTest.java b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/PathSelectionModeFactoryTest.java
deleted file mode 100644 (file)
index 0b58015..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * 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.mode.impl.add.n.paths;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
-import org.opendaylight.protocol.bgp.mode.impl.BGPPeerTrackerMock;
-
-public class PathSelectionModeFactoryTest extends BGPPeerTrackerMock {
-    @Test
-    public void testCreateBestPathSelectionStrategy() {
-        final PathSelectionMode psm = new AddPathBestNPathSelection(2L, this.peerTracker);
-        Assert.assertTrue(psm.createRouteEntry(true) instanceof ComplexRouteEntry);
-    }
-}
\ No newline at end of file
diff --git a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BasePathSelectionModeFactoryTest.java b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BasePathSelectionModeFactoryTest.java
deleted file mode 100644 (file)
index d73cd7b..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * 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.mode.impl.base;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
-import org.opendaylight.protocol.bgp.mode.impl.BGPPeerTrackerMock;
-
-public class BasePathSelectionModeFactoryTest extends BGPPeerTrackerMock {
-    @Test
-    public void testCreateBestPathSelectionStrategy() {
-        final PathSelectionMode psm = BasePathSelectionModeFactory.createBestPathSelectionStrategy(this.peerTracker);
-        Assert.assertTrue(psm.createRouteEntry(true) instanceof ComplexRouteEntry);
-    }
-}
\ No newline at end of file