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 double sum = 0; // sum of 1 over the span OSNRs (linear units)
138 double linkOsnrDb; // link OSNR, in dB
139 double linkOsnrLu; // link OSNR, in dB
140 double spanOsnrDb; // span OSNR, in dB
141 double spanOsnrLu; // span OSNR, in linear units
142 double ampNoise = 5.5; // default amplifier noise value, in dB
143 double loss; // fiber span measured loss, in dB
144 double power; // launch power, in dB
145 double constantA = 38.97293;
146 double constantB = 0.72782;
147 double constantC = -0.532331;
148 double constactD = -0.019549;
149 double upperBoundOSNR = 33;
150 double lowerBoundOSNR = 0.1;
152 if (omsAttributesSpan == null) {
153 return 0L; // indicates no data or N/A
155 loss = omsAttributesSpan.getSpanlossCurrent().getValue().doubleValue();
156 switch (omsAttributesSpan.getLinkConcatenation().get(0).getFiberType()) {
193 spanOsnrDb = constantA + constantB * power + constantC * loss + constactD * power * loss;
194 if (spanOsnrDb > upperBoundOSNR) {
195 spanOsnrDb = upperBoundOSNR;
196 } else if (spanOsnrDb < lowerBoundOSNR) {
197 spanOsnrDb = lowerBoundOSNR;
199 spanOsnrLu = Math.pow(10, (spanOsnrDb / 10.0));
200 sum = PceConstraints.CONST_OSNR / spanOsnrLu;
202 LOG.debug("In retrieveOSNR: link OSNR is {} dB", linkOsnrLu);
207 public LinkId getOppositeLink() {
208 return this.oppositeLink;
211 public Object getSourceTP() {
212 return this.sourceTP;
215 public Object getDestTP() {
219 public OpenroadmLinkType getLinkType() {
220 return this.linkType;
223 public LinkId getLinkId() {
227 public NodeId getSourceId() {
228 return this.sourceId;
231 public NodeId getDestId() {
235 public String getClient() {
239 public void setClient(String client) {
240 this.client = client;
243 // Double for transformer of JUNG graph
244 public Double getLatency() {
245 return this.latency.doubleValue();
248 public boolean isValid() {
249 if ((this.linkId == null) || (this.linkType == null) || (this.oppositeLink == null)) {
250 this.isValid = false;
251 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", this.linkId);
253 if ((this.sourceId == null) || (this.destId == null) || (this.sourceTP == null) || (this.destTP == null)) {
254 this.isValid = false;
255 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", this.linkId);
262 public String toString() {
263 return "PceLink type=" + this.linkType + " ID=" + this.linkId.toString() + " latecy=" + this.latency;