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.io.IOException;
12 import java.io.ObjectInputStream;
13 import java.io.ObjectOutputStream;
14 import java.io.Serializable;
15 import java.util.List;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenation;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenation.FiberType;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenationKey;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.link.oms.attributes.Span;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType;
24 import org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129.OtnLinkType;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class PceLink implements Serializable {
33 private static final long serialVersionUID = 1L;
35 private static final Logger LOG = LoggerFactory.getLogger(PceLink.class);
36 ///////////////////////// LINKS ////////////////////
38 * extension of Link to include constraints and Graph weight
41 private boolean isValid = true;
42 private boolean isOtnValid = true;
44 // this member is for XPONDER INPUT/OUTPUT links.
45 // it keeps name of client corresponding to NETWORK TP
46 private String client = "";
47 private final LinkId linkId;
48 private final OpenroadmLinkType linkType;
49 private final NodeId sourceId;
50 private final NodeId destId;
51 private transient Object sourceTP;
52 private transient Object destTP;
53 private final String sourceNetworkSupNodeId;
54 private final String destNetworkSupNodeId;
55 private final String sourceCLLI;
56 private final String destCLLI;
57 private final LinkId oppositeLink;
58 private final Long latency;
59 private final Long availableBandwidth;
60 private final Long usedBandwidth;
61 private final List<Long> srlgList;
62 private final double osnr;
63 private final transient Span omsAttributesSpan;
64 private static final double CELERITY = 2.99792458 * 1e5; //meter per ms
65 private static final double NOISE_MASK_A = 0.571429;
66 private static final double NOISE_MASK_B = 39.285714;
67 private static final double UPPER_BOUND_OSNR = 33;
68 private static final double LOWER_BOUND_OSNR = 0.1;
70 public PceLink(Link link, PceNode source, PceNode dest) {
71 LOG.info("PceLink: : PceLink start ");
73 this.linkId = link.getLinkId();
75 this.sourceId = link.getSource().getSourceNode();
76 this.destId = link.getDestination().getDestNode();
78 this.sourceTP = link.getSource().getSourceTp();
79 this.destTP = link.getDestination().getDestTp();
81 this.sourceNetworkSupNodeId = source.getSupNetworkNodeId();
82 this.destNetworkSupNodeId = dest.getSupNetworkNodeId();
84 this.sourceCLLI = source.getSupClliNodeId();
85 this.destCLLI = dest.getSupClliNodeId();
87 this.linkType = MapUtils.calcType(link);
89 this.oppositeLink = calcOpposite(link);
91 if (this.linkType == OpenroadmLinkType.ROADMTOROADM) {
92 this.omsAttributesSpan = MapUtils.getOmsAttributesSpan(link);
93 this.srlgList = MapUtils.getSRLG(link);
94 this.latency = calcLatency(link);
95 this.osnr = calcSpanOSNR();
96 this.availableBandwidth = 0L;
97 this.usedBandwidth = 0L;
98 } else if (this.linkType == OpenroadmLinkType.OTNLINK) {
99 this.availableBandwidth = MapUtils.getAvailableBandwidth(link);
100 this.usedBandwidth = MapUtils.getUsedBandwidth(link);
101 this.srlgList = MapUtils.getSRLGfromLink(link);
104 this.omsAttributesSpan = null;
106 this.omsAttributesSpan = null;
107 this.srlgList = null;
109 this.osnr = 100L; //infinite OSNR in DB
110 this.availableBandwidth = 0L;
111 this.usedBandwidth = 0L;
113 LOG.debug("PceLink: created PceLink {}", linkId);
116 //Retrieve the opposite link
117 private LinkId calcOpposite(Link link) {
118 LinkId tmpoppositeLink = MapUtils.extractOppositeLink(link);
119 if (tmpoppositeLink == null) {
120 LOG.error("PceLink: Error calcOpposite. Link is ignored {}", link.getLinkId().getValue());
123 return tmpoppositeLink;
126 //Compute the link latency : if the latency is not defined, the latency is computed from the omsAttributesSpan
127 private Long calcLatency(Link link) {
130 link1 = link.augmentation(Link1.class);
131 if (link1.getLinkLatency() != null) {
132 tmplatency = link1.getLinkLatency().toJava();
139 Map<LinkConcatenationKey, LinkConcatenation> linkConcatenationMap =
140 this.omsAttributesSpan.nonnullLinkConcatenation();
141 for (Map.Entry<LinkConcatenationKey, LinkConcatenation> entry : linkConcatenationMap.entrySet()) {
142 //Length is expressed in meter and latency is expressed in ms according to OpenROADM MSA
143 tmp += entry.getValue().getSRLGLength().toJava() / CELERITY;
144 LOG.info("In PceLink: The latency of link {} == {}",link.getLinkId(),tmp);
146 tmplatency = (long) Math.ceil(tmp);
147 } catch (NullPointerException e) {
148 LOG.debug("In PceLink: cannot compute the latency for the link {}",link.getLinkId().getValue());
154 //Compute the OSNR of a span
155 public double calcSpanOSNR() {
157 double pout; //power on the output of the previous ROADM (dBm)
158 pout = retrievePower(this.omsAttributesSpan.nonnullLinkConcatenation()
159 .values().iterator().next().getFiberType());
160 double spanLoss = this.omsAttributesSpan.getSpanlossCurrent().getValue().doubleValue(); // span loss (dB)
161 double pin = pout - spanLoss; //power on the input of the current ROADM (dBm)
163 spanOsnrDb = NOISE_MASK_A * pin + NOISE_MASK_B;
164 if (spanOsnrDb > UPPER_BOUND_OSNR) {
165 spanOsnrDb = UPPER_BOUND_OSNR;
166 } else if (spanOsnrDb < LOWER_BOUND_OSNR) {
167 spanOsnrDb = LOWER_BOUND_OSNR;
170 } catch (NullPointerException e) {
171 LOG.error("in PceLink : Null field in the OmsAttrubtesSpan");
176 private double retrievePower(FiberType fiberType) {
200 public LinkId getOppositeLink() {
204 public Object getSourceTP() {
208 public Object getDestTP() {
212 public OpenroadmLinkType getlinkType() {
216 public LinkId getLinkId() {
220 public NodeId getSourceId() {
224 public NodeId getDestId() {
228 public String getClient() {
232 public void setClient(String client) {
233 this.client = client;
236 // Double for transformer of JUNG graph
237 public Double getLatency() {
238 return latency.doubleValue();
241 public Long getAvailableBandwidth() {
242 return availableBandwidth;
245 public Long getUsedBandwidth() {
246 return usedBandwidth;
249 public String getsourceNetworkSupNodeId() {
250 return sourceNetworkSupNodeId;
253 public String getdestNetworkSupNodeId() {
254 return destNetworkSupNodeId;
257 public List<Long> getsrlgList() {
261 public double getosnr() {
265 public String getsourceCLLI() {
269 public String getdestCLLI() {
273 public boolean isValid() {
274 if ((this.linkId == null) || (this.linkType == null) || (this.oppositeLink == null)) {
276 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", linkId);
278 if ((this.sourceId == null) || (this.destId == null) || (this.sourceTP == null) || (this.destTP == null)) {
280 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", linkId);
282 if ((this.sourceNetworkSupNodeId.equals("")) || (this.destNetworkSupNodeId.equals(""))) {
284 LOG.error("PceLink: No Link source SuppNodeID or destination SuppNodeID is available. Link is ignored {}",
287 if ((this.sourceCLLI.equals("")) || (this.destCLLI.equals(""))) {
289 LOG.error("PceLink: No Link source CLLI or destination CLLI is available. Link is ignored {}", linkId);
291 if ((this.omsAttributesSpan == null) && (this.linkType == OpenroadmLinkType.ROADMTOROADM)) {
293 LOG.error("PceLink: Error reading Span for OMS link. Link is ignored {}", linkId);
295 if ((this.srlgList != null) && (this.srlgList.isEmpty())) {
297 LOG.error("PceLink: Empty srlgList for OMS link. Link is ignored {}", linkId);
302 public boolean isOtnValid(Link link, String serviceType) {
304 if (this.linkType != OpenroadmLinkType.OTNLINK) {
305 LOG.error("PceLink: Not an OTN link. Link is ignored {}", linkId);
309 OtnLinkType otnLinkType = link
310 .augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129.Link1.class)
312 if (this.availableBandwidth == 0L) {
313 LOG.error("PceLink: No bandwidth available for OTN Link, link {} is ignored ", linkId);
318 OtnLinkType neededType = null;
319 switch (serviceType) {
322 if (this.usedBandwidth != 0L) {
326 neededType = OtnLinkType.OTU4;
340 neededType = OtnLinkType.ODTU4;
344 neededType = OtnLinkType.ODTU4;
347 LOG.error("PceLink: isOtnValid Link {} unsupported serviceType {} ", linkId, serviceType);
351 if ((this.availableBandwidth >= neededBW)
352 && ((neededType == null) || (neededType.equals(otnLinkType)))) {
353 LOG.info("PceLink: Selected Link {} has available bandwidth and is eligible for {} creation ",
354 linkId, serviceType);
357 if ((this.linkId == null) || (this.linkType == null) || (this.oppositeLink == null)) {
358 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", linkId);
361 if ((this.sourceId == null) || (this.destId == null) || (this.sourceTP == null) || (this.destTP == null)) {
362 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", linkId);
365 if ((this.sourceNetworkSupNodeId.equals("")) || (this.destNetworkSupNodeId.equals(""))) {
366 LOG.error("PceLink: No Link source SuppNodeID or destination SuppNodeID is available. Link is ignored {}",
370 if ((this.sourceCLLI.equals("")) || (this.destCLLI.equals(""))) {
371 LOG.error("PceLink: No Link source CLLI or destination CLLI is available. Link is ignored {}", linkId);
379 public String toString() {
380 return "PceLink type=" + linkType + " ID=" + linkId.getValue() + " latency=" + latency;
383 private void writeObject(ObjectOutputStream out) throws IOException {
384 out.defaultWriteObject();
385 out.writeObject(this.sourceTP);
386 out.writeObject(this.destTP);
389 private void readObject(ObjectInputStream in) throws IOException,ClassNotFoundException {
390 in.defaultReadObject();
391 this.sourceTP = in.readObject();
392 this.destTP = in.readObject();