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