cd8f1fef2c48cfc3f5f25bf6f5faf41762642412
[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.rev170228.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,
36                                               String logicalConnPoint) 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 waveNumber wavelength number of the OCH interface.
54      * @return Name of the interface if successful, otherwise return null.
55      */
56
57     public List<String> createOpenRoadmOchInterface(String nodeId, String logicalConnPoint, Long waveNumber)
58         throws OpenRoadmInterfaceException {
59
60         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
61             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
62                 return openRoadmInterface121.createOpenRoadmOchInterface(nodeId, logicalConnPoint,waveNumber);
63             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
64                 return openRoadmInterface221.createFlexOCH(nodeId, logicalConnPoint,waveNumber);
65             default:
66                 return null;
67         }
68     }
69
70
71     public String createOpenRoadmOchInterface(String nodeId, String logicalConnPoint, Long waveNumber,
72         Class<? extends RateIdentity> rate, OchAttributes.ModulationFormat format) throws OpenRoadmInterfaceException {
73         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
74             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
75                 return openRoadmInterface121.createOpenRoadmOchInterface(nodeId, logicalConnPoint, waveNumber,
76                     rate, format);
77             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
78                 return openRoadmInterface221.createOpenRoadmOchInterface(nodeId,logicalConnPoint,waveNumber);
79             default:
80                 return null;
81         }
82     }
83
84     /**
85      * This methods creates an ODU interface on the given termination point.
86      *
87      * @return Name of the interface if successful, otherwise return null.
88      */
89
90     public String createOpenRoadmOdu4Interface(String nodeId, String logicalConnPoint, String supportingOtuInterface)
91             throws OpenRoadmInterfaceException {
92         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
93             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
94                 return openRoadmInterface121.createOpenRoadmOdu4Interface(nodeId, logicalConnPoint,
95                     supportingOtuInterface);
96             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
97                 return openRoadmInterface221.createOpenRoadmOdu4Interface(nodeId, logicalConnPoint,
98                     supportingOtuInterface);
99             default:
100                 return null;
101         }
102     }
103
104     /**
105      * This methods creates an OTU interface on the given termination point.
106      *
107      * @return Name of the interface if successful, otherwise return null.
108      */
109
110     public String createOpenRoadmOtu4Interface(String nodeId, String logicalConnPoint, String supportOchInterface)
111             throws OpenRoadmInterfaceException {
112         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
113             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
114                 return openRoadmInterface121.createOpenRoadmOtu4Interface(nodeId,
115                     logicalConnPoint,supportOchInterface);
116             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
117                 return openRoadmInterface221.createOpenRoadmOtu4Interface(nodeId,logicalConnPoint, supportOchInterface);
118             default:
119                 return null;
120         }
121     }
122
123     public String createOpenRoadmOchInterfaceName(String logicalConnectionPoint, Long waveNumber) {
124         return logicalConnectionPoint + "-" + waveNumber;
125     }
126
127     public String createOpenRoadmOmsInterface(String nodeId, Mapping mapping) throws OpenRoadmInterfaceException {
128         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
129             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
130                 return openRoadmInterface121.createOpenRoadmOmsInterface(nodeId,mapping);
131             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
132                 return openRoadmInterface221.createOpenRoadmOmsInterface(nodeId,mapping);
133             default:
134                 return null;
135         }
136     }
137
138     public String createOpenRoadmOtsInterface(String nodeId, Mapping mapping) throws OpenRoadmInterfaceException {
139         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
140             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
141                 return openRoadmInterface121.createOpenRoadmOtsInterface(nodeId,mapping);
142             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
143                 return openRoadmInterface221.createOpenRoadmOtsInterface(nodeId,mapping);
144             default:
145                 return null;
146         }
147     }
148
149     public boolean isUsedbyXc(String nodeId, String interfaceName, String xc,
150         DeviceTransactionManager deviceTransactionManager) {
151         switch (mappingUtils.getOpenRoadmVersion(nodeId)) {
152             case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
153                 return openRoadmInterface121.isUsedByXc(nodeId, interfaceName, xc, deviceTransactionManager);
154             case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
155                 return openRoadmInterface221.isUsedByXc(nodeId, interfaceName, xc, deviceTransactionManager);
156             default:
157                 return false;
158         }
159     }
160
161
162 }