From: guillaume.lambert Date: Thu, 28 Jan 2021 20:16:10 +0000 (+0100) Subject: Add a portmapping method to retrieve Xpdr port2 X-Git-Tag: 2.3.0~11 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=effedfcad2fc52c2bded0403914e0d9247fb53be;p=transportpce.git Add a portmapping method to retrieve Xpdr port2 JIRA: TRNSPRTPCE-354 Signed-off-by: guillaume.lambert Change-Id: Id642171bd70d991a33d6add56a16783dacc8fa8c --- 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 20d46a281..406fb8f32 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 @@ -247,43 +247,15 @@ public class PortMappingVersion121 { line++; continue; } - - if (!checkPartnerPortNotNull(port)) { - LOG.warn("Error in the configuration of port {} of {} for {}", - port.getPortName(), circuitPackName, nodeId); - continue; - } - - if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) { - continue; - } - - Optional cpOpt = circuitPackList.stream() - .filter(cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName())) - .findFirst(); - if (!cpOpt.isPresent()) { - LOG.error("Error fetching circuit-pack {} for {}", - port.getPartnerPort().getCircuitPackName(), nodeId); - continue; - } - - Optional poOpt = cpOpt.get().nonnullPorts().values().stream() - .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName().toString())) - .findFirst(); - if (!poOpt.isPresent()) { - LOG.error("Error fetching port {} on {} for {}", port.getPartnerPort().getPortName(), - port.getPartnerPort().getCircuitPackName(), nodeId); - continue; - } - Ports port2 = poOpt.get(); - if (!checkPartnerPort(circuitPackName, port, port2)) { - LOG.error("port {} on {} is not a correct partner port of {} on {}", - port2.getPortName(), cpOpt.get().getCircuitPackName(), port.getPortName(), - circuitPackName); + StringBuilder circuitPackName2 = new StringBuilder(); + Ports port2 = getPort2(port, nodeId, circuitPackName, circuitPackName2, + circuitPackList, lcpMap); + if (port2 == null) { + //key already present or an error occured and was logged continue; } putXpdrLcpsInMaps(line, nodeId, 1, - circuitPackName, cpOpt.get().getCircuitPackName(), port, port2, + circuitPackName, circuitPackName2.toString(), port, port2, lcpMap, mappingMap); line += 2; break; @@ -707,6 +679,44 @@ public class PortMappingVersion121 { return mpBldr.build(); } + private Ports getPort2(Ports port, String nodeId, String circuitPackName, StringBuilder circuitPackName2, + //circuitPackName2 will be updated by reference contrary to circuitPackName + List circuitPackList, Map lcpMap) { + if (!checkPartnerPortNotNull(port)) { + LOG.warn("Error in the configuration of port {} of {} for {}", + port.getPortName(), circuitPackName, nodeId); + return null; + } + if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) { + return null; + } + Optional cpOpt = circuitPackList.stream() + .filter(cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName())) + .findFirst(); + if (!cpOpt.isPresent()) { + LOG.error("Error fetching circuit-pack {} for {}", + port.getPartnerPort().getCircuitPackName(), nodeId); + return null; + } + Optional poOpt = cpOpt.get().nonnullPorts().values().stream() + .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName().toString())) + .findFirst(); + if (!poOpt.isPresent()) { + LOG.error("Error fetching port {} on {} for {}", port.getPartnerPort().getPortName(), + port.getPartnerPort().getCircuitPackName(), nodeId); + return null; + } + Ports port2 = poOpt.get(); + circuitPackName2.append(cpOpt.get().getCircuitPackName()); + if (!checkPartnerPort(circuitPackName, port, port2)) { + LOG.error("port {} on {} is not a correct partner port of {} on {}", + port2.getPortName(), circuitPackName2, port.getPortName(), + circuitPackName); + return null; + } + return port2; + } + private void putXpdrLcpsInMaps(int line, String nodeId, Integer xponderNb, String circuitPackName, String circuitPackName2, Ports port, Ports port2, 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 ace72bda9..f8866dc42 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 @@ -274,41 +274,18 @@ public class PortMappingVersion221 { continue; } - if (!checkPartnerPortNotNull(port)) { - LOG.warn("Error in the configuration of port {} of {} for {}", - port.getPortName(), circuitPackName, nodeId); - continue; - } - if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) { - continue; - } - Optional cpOpt = circuitPackList.stream() - .filter( - cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName())) - .findFirst(); - if (!cpOpt.isPresent()) { - LOG.error("Error fetching circuit-pack {} for {}", - port.getPartnerPort().getCircuitPackName(), nodeId); - continue; - } - Optional poOpt = cpOpt.get().nonnullPorts().values().stream() - .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName().toString())) - .findFirst(); - if (!poOpt.isPresent()) { - LOG.error("Error fetching port {} on {} for {}", port.getPartnerPort().getPortName(), - port.getPartnerPort().getCircuitPackName(), nodeId); - continue; - } - Ports port2 = poOpt.get(); - if (!checkPartnerPort(circuitPackName, port, port2)) { - LOG.error("port {} on {} is not a correct partner port of {} on {}", - port2.getPortName(), cpOpt.get().getCircuitPackName(), port.getPortName(), - circuitPackName); + StringBuilder circuitPackName2 = new StringBuilder(); + Ports port2 = getPort2(port, nodeId, circuitPackName, circuitPackName2, + circuitPackList, lcpMap); + + if (port2 == null) { + //key already present or an error occured and was logged continue; } + putXpdrLcpsInMaps(line, nodeId, 1, null, - circuitPackName, cpOpt.get().getCircuitPackName(), port, port2, + circuitPackName, circuitPackName2.toString(), port, port2, lcpMap, mappingMap); line += 2; break; @@ -386,43 +363,17 @@ public class PortMappingVersion221 { continue; } - if (!checkPartnerPortNotNull(port)) { - LOG.warn("Error in the configuration of port {} of {} for {}", - port.getPortName(), circuitPackName, nodeId); - continue; - } - - if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) { - continue; - } + StringBuilder circuitPackName2 = new StringBuilder(); + Ports port2 = getPort2(port, nodeId, circuitPackName, circuitPackName2, + circuitPackList, lcpMap); - Optional cpOpt = circuitPackList.stream() - .filter( - cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName())) - .findFirst(); - if (!cpOpt.isPresent()) { - LOG.error("Error fetching circuit-pack {} for {}", - port.getPartnerPort().getCircuitPackName(), nodeId); + if (port2 == null) { + //key already present or an error occured and was logged continue; } - Optional poOpt = cpOpt.get().nonnullPorts().values().stream() - .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName().toString())) - .findFirst(); - if (!poOpt.isPresent()) { - LOG.error("Error fetching port {} on {} for {}", port.getPartnerPort().getPortName(), - port.getPartnerPort().getCircuitPackName(), nodeId); - continue; - } - Ports port2 = poOpt.get(); - if (!checkPartnerPort(circuitPackName, port, port2)) { - LOG.error("port {} on {} is not a correct partner port of {} on {}", - port2.getPortName(), cpOpt.get().getCircuitPackName(), port.getPortName(), - circuitPackName); - continue; - } putXpdrLcpsInMaps(line, nodeId, xponderNb, xponderType, - circuitPackName, cpOpt.get().getCircuitPackName(), port, port2, + circuitPackName, circuitPackName2.toString(), port, port2, lcpMap, mappingMap); line += 2; break; @@ -993,6 +944,45 @@ public class PortMappingVersion221 { return mpBldr.build(); } + private Ports getPort2(Ports port, String nodeId, String circuitPackName, StringBuilder circuitPackName2, + //circuitPackName2 will be updated by reference contrary to circuitPackName + List circuitPackList, Map lcpMap) { + if (!checkPartnerPortNotNull(port)) { + LOG.warn("Error in the configuration of port {} of {} for {}", + port.getPortName(), circuitPackName, nodeId); + return null; + } + if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) { + return null; + } + Optional cpOpt = circuitPackList.stream() + .filter( + cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName())) + .findFirst(); + if (!cpOpt.isPresent()) { + LOG.error("Error fetching circuit-pack {} for {}", + port.getPartnerPort().getCircuitPackName(), nodeId); + return null; + } + Optional poOpt = cpOpt.get().nonnullPorts().values().stream() + .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName().toString())) + .findFirst(); + if (!poOpt.isPresent()) { + LOG.error("Error fetching port {} on {} for {}", + port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName(), nodeId); + return null; + } + Ports port2 = poOpt.get(); + circuitPackName2.append(cpOpt.get().getCircuitPackName()); + if (!checkPartnerPort(circuitPackName, port, port2)) { + LOG.error("port {} on {} is not a correct partner port of {} on {}", + port2.getPortName(), circuitPackName2, port.getPortName(), circuitPackName); + return null; + } + return port2; + } + + private void putXpdrLcpsInMaps(int line, String nodeId, Integer xponderNb, XpdrNodeTypes xponderType, String circuitPackName, String circuitPackName2, Ports port, Ports port2, 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 d3e75ae2f..89a6d4c42 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 @@ -273,41 +273,18 @@ public class PortMappingVersion710 { continue; } - if (!checkPartnerPortNotNull(port)) { - LOG.warn("Error in the configuration of port {} of {} for {}", - port.getPortName(), circuitPackName, nodeId); - continue; - } - if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) { - continue; - } - Optional cpOpt = circuitPackList.stream() - .filter( - cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName())) - .findFirst(); - if (!cpOpt.isPresent()) { - LOG.error("Error fetching circuit-pack {} for {}", - port.getPartnerPort().getCircuitPackName(), nodeId); - continue; - } - Optional poOpt = cpOpt.get().nonnullPorts().values().stream() - .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName().toString())) - .findFirst(); - if (!poOpt.isPresent()) { - LOG.error("Error fetching port {} on {} for {}", port.getPartnerPort().getPortName(), - port.getPartnerPort().getCircuitPackName(), nodeId); - continue; - } - Ports port2 = poOpt.get(); - if (!checkPartnerPort(circuitPackName, port, port2)) { - LOG.error("port {} on {} is not a correct partner port of {} on {}", - port2.getPortName(), cpOpt.get().getCircuitPackName(), port.getPortName(), - circuitPackName); + StringBuilder circuitPackName2 = new StringBuilder(); + Ports port2 = getPort2(port, nodeId, circuitPackName, circuitPackName2, + circuitPackList, lcpMap); + + if (port2 == null) { + //key already present or an error occured and was logged continue; } + putXpdrLcpsInMaps(line, nodeId, 1, null, - circuitPackName, cpOpt.get().getCircuitPackName(), port, port2, + circuitPackName, circuitPackName2.toString(), port, port2, lcpMap, mappingMap); line += 2; break; @@ -385,43 +362,17 @@ public class PortMappingVersion710 { continue; } - if (!checkPartnerPortNotNull(port)) { - LOG.warn("Error in the configuration of port {} of {} for {}", - port.getPortName(), circuitPackName, nodeId); - continue; - } - - if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) { - continue; - } + StringBuilder circuitPackName2 = new StringBuilder(); + Ports port2 = getPort2(port, nodeId, circuitPackName, circuitPackName2, + circuitPackList, lcpMap); - Optional cpOpt = circuitPackList.stream() - .filter( - cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName())) - .findFirst(); - if (!cpOpt.isPresent()) { - LOG.error("Error fetching circuit-pack {} for {}", - port.getPartnerPort().getCircuitPackName(), nodeId); + if (port2 == null) { + //key already present or an error occured and was logged continue; } - Optional poOpt = cpOpt.get().nonnullPorts().values().stream() - .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName().toString())) - .findFirst(); - if (!poOpt.isPresent()) { - LOG.error("Error fetching port {} on {} for {}", port.getPartnerPort().getPortName(), - port.getPartnerPort().getCircuitPackName(), nodeId); - continue; - } - Ports port2 = poOpt.get(); - if (!checkPartnerPort(circuitPackName, port, port2)) { - LOG.error("port {} on {} is not a correct partner port of {} on {}", - port2.getPortName(), cpOpt.get().getCircuitPackName(), port.getPortName(), - circuitPackName); - continue; - } putXpdrLcpsInMaps(line, nodeId, xponderNb, xponderType, - circuitPackName, cpOpt.get().getCircuitPackName(), port, port2, + circuitPackName, circuitPackName2.toString(), port, port2, lcpMap, mappingMap); line += 2; break; @@ -1033,6 +984,45 @@ public class PortMappingVersion710 { return mpBldr.build(); } + private Ports getPort2(Ports port, String nodeId, String circuitPackName, StringBuilder circuitPackName2, + //circuitPackName2 will be updated by reference contrary to circuitPackName + List circuitPackList, Map lcpMap) { + if (!checkPartnerPortNotNull(port)) { + LOG.warn("Error in the configuration of port {} of {} for {}", + port.getPortName(), circuitPackName, nodeId); + return null; + } + if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) { + return null; + } + Optional cpOpt = circuitPackList.stream() + .filter( + cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName())) + .findFirst(); + if (!cpOpt.isPresent()) { + LOG.error("Error fetching circuit-pack {} for {}", + port.getPartnerPort().getCircuitPackName(), nodeId); + return null; + } + Optional poOpt = cpOpt.get().nonnullPorts().values().stream() + .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName().toString())) + .findFirst(); + if (!poOpt.isPresent()) { + LOG.error("Error fetching port {} on {} for {}", + port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName(), nodeId); + return null; + } + Ports port2 = poOpt.get(); + circuitPackName2.append(cpOpt.get().getCircuitPackName()); + if (!checkPartnerPort(circuitPackName, port, port2)) { + LOG.error("port {} on {} is not a correct partner port of {} on {}", + port2.getPortName(), circuitPackName2, port.getPortName(), circuitPackName); + return null; + } + return port2; + } + + private void putXpdrLcpsInMaps(int line, String nodeId, Integer xponderNb, XpdrNodeTypes xponderType, String circuitPackName, String circuitPackName2, Ports port, Ports port2,