1505752a989d24550cd63adfcd4543f0417c3150
[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.Foic36;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.Foic48;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.FrequencyTHz;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.ModulationFormat;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.ProvisionModeType;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.R200GOtsi;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.R300GOtsi;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.R400GOtsi;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev200529.Ofec;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev200529.Rsfec;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.InterfaceBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.InterfaceKey;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev200529.Interface1Builder;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev200529.ethernet.container.EthernetBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.EthernetCsmacd;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.InterfaceType;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.OtnOdu;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.OtnOtu;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.Otsi;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.OtsiGroup;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.maintenance.loopback.rev191129.maint.loopback.MaintLoopbackBuilder;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.tributary.signal.interfaces.rev200529.otsi.attributes.FlexoBuilder;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.tributary.signal.interfaces.rev200529.otsi.container.OtsiBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUCn;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUTTP;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUTTPCTP;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUflexCbr;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUflexCbr400G;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.OTUCn;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.OpucnTribSlotDef;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.PayloadTypeDef;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.OduAttributes.MonitoringMode;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.odu.container.OduBuilder;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.opu.OpuBuilder;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev200529.otu.container.OtuBuilder;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.otsi.group.interfaces.rev200529.otsi.group.container.OtsiGroupBuilder;
68 import org.opendaylight.yangtools.yang.common.Uint16;
69 import org.opendaylight.yangtools.yang.common.Uint32;
70 import org.opendaylight.yangtools.yang.common.Uint8;
71 import org.slf4j.Logger;
72 import org.slf4j.LoggerFactory;
73
74 public class OpenRoadmInterface710 {
75     private static final String MAPPING_ERROR_EXCEPTION_MESSAGE =
76         "Unable to get mapping from PortMapping for node % and logical connection port %s";
77     private static final String MODULATION_FMT_EXCEPTION_MESSAGE =
78         "Unable to get the modulation format";
79     private static final String RATE_EXCEPTION_MESSAGE =
80         "Unable to get the rate";
81     private static final String ODUC = "-ODUC";
82     private static final List<String> SUPPORTED_ODUCN_RATES = new ArrayList<>() {
83         {
84             add("2");
85             add("3");
86             add("4");
87         }
88     };
89     private final PortMapping portMapping;
90     private final OpenRoadmInterfaces openRoadmInterfaces;
91     private static final Logger LOG = LoggerFactory.getLogger(OpenRoadmInterface710.class);
92
93     public OpenRoadmInterface710(PortMapping portMapping, OpenRoadmInterfaces openRoadmInterfaces) {
94         this.portMapping = portMapping;
95         this.openRoadmInterfaces = openRoadmInterfaces;
96     }
97
98     public String createOpenRoadmEthInterface(String nodeId, String logicalConnPoint)
99             throws OpenRoadmInterfaceException {
100         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
101         if (portMap == null) {
102             throw new OpenRoadmInterfaceException(
103                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
104         }
105
106         // Ethernet interface specific data
107         EthernetBuilder ethIfBuilder = new EthernetBuilder()
108             .setFec(Rsfec.class)
109             .setSpeed(Uint32.valueOf(400000));
110
111         InterfaceBuilder ethInterfaceBldr = createGenericInterfaceBuilder(portMap, EthernetCsmacd.class,
112             logicalConnPoint + "-ETHERNET");
113         // Create Interface1 type object required for adding as augmentation
114         Interface1Builder ethIf1Builder = new Interface1Builder();
115         ethInterfaceBldr.addAugmentation(ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
116
117         // Post interface on the device
118         openRoadmInterfaces.postInterface(nodeId, ethInterfaceBldr);
119
120         // Post the equipment-state change on the device circuit-pack
121         openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
122
123         return ethInterfaceBldr.getName();
124     }
125
126
127     public String createOpenRoadmOtsiInterface(String nodeId, String logicalConnPoint,
128             SpectrumInformation spectrumInformation)
129             throws OpenRoadmInterfaceException {
130
131         ModulationFormat modulationFormat;
132         Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
133             .forName(spectrumInformation.getModulationFormat());
134         if (optionalModulationFormat.isPresent()) {
135             modulationFormat =  optionalModulationFormat.get();
136         } else {
137             throw new OpenRoadmInterfaceException(
138                 String.format(MODULATION_FMT_EXCEPTION_MESSAGE));
139         }
140
141         // OTSI interface specific data
142         OtsiBuilder  otsiBuilder = new OtsiBuilder()
143             .setFrequency(new FrequencyTHz(spectrumInformation.getCenterFrequency()))
144             .setTransmitPower(new PowerDBm(new BigDecimal("-5")))
145             .setProvisionMode(ProvisionModeType.Explicit)
146             .setFec(Ofec.class)
147             .setModulationFormat(modulationFormat);
148
149         // Set the Flexo values
150         FlexoBuilder flexoBuilder = new FlexoBuilder();
151         boolean rateNotFound = false;
152         // Use the rate to switch rather than modulation format
153         int serviceRate = getServiceRate(modulationFormat);
154         switch (serviceRate) {
155             case 200:
156                 LOG.info("Given modulation format is {} and thus rate is 200G", modulationFormat);
157                 flexoBuilder.setFoicType(Foic24.class)
158                     .setIid(new ArrayList<>(Arrays.asList(Uint8.valueOf(1), Uint8.valueOf(2))));
159                 otsiBuilder.setOtsiRate(R200GOtsi.class)
160                     .setFlexo(flexoBuilder.build());
161                 break;
162             case 300:
163                 LOG.info("Given modulation format is {} and thus rate is 300G", modulationFormat);
164                 flexoBuilder.setFoicType(Foic36.class)
165                     .setIid(new ArrayList<>(Arrays.asList(Uint8.valueOf(1), Uint8.valueOf(2),
166                         Uint8.valueOf(3))));
167                 otsiBuilder.setOtsiRate(R300GOtsi.class)
168                     .setFlexo(flexoBuilder.build());
169                 break;
170             case 400:
171                 // Default baud-rate is 63.1 Gbaud
172                 LOG.info("Given modulation format is {} and thus rate is 400G", modulationFormat);
173                 flexoBuilder.setFoicType(Foic48.class)
174                     .setIid(new ArrayList<>(Arrays.asList(Uint8.valueOf(1), Uint8.valueOf(2),
175                         Uint8.valueOf(3), Uint8.valueOf(4))));
176                 otsiBuilder.setModulationFormat(modulationFormat)
177                     .setOtsiRate(R400GOtsi.class)
178                     .setFlexo(flexoBuilder.build());
179                 break;
180             default:
181                 LOG.error("Rate {} is unsupported", serviceRate);
182                 rateNotFound = true;
183                 break;
184         }
185
186         if (rateNotFound) {
187             throw new OpenRoadmInterfaceException(
188                 String.format(RATE_EXCEPTION_MESSAGE));
189         }
190
191         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
192         if (portMap == null) {
193             throw new OpenRoadmInterfaceException(
194                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
195         }
196         // Create generic interface
197         InterfaceBuilder otsiInterfaceBldr = createGenericInterfaceBuilder(portMap, Otsi.class,
198             spectrumInformation.getIdentifierFromParams(logicalConnPoint));
199         // Create Interface1 type object required for adding as augmentation
200         org.opendaylight.yang.gen.v1.http
201             .org.openroadm.optical.channel.tributary.signal.interfaces.rev200529.Interface1Builder otsiIf1Builder =
202             new org.opendaylight.yang.gen.v1.http
203                 .org.openroadm.optical.channel.tributary.signal.interfaces.rev200529.Interface1Builder();
204
205         otsiInterfaceBldr.addAugmentation(otsiIf1Builder.setOtsi(otsiBuilder.build()).build());
206
207         // Post interface on the device
208         openRoadmInterfaces.postInterface(nodeId, otsiInterfaceBldr);
209
210         // Post the equipment-state change on the device circuit-pack if xpdr node
211         if (portMap.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
212             this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
213         }
214
215         return otsiInterfaceBldr.getName();
216     }
217
218     // This is a transponder use-case where the supporting port is just one, but YANG model
219     // requires supporting port to be list
220     public String createOpenRoadmOtsiGroupInterface(String nodeId, String logicalConnPoint,
221             String supportingOtsiInterface, SpectrumInformation spectrumInformation)
222             throws OpenRoadmInterfaceException {
223         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
224         if (portMap == null) {
225             throw new OpenRoadmInterfaceException(
226                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
227                     nodeId, logicalConnPoint));
228         }
229         // Check the modulation format
230         ModulationFormat modulationFormat;
231         Optional<ModulationFormat> optionalModulationFormat = ModulationFormat
232             .forName(spectrumInformation.getModulationFormat());
233         if (optionalModulationFormat.isPresent()) {
234             modulationFormat =  optionalModulationFormat.get();
235         } else {
236             throw new OpenRoadmInterfaceException(
237                 String.format(MODULATION_FMT_EXCEPTION_MESSAGE));
238         }
239         int serviceRate = getServiceRate(modulationFormat);
240         // Create an OTSI group object
241         OtsiGroupBuilder otsiGroupBuilder = new OtsiGroupBuilder()
242             .setGroupId(Uint32.valueOf(1));
243         boolean rateNotFound = false;
244         switch (serviceRate) {
245             case 200:
246                 otsiGroupBuilder.setGroupRate(R200GOtsi.class);
247                 break;
248             case 300:
249                 otsiGroupBuilder.setGroupRate(R300GOtsi.class);
250                 break;
251             case 400:
252                 otsiGroupBuilder.setGroupRate(R400GOtsi.class);
253                 break;
254             default:
255                 LOG.error("Rate {} is not supported", serviceRate);
256                 rateNotFound = true;
257                 break;
258         }
259         if (rateNotFound) {
260             throw new OpenRoadmInterfaceException(
261                 String.format(RATE_EXCEPTION_MESSAGE));
262         }
263
264         // Create generic interface
265         InterfaceBuilder otsiGroupInterfaceBldr = createGenericInterfaceBuilder(portMap, OtsiGroup.class,
266             logicalConnPoint + String.join("-", "", "OTSIGROUP", serviceRate + "G"));
267
268         // Create a list
269         List<String> listSupportingOtsiInterface = new ArrayList<>();
270         listSupportingOtsiInterface.add(supportingOtsiInterface);
271         otsiGroupInterfaceBldr.setSupportingInterfaceList(listSupportingOtsiInterface);
272
273         org.opendaylight.yang.gen.v1.http.org.openroadm.otsi.group.interfaces.rev200529.Interface1Builder
274             otsiGroupIf1Builder =
275             new org.opendaylight.yang.gen.v1.http.org.openroadm.otsi.group.interfaces.rev200529.Interface1Builder();
276         otsiGroupInterfaceBldr.addAugmentation(otsiGroupIf1Builder.setOtsiGroup(otsiGroupBuilder.build()).build());
277
278         // Post interface on the device
279         openRoadmInterfaces.postInterface(nodeId, otsiGroupInterfaceBldr);
280
281         // Post the equipment-state change on the device circuit-pack if xpdr node
282         if (portMap.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
283             this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
284         }
285
286         return otsiGroupInterfaceBldr.getName();
287     }
288
289     public String createOpenRoadmOtucnInterface(String nodeId, String logicalConnPoint,
290             String supportingOtsiGroupInterface, AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ)
291             throws OpenRoadmInterfaceException {
292         Mapping mapping = portMapping.getMapping(nodeId, logicalConnPoint);
293         if (mapping == null) {
294             throw new OpenRoadmInterfaceException(
295                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
296                     nodeId, logicalConnPoint));
297         }
298         // Create an OTUCn object
299         MaintLoopbackBuilder maintLoopbackBuilder = new MaintLoopbackBuilder();
300         maintLoopbackBuilder.setEnabled(false);
301         OtuBuilder otuBuilder = new OtuBuilder()
302             .setRate(OTUCn.class)
303             .setTimActEnabled(false)
304             .setTimDetectMode(TimDetectMode.Disabled)
305             .setDegmIntervals(Uint8.valueOf(2))
306             .setDegthrPercentage(Uint16.valueOf(100))
307             .setMaintLoopback(maintLoopbackBuilder.build());
308         if (apiInfoA != null) {
309             otuBuilder.setTxSapi(apiInfoA.getSapi())
310                 .setTxDapi(apiInfoA.getDapi())
311                 .setExpectedSapi(apiInfoA.getExpectedSapi())
312                 .setExpectedDapi(apiInfoA.getExpectedDapi());
313         }
314         if (apiInfoZ != null) {
315             otuBuilder.setTxSapi(apiInfoZ.getSapi())
316                 .setTxDapi(apiInfoZ.getDapi())
317                 .setExpectedSapi(apiInfoZ.getExpectedSapi())
318                 .setExpectedDapi(apiInfoZ.getExpectedDapi());
319         }
320         // Set the OTUCn rate for various rates
321         String rate = supportingOtsiGroupInterface.substring(supportingOtsiGroupInterface.lastIndexOf('-') + 1);
322
323         String otucnrate = null;
324         boolean rateNotFound = false;
325         switch (rate) {
326             case "200G":
327                 otuBuilder.setOtucnNRate(Uint16.valueOf(2));
328                 otucnrate = "2";
329                 break;
330             case "300G":
331                 otuBuilder.setOtucnNRate(Uint16.valueOf(3));
332                 otucnrate = "3";
333                 break;
334             case "400G":
335                 otuBuilder.setOtucnNRate(Uint16.valueOf(4));
336                 otucnrate = "4";
337                 break;
338             default:
339                 LOG.error("Rate {} is not supported", rate);
340                 rateNotFound = true;
341                 break;
342         }
343         if (rateNotFound) {
344             throw new OpenRoadmInterfaceException(
345                 String.format(RATE_EXCEPTION_MESSAGE));
346         }
347
348         InterfaceBuilder otuInterfaceBuilder = createGenericInterfaceBuilder(mapping, OtnOtu.class,
349             logicalConnPoint + "-OTUC" + otucnrate);
350
351         // Create a list
352         List<String> listSupportingOtsiGroupInterface = new ArrayList<>();
353         listSupportingOtsiGroupInterface.add(supportingOtsiGroupInterface);
354
355         otuInterfaceBuilder.setSupportingInterfaceList(listSupportingOtsiGroupInterface);
356         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev200529.Interface1Builder otuIf1Builder =
357             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev200529.Interface1Builder();
358
359         otuInterfaceBuilder.addAugmentation(otuIf1Builder.setOtu(otuBuilder.build()).build());
360
361         // Post interface on the device
362         openRoadmInterfaces.postInterface(nodeId, otuInterfaceBuilder);
363         // Post the equipment-state change on the device circuit-pack if xpdr node
364         if (mapping.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
365             this.openRoadmInterfaces.postEquipmentState(nodeId, mapping.getSupportingCircuitPackName(), true);
366         }
367         this.portMapping.updateMapping(nodeId, mapping);
368         return otuInterfaceBuilder.getName();
369     }
370
371     public String createOpenRoadmOducnInterface(String nodeId, String logicalConnPoint)
372             throws OpenRoadmInterfaceException {
373         Mapping mapping = portMapping.getMapping(nodeId, logicalConnPoint);
374         if (mapping == null) {
375             throw new OpenRoadmInterfaceException(
376                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
377                     nodeId, logicalConnPoint));
378         }
379         // Create ODUcn object
380         // Start with OPU object
381         // OPU payload
382         OpuBuilder opuBuilder = new OpuBuilder()
383             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("22"))
384             .setPayloadType(PayloadTypeDef.getDefaultInstance("22"));
385
386         // Create an ODUCn object
387         OduBuilder oduBuilder = new OduBuilder()
388             .setRate(ODUCn.class)
389             .setOduFunction(ODUTTP.class)
390             .setMonitoringMode(MonitoringMode.Terminated)
391             .setTimActEnabled(false)
392             .setTimDetectMode(TimDetectMode.Disabled)
393             .setDegmIntervals(Uint8.valueOf(2))
394             .setDegthrPercentage(Uint16.valueOf(100))
395             .setOducnNRate(Uint16.valueOf(4))
396             .setOpu(opuBuilder.build());
397
398         // Create a list
399         String supportingOtucn;
400         List<String> listSupportingOtucnInterface = new ArrayList<>();
401         if (mapping.getSupportingOtucn() != null) {
402             listSupportingOtucnInterface.add(mapping.getSupportingOtucn());
403             supportingOtucn = mapping.getSupportingOtucn();
404         } else {
405             throw new OpenRoadmInterfaceException(
406                 String.format("Missing supporting OTUCn interface on port-mapping"));
407         }
408
409         // Set the ODUCn rate from OTUCn interface naming convention
410         String oducnrate = supportingOtucn.substring(supportingOtucn.length() - 1);
411         // check if the oducnrate is a valid value and if it is invalid, then throw error
412         if (!SUPPORTED_ODUCN_RATES.contains(oducnrate)) {
413             throw new OpenRoadmInterfaceException(
414                 String.format(RATE_EXCEPTION_MESSAGE));
415         }
416
417         oduBuilder.setOducnNRate(Uint16.valueOf(oducnrate));
418
419         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(mapping, OtnOdu.class,
420             logicalConnPoint + "-ODUC" + oducnrate);
421
422         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
423         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
424             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
425
426         oduInterfaceBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
427
428         // Post interface on the device
429         openRoadmInterfaces.postInterface(nodeId, oduInterfaceBuilder);
430
431         // Post the equipment-state change on the device circuit-pack if xpdr node
432         if (mapping.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
433             this.openRoadmInterfaces.postEquipmentState(nodeId, mapping.getSupportingCircuitPackName(), true);
434         }
435
436         return oduInterfaceBuilder.getName();
437     }
438
439     // With SAPI and DAPI information
440     public String createOpenRoadmOducnInterface(String anodeId, String alogicalConnPoint,
441             String supportingOtucn, String znodeId, String zlogicalConnPoint)
442             throws OpenRoadmInterfaceException {
443         Mapping portMapA = portMapping.getMapping(anodeId, alogicalConnPoint);
444         Mapping portMapZ = portMapping.getMapping(znodeId, zlogicalConnPoint);
445         if (portMapA == null) {
446             throw new OpenRoadmInterfaceException(
447                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
448                     anodeId, alogicalConnPoint));
449         }
450         // On the Zside
451         if (portMapZ == null) {
452             throw new OpenRoadmInterfaceException(
453                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
454                     znodeId, zlogicalConnPoint));
455
456         }
457         // Create ODUcn object
458         // Start with OPU object
459         // OPU payload
460         OpuBuilder opuBuilder = new OpuBuilder()
461             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("22"))
462             .setPayloadType(PayloadTypeDef.getDefaultInstance("22"));
463
464         // Create an ODUC4 object
465         OduBuilder oduBuilder = new OduBuilder()
466             .setRate(ODUCn.class)
467             .setOduFunction(ODUTTP.class)
468             .setMonitoringMode(MonitoringMode.Terminated)
469             .setTimActEnabled(false)
470             .setTimDetectMode(TimDetectMode.Disabled)
471             .setDegmIntervals(Uint8.valueOf(2))
472             .setDegthrPercentage(Uint16.valueOf(100))
473             .setOpu(opuBuilder.build())
474             .setTxSapi(portMapA.getLcpHashVal())
475             .setTxDapi(portMapZ.getLcpHashVal())
476             .setExpectedSapi(portMapZ.getLcpHashVal())
477             .setExpectedDapi(portMapZ.getLcpHashVal());
478
479         // Set the ODUCn rate from OTUCn interface naming convention
480         String oducnrate = supportingOtucn.substring(supportingOtucn.length() - 1);
481
482         // check if the oducnrate is a valid value and if it is invalid, then throw error
483         if (!SUPPORTED_ODUCN_RATES.contains(oducnrate)) {
484             throw new OpenRoadmInterfaceException(
485                 String.format(RATE_EXCEPTION_MESSAGE));
486         }
487
488         oduBuilder.setOducnNRate(Uint16.valueOf(oducnrate));
489
490         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMapA, OtnOdu.class,
491             alogicalConnPoint + ODUC + oducnrate);
492
493         // Create a list
494         List<String> listSupportingOtucnInterface = new ArrayList<>();
495         listSupportingOtucnInterface.add(supportingOtucn);
496
497         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
498         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
499             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
500
501         oduInterfaceBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
502
503         // Post interface on the device
504         openRoadmInterfaces.postInterface(anodeId, oduInterfaceBuilder);
505
506         // Post the equipment-state change on the device circuit-pack if xpdr node
507         if (portMapA.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
508             this.openRoadmInterfaces.postEquipmentState(anodeId, portMapA.getSupportingCircuitPackName(), true);
509         }
510
511         return oduInterfaceBuilder.getName();
512     }
513
514     public String createOpenRoadmOtnOducnInterface(String nodeId, String logicalConnPoint,
515         String supportingOtucn)
516         throws OpenRoadmInterfaceException {
517         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
518         if (portMap == null) {
519             throw new OpenRoadmInterfaceException(
520                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
521                     nodeId, logicalConnPoint));
522         }
523         // Create ODUcn object
524         // Start with OPU object
525         // OPU payload
526         OpuBuilder opuBuilder = new OpuBuilder()
527             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("22"))
528             .setPayloadType(PayloadTypeDef.getDefaultInstance("22"));
529
530         // Create an ODUC4 object
531         OduBuilder oduBuilder = new OduBuilder()
532             .setRate(ODUCn.class)
533             .setOduFunction(ODUTTP.class)
534             .setMonitoringMode(MonitoringMode.Terminated)
535             .setTimActEnabled(false)
536             .setTimDetectMode(TimDetectMode.Disabled)
537             .setDegmIntervals(Uint8.valueOf(2))
538             .setDegthrPercentage(Uint16.valueOf(100))
539             .setOpu(opuBuilder.build());
540
541         // Set the ODUCn rate from OTUCn interface naming convention
542         String oducnrate = supportingOtucn.substring(supportingOtucn.length() - 1);
543
544         // check if the oducnrate is a valid value and if it is invalid, then throw error
545         if (!SUPPORTED_ODUCN_RATES.contains(oducnrate)) {
546             throw new OpenRoadmInterfaceException(
547                 String.format(RATE_EXCEPTION_MESSAGE));
548         }
549
550         oduBuilder.setOducnNRate(Uint16.valueOf(oducnrate));
551
552         InterfaceBuilder oduInterfaceBuilder = createGenericInterfaceBuilder(portMap, OtnOdu.class,
553             logicalConnPoint + ODUC + oducnrate);
554
555         // Create a list
556         List<String> listSupportingOtucnInterface = new ArrayList<>();
557         listSupportingOtucnInterface.add(supportingOtucn);
558
559         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
560         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
561             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
562
563         oduInterfaceBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
564
565         // Post interface on the device
566         openRoadmInterfaces.postInterface(nodeId, oduInterfaceBuilder);
567         // Post the equipment-state change on the device circuit-pack if xpdr node
568         if (portMap.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
569             this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
570         }
571         // Update the port-mapping with the interface information
572         this.portMapping.updateMapping(nodeId, portMap);
573         return oduInterfaceBuilder.getName();
574     }
575
576
577     // With SAPI and DAPI information
578     public String createOpenRoadmOtnOducnInterface(String anodeId, String alogicalConnPoint,
579         String supportingOtucn, String znodeId, String zlogicalConnPoint)
580         throws OpenRoadmInterfaceException {
581         Mapping portMapA = portMapping.getMapping(anodeId, alogicalConnPoint);
582         Mapping portMapZ = portMapping.getMapping(znodeId, zlogicalConnPoint);
583         if (portMapA == null) {
584             throw new OpenRoadmInterfaceException(
585                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
586                     anodeId, alogicalConnPoint));
587         }
588         // On the Zside
589         if (portMapZ == null) {
590             throw new OpenRoadmInterfaceException(
591                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
592                     znodeId, zlogicalConnPoint));
593
594         }
595         // Create ODUcn object
596         // Start with OPU object
597         // OPU payload
598         OpuBuilder opuBuilder = new OpuBuilder()
599             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("22"))
600             .setPayloadType(PayloadTypeDef.getDefaultInstance("22"));
601
602         // Create an ODUCn object
603         OduBuilder oduBuilder = new OduBuilder()
604             .setRate(ODUCn.class)
605             .setOduFunction(ODUTTP.class)
606             .setMonitoringMode(MonitoringMode.Terminated)
607             .setTimActEnabled(false)
608             .setTimDetectMode(TimDetectMode.Disabled)
609             .setDegmIntervals(Uint8.valueOf(2))
610             .setDegthrPercentage(Uint16.valueOf(100))
611             .setOpu(opuBuilder.build())
612             .setTxSapi(portMapA.getLcpHashVal())
613             .setTxDapi(portMapZ.getLcpHashVal())
614             .setExpectedSapi(portMapZ.getLcpHashVal())
615             .setExpectedDapi(portMapZ.getLcpHashVal());
616
617         // Set the ODUCn rate from OTUCn interface naming convention
618         String oducnrate = supportingOtucn.substring(supportingOtucn.length() - 1);
619
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(portMapA, OtnOdu.class,
629             alogicalConnPoint + ODUC + oducnrate);
630
631         // Create a list
632         List<String> listSupportingOtucnInterface = new ArrayList<>();
633         listSupportingOtucnInterface.add(supportingOtucn);
634
635         oduInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
636         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder oduIf1Builder =
637             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
638
639         oduInterfaceBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
640
641         // Post interface on the device
642         openRoadmInterfaces.postInterface(anodeId, oduInterfaceBuilder);
643         // Post the equipment-state change on the device circuit-pack if xpdr node
644         if (portMapA.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
645             this.openRoadmInterfaces.postEquipmentState(anodeId, portMapA.getSupportingCircuitPackName(), true);
646         }
647         // Update the port-mapping with the interface information
648         this.portMapping.updateMapping(anodeId, portMapA);
649         return oduInterfaceBuilder.getName();
650     }
651
652     // This is only for transponder
653     public String createOpenRoadmOduflexInterface(String nodeId, String logicalConnPoint,
654             String supportingOducn)
655             throws OpenRoadmInterfaceException {
656         Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
657         if (portMap == null) {
658             throw new OpenRoadmInterfaceException(
659                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
660                     nodeId, logicalConnPoint));
661         }
662         // OPU payload
663         OpuBuilder opuBuilder = new OpuBuilder()
664             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("32"))
665             .setPayloadType(PayloadTypeDef.getDefaultInstance("32"));
666
667         // Parent Odu-allocation
668         // Set the trib-slot array
669         List<OpucnTribSlotDef> tribslots = new ArrayList<>();
670         IntStream.range(1, 5).forEach(a -> IntStream.range(1, 21).forEach(b -> tribslots.add(
671             OpucnTribSlotDef.getDefaultInstance(a + "." + b))));
672
673         ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
674             .setTribPortNumber(Uint16.valueOf(1))
675             .setTribSlotsChoice(new OpucnBuilder().setOpucnTribSlots(tribslots).build());
676
677         // Create an ODUFlex object
678         OduBuilder oduBuilder = new OduBuilder()
679             .setRate(ODUflexCbr.class)
680             .setOduflexCbrService(ODUflexCbr400G.class)
681             .setOduFunction(ODUTTPCTP.class)
682             .setMonitoringMode(MonitoringMode.Terminated)
683             .setTimActEnabled(false)
684             .setTimDetectMode(TimDetectMode.Disabled)
685             .setDegmIntervals(Uint8.valueOf(2))
686             .setDegthrPercentage(Uint16.valueOf(100))
687             .setOpu(opuBuilder.build())
688             .setParentOduAllocation(parentOduAllocationBuilder.build());
689
690         InterfaceBuilder oduflexInterfaceBuilder = createGenericInterfaceBuilder(portMap, OtnOdu.class,
691             logicalConnPoint + "-ODUFLEX");
692
693         List<String> listSupportingOtucnInterface = new ArrayList<>();
694         listSupportingOtucnInterface.add(supportingOducn);
695
696         oduflexInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
697
698
699         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder
700                 oduflexIf1Builder =
701             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
702
703         oduflexInterfaceBuilder.addAugmentation(oduflexIf1Builder.setOdu(oduBuilder.build()).build());
704
705         // Post interface on the device
706         openRoadmInterfaces.postInterface(nodeId, oduflexInterfaceBuilder);
707
708         // Post the equipment-state change on the device circuit-pack if xpdr node
709         if (portMap.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
710             this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
711         }
712
713         return oduflexInterfaceBuilder.getName();
714     }
715
716     // This is only for transponder; with SAPI/DAPI information
717     public String createOpenRoadmOduflexInterface(String anodeId, String alogicalConnPoint,
718             String supportingOducn, String znodeId, String zlogicalConnPoint)
719             throws OpenRoadmInterfaceException {
720         Mapping portMapA = portMapping.getMapping(anodeId, alogicalConnPoint);
721         Mapping portMapZ = portMapping.getMapping(znodeId, zlogicalConnPoint);
722         if (portMapA == null) {
723             throw new OpenRoadmInterfaceException(
724                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
725                     anodeId, alogicalConnPoint));
726         }
727         // On the Zside
728         if (portMapZ == null) {
729             throw new OpenRoadmInterfaceException(
730                 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
731                     znodeId, zlogicalConnPoint));
732
733         }
734         // OPU payload
735         OpuBuilder opuBuilder = new OpuBuilder()
736             .setExpPayloadType(PayloadTypeDef.getDefaultInstance("32"))
737             .setPayloadType(PayloadTypeDef.getDefaultInstance("32"));
738
739         // Parent Odu-allocation
740         // Set the trib-slot array
741         List<OpucnTribSlotDef> tribslots = new ArrayList<>();
742         IntStream.range(1, 5).forEach(a -> IntStream.range(1, 21).forEach(b -> tribslots.add(
743             OpucnTribSlotDef.getDefaultInstance(a + "." + b))));
744
745         ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
746             .setTribPortNumber(Uint16.valueOf(1))
747             .setTribSlotsChoice(new OpucnBuilder().setOpucnTribSlots(tribslots).build());
748
749         // Create an ODUFlex object
750         OduBuilder oduBuilder = new OduBuilder()
751             .setRate(ODUflexCbr.class)
752             .setOduflexCbrService(ODUflexCbr400G.class)
753             .setOduFunction(ODUTTPCTP.class)
754             .setMonitoringMode(MonitoringMode.Terminated)
755             .setTimActEnabled(false)
756             .setTimDetectMode(TimDetectMode.Disabled)
757             .setDegmIntervals(Uint8.valueOf(2))
758             .setDegthrPercentage(Uint16.valueOf(100))
759             .setTxSapi(portMapA.getLcpHashVal())
760             .setTxDapi(portMapZ.getLcpHashVal())
761             .setExpectedSapi(portMapZ.getLcpHashVal())
762             .setExpectedDapi(portMapA.getLcpHashVal())
763             .setOpu(opuBuilder.build())
764             .setParentOduAllocation(parentOduAllocationBuilder.build());
765
766         InterfaceBuilder oduflexInterfaceBuilder = createGenericInterfaceBuilder(portMapA, OtnOdu.class,
767             alogicalConnPoint + "-ODUFLEX");
768
769         List<String> listSupportingOtucnInterface = new ArrayList<>();
770         listSupportingOtucnInterface.add(supportingOducn);
771
772         oduflexInterfaceBuilder.setSupportingInterfaceList(listSupportingOtucnInterface);
773
774
775         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder
776                 oduflexIf1Builder =
777             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
778
779         oduflexInterfaceBuilder.addAugmentation(oduflexIf1Builder.setOdu(oduBuilder.build()).build());
780
781         // Post interface on the device
782         openRoadmInterfaces.postInterface(anodeId, oduflexInterfaceBuilder);
783
784         // Post the equipment-state change on the device circuit-pack if xpdr node
785         if (portMapA.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
786             this.openRoadmInterfaces.postEquipmentState(anodeId, portMapA.getSupportingCircuitPackName(), true);
787         }
788
789         return oduflexInterfaceBuilder.getName();
790     }
791
792     // This creates the name of the interface with slot numbers at the end
793     public String createOpenRoadmOtsiInterfaceName(String logicalConnectionPoint, String spectralSlotName) {
794         return String.join(GridConstant.NAME_PARAMETERS_SEPARATOR, logicalConnectionPoint, spectralSlotName);
795     }
796
797     private InterfaceBuilder createGenericInterfaceBuilder(Mapping portMap, Class<? extends InterfaceType> type,
798             String key) {
799         return new org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.InterfaceBuilder()
800             .setDescription("  TBD   ")
801             .setCircuitId("   TBD    ")
802             .setSupportingCircuitPackName(portMap.getSupportingCircuitPackName())
803             .setSupportingPort(portMap.getSupportingPort())
804             .setAdministrativeState(AdminStates.InService)
805             .setType(type)
806             .setName(key)
807             .withKey(new InterfaceKey(key));
808     }
809
810     @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
811         value = "UPM_UNCALLED_PRIVATE_METHOD",
812         justification = "call in call() method")
813     private int getServiceRate(ModulationFormat modulationFormat) {
814
815         switch (modulationFormat) {
816             case DpQpsk:
817                 LOG.info("Given modulation format is {} and thus rate is 200G", modulationFormat);
818                 return 200;
819             case DpQam8:
820                 LOG.info("Given modulation format is {} and thus rate is 300G", modulationFormat);
821                 return 300;
822             case DpQam16:
823                 // Based on roll-of-factor of 0.5, 87.5 - 12.5 = 75GHz translates to 63.1 GBaud
824                 LOG.info("Given modulation format is {} and thus rate is 400G", modulationFormat);
825                 return 400;
826             default:
827                 LOG.error("Modulation format is required to select the rate");
828                 break;
829         }
830         return 0;
831     }
832
833 }