Fix bug in PCE picking wrong client port
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / networkanalyzer / PceCalculation.java
index f01e14c46af53d945e5e96cc5e1e13334563e0f4..32d9068f33632bcd716e5204eef94865fc3202b2 100644 (file)
@@ -31,7 +31,7 @@ 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.rev210426.mc.capabilities.McCapabilities;
+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.openroadm.common.state.types.rev191129.State;
@@ -158,6 +158,8 @@ public class PceCalculation {
     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:
@@ -179,6 +181,8 @@ public class PceCalculation {
             case StringConstants.SERVICE_TYPE_100GE_T:
             case StringConstants.SERVICE_TYPE_400GE:
             case StringConstants.SERVICE_TYPE_OTU4:
+            case StringConstants.SERVICE_TYPE_OTUC2:
+            case StringConstants.SERVICE_TYPE_OTUC3:
             case StringConstants.SERVICE_TYPE_OTUC4:
                 LOG.info("readMdSal: network {}", NetworkUtils.OVERLAY_NETWORK_ID);
                 nwInstanceIdentifier = InstanceIdentifier.builder(Networks.class)
@@ -187,6 +191,8 @@ public class PceCalculation {
             case StringConstants.SERVICE_TYPE_100GE_M:
             case StringConstants.SERVICE_TYPE_100GE_S:
             case StringConstants.SERVICE_TYPE_ODU4:
+            case StringConstants.SERVICE_TYPE_ODUC2:
+            case StringConstants.SERVICE_TYPE_ODUC3:
             case StringConstants.SERVICE_TYPE_ODUC4:
             case StringConstants.SERVICE_TYPE_10GE:
             case StringConstants.SERVICE_TYPE_1GE:
@@ -259,6 +265,8 @@ public class PceCalculation {
             case StringConstants.SERVICE_TYPE_100GE_T:
             case  StringConstants.SERVICE_TYPE_OTU4:
             case  StringConstants.SERVICE_TYPE_400GE:
+            case StringConstants.SERVICE_TYPE_OTUC2:
+            case StringConstants.SERVICE_TYPE_OTUC3:
             case  StringConstants.SERVICE_TYPE_OTUC4:
                 // 100GE service and OTU4 service are handled at the openroadm-topology layer
                 for (Node node : allNodes) {
@@ -386,6 +394,8 @@ public class PceCalculation {
         switch (serviceType) {
             case StringConstants.SERVICE_TYPE_100GE_T:
             case StringConstants.SERVICE_TYPE_OTU4:
+            case StringConstants.SERVICE_TYPE_OTUC2:
+            case StringConstants.SERVICE_TYPE_OTUC3:
             case StringConstants.SERVICE_TYPE_OTUC4:
             case StringConstants.SERVICE_TYPE_400GE:
                 return processPceLink(link, sourceId, destId, source, dest);
@@ -393,6 +403,8 @@ public class PceCalculation {
             case StringConstants.SERVICE_TYPE_10GE:
             case StringConstants.SERVICE_TYPE_100GE_M:
             case StringConstants.SERVICE_TYPE_100GE_S:
+            case StringConstants.SERVICE_TYPE_ODUC2:
+            case StringConstants.SERVICE_TYPE_ODUC3:
             case StringConstants.SERVICE_TYPE_ODUC4:
             case StringConstants.SERVICE_TYPE_1GE:
                 return processPceOtnLink(link, source, dest);
@@ -437,13 +449,26 @@ public class PceCalculation {
         if (validateNodeConstraints(pceNode).equals(ConstraintTypes.HARD_EXCLUDE)) {
             return;
         }
-        if (endPceNode(nodeType, pceNode.getNodeId(), pceNode) && this.aendPceNode == null
-            && isAZendPceNode(this.serviceFormatA, pceNode, anodeId, "A")) {
-            this.aendPceNode = pceNode;
-        }
-        if (endPceNode(nodeType, pceNode.getNodeId(), pceNode) && this.zendPceNode == null
-            && isAZendPceNode(this.serviceFormatZ, pceNode, znodeId, "Z")) {
-            this.zendPceNode = pceNode;
+
+        if (endPceNode(nodeType, pceNode.getNodeId(), pceNode)) {
+            if (this.aendPceNode == null && isAZendPceNode(this.serviceFormatA, pceNode, anodeId, "A")) {
+                // Added to ensure A-node has a addlink in the topology
+                List<Link> links = this.allLinks.stream()
+                    .filter(x -> x.getSource().getSourceNode().getValue().contains(pceNode.getNodeId().getValue()))
+                    .collect(Collectors.toList());
+                if (links.size() > 0) {
+                    this.aendPceNode = pceNode;
+                }
+            }
+            if (this.zendPceNode == null && isAZendPceNode(this.serviceFormatZ, pceNode, znodeId, "Z")) {
+                // Added to ensure Z-node has a droplink in the topology
+                List<Link> links = this.allLinks.stream()
+                    .filter(x -> x.getDestination().getDestNode().getValue().contains(pceNode.getNodeId().getValue()))
+                    .collect(Collectors.toList());
+                if (links.size() > 0) {
+                    this.zendPceNode = pceNode;
+                }
+            }
         }
 
         allPceNodes.put(pceNode.getNodeId(), pceNode);
@@ -484,8 +509,24 @@ public class PceCalculation {
         }
 
         OpenroadmNodeType nodeType = node.augmentation(Node1.class).getNodeType();
-
-        PceOtnNode pceOtnNode = new PceOtnNode(node, nodeType, node.getNodeId(), "otn", serviceType);
+        String clientPort = null;
+        if (node.getNodeId().getValue().equals(anodeId)
+                && this.aendPceNode == null
+                && input.getServiceAEnd() != null
+                && input.getServiceAEnd().getRxDirection() != null
+                && input.getServiceAEnd().getRxDirection().getPort() != null
+                && input.getServiceAEnd().getRxDirection().getPort().getPortName() != null) {
+            clientPort = input.getServiceAEnd().getRxDirection().getPort().getPortName();
+        } else if (node.getNodeId().getValue().equals(znodeId)
+                && this.zendPceNode == null
+                && input.getServiceZEnd() != null
+                && input.getServiceZEnd().getRxDirection() != null
+                && input.getServiceZEnd().getRxDirection().getPort() != null
+                && input.getServiceZEnd().getRxDirection().getPort().getPortName() != null) {
+            clientPort = input.getServiceZEnd().getRxDirection().getPort().getPortName();
+        }
+
+        PceOtnNode pceOtnNode = new PceOtnNode(node, nodeType, node.getNodeId(), "otn", serviceType, clientPort);
         pceOtnNode.validateXponder(anodeId, znodeId);
 
         if (!pceOtnNode.isValid()) {