OTN Renderer Consolidation
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / openroadminterface / OpenRoadmOtnInterface221.java
similarity index 76%
rename from renderer/src/main/java/org/opendaylight/transportpce/renderer/openroadminterface/OpenRoadmOTNInterface.java
rename to renderer/src/main/java/org/opendaylight/transportpce/renderer/openroadminterface/OpenRoadmOtnInterface221.java
index 187c842cb4966600a123dce8cdfd66fbe79a35ff..997a76c0945e456ecb12c33385bc8807c4bc9ea5 100644 (file)
@@ -9,6 +9,8 @@ package org.opendaylight.transportpce.renderer.openroadminterface;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.IntStream;
+
 import org.opendaylight.transportpce.common.mapping.PortMapping;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
@@ -16,7 +18,6 @@ import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmappi
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.InterfaceBuilder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.InterfaceKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev171215.AdminStates;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev181019.EthAttributes;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev181019.Interface1;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev181019.Interface1Builder;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev181019.ethernet.container.EthernetBuilder;
@@ -37,13 +38,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
-public class OpenRoadmOTNInterface {
+public class OpenRoadmOtnInterface221 {
 
     private final PortMapping portMapping;
     private final OpenRoadmInterfaces openRoadmInterfaces;
-    private static final Logger LOG = LoggerFactory.getLogger(OpenRoadmInterfaceFactory.class);
+    private static final Logger LOG = LoggerFactory.getLogger(OpenRoadmOtnInterface221.class);
 
-    public  OpenRoadmOTNInterface(PortMapping portMapping, OpenRoadmInterfaces openRoadmInterfaces) {
+    public  OpenRoadmOtnInterface221(PortMapping portMapping, OpenRoadmInterfaces openRoadmInterfaces) {
         this.portMapping = portMapping;
         this.openRoadmInterfaces = openRoadmInterfaces;
     }
@@ -52,17 +53,15 @@ public class OpenRoadmOTNInterface {
             throws OpenRoadmInterfaceException {
         Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
         if (portMap == null) {
-            throw new OpenRoadmInterfaceException(String.format("Unable to get mapping from PortMapping for node % and"
-                    + " logical connection port %s", nodeId, logicalConnPoint));
+            throw new OpenRoadmInterfaceException(String.format(
+                "Unable to get mapping from PortMapping for node % and logical connection port %s",
+                nodeId, logicalConnPoint));
         }
 
         // Ethernet interface specific data
-        EthernetBuilder ethIfBuilder = new EthernetBuilder()
-            .setAutoNegotiation(EthAttributes.AutoNegotiation.Disabled)
-            .setSpeed(1000L)
-            .setMtu(9000L);
-            //.setCurrSpeed("1000L")
-            //.setCurrDuplex("FULL");
+        EthernetBuilder ethIfBuilder = new EthernetBuilder();
+        //ethIfBuilder.setAutoNegotiation(EthAttributes.AutoNegotiation.Disabled);
+        ethIfBuilder.setSpeed(1000L);
         InterfaceBuilder ethInterfaceBldr =
             createGenericInterfaceBuilder(portMap, EthernetCsmacd.class, logicalConnPoint + "-ETHERNET1G");
         // Create Interface1 type object required for adding as augmentation
@@ -79,7 +78,7 @@ public class OpenRoadmOTNInterface {
     }
 
     private InterfaceBuilder createGenericInterfaceBuilder(Mapping portMap,
-        Class<? extends InterfaceType> type, String key) {
+            Class<? extends InterfaceType> type, String key) {
         InterfaceBuilder interfaceBuilder = new InterfaceBuilder()
             //.setDescription("  TBD   ")
             //.setCircuitId("   TBD    ")
@@ -108,11 +107,8 @@ public class OpenRoadmOTNInterface {
 
         // Ethernet interface specific data
         EthernetBuilder ethIfBuilder = new EthernetBuilder()
-            .setAutoNegotiation(EthAttributes.AutoNegotiation.Disabled)
-            .setSpeed(10000L)
-            .setMtu(9000L);
-            //.setCurrSpeed("1000L")
-            //.setCurrDuplex("FULL");
+            //.setAutoNegotiation(EthAttributes.AutoNegotiation.Disabled)
+            .setSpeed(10000L);
         // Create Interface1 type object required for adding as augmentation
         Interface1Builder ethIf1Builder = new  Interface1Builder();
         InterfaceBuilder ethInterfaceBldr =
@@ -129,24 +125,29 @@ public class OpenRoadmOTNInterface {
     }
 
 
-    public String createOpenRoadmOdu2eInterface(String nodeId, String logicalConnPoint, String serviceName,
-            String payLoad, boolean isNetworkPort)
+    public String createOpenRoadmOdu2eInterface(
+            String nodeId, String logicalConnPoint, String serviceName,
+            String payLoad, boolean isNetworkPort, int tribPortNumber, int tribSlotIndex)
             throws OpenRoadmInterfaceException {
         Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
         if (portMap == null) {
-            throw new OpenRoadmInterfaceException(
-                String.format("Unable to get mapping from PortMapping for node % and logical connection port %s",
-                    nodeId, logicalConnPoint));
+            throw new OpenRoadmInterfaceException(String.format(
+                "Unable to get mapping from PortMapping for node % and logical connection port %s",
+                nodeId, logicalConnPoint));
         }
         String supportingInterface = null;
 
         if (isNetworkPort) {
             supportingInterface = portMap.getSupportingOdu4();
-
         } else {
-            // supportingInterface = portMap.getSupportingEthernet();
             supportingInterface = logicalConnPoint + "-ETHERNET10G";
         }
+
+        if (supportingInterface == null) {
+            throw new OpenRoadmInterfaceException(
+                "Interface Creation failed because of missing supported ODU4 on network end or Eth iface on client");
+        }
+
         InterfaceBuilder oduInterfaceBldr =
             createGenericInterfaceBuilder(portMap, OtnOdu.class, logicalConnPoint + "-ODU2e-" + serviceName)
                 .setSupportingInterface(supportingInterface);
@@ -156,31 +157,32 @@ public class OpenRoadmOTNInterface {
             .setRate(ODU2e.class)
             .setOduFunction(ODUTTPCTP.class)
             .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
+        LOG.debug("Inside the ODU2e creation {} {} {}",isNetworkPort,tribPortNumber,tribSlotIndex);
         if (isNetworkPort) {
             List<Integer> tribSlots = new ArrayList<>();
-            //add trib slots
-            tribSlots.add(45);
+            int newIdx = tribSlotIndex;
+            tribSlots.add(newIdx);
+            IntStream.range(tribSlotIndex, tribSlotIndex + 8).forEach(
+                nbr -> tribSlots.add(nbr)
+            );
             ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
-                //set trib port numbers
-                .setTribPortNumber(24)
+                .setTribPortNumber(tribPortNumber)
                 .setTribSlots(tribSlots);
             oduIfBuilder.setOduFunction(ODUCTP.class)
-                    .setMonitoringMode(OduAttributes.MonitoringMode.NotTerminated)
+                    .setMonitoringMode(OduAttributes.MonitoringMode.Monitored)
                     .setParentOduAllocation(parentOduAllocationBuilder.build());
         }
         else {
             // Set Opu attributes
             OpuBuilder opuBldr = new OpuBuilder()
-                .setPayloadType(new PayloadTypeDef(payLoad))
-                .setExpPayloadType(new PayloadTypeDef(payLoad));
-                //.setRxPayloadType("07")
-                //.setPayloadInterface(payLoad);
+                    .setPayloadType(new PayloadTypeDef(payLoad))
+                    .setExpPayloadType(new PayloadTypeDef(payLoad));
             oduIfBuilder.setOpu(opuBldr.build());
         }
         // Create Interface1 type object required for adding as augmentation
         // TODO look at imports of different versions of class
         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder oduIf1Builder =
-            new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
+                new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
         oduInterfaceBldr.addAugmentation(
                 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1.class,
                 oduIf1Builder.setOdu(oduIfBuilder.build()).build());
@@ -191,8 +193,8 @@ public class OpenRoadmOTNInterface {
         return oduInterfaceBldr.getName();
     }
 
-    public String createOpenRoadmOdu0Interface(String nodeId, String logicalConnPoint, String serviceName,
-        String payLoad, boolean isNetworkPort, int tribPortNumber, int tribSlot)
+    public String createOpenRoadmOdu0Interface(String nodeId, String logicalConnPoint,
+            String serviceName, String payLoad, boolean isNetworkPort, int tribPortNumber, int tribSlot)
             throws OpenRoadmInterfaceException {
         Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
         String supportingInterface = null;
@@ -200,16 +202,15 @@ public class OpenRoadmOTNInterface {
         if (isNetworkPort) {
             supportingInterface = portMap.getSupportingOdu4();
         } else {
-            // supportingInterface = portMap.getSupportingEthernet();
             supportingInterface = logicalConnPoint + "-ETHERNET1G";
         }
         if (portMap == null) {
-            throw new OpenRoadmInterfaceException(
-                String.format("Unable to get mapping from PortMapping for node % and logical connection port %s",
-                    nodeId, logicalConnPoint));
+            throw new OpenRoadmInterfaceException(String.format(
+                "Unable to get mapping from PortMapping for node % and logical connection port %s",
+                nodeId, logicalConnPoint));
         }
-        InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(portMap, OtnOdu.class, logicalConnPoint
-                + "-ODU0-" + serviceName);
+        InterfaceBuilder oduInterfaceBldr =
+            createGenericInterfaceBuilder(portMap, OtnOdu.class, logicalConnPoint + "-ODU0-" + serviceName);
         oduInterfaceBldr.setSupportingInterface(supportingInterface);
 
         // ODU interface specific data
@@ -218,6 +219,7 @@ public class OpenRoadmOTNInterface {
             .setOduFunction(ODUTTPCTP.class)
             .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
         if (isNetworkPort) {
+            LOG.debug("Network port is true");
             List<Integer> tribSlots = new ArrayList<>();
             tribSlots.add(tribSlot); //add trib slots
             ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
@@ -225,25 +227,27 @@ public class OpenRoadmOTNInterface {
                     .setTribPortNumber(tribPortNumber)
                     .setTribSlots(tribSlots);
             oduIfBuilder.setOduFunction(ODUCTP.class)
-                    .setMonitoringMode(OduAttributes.MonitoringMode.NotTerminated)
+                    .setMonitoringMode(OduAttributes.MonitoringMode.Monitored)
                     .setParentOduAllocation(parentOduAllocationBuilder.build());
+            LOG.debug("Network port is true {} {} {}",
+                    oduIfBuilder.getParentOduAllocation().getTribSlots(),
+                    oduIfBuilder.getRate(),
+                    oduIfBuilder.getParentOduAllocation().getTribPortNumber());
         }
         else {
-            // Set Opu attributes
+            LOG.debug("Current port is a client port");
             OpuBuilder opuBldr = new OpuBuilder()
-                .setPayloadType(new PayloadTypeDef(payLoad))
-                .setExpPayloadType(new PayloadTypeDef(payLoad));
-                //.setRxPayloadType("07")
-                //.setPayloadInterface(payLoad);
+                    .setPayloadType(new PayloadTypeDef(payLoad))
+                    .setExpPayloadType(new PayloadTypeDef(payLoad));
             oduIfBuilder.setOpu(opuBldr.build());
         }
         // Create Interface1 type object required for adding as augmentation
         // TODO look at imports of different versions of class
         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder oduIf1Builder =
-            new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
+                new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
         oduInterfaceBldr.addAugmentation(
-            org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1.class,
-            oduIf1Builder.setOdu(oduIfBuilder.build()).build());
+                org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1.class,
+                oduIf1Builder.setOdu(oduIfBuilder.build()).build());
 
         // Post interface on the device
         this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
@@ -251,21 +255,24 @@ public class OpenRoadmOTNInterface {
         return oduInterfaceBldr.getName();
     }
 
-    public String createOpenRoadmOdu2Interface(String nodeId, String logicalConnPoint, String serviceName,
-            String payLoad, boolean isNetworkPort)
+
+    public String createOpenRoadmOdu2Interface(
+            String nodeId, String logicalConnPoint, String serviceName,
+            String payLoad, boolean isNetworkPort, int tribPortNumber, int tribSlotIndex)
             throws OpenRoadmInterfaceException {
         Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
         String supportingInterface = null;
-        if (portMap == null) {
-            throw new OpenRoadmInterfaceException(
-                String.format("Unable to get mapping from PortMapping for node % and logical connection port %s",
-                    nodeId, logicalConnPoint));
-        }
+
         if (isNetworkPort) {
             supportingInterface = portMap.getSupportingOdu4();
         } else {
             supportingInterface = portMap.getSupportingEthernet();
         }
+        if (portMap == null) {
+            throw new OpenRoadmInterfaceException(
+                String.format("Unable to get mapping from PortMapping for node % and logical connection port %s",
+                        nodeId, logicalConnPoint));
+        }
         InterfaceBuilder oduInterfaceBldr =
             createGenericInterfaceBuilder(portMap, OtnOdu.class, logicalConnPoint + "-ODU2-" + serviceName)
                 .setSupportingInterface(supportingInterface);
@@ -276,22 +283,22 @@ public class OpenRoadmOTNInterface {
             .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
         if (isNetworkPort) {
             List<Integer> tribSlots = new ArrayList<>();
-            tribSlots.add(45); //add trib slots
+            IntStream.range(tribSlotIndex, tribSlotIndex + 8).forEach(
+                nbr -> tribSlots.add(nbr)
+            );
             ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
                     //set trib port numbers
-                    .setTribPortNumber(24)
+                    .setTribPortNumber(tribPortNumber)
                     .setTribSlots(tribSlots);
             oduIfBuilder.setOduFunction(ODUCTP.class)
-                    .setMonitoringMode(OduAttributes.MonitoringMode.NotTerminated)
+                    .setMonitoringMode(OduAttributes.MonitoringMode.Monitored)
                     .setParentOduAllocation(parentOduAllocationBuilder.build());
         }
         else {
             // Set Opu attributes
             OpuBuilder opuBldr = new OpuBuilder()
-                .setPayloadType(new PayloadTypeDef(payLoad))
-                .setExpPayloadType(new PayloadTypeDef(payLoad));
-                //.setRxPayloadType("07")
-                //.setPayloadInterface(payLoad);
+                    .setPayloadType(new PayloadTypeDef(payLoad))
+                    .setExpPayloadType(new PayloadTypeDef(payLoad));
             oduIfBuilder.setOpu(opuBldr.build());
         }
 
@@ -300,10 +307,10 @@ public class OpenRoadmOTNInterface {
         // Create Interface1 type object required for adding as augmentation
         // TODO look at imports of different versions of class
         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder oduIf1Builder =
-            new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
+                new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
         oduInterfaceBldr.addAugmentation(
-            org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1.class,
-            oduIf1Builder.setOdu(oduIfBuilder.build()).build());
+                org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1.class,
+                oduIf1Builder.setOdu(oduIfBuilder.build()).build());
 
         // Post interface on the device
         this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);