Refactor to remove useless wavelength reference
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / networkanalyzer / PceCalculation.java
index 49650f08dc68d4a29a18b2bed69cbbe871dcdcd8..d3c73e8baa2404a3242f9030a817675181d77cb9 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.transportpce.pce.networkanalyzer;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -20,11 +21,14 @@ import java.util.stream.Collectors;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.transportpce.common.NetworkUtils;
 import org.opendaylight.transportpce.common.ResponseCodes;
+import org.opendaylight.transportpce.common.StringConstants;
+import org.opendaylight.transportpce.common.fixedflex.GridConstant;
 import org.opendaylight.transportpce.common.mapping.MappingUtils;
 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.nodes.McCapabilities;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1;
 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;
@@ -38,7 +42,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.top
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-//import org.opendaylight.yangtools.yang.common.Decimal64;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -131,13 +134,13 @@ public class PceCalculation {
             switch (serviceFormatA) {
                 case "Ethernet":
                 case "OC":
-                    serviceType = "100GE";
+                    serviceType = StringConstants.SERVICE_TYPE_100GE;
                     break;
                 case "OTU":
-                    serviceType = "OTU4";
+                    serviceType = StringConstants.SERVICE_TYPE_OTU4;
                     break;
                 case "ODU":
-                    serviceType = "ODU4";
+                    serviceType = StringConstants.SERVICE_TYPE_ODU4;
                     break;
                 default:
                     LOG.debug("parseInput: unsupported service type: Format {} Rate 100L", serviceFormatA);
@@ -151,9 +154,9 @@ public class PceCalculation {
         } else if ("Ethernet".equals(serviceFormatA)) {
         //only rate 100L is currently supported except in Ethernet
             if (serviceRate == 10L) {
-                serviceType = "10GE";
+                serviceType = StringConstants.SERVICE_TYPE_10GE;
             } else if (serviceRate == 1L) {
-                serviceType = "1GE";
+                serviceType = StringConstants.SERVICE_TYPE_1GE;
             } else {
                 LOG.debug("parseInput: unsupported service type: Format Ethernet Rate {}", serviceRate);
             }
@@ -161,7 +164,9 @@ public class PceCalculation {
             LOG.debug("parseInput: unsupported service type: Format {} Rate {}",
                 serviceFormatA, serviceRate);
         }
-        if ("ODU4".equals(serviceType) || "10GE".equals(serviceType)  || "1GE".equals(serviceType)) {
+        if (StringConstants.SERVICE_TYPE_ODU4.equals(serviceType)
+                || StringConstants.SERVICE_TYPE_10GE.equals(serviceType)
+                || StringConstants.SERVICE_TYPE_1GE.equals(serviceType)) {
             anodeId = input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName();
             znodeId = input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName();
         } else {
@@ -244,7 +249,8 @@ public class PceCalculation {
 
         LOG.debug("analyzeNw: allNodes size {}, allLinks size {}", allNodes.size(), allLinks.size());
 
-        if (("100GE".equals(serviceType)) || ("OTU4".equals(serviceType))) {
+        if ((StringConstants.SERVICE_TYPE_100GE.equals(serviceType))
+                || (StringConstants.SERVICE_TYPE_OTU4.equals(serviceType))) {
             // 100GE service and OTU4 service are handled at the openroadm-topology layer
             for (Node node : allNodes) {
                 validateNode(node);
@@ -359,7 +365,8 @@ public class PceCalculation {
             return false;
         }
 
-        if (("100GE".equals(serviceType)) || ("OTU4".equals(serviceType))) {
+        if ((StringConstants.SERVICE_TYPE_100GE.equals(serviceType))
+                || (StringConstants.SERVICE_TYPE_OTU4.equals(serviceType))) {
             // 100GE or OTU4 services are handled at WDM Layer
             PceLink pcelink = new PceLink(link, source, dest);
             if (!pcelink.isValid()) {
@@ -429,7 +436,9 @@ public class PceCalculation {
             }
             return true;
 
-        } else if (("ODU4".equals(serviceType)) || ("10GE".equals(serviceType)) || ("1GE".equals(serviceType))) {
+        } else if ((StringConstants.SERVICE_TYPE_ODU4.equals(serviceType))
+                || (StringConstants.SERVICE_TYPE_10GE.equals(serviceType))
+                || (StringConstants.SERVICE_TYPE_1GE.equals(serviceType))) {
             // ODU4, 1GE and 10GE services relying on ODU2, ODU2e or ODU0 services are handled at OTN layer
             PceLink pceOtnLink = new PceLink(link, source, dest);
 
@@ -484,9 +493,10 @@ public class PceCalculation {
             deviceNodeId = node.getNodeId().getValue();
         }
         LOG.info("Device node id {} for {}", deviceNodeId, node);
-        PceOpticalNode pceNode = new PceOpticalNode(node, nodeType, mappingUtils.getOpenRoadmVersion(deviceNodeId));
+        PceOpticalNode pceNode = new PceOpticalNode(node, nodeType, mappingUtils.getOpenRoadmVersion(deviceNodeId),
+                getSlotWidthGranularity(deviceNodeId, node.getNodeId()));
         pceNode.validateAZxponder(anodeId, znodeId, input.getServiceAEnd().getServiceFormat());
-        pceNode.initWLlist();
+        pceNode.initFrequenciesBitSet();
 
         if (!pceNode.isValid()) {
             LOG.warn(" validateNode: Node is ignored");
@@ -562,15 +572,6 @@ public class PceCalculation {
             LOG.error("ValidateOtnNode: no node-type augmentation. Node {} is ignored", node.getNodeId().getValue());
             return false;
         }
-
-//        if (mode == "AZ") {
-//            pceOtnNode.validateAZxponder(anodeId, znodeId);
-//        } else if (mode == "intermediate") {
-//            pceOtnNode.validateIntermediateSwitch();
-//        } else {
-//            LOG.error("validateOtnNode: unproper mode passed to the method : {} not supported", mode);
-//            return null;
-//        }
     }
 
     private ConstraintTypes validateNodeConstraints(PceNode pcenode) {
@@ -633,7 +634,7 @@ public class PceCalculation {
         }
 
         if (!pceNode.isValid()) {
-            LOG.error("validateNode : there are no availaible wavelengths in node {}", pceNode.getNodeId().getValue());
+            LOG.error("validateNode : there are no available frequencies in node {}", pceNode.getNodeId().getValue());
             return false;
         }
         return true;
@@ -669,4 +670,26 @@ public class PceCalculation {
                     pceNode.getOutgoingLinks());
         }));
     }
+
+    /**
+     * Get mc capability slot width granularity for device.
+     * @param deviceNodeId String
+     * @param nodeId NodeId
+     * @return slot width granularity
+     */
+    private BigDecimal getSlotWidthGranularity(String deviceNodeId, NodeId nodeId) {
+        // nodeId: openroadm-topology level node
+        // deviceNodeId: openroadm-network level node
+        List<McCapabilities> mcCapabilities = mappingUtils.getMcCapabilitiesForNode(deviceNodeId);
+        String[] params = nodeId.getValue().split("-");
+        // DEGX or SRGX
+        String rdmModuleName = params[params.length - 1];
+        for (McCapabilities mcCapabitility : mcCapabilities) {
+            if (mcCapabitility.getMcNodeName().contains(rdmModuleName)
+                    && mcCapabitility.getSlotWidthGranularity() != null) {
+                return mcCapabitility.getSlotWidthGranularity().getValue();
+            }
+        }
+        return GridConstant.SLOT_WIDTH_50;
+    }
 }