9929b4dc02ba90e0e6052372056dc41b2ca33c8e
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / networkanalyzer / 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.networkanalyzer;
10
11 import java.util.List;
12
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenation.FiberType;
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(PceLink.class);
27     ///////////////////////// LINKS ////////////////////
28     /*
29      * extension of Link to include constraints and Graph weight
30      */
31     double weight = 0;
32     private boolean isValid = true;
33     private boolean isOtnValid = true;
34
35     // this member is for XPONDER INPUT/OUTPUT links.
36     // it keeps name of client corresponding to NETWORK TP
37     private String client = "";
38     private final LinkId linkId;
39     private final OpenroadmLinkType linkType;
40     private final NodeId sourceId;
41     private final NodeId destId;
42     private final Object sourceTP;
43     private final Object destTP;
44     private final String sourceSupNodeId;
45     private final String destSupNodeId;
46     private final String sourceNetworkSupNodeId;
47     private final String destNetworkSupNodeId;
48     private final String sourceCLLI;
49     private final String destCLLI;
50     private final LinkId oppositeLink;
51     private final Long latency;
52     private final Long availableBandwidth;
53     private final List<Long> srlgList;
54     private final double osnr;
55     private final Span omsAttributesSpan;
56     private static final double CELERITY = 2.99792458 * 1e5; //meter per ms
57     private static final double NOISE_MASK_A = 0.571429;
58     private static final double NOISE_MASK_B = 39.285714;
59     private static final double UPPER_BOUND_OSNR = 33;
60     private static final double LOWER_BOUND_OSNR = 0.1;
61
62     public PceLink(Link link, PceNode source, PceNode dest) {
63         LOG.debug("PceLink: : PceLink start ");
64
65         this.linkId = link.getLinkId();
66
67         this.sourceId = link.getSource().getSourceNode();
68         this.destId = link.getDestination().getDestNode();
69
70         this.sourceTP = link.getSource().getSourceTp();
71         this.destTP = link.getDestination().getDestTp();
72
73         this.sourceSupNodeId = source.getSupNodeIdPceNode();
74         this.destSupNodeId = dest.getSupNodeIdPceNode();
75         this.sourceNetworkSupNodeId = source.getSupNetworkNodeIdPceNode();
76         this.destNetworkSupNodeId = dest.getSupNetworkNodeIdPceNode();
77
78         this.sourceCLLI = source.getClliSupNodeId();
79         this.destCLLI = dest.getClliSupNodeId();
80
81         this.linkType = MapUtils.calcType(link);
82
83         this.oppositeLink = calcOpposite(link);
84
85         if (this.linkType == OpenroadmLinkType.ROADMTOROADM) {
86             this.omsAttributesSpan = MapUtils.getOmsAttributesSpan(link);
87             this.srlgList = MapUtils.getSRLG(link);
88             this.latency = calcLatency(link);
89             this.osnr = calcSpanOSNR();
90             this.availableBandwidth = 0L;
91         } else if (this.linkType == OpenroadmLinkType.OTNLINK) {
92             this.availableBandwidth = MapUtils.getAvailableBandwidth(link);
93             this.srlgList = MapUtils.getSRLGfromLink(link);
94             this.osnr = 0.0;
95             this.latency = 0L;
96             this.omsAttributesSpan = null;
97         } else {
98             this.omsAttributesSpan = null;
99             this.srlgList = null;
100             this.latency = 0L;
101             this.osnr = 100L; //infinite OSNR in DB
102             this.availableBandwidth = 0L;
103         }
104         LOG.debug("PceLink: created PceLink  {}", toString());
105     }
106
107     //Retrieve the opposite link
108     private LinkId calcOpposite(Link link) {
109         LinkId tmpoppositeLink = MapUtils.extractOppositeLink(link);
110         if (tmpoppositeLink == null) {
111             LOG.error("PceLink: Error calcOpposite. Link is ignored {}", link.getLinkId().getValue());
112             isValid = false;
113         }
114         return tmpoppositeLink;
115     }
116
117     //Compute the link latency : if the latency is not defined, the latency it is computed from the omsAttributesSpan
118     private Long calcLatency(Link link) {
119         Link1 link1 = null;
120         link1 = link.augmentation(Link1.class);
121         Long tmplatency = link1.getLinkLatency();
122         if (tmplatency != null) {
123             return tmplatency;
124         }
125
126         try {
127             double tmp = 0;
128             for (int i = 0; i < this.omsAttributesSpan.getLinkConcatenation().size(); i++) {
129                 //Length is expressed in meter and latency is expressed in ms according to OpenROADM MSA
130                 tmp += this.omsAttributesSpan.getLinkConcatenation().get(i).getSRLGLength() / CELERITY;
131                 LOG.info("In PceLink: The latency of link {} == {}",link.getLinkId(),tmplatency);
132             }
133             tmplatency = (long) Math.ceil(tmp);
134         } catch (NullPointerException e) {
135             LOG.debug("In PceLink: cannot compute the latency for the link {}",link.getLinkId().getValue());
136             tmplatency = 1L;
137         }
138         return tmplatency;
139     }
140
141     //Compute the OSNR of a span
142     public double calcSpanOSNR() {
143         try {
144             double pout; //power on the output of the previous ROADM (dBm)
145             pout = retrievePower(this.omsAttributesSpan.getLinkConcatenation().get(0).getFiberType());
146             double spanLoss = this.omsAttributesSpan.getSpanlossCurrent().getValue().doubleValue(); // span loss (dB)
147             double pin = pout - spanLoss; //power on the input of the current ROADM (dBm)
148             double spanOsnrDb;
149             spanOsnrDb = NOISE_MASK_A * pin + NOISE_MASK_B;
150             if (spanOsnrDb > UPPER_BOUND_OSNR) {
151                 spanOsnrDb =  UPPER_BOUND_OSNR;
152             } else if (spanOsnrDb < LOWER_BOUND_OSNR) {
153                 spanOsnrDb = LOWER_BOUND_OSNR;
154             }
155             return spanOsnrDb;
156         } catch (NullPointerException e) {
157             LOG.error("in PceLink : Null field in the OmsAttrubtesSpan");
158             return 0L;
159         }
160     }
161
162     private double retrievePower(FiberType fiberType) {
163         double power;
164         switch (fiberType) {
165             case Smf:
166                 power = 2;
167                 break;
168             case Eleaf:
169                 power = 1;
170                 break;
171             case Truewavec:
172                 power = -1;
173                 break;
174             case Oleaf:
175             case Dsf:
176             case Truewave:
177             case NzDsf:
178             case Ull:
179             default:
180                 power = 0;
181                 break;
182         }
183         return power;
184     }
185
186     public LinkId getOppositeLink() {
187         return oppositeLink;
188     }
189
190     public Object getSourceTP() {
191         return sourceTP;
192     }
193
194     public Object getDestTP() {
195         return destTP;
196     }
197
198     public OpenroadmLinkType getlinkType() {
199         return linkType;
200     }
201
202     public LinkId getLinkId() {
203         return linkId;
204     }
205
206     public NodeId getSourceId() {
207         return sourceId;
208     }
209
210     public NodeId getDestId() {
211         return destId;
212     }
213
214     public String getClient() {
215         return client;
216     }
217
218     public void setClient(String client) {
219         this.client = client;
220     }
221
222     // Double for transformer of JUNG graph
223     public Double getLatency() {
224         return latency.doubleValue();
225     }
226
227     public Long getAvailableBandwidth() {
228         return availableBandwidth;
229     }
230
231
232     public String getsourceSupNodeId() {
233         return sourceSupNodeId;
234     }
235
236     public String getsourceNetworkSupNodeId() {
237         return sourceNetworkSupNodeId;
238     }
239
240     public String getdestSupNodeId() {
241         return destSupNodeId;
242     }
243
244     public String getdestNetworkSupNodeId() {
245         return destNetworkSupNodeId;
246     }
247
248     public List<Long> getsrlgList() {
249         return srlgList;
250     }
251
252     public double getosnr() {
253         return osnr;
254     }
255
256     public String getsourceCLLI() {
257         return sourceCLLI;
258     }
259
260     public String getdestCLLI() {
261         return destCLLI;
262     }
263
264     public boolean isValid() {
265         if ((this.linkId == null) || (this.linkType == null)
266                 || (this.oppositeLink == null)) {
267             isValid = false;
268             LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", linkId);
269         }
270         if ((this.sourceId == null) || (this.destId == null)
271                 || (this.sourceTP == null) || (this.destTP == null)) {
272             isValid = false;
273             LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", linkId);
274         }
275         if ((this.sourceSupNodeId.equals("")) || (this.destSupNodeId.equals(""))) {
276             isValid = false;
277             LOG.error("PceLink: No Link source SuppNodeID or destination SuppNodeID is available. Link is ignored {}",
278                 linkId);
279         }
280         if ((this.sourceCLLI.equals("")) || (this.destCLLI.equals(""))) {
281             isValid = false;
282             LOG.error("PceLink: No Link source CLLI or destination CLLI is available. Link is ignored {}", linkId);
283         }
284         if ((this.omsAttributesSpan == null) && (this.linkType == OpenroadmLinkType.ROADMTOROADM)) {
285             isValid = false;
286             LOG.error("PceLink: Error reading Span for OMS link. Link is ignored {}", linkId);
287         }
288         if ((this.srlgList != null) && (this.srlgList.isEmpty())) {
289             isValid = false;
290             LOG.error("PceLink: Empty srlgList for OMS link. Link is ignored {}", linkId);
291         }
292         return isValid;
293     }
294
295     public boolean isOtnValid(Link link, String oduType) {
296         if (this.linkType == OpenroadmLinkType.OTNLINK) {
297             isOtnValid = false;
298             Long availableBW = MapUtils.getAvailableBandwidth(link);
299             if ((availableBW == 0L) || (availableBW == null)) {
300                 LOG.error("PceLink: No bandwidth available or not valid OTN Link, Link {}  is ignored ", linkId);
301             } else if (("ODU4".equals(oduType)) && (availableBW == 100000L)) {
302                 isOtnValid = true;
303                 LOG.debug("PceLink: Selected OTU4 Link {} is eligible for ODU creation OTN Link", linkId);
304             } else if (("ODU2".equals(oduType)) || ("ODU2e".equals(oduType)) && (availableBW >= 12500L)) {
305                 isOtnValid = true;
306                 LOG.debug("PceLink: Selected ODU4 Link {} has available bandwidth and is eligible for {} creation ",
307                     linkId, oduType);
308             } else if (("ODU0".equals(oduType)) && (availableBW >= 1250L)) {
309                 isOtnValid = true;
310                 LOG.debug("PceLink: Selected ODU4 Link {} has available bandwidth and is eligible for {} creation ",
311                     linkId, oduType);
312             } else if (("ODU1".equals(oduType)) && (availableBW >= 2500L)) {
313                 isOtnValid = true;
314                 LOG.debug("PceLink: Selected ODU4 Link {} has available bandwidth and is eligible for {} creation ",
315                     linkId, oduType);
316             } else {
317                 isOtnValid = false;
318                 LOG.error(
319                     "PceLink: Selected OTN Link {} is not eligible for ODU creation: not enough available bandwidth",
320                     linkId);
321             }
322
323         } else {
324             isOtnValid = false;
325             LOG.error("PceLink: Not an OTN link. Link is ignored {}", linkId);
326         }
327
328         if ((this.linkId == null) || (this.linkType == null)
329                 || (this.oppositeLink == null)) {
330             isOtnValid = false;
331             LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", linkId);
332         }
333         if ((this.sourceId == null) || (this.destId == null)
334                 || (this.sourceTP == null) || (this.destTP == null)) {
335             isOtnValid = false;
336             LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", linkId);
337         }
338         if ((this.sourceNetworkSupNodeId.equals("")) || (this.destNetworkSupNodeId.equals(""))) {
339             isOtnValid = false;
340             LOG.error("PceLink: No Link source SuppNodeID or destination SuppNodeID is available. Link is ignored {}",
341                 linkId);
342         }
343         if ((this.sourceCLLI.equals("")) || (this.destCLLI.equals(""))) {
344             isOtnValid = false;
345             LOG.error("PceLink: No Link source CLLI or destination CLLI is available. Link is ignored {}", linkId);
346         }
347
348         return isOtnValid;
349     }
350
351     public String toString() {
352         return "PceLink type=" + linkType + " ID=" + linkId.getValue() + " latency=" + latency;
353     }
354
355 }