+ /**
+ * 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;
+ }
+