Algo API impl slight refactoring 95/100095/2
authorguillaume.lambert <guillaume.lambert@orange.com>
Sat, 12 Mar 2022 13:57:14 +0000 (14:57 +0100)
committerRobert Varga <nite@hq.sk>
Sun, 20 Mar 2022 17:30:43 +0000 (17:30 +0000)
JIRA: BGPCEP-979
Signed-off-by: Guillaume Lambert <guillaume.lambert@orange.com>
Change-Id: I7a77c2a1f8073d63e8727d129a4e0f744f0b5836

algo/algo-impl/src/main/java/org/opendaylight/algo/impl/AbstractPathComputation.java
algo/algo-impl/src/main/java/org/opendaylight/algo/impl/ConstrainedShortestPathFirst.java
algo/algo-impl/src/main/java/org/opendaylight/algo/impl/Samcra.java
algo/algo-impl/src/main/java/org/opendaylight/algo/impl/ShortestPathFirst.java

index 0383c2ffd04277fcbce4e8833b38da098638fa46..16190a2e846b36b47793dfae2786d2837e78becb 100644 (file)
@@ -243,11 +243,15 @@ public abstract class AbstractPathComputation implements PathComputationAlgorith
                     }
                 }
                 Long maxBW = attributes.getMaxLinkBandwidth().getValue().longValue();
-                if (unrsv < bandwidth
-                        || maxBW < bandwidth
-                        || (maxBW - edge.getCosResvBandwidth(cos)) < bandwidth
-                        || (maxBW - edge.getGlobalResvBandwidth()) < bandwidth
-                        || attributes.getMaxResvLinkBandwidth().getValue().longValue() < bandwidth) {
+                if (bandwidth > List.of(
+                            unrsv,
+                            // maxBW might be on the list but will always be greater than the next items
+                            maxBW - edge.getCosResvBandwidth(cos),
+                            maxBW - edge.getGlobalResvBandwidth(),
+                            attributes.getMaxResvLinkBandwidth().getValue().longValue())
+                        .stream().mapToLong(v -> v)
+                        .min().getAsLong()
+                ) {
                     LOG.debug("Bandwidth constraint is not met");
                     return true;
                 }
index c21e217fd2703118a0288802ef2ba878e2288818..515cd30db93a218fbd7ccb3afb1ff91056513fd7 100644 (file)
@@ -81,13 +81,13 @@ public class ConstrainedShortestPathFirst extends AbstractPathComputation {
          * The "ConstrainedPathBuilder" object contains the optimal path if it exists
          * Otherwise an empty path with status failed is returned
          */
-        if (cpathBuilder.getStatus() == ComputationStatus.InProgress
-                || cpathBuilder.getPathDescription().size() == 0) {
-            cpathBuilder.setStatus(ComputationStatus.NoPath);
-        } else {
-            cpathBuilder.setStatus(ComputationStatus.Completed);
-        }
-        return cpathBuilder.build();
+        return cpathBuilder
+            .setStatus(
+                cpathBuilder.getStatus() == ComputationStatus.InProgress
+                        || cpathBuilder.getPathDescription().size() == 0
+                   ? ComputationStatus.NoPath
+                   : ComputationStatus.Completed)
+            .build();
     }
 
     private boolean relaxMultiConstraints(final ConnectedEdge edge, final CspfPath currentPath) {
index 9901a9a143a4e52299219e08204fcc0c432db708..a40771e2331edeb1f053a5f5f91bee96ca952460 100644 (file)
@@ -124,15 +124,11 @@ public class Samcra extends AbstractPathComputation {
 
     @Override
     public ConstrainedPath computeP2pPath(final VertexKey src, final VertexKey dst, final PathConstraints cts) {
-        ConstrainedPathBuilder cpathBuilder;
-        List<ConnectedEdge> edges;
-        CspfPath currentPath;
-
         LOG.info("Start SAMCRA Path Computation from {} to {} with constraints {}", src, dst, cts);
 
         /* Initialize SAMCRA variables */
         this.constraints = cts;
-        cpathBuilder = initializePathComputation(src, dst);
+        ConstrainedPathBuilder cpathBuilder = initializePathComputation(src, dst);
         if (cpathBuilder.getStatus() != ComputationStatus.InProgress) {
             return cpathBuilder.build();
         }
@@ -148,7 +144,7 @@ public class Samcra extends AbstractPathComputation {
          * The top of the queue, i.e. the element with the minimal key( path weight), is processed at each loop
          */
         while (priorityQueue.size() != 0) {
-            currentPath = priorityQueue.poll();
+            CspfPath currentPath = priorityQueue.poll();
             LOG.debug(" - Process path up to Vertex {} from Priority Queue", currentPath.getVertex());
 
             /* Prepare Samcra Path from current CSP Path except for the source */
@@ -160,7 +156,7 @@ public class Samcra extends AbstractPathComputation {
                         currentSamcraPath.currentPath, currentCspfPath, queuePathLength);
             }
 
-            edges = currentPath.getVertex().getOutputConnectedEdges();
+            List<ConnectedEdge> edges = currentPath.getVertex().getOutputConnectedEdges();
             float currentPathLength = 1.0F;
             for (ConnectedEdge edge : edges) {
                 /* Connected Vertex's edges processing:
@@ -238,13 +234,13 @@ public class Samcra extends AbstractPathComputation {
          * The "ConstrainedPathBuilder" object contains the optimal path if it exists
          * Otherwise an empty path with status failed is returned
          */
-        if (cpathBuilder.getStatus() == ComputationStatus.InProgress
-                || cpathBuilder.getPathDescription().size() == 0) {
-            cpathBuilder.setStatus(ComputationStatus.NoPath);
-        } else {
-            cpathBuilder.setStatus(ComputationStatus.Completed);
-        }
-        return cpathBuilder.build();
+        return cpathBuilder
+            .setStatus(
+                cpathBuilder.getStatus() == ComputationStatus.InProgress
+                        || cpathBuilder.getPathDescription().size() == 0
+                   ? ComputationStatus.NoPath
+                   : ComputationStatus.Completed)
+            .build();
     }
 
     /* Connected Edge to remote connected vertex processing (on contrast to CSPF algorithm, the already processed
index 157c8bd079be78c497294cab4605569555c2a115..cb2da94daedb17869d8e8812081a9a745591196f 100644 (file)
@@ -80,13 +80,13 @@ public class ShortestPathFirst extends AbstractPathComputation {
          * The "ConstrainedPathBuilder" object contains the optimal path if it exists
          * Otherwise an empty path with status failed is returned
          */
-        if (cpathBuilder.getStatus() == ComputationStatus.InProgress
-                || cpathBuilder.getPathDescription().size() == 0) {
-            cpathBuilder.setStatus(ComputationStatus.NoPath);
-        } else {
-            cpathBuilder.setStatus(ComputationStatus.Completed);
-        }
-        return cpathBuilder.build();
+        return cpathBuilder
+            .setStatus(
+                cpathBuilder.getStatus() == ComputationStatus.InProgress
+                        || cpathBuilder.getPathDescription().size() == 0
+                   ? ComputationStatus.NoPath
+                   : ComputationStatus.Completed)
+            .build();
     }
 
     private boolean relax(final ConnectedEdge edge, final CspfPath currentPath) {