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.eclipse.jdt.annotation.NonNull;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenation;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenation.FiberType;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenationKey;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.link.oms.attributes.Span;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType;
26 import org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129.OtnLinkType;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public class PceLink implements Serializable {
35 private static final long serialVersionUID = 1L;
37 private static final Logger LOG = LoggerFactory.getLogger(PceLink.class);
38 ///////////////////////// LINKS ////////////////////
40 * extension of Link to include constraints and Graph weight
43 private boolean isValid = true;
44 private boolean isOtnValid = true;
46 // this member is for XPONDER INPUT/OUTPUT links.
47 // it keeps name of client corresponding to NETWORK TP
48 private String client = "";
49 private final LinkId linkId;
50 private final OpenroadmLinkType linkType;
51 private final NodeId sourceId;
52 private final NodeId destId;
53 private transient Object sourceTP;
54 private transient Object destTP;
55 private final String sourceNetworkSupNodeId;
56 private final String destNetworkSupNodeId;
57 private final String sourceCLLI;
58 private final String destCLLI;
59 private final LinkId oppositeLink;
60 private final Long latency;
61 private final Long availableBandwidth;
62 private final Long usedBandwidth;
63 private final List<Long> srlgList;
64 private final double osnr;
65 private final transient Span omsAttributesSpan;
66 private static final double CELERITY = 2.99792458 * 1e5; //meter per ms
67 private static final double NOISE_MASK_A = 0.571429;
68 private static final double NOISE_MASK_B = 39.285714;
69 private static final double UPPER_BOUND_OSNR = 33;
70 private static final double LOWER_BOUND_OSNR = 0.1;
72 public PceLink(Link link, PceNode source, PceNode dest) {
73 LOG.info("PceLink: : PceLink start ");
75 this.linkId = link.getLinkId();
77 this.sourceId = link.getSource().getSourceNode();
78 this.destId = link.getDestination().getDestNode();
80 this.sourceTP = link.getSource().getSourceTp();
81 this.destTP = link.getDestination().getDestTp();
83 this.sourceNetworkSupNodeId = source.getSupNetworkNodeId();
84 this.destNetworkSupNodeId = dest.getSupNetworkNodeId();
86 this.sourceCLLI = source.getSupClliNodeId();
87 this.destCLLI = dest.getSupClliNodeId();
89 this.linkType = MapUtils.calcType(link);
91 this.oppositeLink = calcOpposite(link);
93 if (this.linkType == OpenroadmLinkType.ROADMTOROADM) {
94 this.omsAttributesSpan = MapUtils.getOmsAttributesSpan(link);
95 this.srlgList = MapUtils.getSRLG(link);
96 this.latency = calcLatency(link);
97 this.osnr = calcSpanOSNR();
98 this.availableBandwidth = 0L;
99 this.usedBandwidth = 0L;
100 } else if (this.linkType == OpenroadmLinkType.OTNLINK) {
101 this.availableBandwidth = MapUtils.getAvailableBandwidth(link);
102 this.usedBandwidth = MapUtils.getUsedBandwidth(link);
103 this.srlgList = MapUtils.getSRLGfromLink(link);
106 this.omsAttributesSpan = null;
108 this.omsAttributesSpan = null;
109 this.srlgList = null;
111 this.osnr = 100L; //infinite OSNR in DB
112 this.availableBandwidth = 0L;
113 this.usedBandwidth = 0L;
115 LOG.debug("PceLink: created PceLink {}", linkId);
118 //Retrieve the opposite link
119 private LinkId calcOpposite(Link link) {
120 LinkId tmpoppositeLink = MapUtils.extractOppositeLink(link);
121 if (tmpoppositeLink == null) {
122 LOG.error("PceLink: Error calcOpposite. Link is ignored {}", link.getLinkId().getValue());
125 return tmpoppositeLink;
128 //Compute the link latency : if the latency is not defined, the latency is computed from the omsAttributesSpan
129 private Long calcLatency(Link link) {
132 link1 = link.augmentation(Link1.class);
133 if (link1.getLinkLatency() != null) {
134 tmplatency = link1.getLinkLatency().toJava();
141 Map<LinkConcatenationKey, LinkConcatenation> linkConcatenationMap =
142 this.omsAttributesSpan.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 tmp += entry.getValue().getSRLGLength().toJava() / CELERITY;
146 LOG.info("In PceLink: The latency of link {} == {}",link.getLinkId(),tmp);
148 tmplatency = (long) Math.ceil(tmp);
149 } catch (NullPointerException e) {
150 LOG.debug("In PceLink: cannot compute the latency for the link {}",link.getLinkId().getValue());
156 //Compute the OSNR of a span
157 public double calcSpanOSNR() {
158 if (this.omsAttributesSpan == null) {
161 Collection<LinkConcatenation> linkConcatenationList =
162 this.omsAttributesSpan.nonnullLinkConcatenation().values();
163 if (linkConcatenationList == null) {
164 LOG.error("in PceLink : Null field in the OmsAttrubtesSpan");
167 Iterator<LinkConcatenation> linkConcatenationiterator = linkConcatenationList.iterator();
168 if (!linkConcatenationiterator.hasNext()) {
171 // power on the output of the previous ROADM (dBm)
172 double pout = retrievePower(linkConcatenationiterator.next().getFiberType());
174 double spanLoss = this.omsAttributesSpan.getSpanlossCurrent().getValue().doubleValue();
175 double pin = pout - spanLoss; // power on the input of the current ROADM (dBm)
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 if ((this.sourceId == null) || (this.destId == null) || (this.sourceTP == null) || (this.destTP == null)) {
289 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", linkId);
291 if ((this.sourceNetworkSupNodeId.equals("")) || (this.destNetworkSupNodeId.equals(""))) {
293 LOG.error("PceLink: No Link source SuppNodeID or destination SuppNodeID is available. Link is ignored {}",
296 if ((this.sourceCLLI.equals("")) || (this.destCLLI.equals(""))) {
298 LOG.error("PceLink: No Link source CLLI or destination CLLI is available. Link is ignored {}", linkId);
300 if ((this.omsAttributesSpan == null) && (this.linkType == OpenroadmLinkType.ROADMTOROADM)) {
302 LOG.error("PceLink: Error reading Span for OMS link. Link is ignored {}", linkId);
304 if ((this.srlgList != null) && (this.srlgList.isEmpty())) {
306 LOG.error("PceLink: Empty srlgList for OMS link. Link is ignored {}", linkId);
311 public boolean isOtnValid(Link link, String serviceType) {
313 if (this.linkType != OpenroadmLinkType.OTNLINK) {
314 LOG.error("PceLink: Not an OTN link. Link is ignored {}", linkId);
318 OtnLinkType otnLinkType = link
319 .augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129.Link1.class)
321 if (this.availableBandwidth == 0L) {
322 LOG.error("PceLink: No bandwidth available for OTN Link, link {} is ignored ", linkId);
327 OtnLinkType neededType = null;
328 switch (serviceType) {
331 if (this.usedBandwidth != 0L) {
335 neededType = OtnLinkType.OTU4;
349 neededType = OtnLinkType.ODTU4;
353 neededType = OtnLinkType.ODTU4;
356 LOG.error("PceLink: isOtnValid Link {} unsupported serviceType {} ", linkId, serviceType);
360 if ((this.availableBandwidth >= neededBW)
361 && ((neededType == null) || (neededType.equals(otnLinkType)))) {
362 LOG.info("PceLink: Selected Link {} has available bandwidth and is eligible for {} creation ",
363 linkId, serviceType);
366 if ((this.linkId == null) || (this.linkType == null) || (this.oppositeLink == null)) {
367 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", linkId);
370 if ((this.sourceId == null) || (this.destId == null) || (this.sourceTP == null) || (this.destTP == null)) {
371 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", linkId);
374 if ((this.sourceNetworkSupNodeId.equals("")) || (this.destNetworkSupNodeId.equals(""))) {
375 LOG.error("PceLink: No Link source SuppNodeID or destination SuppNodeID is available. Link is ignored {}",
379 if ((this.sourceCLLI.equals("")) || (this.destCLLI.equals(""))) {
380 LOG.error("PceLink: No Link source CLLI or destination CLLI is available. Link is ignored {}", linkId);
388 public String toString() {
389 return "PceLink type=" + linkType + " ID=" + linkId.getValue() + " latency=" + latency;
392 private void writeObject(ObjectOutputStream out) throws IOException {
393 out.defaultWriteObject();
394 out.writeObject(this.sourceTP);
395 out.writeObject(this.destTP);
398 private void readObject(ObjectInputStream in) throws IOException,ClassNotFoundException {
399 in.defaultReadObject();
400 this.sourceTP = in.readObject();
401 this.destTP = in.readObject();