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