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.Collection;
16 import java.util.Iterator;
17 import java.util.List;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev200529.span.attributes.LinkConcatenation;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev200529.span.attributes.LinkConcatenation.FiberType;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev200529.span.attributes.LinkConcatenationKey;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.networks.network.link.oms.attributes.Span;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmLinkType;
25 import org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.OtnLinkType;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 @SuppressWarnings("serial")
33 @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
34 value = "SE_NO_SERIALVERSIONID",
35 justification = "https://github.com/rzwitserloot/lombok/wiki/WHY-NOT:-serialVersionUID")
36 public class PceLink implements Serializable {
39 private static final Logger LOG = LoggerFactory.getLogger(PceLink.class);
40 ///////////////////////// LINKS ////////////////////
42 * extension of Link to include constraints and Graph weight
45 private boolean isValid = true;
47 // this member is for XPONDER INPUT/OUTPUT links.
48 // it keeps name of client corresponding to NETWORK TP
49 private String client = "";
50 private final LinkId linkId;
51 private final OpenroadmLinkType linkType;
52 private final NodeId sourceId;
53 private final NodeId destId;
54 private transient Object sourceTP;
55 private transient Object destTP;
56 private final String sourceNetworkSupNodeId;
57 private final String destNetworkSupNodeId;
58 private final String sourceCLLI;
59 private final String destCLLI;
60 private final LinkId oppositeLink;
61 private final Long latency;
62 private final Long availableBandwidth;
63 private final Long usedBandwidth;
64 private final List<Long> srlgList;
65 private final double osnr;
66 private final transient Span omsAttributesSpan;
68 private static final double CELERITY = 2.99792458 * 1e5;
69 private static final double NOISE_MASK_A = 0.571429;
70 private static final double NOISE_MASK_B = 39.285714;
71 private static final double UPPER_BOUND_OSNR = 33;
72 private static final double LOWER_BOUND_OSNR = 0.1;
74 public PceLink(Link link, PceNode source, PceNode dest) {
75 LOG.info("PceLink: : PceLink start ");
77 this.linkId = link.getLinkId();
79 this.sourceId = link.getSource().getSourceNode();
80 this.destId = link.getDestination().getDestNode();
82 this.sourceTP = link.getSource().getSourceTp();
83 this.destTP = link.getDestination().getDestTp();
85 this.sourceNetworkSupNodeId = source.getSupNetworkNodeId();
86 this.destNetworkSupNodeId = dest.getSupNetworkNodeId();
88 this.sourceCLLI = source.getSupClliNodeId();
89 this.destCLLI = dest.getSupClliNodeId();
91 this.linkType = MapUtils.calcType(link);
93 this.oppositeLink = calcOpposite(link);
95 if (this.linkType == OpenroadmLinkType.ROADMTOROADM) {
96 this.omsAttributesSpan = MapUtils.getOmsAttributesSpan(link);
97 this.srlgList = MapUtils.getSRLG(link);
98 this.latency = calcLatency(link);
99 this.osnr = calcSpanOSNR();
100 this.availableBandwidth = 0L;
101 this.usedBandwidth = 0L;
102 } else if (this.linkType == OpenroadmLinkType.OTNLINK) {
103 this.availableBandwidth = MapUtils.getAvailableBandwidth(link);
104 this.usedBandwidth = MapUtils.getUsedBandwidth(link);
105 this.srlgList = MapUtils.getSRLGfromLink(link);
108 this.omsAttributesSpan = null;
110 this.omsAttributesSpan = null;
111 this.srlgList = null;
113 //infinite OSNR in DB
115 this.availableBandwidth = 0L;
116 this.usedBandwidth = 0L;
118 LOG.debug("PceLink: created PceLink {}", linkId);
121 //Retrieve the opposite link
122 private LinkId calcOpposite(Link link) {
123 LinkId tmpoppositeLink = MapUtils.extractOppositeLink(link);
124 if (tmpoppositeLink == null) {
125 LOG.error("PceLink: Error calcOpposite. Link is ignored {}", link.getLinkId().getValue());
128 return tmpoppositeLink;
131 //Compute the link latency : if the latency is not defined, the latency is computed from the omsAttributesSpan
132 private Long calcLatency(Link link) {
133 Link1 link1 = link.augmentation(Link1.class);
134 if (link1.getLinkLatency() != null) {
135 return link1.getLinkLatency().toJava();
137 if (this.omsAttributesSpan == null) {
141 Map<LinkConcatenationKey, LinkConcatenation> linkConcatenationMap = this.omsAttributesSpan
142 .nonnullLinkConcatenation();
143 for (Map.Entry<LinkConcatenationKey, LinkConcatenation> entry : linkConcatenationMap.entrySet()) {
144 // Length is expressed in meter and latency is expressed in ms according to OpenROADM MSA
145 if (entry == null || entry.getValue() == null || entry.getValue().getSRLGLength() == null) {
146 LOG.debug("In PceLink: cannot compute the latency for the link {}", link.getLinkId().getValue());
149 tmp += entry.getValue().getSRLGLength().toJava() / CELERITY;
150 LOG.info("In PceLink: The latency of link {} == {}", link.getLinkId(), tmp);
152 return (long) Math.ceil(tmp);
155 //Compute the OSNR of a span
156 public double calcSpanOSNR() {
157 if (this.omsAttributesSpan == null) {
160 Collection<LinkConcatenation> linkConcatenationList =
161 this.omsAttributesSpan.nonnullLinkConcatenation().values();
162 if (linkConcatenationList == null) {
163 LOG.error("in PceLink : Null field in the OmsAttrubtesSpan");
166 Iterator<LinkConcatenation> linkConcatenationiterator = linkConcatenationList.iterator();
167 if (!linkConcatenationiterator.hasNext()) {
170 // power on the output of the previous ROADM (dBm)
171 double pout = retrievePower(linkConcatenationiterator.next().getFiberType());
173 double spanLoss = this.omsAttributesSpan.getSpanlossCurrent().getValue().doubleValue();
174 // power on the input of the current ROADM (dBm)
175 double pin = pout - spanLoss;
176 double spanOsnrDb = NOISE_MASK_A * pin + NOISE_MASK_B;
177 if (spanOsnrDb > UPPER_BOUND_OSNR) {
178 spanOsnrDb = UPPER_BOUND_OSNR;
179 } else if (spanOsnrDb < LOWER_BOUND_OSNR) {
180 spanOsnrDb = LOWER_BOUND_OSNR;
185 private double retrievePower(FiberType fiberType) {
209 public LinkId getOppositeLink() {
213 public Object getSourceTP() {
217 public Object getDestTP() {
221 public OpenroadmLinkType getlinkType() {
225 public LinkId getLinkId() {
229 public NodeId getSourceId() {
233 public NodeId getDestId() {
237 public String getClient() {
241 public void setClient(String client) {
242 this.client = client;
245 // Double for transformer of JUNG graph
246 public Double getLatency() {
247 return latency.doubleValue();
250 public Long getAvailableBandwidth() {
251 return availableBandwidth;
254 public Long getUsedBandwidth() {
255 return usedBandwidth;
258 public String getsourceNetworkSupNodeId() {
259 return sourceNetworkSupNodeId;
262 public String getdestNetworkSupNodeId() {
263 return destNetworkSupNodeId;
266 public List<Long> getsrlgList() {
270 public double getosnr() {
274 public String getsourceCLLI() {
278 public String getdestCLLI() {
282 public boolean isValid() {
283 if ((this.linkId == null) || (this.linkType == null) || (this.oppositeLink == null)) {
285 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", linkId);
287 isValid = checkParams();
288 if ((this.omsAttributesSpan == null) && (this.linkType == OpenroadmLinkType.ROADMTOROADM)) {
290 LOG.error("PceLink: Error reading Span for OMS link. Link is ignored {}", linkId);
292 if ((this.srlgList != null) && (this.srlgList.isEmpty())) {
294 LOG.error("PceLink: Empty srlgList for OMS link. Link is ignored {}", linkId);
299 public boolean isOtnValid(Link link, String serviceType) {
301 if (this.linkType != OpenroadmLinkType.OTNLINK) {
302 LOG.error("PceLink: Not an OTN link. Link is ignored {}", linkId);
306 OtnLinkType otnLinkType = link
307 .augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.Link1.class)
309 if (this.availableBandwidth == 0L) {
310 LOG.error("PceLink: No bandwidth available for OTN Link, link {} is ignored ", linkId);
315 OtnLinkType neededType = null;
316 switch (serviceType) {
319 if (this.usedBandwidth != 0L) {
323 neededType = OtnLinkType.OTU4;
337 neededType = OtnLinkType.ODTU4;
341 neededType = OtnLinkType.ODTU4;
344 LOG.error("PceLink: isOtnValid Link {} unsupported serviceType {} ", linkId, serviceType);
348 if ((this.availableBandwidth >= neededBW)
349 && ((neededType == null) || (neededType.equals(otnLinkType)))) {
350 LOG.info("PceLink: Selected Link {} has available bandwidth and is eligible for {} creation ",
351 linkId, serviceType);
354 return checkParams();
357 private boolean checkParams() {
358 if ((this.linkId == null) || (this.linkType == null) || (this.oppositeLink == null)) {
359 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", linkId);
362 if ((this.sourceId == null) || (this.destId == null) || (this.sourceTP == null) || (this.destTP == null)) {
363 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", linkId);
366 if ((this.sourceNetworkSupNodeId.equals("")) || (this.destNetworkSupNodeId.equals(""))) {
367 LOG.error("PceLink: No Link source SuppNodeID or destination SuppNodeID is available. Link is ignored {}",
371 if ((this.sourceCLLI.equals("")) || (this.destCLLI.equals(""))) {
372 LOG.error("PceLink: No Link source CLLI or destination CLLI is available. Link is ignored {}", linkId);
380 public String toString() {
381 return "PceLink type=" + linkType + " ID=" + linkId.getValue() + " latency=" + latency;
384 private void writeObject(ObjectOutputStream out) throws IOException {
385 out.defaultWriteObject();
386 out.writeObject(this.sourceTP);
387 out.writeObject(this.destTP);
390 private void readObject(ObjectInputStream in) throws IOException,ClassNotFoundException {
391 in.defaultReadObject();
392 this.sourceTP = in.readObject();
393 this.destTP = in.readObject();