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.rev210927.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;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.OduAttributes.MonitoringMode;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.odu.container.OduBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.opu.Opu;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.opu.OpuBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.parent.odu.allocation.ParentOduAllocation;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.parent.odu.allocation.ParentOduAllocationBuilder;
41 import org.opendaylight.yangtools.yang.common.Uint16;
42 import org.opendaylight.yangtools.yang.common.Uint32;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
47 public class OpenRoadmOtnInterface221 {
49 private static final String MAPPING_ERROR_EXCEPTION_MESSAGE =
50 "Unable to get mapping from PortMapping for node % and logical connection port %s";
51 private final PortMapping portMapping;
52 private final OpenRoadmInterfaces openRoadmInterfaces;
53 private static final Logger LOG = LoggerFactory
54 .getLogger(OpenRoadmOtnInterface221.class);
56 public OpenRoadmOtnInterface221(PortMapping portMapping,
57 OpenRoadmInterfaces openRoadmInterfaces) {
58 this.portMapping = portMapping;
59 this.openRoadmInterfaces = openRoadmInterfaces;
62 public String createOpenRoadmEth1GInterface(String nodeId,
63 String logicalConnPoint) throws OpenRoadmInterfaceException {
64 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
65 if (portMap == null) {
66 throwException(nodeId, logicalConnPoint);
69 // Ethernet interface specific data
70 EthernetBuilder ethIfBuilder = new EthernetBuilder()
71 .setSpeed(Uint32.valueOf(1000));
72 InterfaceBuilder ethInterfaceBldr = createGenericInterfaceBuilder(
73 portMap, EthernetCsmacd.class,
74 logicalConnPoint + "-ETHERNET1G");
75 // Create Interface1 type object required for adding as augmentation
76 Interface1Builder ethIf1Builder = new Interface1Builder();
77 ethInterfaceBldr.addAugmentation(ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
78 // Post interface on the device
79 this.openRoadmInterfaces.postOTNInterface(nodeId, ethInterfaceBldr);
80 // Post the equipment-state change on the device circuit-pack
81 this.openRoadmInterfaces.postOTNEquipmentState(nodeId,
82 portMap.getSupportingCircuitPackName(), true);
83 this.portMapping.updateMapping(nodeId, portMap);
84 String ethernetInterfaceName = ethInterfaceBldr.getName();
86 return ethernetInterfaceName;
89 private void throwException(String nodeId, String logicalConnPoint)
90 throws OpenRoadmInterfaceException {
91 throw new OpenRoadmInterfaceException(String.format(
92 "Unable to get mapping from PortMapping for node % and logical connection port %s",
93 nodeId, logicalConnPoint));
96 private InterfaceBuilder createGenericInterfaceBuilder(Mapping portMap,
97 Class<? extends InterfaceType> type, String key) {
98 return new InterfaceBuilder()
99 // .setDescription(" TBD ")
100 // .setCircuitId(" TBD ")
101 .setSupportingCircuitPackName(
102 portMap.getSupportingCircuitPackName())
103 .setSupportingPort(portMap.getSupportingPort())
104 .setAdministrativeState(AdminStates.InService)
105 // TODO get rid of unchecked cast warning
106 .setType(type).setName(key).withKey(new InterfaceKey(key));
109 public String createOpenRoadmEth10GInterface(String nodeId,
110 String logicalConnPoint) throws OpenRoadmInterfaceException {
111 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
112 if (portMap == null) {
113 throwException(nodeId, logicalConnPoint);
116 // Ethernet interface specific data
117 EthernetBuilder ethIfBuilder = new EthernetBuilder()
118 // .setAutoNegotiation(EthAttributes.AutoNegotiation.Disabled)
119 .setSpeed(Uint32.valueOf(10000));
120 // Create Interface1 type object required for adding as augmentation
121 Interface1Builder ethIf1Builder = new Interface1Builder();
122 InterfaceBuilder ethInterfaceBldr = createGenericInterfaceBuilder(portMap, EthernetCsmacd.class,
123 logicalConnPoint + "-ETHERNET10G").addAugmentation(ethIf1Builder.setEthernet(ethIfBuilder.build())
125 // Post interface on the device
126 this.openRoadmInterfaces.postOTNInterface(nodeId, ethInterfaceBldr);
127 // Post the equipment-state change on the device circuit-pack
128 this.openRoadmInterfaces.postOTNEquipmentState(nodeId,
129 portMap.getSupportingCircuitPackName(), true);
130 this.portMapping.updateMapping(nodeId, portMap);
131 String ethernetInterfaceName = ethInterfaceBldr.getName();
133 return ethernetInterfaceName;
136 public String createOpenRoadmOdu2eInterface(String nodeId, String logicalConnPoint, String serviceName,
137 boolean isCTP, int tribPortNumber, int tribSlotIndex, AEndApiInfo apiInfoA, ZEndApiInfo apiInfoZ)
138 throws OpenRoadmInterfaceException {
140 Mapping mapping = this.portMapping.getMapping(nodeId, logicalConnPoint);
141 if (mapping == null) {
142 throw new OpenRoadmInterfaceException(
143 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
145 InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(mapping, OtnOdu.class,
146 logicalConnPoint + "-ODU2e-" + serviceName);
147 if (mapping.getSupportingOdu4() != null) {
148 oduInterfaceBldr.setSupportingInterface(mapping.getSupportingOdu4());
150 if (mapping.getSupportingEthernet() != null) {
151 oduInterfaceBldr.setSupportingInterface(mapping.getSupportingEthernet());
154 Class<? extends OduFunctionIdentity> oduFunction;
155 MonitoringMode monitoringMode;
157 ParentOduAllocation parentOduAllocation = null;
159 oduFunction = ODUCTP.class;
160 monitoringMode = MonitoringMode.Monitored;
161 List<Uint16> tribSlots = new ArrayList<>();
162 Uint16 newIdx = Uint16.valueOf(tribSlotIndex);
163 tribSlots.add(newIdx);
164 IntStream.range(tribSlotIndex, tribSlotIndex + 8)
165 .forEach(nbr -> tribSlots.add(Uint16.valueOf(nbr)));
166 parentOduAllocation = new ParentOduAllocationBuilder()
167 .setTribPortNumber(Uint16.valueOf(tribPortNumber))
168 .setTribSlots(tribSlots)
171 oduFunction = ODUTTPCTP.class;
172 monitoringMode = MonitoringMode.Terminated;
173 opu = new OpuBuilder()
174 .setPayloadType(PayloadTypeDef.getDefaultInstance("03"))
175 .setExpPayloadType(PayloadTypeDef.getDefaultInstance("03"))
178 OduBuilder oduIfBuilder = new OduBuilder()
179 .setRate(ODU2e.class)
180 .setOduFunction(oduFunction)
181 .setMonitoringMode(monitoringMode)
183 .setParentOduAllocation(parentOduAllocation);
184 if (apiInfoA != null) {
185 oduIfBuilder.setTxSapi(apiInfoA.getSapi())
186 .setTxDapi(apiInfoA.getDapi())
187 .setExpectedSapi(apiInfoA.getExpectedSapi())
188 .setExpectedDapi(apiInfoA.getExpectedDapi());
190 if (apiInfoZ != null) {
191 oduIfBuilder.setTxSapi(apiInfoZ.getSapi())
192 .setTxDapi(apiInfoZ.getDapi())
193 .setExpectedSapi(apiInfoZ.getExpectedSapi())
194 .setExpectedDapi(apiInfoZ.getExpectedDapi());
196 // Create Interface1 type object required for adding as augmentation
197 // TODO look at imports of different versions of class
198 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder
200 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
201 oduInterfaceBldr.addAugmentation(oduIf1Builder.setOdu(oduIfBuilder.build()).build());
203 // Post interface on the device
204 this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
206 LOG.info("{}-{} updating mapping with interface {}", nodeId, logicalConnPoint, oduInterfaceBldr.getName());
207 this.portMapping.updateMapping(nodeId, mapping);
209 return oduInterfaceBldr.getName();
212 public String createOpenRoadmOdu0Interface(String nodeId,
213 String logicalConnPoint, String serviceName, String payLoad,
214 boolean isNetworkPort, int tribPortNumber, int tribSlot)
215 throws OpenRoadmInterfaceException {
216 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
217 String supportingInterface = null;
220 supportingInterface = portMap.getSupportingOdu4();
222 supportingInterface = logicalConnPoint + "-ETHERNET1G";
224 if (portMap == null) {
225 throwException(nodeId, logicalConnPoint);
227 InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(
228 portMap, OtnOdu.class,
229 logicalConnPoint + "-ODU0-" + serviceName);
230 oduInterfaceBldr.setSupportingInterface(supportingInterface);
232 // ODU interface specific data
233 OduBuilder oduIfBuilder = new OduBuilder().setRate(ODU0.class)
234 .setOduFunction(ODUTTPCTP.class)
235 .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
237 LOG.debug("Network port is true");
238 List<Uint16> tribSlots = new ArrayList<>();
240 tribSlots.add(Uint16.valueOf(tribSlot));
241 ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
242 // set trib port numbers
243 .setTribPortNumber(Uint16.valueOf(tribPortNumber))
244 .setTribSlots(tribSlots);
245 oduIfBuilder.setOduFunction(ODUCTP.class)
246 .setMonitoringMode(OduAttributes.MonitoringMode.Monitored)
247 .setParentOduAllocation(parentOduAllocationBuilder.build());
248 LOG.debug("Network port is true {} {} {}",
249 oduIfBuilder.getParentOduAllocation().getTribSlots(),
250 oduIfBuilder.getRate(),
251 oduIfBuilder.getParentOduAllocation().getTribPortNumber());
253 LOG.debug("Current port is a client port");
254 OpuBuilder opuBldr = new OpuBuilder()
255 .setPayloadType(new PayloadTypeDef(payLoad))
256 .setExpPayloadType(new PayloadTypeDef(payLoad));
257 oduIfBuilder.setOpu(opuBldr.build());
259 // Create Interface1 type object required for adding as augmentation
260 // TODO look at imports of different versions of class
261 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder
263 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
264 oduInterfaceBldr.addAugmentation(oduIf1Builder.setOdu(oduIfBuilder.build()).build());
266 // Post interface on the device
267 this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
268 LOG.info("returning the ODU0 inteface {}", oduInterfaceBldr.getName());
269 return oduInterfaceBldr.getName();
272 public String createOpenRoadmOdu2Interface(String nodeId,
273 String logicalConnPoint, String serviceName, String payLoad,
274 boolean isNetworkPort, int tribPortNumber, int tribSlotIndex)
275 throws OpenRoadmInterfaceException {
276 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
277 String supportingInterface = null;
279 if (portMap != null) {
281 supportingInterface = portMap.getSupportingOdu4();
283 supportingInterface = portMap.getSupportingEthernet();
286 throwException(nodeId, logicalConnPoint);
288 InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(
289 portMap, OtnOdu.class,
290 logicalConnPoint + "-ODU2-" + serviceName)
291 .setSupportingInterface(supportingInterface);
293 OduBuilder oduIfBuilder = new OduBuilder().setRate(ODU2.class)
294 .setOduFunction(ODUTTPCTP.class)
295 .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
297 List<Uint16> tribSlots = new ArrayList<>();
298 IntStream.range(tribSlotIndex, tribSlotIndex + 8)
299 .forEach(nbr -> tribSlots.add(Uint16.valueOf(nbr)));
300 ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
301 // set trib port numbers
302 .setTribPortNumber(Uint16.valueOf(tribPortNumber))
303 .setTribSlots(tribSlots);
304 oduIfBuilder.setOduFunction(ODUCTP.class)
305 .setMonitoringMode(OduAttributes.MonitoringMode.Monitored)
306 .setParentOduAllocation(parentOduAllocationBuilder.build());
308 // Set Opu attributes
309 OpuBuilder opuBldr = new OpuBuilder()
310 .setPayloadType(new PayloadTypeDef(payLoad))
311 .setExpPayloadType(new PayloadTypeDef(payLoad));
312 oduIfBuilder.setOpu(opuBldr.build());
315 // Create Interface1 type object required for adding as augmentation
316 // TODO look at imports of different versions of class
317 // Create Interface1 type object required for adding as augmentation
318 // TODO look at imports of different versions of class
319 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder
321 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
322 oduInterfaceBldr.addAugmentation(oduIf1Builder.setOdu(oduIfBuilder.build()).build());
324 // Post interface on the device
325 this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
326 LOG.info("returning the ODU2 inteface {}", oduInterfaceBldr.getName());
327 return oduInterfaceBldr.getName();