Merge changes I04980c0b,Ib74e699a,I6ca86692,Ida6061da,Iea661424, ...
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / openroadminterface / OpenRoadmInterfaceFactory.java
1 /*
2  * Copyright © 2017 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.util.List;
12 import org.opendaylight.transportpce.common.StringConstants;
13 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
14 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
15 import org.opendaylight.transportpce.common.fixedflex.SpectrumInformation;
16 import org.opendaylight.transportpce.common.mapping.MappingUtils;
17 import org.opendaylight.transportpce.common.mapping.PortMapping;
18 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
19 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.AEndApiInfo;
21 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.ZEndApiInfo;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.mapping.Mapping;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.OpucnTribSlotDef;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 public class OpenRoadmInterfaceFactory {
28
29     private static final String OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_1_2_1_MSG =
30             "OTN functions are not supported by Openroadm models 1.2.1";
31     private static  final String OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_2_2_1_MSG =
32             "OTN functions are not supported by Openroadm models 2.2.1";
33     private static final Logger LOG = LoggerFactory.getLogger(OpenRoadmInterfaceFactory.class);
34     private final MappingUtils mappingUtils;
35     private final OpenRoadmInterface121 openRoadmInterface121;
36     private final OpenRoadmInterface221 openRoadmInterface221;
37     private final OpenRoadmInterface710 openRoadmInterface710;
38     private final OpenRoadmOtnInterface221 openRoadmOtnInterface221;
39     private final OpenRoadmOtnInterface710 openRoadmOtnInterface710;
40
41     public OpenRoadmInterfaceFactory(MappingUtils mappingUtils, PortMapping portMapping,
42             OpenRoadmInterfaces openRoadmInterfaces) {
43         this.mappingUtils = mappingUtils;
44         this.openRoadmInterface121 = new OpenRoadmInterface121(portMapping, openRoadmInterfaces);
45         this.openRoadmInterface221 = new OpenRoadmInterface221(portMapping, openRoadmInterfaces);
46         this.openRoadmInterface710 = new OpenRoadmInterface710(portMapping, openRoadmInterfaces);
47         this.openRoadmOtnInterface221 = new OpenRoadmOtnInterface221(portMapping, openRoadmInterfaces);
48         this.openRoadmOtnInterface710 = new OpenRoadmOtnInterface710(portMapping, openRoadmInterfaces);
49     }
50
51     public String createOpenRoadmEthInterface(String nodeId, String logicalConnPoint)
52             throws OpenRoadmInterfaceException {
53
54         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
55             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
56                 return openRoadmInterface121.createOpenRoadmEthInterface(nodeId, logicalConnPoint);
57             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
58                 return openRoadmInterface221.createOpenRoadmEthInterface(nodeId, logicalConnPoint);
59             case StringConstants.OPENROADM_DEVICE_VERSION_7_1:
60                 // Below method differenciates 100G vs 400G based on supported-if-cap type
61                 return openRoadmInterface710.createOpenRoadmEthInterface(nodeId, logicalConnPoint);
62             default:
63                 return null;
64         }
65     }
66
67     public List<String> createOpenRoadmOchInterfaces(String nodeId, String logicalConnPoint,
68             SpectrumInformation spectrumInformation)
69             throws OpenRoadmInterfaceException {
70         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
71             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
72                 return openRoadmInterface121.createOpenRoadmOchInterfaces(nodeId, logicalConnPoint,
73                         spectrumInformation);
74             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
75                 return openRoadmInterface221.createFlexOCH(nodeId, logicalConnPoint, spectrumInformation);
76             default:
77                 return null;
78         }
79     }
80
81
82     /**
83      * This methods creates an OCH interface on the given termination point on Roadm.
84      *
85      * @param nodeId           node ID
86      * @param logicalConnPoint logical connection point
87      * @param spectrumInformation spectrum information.
88      * @return Name of the interface if successful, otherwise return null.
89      * @throws OpenRoadmInterfaceException OpenRoadm interface exception
90      */
91     public String createOpenRoadmOchInterface(String nodeId, String logicalConnPoint,
92             SpectrumInformation spectrumInformation) throws OpenRoadmInterfaceException {
93         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
94             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
95                 return openRoadmInterface121.createOpenRoadmOchInterface(nodeId, logicalConnPoint,
96                         spectrumInformation);
97             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
98                 return openRoadmInterface221.createOpenRoadmOchInterface(nodeId, logicalConnPoint,
99                         spectrumInformation);
100             case StringConstants.OPENROADM_DEVICE_VERSION_7_1:
101                 return openRoadmInterface710.createOpenRoadmOchOtsiOtsigroupInterface(nodeId, logicalConnPoint,
102                     spectrumInformation);
103             default:
104                 return null;
105         }
106     }
107
108     /**
109      * This methods creates an ODU interface on the given termination point.
110      *
111      * @param nodeId                 node ID
112      * @param logicalConnPoint       logical connection point
113      * @param isCTP                  to distinguish with a TTP odu interface
114      * @param apiInfoA               sapi and dapi for A end of the service
115      * @param apiInfoZ               sapi and dapi for Z end of the service
116      * @param payloadType            payload type of the opu when terminated
117      * @return Name of the interface if successful, otherwise return null.
118      * @throws OpenRoadmInterfaceException OpenRoadm interface exception
119      */
120
121     public String createOpenRoadmOdu4HOInterface(String nodeId, String logicalConnPoint, boolean isCTP,
122             AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ, String payloadType)
123             throws OpenRoadmInterfaceException {
124
125         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
126             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
127                 return openRoadmInterface121.createOpenRoadmOdu4Interface(nodeId, logicalConnPoint);
128             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
129                 return openRoadmInterface221.createOpenRoadmOdu4HOInterface(nodeId, logicalConnPoint, isCTP,
130                     apiInfoA, apiInfoZ, payloadType);
131             case StringConstants.OPENROADM_DEVICE_VERSION_7_1:
132                 return openRoadmInterface710.createOpenRoadmOdu4OducnOduflex(nodeId, logicalConnPoint,
133                     apiInfoA, apiInfoZ);
134             default:
135                 return null;
136         }
137     }
138
139     public String createOpenRoadmOducn(String nodeId, String logicalConnPoint)
140             throws OpenRoadmInterfaceException {
141
142         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
143             case StringConstants.OPENROADM_DEVICE_VERSION_7_1:
144                 return openRoadmInterface710.createOpenRoadmOducnInterface(nodeId, logicalConnPoint);
145             default:
146                 return null;
147         }
148     }
149
150     /**
151      * This methods creates an OTU interface on the given termination point.
152      *
153      * @param nodeId              node ID
154      * @param logicalConnPoint    logical connection point
155      * @param supportOchInterface supporting OCH interface
156      * @param apiInfoA            sapi and dapi for A end of the service
157      * @param apiInfoZ            sapi and dapi for Z end of the service
158      * @return Name of the interface if successful, otherwise return null.
159      * @throws OpenRoadmInterfaceException OpenRoadm interface exception
160      */
161
162     public String createOpenRoadmOtu4Interface(String nodeId, String logicalConnPoint, String supportOchInterface,
163             AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ)
164             throws OpenRoadmInterfaceException {
165
166         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
167             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
168                 return openRoadmInterface121
169                         .createOpenRoadmOtu4Interface(nodeId, logicalConnPoint, supportOchInterface);
170             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
171                 return openRoadmInterface221.createOpenRoadmOtu4Interface(nodeId, logicalConnPoint, supportOchInterface,
172                     apiInfoA, apiInfoZ);
173             case StringConstants.OPENROADM_DEVICE_VERSION_7_1:
174                 return openRoadmInterface710.createOpenRoadmOtu4OtucnInterface(nodeId, logicalConnPoint,
175                     supportOchInterface, apiInfoA, apiInfoZ);
176             default:
177                 return null;
178         }
179     }
180
181
182     public String createOpenRoadmOchInterfaceName(String logicalConnectionPoint, String spectralSlotNumber) {
183         return String.join(GridConstant.NAME_PARAMETERS_SEPARATOR,logicalConnectionPoint, spectralSlotNumber);
184     }
185
186     public String createOpenRoadmOmsInterface(String nodeId, Mapping mapping) throws OpenRoadmInterfaceException {
187         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
188             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
189                 return openRoadmInterface121.createOpenRoadmOmsInterface(nodeId, mapping);
190             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
191                 return openRoadmInterface221.createOpenRoadmOmsInterface(nodeId, mapping);
192             default:
193                 return null;
194         }
195     }
196
197     public String createOpenRoadmOtsInterface(String nodeId, Mapping mapping) throws OpenRoadmInterfaceException {
198         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
199             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
200                 return openRoadmInterface121.createOpenRoadmOtsInterface(nodeId, mapping);
201             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
202                 return openRoadmInterface221.createOpenRoadmOtsInterface(nodeId, mapping);
203             default:
204                 return null;
205         }
206     }
207
208     public boolean isUsedByXc(String nodeId, String interfaceName, String xc,
209             DeviceTransactionManager deviceTransactionManager) {
210         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
211             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
212                 return openRoadmInterface121.isUsedByXc(nodeId, interfaceName, xc, deviceTransactionManager);
213             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
214                 return openRoadmInterface221.isUsedByXc(nodeId, interfaceName, xc, deviceTransactionManager);
215             default:
216                 return false;
217         }
218     }
219
220     public boolean isUsedByOtnXc(String nodeId, String interfaceName, String xc,
221             DeviceTransactionManager deviceTransactionManager) {
222         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
223             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
224                 LOG.error(OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_1_2_1_MSG);
225                 return false;
226             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
227                 return openRoadmInterface221.isUsedByOtnXc(nodeId, interfaceName, xc, deviceTransactionManager);
228             default:
229                 return false;
230         }
231     }
232
233     public String createOpenRoadmEth1GInterface(String nodeId,String logicalConnPoint)
234             throws OpenRoadmInterfaceException {
235
236         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
237             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
238                 LOG.error(OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_1_2_1_MSG);
239                 return null;
240             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
241                 return openRoadmOtnInterface221.createOpenRoadmEth1GInterface(nodeId, logicalConnPoint);
242             default:
243                 return null;
244         }
245     }
246
247     public String createOpenRoadmEth10GInterface(String nodeId, String logicalConnPoint)
248             throws OpenRoadmInterfaceException {
249
250         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
251             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
252                 LOG.error(OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_1_2_1_MSG);
253                 return null;
254             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
255                 return openRoadmOtnInterface221.createOpenRoadmEth10GInterface(nodeId, logicalConnPoint);
256             default:
257                 return null;
258         }
259     }
260
261     public String createOpenRoadmEth100GInterface(String nodeId, String logicalConnPoint)
262             throws OpenRoadmInterfaceException {
263
264         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
265             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
266                 LOG.error(OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_1_2_1_MSG);
267                 return null;
268             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
269                 LOG.warn("Use Ethernet interface creation for 2.2.1, instead this method of Ether 100G");
270                 return openRoadmInterface221.createOpenRoadmEthInterface(nodeId, logicalConnPoint);
271             case StringConstants.OPENROADM_DEVICE_VERSION_7_1:
272                 return openRoadmOtnInterface710.createOpenRoadmEth100GInterface(nodeId, logicalConnPoint);
273             default:
274                 return null;
275         }
276     }
277
278     public String createOpenRoadmOdu0Interface(String nodeId, String logicalConnPoint, String servicename,
279             boolean isCTP, int tribPortNumber, int tribSlotIndex, AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ,
280             String payLoadType)
281             throws OpenRoadmInterfaceException {
282
283         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
284             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
285                 LOG.error(OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_1_2_1_MSG);
286                 return null;
287             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
288                 return openRoadmOtnInterface221.createOpenRoadmOdu0Interface(nodeId, logicalConnPoint, servicename,
289                     isCTP, tribPortNumber, tribSlotIndex, apiInfoA, apiInfoZ, payLoadType);
290             default:
291                 return null;
292         }
293     }
294
295     public String createOpenRoadmOdu2Interface(String nodeId, String logicalConnPoint, String servicename,
296             boolean isCTP, int tribPortNumber, int tribSlotIndex, AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ,
297             String payLoadType)
298             throws OpenRoadmInterfaceException {
299         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
300             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
301                 LOG.error(OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_1_2_1_MSG);
302                 return null;
303             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
304                 return openRoadmOtnInterface221.createOpenRoadmOdu2Interface(nodeId, logicalConnPoint,  servicename,
305                     isCTP, tribPortNumber, tribSlotIndex, apiInfoA, apiInfoZ, payLoadType);
306             default:
307                 return null;
308         }
309     }
310
311     public String createOpenRoadmOdu2eInterface(String nodeId, String logicalConnPoint, String servicename,
312             boolean isCTP, int tribPortNumber, int tribSlotIndex, AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ,
313             String payLoadType)
314             throws OpenRoadmInterfaceException {
315
316         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
317             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
318                 LOG.error(OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_1_2_1_MSG);
319                 return null;
320             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
321                 return openRoadmOtnInterface221.createOpenRoadmOdu2eInterface(nodeId, logicalConnPoint, servicename,
322                     isCTP, tribPortNumber, tribSlotIndex, apiInfoA, apiInfoZ, payLoadType);
323             default:
324                 return null;
325         }
326     }
327
328     public String createOpenRoadmOtnOdu4LoInterface(String nodeId, String logicalConnPoint, String serviceName,
329             String payLoad, boolean isNetworkPort, OpucnTribSlotDef minTribSlotNumber,
330             OpucnTribSlotDef maxTribSlotNumber)
331         throws OpenRoadmInterfaceException {
332
333         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
334             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
335                 LOG.error(OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_1_2_1_MSG);
336                 return null;
337             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
338                 LOG.error(OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_2_2_1_MSG);
339                 return null;
340             case StringConstants.OPENROADM_DEVICE_VERSION_7_1:
341                 return openRoadmOtnInterface710.createOpenRoadmOdu4Interface(nodeId, logicalConnPoint, serviceName,
342                     payLoad, isNetworkPort, minTribSlotNumber, maxTribSlotNumber);
343             default:
344                 return null;
345         }
346     }
347
348
349     public String createOpenRoadmOtnOdu4Interface(String anodeId, String alogicalConnPoint,
350             String asupportingOtuInterface, String znodeId, String zlogicalConnPoint)
351             throws OpenRoadmInterfaceException {
352         switch (mappingUtils.getOpenRoadmVersion(anodeId)) {
353             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
354                 return openRoadmInterface221
355                     .createOpenRoadmOtnOdu4Interface(anodeId, alogicalConnPoint, asupportingOtuInterface,
356                         znodeId, zlogicalConnPoint);
357             default:
358                 return null;
359         }
360     }
361
362     public String createOpenRoadmOtnOduc4Interface(String nodeId, String logicalConnPoint,
363             String supportingOtuInterface)
364             throws OpenRoadmInterfaceException {
365         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
366             case StringConstants.OPENROADM_DEVICE_VERSION_7_1:
367                 return openRoadmInterface710
368                     .createOpenRoadmOtnOducnInterface(nodeId, logicalConnPoint, supportingOtuInterface);
369             default:
370                 return null;
371         }
372     }
373
374     public String createOpenRoadmOtnOducnInterface(String anodeId, String alogicalConnPoint,
375             String asupportingOtuInterface, String znodeId, String zlogicalConnPoint)
376             throws OpenRoadmInterfaceException {
377         switch (mappingUtils.getOpenRoadmVersion(anodeId)) {
378             case StringConstants.OPENROADM_DEVICE_VERSION_7_1:
379                 return openRoadmInterface710
380                     .createOpenRoadmOtnOducnInterface(anodeId, alogicalConnPoint, asupportingOtuInterface,
381                         znodeId, zlogicalConnPoint);
382             default:
383                 return null;
384         }
385     }
386 }