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.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.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.opendaylight.yangtools.yang.common.Uint16;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 public class OpenRoadmOtnInterface221 {
44 private final PortMapping portMapping;
45 private final OpenRoadmInterfaces openRoadmInterfaces;
46 private static final Logger LOG = LoggerFactory
47 .getLogger(OpenRoadmOtnInterface221.class);
49 public OpenRoadmOtnInterface221(PortMapping portMapping,
50 OpenRoadmInterfaces openRoadmInterfaces) {
51 this.portMapping = portMapping;
52 this.openRoadmInterfaces = openRoadmInterfaces;
55 public String createOpenRoadmEth1GInterface(String nodeId,
56 String logicalConnPoint) throws OpenRoadmInterfaceException {
57 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
58 if (portMap == null) {
59 throwException(nodeId, logicalConnPoint);
62 // Ethernet interface specific data
63 EthernetBuilder ethIfBuilder = new EthernetBuilder();
64 ethIfBuilder.setSpeed(1000L);
65 InterfaceBuilder ethInterfaceBldr = createGenericInterfaceBuilder(
66 portMap, EthernetCsmacd.class,
67 logicalConnPoint + "-ETHERNET1G");
68 // Create Interface1 type object required for adding as augmentation
69 Interface1Builder ethIf1Builder = new Interface1Builder();
70 ethInterfaceBldr.addAugmentation(Interface1.class,
71 ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
72 // Post interface on the device
73 this.openRoadmInterfaces.postOTNInterface(nodeId, ethInterfaceBldr);
74 // Post the equipment-state change on the device circuit-pack
75 this.openRoadmInterfaces.postOTNEquipmentState(nodeId,
76 portMap.getSupportingCircuitPackName(), true);
77 this.portMapping.updateMapping(nodeId, portMap);
78 String ethernetInterfaceName = ethInterfaceBldr.getName();
80 return ethernetInterfaceName;
83 private void throwException(String nodeId, String logicalConnPoint)
84 throws OpenRoadmInterfaceException {
85 throw new OpenRoadmInterfaceException(String.format(
86 "Unable to get mapping from PortMapping for node % and logical connection port %s",
87 nodeId, logicalConnPoint));
90 private InterfaceBuilder createGenericInterfaceBuilder(Mapping portMap,
91 Class<? extends InterfaceType> type, String key) {
92 InterfaceBuilder interfaceBuilder = new InterfaceBuilder()
93 // .setDescription(" TBD ")
94 // .setCircuitId(" TBD ")
95 .setSupportingCircuitPackName(
96 portMap.getSupportingCircuitPackName())
97 .setSupportingPort(portMap.getSupportingPort())
98 .setAdministrativeState(AdminStates.InService)
99 // TODO get rid of unchecked cast warning
100 .setType(type).setName(key).withKey(new InterfaceKey(key));
101 return interfaceBuilder;
104 public String createOpenRoadmEth10GInterface(String nodeId,
105 String logicalConnPoint) throws OpenRoadmInterfaceException {
106 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
107 if (portMap == null) {
108 throwException(nodeId, logicalConnPoint);
111 // Ethernet interface specific data
112 EthernetBuilder ethIfBuilder = new EthernetBuilder()
113 // .setAutoNegotiation(EthAttributes.AutoNegotiation.Disabled)
115 // Create Interface1 type object required for adding as augmentation
116 Interface1Builder ethIf1Builder = new Interface1Builder();
117 InterfaceBuilder ethInterfaceBldr = createGenericInterfaceBuilder(portMap, EthernetCsmacd.class,
118 logicalConnPoint + "-ETHERNET10G").addAugmentation(Interface1.class,
119 ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
120 // Post interface on the device
121 this.openRoadmInterfaces.postOTNInterface(nodeId, ethInterfaceBldr);
122 // Post the equipment-state change on the device circuit-pack
123 this.openRoadmInterfaces.postOTNEquipmentState(nodeId,
124 portMap.getSupportingCircuitPackName(), true);
125 this.portMapping.updateMapping(nodeId, portMap);
126 String ethernetInterfaceName = ethInterfaceBldr.getName();
128 return ethernetInterfaceName;
131 public String createOpenRoadmOdu2eInterface(String nodeId,
132 String logicalConnPoint, String serviceName, String payLoad,
133 boolean isNetworkPort, int tribPortNumber, int tribSlotIndex)
134 throws OpenRoadmInterfaceException {
135 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
136 if (portMap == null) {
137 throwException(nodeId, logicalConnPoint);
139 String supportingInterface = null;
142 supportingInterface = portMap.getSupportingOdu4();
144 supportingInterface = logicalConnPoint + "-ETHERNET10G";
147 if (supportingInterface == null) {
148 throw new OpenRoadmInterfaceException(
149 "Interface Creation failed because of missing supported "
150 + "ODU4 on network end or Eth iface on client");
153 InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(
154 portMap, OtnOdu.class,
155 logicalConnPoint + "-ODU2e-" + serviceName)
156 .setSupportingInterface(supportingInterface);
158 // ODU interface specific data
159 OduBuilder oduIfBuilder = new OduBuilder().setRate(ODU2e.class)
160 .setOduFunction(ODUTTPCTP.class)
161 .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
162 LOG.debug("Inside the ODU2e creation {} {} {}", isNetworkPort,
163 tribPortNumber, tribSlotIndex);
165 List<Uint16> tribSlots = new ArrayList<>();
166 Uint16 newIdx = Uint16.valueOf(tribSlotIndex);
167 tribSlots.add(newIdx);
168 IntStream.range(tribSlotIndex, tribSlotIndex + 8)
169 .forEach(nbr -> tribSlots.add(Uint16.valueOf(nbr)));
170 ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
171 .setTribPortNumber(tribPortNumber).setTribSlots(tribSlots);
172 oduIfBuilder.setOduFunction(ODUCTP.class)
173 .setMonitoringMode(OduAttributes.MonitoringMode.Monitored)
174 .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
186 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
187 oduInterfaceBldr.addAugmentation(
188 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1.class,
189 oduIf1Builder.setOdu(oduIfBuilder.build()).build());
191 // Post interface on the device
192 this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
193 LOG.info("returning the ODU2e inteface {}", oduInterfaceBldr.getName());
194 return oduInterfaceBldr.getName();
197 public String createOpenRoadmOdu0Interface(String nodeId,
198 String logicalConnPoint, String serviceName, String payLoad,
199 boolean isNetworkPort, int tribPortNumber, int tribSlot)
200 throws OpenRoadmInterfaceException {
201 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
202 String supportingInterface = null;
205 supportingInterface = portMap.getSupportingOdu4();
207 supportingInterface = logicalConnPoint + "-ETHERNET1G";
209 if (portMap == null) {
210 throwException(nodeId, logicalConnPoint);
212 InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(
213 portMap, OtnOdu.class,
214 logicalConnPoint + "-ODU0-" + serviceName);
215 oduInterfaceBldr.setSupportingInterface(supportingInterface);
217 // ODU interface specific data
218 OduBuilder oduIfBuilder = new OduBuilder().setRate(ODU0.class)
219 .setOduFunction(ODUTTPCTP.class)
220 .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
222 LOG.debug("Network port is true");
223 List<Uint16> tribSlots = new ArrayList<>();
225 tribSlots.add(Uint16.valueOf(tribSlot));
226 ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
227 // set trib port numbers
228 .setTribPortNumber(tribPortNumber).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());
237 LOG.debug("Current port is a client port");
238 OpuBuilder opuBldr = new OpuBuilder()
239 .setPayloadType(new PayloadTypeDef(payLoad))
240 .setExpPayloadType(new PayloadTypeDef(payLoad));
241 oduIfBuilder.setOpu(opuBldr.build());
243 // Create Interface1 type object required for adding as augmentation
244 // TODO look at imports of different versions of class
245 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder
247 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();
258 public String createOpenRoadmOdu2Interface(String nodeId,
259 String logicalConnPoint, String serviceName, String payLoad,
260 boolean isNetworkPort, int tribPortNumber, int tribSlotIndex)
261 throws OpenRoadmInterfaceException {
262 Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
263 String supportingInterface = null;
265 if (portMap != null) {
267 supportingInterface = portMap.getSupportingOdu4();
269 supportingInterface = portMap.getSupportingEthernet();
272 throwException(nodeId, logicalConnPoint);
274 InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(
275 portMap, OtnOdu.class,
276 logicalConnPoint + "-ODU2-" + serviceName)
277 .setSupportingInterface(supportingInterface);
279 OduBuilder oduIfBuilder = new OduBuilder().setRate(ODU2.class)
280 .setOduFunction(ODUTTPCTP.class)
281 .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
283 List<Uint16> tribSlots = new ArrayList<>();
284 IntStream.range(tribSlotIndex, tribSlotIndex + 8)
285 .forEach(nbr -> tribSlots.add(Uint16.valueOf(nbr)));
286 ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
287 // set trib port numbers
288 .setTribPortNumber(tribPortNumber).setTribSlots(tribSlots);
289 oduIfBuilder.setOduFunction(ODUCTP.class)
290 .setMonitoringMode(OduAttributes.MonitoringMode.Monitored)
291 .setParentOduAllocation(parentOduAllocationBuilder.build());
293 // Set Opu attributes
294 OpuBuilder opuBldr = new OpuBuilder()
295 .setPayloadType(new PayloadTypeDef(payLoad))
296 .setExpPayloadType(new PayloadTypeDef(payLoad));
297 oduIfBuilder.setOpu(opuBldr.build());
300 // Create Interface1 type object required for adding as augmentation
301 // TODO look at imports of different versions of class
302 // Create Interface1 type object required for adding as augmentation
303 // TODO look at imports of different versions of class
304 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder
306 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
307 oduInterfaceBldr.addAugmentation(
308 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1.class,
309 oduIf1Builder.setOdu(oduIfBuilder.build()).build());
311 // Post interface on the device
312 this.openRoadmInterfaces.postOTNInterface(nodeId, oduInterfaceBldr);
313 LOG.info("returning the ODU2 inteface {}", oduInterfaceBldr.getName());
314 return oduInterfaceBldr.getName();