Merge changes Ic48b0970,Id372a645
authorGuillaume Lambert <guillaume.lambert@orange.com>
Mon, 18 Oct 2021 09:35:37 +0000 (09:35 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 18 Oct 2021 09:35:37 +0000 (09:35 +0000)
* changes:
  Add a feature to start swagger
  Remove OpenROADM ospf YANG model rev 2020-05-29

22 files changed:
common/src/main/java/org/opendaylight/transportpce/common/crossconnect/CrossConnectImpl221.java
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMapping.java
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingImpl.java
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
inventory/src/main/java/org/opendaylight/transportpce/inventory/INode.java
inventory/src/main/java/org/opendaylight/transportpce/inventory/INode121.java
inventory/src/main/java/org/opendaylight/transportpce/inventory/INode221.java
nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/serialization/NotificationAlarmServiceSerializer.java
nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/serialization/NotificationServiceSerializer.java
nbinotifications/src/main/java/org/opendaylight/transportpce/nbinotifications/utils/NbiNotificationsUtils.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListener.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/service/NetworkModelService.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/service/NetworkModelServiceImpl.java
networkmodel/src/test/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListenerTest.java
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyResult.java
renderer/src/main/java/org/opendaylight/transportpce/renderer/openroadminterface/OpenRoadmInterface710.java
tapi/src/main/java/org/opendaylight/transportpce/tapi/utils/TapiContext.java
tests/dockercmd.sh [new file with mode: 0755]
tests/nbinotifications/docker-compose.yml [deleted file]
tox.ini

index b3b9643c1c1e3157f9cf0d0ffb1fac2e7abc64ed..f22c3eb9420979cd3b8549f5aa813fab4869c1d2 100644 (file)
@@ -50,6 +50,8 @@ import org.slf4j.LoggerFactory;
 public class CrossConnectImpl221 {
 
     private static final Logger LOG = LoggerFactory.getLogger(CrossConnectImpl221.class);
+    private static final String DEV_TRANSACTION_NOT_FOUND = "Device transaction for device {} was not found!";
+    private static final String UNABLE_DEV_TRANSACTION = "Unable to obtain device transaction for device {}!";
     private final DeviceTransactionManager deviceTransactionManager;
 
     public CrossConnectImpl221(DeviceTransactionManager deviceTransactionManager) {
@@ -95,11 +97,11 @@ public class CrossConnectImpl221 {
             if (deviceTxOpt.isPresent()) {
                 deviceTx = deviceTxOpt.get();
             } else {
-                LOG.error("Device transaction for device {} was not found!", deviceId);
+                LOG.error(DEV_TRANSACTION_NOT_FOUND, deviceId);
                 return Optional.empty();
             }
         } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Unable to obtain device transaction for device {}!", deviceId, e);
+            LOG.error(UNABLE_DEV_TRANSACTION, deviceId, e);
             return Optional.empty();
         }
 
@@ -145,11 +147,11 @@ public class CrossConnectImpl221 {
             if (deviceTxOpt.isPresent()) {
                 deviceTx = deviceTxOpt.get();
             } else {
-                LOG.error("Device transaction for device {} was not found!", deviceId);
+                LOG.error(DEV_TRANSACTION_NOT_FOUND, deviceId);
                 return null;
             }
         } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Unable to obtain device transaction for device {}!", deviceId, e);
+            LOG.error(UNABLE_DEV_TRANSACTION, deviceId, e);
             return null;
         }
 
@@ -309,11 +311,11 @@ public class CrossConnectImpl221 {
             if (deviceTxOpt.isPresent()) {
                 deviceTx = deviceTxOpt.get();
             } else {
-                LOG.error("Device transaction for device {} was not found!", deviceId);
+                LOG.error(DEV_TRANSACTION_NOT_FOUND, deviceId);
                 return Optional.empty();
             }
         } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Unable to obtain device transaction for device {}!", deviceId, e);
+            LOG.error(UNABLE_DEV_TRANSACTION, deviceId, e);
             return Optional.empty();
         }
 
index 8b04bd5ca2cbd82aefc9fb16cc18fa8995b56065..fc7090c853b7bbb55156f25d8a47a9dad8fc871b 100644 (file)
@@ -180,4 +180,16 @@ public interface PortMapping {
      */
     boolean updatePortMappingWithOduSwitchingPools(String nodeId, InstanceIdentifier<OduSwitchingPools> ospIID,
         Map<Uint16, List<InstanceIdentifier<PortList>>> nbliidMap);
+
+    /**
+     * This method check the presence or not of a given node inside the PortMapping
+     * datastore.
+     *
+     * @param nodeId
+     *            Unique Identifier for the node of interest.
+     *
+     * @return Result true/false based on existance or not of a given node.
+     */
+    boolean isNodeExist(String nodeId);
+
 }
index 13d52cf707d298322ad9e75681373fb5ee79d504..d92ec0e853ec867c44aff26bbf37823c582e6ad1 100644 (file)
@@ -204,4 +204,9 @@ public class PortMappingImpl implements PortMapping {
                 return false;
         }
     }
+
+    @Override
+    public boolean isNodeExist(String nodeId) {
+        return this.getNode(nodeId) != null;
+    }
 }
index 7994c4bd80d1c9798e2d9ec69bd0502921131f67..9862ec9ad978533bf1ae55a9cc24e9323387acd0 100644 (file)
@@ -323,41 +323,13 @@ public class PortMappingVersion121 {
                             break;
                         case Rx:
                         case Tx:
-                            if (!checkPartnerPortNotNull(port)) {
-                                LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG
-                                        + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
-                                    nodeId, port.getPortName(), circuitPackName);
+                            Ports port2 = getPartnerPort(port, circuitPackName, nodeId);
+                            if (port2 == null) {
                                 continue;
                             }
                             String lcp1 = createLogicalConnectionPort(port, srgCpEntry.getKey(), portIndex);
                             LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
-                                    nodeId, port.getPortName(), circuitPackName, lcp1);
-                            InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                                .child(CircuitPacks.class,
-                                    new CircuitPacksKey(port.getPartnerPort().getCircuitPackName()))
-                                .child(Ports.class, new PortsKey(port.getPartnerPort().getPortName()));
-                            Optional<Ports> port2Object = this.deviceTransactionManager
-                                .getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, port2ID,
-                                    Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                            if (port2Object.isEmpty()
-                                || port2Object.get().getPortQual().getIntValue()
-                                    != Port.PortQual.RoadmExternal.getIntValue()) {
-                                LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG
-                                        + PortMappingUtils.PARTNERPORT_GET_ERROR_LOGMSG,
-                                    nodeId, port.getPartnerPort().getPortName(),
-                                    port.getPartnerPort().getCircuitPackName(),
-                                    port.getPortName(), circuitPackName);
-                                continue;
-                            }
-                            Ports port2 = port2Object.get();
-                            if (!checkPartnerPort(circuitPackName, port, port2)) {
-                                LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG
-                                        + PortMappingUtils.PARTNERPORT_CONF_ERROR_LOGMSG,
-                                    nodeId, port2.getPortName(), port.getPartnerPort().getCircuitPackName(),
-                                    port.getPortName(), circuitPackName);
-                                portIndex++;
-                                continue;
-                            }
+                                nodeId, port.getPortName(), circuitPackName, lcp1);
                             String lcp2 = createLogicalConnectionPort(port2, srgCpEntry.getKey(),portIndex);
                             LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
                                 nodeId, port2.getPortName(), circuitPackName, lcp2);
@@ -378,6 +350,38 @@ public class PortMappingVersion121 {
         return true;
     }
 
+    private Ports getPartnerPort(Ports port, String circuitPackName, String nodeId) {
+        if (!checkPartnerPortNotNull(port)) {
+            LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
+                nodeId, port.getPortName(), circuitPackName);
+            return null;
+        }
+        InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+            .child(CircuitPacks.class, new CircuitPacksKey(port.getPartnerPort().getCircuitPackName()))
+            .child(Ports.class, new PortsKey(port.getPartnerPort().getPortName()));
+        Optional<Ports> port2Object = this.deviceTransactionManager
+            .getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, port2ID,
+                Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (port2Object.isEmpty()
+                || port2Object.get().getPortQual().getIntValue() != Port.PortQual.RoadmExternal.getIntValue()) {
+            LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG + PortMappingUtils.PARTNERPORT_GET_ERROR_LOGMSG,
+                nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName(),
+                port.getPortName(), circuitPackName);
+            return null;
+        }
+        Ports port2 = port2Object.get();
+        if (!checkPartnerPort(circuitPackName, port, port2)) {
+            LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG + PortMappingUtils.PARTNERPORT_CONF_ERROR_LOGMSG,
+                nodeId, port2.getPortName(), port.getPartnerPort().getCircuitPackName(),
+                port.getPortName(), circuitPackName);
+            //portIndex++;
+            //TODO check if we really needed to increase portIndex
+            //     if yes this block should not be in getPartnerPort
+            return null;
+        }
+        return port2;
+    }
+
     private List<Ports> getPortList(String circuitPackName, String nodeId) {
         InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
             .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName));
@@ -801,22 +805,13 @@ public class PortMappingVersion121 {
             switch (cpMapValue.size()) {
                 case 1:
                     // port is bidirectional
-                    InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                        .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
-                        .child(Ports.class, new PortsKey(cp1.getPortName()));
-                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
-                    Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
-                        LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
-                        Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                    if (portObject.isEmpty()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
+                    Ports port = getTtpPort(cp1, cp1Name, nodeId);
+                    if (port == null) {
                         return false;
                     }
-                    Ports port = portObject.get();
                     if (!checkTtpPort(port, cp1Name, nodeId, true)) {
                         continue;
                     }
-
                     String logicalConnectionPoint =
                             PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(), "TXRX");
                     LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
@@ -825,52 +820,19 @@ public class PortMappingVersion121 {
                     break;
                 case 2:
                     // ports are unidirectionals
-                    ConnectionPorts cp2 = cpMapValue.get(1);
-                    String cp2Name = cp2.getCircuitPackName();
-                    InstanceIdentifier<Ports> port1ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                        .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
-                        .child(Ports.class, new PortsKey(cp1.getPortName()));
-                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
-                    Optional<Ports> port1Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
-                        LogicalDatastoreType.OPERATIONAL, port1ID, Timeouts.DEVICE_READ_TIMEOUT,
-                        Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                    InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                        .child(CircuitPacks.class, new CircuitPacksKey(cp2Name))
-                        .child(Ports.class, new PortsKey(cp2.getPortName()));
-                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp2.getPortName(), cp2Name);
-                    Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
-                        LogicalDatastoreType.OPERATIONAL, port2ID, Timeouts.DEVICE_READ_TIMEOUT,
-                        Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                    if (port1Object.isEmpty()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
+                    Ports port1 = getTtpPort(cp1, cp1Name, nodeId);
+                    if (port1 == null) {
                         return false;
                     }
-                    if (port2Object.isEmpty()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp2.getPortName(), cp2Name);
+                    ConnectionPorts cp2 = cpMapValue.get(1);
+                    String cp2Name = cp2.getCircuitPackName();
+                    Ports port2 = getTtpPort(cp2, cp2Name, nodeId);
+                    if (port2 == null) {
                         return false;
                     }
-
-                    Ports port1 = port1Object.get();
-                    if (!checkTtpPort(port1, cp1Name, nodeId, false)) {
-                        continue;
-                    }
-                    Ports port2 = port2Object.get();
-                    if (!checkTtpPort(port2, cp2Name, nodeId, false)) {
+                    if (!checkTtpPortsUnidir(port1, port2, cp1Name, cp2Name, nodeId)) {
                         continue;
                     }
-
-                    if (!checkPartnerPort(cp1Name, port1, port2)) {
-                        LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
-                            nodeId, port2.getPortName(), cp2Name, port1.getPortName(), cp1Name);
-                        continue;
-                    }
-                    // Directions checks are the same for cp1 and cp2, no need to check them twice.
-                    if (!checkPartnerPortNoDir(cp2Name, port2, port1)) {
-                        LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
-                            nodeId, port1.getPortName(), cp1Name, port2.getPortName(), cp2Name);
-                        continue;
-                    }
-
                     String logicalConnectionPoint1 = PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(),
                             port1.getPortDirection().getName().toUpperCase(Locale.getDefault()));
                     LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
@@ -885,11 +847,27 @@ public class PortMappingVersion121 {
                 default:
                     LOG.error(PortMappingUtils.NOT_CORRECT_CONPORT_LOGMSG, nodeId, cpMapEntry.getKey());
                     continue;
+                    //TODO should it be continue or return false ?
             }
         }
         return true;
     }
 
+    private Ports getTtpPort(ConnectionPorts cp, String cpName, String nodeId) {
+        InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+            .child(CircuitPacks.class, new CircuitPacksKey(cpName))
+            .child(Ports.class, new PortsKey(cp.getPortName()));
+        LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp.getPortName(), cpName);
+        Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
+            LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
+            Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (portObject.isEmpty()) {
+            LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp.getPortName(), cpName);
+            return null;
+        }
+        return portObject.get();
+    }
+
     private boolean checkPortQual(Ports port, String cpName, String nodeId) {
         if (port.getPortQual() == null) {
             return false;
@@ -916,14 +894,33 @@ public class PortMappingVersion121 {
         return true;
     }
 
-    private NodeInfo createNodeInfo(Info deviceInfo) {
+    private boolean checkTtpPortsUnidir(Ports port1, Ports port2, String cp1Name, String cp2Name, String nodeId) {
+        if (!checkTtpPort(port1, cp1Name, nodeId, false)) {
+            return false;
+        }
+        if (!checkTtpPort(port2, cp2Name, nodeId, false)) {
+            return false;
+        }
+        if (!checkPartnerPort(cp1Name, port1, port2)) {
+            LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
+                nodeId, port2.getPortName(), cp2Name, port1.getPortName(), cp1Name);
+            return false;
+        }
+        // Directions checks are the same for cp1 and cp2, no need to check them twice.
+        if (!checkPartnerPortNoDir(cp2Name, port2, port1)) {
+            LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
+                nodeId, port1.getPortName(), cp1Name, port2.getPortName(), cp2Name);
+            return false;
+        }
+        return true;
+    }
 
+    private NodeInfo createNodeInfo(Info deviceInfo) {
         if (deviceInfo.getNodeType() == null) {
             // TODO make mandatory in yang
             LOG.error(PortMappingUtils.NODE_TYPE_LOGMSG, deviceInfo.getNodeId(), "field missing");
             return null;
         }
-
         NodeInfoBuilder nodeInfoBldr = new NodeInfoBuilder()
                 .setOpenroadmVersion(OpenroadmNodeVersion._121)
                 .setNodeClli(
@@ -949,7 +946,6 @@ public class PortMappingVersion121 {
         if (deviceInfo.getIpAddress() != null) {
             nodeInfoBldr.setNodeIpAddress(deviceInfo.getIpAddress());
         }
-
         return nodeInfoBldr.build();
     }
 
index 595af60fa2e4f56e17bb62bf43264e37e8a1134c..b56c59045d771ef99616062a7294a5290c69ad33 100644 (file)
@@ -214,22 +214,92 @@ public class PortMappingVersion221 {
 
     private boolean createXpdrPortMapping(String nodeId, List<Mapping> portMapList) {
         // Creating for Xponder Line and Client Ports
+        OrgOpenroadmDevice device = getXpdrDevice(nodeId);
+        if (device == null) {
+            return false;
+        }
+        Map<String, String> lcpMap = new HashMap<>();
+        Map<String, Mapping> mappingMap = new HashMap<>();
+        getXpdrMaps(device, nodeId, lcpMap, mappingMap);
+        if (device.getConnectionMap() == null) {
+            LOG.warn(PortMappingUtils.NO_CONMAP_LOGMSG, nodeId);
+        } else {
+            for (ConnectionMap cm : device.nonnullConnectionMap().values()) {
+                String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
+                Destination destination0 = cm.nonnullDestination().values().iterator().next();
+                String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName();
+                if (!lcpMap.containsKey(skey)) {
+                    LOG.error(PortMappingUtils.CONMAP_ISSUE_LOGMSG, nodeId, skey, dkey);
+                    continue;
+                }
+                String slcp = lcpMap.get(skey);
+                Mapping mapping = mappingMap.get(slcp);
+                mappingMap.remove(slcp);
+                portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping,
+                        //dlcp
+                        lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null,
+                        null));
+            }
+        }
+        if (device.getOduSwitchingPools() != null) {
+            List<SwitchingPoolLcp> switchingPoolList = new ArrayList<>();
+            for (OduSwitchingPools odp : device.nonnullOduSwitchingPools().values()) {
+                Map<NonBlockingListKey,NonBlockingList> nbMap = new HashMap<>();
+                for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org
+                    .openroadm.device.odu.switching.pools.NonBlockingList nbl : odp.nonnullNonBlockingList().values()) {
+                    if (nbl.getPortList() == null) {
+                        continue;
+                    }
+                    List<String> lcpList = new ArrayList<>();
+                    for (PortList item : nbl.nonnullPortList().values()) {
+                        String key = item.getCircuitPackName() + "+" + item.getPortName();
+                        if (!lcpMap.containsKey(key)) {
+                            LOG.error(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG,
+                                nodeId, item.getPortName(), item.getCircuitPackName(), "to a logical connection point");
+                            continue;
+                        }
+                        lcpList.add(lcpMap.get(key));
+                    }
+                    NonBlockingList nonBlockingList = new NonBlockingListBuilder()
+                        .setNblNumber(nbl.getNblNumber())
+                        .setInterconnectBandwidth(nbl.getInterconnectBandwidth())
+                        .setInterconnectBandwidthUnit(nbl.getInterconnectBandwidthUnit())
+                        .setLcpList(lcpList)
+                        .build();
+                    nbMap.put(nonBlockingList.key(), nonBlockingList);
+                }
+                switchingPoolList.add(
+                    new SwitchingPoolLcpBuilder()
+                        .setSwitchingPoolNumber(odp.getSwitchingPoolNumber())
+                        .setSwitchingPoolType(SwitchingPoolTypes.forValue(odp.getSwitchingPoolType().getIntValue()))
+                        .setNonBlockingList(nbMap)
+                        .build());
+            }
+            postPortMapping(nodeId, null, null, null, switchingPoolList, null);
+        }
+        mappingMap.forEach((k,v) -> portMapList.add(v));
+        return true;
+    }
+
+    private OrgOpenroadmDevice getXpdrDevice(String nodeId) {
         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
         Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
             LogicalDatastoreType.OPERATIONAL, deviceIID,
             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
         if (deviceObject.isEmpty()) {
             LOG.error(PortMappingUtils.CANNOT_GET_DEV_CONF_LOGMSG, nodeId);
-            return false;
+            return null;
         }
         OrgOpenroadmDevice device = deviceObject.get();
         if (device.getCircuitPacks() == null) {
             LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, PortMappingUtils.FOUND);
-            return false;
+            return null;
         }
+        return device;
+    }
 
-        Map<String, String> lcpMap = new HashMap<>();
-        Map<String, Mapping> mappingMap = new HashMap<>();
+    private void getXpdrMaps(OrgOpenroadmDevice device, String nodeId,
+            Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
         List<CircuitPacks> circuitPackList = new ArrayList<>(device.nonnullCircuitPacks().values());
         circuitPackList.sort(Comparator.comparing(CircuitPack::getCircuitPackName));
         if (device.getXponder() == null) {
@@ -257,7 +327,7 @@ public class PortMappingVersion221 {
             }
         } else {
             LOG.info(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, PortMappingUtils.FOUND);
-            for (Xponder xponder : deviceObject.get().nonnullXponder().values()) {
+            for (Xponder xponder : device.nonnullXponder().values()) {
                 // Variables to keep track of number of line ports and client ports
                 int line = 1;
                 int client = 1;
@@ -265,93 +335,40 @@ public class PortMappingVersion221 {
                 XpdrNodeTypes xponderType = xponder.getXpdrType();
                 for (XpdrPort xpdrPort : xponder.nonnullXpdrPort().values().stream()
                         .sorted((xp1, xp2) -> xp1.getIndex().compareTo(xp2.getIndex())).collect(Collectors.toList())) {
-                    String circuitPackName = xpdrPort.getCircuitPackName();
-                    String portName = xpdrPort.getPortName();
-                    // If there xponder-subtree has missing circuit-packs or ports,
-                    // This gives a null-pointer expection,
-                    Optional<CircuitPacks> cpList = device.nonnullCircuitPacks().values().stream()
-                            .filter(cp -> cp.getCircuitPackName().equals(circuitPackName)).findFirst();
-                    if (cpList.isEmpty()) {
-                        LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
-                            nodeId, circuitPackName);
-                        continue;
-                    }
-                    Optional<Ports> portsList = cpList.get().nonnullPorts().values().stream()
-                            .filter(p -> p.getPortName().equals(portName)).findFirst();
-                    if (portsList.isEmpty()) {
-                        LOG.warn(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
-                            nodeId, portName, circuitPackName, "in the device");
+                    Ports port = getXpdrPorts(device, xpdrPort, nodeId);
+                    if (port == null) {
                         continue;
                     }
                     int[] counters = fillXpdrLcpsMaps(line, client, nodeId,
-                        xponderNb, xponderType, circuitPackName, portsList.get(),
+                        xponderNb, xponderType, xpdrPort.getCircuitPackName(), port,
                         circuitPackList, lcpMap, mappingMap);
                     line = counters[0];
                     client = counters[1];
                 }
             }
         }
+    }
 
-        if (device.getConnectionMap() == null) {
-            LOG.warn(PortMappingUtils.NO_CONMAP_LOGMSG, nodeId);
-        } else {
-            for (ConnectionMap cm : deviceObject.get().nonnullConnectionMap().values()) {
-                String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
-                Destination destination0 = cm.nonnullDestination().values().iterator().next();
-                String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName();
-                if (!lcpMap.containsKey(skey)) {
-                    LOG.error(PortMappingUtils.CONMAP_ISSUE_LOGMSG, nodeId, skey, dkey);
-                    continue;
-                }
-                String slcp = lcpMap.get(skey);
-                Mapping mapping = mappingMap.get(slcp);
-                mappingMap.remove(slcp);
-                portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping,
-                        //dlcp
-                        lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null,
-                        null));
-            }
+    private Ports getXpdrPorts(OrgOpenroadmDevice device, XpdrPort xpdrPort, String nodeId) {
+        String circuitPackName = xpdrPort.getCircuitPackName();
+        String portName = xpdrPort.getPortName();
+        // If there xponder-subtree has missing circuit-packs or ports,
+        // This gives a null-pointer expection,
+        Optional<CircuitPacks> cpList = device.nonnullCircuitPacks().values().stream()
+                .filter(cp -> cp.getCircuitPackName().equals(circuitPackName)).findFirst();
+        if (cpList.isEmpty()) {
+            LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
+                nodeId, circuitPackName);
+            return null;
         }
-
-        if (device.getOduSwitchingPools() != null) {
-            List<SwitchingPoolLcp> switchingPoolList = new ArrayList<>();
-            for (OduSwitchingPools odp : device.nonnullOduSwitchingPools().values()) {
-                Map<NonBlockingListKey,NonBlockingList> nbMap = new HashMap<>();
-                for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org
-                    .openroadm.device.odu.switching.pools.NonBlockingList nbl : odp.nonnullNonBlockingList().values()) {
-                    if (nbl.getPortList() == null) {
-                        continue;
-                    }
-                    List<String> lcpList = new ArrayList<>();
-                    for (PortList item : nbl.nonnullPortList().values()) {
-                        String key = item.getCircuitPackName() + "+" + item.getPortName();
-                        if (!lcpMap.containsKey(key)) {
-                            LOG.error(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG,
-                                nodeId, item.getPortName(), item.getCircuitPackName(), "to a logical connection point");
-                            continue;
-                        }
-                        lcpList.add(lcpMap.get(key));
-                    }
-                    NonBlockingList nonBlockingList = new NonBlockingListBuilder()
-                        .setNblNumber(nbl.getNblNumber())
-                        .setInterconnectBandwidth(nbl.getInterconnectBandwidth())
-                        .setInterconnectBandwidthUnit(nbl.getInterconnectBandwidthUnit())
-                        .setLcpList(lcpList)
-                        .build();
-                    nbMap.put(nonBlockingList.key(), nonBlockingList);
-                }
-                SwitchingPoolLcp splBldr = new SwitchingPoolLcpBuilder()
-                    .setSwitchingPoolNumber(odp.getSwitchingPoolNumber())
-                    .setSwitchingPoolType(SwitchingPoolTypes.forValue(odp.getSwitchingPoolType().getIntValue()))
-                    .setNonBlockingList(nbMap)
-                    .build();
-                switchingPoolList.add(splBldr);
-            }
-            postPortMapping(nodeId, null, null, null, switchingPoolList, null);
+        Optional<Ports> portsList = cpList.get().nonnullPorts().values().stream()
+                .filter(p -> p.getPortName().equals(portName)).findFirst();
+        if (portsList.isEmpty()) {
+            LOG.warn(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
+                nodeId, portName, circuitPackName, "in the device");
+            return null;
         }
-
-        mappingMap.forEach((k,v) -> portMapList.add(v));
-        return true;
+        return portsList.get();
     }
 
     private boolean checkPartnerPortNotNull(Ports port) {
@@ -430,41 +447,13 @@ public class PortMappingVersion221 {
                             break;
                         case Rx:
                         case Tx:
-                            if (!checkPartnerPortNotNull(port)) {
-                                LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG
-                                        + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
-                                    nodeId, port.getPortName(), circuitPackName);
+                            Ports port2 = getPartnerPort(port, circuitPackName, nodeId);
+                            if (port2 == null) {
                                 continue;
                             }
                             String lcp1 = createLogicalConnectionPort(port, srgCpEntry.getKey(), portIndex);
                             LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
                                 nodeId, port.getPortName(), circuitPackName, lcp1);
-                            InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                                .child(CircuitPacks.class,
-                                    new CircuitPacksKey(port.getPartnerPort().getCircuitPackName()))
-                                .child(Ports.class, new PortsKey(port.getPartnerPort().getPortName()));
-                            Optional<Ports> port2Object = this.deviceTransactionManager
-                                .getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, port2ID,
-                                    Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                            if (port2Object.isEmpty()
-                                || port2Object.get().getPortQual().getIntValue()
-                                    != PortQual.RoadmExternal.getIntValue()) {
-                                LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG
-                                        + PortMappingUtils.PARTNERPORT_GET_ERROR_LOGMSG,
-                                    nodeId, port.getPartnerPort().getPortName(),
-                                    port.getPartnerPort().getCircuitPackName(),
-                                    port.getPortName(), circuitPackName);
-                                continue;
-                            }
-                            Ports port2 = port2Object.get();
-                            if (!checkPartnerPort(circuitPackName, port, port2)) {
-                                LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG
-                                        + PortMappingUtils.PARTNERPORT_CONF_ERROR_LOGMSG,
-                                    nodeId, port2.getPortName(), port.getPartnerPort().getCircuitPackName(),
-                                    port.getPortName(), circuitPackName);
-                                portIndex++;
-                                continue;
-                            }
                             String lcp2 = createLogicalConnectionPort(port2, srgCpEntry.getKey(),portIndex);
                             LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
                                     nodeId, port2.getPortName(), circuitPackName, lcp2);
@@ -485,6 +474,38 @@ public class PortMappingVersion221 {
         return true;
     }
 
+    private Ports getPartnerPort(Ports port, String circuitPackName, String nodeId) {
+        if (!checkPartnerPortNotNull(port)) {
+            LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
+                nodeId, port.getPortName(), circuitPackName);
+            return null;
+        }
+        InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+            .child(CircuitPacks.class, new CircuitPacksKey(port.getPartnerPort().getCircuitPackName()))
+            .child(Ports.class, new PortsKey(port.getPartnerPort().getPortName()));
+        Optional<Ports> port2Object = this.deviceTransactionManager
+            .getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, port2ID,
+                Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (port2Object.isEmpty()
+                || port2Object.get().getPortQual().getIntValue() != PortQual.RoadmExternal.getIntValue()) {
+            LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG + PortMappingUtils.PARTNERPORT_GET_ERROR_LOGMSG,
+                nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName(),
+                port.getPortName(), circuitPackName);
+            return null;
+        }
+        Ports port2 = port2Object.get();
+        if (!checkPartnerPort(circuitPackName, port, port2)) {
+            LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG + PortMappingUtils.PARTNERPORT_CONF_ERROR_LOGMSG,
+                nodeId, port2.getPortName(), port.getPartnerPort().getCircuitPackName(),
+                port.getPortName(), circuitPackName);
+            //portIndex++;
+            //TODO check if we really needed to increase portIndex
+            //     if yes this block should not be in getPartnerPort
+            return null;
+        }
+        return port2;
+    }
+
     private List<Ports> getPortList(String circuitPackName, String nodeId) {
         InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
             .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName));
@@ -1020,22 +1041,13 @@ public class PortMappingVersion221 {
             switch (cpMapValue.size()) {
                 case 1:
                     // port is bidirectional
-                    InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                        .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
-                        .child(Ports.class, new PortsKey(cp1.getPortName()));
-                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
-                    Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
-                        LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
-                        Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                    if (portObject.isEmpty()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
+                    Ports port = getTtpPort(cp1, cp1Name, nodeId);
+                    if (port == null) {
                         return false;
                     }
-                    Ports port = portObject.get();
                     if (!checkTtpPort(port, cp1Name, nodeId, true)) {
                         continue;
                     }
-
                     String logicalConnectionPoint =
                             PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(), "TXRX");
                     LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
@@ -1044,52 +1056,19 @@ public class PortMappingVersion221 {
                     break;
                 case 2:
                     // ports are unidirectionals
-                    ConnectionPorts cp2 = cpMapValue.get(1);
-                    String cp2Name = cp2.getCircuitPackName();
-                    InstanceIdentifier<Ports> port1ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                        .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
-                        .child(Ports.class, new PortsKey(cp1.getPortName()));
-                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
-                    Optional<Ports> port1Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
-                        LogicalDatastoreType.OPERATIONAL, port1ID, Timeouts.DEVICE_READ_TIMEOUT,
-                        Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                    InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                        .child(CircuitPacks.class, new CircuitPacksKey(cp2Name))
-                        .child(Ports.class, new PortsKey(cp2.getPortName()));
-                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp2.getPortName(), cp2Name);
-                    Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
-                        LogicalDatastoreType.OPERATIONAL, port2ID, Timeouts.DEVICE_READ_TIMEOUT,
-                        Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                    if (port1Object.isEmpty()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
+                    Ports port1 = getTtpPort(cp1, cp1Name, nodeId);
+                    if (port1 == null) {
                         return false;
                     }
-                    if (port2Object.isEmpty()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp2.getPortName(), cp2Name);
+                    ConnectionPorts cp2 = cpMapValue.get(1);
+                    String cp2Name = cp2.getCircuitPackName();
+                    Ports port2 = getTtpPort(cp2, cp2Name, nodeId);
+                    if (port2 == null) {
                         return false;
                     }
-
-                    Ports port1 = port1Object.get();
-                    if (!checkTtpPort(port1, cp1Name, nodeId, false)) {
-                        continue;
-                    }
-                    Ports port2 = port2Object.get();
-                    if (!checkTtpPort(port2, cp2Name, nodeId, false)) {
+                    if (!checkTtpPortsUnidir(port1, port2, cp1Name, cp2Name, nodeId)) {
                         continue;
                     }
-
-                    if (!checkPartnerPort(cp1Name, port1, port2)) {
-                        LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
-                            nodeId, port2.getPortName(), cp2Name, port1.getPortName(), cp1Name);
-                        continue;
-                    }
-                    // Directions checks are the same for cp1 and cp2, no need to check them twice.
-                    if (!checkPartnerPortNoDir(cp2Name, port2, port1)) {
-                        LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
-                            nodeId, port1.getPortName(), cp1Name, port2.getPortName(), cp2Name);
-                        continue;
-                    }
-
                     String logicalConnectionPoint1 = PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(),
                             port1.getPortDirection().getName().toUpperCase(Locale.getDefault()));
                     LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
@@ -1104,11 +1083,27 @@ public class PortMappingVersion221 {
                 default:
                     LOG.error(PortMappingUtils.NOT_CORRECT_CONPORT_LOGMSG, nodeId, cpMapEntry.getKey());
                     continue;
+                    //TODO should it be continue or return false ?
             }
         }
         return true;
     }
 
+    private Ports getTtpPort(ConnectionPorts cp, String cpName, String nodeId) {
+        InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+            .child(CircuitPacks.class, new CircuitPacksKey(cpName))
+            .child(Ports.class, new PortsKey(cp.getPortName()));
+        LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp.getPortName(), cpName);
+        Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
+            LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
+            Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (portObject.isEmpty()) {
+            LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp.getPortName(), cpName);
+            return null;
+        }
+        return portObject.get();
+    }
+
     private boolean checkPortQual(Ports port, String cpName, String nodeId) {
         if (port.getPortQual() == null) {
             return false;
@@ -1135,14 +1130,33 @@ public class PortMappingVersion221 {
         return true;
     }
 
-    private NodeInfo createNodeInfo(Info deviceInfo) {
+    private boolean checkTtpPortsUnidir(Ports port1, Ports port2, String cp1Name, String cp2Name, String nodeId) {
+        if (!checkTtpPort(port1, cp1Name, nodeId, false)) {
+            return false;
+        }
+        if (!checkTtpPort(port2, cp2Name, nodeId, false)) {
+            return false;
+        }
+        if (!checkPartnerPort(cp1Name, port1, port2)) {
+            LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
+                nodeId, port2.getPortName(), cp2Name, port1.getPortName(), cp1Name);
+            return false;
+        }
+        // Directions checks are the same for cp1 and cp2, no need to check them twice.
+        if (!checkPartnerPortNoDir(cp2Name, port2, port1)) {
+            LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
+                nodeId, port1.getPortName(), cp1Name, port2.getPortName(), cp2Name);
+            return false;
+        }
+        return true;
+    }
 
+    private NodeInfo createNodeInfo(Info deviceInfo) {
         if (deviceInfo.getNodeType() == null) {
             // TODO make mandatory in yang
             LOG.error(PortMappingUtils.NODE_TYPE_LOGMSG, deviceInfo.getNodeId(), "field missing");
             return null;
         }
-
         NodeInfoBuilder nodeInfoBldr = new NodeInfoBuilder()
                 .setOpenroadmVersion(OpenroadmNodeVersion._221)
                 .setNodeClli(
@@ -1159,7 +1173,6 @@ public class PortMappingVersion221 {
         if (deviceInfo.getIpAddress() != null) {
             nodeInfoBldr.setNodeIpAddress(deviceInfo.getIpAddress());
         }
-
         return nodeInfoBldr.build();
     }
 
index 7c13bf054dcba3fc0cb35b544d1d0007f40a4a87..121c7514010f367e547b0d8a6b69454615237bf3 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.transportpce.common.mapping;
 
 import com.google.common.util.concurrent.FluentFuture;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -298,22 +299,93 @@ public class PortMappingVersion710 {
 
     private boolean createXpdrPortMapping(String nodeId, List<Mapping> portMapList) {
         // Creating for Xponder Line and Client Ports
+        OrgOpenroadmDevice device = getXpdrDevice(nodeId);
+        if (device == null) {
+            return false;
+        }
+        Map<String, String> lcpMap = new HashMap<>();
+        Map<String, Mapping> mappingMap = new HashMap<>();
+        getXpdrMaps(device, nodeId, lcpMap, mappingMap);
+        if (device.getConnectionMap() == null) {
+            LOG.warn(PortMappingUtils.NO_CONMAP_LOGMSG, nodeId);
+        } else {
+            for (ConnectionMap cm : device.nonnullConnectionMap().values()) {
+                String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
+                Destination destination0 = cm.nonnullDestination().values().iterator().next();
+                String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName();
+                if (!lcpMap.containsKey(skey)) {
+                    LOG.error(PortMappingUtils.CONMAP_ISSUE_LOGMSG, nodeId, skey, dkey);
+                    continue;
+                }
+                String slcp = lcpMap.get(skey);
+                Mapping mapping = mappingMap.get(slcp);
+                mappingMap.remove(slcp);
+                portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping,
+                        //dlcp
+                        lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null,
+                        null));
+            }
+        }
+        if (device.getOduSwitchingPools() != null) {
+            List<SwitchingPoolLcp> switchingPoolList = new ArrayList<>();
+            for (OduSwitchingPools odp : device.nonnullOduSwitchingPools().values()) {
+                Map<NonBlockingListKey,NonBlockingList> nbMap = new HashMap<>();
+                for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org
+                    .openroadm.device.odu.switching.pools.NonBlockingList nbl : odp.nonnullNonBlockingList().values()) {
+                    if (nbl.getPortList() == null) {
+                        continue;
+                    }
+                    List<String> lcpList = new ArrayList<>();
+                    for (PortList item : nbl.nonnullPortList().values()) {
+                        String key = item.getCircuitPackName() + "+" + item.getPortName();
+                        if (!lcpMap.containsKey(key)) {
+                            LOG.error(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG,
+                                nodeId, item.getPortName(), item.getCircuitPackName(), "to a logical connection point");
+                            continue;
+                        }
+                        lcpList.add(lcpMap.get(key));
+                    }
+                    NonBlockingList nonBlockingList = new NonBlockingListBuilder()
+                        .setNblNumber(nbl.getNblNumber())
+                        .setInterconnectBandwidth(nbl.getInterconnectBandwidth())
+                        .setInterconnectBandwidthUnit(nbl.getInterconnectBandwidthUnit())
+                        .setLcpList(lcpList)
+                        .build();
+                    nbMap.put(nonBlockingList.key(), nonBlockingList);
+                }
+                switchingPoolList.add(
+                    new SwitchingPoolLcpBuilder()
+                        .setSwitchingPoolNumber(odp.getSwitchingPoolNumber())
+                        .setSwitchingPoolType(odp.getSwitchingPoolType())
+                        //TODO differs from 2.2.1 SwitchingPoolTypes.forValue(odp.getSwitchingPoolType().getIntValue())
+                        .setNonBlockingList(nbMap)
+                        .build());
+            }
+            postPortMapping(nodeId, null, null, null, switchingPoolList, null);
+        }
+        mappingMap.forEach((k,v) -> portMapList.add(v));
+        return true;
+    }
+
+    private OrgOpenroadmDevice getXpdrDevice(String nodeId) {
         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
         Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
             LogicalDatastoreType.OPERATIONAL, deviceIID,
             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
         if (deviceObject.isEmpty()) {
             LOG.error(PortMappingUtils.CANNOT_GET_DEV_CONF_LOGMSG, nodeId);
-            return false;
+            return null;
         }
         OrgOpenroadmDevice device = deviceObject.get();
         if (device.getCircuitPacks() == null) {
             LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, PortMappingUtils.FOUND);
-            return false;
+            return null;
         }
+        return device;
+    }
 
-        Map<String, String> lcpMap = new HashMap<>();
-        Map<String, Mapping> mappingMap = new HashMap<>();
+    private void getXpdrMaps(OrgOpenroadmDevice device, String nodeId,
+            Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
         List<CircuitPacks> circuitPackList = new ArrayList<>(device.nonnullCircuitPacks().values());
         circuitPackList.sort(Comparator.comparing(CircuitPack::getCircuitPackName));
         if (device.getXponder() == null) {
@@ -341,7 +413,7 @@ public class PortMappingVersion710 {
             }
         } else {
             LOG.info(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, PortMappingUtils.FOUND);
-            for (Xponder xponder : deviceObject.get().nonnullXponder().values()) {
+            for (Xponder xponder : device.nonnullXponder().values()) {
                 // Variables to keep track of number of line ports and client ports
                 int line = 1;
                 int client = 1;
@@ -349,94 +421,40 @@ public class PortMappingVersion710 {
                 XpdrNodeTypes xponderType = xponder.getXpdrType();
                 for (XpdrPort xpdrPort : xponder.nonnullXpdrPort().values().stream()
                         .sorted((xp1, xp2) -> xp1.getIndex().compareTo(xp2.getIndex())).collect(Collectors.toList())) {
-                    String circuitPackName = xpdrPort.getCircuitPackName();
-                    String portName = xpdrPort.getPortName();
-                    // If there xponder-subtree has missing circuit-packs or ports,
-                    // This gives a null-pointer expection,
-                    Optional<CircuitPacks> cpList = device.nonnullCircuitPacks().values().stream()
-                            .filter(cp -> cp.getCircuitPackName().equals(circuitPackName)).findFirst();
-                    if (cpList.isEmpty()) {
-                        LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
-                            nodeId, circuitPackName);
-                        continue;
-                    }
-                    Optional<Ports> portsList = cpList.get().nonnullPorts().values().stream()
-                            .filter(p -> p.getPortName().equals(portName)).findFirst();
-                    if (portsList.isEmpty()) {
-                        LOG.warn(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
-                            nodeId, portName, circuitPackName, "in the device");
+                    Ports port = getXpdrPorts(device, xpdrPort, nodeId);
+                    if (port == null) {
                         continue;
                     }
                     int[] counters = fillXpdrLcpsMaps(line, client, nodeId,
-                        xponderNb, xponderType, circuitPackName, portsList.get(),
+                        xponderNb, xponderType, xpdrPort.getCircuitPackName(), port,
                         circuitPackList, lcpMap, mappingMap);
                     line = counters[0];
                     client = counters[1];
                 }
             }
         }
+    }
 
-        if (device.getConnectionMap() == null) {
-            LOG.warn(PortMappingUtils.NO_CONMAP_LOGMSG, nodeId);
-        } else {
-            for (ConnectionMap cm : deviceObject.get().nonnullConnectionMap().values()) {
-                String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
-                Destination destination0 = cm.nonnullDestination().values().iterator().next();
-                String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName();
-                if (!lcpMap.containsKey(skey)) {
-                    LOG.error(PortMappingUtils.CONMAP_ISSUE_LOGMSG, nodeId, skey, dkey);
-                    continue;
-                }
-                String slcp = lcpMap.get(skey);
-                Mapping mapping = mappingMap.get(slcp);
-                mappingMap.remove(slcp);
-                portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping,
-                        //dlcp
-                        lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null,
-                        null));
-            }
+    private Ports getXpdrPorts(OrgOpenroadmDevice device, XpdrPort xpdrPort, String nodeId) {
+        String circuitPackName = xpdrPort.getCircuitPackName();
+        String portName = xpdrPort.getPortName();
+        // If there xponder-subtree has missing circuit-packs or ports,
+        // This gives a null-pointer expection,
+        Optional<CircuitPacks> cpList = device.nonnullCircuitPacks().values().stream()
+                .filter(cp -> cp.getCircuitPackName().equals(circuitPackName)).findFirst();
+        if (cpList.isEmpty()) {
+            LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
+                nodeId, circuitPackName);
+            return null;
         }
-
-        if (device.getOduSwitchingPools() != null) {
-            List<SwitchingPoolLcp> switchingPoolList = new ArrayList<>();
-            for (OduSwitchingPools odp : device.nonnullOduSwitchingPools().values()) {
-                Map<NonBlockingListKey,NonBlockingList> nbMap = new HashMap<>();
-                for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org
-                    .openroadm.device.odu.switching.pools.NonBlockingList nbl : odp.nonnullNonBlockingList().values()) {
-                    if (nbl.getPortList() == null) {
-                        continue;
-                    }
-                    List<String> lcpList = new ArrayList<>();
-                    for (PortList item : nbl.nonnullPortList().values()) {
-                        String key = item.getCircuitPackName() + "+" + item.getPortName();
-                        if (!lcpMap.containsKey(key)) {
-                            LOG.error(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG,
-                                nodeId, item.getPortName(), item.getCircuitPackName(), "to a logical connection point");
-                            continue;
-                        }
-                        lcpList.add(lcpMap.get(key));
-                    }
-                    NonBlockingList nonBlockingList = new NonBlockingListBuilder()
-                        .setNblNumber(nbl.getNblNumber())
-                        .setInterconnectBandwidth(nbl.getInterconnectBandwidth())
-                        .setInterconnectBandwidthUnit(nbl.getInterconnectBandwidthUnit())
-                        .setLcpList(lcpList)
-                        .build();
-                    nbMap.put(nonBlockingList.key(), nonBlockingList);
-                }
-                SwitchingPoolLcp splBldr = new SwitchingPoolLcpBuilder()
-                    .setSwitchingPoolNumber(odp.getSwitchingPoolNumber())
-                    .setSwitchingPoolType(odp.getSwitchingPoolType())
-                    //TODO differs from 2.2.1 SwitchingPoolTypes.forValue(odp.getSwitchingPoolType().getIntValue()
-                    .setNonBlockingList(nbMap)
-                    .build();
-                switchingPoolList.add(splBldr);
-            }
-            postPortMapping(nodeId, null, null, null, switchingPoolList, null);
+        Optional<Ports> portsList = cpList.get().nonnullPorts().values().stream()
+                .filter(p -> p.getPortName().equals(portName)).findFirst();
+        if (portsList.isEmpty()) {
+            LOG.warn(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
+                nodeId, portName, circuitPackName, "in the device");
+            return null;
         }
-
-        mappingMap.forEach((k,v) -> portMapList.add(v));
-        return true;
+        return portsList.get();
     }
 
     private boolean checkPartnerPortNotNull(Ports port) {
@@ -515,41 +533,13 @@ public class PortMappingVersion710 {
                             break;
                         case Rx:
                         case Tx:
-                            if (!checkPartnerPortNotNull(port)) {
-                                LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG
-                                        + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
-                                    nodeId, port.getPortName(), circuitPackName);
+                            Ports port2 = getPartnerPort(port, circuitPackName, nodeId);
+                            if (port2 == null) {
                                 continue;
                             }
                             String lcp1 = createLogicalConnectionPort(port, srgCpEntry.getKey(), portIndex);
                             LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
                                 nodeId, port.getPortName(), circuitPackName, lcp1);
-                            InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                                .child(CircuitPacks.class,
-                                    new CircuitPacksKey(port.getPartnerPort().getCircuitPackName()))
-                                .child(Ports.class, new PortsKey(port.getPartnerPort().getPortName()));
-                            Optional<Ports> port2Object = this.deviceTransactionManager
-                                .getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, port2ID,
-                                    Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                            if (port2Object.isEmpty()
-                                || port2Object.get().getPortQual().getIntValue()
-                                    != PortQual.RoadmExternal.getIntValue()) {
-                                LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG
-                                        + PortMappingUtils.PARTNERPORT_GET_ERROR_LOGMSG,
-                                    nodeId, port.getPartnerPort().getPortName(),
-                                    port.getPartnerPort().getCircuitPackName(),
-                                    port.getPortName(), circuitPackName);
-                                continue;
-                            }
-                            Ports port2 = port2Object.get();
-                            if (!checkPartnerPort(circuitPackName, port, port2)) {
-                                LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG
-                                        + PortMappingUtils.PARTNERPORT_CONF_ERROR_LOGMSG,
-                                    nodeId, port2.getPortName(), port.getPartnerPort().getCircuitPackName(),
-                                    port.getPortName(), circuitPackName);
-                                portIndex++;
-                                continue;
-                            }
                             String lcp2 = createLogicalConnectionPort(port2, srgCpEntry.getKey(),portIndex);
                             LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
                                 nodeId, port2.getPortName(), circuitPackName, lcp2);
@@ -570,6 +560,38 @@ public class PortMappingVersion710 {
         return true;
     }
 
+    private Ports getPartnerPort(Ports port, String circuitPackName, String nodeId) {
+        if (!checkPartnerPortNotNull(port)) {
+            LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
+                nodeId, port.getPortName(), circuitPackName);
+            return null;
+        }
+        InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+            .child(CircuitPacks.class, new CircuitPacksKey(port.getPartnerPort().getCircuitPackName()))
+            .child(Ports.class, new PortsKey(port.getPartnerPort().getPortName()));
+        Optional<Ports> port2Object = this.deviceTransactionManager
+            .getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, port2ID,
+                Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (port2Object.isEmpty()
+                || port2Object.get().getPortQual().getIntValue() != PortQual.RoadmExternal.getIntValue()) {
+            LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG + PortMappingUtils.PARTNERPORT_GET_ERROR_LOGMSG,
+                nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName(),
+                port.getPortName(), circuitPackName);
+            return null;
+        }
+        Ports port2 = port2Object.get();
+        if (!checkPartnerPort(circuitPackName, port, port2)) {
+            LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG + PortMappingUtils.PARTNERPORT_CONF_ERROR_LOGMSG,
+                nodeId, port2.getPortName(), port.getPartnerPort().getCircuitPackName(),
+                port.getPortName(), circuitPackName);
+            //portIndex++;
+            //TODO check if we really needed to increase portIndex
+            //     if yes this block should not be in getPartnerPort
+            return null;
+        }
+        return port2;
+    }
+
     private List<Ports> getPortList(String circuitPackName, String nodeId) {
         InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
             .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName));
@@ -991,12 +1013,12 @@ public class PortMappingVersion710 {
         if (partnerLcp != null) {
             mpBldr.setPartnerLcp(partnerLcp);
         }
-        if (port.augmentation(Ports1.class) != null && port.augmentation(Ports1.class).getPortCapabilities() != null) {
+        Collection<SupportedInterfaceCapability> supIntfCapaList = getSupIntfCapaList(port);
+        if (supIntfCapaList != null) {
             List<Class<? extends org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327
                 .SupportedIfCapability>> supportedIntf = new ArrayList<>();
             SupportedInterfaceCapability sic1 = null;
-            for (SupportedInterfaceCapability sic : port.augmentation(Ports1.class).getPortCapabilities()
-                    .nonnullSupportedInterfaceCapability().values()) {
+            for (SupportedInterfaceCapability sic : supIntfCapaList) {
                 supportedIntf.add(sic.getIfCapType());
                 sic1 = sic;
             }
@@ -1027,6 +1049,13 @@ public class PortMappingVersion710 {
         return mpBldr.build();
     }
 
+    private Collection<SupportedInterfaceCapability> getSupIntfCapaList(Ports port) {
+        return
+            port.augmentation(Ports1.class) == null || port.augmentation(Ports1.class).getPortCapabilities() == null
+                ? null
+                : port.augmentation(Ports1.class).getPortCapabilities().nonnullSupportedInterfaceCapability().values();
+    }
+
     private ArrayList<OpucnTribSlotDef> getOpucnTribSlots(String deviceId, String mxpProfileName) {
         ArrayList<OpucnTribSlotDef> minMaxOpucnTribSlots = new ArrayList<>(2);
 
@@ -1237,22 +1266,13 @@ public class PortMappingVersion710 {
             switch (cpMapValue.size()) {
                 case 1:
                     // port is bidirectional
-                    InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                        .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
-                        .child(Ports.class, new PortsKey(cp1.getPortName()));
-                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
-                    Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
-                        LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
-                        Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                    if (portObject.isEmpty()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
+                    Ports port = getTtpPort(cp1, cp1Name, nodeId);
+                    if (port == null) {
                         return false;
                     }
-                    Ports port = portObject.get();
                     if (!checkTtpPort(port, cp1Name, nodeId, true)) {
                         continue;
                     }
-
                     String logicalConnectionPoint =
                             PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(), "TXRX");
                     LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
@@ -1261,52 +1281,19 @@ public class PortMappingVersion710 {
                     break;
                 case 2:
                     // ports are unidirectionals
-                    ConnectionPorts cp2 = cpMapValue.get(1);
-                    String cp2Name = cp2.getCircuitPackName();
-                    InstanceIdentifier<Ports> port1ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                        .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
-                        .child(Ports.class, new PortsKey(cp1.getPortName()));
-                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
-                    Optional<Ports> port1Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
-                        LogicalDatastoreType.OPERATIONAL, port1ID, Timeouts.DEVICE_READ_TIMEOUT,
-                        Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                    InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                        .child(CircuitPacks.class, new CircuitPacksKey(cp2Name))
-                        .child(Ports.class, new PortsKey(cp2.getPortName()));
-                    LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp2.getPortName(), cp2Name);
-                    Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
-                        LogicalDatastoreType.OPERATIONAL, port2ID, Timeouts.DEVICE_READ_TIMEOUT,
-                        Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-                    if (port1Object.isEmpty()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp1.getPortName(), cp1Name);
+                    Ports port1 = getTtpPort(cp1, cp1Name, nodeId);
+                    if (port1 == null) {
                         return false;
                     }
-                    if (port2Object.isEmpty()) {
-                        LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp2.getPortName(), cp2Name);
+                    ConnectionPorts cp2 = cpMapValue.get(1);
+                    String cp2Name = cp2.getCircuitPackName();
+                    Ports port2 = getTtpPort(cp2, cp2Name, nodeId);
+                    if (port2 == null) {
                         return false;
                     }
-
-                    Ports port1 = port1Object.get();
-                    if (!checkTtpPort(port1, cp1Name, nodeId, false)) {
-                        continue;
-                    }
-                    Ports port2 = port2Object.get();
-                    if (!checkTtpPort(port2, cp2Name, nodeId, false)) {
-                        continue;
-                    }
-
-                    if (!checkPartnerPort(cp1Name, port1, port2)) {
-                        LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
-                            nodeId, port2.getPortName(), cp2Name, port1.getPortName(), cp1Name);
-                        continue;
-                    }
-                    // Directions checks are the same for cp1 and cp2, no need to check them twice.
-                    if (!checkPartnerPortNoDir(cp2Name, port2, port1)) {
-                        LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
-                            nodeId, port1.getPortName(), cp1Name, port2.getPortName(), cp2Name);
+                    if (!checkTtpPortsUnidir(port1, port2, cp1Name, cp2Name, nodeId)) {
                         continue;
                     }
-
                     String logicalConnectionPoint1 = PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(),
                             port1.getPortDirection().getName().toUpperCase(Locale.getDefault()));
                     LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
@@ -1321,11 +1308,27 @@ public class PortMappingVersion710 {
                 default:
                     LOG.error(PortMappingUtils.NOT_CORRECT_CONPORT_LOGMSG, nodeId, cpMapEntry.getKey());
                     continue;
+                    //TODO should it be continue or return false ?
             }
         }
         return true;
     }
 
+    private Ports getTtpPort(ConnectionPorts cp, String cpName, String nodeId) {
+        InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+            .child(CircuitPacks.class, new CircuitPacksKey(cpName))
+            .child(Ports.class, new PortsKey(cp.getPortName()));
+        LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp.getPortName(), cpName);
+        Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
+            LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
+            Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        if (portObject.isEmpty()) {
+            LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp.getPortName(), cpName);
+            return null;
+        }
+        return portObject.get();
+    }
+
     private boolean checkPortQual(Ports port, String cpName, String nodeId) {
         if (port.getPortQual() == null) {
             return false;
@@ -1352,14 +1355,33 @@ public class PortMappingVersion710 {
         return true;
     }
 
-    private NodeInfo createNodeInfo(Info deviceInfo) {
+    private boolean checkTtpPortsUnidir(Ports port1, Ports port2, String cp1Name, String cp2Name, String nodeId) {
+        if (!checkTtpPort(port1, cp1Name, nodeId, false)) {
+            return false;
+        }
+        if (!checkTtpPort(port2, cp2Name, nodeId, false)) {
+            return false;
+        }
+        if (!checkPartnerPort(cp1Name, port1, port2)) {
+            LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
+                nodeId, port2.getPortName(), cp2Name, port1.getPortName(), cp1Name);
+            return false;
+        }
+        // Directions checks are the same for cp1 and cp2, no need to check them twice.
+        if (!checkPartnerPortNoDir(cp2Name, port2, port1)) {
+            LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
+                nodeId, port1.getPortName(), cp1Name, port2.getPortName(), cp2Name);
+            return false;
+        }
+        return true;
+    }
 
+    private NodeInfo createNodeInfo(Info deviceInfo) {
         if (deviceInfo.getNodeType() == null) {
             // TODO make mandatory in yang
             LOG.error(PortMappingUtils.NODE_TYPE_LOGMSG, deviceInfo.getNodeId(), "field missing");
             return null;
         }
-
         NodeInfoBuilder nodeInfoBldr = new NodeInfoBuilder()
                 .setOpenroadmVersion(OpenroadmNodeVersion._71)
                 .setNodeClli(
@@ -1377,7 +1399,6 @@ public class PortMappingVersion710 {
         if (deviceInfo.getIpAddress() != null) {
             nodeInfoBldr.setNodeIpAddress(deviceInfo.getIpAddress());
         }
-
         return nodeInfoBldr.build();
     }
 
index cdcfc621ef6d5e2bb71cc8796a702240ad15d7e7..c7299c835b230c05d60ca0d7e821627c3b159407 100644 (file)
@@ -39,7 +39,7 @@ public class INode {
     }
 
     public boolean addNode(String deviceId, String openROADMversion) {
-        boolean sqlResult = false;
+        //boolean sqlResult = false;
         return inode121.addNode(deviceId);
 
     }
@@ -60,7 +60,7 @@ public class INode {
         } catch (SQLException e) {
             LOG.error("Something wrong when fetching node in DB", e);
         }
-        return nodeExists == 0 ? false : true;
+        return nodeExists != 0;
     }
 
     public boolean dataExists(String tableName, String searchKeys) {
@@ -79,7 +79,7 @@ public class INode {
         } catch (SQLException e) {
             LOG.error("Something wrong when fetching data in DB", e);
         }
-        return dataExists == 0 ? false : true;
+        return dataExists != 0;
     }
 
   /*  public void getRoadmShelves(String nodeId, String openRoadmVersion)
index e5ba1d8334a3f1ee4bc76c57a919a5a0683bdf6b..bc185290114126cb3d59ca1fbb0bd32ab4013c84 100644 (file)
@@ -194,7 +194,7 @@ public class INode121 {
         } catch (SQLException e) {
             LOG.error("Something wrong when fetching node in DB", e);
         }
-        return nodeExists == 0 ? false : true;
+        return nodeExists != 0;
     }
 
     public void getRoadmShelves(String nodeId) throws InterruptedException, ExecutionException {
index eef0289b1bf1fc8078d90275c06dd134661398bb..852a7a849c6dc78c106ac6f765363ec915bb2931 100644 (file)
@@ -192,7 +192,7 @@ public class INode221 {
         } catch (SQLException e) {
             LOG.error("Something wrong when fetching node in DB", e);
         }
-        return nodeExists == 0 ? false : true;
+        return nodeExists != 0;
     }
 
     public void getRoadmShelves(String nodeId) throws InterruptedException, ExecutionException {
index fcf5f026fe1dcdd48a82675b7fe78720f5047523..9d0371a125cab43fab04588c34d0267a470c83d4 100644 (file)
@@ -48,6 +48,7 @@ public class NotificationAlarmServiceSerializer implements Serializer<Notificati
             LOG.info("Serialized event {}", serialized);
             return serialized.getBytes(StandardCharsets.UTF_8);
         } catch (IOException e) {
+            LOG.error("exception raised during serialization", e);
             return new byte[0];
         }
     }
index b3f6ae119c5d86cb44be50145ef48da9c6ea9b6b..dc2c3d775737d8a290baf77416d4f4726a90224b 100644 (file)
@@ -47,6 +47,7 @@ public class NotificationServiceSerializer implements Serializer<NotificationPro
             LOG.info("Serialized event {}", serialized);
             return serialized.getBytes(StandardCharsets.UTF_8);
         } catch (IOException e) {
+            LOG.error("exception raised during serialization", e);
             return new byte[0];
         }
     }
index 0c00503b751c8f1f459bb455743488ec606017d4..af097c35b86d1ec0b222a59126c97f77ad95338b 100644 (file)
@@ -30,7 +30,7 @@ public final class NbiNotificationsUtils {
                 LOG.warn("Kafka property file '{}' is empty", propertyFileName);
             }
         } catch (IOException e) {
-            LOG.warn("Kafka property file '{}' was not found in the classpath", propertyFileName);
+            LOG.error("Kafka property file '{}' was not found in the classpath", propertyFileName, e);
         }
         return props;
     }
index dfc90dd3de49f5f83f83cca751fe52cccbf0a5db..b1b2cc0b0f25e841639337f862cf83241f2ceac6 100644 (file)
@@ -75,9 +75,10 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
             NetconfNode netconfNodeBefore = rootNode.getDataBefore().augmentation(NetconfNode.class);
             switch (rootNode.getModificationType()) {
                 case DELETE:
-                    this.networkModelService.deleteOpenRoadmnode(nodeId);
-                    onDeviceDisConnected(nodeId);
-                    LOG.info("Device {} correctly disconnected from controller", nodeId);
+                    if (this.networkModelService.deleteOpenRoadmnode(nodeId)) {
+                        onDeviceDisConnected(nodeId);
+                        LOG.info("Device {} correctly disconnected from controller", nodeId);
+                    }
                     break;
                 case WRITE:
                     NetconfNode netconfNodeAfter = rootNode.getDataAfter().augmentation(NetconfNode.class);
index 4845ba30789cf3c1f25323e9dd34d514f87df960..aaa515238bcdfb1578a372d3b41e229663f686e6 100644 (file)
@@ -29,13 +29,14 @@ public interface NetworkModelService {
     void createOpenRoadmNode(String nodeId, String nodeVersion);
 
     /**
-     * Delete OpenROADM node mapping and topologies.
+     * Delete OpenROADM node from portmapping and topologies.
      *
      * @param nodeId
      *     unique node ID of OpenROADM node.
      *
+     * @return result of node deletion from portmapping and topologies
      */
-    void deleteOpenRoadmnode(String nodeId);
+    boolean deleteOpenRoadmnode(String nodeId);
 
     /**
      * Update termination point, and if need, be associated links, of
index e5370ee33ebffd2226fff19d576c43abc07884f3..5c1ab9dac131cc22163d74cf4e1d260e1377c340 100644 (file)
@@ -191,8 +191,11 @@ public class NetworkModelServiceImpl implements NetworkModelService {
      */
 
     @Override
-    public void deleteOpenRoadmnode(String nodeId) {
+    public boolean deleteOpenRoadmnode(String nodeId) {
         try {
+            if (!this.portMapping.isNodeExist(nodeId)) {
+                return false;
+            }
             NodeKey nodeIdKey = new NodeKey(new NodeId(nodeId));
 
             LOG.info("deleting node in {}", NetworkUtils.UNDERLAY_NETWORK_ID);
@@ -263,7 +266,9 @@ public class NetworkModelServiceImpl implements NetworkModelService {
             LOG.info("all nodes and links deleted ! ");
         } catch (InterruptedException | ExecutionException | TimeoutException e) {
             LOG.error("Error when trying to delete node : {}", nodeId, e);
+            return false;
         }
+        return true;
     }
 
     @Override
index 8e57c872044184748c69360e4aeabb6d6fcfcfe1..3656c8f02c4abb198e3b1081b6ec6daf383f6b53 100644 (file)
@@ -78,7 +78,6 @@ public class NetConfTopologyListenerTest {
             OPENROADM_DEVICE_VERSION_2_2_1);
         when(node.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
         when(node.getDataBefore()).thenReturn(netconfNode);
-        when(registrations.remove(anyString())).thenReturn(nodeRegistration);
 
         NetConfTopologyListener listener = new NetConfTopologyListener(networkModelService, dataBroker,
             deviceTransactionManager, portMapping, registrations);
@@ -87,7 +86,7 @@ public class NetConfTopologyListenerTest {
         verify(node, times(1)).getModificationType();
         verify(node, times(3)).getDataBefore();
         verify(networkModelService, times(1)).deleteOpenRoadmnode(anyString());
-        verify(nodeRegistration, times(1)).unregisterListeners();
+        verify(nodeRegistration, times(0)).unregisterListeners();
     }
 
     @Test
index b13bc009730ce7b1e88d87c84a2bffbf5600a945..36faf86e0f5c852171ce31e85e408b8bd4694356 100644 (file)
@@ -143,7 +143,7 @@ public class GnpyResult {
                         counter++;
                     }
                 } catch (IllegalArgumentException e) {
-                    LOG.debug(" in GnpyResult: the element {} is not a ipv4Address ", nodeIp);
+                    LOG.error(" in GnpyResult: the element {} is not a ipv4Address ", nodeIp, e);
                 }
             }
         }
index 51bb5aedac965a292e61bf8999fa8435b3a1c61e..25136668019f08a453c376e67c8973728bfc0393 100644 (file)
@@ -69,6 +69,7 @@ import org.opendaylight.yangtools.yang.common.Uint8;
 public class OpenRoadmInterface710 {
     private static final String MAPPING_ERROR_EXCEPTION_MESSAGE =
         "Unable to get mapping from PortMapping for node % and logical connection port %s";
+    private static final String ODUC4 = "-ODUC4";
     private final PortMapping portMapping;
     private final OpenRoadmInterfaces openRoadmInterfaces;
 
@@ -342,7 +343,7 @@ public class OpenRoadmInterface710 {
             .setMaintTestsignal(maintTestsignal.build());
 
         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMap, OtnOdu.class,
-            logicalConnPoint + "-ODUC4");
+            logicalConnPoint + ODUC4);
 
         // Create a list
         List<String> listSupportingOtucnInterface = new ArrayList<>();
@@ -413,7 +414,7 @@ public class OpenRoadmInterface710 {
             .setMaintTestsignal(maintTestsignal.build());
 
         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMapA, OtnOdu.class,
-            alogicalConnPoint + "-ODUC4");
+            alogicalConnPoint + ODUC4);
 
         // Create a list
         List<String> listSupportingOtucnInterface = new ArrayList<>();
@@ -471,7 +472,7 @@ public class OpenRoadmInterface710 {
             .setMaintTestsignal(maintTestsignal.build());
 
         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMap, OtnOdu.class,
-            logicalConnPoint + "-ODUC4");
+            logicalConnPoint + ODUC4);
 
         // Create a list
         List<String> listSupportingOtucnInterface = new ArrayList<>();
@@ -544,7 +545,7 @@ public class OpenRoadmInterface710 {
             .setMaintTestsignal(maintTestsignal.build());
 
         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMapA, OtnOdu.class,
-            alogicalConnPoint + "-ODUC4");
+            alogicalConnPoint + ODUC4);
 
         // Create a list
         List<String> listSupportingOtucnInterface = new ArrayList<>();
index 8de4e6faf3d24e7538cfaf8660cbb700ccd90dca..14fdb46df990f45c6776d470db1309b71c9001bc 100644 (file)
@@ -56,6 +56,7 @@ public class TapiContext {
 
     private static final Logger LOG = LoggerFactory.getLogger(TapiContext.class);
     public static final String TAPI_CONTEXT = "T-API context";
+    public static final String NODE_NOT_PRESENT = "Node is not present in datastore";
     private final NetworkTransactionService networkTransactionService;
 
     public TapiContext(NetworkTransactionService networkTransactionService) {
@@ -256,7 +257,7 @@ public class TapiContext {
             Optional<Node> optNode = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, nodeIID)
                     .get();
             if (!optNode.isPresent()) {
-                LOG.error("Node is not present in datastore");
+                LOG.error(NODE_NOT_PRESENT);
                 return null;
             }
             // TODO -> Need to remove CEPs from NEPs. If not error from get Topology details output
@@ -305,7 +306,7 @@ public class TapiContext {
                     .read(LogicalDatastoreType.OPERATIONAL, nepIID)
                     .get();
             if (!optNode.isPresent()) {
-                LOG.error("Node is not present in datastore");
+                LOG.error(NODE_NOT_PRESENT);
                 return null;
             }
             return optNode.get();
@@ -325,7 +326,7 @@ public class TapiContext {
             Optional<Link> optLink = this.networkTransactionService.read(LogicalDatastoreType.OPERATIONAL, linkIID)
                     .get();
             if (!optLink.isPresent()) {
-                LOG.error("Node is not present in datastore");
+                LOG.error(NODE_NOT_PRESENT);
                 return null;
             }
             return optLink.get();
@@ -483,7 +484,7 @@ public class TapiContext {
             Optional<OwnedNodeEdgePoint> optNode = this.networkTransactionService
                 .read(LogicalDatastoreType.OPERATIONAL, nepIID).get();
             if (!optNode.isPresent()) {
-                LOG.error("Node is not present in datastore");
+                LOG.error(NODE_NOT_PRESENT);
                 return null;
             }
             if (optNode.get().augmentation(OwnedNodeEdgePoint1.class) == null) {
@@ -493,7 +494,7 @@ public class TapiContext {
             return optNode.get().augmentation(OwnedNodeEdgePoint1.class).getCepList().getConnectionEndPoint()
                 .get(new ConnectionEndPointKey(cepUuid));
         } catch (InterruptedException | ExecutionException e) {
-            LOG.error("Couldnt read node in topology");
+            LOG.error("Couldnt read node in topology", e);
             return null;
         }
     }
diff --git a/tests/dockercmd.sh b/tests/dockercmd.sh
new file mode 100755 (executable)
index 0000000..b384c3b
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+DOCKER_CMD=docker
+if [ `which podman` ]
+then DOCKER_CMD=podman
+else
+    if [ ! `which $DOCKER_CMD` ]
+    then  echo "no docker command available" >&2
+        exit 1
+    fi
+    #if "docker ps" cannot be run without error, prepend sudo
+    if ( ! $DOCKER_CMD ps >/dev/null 2>&1 );then
+        echo "docker command only usable as root, using sudo" >&2
+        DOCKER_CMD="sudo docker"
+    fi
+fi
+
+$DOCKER_CMD $@
diff --git a/tests/nbinotifications/docker-compose.yml b/tests/nbinotifications/docker-compose.yml
deleted file mode 100644 (file)
index b13f6b9..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-version: '2'
-services:
-  zookeeper:
-    image: wurstmeister/zookeeper
-    container_name: nbinotifications_zookeeper
-    ports:
-      - "2181:2181"
-  kafka:
-    image: wurstmeister/kafka
-    container_name: nbinotifications_kafka
-    ports:
-      - "9092:9092"
-    environment:
-      KAFKA_ADVERTISED_HOST_NAME: localhost
-      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
\ No newline at end of file
diff --git a/tox.ini b/tox.ini
index 8dda573e0ef78d70c21386609dfaf3b8293e93ec..303b01356a801c5583f958f867f8ce693c77ee56 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -138,24 +138,24 @@ commands =
 
 [testenv:gnpy]
 depends = buildcontroller
-whitelist_externals = sh
-                      sudo
+whitelist_externals = launch_tests.sh
+                      dockercmd.sh
 passenv = LAUNCHER USE_LIGHTY
 commands =
   #sudo docker pull atriki/gnpyrest:v1.2
-  sudo docker run -d -p 8008:5000 --name gnpy_tpce_rest1 atriki/gnpyrest:v1.2
+  ./dockercmd.sh run -d -p 8008:5000 --name gnpy_tpce_rest1 atriki/gnpyrest:v1.2
   ./launch_tests.sh with_docker gnpy
-  sudo docker container rm -f gnpy_tpce_rest1
+  ./dockercmd.sh container rm -f gnpy_tpce_rest1
 
 [testenv:nbinotifications]
 depends = buildcontroller,sims221
-whitelist_externals = sh
-                      sudo
+whitelist_externals = launch_tests.sh
+                      dockercmd.sh
 passenv = LAUNCHER USE_LIGHTY
 commands =
-  sudo docker-compose -f ./nbinotifications/docker-compose.yml up -d
+  ./dockercmd.sh run -d -p 2181:2181 -p 9092:9092 --env ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 --name tpce_kafka1 teivah/kafka:2.0.0
   ./launch_tests.sh with_docker nbinotifications
-  sudo docker-compose -f ./nbinotifications/docker-compose.yml down --rmi all
+  ./dockercmd.sh container rm -f tpce_kafka1
 
 [testenv:docs]
 passenv = http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY