Remove maintenance loopback container
[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.Foic24;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.Foic28;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.Foic36;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.Foic48;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.FrequencyTHz;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.ModulationFormat;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.ProvisionModeType;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.R100G;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.R200GOtsi;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.R300GOtsi;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.R400GOtsi;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev200529.Ofec;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev200529.Rsfec;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev200529.Scfec;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.InterfaceBuilder;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.InterfaceKey;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev200529.Interface1Builder;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev200529.ethernet.container.EthernetBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.EthernetCsmacd;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.InterfaceType;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.OpticalChannel;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.OtnOdu;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.OtnOtu;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.Otsi;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.OtsiGroup;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev200529.och.container.OchBuilder;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.tributary.signal.interfaces.rev200529.otsi.attributes.FlexoBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.tributary.signal.interfaces.rev200529.otsi.container.OtsiBuilder;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODU4;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUCn;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUTTP;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUTTPCTP;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUflexCbr;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUflexCbr400G;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.OTU4;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.OTUCn;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.OpucnTribSlotDef;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.PayloadTypeDef;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.OduAttributes.MonitoringMode;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.odu.container.OduBuilder;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.opu.OpuBuilder;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev200529.otu.container.OtuBuilder;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.otsi.group.interfaces.rev200529.otsi.group.container.OtsiGroupBuilder;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If100GE;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.IfOCHOTU4ODU4;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.IfOtsiOtsigroup;
77 import org.opendaylight.yangtools.yang.common.Uint16;
78 import org.opendaylight.yangtools.yang.common.Uint32;
79 import org.opendaylight.yangtools.yang.common.Uint8;
80 import org.slf4j.Logger;
81 import org.slf4j.LoggerFactory;
82
83 public class OpenRoadmInterface710 {
84     private static final String MAPPING_ERROR_EXCEPTION_MESSAGE =
85         "Unable to get mapping from PortMapping for node % and logical connection port %s";
86     private static final String MODULATION_FMT_EXCEPTION_MESSAGE =
87         "Unable to get the modulation format";
88     private static final String RATE_EXCEPTION_MESSAGE =
89         "Unable to get the rate";
90     private static final String ODUC = "-ODUC";
91     private static final List<String> SUPPORTED_ODUCN_RATES = new ArrayList<>() {
92         {
93             add("2");
94             add("3");
95             add("4");
96         }
97     };
98     private final PortMapping portMapping;
99     private final OpenRoadmInterfaces openRoadmInterfaces;
100     private static final Logger LOG = LoggerFactory.getLogger(OpenRoadmInterface710.class);
101
102     public OpenRoadmInterface710(PortMapping portMapping, OpenRoadmInterfaces openRoadmInterfaces) {
103         this.portMapping = portMapping;
104         this.openRoadmInterfaces = openRoadmInterfaces;
105     }
106
107     public String createOpenRoadmEthInterface(String nodeId, String logicalConnPoint)
108             throws OpenRoadmInterfaceException {
109         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
110         if (portMap == null) {
111             throw new OpenRoadmInterfaceException(
112                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
113         }
114         // Ethernet interface specific data
115         EthernetBuilder ethIfBuilder = new EthernetBuilder()
116             .setFec(Rsfec.class)
117             // Default set to 400G
118             .setSpeed(Uint32.valueOf(400000));
119         // We have to differentiate if-100GE vs if-400GE
120         if (portMap.getSupportedInterfaceCapability().contains(If100GE.class)) {
121             ethIfBuilder.setSpeed(Uint32.valueOf(100000));
122
123         }
124         InterfaceBuilder ethInterfaceBldr = createGenericInterfaceBuilder(portMap, EthernetCsmacd.class,
125             logicalConnPoint + "-ETHERNET");
126
127         // Create Interface1 type object required for adding as augmentation
128         Interface1Builder ethIf1Builder = new Interface1Builder();
129         ethInterfaceBldr.addAugmentation(ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
130
131         // Post interface on the device
132         openRoadmInterfaces.postInterface(nodeId, ethInterfaceBldr);
133
134         // Post the equipment-state change on the device circuit-pack
135         openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
136
137         return ethInterfaceBldr.getName();
138     }
139
140     public String createOpenRoadmOchInterface(String nodeId, String logicalConnPoint,
141         SpectrumInformation spectrumInformation)
142         throws OpenRoadmInterfaceException {
143
144         ModulationFormat   modulationFormat = ModulationFormat.DpQpsk;
145         Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
146             .forName(spectrumInformation.getModulationFormat());
147         if (optionalModulationFormat.isPresent()) {
148             modulationFormat =  optionalModulationFormat.get();
149         }
150         // OCH interface specific data
151         OchBuilder ocIfBuilder = new OchBuilder()
152             .setFrequency(new FrequencyTHz(spectrumInformation.getCenterFrequency()))
153             .setRate(R100G.class)
154             .setTransmitPower(new PowerDBm(new BigDecimal("-5")))
155             .setModulationFormat(modulationFormat);
156         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
157         if (portMap == null) {
158             throw new OpenRoadmInterfaceException(
159                 String.format("Unable to get mapping from PortMapping for node %s and logical connection port %s",
160                     nodeId, logicalConnPoint));
161         }
162         // Create generic interface
163         InterfaceBuilder
164             ochInterfaceBldr = createGenericInterfaceBuilder(portMap, OpticalChannel.class,
165             spectrumInformation.getIdentifierFromParams(logicalConnPoint));
166         // Create Interface1 type object required for adding as augmentation
167         // TODO look at imports of different versions of class
168         org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev200529.Interface1Builder
169             ochIf1Builder = new org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev200529
170             .Interface1Builder();
171         ochInterfaceBldr.addAugmentation(ochIf1Builder.setOch(ocIfBuilder.build()).build());
172
173         // Post interface on the device
174         openRoadmInterfaces.postInterface(nodeId, ochInterfaceBldr);
175
176         // Post the equipment-state change on the device circuit-pack if xpdr node
177         if (portMap.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
178             this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
179         }
180
181         return ochInterfaceBldr.getName();
182     }
183
184     public String createOpenRoadmOtsiInterface(String nodeId, String logicalConnPoint,
185             SpectrumInformation spectrumInformation)
186             throws OpenRoadmInterfaceException {
187
188         ModulationFormat modulationFormat;
189         Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
190             .forName(spectrumInformation.getModulationFormat());
191         if (optionalModulationFormat.isPresent()) {
192             modulationFormat =  optionalModulationFormat.get();
193         } else {
194             throw new OpenRoadmInterfaceException(
195                 String.format(MODULATION_FMT_EXCEPTION_MESSAGE));
196         }
197
198         // OTSI interface specific data
199         OtsiBuilder  otsiBuilder = new OtsiBuilder()
200             .setFrequency(new FrequencyTHz(spectrumInformation.getCenterFrequency()))
201             .setTransmitPower(new PowerDBm(new BigDecimal("-5")))
202             .setProvisionMode(ProvisionModeType.Explicit)
203             .setFec(Ofec.class)
204             .setModulationFormat(modulationFormat);
205
206         // Set the Flexo values
207         FlexoBuilder flexoBuilder = new FlexoBuilder();
208         boolean rateNotFound = false;
209         // Use the rate to switch rather than modulation format
210         int serviceRate = getServiceRate(modulationFormat, spectrumInformation);
211         switch (serviceRate) {
212             case 200:
213                 LOG.info("Given modulation format is {} and thus rate is 200G", modulationFormat);
214                 if (modulationFormat == ModulationFormat.DpQam16) {
215                     LOG.info("FOIC is 2.8 for 31.6 Gbaud and rate is 200");
216                     // FOIC rate is different
217                     flexoBuilder.setFoicType(Foic28.class)
218                         .setIid(new ArrayList<>(Arrays.asList(Uint8.valueOf(1), Uint8.valueOf(2),
219                             Uint8.valueOf(3), Uint8.valueOf(4))));
220                 } else {
221                     // default is dp-qpsk for 200G under 63.1 GBaud
222                     flexoBuilder.setFoicType(Foic24.class)
223                         .setIid(new ArrayList<>(Arrays.asList(Uint8.valueOf(1), Uint8.valueOf(2))));
224                 }
225                 otsiBuilder.setOtsiRate(R200GOtsi.class)
226                     .setFlexo(flexoBuilder.build());
227                 break;
228             case 300:
229                 LOG.info("Given modulation format is {} and thus rate is 300G", modulationFormat);
230                 flexoBuilder.setFoicType(Foic36.class)
231                     .setIid(new ArrayList<>(Arrays.asList(Uint8.valueOf(1), Uint8.valueOf(2),
232                         Uint8.valueOf(3))));
233                 otsiBuilder.setOtsiRate(R300GOtsi.class)
234                     .setFlexo(flexoBuilder.build());
235                 break;
236             case 400:
237                 // Default baud-rate is 63.1 Gbaud
238                 LOG.info("Given modulation format is {} and thus rate is 400G", modulationFormat);
239                 flexoBuilder.setFoicType(Foic48.class)
240                     .setIid(new ArrayList<>(Arrays.asList(Uint8.valueOf(1), Uint8.valueOf(2),
241                         Uint8.valueOf(3), Uint8.valueOf(4))));
242                 otsiBuilder.setModulationFormat(modulationFormat)
243                     .setOtsiRate(R400GOtsi.class)
244                     .setFlexo(flexoBuilder.build());
245                 break;
246             default:
247                 LOG.error("Rate {} is unsupported", serviceRate);
248                 rateNotFound = true;
249                 break;
250         }
251
252         if (rateNotFound) {
253             throw new OpenRoadmInterfaceException(
254                 String.format(RATE_EXCEPTION_MESSAGE));
255         }
256
257         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
258         if (portMap == null) {
259             throw new OpenRoadmInterfaceException(
260                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
261         }
262         // Create generic interface
263         InterfaceBuilder otsiInterfaceBldr = createGenericInterfaceBuilder(portMap, Otsi.class,
264             spectrumInformation.getIdentifierFromParams(logicalConnPoint));
265         // Create Interface1 type object required for adding as augmentation
266         org.opendaylight.yang.gen.v1.http
267             .org.openroadm.optical.channel.tributary.signal.interfaces.rev200529.Interface1Builder otsiIf1Builder =
268             new org.opendaylight.yang.gen.v1.http
269                 .org.openroadm.optical.channel.tributary.signal.interfaces.rev200529.Interface1Builder();
270
271         otsiInterfaceBldr.addAugmentation(otsiIf1Builder.setOtsi(otsiBuilder.build()).build());
272
273         // Post interface on the device
274         openRoadmInterfaces.postInterface(nodeId, otsiInterfaceBldr);
275
276         // Post the equipment-state change on the device circuit-pack if xpdr node
277         if (portMap.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
278             this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
279         }
280
281         return otsiInterfaceBldr.getName();
282     }
283
284     // This is a transponder use-case where the supporting port is just one, but YANG model
285     // requires supporting port to be list
286     public String createOpenRoadmOtsiGroupInterface(String nodeId, String logicalConnPoint,
287             String supportingOtsiInterface, SpectrumInformation spectrumInformation)
288             throws OpenRoadmInterfaceException {
289         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
290         if (portMap == null) {
291             throw new OpenRoadmInterfaceException(
292                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
293                     nodeId, logicalConnPoint));
294         }
295         // Check the modulation format
296         ModulationFormat modulationFormat;
297         Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
298             .forName(spectrumInformation.getModulationFormat());
299         if (optionalModulationFormat.isPresent()) {
300             modulationFormat =  optionalModulationFormat.get();
301         } else {
302             throw new OpenRoadmInterfaceException(
303                 String.format(MODULATION_FMT_EXCEPTION_MESSAGE));
304         }
305         int serviceRate = getServiceRate(modulationFormat, spectrumInformation);
306         // Create an OTSI group object
307         OtsiGroupBuilder otsiGroupBuilder = new OtsiGroupBuilder()
308             .setGroupId(Uint32.valueOf(1));
309         boolean rateNotFound = false;
310         switch (serviceRate) {
311             case 200:
312                 otsiGroupBuilder.setGroupRate(R200GOtsi.class);
313                 break;
314             case 300:
315                 otsiGroupBuilder.setGroupRate(R300GOtsi.class);
316                 break;
317             case 400:
318                 otsiGroupBuilder.setGroupRate(R400GOtsi.class);
319                 break;
320             default:
321                 LOG.error("Rate {} is not supported", serviceRate);
322                 rateNotFound = true;
323                 break;
324         }
325         if (rateNotFound) {
326             throw new OpenRoadmInterfaceException(
327                 String.format(RATE_EXCEPTION_MESSAGE));
328         }
329
330         // Create generic interface
331         InterfaceBuilder otsiGroupInterfaceBldr = createGenericInterfaceBuilder(portMap, OtsiGroup.class,
332             logicalConnPoint + String.join("-", "", "OTSIGROUP", serviceRate + "G"));
333
334         // Create a list
335         List<String> listSupportingOtsiInterface = new ArrayList<>();
336         listSupportingOtsiInterface.add(supportingOtsiInterface);
337         otsiGroupInterfaceBldr.setSupportingInterfaceList(listSupportingOtsiInterface);
338
339         org.opendaylight.yang.gen.v1.http.org.openroadm.otsi.group.interfaces.rev200529.Interface1Builder
340             otsiGroupIf1Builder =
341             new org.opendaylight.yang.gen.v1.http.org.openroadm.otsi.group.interfaces.rev200529.Interface1Builder();
342         otsiGroupInterfaceBldr.addAugmentation(otsiGroupIf1Builder.setOtsiGroup(otsiGroupBuilder.build()).build());
343
344         // Post interface on the device
345         openRoadmInterfaces.postInterface(nodeId, otsiGroupInterfaceBldr);
346
347         // Post the equipment-state change on the device circuit-pack if xpdr node
348         if (portMap.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
349             this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
350         }
351
352         return otsiGroupInterfaceBldr.getName();
353     }
354
355     public String createOpenRoadmOchOtsiOtsigroupInterface(String nodeId, String logicalConnPoint,
356         SpectrumInformation spectrumInformation)
357         throws OpenRoadmInterfaceException {
358         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
359         if (portMap == null) {
360             throw new OpenRoadmInterfaceException(
361                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
362         }
363         String interfaceOchOtsiOtsigroup = null;
364         if (portMap.getSupportedInterfaceCapability().contains(IfOCHOTU4ODU4.class)) {
365             // create OCH interface
366             interfaceOchOtsiOtsigroup = createOpenRoadmOchInterface(nodeId, logicalConnPoint, spectrumInformation);
367         } else if (portMap.getSupportedInterfaceCapability().contains(IfOtsiOtsigroup.class)) {
368             // Create OTSi and OTSi-group
369             String interfaceOtsiName = createOpenRoadmOtsiInterface(nodeId, logicalConnPoint, spectrumInformation);
370             interfaceOchOtsiOtsigroup = createOpenRoadmOtsiGroupInterface(nodeId, logicalConnPoint, interfaceOtsiName,
371                 spectrumInformation);
372         }
373
374         return interfaceOchOtsiOtsigroup;
375     }
376
377     public String createOpenRoadmOtu4Interface(String nodeId, String logicalConnPoint, String supportOchInterface,
378         AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ) throws OpenRoadmInterfaceException {
379
380         Mapping mapping = this.portMapping.getMapping(nodeId, logicalConnPoint);
381         if (mapping == null) {
382             throw new OpenRoadmInterfaceException(
383                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
384         }
385         InterfaceBuilder
386             otuInterfaceBldr = createGenericInterfaceBuilder(mapping, OtnOtu.class,
387             logicalConnPoint + "-OTU4");
388         // Supporting interface list
389         List<String> listSupportingOChInterface = new ArrayList<>();
390         listSupportingOChInterface.add(supportOchInterface);
391         otuInterfaceBldr.setSupportingInterfaceList(listSupportingOChInterface);
392
393         // OTU interface specific data
394         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev200529.otu.container.OtuBuilder
395             otuIfBuilder = new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu
396             .interfaces.rev200529.otu.container.OtuBuilder()
397             .setFec(Scfec.class)
398             .setRate(OTU4.class);
399         if (apiInfoA != null) {
400             otuIfBuilder.setTxSapi(apiInfoA.getSapi())
401                 .setTxDapi(apiInfoA.getDapi())
402                 .setExpectedSapi(apiInfoA.getExpectedSapi())
403                 .setExpectedDapi(apiInfoA.getExpectedDapi());
404         }
405         if (apiInfoZ != null) {
406             otuIfBuilder.setTxSapi(apiInfoZ.getSapi())
407                 .setTxDapi(apiInfoZ.getDapi())
408                 .setExpectedSapi(apiInfoZ.getExpectedSapi())
409                 .setExpectedDapi(apiInfoZ.getExpectedDapi());
410         }
411
412         // Create Interface1 type object required for adding as augmentation
413         // TODO look at imports of different versions of class
414         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev200529.Interface1Builder otuIf1Builder =
415             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev200529.Interface1Builder();
416         otuInterfaceBldr.addAugmentation(otuIf1Builder.setOtu(otuIfBuilder.build()).build());
417
418         // Post interface on the device
419         openRoadmInterfaces.postInterface(nodeId, otuInterfaceBldr);
420         this.portMapping.updateMapping(nodeId, mapping);
421         return otuInterfaceBldr.getName();
422     }
423
424
425     public String createOpenRoadmOtucnInterface(String nodeId, String logicalConnPoint,
426             String supportingOtsiGroupInterface, AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ)
427             throws OpenRoadmInterfaceException {
428         Mapping mapping = portMapping.getMapping(nodeId, logicalConnPoint);
429         if (mapping == null) {
430             throw new OpenRoadmInterfaceException(
431                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
432                     nodeId, logicalConnPoint));
433         }
434         // Create an OTUCn object
435         OtuBuilder otuBuilder = new OtuBuilder()
436             .setRate(OTUCn.class)
437             .setTimActEnabled(false)
438             .setTimDetectMode(TimDetectMode.Disabled)
439             .setDegmIntervals(Uint8.valueOf(2))
440             .setDegthrPercentage(Uint16.valueOf(100));
441
442         if (apiInfoA != null) {
443             otuBuilder.setTxSapi(apiInfoA.getSapi())
444                 .setTxDapi(apiInfoA.getDapi())
445                 .setExpectedSapi(apiInfoA.getExpectedSapi())
446                 .setExpectedDapi(apiInfoA.getExpectedDapi());
447         }
448         if (apiInfoZ != null) {
449             otuBuilder.setTxSapi(apiInfoZ.getSapi())
450                 .setTxDapi(apiInfoZ.getDapi())
451                 .setExpectedSapi(apiInfoZ.getExpectedSapi())
452                 .setExpectedDapi(apiInfoZ.getExpectedDapi());
453         }
454         // Set the OTUCn rate for various rates
455         String rate = supportingOtsiGroupInterface.substring(supportingOtsiGroupInterface.lastIndexOf('-') + 1);
456
457         String otucnrate = null;
458         boolean rateNotFound = false;
459         switch (rate) {
460             case "200G":
461                 otuBuilder.setOtucnNRate(Uint16.valueOf(2));
462                 otucnrate = "2";
463                 break;
464             case "300G":
465                 otuBuilder.setOtucnNRate(Uint16.valueOf(3));
466                 otucnrate = "3";
467                 break;
468             case "400G":
469                 otuBuilder.setOtucnNRate(Uint16.valueOf(4));
470                 otucnrate = "4";
471                 break;
472             default:
473                 LOG.error("Rate {} is not supported", rate);
474                 rateNotFound = true;
475                 break;
476         }
477         if (rateNotFound) {
478             throw new OpenRoadmInterfaceException(
479                 String.format(RATE_EXCEPTION_MESSAGE));
480         }
481
482         InterfaceBuilder otuInterfaceBuilder = createGenericInterfaceBuilder(mapping, OtnOtu.class,
483             logicalConnPoint + "-OTUC" + otucnrate);
484
485         // Create a list
486         List<String> listSupportingOtsiGroupInterface = new ArrayList<>();
487         listSupportingOtsiGroupInterface.add(supportingOtsiGroupInterface);
488
489         otuInterfaceBuilder.setSupportingInterfaceList(listSupportingOtsiGroupInterface);
490         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev200529.Interface1Builder otuIf1Builder =
491             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev200529.Interface1Builder();
492
493         otuInterfaceBuilder.addAugmentation(otuIf1Builder.setOtu(otuBuilder.build()).build());
494
495         // Post interface on the device
496         openRoadmInterfaces.postInterface(nodeId, otuInterfaceBuilder);
497         // Post the equipment-state change on the device circuit-pack if xpdr node
498         if (mapping.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
499             this.openRoadmInterfaces.postEquipmentState(nodeId, mapping.getSupportingCircuitPackName(), true);
500         }
501         this.portMapping.updateMapping(nodeId, mapping);
502         return otuInterfaceBuilder.getName();
503     }
504
505     public String createOpenRoadmOtu4OtucnInterface(String nodeId, String logicalConnPoint,
506         String supportingInterface, AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ)
507         throws OpenRoadmInterfaceException {
508         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
509         if (portMap == null) {
510             throw new OpenRoadmInterfaceException(
511                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
512         }
513         // Depending on OCH-OTU4-ODU4 interface or OTSi-OTSi-group, supporting interface should
514         // reflect that
515         String interfaceOtu4Otucn = null;
516         if (portMap.getSupportedInterfaceCapability().contains(IfOCHOTU4ODU4.class)) {
517             // create OTU4 interface
518             interfaceOtu4Otucn = createOpenRoadmOtu4Interface(nodeId, logicalConnPoint, supportingInterface,
519                 apiInfoA, apiInfoZ);
520         } else if (portMap.getSupportedInterfaceCapability().contains(IfOtsiOtsigroup.class)) {
521             // Create OTUCn
522             interfaceOtu4Otucn = createOpenRoadmOtucnInterface(nodeId, logicalConnPoint, supportingInterface,
523                 apiInfoA, apiInfoZ);
524         }
525
526         return interfaceOtu4Otucn;
527     }
528
529     public String createOpenRoadmOdu4Interface(String nodeId, String logicalConnPoint,
530         AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ) throws OpenRoadmInterfaceException {
531
532         Mapping mapping = portMapping.getMapping(nodeId, logicalConnPoint);
533         if (mapping == null) {
534             throw new OpenRoadmInterfaceException(
535                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
536         }
537         InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(mapping, OtnOdu.class,
538             logicalConnPoint + "-ODU4");
539         List<String> listSupportingOtu4Interface = new ArrayList<>();
540         if (mapping.getSupportingOtu4() != null) {
541             listSupportingOtu4Interface.add(mapping.getSupportingOtu4());
542             oduInterfaceBldr.setSupportingInterfaceList(listSupportingOtu4Interface);
543         }
544
545         // OPU payload
546         OpuBuilder opuBuilder = new OpuBuilder()
547             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("07"))
548             .setPayloadType(PayloadTypeDef.getDefaultInstance("07"));
549
550         // Create an ODU4 object
551         OduBuilder oduBuilder = new OduBuilder()
552             .setRate(ODU4.class)
553             .setOduFunction(ODUTTP.class)
554             .setMonitoringMode(MonitoringMode.Terminated)
555             .setOpu(opuBuilder.build());
556
557         if (apiInfoA != null) {
558             oduBuilder.setTxSapi(apiInfoA.getSapi())
559                 .setTxDapi(apiInfoA.getDapi())
560                 .setExpectedSapi(apiInfoA.getExpectedSapi())
561                 .setExpectedDapi(apiInfoA.getExpectedDapi());
562         }
563         if (apiInfoZ != null) {
564             oduBuilder.setTxSapi(apiInfoZ.getSapi())
565                 .setTxDapi(apiInfoZ.getDapi())
566                 .setExpectedSapi(apiInfoZ.getExpectedSapi())
567                 .setExpectedDapi(apiInfoZ.getExpectedDapi());
568         }
569         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
570             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
571
572         oduInterfaceBldr.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
573
574         // Post interface on the device
575         openRoadmInterfaces.postInterface(nodeId, oduInterfaceBldr);
576         // Since this is not a CTP, we can update the port-mapping
577         LOG.info("{}-{} updating mapping with interface {}", nodeId, logicalConnPoint, oduInterfaceBldr.getName());
578         this.portMapping.updateMapping(nodeId, mapping);
579
580         return oduInterfaceBldr.getName();
581     }
582
583
584     public String createOpenRoadmOducnInterface(String nodeId, String logicalConnPoint)
585             throws OpenRoadmInterfaceException {
586         Mapping mapping = portMapping.getMapping(nodeId, logicalConnPoint);
587         if (mapping == null) {
588             throw new OpenRoadmInterfaceException(
589                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
590                     nodeId, logicalConnPoint));
591         }
592         // Create ODUcn object
593         // Start with OPU object
594         // OPU payload
595         OpuBuilder opuBuilder = new OpuBuilder()
596             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("22"))
597             .setPayloadType(PayloadTypeDef.getDefaultInstance("22"));
598
599         // Create an ODUCn object
600         OduBuilder oduBuilder = new OduBuilder()
601             .setRate(ODUCn.class)
602             .setOduFunction(ODUTTP.class)
603             .setMonitoringMode(MonitoringMode.Terminated)
604             .setTimActEnabled(false)
605             .setTimDetectMode(TimDetectMode.Disabled)
606             .setDegmIntervals(Uint8.valueOf(2))
607             .setDegthrPercentage(Uint16.valueOf(100))
608             .setOducnNRate(Uint16.valueOf(4))
609             .setOpu(opuBuilder.build());
610
611         // Create a list
612         String supportingOtucn;
613         List<String> listSupportingOtucnInterface = new ArrayList<>();
614         if (mapping.getSupportingOtucn() != null) {
615             listSupportingOtucnInterface.add(mapping.getSupportingOtucn());
616             supportingOtucn = mapping.getSupportingOtucn();
617         } else {
618             throw new OpenRoadmInterfaceException(
619                 String.format("Missing supporting OTUCn interface on port-mapping"));
620         }
621
622         // Set the ODUCn rate from OTUCn interface naming convention
623         String oducnrate = supportingOtucn.substring(supportingOtucn.length() - 1);
624         // check if the oducnrate is a valid value and if it is invalid, then throw error
625         if (!SUPPORTED_ODUCN_RATES.contains(oducnrate)) {
626             throw new OpenRoadmInterfaceException(
627                 String.format(RATE_EXCEPTION_MESSAGE));
628         }
629
630         oduBuilder.setOducnNRate(Uint16.valueOf(oducnrate));
631
632         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(mapping, OtnOdu.class,
633             logicalConnPoint + "-ODUC" + oducnrate);
634
635         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
636         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
637             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
638
639         oduInterfaceBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
640
641         // Post interface on the device
642         openRoadmInterfaces.postInterface(nodeId, oduInterfaceBuilder);
643
644         // Post the equipment-state change on the device circuit-pack if xpdr node
645         if (mapping.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
646             this.openRoadmInterfaces.postEquipmentState(nodeId, mapping.getSupportingCircuitPackName(), true);
647         }
648
649         return oduInterfaceBuilder.getName();
650     }
651
652     // Overloaded methods should be together
653     // With SAPI and DAPI information
654     public String createOpenRoadmOducnInterface(String anodeId, String alogicalConnPoint,
655         String supportingOtucn, String znodeId, String zlogicalConnPoint)
656         throws OpenRoadmInterfaceException {
657         Mapping portMapA = portMapping.getMapping(anodeId, alogicalConnPoint);
658         Mapping portMapZ = portMapping.getMapping(znodeId, zlogicalConnPoint);
659         if (portMapA == null) {
660             throw new OpenRoadmInterfaceException(
661                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
662                     anodeId, alogicalConnPoint));
663         }
664         // On the Zside
665         if (portMapZ == null) {
666             throw new OpenRoadmInterfaceException(
667                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
668                     znodeId, zlogicalConnPoint));
669
670         }
671         // Create ODUcn object
672         // Start with OPU object
673         // OPU payload
674         OpuBuilder opuBuilder = new OpuBuilder()
675             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("22"))
676             .setPayloadType(PayloadTypeDef.getDefaultInstance("22"));
677
678         // Create an ODUC4 object
679         OduBuilder oduBuilder = new OduBuilder()
680             .setRate(ODUCn.class)
681             .setOduFunction(ODUTTP.class)
682             .setMonitoringMode(MonitoringMode.Terminated)
683             .setTimActEnabled(false)
684             .setTimDetectMode(TimDetectMode.Disabled)
685             .setDegmIntervals(Uint8.valueOf(2))
686             .setDegthrPercentage(Uint16.valueOf(100))
687             .setOpu(opuBuilder.build())
688             .setTxSapi(portMapA.getLcpHashVal())
689             .setTxDapi(portMapZ.getLcpHashVal())
690             .setExpectedSapi(portMapZ.getLcpHashVal())
691             .setExpectedDapi(portMapZ.getLcpHashVal());
692
693         // Set the ODUCn rate from OTUCn interface naming convention
694         String oducnrate = supportingOtucn.substring(supportingOtucn.length() - 1);
695
696         // check if the oducnrate is a valid value and if it is invalid, then throw error
697         if (!SUPPORTED_ODUCN_RATES.contains(oducnrate)) {
698             throw new OpenRoadmInterfaceException(
699                 String.format(RATE_EXCEPTION_MESSAGE));
700         }
701
702         oduBuilder.setOducnNRate(Uint16.valueOf(oducnrate));
703
704         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMapA, OtnOdu.class,
705             alogicalConnPoint + ODUC + oducnrate);
706
707         // Create a list
708         List<String> listSupportingOtucnInterface = new ArrayList<>();
709         listSupportingOtucnInterface.add(supportingOtucn);
710
711         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
712         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
713             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
714
715         oduInterfaceBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
716
717         // Post interface on the device
718         openRoadmInterfaces.postInterface(anodeId, oduInterfaceBuilder);
719
720         // Post the equipment-state change on the device circuit-pack if xpdr node
721         if (portMapA.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
722             this.openRoadmInterfaces.postEquipmentState(anodeId, portMapA.getSupportingCircuitPackName(), true);
723         }
724
725         return oduInterfaceBuilder.getName();
726     }
727
728
729     // This is only for transponder
730     public String createOpenRoadmOduflexInterface(String nodeId, String logicalConnPoint,
731         String supportingOducn)
732         throws OpenRoadmInterfaceException {
733         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
734         if (portMap == null) {
735             throw new OpenRoadmInterfaceException(
736                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
737                     nodeId, logicalConnPoint));
738         }
739         // OPU payload
740         OpuBuilder opuBuilder = new OpuBuilder()
741             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("32"))
742             .setPayloadType(PayloadTypeDef.getDefaultInstance("32"));
743
744         // Parent Odu-allocation
745         // Set the trib-slot array
746         List<OpucnTribSlotDef> tribslots = new ArrayList<>();
747         IntStream.range(1, 5).forEach(a -> IntStream.range(1, 21).forEach(b -> tribslots.add(
748             OpucnTribSlotDef.getDefaultInstance(a + "." + b))));
749
750         ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
751             .setTribPortNumber(Uint16.valueOf(1))
752             .setTribSlotsChoice(new OpucnBuilder().setOpucnTribSlots(tribslots).build());
753
754         // Create an ODUFlex object
755         OduBuilder oduBuilder = new OduBuilder()
756             .setRate(ODUflexCbr.class)
757             .setOduflexCbrService(ODUflexCbr400G.class)
758             .setOduFunction(ODUTTPCTP.class)
759             .setMonitoringMode(MonitoringMode.Terminated)
760             .setTimActEnabled(false)
761             .setTimDetectMode(TimDetectMode.Disabled)
762             .setDegmIntervals(Uint8.valueOf(2))
763             .setDegthrPercentage(Uint16.valueOf(100))
764             .setOpu(opuBuilder.build())
765             .setParentOduAllocation(parentOduAllocationBuilder.build());
766
767         InterfaceBuilder oduflexInterfaceBuilder = createGenericInterfaceBuilder(portMap, OtnOdu.class,
768             logicalConnPoint + "-ODUFLEX");
769
770         List<String> listSupportingOtucnInterface = new ArrayList<>();
771         listSupportingOtucnInterface.add(supportingOducn);
772
773         oduflexInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
774
775
776         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder
777             oduflexIf1Builder =
778             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
779
780         oduflexInterfaceBuilder.addAugmentation(oduflexIf1Builder.setOdu(oduBuilder.build()).build());
781
782         // Post interface on the device
783         openRoadmInterfaces.postInterface(nodeId, oduflexInterfaceBuilder);
784
785         // Post the equipment-state change on the device circuit-pack if xpdr node
786         if (portMap.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
787             this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
788         }
789
790         return oduflexInterfaceBuilder.getName();
791     }
792
793     // Overloaded methods should be together
794     // This is only for transponder; with SAPI/DAPI information
795     public String createOpenRoadmOduflexInterface(String anodeId, String alogicalConnPoint,
796         String supportingOducn, String znodeId, String zlogicalConnPoint)
797         throws OpenRoadmInterfaceException {
798         Mapping portMapA = portMapping.getMapping(anodeId, alogicalConnPoint);
799         Mapping portMapZ = portMapping.getMapping(znodeId, zlogicalConnPoint);
800         if (portMapA == null) {
801             throw new OpenRoadmInterfaceException(
802                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
803                     anodeId, alogicalConnPoint));
804         }
805         // On the Zside
806         if (portMapZ == null) {
807             throw new OpenRoadmInterfaceException(
808                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
809                     znodeId, zlogicalConnPoint));
810
811         }
812         // OPU payload
813         OpuBuilder opuBuilder = new OpuBuilder()
814             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("32"))
815             .setPayloadType(PayloadTypeDef.getDefaultInstance("32"));
816
817         // Parent Odu-allocation
818         // Set the trib-slot array
819         List<OpucnTribSlotDef> tribslots = new ArrayList<>();
820         IntStream.range(1, 5).forEach(a -> IntStream.range(1, 21).forEach(b -> tribslots.add(
821             OpucnTribSlotDef.getDefaultInstance(a + "." + b))));
822
823         ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
824             .setTribPortNumber(Uint16.valueOf(1))
825             .setTribSlotsChoice(new OpucnBuilder().setOpucnTribSlots(tribslots).build());
826
827         // Create an ODUFlex object
828         OduBuilder oduBuilder = new OduBuilder()
829             .setRate(ODUflexCbr.class)
830             .setOduflexCbrService(ODUflexCbr400G.class)
831             .setOduFunction(ODUTTPCTP.class)
832             .setMonitoringMode(MonitoringMode.Terminated)
833             .setTimActEnabled(false)
834             .setTimDetectMode(TimDetectMode.Disabled)
835             .setDegmIntervals(Uint8.valueOf(2))
836             .setDegthrPercentage(Uint16.valueOf(100))
837             .setTxSapi(portMapA.getLcpHashVal())
838             .setTxDapi(portMapZ.getLcpHashVal())
839             .setExpectedSapi(portMapZ.getLcpHashVal())
840             .setExpectedDapi(portMapA.getLcpHashVal())
841             .setOpu(opuBuilder.build())
842             .setParentOduAllocation(parentOduAllocationBuilder.build());
843
844         InterfaceBuilder oduflexInterfaceBuilder = createGenericInterfaceBuilder(portMapA, OtnOdu.class,
845             alogicalConnPoint + "-ODUFLEX");
846
847         List<String> listSupportingOtucnInterface = new ArrayList<>();
848         listSupportingOtucnInterface.add(supportingOducn);
849
850         oduflexInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
851
852
853         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder
854             oduflexIf1Builder =
855             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
856
857         oduflexInterfaceBuilder.addAugmentation(oduflexIf1Builder.setOdu(oduBuilder.build()).build());
858
859         // Post interface on the device
860         openRoadmInterfaces.postInterface(anodeId, oduflexInterfaceBuilder);
861
862         // Post the equipment-state change on the device circuit-pack if xpdr node
863         if (portMapA.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
864             this.openRoadmInterfaces.postEquipmentState(anodeId, portMapA.getSupportingCircuitPackName(), true);
865         }
866
867         return oduflexInterfaceBuilder.getName();
868     }
869
870     public String createOpenRoadmOdu4OducnOduflex(String nodeId, String logicalConnPoint,
871         AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ) throws OpenRoadmInterfaceException {
872
873         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
874         if (portMap == null) {
875             throw new OpenRoadmInterfaceException(
876                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
877         }
878         // Depending on OTU4 or OTUCn, supporting interface should
879         // reflect that
880         String interfaceOdu4Oducn = null;
881         if (portMap.getSupportedInterfaceCapability().contains(IfOCHOTU4ODU4.class)) {
882             // create OTU4 interface
883             interfaceOdu4Oducn = createOpenRoadmOdu4Interface(nodeId, logicalConnPoint, apiInfoA, apiInfoZ);
884         } else if (portMap.getSupportedInterfaceCapability().contains(IfOtsiOtsigroup.class)) {
885             // Create ODUCn and ODUFlex interface.
886             String interfaceOducn = createOpenRoadmOducnInterface(nodeId, logicalConnPoint);
887             interfaceOdu4Oducn = createOpenRoadmOduflexInterface(nodeId, logicalConnPoint, interfaceOducn);
888         }
889
890         return interfaceOdu4Oducn;
891     }
892
893     public String createOpenRoadmOtnOducnInterface(String nodeId, String logicalConnPoint,
894         String supportingOtucn)
895         throws OpenRoadmInterfaceException {
896         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
897         if (portMap == null) {
898             throw new OpenRoadmInterfaceException(
899                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
900                     nodeId, logicalConnPoint));
901         }
902         // Create ODUcn object
903         // Start with OPU object
904         // OPU payload
905         OpuBuilder opuBuilder = new OpuBuilder()
906             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("22"))
907             .setPayloadType(PayloadTypeDef.getDefaultInstance("22"));
908
909         // Create an ODUC4 object
910         OduBuilder oduBuilder = new OduBuilder()
911             .setRate(ODUCn.class)
912             .setOduFunction(ODUTTP.class)
913             .setMonitoringMode(MonitoringMode.Terminated)
914             .setTimActEnabled(false)
915             .setTimDetectMode(TimDetectMode.Disabled)
916             .setDegmIntervals(Uint8.valueOf(2))
917             .setDegthrPercentage(Uint16.valueOf(100))
918             .setOpu(opuBuilder.build());
919
920         // Set the ODUCn rate from OTUCn interface naming convention
921         String oducnrate = supportingOtucn.substring(supportingOtucn.length() - 1);
922
923         // check if the oducnrate is a valid value and if it is invalid, then throw error
924         if (!SUPPORTED_ODUCN_RATES.contains(oducnrate)) {
925             throw new OpenRoadmInterfaceException(
926                 String.format(RATE_EXCEPTION_MESSAGE));
927         }
928
929         oduBuilder.setOducnNRate(Uint16.valueOf(oducnrate));
930
931         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMap, OtnOdu.class,
932             logicalConnPoint + ODUC + oducnrate);
933
934         // Create a list
935         List<String> listSupportingOtucnInterface = new ArrayList<>();
936         listSupportingOtucnInterface.add(supportingOtucn);
937
938         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
939         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
940             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
941
942         oduInterfaceBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
943
944         // Post interface on the device
945         openRoadmInterfaces.postInterface(nodeId, oduInterfaceBuilder);
946         // Post the equipment-state change on the device circuit-pack if xpdr node
947         if (portMap.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
948             this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
949         }
950         // Update the port-mapping with the interface information
951         this.portMapping.updateMapping(nodeId, portMap);
952         return oduInterfaceBuilder.getName();
953     }
954
955
956     // With SAPI and DAPI information
957     public String createOpenRoadmOtnOducnInterface(String anodeId, String alogicalConnPoint,
958         String supportingOtucn, String znodeId, String zlogicalConnPoint)
959         throws OpenRoadmInterfaceException {
960         Mapping portMapA = portMapping.getMapping(anodeId, alogicalConnPoint);
961         Mapping portMapZ = portMapping.getMapping(znodeId, zlogicalConnPoint);
962         if (portMapA == null) {
963             throw new OpenRoadmInterfaceException(
964                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
965                     anodeId, alogicalConnPoint));
966         }
967         // On the Zside
968         if (portMapZ == null) {
969             throw new OpenRoadmInterfaceException(
970                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
971                     znodeId, zlogicalConnPoint));
972
973         }
974         // Create ODUcn object
975         // Start with OPU object
976         // OPU payload
977         OpuBuilder opuBuilder = new OpuBuilder()
978             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("22"))
979             .setPayloadType(PayloadTypeDef.getDefaultInstance("22"));
980
981         // Create an ODUCn object
982         OduBuilder oduBuilder = new OduBuilder()
983             .setRate(ODUCn.class)
984             .setOduFunction(ODUTTP.class)
985             .setMonitoringMode(MonitoringMode.Terminated)
986             .setTimActEnabled(false)
987             .setTimDetectMode(TimDetectMode.Disabled)
988             .setDegmIntervals(Uint8.valueOf(2))
989             .setDegthrPercentage(Uint16.valueOf(100))
990             .setOpu(opuBuilder.build())
991             .setTxSapi(portMapA.getLcpHashVal())
992             .setTxDapi(portMapZ.getLcpHashVal())
993             .setExpectedSapi(portMapZ.getLcpHashVal())
994             .setExpectedDapi(portMapZ.getLcpHashVal());
995
996         // Set the ODUCn rate from OTUCn interface naming convention
997         String oducnrate = supportingOtucn.substring(supportingOtucn.length() - 1);
998
999         // check if the oducnrate is a valid value and if it is invalid, then throw error
1000         if (!SUPPORTED_ODUCN_RATES.contains(oducnrate)) {
1001             throw new OpenRoadmInterfaceException(
1002                 String.format(RATE_EXCEPTION_MESSAGE));
1003         }
1004
1005         oduBuilder.setOducnNRate(Uint16.valueOf(oducnrate));
1006
1007         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMapA, OtnOdu.class,
1008             alogicalConnPoint + ODUC + oducnrate);
1009
1010         // Create a list
1011         List<String> listSupportingOtucnInterface = new ArrayList<>();
1012         listSupportingOtucnInterface.add(supportingOtucn);
1013
1014         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
1015         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
1016             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
1017
1018         oduInterfaceBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
1019
1020         // Post interface on the device
1021         openRoadmInterfaces.postInterface(anodeId, oduInterfaceBuilder);
1022         // Post the equipment-state change on the device circuit-pack if xpdr node
1023         if (portMapA.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
1024             this.openRoadmInterfaces.postEquipmentState(anodeId, portMapA.getSupportingCircuitPackName(), true);
1025         }
1026         // Update the port-mapping with the interface information
1027         this.portMapping.updateMapping(anodeId, portMapA);
1028         return oduInterfaceBuilder.getName();
1029     }
1030
1031     // This creates the name of the interface with slot numbers at the end
1032     public String createOpenRoadmOtsiInterfaceName(String logicalConnectionPoint, String spectralSlotName) {
1033         return String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, logicalConnectionPoint, spectralSlotName);
1034     }
1035
1036     private InterfaceBuilder createGenericInterfaceBuilder(Mapping portMap, Class<? extends InterfaceType> type,
1037             String key) {
1038         return new org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.InterfaceBuilder()
1039             .setDescription("  TBD   ")
1040             .setCircuitId("   TBD    ")
1041             .setSupportingCircuitPackName(portMap.getSupportingCircuitPackName())
1042             .setSupportingPort(portMap.getSupportingPort())
1043             .setAdministrativeState(AdminStates.InService)
1044             .setType(type)
1045             .setName(key)
1046             .withKey(new InterfaceKey(key));
1047     }
1048
1049     @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
1050         value = "UPM_UNCALLED_PRIVATE_METHOD",
1051         justification = "call in call() method")
1052     private int getServiceRate(ModulationFormat modulationFormat, SpectrumInformation spectrumInformation) {
1053
1054         switch (modulationFormat) {
1055             case DpQpsk:
1056                 LOG.info("Given modulation format is {} and thus rate is 200G", modulationFormat);
1057                 return 200;
1058             case DpQam8:
1059                 LOG.info("Given modulation format is {} and thus rate is 300G", modulationFormat);
1060                 return 300;
1061             case DpQam16:
1062                 // DpQam16 is possible for both 31.6 or 63.1 GBaud, for which spectral width is different
1063                 // Here take the difference of highest and lowest spectral numbers and determine the width
1064                 LOG.info("The width with guard band {}", (spectrumInformation.getHigherSpectralSlotNumber()
1065                     - spectrumInformation.getLowerSpectralSlotNumber() + 1) * GridConstant.GRANULARITY);
1066                 if ((spectrumInformation.getHigherSpectralSlotNumber()
1067                     - spectrumInformation.getLowerSpectralSlotNumber() + 1) * GridConstant.GRANULARITY == 50.0) {
1068                     // Based on roll-of-factor of 0.5, 50 - 12.5 = 37.5GHz translates to 31.6 GBaud
1069                     LOG.info("The baud-rate is 31.6 GBaud");
1070                     LOG.info("Given modulation format {} with 31.6 Gbaud rate is 200G", modulationFormat);
1071                     return 200;
1072                 } else {
1073                     // Based on roll-of-factor of 0.5, 87.5 - 12.5 = 75GHz translates to 63.1 GBaud
1074                     LOG.info("The baud-rate is 63.1 GBaud");
1075                     return 400;
1076                 }
1077             default:
1078                 LOG.error("Modulation format is required to select the rate");
1079                 break;
1080         }
1081         return 0;
1082     }
1083
1084 }