improve partner-port check in createTtpPortMapping 55/94055/3
authorguillaume.lambert <guillaume.lambert@orange.com>
Fri, 4 Dec 2020 21:10:19 +0000 (22:10 +0100)
committerGilles Thouenon <gilles.thouenon@orange.com>
Mon, 14 Dec 2020 08:42:01 +0000 (08:42 +0000)
use the checkPartnerPort method inside createTtpPortMapping
such as done in createXpdrPortMapping or createPpPortMapping.

Beyond the overall coherency, this allows to perform some additional
(and maybe missing) null checking before accessing the related fields
and it also improves the log messages details.

JIRA: TRNSPRTPCE-353
Signed-off-by: guillaume.lambert <guillaume.lambert@orange.com>
Change-Id: Ibe90c2d9755ff981762da0cc179e367882f3fa33

common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java

index a27b75c4d240589ad54e6c889ae4cdce6b5c93d7..6de73f84d0e638b91939c1871188ffee06a5b51b 100644 (file)
@@ -816,22 +816,23 @@ public class PortMappingVersion121 {
                         continue;
                     }
                     if (Port.PortQual.RoadmExternal.getIntValue() != port1.getPortQual().getIntValue()
-                        || Port.PortQual.RoadmExternal.getIntValue() != port2.getPortQual().getIntValue()
-                        || port1.getPartnerPort() == null
-                        || port2.getPartnerPort() == null
-                        || !port1.getPartnerPort().getCircuitPackName().equals(cp2Name)
-                        || !port1.getPartnerPort().getPortName().equals(port2.getPortName())
-                        || !port2.getPartnerPort().getCircuitPackName().equals(cp1Name)
-                        || !port2.getPartnerPort().getPortName().equals(port1.getPortName())
-                        || ((Direction.Rx.getIntValue() != port1.getPortDirection().getIntValue()
-                                || Direction.Tx.getIntValue() != port2.getPortDirection().getIntValue())
-                            && (Direction.Rx.getIntValue() != port2.getPortDirection().getIntValue()
-                                || Direction.Tx.getIntValue() != port1.getPortDirection().getIntValue()))) {
-                        LOG.error("Impossible to create logical connection point for port {} or port {} on node {} - "
-                                + "Error in configuration with port-qual, port-direction or partner-port configuration",
+                        || Port.PortQual.RoadmExternal.getIntValue() != port2.getPortQual().getIntValue()) {
+                        LOG.error("Impossible to create logical connection point for port {} or port {} on node {}"
+                                + " - Error in configuration with port-qual",
                             port1.getPortName(), port2.getPortName(), nodeId);
                         continue;
                     }
+                    if (!checkPartnerPort(cp1Name, port1, port2)) {
+                        LOG.error("port {} on {} is not a correct partner port of {} on  {}",
+                            port2.getPortName(), cp2Name, port1.getPortName(), cp1Name);
+                        continue;
+                    }
+                    // TODO this second checkPartnerPort call has overlap checkings with the first one (Directions)
+                    if (!checkPartnerPort(cp2Name, port2, port1)) {
+                        LOG.error("port {} on {} is not a correct partner port of {} on  {}",
+                            port1.getPortName(), cp1Name, port2.getPortName(), cp2Name);
+                        continue;
+                    }
 
                     String logicalConnectionPoint1 = new StringBuilder("DEG")
                         .append(cpMapEntry.getKey())
index 574e447a69912a2937fd3b10438d397bfaf3bd60..af9319d56efd7e9bda6acde944513b52da2d3d32 100644 (file)
@@ -1130,22 +1130,24 @@ public class PortMappingVersion221 {
                         continue;
                     }
                     if (PortQual.RoadmExternal.getIntValue() != port1.getPortQual().getIntValue()
-                        || PortQual.RoadmExternal.getIntValue() != port2.getPortQual().getIntValue()
-                        || port1.getPartnerPort() == null
-                        || port2.getPartnerPort() == null
-                        || !port1.getPartnerPort().getCircuitPackName().equals(cp2Name)
-                        || !port1.getPartnerPort().getPortName().equals(port2.getPortName())
-                        || !port2.getPartnerPort().getCircuitPackName().equals(cp1Name)
-                        || !port2.getPartnerPort().getPortName().equals(port1.getPortName())
-                        || ((Direction.Rx.getIntValue() != port1.getPortDirection().getIntValue()
-                                || Direction.Tx.getIntValue() != port2.getPortDirection().getIntValue())
-                            && (Direction.Rx.getIntValue() != port2.getPortDirection().getIntValue()
-                                || Direction.Tx.getIntValue() != port1.getPortDirection().getIntValue()))) {
-                        LOG.error("Impossible to create logical connection point for port {} or port {} on node {} - "
-                                + "Error in configuration with port-qual, port-direction or partner-port configuration",
+                        || PortQual.RoadmExternal.getIntValue() != port2.getPortQual().getIntValue()) {
+                        LOG.error("Impossible to create logical connection point for port {} or port {} on node {}"
+                                + " - Error in configuration with port-qual",
                             port1.getPortName(), port2.getPortName(), nodeId);
                         continue;
                     }
+                    if (!checkPartnerPort(cp1Name, port1, port2)) {
+                        LOG.error("port {} on {} is not a correct partner port of {} on  {}",
+                            port2.getPortName(), cp2Name, port1.getPortName(), cp1Name);
+                        continue;
+                    }
+                    // TODO this second checkPartnerPort call has overlap checkings with the first one (Directions)
+                    if (!checkPartnerPort(cp2Name, port2, port1)) {
+                        LOG.error("port {} on {} is not a correct partner port of {} on  {}",
+                            port1.getPortName(), cp1Name, port2.getPortName(), cp2Name);
+                        continue;
+                    }
+
                     String logicalConnectionPoint1 = new StringBuilder("DEG")
                         .append(cpMapEntry.getKey())
                         .append("-TTP-")
index ed4b697cc59760aa87b918e6ecc5f64f9cabc713..b5cdb568acf64816771fa1c665512f93cf965fd4 100644 (file)
@@ -1171,22 +1171,24 @@ public class PortMappingVersion710 {
                         continue;
                     }
                     if (PortQual.RoadmExternal.getIntValue() != port1.getPortQual().getIntValue()
-                        || PortQual.RoadmExternal.getIntValue() != port2.getPortQual().getIntValue()
-                        || port1.getPartnerPort() == null
-                        || port2.getPartnerPort() == null
-                        || !port1.getPartnerPort().getCircuitPackName().equals(cp2Name)
-                        || !port1.getPartnerPort().getPortName().equals(port2.getPortName())
-                        || !port2.getPartnerPort().getCircuitPackName().equals(cp1Name)
-                        || !port2.getPartnerPort().getPortName().equals(port1.getPortName())
-                        || ((Direction.Rx.getIntValue() != port1.getPortDirection().getIntValue()
-                                || Direction.Tx.getIntValue() != port2.getPortDirection().getIntValue())
-                            && (Direction.Rx.getIntValue() != port2.getPortDirection().getIntValue()
-                                || Direction.Tx.getIntValue() != port1.getPortDirection().getIntValue()))) {
-                        LOG.error("Impossible to create logical connection point for port {} or port {} on node {} - "
-                                + "Error in configuration with port-qual, port-direction or partner-port configuration",
+                        || PortQual.RoadmExternal.getIntValue() != port2.getPortQual().getIntValue()) {
+                        LOG.error("Impossible to create logical connection point for port {} or port {} on node {}"
+                                + " - Error in configuration with port-qual",
                             port1.getPortName(), port2.getPortName(), nodeId);
                         continue;
                     }
+                    if (!checkPartnerPort(cp1Name, port1, port2)) {
+                        LOG.error("port {} on {} is not a correct partner port of {} on  {}",
+                            port2.getPortName(), cp2Name, port1.getPortName(), cp1Name);
+                        continue;
+                    }
+                    // TODO this second checkPartnerPort call has overlap checkings with the first one (Directions)
+                    if (!checkPartnerPort(cp2Name, port2, port1)) {
+                        LOG.error("port {} on {} is not a correct partner port of {} on  {}",
+                            port1.getPortName(), cp1Name, port2.getPortName(), cp2Name);
+                        continue;
+                    }
+
                     String logicalConnectionPoint1 = new StringBuilder("DEG")
                         .append(cpMapEntry.getKey())
                         .append("-TTP-")