Refactor PCE network analyzer PceOtnNode step 3
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / networkanalyzer / PceOtnNode.java
index 5dbe3679db4e183e40a523a06ca29a66e3751049..f7cfc4a5bbd1616f1504c1558c8488dd03d4b667 100644 (file)
@@ -8,27 +8,36 @@
 
 package org.opendaylight.transportpce.pce.networkanalyzer;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.BitSet;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 import java.util.stream.Collectors;
-import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev181130.xpdr.odu.switching.pools.OduSwitchingPools;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev181130.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingList;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmNodeType;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmTpType;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.xpdr.tp.supported.interfaces.SupportedInterfaceCapability;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev181130.ODTU4TsAllocated;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.Node1;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.TerminationPoint1;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.networks.network.node.SwitchingPools;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev181130.If100GEODU4;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev181130.If10GEODU2e;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev181130.If1GEODU0;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev181130.IfOCHOTU4ODU4;
+import org.opendaylight.transportpce.common.StringConstants;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev200327.xpdr.odu.switching.pools.OduSwitchingPools;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev200327.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingList;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmTpType;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.xpdr.tp.supported.interfaces.SupportedInterfaceCapability;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODTU4TsAllocated;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODTUCnTs;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.Node1;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.TerminationPoint1;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.networks.network.node.SwitchingPools;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.networks.network.node.termination.point.XpdrTpPortConnectionAttributes;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If100GEODU4;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If10GEODU2e;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If1GEODU0;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.IfOCHOTU4ODU4;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.IfOtsiOtsigroup;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.SupportedIfCapability;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.xponder.rev200529.xpdr.otn.tp.attributes.OdtuTpnPool;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.TpId;
@@ -38,13 +47,36 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class PceOtnNode implements PceNode {
-    /* Logging. */
-    private static final Logger LOG = LoggerFactory.getLogger(PceOtnNode.class);
     ////////////////////////// OTN NODES ///////////////////////////
     /*
      * For This Class the node passed shall be at the otn-openroadm Layer
      */
 
+    private static final Logger LOG = LoggerFactory.getLogger(PceOtnNode.class);
+    private static final List<String> SERVICE_TYPE_ODU_LIST = List.of(
+        StringConstants.SERVICE_TYPE_ODU4,
+        StringConstants.SERVICE_TYPE_ODUC4,
+        StringConstants.SERVICE_TYPE_ODUC3,
+        StringConstants.SERVICE_TYPE_ODUC2);
+    private static final List<OpenroadmNodeType> VALID_NODETYPES_LIST = List.of(
+        OpenroadmNodeType.MUXPDR,
+        OpenroadmNodeType.SWITCH,
+        OpenroadmNodeType.TPDR);
+    private static final Map<String, Class<? extends SupportedIfCapability>> SERVICE_TYPE_ETH_CLASS_MAP = Map.of(
+        StringConstants.SERVICE_TYPE_1GE, If1GEODU0.class,
+        StringConstants.SERVICE_TYPE_10GE, If10GEODU2e.class,
+        StringConstants.SERVICE_TYPE_100GE_T, If100GEODU4.class,
+        StringConstants.SERVICE_TYPE_100GE_M, If100GEODU4.class,
+        StringConstants.SERVICE_TYPE_100GE_S, If100GEODU4.class);
+    private static final Map<String, Integer> SERVICE_TYPE_ETH_TS_NB_MAP = Map.of(
+        StringConstants.SERVICE_TYPE_1GE, 1,
+        StringConstants.SERVICE_TYPE_10GE, 10,
+        StringConstants.SERVICE_TYPE_100GE_M, 20);
+    private static final Map<String, String> SERVICE_TYPE_ETH_ODU_STRING_MAP = Map.of(
+        StringConstants.SERVICE_TYPE_1GE, "ODU0",
+        StringConstants.SERVICE_TYPE_10GE, "ODU2e",
+        StringConstants.SERVICE_TYPE_100GE_M, "ODU4");
+
     private boolean valid = true;
 
     private final Node node;
@@ -52,6 +84,10 @@ public class PceOtnNode implements PceNode {
     private final OpenroadmNodeType nodeType;
     private final String pceNodeType;
     private final String otnServiceType;
+    private String modeType;
+    // TODO: not adding state check in this class as otn topology has not been modified
+    private final AdminStates adminStates;
+    private final State state;
 
     private Map<String, List<Uint16>> tpAvailableTribPort = new TreeMap<>();
     private Map<String, List<Uint16>> tpAvailableTribSlot = new TreeMap<>();
@@ -65,8 +101,10 @@ public class PceOtnNode implements PceNode {
 
     private List<PceLink> outgoingLinks = new ArrayList<>();
     private Map<String, String> clientPerNwTp = new HashMap<>();
+    private String clientPort;
 
-    public PceOtnNode(Node node, OpenroadmNodeType nodeType, NodeId nodeId, String pceNodeType, String serviceType) {
+    public PceOtnNode(Node node, OpenroadmNodeType nodeType, NodeId nodeId, String pceNodeType, String serviceType,
+            String clientPort) {
         this.node = node;
         this.nodeId = nodeId;
         this.nodeType = nodeType;
@@ -79,12 +117,18 @@ public class PceOtnNode implements PceNode {
         this.usedXpdrClientTps.clear();
         this.availableXpdrClientTps = new ArrayList<>();
         this.usableXpdrClientTps = new ArrayList<>();
+        this.adminStates = node
+            .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1.class)
+            .getAdministrativeState();
+        this.state = node
+            .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1.class)
+            .getOperationalState();
         this.tpAvailableTribPort.clear();
         checkAvailableTribPort();
         this.tpAvailableTribSlot.clear();
         checkAvailableTribSlot();
-        if ((node == null) || (nodeId == null) || (nodeType != OpenroadmNodeType.MUXPDR)
-            && (nodeType != OpenroadmNodeType.SWITCH) && (nodeType != OpenroadmNodeType.TPDR)) {
+        this.clientPort = clientPort;
+        if (node == null || nodeId == null || nodeType == null || !VALID_NODETYPES_LIST.contains(nodeType)) {
             LOG.error("PceOtnNode: one of parameters is not populated : nodeId, node type");
             this.valid = false;
         }
@@ -93,125 +137,130 @@ public class PceOtnNode implements PceNode {
     public void initXndrTps(String mode) {
         LOG.info("PceOtnNode: initXndrTps for node {}", this.nodeId.getValue());
         this.availableXponderTp.clear();
-
-        org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeTp
-            = this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
-                .ietf.network.topology.rev180226.Node1.class);
-        List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
-            .node.TerminationPoint> allTps = nodeTp.getTerminationPoint();
+        this.modeType = mode;
+        List<TerminationPoint> allTps =
+            new ArrayList<>(
+                this.node.augmentation(
+                    org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226
+                        .Node1.class)
+                .nonnullTerminationPoint()
+                .values());
         this.valid = false;
-        if (allTps == null) {
+        if (allTps.isEmpty()) {
             LOG.error("PceOtnNode: initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
             return;
         }
-
-        for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
-            .node.TerminationPoint tp : allTps) {
-            org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.@Nullable TerminationPoint1 ocnTp1
-                = tp.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130
-                .TerminationPoint1.class);
-            //TODO many nested if-structures below, this needs to be reworked
-            if (OpenroadmTpType.XPONDERNETWORK.equals(ocnTp1.getTpType()) && this.otnServiceType.equals("ODU4")) {
-                TerminationPoint1 ontTp1;
-                if (tp.augmentation(TerminationPoint1.class) != null) {
-                    ontTp1 = tp.augmentation(TerminationPoint1.class);
-                } else {
-                    continue;
-                }
-                if (checkTpForOdtuTermination(ontTp1)) {
-                    LOG.info("TP {} of XPONDER {} is validated", tp.getTpId(), node.getNodeId().getValue());
-                    this.availableXpdrNWTps.add(tp.getTpId());
-                } else {
-                    LOG.error("TP {} of {} does not allow ODU4 termination creation", tp.getTpId().getValue(),
-                        node.getNodeId().getValue());
-                }
-            } else if (OpenroadmTpType.XPONDERNETWORK.equals(ocnTp1.getTpType())
-                && (this.otnServiceType.equals("10GE") || this.otnServiceType.equals("1GE"))) {
-                TerminationPoint1 ontTp1;
-                if (tp.augmentation(TerminationPoint1.class) != null) {
-                    ontTp1 = tp.augmentation(TerminationPoint1.class);
-                } else {
-                    continue;
-                }
-                if ("10GE".equals(otnServiceType) && checkOdtuTTPforLoOduCreation(ontTp1, 10)
-                    || "1GE".equals(otnServiceType) && checkOdtuTTPforLoOduCreation(ontTp1, 1)) {
-                    LOG.info("TP {} of XPONDER {} is validated", tp.getTpId(), node.getNodeId().getValue());
-                    this.availableXpdrNWTps.add(tp.getTpId());
-                } else {
-                    if ("10GE".equals(otnServiceType)) {
-                        LOG.error("TP {} of {} does not allow OD2e termination creation", tp.getTpId().getValue(),
-                            node.getNodeId().getValue());
-                    } else if ("1GE".equals(otnServiceType)) {
-                        LOG.error("TP {} of {} does not allow ODU0 termination creation", tp.getTpId().getValue(),
-                            node.getNodeId().getValue());
+        for (TerminationPoint tp : allTps) {
+            org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1 ocnTp1
+                = tp.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529
+                        .TerminationPoint1.class);
+            if (ocnTp1 == null) {
+                LOG.warn("null ocn TP {}", tp);
+                continue;
+            }
+            //TODO many nested structures below, this needs to be reworked
+            switch (ocnTp1.getTpType()) {
+                case XPONDERNETWORK:
+                    if (tp.augmentation(TerminationPoint1.class) == null) {
+                        continue;
+                    }
+                    TerminationPoint1 ontTp1 = tp.augmentation(TerminationPoint1.class);
+                    if (SERVICE_TYPE_ODU_LIST.contains(this.otnServiceType)
+                            || StringConstants.SERVICE_TYPE_100GE_S.equals(this.otnServiceType)) {
+                            // TODO verify the capability of network port to support ODU4 CTP interface creation
+                        if (!checkTpForOdtuTermination(ontTp1)) {
+                            LOG.error("TP {} of {} does not allow ODU4 termination creation",
+                                tp.getTpId().getValue(), node.getNodeId().getValue());
+                            continue;
+                        }
+                    } else if (SERVICE_TYPE_ETH_TS_NB_MAP.containsKey(this.otnServiceType)) {
+                        if (!checkOdtuTTPforLoOduCreation(
+                                ontTp1, SERVICE_TYPE_ETH_TS_NB_MAP.get(this.otnServiceType))) {
+                            LOG.error("TP {} of {} does not allow {} termination creation",
+                                tp.getTpId().getValue(),
+                                SERVICE_TYPE_ETH_ODU_STRING_MAP.get(this.otnServiceType),
+                                node.getNodeId().getValue());
+                            continue;
+                        }
+                    // TODO what about SERVICE_TYPE_100GE_T ?
                     } else {
-                        LOG.error("TP {} of {} does not allow any termination creation", tp.getTpId().getValue(),
-                            node.getNodeId().getValue());
+                        LOG.error("TP {} of {} does not allow any termination creation",
+                            tp.getTpId().getValue(), node.getNodeId().getValue());
+                        continue;
                     }
-                }
-            } else if (OpenroadmTpType.XPONDERCLIENT.equals(ocnTp1.getTpType())
-                && (this.otnServiceType.equals("10GE") || this.otnServiceType.equals("1GE"))) {
-                TerminationPoint1 ontTp1;
-                if (tp.augmentation(TerminationPoint1.class) != null) {
-                    ontTp1 = tp.augmentation(TerminationPoint1.class);
-                } else {
-                    continue;
-                }
-                if (checkClientTp(ontTp1)) {
                     LOG.info("TP {} of XPONDER {} is validated", tp.getTpId(), node.getNodeId().getValue());
-                    this.availableXpdrClientTps.add(tp.getTpId());
-                } else {
-                    LOG.error("TP {} of {} does not allow lo-ODU (ODU2e or ODU0) termination creation",
-                        tp.getTpId().getValue(), node.getNodeId().getValue());
-                }
-            }
-        }
+                    this.availableXpdrNWTps.add(tp.getTpId());
+                    break;
 
-        if ((this.otnServiceType.equals("ODU4") && mode.equals("AZ"))
-            || ((this.otnServiceType.equals("10GE") || this.otnServiceType.equals("1GE"))
-                && ((mode.equals("AZ") && checkSwPool(availableXpdrClientTps, availableXpdrNWTps, 1, 1))
-                     || (mode.equals("intermediate") && checkSwPool(null, availableXpdrNWTps, 0, 2)))
-               )) {
-            this.valid = true;
-        } else {
-            this.valid = false;
+                case XPONDERCLIENT:
+                    if (SERVICE_TYPE_ETH_CLASS_MAP.containsKey(otnServiceType)
+                            && !StringConstants.SERVICE_TYPE_100GE_T.equals(this.otnServiceType)) {
+                            // TODO should we really exclude SERVICE_TYPE_100GE_T ?
+                        if (tp.augmentation(TerminationPoint1.class) == null) {
+                            continue;
+                        }
+                        if (checkClientTp(tp.augmentation(TerminationPoint1.class))) {
+                            LOG.info("TP {} of XPONDER {} is validated", tp.getTpId(), node.getNodeId().getValue());
+                            this.availableXpdrClientTps.add(tp.getTpId());
+                        } else {
+                            LOG.error("TP {} of {} does not allow lo-ODU (ODU2e or ODU0) termination creation",
+                                tp.getTpId().getValue(), node.getNodeId().getValue());
+                        }
+                    }
+                    break;
+
+                default:
+                    LOG.debug("unsupported ocn TP type {}", ocnTp1.getTpType());
+            }
         }
+        this.valid = SERVICE_TYPE_ODU_LIST.contains(this.otnServiceType)
+                || SERVICE_TYPE_ETH_TS_NB_MAP.containsKey(this.otnServiceType)
+                    && isAzOrIntermediateAvl(mode, null, availableXpdrClientTps, availableXpdrNWTps)
+                || StringConstants.SERVICE_TYPE_100GE_S.equals(this.otnServiceType)
+                    && isAzOrIntermediateAvl(mode, availableXpdrClientTps, availableXpdrClientTps, availableXpdrNWTps);
+                //TODO very similar to isOtnServiceTypeValid method
+                //     check whether the different treatment for SERVICE_TYPE_100GE_S here is appropriate or not
     }
 
     private boolean checkSwPool(List<TpId> clientTps, List<TpId> netwTps, int nbClient, int nbNetw) {
-        if (clientTps != null && netwTps != null && nbClient == 1 && nbNetw == 1) {
+        if (netwTps == null) {
+            return false;
+        }
+        if (clientTps != null && nbClient == 1 && nbNetw == 1) {
             clientTps.sort(Comparator.comparing(TpId::getValue));
             netwTps.sort(Comparator.comparing(TpId::getValue));
             for (TpId nwTp : netwTps) {
                 for (TpId clTp : clientTps) {
-                    @Nullable
-                    List<NonBlockingList> nblList = node.augmentation(Node1.class).getSwitchingPools()
-                        .getOduSwitchingPools().get(0).getNonBlockingList();
-                    for (NonBlockingList nbl : nblList) {
+                    for (NonBlockingList nbl : new ArrayList<>(node.augmentation(Node1.class).getSwitchingPools()
+                            .nonnullOduSwitchingPools().values().stream().findFirst().get()
+                                .getNonBlockingList().values())) {
                         if (nbl.getTpList().contains(clTp) && nbl.getTpList().contains(nwTp)) {
                             usableXpdrClientTps.add(clTp);
                             usableXpdrNWTps.add(nwTp);
                         }
-                        if (usableXpdrClientTps.size() >= nbClient && usableXpdrNWTps.size() >= nbNetw) {
+                        if (usableXpdrClientTps.size() >= 1 && usableXpdrNWTps.size() >= 1
+                            //since nbClient == 1 && nbNetw == 1...
+                                && (this.clientPort == null || this.clientPort.equals(clTp.getValue()))) {
                             clientPerNwTp.put(nwTp.getValue(), clTp.getValue());
                             return true;
                         }
                     }
                 }
             }
-
         }
-        if (clientTps == null && netwTps != null && nbClient == 0 && nbNetw == 2) {
+        if (nbClient == 0 && nbNetw == 2) {
             netwTps.sort(Comparator.comparing(TpId::getValue));
-            @Nullable
-            List<NonBlockingList> nblList = node.augmentation(Node1.class).getSwitchingPools().getOduSwitchingPools()
-                .get(0).getNonBlockingList();
-            for (NonBlockingList nbl : nblList) {
+            //TODO compared to above, nested loops are inverted below - does it make really sense ?
+            //     there is room to rationalize things here
+            for (NonBlockingList nbl : new ArrayList<>(node.augmentation(Node1.class).getSwitchingPools()
+                    .nonnullOduSwitchingPools().values().stream().findFirst().get()
+                        .getNonBlockingList().values())) {
                 for (TpId nwTp : netwTps) {
                     if (nbl.getTpList().contains(nwTp)) {
                         usableXpdrNWTps.add(nwTp);
                     }
-                    if (usableXpdrNWTps.size() >= nbNetw) {
+                    if (usableXpdrNWTps.size() >= 2) {
+                    //since nbClient == 0 && nbNetw == 2...
                         return true;
                     }
                 }
@@ -221,10 +270,12 @@ public class PceOtnNode implements PceNode {
     }
 
     private boolean checkTpForOdtuTermination(TerminationPoint1 ontTp1) {
-        for (SupportedInterfaceCapability sic : ontTp1.getTpSupportedInterfaces().getSupportedInterfaceCapability()) {
-            LOG.debug("in checkTpForOduTermination - sic = {}", sic.getIfCapType());
-            if (sic.getIfCapType().equals(IfOCHOTU4ODU4.class)
-                && ontTp1.getXpdrTpPortConnectionAttributes().getTsPool() == null) {
+        for (SupportedInterfaceCapability sic : ontTp1.getTpSupportedInterfaces().getSupportedInterfaceCapability()
+                .values()) {
+            LOG.info("in checkTpForOduTermination - sic = {}", sic.getIfCapType());
+            if ((sic.getIfCapType().equals(IfOCHOTU4ODU4.class) || sic.getIfCapType().equals(IfOtsiOtsigroup.class))
+                && (ontTp1.getXpdrTpPortConnectionAttributes() == null
+                    || ontTp1.getXpdrTpPortConnectionAttributes().getTsPool() == null)) {
                 return true;
             }
         }
@@ -232,40 +283,30 @@ public class PceOtnNode implements PceNode {
     }
 
     private boolean checkOdtuTTPforLoOduCreation(TerminationPoint1 ontTp1, int tsNb) {
-        if (ontTp1.getXpdrTpPortConnectionAttributes() != null
-            && ontTp1.getXpdrTpPortConnectionAttributes().getTsPool() != null
-            && ontTp1.getXpdrTpPortConnectionAttributes().getOdtuTpnPool() != null
-            && ontTp1.getXpdrTpPortConnectionAttributes().getOdtuTpnPool().get(0).getOdtuType()
-                .equals(ODTU4TsAllocated.class)
-            && ontTp1.getXpdrTpPortConnectionAttributes().getOdtuTpnPool().get(0).getTpnPool().isEmpty()
-            && (ontTp1.getXpdrTpPortConnectionAttributes().getTsPool().size() >= tsNb)) {
-            return true;
+        XpdrTpPortConnectionAttributes portConAttr = ontTp1.getXpdrTpPortConnectionAttributes();
+        if (portConAttr == null
+                || portConAttr.getTsPool() == null
+                || portConAttr.getTsPool().size() < tsNb
+                || portConAttr.getOdtuTpnPool() == null) {
+            return false;
         }
-        return false;
+        return checkFirstOdtuTpn(portConAttr.getOdtuTpnPool().values().stream().findFirst().get());
+    }
+
+    private boolean checkFirstOdtuTpn(OdtuTpnPool otPool) {
+        return (otPool.getOdtuType().equals(ODTU4TsAllocated.class)
+                || otPool.getOdtuType().equals(ODTUCnTs.class))
+            && !otPool.getTpnPool().isEmpty();
     }
 
     private boolean checkClientTp(TerminationPoint1 ontTp1) {
-        for (SupportedInterfaceCapability sic : ontTp1.getTpSupportedInterfaces().getSupportedInterfaceCapability()) {
+        for (SupportedInterfaceCapability sic : ontTp1.getTpSupportedInterfaces().getSupportedInterfaceCapability()
+                .values()) {
             LOG.debug("in checkTpForOduTermination - sic = {}", sic.getIfCapType());
-            switch (otnServiceType) {
-                case "1GE":
-                // we could also check the administrative status of the tp
-                    if (sic.getIfCapType().equals(If1GEODU0.class)) {
-                        return true;
-                    }
-                    break;
-                case "10GE":
-                    if (sic.getIfCapType().equals(If10GEODU2e.class)) {
-                        return true;
-                    }
-                    break;
-                case "100GE":
-                    if (sic.getIfCapType().equals(If100GEODU4.class)) {
-                        return true;
-                    }
-                    break;
-                default:
-                    break;
+            // we could also check the administrative status of the tp
+            if (SERVICE_TYPE_ETH_CLASS_MAP.containsKey(otnServiceType)
+                    && sic.getIfCapType().equals(SERVICE_TYPE_ETH_CLASS_MAP.get(otnServiceType))) {
+                return true;
             }
         }
         return false;
@@ -275,33 +316,25 @@ public class PceOtnNode implements PceNode {
         if (!isValid()) {
             return;
         }
-        if (OpenroadmNodeType.SWITCH.equals(this.nodeType)) {
-            initXndrTps("intermediate");
-        }
         if (this.nodeId.getValue().equals(anodeId) || (this.nodeId.getValue().equals(znodeId))) {
             initXndrTps("AZ");
+        } else if (OpenroadmNodeType.SWITCH.equals(this.nodeType)) {
+            initXndrTps("intermediate");
         } else {
             LOG.info("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
             valid = false;
         }
     }
 
-    public boolean validateSwitchingPoolBandwidth(
-            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
-                .ietf.network.topology.rev180226.networks.network.node.TerminationPoint tp1,
-            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
-                .ietf.network.topology.rev180226.networks.network.node.TerminationPoint tp2,
-            Long neededBW) {
+    public boolean validateSwitchingPoolBandwidth(TerminationPoint tp1, TerminationPoint tp2, Long neededBW) {
         if (this.nodeType != OpenroadmNodeType.TPDR) {
             return true;
         }
-        org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.Node1 node1 =
-            node.augmentation(
-                org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.Node1.class);
+        Node1 node1 = node.augmentation(Node1.class);
         SwitchingPools sp = node1.getSwitchingPools();
-        List<OduSwitchingPools> osp = sp.getOduSwitchingPools();
+        List<OduSwitchingPools> osp = new ArrayList<>(sp.nonnullOduSwitchingPools().values());
         for (OduSwitchingPools ospx : osp) {
-            List<NonBlockingList> nbl = ospx.getNonBlockingList();
+            List<NonBlockingList> nbl = new ArrayList<>(ospx.nonnullNonBlockingList().values());
             for (NonBlockingList nbll : nbl) {
                 if (nbll.getAvailableInterconnectBandwidth().toJava() >= neededBW && nbll.getTpList() != null
                         && nbll.getTpList().contains(tp1.getTpId()) && nbll.getTpList().contains(tp2.getTpId())) {
@@ -311,11 +344,9 @@ public class PceOtnNode implements PceNode {
                 }
             }
         }
-
         LOG.debug("validateSwitchingPoolBandwidth: No valid Switching pool for crossconnecting tp {} and {}",
             tp1.getTpId(), tp2.getTpId());
         return false;
-
     }
 
     public void validateIntermediateSwitch() {
@@ -327,66 +358,106 @@ public class PceOtnNode implements PceNode {
         }
         // Validate switch for use as an intermediate XPONDER on the path
         initXndrTps("intermediate");
-        if (!this.valid) {
-            LOG.debug("validateIntermediateSwitch: Switch unusable for transit == {}", nodeId.getValue());
-        } else {
+        if (this.valid) {
             LOG.info("validateIntermediateSwitch: Switch usable for transit == {}", nodeId.getValue());
+        } else {
+            LOG.debug("validateIntermediateSwitch: Switch unusable for transit == {}", nodeId.getValue());
         }
     }
 
     public void checkAvailableTribPort() {
-        List<TerminationPoint> networkTpList = node.augmentation(
-            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
-            .getTerminationPoint().stream()
-            .filter(type -> type
-                .augmentation(
-                    org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.TerminationPoint1.class)
-                .getTpType().equals(OpenroadmTpType.XPONDERNETWORK))
-            .collect(Collectors.toList());
-
-        for (TerminationPoint tp : networkTpList) {
-            if (tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes().getOdtuTpnPool() != null
-                && tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes().getOdtuTpnPool().get(0)
-                    .getOdtuType().equals(ODTU4TsAllocated.class)) {
-                @Nullable
-                List<Uint16> tpnPool = tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes()
-                    .getOdtuTpnPool().get(0).getTpnPool();
-                if (tpnPool != null) {
-                    tpAvailableTribPort.put(tp.getTpId().getValue(), tpnPool);
+        for (TerminationPoint tp :
+            node.augmentation(
+                    org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226
+                        .Node1.class)
+                .getTerminationPoint().values().stream()
+                .filter(type -> type
+                    .augmentation(
+                        org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529
+                            .TerminationPoint1.class)
+                    .getTpType()
+                    .equals(OpenroadmTpType.XPONDERNETWORK))
+                .collect(Collectors.toList())) {
+            XpdrTpPortConnectionAttributes portConAttr =
+                tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes();
+            if (portConAttr != null && portConAttr.getOdtuTpnPool() != null) {
+                OdtuTpnPool otPool = portConAttr.getOdtuTpnPool().values().stream().findFirst().get();
+                if (checkFirstOdtuTpn(otPool)) {
+                    tpAvailableTribPort.put(tp.getTpId().getValue(), otPool.getTpnPool());
                 }
             }
         }
     }
 
     public void checkAvailableTribSlot() {
-        List<TerminationPoint> networkTpList = node.augmentation(
-            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
-            .getTerminationPoint().stream()
+        for (TerminationPoint tp :
+            node.augmentation(
+                org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
+            .getTerminationPoint().values().stream()
             .filter(type -> type
                 .augmentation(
-                    org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.TerminationPoint1.class)
+                    org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1.class)
                 .getTpType().equals(OpenroadmTpType.XPONDERNETWORK))
-            .collect(Collectors.toList());
-
-        for (TerminationPoint tp : networkTpList) {
-            if (tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes().getTsPool() != null) {
-                @Nullable
-                List<Uint16> tsPool = tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes()
-                    .getTsPool();
-                tpAvailableTribSlot.put(tp.getTpId().getValue(), tsPool);
+            .collect(Collectors.toList())
+        ) {
+            XpdrTpPortConnectionAttributes portConAttr =
+                tp.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes();
+            if (portConAttr != null && portConAttr.getTsPool() != null) {
+                tpAvailableTribSlot.put(tp.getTpId().getValue(), portConAttr.getTsPool());
             }
         }
     }
 
     public boolean isValid() {
-        if ((node == null) || (nodeId == null) || (nodeType == null) || (this.getSupNetworkNodeId() == null)
-            || (this.getSupClliNodeId() == null)) {
+        if (isNotValid(this)) {
             LOG.error("PceNode: one of parameters is not populated : nodeId, node type, supporting nodeId");
             valid = false;
         }
         return valid;
     }
 
+    private boolean isNotValid(final PceOtnNode poNode) {
+        return poNode == null || poNode.nodeId == null || poNode.nodeType == null
+                || poNode.getSupNetworkNodeId() == null || poNode.getSupClliNodeId() == null;
+    }
+
+    public boolean isPceOtnNodeValid(final PceOtnNode pceOtnNode) {
+        if (isNotValid(pceOtnNode) || pceOtnNode.otnServiceType == null) {
+            LOG.error(
+                "PceOtnNode: one of parameters is not populated : nodeId, node type, supporting nodeId, otnServiceType"
+            );
+            return false;
+        }
+        if (VALID_NODETYPES_LIST.contains(pceOtnNode.nodeType)) {
+            return isOtnServiceTypeValid(pceOtnNode);
+        }
+        LOG.error("PceOtnNode node type: node type is not one of MUXPDR or SWITCH or TPDR");
+        return false;
+    }
+
+    private boolean isOtnServiceTypeValid(final PceOtnNode poNode) {
+        if (poNode.modeType == null) {
+            return false;
+        }
+        //Todo refactor Strings (mode and otnServiceType ) to enums
+        if (poNode.otnServiceType.equals(StringConstants.SERVICE_TYPE_ODU4)
+                && poNode.modeType.equals("AZ")) {
+            return true;
+        }
+        return (poNode.otnServiceType.equals(StringConstants.SERVICE_TYPE_10GE)
+                || poNode.otnServiceType.equals(StringConstants.SERVICE_TYPE_1GE)
+                || poNode.otnServiceType.equals(StringConstants.SERVICE_TYPE_100GE_S))
+            && isAzOrIntermediateAvl(poNode.modeType, null, poNode.availableXpdrClientTps, poNode.availableXpdrNWTps);
+        //TODO SERVICE_TYPE_ETH_TS_NB_MAP.containsKey(this.otnServiceType) might be more appropriate here
+        //     but only SERVICE_TYPE_100GE_S is managed and not SERVICE_TYPE_100GE_M and _T
+    }
+
+    private boolean isAzOrIntermediateAvl(
+            String mdType, List<TpId> clientTps0, List<TpId> clientTps, List<TpId> netwTps) {
+        return mdType.equals("intermediate") && checkSwPool(clientTps0, netwTps, 0, 2)
+               || mdType.equals("AZ") && checkSwPool(clientTps, netwTps, 1, 1);
+    }
+
     @Override
     public void addOutgoingLink(PceLink outLink) {
         this.outgoingLinks.add(outLink);
@@ -397,6 +468,16 @@ public class PceOtnNode implements PceNode {
         return outgoingLinks;
     }
 
+    @Override
+    public AdminStates getAdminStates() {
+        return adminStates;
+    }
+
+    @Override
+    public State getState() {
+        return state;
+    }
+
     @Override
     public String getXpdrClient(String tp) {
         return this.clientPerNwTp.get(tp);
@@ -445,7 +526,7 @@ public class PceOtnNode implements PceNode {
     }
 
     @Override
-    public String getRdmSrgClient(String tp) {
+    public String getRdmSrgClient(String tp, String direction) {
         return null;
     }
 
@@ -459,8 +540,40 @@ public class PceOtnNode implements PceNode {
         return false;
     }
 
+    /*
+    * (non-Javadoc)
+    *
+    * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getVersion()
+    */
     @Override
-    public boolean checkWL(long index) {
-        return false;
+    public String getVersion() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public BitSet getBitSetData() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+    * (non-Javadoc)
+    *
+    * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getSlotWidthGranularity()
+    */
+    @Override
+    public BigDecimal getSlotWidthGranularity() {
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getCentralFreqGranularity()
+     */
+    @Override
+    public BigDecimal getCentralFreqGranularity() {
+        return null;
     }
 }