From d356e7d288af388774773eaea7ea64d66de9bab4 Mon Sep 17 00:00:00 2001 From: "guillaume.lambert" Date: Fri, 4 Dec 2020 22:10:19 +0100 Subject: [PATCH] improve partner-port check in createTtpPortMapping 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 Change-Id: Ibe90c2d9755ff981762da0cc179e367882f3fa33 --- .../common/mapping/PortMappingVersion121.java | 27 +++++++++--------- .../common/mapping/PortMappingVersion221.java | 28 ++++++++++--------- .../common/mapping/PortMappingVersion710.java | 28 ++++++++++--------- 3 files changed, 44 insertions(+), 39 deletions(-) diff --git a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java index a27b75c4d..6de73f84d 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java @@ -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()) diff --git a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java index 574e447a6..af9319d56 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java @@ -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-") diff --git a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java index ed4b697cc..b5cdb568a 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java @@ -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-") -- 2.36.6