import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.Optional;
+import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.opendaylight.transportpce.olm.power.PowerMgmt;
import org.opendaylight.transportpce.olm.util.OlmUtils;
import org.opendaylight.transportpce.olm.util.OtsPmHolder;
-import org.opendaylight.transportpce.olm.util.RoadmLinks;
import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RatioDB;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.network.Node;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.network.NodeKey;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.network.node.SupportingNode;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.LinkId;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.Network1;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.network.Link;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.CalculateSpanlossBaseInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.ServicePowerTurndownInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.ServicePowerTurndownOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.ServicePowerTurndownOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.calculate.spanloss.base.output.Spans;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.calculate.spanloss.base.output.SpansBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.olm.rev170418.get.pm.output.Measurements;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.portmapping.rev170228.network.nodes.Mapping;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
private final PortMapping portMapping;
public OlmPowerServiceImpl(DataBroker dataBroker, PowerMgmt powerMgmt,
- DeviceTransactionManager deviceTransactionManager, PortMapping portMapping) {
+ DeviceTransactionManager deviceTransactionManager, PortMapping portMapping) {
this.dataBroker = dataBroker;
this.powerMgmt = powerMgmt;
this.portMapping = portMapping;
LOG.info("close ...");
}
-
@Override
public GetPmOutput getPm(GetPmInput pmInput) {
GetPmOutputBuilder pmOutputBuilder = OlmUtils.pmFetch(pmInput, this.deviceTransactionManager);
@Override
public ServicePowerTurndownOutput servicePowerTurndown(
- ServicePowerTurndownInput powerTurndownInput) {
+ ServicePowerTurndownInput powerTurndownInput) {
ServicePowerTurndownOutputBuilder powerTurnDownOutput = new ServicePowerTurndownOutputBuilder();
// TODO add flag or return failure instead of string
return new CalculateSpanlossBaseOutputBuilder().setResult(FAILED).build();
}
- if (! CalculateSpanlossBaseInput.SrcType.All.equals(spanlossBaseInput.getSrcType())) {
+ if (!CalculateSpanlossBaseInput.SrcType.All.equals(spanlossBaseInput.getSrcType())) {
networkLinks = networkLinks.stream()
- .filter(link -> link.getLinkId().equals(spanlossBaseInput.getLinkId()))
- .collect(Collectors.toList());
+ .filter(link -> link.getLinkId().equals(spanlossBaseInput.getLinkId()))
+ .collect(Collectors.toList());
}
- List<RoadmLinks> roadmLinks = new ArrayList<>();
+ List<Link> roadmLinks = new ArrayList<>();
for (Link link : networkLinks) {
Link1 roadmLinkAugmentation = link.augmentation(Link1.class);
if (roadmLinkAugmentation == null) {
LOG.debug("Missing OpenRoadm link augmentation in link {} from {} topology.",
- link.getLinkId().getValue(), NetworkUtils.OVERLAY_NETWORK_ID);
+ link.getLinkId().getValue(), NetworkUtils.OVERLAY_NETWORK_ID);
continue;
}
if (OpenroadmLinkType.ROADMTOROADM.equals(roadmLinkAugmentation.getLinkType())) {
- // Only calculate spanloss for Roadm-to-Roadm links
- RoadmLinks roadmLink = new RoadmLinks();
- roadmLink.setSrcNodeId(link.getSource().getSourceNode().getValue());
- roadmLink.setSrcTpId(link.getSource().getSourceTp().toString());
- roadmLink.setDestNodeId(link.getDestination().getDestNode().getValue());
- roadmLink.setDestTpid(link.getDestination().getDestTp().toString());
- roadmLinks.add(roadmLink);
+ roadmLinks.add(link);
}
}
return new CalculateSpanlossBaseOutputBuilder().setResult(FAILED).build();
}
- boolean spanLossResult = getLinkSpanloss(roadmLinks);
+ Map<LinkId, BigDecimal> spanLossResult = getLinkSpanloss(roadmLinks);
CalculateSpanlossBaseOutputBuilder spanLossBaseBuilder = new CalculateSpanlossBaseOutputBuilder();
- if (spanLossResult) {
+
+ if (spanLossResult != null && !spanLossResult.isEmpty()) {
spanLossBaseBuilder.setResult(SUCCESS);
+ List<Spans> listSpans = new ArrayList<>();
+ Set<Entry<LinkId, BigDecimal>> spanLossResultSet = spanLossResult.entrySet();
+ for (Entry<LinkId, BigDecimal> entry : spanLossResultSet) {
+ Spans span = new SpansBuilder().setLinkId(entry.getKey()).setSpanloss(entry.getValue().toString())
+ .build();
+ listSpans.add(span);
+ }
+ spanLossBaseBuilder.setSpans(listSpans);
return spanLossBaseBuilder.build();
} else {
LOG.warn("Spanloss calculation failed");
LOG.warn("Failed to get links form {} topology.", NetworkUtils.OVERLAY_NETWORK_ID);
return null;
}
- List<RoadmLinks> roadmLinks = new ArrayList<>();
+ List<Link> roadmLinks = new ArrayList<>();
for (Link link : networkLinks) {
Link1 roadmLinkAugmentation = link.augmentation(Link1.class);
if (roadmLinkAugmentation == null) {
LOG.debug("Missing OpenRoadm link augmentation in link {} from {} topology.",
- link.getLinkId().getValue(), NetworkUtils.OVERLAY_NETWORK_ID);
+ link.getLinkId().getValue(), NetworkUtils.OVERLAY_NETWORK_ID);
continue;
}
if (OpenroadmLinkType.ROADMTOROADM.equals(roadmLinkAugmentation.getLinkType())) {
// Only calculate spanloss for Roadm-to-Roadm links
- RoadmLinks roadmLink = new RoadmLinks();
- roadmLink.setSrcNodeId(link.getSource().getSourceNode().toString());
- roadmLink.setSrcTpId(link.getSource().getSourceTp().toString());
- roadmLink.setDestNodeId(link.getDestination().getDestNode().toString());
- roadmLink.setDestTpid(link.getDestination().getDestTp().toString());
- roadmLinks.add(roadmLink);
+ roadmLinks.add(link);
}
}
return null;
}
- boolean spanLossResult = getLinkSpanloss(roadmLinks);
+ Map<LinkId, BigDecimal> spanLossResult = getLinkSpanloss(roadmLinks);
CalculateSpanlossCurrentOutputBuilder spanLossCurrentBuilder = new CalculateSpanlossCurrentOutputBuilder();
- if (spanLossResult) {
+ if (spanLossResult != null && !spanLossResult.isEmpty()) {
spanLossCurrentBuilder.setResult(SUCCESS);
return spanLossCurrentBuilder.build();
} else {
NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Network.class, overlayTopologyKey)
- .augmentation(Network1.class)
- .build();
+ .augmentation(Network1.class)
+ .build();
Optional<Network1> networkOptional;
try (ReadOnlyTransaction rtx = this.dataBroker.newReadOnlyTransaction()) {
- //TODO change to constant from Timeouts class when it will be merged.
+ // TODO change to constant from Timeouts class when it will be
+ // merged.
networkOptional = rtx.read(LogicalDatastoreType.CONFIGURATION, networkIID).get(Timeouts.DATASTORE_READ,
- TimeUnit.MILLISECONDS).toJavaUtil();
+ TimeUnit.MILLISECONDS).toJavaUtil();
} catch (InterruptedException | ExecutionException | TimeoutException e) {
LOG.warn("Read of {} topology failed", NetworkUtils.OVERLAY_NETWORK_ID);
return Collections.emptyList();
}
- if (! networkOptional.isPresent()) {
+ if (!networkOptional.isPresent()) {
LOG.warn("Network augmentation with links data is not present in {} topology.",
- NetworkUtils.OVERLAY_NETWORK_ID);
+ NetworkUtils.OVERLAY_NETWORK_ID);
return Collections.emptyList();
}
}
/**
- * This method retrieves OTS PM from current PM list by nodeId and TPId: Steps:
+ * This method retrieves OTS PM from current PM list by nodeId and TPId:
+ * Steps:
*
* <p>
- * 1. Get OTS interface name from port mapping by TPId 2. Call getPm RPC to get OTS PM
+ * 1. Get OTS interface name from port mapping by TPId 2. Call getPm RPC to
+ * get OTS PM
*
* <p>
*
- * @param nodeId Node-id of the NE.
- * @param tpID Termination point Name.
- * @param pmName PM name which need to be retrieved
+ * @param nodeId
+ * Node-id of the NE.
+ * @param tpID
+ * Termination point Name.
+ * @param pmName
+ * PM name which need to be retrieved
* @return reference to OtsPmHolder
*/
private OtsPmHolder getPmMeasurements(String nodeId, String tpID, String pmName) {
return null;
}
GetPmInput getPmInput = new GetPmInputBuilder().setNodeId(realNodeId)
- .setResourceType(ResourceTypeEnum.Interface).setGranularity(PmGranularity._15min)
- .setResourceIdentifier(
- new ResourceIdentifierBuilder().setResourceName(mapping.getSupportingOts()).build())
- .build();
+ .setResourceType(ResourceTypeEnum.Interface).setGranularity(PmGranularity._15min)
+ .setResourceIdentifier(
+ new ResourceIdentifierBuilder().setResourceName(mapping.getSupportingOts()).build())
+ .build();
GetPmOutput otsPmOutput = getPm(getPmInput);
if (otsPmOutput == null) {
for (Measurements measurement : otsPmOutput.getMeasurements()) {
if (pmName.equals(measurement.getPmparameterName())) {
return new OtsPmHolder(pmName, Double.parseDouble(measurement.getPmparameterValue()),
- mapping.getSupportingOts());
+ mapping.getSupportingOts());
}
}
} catch (NumberFormatException e) {
* <p>
* 2. Set spanloss
*
- * @param nodeId nodeId of NE on which spanloss need to be updated
- * @param interfaceName OTS interface for NE on which spanloss is cacluated
- * @param spanLoss calculated spanloss value
- * @param direction for which spanloss is calculated.It can be either Tx or Rx
+ * @param nodeId
+ * nodeId of NE on which spanloss need to be updated
+ * @param interfaceName
+ * OTS interface for NE on which spanloss is cacluated
+ * @param spanLoss
+ * calculated spanloss value
+ * @param direction
+ * for which spanloss is calculated.It can be either Tx or Rx
* @return true/false
*/
private boolean setSpanLoss(String nodeId, String interfaceName, BigDecimal spanLoss, String direction) {
String realNodeId = getRealNodeId(nodeId);
- LOG.info("Setting Spanloss in device for {}, InterfaceName: {}", realNodeId, interfaceName);
+ switch (direction) {
+ case "TX":
+ LOG.info("Setting 'span-loss-transmit' in device: {}, Interface: {}", realNodeId, interfaceName);
+ break;
+ case "RX":
+ LOG.info("Setting 'span-loss-receive' in device: {}, Interface: {}", realNodeId, interfaceName);
+ break;
+ default:
+ LOG.error("Impossible to set spanloss in device: {}, Interface: {}", realNodeId, interfaceName);
+ break;
+ }
InstanceIdentifier<Interface> interfacesIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
- .child(Interface.class, new InterfaceKey(interfaceName));
+ .child(Interface.class, new InterfaceKey(interfaceName));
com.google.common.base.Optional<Interface> interfaceObject;
try {
Future<Optional<DeviceTransaction>> deviceTxFuture =
- this.deviceTransactionManager.getDeviceTransaction(realNodeId);
+ this.deviceTransactionManager.getDeviceTransaction(realNodeId);
java.util.Optional<DeviceTransaction> deviceTxOpt = deviceTxFuture.get();
DeviceTransaction deviceTx;
if (deviceTxOpt.isPresent()) {
interfaceBuilder.addAugmentation(Interface1.class, intf1Builder.setOts(otsBuilder.build()).build());
deviceTx.put(LogicalDatastoreType.CONFIGURATION, interfacesIID, interfaceBuilder.build());
ListenableFuture<Void> submit =
- deviceTx.submit(Timeouts.DEVICE_WRITE_TIMEOUT, Timeouts.DEVICE_WRITE_TIMEOUT_UNIT);
+ deviceTx.submit(Timeouts.DEVICE_WRITE_TIMEOUT, Timeouts.DEVICE_WRITE_TIMEOUT_UNIT);
submit.get();
LOG.info("Spanloss Value update completed successfully");
return true;
* <p>
* 2. Set Spanloss value for interface
*
- * @param roadmLinks reference to list of RoadmLinks
- * @return true/false
+ * @param roadmLinks
+ * reference to list of RoadmLinks
+ * @return map with list of spans with their spanloss value
*/
- private boolean getLinkSpanloss(List<RoadmLinks> roadmLinks) {
+ private Map<LinkId, BigDecimal> getLinkSpanloss(List<Link> roadmLinks) {
+ Map<LinkId, BigDecimal> map = new HashMap<LinkId, BigDecimal>();
LOG.info("Executing GetLinkSpanLoss");
BigDecimal spanLoss = new BigDecimal(0);
- for (int i = 0; i < roadmLinks.size(); i++) {
-
- OtsPmHolder srcOtsPmHoler = getPmMeasurements(roadmLinks.get(i).getSrcNodeId(),
- roadmLinks.get(i).getSrcTpId(), "OpticalPowerOutput");
- OtsPmHolder destOtsPmHoler = getPmMeasurements(roadmLinks.get(i).getDestNodeId(),
- roadmLinks.get(i).getDestTpid(), "OpticalPowerInput");
+ for (Link link : roadmLinks) {
+ String sourceNodeId = link.getSource().getSourceNode().getValue();
+ String sourceTpId = link.getSource().getSourceTp().toString();
+ String destNodeId = link.getDestination().getDestNode().getValue();
+ String destTpId = link.getDestination().getDestTp().toString();
+ OtsPmHolder srcOtsPmHoler = getPmMeasurements(sourceNodeId, sourceTpId, "OpticalPowerOutput");
+ OtsPmHolder destOtsPmHoler = getPmMeasurements(destNodeId, destTpId, "OpticalPowerInput");
spanLoss = new BigDecimal(srcOtsPmHoler.getOtsParameterVal() - destOtsPmHoler.getOtsParameterVal())
- .setScale(0, RoundingMode.HALF_UP);
+ .setScale(0, RoundingMode.HALF_UP);
LOG.info("Spanloss Calculated as :" + spanLoss + "=" + srcOtsPmHoler.getOtsParameterVal() + "-"
- + destOtsPmHoler.getOtsParameterVal());
+ + destOtsPmHoler.getOtsParameterVal());
if ((spanLoss.doubleValue() < 28) && (spanLoss.doubleValue() > 0)) {
- if (!setSpanLoss(roadmLinks.get(i).getSrcNodeId(), srcOtsPmHoler.getOtsInterfaceName(), spanLoss,
- "TX")) {
- LOG.info("Setting spanLoss failed for " + roadmLinks.get(i).getSrcNodeId());
- return false;
+ if (!setSpanLoss(sourceNodeId, srcOtsPmHoler.getOtsInterfaceName(), spanLoss, "TX")) {
+ LOG.info("Setting spanLoss failed for " + sourceNodeId);
+ return null;
}
- if (!setSpanLoss(roadmLinks.get(i).getDestNodeId(), destOtsPmHoler.getOtsInterfaceName(), spanLoss,
- "RX")) {
- LOG.info("Setting spanLoss failed for " + roadmLinks.get(i).getDestNodeId());
- return false;
+ if (!setSpanLoss(destNodeId, destOtsPmHoler.getOtsInterfaceName(), spanLoss, "RX")) {
+ LOG.info("Setting spanLoss failed for " + destNodeId);
+ return null;
}
+ map.put(link.getLinkId(), spanLoss);
}
}
- return true;
+ return map;
}
private String getRealNodeId(String mappedNodeId) {
KeyedInstanceIdentifier<Node, NodeKey> mappedNodeII =
- InstanceIdentifiers.OVERLAY_NETWORK_II.child(Node.class, new NodeKey(new NodeId(mappedNodeId)));
+ InstanceIdentifiers.OVERLAY_NETWORK_II.child(Node.class, new NodeKey(new NodeId(mappedNodeId)));
com.google.common.base.Optional<Node> realNode;
try (ReadOnlyTransaction readOnlyTransaction = this.dataBroker.newReadOnlyTransaction()) {
realNode = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, mappedNodeII).get();
}
if (!realNode.isPresent() || (realNode.get().getSupportingNode() == null)) {
throw new IllegalArgumentException(
- String.format("Could not find node %s, or supporting node is not present", mappedNodeId));
+ String.format("Could not find node %s, or supporting node is not present", mappedNodeId));
}
List<SupportingNode> collect = realNode.get().getSupportingNode().stream()
- .filter(node -> (node.getNetworkRef() != null)
- && NetworkUtils.UNDERLAY_NETWORK_ID.equals(node.getNetworkRef().getValue())
- && (node.getNodeRef() != null) && !Strings.isNullOrEmpty(node.getNodeRef().getValue()))
- .collect(Collectors.toList());
+ .filter(node -> (node.getNetworkRef() != null)
+ && NetworkUtils.UNDERLAY_NETWORK_ID.equals(node.getNetworkRef().getValue())
+ && (node.getNodeRef() != null) && !Strings.isNullOrEmpty(node.getNodeRef().getValue()))
+ .collect(Collectors.toList());
if (collect.isEmpty() || (collect.size() > 1)) {
throw new IllegalArgumentException(String.format("Invalid support node count [%d] was found for node %s",
- collect.size(), mappedNodeId));
+ collect.size(), mappedNodeId));
}
return collect.iterator().next().getNodeRef().getValue();
}