X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pce%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fpce%2Fgraph%2FPostAlgoPathValidator.java;h=7c111940cc2c1af453712b21c622c2cbf960d434;hb=0f9a451081238311c3f1f30e97aa22dcc5998a8a;hp=626895fd181b71486e0241f5569870f955e58a23;hpb=442088b23f7f20667badfa66759c15d48ee28605;p=transportpce.git diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PostAlgoPathValidator.java b/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PostAlgoPathValidator.java index 626895fd1..7c111940c 100644 --- a/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PostAlgoPathValidator.java +++ b/pce/src/main/java/org/opendaylight/transportpce/pce/graph/PostAlgoPathValidator.java @@ -8,10 +8,12 @@ package org.opendaylight.transportpce.pce.graph; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; - import org.jgrapht.GraphPath; import org.opendaylight.transportpce.common.ResponseCodes; import org.opendaylight.transportpce.pce.constraints.PceConstraints; @@ -20,14 +22,14 @@ import org.opendaylight.transportpce.pce.networkanalyzer.PceNode; import org.opendaylight.transportpce.pce.networkanalyzer.PceResult; import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId; +import org.opendaylight.yangtools.yang.common.Uint16; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class PostAlgoPathValidator { /* Logging. */ - private static final Logger LOG = LoggerFactory.getLogger(PceGraph.class); + private static final Logger LOG = LoggerFactory.getLogger(PostAlgoPathValidator.class); - // TODO hard-coded 96 private static final int MAX_WAWELENGTH = 96; private static final double MIN_OSNR_W100G = 17; private static final double TRX_OSNR = 33; @@ -35,64 +37,107 @@ public class PostAlgoPathValidator { public static final Long CONST_OSNR = 1L; public static final double SYS_MARGIN = 0; - public PceResult checkPath(GraphPath path, - Map allPceNodes, PceResult pceResult, PceConstraints pceHardConstraints) { + @SuppressFBWarnings( + value = "SF_SWITCH_FALLTHROUGH", + justification = "intentional fallthrough") + public PceResult checkPath(GraphPath path, Map allPceNodes, + PceResult pceResult, PceConstraints pceHardConstraints, String serviceType) { - //check if the path is empty - if (path.getEdgeList().size() == 0) { + // check if the path is empty + if (path.getEdgeList().isEmpty()) { pceResult.setRC(ResponseCodes.RESPONSE_FAILED); return pceResult; } - //Choose wavelength available in all nodes of the path - Long waveL = chooseWavelength(path, allPceNodes); - if (waveL < 0) { - pceResult.setRC(ResponseCodes.RESPONSE_FAILED); - pceResult.setLocalCause(PceResult.LocalCause.NO_PATH_EXISTS); - return pceResult; - } - pceResult.setResultWavelength(waveL); - LOG.info("In PostAlgoPathValidator: chooseWavelength WL found {} {}", waveL, path.toString()); + int tribSlotNb = 1; + //variable to deal with 1GE (Nb=1) and 10GE (Nb=10) cases + switch (serviceType) { + + case "100GE": + case "OTU4": + // choose wavelength available in all nodes of the path + Long waveL = chooseWavelength(path, allPceNodes); + pceResult.setServiceType(serviceType); + if (waveL < 0) { + pceResult.setRC(ResponseCodes.RESPONSE_FAILED); + pceResult.setLocalCause(PceResult.LocalCause.NO_PATH_EXISTS); + return pceResult; + } + pceResult.setResultWavelength(waveL); + LOG.info("In PostAlgoPathValidator: chooseWavelength WL found {} {}", waveL, path); + + // Check the OSNR + if (!checkOSNR(path)) { + pceResult.setRC(ResponseCodes.RESPONSE_FAILED); + pceResult.setLocalCause(PceResult.LocalCause.OUT_OF_SPEC_OSNR); + return pceResult; + } + + // Check if MaxLatency is defined in the hard constraints + if ((pceHardConstraints.getMaxLatency() != -1) + && (!checkLatency(pceHardConstraints.getMaxLatency(), path))) { + pceResult.setRC(ResponseCodes.RESPONSE_FAILED); + pceResult.setLocalCause(PceResult.LocalCause.TOO_HIGH_LATENCY); + return pceResult; + } - // TODO here other post algo validations can be added - // more data can be sent to PceGraph module via PceResult structure if required + // Check if nodes are included in the hard constraints + if (!checkInclude(path, pceHardConstraints)) { + pceResult.setRC(ResponseCodes.RESPONSE_FAILED); + pceResult.setLocalCause(PceResult.LocalCause.HD_NODE_INCLUDE); + return pceResult; + } - //Check the OSNR - if (!checkOSNR(path)) { - pceResult.setRC(ResponseCodes.RESPONSE_FAILED); - pceResult.setLocalCause(PceResult.LocalCause.OUT_OF_SPEC_OSNR); - return pceResult; - } + // TODO here other post algo validations can be added + // more data can be sent to PceGraph module via PceResult structure if required + + pceResult.setRC(ResponseCodes.RESPONSE_OK); + pceResult.setLocalCause(PceResult.LocalCause.NONE); - //Check if MaxLatency is defined in the hard constraints - if (pceHardConstraints.getMaxLatency() != -1) { - if (!checkLatency(pceHardConstraints.getMaxLatency(), path)) { + break; + + case "10GE": + tribSlotNb = 8; + //fallthrough + case "1GE": pceResult.setRC(ResponseCodes.RESPONSE_FAILED); - pceResult.setLocalCause(PceResult.LocalCause.TOO_HIGH_LATENCY); - return pceResult; - } - } + pceResult.setServiceType(serviceType); + Map tribPort = chooseTribPort(path, allPceNodes); + Map> tribSlot = chooseTribSlot(path, allPceNodes, tribSlotNb); + + if (tribPort != null && tribSlot != null) { + pceResult.setResultTribPort(tribPort); + pceResult.setResultTribSlot(tribSlot); + pceResult.setResultTribSlotNb(tribSlotNb); + pceResult.setRC(ResponseCodes.RESPONSE_OK); + LOG.info("In PostAlgoPathValidator: found TribPort {} - tribSlot {} - tribSlotNb {}", + tribPort, tribSlot, tribSlotNb); + } + break; - //Check if nodes are included in the hard constraints - if (!checkInclude(path, pceHardConstraints)) { - pceResult.setRC(ResponseCodes.RESPONSE_FAILED); - pceResult.setLocalCause(PceResult.LocalCause.HD_NODE_INCLUDE); - return pceResult; + case "ODU4": + pceResult.setRC(ResponseCodes.RESPONSE_OK); + LOG.info("In PostAlgoPathValidator: ODU4 path found {}", path); + break; + + default: + pceResult.setRC(ResponseCodes.RESPONSE_FAILED); + LOG.warn("In PostAlgoPathValidator checkPath: unsupported serviceType {} found {}", + serviceType, path); + break; } - pceResult.setRC(ResponseCodes.RESPONSE_OK); return pceResult; } - //Choose the first available wavelength from the source to the destination + // Choose the first available wavelength from the source to the destination private Long chooseWavelength(GraphPath path, Map allPceNodes) { Long wavelength = -1L; - for (long i = 1; i <= MAX_WAWELENGTH; i++) { boolean completed = true; - LOG.debug("In chooseWavelength: {} {}", path.getLength(), path.toString()); + LOG.debug("In chooseWavelength: {} {}", path.getLength(), path); for (PceGraphEdge edge : path.getEdgeList()) { - LOG.debug("In chooseWavelength: source {} ", edge.link().getSourceId().toString()); + LOG.debug("In chooseWavelength: source {} ", edge.link().getSourceId()); PceNode pceNode = allPceNodes.get(edge.link().getSourceId()); if (!pceNode.checkWL(i)) { completed = false; @@ -107,26 +152,23 @@ public class PostAlgoPathValidator { return wavelength; } - //Check the latency + // Check the latency private boolean checkLatency(Long maxLatency, GraphPath path) { double latency = 0; for (PceGraphEdge edge : path.getEdgeList()) { try { latency += edge.link().getLatency(); - LOG.debug("- In checkLatency: latency of {} = {} units", edge.link().getLinkId().getValue(),latency); + LOG.debug("- In checkLatency: latency of {} = {} units", edge.link().getLinkId().getValue(), latency); } catch (NullPointerException e) { LOG.warn("- In checkLatency: the link {} does not contain latency field", edge.link().getLinkId().getValue()); } } - if (latency > maxLatency) { - return false; - } - return true; + return (latency < maxLatency); } - //Check the inclusion if it is defined in the hard constraints + // Check the inclusion if it is defined in the hard constraints private boolean checkInclude(GraphPath path, PceConstraints pceHardConstraintsInput) { List listToInclude = pceHardConstraintsInput.getListToInclude(); if (listToInclude.isEmpty()) { @@ -136,17 +178,17 @@ public class PostAlgoPathValidator { List pathEdges = path.getEdgeList(); LOG.debug(" in checkInclude vertex list: [{}]", path.getVertexList()); - List listOfElementsSubNode = new ArrayList(); - listOfElementsSubNode.add(pathEdges.get(0).link().getsourceSupNodeId()); + List listOfElementsSubNode = new ArrayList<>(); + listOfElementsSubNode.add(pathEdges.get(0).link().getsourceNetworkSupNodeId()); listOfElementsSubNode.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.NODE, pceHardConstraintsInput)); - List listOfElementsCLLI = new ArrayList(); + List listOfElementsCLLI = new ArrayList<>(); listOfElementsCLLI.add(pathEdges.get(0).link().getsourceCLLI()); listOfElementsCLLI.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.CLLI, pceHardConstraintsInput)); - List listOfElementsSRLG = new ArrayList(); + List listOfElementsSRLG = new ArrayList<>(); // first link is XPONDEROUTPUT, no SRLG for it listOfElementsSRLG.add("NONE"); listOfElementsSRLG.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.SRLG, @@ -194,11 +236,11 @@ public class PostAlgoPathValidator { private List listOfElementsBuild(List pathEdges, PceConstraints.ResourceType type, PceConstraints pceHardConstraints) { - List listOfElements = new ArrayList(); - for (PceGraphEdge link: pathEdges) { + List listOfElements = new ArrayList<>(); + for (PceGraphEdge link : pathEdges) { switch (type) { case NODE: - listOfElements.add(link.link().getdestSupNodeId()); + listOfElements.add(link.link().getdestNetworkSupNodeId()); break; case CLLI: listOfElements.add(link.link().getdestCLLI()); @@ -208,17 +250,17 @@ public class PostAlgoPathValidator { listOfElements.add("NONE"); break; } - - // srlg of link is List. But in this algo we need string representation of one SRLG - // this should be any SRLG mentioned in include constraints if any of them if mentioned + // srlg of link is List. But in this algo we need string representation of + // one SRLG + // this should be any SRLG mentioned in include constraints if any of them if + // mentioned boolean found = false; for (Long srlg : link.link().getsrlgList()) { String srlgStr = String.valueOf(srlg); if (pceHardConstraints.getSRLGnames().contains(srlgStr)) { listOfElements.add(srlgStr); - LOG.info("listOfElementsBuild. FOUND SRLG {} in link {}", srlgStr, link.link().toString()); + LOG.info("listOfElementsBuild. FOUND SRLG {} in link {}", srlgStr, link.link()); found = true; - continue; } } if (!found) { @@ -233,7 +275,80 @@ public class PostAlgoPathValidator { return listOfElements; } - //Check the path OSNR + private Map chooseTribPort(GraphPath path, Map allPceNodes) { + LOG.info("In choosetribPort: edgeList = {} ", path.getEdgeList()); + Map tribPortMap = new HashMap<>(); + + for (PceGraphEdge edge : path.getEdgeList()) { + NodeId linkSrcNode = edge.link().getSourceId(); + String linkSrcTp = edge.link().getSourceTP().toString(); + NodeId linkDestNode = edge.link().getDestId(); + String linkDestTp = edge.link().getDestTP().toString(); + PceNode pceOtnNodeSrc = allPceNodes.get(linkSrcNode); + PceNode pceOtnNodeDest = allPceNodes.get(linkDestNode); + List srcTpnPool = pceOtnNodeSrc.getAvailableTribPorts().get(linkSrcTp); + List destTpnPool = pceOtnNodeDest.getAvailableTribPorts().get(linkDestTp); + List commonEdgeTpnPool = new ArrayList<>(); + for (Uint16 integer : srcTpnPool) { + if (destTpnPool.contains(integer)) { + commonEdgeTpnPool.add(integer); + } + } + Collections.sort(commonEdgeTpnPool); + if (!commonEdgeTpnPool.isEmpty()) { + tribPortMap.put(edge.link().getLinkId().getValue(), commonEdgeTpnPool.get(0)); + } + } + tribPortMap.forEach((k,v) -> LOG.info("TribPortMap : k = {}, v = {}", k, v)); + return tribPortMap; + } + + private Map> chooseTribSlot(GraphPath path, Map allPceNodes, int nbSlot) { + LOG.info("In choosetribSlot: edgeList = {} ", path.getEdgeList()); + Map> tribSlotMap = new HashMap<>(); + + for (PceGraphEdge edge : path.getEdgeList()) { + NodeId linkSrcNode = edge.link().getSourceId(); + String linkSrcTp = edge.link().getSourceTP().toString(); + NodeId linkDestNode = edge.link().getDestId(); + String linkDestTp = edge.link().getDestTP().toString(); + PceNode pceOtnNodeSrc = allPceNodes.get(linkSrcNode); + PceNode pceOtnNodeDest = allPceNodes.get(linkDestNode); + List srcTsPool = pceOtnNodeSrc.getAvailableTribSlots().get(linkSrcTp); + List destTsPool = pceOtnNodeDest.getAvailableTribSlots().get(linkDestTp); + List commonEdgeTsPool = new ArrayList<>(); + List tribSlotList = new ArrayList<>(); + for (Uint16 integer : srcTsPool) { + if (destTsPool.contains(integer)) { + commonEdgeTsPool.add(integer); + } + } + Collections.sort(commonEdgeTsPool); + boolean discontinue = true; + int index = 0; + while (discontinue && (commonEdgeTsPool.size() - index >= nbSlot)) { + discontinue = false; + Integer val = commonEdgeTsPool.get(index).toJava(); + for (int i = 0; i < nbSlot; i++) { + if (commonEdgeTsPool.get(index + i).equals(Uint16.valueOf(val + i))) { + tribSlotList.add(commonEdgeTsPool.get(index + i)); + } else { + discontinue = true; + tribSlotList.clear(); + index += i; + break; + } + } + } + tribSlotMap.put(edge.link().getLinkId().getValue(), tribSlotList); + } + tribSlotMap.forEach((k,v) -> LOG.info("TribSlotMap : k = {}, v = {}", k, v)); + return tribSlotMap; + } + + // Check the path OSNR private boolean checkOSNR(GraphPath path) { double linkOsnrDb; double osnrDb = 0; @@ -251,16 +366,12 @@ public class PostAlgoPathValidator { } try { osnrDb = getOsnrDb(1 / inverseLocalOsnr); - } - catch (ArithmeticException e) { + } catch (ArithmeticException e) { LOG.debug("In checkOSNR: OSNR is equal to 0 and the number of links is: {}", path.getEdgeList().size()); return false; } LOG.info("In checkOSNR: OSNR of the path is {} dB", osnrDb); - if ((osnrDb + SYS_MARGIN) < MIN_OSNR_W100G) { - return false; - } - return true; + return ((osnrDb + SYS_MARGIN) > MIN_OSNR_W100G); } private double getOsnrDb(double osnrLu) { @@ -277,4 +388,4 @@ public class PostAlgoPathValidator { return (CONST_OSNR / linkOsnrLu); } -} \ No newline at end of file +}