2 * Copyright © 2024 Orange, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.pce.constraints;
10 import java.util.BitSet;
12 import java.util.concurrent.ExecutionException;
13 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
14 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
15 import org.opendaylight.transportpce.common.fixedflex.GridUtils;
16 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev230526.FrequencyTHz;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.controller.customization.rev230526.controller.parameters.SpectrumFilling;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.controller.customization.rev230526.controller.parameters.spectrum.filling.SpectrumFillingRules;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.controller.customization.rev230526.controller.parameters.spectrum.filling.SpectrumFillingRulesKey;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ControllerBehaviourSettings;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Class to handle Operator Constraints associated with Specific Engineering rules
28 * as they are defined in the controller-behaviour-settings container of the service
33 public class OperatorConstraints {
36 private static final Logger LOG = LoggerFactory.getLogger(OperatorConstraints.class);
37 private static final String SPECTRUM_LOG_MSG =
38 "Specific Spectrum filling Rules have been defined for {} the spectrum range {} - {}";
39 private NetworkTransactionService networkTransaction;
41 public OperatorConstraints(NetworkTransactionService networkTransaction) {
43 this.networkTransaction = networkTransaction;
47 public BitSet getBitMapConstraint(String customerName) {
48 BitSet referenceBitSet = new BitSet(GridConstant.EFFECTIVE_BITS);
49 referenceBitSet.set(0, GridConstant.EFFECTIVE_BITS, true);
50 InstanceIdentifier<SpectrumFilling> sfIID =
52 .builder(ControllerBehaviourSettings.class)
53 .child(SpectrumFilling.class)
57 if (networkTransaction.read(LogicalDatastoreType.CONFIGURATION, sfIID).get().isPresent()) {
58 SpectrumFilling spectrumConstraint = networkTransaction
59 .read(LogicalDatastoreType.CONFIGURATION, sfIID)
61 if (spectrumConstraint.getSpectrumFillingRules().isEmpty()) {
62 return referenceBitSet;
64 if (customerName == null) {
65 for (Map.Entry<SpectrumFillingRulesKey, SpectrumFillingRules> rule:
66 spectrumConstraint.getSpectrumFillingRules().entrySet()) {
67 var spectrumRangeOfAppl = rule.getValue().getSpectrumRangeOfAppliance();
68 var dedicatedCustomer = spectrumRangeOfAppl.getDedicatedCustomer();
69 if (dedicatedCustomer == null || dedicatedCustomer.isEmpty()) {
72 // Spectrum portion is dedicated to some customers that do not include this one
73 FrequencyTHz startFreq = spectrumRangeOfAppl.getStartEdgeFrequency();
74 FrequencyTHz stopFreq = spectrumRangeOfAppl.getStopEdgeFrequency();
76 GridUtils.getIndexFromFrequency(startFreq.getValue()),
77 GridUtils.getIndexFromFrequency(stopFreq.getValue()),
79 LOG.info(SPECTRUM_LOG_MSG,
80 "other customers, preventing the customer from using", startFreq, stopFreq);
82 return referenceBitSet;
85 for (Map.Entry<SpectrumFillingRulesKey, SpectrumFillingRules> rule:
86 spectrumConstraint.getSpectrumFillingRules().entrySet()) {
87 var spectrumRangeOfAppl = rule.getValue().getSpectrumRangeOfAppliance();
88 FrequencyTHz startFreq = spectrumRangeOfAppl.getStartEdgeFrequency();
89 FrequencyTHz stopFreq = spectrumRangeOfAppl.getStopEdgeFrequency();
90 var nonAuthorizedCustomer = spectrumRangeOfAppl.getNonAuthorizedCustomer();
91 if (nonAuthorizedCustomer != null && nonAuthorizedCustomer.contains(customerName)) {
92 //Customer shall not be put in this spectrum portion
94 GridUtils.getIndexFromFrequency(startFreq.getValue()),
95 GridUtils.getIndexFromFrequency(stopFreq.getValue()),
97 LOG.info(SPECTRUM_LOG_MSG,
98 "customer " + customerName + ", exluding it from", startFreq, stopFreq);
101 var dedicatedCustomer = spectrumRangeOfAppl.getDedicatedCustomer();
102 if (dedicatedCustomer == null || dedicatedCustomer.isEmpty()) {
105 if (dedicatedCustomer.contains(customerName)) {
106 // Spectrum portion is dedicated to customers including this one
108 GridUtils.getIndexFromFrequency(startFreq.getValue()),
109 GridUtils.getIndexFromFrequency(stopFreq.getValue()),
111 LOG.info(SPECTRUM_LOG_MSG,
112 "customer " + customerName + ", to dedicate", startFreq, stopFreq + " to it");
115 // Spectrum portion is dedicated to some customers that do not include this one
117 GridUtils.getIndexFromFrequency(startFreq.getValue()),
118 GridUtils.getIndexFromFrequency(stopFreq.getValue()),
120 LOG.info(SPECTRUM_LOG_MSG,
121 "other customers, preventing the customer from using", startFreq, stopFreq);
123 return referenceBitSet;
125 } catch (InterruptedException | ExecutionException e1) {
126 LOG.error("Exception caught handling Spectrum filling Rules ", e1.getCause());
128 LOG.info("Did not succeed finding any Specific Spectrum filling Rules defined in Configuration Datastore");
129 return referenceBitSet;