Fix bug in PCE picking wrong client port
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / networkanalyzer / PceCalculation.java
index d2f3305f1c321ff37bf23f323d9cc78dfee70329..32d9068f33632bcd716e5204eef94865fc3202b2 100644 (file)
@@ -449,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);
@@ -496,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()) {