2 * Copyright © 2017 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
9 package org.opendaylight.transportpce.renderer.openroadminterface;
11 import java.math.BigDecimal;
12 import java.util.ArrayList;
13 import java.util.List;
14 import java.util.Optional;
15 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
16 import org.opendaylight.transportpce.common.StringConstants;
17 import org.opendaylight.transportpce.common.Timeouts;
18 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
19 import org.opendaylight.transportpce.common.fixedflex.FixedFlexInterface;
20 import org.opendaylight.transportpce.common.fixedflex.FlexGridInterface;
21 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
22 import org.opendaylight.transportpce.common.mapping.PortMapping;
23 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
24 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.nodes.Mapping;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyGHz;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyTHz;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.ModulationFormat;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.PowerDBm;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.R100G;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.InterfaceBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.InterfaceKey;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.OrgOpenroadmDevice;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.OduConnection;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.OduConnectionKey;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.RoadmConnections;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.RoadmConnectionsKey;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev171215.AdminStates;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev181019.EthAttributes;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev181019.Interface1Builder;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev181019.ethernet.container.EthernetBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.EthernetCsmacd;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.InterfaceType;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.MediaChannelTrailTerminationPoint;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.NetworkMediaChannelConnectionTerminationPoint;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OpenROADMOpticalMultiplex;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OpticalChannel;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OpticalTransport;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OtnOdu;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OtnOtu;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.media.channel.interfaces.rev181019.mc.ttp.container.McTtpBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.media.channel.interfaces.rev181019.nmc.ctp.container.NmcCtpBuilder;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev181019.och.container.OchBuilder;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev181019.OtsAttributes;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev181019.ots.container.OtsBuilder;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODU4;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.ODUTTP;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.OTU4;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev171215.PayloadTypeDef;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.OduAttributes;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.odu.container.OduBuilder;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.opu.OpuBuilder;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev181019.OtuAttributes;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev181019.otu.container.OtuBuilder;
65 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
66 import org.opendaylight.yangtools.yang.common.Uint32;
67 import org.slf4j.Logger;
68 import org.slf4j.LoggerFactory;
71 public class OpenRoadmInterface221 {
72 private static final String MAPPING_ERROR_EXCEPTION_MESSAGE =
73 "Unable to get mapping from PortMapping for node % and logical connection port %s";
74 private final PortMapping portMapping;
75 private final OpenRoadmInterfaces openRoadmInterfaces;
76 private FixedFlexInterface fixedFlex;
77 private FlexGridInterface flexGrid;
78 private static final Logger LOG = LoggerFactory.getLogger(OpenRoadmInterface221.class);
81 public OpenRoadmInterface221(PortMapping portMapping, OpenRoadmInterfaces openRoadmInterfaces,
82 FixedFlexInterface fixedFlex, FlexGridInterface flexGrid) {
83 this.portMapping = portMapping;
84 this.openRoadmInterfaces = openRoadmInterfaces;
85 this.fixedFlex = fixedFlex;
86 this.flexGrid = flexGrid;
89 public String createOpenRoadmEthInterface(String nodeId, String logicalConnPoint)
90 throws OpenRoadmInterfaceException {
91 Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
92 if (portMap == null) {
93 throw new OpenRoadmInterfaceException(
94 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
97 // Ethernet interface specific data
98 EthernetBuilder ethIfBuilder = new EthernetBuilder()
99 .setFec(EthAttributes.Fec.Off)
100 .setSpeed(Uint32.valueOf(100000));
102 InterfaceBuilder ethInterfaceBldr = createGenericInterfaceBuilder(portMap, EthernetCsmacd.class,
103 logicalConnPoint + "-ETHERNET");
104 // Create Interface1 type object required for adding as augmentation
105 Interface1Builder ethIf1Builder = new Interface1Builder();
106 ethInterfaceBldr.addAugmentation(ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
108 // Post interface on the device
109 openRoadmInterfaces.postInterface(nodeId, ethInterfaceBldr);
111 // Post the equipment-state change on the device circuit-pack
112 openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
114 return ethInterfaceBldr.getName();
117 public List<String> createFlexOCH(String nodeId, String logicalConnPoint, BigDecimal centerFreq,
118 BigDecimal width, int lowerSpectralSlotNumber, int higherSpectralSlotNumber)
119 throws OpenRoadmInterfaceException {
120 Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
121 if (portMap == null) {
122 throw new OpenRoadmInterfaceException(
123 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
126 List<String> interfacesCreated = new ArrayList<>();
128 if (logicalConnPoint.contains("DEG")) {
129 String mcInterfaceCreated = createMCInterface(nodeId, logicalConnPoint, centerFreq, width,
130 lowerSpectralSlotNumber, higherSpectralSlotNumber);
131 interfacesCreated.add(mcInterfaceCreated);
133 String mcInterfaceCreated = createNMCInterface(nodeId, logicalConnPoint, centerFreq, width,
134 lowerSpectralSlotNumber, higherSpectralSlotNumber);
135 interfacesCreated.add(mcInterfaceCreated);
136 return interfacesCreated;
140 * This methods creates an OCH interface on the given termination point on
143 * @param nodeId node ID
144 * @param logicalConnPoint logical connection point
145 * @param waveNumber wavelength number of the OCH interface.
146 * @param lowerSpectralSlotNumber int
147 * @param higherSpectralSlotNumber int
148 * @return Name of the interface if successful, otherwise return null.
150 * @throws OpenRoadmInterfaceException OpenRoadm interface exception
153 public List<String> createFlexOCH(String nodeId, String logicalConnPoint, Long waveNumber,
154 int lowerSpectralSlotNumber, int higherSpectralSlotNumber)
155 throws OpenRoadmInterfaceException {
156 Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
157 if (portMap == null) {
158 throw new OpenRoadmInterfaceException(
159 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
162 List<String> interfacesCreated = new ArrayList<>();
164 if (logicalConnPoint.contains("DEG")) {
165 String mcInterfaceCreated = createMCInterface(nodeId, logicalConnPoint, waveNumber,
166 lowerSpectralSlotNumber, higherSpectralSlotNumber);
167 interfacesCreated.add(mcInterfaceCreated);
169 String nmcInterfaceCreated = createNMCInterface(nodeId, logicalConnPoint, waveNumber,
170 lowerSpectralSlotNumber, higherSpectralSlotNumber);
171 interfacesCreated.add(nmcInterfaceCreated);
172 return interfacesCreated;
176 public String createMCInterface(String nodeId, String logicalConnPoint, Long waveNumber,
177 int lowerSpectralSlotNumber, int higherSpectralSlotNumber)
178 throws OpenRoadmInterfaceException {
180 // TODO : Check this method
182 fixedFlex = fixedFlex.getFixedFlexWaveMapping(waveNumber.shortValue());
184 Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
185 if (portMap == null) {
186 throw new OpenRoadmInterfaceException(
187 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
190 // TODO : Check this method
191 String spectralSlotName = String.join(GridConstant.SPECTRAL_SLOT_SEPARATOR,
192 String.valueOf(lowerSpectralSlotNumber),
193 String.valueOf(higherSpectralSlotNumber));
194 InterfaceBuilder mcInterfaceBldr = createGenericInterfaceBuilder(portMap,
195 MediaChannelTrailTerminationPoint.class, String.join(GridConstant.NAME_PARAMETERS_SEPARATOR,
196 logicalConnPoint,"mc",
198 .setSupportingInterface(portMap.getSupportingOms());
200 McTtpBuilder mcTtpBuilder = new McTtpBuilder()
201 .setMinFreq(FrequencyTHz.getDefaultInstance(String.valueOf(fixedFlex.getStart())))
202 .setMaxFreq(FrequencyTHz.getDefaultInstance(String.valueOf(fixedFlex.getStop())));
204 // Create Interface1 type object required for adding as augmentation
205 org.opendaylight.yang.gen.v1.http.org.openroadm.media.channel.interfaces.rev181019.Interface1Builder
207 new org.opendaylight.yang.gen.v1.http.org.openroadm.media.channel.interfaces.rev181019.Interface1Builder()
208 .setMcTtp(mcTtpBuilder.build());
210 mcInterfaceBldr.addAugmentation(interface1Builder.build());
212 // Post interface on the device
213 openRoadmInterfaces.postInterface(nodeId, mcInterfaceBldr);
214 return mcInterfaceBldr.getName();
217 public String createMCInterface(String nodeId, String logicalConnPoint,
218 BigDecimal centerFrequency, BigDecimal width, int lowerSpectralSlotNumber, int higherSpectralSlotNumber)
219 throws OpenRoadmInterfaceException {
221 // TODO : Check this method
222 flexGrid = flexGrid.getFlexWaveMapping(centerFrequency.floatValue(),
223 GridConstant.WIDTH_SLOT_WIDTH_MAP.get(width).floatValue());
225 Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
226 if (portMap == null) {
227 throw new OpenRoadmInterfaceException(
228 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
230 String spectralSlotName = String.join(GridConstant.SPECTRAL_SLOT_SEPARATOR,
231 String.valueOf(lowerSpectralSlotNumber),
232 String.valueOf(higherSpectralSlotNumber));
233 // TODO : Check this method
234 LOG.info("MC interface Freq Start {} and Freq End {} and center-Freq {}",
235 flexGrid.getStart(), flexGrid.getStop(), centerFrequency);
236 InterfaceBuilder mcInterfaceBldr = createGenericInterfaceBuilder(portMap,
237 MediaChannelTrailTerminationPoint.class, String.join(GridConstant.NAME_PARAMETERS_SEPARATOR,
238 logicalConnPoint, "mc", spectralSlotName))
239 .setSupportingInterface(portMap.getSupportingOms());
241 McTtpBuilder mcTtpBuilder = new McTtpBuilder()
242 .setMinFreq(FrequencyTHz.getDefaultInstance(String.valueOf(flexGrid.getStart())))
243 .setMaxFreq(FrequencyTHz.getDefaultInstance(String.valueOf(flexGrid.getStop())));
245 // Create Interface1 type object required for adding as augmentation
246 org.opendaylight.yang.gen.v1.http.org.openroadm.media.channel.interfaces.rev181019.Interface1Builder
248 new org.opendaylight.yang.gen.v1.http.org.openroadm.media.channel.interfaces.rev181019.Interface1Builder()
249 .setMcTtp(mcTtpBuilder.build());
251 mcInterfaceBldr.addAugmentation(interface1Builder.build());
253 // Post interface on the device
254 openRoadmInterfaces.postInterface(nodeId, mcInterfaceBldr);
255 return mcInterfaceBldr.getName();
258 public String createNMCInterface(String nodeId, String logicalConnPoint, Long waveNumber,
259 int lowerSpectralSlotNumber, int higherSpectralSlotNumber)
260 throws OpenRoadmInterfaceException {
262 // TODO : Check this method
263 fixedFlex = fixedFlex.getFixedFlexWaveMapping(waveNumber.shortValue());
265 Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
266 if (portMap == null) {
267 throw new OpenRoadmInterfaceException(
268 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
270 String spectralSlotName = String.join(GridConstant.SPECTRAL_SLOT_SEPARATOR,
271 String.valueOf(lowerSpectralSlotNumber),
272 String.valueOf(higherSpectralSlotNumber));
273 LOG.info("Freq Start {} and Freq End {} and center-Freq {}",
274 fixedFlex.getStart(), fixedFlex.getStop(), fixedFlex.getCenterFrequency());
275 //TODO : Check this method
276 InterfaceBuilder nmcInterfaceBldr = createGenericInterfaceBuilder(portMap,
277 NetworkMediaChannelConnectionTerminationPoint.class, String.join(GridConstant.NAME_PARAMETERS_SEPARATOR,
278 logicalConnPoint, "nmc", spectralSlotName));
279 if (logicalConnPoint.contains("DEG")) {
280 nmcInterfaceBldr.setSupportingInterface(String.join(GridConstant.NAME_PARAMETERS_SEPARATOR,
281 logicalConnPoint, "mc", spectralSlotName));
284 NmcCtpBuilder nmcCtpIfBuilder = new NmcCtpBuilder()
285 .setFrequency(FrequencyTHz.getDefaultInstance(String.valueOf(fixedFlex.getCenterFrequency())))
286 .setWidth(FrequencyGHz.getDefaultInstance("40"));
288 // Create Interface1 type object required for adding as augmentation
289 org.opendaylight.yang.gen.v1.http.org.openroadm.network.media.channel.interfaces.rev181019.Interface1Builder
291 new org.opendaylight.yang.gen.v1.http.org.openroadm.network.media.channel.interfaces.rev181019
292 .Interface1Builder().setNmcCtp(nmcCtpIfBuilder.build());
293 nmcInterfaceBldr.addAugmentation(nmcCtpI1fBuilder.build());
295 // Post interface on the device
296 openRoadmInterfaces.postInterface(nodeId, nmcInterfaceBldr);
297 return nmcInterfaceBldr.getName();
300 public String createNMCInterface(String nodeId, String logicalConnPoint,
301 BigDecimal centerFrequency, BigDecimal width, int lowerSpectralSlotNumber, int higherSpectralSlotNumber)
302 throws OpenRoadmInterfaceException {
303 LOG.info("This is the central frequency {}", centerFrequency.floatValue());
304 LOG.info("This is the nmc width {}", width.floatValue());
305 // TODO : Check this method
306 Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
307 if (portMap == null) {
308 throw new OpenRoadmInterfaceException(
309 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
311 String spectralSlotName = String.join(GridConstant.SPECTRAL_SLOT_SEPARATOR,
312 String.valueOf(lowerSpectralSlotNumber),
313 String.valueOf(higherSpectralSlotNumber));
314 //TODO : Check this method
315 String nmcName = String.join(GridConstant.NAME_PARAMETERS_SEPARATOR,logicalConnPoint, "nmc",
317 InterfaceBuilder nmcInterfaceBldr = createGenericInterfaceBuilder(portMap,
318 NetworkMediaChannelConnectionTerminationPoint.class, nmcName);
319 if (logicalConnPoint.contains("DEG")) {
320 nmcInterfaceBldr.setSupportingInterface(nmcName);
323 NmcCtpBuilder nmcCtpIfBuilder = new NmcCtpBuilder()
324 .setFrequency(FrequencyTHz.getDefaultInstance(String.valueOf(centerFrequency)))
325 .setWidth(new FrequencyGHz(width));
327 // Create Interface1 type object required for adding as augmentation
328 org.opendaylight.yang.gen.v1.http.org.openroadm.network.media.channel.interfaces.rev181019.Interface1Builder
330 new org.opendaylight.yang.gen.v1.http.org.openroadm.network.media.channel.interfaces.rev181019
331 .Interface1Builder().setNmcCtp(nmcCtpIfBuilder.build());
332 nmcInterfaceBldr.addAugmentation(nmcCtpI1fBuilder.build());
333 // Post interface on the device
334 openRoadmInterfaces.postInterface(nodeId, nmcInterfaceBldr);
335 return nmcInterfaceBldr.getName();
338 public String createOpenRoadmOchInterface(String nodeId, String logicalConnPoint, Long waveNumber,
339 int lowerSpectralSlotNumber, int higherSpectralSlotNumber)
340 throws OpenRoadmInterfaceException {
341 // TODO : Check this method
343 fixedFlex = fixedFlex.getFixedFlexWaveMapping(waveNumber.shortValue());
345 Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
346 if (portMap == null) {
347 throw new OpenRoadmInterfaceException(
348 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
351 // OCH interface specific data
352 OchBuilder ocIfBuilder = new OchBuilder()
353 .setFrequency(FrequencyTHz.getDefaultInstance(String.valueOf(fixedFlex.getCenterFrequency())))
354 .setRate(R100G.class)
355 // TODO: Check if this the correct way to set modulation format here
356 .setModulationFormat(ModulationFormat.DpQpsk)
357 .setTransmitPower(new PowerDBm(new BigDecimal("-5")));
358 String spectralSlotName = String.join(GridConstant.SPECTRAL_SLOT_SEPARATOR,
359 String.valueOf(lowerSpectralSlotNumber),
360 String.valueOf(higherSpectralSlotNumber));
361 // Create generic interface
362 InterfaceBuilder ochInterfaceBldr = createGenericInterfaceBuilder(portMap, OpticalChannel.class,
363 createOpenRoadmOchInterfaceName(logicalConnPoint, spectralSlotName));
364 // Create Interface1 type object required for adding as augmentation
365 // TODO look at imports of different versions of class
366 org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev181019.Interface1Builder
367 ochIf1Builder = new org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev181019
368 .Interface1Builder();
369 ochInterfaceBldr.addAugmentation(ochIf1Builder.setOch(ocIfBuilder.build()).build());
371 // Post interface on the device
372 openRoadmInterfaces.postInterface(nodeId, ochInterfaceBldr);
374 // Post the equipment-state change on the device circuit-pack if xpdr node
375 if (portMap.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
376 this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
379 return ochInterfaceBldr.getName();
382 public String createOpenRoadmOchInterface(String nodeId, String logicalConnPoint,
383 BigDecimal centerFrequency, int lowerSpectralSlotNumber, int higherSpectralSlotNumber, String format)
384 throws OpenRoadmInterfaceException {
385 // TODO : Check this method
386 if (centerFrequency == null) {
387 LOG.error("Center frequency cannot be null");
388 throw new OpenRoadmInterfaceException("Center frequency cannot be null");
390 ModulationFormat modulationFormat = ModulationFormat.DpQpsk;
391 Optional<ModulationFormat> optionalModulationFormat = ModulationFormat.forName(format);
392 if (optionalModulationFormat.isPresent()) {
393 modulationFormat = optionalModulationFormat.get();
395 // OCH interface specific data
396 OchBuilder ocIfBuilder = new OchBuilder()
397 .setFrequency(FrequencyTHz.getDefaultInstance(String.valueOf(centerFrequency)))
398 .setRate(R100G.class)
399 .setTransmitPower(new PowerDBm(new BigDecimal("-5")))
400 .setModulationFormat(modulationFormat);
401 Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
402 if (portMap == null) {
403 throw new OpenRoadmInterfaceException(
404 String.format("Unable to get mapping from PortMapping for node %s and logical connection port %s",
405 nodeId, logicalConnPoint));
407 String spectralSlotName = String.join(GridConstant.SPECTRAL_SLOT_SEPARATOR,
408 String.valueOf(lowerSpectralSlotNumber),
409 String.valueOf(higherSpectralSlotNumber));
410 // Create generic interface
411 InterfaceBuilder ochInterfaceBldr = createGenericInterfaceBuilder(portMap, OpticalChannel.class,
412 createOpenRoadmOchInterfaceName(logicalConnPoint, spectralSlotName));
413 // Create Interface1 type object required for adding as augmentation
414 // TODO look at imports of different versions of class
415 org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev181019.Interface1Builder
416 ochIf1Builder = new org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev181019
417 .Interface1Builder();
418 ochInterfaceBldr.addAugmentation(ochIf1Builder.setOch(ocIfBuilder.build()).build());
420 // Post interface on the device
421 openRoadmInterfaces.postInterface(nodeId, ochInterfaceBldr);
423 // Post the equipment-state change on the device circuit-pack if xpdr node
424 if (portMap.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN)) {
425 this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
428 return ochInterfaceBldr.getName();
431 public String createOpenRoadmOdu4Interface(String nodeId, String logicalConnPoint, String supportingOtuInterface)
432 throws OpenRoadmInterfaceException {
433 Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
434 if (portMap == null) {
435 throw new OpenRoadmInterfaceException(
436 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE,
437 nodeId, logicalConnPoint));
439 InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(portMap, OtnOdu.class,
440 logicalConnPoint + "-ODU");
441 oduInterfaceBldr.setSupportingInterface(supportingOtuInterface);
443 // ODU interface specific data
444 // Set Opu attributes
445 OpuBuilder opuBldr = new OpuBuilder()
446 .setPayloadType(PayloadTypeDef.getDefaultInstance("07"))
447 .setExpPayloadType(PayloadTypeDef.getDefaultInstance("07"));
448 OduBuilder oduIfBuilder = new OduBuilder()
450 .setMonitoringMode(OduAttributes.MonitoringMode.Terminated)
451 .setOpu(opuBldr.build());
453 // Create Interface1 type object required for adding as augmentation
454 // TODO look at imports of different versions of class
455 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder oduIf1Builder =
456 new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
457 oduInterfaceBldr.addAugmentation(oduIf1Builder.setOdu(oduIfBuilder.build()).build());
459 // Post interface on the device
460 openRoadmInterfaces.postInterface(nodeId, oduInterfaceBldr);
461 return oduInterfaceBldr.getName();
464 public String createOpenRoadmOdu4Interface(String anodeId, String alogicalConnPoint, String supportingOtuInterface,
465 String znodeId, String zlogicalConnPoint)
466 throws OpenRoadmInterfaceException {
467 Mapping portMapA = portMapping.getMapping(anodeId, alogicalConnPoint);
468 Mapping portMapZ = portMapping.getMapping(znodeId, zlogicalConnPoint);
469 if (portMapA == null) {
470 throw new OpenRoadmInterfaceException(
471 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, anodeId, alogicalConnPoint));
473 if (portMapZ == null) {
474 throw new OpenRoadmInterfaceException(
475 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, znodeId, zlogicalConnPoint));
477 InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(portMapA, OtnOdu.class,
478 alogicalConnPoint + "-ODU");
479 oduInterfaceBldr.setSupportingInterface(supportingOtuInterface);
481 // ODU interface specific data
482 // Set Opu attributes
483 OpuBuilder opuBldr = new OpuBuilder()
484 .setPayloadType(PayloadTypeDef.getDefaultInstance("07"))
485 .setExpPayloadType(PayloadTypeDef.getDefaultInstance("07"));
486 OduBuilder oduIfBuilder = new OduBuilder()
488 .setMonitoringMode(OduAttributes.MonitoringMode.Terminated)
489 .setOpu(opuBldr.build())
490 .setTxSapi(portMapA.getLcpHashVal())
491 .setTxDapi(portMapZ.getLcpHashVal())
492 // Setting the expected Dapi and Sapi values
493 .setExpectedDapi(portMapA.getLcpHashVal())
494 .setExpectedSapi(portMapZ.getLcpHashVal());
496 // Create Interface1 type object required for adding as augmentation
497 // TODO look at imports of different versions of class
498 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder oduIf1Builder =
499 new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
500 oduInterfaceBldr.addAugmentation(oduIf1Builder.setOdu(oduIfBuilder.build()).build());
502 // Post interface on the device
503 openRoadmInterfaces.postInterface(anodeId, oduInterfaceBldr);
504 return oduInterfaceBldr.getName();
507 public String createOpenRoadmOtu4Interface(String nodeId, String logicalConnPoint, String supportOchInterface)
508 throws OpenRoadmInterfaceException {
509 Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
510 if (portMap == null) {
511 throw new OpenRoadmInterfaceException(
512 String.format("Unable to get mapping from PortMapping for node %s and logical connection port %s",
513 nodeId, logicalConnPoint));
515 // Create generic interface
516 InterfaceBuilder otuInterfaceBldr = createGenericInterfaceBuilder(portMap, OtnOtu.class,
517 logicalConnPoint + "-OTU");
518 otuInterfaceBldr.setSupportingInterface(supportOchInterface);
520 // OTU interface specific data
521 OtuBuilder otuIfBuilder = new OtuBuilder();
522 otuIfBuilder.setFec(OtuAttributes.Fec.Scfec);
523 otuIfBuilder.setRate(OTU4.class);
525 // Create Interface1 type object required for adding as augmentation
526 // TODO look at imports of different versions of class
527 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev181019.Interface1Builder otuIf1Builder =
528 new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev181019.Interface1Builder();
529 otuInterfaceBldr.addAugmentation(otuIf1Builder.setOtu(otuIfBuilder.build()).build());
531 // Post interface on the device
532 openRoadmInterfaces.postInterface(nodeId, otuInterfaceBldr);
533 return otuInterfaceBldr.getName();
536 public String createOpenRoadmOtu4Interface(String anodeId, String alogicalConnPoint, String asupportOchInterface,
537 String znodeId, String zlogicalConnPoint)
538 throws OpenRoadmInterfaceException {
539 Mapping portMapA = portMapping.getMapping(anodeId, alogicalConnPoint);
540 Mapping portMapZ = portMapping.getMapping(znodeId, zlogicalConnPoint);
541 if (portMapA == null) {
542 throw new OpenRoadmInterfaceException(
543 String.format("Unable to get mapping from PortMapping for node %s and logical connection port %s ",
544 anodeId, alogicalConnPoint));
547 if (portMapZ == null) {
548 throw new OpenRoadmInterfaceException(
549 String.format("Unable to get mapping from PortMapping for node %s and logical connection port %s ",
550 znodeId, zlogicalConnPoint));
553 // Create generic interface builder
554 InterfaceBuilder otuInterfaceBldr = createGenericInterfaceBuilder(portMapA, OtnOtu.class,
555 alogicalConnPoint + "-OTU");
557 // Set the supporting interface data
558 otuInterfaceBldr.setSupportingInterface(asupportOchInterface);
560 // OTU interface specific data
561 OtuBuilder otuIfBuilder = new OtuBuilder()
562 .setFec(OtuAttributes.Fec.Scfec)
564 .setTxSapi(portMapA.getLcpHashVal())
565 .setTxDapi(portMapZ.getLcpHashVal())
566 // setting expected SAPI and DAPI values
567 .setExpectedDapi(portMapA.getLcpHashVal())
568 .setExpectedSapi(portMapZ.getLcpHashVal());
570 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev181019.Interface1Builder otuIf1Builder =
571 new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev181019.Interface1Builder();
573 otuInterfaceBldr.addAugmentation(otuIf1Builder.setOtu(otuIfBuilder.build()).build());
575 // Post interface on the device
576 openRoadmInterfaces.postInterface(anodeId, otuInterfaceBldr);
577 return otuInterfaceBldr.getName();
581 public String createOpenRoadmOchInterfaceName(String logicalConnectionPoint, String spectralSlotName) {
582 return String.join(GridConstant.NAME_PARAMETERS_SEPARATOR,logicalConnectionPoint, spectralSlotName);
585 private InterfaceBuilder createGenericInterfaceBuilder(Mapping portMap, Class<? extends InterfaceType> type,
587 return new InterfaceBuilder()
588 .setDescription(" TBD ")
589 .setCircuitId(" TBD ")
590 .setSupportingCircuitPackName(portMap.getSupportingCircuitPackName())
591 .setSupportingPort(portMap.getSupportingPort())
592 .setAdministrativeState(AdminStates.InService)
595 .withKey(new InterfaceKey(key));
598 public String createOpenRoadmOmsInterface(String nodeId, Mapping mapping) throws OpenRoadmInterfaceException {
599 if (mapping.getSupportingOms() == null) {
600 // Create generic interface
601 InterfaceBuilder omsInterfaceBldr = createGenericInterfaceBuilder(mapping, OpenROADMOpticalMultiplex.class,
602 "OMS-" + mapping.getLogicalConnectionPoint());
603 if (mapping.getSupportingOts() != null) {
604 omsInterfaceBldr.setSupportingInterface(mapping.getSupportingOts());
606 LOG.error("Unable to get ots interface from mapping {} - {}", nodeId,
607 mapping.getLogicalConnectionPoint());
610 this.openRoadmInterfaces.postInterface(nodeId, omsInterfaceBldr);
611 this.portMapping.updateMapping(nodeId, mapping);
612 return omsInterfaceBldr.build().getName();
614 return mapping.getSupportingOms();
618 public String createOpenRoadmOtsInterface(String nodeId, Mapping mapping) throws OpenRoadmInterfaceException {
619 if (mapping.getSupportingOts() == null) {
620 // Create generic interface
621 InterfaceBuilder otsInterfaceBldr = createGenericInterfaceBuilder(mapping, OpticalTransport.class, "OTS-"
622 + mapping.getLogicalConnectionPoint());
623 // OTS interface augmentation specific data
624 OtsBuilder otsIfBuilder = new OtsBuilder();
625 otsIfBuilder.setFiberType(OtsAttributes.FiberType.Smf);
627 // Create Interface1 type object required for adding as
629 org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev181019.Interface1Builder
630 otsIf1Builder = new org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces
631 .rev181019.Interface1Builder();
632 otsInterfaceBldr.addAugmentation(otsIf1Builder.setOts(otsIfBuilder.build()).build());
633 this.openRoadmInterfaces.postInterface(nodeId, otsInterfaceBldr);
634 this.portMapping.updateMapping(nodeId, mapping);
635 return otsInterfaceBldr.build().getName();
637 return mapping.getSupportingOts();
641 public boolean isUsedByXc(String nodeId, String interfaceName, String xc,
642 DeviceTransactionManager deviceTransactionManager) {
643 InstanceIdentifier<RoadmConnections> xciid = InstanceIdentifier.create(OrgOpenroadmDevice.class)
644 .child(RoadmConnections.class, new RoadmConnectionsKey(xc));
645 LOG.info("reading xc {} in node {}", xc, nodeId);
646 Optional<RoadmConnections> crossconnection = deviceTransactionManager.getDataFromDevice(nodeId,
647 LogicalDatastoreType.CONFIGURATION, xciid, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
648 if (crossconnection.isPresent()) {
649 RoadmConnections rc = crossconnection.get();
650 LOG.info("xd {} found", xc);
651 String supportedinter = null;
652 if (!interfaceName.contains("nmc")) {
653 supportedinter = interfaceName.replace("mc", "nmc");
655 if (rc.getSource().getSrcIf().equals(interfaceName)
656 || rc.getDestination().getDstIf().equals(interfaceName)
657 || rc.getSource().getSrcIf().equals(supportedinter)
658 || rc.getDestination().getDstIf().equals(supportedinter)) {
662 LOG.info("xd {} not found !", xc);
667 public boolean isUsedByOtnXc(String nodeId, String interfaceName, String xc,
668 DeviceTransactionManager deviceTransactionManager) {
669 InstanceIdentifier<OduConnection> xciid = InstanceIdentifier.create(OrgOpenroadmDevice.class)
670 .child(OduConnection.class, new OduConnectionKey(xc));
671 LOG.info("reading xc {} in node {}", xc, nodeId);
672 Optional<OduConnection> oduConnectionOpt = deviceTransactionManager.getDataFromDevice(nodeId,
673 LogicalDatastoreType.CONFIGURATION, xciid, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
674 if (oduConnectionOpt.isPresent()) {
675 OduConnection oduXc = oduConnectionOpt.get();
676 LOG.info("xc {} found", xc);
677 if (oduXc.getSource().getSrcIf().equals(interfaceName)
678 || oduXc.getDestination().getDstIf().equals(interfaceName)) {
682 LOG.info("xc {} not found !", xc);
687 public String createOpenRoadmOtnOdu4Interface(String nodeId, String logicalConnPoint, String supportingOtuInterface)
688 throws OpenRoadmInterfaceException {
689 Mapping portMap = portMapping.getMapping(nodeId, logicalConnPoint);
690 if (portMap == null) {
691 throw new OpenRoadmInterfaceException(
692 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, nodeId, logicalConnPoint));
694 InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(portMap, OtnOdu.class,
695 logicalConnPoint + "-ODU4");
696 oduInterfaceBldr.setSupportingInterface(supportingOtuInterface);
698 // ODU interface specific data
699 OduBuilder oduIfBuilder = new OduBuilder()
701 .setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
703 // Set Opu attributes
704 OpuBuilder opuBldr = new OpuBuilder()
705 .setPayloadType(PayloadTypeDef.getDefaultInstance("21"))
706 .setExpPayloadType(PayloadTypeDef.getDefaultInstance("21"));
707 oduIfBuilder.setOduFunction(ODUTTP.class)
708 .setOpu(opuBldr.build());
710 // Create Interface1 type object required for adding as augmentation
711 // TODO look at imports of different versions of class
712 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder oduIf1Builder =
713 new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
714 oduInterfaceBldr.addAugmentation(oduIf1Builder.setOdu(oduIfBuilder.build()).build());
716 // Post interface on the device
717 openRoadmInterfaces.postInterface(nodeId, oduInterfaceBldr);
720 } catch (InterruptedException e) {
721 LOG.error("Error waiting post interface on device", e);
723 this.portMapping.updateMapping(nodeId, portMap);
724 return oduInterfaceBldr.getName();
727 public String createOpenRoadmOtnOdu4Interface(String anodeId, String alogicalConnPoint,
728 String asupportingOtuInterface, String znodeId, String zlogicalConnPoint)
729 throws OpenRoadmInterfaceException {
730 Mapping portMapA = portMapping.getMapping(anodeId, alogicalConnPoint);
731 if (portMapA == null) {
732 throw new OpenRoadmInterfaceException(
733 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, anodeId, alogicalConnPoint));
735 Mapping portMapZ = portMapping.getMapping(znodeId, zlogicalConnPoint);
736 if (portMapZ == null) {
737 throw new OpenRoadmInterfaceException(
738 String.format(MAPPING_ERROR_EXCEPTION_MESSAGE, znodeId, zlogicalConnPoint));
740 InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(portMapA, OtnOdu.class,
741 alogicalConnPoint + "-ODU4");
742 oduInterfaceBldr.setSupportingInterface(asupportingOtuInterface);
744 // ODU interface specific data
745 OduBuilder oduIfBuilder = new OduBuilder()
747 .setMonitoringMode(OduAttributes.MonitoringMode.Terminated)
748 .setTxSapi(portMapA.getLcpHashVal())
749 .setTxDapi(portMapZ.getLcpHashVal())
750 .setExpectedSapi(portMapZ.getLcpHashVal())
751 .setExpectedDapi(portMapA.getLcpHashVal());
754 // Set Opu attributes
755 OpuBuilder opuBldr = new OpuBuilder()
756 .setPayloadType(PayloadTypeDef.getDefaultInstance("21"))
757 .setExpPayloadType(PayloadTypeDef.getDefaultInstance("21"));
758 oduIfBuilder.setOduFunction(ODUTTP.class)
759 .setOpu(opuBldr.build());
761 // Create Interface1 type object required for adding as augmentation
762 // TODO look at imports of different versions of class
763 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder oduIf1Builder =
764 new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev181019.Interface1Builder();
765 oduInterfaceBldr.addAugmentation(oduIf1Builder.setOdu(oduIfBuilder.build()).build());
767 // Post interface on the device
768 openRoadmInterfaces.postInterface(anodeId, oduInterfaceBldr);
771 } catch (InterruptedException e) {
772 LOG.error("Error waiting post interface on device", e);
774 this.portMapping.updateMapping(anodeId, portMapA);
775 return oduInterfaceBldr.getName();