Manage ODU4 services over multiple OTU4
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / provisiondevice / OtnDeviceRendererServiceImpl.java
index 8bb68e95cf6ab0875f468ca9133ad657f7d0e057..3d3e704910d0d569c2807f4eb90d455b8ffbf905 100644 (file)
 package org.opendaylight.transportpce.renderer.provisiondevice;
 
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ForkJoinPool;
 import java.util.concurrent.ForkJoinTask;
 import java.util.concurrent.atomic.AtomicBoolean;
-
+import org.opendaylight.transportpce.common.StringConstants;
 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
+import org.opendaylight.transportpce.networkmodel.service.NetworkModelService;
 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.OtnServicePathInput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.OtnServicePathOutput;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev200128.OtnServicePathOutputBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.Interface;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200128.node.interfaces.NodeInterface;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200128.node.interfaces.NodeInterfaceBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200128.node.interfaces.NodeInterfaceKey;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev200128.otn.renderer.input.Nodes;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.OtnServicePathInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.OtnServicePathOutput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.OtnServicePathOutputBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.AEndApiInfo;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.ZEndApiInfo;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.OpucnTribSlotDef;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.link.tp.LinkTp;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.link.tp.LinkTpBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.node.interfaces.NodeInterface;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.node.interfaces.NodeInterfaceBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.node.interfaces.NodeInterfaceKey;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.otn.renderer.nodes.Nodes;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 public class OtnDeviceRendererServiceImpl implements OtnDeviceRendererService {
     private static final Logger LOG = LoggerFactory.getLogger(OtnDeviceRendererServiceImpl.class);
+    private static final String PT_03 = "03";
+    private static final String PT_07 = "07";
     private final OpenRoadmInterfaceFactory openRoadmInterfaceFactory;
     private final CrossConnect crossConnect;
     private final OpenRoadmInterfaces openRoadmInterfaces;
     private final DeviceTransactionManager deviceTransactionManager;
-
+    private final NetworkModelService networkModelService;
 
     public OtnDeviceRendererServiceImpl(OpenRoadmInterfaceFactory openRoadmInterfaceFactory, CrossConnect crossConnect,
                                         OpenRoadmInterfaces openRoadmInterfaces,
-                                        DeviceTransactionManager deviceTransactionManager) {
+                                        DeviceTransactionManager deviceTransactionManager,
+                                        NetworkModelService networkModelService) {
         this.openRoadmInterfaceFactory = openRoadmInterfaceFactory;
         this.crossConnect = crossConnect;
         this.openRoadmInterfaces = openRoadmInterfaces;
         this.deviceTransactionManager = deviceTransactionManager;
+        this.networkModelService = networkModelService;
     }
 
+//TODO Align log messages and returned results messages
     @Override
-    public OtnServicePathOutput setupOtnServicePath(OtnServicePathInput input) {
-        LOG.info("Calling setup service path");
-        boolean success = true;
+    public OtnServicePathOutput setupOtnServicePath(OtnServicePathInput input, String serviceType) {
+        LOG.info("Calling setup otn-service path");
+        if (input.getServiceFormat() == null || input.getServiceRate() == null) {
+            return new OtnServicePathOutputBuilder()
+                .setSuccess(false)
+                .setResult("Error - service-type and service-rate must be present")
+                .build();
+        }
         List<NodeInterface> nodeInterfaces = new ArrayList<>();
-        List<String> results = new ArrayList<>();
-        if (input.getServiceType().equals("Ethernet")) {
-            try {
-                LOG.info("Calling Node interfaces {} {} {} {} {} {} {}",
-                        input.getServiceRate(),input.getEthernetEncoding(),
-                        input.getServiceType(),input.getOperation(),input.getTribPortNumber(),
-                        input.getTribSlot(),input.getNodes());
-                nodeInterfaces = createInterface(input);
-                LOG.info("Node interfaces created just fine ");
+        CopyOnWriteArrayList<LinkTp> otnLinkTps = new CopyOnWriteArrayList<>();
+        try {
+            switch (serviceType) {
+                case StringConstants.SERVICE_TYPE_1GE:
+                case StringConstants.SERVICE_TYPE_10GE:
+                case StringConstants.SERVICE_TYPE_100GE_M:
+                    LOG.info("Calling Node interfaces {} {} {} {} {} {} {}",
+                        input.getServiceRate(), input.getEthernetEncoding(),
+                        input.getServiceFormat(), input.getOperation(), input.getTribPortNumber(),
+                        input.getTribSlot(), input.getNodes());
+                    if (input.getNodes() != null) {
+                        createLowOrderInterfaces(input, nodeInterfaces, otnLinkTps);
+                        LOG.info("Node interfaces created just fine ");
+                    }
+                    break;
+                case StringConstants.SERVICE_TYPE_ODU4:
+                    createHighOrderInterfaces(input, nodeInterfaces, otnLinkTps);
+                    break;
+                case StringConstants.SERVICE_TYPE_ODUC4:
+                    createOduc4TtpInterface(input, nodeInterfaces, otnLinkTps);
+                    break;
+                case StringConstants.SERVICE_TYPE_100GE_S:
+                    LOG.info("Calling Node interface for service-type {}", serviceType);
+                    if (input.getNodes() != null) {
+                        createHighOrderInterfaces(input, nodeInterfaces, otnLinkTps);
+                        LOG.info("Node interfaces created");
+                    }
+                    break;
+                default:
+                    LOG.error("Service-type {} not managed yet", serviceType);
+                    return new OtnServicePathOutputBuilder()
+                        .setSuccess(false)
+                        .setResult("Service-type not managed")
+                        .build();
             }
-            catch (OpenRoadmInterfaceException e) {
-                //handle exception
-                LOG.warn("Set up service path failed {}", e.toString());
-                success = false;
+        } catch (OpenRoadmInterfaceException e) {
+            LOG.warn("Service path set-up failed", e);
+            Map<NodeInterfaceKey,NodeInterface> nodeInterfacesMap = new HashMap<>();
+            for (NodeInterface nodeInterface : nodeInterfaces) {
+                if (nodeInterface != null) {
+                    nodeInterfacesMap.put(nodeInterface.key(), nodeInterface);
+                }
             }
-
+            //TODO check if we need to set a NodeInterface Map in the result in that case
+            return new OtnServicePathOutputBuilder()
+                    .setSuccess(false)
+                    .setNodeInterface(nodeInterfacesMap)
+                    .setResult("Service path set-up failed")
+                    .setLinkTp(otnLinkTps)
+                    .build();
         }
-        if (success) {
-            LOG.info("Result is success");
-            for (NodeInterface nodeInterface: nodeInterfaces) {
+        LOG.info("Service path set-up succeed");
+        List<String> results = new ArrayList<>();
+        Map<NodeInterfaceKey,NodeInterface> nodeInterfacesMap = new HashMap<>();
+        for (NodeInterface nodeInterface : nodeInterfaces) {
+            if (nodeInterface != null) {
                 results.add("Otn Service path was set up successfully for node :" + nodeInterface.getNodeId());
+                nodeInterfacesMap.put(nodeInterface.key(), nodeInterface);
             }
-            //TODO Add otn topology links
         }
-        OtnServicePathOutputBuilder otnServicePathOutputBuilder = new OtnServicePathOutputBuilder()
-                .setSuccess(success)
-                .setNodeInterface(nodeInterfaces)
-                .setResult(String.join("\n", results));
-        return otnServicePathOutputBuilder.build();
+        return new OtnServicePathOutputBuilder()
+                .setSuccess(true)
+                .setNodeInterface(nodeInterfacesMap)
+                .setResult(String.join("\n", results))
+                .setLinkTp(otnLinkTps)
+                .build();
     }
 
-    @Override
-    public OtnServicePathOutput deleteOtnServicePath(OtnServicePathInput input) {
+    @SuppressWarnings("rawtypes")
+    // FIXME check if the ForkJoinTask raw type can be avoided
+    // Raw types use are discouraged since they lack type safety.
+    // Resulting Problems are observed at run time and not at compile time
+    public OtnServicePathOutput deleteOtnServicePath(OtnServicePathInput input, String serviceType) {
+        if (input.getNodes() == null) {
+            LOG.error("Unable to delete otn service path. input nodes = null");
+            return new OtnServicePathOutputBuilder()
+                .setResult("Unable to delete otn service path. input nodes = null")
+                .setSuccess(false)
+                .build();
+        }
         List<Nodes> nodes = input.getNodes();
         AtomicBoolean success = new AtomicBoolean(true);
         ConcurrentLinkedQueue<String> results = new ConcurrentLinkedQueue<>();
+        CopyOnWriteArrayList<LinkTp> otnLinkTps = new CopyOnWriteArrayList<>();
         ForkJoinPool forkJoinPool = new ForkJoinPool();
         ForkJoinTask forkJoinTask = forkJoinPool.submit(() -> nodes.parallelStream().forEach(node -> {
-            List<String> interfacesToDelete = new LinkedList<>();
             String nodeId = node.getNodeId();
             LOG.info("Deleting service setup on node {}", nodeId);
-            String srcTp = node.getClientTp();
-            String destTp = node.getNetworkTp();
-            if ((srcTp == null) || (destTp == null) || input.getServiceRate() == null) {
-                LOG.error("Source ({}) or destination ({}) termination point is null.", srcTp, destTp);
+            String networkTp = node.getNetworkTp();
+            if (networkTp == null || input.getServiceRate() == null || input.getServiceFormat() == null) {
+                LOG.error("destination ({}) or service-rate ({}) or service-format ({}) is null.",
+                    networkTp, input.getServiceRate(), input.getServiceFormat());
                 return;
             }
-            // if the node is currently mounted then proceed.
-            if (this.deviceTransactionManager.isDeviceMounted(nodeId)) {
-                String connectionNumber = "";
-                switch (input.getServiceRate()) {
-                    case("10G"):
-                        connectionNumber = srcTp + "-ODU2e-" + input.getServiceName() + "-x-" + destTp
-                            + "-ODU2e-" + input.getServiceName();
-                        break;
-                    case("1G"):
-                        connectionNumber = srcTp + "-ODU0-" + input.getServiceName() + "-x-" + destTp
-                            + "-ODU2e-" + input.getServiceName();
-                        break;
-                    default:
-                        LOG.error("service rate {} not managed yet", input.getServiceRate());
-                        String result = input.getServiceRate() + " is not supported";
-                        results.add(result);
-                        success.set(false);
-                        return;
-                }
-                List<String> intToDelete = this.crossConnect.deleteCrossConnect(nodeId, connectionNumber, true);
-                if (intToDelete != null) {
-                    for (String interf : intToDelete) {
-                        if (!this.openRoadmInterfaceFactory.isUsedbyOtnXc(nodeId, interf, connectionNumber,
-                            this.deviceTransactionManager)) {
-                            interfacesToDelete.add(interf);
-                            if (!getSupportedInterface(nodeId, interf).contains("ODU4")) {
-                                interfacesToDelete.add(getSupportedInterface(nodeId, interf));
-                            }
-                        }
-                    }
-                }
-            } else {
+            if (!this.deviceTransactionManager.isDeviceMounted(nodeId)) {
                 String result = nodeId + " is not mounted on the controller";
                 results.add(result);
                 success.set(false);
                 LOG.warn(result);
                 forkJoinPool.shutdown();
                 return;
-                //TODO should deletion end here?
+                // TODO should deletion end here?
+            }
+            // if the node is currently mounted then proceed.
+            List<String> interfacesToDelete = new LinkedList<>();
+            String connectionNumber = "";
+            switch (serviceType) {
+                case StringConstants.SERVICE_TYPE_100GE_S:
+                    connectionNumber = getConnectionNumber(null, node, networkTp, "ODU4");
+                    break;
+                case StringConstants.SERVICE_TYPE_100GE_M:
+                    connectionNumber = getConnectionNumber(input.getServiceName(), node, networkTp, "ODU4");
+                    otnLinkTps.add(new LinkTpBuilder()
+                        .setNodeId(nodeId)
+                        .setTpId(networkTp)
+                        .build());
+                    break;
+                case StringConstants.SERVICE_TYPE_ODU4:
+                    if (node.getClientTp() == null && node.getNetwork2Tp() == null) {
+                        interfacesToDelete.add(networkTp + "-ODU4");
+                        otnLinkTps.add(new LinkTpBuilder()
+                            .setNodeId(nodeId)
+                            .setTpId(networkTp)
+                            .build());
+                    }
+                    if (node.getClientTp() == null && node.getNetwork2Tp() != null) {
+                        interfacesToDelete.add(networkTp + "-ODU4");
+                        interfacesToDelete.add(node.getNetwork2Tp() + "-ODU4");
+                        connectionNumber = getConnectionNumber(null, node, networkTp, "ODU4");
+                    }
+                    break;
+                case StringConstants.SERVICE_TYPE_ODUC4:
+                    if (node.getClientTp() == null && node.getNetwork2Tp() == null) {
+                        interfacesToDelete.add(networkTp + "-ODUC4");
+                        otnLinkTps.add(new LinkTpBuilder()
+                            .setNodeId(nodeId)
+                            .setTpId(networkTp)
+                            .build());
+                    }
+                    if (node.getClientTp() == null && node.getNetwork2Tp() != null) {
+                        interfacesToDelete.add(networkTp + "-ODUC4");
+                        interfacesToDelete.add(node.getNetwork2Tp() + "-ODUC4");
+                        connectionNumber = getConnectionNumber(null, node, networkTp, "ODUC4");
+                    }
+                    break;
+                case StringConstants.SERVICE_TYPE_10GE:
+                    connectionNumber = getConnectionNumber(input.getServiceName(), node, networkTp, "ODU2e");
+                    otnLinkTps.add(new LinkTpBuilder()
+                        .setNodeId(nodeId)
+                        .setTpId(networkTp)
+                        .build());
+                    break;
+                case StringConstants.SERVICE_TYPE_1GE:
+                    connectionNumber = getConnectionNumber(input.getServiceName(), node, networkTp, "ODU0");
+                    otnLinkTps.add(new LinkTpBuilder()
+                        .setNodeId(nodeId)
+                        .setTpId(networkTp)
+                        .build());
+                    break;
+                default:
+                    LOG.error("service-type {} not managed yet", serviceType);
+                    String result = serviceType + " is not supported";
+                    results.add(result);
+                    success.set(false);
+                    return;
+            }
+            List<String> intToDelete = this.crossConnect.deleteCrossConnect(nodeId, connectionNumber, true);
+            for (String interf : intToDelete == null ? new ArrayList<String>() : intToDelete) {
+                if (!this.openRoadmInterfaceFactory.isUsedByOtnXc(nodeId, interf, connectionNumber,
+                        this.deviceTransactionManager)) {
+                    interfacesToDelete.add(interf);
+                    String supportedInterface = this.openRoadmInterfaces.getSupportedInterface(nodeId, interf);
+                    if (supportedInterface == null) {
+                        continue;
+                    }
+                    if ((input.getServiceRate().intValue() == 100 && !supportedInterface.contains("ODUC4"))
+                        || (input.getServiceRate().intValue() != 100 && !supportedInterface.contains("ODU4"))) {
+                        interfacesToDelete.add(supportedInterface);
+                    }
+                }
             }
+
             for (String interfaceId : interfacesToDelete) {
                 try {
                     this.openRoadmInterfaces.deleteInterface(nodeId, interfaceId);
@@ -157,101 +272,262 @@ public class OtnDeviceRendererServiceImpl implements OtnDeviceRendererService {
             forkJoinTask.get();
         } catch (InterruptedException | ExecutionException e) {
             LOG.error("Error while deleting service paths!", e);
+            return new OtnServicePathOutputBuilder()
+                .setResult("Error while deleting service paths!")
+                .setSuccess(false)
+                .build();
         }
         forkJoinPool.shutdown();
-        OtnServicePathOutputBuilder delServBldr = new OtnServicePathOutputBuilder();
-        delServBldr.setSuccess(success.get());
-        if (results.isEmpty()) {
-            return delServBldr.setResult("Request processed").build();
-        } else {
-            return delServBldr.setResult(String.join("\n", results)).build();
-        }
-
-    }
-
-    private String getSupportedInterface(String nodeId, String interf) {
-        Optional<Interface> supInterfOpt;
-        try {
-            supInterfOpt = this.openRoadmInterfaces.getInterface(nodeId, interf);
-            if (supInterfOpt.isPresent()) {
-                return supInterfOpt.get().getSupportingInterface();
-            } else {
-                return null;
-            }
-        } catch (OpenRoadmInterfaceException e) {
-            LOG.error("error getting Supported Interface of {} - {}", interf, nodeId, e);
-            return null;
-        }
+        return new OtnServicePathOutputBuilder()
+                .setSuccess(success.get())
+                .setLinkTp(otnLinkTps)
+                .setResult(
+                    results.isEmpty()
+                        ? "Request processed"
+                        : String.join("\n", results))
+                .build();
     }
 
-    private List<NodeInterface> createInterface(OtnServicePathInput input) throws OpenRoadmInterfaceException {
-        List<NodeInterface> nodeInterfaces = new ArrayList<>();
-        LOG.info("Calling Create Interface entry for OTN service path");
-        if (input.getServiceRate() == null
-            || !("1G".equals(input.getServiceRate()) || "10G".equals(input.getServiceRate()))) {
-            LOG.error("Service rate {} not managed yet", input.getServiceRate());
+    private String getConnectionNumber(String serviceName, Nodes node, String networkTp, String oduType) {
+        List<String> list1 = new ArrayList<>();
+        List<String> list2 = new ArrayList<>(Arrays.asList("x"));
+        if (node.getClientTp() != null) {
+            list1.addAll(Arrays.asList(node.getClientTp(), oduType));
+            list2.addAll(Arrays.asList(networkTp, oduType));
+        } else if (node.getNetwork2Tp() != null) {
+            list1.addAll(Arrays.asList(networkTp, oduType));
+            list2.addAll(Arrays.asList(node.getNetwork2Tp(), oduType));
         } else {
-            createLowOrderInterfaces(input, nodeInterfaces);
+            return "";
+        }
+        if (serviceName != null) {
+            list1.add(serviceName);
+            list2.add(serviceName);
         }
-        return nodeInterfaces;
+        list1.addAll(list2);
+        return String.join("-", list1);
     }
 
     private Optional<String> postCrossConnect(List<String> createdOduInterfaces, Nodes node)
             throws OpenRoadmInterfaceException {
-        return this.crossConnect.postOtnCrossConnect(createdOduInterfaces,node);
+        return this.crossConnect.postOtnCrossConnect(createdOduInterfaces, node);
     }
 
-    private void createLowOrderInterfaces(OtnServicePathInput input, List<NodeInterface> nodeInterfaces)
-        throws OpenRoadmInterfaceException {
-        for (Nodes node: input.getNodes()) {
-            //check if the node is mounted or not?
+    private void createLowOrderInterfaces(OtnServicePathInput input, List<NodeInterface> nodeInterfaces,
+            CopyOnWriteArrayList<LinkTp> linkTpList) throws OpenRoadmInterfaceException {
+        for (Nodes node : input.getNodes()) {
+            AEndApiInfo apiInfoA = null;
+            ZEndApiInfo apiInfoZ = null;
+            if (input.getAEndApiInfo() != null && input.getAEndApiInfo().getNodeId().contains(node.getNodeId())) {
+                apiInfoA = input.getAEndApiInfo();
+            }
+            if (input.getZEndApiInfo() != null && input.getZEndApiInfo().getNodeId().contains(node.getNodeId())) {
+                apiInfoZ = input.getZEndApiInfo();
+            }
+            // check if the node is mounted or not?
             List<String> createdEthInterfaces = new ArrayList<>();
             List<String> createdOduInterfaces = new ArrayList<>();
-            switch (input.getServiceRate()) {
-                case("1G"):
+            switch (input.getServiceRate().intValue()) {
+                case 1:
                     LOG.info("Input service is 1G");
-                    createdEthInterfaces.add(
-                        openRoadmInterfaceFactory.createOpenRoadmEth1GInterface(node.getNodeId(), node.getClientTp()));
-                    createdOduInterfaces.add(
-                        //suppporting interface?, payload ?
-                        openRoadmInterfaceFactory.createOpenRoadmOdu0Interface(node.getNodeId(), node.getClientTp(),
-                            input.getServiceName(), "07", false, input.getTribPortNumber(), input.getTribSlot()));
+                    if (node.getClientTp() != null) {
+                        createdEthInterfaces.add(
+                            openRoadmInterfaceFactory.createOpenRoadmEth1GInterface(node.getNodeId(),
+                                node.getClientTp()));
+                        createdOduInterfaces.add(
+                            // suppporting interface?, payload ?
+                            openRoadmInterfaceFactory.createOpenRoadmOdu0Interface(node.getNodeId(), node.getClientTp(),
+                                input.getServiceName(), PT_07, false, input.getTribPortNumber(), input.getTribSlot()));
+                    }
                     createdOduInterfaces.add(
                         openRoadmInterfaceFactory.createOpenRoadmOdu0Interface(node.getNodeId(), node.getNetworkTp(),
-                            input.getServiceName(), "07", true, input.getTribPortNumber(), input.getTribSlot()));
+                            input.getServiceName(), PT_07, true, input.getTribPortNumber(), input.getTribSlot()));
+                    linkTpList.add(
+                        new LinkTpBuilder().setNodeId(node.getNodeId()).setTpId(node.getNetworkTp()).build());
+                    if (node.getNetwork2Tp() != null) {
+                        createdOduInterfaces.add(
+                            // supporting interface? payload ?
+                            openRoadmInterfaceFactory.createOpenRoadmOdu0Interface(node.getNodeId(),
+                                node.getNetwork2Tp(), input.getServiceName(), PT_07, true, input.getTribPortNumber(),
+                                input.getTribSlot()));
+                        linkTpList.add(
+                            new LinkTpBuilder().setNodeId(node.getNodeId()).setTpId(node.getNetworkTp()).build());
+                    }
                     break;
-                case("10G"):
+                case 10:
                     LOG.info("Input service is 10G");
-                    createdEthInterfaces.add(
-                        openRoadmInterfaceFactory.createOpenRoadmEth10GInterface(node.getNodeId(), node.getClientTp()));
-                    createdOduInterfaces.add(
-                        //suppporting interface?, payload ?
-                        openRoadmInterfaceFactory.createOpenRoadmOdu2eInterface(node.getNodeId(), node.getClientTp(),
-                            input.getServiceName(),"03", false ,input.getTribPortNumber(),input.getTribSlot()));
+                    if (node.getClientTp() != null) {
+                        createdEthInterfaces.add(openRoadmInterfaceFactory.createOpenRoadmEth10GInterface(
+                            node.getNodeId(), node.getClientTp()));
+                        createdOduInterfaces.add(
+                            // suppporting interface?, payload ?
+                            openRoadmInterfaceFactory.createOpenRoadmOdu2eInterface(node.getNodeId(),
+                                node.getClientTp(), input.getServiceName(), false, input.getTribPortNumber(),
+                                input.getTribSlot(), apiInfoA, apiInfoZ));
+                    }
                     createdOduInterfaces.add(
                         // supporting interface? payload ?
                         openRoadmInterfaceFactory.createOpenRoadmOdu2eInterface(node.getNodeId(), node.getNetworkTp(),
-                            input.getServiceName(),"03" , true ,input.getTribPortNumber(),input.getTribSlot()));
+                            input.getServiceName(), true, input.getTribPortNumber(), input.getTribSlot(), apiInfoA,
+                            apiInfoZ));
+                    linkTpList.add(
+                        new LinkTpBuilder().setNodeId(node.getNodeId()).setTpId(node.getNetworkTp()).build());
+                    if (node.getNetwork2Tp() != null) {
+                        createdOduInterfaces.add(
+                            // supporting interface? payload ?
+                            openRoadmInterfaceFactory.createOpenRoadmOdu2eInterface(node.getNodeId(),
+                                node.getNetwork2Tp(), input.getServiceName(), true, input.getTribPortNumber(),
+                                input.getTribSlot(), apiInfoA, apiInfoZ));
+                        linkTpList.add(
+                            new LinkTpBuilder().setNodeId(node.getNodeId()).setTpId(node.getNetworkTp()).build());
+                    }
+                    break;
+                case 100:
+                    LOG.info("Input service is 100G");
+                    // Take the first and last value in the list of OpucnTribSlot (assuming SH would provide
+                    // min and max value only, size two)
+                    OpucnTribSlotDef minOpucnTs = OpucnTribSlotDef.getDefaultInstance(
+                        input.getOpucnTribSlots().get(0).getValue());
+                    OpucnTribSlotDef maxOpucnTs = OpucnTribSlotDef.getDefaultInstance(
+                        input.getOpucnTribSlots().get(1).getValue());
+                    if (node.getClientTp() != null) {
+                        createdEthInterfaces.add(openRoadmInterfaceFactory.createOpenRoadmEth100GInterface(
+                            node.getNodeId(), node.getClientTp()));
+                        // OPUCn trib information is optional when creating ODU4 ethernet (client) interface
+                        createdOduInterfaces.add(
+                            openRoadmInterfaceFactory.createOpenRoadmOtnOdu4LoInterface(node.getNodeId(),
+                            node.getClientTp(), input.getServiceName(), PT_07, false, minOpucnTs,
+                                maxOpucnTs));
+                    }
+                    // Here payload-type is optional and is not used for interface creation (especially for network)
+                    createdOduInterfaces.add(
+                        openRoadmInterfaceFactory.createOpenRoadmOtnOdu4LoInterface(node.getNodeId(),
+                            node.getNetworkTp(), input.getServiceName(), PT_07, true, minOpucnTs,
+                            maxOpucnTs));
+                    linkTpList.add(
+                        new LinkTpBuilder().setNodeId(node.getNodeId()).setTpId(node.getNetworkTp()).build());
+                    // Here payload-type is optional and is not used for service creation
+                    // This is needed if there is an intermediate node
+                    if (node.getNetwork2Tp() != null) {
+                        createdOduInterfaces.add(
+                            openRoadmInterfaceFactory.createOpenRoadmOtnOdu4LoInterface(node.getNodeId(),
+                                node.getNetwork2Tp(), input.getServiceName(), PT_07, true, minOpucnTs,
+                                maxOpucnTs));
+                        linkTpList.add(
+                            new LinkTpBuilder().setNodeId(node.getNodeId()).setTpId(node.getNetworkTp()).build());
+                    }
                     break;
                 default:
                     LOG.error("service rate {} not managed yet", input.getServiceRate());
                     return;
             }
 
-            //implement cross connect
+            // implement cross connect
             List<String> createdConnections = new ArrayList<>();
             if (!createdOduInterfaces.isEmpty()) {
                 Optional<String> connectionNameOpt = postCrossConnect(createdOduInterfaces, node);
                 createdConnections.add(connectionNameOpt.get());
                 LOG.info("Created cross connects");
             }
-            NodeInterfaceBuilder nodeInterfaceBuilder = new NodeInterfaceBuilder()
-                    .withKey(new NodeInterfaceKey(input.getServiceName() + "-" + node.getNodeId()))
-                    .setNodeId(input.getServiceName() + "-" + node.getNodeId())
+            nodeInterfaces.add(new NodeInterfaceBuilder()
+                    .withKey(new NodeInterfaceKey(node.getNodeId()))
+                    .setNodeId(node.getNodeId())
+                    .setConnectionId(createdConnections)
+                    .setEthInterfaceId(createdEthInterfaces)
+                    .setOduInterfaceId(createdOduInterfaces)
+                    .build());
+        }
+    }
+
+    private void createHighOrderInterfaces(OtnServicePathInput input, List<NodeInterface> nodeInterfaces,
+            CopyOnWriteArrayList<LinkTp> linkTpList) throws OpenRoadmInterfaceException {
+        for (Nodes node : input.nonnullNodes()) {
+            AEndApiInfo apiInfoA = null;
+            ZEndApiInfo apiInfoZ = null;
+            if (input.getAEndApiInfo() != null && input.getAEndApiInfo().getNodeId().contains(node.getNodeId())) {
+                apiInfoA = input.getAEndApiInfo();
+            }
+            if (input.getZEndApiInfo() != null && input.getZEndApiInfo().getNodeId().contains(node.getNodeId())) {
+                apiInfoZ = input.getZEndApiInfo();
+            }
+            // check if the node is mounted or not?
+            List<String> createdEthInterfaces = new ArrayList<>();
+            List<String> createdOduInterfaces = new ArrayList<>();
+            switch (input.getServiceRate().intValue()) {
+                case 100:
+                    LOG.info("Input service is 100G");
+                    if (node.getClientTp() != null && node.getNetwork2Tp() == null) {
+                        createdEthInterfaces.add(openRoadmInterfaceFactory.createOpenRoadmEth100GInterface(
+                            node.getNodeId(), node.getClientTp()));
+                        createdOduInterfaces.add(openRoadmInterfaceFactory.createOpenRoadmOdu4HOInterface(
+                                node.getNodeId(), node.getClientTp(), false, apiInfoA, apiInfoZ, "21"));
+                        // supporting interface? payload ?
+                        createdOduInterfaces.add(openRoadmInterfaceFactory.createOpenRoadmOdu4HOInterface(
+                                node.getNodeId(), node.getNetworkTp(), true, null, null, "21"));
+                        linkTpList.add(new LinkTpBuilder().setNodeId(node.getNodeId()).setTpId(node.getClientTp())
+                                .build());
+                    }
+                    if (node.getClientTp() == null && node.getNetwork2Tp() == null) {
+                        createdOduInterfaces.add(openRoadmInterfaceFactory.createOpenRoadmOdu4HOInterface(
+                            node.getNodeId(), node.getNetworkTp(), false, apiInfoA, apiInfoZ, "21"));
+                        linkTpList.add(new LinkTpBuilder().setNodeId(node.getNodeId()).setTpId(node.getNetworkTp())
+                            .build());
+                    }
+                    if (node.getClientTp() == null && node.getNetwork2Tp() != null) {
+                        // supporting interface? payload ?
+                        createdOduInterfaces.add(openRoadmInterfaceFactory.createOpenRoadmOdu4HOInterface(
+                            node.getNodeId(), node.getNetworkTp(), true, null, null, "21"));
+                        createdOduInterfaces.add(openRoadmInterfaceFactory.createOpenRoadmOdu4HOInterface(
+                                node.getNodeId(), node.getNetwork2Tp(), true, null, null, "21"));
+                    }
+                    break;
+                default:
+                    LOG.error("service rate {} not managed yet", input.getServiceRate());
+                    return;
+            }
+
+            // implement cross connect
+            List<String> createdConnections = new ArrayList<>();
+            if (createdOduInterfaces.size() == 2) {
+                Optional<String> connectionNameOpt = postCrossConnect(createdOduInterfaces, node);
+                createdConnections.add(connectionNameOpt.get());
+                LOG.info("Created cross connects");
+            }
+            nodeInterfaces.add(new NodeInterfaceBuilder()
+                    .withKey(new NodeInterfaceKey(node.getNodeId()))
+                    .setNodeId(node.getNodeId())
                     .setConnectionId(createdConnections)
                     .setEthInterfaceId(createdEthInterfaces)
-                    .setOduInterfaceId(createdOduInterfaces);
-            nodeInterfaces.add(nodeInterfaceBuilder.build());
+                    .setOduInterfaceId(createdOduInterfaces)
+                    .build());
+        }
+    }
+
+    private void createOduc4TtpInterface(OtnServicePathInput input, List<NodeInterface> nodeInterfaces,
+        CopyOnWriteArrayList<LinkTp> linkTpList) throws OpenRoadmInterfaceException {
+        if (input.getNodes() == null) {
+            return;
+        }
+        LOG.info("Creation of ODUC4 TTP interface in OTN service path {}", input);
+        for (int i = 0; i < input.getNodes().size(); i++) {
+            Nodes node = input.getNodes().get(i);
+            String supportingOtuInterface = node.getNetworkTp() + "-OTUC4";
+
+            Nodes tgtNode =
+                i + 1 == input.getNodes().size()
+                // For the end node, tgtNode becomes the first node in the list
+                    ? input.getNodes().get(0)
+                    : input.getNodes().get(i + 1);
+
+            nodeInterfaces.add(new NodeInterfaceBuilder()
+                    .withKey(new NodeInterfaceKey(node.getNodeId()))
+                    .setNodeId(node.getNodeId())
+                    .setOduInterfaceId(List.of(
+                        // though this is odu, actually it has ODUC4 interfaces
+                        openRoadmInterfaceFactory.createOpenRoadmOtnOduc4Interface(node.getNodeId(),
+                            node.getNetworkTp(), supportingOtuInterface, tgtNode.getNodeId(), tgtNode.getNetworkTp())))
+                    .build());
+            linkTpList.add(new LinkTpBuilder().setNodeId(node.getNodeId()).setTpId(node.getNetworkTp()).build());
         }
     }
 }