Add protection in portmapping connection-map loop 88/93788/4
authorBalagangadhar Bathula <bb4341@att.com>
Wed, 11 Nov 2020 20:02:06 +0000 (15:02 -0500)
committerguillaume.lambert <guillaume.lambert@orange.com>
Thu, 26 Nov 2020 13:23:06 +0000 (14:23 +0100)
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/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 f96f5125a30f257e5a172a2fe1a79bfef1a73968..70e9e98d97ec0597cb71d3db8dec45af86b2a3f6 100644 (file)
@@ -291,10 +291,11 @@ public class PortMappingVersion121 {
                 }
             }
         }
+
         Collection<ConnectionMap> 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);
index f0467ae02f89162ecfadfac0528f02c0cf369c49..a908de054ae60bb514c866f344ae9111a6924d8e 100644 (file)
@@ -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> 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<OduSwitchingPools> oduSwithcingPools = device.nonnullOduSwitchingPools().values();
             List<SwitchingPoolLcp> switchingPoolList = new ArrayList<>();
index 6cdfb83581c77716031ac5f6155c9a67b7640da1..9eb0cf9f6048c41db228e857129f8638794782d1 100644 (file)
@@ -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> 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<OduSwitchingPools> oduSwithcingPools = device.nonnullOduSwitchingPools().values();
             List<SwitchingPoolLcp> switchingPoolList = new ArrayList<>();