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
32 // double capacity = 1;
36 private boolean isValid = true;
38 // this member is for XPONDER INPUT/OUTPUT links.
39 // it keeps name of client corresponding 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 LinkId oppositeLink;
49 private final Long latency;
50 private final List<Long> srlg;
51 private final double osnr;
52 private final Span omsAttributesSpan;
54 public PceLink(Link link) {
55 LOG.debug("PceLink: : PceLink start ");
57 this.linkId = link.getLinkId();
59 this.sourceId = link.getSource().getSourceNode();
60 this.destId = link.getDestination().getDestNode();
62 this.sourceTP = link.getSource().getSourceTp();
63 this.destTP = link.getDestination().getDestTp();
65 this.linkType = calcType(link);
67 this.oppositeLink = calcOpposite(link);
68 this.latency = calcLatency(link);
70 if (this.linkType == OpenroadmLinkType.ROADMTOROADM) {
71 this.omsAttributesSpan = MapUtils.getOmsAttributesSpan(link);
72 this.srlg = MapUtils.getSRLG(link);
73 this.osnr = retrieveOSNR();
75 this.omsAttributesSpan = null;
80 LOG.debug("PceLink: created PceLink {}", toString());
83 private OpenroadmLinkType calcType(Link link) {
84 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.@Nullable Link1 link1 = null;
85 OpenroadmLinkType tmplType = null;
88 link1 = link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
92 LOG.error("PceLink: No Link augmentation available. Link is ignored {}", this.linkId);
96 tmplType = link1.getLinkType();
97 if (tmplType == null) {
99 LOG.error("PceLink: No Link type available. Link is ignored {}", this.linkId);
105 private LinkId calcOpposite(Link link) {
107 LinkId tmpoppositeLink = null;
108 Link1 linkOpposite = link.augmentation(Link1.class);
109 if (linkOpposite.getOppositeLink() != null) {
110 tmpoppositeLink = linkOpposite.getOppositeLink();
112 LOG.error("link {} has no opposite link", link.getLinkId().getValue());
114 LOG.debug("PceLink: reading oppositeLink. {}", linkOpposite.toString());
115 if (tmpoppositeLink == null) {
116 this.isValid = false;
117 LOG.error("PceLink: Error reading oppositeLink. Link is ignored {}", this.linkId);
120 return tmpoppositeLink;
123 private Long calcLatency(Link link) {
124 Long tmplatency = (long)0;
127 link1 = link.augmentation(Link1.class);
128 tmplatency = link1.getLinkLatency();
129 if (tmplatency == null) {
130 tmplatency = (long) 0;
136 @SuppressWarnings("checkstyle:VariableDeclarationUsageDistance")
137 public double retrieveOSNR() {
138 // sum of 1 over the span OSNRs (linear units)
146 // span OSNR, in linear units
148 // default amplifier noise value, in dB
149 double ampNoise = 5.5;
150 // fiber span measured loss, in dB
152 // launch power, in dB
154 double constantA = 38.97293;
155 double constantB = 0.72782;
156 double constantC = -0.532331;
157 double constactD = -0.019549;
158 double upperBoundOSNR = 33;
159 double lowerBoundOSNR = 0.1;
161 if (omsAttributesSpan == null) {
162 // indicates no data or N/A
165 loss = omsAttributesSpan.getSpanlossCurrent().getValue().doubleValue();
166 switch (omsAttributesSpan.getLinkConcatenation().get(0).getFiberType()) {
203 spanOsnrDb = constantA + constantB * power + constantC * loss + constactD * power * loss;
204 if (spanOsnrDb > upperBoundOSNR) {
205 spanOsnrDb = upperBoundOSNR;
206 } else if (spanOsnrDb < lowerBoundOSNR) {
207 spanOsnrDb = lowerBoundOSNR;
209 spanOsnrLu = Math.pow(10, (spanOsnrDb / 10.0));
210 sum = PceConstraints.CONST_OSNR / spanOsnrLu;
212 //link_OSNR_dB = 10 * Math.log10(1 / sum);
213 LOG.debug("In retrieveOSNR: link OSNR is {} dB", linkOsnrLu);
218 public LinkId getOppositeLink() {
219 return this.oppositeLink;
222 public Object getSourceTP() {
223 return this.sourceTP;
226 public Object getDestTP() {
230 public OpenroadmLinkType getLinkType() {
231 return this.linkType;
234 public LinkId getLinkId() {
238 public NodeId getSourceId() {
239 return this.sourceId;
242 public NodeId getDestId() {
246 public String getClient() {
250 public void setClient(String client) {
251 this.client = client;
254 // Double for transformer of JUNG graph
255 public Double getLatency() {
256 return this.latency.doubleValue();
259 public boolean isValid() {
260 if ((this.linkId == null) || (this.linkType == null) || (this.oppositeLink == null)) {
261 this.isValid = false;
262 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", this.linkId);
264 if ((this.sourceId == null) || (this.destId == null) || (this.sourceTP == null) || (this.destTP == null)) {
265 this.isValid = false;
266 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", this.linkId);
273 public String toString() {
274 return "PceLink type=" + this.linkType + " ID=" + this.linkId.toString() + " latecy=" + this.latency;