Adapt TransportPCE code to Sulfur
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / networkanalyzer / PceCalculation.java
index 2a189e440d752b5d5c79fd6f9edacb3aff679bd4..a817bec4aaed44050e6d259f0b4288c60f09a309 100644 (file)
@@ -8,14 +8,13 @@
 
 package org.opendaylight.transportpce.pce.networkanalyzer;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
-import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.stream.Collectors;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
@@ -30,14 +29,18 @@ import org.opendaylight.transportpce.common.network.NetworkTransactionService;
 import org.opendaylight.transportpce.common.service.ServiceTypes;
 import org.opendaylight.transportpce.pce.PceComplianceCheck;
 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.PathComputationRequestInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220114.mc.capabilities.McCapabilities;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220615.PathComputationRequestInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mc.capabilities.McCapabilities;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Link1;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Node1;
+//import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1;
+//import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmLinkType;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmLinkType;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmNodeType;
+//import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmLinkType;
+//import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
@@ -71,7 +74,7 @@ public class PceCalculation {
     ///////////// Intermediate data/////////////////
     private List<PceLink> addLinks = new ArrayList<>();
     private List<PceLink> dropLinks = new ArrayList<>();
-    private HashSet<NodeId> azSrgs = new HashSet<>();
+    private List<NodeId> azSrgs = new ArrayList<>();
 
     private PceNode aendPceNode = null;
     private PceNode zendPceNode = null;
@@ -84,7 +87,7 @@ public class PceCalculation {
     // this List serves calculation of ZtoA path description
     // TODO maybe better solution is possible
     private Map<LinkId, PceLink> allPceLinks = new HashMap<>();
-    private Set<LinkId> linksToExclude = new HashSet<>();
+    private List<LinkId> linksToExclude = new ArrayList<>();
     private PceResult returnStructure;
     private PortMapping portMapping;
 
@@ -137,12 +140,13 @@ public class PceCalculation {
         serviceFormatA = input.getServiceAEnd().getServiceFormat().getName();
         serviceFormatZ = input.getServiceZEnd().getServiceFormat().getName();
         serviceRate = input.getServiceAEnd().getServiceRate();
-        serviceType = ServiceTypes.getServiceType(serviceFormatA, serviceRate,
-            (NodeTypes.Xpdr.equals(portMapping.getNode(input.getServiceAEnd().getNodeId()).getNodeInfo().getNodeType())
-            && input.getServiceAEnd().getTxDirection() != null
-            && input.getServiceAEnd().getTxDirection().getPort() != null
-            && input.getServiceAEnd().getTxDirection().getPort().getPortName() != null)
-                ? portMapping.getMapping(input.getServiceAEnd().getNodeId(),
+        serviceType = ServiceTypes.getServiceType(
+            serviceFormatA,
+            serviceRate,
+            NodeTypes.Xpdr.equals(portMapping.getNode(input.getServiceAEnd().getNodeId()).getNodeInfo().getNodeType())
+                    && checkAendInputTxPortName()
+                ? portMapping.getMapping(
+                    input.getServiceAEnd().getNodeId(),
                     input.getServiceAEnd().getTxDirection().getPort().getPortName())
                 : null);
 
@@ -155,24 +159,38 @@ public class PceCalculation {
         return true;
     }
 
+    private boolean checkAendInputTxPortName() {
+        return checkAendInputTxPort()
+            && input.getServiceAEnd().getTxDirection().getPort().getPortName() != null;
+    }
+
+    private boolean checkAendInputTxPortDeviceName() {
+        return checkAendInputTxPort()
+            && input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName() != null;
+    }
+
+    private boolean checkAendInputTxPort() {
+        return input.getServiceAEnd() != null
+            && input.getServiceAEnd().getTxDirection() != null
+            && input.getServiceAEnd().getTxDirection().getPort() != null;
+    }
+
+    private boolean checkZendInputTxPortDeviceName() {
+        return input.getServiceZEnd() != null
+            && input.getServiceZEnd().getTxDirection() != null
+            && input.getServiceZEnd().getTxDirection().getPort() != null
+            && input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName() != null;
+    }
+
     private void getAZnodeId() {
-        switch (serviceType) {
-            case StringConstants.SERVICE_TYPE_ODU4:
-            case StringConstants.SERVICE_TYPE_ODUC2:
-            case StringConstants.SERVICE_TYPE_ODUC3:
-            case StringConstants.SERVICE_TYPE_ODUC4:
-            case StringConstants.SERVICE_TYPE_100GE_M:
-            case StringConstants.SERVICE_TYPE_100GE_S:
-            case StringConstants.SERVICE_TYPE_10GE:
-            case StringConstants.SERVICE_TYPE_1GE:
-                anodeId = input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName();
-                znodeId = input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName();
-                break;
-            default:
-                anodeId = input.getServiceAEnd().getNodeId();
-                znodeId = input.getServiceZEnd().getNodeId();
-                break;
-        }
+        anodeId =
+            checkAendInputTxPortDeviceName()
+                ? input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName()
+                : input.getServiceAEnd().getNodeId();
+        znodeId =
+            checkZendInputTxPortDeviceName()
+                ? input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName()
+                : input.getServiceZEnd().getNodeId();
     }
 
     private boolean readMdSal() {
@@ -415,7 +433,7 @@ public class PceCalculation {
     }
 
     private void validateNode(Node node) {
-        LOG.debug("validateNode: node {} ", node);
+        LOG.info("validateNode: node {} ", node);
         // PceNode will be used in Graph algorithm
         Node1 node1 = node.augmentation(Node1.class);
         if (node1 == null) {
@@ -476,6 +494,10 @@ public class PceCalculation {
         return;
     }
 
+    @SuppressWarnings("fallthrough")
+    @SuppressFBWarnings(
+        value = "SF_SWITCH_FALLTHROUGH",
+        justification = "intentional fallthrough")
     private boolean isAZendPceNode(String serviceFormat, PceOpticalNode pceNode, String azNodeId, String azEndPoint) {
         switch (serviceFormat) {
             case "Ethernet":
@@ -483,17 +505,20 @@ public class PceCalculation {
                 if (pceNode.getSupNetworkNodeId().equals(azNodeId)) {
                     return true;
                 }
-                return false;
+            //fallthrough
             case "OTU":
-                if ("A".equals(azEndPoint) && pceNode.getNodeId().getValue()
-                    .equals(this.input.getServiceAEnd().getRxDirection().getPort().getPortDeviceName())) {
-                    return true;
+                switch (azEndPoint) {
+                    case "A":
+                        return checkAendInputTxPortDeviceName()
+                            && pceNode.getNodeId().getValue()
+                                .equals(this.input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName());
+                    case "Z":
+                        return checkZendInputTxPortDeviceName()
+                            && pceNode.getNodeId().getValue()
+                                .equals(this.input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName());
+                    default:
+                        return false;
                 }
-                if ("Z".equals(azEndPoint) && pceNode.getNodeId().getValue()
-                    .equals(this.input.getServiceZEnd().getRxDirection().getPort().getPortDeviceName())) {
-                    return true;
-                }
-                return false;
             default:
                 LOG.debug("Unsupported service Format {} for node {}", serviceFormat, pceNode.getNodeId().getValue());
                 return false;
@@ -765,12 +790,12 @@ public class PceCalculation {
         String moduleName = params[params.length - 1];
         for (McCapabilities mcCapabitility : mcCapabilities) {
             if (mcCapabitility.getMcNodeName().contains("XPDR")
-                && mcCapabitility.getSlotWidthGranularity() != null) {
-                return mcCapabitility.getSlotWidthGranularity().getValue();
+                    && mcCapabitility.getSlotWidthGranularity() != null) {
+                return mcCapabitility.getSlotWidthGranularity().getValue().decimalValue();
             }
             if (mcCapabitility.getMcNodeName().contains(moduleName)
                     && mcCapabitility.getSlotWidthGranularity() != null) {
-                return mcCapabitility.getSlotWidthGranularity().getValue();
+                return mcCapabitility.getSlotWidthGranularity().getValue().decimalValue();
             }
         }
         return GridConstant.SLOT_WIDTH_50;
@@ -791,12 +816,12 @@ public class PceCalculation {
         String moduleName = params[params.length - 1];
         for (McCapabilities mcCapabitility : mcCapabilities) {
             if (mcCapabitility.getMcNodeName().contains("XPDR")
-                && mcCapabitility.getCenterFreqGranularity() != null) {
-                return mcCapabitility.getCenterFreqGranularity().getValue();
+                    && mcCapabitility.getCenterFreqGranularity() != null) {
+                return mcCapabitility.getCenterFreqGranularity().getValue().decimalValue();
             }
             if (mcCapabitility.getMcNodeName().contains(moduleName)
-                && mcCapabitility.getCenterFreqGranularity() != null) {
-                return mcCapabitility.getCenterFreqGranularity().getValue();
+                    && mcCapabitility.getCenterFreqGranularity() != null) {
+                return mcCapabitility.getCenterFreqGranularity().getValue().decimalValue();
             }
         }
         return GridConstant.SLOT_WIDTH_50;