2 * Copyright © 2019 AT&T and others. All rights reserved.
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
8 package org.opendaylight.transportpce.renderer.openroadminterface;
10 import java.util.ArrayList;
11 import java.util.List;
12 import java.util.stream.IntStream;
13 import org.opendaylight.transportpce.common.mapping.PortMapping;
14 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
15 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.AEndApiInfo;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.az.api.info.ZEndApiInfo;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.Mapping;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.InterfaceBuilder;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.InterfaceKey;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev171215.AdminStates;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev181019.Interface1Builder;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev181019.ethernet.container.EthernetBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.EthernetCsmacd;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.InterfaceType;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OtnOdu;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODU0;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODU2;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODU2e;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODUCTP;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODUTTPCTP;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.OduFunctionIdentity;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.PayloadTypeDef;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.OduAttributes.MonitoringMode;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.odu.container.OduBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.opu.Opu;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.opu.OpuBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.parent.odu.allocation.ParentOduAllocation;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.parent.odu.allocation.ParentOduAllocationBuilder;
40 import org.opendaylight.yangtools.yang.common.Uint16;
41 import org.opendaylight.yangtools.yang.common.Uint32;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
46 public class OpenRoadmOtnInterface221 {
48 private static final String MAPPING_ERROR_EXCEPTION_MESSAGE =
49 "Unable to get mapping from PortMapping for node % and logical connection port %s";
50 private final PortMapping portMapping;
51 private final OpenRoadmInterfaces openRoadmInterfaces;
52 private static final Logger LOG = LoggerFactory
53 .getLogger(OpenRoadmOtnInterface221.class);
55 public OpenRoadmOtnInterface221(PortMapping portMapping,
56 OpenRoadmInterfaces openRoadmInterfaces) {
57 this.portMapping = portMapping;
58 this.openRoadmInterfaces = openRoadmInterfaces;
61 public String createOpenRoadmEth1GInterface(String nodeId,
62 String logicalConnPoint) throws OpenRoadmInterfaceException {
63 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
64 if (portMap == null) {
65 throwException(nodeId, logicalConnPoint);
68 // Ethernet interface specific data
69 EthernetBuilder ethIfBuilder = new EthernetBuilder()
70 .setSpeed(Uint32.valueOf(1000));
71 InterfaceBuilder ethInterfaceBldr = createGenericInterfaceBuilder(
72 portMap, EthernetCsmacd.class,
73 logicalConnPoint + "-ETHERNET1G");
74 // Create Interface1 type object required for adding as augmentation
75 Interface1Builder ethIf1Builder = new Interface1Builder();
76 ethInterfaceBldr.addAugmentation(ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
77 // Post interface on the device
78 this.openRoadmInterfaces.postOTNInterface(nodeId, ethInterfaceBldr);
79 // Post the equipment-state change on the device circuit-pack
80 this.openRoadmInterfaces.postOTNEquipmentState(nodeId,
81 portMap.getSupportingCircuitPackName(), true);
82 this.portMapping.updateMapping(nodeId, portMap);
83 String ethernetInterfaceName = ethInterfaceBldr.getName();
85 return ethernetInterfaceName;
88 private void throwException(String nodeId, String logicalConnPoint)
89 throws OpenRoadmInterfaceException {
90 throw new OpenRoadmInterfaceException(String.format(
91 "Unable to get mapping from PortMapping for node % and logical connection port %s",
92 nodeId, logicalConnPoint));
95 private InterfaceBuilder createGenericInterfaceBuilder(Mapping portMap,
96 Class<? extends InterfaceType> type, String key) {
97 return new InterfaceBuilder()
98 // .setDescription(" TBD ")
99 // .setCircuitId(" TBD ")
100 .setSupportingCircuitPackName(
101 portMap.getSupportingCircuitPackName())
102 .setSupportingPort(portMap.getSupportingPort())
103 .setAdministrativeState(AdminStates.InService)
104 // TODO get rid of unchecked cast warning
105 .setType(type).setName(key).withKey(new InterfaceKey(key));
108 public String createOpenRoadmEth10GInterface(String nodeId,
109 String logicalConnPoint) throws OpenRoadmInterfaceException {
110 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
111 if (portMap == null) {
112 throwException(nodeId, logicalConnPoint);
115 // Ethernet interface specific data
116 EthernetBuilder ethIfBuilder = new EthernetBuilder()
117 // .setAutoNegotiation(EthAttributes.AutoNegotiation.Disabled)
118 .setSpeed(Uint32.valueOf(10000));
119 // Create Interface1 type object required for adding as augmentation
120 Interface1Builder ethIf1Builder = new Interface1Builder();
121 InterfaceBuilder ethInterfaceBldr = createGenericInterfaceBuilder(portMap, EthernetCsmacd.class,
122 logicalConnPoint + "-ETHERNET10G").addAugmentation(ethIf1Builder.setEthernet(ethIfBuilder.build())
124 // Post interface on the device
125 this.openRoadmInterfaces.postOTNInterface(nodeId, ethInterfaceBldr);
126 // Post the equipment-state change on the device circuit-pack
127 this.openRoadmInterfaces.postOTNEquipmentState(nodeId,
128 portMap.getSupportingCircuitPackName(), true);
129 this.portMapping.updateMapping(nodeId, portMap);
130 String ethernetInterfaceName = ethInterfaceBldr.getName();
132 return ethernetInterfaceName;
135 public String createOpenRoadmOdu2eInterface(String nodeId, String logicalConnPoint,
136 boolean isCTP, int tribPortNumber, int tribSlotIndex, AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ,
137 String payloadType) throws OpenRoadmInterfaceException {
139 Mapping mapping = this.portMapping.getMapping(nodeId, logicalConnPoint);
140 if (mapping == null) {
141 throw new OpenRoadmInterfaceException(
142 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
144 InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(mapping, OtnOdu.class,
145 logicalConnPoint + "-ODU2e");
146 if (mapping.getSupportingOdu4() != null) {
147 oduInterfaceBldr.setSupportingInterface(mapping.getSupportingOdu4());
149 if (mapping.getSupportingEthernet() != null) {
150 oduInterfaceBldr.setSupportingInterface(mapping.getSupportingEthernet());
153 Class<? extends OduFunctionIdentity> oduFunction;
154 MonitoringMode monitoringMode;
156 ParentOduAllocation parentOduAllocation = null;
158 oduFunction = ODUCTP.class;
159 monitoringMode = MonitoringMode.Monitored;
160 List<Uint16> tribSlots = new ArrayList<>();
161 Uint16 newIdx = Uint16.valueOf(tribSlotIndex);
162 tribSlots.add(newIdx);
163 IntStream.range(tribSlotIndex, tribSlotIndex + 8)
164 .forEach(nbr -> tribSlots.add(Uint16.valueOf(nbr)));
165 parentOduAllocation = new ParentOduAllocationBuilder()
166 .setTribPortNumber(Uint16.valueOf(tribPortNumber))
167 .setTribSlots(tribSlots)
170 oduFunction = ODUTTPCTP.class;
171 monitoringMode = MonitoringMode.Terminated;
172 opu = new OpuBuilder()
173 .setPayloadType(PayloadTypeDef.getDefaultInstance(payloadType))
174 .setExpPayloadType(PayloadTypeDef.getDefaultInstance(payloadType))
177 OduBuilder oduIfBuilder = new OduBuilder()
178 .setRate(ODU2e.class)
179 .setOduFunction(oduFunction)
180 .setMonitoringMode(monitoringMode)
182 .setParentOduAllocation(parentOduAllocation);
183 if (apiInfoA != null) {
184 oduIfBuilder.setTxSapi(apiInfoA.getSapi())
185 .setTxDapi(apiInfoA.getDapi())
186 .setExpectedSapi(apiInfoA.getExpectedSapi())
187 .setExpectedDapi(apiInfoA.getExpectedDapi());
189 if (apiInfoZ != null) {
190 oduIfBuilder.setTxSapi(apiInfoZ.getSapi())
191 .setTxDapi(apiInfoZ.getDapi())
192 .setExpectedSapi(apiInfoZ.getExpectedSapi())
193 .setExpectedDapi(apiInfoZ.getExpectedDapi());
195 // Create Interface1 type object required for adding as augmentation
196 // TODO look at imports of different versions of class
197 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder
199 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
200 oduInterfaceBldr.addAugmentation(oduIf1Builder.setOdu(oduIfBuilder.build()).build());
202 // Post interface on the device
203 this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
205 LOG.info("{}-{} updating mapping with interface {}", nodeId, logicalConnPoint, oduInterfaceBldr.getName());
206 this.portMapping.updateMapping(nodeId, mapping);
208 return oduInterfaceBldr.getName();
211 public String createOpenRoadmOdu0Interface(String nodeId, String logicalConnPoint,
212 boolean isCTP, int tribPortNumber, int tribSlotIndex, AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ,
213 String payloadType) throws OpenRoadmInterfaceException {
215 Mapping mapping = this.portMapping.getMapping(nodeId, logicalConnPoint);
216 if (mapping == null) {
217 throw new OpenRoadmInterfaceException(
218 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
220 InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(mapping, OtnOdu.class,
221 logicalConnPoint + "-ODU0");
222 if (mapping.getSupportingOdu4() != null) {
223 oduInterfaceBldr.setSupportingInterface(mapping.getSupportingOdu4());
225 if (mapping.getSupportingEthernet() != null) {
226 oduInterfaceBldr.setSupportingInterface(mapping.getSupportingEthernet());
229 Class<? extends OduFunctionIdentity> oduFunction;
230 MonitoringMode monitoringMode;
232 ParentOduAllocation parentOduAllocation = null;
234 oduFunction = ODUCTP.class;
235 monitoringMode = MonitoringMode.Monitored;
236 List<Uint16> tribSlots = new ArrayList<>();
237 Uint16 newIdx = Uint16.valueOf(tribSlotIndex);
238 tribSlots.add(newIdx);
239 IntStream.range(tribSlotIndex, tribSlotIndex + 8)
240 .forEach(nbr -> tribSlots.add(Uint16.valueOf(nbr)));
241 parentOduAllocation = new ParentOduAllocationBuilder()
242 .setTribPortNumber(Uint16.valueOf(tribPortNumber))
243 .setTribSlots(tribSlots)
246 oduFunction = ODUTTPCTP.class;
247 monitoringMode = MonitoringMode.Terminated;
248 opu = new OpuBuilder()
249 .setPayloadType(PayloadTypeDef.getDefaultInstance(payloadType))
250 .setExpPayloadType(PayloadTypeDef.getDefaultInstance(payloadType))
253 OduBuilder oduIfBuilder = new OduBuilder()
255 .setOduFunction(oduFunction)
256 .setMonitoringMode(monitoringMode)
258 .setParentOduAllocation(parentOduAllocation);
259 if (apiInfoA != null) {
260 oduIfBuilder.setTxSapi(apiInfoA.getSapi())
261 .setTxDapi(apiInfoA.getDapi())
262 .setExpectedSapi(apiInfoA.getExpectedSapi())
263 .setExpectedDapi(apiInfoA.getExpectedDapi());
265 if (apiInfoZ != null) {
266 oduIfBuilder.setTxSapi(apiInfoZ.getSapi())
267 .setTxDapi(apiInfoZ.getDapi())
268 .setExpectedSapi(apiInfoZ.getExpectedSapi())
269 .setExpectedDapi(apiInfoZ.getExpectedDapi());
271 // Create Interface1 type object required for adding as augmentation
272 // TODO look at imports of different versions of class
273 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder
275 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
276 oduInterfaceBldr.addAugmentation(oduIf1Builder.setOdu(oduIfBuilder.build()).build());
278 // Post interface on the device
279 this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
281 LOG.info("{}-{} updating mapping with interface {}", nodeId, logicalConnPoint, oduInterfaceBldr.getName());
282 this.portMapping.updateMapping(nodeId, mapping);
284 return oduInterfaceBldr.getName();
287 public String createOpenRoadmOdu2Interface(String nodeId, String logicalConnPoint,
288 boolean isCTP, int tribPortNumber, int tribSlotIndex, AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ,
289 String payloadType) throws OpenRoadmInterfaceException {
291 Mapping mapping = this.portMapping.getMapping(nodeId, logicalConnPoint);
292 if (mapping == null) {
293 throw new OpenRoadmInterfaceException(
294 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
296 InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(mapping, OtnOdu.class,
297 logicalConnPoint + "-ODU2");
298 if (mapping.getSupportingOdu4() != null) {
299 oduInterfaceBldr.setSupportingInterface(mapping.getSupportingOdu4());
301 if (mapping.getSupportingEthernet() != null) {
302 oduInterfaceBldr.setSupportingInterface(mapping.getSupportingEthernet());
305 Class<? extends OduFunctionIdentity> oduFunction;
306 MonitoringMode monitoringMode;
308 ParentOduAllocation parentOduAllocation = null;
310 oduFunction = ODUCTP.class;
311 monitoringMode = MonitoringMode.Monitored;
312 List<Uint16> tribSlots = new ArrayList<>();
313 Uint16 newIdx = Uint16.valueOf(tribSlotIndex);
314 tribSlots.add(newIdx);
315 IntStream.range(tribSlotIndex, tribSlotIndex + 8)
316 .forEach(nbr -> tribSlots.add(Uint16.valueOf(nbr)));
317 parentOduAllocation = new ParentOduAllocationBuilder()
318 .setTribPortNumber(Uint16.valueOf(tribPortNumber))
319 .setTribSlots(tribSlots)
322 oduFunction = ODUTTPCTP.class;
323 monitoringMode = MonitoringMode.Terminated;
324 opu = new OpuBuilder()
325 .setPayloadType(PayloadTypeDef.getDefaultInstance(payloadType))
326 .setExpPayloadType(PayloadTypeDef.getDefaultInstance(payloadType))
329 OduBuilder oduIfBuilder = new OduBuilder()
331 .setOduFunction(oduFunction)
332 .setMonitoringMode(monitoringMode)
334 .setParentOduAllocation(parentOduAllocation);
335 if (apiInfoA != null) {
336 oduIfBuilder.setTxSapi(apiInfoA.getSapi())
337 .setTxDapi(apiInfoA.getDapi())
338 .setExpectedSapi(apiInfoA.getExpectedSapi())
339 .setExpectedDapi(apiInfoA.getExpectedDapi());
341 if (apiInfoZ != null) {
342 oduIfBuilder.setTxSapi(apiInfoZ.getSapi())
343 .setTxDapi(apiInfoZ.getDapi())
344 .setExpectedSapi(apiInfoZ.getExpectedSapi())
345 .setExpectedDapi(apiInfoZ.getExpectedDapi());
347 // Create Interface1 type object required for adding as augmentation
348 // TODO look at imports of different versions of class
349 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder
351 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
352 oduInterfaceBldr.addAugmentation(oduIf1Builder.setOdu(oduIfBuilder.build()).build());
354 // Post interface on the device
355 this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
357 LOG.info("{}-{} updating mapping with interface {}", nodeId, logicalConnPoint, oduInterfaceBldr.getName());
358 this.portMapping.updateMapping(nodeId, mapping);
360 return oduInterfaceBldr.getName();