2 * Copyright © 2020 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
9 package org.opendaylight.transportpce.common.fixedflex;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
14 import java.math.BigDecimal;
15 import java.util.Arrays;
17 import org.junit.Test;
18 import org.opendaylight.transportpce.common.ServiceRateConstant;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInput;
20 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInputBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev211210.FrequencyGHz;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev211210.FrequencyTHz;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.ModulationFormat;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.available.freq.map.AvailFreqMaps;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.available.freq.map.AvailFreqMapsKey;
26 import org.opendaylight.yangtools.yang.common.Decimal64;
27 import org.opendaylight.yangtools.yang.common.Uint32;
29 public class GridUtilsTest {
32 public void getWaveLengthIndexFromSpectrumAssigmentTest() {
33 assertEquals("Wavelength index should be 15", 15, GridUtils.getWaveLengthIndexFromSpectrumAssigment(647));
37 public void getFrequencyFromIndexTest() {
38 BigDecimal[] expectedFrequencies = new BigDecimal[768];
39 BigDecimal frequency = BigDecimal.valueOf(191.325);
40 for (int i = 0; i < expectedFrequencies.length; i++) {
41 expectedFrequencies[i] = frequency;
42 frequency = frequency.add(BigDecimal.valueOf(0.00625));
44 assertEquals("Frequency should be 191.325", 0, expectedFrequencies[0]
45 .compareTo(GridUtils.getStartFrequencyFromIndex(0)));
46 assertEquals("Frequency should be 193.1", 0, expectedFrequencies[284]
47 .compareTo(GridUtils.getStartFrequencyFromIndex(284)));
48 assertEquals("Frequency should be 196.1188", 0, expectedFrequencies[767]
49 .compareTo(GridUtils.getStartFrequencyFromIndex(767)));
53 public void initFreqMaps4FixedGrid2AvailableTest() {
54 AvailFreqMapsKey key = new AvailFreqMapsKey(GridConstant.C_BAND);
55 byte[] byteArray = new byte[GridConstant.NB_OCTECTS];
56 Arrays.fill(byteArray, (byte) GridConstant.AVAILABLE_SLOT_VALUE);
57 Map<AvailFreqMapsKey, AvailFreqMaps> availFreqMaps = GridUtils.initFreqMaps4FixedGrid2Available();
58 assertEquals("Should contains 1 element", 1, availFreqMaps.size());
59 assertTrue("should contains cband key", availFreqMaps.containsKey(key));
60 assertTrue("Should have available freq map", Arrays.equals(byteArray, availFreqMaps.get(key).getFreqMap()));
64 public void getIndexFromFrequencyTest() {
65 assertEquals("Index should be 693", 693, GridUtils.getIndexFromFrequency(Decimal64.valueOf("195.65625")));
66 assertEquals("Index should be 0", 0, GridUtils.getIndexFromFrequency(Decimal64.valueOf("191.325")));
67 assertEquals("Index should be 767", 767, GridUtils.getIndexFromFrequency(Decimal64.valueOf("196.11875")));
68 assertEquals("Index should be 8", 8, GridUtils.getIndexFromFrequency(Decimal64.valueOf("191.375")));
69 assertEquals("Index should be 15", 15, GridUtils.getIndexFromFrequency(Decimal64.valueOf("191.41875")));
70 assertEquals("Index should be 768", 768, GridUtils.getIndexFromFrequency(Decimal64.valueOf("196.125")));
73 @Test(expected = IllegalArgumentException.class)
74 public void getIndexFromFrequencyExceptionTest() {
75 GridUtils.getIndexFromFrequency(Decimal64.valueOf("196.13125"));
78 @Test(expected = IllegalArgumentException.class)
79 public void getIndexFromFrequencyException2Test() {
80 GridUtils.getIndexFromFrequency(Decimal64.valueOf("191.31875"));
84 public void getWidthFromRateAndModulationFormatTest() {
85 assertEquals("Width should be 75", new FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_75)),
86 GridUtils.getWidthFromRateAndModulationFormat(ServiceRateConstant.RATE_400,
87 ModulationFormat.DpQam16));
91 public void getWidthFromRateAndModulationFormatNotFoundTest() {
92 assertEquals("As not found width should be 40", new FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40)),
93 GridUtils.getWidthFromRateAndModulationFormat(ServiceRateConstant.RATE_100,
94 ModulationFormat.DpQam16));
98 public void getCentralFrequencyTest() {
99 assertEquals("Central frequency should be 191.350",
100 new FrequencyTHz(Decimal64.valueOf(BigDecimal.valueOf(191.35).setScale(3))),
101 GridUtils.getCentralFrequency(BigDecimal.valueOf(191.325), BigDecimal.valueOf(191.375)));
105 public void getCentralFrequencyWithPrecisionTest() {
106 assertEquals("Central frequency should be 191.3500",
107 new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyTHz(
108 Decimal64.valueOf(BigDecimal.valueOf(191.35).setScale(4))),
109 GridUtils.getCentralFrequencyWithPrecision(BigDecimal.valueOf(191.325),
110 BigDecimal.valueOf(191.375), 4));
114 public void getCentralFrequencyWithPrecisionAndRoundTest() {
115 assertEquals("Central frequency should be 191.3499",
116 new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.FrequencyTHz(
117 Decimal64.valueOf("191.3499")),
118 GridUtils.getCentralFrequencyWithPrecision(BigDecimal.valueOf(191.3244445),
119 BigDecimal.valueOf(191.3754457788), 4));
123 public void initSpectrumInformationFromServicePathInputTest() {
124 ServicePathInput input = new ServicePathInputBuilder()
125 .setWaveNumber(Uint32.valueOf(1))
126 .setCenterFreq(new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019
127 .FrequencyTHz(Decimal64.valueOf("196.1")))
128 .setHigherSpectralSlotNumber(Uint32.valueOf(768))
129 .setLowerSpectralSlotNumber(Uint32.valueOf(761))
130 .setMaxFreq(new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019
131 .FrequencyTHz(Decimal64.valueOf("196.125")))
132 .setMinFreq(new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019
133 .FrequencyTHz(Decimal64.valueOf("196.075")))
134 .setNmcWidth(new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019
135 .FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40)))
137 SpectrumInformation spectrumInformation = GridUtils.initSpectrumInformationFromServicePathInput(input);
138 assertEquals("Width should be 40", BigDecimal.valueOf(40), spectrumInformation.getWidth());
139 assertEquals("Wavelength should be 1", Uint32.valueOf(1), spectrumInformation.getWaveLength());
140 assertEquals("Center freq should be 196.1", BigDecimal.valueOf(196.1).setScale(4),
141 spectrumInformation.getCenterFrequency());
142 assertEquals("Lower slot number should be 761", 761, spectrumInformation.getLowerSpectralSlotNumber());
143 assertEquals("Higher slot number should be 768", 768, spectrumInformation.getHigherSpectralSlotNumber());
144 assertEquals("Min freq should be 196.075", BigDecimal.valueOf(196.075).setScale(4),
145 spectrumInformation.getMinFrequency());
146 assertEquals("Max freq should be 196.125", BigDecimal.valueOf(196.125).setScale(4),
147 spectrumInformation.getMaxFrequency());
151 public void initSpectrumInformationFromServicePathInputNoCenterFreqTest() {
152 ServicePathInput input = new ServicePathInputBuilder()
153 .setWaveNumber(Uint32.valueOf(1))
154 .setHigherSpectralSlotNumber(Uint32.valueOf(768))
155 .setLowerSpectralSlotNumber(Uint32.valueOf(761))
156 .setMaxFreq(new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019
157 .FrequencyTHz(Decimal64.valueOf("196.125")))
158 .setMinFreq(new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019
159 .FrequencyTHz(Decimal64.valueOf("196.075")))
160 .setNmcWidth(new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019
161 .FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40)))
163 SpectrumInformation spectrumInformation = GridUtils.initSpectrumInformationFromServicePathInput(input);
164 assertEquals("Width should be 40", BigDecimal.valueOf(40), spectrumInformation.getWidth());
165 assertEquals("Wavelength should be 1", Uint32.valueOf(1), spectrumInformation.getWaveLength());
166 assertEquals("Center freq should be 196.1", BigDecimal.valueOf(196.1).setScale(4),
167 spectrumInformation.getCenterFrequency());
168 assertEquals("Lower slot number should be 761", 761, spectrumInformation.getLowerSpectralSlotNumber());
169 assertEquals("Higher slot number should be 768", 768, spectrumInformation.getHigherSpectralSlotNumber());
170 assertEquals("Min freq should be 196.075", BigDecimal.valueOf(196.075).setScale(4),
171 spectrumInformation.getMinFrequency());
172 assertEquals("Max freq should be 196.125", BigDecimal.valueOf(196.125).setScale(4),
173 spectrumInformation.getMaxFrequency());
177 public void initSpectrumInformationFromServicePathInputNoFreqTest() {
178 ServicePathInput input = new ServicePathInputBuilder()
179 .setWaveNumber(Uint32.valueOf(1))
180 .setHigherSpectralSlotNumber(Uint32.valueOf(768))
181 .setLowerSpectralSlotNumber(Uint32.valueOf(761))
182 .setNmcWidth(new org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019
183 .FrequencyGHz(Decimal64.valueOf(GridConstant.WIDTH_40)))
185 SpectrumInformation spectrumInformation = GridUtils.initSpectrumInformationFromServicePathInput(input);
186 assertEquals("Width should be 40", BigDecimal.valueOf(40), spectrumInformation.getWidth());
187 assertEquals("Wavelength should be 1", Uint32.valueOf(1), spectrumInformation.getWaveLength());
188 assertEquals("Center freq should be 196.1", BigDecimal.valueOf(196.1).setScale(4),
189 spectrumInformation.getCenterFrequency());
190 assertEquals("Lower slot number should be 761", 761, spectrumInformation.getLowerSpectralSlotNumber());
191 assertEquals("Higher slot number should be 768", 768, spectrumInformation.getHigherSpectralSlotNumber());
192 assertEquals("Min freq should be 196.075", BigDecimal.valueOf(196.075).setScale(4),
193 spectrumInformation.getMinFrequency());
194 assertEquals("Max freq should be 196.125", BigDecimal.valueOf(196.125).setScale(4),
195 spectrumInformation.getMaxFrequency());
198 @Test(expected = IllegalArgumentException.class)
199 public void initSpectrumInformationFromServicePathInputNoSlotTest() {
200 GridUtils.initSpectrumInformationFromServicePathInput(new ServicePathInputBuilder().build());