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=d1e1d30216e2e27b9a9a446a145d3e24704ea0e9;hb=e4411e83f9c4cfba18a9000616fd37149dc3c302;hp=7c111940cc2c1af453712b21c622c2cbf960d434;hpb=0f9a451081238311c3f1f30e97aa22dcc5998a8a;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 7c111940c..d1e1d3021 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 @@ -10,17 +10,23 @@ package org.opendaylight.transportpce.pce.graph; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.ArrayList; +import java.util.Arrays; +import java.util.BitSet; 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.common.StringConstants; +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.rev181130.OpenroadmLinkType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.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; @@ -30,7 +36,6 @@ public class PostAlgoPathValidator { /* Logging. */ private static final Logger LOG = LoggerFactory.getLogger(PostAlgoPathValidator.class); - private static final int MAX_WAWELENGTH = 96; private static final double MIN_OSNR_W100G = 17; private static final double TRX_OSNR = 33; private static final double ADD_OSNR = 30; @@ -48,23 +53,29 @@ public class PostAlgoPathValidator { pceResult.setRC(ResponseCodes.RESPONSE_FAILED); return pceResult; } - 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); + case StringConstants.SERVICE_TYPE_100GE: + case StringConstants.SERVICE_TYPE_OTU4: + int spectralWidthSlotNumber = GridConstant.SPECTRAL_WIDTH_SLOT_NUMBER_MAP + .getOrDefault(serviceType, GridConstant.NB_SLOTS_100G); + SpectrumAssignment spectrumAssignment = getSpectrumAssignment(path, + allPceNodes, spectralWidthSlotNumber); pceResult.setServiceType(serviceType); - if (waveL < 0) { + if (spectrumAssignment.getBeginIndex() == 0 && spectrumAssignment.getStopIndex() == 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); + //TODO: until change to manage connection name, logical connection point name and service path + // keep set wavelength number + pceResult.setResultWavelength( + GridUtils.getWaveLengthIndexFromSpectrumAssigment(spectrumAssignment.getBeginIndex())); + pceResult.setMinFreq(GridUtils.getStartFrequencyFromIndex(spectrumAssignment.getBeginIndex())); + pceResult.setMaxFreq(GridUtils.getStopFrequencyFromIndex(spectrumAssignment.getStopIndex())); + LOG.info("In PostAlgoPathValidator: spectrum assignment found {} {}", spectrumAssignment, path); // Check the OSNR if (!checkOSNR(path)) { @@ -96,10 +107,10 @@ public class PostAlgoPathValidator { break; - case "10GE": + case StringConstants.SERVICE_TYPE_10GE: tribSlotNb = 8; //fallthrough - case "1GE": + case StringConstants.SERVICE_TYPE_1GE: pceResult.setRC(ResponseCodes.RESPONSE_FAILED); pceResult.setServiceType(serviceType); Map tribPort = chooseTribPort(path, allPceNodes); @@ -115,7 +126,7 @@ public class PostAlgoPathValidator { } break; - case "ODU4": + case StringConstants.SERVICE_TYPE_ODU4: pceResult.setRC(ResponseCodes.RESPONSE_OK); LOG.info("In PostAlgoPathValidator: ODU4 path found {}", path); break; @@ -130,28 +141,6 @@ public class PostAlgoPathValidator { return pceResult; } - // 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); - for (PceGraphEdge edge : path.getEdgeList()) { - LOG.debug("In chooseWavelength: source {} ", edge.link().getSourceId()); - PceNode pceNode = allPceNodes.get(edge.link().getSourceId()); - if (!pceNode.checkWL(i)) { - completed = false; - break; - } - } - if (completed) { - wavelength = i; - break; - } - } - return wavelength; - } - // Check the latency private boolean checkLatency(Long maxLatency, GraphPath path) { double latency = 0; @@ -388,4 +377,77 @@ public class PostAlgoPathValidator { return (CONST_OSNR / linkOsnrLu); } + /** + * Get spectrum assignment for path. + * + * @param path the path for which we get spectrum assignment. + * @param allPceNodes all optical nodes. + * @param spectralWidthSlotNumber number of slot for spectral width. Depends on + * service type. + * @return a spectrum assignment object which contains begin and end index. If + * no spectrum assignment found, beginIndex = stopIndex = 0 + */ + private SpectrumAssignment getSpectrumAssignment(GraphPath path, + Map allPceNodes, int spectralWidthSlotNumber) { + byte[] freqMap = new byte[GridConstant.NB_OCTECTS]; + Arrays.fill(freqMap, (byte) GridConstant.AVAILABLE_SLOT_VALUE); + BitSet result = BitSet.valueOf(freqMap); + boolean isFlexGrid = true; + LOG.info("Processing path {} with length {}", path, path.getLength()); + BitSet pceNodeFreqMap; + for (PceGraphEdge edge : path.getEdgeList()) { + LOG.info("Processing source {} ", edge.link().getSourceId()); + 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) { + LOG.info("Node {}: version is {} and slot width granularity is {} -> fixed grid mode", + pceNode.getNodeId(), pceNode.getVersion(), pceNode.getSlotWidthGranularity()); + isFlexGrid = false; + } + pceNodeFreqMap = pceNode.getBitSetData(); + LOG.debug("Pce node bitset {}", pceNodeFreqMap); + if (pceNodeFreqMap != null) { + result.and(pceNodeFreqMap); + LOG.debug("intermediate bitset {}", result); + } + } + } + LOG.debug("Bitset result {}", result); + return computeBestSpectrumAssignment(result, spectralWidthSlotNumber, isFlexGrid); + } + + /** + * Compute spectrum assignment from spectrum occupation for spectral width. + * + * @param spectrumOccupation the spectrum occupation BitSet. + * @param spectralWidthSlotNumber the nb slots for spectral width. + * @param isFlexGrid true if flexible grid, false otherwise. + * @return a spectrum assignment object which contains begin and stop index. If + * no spectrum assignment found, beginIndex = stopIndex = 0 + */ + private SpectrumAssignment computeBestSpectrumAssignment(BitSet spectrumOccupation, int spectralWidthSlotNumber, + boolean isFlexGrid) { + SpectrumAssignment spectrumAssignment = new SpectrumAssignment(0, 0); + spectrumAssignment.setFlexGrid(isFlexGrid); + BitSet referenceBitSet = new BitSet(spectralWidthSlotNumber); + referenceBitSet.set(0, spectralWidthSlotNumber); + int nbSteps = 1; + if (isFlexGrid) { + nbSteps = spectralWidthSlotNumber; + } + //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); + break; + } + } + return spectrumAssignment; + } + }