clean OTN renderer code
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / provisiondevice / OtnDeviceRendererServiceImpl.java
index aee77a643d95e6024e619a74809dbe151b95a582..8bb68e95cf6ab0875f468ca9133ad657f7d0e057 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterf
 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;
@@ -103,21 +104,32 @@ public class OtnDeviceRendererServiceImpl implements OtnDeviceRendererService {
             }
             // if the node is currently mounted then proceed.
             if (this.deviceTransactionManager.isDeviceMounted(nodeId)) {
+                String connectionNumber = "";
                 switch (input.getServiceRate()) {
                     case("10G"):
-                        interfacesToDelete.add(srcTp + "-ODU2e-" + input.getServiceName());
-                        interfacesToDelete.add(destTp + "-ODU2e-" + input.getServiceName());
+                        connectionNumber = srcTp + "-ODU2e-" + input.getServiceName() + "-x-" + destTp
+                            + "-ODU2e-" + input.getServiceName();
+                        break;
                     case("1G"):
-                        interfacesToDelete.add(srcTp + "-ODU0-" + input.getServiceName());
-                        interfacesToDelete.add(destTp + "-ODU0-" + input.getServiceName());
+                        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;
                 }
-                String connectionNumber = interfacesToDelete.get(0) + "-x-" + interfacesToDelete.get(1);
-                List<String> intToDelete = this.crossConnect.deleteCrossConnect(nodeId, connectionNumber);
+                List<String> intToDelete = this.crossConnect.deleteCrossConnect(nodeId, connectionNumber, true);
                 if (intToDelete != null) {
                     for (String interf : intToDelete) {
-                        if (!this.openRoadmInterfaceFactory.isUsedbyXc(nodeId, interf, connectionNumber,
-                                this.deviceTransactionManager)) {
+                        if (!this.openRoadmInterfaceFactory.isUsedbyOtnXc(nodeId, interf, connectionNumber,
+                            this.deviceTransactionManager)) {
                             interfacesToDelete.add(interf);
+                            if (!getSupportedInterface(nodeId, interf).contains("ODU4")) {
+                                interfacesToDelete.add(getSupportedInterface(nodeId, interf));
+                            }
                         }
                     }
                 }
@@ -157,85 +169,89 @@ public class OtnDeviceRendererServiceImpl implements OtnDeviceRendererService {
 
     }
 
+    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;
+        }
+    }
+
     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().equals("1G")) {
-            for (Nodes node: input.getNodes()) {
-                LOG.info("Input service is 1G");
-                //check if the node is mounted or not?
-                List<String> createdConnections = new ArrayList<>();
-                List<String> createdEthInterfaces = new ArrayList<>();
-                List<String> createdOduInterfaces = new ArrayList<>();
-                createdEthInterfaces.add(
-                    openRoadmInterfaceFactory.createOpenRoadmEth1GInterface(node.getNodeId(), node.getClientTp()));
-                LOG.debug("created ethernet interface {}",createdEthInterfaces.get(0));
-                createdOduInterfaces.add(
-                    //suppporting interface?, payload ?
-                    openRoadmInterfaceFactory.createOpenRoadmOdu0Interface(node.getNodeId(), node.getClientTp(),
-                        input.getServiceName(), "07", false, input.getTribPortNumber(), input.getTribSlot()));
-                LOG.debug("Created odu interface client side {}",createdOduInterfaces.get(0));
-                createdOduInterfaces.add(
-                    openRoadmInterfaceFactory.createOpenRoadmOdu0Interface(node.getNodeId(), node.getNetworkTp(),
-                        input.getServiceName(), "07", true, input.getTribPortNumber(), input.getTribSlot()));
-                LOG.debug("created odu inteface network side {} {}",createdOduInterfaces.get(0),createdOduInterfaces.get(1));
+        if (input.getServiceRate() == null
+            || !("1G".equals(input.getServiceRate()) || "10G".equals(input.getServiceRate()))) {
+            LOG.error("Service rate {} not managed yet", input.getServiceRate());
+        } else {
+            createLowOrderInterfaces(input, nodeInterfaces);
+        }
+        return nodeInterfaces;
+    }
 
-                //implement cross connect
-                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())
-                        .setConnectionId(createdConnections)
-                        .setEthInterfaceId(createdEthInterfaces)
-                        .setOduInterfaceId(createdOduInterfaces);
-                nodeInterfaces.add(nodeInterfaceBuilder.build());
+    private Optional<String> postCrossConnect(List<String> createdOduInterfaces, Nodes node)
+            throws OpenRoadmInterfaceException {
+        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?
+            List<String> createdEthInterfaces = new ArrayList<>();
+            List<String> createdOduInterfaces = new ArrayList<>();
+            switch (input.getServiceRate()) {
+                case("1G"):
+                    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()));
+                    createdOduInterfaces.add(
+                        openRoadmInterfaceFactory.createOpenRoadmOdu0Interface(node.getNodeId(), node.getNetworkTp(),
+                            input.getServiceName(), "07", true, input.getTribPortNumber(), input.getTribSlot()));
+                    break;
+                case("10G"):
+                    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()));
+                    createdOduInterfaces.add(
+                        // supporting interface? payload ?
+                        openRoadmInterfaceFactory.createOpenRoadmOdu2eInterface(node.getNodeId(), node.getNetworkTp(),
+                            input.getServiceName(),"03" , true ,input.getTribPortNumber(),input.getTribSlot()));
+                    break;
+                default:
+                    LOG.error("service rate {} not managed yet", input.getServiceRate());
+                    return;
             }
-        }
-        else if (input.getServiceRate().equals("10G")) {
-            // implementing ODU2e for now
 
-            for (Nodes node: input.getNodes()) {
-                LOG.info("Input service is 10G");
-                //check if the node is mounted or not?
-                List<String> createdConnections = new ArrayList<>();
-                List<String> createdEthInterfaces = new ArrayList<>();
-                List<String> createdOduInterfaces = new ArrayList<>();
-                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()));
-                createdOduInterfaces.add(
-                    // supporting interface? payload ?
-                    openRoadmInterfaceFactory.createOpenRoadmOdu2eInterface(node.getNodeId(), node.getNetworkTp(),
-                        input.getServiceName(),"03" , true ,input.getTribPortNumber(),input.getTribSlot()));
-                //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");
-                LOG.info("Now creating  node interface builder");
-                NodeInterfaceBuilder nodeInterfaceBuilder = new NodeInterfaceBuilder();
-                LOG.info("Now Created node interface builder");
-                nodeInterfaceBuilder.withKey(new NodeInterfaceKey(input.getServiceName() + "-" + node.getNodeId()));
-                nodeInterfaceBuilder.setNodeId(input.getServiceName() + "-" + node.getNodeId());
-                LOG.info("Now Ids are set");
-                nodeInterfaceBuilder.setConnectionId(createdConnections);
-                LOG.info("Now connections are set");
-                nodeInterfaceBuilder.setEthInterfaceId(createdEthInterfaces);
-                nodeInterfaceBuilder.setOduInterfaceId(createdOduInterfaces);
-                LOG.info("Now Interfaces are set");
-                nodeInterfaces.add(nodeInterfaceBuilder.build());
-                LOG.info("Everythiong is done and now returning ");
             }
+            NodeInterfaceBuilder nodeInterfaceBuilder = new NodeInterfaceBuilder()
+                    .withKey(new NodeInterfaceKey(input.getServiceName() + "-" + node.getNodeId()))
+                    .setNodeId(input.getServiceName() + "-" + node.getNodeId())
+                    .setConnectionId(createdConnections)
+                    .setEthInterfaceId(createdEthInterfaces)
+                    .setOduInterfaceId(createdOduInterfaces);
+            nodeInterfaces.add(nodeInterfaceBuilder.build());
         }
-        return nodeInterfaces;
-    }
-
-    private Optional<String> postCrossConnect(List<String> createdOduInterfaces, Nodes node)
-            throws OpenRoadmInterfaceException {
-        return this.crossConnect.postOtnCrossConnect(createdOduInterfaces,node);
     }
 }