Merge "Drop the service name from ODU connection name"
[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.rev220316.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.rev201211.If100GE;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOCHOTU4ODU4;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.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 and concat the names of the interface
369             String interfaceOtsiName = createOpenRoadmOtsiInterface(nodeId, logicalConnPoint, spectrumInformation);
370             // Concat the two names for this interface
371             interfaceOchOtsiOtsigroup = interfaceOtsiName
372                 + "#" + createOpenRoadmOtsiGroupInterface(nodeId, logicalConnPoint, interfaceOtsiName,
373                 spectrumInformation);
374         }
375
376         return interfaceOchOtsiOtsigroup;
377     }
378
379     public String createOpenRoadmOtu4Interface(String nodeId, String logicalConnPoint, String supportOchInterface,
380         AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ) throws OpenRoadmInterfaceException {
381
382         Mapping mapping = this.portMapping.getMapping(nodeId, logicalConnPoint);
383         if (mapping == null) {
384             throw new OpenRoadmInterfaceException(
385                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
386         }
387         InterfaceBuilder
388             otuInterfaceBldr = createGenericInterfaceBuilder(mapping, OtnOtu.class,
389             logicalConnPoint + "-OTU4");
390         // Supporting interface list
391         List<String> listSupportingOChInterface = new ArrayList<>();
392         listSupportingOChInterface.add(supportOchInterface);
393         otuInterfaceBldr.setSupportingInterfaceList(listSupportingOChInterface);
394
395         // OTU interface specific data
396         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev200529.otu.container.OtuBuilder
397             otuIfBuilder = new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu
398             .interfaces.rev200529.otu.container.OtuBuilder()
399             .setFec(Scfec.class)
400             .setRate(OTU4.class);
401         if (apiInfoA != null) {
402             otuIfBuilder.setTxSapi(apiInfoA.getSapi())
403                 .setTxDapi(apiInfoA.getDapi())
404                 .setExpectedSapi(apiInfoA.getExpectedSapi())
405                 .setExpectedDapi(apiInfoA.getExpectedDapi());
406         }
407         if (apiInfoZ != null) {
408             otuIfBuilder.setTxSapi(apiInfoZ.getSapi())
409                 .setTxDapi(apiInfoZ.getDapi())
410                 .setExpectedSapi(apiInfoZ.getExpectedSapi())
411                 .setExpectedDapi(apiInfoZ.getExpectedDapi());
412         }
413
414         // Create Interface1 type object required for adding as augmentation
415         // TODO look at imports of different versions of class
416         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev200529.Interface1Builder otuIf1Builder =
417             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev200529.Interface1Builder();
418         otuInterfaceBldr.addAugmentation(otuIf1Builder.setOtu(otuIfBuilder.build()).build());
419
420         // Post interface on the device
421         openRoadmInterfaces.postInterface(nodeId, otuInterfaceBldr);
422         this.portMapping.updateMapping(nodeId, mapping);
423         return otuInterfaceBldr.getName();
424     }
425
426
427     public String createOpenRoadmOtucnInterface(String nodeId, String logicalConnPoint,
428             String supportingOtsiGroupInterface, AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ)
429             throws OpenRoadmInterfaceException {
430         Mapping mapping = portMapping.getMapping(nodeId, logicalConnPoint);
431         if (mapping == null) {
432             throw new OpenRoadmInterfaceException(
433                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
434                     nodeId, logicalConnPoint));
435         }
436         // Create an OTUCn object
437         OtuBuilder otuBuilder = new OtuBuilder()
438             .setRate(OTUCn.class)
439             .setTimActEnabled(false)
440             .setTimDetectMode(TimDetectMode.Disabled)
441             .setDegmIntervals(Uint8.valueOf(2))
442             .setDegthrPercentage(Uint16.valueOf(100));
443
444         if (apiInfoA != null) {
445             otuBuilder.setTxSapi(apiInfoA.getSapi())
446                 .setTxDapi(apiInfoA.getDapi())
447                 .setExpectedSapi(apiInfoA.getExpectedSapi())
448                 .setExpectedDapi(apiInfoA.getExpectedDapi());
449         }
450         if (apiInfoZ != null) {
451             otuBuilder.setTxSapi(apiInfoZ.getSapi())
452                 .setTxDapi(apiInfoZ.getDapi())
453                 .setExpectedSapi(apiInfoZ.getExpectedSapi())
454                 .setExpectedDapi(apiInfoZ.getExpectedDapi());
455         }
456         // Set the OTUCn rate for various rates
457         String rate = supportingOtsiGroupInterface.substring(supportingOtsiGroupInterface.lastIndexOf('-') + 1);
458
459         String otucnrate = null;
460         boolean rateNotFound = false;
461         switch (rate) {
462             case "200G":
463                 otuBuilder.setOtucnNRate(Uint16.valueOf(2));
464                 otucnrate = "2";
465                 break;
466             case "300G":
467                 otuBuilder.setOtucnNRate(Uint16.valueOf(3));
468                 otucnrate = "3";
469                 break;
470             case "400G":
471                 otuBuilder.setOtucnNRate(Uint16.valueOf(4));
472                 otucnrate = "4";
473                 break;
474             default:
475                 LOG.error("Rate {} is not supported", rate);
476                 rateNotFound = true;
477                 break;
478         }
479         if (rateNotFound) {
480             throw new OpenRoadmInterfaceException(
481                 String.format(RATE_EXCEPTION_MESSAGE));
482         }
483
484         InterfaceBuilder otuInterfaceBuilder = createGenericInterfaceBuilder(mapping, OtnOtu.class,
485             logicalConnPoint + "-OTUC" + otucnrate);
486
487         // Create a list
488         List<String> listSupportingOtsiGroupInterface = new ArrayList<>();
489         listSupportingOtsiGroupInterface.add(supportingOtsiGroupInterface);
490
491         otuInterfaceBuilder.setSupportingInterfaceList(listSupportingOtsiGroupInterface);
492         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev200529.Interface1Builder otuIf1Builder =
493             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev200529.Interface1Builder();
494
495         otuInterfaceBuilder.addAugmentation(otuIf1Builder.setOtu(otuBuilder.build()).build());
496
497         // Post interface on the device
498         openRoadmInterfaces.postInterface(nodeId, otuInterfaceBuilder);
499         // Post the equipment-state change on the device circuit-pack if xpdr node
500         if (mapping.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
501             this.openRoadmInterfaces.postEquipmentState(nodeId, mapping.getSupportingCircuitPackName(), true);
502         }
503         this.portMapping.updateMapping(nodeId, mapping);
504         return otuInterfaceBuilder.getName();
505     }
506
507     public String createOpenRoadmOtu4OtucnInterface(String nodeId, String logicalConnPoint,
508         String supportingInterface, AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ)
509         throws OpenRoadmInterfaceException {
510         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
511         if (portMap == null) {
512             throw new OpenRoadmInterfaceException(
513                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
514         }
515         // Depending on OCH-OTU4-ODU4 interface or OTSi-OTSi-group, supporting interface should
516         // reflect that
517         String interfaceOtu4Otucn = null;
518         if (portMap.getSupportedInterfaceCapability().contains(IfOCHOTU4ODU4.class)) {
519             // create OTU4 interface
520             interfaceOtu4Otucn = createOpenRoadmOtu4Interface(nodeId, logicalConnPoint, supportingInterface,
521                 apiInfoA, apiInfoZ);
522         } else if (portMap.getSupportedInterfaceCapability().contains(IfOtsiOtsigroup.class)) {
523             // Create OTUCn
524             interfaceOtu4Otucn = createOpenRoadmOtucnInterface(nodeId, logicalConnPoint, supportingInterface,
525                 apiInfoA, apiInfoZ);
526         }
527
528         return interfaceOtu4Otucn;
529     }
530
531     public String createOpenRoadmOdu4Interface(String nodeId, String logicalConnPoint,
532         AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ) throws OpenRoadmInterfaceException {
533
534         Mapping mapping = portMapping.getMapping(nodeId, logicalConnPoint);
535         if (mapping == null) {
536             throw new OpenRoadmInterfaceException(
537                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
538         }
539         InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(mapping, OtnOdu.class,
540             logicalConnPoint + "-ODU4");
541         List<String> listSupportingOtu4Interface = new ArrayList<>();
542         if (mapping.getSupportingOtu4() != null) {
543             listSupportingOtu4Interface.add(mapping.getSupportingOtu4());
544             oduInterfaceBldr.setSupportingInterfaceList(listSupportingOtu4Interface);
545         }
546
547         // OPU payload
548         OpuBuilder opuBuilder = new OpuBuilder()
549             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("07"))
550             .setPayloadType(PayloadTypeDef.getDefaultInstance("07"));
551
552         // Create an ODU4 object
553         OduBuilder oduBuilder = new OduBuilder()
554             .setRate(ODU4.class)
555             .setOduFunction(ODUTTP.class)
556             .setMonitoringMode(MonitoringMode.Terminated)
557             .setOpu(opuBuilder.build());
558
559         if (apiInfoA != null) {
560             oduBuilder.setTxSapi(apiInfoA.getSapi())
561                 .setTxDapi(apiInfoA.getDapi())
562                 .setExpectedSapi(apiInfoA.getExpectedSapi())
563                 .setExpectedDapi(apiInfoA.getExpectedDapi());
564         }
565         if (apiInfoZ != null) {
566             oduBuilder.setTxSapi(apiInfoZ.getSapi())
567                 .setTxDapi(apiInfoZ.getDapi())
568                 .setExpectedSapi(apiInfoZ.getExpectedSapi())
569                 .setExpectedDapi(apiInfoZ.getExpectedDapi());
570         }
571         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
572             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
573
574         oduInterfaceBldr.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
575
576         // Post interface on the device
577         openRoadmInterfaces.postInterface(nodeId, oduInterfaceBldr);
578         // Since this is not a CTP, we can update the port-mapping
579         LOG.info("{}-{} updating mapping with interface {}", nodeId, logicalConnPoint, oduInterfaceBldr.getName());
580         this.portMapping.updateMapping(nodeId, mapping);
581
582         return oduInterfaceBldr.getName();
583     }
584
585
586     public String createOpenRoadmOducnInterface(String nodeId, String logicalConnPoint)
587             throws OpenRoadmInterfaceException {
588         Mapping mapping = portMapping.getMapping(nodeId, logicalConnPoint);
589         if (mapping == null) {
590             throw new OpenRoadmInterfaceException(
591                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
592                     nodeId, logicalConnPoint));
593         }
594         // Create ODUcn object
595         // Start with OPU object
596         // OPU payload
597         OpuBuilder opuBuilder = new OpuBuilder()
598             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("22"))
599             .setPayloadType(PayloadTypeDef.getDefaultInstance("22"));
600
601         // Create an ODUCn object
602         OduBuilder oduBuilder = new OduBuilder()
603             .setRate(ODUCn.class)
604             .setOduFunction(ODUTTP.class)
605             .setMonitoringMode(MonitoringMode.Terminated)
606             .setTimActEnabled(false)
607             .setTimDetectMode(TimDetectMode.Disabled)
608             .setDegmIntervals(Uint8.valueOf(2))
609             .setDegthrPercentage(Uint16.valueOf(100))
610             .setOducnNRate(Uint16.valueOf(4))
611             .setOpu(opuBuilder.build());
612
613         // Create a list
614         String supportingOtucn;
615         List<String> listSupportingOtucnInterface = new ArrayList<>();
616         if (mapping.getSupportingOtucn() != null) {
617             listSupportingOtucnInterface.add(mapping.getSupportingOtucn());
618             supportingOtucn = mapping.getSupportingOtucn();
619         } else {
620             throw new OpenRoadmInterfaceException(
621                 String.format("Missing supporting OTUCn interface on port-mapping"));
622         }
623
624         // Set the ODUCn rate from OTUCn interface naming convention
625         String oducnrate = supportingOtucn.substring(supportingOtucn.length() - 1);
626         // check if the oducnrate is a valid value and if it is invalid, then throw error
627         if (!SUPPORTED_ODUCN_RATES.contains(oducnrate)) {
628             throw new OpenRoadmInterfaceException(
629                 String.format(RATE_EXCEPTION_MESSAGE));
630         }
631
632         oduBuilder.setOducnNRate(Uint16.valueOf(oducnrate));
633
634         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(mapping, OtnOdu.class,
635             logicalConnPoint + "-ODUC" + oducnrate);
636
637         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
638         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
639             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
640
641         oduInterfaceBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
642
643         // Post interface on the device
644         openRoadmInterfaces.postInterface(nodeId, oduInterfaceBuilder);
645
646         // Post the equipment-state change on the device circuit-pack if xpdr node
647         if (mapping.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
648             this.openRoadmInterfaces.postEquipmentState(nodeId, mapping.getSupportingCircuitPackName(), true);
649         }
650
651         return oduInterfaceBuilder.getName();
652     }
653
654     // Overloaded methods should be together
655     // With SAPI and DAPI information
656     public String createOpenRoadmOducnInterface(String anodeId, String alogicalConnPoint,
657         String supportingOtucn, String znodeId, String zlogicalConnPoint)
658         throws OpenRoadmInterfaceException {
659         Mapping portMapA = portMapping.getMapping(anodeId, alogicalConnPoint);
660         Mapping portMapZ = portMapping.getMapping(znodeId, zlogicalConnPoint);
661         if (portMapA == null) {
662             throw new OpenRoadmInterfaceException(
663                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
664                     anodeId, alogicalConnPoint));
665         }
666         // On the Zside
667         if (portMapZ == null) {
668             throw new OpenRoadmInterfaceException(
669                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
670                     znodeId, zlogicalConnPoint));
671
672         }
673         // Create ODUcn object
674         // Start with OPU object
675         // OPU payload
676         OpuBuilder opuBuilder = new OpuBuilder()
677             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("22"))
678             .setPayloadType(PayloadTypeDef.getDefaultInstance("22"));
679
680         // Create an ODUC4 object
681         OduBuilder oduBuilder = new OduBuilder()
682             .setRate(ODUCn.class)
683             .setOduFunction(ODUTTP.class)
684             .setMonitoringMode(MonitoringMode.Terminated)
685             .setTimActEnabled(false)
686             .setTimDetectMode(TimDetectMode.Disabled)
687             .setDegmIntervals(Uint8.valueOf(2))
688             .setDegthrPercentage(Uint16.valueOf(100))
689             .setOpu(opuBuilder.build())
690             .setTxSapi(portMapA.getLcpHashVal())
691             .setTxDapi(portMapZ.getLcpHashVal())
692             .setExpectedSapi(portMapZ.getLcpHashVal())
693             .setExpectedDapi(portMapZ.getLcpHashVal());
694
695         // Set the ODUCn rate from OTUCn interface naming convention
696         String oducnrate = supportingOtucn.substring(supportingOtucn.length() - 1);
697
698         // check if the oducnrate is a valid value and if it is invalid, then throw error
699         if (!SUPPORTED_ODUCN_RATES.contains(oducnrate)) {
700             throw new OpenRoadmInterfaceException(
701                 String.format(RATE_EXCEPTION_MESSAGE));
702         }
703
704         oduBuilder.setOducnNRate(Uint16.valueOf(oducnrate));
705
706         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMapA, OtnOdu.class,
707             alogicalConnPoint + ODUC + oducnrate);
708
709         // Create a list
710         List<String> listSupportingOtucnInterface = new ArrayList<>();
711         listSupportingOtucnInterface.add(supportingOtucn);
712
713         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
714         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
715             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
716
717         oduInterfaceBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
718
719         // Post interface on the device
720         openRoadmInterfaces.postInterface(anodeId, oduInterfaceBuilder);
721
722         // Post the equipment-state change on the device circuit-pack if xpdr node
723         if (portMapA.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
724             this.openRoadmInterfaces.postEquipmentState(anodeId, portMapA.getSupportingCircuitPackName(), true);
725         }
726
727         return oduInterfaceBuilder.getName();
728     }
729
730
731     // This is only for transponder
732     public String createOpenRoadmOduflexInterface(String nodeId, String logicalConnPoint,
733         String supportingOducn)
734         throws OpenRoadmInterfaceException {
735         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
736         if (portMap == null) {
737             throw new OpenRoadmInterfaceException(
738                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
739                     nodeId, logicalConnPoint));
740         }
741         // OPU payload
742         OpuBuilder opuBuilder = new OpuBuilder()
743             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("32"))
744             .setPayloadType(PayloadTypeDef.getDefaultInstance("32"));
745
746         // Parent Odu-allocation
747         // Set the trib-slot array
748         List<OpucnTribSlotDef> tribslots = new ArrayList<>();
749         IntStream.range(1, 5).forEach(a -> IntStream.range(1, 21).forEach(b -> tribslots.add(
750             OpucnTribSlotDef.getDefaultInstance(a + "." + b))));
751
752         ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
753             .setTribPortNumber(Uint16.valueOf(1))
754             .setTribSlotsChoice(new OpucnBuilder().setOpucnTribSlots(tribslots).build());
755
756         // Create an ODUFlex object
757         OduBuilder oduBuilder = new OduBuilder()
758             .setRate(ODUflexCbr.class)
759             .setOduflexCbrService(ODUflexCbr400G.class)
760             .setOduFunction(ODUTTPCTP.class)
761             .setMonitoringMode(MonitoringMode.Terminated)
762             .setTimActEnabled(false)
763             .setTimDetectMode(TimDetectMode.Disabled)
764             .setDegmIntervals(Uint8.valueOf(2))
765             .setDegthrPercentage(Uint16.valueOf(100))
766             .setOpu(opuBuilder.build())
767             .setParentOduAllocation(parentOduAllocationBuilder.build());
768
769         InterfaceBuilder oduflexInterfaceBuilder = createGenericInterfaceBuilder(portMap, OtnOdu.class,
770             logicalConnPoint + "-ODUFLEX");
771
772         List<String> listSupportingOtucnInterface = new ArrayList<>();
773         listSupportingOtucnInterface.add(supportingOducn);
774
775         oduflexInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
776
777
778         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder
779             oduflexIf1Builder =
780             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
781
782         oduflexInterfaceBuilder.addAugmentation(oduflexIf1Builder.setOdu(oduBuilder.build()).build());
783
784         // Post interface on the device
785         openRoadmInterfaces.postInterface(nodeId, oduflexInterfaceBuilder);
786
787         // Post the equipment-state change on the device circuit-pack if xpdr node
788         if (portMap.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
789             this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
790         }
791
792         return oduflexInterfaceBuilder.getName();
793     }
794
795     // Overloaded methods should be together
796     // This is only for transponder; with SAPI/DAPI information
797     public String createOpenRoadmOduflexInterface(String anodeId, String alogicalConnPoint,
798         String supportingOducn, String znodeId, String zlogicalConnPoint)
799         throws OpenRoadmInterfaceException {
800         Mapping portMapA = portMapping.getMapping(anodeId, alogicalConnPoint);
801         Mapping portMapZ = portMapping.getMapping(znodeId, zlogicalConnPoint);
802         if (portMapA == null) {
803             throw new OpenRoadmInterfaceException(
804                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
805                     anodeId, alogicalConnPoint));
806         }
807         // On the Zside
808         if (portMapZ == null) {
809             throw new OpenRoadmInterfaceException(
810                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
811                     znodeId, zlogicalConnPoint));
812
813         }
814         // OPU payload
815         OpuBuilder opuBuilder = new OpuBuilder()
816             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("32"))
817             .setPayloadType(PayloadTypeDef.getDefaultInstance("32"));
818
819         // Parent Odu-allocation
820         // Set the trib-slot array
821         List<OpucnTribSlotDef> tribslots = new ArrayList<>();
822         IntStream.range(1, 5).forEach(a -> IntStream.range(1, 21).forEach(b -> tribslots.add(
823             OpucnTribSlotDef.getDefaultInstance(a + "." + b))));
824
825         ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
826             .setTribPortNumber(Uint16.valueOf(1))
827             .setTribSlotsChoice(new OpucnBuilder().setOpucnTribSlots(tribslots).build());
828
829         // Create an ODUFlex object
830         OduBuilder oduBuilder = new OduBuilder()
831             .setRate(ODUflexCbr.class)
832             .setOduflexCbrService(ODUflexCbr400G.class)
833             .setOduFunction(ODUTTPCTP.class)
834             .setMonitoringMode(MonitoringMode.Terminated)
835             .setTimActEnabled(false)
836             .setTimDetectMode(TimDetectMode.Disabled)
837             .setDegmIntervals(Uint8.valueOf(2))
838             .setDegthrPercentage(Uint16.valueOf(100))
839             .setTxSapi(portMapA.getLcpHashVal())
840             .setTxDapi(portMapZ.getLcpHashVal())
841             .setExpectedSapi(portMapZ.getLcpHashVal())
842             .setExpectedDapi(portMapA.getLcpHashVal())
843             .setOpu(opuBuilder.build())
844             .setParentOduAllocation(parentOduAllocationBuilder.build());
845
846         InterfaceBuilder oduflexInterfaceBuilder = createGenericInterfaceBuilder(portMapA, OtnOdu.class,
847             alogicalConnPoint + "-ODUFLEX");
848
849         List<String> listSupportingOtucnInterface = new ArrayList<>();
850         listSupportingOtucnInterface.add(supportingOducn);
851
852         oduflexInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
853
854
855         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder
856             oduflexIf1Builder =
857             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
858
859         oduflexInterfaceBuilder.addAugmentation(oduflexIf1Builder.setOdu(oduBuilder.build()).build());
860
861         // Post interface on the device
862         openRoadmInterfaces.postInterface(anodeId, oduflexInterfaceBuilder);
863
864         // Post the equipment-state change on the device circuit-pack if xpdr node
865         if (portMapA.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
866             this.openRoadmInterfaces.postEquipmentState(anodeId, portMapA.getSupportingCircuitPackName(), true);
867         }
868
869         return oduflexInterfaceBuilder.getName();
870     }
871
872     public String createOpenRoadmOdu4OducnOduflex(String nodeId, String logicalConnPoint,
873         AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ) throws OpenRoadmInterfaceException {
874
875         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
876         if (portMap == null) {
877             throw new OpenRoadmInterfaceException(
878                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
879         }
880         // Depending on OTU4 or OTUCn, supporting interface should
881         // reflect that
882         String interfaceOdu4OducnOduflex = null;
883         if (portMap.getSupportedInterfaceCapability().contains(IfOCHOTU4ODU4.class)) {
884             // create OTU4 interface
885             interfaceOdu4OducnOduflex = createOpenRoadmOdu4Interface(nodeId, logicalConnPoint, apiInfoA, apiInfoZ);
886         } else if (portMap.getSupportedInterfaceCapability().contains(IfOtsiOtsigroup.class)) {
887             // Create ODUCn and ODUFlex interface.
888             String interfaceOducn = createOpenRoadmOducnInterface(nodeId, logicalConnPoint);
889             // Here we concat the two interfaces
890             interfaceOdu4OducnOduflex = interfaceOducn + "#"
891                 + createOpenRoadmOduflexInterface(nodeId, logicalConnPoint, interfaceOducn);
892         }
893
894         return interfaceOdu4OducnOduflex;
895     }
896
897     public String createOpenRoadmOtnOducnInterface(String nodeId, String logicalConnPoint,
898         String supportingOtucn)
899         throws OpenRoadmInterfaceException {
900         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
901         if (portMap == null) {
902             throw new OpenRoadmInterfaceException(
903                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
904                     nodeId, logicalConnPoint));
905         }
906         // Create ODUcn object
907         // Start with OPU object
908         // OPU payload
909         OpuBuilder opuBuilder = new OpuBuilder()
910             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("22"))
911             .setPayloadType(PayloadTypeDef.getDefaultInstance("22"));
912
913         // Create an ODUC4 object
914         OduBuilder oduBuilder = new OduBuilder()
915             .setRate(ODUCn.class)
916             .setOduFunction(ODUTTP.class)
917             .setMonitoringMode(MonitoringMode.Terminated)
918             .setTimActEnabled(false)
919             .setTimDetectMode(TimDetectMode.Disabled)
920             .setDegmIntervals(Uint8.valueOf(2))
921             .setDegthrPercentage(Uint16.valueOf(100))
922             .setOpu(opuBuilder.build());
923
924         // Set the ODUCn rate from OTUCn interface naming convention
925         String oducnrate = supportingOtucn.substring(supportingOtucn.length() - 1);
926
927         // check if the oducnrate is a valid value and if it is invalid, then throw error
928         if (!SUPPORTED_ODUCN_RATES.contains(oducnrate)) {
929             throw new OpenRoadmInterfaceException(
930                 String.format(RATE_EXCEPTION_MESSAGE));
931         }
932
933         oduBuilder.setOducnNRate(Uint16.valueOf(oducnrate));
934
935         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMap, OtnOdu.class,
936             logicalConnPoint + ODUC + oducnrate);
937
938         // Create a list
939         List<String> listSupportingOtucnInterface = new ArrayList<>();
940         listSupportingOtucnInterface.add(supportingOtucn);
941
942         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
943         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
944             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
945
946         oduInterfaceBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
947
948         // Post interface on the device
949         openRoadmInterfaces.postInterface(nodeId, oduInterfaceBuilder);
950         // Post the equipment-state change on the device circuit-pack if xpdr node
951         if (portMap.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
952             this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
953         }
954         // Update the port-mapping with the interface information
955         this.portMapping.updateMapping(nodeId, portMap);
956         return oduInterfaceBuilder.getName();
957     }
958
959
960     // With SAPI and DAPI information
961     public String createOpenRoadmOtnOducnInterface(String anodeId, String alogicalConnPoint,
962         String supportingOtucn, String znodeId, String zlogicalConnPoint)
963         throws OpenRoadmInterfaceException {
964         Mapping portMapA = portMapping.getMapping(anodeId, alogicalConnPoint);
965         Mapping portMapZ = portMapping.getMapping(znodeId, zlogicalConnPoint);
966         if (portMapA == null) {
967             throw new OpenRoadmInterfaceException(
968                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
969                     anodeId, alogicalConnPoint));
970         }
971         // On the Zside
972         if (portMapZ == null) {
973             throw new OpenRoadmInterfaceException(
974                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
975                     znodeId, zlogicalConnPoint));
976
977         }
978         // Create ODUcn object
979         // Start with OPU object
980         // OPU payload
981         OpuBuilder opuBuilder = new OpuBuilder()
982             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("22"))
983             .setPayloadType(PayloadTypeDef.getDefaultInstance("22"));
984
985         // Create an ODUCn object
986         OduBuilder oduBuilder = new OduBuilder()
987             .setRate(ODUCn.class)
988             .setOduFunction(ODUTTP.class)
989             .setMonitoringMode(MonitoringMode.Terminated)
990             .setTimActEnabled(false)
991             .setTimDetectMode(TimDetectMode.Disabled)
992             .setDegmIntervals(Uint8.valueOf(2))
993             .setDegthrPercentage(Uint16.valueOf(100))
994             .setOpu(opuBuilder.build())
995             .setTxSapi(portMapA.getLcpHashVal())
996             .setTxDapi(portMapZ.getLcpHashVal())
997             .setExpectedSapi(portMapZ.getLcpHashVal())
998             .setExpectedDapi(portMapZ.getLcpHashVal());
999
1000         // Set the ODUCn rate from OTUCn interface naming convention
1001         String oducnrate = supportingOtucn.substring(supportingOtucn.length() - 1);
1002
1003         // check if the oducnrate is a valid value and if it is invalid, then throw error
1004         if (!SUPPORTED_ODUCN_RATES.contains(oducnrate)) {
1005             throw new OpenRoadmInterfaceException(
1006                 String.format(RATE_EXCEPTION_MESSAGE));
1007         }
1008
1009         oduBuilder.setOducnNRate(Uint16.valueOf(oducnrate));
1010
1011         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMapA, OtnOdu.class,
1012             alogicalConnPoint + ODUC + oducnrate);
1013
1014         // Create a list
1015         List<String> listSupportingOtucnInterface = new ArrayList<>();
1016         listSupportingOtucnInterface.add(supportingOtucn);
1017
1018         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
1019         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
1020             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
1021
1022         oduInterfaceBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
1023
1024         // Post interface on the device
1025         openRoadmInterfaces.postInterface(anodeId, oduInterfaceBuilder);
1026         // Post the equipment-state change on the device circuit-pack if xpdr node
1027         if (portMapA.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
1028             this.openRoadmInterfaces.postEquipmentState(anodeId, portMapA.getSupportingCircuitPackName(), true);
1029         }
1030         // Update the port-mapping with the interface information
1031         this.portMapping.updateMapping(anodeId, portMapA);
1032         return oduInterfaceBuilder.getName();
1033     }
1034
1035     // This creates the name of the interface with slot numbers at the end
1036     public String createOpenRoadmOtsiInterfaceName(String logicalConnectionPoint, String spectralSlotName) {
1037         return String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, logicalConnectionPoint, spectralSlotName);
1038     }
1039
1040     private InterfaceBuilder createGenericInterfaceBuilder(Mapping portMap, Class<? extends InterfaceType> type,
1041             String key) {
1042         return new org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.InterfaceBuilder()
1043             .setDescription("  TBD   ")
1044             .setCircuitId("   TBD    ")
1045             .setSupportingCircuitPackName(portMap.getSupportingCircuitPackName())
1046             .setSupportingPort(portMap.getSupportingPort())
1047             .setAdministrativeState(AdminStates.InService)
1048             .setType(type)
1049             .setName(key)
1050             .withKey(new InterfaceKey(key));
1051     }
1052
1053     @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
1054         value = "UPM_UNCALLED_PRIVATE_METHOD",
1055         justification = "call in call() method")
1056     private int getServiceRate(ModulationFormat modulationFormat, SpectrumInformation spectrumInformation) {
1057
1058         switch (modulationFormat) {
1059             case DpQpsk:
1060                 LOG.info("Given modulation format is {} and thus rate is 200G", modulationFormat);
1061                 return 200;
1062             case DpQam8:
1063                 LOG.info("Given modulation format is {} and thus rate is 300G", modulationFormat);
1064                 return 300;
1065             case DpQam16:
1066                 // DpQam16 is possible for both 31.6 or 63.1 GBaud, for which spectral width is different
1067                 // Here take the difference of highest and lowest spectral numbers and determine the width
1068                 LOG.info("The width with guard band {}", (spectrumInformation.getHigherSpectralSlotNumber()
1069                     - spectrumInformation.getLowerSpectralSlotNumber() + 1) * GridConstant.GRANULARITY);
1070                 if ((spectrumInformation.getHigherSpectralSlotNumber()
1071                     - spectrumInformation.getLowerSpectralSlotNumber() + 1) * GridConstant.GRANULARITY == 50.0) {
1072                     // Based on roll-of-factor of 0.5, 50 - 12.5 = 37.5GHz translates to 31.6 GBaud
1073                     LOG.info("The baud-rate is 31.6 GBaud");
1074                     LOG.info("Given modulation format {} with 31.6 Gbaud rate is 200G", modulationFormat);
1075                     return 200;
1076                 } else {
1077                     // Based on roll-of-factor of 0.5, 87.5 - 12.5 = 75GHz translates to 63.1 GBaud
1078                     LOG.info("The baud-rate is 63.1 GBaud");
1079                     return 400;
1080                 }
1081             default:
1082                 LOG.error("Modulation format is required to select the rate");
1083                 break;
1084         }
1085         return 0;
1086     }
1087
1088 }