Adding SAPI/DAPI to Renderer
[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.mapping.MappingUtils;
15 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200429.network.nodes.Mapping;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.OchAttributes;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 public class OpenRoadmInterfaceFactory {
22
23     private static final String OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_1_2_1_MSG =
24             "OTN funtions are not supported by Openroadm models 1.2.1";
25     private static final Logger LOG = LoggerFactory.getLogger(OpenRoadmInterfaceFactory.class);
26     private final MappingUtils mappingUtils;
27     private final OpenRoadmInterface121 openRoadmInterface121;
28     private final OpenRoadmInterface221 openRoadmInterface221;
29     private final OpenRoadmOtnInterface221 openRoadmOtnInterface;
30
31     public OpenRoadmInterfaceFactory(MappingUtils mappingUtils, OpenRoadmInterface121 openRoadmInterface121,
32             OpenRoadmInterface221 openRoadmInterface221, OpenRoadmOtnInterface221 openRoadmOTNInterface) {
33         this.mappingUtils = mappingUtils;
34         this.openRoadmInterface121 = openRoadmInterface121;
35         this.openRoadmInterface221 = openRoadmInterface221;
36         this.openRoadmOtnInterface = openRoadmOTNInterface;
37     }
38
39     public String createOpenRoadmEthInterface(String nodeId, String logicalConnPoint)
40             throws OpenRoadmInterfaceException {
41
42         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
43             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
44                 return openRoadmInterface121.createOpenRoadmEthInterface(nodeId, logicalConnPoint);
45             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
46                 return openRoadmInterface221.createOpenRoadmEthInterface(nodeId, logicalConnPoint);
47             default:
48                 return null;
49         }
50     }
51
52
53     /**
54      * This methods creates an OCH interface on the given termination point on
55      * Roadm.
56      *
57      * @param nodeId           node ID
58      * @param logicalConnPoint logical connection point
59      * @param waveNumber       wavelength number of the OCH interface.
60      * @return Name of the interface if successful, otherwise return null.
61      * @throws OpenRoadmInterfaceException OpenRoadm interface exception
62      */
63
64     public List<String> createOpenRoadmOchInterface(String nodeId, String logicalConnPoint, Long waveNumber)
65             throws OpenRoadmInterfaceException {
66
67         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
68             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
69                 return openRoadmInterface121.createOpenRoadmOchInterface(nodeId, logicalConnPoint, waveNumber);
70             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
71                 return openRoadmInterface221.createFlexOCH(nodeId, logicalConnPoint, waveNumber);
72             default:
73                 return null;
74         }
75     }
76
77
78     public String createOpenRoadmOchInterface(String nodeId, String logicalConnPoint, Long waveNumber,
79         OchAttributes.ModulationFormat format)
80             throws OpenRoadmInterfaceException {
81         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
82             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
83                 return openRoadmInterface121.createOpenRoadmOchInterface(nodeId, logicalConnPoint, waveNumber, format);
84             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
85                 return openRoadmInterface221.createOpenRoadmOchInterface(nodeId, logicalConnPoint, waveNumber);
86             default:
87                 return null;
88         }
89     }
90
91     /**
92      * This methods creates an ODU interface on the given termination point.
93      *
94      * @param nodeId                 node ID
95      * @param logicalConnPoint       logical connection point
96      * @param supportingOtuInterface supporting OTU interface
97      * @return Name of the interface if successful, otherwise return null.
98      * @throws OpenRoadmInterfaceException OpenRoadm interface exception
99      */
100
101     public String createOpenRoadmOdu4Interface(String nodeId, String logicalConnPoint, String supportingOtuInterface)
102             throws OpenRoadmInterfaceException {
103         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
104             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
105                 return openRoadmInterface121.createOpenRoadmOdu4Interface(nodeId, logicalConnPoint,
106                         supportingOtuInterface);
107             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
108                 return openRoadmInterface221.createOpenRoadmOdu4Interface(nodeId, logicalConnPoint,
109                         supportingOtuInterface);
110             default:
111                 return null;
112         }
113     }
114
115     /**
116      * This methods creates an ODU interface on the given termination point.
117      *
118      * @param anodeId                 node ID for A side
119      * @param alogicalConnPoint       logical connection point for A side
120      * @param asupportingOtuInterface supporting OTU interface
121      * @param znodeId                 node ID for Z side
122      * @param zlogicalConnPoint       logical connection point for Z side
123      * @return Name of the interface if successful, otherwise return null.
124      * @throws OpenRoadmInterfaceException OpenRoadm interface exception
125      */
126
127     public String createOpenRoadmOdu4Interface(String anodeId, String alogicalConnPoint, String asupportingOtuInterface,
128         String znodeId, String zlogicalConnPoint)
129         throws OpenRoadmInterfaceException {
130         switch (mappingUtils.getOpenRoadmVersion(anodeId)) {
131             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
132                 return openRoadmInterface121.createOpenRoadmOdu4Interface(anodeId, alogicalConnPoint,
133                     asupportingOtuInterface);
134             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
135                 return openRoadmInterface221.createOpenRoadmOdu4Interface(anodeId, alogicalConnPoint,
136                     asupportingOtuInterface, znodeId, zlogicalConnPoint);
137             default:
138                 return null;
139         }
140     }
141
142     /**
143      * This methods creates an OTU interface on the given termination point.
144      *
145      * @param nodeId              node ID
146      * @param logicalConnPoint    logical connection point
147      * @param supportOchInterface supporting OCH interface
148      * @return Name of the interface if successful, otherwise return null.
149      * @throws OpenRoadmInterfaceException OpenRoadm interface exception
150      */
151
152     public String createOpenRoadmOtu4Interface(String nodeId, String logicalConnPoint, String supportOchInterface)
153             throws OpenRoadmInterfaceException {
154         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
155             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
156                 return openRoadmInterface121
157                         .createOpenRoadmOtu4Interface(nodeId, logicalConnPoint, supportOchInterface);
158             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
159                 return openRoadmInterface221
160                         .createOpenRoadmOtu4Interface(nodeId, logicalConnPoint, supportOchInterface);
161             default:
162                 return null;
163         }
164     }
165
166     /**
167      * This methods creates an OTU interface on the given termination point.
168      *
169      * @param anodeId node ID for A side
170      * @param alogicalConnPoint logical connection point for A side
171      * @param asupportOchInterface supporting OCH interface
172      * @param znodeId node ID for the Z side
173      * @param zlogicalConnPoint logical connection point for Z side
174      * @return Name of the interface if successful, otherwise return null.
175      *
176      * @throws OpenRoadmInterfaceException OpenRoadm interface exception
177      */
178
179     public String createOpenRoadmOtu4Interface(String anodeId, String alogicalConnPoint, String asupportOchInterface,
180             String znodeId, String zlogicalConnPoint)
181             throws OpenRoadmInterfaceException {
182         switch (mappingUtils.getOpenRoadmVersion(anodeId)) {
183             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
184                 return openRoadmInterface121.createOpenRoadmOtu4Interface(anodeId,
185                         alogicalConnPoint, asupportOchInterface);
186             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
187                 return openRoadmInterface221.createOpenRoadmOtu4Interface(anodeId, alogicalConnPoint,
188                         asupportOchInterface, znodeId, zlogicalConnPoint);
189             default:
190                 return null;
191         }
192     }
193
194     public String createOpenRoadmOchInterfaceName(String logicalConnectionPoint, Long waveNumber) {
195         return logicalConnectionPoint + "-" + waveNumber;
196     }
197
198     public String createOpenRoadmOmsInterface(String nodeId, Mapping mapping) throws OpenRoadmInterfaceException {
199         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
200             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
201                 return openRoadmInterface121.createOpenRoadmOmsInterface(nodeId, mapping);
202             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
203                 return openRoadmInterface221.createOpenRoadmOmsInterface(nodeId, mapping);
204             default:
205                 return null;
206         }
207     }
208
209     public String createOpenRoadmOtsInterface(String nodeId, Mapping mapping) throws OpenRoadmInterfaceException {
210         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
211             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
212                 return openRoadmInterface121.createOpenRoadmOtsInterface(nodeId, mapping);
213             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
214                 return openRoadmInterface221.createOpenRoadmOtsInterface(nodeId, mapping);
215             default:
216                 return null;
217         }
218     }
219
220     public boolean isUsedByXc(String nodeId, String interfaceName, String xc,
221                               DeviceTransactionManager deviceTransactionManager) {
222         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
223             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
224                 return openRoadmInterface121.isUsedByXc(nodeId, interfaceName, xc, deviceTransactionManager);
225             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
226                 return openRoadmInterface221.isUsedByXc(nodeId, interfaceName, xc, deviceTransactionManager);
227             default:
228                 return false;
229         }
230     }
231
232     public boolean isUsedByOtnXc(String nodeId, String interfaceName, String xc,
233         DeviceTransactionManager deviceTransactionManager) {
234         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
235             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
236                 LOG.error(OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_1_2_1_MSG);
237                 return false;
238             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
239                 return openRoadmInterface221.isUsedByOtnXc(nodeId, interfaceName, xc, deviceTransactionManager);
240             default:
241                 return false;
242         }
243     }
244
245     public String createOpenRoadmEth1GInterface(String nodeId,
246                                                 String logicalConnPoint) throws OpenRoadmInterfaceException {
247         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
248             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
249                 LOG.error(OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_1_2_1_MSG);
250                 return null;
251             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
252                 return openRoadmOtnInterface.createOpenRoadmEth1GInterface(nodeId, logicalConnPoint);
253             default:
254                 return null;
255         }
256     }
257
258     public String createOpenRoadmEth10GInterface(String nodeId,
259                                                  String logicalConnPoint) throws OpenRoadmInterfaceException {
260         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
261             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
262                 LOG.error(OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_1_2_1_MSG);
263                 return null;
264             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
265                 return openRoadmOtnInterface.createOpenRoadmEth10GInterface(nodeId, logicalConnPoint);
266             default:
267                 return null;
268         }
269
270     }
271
272     public String createOpenRoadmOdu0Interface(String nodeId, String logicalConnPoint, String servicename,
273             String payLoad, boolean isNetworkPort, int tribPortNumber, int tribSlot)
274             throws OpenRoadmInterfaceException {
275         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
276             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
277                 LOG.error(OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_1_2_1_MSG);
278                 return null;
279             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
280                 return openRoadmOtnInterface.createOpenRoadmOdu0Interface(
281                     nodeId, logicalConnPoint, servicename, payLoad, isNetworkPort, tribPortNumber, tribSlot);
282             default:
283                 return null;
284         }
285     }
286
287     public String createOpenRoadmOdu2Interface(String nodeId, String logicalConnPoint, String servicename,
288             String payLoad, boolean isNetworkPort, int tribPortNumber, int tribSlotIndex)
289             throws OpenRoadmInterfaceException {
290         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
291             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
292                 LOG.error(OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_1_2_1_MSG);
293                 return null;
294             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
295                 return openRoadmOtnInterface.createOpenRoadmOdu2Interface(
296                     nodeId, logicalConnPoint, servicename, payLoad, isNetworkPort, tribPortNumber, tribSlotIndex);
297             default:
298                 return null;
299         }
300     }
301
302     public String createOpenRoadmOdu2eInterface(String nodeId, String logicalConnPoint, String servicename,
303             String payLoad, boolean isNetworkPort, int tribPortNumber, int tribSlotIndex)
304             throws OpenRoadmInterfaceException {
305         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
306             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
307                 LOG.error(OTN_FUNTIONS_ARE_NOT_SUPPORTED_BY_OPENROADM_MODELS_1_2_1_MSG);
308                 return null;
309             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
310                 return openRoadmOtnInterface.createOpenRoadmOdu2eInterface(
311                         nodeId, logicalConnPoint, servicename, payLoad, isNetworkPort, tribPortNumber, tribSlotIndex);
312             default:
313                 return null;
314         }
315
316     }
317
318     public String createOpenRoadmOtnOdu4Interface(String nodeId, String logicalConnPoint, String supportingOtuInterface)
319             throws OpenRoadmInterfaceException {
320         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
321             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
322                 return openRoadmInterface221
323                         .createOpenRoadmOtnOdu4Interface(nodeId, logicalConnPoint, supportingOtuInterface);
324             default:
325                 return null;
326         }
327     }
328 }