2 * Copyright © 2017 AT&T, Inc. 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.pce.networkanalyzer;
11 import java.util.List;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.link.oms.attributes.Span;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 public class PceLink {
27 private static final Logger LOG = LoggerFactory.getLogger(PceLink.class);
29 ///////////////////////// LINKS ////////////////////
31 * extension of Link to include constraints and Graph weight
36 private boolean isValid = true;
38 // this member is for XPONDER INPUT/OUTPUT links.
39 // it keeps name of client correcponding to NETWORK TP
40 private String client = "";
42 private final LinkId linkId;
43 private final OpenroadmLinkType linkType;
44 private final NodeId sourceId;
45 private final NodeId destId;
46 private final Object sourceTP;
47 private final Object destTP;
48 private final String sourceSupNodeId;
49 private final String destSupNodeId;
50 private final String sourceCLLI;
51 private final String destCLLI;
52 private final LinkId oppositeLink;
53 private final Long latency;
54 private final List<Long> srlgList;
55 private final double osnr;
56 private final Span omsAttributesSpan;
58 public PceLink(Link link, PceNode source, PceNode dest) {
59 LOG.debug("PceLink: : PceLink start ");
61 this.linkId = link.getLinkId();
63 this.sourceId = link.getSource().getSourceNode();
64 this.destId = link.getDestination().getDestNode();
66 this.sourceTP = link.getSource().getSourceTp();
67 this.destTP = link.getDestination().getDestTp();
69 this.sourceSupNodeId = source.getSupNodeIdPceNode();
70 this.destSupNodeId = dest.getSupNodeIdPceNode();
72 this.sourceCLLI = source.getCLLI();
73 this.destCLLI = dest.getCLLI();
75 this.linkType = MapUtils.calcType(link);
77 this.oppositeLink = calcOpposite(link);
78 this.latency = calcLatency(link);
80 if (this.linkType == OpenroadmLinkType.ROADMTOROADM) {
81 this.omsAttributesSpan = MapUtils.getOmsAttributesSpan(link);
82 this.srlgList = MapUtils.getSRLG(link);
83 this.osnr = retrieveOSNR();
85 this.omsAttributesSpan = null;
91 LOG.debug("PceLink: created PceLink {}", toString());
94 private OpenroadmLinkType calcType(Link link) {
95 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.@Nullable Link1 link1 = null;
96 OpenroadmLinkType tmplinkType = null;
99 link1 = link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
102 this.isValid = false;
103 LOG.error("PceLink: No Link augmentation available. Link is ignored {}", this.linkId);
107 tmplinkType = link1.getLinkType();
108 if (tmplinkType == null) {
109 this.isValid = false;
110 LOG.error("PceLink: No Link type available. Link is ignored {}", this.linkId);
116 private LinkId calcOpposite(Link link) {
119 LinkId tmpoppositeLink = MapUtils.extractOppositeLink(link);
120 if (tmpoppositeLink == null) {
121 LOG.error("PceLink: Error calcOpposite. Link is ignored {}", link.getLinkId().getValue());
124 return tmpoppositeLink;
127 private Long calcLatency(Link link) {
128 Long tmplatency = 1L;
131 link1 = link.augmentation(Link1.class);
133 tmplatency = link1.getLinkLatency();
134 } catch (NullPointerException e) {
135 LOG.debug("the latency does not exist for this link");
140 @SuppressWarnings("checkstyle:VariableDeclarationUsageDistance")
141 public double retrieveOSNR() {
142 // sum of 1 over the span OSNRs (linear units)
150 // span OSNR, in linear units
152 // default amplifier noise value, in dB
153 double ampNoise = 5.5;
154 // fiber span measured loss, in dB
156 // launch power, in dB
158 double constantA = 38.97293;
159 double constantB = 0.72782;
160 double constantC = -0.532331;
161 double constactD = -0.019549;
162 double upperBoundosnr = 33;
163 double lowerBoundosnr = 0.1;
165 if (omsAttributesSpan == null) {
166 // indicates no data or N/A
169 loss = omsAttributesSpan.getSpanlossCurrent().getValue().doubleValue();
170 switch (omsAttributesSpan.getLinkConcatenation().get(0).getFiberType()) {
207 spanOsnrDb = constantA + constantB * power + constantC * loss + constactD * power * loss;
208 if (spanOsnrDb > upperBoundosnr) {
209 spanOsnrDb = upperBoundosnr;
210 } else if (spanOsnrDb < lowerBoundosnr) {
211 spanOsnrDb = lowerBoundosnr;
213 spanOsnrLu = Math.pow(10, (spanOsnrDb / 10.0));
214 sum = PceConstraints.CONST_OSNR / spanOsnrLu;
216 //link_osnr_dB = 10 * Math.log10(1 / sum);
217 LOG.debug("In retrieveosnr: link osnr is {} dB", linkOsnrLu);
221 public LinkId getOppositeLink() {
225 public Object getSourceTP() {
229 public Object getDestTP() {
233 public OpenroadmLinkType getlinkType() {
237 public LinkId getLinkId() {
241 public NodeId getSourceId() {
245 public NodeId getDestId() {
249 public String getClient() {
253 public void setClient(String client) {
254 this.client = client;
257 // Double for transformer of JUNG graph
258 public Double getLatency() {
259 return latency.doubleValue();
262 public String getsourceSupNodeId() {
263 return sourceSupNodeId;
266 public String getdestSupNodeId() {
267 return destSupNodeId;
270 public List<Long> getsrlgList() {
274 public double getosnr() {
278 public String getsourceCLLI() {
282 public String getdestCLLI() {
286 public boolean isValid() {
287 if ((this.linkId == null) || (this.linkType == null)
288 || (this.oppositeLink == null)) {
290 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", linkId);
292 if ((this.sourceId == null) || (this.destId == null)
293 || (this.sourceTP == null) || (this.destTP == null)) {
295 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", linkId);
297 if ((this.sourceSupNodeId.equals("")) || (this.destSupNodeId.equals(""))) {
299 LOG.error("PceLink: No Link source SuppNodeID or destination SuppNodeID is available. Link is ignored {}",
302 if ((this.sourceCLLI.equals("")) || (this.destCLLI.equals(""))) {
304 LOG.error("PceLink: No Link source CLLI or destination CLLI is available. Link is ignored {}", linkId);
306 if ((this.omsAttributesSpan == null) && (this.linkType == OpenroadmLinkType.ROADMTOROADM)) {
308 LOG.error("PceLink: Error reading Span for OMS link. Link is ignored {}", linkId);
310 if ((this.srlgList != null) && (this.srlgList.isEmpty())) {
312 LOG.error("PceLink: Empty srlgList for OMS link. Link is ignored {}", linkId);
317 public String toString() {
318 return "PceLink type=" + linkType + " ID=" + linkId.getValue() + " latecy=" + latency;