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 is computed from the omsAttributesSpan
119 private Long calcLatency(Link link) {
122 link1 = link.augmentation(Link1.class);
123 if (link1.getLinkLatency() != null) {
124 tmplatency = link1.getLinkLatency().toJava();
130 for (int i = 0; i < this.omsAttributesSpan.getLinkConcatenation().size(); i++) {
131 //Length is expressed in meter and latency is expressed in ms according to OpenROADM MSA
132 tmp += this.omsAttributesSpan.getLinkConcatenation().get(i).getSRLGLength().toJava() / CELERITY;
133 LOG.info("In PceLink: The latency of link {} == {}",link.getLinkId(),tmp);
135 tmplatency = (long) Math.ceil(tmp);
136 } catch (NullPointerException e) {
137 LOG.debug("In PceLink: cannot compute the latency for the link {}",link.getLinkId().getValue());
143 //Compute the OSNR of a span
144 public double calcSpanOSNR() {
146 double pout; //power on the output of the previous ROADM (dBm)
147 pout = retrievePower(this.omsAttributesSpan.getLinkConcatenation().get(0).getFiberType());
148 double spanLoss = this.omsAttributesSpan.getSpanlossCurrent().getValue().doubleValue(); // span loss (dB)
149 double pin = pout - spanLoss; //power on the input of the current ROADM (dBm)
151 spanOsnrDb = NOISE_MASK_A * pin + NOISE_MASK_B;
152 if (spanOsnrDb > UPPER_BOUND_OSNR) {
153 spanOsnrDb = UPPER_BOUND_OSNR;
154 } else if (spanOsnrDb < LOWER_BOUND_OSNR) {
155 spanOsnrDb = LOWER_BOUND_OSNR;
158 } catch (NullPointerException e) {
159 LOG.error("in PceLink : Null field in the OmsAttrubtesSpan");
164 private double retrievePower(FiberType fiberType) {
188 public LinkId getOppositeLink() {
192 public Object getSourceTP() {
196 public Object getDestTP() {
200 public OpenroadmLinkType getlinkType() {
204 public LinkId getLinkId() {
208 public NodeId getSourceId() {
212 public NodeId getDestId() {
216 public String getClient() {
220 public void setClient(String client) {
221 this.client = client;
224 // Double for transformer of JUNG graph
225 public Double getLatency() {
226 return latency.doubleValue();
229 public Long getAvailableBandwidth() {
230 return availableBandwidth;
233 public Long getUsedBandwidth() {
234 return availableBandwidth;
237 public String getsourceNetworkSupNodeId() {
238 return sourceNetworkSupNodeId;
241 public String getdestNetworkSupNodeId() {
242 return destNetworkSupNodeId;
245 public List<Long> getsrlgList() {
249 public double getosnr() {
253 public String getsourceCLLI() {
257 public String getdestCLLI() {
261 public boolean isValid() {
262 if ((this.linkId == null) || (this.linkType == null) || (this.oppositeLink == null)) {
264 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", linkId);
266 if ((this.sourceId == null) || (this.destId == null) || (this.sourceTP == null) || (this.destTP == null)) {
268 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", linkId);
270 if ((this.sourceNetworkSupNodeId.equals("")) || (this.destNetworkSupNodeId.equals(""))) {
272 LOG.error("PceLink: No Link source SuppNodeID or destination SuppNodeID is available. Link is ignored {}",
275 if ((this.sourceCLLI.equals("")) || (this.destCLLI.equals(""))) {
277 LOG.error("PceLink: No Link source CLLI or destination CLLI is available. Link is ignored {}", linkId);
279 if ((this.omsAttributesSpan == null) && (this.linkType == OpenroadmLinkType.ROADMTOROADM)) {
281 LOG.error("PceLink: Error reading Span for OMS link. Link is ignored {}", linkId);
283 if ((this.srlgList != null) && (this.srlgList.isEmpty())) {
285 LOG.error("PceLink: Empty srlgList for OMS link. Link is ignored {}", linkId);
290 public boolean isOtnValid(Link link, String serviceType) {
292 if (this.linkType != OpenroadmLinkType.OTNLINK) {
293 LOG.error("PceLink: Not an OTN link. Link is ignored {}", linkId);
297 OtnLinkType otnLinkType = link
298 .augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129.Link1.class)
300 if (this.availableBandwidth == 0L) {
301 LOG.error("PceLink: No bandwidth available for OTN Link, link {} is ignored ", linkId);
306 OtnLinkType neededType = null;
307 switch (serviceType) {
310 if (this.usedBandwidth != 0L) {
314 neededType = OtnLinkType.OTU4;
328 neededType = OtnLinkType.ODTU4;
332 neededType = OtnLinkType.ODTU4;
335 LOG.error("PceLink: isOtnValid Link {} unsupported serviceType {} ", linkId, serviceType);
339 if ((this.availableBandwidth >= neededBW)
340 && ((neededType == null) || (neededType.equals(otnLinkType)))) {
341 LOG.info("PceLink: Selected Link {} has available bandwidth and is eligible for {} creation ",
342 linkId, serviceType);
345 if ((this.linkId == null) || (this.linkType == null) || (this.oppositeLink == null)) {
346 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", linkId);
349 if ((this.sourceId == null) || (this.destId == null) || (this.sourceTP == null) || (this.destTP == null)) {
350 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", linkId);
353 if ((this.sourceNetworkSupNodeId.equals("")) || (this.destNetworkSupNodeId.equals(""))) {
354 LOG.error("PceLink: No Link source SuppNodeID or destination SuppNodeID is available. Link is ignored {}",
358 if ((this.sourceCLLI.equals("")) || (this.destCLLI.equals(""))) {
359 LOG.error("PceLink: No Link source CLLI or destination CLLI is available. Link is ignored {}", linkId);
366 public String toString() {
367 return "PceLink type=" + linkType + " ID=" + linkId.getValue() + " latency=" + latency;