remove dead code pointed out by sonar
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / PceLink.java
1 /*
2  * Copyright © 2017 AT&T, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.transportpce.pce;
10
11 import java.util.List;
12
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;
22
23 public class PceLink {
24
25     /* Logging. */
26     private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
27
28     ///////////////////////// LINKS ////////////////////
29     /*
30      * extension of Link to include constraints and Graph weight
31      */
32
33     double weight = 0;
34
35     private boolean isValid = true;
36
37     // this member is for XPONDER INPUT/OUTPUT links.
38     // it keeps name of client corresponding to NETWORK TP
39     private String client = "";
40
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;
52
53     public PceLink(Link link) {
54         LOG.debug("PceLink: : PceLink start ");
55
56         this.linkId = link.getLinkId();
57
58         this.sourceId = link.getSource().getSourceNode();
59         this.destId = link.getDestination().getDestNode();
60
61         this.sourceTP = link.getSource().getSourceTp();
62         this.destTP = link.getDestination().getDestTp();
63
64         this.linkType = calcType(link);
65
66         this.oppositeLink = calcOpposite(link);
67         this.latency = calcLatency(link);
68
69         if (this.linkType == OpenroadmLinkType.ROADMTOROADM) {
70             this.omsAttributesSpan = MapUtils.getOmsAttributesSpan(link);
71             this.srlg = MapUtils.getSRLG(link);
72             this.osnr = retrieveOSNR();
73         } else {
74             this.omsAttributesSpan = null;
75             this.srlg = null;
76             this.osnr = 0L;
77         }
78
79         LOG.debug("PceLink: created PceLink  {}", toString());
80     }
81
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;
85
86         // ID and type
87         link1 = link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
88             .Link1.class);
89         if (link1 == null) {
90             this.isValid = false;
91             LOG.error("PceLink: No Link augmentation available. Link is ignored {}", this.linkId);
92             return null;
93         }
94
95         tmplType = link1.getLinkType();
96         if (tmplType == null) {
97             this.isValid = false;
98             LOG.error("PceLink: No Link type available. Link is ignored {}", this.linkId);
99             return null;
100         }
101         return tmplType;
102     }
103
104     private LinkId calcOpposite(Link link) {
105         // opposite link
106         LinkId tmpoppositeLink = null;
107         Link1 linkOpposite = link.augmentation(Link1.class);
108         if (linkOpposite.getOppositeLink() != null) {
109             tmpoppositeLink = linkOpposite.getOppositeLink();
110         } else {
111             LOG.error("link {} has no opposite link", link.getLinkId().getValue());
112         }
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);
117             return null;
118         }
119         return tmpoppositeLink;
120     }
121
122     private Long calcLatency(Link link) {
123         Long tmplatency = (long)0;
124         Link1 link1 = null;
125         // latency
126         link1 = link.augmentation(Link1.class);
127         tmplatency = link1.getLinkLatency();
128         if (tmplatency == null) {
129             tmplatency = (long) 0;
130         }
131         return tmplatency;
132
133     }
134
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;
151
152         if (omsAttributesSpan ==  null) {
153             return 0L; // indicates no data or N/A
154         }
155         loss = omsAttributesSpan.getSpanlossCurrent().getValue().doubleValue();
156         switch (omsAttributesSpan.getLinkConcatenation().get(0).getFiberType()) {
157             case Smf:
158                 power = 2;
159                 break;
160
161             case Eleaf:
162                 power = 1;
163                 break;
164
165             case Oleaf:
166                 power = 0;
167                 break;
168
169             case Dsf:
170                 power = 0;
171                 break;
172
173             case Truewave:
174                 power = 0;
175                 break;
176
177             case Truewavec:
178                 power = -1;
179                 break;
180
181             case NzDsf:
182                 power = 0;
183                 break;
184
185             case Ull:
186                 power = 0;
187                 break;
188
189             default:
190                 power = 0;
191                 break;
192         }
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;
198         }
199         spanOsnrLu = Math.pow(10, (spanOsnrDb / 10.0));
200         sum = PceConstraints.CONST_OSNR / spanOsnrLu;
201         linkOsnrLu = sum;
202         LOG.debug("In retrieveOSNR: link OSNR is {} dB", linkOsnrLu);
203         return linkOsnrLu;
204     }
205
206
207     public LinkId getOppositeLink() {
208         return this.oppositeLink;
209     }
210
211     public Object getSourceTP() {
212         return this.sourceTP;
213     }
214
215     public Object getDestTP() {
216         return this.destTP;
217     }
218
219     public OpenroadmLinkType getLinkType() {
220         return this.linkType;
221     }
222
223     public LinkId getLinkId() {
224         return this.linkId;
225     }
226
227     public NodeId getSourceId() {
228         return this.sourceId;
229     }
230
231     public NodeId getDestId() {
232         return this.destId;
233     }
234
235     public String getClient() {
236         return this.client;
237     }
238
239     public void setClient(String client) {
240         this.client = client;
241     }
242
243     // Double for transformer of JUNG graph
244     public Double getLatency() {
245         return this.latency.doubleValue();
246     }
247
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);
252         }
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);
256         }
257
258         return this.isValid;
259     }
260
261     @Override
262     public String toString() {
263         return "PceLink type=" + this.linkType + " ID=" + this.linkId.toString() + " latecy=" + this.latency;
264     }
265
266 }