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.Serializable;
12 import java.util.Collection;
13 import java.util.Iterator;
14 import java.util.List;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Link1;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev211210.span.attributes.LinkConcatenation1;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev211210.span.attributes.LinkConcatenation1.FiberType;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.networks.network.link.oms.attributes.Span;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmLinkType;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.link.concatenation.LinkConcatenation;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.link.concatenation.LinkConcatenationKey;
25 import org.opendaylight.yang.gen.v1.http.transportpce.topology.rev220123.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.TpId;
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 @SuppressWarnings("serial")
34 @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
35 value = "SE_NO_SERIALVERSIONID",
36 justification = "https://github.com/rzwitserloot/lombok/wiki/WHY-NOT:-serialVersionUID")
37 public class PceLink implements Serializable {
40 private static final Logger LOG = LoggerFactory.getLogger(PceLink.class);
41 ///////////////////////// LINKS ////////////////////
43 * extension of Link to include constraints and Graph weight
46 private boolean isValid = true;
48 // this member is for XPONDER INPUT/OUTPUT links.
49 // it keeps name of client corresponding to NETWORK TP
50 private String client = "";
51 private final LinkId linkId;
52 private final OpenroadmLinkType linkType;
53 private final NodeId sourceId;
54 private final NodeId destId;
55 private final TpId sourceTP;
56 private final TpId destTP;
57 private final String sourceNetworkSupNodeId;
58 private final String destNetworkSupNodeId;
59 private final String sourceCLLI;
60 private final String destCLLI;
61 private final LinkId oppositeLink;
62 private final AdminStates adminStates;
63 private final State state;
64 private final Long latency;
65 private final Long availableBandwidth;
66 private final Long usedBandwidth;
67 private final List<Long> srlgList;
68 private final double osnr;
69 private final transient Span omsAttributesSpan;
71 private static final double CELERITY = 2.99792458 * 1e5;
72 private static final double NOISE_MASK_A = 0.571429;
73 private static final double NOISE_MASK_B = 39.285714;
74 private static final double UPPER_BOUND_OSNR = 33;
75 private static final double LOWER_BOUND_OSNR = 0.1;
77 public PceLink(Link link, PceNode source, PceNode dest) {
78 LOG.info("PceLink: : PceLink start ");
80 this.linkId = link.getLinkId();
82 this.sourceId = link.getSource().getSourceNode();
83 this.destId = link.getDestination().getDestNode();
85 this.sourceTP = link.getSource().getSourceTp();
86 this.destTP = link.getDestination().getDestTp();
88 this.sourceNetworkSupNodeId = source.getSupNetworkNodeId();
89 this.destNetworkSupNodeId = dest.getSupNetworkNodeId();
91 this.sourceCLLI = source.getSupClliNodeId();
92 this.destCLLI = dest.getSupClliNodeId();
94 this.linkType = MapUtils.calcType(link);
96 this.oppositeLink = calcOpposite(link);
98 this.adminStates = link.augmentation(Link1.class).getAdministrativeState();
99 this.state = link.augmentation(Link1.class).getOperationalState();
101 if (this.linkType == OpenroadmLinkType.ROADMTOROADM) {
102 this.omsAttributesSpan = MapUtils.getOmsAttributesSpan(link);
103 this.srlgList = MapUtils.getSRLG(link);
104 this.latency = calcLatency(link);
105 this.osnr = calcSpanOSNR();
106 this.availableBandwidth = 0L;
107 this.usedBandwidth = 0L;
108 } else if (this.linkType == OpenroadmLinkType.OTNLINK) {
109 this.availableBandwidth = MapUtils.getAvailableBandwidth(link);
110 this.usedBandwidth = MapUtils.getUsedBandwidth(link);
111 this.srlgList = MapUtils.getSRLGfromLink(link);
114 this.omsAttributesSpan = null;
116 this.omsAttributesSpan = null;
117 this.srlgList = null;
119 //infinite OSNR in DB
121 this.availableBandwidth = 0L;
122 this.usedBandwidth = 0L;
124 LOG.debug("PceLink: created PceLink {}", linkId);
127 //Retrieve the opposite link
128 private LinkId calcOpposite(Link link) {
129 LinkId tmpoppositeLink = MapUtils.extractOppositeLink(link);
130 if (tmpoppositeLink == null) {
131 LOG.error("PceLink: Error calcOpposite. Link is ignored {}", link.getLinkId().getValue());
134 return tmpoppositeLink;
137 //Compute the link latency : if the latency is not defined, the latency is computed from the omsAttributesSpan
138 private Long calcLatency(Link link) {
139 Link1 link1 = link.augmentation(Link1.class);
140 if (link1.getLinkLatency() != null) {
141 return link1.getLinkLatency().toJava();
143 if (this.omsAttributesSpan == null) {
147 Map<LinkConcatenationKey, LinkConcatenation> linkConcatenationMap = this.omsAttributesSpan
148 .nonnullLinkConcatenation();
149 for (Map.Entry<LinkConcatenationKey, LinkConcatenation> entry : linkConcatenationMap.entrySet()) {
150 // Length is expressed in meter and latency is expressed in ms according to OpenROADM MSA
151 if (entry == null || entry.getValue() == null || entry.getValue().getSRLGLength() == null) {
152 LOG.debug("In PceLink: cannot compute the latency for the link {}", link.getLinkId().getValue());
155 tmp += entry.getValue().getSRLGLength().doubleValue() / CELERITY;
156 LOG.info("In PceLink: The latency of link {} == {}", link.getLinkId(), tmp);
158 return (long) Math.ceil(tmp);
161 //Compute the OSNR of a span
162 private double calcSpanOSNR() {
163 if (this.omsAttributesSpan == null) {
166 Collection<LinkConcatenation> linkConcatenationList =
167 this.omsAttributesSpan.nonnullLinkConcatenation().values();
168 if (linkConcatenationList == null) {
169 LOG.error("in PceLink : Null field in the OmsAttrubtesSpan");
172 Iterator<LinkConcatenation> linkConcatenationiterator = linkConcatenationList.iterator();
173 if (!linkConcatenationiterator.hasNext()) {
176 // power on the output of the previous ROADM (dBm)
177 double pout = retrievePower(linkConcatenationiterator.next().augmentation(LinkConcatenation1.class)
180 double spanLoss = this.omsAttributesSpan.getSpanlossCurrent().getValue().doubleValue();
181 // power on the input of the current ROADM (dBm)
182 double pin = pout - spanLoss;
183 double spanOsnrDb = NOISE_MASK_A * pin + NOISE_MASK_B;
184 if (spanOsnrDb > UPPER_BOUND_OSNR) {
185 spanOsnrDb = UPPER_BOUND_OSNR;
186 } else if (spanOsnrDb < LOWER_BOUND_OSNR) {
187 spanOsnrDb = LOWER_BOUND_OSNR;
192 private double retrievePower(FiberType fiberType) {
216 public LinkId getOppositeLink() {
220 public AdminStates getAdminStates() {
224 public State getState() {
228 public TpId getSourceTP() {
232 public TpId getDestTP() {
236 public OpenroadmLinkType getlinkType() {
240 public LinkId getLinkId() {
244 public NodeId getSourceId() {
248 public NodeId getDestId() {
252 public String getClient() {
256 public void setClient(String client) {
257 this.client = client;
260 // Double for transformer of JUNG graph
261 public Double getLatency() {
262 return latency.doubleValue();
265 public Long getAvailableBandwidth() {
266 return availableBandwidth;
269 public Long getUsedBandwidth() {
270 return usedBandwidth;
273 public String getsourceNetworkSupNodeId() {
274 return sourceNetworkSupNodeId;
277 public String getdestNetworkSupNodeId() {
278 return destNetworkSupNodeId;
281 public List<Long> getsrlgList() {
285 public double getosnr() {
289 public String getsourceCLLI() {
293 public String getdestCLLI() {
297 public boolean isValid() {
298 if ((this.linkId == null) || (this.linkType == null) || (this.oppositeLink == null)) {
300 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", linkId);
302 isValid = checkParams();
303 if ((this.omsAttributesSpan == null) && (this.linkType == OpenroadmLinkType.ROADMTOROADM)) {
305 LOG.error("PceLink: Error reading Span for OMS link. Link is ignored {}", linkId);
307 if ((this.srlgList != null) && (this.srlgList.isEmpty())) {
309 LOG.error("PceLink: Empty srlgList for OMS link. Link is ignored {}", linkId);
314 public boolean isOtnValid(Link link, String serviceType) {
316 if (this.linkType != OpenroadmLinkType.OTNLINK) {
317 LOG.error("PceLink: Not an OTN link. Link is ignored {}", linkId);
321 OtnLinkType otnLinkType = link
322 .augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev220123.Link1.class)
324 if (this.availableBandwidth == 0L) {
325 LOG.error("PceLink: No bandwidth available for OTN Link, link {} is ignored ", linkId);
330 OtnLinkType neededType = null;
331 switch (serviceType) {
333 if (this.usedBandwidth != 0L) {
337 // Add intermediate rate otn-link-type
338 neededType = OtnLinkType.OTUC2;
341 if (this.usedBandwidth != 0L) {
345 // hange otn-link-type
346 neededType = OtnLinkType.OTUC3;
349 if (this.usedBandwidth != 0L) {
353 neededType = OtnLinkType.OTUC4;
357 if (this.usedBandwidth != 0L) {
361 neededType = OtnLinkType.OTU4;
375 // TODO: Here link type needs to be changed, based on the line-rate
376 neededType = OtnLinkType.ODUC4;
380 neededType = OtnLinkType.ODTU4;
384 neededType = OtnLinkType.ODTU4;
387 LOG.error("PceLink: isOtnValid Link {} unsupported serviceType {} ", linkId, serviceType);
391 if ((this.availableBandwidth >= neededBW)
392 && ((neededType == null) || (neededType.equals(otnLinkType)))) {
393 LOG.info("PceLink: Selected Link {} has available bandwidth and is eligible for {} creation ",
394 linkId, serviceType);
397 return checkParams();
400 private boolean checkParams() {
401 if ((this.linkId == null) || (this.linkType == null) || (this.oppositeLink == null)) {
402 LOG.error("PceLink: No Link type or opposite link is available. Link is ignored {}", linkId);
405 if ((this.adminStates == null) || (this.state == null)) {
406 LOG.error("PceLink: Link is not available. Link is ignored {}", linkId);
409 if ((this.sourceId == null) || (this.destId == null) || (this.sourceTP == null) || (this.destTP == null)) {
410 LOG.error("PceLink: No Link source or destination is available. Link is ignored {}", linkId);
413 if ((this.sourceNetworkSupNodeId.equals("")) || (this.destNetworkSupNodeId.equals(""))) {
414 LOG.error("PceLink: No Link source SuppNodeID or destination SuppNodeID is available. Link is ignored {}",
418 if ((this.sourceCLLI.equals("")) || (this.destCLLI.equals(""))) {
419 LOG.error("PceLink: No Link source CLLI or destination CLLI is available. Link is ignored {}", linkId);
427 public String toString() {
428 return "PceLink type=" + linkType + " ID=" + linkId.getValue() + " latency=" + latency;