Update Fixed to flex mapping
[transportpce.git] / common / src / main / java / org / opendaylight / transportpce / common / fixedflex / FixedFlexImpl.java
index bc829630a8c19afbcba5bb4afd7700aee174b40a..9b4e3b1457e1e6166cc70c51548bb6a8b6de964b 100644 (file)
@@ -14,6 +14,12 @@ public final class FixedFlexImpl implements FixedFlexInterface {
     private double start;
     private double stop;
     private double wavelength;
+    // wavelengthSpacing is in GHz
+    float wavelengthSpacing = 50;
+    // beginWavelength is in nm: f or F is appended to treat it explicitly as simple float (and not double float)
+    final float beginWavelength = 1528.77f;
+    // java double is double float - d or D is appended to treat it explicitly as double float
+    final double precision = 10000d;
 
     public FixedFlexImpl(Long index, double centreFrequency, double start, double stop, double wavelength) {
         this.index = index;
@@ -32,12 +38,15 @@ public final class FixedFlexImpl implements FixedFlexInterface {
     }
 
     public FixedFlexImpl(long wlIndex) {
-        this.index = wlIndex;
-        long mappedWL = wlIndex - 36;
-        this.centerFrequency = 193.1 + (50.0 / 1000.0) * mappedWL;
-        this.start = 193.1 + (50.0 * mappedWL - 25) / 1000.0;
-        this.stop = 193.1 + (50.0 * mappedWL + 25) / 1000.0;
-        this.wavelength = 1528.77 + ((wlIndex - 1) * 0.39);
+        this.centerFrequency = 196.1 - (wlIndex - 1) * wavelengthSpacing / 1000;
+        // Truncate the value to the two decimal places
+        this.centerFrequency = Math.round(this.centerFrequency * precision) / precision;
+        this.start = this.centerFrequency - (wavelengthSpacing / 2) / 1000;
+        this.start = Math.round(this.start * precision) / precision;
+        this.stop = this.centerFrequency + (wavelengthSpacing / 2) / 1000;
+        this.stop = Math.round(this.stop * precision) / precision;
+        this.wavelength = beginWavelength + ((wlIndex - 1) * 0.40);
+        this.wavelength = Math.round(this.wavelength * precision) / precision;
     }
 
     @Override
@@ -46,11 +55,18 @@ public final class FixedFlexImpl implements FixedFlexInterface {
      * @return Returns FixedFlexImp object with the calculated result.
      **/
     public FixedFlexImpl getFixedFlexWaveMapping(long wlIndex) {
+        // In Flex grid  -35 <= n <= 60
+        long mappedWL = 61 - wlIndex;
         FixedFlexImpl fixedFlex = new FixedFlexImpl();
-        long mappedWL = wlIndex - 36;
         fixedFlex.centerFrequency = 193.1 + (50.0 / 1000.0) * mappedWL;
+        fixedFlex.centerFrequency = Math.round(fixedFlex.centerFrequency * precision) / precision;
+        fixedFlex.wavelength = beginWavelength + ((wlIndex - 1) * 0.40);
+        fixedFlex.wavelength = Math.round(fixedFlex.wavelength * precision) / precision;
         fixedFlex.start = 193.1 + (50.0 * mappedWL - 25) / 1000.0;
+        fixedFlex.start = Math.round(fixedFlex.start * precision) / precision;
         fixedFlex.stop = 193.1 + (50.0 * mappedWL + 25) / 1000.0;
+        fixedFlex.stop = Math.round(fixedFlex.stop * precision) / precision;
+        fixedFlex.index = wlIndex;
         return fixedFlex;
     }