Refactor PCE network analyzer PceOtnNode step 5 20/99720/3
authorguillaume.lambert <guillaume.lambert@orange.com>
Mon, 14 Feb 2022 10:41:45 +0000 (11:41 +0100)
committerguillaume.lambert <guillaume.lambert@orange.com>
Mon, 14 Feb 2022 16:50:54 +0000 (17:50 +0100)
There is no point to have a different treatment for SERVICE_TYPE_100GE_S
in initXndrTps() to determine the attribute 'valid'.
This specific treatment only affects the argument availableXpdrClientTps
to pass to checkSwPool() when modeType equals "intermediate".
But this parameter is not used in that case.

- refactor and merge checkSwPool() and isAzOrIntermediateAvl() methods
- use checkSwPool() directly in initXndrTps()
- remove SERVICE_TYPE_100GE_S specific treatment

JIRA: TRNSPRTPCE-572
Signed-off-by: guillaume.lambert <guillaume.lambert@orange.com>
Change-Id: I0c7b0ba2f07fd904650a5d8ec456c326f1794c76

pce/src/main/java/org/opendaylight/transportpce/pce/networkanalyzer/PceOtnNode.java

index d31c51ff95a72201d1346f37f150bdc1b2e50762..65132ce352e015ceafbef72abd47b39af6226a60 100644 (file)
@@ -211,74 +211,68 @@ public class PceOtnNode implements PceNode {
         }
         this.valid = SERVICE_TYPE_ODU_LIST.contains(this.otnServiceType)
                 || SERVICE_TYPE_ETH_CLASS_MAP.containsKey(this.otnServiceType)
-                    && isAzOrIntermediateAvl(availableXpdrClientTps, availableXpdrNWTps,
-                        StringConstants.SERVICE_TYPE_100GE_S.equals(this.otnServiceType)
-                            ? availableXpdrClientTps
-                            : null);
-                //TODO check whether it makes sense to pass twice availableXpdrClientTps tp isAzOrIntermediateAvl
-                //     and to differentiate SERVICE_TYPE_100GE_S case
-                //     better pass otnServiceType -> this should probably be refactored
+                    && checkSwPool(availableXpdrNWTps, availableXpdrClientTps);
     }
 
-    private boolean isAzOrIntermediateAvl(List<TpId> clientTps, List<TpId> netwTps, List<TpId> clientTps0) {
-        switch (modeType) {
-            case "intermediate":
-                return checkSwPool(clientTps0, netwTps, 0, 2);
-
-            case "AZ":
-                return checkSwPool(clientTps, netwTps, 1, 1);
-
-            default:
-                LOG.error("unknown mode type {}", modeType);
-                return false;
-        }
-    }
+    private boolean checkSwPool(List<TpId> netwTps, List<TpId> clientTps) {
 
-    private boolean checkSwPool(List<TpId> clientTps, List<TpId> netwTps, int nbClient, int nbNetw) {
         if (netwTps == null) {
             return false;
         }
-        if (clientTps != null && nbClient == 1 && nbNetw == 1) {
-            clientTps.sort(Comparator.comparing(TpId::getValue));
-            netwTps.sort(Comparator.comparing(TpId::getValue));
-            for (TpId nwTp : netwTps) {
-                for (TpId clTp : clientTps) {
-                    for (NonBlockingList nbl : new ArrayList<>(node.augmentation(Node1.class).getSwitchingPools()
-                            .nonnullOduSwitchingPools().values().stream().findFirst().get()
-                                .getNonBlockingList().values())) {
-                        if (nbl.getTpList().contains(clTp) && nbl.getTpList().contains(nwTp)) {
-                            usableXpdrClientTps.add(clTp);
+        Node1 node1 = node.augmentation(Node1.class);
+        if (node1 == null) {
+            return false;
+        }
+        List<NonBlockingList> nblList = new ArrayList<>(
+                node1.getSwitchingPools().nonnullOduSwitchingPools()
+                        .values().stream().findFirst().get()
+                                .getNonBlockingList().values());
+        if (nblList == null) {
+            return false;
+        }
+        netwTps.sort(Comparator.comparing(TpId::getValue));
+
+        switch (modeType) {
+
+            case "intermediate":
+                for (NonBlockingList nbl: nblList) {
+                    for (TpId nwTp : netwTps) {
+                        if (nbl.getTpList().contains(nwTp)) {
                             usableXpdrNWTps.add(nwTp);
                         }
-                        if (usableXpdrClientTps.size() >= 1 && usableXpdrNWTps.size() >= 1
-                            //since nbClient == 1 && nbNetw == 1...
-                                && (this.clientPort == null || this.clientPort.equals(clTp.getValue()))) {
-                            clientPerNwTp.put(nwTp.getValue(), clTp.getValue());
+                        if (usableXpdrNWTps.size() >= 2) {
                             return true;
                         }
                     }
                 }
-            }
-        }
-        if (nbClient == 0 && nbNetw == 2) {
-            netwTps.sort(Comparator.comparing(TpId::getValue));
-            //TODO compared to above, nested loops are inverted below - does it make really sense ?
-            //     there is room to rationalize things here
-            for (NonBlockingList nbl : new ArrayList<>(node.augmentation(Node1.class).getSwitchingPools()
-                    .nonnullOduSwitchingPools().values().stream().findFirst().get()
-                        .getNonBlockingList().values())) {
-                for (TpId nwTp : netwTps) {
-                    if (nbl.getTpList().contains(nwTp)) {
-                        usableXpdrNWTps.add(nwTp);
-                    }
-                    if (usableXpdrNWTps.size() >= 2) {
-                    //since nbClient == 0 && nbNetw == 2...
-                        return true;
+                return false;
+
+            case "AZ":
+                if (clientTps == null) {
+                    return false;
+                }
+                clientTps.sort(Comparator.comparing(TpId::getValue));
+                for (NonBlockingList nbl: nblList) {
+                    for (TpId nwTp : netwTps) {
+                        for (TpId clTp : clientTps) {
+                            if (nbl.getTpList().contains(clTp) && nbl.getTpList().contains(nwTp)) {
+                                usableXpdrClientTps.add(clTp);
+                                usableXpdrNWTps.add(nwTp);
+                            }
+                            if (usableXpdrClientTps.size() >= 1 && usableXpdrNWTps.size() >= 1
+                                    && (this.clientPort == null || this.clientPort.equals(clTp.getValue()))) {
+                                clientPerNwTp.put(nwTp.getValue(), clTp.getValue());
+                                return true;
+                            }
+                        }
                     }
                 }
-            }
+                return false;
+
+            default:
+                LOG.error("Unsupported mode type {}", modeType);
+                return false;
         }
-        return false;
     }
 
     private boolean checkTpForOdtuTermination(TerminationPoint1 ontTp1) {