From 9732c621dfe6aa4901d2bc763a17a667a386ed07 Mon Sep 17 00:00:00 2001 From: Balagangadhar Bathula Date: Wed, 11 Nov 2020 15:02:06 -0500 Subject: [PATCH] Add protection in portmapping connection-map loop the port-mapping fails if the xponder subtree is absent for the entries in connection-map. This can happen with some devices buggy implementations. JIRA: TRNSPRTPCE-348 Change-Id: If1a0cb15f8e55038485d75cbe9cdcd826d70c06b --- .../common/mapping/PortMappingVersion121.java | 19 ++++++++------ .../common/mapping/PortMappingVersion221.java | 26 ++++++++++--------- .../common/mapping/PortMappingVersion710.java | 26 ++++++++++--------- 3 files changed, 39 insertions(+), 32 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 f96f5125a..70e9e98d9 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 @@ -291,10 +291,11 @@ public class PortMappingVersion121 { } } } + Collection connectionMap = deviceObject.get().nonnullConnectionMap().values(); - String slcp = null; - String dlcp = null; for (ConnectionMap cm : connectionMap) { + String slcp = null; + String dlcp = null; String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName(); if (lcpMap.containsKey(skey)) { slcp = lcpMap.get(skey); @@ -304,14 +305,16 @@ public class PortMappingVersion121 { if (lcpMap.containsKey(dkey)) { dlcp = lcpMap.get(dkey); } - if (slcp != null) { - Mapping mapping = mappingMap.get(slcp); - mappingMap.remove(slcp); - portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping, dlcp)); - } else { - LOG.error("Error in connection-map analysis"); + if (slcp == null) { + LOG.error("Error in connection-map analysis for source {} and destination (circuitpack+port) {}", + skey, dkey); + continue; } + Mapping mapping = mappingMap.get(slcp); + mappingMap.remove(slcp); + portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping, dlcp)); } + if (!mappingMap.isEmpty()) { for (Mapping m : mappingMap.values()) { portMapList.add(m); 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 f0467ae02..a908de054 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 @@ -418,31 +418,33 @@ public class PortMappingVersion221 { } } - if (device.getConnectionMap() != null) { + if (device.getConnectionMap() == null) { + LOG.warn("No connection-map inside device configuration"); + } else { Collection connectionMap = deviceObject.get().nonnullConnectionMap().values(); - String slcp = null; - String dlcp = null; for (ConnectionMap cm : connectionMap) { + String slcp = null; + String dlcp = null; String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName(); if (lcpMap.containsKey(skey)) { slcp = lcpMap.get(skey); } Destination destination0 = cm.nonnullDestination().values().iterator().next(); String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName(); + if (slcp == null) { + LOG.error("Error in connection-map analysis for source {} and destination (circuitpack+port) {}", + skey, dkey); + continue; + } if (lcpMap.containsKey(dkey)) { dlcp = lcpMap.get(dkey); } - if (slcp != null) { - Mapping mapping = mappingMap.get(slcp); - mappingMap.remove(slcp); - portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping, dlcp, null)); - } else { - LOG.error("Error in connection-map analysis"); - } + Mapping mapping = mappingMap.get(slcp); + mappingMap.remove(slcp); + portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping, dlcp, null)); } - } else { - LOG.warn("No connection-map inside device configuration"); } + if (device.getOduSwitchingPools() != null) { Collection oduSwithcingPools = device.nonnullOduSwitchingPools().values(); List switchingPoolList = new ArrayList<>(); 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 6cdfb8358..9eb0cf9f6 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 @@ -417,31 +417,33 @@ public class PortMappingVersion710 { } } - if (device.getConnectionMap() != null) { + if (device.getConnectionMap() == null) { + LOG.warn("No connection-map inside device configuration"); + } else { Collection connectionMap = deviceObject.get().nonnullConnectionMap().values(); - String slcp = null; - String dlcp = null; for (ConnectionMap cm : connectionMap) { + String slcp = null; + String dlcp = null; String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName(); if (lcpMap.containsKey(skey)) { slcp = lcpMap.get(skey); } Destination destination0 = cm.nonnullDestination().values().iterator().next(); String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName(); + if (slcp == null) { + LOG.error("Error in connection-map analysis for source {} and destination (circuitpack+port) {}", + skey, dkey); + continue; + } if (lcpMap.containsKey(dkey)) { dlcp = lcpMap.get(dkey); } - if (slcp != null) { - Mapping mapping = mappingMap.get(slcp); - mappingMap.remove(slcp); - portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping, dlcp, null)); - } else { - LOG.error("Error in connection-map analysis"); - } + Mapping mapping = mappingMap.get(slcp); + mappingMap.remove(slcp); + portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping, dlcp, null)); } - } else { - LOG.warn("No connection-map inside device configuration"); } + if (device.getOduSwitchingPools() != null) { Collection oduSwithcingPools = device.nonnullOduSwitchingPools().values(); List switchingPoolList = new ArrayList<>(); -- 2.36.6