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.PceOtnNode;
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;
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;
private static final double ADD_OSNR = 30;
public static final Long CONST_OSNR = 1L;
public static final double SYS_MARGIN = 0;
+ @SuppressFBWarnings(
+ value = "SF_SWITCH_FALLTHROUGH",
+ justification = "intentional fallthrough")
public PceResult checkPath(GraphPath<String, PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes,
PceResult pceResult, PceConstraints pceHardConstraints, String serviceType) {
// check if the path is empty
- if (path.getEdgeList().size() == 0) {
+ if (path.getEdgeList().isEmpty()) {
pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
return pceResult;
}
- if (("100GE".equals(serviceType)) || ("OTU4".equals(serviceType))) {
- // 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());
-
- // TODO here other post algo validations can be added
- // more data can be sent to PceGraph module via PceResult structure if required
-
- // Check the OSNR
- if (!checkOSNR(path)) {
- pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
- pceResult.setLocalCause(PceResult.LocalCause.OUT_OF_SPEC_OSNR);
- return pceResult;
- }
+ int tribSlotNb = 1;
+ //variable to deal with 1GE (Nb=1) and 10GE (Nb=10) cases
+ switch (serviceType) {
+
+ 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 (spectrumAssignment.getBeginIndex() == 0 && spectrumAssignment.getStopIndex() == 0) {
+ pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
+ pceResult.setLocalCause(PceResult.LocalCause.NO_PATH_EXISTS);
+ return pceResult;
+ }
+ //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)) {
+ 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) {
- if (!checkLatency(pceHardConstraints.getMaxLatency(), path)) {
+ // 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;
}
- }
- // 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;
- }
- pceResult.setRC(ResponseCodes.RESPONSE_OK);
+ // 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;
+ }
+
+ // TODO here other post algo validations can be added
+ // more data can be sent to PceGraph module via PceResult structure if required
- } else if (("1GE".equals(serviceType)) || ("10GE".equals(serviceType))) {
- // Path is at the OTN layer
- pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
- // In a first step we select the first tribPort available on the first edge
- // TODO : after the way to pass trib-ports and trib-slots to the renderer has
- // been adapted to fit
- // with multiple OTN Hops, each first available port shall be passed for each
- // edge to Renderer
- Integer tribPort = chooseTribPort(path, allPceNodes).get(0).get(0);
- // TODO : Same comment apply for tribSlot
- Integer tribSlot = chooseTribSlot(path, allPceNodes).get(0).get(0);
-
- if (tribPort != null) {
- // Temporarily we use wavelength-number to provide the TribPort
- // TODO adapt the path-description
- // TODO make the adaptation to return the first tribSlot in an intermediate
- // phase
- pceResult.setResultWavelength(tribPort);
pceResult.setRC(ResponseCodes.RESPONSE_OK);
- LOG.info("In PostAlgoPathValidator: chooseTribPort TribPort found {} {}", tribPort, path.toString());
- }
- }
- return pceResult;
- }
+ pceResult.setLocalCause(PceResult.LocalCause.NONE);
- // Choose the first available wavelength from the source to the destination
- private Long chooseWavelength(GraphPath<String, PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes) {
- Long wavelength = -1L;
+ break;
- for (long i = 1; i <= MAX_WAWELENGTH; i++) {
- boolean completed = true;
- LOG.debug("In chooseWavelength: {} {}", path.getLength(), path.toString());
- for (PceGraphEdge edge : path.getEdgeList()) {
- LOG.debug("In chooseWavelength: source {} ", edge.link().getSourceId().toString());
- PceNode pceNode = allPceNodes.get(edge.link().getSourceId());
- if (!pceNode.checkWL(i)) {
- completed = false;
- break;
+ case StringConstants.SERVICE_TYPE_10GE:
+ tribSlotNb = 8;
+ //fallthrough
+ case StringConstants.SERVICE_TYPE_1GE:
+ pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
+ pceResult.setServiceType(serviceType);
+ Map<String, Uint16> tribPort = chooseTribPort(path, allPceNodes);
+ Map<String, List<Uint16>> 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);
}
- }
- if (completed) {
- wavelength = i;
break;
- }
+
+ case StringConstants.SERVICE_TYPE_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;
}
- return wavelength;
+
+ return pceResult;
}
// Check the latency
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
List<PceGraphEdge> pathEdges = path.getEdgeList();
LOG.debug(" in checkInclude vertex list: [{}]", path.getVertexList());
- List<String> listOfElementsSubNode = new ArrayList<String>();
- listOfElementsSubNode.add(pathEdges.get(0).link().getsourceSupNodeId());
+ List<String> listOfElementsSubNode = new ArrayList<>();
+ listOfElementsSubNode.add(pathEdges.get(0).link().getsourceNetworkSupNodeId());
listOfElementsSubNode.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.NODE,
pceHardConstraintsInput));
- List<String> listOfElementsCLLI = new ArrayList<String>();
+ List<String> listOfElementsCLLI = new ArrayList<>();
listOfElementsCLLI.add(pathEdges.get(0).link().getsourceCLLI());
listOfElementsCLLI.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.CLLI,
pceHardConstraintsInput));
- List<String> listOfElementsSRLG = new ArrayList<String>();
+ List<String> listOfElementsSRLG = new ArrayList<>();
// first link is XPONDEROUTPUT, no SRLG for it
listOfElementsSRLG.add("NONE");
listOfElementsSRLG.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.SRLG,
private List<String> listOfElementsBuild(List<PceGraphEdge> pathEdges, PceConstraints.ResourceType type,
PceConstraints pceHardConstraints) {
- List<String> listOfElements = new ArrayList<String>();
+ List<String> 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());
listOfElements.add("NONE");
break;
}
-
// srlg of link is List<Long>. 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
listOfElements.add(srlgStr);
LOG.info("listOfElementsBuild. FOUND SRLG {} in link {}", srlgStr, link.link());
found = true;
- continue;
}
}
if (!found) {
return listOfElements;
}
- private List<List<Integer>> chooseTribPort(GraphPath<String, PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes) {
- List<List<Integer>> tribPort = new ArrayList<>();
- boolean statusOK = true;
- boolean check = false;
- Object nodeClass = allPceNodes.getClass();
- if (nodeClass.getClass().isInstance(PceNode.class)) {
- LOG.debug("In choosetribPort: AllPceNodes contains PceNode instance, no trib port search");
- return tribPort;
- } else if (nodeClass.getClass().isInstance(PceOtnNode.class)) {
- LOG.debug("In choosetribPort: {} {}", path.getLength(), path.toString());
- for (PceGraphEdge edge : path.getEdgeList()) {
- LOG.debug("In chooseTribPort: source {} ", edge.link().getSourceId().toString());
- PceNode pceNode = allPceNodes.get(edge.link().getSourceId());
- Object tps = allPceNodes.get(edge.link().getSourceTP());
- Object tpd = allPceNodes.get(edge.link().getDestTP());
- if ((pceNode.getAvailableTribPorts().containsKey(tps.toString()))
- && (pceNode.getAvailableTribPorts().containsKey(tpd.toString()))) {
-
- List<Integer> tribPortEdgeSourceN = new ArrayList<>();
- List<Integer> tribPortEdgeDestN = new ArrayList<>();
- tribPortEdgeSourceN = pceNode.getAvailableTribPorts().get(tps.toString());
- tribPortEdgeDestN = pceNode.getAvailableTribPorts().get(tps.toString());
- check = false;
- for (int i = 0; i <= 9; i++) {
- if (tribPortEdgeSourceN.get(i) == null) {
- break;
- }
- if (tribPortEdgeSourceN.get(i) == tribPortEdgeDestN.get(i)) {
- check = true;
- } else {
- check = false;
- LOG.debug("In chooseTribPort: Misalignement of trib port between source {} and dest {}",
- edge.link().getSourceId().toString(), edge.link().getDestId().toString());
- break;
- }
- }
- if (check) {
- tribPort.add(tribPortEdgeSourceN);
- }
- } else {
- LOG.debug("In chooseTribPort: source {} does not have provisonned hosting HO interface ",
- edge.link().getSourceId().toString());
- statusOK = false;
+ private Map<String, Uint16> chooseTribPort(GraphPath<String,
+ PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes) {
+ LOG.info("In choosetribPort: edgeList = {} ", path.getEdgeList());
+ Map<String, Uint16> 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<Uint16> srcTpnPool = pceOtnNodeSrc.getAvailableTribPorts().get(linkSrcTp);
+ List<Uint16> destTpnPool = pceOtnNodeDest.getAvailableTribPorts().get(linkDestTp);
+ List<Uint16> 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));
+ }
}
- if (statusOK && check) {
- return tribPort;
- } else {
- tribPort.clear();
- return tribPort;
- }
-
+ tribPortMap.forEach((k,v) -> LOG.info("TribPortMap : k = {}, v = {}", k, v));
+ return tribPortMap;
}
- private List<List<Integer>> chooseTribSlot(GraphPath<String, PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes) {
- List<List<Integer>> tribSlot = new ArrayList<>();
- boolean statusOK = true;
- boolean check = false;
- Object nodeClass = allPceNodes.getClass();
- if (nodeClass.getClass().isInstance(PceNode.class)) {
- LOG.debug("In choosetribSlot: AllPceNodes contains PceNode instance, no trib port search");
- return tribSlot;
- } else if (nodeClass.getClass().isInstance(PceOtnNode.class)) {
- LOG.debug("In choosetribPort: {} {}", path.getLength(), path.toString());
- for (PceGraphEdge edge : path.getEdgeList()) {
- LOG.debug("In chooseTribSlot: source {} ", edge.link().getSourceId().toString());
- PceNode pceNode = allPceNodes.get(edge.link().getSourceId());
- Object tps = allPceNodes.get(edge.link().getSourceTP());
- Object tpd = allPceNodes.get(edge.link().getDestTP());
- if ((pceNode.getAvailableTribSlots().containsKey(tps.toString()))
- && (pceNode.getAvailableTribSlots().containsKey(tpd.toString()))) {
-
- List<Integer> tribSlotEdgeSourceN = new ArrayList<>();
- List<Integer> tribSlotEdgeDestN = new ArrayList<>();
- tribSlotEdgeSourceN = pceNode.getAvailableTribSlots().get(tps.toString());
- tribSlotEdgeDestN = pceNode.getAvailableTribSlots().get(tps.toString());
- check = false;
- for (int i = 0; i <= 79; i++) {
- if (tribSlotEdgeSourceN.get(i) == null) {
- break;
- }
- // TODO This will need to be modified as soon as the trib-slots allocation per
- // trib-port
- // policy applied by the different manufacturer is known
- if (tribSlotEdgeSourceN.get(i) == tribSlotEdgeDestN.get(i)) {
- check = true;
- } else {
- check = false;
- LOG.debug("In chooseTribSlot: Misalignement of trib slots between source {} and dest {}",
- edge.link().getSourceId().toString(), edge.link().getDestId().toString());
- break;
- }
- }
- if (check) {
- tribSlot.add(tribSlotEdgeSourceN);
+ private Map<String, List<Uint16>> chooseTribSlot(GraphPath<String,
+ PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes, int nbSlot) {
+ LOG.info("In choosetribSlot: edgeList = {} ", path.getEdgeList());
+ Map<String, List<Uint16>> 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<Uint16> srcTsPool = pceOtnNodeSrc.getAvailableTribSlots().get(linkSrcTp);
+ List<Uint16> destTsPool = pceOtnNodeDest.getAvailableTribSlots().get(linkDestTp);
+ List<Uint16> commonEdgeTsPool = new ArrayList<>();
+ List<Uint16> 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;
}
- } else {
- LOG.debug("In chooseTribSlot: source {} does not have provisonned hosting HO interface ",
- edge.link().getSourceId().toString());
- statusOK = false;
}
}
+ tribSlotMap.put(edge.link().getLinkId().getValue(), tribSlotList);
}
- if (statusOK && check) {
- return tribSlot;
- } else {
- tribSlot.clear();
- return tribSlot;
- }
-
+ tribSlotMap.forEach((k,v) -> LOG.info("TribSlotMap : k = {}, v = {}", k, v));
+ return tribSlotMap;
}
// Check the path OSNR
return false;
}
LOG.info("In checkOSNR: OSNR of the path is {} dB", osnrDb);
- if ((osnrDb + SYS_MARGIN) < MIN_OSNR_W100G) {
- return false;
- }
- double localOsnr = 0L;
- LOG.info("In OSNR Stub: {}", localOsnr);
- // TODO : change this to return OSNR value and validate or invalidate the path
- return true;
+ return ((osnrDb + SYS_MARGIN) > MIN_OSNR_W100G);
}
private double getOsnrDb(double osnrLu) {
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<String, PceGraphEdge> path,
+ Map<NodeId, PceNode> 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;
+ }
+
}