Fix PceCalculation bug when validating nodes 47/101647/4
authorThierry Jiao <thierry.jiao@orange.com>
Thu, 30 Jun 2022 07:31:41 +0000 (09:31 +0200)
committerThierry Jiao <thierry.jiao@orange.com>
Fri, 1 Jul 2022 12:26:55 +0000 (14:26 +0200)
JIRA: TRNSPRTPCE-677
Signed-off-by: Thierry Jiao <thierry.jiao@orange.com>
Change-Id: Ia969fce0ad8cdb57f5e18db9576a6007a54930f4

pce/src/main/java/org/opendaylight/transportpce/pce/networkanalyzer/PceCalculation.java
pce/src/main/java/org/opendaylight/transportpce/pce/networkanalyzer/PceOpticalNode.java
tests/sample_configs/openroadm/7.1/oper-XPDRA2.xml
tests/sample_configs/openroadm/7.1/oper-XPDRC2.xml
tests/transportpce_tests/7.1/test03_renderer_or_modes.py

index c916b378c0d7626eb966a082ad07d24537524988..f0929fcc4abc9b7595d8c048cc91603c8c216eb8 100644 (file)
@@ -58,7 +58,7 @@ import org.slf4j.LoggerFactory;
 public class PceCalculation {
     /* Logging. */
     private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
-    private NetworkTransactionService networkTransactionService = null;
+    private NetworkTransactionService networkTransactionService;
 
     ///////////// data parsed from Input/////////////////
     private PathComputationRequestInput input;
@@ -127,7 +127,6 @@ public class PceCalculation {
         printNodesInfo(allPceNodes);
 
         returnStructure.setRC(ResponseCodes.RESPONSE_OK);
-        return;
     }
 
     private boolean parseInput() {
@@ -474,7 +473,7 @@ public class PceCalculation {
                 List<Link> links = this.allLinks.stream()
                     .filter(x -> x.getSource().getSourceNode().getValue().contains(pceNode.getNodeId().getValue()))
                     .collect(Collectors.toList());
-                if (links.size() > 0) {
+                if (!links.isEmpty()) {
                     this.aendPceNode = pceNode;
                 }
             }
@@ -483,7 +482,7 @@ public class PceCalculation {
                 List<Link> links = this.allLinks.stream()
                     .filter(x -> x.getDestination().getDestNode().getValue().contains(pceNode.getNodeId().getValue()))
                     .collect(Collectors.toList());
-                if (links.size() > 0) {
+                if (!links.isEmpty()) {
                     this.zendPceNode = pceNode;
                 }
             }
@@ -491,7 +490,6 @@ public class PceCalculation {
 
         allPceNodes.put(pceNode.getNodeId(), pceNode);
         LOG.debug("validateNode: node is saved {}", pceNode.getNodeId().getValue());
-        return;
     }
 
     @SuppressWarnings("fallthrough")
@@ -569,7 +567,6 @@ public class PceCalculation {
         }
         allPceNodes.put(pceOtnNode.getNodeId(), pceOtnNode);
         LOG.info("validateOtnNode: node {} is saved", node.getNodeId().getValue());
-        return;
     }
 
     private ConstraintTypes validateNodeConstraints(PceNode pcenode) {
index 74e70c7806f4942f44c8f4f84c05295f4ea5be9b..7e96ea39860a053edfa02c9c8caae4bccdcc52b9 100644 (file)
@@ -186,12 +186,8 @@ public class PceOpticalNode implements PceNode {
                 }
                 return false;
             case "100GE":
-                if (mapping.getSupportedInterfaceCapability().contains(IfOCH.class)
-                        || mapping.getSupportedInterfaceCapability().contains(IfOCHOTU4ODU4.class)) {
-                    return true;
-                } else {
-                    return false;
-                }
+                return mapping.getSupportedInterfaceCapability().contains(IfOCH.class)
+                        || mapping.getSupportedInterfaceCapability().contains(IfOCHOTU4ODU4.class);
             default:
                 return true;
         }
@@ -242,7 +238,6 @@ public class PceOpticalNode implements PceNode {
                 if (!State.InService.equals(node11.getOperationalState())) {
                     this.valid = false;
                     LOG.error("initWLlist: XPDR node {} is OOS/degraded", this);
-                    return;
                 }
                 break;
             default:
@@ -256,17 +251,16 @@ public class PceOpticalNode implements PceNode {
         if (!isValid()) {
             return;
         }
+        this.valid = false;
         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp =
                 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
                     .ietf.network.topology.rev180226.Node1.class);
         List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
             .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
         if (allTps.isEmpty()) {
-            this.valid = false;
             LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
             return;
         }
-        this.valid = false;
         for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
             .node.TerminationPoint tp : allTps) {
             TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
@@ -280,7 +274,6 @@ public class PceOpticalNode implements PceNode {
             }
             if (!State.InService.equals(cntp1.getOperationalState())) {
                 LOG.warn("initXndrTps: XPONDER tp = {} is OOS/degraded", tp.getTpId().getValue());
-                this.valid = false;
                 continue;
             }
             org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.TerminationPoint1 nttp1 = tp
@@ -289,22 +282,22 @@ public class PceOpticalNode implements PceNode {
             if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
                 this.usedXpndrNWTps.add(tp.getTpId().getValue());
                 LOG.debug("initXndrTps: XPONDER tp = {} is used", tp.getTpId().getValue());
-            } else {
-                this.valid = true;
+                continue;
             }
             // find Client of this network TP
-            String client;
             org.opendaylight.yang.gen.v1.http.transportpce.topology.rev220123.TerminationPoint1 tpceTp1 =
                     tp.augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev220123
                             .TerminationPoint1.class);
             if (tpceTp1 != null) {
-                client = tpceTp1.getAssociatedConnectionMapPort();
+                String client = tpceTp1.getAssociatedConnectionMapPort();
                 if (client != null) {
                     this.clientPerNwTp.put(tp.getTpId().getValue(), client);
                     this.valid = true;
                 } else {
                     LOG.error("Service Format {} not managed yet", serviceFormat.getName());
                 }
+            } else {
+                this.valid = true;
             }
         }
         if (!isValid()) {
@@ -347,32 +340,25 @@ public class PceOpticalNode implements PceNode {
                 break;
         }
         LOG.debug("getRdmSrgClient:  Getting client PP for CP '{}'", tp);
-        if (!this.availableSrgPp.isEmpty()) {
-            Optional<String> client = null;
-            final OpenroadmTpType openType = srgType;
-            client = this.availableSrgPp.entrySet()
-                    .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
-                    .map(Map.Entry::getKey)
-                    .sorted(new SortPortsByName())
-                    .findFirst();
-            if (!client.isPresent()) {
-                LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this, tp);
-                return null;
-            }
-            LOG.debug("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
-            return client.get();
-        } else {
+        if (this.availableSrgPp.isEmpty()) {
             LOG.error("getRdmSrgClient: SRG TerminationPoint PP list is not available for node {}", this);
             return null;
         }
+        final OpenroadmTpType openType = srgType;
+        Optional<String> client = this.availableSrgPp.entrySet()
+                .stream().filter(pp -> pp.getValue().getName().equals(openType.getName()))
+                .map(Map.Entry::getKey).min(new SortPortsByName());
+        if (client.isEmpty()) {
+            LOG.error("getRdmSrgClient: ROADM {} doesn't have PP Client for CP {}", this, tp);
+            return null;
+        }
+        LOG.debug("getRdmSrgClient: client PP {} for CP {} found !", client, tp);
+        return client.get();
     }
 
 
     public void validateAZxponder(String anodeId, String znodeId, ServiceFormat serviceFormat) {
-        if (!isValid()) {
-            return;
-        }
-        if (this.nodeType != OpenroadmNodeType.XPONDER) {
+        if (!isValid() || this.nodeType != OpenroadmNodeType.XPONDER) {
             return;
         }
         // Detect A and Z
index 18388fd436e28930dcbc9b4776a068b48caaab32..c66f372b4916cb319748c897e0fd625f852dadcb 100644 (file)
         <port-name>C1</port-name>
       </destination>
     </connection-map>
+    <connection-map>
+      <connection-map-number>3</connection-map-number>
+      <source>
+        <port-name>C1</port-name>
+        <circuit-pack-name>1/1/3-PLUG-CLIENT</circuit-pack-name>
+      </source>
+      <destination>
+        <circuit-pack-name>1/1/4-PLUG-NET</circuit-pack-name>
+        <port-name>L1</port-name>
+      </destination>
+    </connection-map>
+    <connection-map>
+      <connection-map-number>4</connection-map-number>
+      <source>
+        <port-name>L1</port-name>
+        <circuit-pack-name>1/1/4-PLUG-NET</circuit-pack-name>
+      </source>
+      <destination>
+        <circuit-pack-name>1/1/3-PLUG-CLIENT</circuit-pack-name>
+        <port-name>C1</port-name>
+      </destination>
+    </connection-map>
     <odu-switching-pools>
       <switching-pool-number>1</switching-pool-number>
       <switching-pool-type>blocking</switching-pool-type>
index 02ee4a010d6e8a508172c5bb162244dfd1e90137..7a23dace3c1e16e06749110691387f110821e775 100644 (file)
         <port-name>C1</port-name>
       </destination>
     </connection-map>
+    <connection-map>
+      <connection-map-number>3</connection-map-number>
+      <source>
+        <port-name>C1</port-name>
+        <circuit-pack-name>1/1/3-PLUG-CLIENT</circuit-pack-name>
+      </source>
+      <destination>
+        <circuit-pack-name>1/1/4-PLUG-NET</circuit-pack-name>
+        <port-name>L1</port-name>
+      </destination>
+    </connection-map>
+    <connection-map>
+      <connection-map-number>4</connection-map-number>
+      <source>
+        <port-name>L1</port-name>
+        <circuit-pack-name>1/1/4-PLUG-NET</circuit-pack-name>
+      </source>
+      <destination>
+        <circuit-pack-name>1/1/3-PLUG-CLIENT</circuit-pack-name>
+        <port-name>C1</port-name>
+      </destination>
+    </connection-map>
     <odu-switching-pools>
       <switching-pool-number>1</switching-pool-number>
       <switching-pool-type>blocking</switching-pool-type>
index 8ffca82b900d153045c4477d93b192222f089603..3d8ee82a0a439646dd392a3ed870322d98ad1e8f 100644 (file)
@@ -27,7 +27,7 @@ import test_utils_rfc8040  # nopep8
 class TransportPCE400GPortMappingTesting(unittest.TestCase):
 
     processes = None
-    NETWORK2_CHECK_DICT = {"logical-connection-point": "XPDR3-NETWORK1",
+    NETWORK1_CHECK_DICT = {"logical-connection-point": "XPDR3-NETWORK1",
                            "supporting-port": "L1",
                            "supported-interface-capability": [
                                "org-openroadm-port-types:if-otsi-otsigroup"
@@ -164,19 +164,21 @@ class TransportPCE400GPortMappingTesting(unittest.TestCase):
     def test_05_get_portmapping_network1(self):
         response = test_utils_rfc8040.portmapping_request("XPDR-A2", "XPDR3-NETWORK1")
         self.assertEqual(response["status_code"], requests.codes.ok)
-        self.NETWORK2_CHECK_DICT["supporting-otucn"] = "XPDR3-NETWORK1-OTUC1"
-        self.NETWORK2_CHECK_DICT["lcp-hash-val"] = "FDvaQIf2Z08="
+        self.NETWORK1_CHECK_DICT["supporting-otucn"] = "XPDR3-NETWORK1-OTUC1"
+        self.NETWORK1_CHECK_DICT["lcp-hash-val"] = "FDvaQIf2Z08="
+        self.NETWORK1_CHECK_DICT["connection-map-lcp"] = "XPDR3-CLIENT1"
         self.assertIn(
-            self.NETWORK2_CHECK_DICT,
+            self.NETWORK1_CHECK_DICT,
             response["mapping"])
 
     def test_06_get_portmapping_network1(self):
         response = test_utils_rfc8040.portmapping_request("XPDR-C2", "XPDR3-NETWORK1")
         self.assertEqual(response["status_code"], requests.codes.ok)
-        self.NETWORK2_CHECK_DICT["supporting-otucn"] = "XPDR3-NETWORK1-OTUC1"
-        self.NETWORK2_CHECK_DICT["lcp-hash-val"] = "AJpkaVmZKJk5"
+        self.NETWORK1_CHECK_DICT["supporting-otucn"] = "XPDR3-NETWORK1-OTUC1"
+        self.NETWORK1_CHECK_DICT["lcp-hash-val"] = "AJpkaVmZKJk5"
+        self.NETWORK1_CHECK_DICT["connection-map-lcp"] = "XPDR3-CLIENT1"
         self.assertIn(
-            self.NETWORK2_CHECK_DICT,
+            self.NETWORK1_CHECK_DICT,
             response["mapping"])
 
     def test_07_check_interface_otsi(self):
@@ -596,18 +598,19 @@ class TransportPCE400GPortMappingTesting(unittest.TestCase):
              ]},
             response["output"]["node-interface"][1])
         # Update the network dict variable for mpdr
-        self.NETWORK2_CHECK_DICT["logical-connection-point"] = "XPDR2-NETWORK1"
-        self.NETWORK2_CHECK_DICT["supporting-circuit-pack-name"] = "1/2/2-PLUG-NET"
-        self.NETWORK2_CHECK_DICT["port-qual"] = "switch-network"
-        self.NETWORK2_CHECK_DICT["xponder-type"] = "mpdr"
-        self.NETWORK2_CHECK_DICT["lcp-hash-val"] = "LY9PxYJqUbw="
+        self.NETWORK1_CHECK_DICT["logical-connection-point"] = "XPDR2-NETWORK1"
+        self.NETWORK1_CHECK_DICT["supporting-circuit-pack-name"] = "1/2/2-PLUG-NET"
+        self.NETWORK1_CHECK_DICT["port-qual"] = "switch-network"
+        self.NETWORK1_CHECK_DICT["xponder-type"] = "mpdr"
+        self.NETWORK1_CHECK_DICT["lcp-hash-val"] = "LY9PxYJqUbw="
 
     def test_33_get_portmapping_network1(self):
         response = test_utils_rfc8040.portmapping_request("XPDR-A2", "XPDR2-NETWORK1")
         self.assertEqual(response["status_code"], requests.codes.ok)
-        self.NETWORK2_CHECK_DICT["supporting-otucn"] = "XPDR2-NETWORK1-OTUC2"
+        self.NETWORK1_CHECK_DICT["supporting-otucn"] = "XPDR2-NETWORK1-OTUC2"
+        del self.NETWORK1_CHECK_DICT["connection-map-lcp"]
         self.assertIn(
-            self.NETWORK2_CHECK_DICT,
+            self.NETWORK1_CHECK_DICT,
             response["mapping"])
 
     def test_34_check_interface_otsi(self):
@@ -706,7 +709,7 @@ class TransportPCE400GPortMappingTesting(unittest.TestCase):
             })
         self.assertEqual(response["status_code"], requests.codes.ok)
         self.assertIn("Request processed", response["output"]["result"])
-        del self.NETWORK2_CHECK_DICT["supporting-otucn"]
+        del self.NETWORK1_CHECK_DICT["supporting-otucn"]
 
     def test_38_check_no_interface_otuc2(self):
         response = test_utils_rfc8040.check_node_attribute_request("XPDR-A2", "interface", "XPDR2-NETWORK1-OTUC2")