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.portmapping.rev200429.network.nodes.Mapping;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.InterfaceBuilder;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.InterfaceKey;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev171215.AdminStates;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev181019.Interface1;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev181019.Interface1Builder;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev181019.ethernet.container.EthernetBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.EthernetCsmacd;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.InterfaceType;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OtnOdu;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODU0;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODU2;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODU2e;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODUCTP;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODUTTPCTP;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.PayloadTypeDef;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.OduAttributes;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.odu.container.OduBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.opu.OpuBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.parent.odu.allocation.ParentOduAllocationBuilder;
36 import org.opendaylight.yangtools.yang.common.Uint16;
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
46 .getLogger(OpenRoadmOtnInterface221.class);
48 public OpenRoadmOtnInterface221(PortMapping portMapping,
49 OpenRoadmInterfaces openRoadmInterfaces) {
50 this.portMapping = portMapping;
51 this.openRoadmInterfaces = openRoadmInterfaces;
54 public String createOpenRoadmEth1GInterface(String nodeId,
55 String logicalConnPoint) throws OpenRoadmInterfaceException {
56 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
57 if (portMap == null) {
58 throwException(nodeId, logicalConnPoint);
61 // Ethernet interface specific data
62 EthernetBuilder ethIfBuilder = new EthernetBuilder();
63 ethIfBuilder.setSpeed(1000L);
64 InterfaceBuilder ethInterfaceBldr = createGenericInterfaceBuilder(
65 portMap, EthernetCsmacd.class,
66 logicalConnPoint + "-ETHERNET1G");
67 // Create Interface1 type object required for adding as augmentation
68 Interface1Builder ethIf1Builder = new Interface1Builder();
69 ethInterfaceBldr.addAugmentation(Interface1.class,
70 ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
71 // Post interface on the device
72 this.openRoadmInterfaces.postOTNInterface(nodeId, ethInterfaceBldr);
73 // Post the equipment-state change on the device circuit-pack
74 this.openRoadmInterfaces.postOTNEquipmentState(nodeId,
75 portMap.getSupportingCircuitPackName(), true);
76 this.portMapping.updateMapping(nodeId, portMap);
77 String ethernetInterfaceName = ethInterfaceBldr.getName();
79 return ethernetInterfaceName;
82 private void throwException(String nodeId, String logicalConnPoint)
83 throws OpenRoadmInterfaceException {
84 throw new OpenRoadmInterfaceException(String.format(
85 "Unable to get mapping from PortMapping for node % and logical connection port %s",
86 nodeId, logicalConnPoint));
89 private InterfaceBuilder createGenericInterfaceBuilder(Mapping portMap,
90 Class<? extends InterfaceType> type, String key) {
91 InterfaceBuilder interfaceBuilder = new InterfaceBuilder()
92 // .setDescription(" TBD ")
93 // .setCircuitId(" TBD ")
94 .setSupportingCircuitPackName(
95 portMap.getSupportingCircuitPackName())
96 .setSupportingPort(portMap.getSupportingPort())
97 .setAdministrativeState(AdminStates.InService)
98 // TODO get rid of unchecked cast warning
99 .setType(type).setName(key).withKey(new InterfaceKey(key));
100 return interfaceBuilder;
103 public String createOpenRoadmEth10GInterface(String nodeId,
104 String logicalConnPoint) throws OpenRoadmInterfaceException {
105 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
106 if (portMap == null) {
107 throwException(nodeId, logicalConnPoint);
110 // Ethernet interface specific data
111 EthernetBuilder ethIfBuilder = new EthernetBuilder()
112 // .setAutoNegotiation(EthAttributes.AutoNegotiation.Disabled)
114 // Create Interface1 type object required for adding as augmentation
115 Interface1Builder ethIf1Builder = new Interface1Builder();
116 InterfaceBuilder ethInterfaceBldr = createGenericInterfaceBuilder(portMap, EthernetCsmacd.class,
117 logicalConnPoint + "-ETHERNET10G").addAugmentation(Interface1.class,
118 ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
119 // Post interface on the device
120 this.openRoadmInterfaces.postOTNInterface(nodeId, ethInterfaceBldr);
121 // Post the equipment-state change on the device circuit-pack
122 this.openRoadmInterfaces.postOTNEquipmentState(nodeId,
123 portMap.getSupportingCircuitPackName(), true);
124 this.portMapping.updateMapping(nodeId, portMap);
125 String ethernetInterfaceName = ethInterfaceBldr.getName();
127 return ethernetInterfaceName;
130 public String createOpenRoadmOdu2eInterface(String nodeId,
131 String logicalConnPoint, String serviceName, String payLoad,
132 boolean isNetworkPort, int tribPortNumber, int tribSlotIndex)
133 throws OpenRoadmInterfaceException {
134 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
135 if (portMap == null) {
136 throwException(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 "
149 + "ODU4 on network end or Eth iface on client");
152 InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(
153 portMap, OtnOdu.class,
154 logicalConnPoint + "-ODU2e-" + serviceName)
155 .setSupportingInterface(supportingInterface);
157 // ODU interface specific data
158 OduBuilder oduIfBuilder = new OduBuilder().setRate(ODU2e.class)
159 .setOduFunction(ODUTTPCTP.class)
160 .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
161 LOG.debug("Inside the ODU2e creation {} {} {}", isNetworkPort,
162 tribPortNumber, tribSlotIndex);
164 List<Uint16> tribSlots = new ArrayList<>();
165 Uint16 newIdx = Uint16.valueOf(tribSlotIndex);
166 tribSlots.add(newIdx);
167 IntStream.range(tribSlotIndex, tribSlotIndex + 8)
168 .forEach(nbr -> tribSlots.add(Uint16.valueOf(nbr)));
169 ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
170 .setTribPortNumber(tribPortNumber).setTribSlots(tribSlots);
171 oduIfBuilder.setOduFunction(ODUCTP.class)
172 .setMonitoringMode(OduAttributes.MonitoringMode.Monitored)
173 .setParentOduAllocation(parentOduAllocationBuilder.build());
175 // Set Opu attributes
176 OpuBuilder opuBldr = new OpuBuilder()
177 .setPayloadType(new PayloadTypeDef(payLoad))
178 .setExpPayloadType(new PayloadTypeDef(payLoad));
179 oduIfBuilder.setOpu(opuBldr.build());
181 // Create Interface1 type object required for adding as augmentation
182 // TODO look at imports of different versions of class
183 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder
185 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,
197 String logicalConnPoint, String serviceName, String payLoad,
198 boolean isNetworkPort, int tribPortNumber, int tribSlot)
199 throws OpenRoadmInterfaceException {
200 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
201 String supportingInterface = null;
204 supportingInterface = portMap.getSupportingOdu4();
206 supportingInterface = logicalConnPoint + "-ETHERNET1G";
208 if (portMap == null) {
209 throwException(nodeId, logicalConnPoint);
211 InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(
212 portMap, OtnOdu.class,
213 logicalConnPoint + "-ODU0-" + serviceName);
214 oduInterfaceBldr.setSupportingInterface(supportingInterface);
216 // ODU interface specific data
217 OduBuilder oduIfBuilder = new OduBuilder().setRate(ODU0.class)
218 .setOduFunction(ODUTTPCTP.class)
219 .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
221 LOG.debug("Network port is true");
222 List<Uint16> tribSlots = new ArrayList<>();
224 tribSlots.add(Uint16.valueOf(tribSlot));
225 ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
226 // set trib port numbers
227 .setTribPortNumber(tribPortNumber).setTribSlots(tribSlots);
228 oduIfBuilder.setOduFunction(ODUCTP.class)
229 .setMonitoringMode(OduAttributes.MonitoringMode.Monitored)
230 .setParentOduAllocation(parentOduAllocationBuilder.build());
231 LOG.debug("Network port is true {} {} {}",
232 oduIfBuilder.getParentOduAllocation().getTribSlots(),
233 oduIfBuilder.getRate(),
234 oduIfBuilder.getParentOduAllocation().getTribPortNumber());
236 LOG.debug("Current port is a client port");
237 OpuBuilder opuBldr = new OpuBuilder()
238 .setPayloadType(new PayloadTypeDef(payLoad))
239 .setExpPayloadType(new PayloadTypeDef(payLoad));
240 oduIfBuilder.setOpu(opuBldr.build());
242 // Create Interface1 type object required for adding as augmentation
243 // TODO look at imports of different versions of class
244 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder
246 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
247 oduInterfaceBldr.addAugmentation(
248 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1.class,
249 oduIf1Builder.setOdu(oduIfBuilder.build()).build());
251 // Post interface on the device
252 this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
253 LOG.info("returning the ODU0 inteface {}", oduInterfaceBldr.getName());
254 return oduInterfaceBldr.getName();
257 public String createOpenRoadmOdu2Interface(String nodeId,
258 String logicalConnPoint, String serviceName, String payLoad,
259 boolean isNetworkPort, int tribPortNumber, int tribSlotIndex)
260 throws OpenRoadmInterfaceException {
261 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
262 String supportingInterface = null;
264 if (portMap != null) {
266 supportingInterface = portMap.getSupportingOdu4();
268 supportingInterface = portMap.getSupportingEthernet();
271 throwException(nodeId, logicalConnPoint);
273 InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(
274 portMap, OtnOdu.class,
275 logicalConnPoint + "-ODU2-" + serviceName)
276 .setSupportingInterface(supportingInterface);
278 OduBuilder oduIfBuilder = new OduBuilder().setRate(ODU2.class)
279 .setOduFunction(ODUTTPCTP.class)
280 .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
282 List<Uint16> tribSlots = new ArrayList<>();
283 IntStream.range(tribSlotIndex, tribSlotIndex + 8)
284 .forEach(nbr -> tribSlots.add(Uint16.valueOf(nbr)));
285 ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
286 // set trib port numbers
287 .setTribPortNumber(tribPortNumber).setTribSlots(tribSlots);
288 oduIfBuilder.setOduFunction(ODUCTP.class)
289 .setMonitoringMode(OduAttributes.MonitoringMode.Monitored)
290 .setParentOduAllocation(parentOduAllocationBuilder.build());
292 // Set Opu attributes
293 OpuBuilder opuBldr = new OpuBuilder()
294 .setPayloadType(new PayloadTypeDef(payLoad))
295 .setExpPayloadType(new PayloadTypeDef(payLoad));
296 oduIfBuilder.setOpu(opuBldr.build());
299 // Create Interface1 type object required for adding as augmentation
300 // TODO look at imports of different versions of class
301 // Create Interface1 type object required for adding as augmentation
302 // TODO look at imports of different versions of class
303 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder
305 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
306 oduInterfaceBldr.addAugmentation(
307 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1.class,
308 oduIf1Builder.setOdu(oduIfBuilder.build()).build());
310 // Post interface on the device
311 this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
312 LOG.info("returning the ODU2 inteface {}", oduInterfaceBldr.getName());
313 return oduInterfaceBldr.getName();