From d35fcfe4c76370e81269de933adfc103228a02b5 Mon Sep 17 00:00:00 2001 From: "guillaume.lambert" Date: Tue, 27 Feb 2024 12:16:22 +0100 Subject: [PATCH] Refactor PCE OperatorConstraints JIRA: TRNSPRTPCE-783 Change-Id: I062e49ad39ad417026919d4bf5f74b15265cd7bd Signed-off-by: guillaume.lambert --- .../pce/constraints/OperatorConstraints.java | 80 +++++++++++++------ 1 file changed, 54 insertions(+), 26 deletions(-) diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/constraints/OperatorConstraints.java b/pce/src/main/java/org/opendaylight/transportpce/pce/constraints/OperatorConstraints.java index 3c1159648..7e0048f5b 100644 --- a/pce/src/main/java/org/opendaylight/transportpce/pce/constraints/OperatorConstraints.java +++ b/pce/src/main/java/org/opendaylight/transportpce/pce/constraints/OperatorConstraints.java @@ -34,6 +34,8 @@ public class OperatorConstraints { /* Logging. */ private static final Logger LOG = LoggerFactory.getLogger(OperatorConstraints.class); + private static final String SPECTRUM_LOG_MSG = + "Specific Spectrum filling Rules have been defined for {} the spectrum range {} - {}"; private NetworkTransactionService networkTransaction; public OperatorConstraints(NetworkTransactionService networkTransaction) { @@ -54,48 +56,74 @@ public class OperatorConstraints { try { if (networkTransaction.read(LogicalDatastoreType.CONFIGURATION, sfIID).get().isPresent()) { SpectrumFilling spectrumConstraint = networkTransaction - .read(LogicalDatastoreType.CONFIGURATION, sfIID).get().orElseThrow(); + .read(LogicalDatastoreType.CONFIGURATION, sfIID) + .get().orElseThrow(); if (spectrumConstraint.getSpectrumFillingRules().isEmpty()) { return referenceBitSet; } + if (customerName == null) { + for (Map.Entry rule: + spectrumConstraint.getSpectrumFillingRules().entrySet()) { + var spectrumRangeOfAppl = rule.getValue().getSpectrumRangeOfAppliance(); + var dedicatedCustomer = spectrumRangeOfAppl.getDedicatedCustomer(); + if (dedicatedCustomer == null || dedicatedCustomer.isEmpty()) { + continue; + } + // Spectrum portion is dedicated to some customers that do not include this one + FrequencyTHz startFreq = spectrumRangeOfAppl.getStartEdgeFrequency(); + FrequencyTHz stopFreq = spectrumRangeOfAppl.getStopEdgeFrequency(); + referenceBitSet.set( + GridUtils.getIndexFromFrequency(startFreq.getValue()), + GridUtils.getIndexFromFrequency(stopFreq.getValue()), + false); + LOG.info(SPECTRUM_LOG_MSG, + "other customers, preventing the customer from using", startFreq, stopFreq); + } + return referenceBitSet; + } + for (Map.Entry rule: spectrumConstraint.getSpectrumFillingRules().entrySet()) { - FrequencyTHz startFreq = rule.getValue().getSpectrumRangeOfAppliance().getStartEdgeFrequency(); - FrequencyTHz stopFreq = rule.getValue().getSpectrumRangeOfAppliance().getStopEdgeFrequency(); - if (customerName != null - && rule.getValue().getSpectrumRangeOfAppliance().getNonAuthorizedCustomer() != null - && rule.getValue().getSpectrumRangeOfAppliance().getNonAuthorizedCustomer() - .contains(customerName)) { + var spectrumRangeOfAppl = rule.getValue().getSpectrumRangeOfAppliance(); + FrequencyTHz startFreq = spectrumRangeOfAppl.getStartEdgeFrequency(); + FrequencyTHz stopFreq = spectrumRangeOfAppl.getStopEdgeFrequency(); + var nonAuthorizedCustomer = spectrumRangeOfAppl.getNonAuthorizedCustomer(); + if (nonAuthorizedCustomer != null && nonAuthorizedCustomer.contains(customerName)) { //Customer shall not be put in this spectrum portion referenceBitSet.set( GridUtils.getIndexFromFrequency(startFreq.getValue()), - GridUtils.getIndexFromFrequency(stopFreq.getValue()), false); - LOG.info("Specific Spectrum filling Rules have been defined for customer {}, exluding it from " - + "the spectrum range {} - {} ", customerName, startFreq.toString(), stopFreq.toString()); - } else if (customerName != null - && rule.getValue().getSpectrumRangeOfAppliance().getDedicatedCustomer() != null - && rule.getValue().getSpectrumRangeOfAppliance() - .getDedicatedCustomer().contains(customerName)) { + GridUtils.getIndexFromFrequency(stopFreq.getValue()), + false); + LOG.info(SPECTRUM_LOG_MSG, + "customer " + customerName + ", exluding it from", startFreq, stopFreq); + continue; + } + var dedicatedCustomer = spectrumRangeOfAppl.getDedicatedCustomer(); + if (dedicatedCustomer == null || dedicatedCustomer.isEmpty()) { + continue; + } + if (dedicatedCustomer.contains(customerName)) { // Spectrum portion is dedicated to customers including this one referenceBitSet.set( GridUtils.getIndexFromFrequency(startFreq.getValue()), - GridUtils.getIndexFromFrequency(stopFreq.getValue()), true); - LOG.info("Specific Spectrum filling Rules have been defined for customer {}, to dedicate " - + "spectrum range {} - {} to it ", customerName, startFreq.toString(), stopFreq.toString()); - } else if (rule.getValue().getSpectrumRangeOfAppliance().getDedicatedCustomer() != null - && !rule.getValue().getSpectrumRangeOfAppliance().getDedicatedCustomer().isEmpty()) { - // Spectrum portion is dedicated to some customers that do not include this one - referenceBitSet.set( - GridUtils.getIndexFromFrequency(startFreq.getValue()), - GridUtils.getIndexFromFrequency(stopFreq.getValue()), false); - LOG.info("Specific Spectrum filling Rules have been defined for other customers, preventing" - + " the customer to use spectrum range {}--{}", startFreq.toString(), stopFreq.toString()); + GridUtils.getIndexFromFrequency(stopFreq.getValue()), + true); + LOG.info(SPECTRUM_LOG_MSG, + "customer " + customerName + ", to dedicate", startFreq, stopFreq + " to it"); + continue; } + // Spectrum portion is dedicated to some customers that do not include this one + referenceBitSet.set( + GridUtils.getIndexFromFrequency(startFreq.getValue()), + GridUtils.getIndexFromFrequency(stopFreq.getValue()), + false); + LOG.info(SPECTRUM_LOG_MSG, + "other customers, preventing the customer from using", startFreq, stopFreq); } return referenceBitSet; } } catch (InterruptedException | ExecutionException e1) { - LOG.error("Exception caught handling Spectrum filling Rules {} ", e1.getCause().toString()); + LOG.error("Exception caught handling Spectrum filling Rules ", e1.getCause()); } LOG.info("Did not succeed finding any Specific Spectrum filling Rules defined in Configuration Datastore"); return referenceBitSet; -- 2.36.6