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;
14 import org.opendaylight.transportpce.common.mapping.PortMapping;
15 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
16 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
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.device.rev181019.interfaces.grp.InterfaceBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.InterfaceKey;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev171215.AdminStates;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev181019.Interface1;
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.rev161014.EthernetCsmacd;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.InterfaceType;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.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.PayloadTypeDef;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.OduAttributes;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.odu.container.OduBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.opu.OpuBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.parent.odu.allocation.ParentOduAllocationBuilder;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
41 public class OpenRoadmOtnInterface221 {
43 private final PortMapping portMapping;
44 private final OpenRoadmInterfaces openRoadmInterfaces;
45 private static final Logger LOG = LoggerFactory.getLogger(OpenRoadmOtnInterface221.class);
47 public OpenRoadmOtnInterface221(PortMapping portMapping, OpenRoadmInterfaces openRoadmInterfaces) {
48 this.portMapping = portMapping;
49 this.openRoadmInterfaces = openRoadmInterfaces;
52 public String createOpenRoadmEth1GInterface(String nodeId, String logicalConnPoint)
53 throws OpenRoadmInterfaceException {
54 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
55 if (portMap == null) {
56 throw new OpenRoadmInterfaceException(String.format(
57 "Unable to get mapping from PortMapping for node % and logical connection port %s",
58 nodeId, logicalConnPoint));
61 // Ethernet interface specific data
62 EthernetBuilder ethIfBuilder = new EthernetBuilder();
63 //ethIfBuilder.setAutoNegotiation(EthAttributes.AutoNegotiation.Disabled);
64 ethIfBuilder.setSpeed(1000L);
65 InterfaceBuilder ethInterfaceBldr =
66 createGenericInterfaceBuilder(portMap, EthernetCsmacd.class, logicalConnPoint + "-ETHERNET1G");
67 // Create Interface1 type object required for adding as augmentation
68 Interface1Builder ethIf1Builder = new Interface1Builder();
69 ethInterfaceBldr.addAugmentation(Interface1.class, ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
70 // Post interface on the device
71 this.openRoadmInterfaces.postOTNInterface(nodeId, ethInterfaceBldr);
72 // Post the equipment-state change on the device circuit-pack
73 this.openRoadmInterfaces.postOTNEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
74 this.portMapping.updateMapping(nodeId,portMap);
75 String ethernetInterfaceName = ethInterfaceBldr.getName();
77 return ethernetInterfaceName;
80 private InterfaceBuilder createGenericInterfaceBuilder(Mapping portMap,
81 Class<? extends InterfaceType> type, String key) {
82 InterfaceBuilder interfaceBuilder = new InterfaceBuilder()
83 //.setDescription(" TBD ")
84 //.setCircuitId(" TBD ")
85 .setSupportingCircuitPackName(portMap.getSupportingCircuitPackName())
86 .setSupportingPort(portMap.getSupportingPort())
87 .setAdministrativeState(AdminStates.InService)
88 //TODO get rid of unchecked cast warning
90 (Class<? extends org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.InterfaceType>)
94 .withKey(new InterfaceKey(key));
95 return interfaceBuilder;
98 public String createOpenRoadmEth10GInterface(String nodeId, String logicalConnPoint)
99 throws OpenRoadmInterfaceException {
100 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
101 if (portMap == null) {
102 throw new OpenRoadmInterfaceException(
104 "Unable to get mapping from PortMapping for node % and logical connection port %s",
105 nodeId, logicalConnPoint));
108 // Ethernet interface specific data
109 EthernetBuilder ethIfBuilder = new EthernetBuilder()
110 //.setAutoNegotiation(EthAttributes.AutoNegotiation.Disabled)
112 // Create Interface1 type object required for adding as augmentation
113 Interface1Builder ethIf1Builder = new Interface1Builder();
114 InterfaceBuilder ethInterfaceBldr =
115 createGenericInterfaceBuilder(portMap, EthernetCsmacd.class, logicalConnPoint + "-ETHERNET10G")
116 .addAugmentation(Interface1.class, ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
117 // Post interface on the device
118 this.openRoadmInterfaces.postOTNInterface(nodeId, ethInterfaceBldr);
119 // Post the equipment-state change on the device circuit-pack
120 this.openRoadmInterfaces.postOTNEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
121 this.portMapping.updateMapping(nodeId,portMap);
122 String ethernetInterfaceName = ethInterfaceBldr.getName();
124 return ethernetInterfaceName;
128 public String createOpenRoadmOdu2eInterface(
129 String nodeId, String logicalConnPoint, String serviceName,
130 String payLoad, boolean isNetworkPort, int tribPortNumber, int tribSlotIndex)
131 throws OpenRoadmInterfaceException {
132 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
133 if (portMap == null) {
134 throw new OpenRoadmInterfaceException(String.format(
135 "Unable to get mapping from PortMapping for node % and logical connection port %s",
136 nodeId, logicalConnPoint));
138 String supportingInterface = null;
141 supportingInterface = portMap.getSupportingOdu4();
143 supportingInterface = logicalConnPoint + "-ETHERNET10G";
146 if (supportingInterface == null) {
147 throw new OpenRoadmInterfaceException(
148 "Interface Creation failed because of missing supported ODU4 on network end or Eth iface on client");
151 InterfaceBuilder oduInterfaceBldr =
152 createGenericInterfaceBuilder(portMap, OtnOdu.class, logicalConnPoint + "-ODU2e-" + serviceName)
153 .setSupportingInterface(supportingInterface);
155 // ODU interface specific data
156 OduBuilder oduIfBuilder = new OduBuilder()
157 .setRate(ODU2e.class)
158 .setOduFunction(ODUTTPCTP.class)
159 .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
160 LOG.debug("Inside the ODU2e creation {} {} {}",isNetworkPort,tribPortNumber,tribSlotIndex);
162 List<Integer> tribSlots = new ArrayList<>();
163 int newIdx = tribSlotIndex;
164 tribSlots.add(newIdx);
165 IntStream.range(tribSlotIndex, tribSlotIndex + 8).forEach(
166 nbr -> tribSlots.add(nbr)
168 ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
169 .setTribPortNumber(tribPortNumber)
170 .setTribSlots(tribSlots);
171 oduIfBuilder.setOduFunction(ODUCTP.class)
172 .setMonitoringMode(OduAttributes.MonitoringMode.Monitored)
173 .setParentOduAllocation(parentOduAllocationBuilder.build());
176 // Set Opu attributes
177 OpuBuilder opuBldr = new OpuBuilder()
178 .setPayloadType(new PayloadTypeDef(payLoad))
179 .setExpPayloadType(new PayloadTypeDef(payLoad));
180 oduIfBuilder.setOpu(opuBldr.build());
182 // Create Interface1 type object required for adding as augmentation
183 // TODO look at imports of different versions of class
184 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder oduIf1Builder =
185 new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
186 oduInterfaceBldr.addAugmentation(
187 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1.class,
188 oduIf1Builder.setOdu(oduIfBuilder.build()).build());
190 // Post interface on the device
191 this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
192 LOG.info("returning the ODU2e inteface {}", oduInterfaceBldr.getName());
193 return oduInterfaceBldr.getName();
196 public String createOpenRoadmOdu0Interface(String nodeId, String logicalConnPoint,
197 String serviceName, String payLoad, boolean isNetworkPort, int tribPortNumber, int tribSlot)
198 throws OpenRoadmInterfaceException {
199 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
200 String supportingInterface = null;
203 supportingInterface = portMap.getSupportingOdu4();
205 supportingInterface = logicalConnPoint + "-ETHERNET1G";
207 if (portMap == null) {
208 throw new OpenRoadmInterfaceException(String.format(
209 "Unable to get mapping from PortMapping for node % and logical connection port %s",
210 nodeId, logicalConnPoint));
212 InterfaceBuilder oduInterfaceBldr =
213 createGenericInterfaceBuilder(portMap, OtnOdu.class, logicalConnPoint + "-ODU0-" + serviceName);
214 oduInterfaceBldr.setSupportingInterface(supportingInterface);
216 // ODU interface specific data
217 OduBuilder oduIfBuilder = new OduBuilder()
219 .setOduFunction(ODUTTPCTP.class)
220 .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
222 LOG.debug("Network port is true");
223 List<Integer> tribSlots = new ArrayList<>();
224 tribSlots.add(tribSlot); //add trib slots
225 ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
226 //set trib port numbers
227 .setTribPortNumber(tribPortNumber)
228 .setTribSlots(tribSlots);
229 oduIfBuilder.setOduFunction(ODUCTP.class)
230 .setMonitoringMode(OduAttributes.MonitoringMode.Monitored)
231 .setParentOduAllocation(parentOduAllocationBuilder.build());
232 LOG.debug("Network port is true {} {} {}",
233 oduIfBuilder.getParentOduAllocation().getTribSlots(),
234 oduIfBuilder.getRate(),
235 oduIfBuilder.getParentOduAllocation().getTribPortNumber());
238 LOG.debug("Current port is a client port");
239 OpuBuilder opuBldr = new OpuBuilder()
240 .setPayloadType(new PayloadTypeDef(payLoad))
241 .setExpPayloadType(new PayloadTypeDef(payLoad));
242 oduIfBuilder.setOpu(opuBldr.build());
244 // Create Interface1 type object required for adding as augmentation
245 // TODO look at imports of different versions of class
246 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder oduIf1Builder =
247 new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
248 oduInterfaceBldr.addAugmentation(
249 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1.class,
250 oduIf1Builder.setOdu(oduIfBuilder.build()).build());
252 // Post interface on the device
253 this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
254 LOG.info("returning the ODU0 inteface {}", oduInterfaceBldr.getName());
255 return oduInterfaceBldr.getName();
259 public String createOpenRoadmOdu2Interface(
260 String nodeId, String logicalConnPoint, String serviceName,
261 String payLoad, boolean isNetworkPort, int tribPortNumber, int tribSlotIndex)
262 throws OpenRoadmInterfaceException {
263 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
264 String supportingInterface = null;
267 supportingInterface = portMap.getSupportingOdu4();
269 supportingInterface = portMap.getSupportingEthernet();
271 if (portMap == null) {
272 throw new OpenRoadmInterfaceException(
273 String.format("Unable to get mapping from PortMapping for node % and logical connection port %s",
274 nodeId, logicalConnPoint));
276 InterfaceBuilder oduInterfaceBldr =
277 createGenericInterfaceBuilder(portMap, OtnOdu.class, logicalConnPoint + "-ODU2-" + serviceName)
278 .setSupportingInterface(supportingInterface);
280 OduBuilder oduIfBuilder = new OduBuilder()
282 .setOduFunction(ODUTTPCTP.class)
283 .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
285 List<Integer> tribSlots = new ArrayList<>();
286 IntStream.range(tribSlotIndex, tribSlotIndex + 8).forEach(
287 nbr -> tribSlots.add(nbr)
289 ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
290 //set trib port numbers
291 .setTribPortNumber(tribPortNumber)
292 .setTribSlots(tribSlots);
293 oduIfBuilder.setOduFunction(ODUCTP.class)
294 .setMonitoringMode(OduAttributes.MonitoringMode.Monitored)
295 .setParentOduAllocation(parentOduAllocationBuilder.build());
298 // Set Opu attributes
299 OpuBuilder opuBldr = new OpuBuilder()
300 .setPayloadType(new PayloadTypeDef(payLoad))
301 .setExpPayloadType(new PayloadTypeDef(payLoad));
302 oduIfBuilder.setOpu(opuBldr.build());
305 // Create Interface1 type object required for adding as augmentation
306 // TODO look at imports of different versions of class
307 // Create Interface1 type object required for adding as augmentation
308 // TODO look at imports of different versions of class
309 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder oduIf1Builder =
310 new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
311 oduInterfaceBldr.addAugmentation(
312 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1.class,
313 oduIf1Builder.setOdu(oduIfBuilder.build()).build());
315 // Post interface on the device
316 this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
317 LOG.info("returning the ODU2 inteface {}", oduInterfaceBldr.getName());
318 return oduInterfaceBldr.getName();