Frequency computation 53/94553/7
authormanuedelf <emmanuelle.delfour@orange.com>
Tue, 1 Dec 2020 19:52:33 +0000 (20:52 +0100)
committermanuedelf <emmanuelle.delfour@orange.com>
Sat, 9 Jan 2021 14:41:35 +0000 (15:41 +0100)
- 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 <emmanuelle.delfour@orange.com>
Change-Id: I634d715fac05c52911dfc8158b4c5f0822883065

common/src/main/java/org/opendaylight/transportpce/common/fixedflex/GridConstant.java
common/src/main/java/org/opendaylight/transportpce/common/fixedflex/GridUtils.java
common/src/test/java/org/opendaylight/transportpce/common/fixedflex/GridUtilsTest.java [new file with mode: 0644]

index d3f98f5d75f9bca80f90ea33a5f20db2321f69c7..83e037aed01f9471636d5c1d33f622b547dfbdd4 100644 (file)
@@ -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() {
     }
index 9c150f24520669991aa22d34731aa85729b0f5cd..a8251c9832fdaf45705b7fb922b9cd7c9e4ca306 100644 (file)
@@ -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 (file)
index 0000000..8e485bb
--- /dev/null
@@ -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<AvailFreqMapsKey, AvailFreqMaps> 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()));
+    }
+
+}