Sho SHIMIZU
Committed by Thomas Vachuska

Avoid potential round-off error caused by floating point

Change-Id: If1a6266c7a0951441de3fe444663a109bb819056
......@@ -21,11 +21,11 @@ import org.onlab.util.Frequency;
* Represents interval frequency between two neighboring wavelengths.
*/
public enum ChannelSpacing {
CHL_100GHZ(100), // 100 GHz
CHL_50GHZ(50), // 50 GHz
CHL_25GHZ(25), // 25 GHz
CHL_12P5GHZ(12.5), // 12.5 GHz
CHL_6P25GHZ(6.25); // 6.25 GHz
CHL_100GHZ(100_000), // 100 GHz
CHL_50GHZ(50_000), // 50 GHz
CHL_25GHZ(25_000), // 25 GHz
CHL_12P5GHZ(12_500), // 12.5 GHz
CHL_6P25GHZ(6_250); // 6.25 GHz
private final Frequency frequency;
......@@ -34,8 +34,8 @@ public enum ChannelSpacing {
*
* @param value interval of neighboring wavelengths in GHz.
*/
ChannelSpacing(double value) {
this.frequency = Frequency.ofGHz(value);
ChannelSpacing(long value) {
this.frequency = Frequency.ofMHz(value);
}
public Frequency frequency() {
......
......@@ -124,7 +124,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
private static final long KBPS = 1_000;
private static final long MBPS = 1_000 * 1_000;
private static final Frequency FREQ100 = Frequency.ofGHz(100);
private static final Frequency FREQ4_4 = Frequency.ofTHz(4.4);
private static final Frequency FREQ4_4 = Frequency.ofGHz(4_400);
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceProviderRegistry providerRegistry;
......
......@@ -72,6 +72,16 @@ public final class Frequency implements RichComparable<Frequency> {
* @param value frequency in KHz
* @return instance representing the given frequency
*/
public static Frequency ofKHz(long value) {
return new Frequency(value * KHZ);
}
/**
* Returns an instance representing the specified value in KHz.
*
* @param value frequency in KHz
* @return instance representing the given frequency
*/
public static Frequency ofKHz(double value) {
return new Frequency((long) (value * KHZ));
}
......@@ -82,6 +92,16 @@ public final class Frequency implements RichComparable<Frequency> {
* @param value frequency in MHz
* @return instance representing the given frequency
*/
public static Frequency ofMHz(long value) {
return new Frequency(value * MHZ);
}
/**
* Returns an instance representing the specified value in MHz.
*
* @param value frequency in MHz
* @return instance representing the given frequency
*/
public static Frequency ofMHz(double value) {
return new Frequency((long) (value * MHZ));
}
......@@ -92,6 +112,16 @@ public final class Frequency implements RichComparable<Frequency> {
* @param value frequency in GHz
* @return instance representing the given frequency
*/
public static Frequency ofGHz(long value) {
return new Frequency(value * GHZ);
}
/**
* Returns an instance representing the specified value in GHz.
*
* @param value frequency in GHz
* @return instance representing the given frequency
*/
public static Frequency ofGHz(double value) {
return new Frequency((long) (value * GHZ));
}
......@@ -102,6 +132,16 @@ public final class Frequency implements RichComparable<Frequency> {
* @param value frequency in THz
* @return instance representing the given frequency
*/
public static Frequency ofTHz(long value) {
return new Frequency(value * THZ);
}
/**
* Returns an instance representing the specified value in THz.
*
* @param value frequency in THz
* @return instance representing the given frequency
*/
public static Frequency ofTHz(double value) {
return new Frequency((long) (value * THZ));
}
......
......@@ -24,31 +24,31 @@ package org.onlab.util;
public final class Spectrum {
// Center frequency
public static final Frequency CENTER_FREQUENCY = Frequency.ofTHz(193.1);
public static final Frequency CENTER_FREQUENCY = Frequency.ofGHz(193_100);
// O band (original): 1260 to 1360 nm
public static final Frequency O_BAND_MIN = Frequency.ofTHz(220.436);
public static final Frequency O_BAND_MAX = Frequency.ofTHz(237.931);
public static final Frequency O_BAND_MIN = Frequency.ofGHz(220_436);
public static final Frequency O_BAND_MAX = Frequency.ofGHz(237_931);
// E band (extended): 1360 to 1460 nm
public static final Frequency E_BAND_MIN = Frequency.ofTHz(205.337);
public static final Frequency E_BAND_MAX = Frequency.ofTHz(220.436);
public static final Frequency E_BAND_MIN = Frequency.ofGHz(205_337);
public static final Frequency E_BAND_MAX = Frequency.ofGHz(220_436);
// S band (short wavelength): 1460 to 1530 nm
public static final Frequency S_BAND_MIN = Frequency.ofTHz(195.943);
public static final Frequency S_BAND_MAX = Frequency.ofTHz(205.337);
public static final Frequency S_BAND_MIN = Frequency.ofGHz(195_943);
public static final Frequency S_BAND_MAX = Frequency.ofGHz(205_337);
// C band (conventional): 1530 to 1565 nm
public static final Frequency C_BAND_MIN = Frequency.ofTHz(191.561);
public static final Frequency C_BAND_MAX = Frequency.ofTHz(195.943);
public static final Frequency C_BAND_MIN = Frequency.ofGHz(191_561);
public static final Frequency C_BAND_MAX = Frequency.ofGHz(195_943);
// L band (long wavelength): 1565 to 1625 nm
public static final Frequency L_BAND_MIN = Frequency.ofTHz(184.488);
public static final Frequency L_BAND_MAX = Frequency.ofTHz(191.561);
public static final Frequency L_BAND_MIN = Frequency.ofGHz(184_488);
public static final Frequency L_BAND_MAX = Frequency.ofGHz(191_561);
// U band (ultra-long wavelength): 1625 to 1675 nm
public static final Frequency U_BAND_MIN = Frequency.ofTHz(178.981);
public static final Frequency U_BAND_MAX = Frequency.ofTHz(184.488);
public static final Frequency U_BAND_MIN = Frequency.ofGHz(178_981);
public static final Frequency U_BAND_MAX = Frequency.ofGHz(184_488);
private Spectrum() {
}
......
......@@ -102,7 +102,7 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider {
private static final String UNKNOWN = "unknown";
// C-band has 4.4 THz (4,400 GHz) total bandwidth
private static final Frequency TOTAL = Frequency.ofTHz(4.4);
private static final Frequency TOTAL = Frequency.ofGHz(4_400);
private CountDownLatch deviceLatch;
......