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.http.transportpce.topology.rev200129.OtnLinkType;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 public class PceLink {
27 private static final Logger LOG = LoggerFactory.getLogger(PceLink.class);
28 ///////////////////////// LINKS ////////////////////
30 * extension of Link to include constraints and Graph weight
33 private boolean isValid = true;
34 private boolean isOtnValid = true;
36 // this member is for XPONDER INPUT/OUTPUT links.
37 // it keeps name of client corresponding to NETWORK TP
38 private String client = "";
39 private final LinkId linkId;
40 private final OpenroadmLinkType linkType;
41 private final NodeId sourceId;
42 private final NodeId destId;
43 private final Object sourceTP;
44 private final Object destTP;
45 private final String sourceNetworkSupNodeId;
46 private final String destNetworkSupNodeId;
47 private final String sourceCLLI;
48 private final String destCLLI;
49 private final LinkId oppositeLink;
50 private final Long latency;
51 private final Long availableBandwidth;
52 private final Long usedBandwidth;
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.info("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.sourceNetworkSupNodeId = source.getSupNetworkNodeId();
74 this.destNetworkSupNodeId = dest.getSupNetworkNodeId();
76 this.sourceCLLI = source.getSupClliNodeId();
77 this.destCLLI = dest.getSupClliNodeId();
79 this.linkType = MapUtils.calcType(link);
81 this.oppositeLink = calcOpposite(link);
83 if (this.linkType == OpenroadmLinkType.ROADMTOROADM) {
84 this.omsAttributesSpan = MapUtils.getOmsAttributesSpan(link);
85 this.srlgList = MapUtils.getSRLG(link);
86 this.latency = calcLatency(link);
87 this.osnr = calcSpanOSNR();
88 this.availableBandwidth = 0L;
89 this.usedBandwidth = 0L;
90 } else if (this.linkType == OpenroadmLinkType.OTNLINK) {
91 this.availableBandwidth = MapUtils.getAvailableBandwidth(link);
92 this.usedBandwidth = MapUtils.getUsedBandwidth(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;
103 this.usedBandwidth = 0L;
105 LOG.debug("PceLink: created PceLink {}", toString());
108 //Retrieve the opposite link
109 private LinkId calcOpposite(Link link) {
110 LinkId tmpoppositeLink = MapUtils.extractOppositeLink(link);
111 if (tmpoppositeLink == null) {
112 LOG.error("PceLink: Error calcOpposite. Link is ignored {}", link.getLinkId().getValue());
115 return tmpoppositeLink;
118 //Compute the link latency : if the latency is not defined, the latency it is computed from the omsAttributesSpan
119 private Long calcLatency(Link link) {
121 link1 = link.augmentation(Link1.class);
122 Long tmplatency = link1.getLinkLatency();
123 if (tmplatency != null) {
129 for (int i = 0; i < this.omsAttributesSpan.getLinkConcatenation().size(); i++) {
130 //Length is expressed in meter and latency is expressed in ms according to OpenROADM MSA
131 tmp += this.omsAttributesSpan.getLinkConcatenation().get(i).getSRLGLength() / CELERITY;
132 LOG.info("In PceLink: The latency of link {} == {}",link.getLinkId(),tmplatency);
134 tmplatency = (long) Math.ceil(tmp);
135 } catch (NullPointerException e) {
136 LOG.debug("In PceLink: cannot compute the latency for the link {}",link.getLinkId().getValue());
142 //Compute the OSNR of a span
143 public double calcSpanOSNR() {
145 double pout; //power on the output of the previous ROADM (dBm)
146 pout = retrievePower(this.omsAttributesSpan.getLinkConcatenation().get(0).getFiberType());
147 double spanLoss = this.omsAttributesSpan.getSpanlossCurrent().getValue().doubleValue(); // span loss (dB)
148 double pin = pout - spanLoss; //power on the input of the current ROADM (dBm)
150 spanOsnrDb = NOISE_MASK_A * pin + NOISE_MASK_B;
151 if (spanOsnrDb > UPPER_BOUND_OSNR) {
152 spanOsnrDb = UPPER_BOUND_OSNR;
153 } else if (spanOsnrDb < LOWER_BOUND_OSNR) {
154 spanOsnrDb = LOWER_BOUND_OSNR;
157 } catch (NullPointerException e) {
158 LOG.error("in PceLink : Null field in the OmsAttrubtesSpan");
163 private double retrievePower(FiberType fiberType) {
187 public LinkId getOppositeLink() {
191 public Object getSourceTP() {
195 public Object getDestTP() {
199 public OpenroadmLinkType getlinkType() {
203 public LinkId getLinkId() {
207 public NodeId getSourceId() {
211 public NodeId getDestId() {
215 public String getClient() {
219 public void setClient(String client) {
220 this.client = client;
223 // Double for transformer of JUNG graph
224 public Double getLatency() {
225 return latency.doubleValue();
228 public Long getAvailableBandwidth() {
229 return availableBandwidth;
232 public Long getUsedBandwidth() {
233 return availableBandwidth;
236 public String getsourceNetworkSupNodeId() {
237 return sourceNetworkSupNodeId;
240 public String getdestNetworkSupNodeId() {
241 return destNetworkSupNodeId;
244 public List<Long> getsrlgList() {
248 public double getosnr() {
252 public String getsourceCLLI() {
256 public String getdestCLLI() {
260 public boolean isValid() {
261 if ((this.linkId == null) || (this.linkType == null) || (this.oppositeLink == null)) {
263 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", linkId);
265 if ((this.sourceId == null) || (this.destId == null) || (this.sourceTP == null) || (this.destTP == null)) {
267 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", linkId);
269 if ((this.sourceNetworkSupNodeId.equals("")) || (this.destNetworkSupNodeId.equals(""))) {
271 LOG.error("PceLink: No Link source SuppNodeID or destination SuppNodeID is available. Link is ignored {}",
274 if ((this.sourceCLLI.equals("")) || (this.destCLLI.equals(""))) {
276 LOG.error("PceLink: No Link source CLLI or destination CLLI is available. Link is ignored {}", linkId);
278 if ((this.omsAttributesSpan == null) && (this.linkType == OpenroadmLinkType.ROADMTOROADM)) {
280 LOG.error("PceLink: Error reading Span for OMS link. Link is ignored {}", linkId);
282 if ((this.srlgList != null) && (this.srlgList.isEmpty())) {
284 LOG.error("PceLink: Empty srlgList for OMS link. Link is ignored {}", linkId);
289 public boolean isOtnValid(Link link, String serviceType) {
291 if (this.linkType != OpenroadmLinkType.OTNLINK) {
292 LOG.error("PceLink: Not an OTN link. Link is ignored {}", linkId);
296 OtnLinkType otnLinkType = link
297 .augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129.Link1.class)
299 if (this.availableBandwidth == 0L) {
300 LOG.error("PceLink: No bandwidth available for OTN Link, link {} is ignored ", linkId);
305 OtnLinkType neededType = null;
306 switch (serviceType) {
309 if (this.usedBandwidth != 0L) {
313 neededType = OtnLinkType.OTU4;
327 neededType = OtnLinkType.ODTU4;
331 neededType = OtnLinkType.ODTU4;
334 LOG.error("PceLink: isOtnValid Link {} unsupported serviceType {} ", linkId, serviceType);
338 if ((this.availableBandwidth >= neededBW)
339 && ((neededType == null) || (neededType.equals(otnLinkType)))) {
340 LOG.info("PceLink: Selected Link {} has available bandwidth and is eligible for {} creation ",
341 linkId, serviceType);
344 if ((this.linkId == null) || (this.linkType == null) || (this.oppositeLink == null)) {
345 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", linkId);
348 if ((this.sourceId == null) || (this.destId == null) || (this.sourceTP == null) || (this.destTP == null)) {
349 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", linkId);
352 if ((this.sourceNetworkSupNodeId.equals("")) || (this.destNetworkSupNodeId.equals(""))) {
353 LOG.error("PceLink: No Link source SuppNodeID or destination SuppNodeID is available. Link is ignored {}",
357 if ((this.sourceCLLI.equals("")) || (this.destCLLI.equals(""))) {
358 LOG.error("PceLink: No Link source CLLI or destination CLLI is available. Link is ignored {}", linkId);
365 public String toString() {
366 return "PceLink type=" + linkType + " ID=" + linkId.getValue() + " latency=" + latency;