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;
16 import org.jgrapht.GraphPath;
17 import org.opendaylight.transportpce.common.ResponseCodes;
18 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
19 import org.opendaylight.transportpce.pce.constraints.PceConstraints.ResourcePair;
20 import org.opendaylight.transportpce.pce.networkanalyzer.PceNode;
21 import org.opendaylight.transportpce.pce.networkanalyzer.PceResult;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
24 import org.opendaylight.yangtools.yang.common.Uint16;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class PostAlgoPathValidator {
30 private static final Logger LOG = LoggerFactory.getLogger(PostAlgoPathValidator.class);
32 private static final int MAX_WAWELENGTH = 96;
33 private static final double MIN_OSNR_W100G = 17;
34 private static final double TRX_OSNR = 33;
35 private static final double ADD_OSNR = 30;
36 public static final Long CONST_OSNR = 1L;
37 public static final double SYS_MARGIN = 0;
39 public PceResult checkPath(GraphPath<String, PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes,
40 PceResult pceResult, PceConstraints pceHardConstraints, String serviceType) {
42 // check if the path is empty
43 if (path.getEdgeList().isEmpty()) {
44 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
49 //variable to deal with 1GE (Nb=1) and 10GE (Nb=10) cases
50 switch (serviceType) {
54 // choose wavelength available in all nodes of the path
55 Long waveL = chooseWavelength(path, allPceNodes);
56 pceResult.setServiceType(serviceType);
58 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
59 pceResult.setLocalCause(PceResult.LocalCause.NO_PATH_EXISTS);
62 pceResult.setResultWavelength(waveL);
63 LOG.info("In PostAlgoPathValidator: chooseWavelength WL found {} {}", waveL, path);
66 if (!checkOSNR(path)) {
67 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
68 pceResult.setLocalCause(PceResult.LocalCause.OUT_OF_SPEC_OSNR);
72 // Check if MaxLatency is defined in the hard constraints
73 if ((pceHardConstraints.getMaxLatency() != -1)
74 && (!checkLatency(pceHardConstraints.getMaxLatency(), path))) {
75 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
76 pceResult.setLocalCause(PceResult.LocalCause.TOO_HIGH_LATENCY);
80 // Check if nodes are included in the hard constraints
81 if (!checkInclude(path, pceHardConstraints)) {
82 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
83 pceResult.setLocalCause(PceResult.LocalCause.HD_NODE_INCLUDE);
87 // TODO here other post algo validations can be added
88 // more data can be sent to PceGraph module via PceResult structure if required
90 pceResult.setRC(ResponseCodes.RESPONSE_OK);
91 pceResult.setLocalCause(PceResult.LocalCause.NONE);
99 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
100 pceResult.setServiceType(serviceType);
101 Map<String, Uint16> tribPort = chooseTribPort(path, allPceNodes);
102 Map<String, List<Uint16>> tribSlot = chooseTribSlot(path, allPceNodes, tribSlotNb);
104 if (tribPort != null && tribSlot != null) {
105 pceResult.setResultTribPort(tribPort);
106 pceResult.setResultTribSlot(tribSlot);
107 pceResult.setResultTribSlotNb(tribSlotNb);
108 pceResult.setRC(ResponseCodes.RESPONSE_OK);
109 LOG.info("In PostAlgoPathValidator: found TribPort {} - tribSlot {} - tribSlotNb {}",
110 tribPort, tribSlot, tribSlotNb);
115 pceResult.setRC(ResponseCodes.RESPONSE_OK);
116 LOG.info("In PostAlgoPathValidator: ODU4 path found {}", path);
120 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
121 LOG.warn("In PostAlgoPathValidator checkPath: unsupported serviceType {} found {}",
129 // Choose the first available wavelength from the source to the destination
130 private Long chooseWavelength(GraphPath<String, PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes) {
131 Long wavelength = -1L;
132 for (long i = 1; i <= MAX_WAWELENGTH; i++) {
133 boolean completed = true;
134 LOG.debug("In chooseWavelength: {} {}", path.getLength(), path);
135 for (PceGraphEdge edge : path.getEdgeList()) {
136 LOG.debug("In chooseWavelength: source {} ", edge.link().getSourceId());
137 PceNode pceNode = allPceNodes.get(edge.link().getSourceId());
138 if (!pceNode.checkWL(i)) {
152 private boolean checkLatency(Long maxLatency, GraphPath<String, PceGraphEdge> path) {
155 for (PceGraphEdge edge : path.getEdgeList()) {
157 latency += edge.link().getLatency();
158 LOG.debug("- In checkLatency: latency of {} = {} units", edge.link().getLinkId().getValue(), latency);
159 } catch (NullPointerException e) {
160 LOG.warn("- In checkLatency: the link {} does not contain latency field",
161 edge.link().getLinkId().getValue());
164 return (latency < maxLatency);
167 // Check the inclusion if it is defined in the hard constraints
168 private boolean checkInclude(GraphPath<String, PceGraphEdge> path, PceConstraints pceHardConstraintsInput) {
169 List<ResourcePair> listToInclude = pceHardConstraintsInput.getListToInclude();
170 if (listToInclude.isEmpty()) {
174 List<PceGraphEdge> pathEdges = path.getEdgeList();
175 LOG.debug(" in checkInclude vertex list: [{}]", path.getVertexList());
177 List<String> listOfElementsSubNode = new ArrayList<>();
178 listOfElementsSubNode.add(pathEdges.get(0).link().getsourceNetworkSupNodeId());
179 listOfElementsSubNode.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.NODE,
180 pceHardConstraintsInput));
182 List<String> listOfElementsCLLI = new ArrayList<>();
183 listOfElementsCLLI.add(pathEdges.get(0).link().getsourceCLLI());
184 listOfElementsCLLI.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.CLLI,
185 pceHardConstraintsInput));
187 List<String> listOfElementsSRLG = new ArrayList<>();
188 // first link is XPONDEROUTPUT, no SRLG for it
189 listOfElementsSRLG.add("NONE");
190 listOfElementsSRLG.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.SRLG,
191 pceHardConstraintsInput));
193 // validation: check each type for each element
194 for (ResourcePair next : listToInclude) {
196 switch (next.getType()) {
198 if (listOfElementsSubNode.contains(next.getName())) {
199 indx = listOfElementsSubNode.indexOf(next.getName());
203 if (listOfElementsSRLG.contains(next.getName())) {
204 indx = listOfElementsSRLG.indexOf(next.getName());
208 if (listOfElementsCLLI.contains(next.getName())) {
209 indx = listOfElementsCLLI.indexOf(next.getName());
213 LOG.warn(" in checkInclude vertex list unsupported resource type: [{}]", next.getType());
217 LOG.debug(" in checkInclude stopped : {} ", next.getName());
221 LOG.debug(" in checkInclude next found {} in {}", next.getName(), path.getVertexList());
223 listOfElementsSubNode.subList(0, indx).clear();
224 listOfElementsCLLI.subList(0, indx).clear();
225 listOfElementsSRLG.subList(0, indx).clear();
228 LOG.info(" in checkInclude passed : {} ", path.getVertexList());
232 private List<String> listOfElementsBuild(List<PceGraphEdge> pathEdges, PceConstraints.ResourceType type,
233 PceConstraints pceHardConstraints) {
235 List<String> listOfElements = new ArrayList<>();
236 for (PceGraphEdge link : pathEdges) {
239 listOfElements.add(link.link().getdestNetworkSupNodeId());
242 listOfElements.add(link.link().getdestCLLI());
245 if (link.link().getlinkType() != OpenroadmLinkType.ROADMTOROADM) {
246 listOfElements.add("NONE");
249 // srlg of link is List<Long>. But in this algo we need string representation of
251 // this should be any SRLG mentioned in include constraints if any of them if
253 boolean found = false;
254 for (Long srlg : link.link().getsrlgList()) {
255 String srlgStr = String.valueOf(srlg);
256 if (pceHardConstraints.getSRLGnames().contains(srlgStr)) {
257 listOfElements.add(srlgStr);
258 LOG.info("listOfElementsBuild. FOUND SRLG {} in link {}", srlgStr, link.link());
263 // there is no specific srlg to include. thus add to list just the first one
264 listOfElements.add("NONE");
268 LOG.debug("listOfElementsBuild unsupported resource type");
271 return listOfElements;
274 private Map<String, Uint16> chooseTribPort(GraphPath<String,
275 PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes) {
276 LOG.info("In choosetribPort: edgeList = {} ", path.getEdgeList());
277 Map<String, Uint16> tribPortMap = new HashMap<>();
279 for (PceGraphEdge edge : path.getEdgeList()) {
280 NodeId linkSrcNode = edge.link().getSourceId();
281 String linkSrcTp = edge.link().getSourceTP().toString();
282 NodeId linkDestNode = edge.link().getDestId();
283 String linkDestTp = edge.link().getDestTP().toString();
284 PceNode pceOtnNodeSrc = allPceNodes.get(linkSrcNode);
285 PceNode pceOtnNodeDest = allPceNodes.get(linkDestNode);
286 List<Uint16> srcTpnPool = pceOtnNodeSrc.getAvailableTribPorts().get(linkSrcTp);
287 List<Uint16> destTpnPool = pceOtnNodeDest.getAvailableTribPorts().get(linkDestTp);
288 List<Uint16> commonEdgeTpnPool = new ArrayList<>();
289 for (Uint16 integer : srcTpnPool) {
290 if (destTpnPool.contains(integer)) {
291 commonEdgeTpnPool.add(integer);
294 Collections.sort(commonEdgeTpnPool);
295 if (!commonEdgeTpnPool.isEmpty()) {
296 tribPortMap.put(edge.link().getLinkId().getValue(), commonEdgeTpnPool.get(0));
299 tribPortMap.forEach((k,v) -> LOG.info("TribPortMap : k = {}, v = {}", k, v));
303 private Map<String, List<Uint16>> chooseTribSlot(GraphPath<String,
304 PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes, int nbSlot) {
305 LOG.info("In choosetribSlot2: edgeList = {} ", path.getEdgeList());
306 Map<String, List<Uint16>> tribSlotMap = new HashMap<>();
308 for (PceGraphEdge edge : path.getEdgeList()) {
309 NodeId linkSrcNode = edge.link().getSourceId();
310 String linkSrcTp = edge.link().getSourceTP().toString();
311 NodeId linkDestNode = edge.link().getDestId();
312 String linkDestTp = edge.link().getDestTP().toString();
313 PceNode pceOtnNodeSrc = allPceNodes.get(linkSrcNode);
314 PceNode pceOtnNodeDest = allPceNodes.get(linkDestNode);
315 List<Uint16> srcTsPool = pceOtnNodeSrc.getAvailableTribSlots().get(linkSrcTp);
316 List<Uint16> destTsPool = pceOtnNodeDest.getAvailableTribSlots().get(linkDestTp);
317 List<Uint16> commonEdgeTsPool = new ArrayList<>();
318 List<Uint16> tribSlotList = new ArrayList<>();
319 for (Uint16 integer : srcTsPool) {
320 if (destTsPool.contains(integer)) {
321 commonEdgeTsPool.add(integer);
324 Collections.sort(commonEdgeTsPool);
325 boolean discontinue = true;
327 while (discontinue && (commonEdgeTsPool.size() - index >= nbSlot)) {
329 Integer val = commonEdgeTsPool.get(index).toJava();
330 for (int i = 0; i < nbSlot; i++) {
331 if (commonEdgeTsPool.get(index + i).equals(Uint16.valueOf(val + i))) {
332 tribSlotList.add(commonEdgeTsPool.get(index + i));
335 tribSlotList.clear();
341 tribSlotMap.put(edge.link().getLinkId().getValue(), tribSlotList);
343 tribSlotMap.forEach((k,v) -> LOG.info("TribSlotMap : k = {}, v = {}", k, v));
347 private List<List<Uint16>> chooseTribSlot3(GraphPath<String, PceGraphEdge> path,
348 Map<NodeId, PceNode> allPceNodes) {
349 List<List<Uint16>> tribSlot = new ArrayList<>();
350 boolean statusOK = true;
351 boolean check = false;
352 Object nodeClass = allPceNodes.getClass();
353 if (nodeClass.getClass().isInstance(PceNode.class)) {
354 LOG.debug("In choosetribSlot: AllPceNodes contains PceNode instance, no trib port search");
356 } else if (nodeClass.getClass().isInstance(PceNode.class)) {
357 LOG.debug("In choosetribPort: {} {}", path.getLength(), path);
359 for (PceGraphEdge edge : path.getEdgeList()) {
360 LOG.debug("In chooseTribSlot: source {} ", edge.link().getSourceId());
361 PceNode pceNode = allPceNodes.get(edge.link().getSourceId());
362 Object tps = allPceNodes.get(edge.link().getSourceTP());
363 Object tpd = allPceNodes.get(edge.link().getDestTP());
364 if ((pceNode.getAvailableTribSlots().containsKey(tps.toString()))
365 && (pceNode.getAvailableTribSlots().containsKey(tpd.toString()))) {
366 List<Uint16> tribSlotEdgeSourceN = pceNode.getAvailableTribSlots().get(tps.toString());
367 List<Uint16> tribSlotEdgeDestN = pceNode.getAvailableTribSlots().get(tps.toString());
369 for (int i = 0; i <= 79; i++) {
370 if (tribSlotEdgeSourceN.get(i) == null) {
373 // TODO This will need to be modified as soon as the trib-slots allocation per
375 // policy applied by the different manufacturer is known
376 if (tribSlotEdgeSourceN.get(i).equals(tribSlotEdgeDestN.get(i))) {
380 LOG.debug("In chooseTribSlot: Misalignement of trib slots between source {} and dest {}",
381 edge.link().getSourceId(), edge.link().getDestId());
386 tribSlot.add(tribSlotEdgeSourceN);
389 LOG.debug("In chooseTribSlot: source {} does not have provisonned hosting HO interface ",
390 edge.link().getSourceId());
394 if (statusOK && check) {
402 // Check the path OSNR
403 private boolean checkOSNR(GraphPath<String, PceGraphEdge> path) {
406 LOG.info("- In checkOSNR: OSNR of the transmitter = {} dB", TRX_OSNR);
407 LOG.info("- In checkOSNR: add-path incremental OSNR = {} dB", ADD_OSNR);
408 double inverseLocalOsnr = getInverseOsnrLinkLu(TRX_OSNR) + getInverseOsnrLinkLu(ADD_OSNR);
409 for (PceGraphEdge edge : path.getEdgeList()) {
410 if (edge.link().getlinkType() == OpenroadmLinkType.ROADMTOROADM) {
412 linkOsnrDb = edge.link().getosnr();
413 LOG.info("- In checkOSNR: OSNR of {} = {} dB", edge.link().getLinkId().getValue(), linkOsnrDb);
414 // 1 over the local OSNR, in linear units
415 inverseLocalOsnr += getInverseOsnrLinkLu(linkOsnrDb);
419 osnrDb = getOsnrDb(1 / inverseLocalOsnr);
420 } catch (ArithmeticException e) {
421 LOG.debug("In checkOSNR: OSNR is equal to 0 and the number of links is: {}", path.getEdgeList().size());
424 LOG.info("In checkOSNR: OSNR of the path is {} dB", osnrDb);
425 return ((osnrDb + SYS_MARGIN) > MIN_OSNR_W100G);
428 private double getOsnrDb(double osnrLu) {
430 osnrDb = 10 * Math.log10(osnrLu);
434 private double getInverseOsnrLinkLu(double linkOsnrDb) {
435 // 1 over the link OSNR, in linear units
437 linkOsnrLu = Math.pow(10, (linkOsnrDb / 10.0));
438 LOG.debug("In retrieveosnr: the inverse of link osnr is {} (Linear Unit)", linkOsnrLu);
439 return (CONST_OSNR / linkOsnrLu);