c90d476c3b83b30fe7e9db28dd715640b8a68c30
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / openroadminterface / OpenRoadmInterface710.java
1 /*
2  * Copyright © 2021 AT&T and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.transportpce.renderer.openroadminterface;
10
11 import java.math.BigDecimal;
12 import java.util.ArrayList;
13 import java.util.Arrays;
14 import java.util.List;
15 import java.util.Optional;
16 import java.util.stream.IntStream;
17 import org.opendaylight.transportpce.common.StringConstants;
18 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
19 import org.opendaylight.transportpce.common.fixedflex.SpectrumInformation;
20 import org.opendaylight.transportpce.common.mapping.PortMapping;
21 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
22 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.AEndApiInfo;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.ZEndApiInfo;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220114.mapping.Mapping;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.attributes.rev200327.TrailTraceOther.TimDetectMode;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.attributes.rev200327.parent.odu.allocation.ParentOduAllocationBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.attributes.rev200327.parent.odu.allocation.parent.odu.allocation.trib.slots.choice.OpucnBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.link.types.rev191129.PowerDBm;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.Foic48;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.FrequencyTHz;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.ModulationFormat;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.ProvisionModeType;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.R400GOtsi;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev200529.Ofec;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev200529.Rsfec;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.InterfaceBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.InterfaceKey;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev200529.Interface1Builder;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev200529.ethernet.container.EthernetBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.EthernetCsmacd;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.InterfaceType;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.OtnOdu;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.OtnOtu;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.Otsi;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.OtsiGroup;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.maintenance.loopback.rev191129.maint.loopback.MaintLoopbackBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.maintenance.testsignal.rev200529.maint.testsignal.MaintTestsignal.TestPattern;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.maintenance.testsignal.rev200529.maint.testsignal.MaintTestsignalBuilder;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.tributary.signal.interfaces.rev200529.otsi.attributes.FlexoBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.tributary.signal.interfaces.rev200529.otsi.container.OtsiBuilder;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUCn;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUTTP;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUTTPCTP;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUflexCbr;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUflexCbr400G;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.OTUCn;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.OpucnTribSlotDef;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.PayloadTypeDef;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.OduAttributes.MonitoringMode;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.odu.container.OduBuilder;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.opu.OpuBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev200529.otu.container.OtuBuilder;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.otsi.group.interfaces.rev200529.otsi.group.container.OtsiGroupBuilder;
66 import org.opendaylight.yangtools.yang.common.Uint16;
67 import org.opendaylight.yangtools.yang.common.Uint32;
68 import org.opendaylight.yangtools.yang.common.Uint8;
69
70
71 public class OpenRoadmInterface710 {
72     private static final String MAPPING_ERROR_EXCEPTION_MESSAGE =
73         "Unable to get mapping from PortMapping for node % and logical connection port %s";
74     private static final String ODUC4 = "-ODUC4";
75     private final PortMapping portMapping;
76     private final OpenRoadmInterfaces openRoadmInterfaces;
77
78
79     public OpenRoadmInterface710(PortMapping portMapping, OpenRoadmInterfaces openRoadmInterfaces) {
80         this.portMapping = portMapping;
81         this.openRoadmInterfaces = openRoadmInterfaces;
82     }
83
84     public String createOpenRoadmEthInterface(String nodeId, String logicalConnPoint)
85             throws OpenRoadmInterfaceException {
86         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
87         if (portMap == null) {
88             throw new OpenRoadmInterfaceException(
89                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
90         }
91
92         // Ethernet interface specific data
93         EthernetBuilder ethIfBuilder = new EthernetBuilder()
94             .setFec(Rsfec.class)
95             .setSpeed(Uint32.valueOf(400000));
96
97         InterfaceBuilder ethInterfaceBldr = createGenericInterfaceBuilder(portMap, EthernetCsmacd.class,
98             logicalConnPoint + "-ETHERNET");
99         // Create Interface1 type object required for adding as augmentation
100         Interface1Builder ethIf1Builder = new Interface1Builder();
101         ethInterfaceBldr.addAugmentation(ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
102
103         // Post interface on the device
104         openRoadmInterfaces.postInterface(nodeId, ethInterfaceBldr);
105
106         // Post the equipment-state change on the device circuit-pack
107         openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
108
109         return ethInterfaceBldr.getName();
110     }
111
112
113     public String createOpenRoadmOtsiInterface(String nodeId, String logicalConnPoint,
114             SpectrumInformation spectrumInformation)
115             throws OpenRoadmInterfaceException {
116         // TODO : Check this method
117         ModulationFormat modulationFormat = ModulationFormat.DpQam16;
118         Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
119             .forName(spectrumInformation.getModulationFormat());
120         if (optionalModulationFormat.isPresent()) {
121             modulationFormat =  optionalModulationFormat.get();
122         }
123         // Set the Flexo values
124         FlexoBuilder flexoBuilder = new FlexoBuilder()
125             .setFoicType(Foic48.class)
126             .setIid(new ArrayList<>(Arrays.asList(Uint8.valueOf(1), Uint8.valueOf(2),
127                 Uint8.valueOf(3), Uint8.valueOf(4))));
128
129         // OTSI interface specific data
130         OtsiBuilder  otsiBuilder = new OtsiBuilder()
131             .setFrequency(new FrequencyTHz(spectrumInformation.getCenterFrequency()))
132             .setTransmitPower(new PowerDBm(new BigDecimal("-5")))
133             .setModulationFormat(modulationFormat)
134             .setOtsiRate(R400GOtsi.class)
135             .setProvisionMode(ProvisionModeType.Explicit)
136             .setFec(Ofec.class)
137             .setFlexo(flexoBuilder.build());
138         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
139         if (portMap == null) {
140             throw new OpenRoadmInterfaceException(
141                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
142         }
143         // Create generic interface
144         InterfaceBuilder otsiInterfaceBldr = createGenericInterfaceBuilder(portMap, Otsi.class,
145             spectrumInformation.getIdentifierFromParams(logicalConnPoint));
146
147         // Create Interface1 type object required for adding as augmentation
148         org.opendaylight.yang.gen.v1.http
149                 .org.openroadm.optical.channel.tributary.signal.interfaces.rev200529.Interface1Builder otsiIf1Builder =
150             new org.opendaylight.yang.gen.v1.http
151                 .org.openroadm.optical.channel.tributary.signal.interfaces.rev200529.Interface1Builder();
152
153         otsiInterfaceBldr.addAugmentation(otsiIf1Builder.setOtsi(otsiBuilder.build()).build());
154
155         // Post interface on the device
156         openRoadmInterfaces.postInterface(nodeId, otsiInterfaceBldr);
157
158         // Post the equipment-state change on the device circuit-pack if xpdr node
159         if (portMap.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
160             this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
161         }
162
163         return otsiInterfaceBldr.getName();
164     }
165
166     // This is a transponder use-case where the supporting port is just one, but YANG model
167     // requires supporting port to be list
168     public String createOpenRoadmOtsiGroupInterface(String nodeId, String logicalConnPoint,
169             String supportingOtsiInterface)
170             throws OpenRoadmInterfaceException {
171         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
172         if (portMap == null) {
173             throw new OpenRoadmInterfaceException(
174                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
175                     nodeId, logicalConnPoint));
176         }
177         // Create an OTSI group object
178         OtsiGroupBuilder otsiGroupBuilder = new OtsiGroupBuilder()
179             .setGroupId(Uint32.valueOf(1))
180             .setGroupRate(R400GOtsi.class);
181
182         // Create generic interface
183         InterfaceBuilder otsiGroupInterfaceBldr = createGenericInterfaceBuilder(portMap, OtsiGroup.class,
184             logicalConnPoint + "-OTSI-GROUP");
185
186         // Create a list
187         List<String> listSupportingOtsiInterface = new ArrayList<>();
188         listSupportingOtsiInterface.add(supportingOtsiInterface);
189         otsiGroupInterfaceBldr.setSupportingInterfaceList(listSupportingOtsiInterface);
190
191         org.opendaylight.yang.gen.v1.http.org.openroadm.otsi.group.interfaces.rev200529.Interface1Builder
192                 otsiGroupIf1Builder =
193             new org.opendaylight.yang.gen.v1.http.org.openroadm.otsi.group.interfaces.rev200529.Interface1Builder();
194         otsiGroupInterfaceBldr.addAugmentation(otsiGroupIf1Builder.setOtsiGroup(otsiGroupBuilder.build()).build());
195
196         // Post interface on the device
197         openRoadmInterfaces.postInterface(nodeId, otsiGroupInterfaceBldr);
198
199         // Post the equipment-state change on the device circuit-pack if xpdr node
200         if (portMap.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
201             this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
202         }
203
204         return otsiGroupInterfaceBldr.getName();
205     }
206
207     public String createOpenRoadmOtucnInterface(String nodeId, String logicalConnPoint,
208             String supportingOtsiGroupInterface, AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ)
209             throws OpenRoadmInterfaceException {
210         Mapping mapping = portMapping.getMapping(nodeId, logicalConnPoint);
211         if (mapping == null) {
212             throw new OpenRoadmInterfaceException(
213                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
214                     nodeId, logicalConnPoint));
215         }
216         // Create an OTUCn object
217         MaintLoopbackBuilder maintLoopbackBuilder = new MaintLoopbackBuilder();
218         maintLoopbackBuilder.setEnabled(false);
219         OtuBuilder otuBuilder = new OtuBuilder()
220             .setRate(OTUCn.class)
221             .setOtucnNRate(Uint16.valueOf(4))
222             .setTimActEnabled(false)
223             .setTimDetectMode(TimDetectMode.Disabled)
224             .setDegmIntervals(Uint8.valueOf(2))
225             .setDegthrPercentage(Uint16.valueOf(100))
226             .setMaintLoopback(maintLoopbackBuilder.build());
227         if (apiInfoA != null) {
228             otuBuilder.setTxSapi(apiInfoA.getSapi())
229                 .setTxDapi(apiInfoA.getDapi())
230                 .setExpectedSapi(apiInfoA.getExpectedSapi())
231                 .setExpectedDapi(apiInfoA.getExpectedDapi());
232         }
233         if (apiInfoZ != null) {
234             otuBuilder.setTxSapi(apiInfoZ.getSapi())
235                 .setTxDapi(apiInfoZ.getDapi())
236                 .setExpectedSapi(apiInfoZ.getExpectedSapi())
237                 .setExpectedDapi(apiInfoZ.getExpectedDapi());
238         }
239
240         InterfaceBuilder otuInterfaceBuilder = createGenericInterfaceBuilder(mapping, OtnOtu.class,
241             logicalConnPoint + "-OTUC4");
242
243         // Create a list
244         List<String> listSupportingOtsiGroupInterface = new ArrayList<>();
245         listSupportingOtsiGroupInterface.add(supportingOtsiGroupInterface);
246
247         otuInterfaceBuilder.setSupportingInterfaceList(listSupportingOtsiGroupInterface);
248         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev200529.Interface1Builder otuIf1Builder =
249             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev200529.Interface1Builder();
250
251         otuInterfaceBuilder.addAugmentation(otuIf1Builder.setOtu(otuBuilder.build()).build());
252
253         // Post interface on the device
254         openRoadmInterfaces.postInterface(nodeId, otuInterfaceBuilder);
255         // Post the equipment-state change on the device circuit-pack if xpdr node
256         if (mapping.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
257             this.openRoadmInterfaces.postEquipmentState(nodeId, mapping.getSupportingCircuitPackName(), true);
258         }
259         this.portMapping.updateMapping(nodeId, mapping);
260         return otuInterfaceBuilder.getName();
261     }
262
263     public String createOpenRoadmOducnInterface(String nodeId, String logicalConnPoint)
264             throws OpenRoadmInterfaceException {
265         Mapping mapping = portMapping.getMapping(nodeId, logicalConnPoint);
266         if (mapping == null) {
267             throw new OpenRoadmInterfaceException(
268                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
269                     nodeId, logicalConnPoint));
270         }
271         // Create ODUcn object
272         // Start with OPU object
273         // OPU payload
274         OpuBuilder opuBuilder = new OpuBuilder()
275             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("22"))
276             .setPayloadType(PayloadTypeDef.getDefaultInstance("22"));
277
278         // Create an ODUC4 object
279         OduBuilder oduBuilder = new OduBuilder()
280             .setRate(ODUCn.class)
281             .setOducnNRate(Uint16.valueOf(4))
282             .setOduFunction(ODUTTP.class)
283             .setMonitoringMode(MonitoringMode.Terminated)
284             .setTimActEnabled(false)
285             .setTimDetectMode(TimDetectMode.Disabled)
286             .setDegmIntervals(Uint8.valueOf(2))
287             .setDegthrPercentage(Uint16.valueOf(100))
288             .setOpu(opuBuilder.build());
289
290         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(mapping, OtnOdu.class,
291             logicalConnPoint + "-ODUC4");
292
293         // Create a list
294         List<String> listSupportingOtucnInterface = new ArrayList<>();
295         if (mapping.getSupportingOtucn() != null) {
296             listSupportingOtucnInterface.add(mapping.getSupportingOtucn());
297         }
298
299         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
300         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
301             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
302
303         oduInterfaceBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
304
305         // Post interface on the device
306         openRoadmInterfaces.postInterface(nodeId, oduInterfaceBuilder);
307
308         // Post the equipment-state change on the device circuit-pack if xpdr node
309         if (mapping.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
310             this.openRoadmInterfaces.postEquipmentState(nodeId, mapping.getSupportingCircuitPackName(), true);
311         }
312
313         return oduInterfaceBuilder.getName();
314     }
315
316     // With SAPI and DAPI information
317     public String createOpenRoadmOducnInterface(String anodeId, String alogicalConnPoint,
318             String supportingOtucn, String znodeId, String zlogicalConnPoint)
319             throws OpenRoadmInterfaceException {
320         Mapping portMapA = portMapping.getMapping(anodeId, alogicalConnPoint);
321         Mapping portMapZ = portMapping.getMapping(znodeId, zlogicalConnPoint);
322         if (portMapA == null) {
323             throw new OpenRoadmInterfaceException(
324                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
325                     anodeId, alogicalConnPoint));
326         }
327         // On the Zside
328         if (portMapZ == null) {
329             throw new OpenRoadmInterfaceException(
330                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
331                     znodeId, zlogicalConnPoint));
332
333         }
334         // Create ODUcn object
335         // Start with OPU object
336         // OPU payload
337         OpuBuilder opuBuilder = new OpuBuilder()
338             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("22"))
339             .setPayloadType(PayloadTypeDef.getDefaultInstance("22"));
340
341         // Create an ODUC4 object
342         OduBuilder oduBuilder = new OduBuilder()
343             .setRate(ODUCn.class)
344             .setOducnNRate(Uint16.valueOf(4))
345             .setOduFunction(ODUTTP.class)
346             .setMonitoringMode(MonitoringMode.Terminated)
347             .setTimActEnabled(false)
348             .setTimDetectMode(TimDetectMode.Disabled)
349             .setDegmIntervals(Uint8.valueOf(2))
350             .setDegthrPercentage(Uint16.valueOf(100))
351             .setOpu(opuBuilder.build())
352             .setTxSapi(portMapA.getLcpHashVal())
353             .setTxDapi(portMapZ.getLcpHashVal())
354             .setExpectedSapi(portMapZ.getLcpHashVal())
355             .setExpectedDapi(portMapZ.getLcpHashVal());
356
357         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMapA, OtnOdu.class,
358             alogicalConnPoint + ODUC4);
359
360         // Create a list
361         List<String> listSupportingOtucnInterface = new ArrayList<>();
362         listSupportingOtucnInterface.add(supportingOtucn);
363
364         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
365         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
366             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
367
368         oduInterfaceBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
369
370         // Post interface on the device
371         openRoadmInterfaces.postInterface(anodeId, oduInterfaceBuilder);
372
373         // Post the equipment-state change on the device circuit-pack if xpdr node
374         if (portMapA.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
375             this.openRoadmInterfaces.postEquipmentState(anodeId, portMapA.getSupportingCircuitPackName(), true);
376         }
377
378         return oduInterfaceBuilder.getName();
379     }
380
381     public String createOpenRoadmOtnOducnInterface(String nodeId, String logicalConnPoint,
382         String supportingOtucn)
383         throws OpenRoadmInterfaceException {
384         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
385         if (portMap == null) {
386             throw new OpenRoadmInterfaceException(
387                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
388                     nodeId, logicalConnPoint));
389         }
390         // Create ODUcn object
391         // Start with OPU object
392         // OPU payload
393         OpuBuilder opuBuilder = new OpuBuilder()
394             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("22"))
395             .setPayloadType(PayloadTypeDef.getDefaultInstance("22"));
396
397         // Create an ODUC4 object
398         OduBuilder oduBuilder = new OduBuilder()
399             .setRate(ODUCn.class)
400             .setOducnNRate(Uint16.valueOf(4))
401             .setOduFunction(ODUTTP.class)
402             .setMonitoringMode(MonitoringMode.Terminated)
403             .setTimActEnabled(false)
404             .setTimDetectMode(TimDetectMode.Disabled)
405             .setDegmIntervals(Uint8.valueOf(2))
406             .setDegthrPercentage(Uint16.valueOf(100))
407             .setOpu(opuBuilder.build());
408
409         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMap, OtnOdu.class,
410             logicalConnPoint + ODUC4);
411
412         // Create a list
413         List<String> listSupportingOtucnInterface = new ArrayList<>();
414         listSupportingOtucnInterface.add(supportingOtucn);
415
416         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
417         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
418             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
419
420         oduInterfaceBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
421
422         // Post interface on the device
423         openRoadmInterfaces.postInterface(nodeId, oduInterfaceBuilder);
424
425         // Post the equipment-state change on the device circuit-pack if xpdr node
426         if (portMap.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
427             this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
428         }
429         // Update the port-mapping with the interface information
430         this.portMapping.updateMapping(nodeId, portMap);
431         return oduInterfaceBuilder.getName();
432     }
433
434
435     // With SAPI and DAPI information
436     public String createOpenRoadmOtnOducnInterface(String anodeId, String alogicalConnPoint,
437         String supportingOtucn, String znodeId, String zlogicalConnPoint)
438         throws OpenRoadmInterfaceException {
439         Mapping portMapA = portMapping.getMapping(anodeId, alogicalConnPoint);
440         Mapping portMapZ = portMapping.getMapping(znodeId, zlogicalConnPoint);
441         if (portMapA == null) {
442             throw new OpenRoadmInterfaceException(
443                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
444                     anodeId, alogicalConnPoint));
445         }
446         // On the Zside
447         if (portMapZ == null) {
448             throw new OpenRoadmInterfaceException(
449                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
450                     znodeId, zlogicalConnPoint));
451
452         }
453         // Create ODUcn object
454         // Start with OPU object
455         // OPU payload
456         OpuBuilder opuBuilder = new OpuBuilder()
457             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("22"))
458             .setPayloadType(PayloadTypeDef.getDefaultInstance("22"));
459
460         // Create an ODUC4 object
461         OduBuilder oduBuilder = new OduBuilder()
462             .setRate(ODUCn.class)
463             .setOducnNRate(Uint16.valueOf(4))
464             .setOduFunction(ODUTTP.class)
465             .setMonitoringMode(MonitoringMode.Terminated)
466             .setTimActEnabled(false)
467             .setTimDetectMode(TimDetectMode.Disabled)
468             .setDegmIntervals(Uint8.valueOf(2))
469             .setDegthrPercentage(Uint16.valueOf(100))
470             .setOpu(opuBuilder.build())
471             .setTxSapi(portMapA.getLcpHashVal())
472             .setTxDapi(portMapZ.getLcpHashVal())
473             .setExpectedSapi(portMapZ.getLcpHashVal())
474             .setExpectedDapi(portMapZ.getLcpHashVal());
475
476         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMapA, OtnOdu.class,
477             alogicalConnPoint + ODUC4);
478
479         // Create a list
480         List<String> listSupportingOtucnInterface = new ArrayList<>();
481         listSupportingOtucnInterface.add(supportingOtucn);
482
483         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
484         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
485             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
486
487         oduInterfaceBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
488
489         // Post interface on the device
490         openRoadmInterfaces.postInterface(anodeId, oduInterfaceBuilder);
491
492         // Post the equipment-state change on the device circuit-pack if xpdr node
493         if (portMapA.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
494             this.openRoadmInterfaces.postEquipmentState(anodeId, portMapA.getSupportingCircuitPackName(), true);
495         }
496         // Update the port-mapping with the interface information
497         this.portMapping.updateMapping(anodeId, portMapA);
498         return oduInterfaceBuilder.getName();
499     }
500
501     // This is only for transponder
502     public String createOpenRoadmOduflexInterface(String nodeId, String logicalConnPoint,
503             String supportingOducn)
504             throws OpenRoadmInterfaceException {
505         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
506         if (portMap == null) {
507             throw new OpenRoadmInterfaceException(
508                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
509                     nodeId, logicalConnPoint));
510         }
511         // OPU payload
512         OpuBuilder opuBuilder = new OpuBuilder()
513             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("32"))
514             .setPayloadType(PayloadTypeDef.getDefaultInstance("32"));
515
516         // Parent Odu-allocation
517         // Set the trib-slot array
518         List<OpucnTribSlotDef> tribslots = new ArrayList<>();
519         IntStream.range(1, 5).forEach(a -> IntStream.range(1, 21).forEach(b -> tribslots.add(
520             OpucnTribSlotDef.getDefaultInstance(a + "." + b))));
521
522         ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
523             .setTribPortNumber(Uint16.valueOf(1))
524             .setTribSlotsChoice(new OpucnBuilder().setOpucnTribSlots(tribslots).build());
525
526         // Create an ODUFlex object
527         OduBuilder oduBuilder = new OduBuilder()
528             .setRate(ODUflexCbr.class)
529             .setOduflexCbrService(ODUflexCbr400G.class)
530             .setOduFunction(ODUTTPCTP.class)
531             .setMonitoringMode(MonitoringMode.Terminated)
532             .setTimActEnabled(false)
533             .setTimDetectMode(TimDetectMode.Disabled)
534             .setDegmIntervals(Uint8.valueOf(2))
535             .setDegthrPercentage(Uint16.valueOf(100))
536             .setOpu(opuBuilder.build())
537             .setParentOduAllocation(parentOduAllocationBuilder.build());
538
539         InterfaceBuilder oduflexInterfaceBuilder = createGenericInterfaceBuilder(portMap, OtnOdu.class,
540             logicalConnPoint + "-ODUFLEX");
541
542         List<String> listSupportingOtucnInterface = new ArrayList<>();
543         listSupportingOtucnInterface.add(supportingOducn);
544
545         oduflexInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
546
547
548         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder
549                 oduflexIf1Builder =
550             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
551
552         oduflexInterfaceBuilder.addAugmentation(oduflexIf1Builder.setOdu(oduBuilder.build()).build());
553
554         // Post interface on the device
555         openRoadmInterfaces.postInterface(nodeId, oduflexInterfaceBuilder);
556
557         // Post the equipment-state change on the device circuit-pack if xpdr node
558         if (portMap.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
559             this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
560         }
561
562         return oduflexInterfaceBuilder.getName();
563     }
564
565     // This is only for transponder; with SAPI/DAPI information
566     public String createOpenRoadmOduflexInterface(String anodeId, String alogicalConnPoint,
567             String supportingOducn, String znodeId, String zlogicalConnPoint)
568             throws OpenRoadmInterfaceException {
569         Mapping portMapA = portMapping.getMapping(anodeId, alogicalConnPoint);
570         Mapping portMapZ = portMapping.getMapping(znodeId, zlogicalConnPoint);
571         if (portMapA == null) {
572             throw new OpenRoadmInterfaceException(
573                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
574                     anodeId, alogicalConnPoint));
575         }
576         // On the Zside
577         if (portMapZ == null) {
578             throw new OpenRoadmInterfaceException(
579                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
580                     znodeId, zlogicalConnPoint));
581
582         }
583         // OPU payload
584         OpuBuilder opuBuilder = new OpuBuilder()
585             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("32"))
586             .setPayloadType(PayloadTypeDef.getDefaultInstance("32"));
587
588         // Maint test signal
589         MaintTestsignalBuilder maintTestsignal = new MaintTestsignalBuilder()
590             // PRBS value should be PRBS31 if enabled is true
591             .setTestPattern(TestPattern.PRBS31)
592             .setEnabled(false);
593
594         // Parent Odu-allocation
595         // Set the trib-slot array
596         List<OpucnTribSlotDef> tribslots = new ArrayList<>();
597         IntStream.range(1, 5).forEach(a -> IntStream.range(1, 21).forEach(b -> tribslots.add(
598             OpucnTribSlotDef.getDefaultInstance(a + "." + b))));
599
600         ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
601             .setTribPortNumber(Uint16.valueOf(1))
602             .setTribSlotsChoice(new OpucnBuilder().setOpucnTribSlots(tribslots).build());
603
604         // Create an ODUFlex object
605         OduBuilder oduBuilder = new OduBuilder()
606             .setRate(ODUflexCbr.class)
607             .setOduflexCbrService(ODUflexCbr400G.class)
608             .setOduFunction(ODUTTPCTP.class)
609             .setMonitoringMode(MonitoringMode.Terminated)
610             .setTimActEnabled(false)
611             .setTimDetectMode(TimDetectMode.Disabled)
612             .setDegmIntervals(Uint8.valueOf(2))
613             .setDegthrPercentage(Uint16.valueOf(100))
614             .setTxSapi(portMapA.getLcpHashVal())
615             .setTxDapi(portMapZ.getLcpHashVal())
616             .setExpectedSapi(portMapZ.getLcpHashVal())
617             .setExpectedDapi(portMapA.getLcpHashVal())
618             .setOpu(opuBuilder.build())
619             .setMaintTestsignal(maintTestsignal.build())
620             .setParentOduAllocation(parentOduAllocationBuilder.build());
621
622         InterfaceBuilder oduflexInterfaceBuilder = createGenericInterfaceBuilder(portMapA, OtnOdu.class,
623             alogicalConnPoint + "-ODUFLEX");
624
625         List<String> listSupportingOtucnInterface = new ArrayList<>();
626         listSupportingOtucnInterface.add(supportingOducn);
627
628         oduflexInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
629
630
631         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder
632                 oduflexIf1Builder =
633             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
634
635         oduflexInterfaceBuilder.addAugmentation(oduflexIf1Builder.setOdu(oduBuilder.build()).build());
636
637         // Post interface on the device
638         openRoadmInterfaces.postInterface(anodeId, oduflexInterfaceBuilder);
639
640         // Post the equipment-state change on the device circuit-pack if xpdr node
641         if (portMapA.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
642             this.openRoadmInterfaces.postEquipmentState(anodeId, portMapA.getSupportingCircuitPackName(), true);
643         }
644
645         return oduflexInterfaceBuilder.getName();
646     }
647
648     // This creates the name of the interface with slot numbers at the end
649     public String createOpenRoadmOtsiInterfaceName(String logicalConnectionPoint, String spectralSlotName) {
650         return String.join(GridConstant.NAME_PARAMETERS_SEPARATOR,logicalConnectionPoint, spectralSlotName);
651     }
652
653     private InterfaceBuilder createGenericInterfaceBuilder(Mapping portMap, Class<? extends InterfaceType> type,
654             String key) {
655         return new org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.InterfaceBuilder()
656             .setDescription("  TBD   ")
657             .setCircuitId("   TBD    ")
658             .setSupportingCircuitPackName(portMap.getSupportingCircuitPackName())
659             .setSupportingPort(portMap.getSupportingPort())
660             .setAdministrativeState(AdminStates.InService)
661             .setType(type)
662             .setName(key)
663             .withKey(new InterfaceKey(key));
664     }
665
666 }