ONOS-426 - make the unit of Bandwidth clear
Change-Id: I6f23f01306ece906fb6a6a894a52a6369983eeed
diff --git a/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java b/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java
index 6ccb519..8b55fa3 100644
--- a/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java
+++ b/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java
@@ -61,6 +61,7 @@
/**
* Annotation key for bandwidth.
+ * The value for this key is interpreted as Mbps.
*/
public static final String BANDWIDTH = "bandwidth";
diff --git a/core/api/src/main/java/org/onosproject/net/resource/Bandwidth.java b/core/api/src/main/java/org/onosproject/net/resource/Bandwidth.java
index 19ceff4..dd6000e 100644
--- a/core/api/src/main/java/org/onosproject/net/resource/Bandwidth.java
+++ b/core/api/src/main/java/org/onosproject/net/resource/Bandwidth.java
@@ -17,9 +17,8 @@
import java.util.Objects;
-// FIXME: Document what is the unit? Mbps?
/**
- * Representation of bandwidth resource.
+ * Representation of bandwidth resource in bps.
*/
public final class Bandwidth extends LinkResource {
@@ -40,16 +39,57 @@
}
/**
- * Creates a new instance with given bandwidth.
+ * Creates a new instance with given bandwidth in bps.
*
* @param bandwidth bandwidth value to be assigned
* @return {@link Bandwidth} instance with given bandwidth
*/
+ @Deprecated
public static Bandwidth valueOf(double bandwidth) {
+ return bps(bandwidth);
+ }
+
+ /**
+ * Creates a new instance with given bandwidth in bps.
+ *
+ * @param bandwidth bandwidth value to be assigned
+ * @return {@link Bandwidth} instance with given bandwidth
+ */
+ public static Bandwidth bps(double bandwidth) {
return new Bandwidth(bandwidth);
}
/**
+ * Creates a new instance with given bandwidth in Kbps.
+ *
+ * @param bandwidth bandwidth value to be assigned
+ * @return {@link Bandwidth} instance with given bandwidth
+ */
+ public static Bandwidth kbps(double bandwidth) {
+ return new Bandwidth(bandwidth * 1_000L);
+ }
+
+ /**
+ * Creates a new instance with given bandwidth in Mbps.
+ *
+ * @param bandwidth bandwidth value to be assigned
+ * @return {@link Bandwidth} instance with given bandwidth
+ */
+ public static Bandwidth mbps(double bandwidth) {
+ return new Bandwidth(bandwidth * 1_000_000L);
+ }
+
+ /**
+ * Creates a new instance with given bandwidth in Gbps.
+ *
+ * @param bandwidth bandwidth value to be assigned
+ * @return {@link Bandwidth} instance with given bandwidth
+ */
+ public static Bandwidth gbps(double bandwidth) {
+ return new Bandwidth(bandwidth * 1_000_000_000L);
+ }
+
+ /**
* Returns bandwidth as a double value.
*
* @return bandwidth as a double value
diff --git a/core/api/src/main/java/org/onosproject/net/resource/BandwidthResourceRequest.java b/core/api/src/main/java/org/onosproject/net/resource/BandwidthResourceRequest.java
index 9acd200..20dc9ae 100644
--- a/core/api/src/main/java/org/onosproject/net/resource/BandwidthResourceRequest.java
+++ b/core/api/src/main/java/org/onosproject/net/resource/BandwidthResourceRequest.java
@@ -38,6 +38,7 @@
*
* @param bandwidth bandwidth value to be requested
*/
+ @Deprecated
public BandwidthResourceRequest(double bandwidth) {
this.bandwidth = Bandwidth.valueOf(bandwidth);
}