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.olm.service;
11 import com.google.common.base.Strings;
12 import java.math.BigDecimal;
13 import java.math.RoundingMode;
14 import java.util.ArrayList;
15 import java.util.Collections;
16 import java.util.HashMap;
17 import java.util.List;
19 import java.util.Map.Entry;
20 import java.util.Optional;
22 import java.util.concurrent.ExecutionException;
23 import java.util.concurrent.TimeUnit;
24 import java.util.concurrent.TimeoutException;
25 import java.util.stream.Collectors;
26 import org.eclipse.jdt.annotation.Nullable;
27 import org.opendaylight.mdsal.binding.api.DataBroker;
28 import org.opendaylight.mdsal.binding.api.ReadTransaction;
29 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
30 import org.opendaylight.transportpce.common.InstanceIdentifiers;
31 import org.opendaylight.transportpce.common.NetworkUtils;
32 import org.opendaylight.transportpce.common.ResponseCodes;
33 import org.opendaylight.transportpce.common.StringConstants;
34 import org.opendaylight.transportpce.common.Timeouts;
35 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
36 import org.opendaylight.transportpce.common.mapping.MappingUtils;
37 import org.opendaylight.transportpce.common.mapping.PortMapping;
38 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
39 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
40 import org.opendaylight.transportpce.olm.power.PowerMgmt;
41 import org.opendaylight.transportpce.olm.util.OlmUtils;
42 import org.opendaylight.transportpce.olm.util.OtsPmHolder;
43 import org.opendaylight.transportpce.olm.util.RoadmLinks;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseInput;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseOutput;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseOutputBuilder;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentInput;
48 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentOutput;
49 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentOutputBuilder;
50 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInput;
51 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInputBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutput;
53 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutputBuilder;
54 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetInput;
55 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetOutput;
56 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
57 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutput;
58 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutputBuilder;
59 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInput;
60 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutput;
61 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutputBuilder;
62 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.calculate.spanloss.base.output.Spans;
63 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.calculate.spanloss.base.output.SpansBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.get.pm.output.Measurements;
65 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.OpenroadmNodeVersion;
66 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.mapping.Mapping;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RatioDB;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceBuilder;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmLinkType;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.Interface1;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.Interface1Builder;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.ots.container.Ots;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.ots.container.OtsBuilder;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmGranularity;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev161014.ResourceTypeEnum;
78 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.PmNamesEnum;
79 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev210930.olm.get.pm.input.ResourceIdentifierBuilder;
80 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
81 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
82 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
83 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
84 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
85 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
86 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.NodeKey;
87 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.node.SupportingNode;
88 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
89 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
90 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
91 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.LinkKey;
92 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
93 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
94 import org.slf4j.Logger;
95 import org.slf4j.LoggerFactory;
97 public class OlmPowerServiceImpl implements OlmPowerService {
98 private static final Logger LOG = LoggerFactory.getLogger(OlmPowerServiceImpl.class);
99 private final MappingUtils mappingUtils;
100 private final OpenRoadmInterfaces openRoadmInterfaces;
101 private final DataBroker dataBroker;
102 private final PowerMgmt powerMgmt;
103 private final DeviceTransactionManager deviceTransactionManager;
104 private final PortMapping portMapping;
106 public OlmPowerServiceImpl(DataBroker dataBroker, PowerMgmt powerMgmt,
107 DeviceTransactionManager deviceTransactionManager, PortMapping portMapping,
108 MappingUtils mappingUtils, OpenRoadmInterfaces openRoadmInterfaces) {
109 this.dataBroker = dataBroker;
110 this.powerMgmt = powerMgmt;
111 this.portMapping = portMapping;
112 this.deviceTransactionManager = deviceTransactionManager;
113 this.mappingUtils = mappingUtils;
114 this.openRoadmInterfaces = openRoadmInterfaces;
118 LOG.info("init ...");
121 public void close() {
122 LOG.info("close ...");
127 public GetPmOutput getPm(GetPmInput pmInput) {
128 OpenroadmNodeVersion openroadmVersion;
129 GetPmOutputBuilder pmOutputBuilder = new GetPmOutputBuilder();
130 switch (mappingUtils.getOpenRoadmVersion(pmInput.getNodeId())) {
131 case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
132 openroadmVersion = OpenroadmNodeVersion._121;
134 case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
135 openroadmVersion = OpenroadmNodeVersion._221;
137 case StringConstants.OPENROADM_DEVICE_VERSION_7_1:
138 openroadmVersion = OpenroadmNodeVersion._71;
141 LOG.error("Unknown device version");
142 return pmOutputBuilder.build();
144 LOG.info("Now calling get pm data");
145 pmOutputBuilder = OlmUtils.pmFetch(pmInput, deviceTransactionManager,
147 return pmOutputBuilder.build();
151 public ServicePowerSetupOutput servicePowerSetup(ServicePowerSetupInput powerSetupInput) {
152 ServicePowerSetupOutputBuilder powerSetupOutput = new ServicePowerSetupOutputBuilder();
153 boolean successValPowerCalculation = powerMgmt.setPower(powerSetupInput);
154 if (successValPowerCalculation) {
155 powerSetupOutput.setResult(ResponseCodes.SUCCESS_RESULT);
157 powerSetupOutput.setResult(ResponseCodes.FAILED_RESULT);
159 return powerSetupOutput.build();
163 public ServicePowerTurndownOutput servicePowerTurndown(
164 ServicePowerTurndownInput powerTurndownInput) {
166 ServicePowerTurndownOutputBuilder powerTurnDownOutput = new ServicePowerTurndownOutputBuilder();
167 // TODO add flag or return failure instead of string
168 if (powerMgmt.powerTurnDown(powerTurndownInput)) {
169 powerTurnDownOutput.setResult(ResponseCodes.SUCCESS_RESULT);
171 powerTurnDownOutput.setResult(ResponseCodes.FAILED_RESULT);
173 return powerTurnDownOutput.build();
177 public CalculateSpanlossBaseOutput calculateSpanlossBase(CalculateSpanlossBaseInput spanlossBaseInput) {
178 LOG.info("CalculateSpanlossBase Request received for source type {}", spanlossBaseInput.getSrcType());
179 List<RoadmLinks> roadmLinks = new ArrayList<>();
180 CalculateSpanlossBaseOutputBuilder spanLossBaseBuilder = new CalculateSpanlossBaseOutputBuilder();
181 Map<LinkId, BigDecimal> spanLossResult = null;
182 //Depending on the source type do the calculation
183 switch (spanlossBaseInput.getSrcType()) {
185 LOG.debug("Calculate SpanLossBase for a linkId: {}",spanlossBaseInput.getLinkId());
186 Link inputLink = getNetworkLinkById(spanlossBaseInput.getLinkId());
187 if (inputLink != null) {
188 RoadmLinks roadmLink = new RoadmLinks();
189 roadmLink.setSrcNodeId(inputLink.getSource().getSourceNode().getValue());
190 roadmLink.setSrcTpId(inputLink.getSource().getSourceTp().getValue());
191 roadmLink.setDestNodeId(inputLink.getDestination().getDestNode().getValue());
192 roadmLink.setDestTpid(inputLink.getDestination().getDestTp().getValue());
193 roadmLink.setLinkId(inputLink.getLinkId());
194 roadmLinks.add(roadmLink);
195 spanLossResult = getLinkSpanloss(roadmLinks);
199 LOG.info("Do something for all");
200 List<Link> networkLinks = getNetworkLinks();
201 if (networkLinks.isEmpty()) {
202 LOG.warn("Failed to get links form {} topology.", NetworkUtils.OVERLAY_NETWORK_ID);
203 return new CalculateSpanlossBaseOutputBuilder().setResult(ResponseCodes.FAILED_RESULT).build();
205 //else for all other links
206 for (Link link : networkLinks) {
207 Link1 roadmLinkAugmentation = link.augmentation(Link1.class);
208 if (roadmLinkAugmentation == null) {
209 LOG.debug("Missing OpenRoadm link augmentation in link {} from {} topology.",
210 link.getLinkId().getValue(), NetworkUtils.OVERLAY_NETWORK_ID);
213 if (OpenroadmLinkType.ROADMTOROADM.equals(roadmLinkAugmentation.getLinkType())) {
214 // Only calculate spanloss for Roadm-to-Roadm links
215 RoadmLinks roadmLink = new RoadmLinks();
216 roadmLink.setSrcNodeId(link.getSource().getSourceNode().getValue());
217 roadmLink.setSrcTpId(link.getSource().getSourceTp().getValue());
218 roadmLink.setDestNodeId(link.getDestination().getDestNode().getValue());
219 roadmLink.setDestTpid(link.getDestination().getDestTp().getValue());
220 roadmLink.setLinkId(link.getLinkId());
221 roadmLinks.add(roadmLink);
224 if (roadmLinks.isEmpty()) {
225 LOG.warn("Topology {} does not have any Roadm-to-Roadm links.", NetworkUtils.OVERLAY_NETWORK_ID);
226 return new CalculateSpanlossBaseOutputBuilder().setResult(ResponseCodes.FAILED_RESULT).build();
228 spanLossResult = getLinkSpanloss(roadmLinks);
231 LOG.info("Invalid input in request");
234 if (spanLossResult != null && !spanLossResult.isEmpty()) {
235 spanLossBaseBuilder.setResult(ResponseCodes.SUCCESS_RESULT);
236 List<Spans> listSpans = new ArrayList<>();
237 Set<Entry<LinkId, BigDecimal>> spanLossResultSet = spanLossResult.entrySet();
238 for (Entry<LinkId, BigDecimal> entry : spanLossResultSet) {
239 Spans span = new SpansBuilder().setLinkId(entry.getKey()).setSpanloss(entry.getValue().toString())
243 spanLossBaseBuilder.setSpans(listSpans);
244 return spanLossBaseBuilder.build();
246 LOG.warn("Spanloss calculation failed");
247 spanLossBaseBuilder.setResult(ResponseCodes.FAILED_RESULT);
248 return spanLossBaseBuilder.build();
255 public CalculateSpanlossCurrentOutput calculateSpanlossCurrent(CalculateSpanlossCurrentInput input) {
256 LOG.info("calculateSpanlossCurrent Request received for all links in network model.");
257 List<Link> networkLinks = getNetworkLinks();
258 if (networkLinks.isEmpty()) {
259 LOG.warn("Failed to get links form {} topology.", NetworkUtils.OVERLAY_NETWORK_ID);
262 List<RoadmLinks> roadmLinks = new ArrayList<>();
263 for (Link link : networkLinks) {
264 Link1 roadmLinkAugmentation = link.augmentation(Link1.class);
265 if (roadmLinkAugmentation == null) {
266 LOG.debug("Missing OpenRoadm link augmentation in link {} from {} topology.",
267 link.getLinkId().getValue(), NetworkUtils.OVERLAY_NETWORK_ID);
270 if (OpenroadmLinkType.ROADMTOROADM.equals(roadmLinkAugmentation.getLinkType())) {
271 // Only calculate spanloss for Roadm-to-Roadm links
272 RoadmLinks roadmLink = new RoadmLinks();
273 roadmLink.setSrcNodeId(link.getSource().getSourceNode().getValue());
274 roadmLink.setSrcTpId(link.getSource().getSourceTp().getValue());
275 roadmLink.setDestNodeId(link.getDestination().getDestNode().getValue());
276 roadmLink.setDestTpid(link.getDestination().getDestTp().getValue());
277 roadmLinks.add(roadmLink);
281 if (roadmLinks.isEmpty()) {
282 LOG.warn("Topology {} does not have any Roadm-to-Roadm links.", NetworkUtils.OVERLAY_NETWORK_ID);
286 Map<LinkId, BigDecimal> spanLossResult = getLinkSpanloss(roadmLinks);
287 CalculateSpanlossCurrentOutputBuilder spanLossCurrentBuilder = new CalculateSpanlossCurrentOutputBuilder();
288 if (spanLossResult != null && !spanLossResult.isEmpty()) {
289 spanLossCurrentBuilder.setResult(ResponseCodes.SUCCESS_RESULT);
290 return spanLossCurrentBuilder.build();
292 LOG.error("Spanloss Current calculation failed");
293 spanLossCurrentBuilder.setResult(ResponseCodes.FAILED_RESULT);
294 return spanLossCurrentBuilder.build();
299 public ServicePowerResetOutput servicePowerReset(ServicePowerResetInput input) {
304 private List<Link> getNetworkLinks() {
305 NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
307 InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Networks.class)
308 .child(Network.class, overlayTopologyKey)
309 .augmentation(Network1.class)
311 Optional<Network1> networkOptional;
312 try (ReadTransaction rtx = this.dataBroker.newReadOnlyTransaction()) {
313 //TODO change to constant from Timeouts class when it will be merged.
314 networkOptional = rtx.read(LogicalDatastoreType.CONFIGURATION, networkIID).get(Timeouts.DATASTORE_READ,
315 TimeUnit.MILLISECONDS);
317 } catch (InterruptedException | ExecutionException | TimeoutException e) {
318 LOG.warn("Read of {} topology failed", NetworkUtils.OVERLAY_NETWORK_ID);
319 return Collections.emptyList();
322 if (! networkOptional.isPresent()) {
323 LOG.warn("Network augmentation with links data is not present in {} topology.",
324 NetworkUtils.OVERLAY_NETWORK_ID);
326 return Collections.emptyList();
329 @Nullable Map<LinkKey, Link> networkLinks = networkOptional.get().getLink();
330 if ((networkLinks == null) || networkLinks.isEmpty()) {
331 LOG.warn("Links are not present in {} topology.", NetworkUtils.OVERLAY_NETWORK_ID);
332 return Collections.emptyList();
334 return new ArrayList<>(networkLinks.values());
338 * This method retrieves OTS PM from current PM list by nodeId and TPId: Steps:
341 * 1. Get OTS interface name from port mapping by TPId 2. Call getPm RPC to get OTS PM
345 * @param nodeId Node-id of the NE.
346 * @param tpID Termination point Name.
347 * @param pmName PM name which need to be retrieved
348 * @return reference to OtsPmHolder
350 private OtsPmHolder getPmMeasurements(String nodeId, String tpID, String pmName) {
351 String realNodeId = getRealNodeId(nodeId);
352 Mapping mapping = portMapping.getMapping(realNodeId, tpID);
353 if (mapping == null) {
356 GetPmInput getPmInput = new GetPmInputBuilder().setNodeId(realNodeId)
357 .setResourceType(ResourceTypeEnum.Interface)
358 .setResourceIdentifier(
359 new ResourceIdentifierBuilder().setResourceName(mapping.getSupportingOts()).build())
360 .setPmNameType(PmNamesEnum.valueOf(pmName))
361 .setGranularity(PmGranularity._15min)
363 GetPmOutput otsPmOutput = getPm(getPmInput);
365 if (otsPmOutput == null || otsPmOutput.getMeasurements() == null) {
366 LOG.info("OTS PM not found for NodeId: {} TP Id:{} PMName:{}", realNodeId, tpID, pmName);
370 for (Measurements measurement : otsPmOutput.getMeasurements()) {
371 if (pmName.equalsIgnoreCase(measurement.getPmparameterName())) {
372 return new OtsPmHolder(pmName, Double.parseDouble(measurement.getPmparameterValue()),
373 mapping.getSupportingOts());
376 } catch (NumberFormatException e) {
377 LOG.warn("Unable to get PM for NodeId: {} TP Id:{} PMName:{}", realNodeId, tpID, pmName, e);
383 * This method Sets Spanloss on A-End and Z-End OTS interface: Steps:
386 * 1. Read existing interface details
391 * @param nodeId nodeId of NE on which spanloss need to be updated
392 * @param interfaceName OTS interface for NE on which spanloss is cacluated
393 * @param spanLoss calculated spanloss value
394 * @param direction for which spanloss is calculated.It can be either Tx or Rx
397 private boolean setSpanLoss(String nodeId, String interfaceName, BigDecimal spanLoss, String direction) {
398 String realNodeId = getRealNodeId(nodeId);
400 LOG.info("Setting Spanloss in device for {}, InterfaceName: {}", realNodeId, interfaceName);
401 if (mappingUtils.getOpenRoadmVersion(realNodeId)
402 .equals(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1)) {
406 Optional<Interface> interfaceObject;
407 interfaceObject = openRoadmInterfaces.getInterface(realNodeId, interfaceName);
408 if (interfaceObject.isPresent()) {
409 InterfaceBuilder interfaceBuilder = new InterfaceBuilder(interfaceObject.get());
410 OtsBuilder otsBuilder = new OtsBuilder();
411 Interface intf = interfaceObject.get();
412 if (intf.augmentation(Interface1.class) != null
413 && intf.augmentation(Interface1.class).getOts() != null) {
414 Ots ots = intf.augmentation(Interface1.class).getOts();
415 otsBuilder.setFiberType(ots.getFiberType());
416 spanLossRx = ots.getSpanLossReceive();
417 spanLossTx = ots.getSpanLossTransmit();
419 spanLossRx = new RatioDB(spanLoss);
420 spanLossTx = new RatioDB(spanLoss);
422 Interface1Builder intf1Builder = new Interface1Builder();
423 if (direction.equals("TX")) {
424 otsBuilder.setSpanLossTransmit(new RatioDB(spanLoss));
425 otsBuilder.setSpanLossReceive(spanLossRx);
427 otsBuilder.setSpanLossTransmit(spanLossTx).setSpanLossReceive(new RatioDB(spanLoss));
429 interfaceBuilder.addAugmentation(intf1Builder.setOts(otsBuilder.build()).build());
430 openRoadmInterfaces.postInterface(realNodeId,interfaceBuilder);
431 LOG.info("Spanloss Value update completed successfully");
434 LOG.error("Interface not found for nodeId: {} and interfaceName: {}", nodeId, interfaceName);
437 } else if (mappingUtils.getOpenRoadmVersion(realNodeId)
438 .equals(StringConstants.OPENROADM_DEVICE_VERSION_2_2_1)) {
440 org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.RatioDB spanLossRx;
441 org.opendaylight.yang.gen.v1.http.org.openroadm.common.types
442 .rev181019.RatioDB spanLossTx;
443 Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019
444 .interfaces.grp.Interface> interfaceObject =
445 openRoadmInterfaces.getInterface(realNodeId, interfaceName);
446 if (interfaceObject.isPresent()) {
447 org.opendaylight.yang.gen.v1.http.org.openroadm.device
448 .rev181019.interfaces.grp.InterfaceBuilder interfaceBuilder =
449 new org.opendaylight.yang.gen.v1.http.org.openroadm.device
450 .rev181019.interfaces.grp.InterfaceBuilder(interfaceObject.get());
451 org.opendaylight.yang.gen.v1.http.org.openroadm.optical
452 .transport.interfaces.rev181019.ots.container.OtsBuilder otsBuilder =
453 new org.opendaylight.yang.gen.v1.http.org.openroadm
454 .optical.transport.interfaces.rev181019.ots.container.OtsBuilder();
455 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.Interface intf =
456 interfaceObject.get();
457 if (intf.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.optical
458 .transport.interfaces.rev181019.Interface1.class) != null
459 && intf.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport
460 .interfaces.rev181019.Interface1.class).getOts() != null) {
461 org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces
462 .rev181019.ots.container.Ots ots =
463 intf.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.optical
464 .transport.interfaces.rev181019.Interface1.class).getOts();
466 otsBuilder.setFiberType(ots.getFiberType());
467 spanLossRx = ots.getSpanLossReceive();
468 spanLossTx = ots.getSpanLossTransmit();
470 spanLossRx = new org.opendaylight.yang.gen.v1.http.org
471 .openroadm.common.types.rev181019.RatioDB(spanLoss);
472 spanLossTx = new org.opendaylight.yang.gen.v1.http.org
473 .openroadm.common.types.rev181019.RatioDB(spanLoss);
475 org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces
476 .rev181019.Interface1Builder intf1Builder =
477 new org.opendaylight.yang.gen.v1.http.org.openroadm.optical
478 .transport.interfaces.rev181019.Interface1Builder();
479 if (direction.equals("TX")) {
480 otsBuilder.setSpanLossTransmit(new org.opendaylight.yang.gen.v1.http.org
481 .openroadm.common.types.rev181019.RatioDB(spanLoss));
482 otsBuilder.setSpanLossReceive(spanLossRx);
484 otsBuilder.setSpanLossTransmit(spanLossTx).setSpanLossReceive(
485 new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.RatioDB(spanLoss)
488 interfaceBuilder.addAugmentation(intf1Builder.setOts(otsBuilder.build()).build());
489 openRoadmInterfaces.postInterface(realNodeId,interfaceBuilder);
490 LOG.info("Spanloss Value update completed successfully");
493 LOG.error("Interface not found for nodeId: {} and interfaceName: {}", nodeId,interfaceName);
497 } catch (OpenRoadmInterfaceException e) {
498 // TODO Auto-generated catch block
499 LOG.error("OpenRoadmInterfaceException occured: ",e);
500 } /**catch (InterruptedException e) {
501 // TODO Auto-generated catch block
502 } catch (ExecutionException e) {
503 // TODO Auto-generated catch block
509 * This method calculates Spanloss by TranmistPower - Receive Power Steps:
512 * 1. Read PM measurement
515 * 2. Set Spanloss value for interface
518 * reference to list of RoadmLinks
519 * @return map with list of spans with their spanloss value
521 private Map<LinkId, BigDecimal> getLinkSpanloss(List<RoadmLinks> roadmLinks) {
522 Map<LinkId, BigDecimal> map = new HashMap<>();
523 LOG.info("Executing GetLinkSpanLoss");
525 for (RoadmLinks link : roadmLinks) {
526 String sourceNodeId = link.getSrcNodeId();
527 String sourceTpId = link.getSrcTpId();
528 String destNodeId = link.getDestNodeId();
529 String destTpId = link.getDestTpid();
530 OtsPmHolder srcOtsPmHolder = getPmMeasurements(sourceNodeId, sourceTpId, "OpticalPowerOutput");
531 if (srcOtsPmHolder == null) {
532 srcOtsPmHolder = getPmMeasurements(sourceNodeId, sourceTpId, "OpticalPowerOutputOSC");
533 if (srcOtsPmHolder == null) {
534 LOG.warn("OTS configuration issue at {} - {}", sourceNodeId, sourceTpId);
538 OtsPmHolder destOtsPmHolder = getPmMeasurements(destNodeId, destTpId, "OpticalPowerInput");
539 if (destOtsPmHolder == null) {
540 destOtsPmHolder = getPmMeasurements(destNodeId, destTpId, "OpticalPowerInputOSC");
541 if (destOtsPmHolder == null) {
542 LOG.warn("OTS configuration issue at {} - {}", destNodeId, destTpId);
546 spanLoss = BigDecimal.valueOf(srcOtsPmHolder.getOtsParameterVal() - destOtsPmHolder.getOtsParameterVal())
547 .setScale(1, RoundingMode.HALF_UP);
548 LOG.info("Spanloss Calculated as :{}={}-{}",
549 spanLoss, srcOtsPmHolder.getOtsParameterVal(), destOtsPmHolder.getOtsParameterVal());
550 if (spanLoss.doubleValue() > 28) {
551 LOG.warn("Span Loss is out of range of OpenROADM specifications");
553 if (spanLoss.intValue() <= 0) {
554 spanLoss = BigDecimal.valueOf(0);
556 if (!setSpanLoss(sourceNodeId, srcOtsPmHolder.getOtsInterfaceName(), spanLoss, "TX")) {
557 LOG.info("Setting spanLoss failed for {}", sourceNodeId);
560 if (!setSpanLoss(destNodeId, destOtsPmHolder.getOtsInterfaceName(), spanLoss, "RX")) {
561 LOG.info("Setting spanLoss failed for {}", destNodeId);
564 map.put(link.getLinkId(), spanLoss);
569 private String getRealNodeId(String mappedNodeId) {
570 KeyedInstanceIdentifier<Node, NodeKey> mappedNodeII =
571 InstanceIdentifiers.OVERLAY_NETWORK_II.child(Node.class, new NodeKey(new NodeId(mappedNodeId)));
572 Optional<Node> realNode;
573 try (ReadTransaction readOnlyTransaction = this.dataBroker.newReadOnlyTransaction()) {
574 realNode = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, mappedNodeII).get();
575 } catch (InterruptedException | ExecutionException e) {
576 LOG.error("Error on getRealNodeId {} :", mappedNodeId, e);
577 throw new IllegalStateException(e);
579 if (!realNode.isPresent() || (realNode.get().getSupportingNode() == null)) {
580 LOG.error("supporting node is null");
581 throw new IllegalArgumentException(
582 String.format("Could not find node %s, or supporting node is not present", mappedNodeId));
584 List<SupportingNode> collect = realNode.get().nonnullSupportingNode().values().stream()
585 .filter(node -> (node.getNetworkRef() != null)
586 && NetworkUtils.UNDERLAY_NETWORK_ID.equals(node.getNetworkRef().getValue())
587 && (node.getNodeRef() != null) && !Strings.isNullOrEmpty(node.getNodeRef().getValue()))
588 .collect(Collectors.toList());
589 if (collect.isEmpty() || (collect.size() > 1)) {
590 throw new IllegalArgumentException(String.format("Invalid support node count [%d] was found for node %s",
591 collect.size(), mappedNodeId));
594 LOG.info("getRealNodeId - return {}", collect.iterator().next().getNodeRef().getValue());
595 return collect.iterator().next().getNodeRef().getValue();
598 private Link getNetworkLinkById(LinkId linkId) {
599 NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
600 InstanceIdentifier<Link> linkIID = InstanceIdentifier.builder(Networks.class)
601 .child(Network.class, overlayTopologyKey)
602 .augmentation(Network1.class).child(Link.class, new LinkKey(linkId))
604 Optional<Link> linkOptional;
605 try (ReadTransaction rtx = dataBroker.newReadOnlyTransaction()) {
606 //TODO change to constant from Timeouts class when it will be merged.
607 linkOptional = rtx.read(LogicalDatastoreType.CONFIGURATION, linkIID).get(Timeouts.DATASTORE_READ,
608 TimeUnit.MILLISECONDS);
609 return linkOptional.get();
610 } catch (InterruptedException | ExecutionException | TimeoutException e) {
611 LOG.warn("Read of {} topology failed", NetworkUtils.OVERLAY_NETWORK_ID);