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=960ae3bc1e6e407399d5aa99b40b042e11631d6a;hb=66f6af8141d231619ad9d6e6133910e14f3a32e2;hp=3462effa240ce8ba4173e6a9a53281d761b9eb21;hpb=feb80c05128f6292a0c9735db4e7e542fbac1999;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 3462effa2..960ae3bc1 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 @@ -9,6 +9,7 @@ package org.opendaylight.transportpce.pce.graph; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.math.RoundingMode; import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; @@ -16,6 +17,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import org.jgrapht.GraphPath; import org.opendaylight.transportpce.common.ResponseCodes; import org.opendaylight.transportpce.common.StringConstants; @@ -23,10 +25,12 @@ import org.opendaylight.transportpce.common.fixedflex.GridConstant; import org.opendaylight.transportpce.common.fixedflex.GridUtils; import org.opendaylight.transportpce.pce.constraints.PceConstraints; import org.opendaylight.transportpce.pce.constraints.PceConstraints.ResourcePair; -import org.opendaylight.transportpce.pce.model.SpectrumAssignment; 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.rev200529.OpenroadmLinkType; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220615.SpectrumAssignment; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220615.SpectrumAssignmentBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmLinkType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev181130.OpucnTribSlotDef; 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; @@ -42,6 +46,7 @@ public class PostAlgoPathValidator { public static final Long CONST_OSNR = 1L; public static final double SYS_MARGIN = 0; + @SuppressWarnings("fallthrough") @SuppressFBWarnings( value = "SF_SWITCH_FALLTHROUGH", justification = "intentional fallthrough") @@ -53,12 +58,13 @@ public class PostAlgoPathValidator { pceResult.setRC(ResponseCodes.RESPONSE_FAILED); return pceResult; } - int tribSlotNb = 1; int spectralWidthSlotNumber = GridConstant.SPECTRAL_WIDTH_SLOT_NUMBER_MAP .getOrDefault(serviceType, GridConstant.NB_SLOTS_100G); SpectrumAssignment spectrumAssignment = null; //variable to deal with 1GE (Nb=1) and 10GE (Nb=10) cases switch (serviceType) { + case StringConstants.SERVICE_TYPE_OTUC2: + case StringConstants.SERVICE_TYPE_OTUC3: case StringConstants.SERVICE_TYPE_OTUC4: case StringConstants.SERVICE_TYPE_400GE: spectralWidthSlotNumber = GridConstant.SPECTRAL_WIDTH_SLOT_NUMBER_MAP @@ -66,24 +72,25 @@ public class PostAlgoPathValidator { //fallthrough case StringConstants.SERVICE_TYPE_100GE_T: case StringConstants.SERVICE_TYPE_OTU4: - spectrumAssignment = getSpectrumAssignment(path, - allPceNodes, spectralWidthSlotNumber); + spectrumAssignment = getSpectrumAssignment(path, allPceNodes, spectralWidthSlotNumber); pceResult.setServiceType(serviceType); - if (spectrumAssignment.getBeginIndex() == 0 && spectrumAssignment.getStopIndex() == 0) { + if (spectrumAssignment.getBeginIndex().equals(Uint16.valueOf(0)) + && spectrumAssignment.getStopIndex().equals(Uint16.valueOf(0))) { pceResult.setRC(ResponseCodes.RESPONSE_FAILED); pceResult.setLocalCause(PceResult.LocalCause.NO_PATH_EXISTS); return pceResult; } - if (spectrumAssignment.isFlexGrid()) { + if (spectrumAssignment.getFlexGrid()) { LOG.info("Spectrum assignment flexgrid mode"); pceResult.setResultWavelength(GridConstant.IRRELEVANT_WAVELENGTH_NUMBER); } else { LOG.info("Spectrum assignment fixedgrid mode"); pceResult.setResultWavelength( - GridUtils.getWaveLengthIndexFromSpectrumAssigment(spectrumAssignment.getBeginIndex())); + GridUtils.getWaveLengthIndexFromSpectrumAssigment(spectrumAssignment.getBeginIndex() + .toJava())); } - pceResult.setMinFreq(GridUtils.getStartFrequencyFromIndex(spectrumAssignment.getBeginIndex())); - pceResult.setMaxFreq(GridUtils.getStopFrequencyFromIndex(spectrumAssignment.getStopIndex())); + pceResult.setMinFreq(GridUtils.getStartFrequencyFromIndex(spectrumAssignment.getBeginIndex().toJava())); + pceResult.setMaxFreq(GridUtils.getStopFrequencyFromIndex(spectrumAssignment.getStopIndex().toJava())); LOG.info("In PostAlgoPathValidator: spectrum assignment found {} {}", spectrumAssignment, path); // Check the OSNR @@ -116,27 +123,33 @@ public class PostAlgoPathValidator { break; case StringConstants.SERVICE_TYPE_100GE_M: case StringConstants.SERVICE_TYPE_10GE: - tribSlotNb = StringConstants.SERVICE_TYPE_10GE.equals(serviceType) ? 8 : 20; - //fallthrough case StringConstants.SERVICE_TYPE_1GE: + Map tribSlotNbMap = Map.of( + StringConstants.SERVICE_TYPE_100GE_M, 20, + StringConstants.SERVICE_TYPE_10GE, 8, + StringConstants.SERVICE_TYPE_1GE, 1); + int tribSlotNb = tribSlotNbMap.get(serviceType); pceResult.setRC(ResponseCodes.RESPONSE_FAILED); pceResult.setServiceType(serviceType); - Map tribPort = chooseTribPort(path, allPceNodes); Map> tribSlot = chooseTribSlot(path, allPceNodes, tribSlotNb); + Map tribPort = chooseTribPort(path, allPceNodes, tribSlot, tribSlotNb); + List resultTribPortTribSlot = getMinMaxTpTs(tribPort, tribSlot); - if (tribPort != null && tribSlot != null) { - pceResult.setResultTribPort(tribPort); - pceResult.setResultTribSlot(tribSlot); - pceResult.setResultTribSlotNb(tribSlotNb); + if (resultTribPortTribSlot.get(0) != null && resultTribPortTribSlot.get(1) != null) { + pceResult.setResultTribPortTribSlot(resultTribPortTribSlot); pceResult.setRC(ResponseCodes.RESPONSE_OK); LOG.info("In PostAlgoPathValidator: found TribPort {} - tribSlot {} - tribSlotNb {}", tribPort, tribSlot, tribSlotNb); } break; case StringConstants.SERVICE_TYPE_ODU4: + case StringConstants.SERVICE_TYPE_ODUC2: + case StringConstants.SERVICE_TYPE_ODUC3: case StringConstants.SERVICE_TYPE_ODUC4: + case StringConstants.SERVICE_TYPE_100GE_S: pceResult.setRC(ResponseCodes.RESPONSE_OK); - LOG.info("In PostAlgoPathValidator: ODU4/ODUC4 path found {}", path); + pceResult.setServiceType(serviceType); + LOG.info("In PostAlgoPathValidator: ODU4/ODUCn path found {}", path); break; default: pceResult.setRC(ResponseCodes.RESPONSE_FAILED); @@ -152,13 +165,13 @@ public class PostAlgoPathValidator { 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); - } catch (NullPointerException e) { + if (edge.link() == null || edge.link().getLatency() == null) { LOG.warn("- In checkLatency: the link {} does not contain latency field", edge.link().getLinkId().getValue()); + return false; } + latency += edge.link().getLatency(); + LOG.debug("- In checkLatency: latency of {} = {} units", edge.link().getLinkId().getValue(), latency); } return (latency < maxLatency); } @@ -190,42 +203,19 @@ public class PostAlgoPathValidator { pceHardConstraintsInput)); // validation: check each type for each element - for (ResourcePair next : listToInclude) { - int indx = -1; - switch (next.getType()) { - case NODE: - if (listOfElementsSubNode.contains(next.getName())) { - indx = listOfElementsSubNode.indexOf(next.getName()); - } - break; - case SRLG: - if (listOfElementsSRLG.contains(next.getName())) { - indx = listOfElementsSRLG.indexOf(next.getName()); - } - break; - case CLLI: - if (listOfElementsCLLI.contains(next.getName())) { - indx = listOfElementsCLLI.indexOf(next.getName()); - } - break; - default: - LOG.warn(" in checkInclude vertex list unsupported resource type: [{}]", next.getType()); - } - - if (indx < 0) { - LOG.debug(" in checkInclude stopped : {} ", next.getName()); - return false; - } - - LOG.debug(" in checkInclude next found {} in {}", next.getName(), path.getVertexList()); - - listOfElementsSubNode.subList(0, indx).clear(); - listOfElementsCLLI.subList(0, indx).clear(); - listOfElementsSRLG.subList(0, indx).clear(); - } - - LOG.info(" in checkInclude passed : {} ", path.getVertexList()); - return true; + List listNodeToInclude = listToInclude + .stream().filter(rp -> PceConstraints.ResourceType.NODE.equals(rp.getType())) + .map(ResourcePair::getName).collect(Collectors.toList()); + List listSrlgToInclude = listToInclude + .stream().filter(rp -> PceConstraints.ResourceType.SRLG.equals(rp.getType())) + .map(ResourcePair::getName).collect(Collectors.toList()); + List listClliToInclude = listToInclude + .stream().filter(rp -> PceConstraints.ResourceType.CLLI.equals(rp.getType())) + .map(ResourcePair::getName).collect(Collectors.toList()); + + return listOfElementsSubNode.containsAll(listNodeToInclude) + && listOfElementsSRLG.containsAll(listSrlgToInclude) + && listOfElementsCLLI.containsAll(listClliToInclude); } private List listOfElementsBuild(List pathEdges, PceConstraints.ResourceType type, @@ -271,28 +261,34 @@ public class PostAlgoPathValidator { } private Map chooseTribPort(GraphPath path, Map allPceNodes) { + PceGraphEdge> path, Map allPceNodes, Map> tribSlotMap, int nbSlot) { 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(); + String linkSrcTp = edge.link().getSourceTP().getValue(); NodeId linkDestNode = edge.link().getDestId(); - String linkDestTp = edge.link().getDestTP().toString(); + String linkDestTp = edge.link().getDestTP().getValue(); 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); + for (Uint16 srcTpn : srcTpnPool) { + if (destTpnPool.contains(srcTpn)) { + commonEdgeTpnPool.add(srcTpn); } } - Collections.sort(commonEdgeTpnPool); + if (!commonEdgeTpnPool.isEmpty()) { - tribPortMap.put(edge.link().getLinkId().getValue(), commonEdgeTpnPool.get(0)); + Integer startTribSlot = tribSlotMap.values().stream().findFirst().get().get(0).toJava(); + Integer tribPort = (int) Math.ceil((double)startTribSlot / nbSlot); + for (Uint16 commonTribPort : commonEdgeTpnPool) { + if (tribPort.equals(commonTribPort.toJava())) { + tribPortMap.put(edge.link().getLinkId().getValue(), commonTribPort); + } + } } } tribPortMap.forEach((k,v) -> LOG.info("TribPortMap : k = {}, v = {}", k, v)); @@ -306,34 +302,42 @@ public class PostAlgoPathValidator { for (PceGraphEdge edge : path.getEdgeList()) { NodeId linkSrcNode = edge.link().getSourceId(); - String linkSrcTp = edge.link().getSourceTP().toString(); + String linkSrcTp = edge.link().getSourceTP().getValue(); NodeId linkDestNode = edge.link().getDestId(); - String linkDestTp = edge.link().getDestTP().toString(); + String linkDestTp = edge.link().getDestTP().getValue(); 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 commonEdgeTsPoolList = new ArrayList<>(); List tribSlotList = new ArrayList<>(); for (Uint16 integer : srcTsPool) { if (destTsPool.contains(integer)) { - commonEdgeTsPool.add(integer); + commonEdgeTsPoolList.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; + Collections.sort(commonEdgeTsPoolList); + List commonGoodStartEdgeTsPoolList = new ArrayList<>(); + for (Uint16 startEdgeTsPool : commonEdgeTsPoolList) { + if (Integer.valueOf(1).equals(startEdgeTsPool.toJava() % nbSlot) + || nbSlot == 1) { + commonGoodStartEdgeTsPoolList.add(startEdgeTsPool); + } + } + Collections.sort(commonGoodStartEdgeTsPoolList); + boolean goodTsList = false; + for (Uint16 goodStartTsPool : commonGoodStartEdgeTsPoolList) { + int goodStartIndex = commonEdgeTsPoolList.indexOf(Uint16.valueOf(goodStartTsPool.intValue())); + if (!goodTsList && commonEdgeTsPoolList.size() - goodStartIndex >= nbSlot) { + for (int i = 0; i < nbSlot; i++) { + if (!commonEdgeTsPoolList.get(goodStartIndex + i) + .equals(Uint16.valueOf(goodStartTsPool.toJava() + i))) { + goodTsList = false; + tribSlotList.clear(); + break; + } + tribSlotList.add(commonEdgeTsPoolList.get(goodStartIndex + i)); + goodTsList = true; } } } @@ -343,6 +347,20 @@ public class PostAlgoPathValidator { return tribSlotMap; } + private List getMinMaxTpTs(Map tribPort, Map> tribSlot) { + String tribport = tribPort.values().toArray()[0].toString(); + @SuppressWarnings("unchecked") + List tsList = (List) tribSlot.values().toArray()[0]; + OpucnTribSlotDef minOpucnTs = OpucnTribSlotDef + .getDefaultInstance(String.join(".", tribport, tsList.get(0).toString())); + OpucnTribSlotDef maxOpucnTs = OpucnTribSlotDef + .getDefaultInstance(String.join(".", tribport, tsList.get(tsList.size() - 1).toString())); + List minmaxTpTsList = new ArrayList<>(); + minmaxTpTsList.add(minOpucnTs); + minmaxTpTsList.add(maxOpucnTs); + return minmaxTpTsList; + } + // Check the path OSNR private boolean checkOSNR(GraphPath path) { double linkOsnrDb; @@ -370,15 +388,12 @@ public class PostAlgoPathValidator { } private double getOsnrDb(double osnrLu) { - double osnrDb; - osnrDb = 10 * Math.log10(osnrLu); - return osnrDb; + return (10 * Math.log10(osnrLu)); } private double getInverseOsnrLinkLu(double linkOsnrDb) { // 1 over the link OSNR, in linear units - double linkOsnrLu; - linkOsnrLu = Math.pow(10, (linkOsnrDb / 10.0)); + double linkOsnrLu = Math.pow(10, (linkOsnrDb / 10.0)); LOG.debug("In retrieveosnr: the inverse of link osnr is {} (Linear Unit)", linkOsnrLu); return (CONST_OSNR / linkOsnrLu); } @@ -406,10 +421,19 @@ public class PostAlgoPathValidator { if (allPceNodes.containsKey(edge.link().getSourceId())) { PceNode pceNode = allPceNodes.get(edge.link().getSourceId()); LOG.info("Processing PCE node {}", pceNode); - if (StringConstants.OPENROADM_DEVICE_VERSION_1_2_1.equals(pceNode.getVersion()) - || pceNode.getSlotWidthGranularity().compareTo(GridConstant.SLOT_WIDTH_50) == 0) { + if (StringConstants.OPENROADM_DEVICE_VERSION_1_2_1.equals(pceNode.getVersion())) { LOG.info("Node {}: version is {} and slot width granularity is {} -> fixed grid mode", - pceNode.getNodeId(), pceNode.getVersion(), pceNode.getSlotWidthGranularity()); + pceNode.getNodeId(), pceNode.getVersion(), pceNode.getSlotWidthGranularity()); + isFlexGrid = false; + } + if ((pceNode.getSlotWidthGranularity().setScale(0, RoundingMode.CEILING) + .equals(GridConstant.SLOT_WIDTH_50)) + && (pceNode.getCentralFreqGranularity().setScale(0, RoundingMode.CEILING) + .equals(GridConstant.SLOT_WIDTH_50))) { + LOG.debug("Node {}: version is {} with slot width granularity {} and central " + + "frequency granularity is {} -> fixed grid mode", + pceNode.getNodeId(), pceNode.getVersion(), pceNode.getSlotWidthGranularity(), + pceNode.getCentralFreqGranularity()); isFlexGrid = false; } pceNodeFreqMap = pceNode.getBitSetData(); @@ -435,25 +459,23 @@ public class PostAlgoPathValidator { */ private SpectrumAssignment computeBestSpectrumAssignment(BitSet spectrumOccupation, int spectralWidthSlotNumber, boolean isFlexGrid) { - SpectrumAssignment spectrumAssignment = new SpectrumAssignment(0, 0); - spectrumAssignment.setFlexGrid(isFlexGrid); + SpectrumAssignmentBuilder spectrumAssignmentBldr = new SpectrumAssignmentBuilder() + .setBeginIndex(Uint16.valueOf(0)) + .setStopIndex(Uint16.valueOf(0)) + .setFlexGrid(isFlexGrid); BitSet referenceBitSet = new BitSet(spectralWidthSlotNumber); referenceBitSet.set(0, spectralWidthSlotNumber); - int nbSteps = 1; - if (isFlexGrid) { - nbSteps = spectralWidthSlotNumber; - } + int nbSteps = isFlexGrid ? spectralWidthSlotNumber : 1; //higher is the frequency, smallest is the wavelength number //in operational, the allocation is done through wavelength starting from the smallest //so we have to loop from the last element of the spectrum occupation for (int i = spectrumOccupation.size(); i >= spectralWidthSlotNumber; i -= nbSteps) { if (spectrumOccupation.get(i - spectralWidthSlotNumber, i).equals(referenceBitSet)) { - spectrumAssignment.setBeginIndex(i - spectralWidthSlotNumber); - spectrumAssignment.setStopIndex(i - 1); + spectrumAssignmentBldr.setBeginIndex(Uint16.valueOf(i - spectralWidthSlotNumber)); + spectrumAssignmentBldr.setStopIndex(Uint16.valueOf(i - 1)); break; } } - return spectrumAssignment; + return spectrumAssignmentBldr.build(); } - }