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;
11 import java.util.List;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.link.oms.attributes.Span;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public class PceLink {
26 private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
28 ///////////////////////// LINKS ////////////////////
30 * extension of Link to include constraints and Graph weight
35 private boolean isValid = true;
37 // this member is for XPONDER INPUT/OUTPUT links.
38 // it keeps name of client corresponding to NETWORK TP
39 private String client = "";
41 private final LinkId linkId;
42 private final OpenroadmLinkType linkType;
43 private final NodeId sourceId;
44 private final NodeId destId;
45 private final Object sourceTP;
46 private final Object destTP;
47 private final LinkId oppositeLink;
48 private final Long latency;
49 private final List<Long> srlg;
50 private final double osnr;
51 private final Span omsAttributesSpan;
53 public PceLink(Link link) {
54 LOG.debug("PceLink: : PceLink start ");
56 this.linkId = link.getLinkId();
58 this.sourceId = link.getSource().getSourceNode();
59 this.destId = link.getDestination().getDestNode();
61 this.sourceTP = link.getSource().getSourceTp();
62 this.destTP = link.getDestination().getDestTp();
64 this.linkType = calcType(link);
66 this.oppositeLink = calcOpposite(link);
67 this.latency = calcLatency(link);
69 if (this.linkType == OpenroadmLinkType.ROADMTOROADM) {
70 this.omsAttributesSpan = MapUtils.getOmsAttributesSpan(link);
71 this.srlg = MapUtils.getSRLG(link);
72 this.osnr = retrieveOSNR();
74 this.omsAttributesSpan = null;
79 LOG.debug("PceLink: created PceLink {}", toString());
82 private OpenroadmLinkType calcType(Link link) {
83 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.@Nullable Link1 link1 = null;
84 OpenroadmLinkType tmplType = null;
87 link1 = link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
91 LOG.error("PceLink: No Link augmentation available. Link is ignored {}", this.linkId);
95 tmplType = link1.getLinkType();
96 if (tmplType == null) {
98 LOG.error("PceLink: No Link type available. Link is ignored {}", this.linkId);
104 private LinkId calcOpposite(Link link) {
106 LinkId tmpoppositeLink = null;
107 Link1 linkOpposite = link.augmentation(Link1.class);
108 if (linkOpposite.getOppositeLink() != null) {
109 tmpoppositeLink = linkOpposite.getOppositeLink();
111 LOG.error("link {} has no opposite link", link.getLinkId().getValue());
113 LOG.debug("PceLink: reading oppositeLink. {}", linkOpposite.toString());
114 if (tmpoppositeLink == null) {
115 this.isValid = false;
116 LOG.error("PceLink: Error reading oppositeLink. Link is ignored {}", this.linkId);
119 return tmpoppositeLink;
122 private Long calcLatency(Link link) {
123 Long tmplatency = (long)0;
126 link1 = link.augmentation(Link1.class);
127 tmplatency = link1.getLinkLatency();
128 if (tmplatency == null) {
129 tmplatency = (long) 0;
135 @SuppressWarnings("checkstyle:VariableDeclarationUsageDistance")
136 public double retrieveOSNR() {
137 // sum of 1 over the span OSNRs (linear units)
145 // span OSNR, in linear units
147 // default amplifier noise value, in dB
148 double ampNoise = 5.5;
149 // fiber span measured loss, in dB
151 // launch power, in dB
153 double constantA = 38.97293;
154 double constantB = 0.72782;
155 double constantC = -0.532331;
156 double constactD = -0.019549;
157 double upperBoundOSNR = 33;
158 double lowerBoundOSNR = 0.1;
160 if (omsAttributesSpan == null) {
161 // indicates no data or N/A
164 loss = omsAttributesSpan.getSpanlossCurrent().getValue().doubleValue();
165 switch (omsAttributesSpan.getLinkConcatenation().get(0).getFiberType()) {
202 spanOsnrDb = constantA + constantB * power + constantC * loss + constactD * power * loss;
203 if (spanOsnrDb > upperBoundOSNR) {
204 spanOsnrDb = upperBoundOSNR;
205 } else if (spanOsnrDb < lowerBoundOSNR) {
206 spanOsnrDb = lowerBoundOSNR;
208 spanOsnrLu = Math.pow(10, (spanOsnrDb / 10.0));
209 sum = PceConstraints.CONST_OSNR / spanOsnrLu;
211 LOG.debug("In retrieveOSNR: link OSNR is {} dB", linkOsnrLu);
216 public LinkId getOppositeLink() {
217 return this.oppositeLink;
220 public Object getSourceTP() {
221 return this.sourceTP;
224 public Object getDestTP() {
228 public OpenroadmLinkType getLinkType() {
229 return this.linkType;
232 public LinkId getLinkId() {
236 public NodeId getSourceId() {
237 return this.sourceId;
240 public NodeId getDestId() {
244 public String getClient() {
248 public void setClient(String client) {
249 this.client = client;
252 // Double for transformer of JUNG graph
253 public Double getLatency() {
254 return this.latency.doubleValue();
257 public boolean isValid() {
258 if ((this.linkId == null) || (this.linkType == null) || (this.oppositeLink == null)) {
259 this.isValid = false;
260 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", this.linkId);
262 if ((this.sourceId == null) || (this.destId == null) || (this.sourceTP == null) || (this.destTP == null)) {
263 this.isValid = false;
264 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", this.linkId);
271 public String toString() {
272 return "PceLink type=" + this.linkType + " ID=" + this.linkId.toString() + " latecy=" + this.latency;