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;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenation.FiberType;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.link.oms.attributes.Span;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType;
20 import org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129.OtnLinkType;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class PceLink implements Serializable {
29 private static final long serialVersionUID = 1L;
31 private static final Logger LOG = LoggerFactory.getLogger(PceLink.class);
32 ///////////////////////// LINKS ////////////////////
34 * extension of Link to include constraints and Graph weight
37 private boolean isValid = true;
38 private boolean isOtnValid = true;
40 // this member is for XPONDER INPUT/OUTPUT links.
41 // it keeps name of client corresponding to NETWORK TP
42 private String client = "";
43 private final LinkId linkId;
44 private final OpenroadmLinkType linkType;
45 private final NodeId sourceId;
46 private final NodeId destId;
47 private transient Object sourceTP;
48 private transient Object destTP;
49 private final String sourceNetworkSupNodeId;
50 private final String destNetworkSupNodeId;
51 private final String sourceCLLI;
52 private final String destCLLI;
53 private final LinkId oppositeLink;
54 private final Long latency;
55 private final Long availableBandwidth;
56 private final Long usedBandwidth;
57 private final List<Long> srlgList;
58 private final double osnr;
59 private final transient Span omsAttributesSpan;
60 private static final double CELERITY = 2.99792458 * 1e5; //meter per ms
61 private static final double NOISE_MASK_A = 0.571429;
62 private static final double NOISE_MASK_B = 39.285714;
63 private static final double UPPER_BOUND_OSNR = 33;
64 private static final double LOWER_BOUND_OSNR = 0.1;
66 public PceLink(Link link, PceNode source, PceNode dest) {
67 LOG.info("PceLink: : PceLink start ");
69 this.linkId = link.getLinkId();
71 this.sourceId = link.getSource().getSourceNode();
72 this.destId = link.getDestination().getDestNode();
74 this.sourceTP = link.getSource().getSourceTp();
75 this.destTP = link.getDestination().getDestTp();
77 this.sourceNetworkSupNodeId = source.getSupNetworkNodeId();
78 this.destNetworkSupNodeId = dest.getSupNetworkNodeId();
80 this.sourceCLLI = source.getSupClliNodeId();
81 this.destCLLI = dest.getSupClliNodeId();
83 this.linkType = MapUtils.calcType(link);
85 this.oppositeLink = calcOpposite(link);
87 if (this.linkType == OpenroadmLinkType.ROADMTOROADM) {
88 this.omsAttributesSpan = MapUtils.getOmsAttributesSpan(link);
89 this.srlgList = MapUtils.getSRLG(link);
90 this.latency = calcLatency(link);
91 this.osnr = calcSpanOSNR();
92 this.availableBandwidth = 0L;
93 this.usedBandwidth = 0L;
94 } else if (this.linkType == OpenroadmLinkType.OTNLINK) {
95 this.availableBandwidth = MapUtils.getAvailableBandwidth(link);
96 this.usedBandwidth = MapUtils.getUsedBandwidth(link);
97 this.srlgList = MapUtils.getSRLGfromLink(link);
100 this.omsAttributesSpan = null;
102 this.omsAttributesSpan = null;
103 this.srlgList = null;
105 this.osnr = 100L; //infinite OSNR in DB
106 this.availableBandwidth = 0L;
107 this.usedBandwidth = 0L;
109 LOG.debug("PceLink: created PceLink {}", linkId);
112 //Retrieve the opposite link
113 private LinkId calcOpposite(Link link) {
114 LinkId tmpoppositeLink = MapUtils.extractOppositeLink(link);
115 if (tmpoppositeLink == null) {
116 LOG.error("PceLink: Error calcOpposite. Link is ignored {}", link.getLinkId().getValue());
119 return tmpoppositeLink;
122 //Compute the link latency : if the latency is not defined, the latency is computed from the omsAttributesSpan
123 private Long calcLatency(Link link) {
126 link1 = link.augmentation(Link1.class);
127 if (link1.getLinkLatency() != null) {
128 tmplatency = link1.getLinkLatency().toJava();
134 for (int i = 0; i < this.omsAttributesSpan.getLinkConcatenation().size(); i++) {
135 //Length is expressed in meter and latency is expressed in ms according to OpenROADM MSA
136 tmp += this.omsAttributesSpan.getLinkConcatenation().get(i).getSRLGLength().toJava() / CELERITY;
137 LOG.info("In PceLink: The latency of link {} == {}",link.getLinkId(),tmp);
139 tmplatency = (long) Math.ceil(tmp);
140 } catch (NullPointerException e) {
141 LOG.debug("In PceLink: cannot compute the latency for the link {}",link.getLinkId().getValue());
147 //Compute the OSNR of a span
148 public double calcSpanOSNR() {
150 double pout; //power on the output of the previous ROADM (dBm)
151 pout = retrievePower(this.omsAttributesSpan.getLinkConcatenation().get(0).getFiberType());
152 double spanLoss = this.omsAttributesSpan.getSpanlossCurrent().getValue().doubleValue(); // span loss (dB)
153 double pin = pout - spanLoss; //power on the input of the current ROADM (dBm)
155 spanOsnrDb = NOISE_MASK_A * pin + NOISE_MASK_B;
156 if (spanOsnrDb > UPPER_BOUND_OSNR) {
157 spanOsnrDb = UPPER_BOUND_OSNR;
158 } else if (spanOsnrDb < LOWER_BOUND_OSNR) {
159 spanOsnrDb = LOWER_BOUND_OSNR;
162 } catch (NullPointerException e) {
163 LOG.error("in PceLink : Null field in the OmsAttrubtesSpan");
168 private double retrievePower(FiberType fiberType) {
192 public LinkId getOppositeLink() {
196 public Object getSourceTP() {
200 public Object getDestTP() {
204 public OpenroadmLinkType getlinkType() {
208 public LinkId getLinkId() {
212 public NodeId getSourceId() {
216 public NodeId getDestId() {
220 public String getClient() {
224 public void setClient(String client) {
225 this.client = client;
228 // Double for transformer of JUNG graph
229 public Double getLatency() {
230 return latency.doubleValue();
233 public Long getAvailableBandwidth() {
234 return availableBandwidth;
237 public Long getUsedBandwidth() {
238 return usedBandwidth;
241 public String getsourceNetworkSupNodeId() {
242 return sourceNetworkSupNodeId;
245 public String getdestNetworkSupNodeId() {
246 return destNetworkSupNodeId;
249 public List<Long> getsrlgList() {
253 public double getosnr() {
257 public String getsourceCLLI() {
261 public String getdestCLLI() {
265 public boolean isValid() {
266 if ((this.linkId == null) || (this.linkType == null) || (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) || (this.sourceTP == null) || (this.destTP == null)) {
272 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", linkId);
274 if ((this.sourceNetworkSupNodeId.equals("")) || (this.destNetworkSupNodeId.equals(""))) {
276 LOG.error("PceLink: No Link source SuppNodeID or destination SuppNodeID is available. Link is ignored {}",
279 if ((this.sourceCLLI.equals("")) || (this.destCLLI.equals(""))) {
281 LOG.error("PceLink: No Link source CLLI or destination CLLI is available. Link is ignored {}", linkId);
283 if ((this.omsAttributesSpan == null) && (this.linkType == OpenroadmLinkType.ROADMTOROADM)) {
285 LOG.error("PceLink: Error reading Span for OMS link. Link is ignored {}", linkId);
287 if ((this.srlgList != null) && (this.srlgList.isEmpty())) {
289 LOG.error("PceLink: Empty srlgList for OMS link. Link is ignored {}", linkId);
294 public boolean isOtnValid(Link link, String serviceType) {
296 if (this.linkType != OpenroadmLinkType.OTNLINK) {
297 LOG.error("PceLink: Not an OTN link. Link is ignored {}", linkId);
301 OtnLinkType otnLinkType = link
302 .augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129.Link1.class)
304 if (this.availableBandwidth == 0L) {
305 LOG.error("PceLink: No bandwidth available for OTN Link, link {} is ignored ", linkId);
310 OtnLinkType neededType = null;
311 switch (serviceType) {
314 if (this.usedBandwidth != 0L) {
318 neededType = OtnLinkType.OTU4;
332 neededType = OtnLinkType.ODTU4;
336 neededType = OtnLinkType.ODTU4;
339 LOG.error("PceLink: isOtnValid Link {} unsupported serviceType {} ", linkId, serviceType);
343 if ((this.availableBandwidth >= neededBW)
344 && ((neededType == null) || (neededType.equals(otnLinkType)))) {
345 LOG.info("PceLink: Selected Link {} has available bandwidth and is eligible for {} creation ",
346 linkId, serviceType);
349 if ((this.linkId == null) || (this.linkType == null) || (this.oppositeLink == null)) {
350 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", linkId);
353 if ((this.sourceId == null) || (this.destId == null) || (this.sourceTP == null) || (this.destTP == null)) {
354 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", linkId);
357 if ((this.sourceNetworkSupNodeId.equals("")) || (this.destNetworkSupNodeId.equals(""))) {
358 LOG.error("PceLink: No Link source SuppNodeID or destination SuppNodeID is available. Link is ignored {}",
362 if ((this.sourceCLLI.equals("")) || (this.destCLLI.equals(""))) {
363 LOG.error("PceLink: No Link source CLLI or destination CLLI is available. Link is ignored {}", linkId);
371 public String toString() {
372 return "PceLink type=" + linkType + " ID=" + linkId.getValue() + " latency=" + latency;
375 private void writeObject(ObjectOutputStream out) throws IOException {
376 out.defaultWriteObject();
377 out.writeObject(this.sourceTP);
378 out.writeObject(this.destTP);
381 private void readObject(ObjectInputStream in) throws IOException,ClassNotFoundException {
382 in.defaultReadObject();
383 this.sourceTP = in.readObject();
384 this.destTP = in.readObject();