2 * Copyright © 2024 Orange Labs, 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 static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.fail;
13 import java.io.FileReader;
14 import java.io.IOException;
15 import java.io.Reader;
16 import java.nio.charset.StandardCharsets;
17 import java.util.BitSet;
18 import java.util.concurrent.ExecutionException;
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.junit.jupiter.api.BeforeEach;
21 import org.junit.jupiter.api.Test;
22 import org.junit.jupiter.api.extension.ExtendWith;
23 import org.mockito.Mock;
24 import org.mockito.junit.jupiter.MockitoExtension;
25 import org.opendaylight.mdsal.binding.api.DataBroker;
26 import org.opendaylight.mdsal.binding.api.WriteTransaction;
27 import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices;
28 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
29 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
30 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
31 import org.opendaylight.transportpce.pce.graph.PceGraphTest;
32 import org.opendaylight.transportpce.pce.utils.PceTestUtils;
33 import org.opendaylight.transportpce.test.AbstractTest;
34 import org.opendaylight.transportpce.test.converter.DataObjectConverter;
35 import org.opendaylight.transportpce.test.converter.JSONDataObjectConverter;
36 //import org.opendaylight.yang.gen.v1.http.org.openroadm.controller.customization.rev230526.controller.parameters
38 //import org.opendaylight.yang.gen.v1.http.org.openroadm.controller.customization.rev230526.controller.parameters
39 //.spectrum.filling.SpectrumFillingRules;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ControllerBehaviourSettings;
41 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
42 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
43 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
48 @ExtendWith(MockitoExtension.class)
49 public class OperatorConstraintsTest extends AbstractTest {
51 private static final Logger LOG = LoggerFactory.getLogger(PceGraphTest.class);
52 private NetworkTransactionImpl networkTransaction;
53 private static final String SPEC_FILLING_FILE = "src/test/resources/spectrum-filling-rule1.json";
54 // private static SpectrumFillingRules sfRule;
55 private static ControllerBehaviourSettings cbSettings;
56 private OperatorConstraints opConstraints;
58 private BindingDOMCodecServices bindingDOMCodecServices;
59 private DataBroker dataBroker;
62 void setUp() throws InterruptedException, ExecutionException {
63 this.dataBroker = getNewDataBroker();
64 networkTransaction = new NetworkTransactionImpl(this.dataBroker);
65 opConstraints = new OperatorConstraints(networkTransaction);
66 PceTestUtils.writeNetworkInDataStore(this.dataBroker);
67 DataObjectConverter dataObjectConverter = JSONDataObjectConverter
68 .createWithDataStoreUtil(getDataStoreContextUtil());
69 // The Spectrum filling rules associated with CustomerProfileLamda1 is populated from a file in the Data Store
70 try (Reader reader = new FileReader(SPEC_FILLING_FILE, StandardCharsets.UTF_8)) {
71 NormalizedNode normalizedNode = dataObjectConverter.transformIntoNormalizedNode(reader).orElseThrow();
72 cbSettings = (ControllerBehaviourSettings) getDataStoreContextUtil()
73 .getBindingDOMCodecServices()
75 YangInstanceIdentifier.of(ControllerBehaviourSettings.QNAME), normalizedNode)
77 InstanceIdentifier<ControllerBehaviourSettings> sfIID =
79 .builder(ControllerBehaviourSettings.class)
80 // .child(SpectrumFilling.class)
81 // .child(SpectrumFillingRules.class)
84 WriteTransaction newWriteOnlyTransaction = dataBroker.newWriteOnlyTransaction();
85 newWriteOnlyTransaction.put(LogicalDatastoreType.CONFIGURATION, sfIID, cbSettings);
86 newWriteOnlyTransaction.commit().get();
87 } catch (IOException e) {
88 LOG.error("Cannot load Spectrum-Filling-Rules in Service DS ", e);
89 fail("Cannot load Spectrum-Filling-Rules");
95 void checkSpecttrumFilling() {
96 BitSet referenceBitSet = new BitSet(GridConstant.EFFECTIVE_BITS);
97 referenceBitSet.set(0, GridConstant.EFFECTIVE_BITS, false);
98 referenceBitSet.set(0, 8, true);
99 assertEquals(referenceBitSet, opConstraints.getBitMapConstraint("CustomerProfileLamda1"));
100 referenceBitSet.set(8, GridConstant.EFFECTIVE_BITS, true);
101 referenceBitSet.set(0, 8, false);
102 assertEquals(referenceBitSet, opConstraints.getBitMapConstraint("otherCustomer"));