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(PostAlgoPathValidator.class);
33 private static final int MAX_WAWELENGTH = 96;
34 private static final double MIN_OSNR_W100G = 17;
35 private static final double TRX_OSNR = 33;
36 private static final double ADD_OSNR = 30;
37 public static final Long CONST_OSNR = 1L;
38 public static final double SYS_MARGIN = 0;
40 public PceResult checkPath(GraphPath<String, PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes,
41 PceResult pceResult, PceConstraints pceHardConstraints, String serviceType) {
43 // check if the path is empty
44 if (path.getEdgeList().isEmpty()) {
45 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
50 //variable to deal with 1GE (Nb=1) and 10GE (Nb=10) cases
51 switch (serviceType) {
55 // choose wavelength available in all nodes of the path
56 Long waveL = chooseWavelength(path, allPceNodes);
57 pceResult.setServiceType(serviceType);
59 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
60 pceResult.setLocalCause(PceResult.LocalCause.NO_PATH_EXISTS);
63 pceResult.setResultWavelength(waveL);
64 LOG.info("In PostAlgoPathValidator: chooseWavelength WL found {} {}", waveL, path);
67 if (!checkOSNR(path)) {
68 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
69 pceResult.setLocalCause(PceResult.LocalCause.OUT_OF_SPEC_OSNR);
73 // Check if MaxLatency is defined in the hard constraints
74 if ((pceHardConstraints.getMaxLatency() != -1)
75 && (!checkLatency(pceHardConstraints.getMaxLatency(), path))) {
76 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
77 pceResult.setLocalCause(PceResult.LocalCause.TOO_HIGH_LATENCY);
81 // Check if nodes are included in the hard constraints
82 if (!checkInclude(path, pceHardConstraints)) {
83 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
84 pceResult.setLocalCause(PceResult.LocalCause.HD_NODE_INCLUDE);
88 // TODO here other post algo validations can be added
89 // more data can be sent to PceGraph module via PceResult structure if required
91 pceResult.setRC(ResponseCodes.RESPONSE_OK);
92 pceResult.setLocalCause(PceResult.LocalCause.NONE);
100 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
101 pceResult.setServiceType(serviceType);
102 Map<String, Uint16> tribPort = chooseTribPort(path, allPceNodes);
103 Map<String, List<Uint16>> tribSlot = chooseTribSlot(path, allPceNodes, tribSlotNb);
105 if (tribPort != null && tribSlot != null) {
106 pceResult.setResultTribPort(tribPort);
107 pceResult.setResultTribSlot(tribSlot);
108 pceResult.setResultTribSlotNb(tribSlotNb);
109 pceResult.setRC(ResponseCodes.RESPONSE_OK);
110 LOG.info("In PostAlgoPathValidator: found TribPort {} - tribSlot {} - tribSlotNb {}",
111 tribPort, tribSlot, tribSlotNb);
116 pceResult.setRC(ResponseCodes.RESPONSE_OK);
117 LOG.info("In PostAlgoPathValidator: ODU4 path found {}", path);
121 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
122 LOG.warn("In PostAlgoPathValidator checkPath: unsupported serviceType {} found {}",
130 // Choose the first available wavelength from the source to the destination
131 private Long chooseWavelength(GraphPath<String, PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes) {
132 Long wavelength = -1L;
133 for (long i = 1; i <= MAX_WAWELENGTH; i++) {
134 boolean completed = true;
135 LOG.debug("In chooseWavelength: {} {}", path.getLength(), path);
136 for (PceGraphEdge edge : path.getEdgeList()) {
137 LOG.debug("In chooseWavelength: source {} ", edge.link().getSourceId());
138 PceNode pceNode = allPceNodes.get(edge.link().getSourceId());
139 if (!pceNode.checkWL(i)) {
153 private boolean checkLatency(Long maxLatency, GraphPath<String, PceGraphEdge> path) {
156 for (PceGraphEdge edge : path.getEdgeList()) {
158 latency += edge.link().getLatency();
159 LOG.debug("- In checkLatency: latency of {} = {} units", edge.link().getLinkId().getValue(), latency);
160 } catch (NullPointerException e) {
161 LOG.warn("- In checkLatency: the link {} does not contain latency field",
162 edge.link().getLinkId().getValue());
165 return (latency < maxLatency);
168 // Check the inclusion if it is defined in the hard constraints
169 private boolean checkInclude(GraphPath<String, PceGraphEdge> path, PceConstraints pceHardConstraintsInput) {
170 List<ResourcePair> listToInclude = pceHardConstraintsInput.getListToInclude();
171 if (listToInclude.isEmpty()) {
175 List<PceGraphEdge> pathEdges = path.getEdgeList();
176 LOG.debug(" in checkInclude vertex list: [{}]", path.getVertexList());
178 List<String> listOfElementsSubNode = new ArrayList<>();
179 listOfElementsSubNode.add(pathEdges.get(0).link().getsourceNetworkSupNodeId());
180 listOfElementsSubNode.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.NODE,
181 pceHardConstraintsInput));
183 List<String> listOfElementsCLLI = new ArrayList<>();
184 listOfElementsCLLI.add(pathEdges.get(0).link().getsourceCLLI());
185 listOfElementsCLLI.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.CLLI,
186 pceHardConstraintsInput));
188 List<String> listOfElementsSRLG = new ArrayList<>();
189 // first link is XPONDEROUTPUT, no SRLG for it
190 listOfElementsSRLG.add("NONE");
191 listOfElementsSRLG.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.SRLG,
192 pceHardConstraintsInput));
194 // validation: check each type for each element
195 for (ResourcePair next : listToInclude) {
197 switch (next.getType()) {
199 if (listOfElementsSubNode.contains(next.getName())) {
200 indx = listOfElementsSubNode.indexOf(next.getName());
204 if (listOfElementsSRLG.contains(next.getName())) {
205 indx = listOfElementsSRLG.indexOf(next.getName());
209 if (listOfElementsCLLI.contains(next.getName())) {
210 indx = listOfElementsCLLI.indexOf(next.getName());
214 LOG.warn(" in checkInclude vertex list unsupported resource type: [{}]", next.getType());
218 LOG.debug(" in checkInclude stopped : {} ", next.getName());
222 LOG.debug(" in checkInclude next found {} in {}", next.getName(), path.getVertexList());
224 listOfElementsSubNode.subList(0, indx).clear();
225 listOfElementsCLLI.subList(0, indx).clear();
226 listOfElementsSRLG.subList(0, indx).clear();
229 LOG.info(" in checkInclude passed : {} ", path.getVertexList());
233 private List<String> listOfElementsBuild(List<PceGraphEdge> pathEdges, PceConstraints.ResourceType type,
234 PceConstraints pceHardConstraints) {
236 List<String> listOfElements = new ArrayList<>();
237 for (PceGraphEdge link : pathEdges) {
240 listOfElements.add(link.link().getdestNetworkSupNodeId());
243 listOfElements.add(link.link().getdestCLLI());
246 if (link.link().getlinkType() != OpenroadmLinkType.ROADMTOROADM) {
247 listOfElements.add("NONE");
250 // srlg of link is List<Long>. But in this algo we need string representation of
252 // this should be any SRLG mentioned in include constraints if any of them if
254 boolean found = false;
255 for (Long srlg : link.link().getsrlgList()) {
256 String srlgStr = String.valueOf(srlg);
257 if (pceHardConstraints.getSRLGnames().contains(srlgStr)) {
258 listOfElements.add(srlgStr);
259 LOG.info("listOfElementsBuild. FOUND SRLG {} in link {}", srlgStr, link.link());
264 // there is no specific srlg to include. thus add to list just the first one
265 listOfElements.add("NONE");
269 LOG.debug("listOfElementsBuild unsupported resource type");
272 return listOfElements;
275 private Map<String, Uint16> chooseTribPort(GraphPath<String,
276 PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes) {
277 LOG.info("In choosetribPort: edgeList = {} ", path.getEdgeList());
278 Map<String, Uint16> tribPortMap = new HashMap<>();
280 for (PceGraphEdge edge : path.getEdgeList()) {
281 NodeId linkSrcNode = edge.link().getSourceId();
282 String linkSrcTp = edge.link().getSourceTP().toString();
283 NodeId linkDestNode = edge.link().getDestId();
284 String linkDestTp = edge.link().getDestTP().toString();
285 PceNode pceOtnNodeSrc = allPceNodes.get(linkSrcNode);
286 PceNode pceOtnNodeDest = allPceNodes.get(linkDestNode);
287 List<Uint16> srcTpnPool = pceOtnNodeSrc.getAvailableTribPorts().get(linkSrcTp);
288 List<Uint16> destTpnPool = pceOtnNodeDest.getAvailableTribPorts().get(linkDestTp);
289 List<Uint16> commonEdgeTpnPool = new ArrayList<>();
290 for (Uint16 integer : srcTpnPool) {
291 if (destTpnPool.contains(integer)) {
292 commonEdgeTpnPool.add(integer);
295 Collections.sort(commonEdgeTpnPool);
296 if (!commonEdgeTpnPool.isEmpty()) {
297 tribPortMap.put(edge.link().getLinkId().getValue(), commonEdgeTpnPool.get(0));
300 tribPortMap.forEach((k,v) -> LOG.info("TribPortMap : k = {}, v = {}", k, v));
304 private Map<String, List<Uint16>> chooseTribSlot(GraphPath<String,
305 PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes, int nbSlot) {
306 LOG.info("In choosetribSlot2: edgeList = {} ", path.getEdgeList());
307 Map<String, List<Uint16>> tribSlotMap = new HashMap<>();
309 for (PceGraphEdge edge : path.getEdgeList()) {
310 NodeId linkSrcNode = edge.link().getSourceId();
311 String linkSrcTp = edge.link().getSourceTP().toString();
312 NodeId linkDestNode = edge.link().getDestId();
313 String linkDestTp = edge.link().getDestTP().toString();
314 PceNode pceOtnNodeSrc = allPceNodes.get(linkSrcNode);
315 PceNode pceOtnNodeDest = allPceNodes.get(linkDestNode);
316 List<Uint16> srcTsPool = pceOtnNodeSrc.getAvailableTribSlots().get(linkSrcTp);
317 List<Uint16> destTsPool = pceOtnNodeDest.getAvailableTribSlots().get(linkDestTp);
318 List<Uint16> commonEdgeTsPool = new ArrayList<>();
319 List<Uint16> tribSlotList = new ArrayList<>();
320 for (Uint16 integer : srcTsPool) {
321 if (destTsPool.contains(integer)) {
322 commonEdgeTsPool.add(integer);
325 Collections.sort(commonEdgeTsPool);
326 boolean discontinue = true;
328 while (discontinue && (commonEdgeTsPool.size() - index >= nbSlot)) {
330 Integer val = commonEdgeTsPool.get(index).toJava();
331 for (int i = 0; i < nbSlot; i++) {
332 if (commonEdgeTsPool.get(index + i).equals(Uint16.valueOf(val + i))) {
333 tribSlotList.add(commonEdgeTsPool.get(index + i));
336 tribSlotList.clear();
342 tribSlotMap.put(edge.link().getLinkId().getValue(), tribSlotList);
344 tribSlotMap.forEach((k,v) -> LOG.info("TribSlotMap : k = {}, v = {}", k, v));
348 private List<List<Uint16>> chooseTribSlot3(GraphPath<String, PceGraphEdge> path,
349 Map<NodeId, PceNode> allPceNodes) {
350 List<List<Uint16>> tribSlot = new ArrayList<>();
351 boolean statusOK = true;
352 boolean check = false;
353 Object nodeClass = allPceNodes.getClass();
354 if (nodeClass.getClass().isInstance(PceNode.class)) {
355 LOG.debug("In choosetribSlot: AllPceNodes contains PceNode instance, no trib port search");
357 } else if (nodeClass.getClass().isInstance(PceNode.class)) {
358 LOG.debug("In choosetribPort: {} {}", path.getLength(), path);
360 for (PceGraphEdge edge : path.getEdgeList()) {
361 LOG.debug("In chooseTribSlot: source {} ", edge.link().getSourceId());
362 PceNode pceNode = allPceNodes.get(edge.link().getSourceId());
363 Object tps = allPceNodes.get(edge.link().getSourceTP());
364 Object tpd = allPceNodes.get(edge.link().getDestTP());
365 if ((pceNode.getAvailableTribSlots().containsKey(tps.toString()))
366 && (pceNode.getAvailableTribSlots().containsKey(tpd.toString()))) {
367 List<Uint16> tribSlotEdgeSourceN = pceNode.getAvailableTribSlots().get(tps.toString());
368 List<Uint16> tribSlotEdgeDestN = pceNode.getAvailableTribSlots().get(tps.toString());
370 for (int i = 0; i <= 79; i++) {
371 if (tribSlotEdgeSourceN.get(i) == null) {
374 // TODO This will need to be modified as soon as the trib-slots allocation per
376 // policy applied by the different manufacturer is known
377 if (tribSlotEdgeSourceN.get(i).equals(tribSlotEdgeDestN.get(i))) {
381 LOG.debug("In chooseTribSlot: Misalignement of trib slots between source {} and dest {}",
382 edge.link().getSourceId(), edge.link().getDestId());
387 tribSlot.add(tribSlotEdgeSourceN);
390 LOG.debug("In chooseTribSlot: source {} does not have provisonned hosting HO interface ",
391 edge.link().getSourceId());
395 if (statusOK && check) {
403 // Check the path OSNR
404 private boolean checkOSNR(GraphPath<String, PceGraphEdge> path) {
407 LOG.info("- In checkOSNR: OSNR of the transmitter = {} dB", TRX_OSNR);
408 LOG.info("- In checkOSNR: add-path incremental OSNR = {} dB", ADD_OSNR);
409 double inverseLocalOsnr = getInverseOsnrLinkLu(TRX_OSNR) + getInverseOsnrLinkLu(ADD_OSNR);
410 for (PceGraphEdge edge : path.getEdgeList()) {
411 if (edge.link().getlinkType() == OpenroadmLinkType.ROADMTOROADM) {
413 linkOsnrDb = edge.link().getosnr();
414 LOG.info("- In checkOSNR: OSNR of {} = {} dB", edge.link().getLinkId().getValue(), linkOsnrDb);
415 // 1 over the local OSNR, in linear units
416 inverseLocalOsnr += getInverseOsnrLinkLu(linkOsnrDb);
420 osnrDb = getOsnrDb(1 / inverseLocalOsnr);
421 } catch (ArithmeticException e) {
422 LOG.debug("In checkOSNR: OSNR is equal to 0 and the number of links is: {}", path.getEdgeList().size());
425 LOG.info("In checkOSNR: OSNR of the path is {} dB", osnrDb);
426 return ((osnrDb + SYS_MARGIN) > MIN_OSNR_W100G);
429 private double getOsnrDb(double osnrLu) {
431 osnrDb = 10 * Math.log10(osnrLu);
435 private double getInverseOsnrLinkLu(double linkOsnrDb) {
436 // 1 over the link OSNR, in linear units
438 linkOsnrLu = Math.pow(10, (linkOsnrDb / 10.0));
439 LOG.debug("In retrieveosnr: the inverse of link osnr is {} (Linear Unit)", linkOsnrLu);
440 return (CONST_OSNR / linkOsnrLu);