Fix renderer for 100GE on intermediate OTN Switch
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / ModelMappingUtils.java
index 09c6f3391c79a8778f6a92ff94f5b94596f01a34..c349a300b0a5741ed87848956cbbb25353b23801 100644 (file)
@@ -35,12 +35,14 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev1
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyGHz;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyTHz;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.ModulationFormat;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev181130.OpucnTribSlotDef;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInput;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.PathDescription;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirection;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirection;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.atoz.direction.AToZ;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ztoa.direction.ZToA;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.Resource;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.pce.resource.resource.resource.TerminationPoint;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.optical.renderer.nodes.Nodes;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.optical.renderer.nodes.NodesBuilder;
@@ -57,6 +59,7 @@ public final class ModelMappingUtils {
 
     private static final Logger LOG = LoggerFactory.getLogger(ModelMappingUtils.class);
     private static final String TERMINATION_POINT = "TerminationPoint";
+    private static final String LINK = "Link";
 
     private ModelMappingUtils() {
     }
@@ -112,14 +115,14 @@ public final class ModelMappingUtils {
     }
 
     public static ServicePathInputData rendererCreateServiceInputAToZ(String serviceName,
-            PathDescription pathDescription) {
+            PathDescription pathDescription, Action operation) {
         int scale = GridConstant.FIXED_GRID_FREQUENCY_PRECISION;
         AToZDirection atoZDirection = pathDescription.getAToZDirection();
         LOG.info("Building ServicePathInputData for a to z direction {}", atoZDirection);
         NodeLists nodeLists = getNodesListAToZ(atoZDirection.nonnullAToZ().values().iterator());
         ServicePathInputBuilder servicePathInputBuilder = new ServicePathInputBuilder()
             .setServiceName(serviceName)
-            .setOperation(Action.Create)
+            .setOperation(operation)
             .setNodes(nodeLists.getRendererNodeList())
             .setWidth(new FrequencyGHz(GridConstant.WIDTH_40));
         if (atoZDirection.getAToZWavelengthNumber() != null) {
@@ -164,13 +167,13 @@ public final class ModelMappingUtils {
     }
 
     public static ServicePathInputData rendererCreateServiceInputZToA(String serviceName,
-            PathDescription pathDescription) {
+            PathDescription pathDescription, Action operation) {
         int scale = GridConstant.FIXED_GRID_FREQUENCY_PRECISION;
         ZToADirection ztoADirection = pathDescription.getZToADirection();
         LOG.info("Building ServicePathInputData for z to a direction {}", ztoADirection);
         NodeLists nodeLists = getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
         ServicePathInputBuilder servicePathInputBuilder = new ServicePathInputBuilder()
-            .setOperation(Action.Create)
+            .setOperation(operation)
             .setServiceName(serviceName)
             .setNodes(nodeLists.getRendererNodeList())
             .setWidth(new FrequencyGHz(GridConstant.WIDTH_40));
@@ -215,26 +218,30 @@ public final class ModelMappingUtils {
     }
 
     // Adding createOtnServiceInputpath for A-Z and Z-A directions as one method
-    public static OtnServicePathInput rendererCreateOtnServiceInput(String serviceName, String serviceFormat,
-        Uint32 serviceRate, PathDescription pathDescription, boolean asideToZside) {
+    public static OtnServicePathInput rendererCreateOtnServiceInput(String serviceName, Action operation,
+        String serviceFormat, Uint32 serviceRate, PathDescription pathDescription, boolean asideToZside) {
         // If atoZ is set true use A-to-Z direction otherwise use Z-to-A
         List<org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.otn.renderer.nodes.Nodes> nodes =
             new ArrayList<>();
-        NodeLists nodeLists = getNodesListAToZ(pathDescription.getAToZDirection().nonnullAToZ().values().iterator());
-        if (!asideToZside) {
-            nodeLists = getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
-        }
+        NodeLists nodeLists =
+            (asideToZside)
+            ? getNodesListAToZ(pathDescription.getAToZDirection().nonnullAToZ().values().iterator())
+            : getNodesListZtoA(pathDescription.getZToADirection().nonnullZToA().values().iterator());
         LOG.info("These are node-lists {}, {}", nodeLists.getRendererNodeList(), nodeLists.getOlmNodeList());
         for (Nodes node: nodeLists.getRendererNodeList()) {
-            nodes.add(new org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.otn.renderer.nodes
-                .NodesBuilder()
-                            .setNodeId(node.getNodeId())
-                            .setClientTp(node.getSrcTp())
-                            .setNetworkTp(node.getDestTp())
-                            .build());
+            org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.otn.renderer.nodes.NodesBuilder nb
+                = new org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210618.otn.renderer.nodes
+                    .NodesBuilder().setNodeId(node.getNodeId()).setNetworkTp(node.getDestTp());
+            if (node.getSrcTp() != null && node.getSrcTp().contains("NETWORK")) {
+                nb.setNetwork2Tp(node.getSrcTp());
+            } else {
+                nb.setClientTp(node.getSrcTp());
+            }
+            nodes.add(nb.build());
         }
         OtnServicePathInputBuilder otnServicePathInputBuilder = new OtnServicePathInputBuilder()
             .setServiceName(serviceName)
+            .setOperation(operation)
             .setServiceFormat(serviceFormat)
             .setServiceRate(serviceRate)
             .setNodes(nodes);
@@ -249,6 +256,12 @@ public final class ModelMappingUtils {
                 .setTribPortNumber(tribPort)
                 .setTribSlot(minTribSlot);
         }
+        if (serviceRate.intValue() == 100) {
+            List<OpucnTribSlotDef> opucnTribSlotDefList = new ArrayList<>();
+            opucnTribSlotDefList.add(pathDescription.getAToZDirection().getMinTribSlot());
+            opucnTribSlotDefList.add(pathDescription.getAToZDirection().getMaxTribSlot());
+            otnServicePathInputBuilder.setOpucnTribSlots(opucnTribSlotDefList);
+        }
         return otnServicePathInputBuilder.build();
     }
 
@@ -262,47 +275,14 @@ public final class ModelMappingUtils {
         Map<Integer, NodeIdPair> treeMap = new TreeMap<>();
         List<Nodes> olmList = new ArrayList<>();
         List<Nodes> list = new ArrayList<>();
-        String resourceType;
-        TerminationPoint tp;
-        String tpID = "";
-        String nodeID = "";
-        String sortId = "";
+
         while (iterator.hasNext()) {
             ZToA pathDesObj = iterator.next();
-            resourceType = pathDesObj.getResource().getResource().implementedInterface().getSimpleName();
-            LOG.info("Inside ZtoA {}", resourceType);
-
             try {
-                if (TERMINATION_POINT.equals(resourceType)) {
-                    tp = (TerminationPoint) pathDesObj.getResource().getResource();
-                    LOG.info(" TP is {} {}", tp.getTpId(),
-                            tp.getTpNodeId());
-                    tpID = tp.getTpId();
-                    sortId = pathDesObj.getId();
-
-                    //TODO: do not rely on ID to be in certain format
-                    if (tpID.contains("CTP") || tpID.contains("CP")) {
-                        continue;
-                    }
-                    if (tpID.contains(StringConstants.TTP_TOKEN)) {
-                        nodeID = tp.getTpNodeId().split("-DEG")[0];
-                    } else if (tpID.contains(StringConstants.PP_TOKEN)) {
-                        nodeID = tp.getTpNodeId().split("-SRG")[0];
-                    } else if (tpID.contains(StringConstants.NETWORK_TOKEN)
-                        || tpID.contains(StringConstants.CLIENT_TOKEN) || tpID.isEmpty()) {
-                        nodeID = tp.getTpNodeId().split("-XPDR")[0];
-                    } else {
-                        continue;
-                    }
-                    int id = Integer.parseInt(sortId);
-                    treeMap.put(id, new NodeIdPair(nodeID, tpID));
-                } else if ("Link".equals(resourceType)) {
-                    LOG.info("The type is link");
-                } else {
-                    LOG.info("The type is not identified: {}", resourceType);
-                }
+                populateTreeMap(treeMap, pathDesObj.getResource().getResource(), pathDesObj.getId(), "ZtoA");
             } catch (IllegalArgumentException | SecurityException e) {
-                LOG.error("Dont find the getResource method", e);
+                //TODO: Auto-generated catch block
+                LOG.error("Did not find the getResource method", e);
             }
         }
         populateNodeLists(treeMap, list, olmList, false);
@@ -313,45 +293,11 @@ public final class ModelMappingUtils {
         Map<Integer, NodeIdPair> treeMap = new TreeMap<>();
         List<Nodes> list = new ArrayList<>();
         List<Nodes> olmList = new ArrayList<>();
-        String resourceType;
-        TerminationPoint tp;
-        String tpID = "";
-        String nodeID = "";
-        String sortId = "";
 
         while (iterator.hasNext()) {
             AToZ pathDesObj = iterator.next();
-            resourceType = pathDesObj.getResource().getResource().implementedInterface().getSimpleName();
-            LOG.info("Inside AtoZ {}", resourceType);
             try {
-                if (TERMINATION_POINT.equals(resourceType)) {
-                    tp = (TerminationPoint) pathDesObj.getResource().getResource();
-                    LOG.info("TP is {} {}", tp.getTpId(),
-                            tp.getTpNodeId());
-                    tpID = tp.getTpId();
-                    sortId = pathDesObj.getId();
-
-                    //TODO: do not rely on ID to be in certain format
-                    if (tpID.contains("CTP") || tpID.contains("CP")) {
-                        continue;
-                    }
-                    if (tpID.contains(StringConstants.TTP_TOKEN)) {
-                        nodeID = tp.getTpNodeId().split("-DEG")[0];
-                    } else if (tpID.contains(StringConstants.PP_TOKEN)) {
-                        nodeID = tp.getTpNodeId().split("-SRG")[0];
-                    } else if (tpID.contains(StringConstants.NETWORK_TOKEN)
-                        || tpID.contains(StringConstants.CLIENT_TOKEN) || tpID.isEmpty()) {
-                        nodeID = tp.getTpNodeId().split("-XPDR")[0];
-                    } else {
-                        continue;
-                    }
-                    int id = Integer.parseInt(sortId);
-                    treeMap.put(id, new NodeIdPair(nodeID, tpID));
-                } else if ("Link".equals(resourceType)) {
-                    LOG.info("The type is link");
-                } else {
-                    LOG.info("The type is not identified: {}", resourceType);
-                }
+                populateTreeMap(treeMap, pathDesObj.getResource().getResource(), pathDesObj.getId(), "AtoZ");
             } catch (IllegalArgumentException | SecurityException e) {
                 //TODO: Auto-generated catch block
                 LOG.error("Did not find the getResource method", e);
@@ -361,12 +307,49 @@ public final class ModelMappingUtils {
         return new NodeLists(olmList, list);
     }
 
+    private static void populateTreeMap(Map<Integer, NodeIdPair> treeMap, Resource rsrc, String sortId,
+            String direction) {
+        String resourceType = rsrc.implementedInterface().getSimpleName();
+        LOG.info("Inside {} {}", direction, resourceType);
+        switch (resourceType) {
+            case TERMINATION_POINT:
+                TerminationPoint tp = (TerminationPoint) rsrc;
+                LOG.info(" TP is {} {}", tp.getTpId(), tp.getTpNodeId());
+                String tpID = tp.getTpId();
+
+                //TODO: do not rely on ID to be in certain format
+                if (tpID.contains("CTP") || tpID.contains("CP")) {
+                    return;
+                }
+                String nodeID = "";
+                if (tpID.contains(StringConstants.TTP_TOKEN)) {
+                    nodeID = tp.getTpNodeId().split("-DEG")[0];
+                } else if (tpID.contains(StringConstants.PP_TOKEN)) {
+                    nodeID = tp.getTpNodeId().split("-SRG")[0];
+                } else if (tpID.contains(StringConstants.NETWORK_TOKEN)
+                        || tpID.contains(StringConstants.CLIENT_TOKEN) || tpID.isEmpty()) {
+                    nodeID = tp.getTpNodeId().split("-XPDR")[0];
+                } else {
+                    return;
+                }
+                int id = Integer.parseInt(sortId);
+                treeMap.put(id, new NodeIdPair(nodeID, tpID));
+                return;
+            case LINK:
+                LOG.info("The type is link");
+                return;
+            default:
+                LOG.info("The type is not identified: {}", resourceType);
+                return;
+        }
+    }
+
     @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
         value = {"NP_LOAD_OF_KNOWN_NULL_VALUE","RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"},
         justification = "loop when value is not always null - "
                 + "TODO: check if something exists in Java lib")
     private static void populateNodeLists(Map<Integer, NodeIdPair> treeMap, List<Nodes> list, List<Nodes> olmList,
-        boolean isAToz) {
+            boolean isAToz) {
         String desID = null;
         String srcID = null;
         LOG.info("treeMap values = {}", treeMap.values());
@@ -409,7 +392,7 @@ public final class ModelMappingUtils {
                 srcID = null;
                 desID = null;
             } else {
-                LOG.warn("both, the source and destination id are null!");
+                LOG.warn("both, the source and destination id are not null!");
             }
         }
     }
@@ -417,7 +400,7 @@ public final class ModelMappingUtils {
 
     @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
             value = "PZLA_PREFER_ZERO_LENGTH_ARRAYS",
-            justification = "not relevant to return and zero length array"
+            justification = "not relevant to return a zero length array"
                     + " as we need real pos")
     public static int[] findTheLongestSubstring(String s1, String s2) {
         if ((s1 == null) || (s2 == null)) {