From: manuedelf Date: Tue, 1 Dec 2020 19:52:33 +0000 (+0100) Subject: Frequency computation X-Git-Tag: 2.2.0~16 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F33%2F94233%2F6;p=transportpce.git Frequency computation - Update GridUtils with 2 methods for computing wavelength number and frequency. - Add unit tests for those methods - Add nb slots constants for 100G and 400G - Add constant for central frequency JIRA: TRNSPRTPCE-230 Signed-off-by: manuedelf Change-Id: I634d715fac05c52911dfc8158b4c5f0822883065 --- diff --git a/common/src/main/java/org/opendaylight/transportpce/common/fixedflex/GridConstant.java b/common/src/main/java/org/opendaylight/transportpce/common/fixedflex/GridConstant.java index d3f98f5d7..83e037aed 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/fixedflex/GridConstant.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/fixedflex/GridConstant.java @@ -21,6 +21,9 @@ public final class GridConstant { public static final int EFFECTIVE_BITS = 768; public static final double START_EDGE_FREQUENCY = 191.325; public static final int NB_OCTECTS = 96; + public static final double CENTRAL_FREQUENCY = 193.1; + public static final int NB_SLOTS_100G = 8; + public static final int NB_SLOTS_400G = 14; private GridConstant() { } diff --git a/common/src/main/java/org/opendaylight/transportpce/common/fixedflex/GridUtils.java b/common/src/main/java/org/opendaylight/transportpce/common/fixedflex/GridUtils.java index 9c150f245..a8251c983 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/fixedflex/GridUtils.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/fixedflex/GridUtils.java @@ -42,4 +42,24 @@ public final class GridUtils { return waveMap; } + /** + * Compute the wavelength index from Spectrum assignment stop index. + * Only for fix grid and device 1.2.1. + * @param stopIndex int + * @return the wavelength number. + */ + public static long getWaveLengthIndexFromSpectrumAssigment(int stopIndex) { + return (stopIndex + 1) / GridConstant.NB_SLOTS_100G; + } + + /** + * Compute the frequency in TGz for the given index. + * @param index int + * @return the frequency in THz for the provided index. + */ + public static BigDecimal getFrequencyFromIndex(int index) { + int nvalue = index - 284; + return BigDecimal.valueOf(GridConstant.CENTRAL_FREQUENCY + (nvalue * GridConstant.GRANULARITY / 1000)); + } + } diff --git a/common/src/test/java/org/opendaylight/transportpce/common/fixedflex/GridUtilsTest.java b/common/src/test/java/org/opendaylight/transportpce/common/fixedflex/GridUtilsTest.java new file mode 100644 index 000000000..8e485bb19 --- /dev/null +++ b/common/src/test/java/org/opendaylight/transportpce/common/fixedflex/GridUtilsTest.java @@ -0,0 +1,55 @@ +/* + * Copyright © 2020 Orange, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.transportpce.common.fixedflex; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.math.BigDecimal; +import java.util.Arrays; +import java.util.Map; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.available.freq.map.AvailFreqMaps; +import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.available.freq.map.AvailFreqMapsKey; + +public class GridUtilsTest { + + @Test + public void getWaveLengthIndexFromSpectrumAssigmentTest() { + assertEquals("Wavelength index should be 15", 15, GridUtils.getWaveLengthIndexFromSpectrumAssigment(119)); + } + + @Test + public void getFrequencyFromIndexTest() { + BigDecimal[] expectedFrequencies = new BigDecimal[768]; + BigDecimal frequency = BigDecimal.valueOf(191.325); + for (int i = 0; i < expectedFrequencies.length; i++) { + expectedFrequencies[i] = frequency; + frequency = frequency.add(BigDecimal.valueOf(0.00625)); + } + assertEquals("Frequency should be 191.325", expectedFrequencies[0], + GridUtils.getFrequencyFromIndex(0)); + assertEquals("Frequency should be 193.1", expectedFrequencies[284].setScale(1), + GridUtils.getFrequencyFromIndex(284)); + assertEquals("Frequency should be 196.11875", expectedFrequencies[767], + GridUtils.getFrequencyFromIndex(767)); + } + + @Test + public void initFreqMaps4FixedGrid2AvailableTest() { + AvailFreqMapsKey key = new AvailFreqMapsKey(GridConstant.C_BAND); + byte[] byteArray = new byte[GridConstant.NB_OCTECTS]; + Arrays.fill(byteArray, (byte) GridConstant.AVAILABLE_SLOT_VALUE); + Map availFreqMaps = GridUtils.initFreqMaps4FixedGrid2Available(); + assertEquals("Should contains 1 element", 1, availFreqMaps.size()); + assertTrue("should contains cband key", availFreqMaps.containsKey(key)); + assertTrue("Should have available freq map", Arrays.equals(byteArray, availFreqMaps.get(key).getFreqMap())); + } + +}