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.graph;
11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
12 import java.util.ArrayList;
13 import java.util.Collections;
14 import java.util.HashMap;
15 import java.util.List;
17 import org.jgrapht.GraphPath;
18 import org.opendaylight.transportpce.common.ResponseCodes;
19 import org.opendaylight.transportpce.common.StringConstants;
20 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
21 import org.opendaylight.transportpce.pce.constraints.PceConstraints.ResourcePair;
22 import org.opendaylight.transportpce.pce.networkanalyzer.PceNode;
23 import org.opendaylight.transportpce.pce.networkanalyzer.PceResult;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmLinkType;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
26 import org.opendaylight.yangtools.yang.common.Uint16;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class PostAlgoPathValidator {
32 private static final Logger LOG = LoggerFactory.getLogger(PostAlgoPathValidator.class);
34 private static final int MAX_WAWELENGTH = 96;
35 private static final double MIN_OSNR_W100G = 17;
36 private static final double TRX_OSNR = 33;
37 private static final double ADD_OSNR = 30;
38 public static final Long CONST_OSNR = 1L;
39 public static final double SYS_MARGIN = 0;
42 value = "SF_SWITCH_FALLTHROUGH",
43 justification = "intentional fallthrough")
44 public PceResult checkPath(GraphPath<String, PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes,
45 PceResult pceResult, PceConstraints pceHardConstraints, String serviceType) {
47 // check if the path is empty
48 if (path.getEdgeList().isEmpty()) {
49 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
54 //variable to deal with 1GE (Nb=1) and 10GE (Nb=10) cases
55 switch (serviceType) {
57 case StringConstants.SERVICE_TYPE_100GE:
58 case StringConstants.SERVICE_TYPE_OTU4:
59 // choose wavelength available in all nodes of the path
60 Long waveL = chooseWavelength(path, allPceNodes);
61 pceResult.setServiceType(serviceType);
63 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
64 pceResult.setLocalCause(PceResult.LocalCause.NO_PATH_EXISTS);
67 pceResult.setResultWavelength(waveL);
68 LOG.info("In PostAlgoPathValidator: chooseWavelength WL found {} {}", waveL, path);
71 if (!checkOSNR(path)) {
72 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
73 pceResult.setLocalCause(PceResult.LocalCause.OUT_OF_SPEC_OSNR);
77 // Check if MaxLatency is defined in the hard constraints
78 if ((pceHardConstraints.getMaxLatency() != -1)
79 && (!checkLatency(pceHardConstraints.getMaxLatency(), path))) {
80 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
81 pceResult.setLocalCause(PceResult.LocalCause.TOO_HIGH_LATENCY);
85 // Check if nodes are included in the hard constraints
86 if (!checkInclude(path, pceHardConstraints)) {
87 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
88 pceResult.setLocalCause(PceResult.LocalCause.HD_NODE_INCLUDE);
92 // TODO here other post algo validations can be added
93 // more data can be sent to PceGraph module via PceResult structure if required
95 pceResult.setRC(ResponseCodes.RESPONSE_OK);
96 pceResult.setLocalCause(PceResult.LocalCause.NONE);
100 case StringConstants.SERVICE_TYPE_10GE:
103 case StringConstants.SERVICE_TYPE_1GE:
104 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
105 pceResult.setServiceType(serviceType);
106 Map<String, Uint16> tribPort = chooseTribPort(path, allPceNodes);
107 Map<String, List<Uint16>> tribSlot = chooseTribSlot(path, allPceNodes, tribSlotNb);
109 if (tribPort != null && tribSlot != null) {
110 pceResult.setResultTribPort(tribPort);
111 pceResult.setResultTribSlot(tribSlot);
112 pceResult.setResultTribSlotNb(tribSlotNb);
113 pceResult.setRC(ResponseCodes.RESPONSE_OK);
114 LOG.info("In PostAlgoPathValidator: found TribPort {} - tribSlot {} - tribSlotNb {}",
115 tribPort, tribSlot, tribSlotNb);
119 case StringConstants.SERVICE_TYPE_ODU4:
120 pceResult.setRC(ResponseCodes.RESPONSE_OK);
121 LOG.info("In PostAlgoPathValidator: ODU4 path found {}", path);
125 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
126 LOG.warn("In PostAlgoPathValidator checkPath: unsupported serviceType {} found {}",
134 // Choose the first available wavelength from the source to the destination
135 private Long chooseWavelength(GraphPath<String, PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes) {
136 Long wavelength = -1L;
137 for (long i = 1; i <= MAX_WAWELENGTH; i++) {
138 boolean completed = true;
139 LOG.debug("In chooseWavelength: {} {}", path.getLength(), path);
140 for (PceGraphEdge edge : path.getEdgeList()) {
141 LOG.debug("In chooseWavelength: source {} ", edge.link().getSourceId());
142 PceNode pceNode = allPceNodes.get(edge.link().getSourceId());
143 if (!pceNode.checkWL(i)) {
157 private boolean checkLatency(Long maxLatency, GraphPath<String, PceGraphEdge> path) {
160 for (PceGraphEdge edge : path.getEdgeList()) {
162 latency += edge.link().getLatency();
163 LOG.debug("- In checkLatency: latency of {} = {} units", edge.link().getLinkId().getValue(), latency);
164 } catch (NullPointerException e) {
165 LOG.warn("- In checkLatency: the link {} does not contain latency field",
166 edge.link().getLinkId().getValue());
169 return (latency < maxLatency);
172 // Check the inclusion if it is defined in the hard constraints
173 private boolean checkInclude(GraphPath<String, PceGraphEdge> path, PceConstraints pceHardConstraintsInput) {
174 List<ResourcePair> listToInclude = pceHardConstraintsInput.getListToInclude();
175 if (listToInclude.isEmpty()) {
179 List<PceGraphEdge> pathEdges = path.getEdgeList();
180 LOG.debug(" in checkInclude vertex list: [{}]", path.getVertexList());
182 List<String> listOfElementsSubNode = new ArrayList<>();
183 listOfElementsSubNode.add(pathEdges.get(0).link().getsourceNetworkSupNodeId());
184 listOfElementsSubNode.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.NODE,
185 pceHardConstraintsInput));
187 List<String> listOfElementsCLLI = new ArrayList<>();
188 listOfElementsCLLI.add(pathEdges.get(0).link().getsourceCLLI());
189 listOfElementsCLLI.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.CLLI,
190 pceHardConstraintsInput));
192 List<String> listOfElementsSRLG = new ArrayList<>();
193 // first link is XPONDEROUTPUT, no SRLG for it
194 listOfElementsSRLG.add("NONE");
195 listOfElementsSRLG.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.SRLG,
196 pceHardConstraintsInput));
198 // validation: check each type for each element
199 for (ResourcePair next : listToInclude) {
201 switch (next.getType()) {
203 if (listOfElementsSubNode.contains(next.getName())) {
204 indx = listOfElementsSubNode.indexOf(next.getName());
208 if (listOfElementsSRLG.contains(next.getName())) {
209 indx = listOfElementsSRLG.indexOf(next.getName());
213 if (listOfElementsCLLI.contains(next.getName())) {
214 indx = listOfElementsCLLI.indexOf(next.getName());
218 LOG.warn(" in checkInclude vertex list unsupported resource type: [{}]", next.getType());
222 LOG.debug(" in checkInclude stopped : {} ", next.getName());
226 LOG.debug(" in checkInclude next found {} in {}", next.getName(), path.getVertexList());
228 listOfElementsSubNode.subList(0, indx).clear();
229 listOfElementsCLLI.subList(0, indx).clear();
230 listOfElementsSRLG.subList(0, indx).clear();
233 LOG.info(" in checkInclude passed : {} ", path.getVertexList());
237 private List<String> listOfElementsBuild(List<PceGraphEdge> pathEdges, PceConstraints.ResourceType type,
238 PceConstraints pceHardConstraints) {
240 List<String> listOfElements = new ArrayList<>();
241 for (PceGraphEdge link : pathEdges) {
244 listOfElements.add(link.link().getdestNetworkSupNodeId());
247 listOfElements.add(link.link().getdestCLLI());
250 if (link.link().getlinkType() != OpenroadmLinkType.ROADMTOROADM) {
251 listOfElements.add("NONE");
254 // srlg of link is List<Long>. But in this algo we need string representation of
256 // this should be any SRLG mentioned in include constraints if any of them if
258 boolean found = false;
259 for (Long srlg : link.link().getsrlgList()) {
260 String srlgStr = String.valueOf(srlg);
261 if (pceHardConstraints.getSRLGnames().contains(srlgStr)) {
262 listOfElements.add(srlgStr);
263 LOG.info("listOfElementsBuild. FOUND SRLG {} in link {}", srlgStr, link.link());
268 // there is no specific srlg to include. thus add to list just the first one
269 listOfElements.add("NONE");
273 LOG.debug("listOfElementsBuild unsupported resource type");
276 return listOfElements;
279 private Map<String, Uint16> chooseTribPort(GraphPath<String,
280 PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes) {
281 LOG.info("In choosetribPort: edgeList = {} ", path.getEdgeList());
282 Map<String, Uint16> tribPortMap = new HashMap<>();
284 for (PceGraphEdge edge : path.getEdgeList()) {
285 NodeId linkSrcNode = edge.link().getSourceId();
286 String linkSrcTp = edge.link().getSourceTP().toString();
287 NodeId linkDestNode = edge.link().getDestId();
288 String linkDestTp = edge.link().getDestTP().toString();
289 PceNode pceOtnNodeSrc = allPceNodes.get(linkSrcNode);
290 PceNode pceOtnNodeDest = allPceNodes.get(linkDestNode);
291 List<Uint16> srcTpnPool = pceOtnNodeSrc.getAvailableTribPorts().get(linkSrcTp);
292 List<Uint16> destTpnPool = pceOtnNodeDest.getAvailableTribPorts().get(linkDestTp);
293 List<Uint16> commonEdgeTpnPool = new ArrayList<>();
294 for (Uint16 integer : srcTpnPool) {
295 if (destTpnPool.contains(integer)) {
296 commonEdgeTpnPool.add(integer);
299 Collections.sort(commonEdgeTpnPool);
300 if (!commonEdgeTpnPool.isEmpty()) {
301 tribPortMap.put(edge.link().getLinkId().getValue(), commonEdgeTpnPool.get(0));
304 tribPortMap.forEach((k,v) -> LOG.info("TribPortMap : k = {}, v = {}", k, v));
308 private Map<String, List<Uint16>> chooseTribSlot(GraphPath<String,
309 PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes, int nbSlot) {
310 LOG.info("In choosetribSlot: edgeList = {} ", path.getEdgeList());
311 Map<String, List<Uint16>> tribSlotMap = new HashMap<>();
313 for (PceGraphEdge edge : path.getEdgeList()) {
314 NodeId linkSrcNode = edge.link().getSourceId();
315 String linkSrcTp = edge.link().getSourceTP().toString();
316 NodeId linkDestNode = edge.link().getDestId();
317 String linkDestTp = edge.link().getDestTP().toString();
318 PceNode pceOtnNodeSrc = allPceNodes.get(linkSrcNode);
319 PceNode pceOtnNodeDest = allPceNodes.get(linkDestNode);
320 List<Uint16> srcTsPool = pceOtnNodeSrc.getAvailableTribSlots().get(linkSrcTp);
321 List<Uint16> destTsPool = pceOtnNodeDest.getAvailableTribSlots().get(linkDestTp);
322 List<Uint16> commonEdgeTsPool = new ArrayList<>();
323 List<Uint16> tribSlotList = new ArrayList<>();
324 for (Uint16 integer : srcTsPool) {
325 if (destTsPool.contains(integer)) {
326 commonEdgeTsPool.add(integer);
329 Collections.sort(commonEdgeTsPool);
330 boolean discontinue = true;
332 while (discontinue && (commonEdgeTsPool.size() - index >= nbSlot)) {
334 Integer val = commonEdgeTsPool.get(index).toJava();
335 for (int i = 0; i < nbSlot; i++) {
336 if (commonEdgeTsPool.get(index + i).equals(Uint16.valueOf(val + i))) {
337 tribSlotList.add(commonEdgeTsPool.get(index + i));
340 tribSlotList.clear();
346 tribSlotMap.put(edge.link().getLinkId().getValue(), tribSlotList);
348 tribSlotMap.forEach((k,v) -> LOG.info("TribSlotMap : k = {}, v = {}", k, v));
352 // Check the path OSNR
353 private boolean checkOSNR(GraphPath<String, PceGraphEdge> path) {
356 LOG.info("- In checkOSNR: OSNR of the transmitter = {} dB", TRX_OSNR);
357 LOG.info("- In checkOSNR: add-path incremental OSNR = {} dB", ADD_OSNR);
358 double inverseLocalOsnr = getInverseOsnrLinkLu(TRX_OSNR) + getInverseOsnrLinkLu(ADD_OSNR);
359 for (PceGraphEdge edge : path.getEdgeList()) {
360 if (edge.link().getlinkType() == OpenroadmLinkType.ROADMTOROADM) {
362 linkOsnrDb = edge.link().getosnr();
363 LOG.info("- In checkOSNR: OSNR of {} = {} dB", edge.link().getLinkId().getValue(), linkOsnrDb);
364 // 1 over the local OSNR, in linear units
365 inverseLocalOsnr += getInverseOsnrLinkLu(linkOsnrDb);
369 osnrDb = getOsnrDb(1 / inverseLocalOsnr);
370 } catch (ArithmeticException e) {
371 LOG.debug("In checkOSNR: OSNR is equal to 0 and the number of links is: {}", path.getEdgeList().size());
374 LOG.info("In checkOSNR: OSNR of the path is {} dB", osnrDb);
375 return ((osnrDb + SYS_MARGIN) > MIN_OSNR_W100G);
378 private double getOsnrDb(double osnrLu) {
380 osnrDb = 10 * Math.log10(osnrLu);
384 private double getInverseOsnrLinkLu(double linkOsnrDb) {
385 // 1 over the link OSNR, in linear units
387 linkOsnrLu = Math.pow(10, (linkOsnrDb / 10.0));
388 LOG.debug("In retrieveosnr: the inverse of link osnr is {} (Linear Unit)", linkOsnrLu);
389 return (CONST_OSNR / linkOsnrLu);