Upgrade to Service Path 1.7
[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
13 import org.opendaylight.transportpce.common.StringConstants;
14 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
15 import org.opendaylight.transportpce.common.mapping.MappingUtils;
16 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200128.network.nodes.Mapping;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.OchAttributes;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.RateIdentity;
20
21 public class OpenRoadmInterfaceFactory {
22
23     private final MappingUtils mappingUtils;
24     private final OpenRoadmInterface121 openRoadmInterface121;
25     private final OpenRoadmInterface221 openRoadmInterface221;
26
27
28     public OpenRoadmInterfaceFactory(MappingUtils mappingUtils, OpenRoadmInterface121 openRoadmInterface121,
29         OpenRoadmInterface221 openRoadmInterface221) {
30         this.mappingUtils = mappingUtils;
31         this.openRoadmInterface121 = openRoadmInterface121;
32         this.openRoadmInterface221 = openRoadmInterface221;
33     }
34
35     public String createOpenRoadmEthInterface(String nodeId, String logicalConnPoint)
36         throws OpenRoadmInterfaceException {
37
38         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
39             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
40                 return openRoadmInterface121.createOpenRoadmEthInterface(nodeId, logicalConnPoint);
41             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
42                 return openRoadmInterface221.createOpenRoadmEthInterface(nodeId, logicalConnPoint);
43             default:
44                 return null;
45         }
46     }
47
48
49     /**
50      * This methods creates an OCH interface on the given termination point on
51      * Roadm.
52      *
53      * @param nodeId node ID
54      * @param logicalConnPoint logical connection point
55      * @param waveNumber wavelength number of the OCH interface.
56      *
57      * @return Name of the interface if successful, otherwise return null.
58      *
59      * @throws OpenRoadmInterfaceException OpenRoadm interface exception
60      */
61
62     public List<String> createOpenRoadmOchInterface(String nodeId, String logicalConnPoint, Long waveNumber)
63         throws OpenRoadmInterfaceException {
64
65         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
66             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
67                 return openRoadmInterface121.createOpenRoadmOchInterface(nodeId, logicalConnPoint,waveNumber);
68             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
69                 return openRoadmInterface221.createFlexOCH(nodeId, logicalConnPoint,waveNumber);
70             default:
71                 return null;
72         }
73     }
74
75
76     public String createOpenRoadmOchInterface(String nodeId, String logicalConnPoint, Long waveNumber,
77         Class<? extends RateIdentity> rate, OchAttributes.ModulationFormat format) throws OpenRoadmInterfaceException {
78         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
79             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
80                 return openRoadmInterface121.createOpenRoadmOchInterface(nodeId, logicalConnPoint, waveNumber,
81                     rate, format);
82             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
83                 return openRoadmInterface221.createOpenRoadmOchInterface(nodeId,logicalConnPoint,waveNumber);
84             default:
85                 return null;
86         }
87     }
88
89     /**
90      * This methods creates an ODU interface on the given termination point.
91      *
92      * @param nodeId node ID
93      * @param logicalConnPoint logical connection point
94      * @param supportingOtuInterface supporting OTU interface
95      *
96      * @return Name of the interface if successful, otherwise return null.
97      *
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 OTU interface on the given termination point.
117      *
118      * @param nodeId node ID
119      * @param logicalConnPoint logical connection point
120      * @param supportOchInterface supporting OCH interface
121      *
122      * @return Name of the interface if successful, otherwise return null.
123      *
124      * @throws OpenRoadmInterfaceException OpenRoadm interface exception
125      */
126
127     public String createOpenRoadmOtu4Interface(String nodeId, String logicalConnPoint, String supportOchInterface)
128             throws OpenRoadmInterfaceException {
129         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
130             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
131                 return openRoadmInterface121.createOpenRoadmOtu4Interface(nodeId,
132                     logicalConnPoint,supportOchInterface);
133             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
134                 return openRoadmInterface221.createOpenRoadmOtu4Interface(nodeId,logicalConnPoint, supportOchInterface);
135             default:
136                 return null;
137         }
138     }
139
140     public String createOpenRoadmOchInterfaceName(String logicalConnectionPoint, Long waveNumber) {
141         return logicalConnectionPoint + "-" + waveNumber;
142     }
143
144     public String createOpenRoadmOmsInterface(String nodeId, Mapping mapping) throws OpenRoadmInterfaceException {
145         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
146             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
147                 return openRoadmInterface121.createOpenRoadmOmsInterface(nodeId,mapping);
148             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
149                 return openRoadmInterface221.createOpenRoadmOmsInterface(nodeId,mapping);
150             default:
151                 return null;
152         }
153     }
154
155     public String createOpenRoadmOtsInterface(String nodeId, Mapping mapping) throws OpenRoadmInterfaceException {
156         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
157             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
158                 return openRoadmInterface121.createOpenRoadmOtsInterface(nodeId,mapping);
159             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
160                 return openRoadmInterface221.createOpenRoadmOtsInterface(nodeId,mapping);
161             default:
162                 return null;
163         }
164     }
165
166     public boolean isUsedbyXc(String nodeId, String interfaceName, String xc,
167         DeviceTransactionManager deviceTransactionManager) {
168         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
169             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
170                 return openRoadmInterface121.isUsedByXc(nodeId, interfaceName, xc, deviceTransactionManager);
171             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
172                 return openRoadmInterface221.isUsedByXc(nodeId, interfaceName, xc, deviceTransactionManager);
173             default:
174                 return false;
175         }
176     }
177
178
179 }