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.networkanalyzer;
11 import java.util.List;
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;
23 public class PceLink {
26 private static final Logger LOG = LoggerFactory.getLogger(PceLink.class);
27 ///////////////////////// LINKS ////////////////////
29 * extension of Link to include constraints and Graph weight
32 private boolean isValid = true;
33 private boolean isOtnValid = true;
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;
62 public PceLink(Link link, PceNode source, PceNode dest) {
63 LOG.debug("PceLink: : PceLink start ");
65 this.linkId = link.getLinkId();
67 this.sourceId = link.getSource().getSourceNode();
68 this.destId = link.getDestination().getDestNode();
70 this.sourceTP = link.getSource().getSourceTp();
71 this.destTP = link.getDestination().getDestTp();
73 this.sourceSupNodeId = source.getSupNodeIdPceNode();
74 this.destSupNodeId = dest.getSupNodeIdPceNode();
75 this.sourceNetworkSupNodeId = source.getSupNetworkNodeIdPceNode();
76 this.destNetworkSupNodeId = dest.getSupNetworkNodeIdPceNode();
78 this.sourceCLLI = source.getClliSupNodeId();
79 this.destCLLI = dest.getClliSupNodeId();
81 this.linkType = MapUtils.calcType(link);
83 this.oppositeLink = calcOpposite(link);
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);
96 this.omsAttributesSpan = null;
98 this.omsAttributesSpan = null;
101 this.osnr = 100L; //infinite OSNR in DB
102 this.availableBandwidth = 0L;
104 LOG.debug("PceLink: created PceLink {}", toString());
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());
114 return tmpoppositeLink;
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) {
120 link1 = link.augmentation(Link1.class);
121 Long tmplatency = link1.getLinkLatency();
122 if (tmplatency != null) {
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);
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());
141 //Compute the OSNR of a span
142 public double calcSpanOSNR() {
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)
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;
156 } catch (NullPointerException e) {
157 LOG.error("in PceLink : Null field in the OmsAttrubtesSpan");
162 private double retrievePower(FiberType fiberType) {
186 public LinkId getOppositeLink() {
190 public Object getSourceTP() {
194 public Object getDestTP() {
198 public OpenroadmLinkType getlinkType() {
202 public LinkId getLinkId() {
206 public NodeId getSourceId() {
210 public NodeId getDestId() {
214 public String getClient() {
218 public void setClient(String client) {
219 this.client = client;
222 // Double for transformer of JUNG graph
223 public Double getLatency() {
224 return latency.doubleValue();
227 public Long getAvailableBandwidth() {
228 return availableBandwidth;
232 public String getsourceSupNodeId() {
233 return sourceSupNodeId;
236 public String getsourceNetworkSupNodeId() {
237 return sourceNetworkSupNodeId;
240 public String getdestSupNodeId() {
241 return destSupNodeId;
244 public String getdestNetworkSupNodeId() {
245 return destNetworkSupNodeId;
248 public List<Long> getsrlgList() {
252 public double getosnr() {
256 public String getsourceCLLI() {
260 public String getdestCLLI() {
264 public boolean isValid() {
265 if ((this.linkId == null) || (this.linkType == null)
266 || (this.oppositeLink == null)) {
268 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", linkId);
270 if ((this.sourceId == null) || (this.destId == null)
271 || (this.sourceTP == null) || (this.destTP == null)) {
273 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", linkId);
275 if ((this.sourceSupNodeId.equals("")) || (this.destSupNodeId.equals(""))) {
277 LOG.error("PceLink: No Link source SuppNodeID or destination SuppNodeID is available. Link is ignored {}",
280 if ((this.sourceCLLI.equals("")) || (this.destCLLI.equals(""))) {
282 LOG.error("PceLink: No Link source CLLI or destination CLLI is available. Link is ignored {}", linkId);
284 if ((this.omsAttributesSpan == null) && (this.linkType == OpenroadmLinkType.ROADMTOROADM)) {
286 LOG.error("PceLink: Error reading Span for OMS link. Link is ignored {}", linkId);
288 if ((this.srlgList != null) && (this.srlgList.isEmpty())) {
290 LOG.error("PceLink: Empty srlgList for OMS link. Link is ignored {}", linkId);
295 public boolean isOtnValid(Link link, String oduType) {
296 if (this.linkType == OpenroadmLinkType.OTNLINK) {
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)) {
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)) {
306 LOG.debug("PceLink: Selected ODU4 Link {} has available bandwidth and is eligible for {} creation ",
308 } else if (("ODU0".equals(oduType)) && (availableBW >= 1250L)) {
310 LOG.debug("PceLink: Selected ODU4 Link {} has available bandwidth and is eligible for {} creation ",
312 } else if (("ODU1".equals(oduType)) && (availableBW >= 2500L)) {
314 LOG.debug("PceLink: Selected ODU4 Link {} has available bandwidth and is eligible for {} creation ",
319 "PceLink: Selected OTN Link {} is not eligible for ODU creation: not enough available bandwidth",
325 LOG.error("PceLink: Not an OTN link. Link is ignored {}", linkId);
328 if ((this.linkId == null) || (this.linkType == null)
329 || (this.oppositeLink == null)) {
331 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", linkId);
333 if ((this.sourceId == null) || (this.destId == null)
334 || (this.sourceTP == null) || (this.destTP == null)) {
336 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", linkId);
338 if ((this.sourceNetworkSupNodeId.equals("")) || (this.destNetworkSupNodeId.equals(""))) {
340 LOG.error("PceLink: No Link source SuppNodeID or destination SuppNodeID is available. Link is ignored {}",
343 if ((this.sourceCLLI.equals("")) || (this.destCLLI.equals(""))) {
345 LOG.error("PceLink: No Link source CLLI or destination CLLI is available. Link is ignored {}", linkId);
351 public String toString() {
352 return "PceLink type=" + linkType + " ID=" + linkId.getValue() + " latency=" + latency;