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 java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.HashMap;
14 import java.util.List;
17 import org.jgrapht.GraphPath;
18 import org.opendaylight.transportpce.common.ResponseCodes;
19 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
20 import org.opendaylight.transportpce.pce.constraints.PceConstraints.ResourcePair;
21 import org.opendaylight.transportpce.pce.networkanalyzer.PceNode;
22 import org.opendaylight.transportpce.pce.networkanalyzer.PceResult;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
25 import org.opendaylight.yangtools.yang.common.Uint16;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 public class PostAlgoPathValidator {
31 private static final Logger LOG = LoggerFactory.getLogger(PceGraph.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;
41 public PceResult checkPath(GraphPath<String, PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes,
42 PceResult pceResult, PceConstraints pceHardConstraints, String serviceType) {
44 // check if the path is empty
45 if (path.getEdgeList().size() == 0) {
46 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
51 //variable to deal with 1GE (Nb=1) and 10GE (Nb=10) cases
52 switch (serviceType) {
56 // choose wavelength available in all nodes of the path
57 Long waveL = chooseWavelength(path, allPceNodes);
58 pceResult.setServiceType(serviceType);
60 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
61 pceResult.setLocalCause(PceResult.LocalCause.NO_PATH_EXISTS);
64 pceResult.setResultWavelength(waveL);
65 LOG.info("In PostAlgoPathValidator: chooseWavelength WL found {} {}", waveL, path.toString());
68 if (!checkOSNR(path)) {
69 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
70 pceResult.setLocalCause(PceResult.LocalCause.OUT_OF_SPEC_OSNR);
74 // Check if MaxLatency is defined in the hard constraints
75 if ((pceHardConstraints.getMaxLatency() != -1)
76 && (!checkLatency(pceHardConstraints.getMaxLatency(), path))) {
77 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
78 pceResult.setLocalCause(PceResult.LocalCause.TOO_HIGH_LATENCY);
82 // Check if nodes are included in the hard constraints
83 if (!checkInclude(path, pceHardConstraints)) {
84 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
85 pceResult.setLocalCause(PceResult.LocalCause.HD_NODE_INCLUDE);
89 // TODO here other post algo validations can be added
90 // more data can be sent to PceGraph module via PceResult structure if required
92 pceResult.setRC(ResponseCodes.RESPONSE_OK);
93 pceResult.setLocalCause(PceResult.LocalCause.NONE);
101 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
102 pceResult.setServiceType(serviceType);
103 Map<String, Uint16> tribPort = chooseTribPort(path, allPceNodes);
104 Map<String, List<Uint16>> tribSlot = chooseTribSlot(path, allPceNodes, tribSlotNb);
106 if (tribPort != null && tribSlot != null) {
107 pceResult.setResultTribPort(tribPort);
108 pceResult.setResultTribSlot(tribSlot);
109 pceResult.setResultTribSlotNb(tribSlotNb);
110 pceResult.setRC(ResponseCodes.RESPONSE_OK);
111 LOG.info("In PostAlgoPathValidator: found TribPort {} - tribSlot {} - tribSlotNb {}",
112 tribPort, tribSlot, tribSlotNb);
117 pceResult.setRC(ResponseCodes.RESPONSE_OK);
118 LOG.info("In PostAlgoPathValidator: ODU4 path found {}", path.toString());
122 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
123 LOG.warn("In PostAlgoPathValidator checkPath: unsupported serviceType {} found {}",
124 serviceType, path.toString());
131 // Choose the first available wavelength from the source to the destination
132 private Long chooseWavelength(GraphPath<String, PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes) {
133 Long wavelength = -1L;
134 for (long i = 1; i <= MAX_WAWELENGTH; i++) {
135 boolean completed = true;
136 LOG.debug("In chooseWavelength: {} {}", path.getLength(), path.toString());
137 for (PceGraphEdge edge : path.getEdgeList()) {
138 LOG.debug("In chooseWavelength: source {} ", edge.link().getSourceId().toString());
139 PceNode pceNode = allPceNodes.get(edge.link().getSourceId());
140 if (!pceNode.checkWL(i)) {
154 private boolean checkLatency(Long maxLatency, GraphPath<String, PceGraphEdge> path) {
157 for (PceGraphEdge edge : path.getEdgeList()) {
159 latency += edge.link().getLatency();
160 LOG.debug("- In checkLatency: latency of {} = {} units", edge.link().getLinkId().getValue(), latency);
161 } catch (NullPointerException e) {
162 LOG.warn("- In checkLatency: the link {} does not contain latency field",
163 edge.link().getLinkId().getValue());
166 if (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<String>();
183 listOfElementsSubNode.add(pathEdges.get(0).link().getsourceNetworkSupNodeId());
184 listOfElementsSubNode.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.NODE,
185 pceHardConstraintsInput));
187 List<String> listOfElementsCLLI = new ArrayList<String>();
188 listOfElementsCLLI.add(pathEdges.get(0).link().getsourceCLLI());
189 listOfElementsCLLI.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.CLLI,
190 pceHardConstraintsInput));
192 List<String> listOfElementsSRLG = new ArrayList<String>();
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<String>();
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());
269 // there is no specific srlg to include. thus add to list just the first one
270 listOfElements.add("NONE");
274 LOG.debug("listOfElementsBuild unsupported resource type");
277 return listOfElements;
280 private Map<String, Uint16> chooseTribPort(GraphPath<String,
281 PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes) {
282 LOG.info("In choosetribPort: edgeList = {} ", path.getEdgeList().toString());
283 Map<String, Uint16> tribPortMap = new HashMap<>();
285 for (PceGraphEdge edge : path.getEdgeList()) {
286 NodeId linkSrcNode = edge.link().getSourceId();
287 String linkSrcTp = edge.link().getSourceTP().toString();
288 NodeId linkDestNode = edge.link().getDestId();
289 String linkDestTp = edge.link().getDestTP().toString();
290 PceNode pceOtnNodeSrc = allPceNodes.get(linkSrcNode);
291 PceNode pceOtnNodeDest = allPceNodes.get(linkDestNode);
292 List<Uint16> srcTpnPool = pceOtnNodeSrc.getAvailableTribPorts().get(linkSrcTp);
293 List<Uint16> destTpnPool = pceOtnNodeDest.getAvailableTribPorts().get(linkDestTp);
294 List<Uint16> commonEdgeTpnPool = new ArrayList<>();
295 for (Uint16 integer : srcTpnPool) {
296 if (destTpnPool.contains(integer)) {
297 commonEdgeTpnPool.add(integer);
300 Collections.sort(commonEdgeTpnPool);
301 if (!commonEdgeTpnPool.isEmpty()) {
302 tribPortMap.put(edge.link().getLinkId().getValue(), commonEdgeTpnPool.get(0));
305 tribPortMap.forEach((k,v) -> LOG.info("TribPortMap : k = {}, v = {}", k, v));
309 private Map<String, List<Uint16>> chooseTribSlot(GraphPath<String,
310 PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes, int nbSlot) {
311 LOG.info("In choosetribSlot2: edgeList = {} ", path.getEdgeList().toString());
312 Map<String, List<Uint16>> tribSlotMap = new HashMap<>();
314 for (PceGraphEdge edge : path.getEdgeList()) {
315 NodeId linkSrcNode = edge.link().getSourceId();
316 String linkSrcTp = edge.link().getSourceTP().toString();
317 NodeId linkDestNode = edge.link().getDestId();
318 String linkDestTp = edge.link().getDestTP().toString();
319 PceNode pceOtnNodeSrc = allPceNodes.get(linkSrcNode);
320 PceNode pceOtnNodeDest = allPceNodes.get(linkDestNode);
321 List<Uint16> srcTsPool = pceOtnNodeSrc.getAvailableTribSlots().get(linkSrcTp);
322 List<Uint16> destTsPool = pceOtnNodeDest.getAvailableTribSlots().get(linkDestTp);
323 List<Uint16> commonEdgeTsPool = new ArrayList<>();
324 List<Uint16> tribSlotList = new ArrayList<>();
325 for (Uint16 integer : srcTsPool) {
326 if (destTsPool.contains(integer)) {
327 commonEdgeTsPool.add(integer);
330 Collections.sort(commonEdgeTsPool);
331 boolean discontinue = true;
333 while (discontinue && (commonEdgeTsPool.size() - index >= nbSlot)) {
335 Integer val = commonEdgeTsPool.get(index).toJava();
336 for (int i = 0; i < nbSlot; i++) {
337 if (commonEdgeTsPool.get(index + i).equals(val + i)) {
338 tribSlotList.add(commonEdgeTsPool.get(index + i));
341 tribSlotList.clear();
347 tribSlotMap.put(edge.link().getLinkId().getValue(), tribSlotList);
349 tribSlotMap.forEach((k,v) -> LOG.info("TribSlotMap : k = {}, v = {}", k, v));
353 private List<List<Uint16>> chooseTribSlot3(GraphPath<String, PceGraphEdge> path,
354 Map<NodeId, PceNode> allPceNodes) {
355 List<List<Uint16>> tribSlot = new ArrayList<>();
356 boolean statusOK = true;
357 boolean check = false;
358 Object nodeClass = allPceNodes.getClass();
359 if (nodeClass.getClass().isInstance(PceNode.class)) {
360 LOG.debug("In choosetribSlot: AllPceNodes contains PceNode instance, no trib port search");
362 } else if (nodeClass.getClass().isInstance(PceNode.class)) {
363 LOG.debug("In choosetribPort: {} {}", path.getLength(), path.toString());
365 for (PceGraphEdge edge : path.getEdgeList()) {
366 LOG.debug("In chooseTribSlot: source {} ", edge.link().getSourceId().toString());
367 PceNode pceNode = allPceNodes.get(edge.link().getSourceId());
368 Object tps = allPceNodes.get(edge.link().getSourceTP());
369 Object tpd = allPceNodes.get(edge.link().getDestTP());
370 if ((pceNode.getAvailableTribSlots().containsKey(tps.toString()))
371 && (pceNode.getAvailableTribSlots().containsKey(tpd.toString()))) {
372 List<Uint16> tribSlotEdgeSourceN = new ArrayList<>();
373 List<Uint16> tribSlotEdgeDestN = new ArrayList<>();
374 tribSlotEdgeSourceN = pceNode.getAvailableTribSlots().get(tps.toString());
375 tribSlotEdgeDestN = pceNode.getAvailableTribSlots().get(tps.toString());
377 for (int i = 0; i <= 79; i++) {
378 if (tribSlotEdgeSourceN.get(i) == null) {
381 // TODO This will need to be modified as soon as the trib-slots allocation per
383 // policy applied by the different manufacturer is known
384 if (tribSlotEdgeSourceN.get(i) == tribSlotEdgeDestN.get(i)) {
388 LOG.debug("In chooseTribSlot: Misalignement of trib slots between source {} and dest {}",
389 edge.link().getSourceId().toString(), edge.link().getDestId().toString());
394 tribSlot.add(tribSlotEdgeSourceN);
397 LOG.debug("In chooseTribSlot: source {} does not have provisonned hosting HO interface ",
398 edge.link().getSourceId().toString());
402 if (statusOK && check) {
410 // Check the path OSNR
411 private boolean checkOSNR(GraphPath<String, PceGraphEdge> path) {
414 LOG.info("- In checkOSNR: OSNR of the transmitter = {} dB", TRX_OSNR);
415 LOG.info("- In checkOSNR: add-path incremental OSNR = {} dB", ADD_OSNR);
416 double inverseLocalOsnr = getInverseOsnrLinkLu(TRX_OSNR) + getInverseOsnrLinkLu(ADD_OSNR);
417 for (PceGraphEdge edge : path.getEdgeList()) {
418 if (edge.link().getlinkType() == OpenroadmLinkType.ROADMTOROADM) {
420 linkOsnrDb = edge.link().getosnr();
421 LOG.info("- In checkOSNR: OSNR of {} = {} dB", edge.link().getLinkId().getValue(), linkOsnrDb);
422 // 1 over the local OSNR, in linear units
423 inverseLocalOsnr += getInverseOsnrLinkLu(linkOsnrDb);
427 osnrDb = getOsnrDb(1 / inverseLocalOsnr);
428 } catch (ArithmeticException e) {
429 LOG.debug("In checkOSNR: OSNR is equal to 0 and the number of links is: {}", path.getEdgeList().size());
432 LOG.info("In checkOSNR: OSNR of the path is {} dB", osnrDb);
433 if ((osnrDb + SYS_MARGIN) < MIN_OSNR_W100G) {
439 private double getOsnrDb(double osnrLu) {
441 osnrDb = 10 * Math.log10(osnrLu);
445 private double getInverseOsnrLinkLu(double linkOsnrDb) {
446 // 1 over the link OSNR, in linear units
448 linkOsnrLu = Math.pow(10, (linkOsnrDb / 10.0));
449 LOG.debug("In retrieveosnr: the inverse of link osnr is {} (Linear Unit)", linkOsnrLu);
450 return (CONST_OSNR / linkOsnrLu);