Refactor SupportedIfCapability usage
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / openroadminterface / OpenRoadmOtnInterface221.java
index 538bd2ee897514b82c584a3332bd6ad35c7d79d8..46a163a94cc9eacc808093cfbe7efebfcb2ac7b3 100644 (file)
@@ -10,15 +10,15 @@ 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;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200128.network.nodes.Mapping;
+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.opendaylight.transportpce.portmapping.rev220316.mapping.Mapping;
 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.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;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.EthernetCsmacd;
@@ -29,18 +29,24 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev17121
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODU2e;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODUCTP;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODUTTPCTP;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.OduFunctionIdentity;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.PayloadTypeDef;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.OduAttributes;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.OduAttributes.MonitoringMode;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.odu.container.OduBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.opu.Opu;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.opu.OpuBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.parent.odu.allocation.ParentOduAllocation;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.parent.odu.allocation.ParentOduAllocationBuilder;
 import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
 public class OpenRoadmOtnInterface221 {
 
+    private static final String MAPPING_ERROR_EXCEPTION_MESSAGE =
+        "Unable to get mapping from PortMapping for node % and logical connection port %s";
     private final PortMapping portMapping;
     private final OpenRoadmInterfaces openRoadmInterfaces;
     private static final Logger LOG = LoggerFactory
@@ -60,15 +66,14 @@ public class OpenRoadmOtnInterface221 {
         }
 
         // Ethernet interface specific data
-        EthernetBuilder ethIfBuilder = new EthernetBuilder();
-        ethIfBuilder.setSpeed(1000L);
+        EthernetBuilder ethIfBuilder = new EthernetBuilder()
+                .setSpeed(Uint32.valueOf(1000));
         InterfaceBuilder ethInterfaceBldr = createGenericInterfaceBuilder(
                 portMap, EthernetCsmacd.class,
                 logicalConnPoint + "-ETHERNET1G");
         // Create Interface1 type object required for adding as augmentation
         Interface1Builder ethIf1Builder = new Interface1Builder();
-        ethInterfaceBldr.addAugmentation(Interface1.class,
-                ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
+        ethInterfaceBldr.addAugmentation(ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
         // Post interface on the device
         this.openRoadmInterfaces.postOTNInterface(nodeId, ethInterfaceBldr);
         // Post the equipment-state change on the device circuit-pack
@@ -89,7 +94,7 @@ public class OpenRoadmOtnInterface221 {
 
     private InterfaceBuilder createGenericInterfaceBuilder(Mapping portMap,
             Class<? extends InterfaceType> type, String key) {
-        InterfaceBuilder interfaceBuilder = new InterfaceBuilder()
+        return new InterfaceBuilder()
                 // .setDescription(" TBD ")
                 // .setCircuitId(" TBD ")
                 .setSupportingCircuitPackName(
@@ -98,7 +103,6 @@ public class OpenRoadmOtnInterface221 {
                 .setAdministrativeState(AdminStates.InService)
                 // TODO get rid of unchecked cast warning
                 .setType(type).setName(key).withKey(new InterfaceKey(key));
-        return interfaceBuilder;
     }
 
     public String createOpenRoadmEth10GInterface(String nodeId,
@@ -111,12 +115,12 @@ public class OpenRoadmOtnInterface221 {
         // Ethernet interface specific data
         EthernetBuilder ethIfBuilder = new EthernetBuilder()
                 // .setAutoNegotiation(EthAttributes.AutoNegotiation.Disabled)
-                .setSpeed(10000L);
+                .setSpeed(Uint32.valueOf(10000));
         // Create Interface1 type object required for adding as augmentation
         Interface1Builder ethIf1Builder = new Interface1Builder();
         InterfaceBuilder ethInterfaceBldr = createGenericInterfaceBuilder(portMap, EthernetCsmacd.class,
-                logicalConnPoint + "-ETHERNET10G").addAugmentation(Interface1.class,
-                        ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
+                logicalConnPoint + "-ETHERNET10G").addAugmentation(ethIf1Builder.setEthernet(ethIfBuilder.build())
+                        .build());
         // Post interface on the device
         this.openRoadmInterfaces.postOTNInterface(nodeId, ethInterfaceBldr);
         // Post the equipment-state change on the device circuit-pack
@@ -128,189 +132,231 @@ public class OpenRoadmOtnInterface221 {
         return ethernetInterfaceName;
     }
 
-    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) {
-            throwException(nodeId, logicalConnPoint);
-        }
-        String supportingInterface = null;
-
-        if (isNetworkPort) {
-            supportingInterface = portMap.getSupportingOdu4();
-        } else {
-            supportingInterface = logicalConnPoint + "-ETHERNET10G";
-        }
+    public String createOpenRoadmOdu2eInterface(String nodeId, String logicalConnPoint, String serviceName,
+            boolean isCTP, int tribPortNumber, int tribSlotIndex, AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ,
+            String payloadType) throws OpenRoadmInterfaceException {
 
-        if (supportingInterface == null) {
+        Mapping mapping = this.portMapping.getMapping(nodeId, logicalConnPoint);
+        if (mapping == null) {
             throw new OpenRoadmInterfaceException(
-                    "Interface Creation failed because of missing supported "
-                    + "ODU4 on network end or Eth iface on client");
+                String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
+        }
+        InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(mapping, OtnOdu.class,
+            logicalConnPoint + "-ODU2e-" + serviceName);
+        if (mapping.getSupportingOdu4() != null) {
+            oduInterfaceBldr.setSupportingInterface(mapping.getSupportingOdu4());
+        }
+        if (mapping.getSupportingEthernet() != null) {
+            oduInterfaceBldr.setSupportingInterface(mapping.getSupportingEthernet());
         }
 
-        InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(
-                portMap, OtnOdu.class,
-                logicalConnPoint + "-ODU2e-" + serviceName)
-                        .setSupportingInterface(supportingInterface);
-
-        // ODU interface specific data
-        OduBuilder oduIfBuilder = new OduBuilder().setRate(ODU2e.class)
-                .setOduFunction(ODUTTPCTP.class)
-                .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
-        LOG.debug("Inside the ODU2e creation {} {} {}", isNetworkPort,
-                tribPortNumber, tribSlotIndex);
-        if (isNetworkPort) {
+        Class<? extends OduFunctionIdentity> oduFunction;
+        MonitoringMode monitoringMode;
+        Opu opu = null;
+        ParentOduAllocation parentOduAllocation = null;
+        if (isCTP) {
+            oduFunction = ODUCTP.class;
+            monitoringMode = MonitoringMode.Monitored;
             List<Uint16> tribSlots = new ArrayList<>();
             Uint16 newIdx = Uint16.valueOf(tribSlotIndex);
             tribSlots.add(newIdx);
             IntStream.range(tribSlotIndex, tribSlotIndex + 8)
                     .forEach(nbr -> tribSlots.add(Uint16.valueOf(nbr)));
-            ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
-                    .setTribPortNumber(tribPortNumber).setTribSlots(tribSlots);
-            oduIfBuilder.setOduFunction(ODUCTP.class)
-                    .setMonitoringMode(OduAttributes.MonitoringMode.Monitored)
-                    .setParentOduAllocation(parentOduAllocationBuilder.build());
+            parentOduAllocation = new ParentOduAllocationBuilder()
+                    .setTribPortNumber(Uint16.valueOf(tribPortNumber))
+                    .setTribSlots(tribSlots)
+                    .build();
         } else {
-            // Set Opu attributes
-            OpuBuilder opuBldr = new OpuBuilder()
-                    .setPayloadType(new PayloadTypeDef(payLoad))
-                    .setExpPayloadType(new PayloadTypeDef(payLoad));
-            oduIfBuilder.setOpu(opuBldr.build());
+            oduFunction = ODUTTPCTP.class;
+            monitoringMode = MonitoringMode.Terminated;
+            opu = new OpuBuilder()
+                .setPayloadType(PayloadTypeDef.getDefaultInstance(payloadType))
+                .setExpPayloadType(PayloadTypeDef.getDefaultInstance(payloadType))
+                .build();
+        }
+        OduBuilder oduIfBuilder = new OduBuilder()
+            .setRate(ODU2e.class)
+            .setOduFunction(oduFunction)
+            .setMonitoringMode(monitoringMode)
+            .setOpu(opu)
+            .setParentOduAllocation(parentOduAllocation);
+        if (apiInfoA != null) {
+            oduIfBuilder.setTxSapi(apiInfoA.getSapi())
+                .setTxDapi(apiInfoA.getDapi())
+                .setExpectedSapi(apiInfoA.getExpectedSapi())
+                .setExpectedDapi(apiInfoA.getExpectedDapi());
+        }
+        if (apiInfoZ != null) {
+            oduIfBuilder.setTxSapi(apiInfoZ.getSapi())
+                .setTxDapi(apiInfoZ.getDapi())
+                .setExpectedSapi(apiInfoZ.getExpectedSapi())
+                .setExpectedDapi(apiInfoZ.getExpectedDapi());
         }
         // 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();
-        oduInterfaceBldr.addAugmentation(
-                org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1.class,
-                oduIf1Builder.setOdu(oduIfBuilder.build()).build());
+        oduInterfaceBldr.addAugmentation(oduIf1Builder.setOdu(oduIfBuilder.build()).build());
 
         // Post interface on the device
         this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
-        LOG.info("returning the ODU2e inteface {}", oduInterfaceBldr.getName());
+        if (!isCTP) {
+            LOG.info("{}-{} updating mapping with interface {}", nodeId, logicalConnPoint, oduInterfaceBldr.getName());
+            this.portMapping.updateMapping(nodeId, mapping);
+        }
         return oduInterfaceBldr.getName();
     }
 
-    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;
+    public String createOpenRoadmOdu0Interface(String nodeId, String logicalConnPoint, String serviceName,
+            boolean isCTP, int tribPortNumber, int tribSlotIndex, AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ,
+            String payloadType) throws OpenRoadmInterfaceException {
 
-        if (isNetworkPort) {
-            supportingInterface = portMap.getSupportingOdu4();
-        } else {
-            supportingInterface = logicalConnPoint + "-ETHERNET1G";
+        Mapping mapping = this.portMapping.getMapping(nodeId, logicalConnPoint);
+        if (mapping == null) {
+            throw new OpenRoadmInterfaceException(
+                String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
         }
-        if (portMap == null) {
-            throwException(nodeId, logicalConnPoint);
+        InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(mapping, OtnOdu.class,
+            logicalConnPoint + "-ODU0-" + serviceName);
+        if (mapping.getSupportingOdu4() != null) {
+            oduInterfaceBldr.setSupportingInterface(mapping.getSupportingOdu4());
+        }
+        if (mapping.getSupportingEthernet() != null) {
+            oduInterfaceBldr.setSupportingInterface(mapping.getSupportingEthernet());
         }
-        InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(
-                portMap, OtnOdu.class,
-                logicalConnPoint + "-ODU0-" + serviceName);
-        oduInterfaceBldr.setSupportingInterface(supportingInterface);
 
-        // ODU interface specific data
-        OduBuilder oduIfBuilder = new OduBuilder().setRate(ODU0.class)
-                .setOduFunction(ODUTTPCTP.class)
-                .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
-        if (isNetworkPort) {
-            LOG.debug("Network port is true");
+        Class<? extends OduFunctionIdentity> oduFunction;
+        MonitoringMode monitoringMode;
+        Opu opu = null;
+        ParentOduAllocation parentOduAllocation = null;
+        if (isCTP) {
+            oduFunction = ODUCTP.class;
+            monitoringMode = MonitoringMode.Monitored;
             List<Uint16> tribSlots = new ArrayList<>();
-            // add trib slots
-            tribSlots.add(Uint16.valueOf(tribSlot));
-            ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
-                    // set trib port numbers
-                    .setTribPortNumber(tribPortNumber).setTribSlots(tribSlots);
-            oduIfBuilder.setOduFunction(ODUCTP.class)
-                    .setMonitoringMode(OduAttributes.MonitoringMode.Monitored)
-                    .setParentOduAllocation(parentOduAllocationBuilder.build());
-            LOG.debug("Network port is true {} {} {}",
-                    oduIfBuilder.getParentOduAllocation().getTribSlots(),
-                    oduIfBuilder.getRate(),
-                    oduIfBuilder.getParentOduAllocation().getTribPortNumber());
+            Uint16 newIdx = Uint16.valueOf(tribSlotIndex);
+            tribSlots.add(newIdx);
+            IntStream.range(tribSlotIndex, tribSlotIndex + 8)
+                    .forEach(nbr -> tribSlots.add(Uint16.valueOf(nbr)));
+            parentOduAllocation = new ParentOduAllocationBuilder()
+                    .setTribPortNumber(Uint16.valueOf(tribPortNumber))
+                    .setTribSlots(tribSlots)
+                    .build();
         } else {
-            LOG.debug("Current port is a client port");
-            OpuBuilder opuBldr = new OpuBuilder()
-                    .setPayloadType(new PayloadTypeDef(payLoad))
-                    .setExpPayloadType(new PayloadTypeDef(payLoad));
-            oduIfBuilder.setOpu(opuBldr.build());
+            oduFunction = ODUTTPCTP.class;
+            monitoringMode = MonitoringMode.Terminated;
+            opu = new OpuBuilder()
+                .setPayloadType(PayloadTypeDef.getDefaultInstance(payloadType))
+                .setExpPayloadType(PayloadTypeDef.getDefaultInstance(payloadType))
+                .build();
+        }
+        OduBuilder oduIfBuilder = new OduBuilder()
+            .setRate(ODU0.class)
+            .setOduFunction(oduFunction)
+            .setMonitoringMode(monitoringMode)
+            .setOpu(opu)
+            .setParentOduAllocation(parentOduAllocation);
+        if (apiInfoA != null) {
+            oduIfBuilder.setTxSapi(apiInfoA.getSapi())
+                .setTxDapi(apiInfoA.getDapi())
+                .setExpectedSapi(apiInfoA.getExpectedSapi())
+                .setExpectedDapi(apiInfoA.getExpectedDapi());
+        }
+        if (apiInfoZ != null) {
+            oduIfBuilder.setTxSapi(apiInfoZ.getSapi())
+                .setTxDapi(apiInfoZ.getDapi())
+                .setExpectedSapi(apiInfoZ.getExpectedSapi())
+                .setExpectedDapi(apiInfoZ.getExpectedDapi());
         }
         // 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();
-        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.Interface1Builder();
+        oduInterfaceBldr.addAugmentation(oduIf1Builder.setOdu(oduIfBuilder.build()).build());
 
         // Post interface on the device
         this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
-        LOG.info("returning the ODU0 inteface {}", oduInterfaceBldr.getName());
+        if (!isCTP) {
+            LOG.info("{}-{} updating mapping with interface {}", nodeId, logicalConnPoint, oduInterfaceBldr.getName());
+            this.portMapping.updateMapping(nodeId, mapping);
+        }
         return oduInterfaceBldr.getName();
     }
 
-    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;
+    public String createOpenRoadmOdu2Interface(String nodeId, String logicalConnPoint, String serviceName,
+            boolean isCTP, int tribPortNumber, int tribSlotIndex, AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ,
+            String payloadType) throws OpenRoadmInterfaceException {
 
-        if (portMap != null) {
-            if (isNetworkPort) {
-                supportingInterface = portMap.getSupportingOdu4();
-            } else {
-                supportingInterface = portMap.getSupportingEthernet();
-            }
-        } else {
-            throwException(nodeId, logicalConnPoint);
+        Mapping mapping = this.portMapping.getMapping(nodeId, logicalConnPoint);
+        if (mapping == null) {
+            throw new OpenRoadmInterfaceException(
+                String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
+        }
+        InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(mapping, OtnOdu.class,
+            logicalConnPoint + "-ODU2-" + serviceName);
+        if (mapping.getSupportingOdu4() != null) {
+            oduInterfaceBldr.setSupportingInterface(mapping.getSupportingOdu4());
+        }
+        if (mapping.getSupportingEthernet() != null) {
+            oduInterfaceBldr.setSupportingInterface(mapping.getSupportingEthernet());
         }
-        InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(
-                portMap, OtnOdu.class,
-                logicalConnPoint + "-ODU2-" + serviceName)
-                        .setSupportingInterface(supportingInterface);
 
-        OduBuilder oduIfBuilder = new OduBuilder().setRate(ODU2.class)
-                .setOduFunction(ODUTTPCTP.class)
-                .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
-        if (isNetworkPort) {
+        Class<? extends OduFunctionIdentity> oduFunction;
+        MonitoringMode monitoringMode;
+        Opu opu = null;
+        ParentOduAllocation parentOduAllocation = null;
+        if (isCTP) {
+            oduFunction = ODUCTP.class;
+            monitoringMode = MonitoringMode.Monitored;
             List<Uint16> tribSlots = new ArrayList<>();
+            Uint16 newIdx = Uint16.valueOf(tribSlotIndex);
+            tribSlots.add(newIdx);
             IntStream.range(tribSlotIndex, tribSlotIndex + 8)
                     .forEach(nbr -> tribSlots.add(Uint16.valueOf(nbr)));
-            ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
-                    // set trib port numbers
-                    .setTribPortNumber(tribPortNumber).setTribSlots(tribSlots);
-            oduIfBuilder.setOduFunction(ODUCTP.class)
-                    .setMonitoringMode(OduAttributes.MonitoringMode.Monitored)
-                    .setParentOduAllocation(parentOduAllocationBuilder.build());
+            parentOduAllocation = new ParentOduAllocationBuilder()
+                    .setTribPortNumber(Uint16.valueOf(tribPortNumber))
+                    .setTribSlots(tribSlots)
+                    .build();
         } else {
-            // Set Opu attributes
-            OpuBuilder opuBldr = new OpuBuilder()
-                    .setPayloadType(new PayloadTypeDef(payLoad))
-                    .setExpPayloadType(new PayloadTypeDef(payLoad));
-            oduIfBuilder.setOpu(opuBldr.build());
+            oduFunction = ODUTTPCTP.class;
+            monitoringMode = MonitoringMode.Terminated;
+            opu = new OpuBuilder()
+                .setPayloadType(PayloadTypeDef.getDefaultInstance(payloadType))
+                .setExpPayloadType(PayloadTypeDef.getDefaultInstance(payloadType))
+                .build();
+        }
+        OduBuilder oduIfBuilder = new OduBuilder()
+            .setRate(ODU2.class)
+            .setOduFunction(oduFunction)
+            .setMonitoringMode(monitoringMode)
+            .setOpu(opu)
+            .setParentOduAllocation(parentOduAllocation);
+        if (apiInfoA != null) {
+            oduIfBuilder.setTxSapi(apiInfoA.getSapi())
+                .setTxDapi(apiInfoA.getDapi())
+                .setExpectedSapi(apiInfoA.getExpectedSapi())
+                .setExpectedDapi(apiInfoA.getExpectedDapi());
+        }
+        if (apiInfoZ != null) {
+            oduIfBuilder.setTxSapi(apiInfoZ.getSapi())
+                .setTxDapi(apiInfoZ.getDapi())
+                .setExpectedSapi(apiInfoZ.getExpectedSapi())
+                .setExpectedDapi(apiInfoZ.getExpectedDapi());
         }
-
-        // Create Interface1 type object required for adding as augmentation
-        // TODO look at imports of different versions of class
         // 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();
-        oduInterfaceBldr.addAugmentation(
-                org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1.class,
-                oduIf1Builder.setOdu(oduIfBuilder.build()).build());
+        oduInterfaceBldr.addAugmentation(oduIf1Builder.setOdu(oduIfBuilder.build()).build());
 
         // Post interface on the device
         this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
-        LOG.info("returning the ODU2 inteface {}", oduInterfaceBldr.getName());
+        if (!isCTP) {
+            LOG.info("{}-{} updating mapping with interface {}", nodeId, logicalConnPoint, oduInterfaceBldr.getName());
+            this.portMapping.updateMapping(nodeId, mapping);
+        }
         return oduInterfaceBldr.getName();
     }
 }