ONOS-426 - make the unit of Bandwidth clear

Change-Id: I6f23f01306ece906fb6a6a894a52a6369983eeed
diff --git a/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java
index 5b73b29..d0633e6 100644
--- a/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java
@@ -169,7 +169,7 @@
         // Check for a bandwidth specification
         if (!isNullOrEmpty(bandwidthString)) {
             final double bandwidthValue = Double.parseDouble(bandwidthString);
-            constraints.add(new BandwidthConstraint(Bandwidth.valueOf(bandwidthValue)));
+            constraints.add(new BandwidthConstraint(Bandwidth.bps(bandwidthValue)));
         }
 
         // Check for a lambda specification
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);
     }
diff --git a/core/api/src/test/java/org/onosproject/net/intent/constraint/ConstraintObjectsTest.java b/core/api/src/test/java/org/onosproject/net/intent/constraint/ConstraintObjectsTest.java
index cc7f2dc..0a380a1 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/constraint/ConstraintObjectsTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/constraint/ConstraintObjectsTest.java
@@ -35,11 +35,11 @@
     // Bandwidth Constraint
 
     final BandwidthConstraint bandwidthConstraint1 =
-            new BandwidthConstraint(Bandwidth.valueOf(100.0));
+            new BandwidthConstraint(Bandwidth.bps(100.0));
     final BandwidthConstraint bandwidthConstraintSameAs1 =
-            new BandwidthConstraint(Bandwidth.valueOf(100.0));
+            new BandwidthConstraint(Bandwidth.bps(100.0));
     final BandwidthConstraint bandwidthConstraint2 =
-            new BandwidthConstraint(Bandwidth.valueOf(200.0));
+            new BandwidthConstraint(Bandwidth.bps(200.0));
 
     /**
      * Checks that the objects were created properly.
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/PathConstraintCalculationTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/PathConstraintCalculationTest.java
index cb654c3..d54789a 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/PathConstraintCalculationTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/PathConstraintCalculationTest.java
@@ -116,7 +116,7 @@
 
         final LinkResourceService resourceService =
                 IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0);
-        final Constraint constraint = new BandwidthConstraint(Bandwidth.valueOf(100.0));
+        final Constraint constraint = new BandwidthConstraint(Bandwidth.bps(100.0));
 
         final List<Intent> compiledIntents = compileIntent(constraint, resourceService);
         assertThat(compiledIntents, notNullValue());
@@ -131,7 +131,7 @@
 
         final LinkResourceService resourceService =
                 IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0);
-        final Constraint constraint = new BandwidthConstraint(Bandwidth.valueOf(100.0));
+        final Constraint constraint = new BandwidthConstraint(Bandwidth.bps(100.0));
 
         try {
             compileIntent(constraint, resourceService);
@@ -186,7 +186,7 @@
 
         final IntentTestsMocks.MockResourceService resourceService =
                 IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0);
-        final Constraint constraint = new BandwidthConstraint(Bandwidth.valueOf(100.0));
+        final Constraint constraint = new BandwidthConstraint(Bandwidth.bps(100.0));
 
         final List<Intent> compiledIntents = compileIntent(constraint, resourceService);
         assertThat(compiledIntents, notNullValue());
@@ -208,7 +208,7 @@
 
         final IntentTestsMocks.MockResourceService resourceService =
                 IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0);
-        final Constraint constraint = new BandwidthConstraint(Bandwidth.valueOf(100.0));
+        final Constraint constraint = new BandwidthConstraint(Bandwidth.bps(100.0));
 
         final List<Intent> compiledIntents = compileIntent(constraint, resourceService);
         assertThat(compiledIntents, notNullValue());
diff --git a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/DistributedLinkResourceStore.java b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/DistributedLinkResourceStore.java
index 2835c15..0119e1f 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/DistributedLinkResourceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/DistributedLinkResourceStore.java
@@ -80,7 +80,7 @@
 
     private final Logger log = getLogger(getClass());
 
-    private static final Bandwidth DEFAULT_BANDWIDTH = Bandwidth.valueOf(1_000);
+    private static final Bandwidth DEFAULT_BANDWIDTH = Bandwidth.mbps(1_000);
 
     // table to store current allocations
     /** LinkKey -> List<LinkResourceAllocations>. */
@@ -89,7 +89,7 @@
     /** IntentId -> LinkResourceAllocations. */
     private static final String INTENT_ALLOCATIONS = "IntentAllocations";
 
-    private static final Bandwidth EMPTY_BW = Bandwidth.valueOf(0);
+    private static final Bandwidth EMPTY_BW = Bandwidth.bps(0);
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected DatabaseAdminService databaseAdminService;
@@ -100,7 +100,7 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected LinkService linkService;
 
-    // Link annotation key name to use as bandwidth
+    // Link annotation key name to use as bandwidth in Mbps
     private String bandwidthAnnotation = AnnotationKeys.BANDWIDTH;
     // Link annotation key name to use as max lambda
     private String wavesAnnotation = AnnotationKeys.OPTICAL_WAVES;
@@ -175,7 +175,7 @@
         String strBw = link.annotations().value(bandwidthAnnotation);
         if (strBw != null) {
             try {
-                bandwidth = Bandwidth.valueOf(Double.parseDouble(strBw));
+                bandwidth = Bandwidth.mbps(Double.parseDouble(strBw));
             } catch (NumberFormatException e) {
                 // do nothings
                 bandwidth = null;
@@ -242,7 +242,7 @@
                     }
                 }
 
-                free.put(type, Sets.newHashSet(new BandwidthResourceAllocation(Bandwidth.valueOf(freeBw))));
+                free.put(type, Sets.newHashSet(new BandwidthResourceAllocation(Bandwidth.bps(freeBw))));
                 break;
             }
 
diff --git a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/HazelcastLinkResourceStore.java b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/HazelcastLinkResourceStore.java
index 5a2ce9a..7344862 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/HazelcastLinkResourceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/HazelcastLinkResourceStore.java
@@ -78,9 +78,9 @@
 
     private final Logger log = getLogger(getClass());
 
-    private static final Bandwidth DEFAULT_BANDWIDTH = Bandwidth.valueOf(1_000);
+    private static final Bandwidth DEFAULT_BANDWIDTH = Bandwidth.mbps(1_000);
 
-    private static final Bandwidth EMPTY_BW = Bandwidth.valueOf(0);
+    private static final Bandwidth EMPTY_BW = Bandwidth.bps(0);
 
     // table to store current allocations
     /** LinkKey -> List<LinkResourceAllocations>. */
@@ -166,7 +166,7 @@
         String strBw = link.annotations().value(bandwidthAnnotation);
         if (strBw != null) {
             try {
-                bandwidth = Bandwidth.valueOf(Double.parseDouble(strBw));
+                bandwidth = Bandwidth.mbps(Double.parseDouble(strBw));
             } catch (NumberFormatException e) {
                 // do nothings
                 bandwidth = null;
@@ -243,7 +243,7 @@
                     }
                 }
 
-                free.put(type, Sets.newHashSet(new BandwidthResourceAllocation(Bandwidth.valueOf(freeBw))));
+                free.put(type, Sets.newHashSet(new BandwidthResourceAllocation(Bandwidth.bps(freeBw))));
                 break;
             }
 
diff --git a/core/store/dist/src/test/java/org/onosproject/store/resource/impl/HazelcastLinkResourceStoreTest.java b/core/store/dist/src/test/java/org/onosproject/store/resource/impl/HazelcastLinkResourceStoreTest.java
index c15018f..53bef7e 100644
--- a/core/store/dist/src/test/java/org/onosproject/store/resource/impl/HazelcastLinkResourceStoreTest.java
+++ b/core/store/dist/src/test/java/org/onosproject/store/resource/impl/HazelcastLinkResourceStoreTest.java
@@ -80,7 +80,7 @@
     private Link newLink(String dev1, int port1, String dev2, int port2) {
         Annotations annotations = DefaultAnnotations.builder()
                 .set(AnnotationKeys.OPTICAL_WAVES, "80")
-                .set(AnnotationKeys.BANDWIDTH, "1000000")
+                .set(AnnotationKeys.BANDWIDTH, "1000")
                 .build();
         return new DefaultLink(
                 new ProviderId("of", "foo"),
@@ -175,7 +175,7 @@
         final BandwidthResourceAllocation alloc = getBandwidthObj(freeRes);
         assertNotNull(alloc);
 
-        assertEquals(Bandwidth.valueOf(1000000.0), alloc.bandwidth());
+        assertEquals(Bandwidth.mbps(1000.0), alloc.bandwidth());
     }
 
     /**
@@ -212,7 +212,7 @@
                         ImmutableSet.of(link))
                 .build();
         final ResourceAllocation allocation =
-                new BandwidthResourceAllocation(Bandwidth.valueOf(900000.0));
+                new BandwidthResourceAllocation(Bandwidth.mbps(900.0));
         final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation);
 
         final LinkResourceAllocations allocations =
@@ -233,7 +233,7 @@
                         ImmutableSet.of(link))
                         .build();
         final ResourceAllocation allocation =
-                new BandwidthResourceAllocation(Bandwidth.valueOf(9000000.0));
+                new BandwidthResourceAllocation(Bandwidth.mbps(9000.0));
         final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation);
 
         final LinkResourceAllocations allocations =
@@ -261,7 +261,7 @@
                         ImmutableSet.of(link))
                         .build();
         final ResourceAllocation allocation =
-                new BandwidthResourceAllocation(Bandwidth.valueOf(900000.0));
+                new BandwidthResourceAllocation(Bandwidth.mbps(900.0));
         final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation);
 
         final LinkResourceAllocations allocations =
diff --git a/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java b/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java
index 86ed13f..d32119c 100644
--- a/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java
+++ b/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java
@@ -312,7 +312,7 @@
                         .build();
         Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>();
         allocations.put(new DefaultLink(PID, CP1, CP2, Type.DIRECT),
-                        ImmutableSet.of(new BandwidthResourceAllocation(Bandwidth.valueOf(10.0)),
+                        ImmutableSet.of(new BandwidthResourceAllocation(Bandwidth.bps(10.0)),
                                         new LambdaResourceAllocation(Lambda.valueOf(1))));
         testSerializable(new DefaultLinkResourceAllocations(request, allocations));
     }
@@ -324,7 +324,7 @@
 
     @Test
     public void testBandwidthConstraint() {
-        testSerializable(new BandwidthConstraint(Bandwidth.valueOf(1000.0)));
+        testSerializable(new BandwidthConstraint(Bandwidth.bps(1000.0)));
     }
 
     @Test
diff --git a/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStore.java b/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStore.java
index 64e18e2..b31face 100644
--- a/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStore.java
+++ b/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStore.java
@@ -55,7 +55,7 @@
 @Component(immediate = true)
 @Service
 public class SimpleLinkResourceStore implements LinkResourceStore {
-    private static final int DEFAULT_BANDWIDTH = 1_000;
+    private static final Bandwidth DEFAULT_BANDWIDTH = Bandwidth.mbps(1_000);
     private final Logger log = getLogger(getClass());
 
     private Map<IntentId, LinkResourceAllocations> linkResourceAllocationsMap;
@@ -96,14 +96,14 @@
             log.debug("No optical.wave annotation on link %s", link);
         }
 
-        int bandwidth = DEFAULT_BANDWIDTH;
+        Bandwidth bandwidth = DEFAULT_BANDWIDTH;
         try {
-            bandwidth = Integer.parseInt(annotations.value(AnnotationKeys.BANDWIDTH));
+            bandwidth = Bandwidth.mbps((Double.parseDouble(annotations.value(AnnotationKeys.BANDWIDTH))));
         } catch (NumberFormatException e) {
             log.debug("No bandwidth annotation on link %s", link);
         }
         allocations.add(
-                new BandwidthResourceAllocation(Bandwidth.valueOf(bandwidth)));
+                new BandwidthResourceAllocation(bandwidth));
         return allocations;
     }
 
@@ -123,7 +123,7 @@
                 return (BandwidthResourceAllocation) res;
             }
         }
-        return new BandwidthResourceAllocation(Bandwidth.valueOf(0));
+        return new BandwidthResourceAllocation(Bandwidth.bps(0));
     }
 
     /**
@@ -156,7 +156,7 @@
                 }
                 freeRes.remove(ba);
                 freeRes.add(new BandwidthResourceAllocation(
-                        Bandwidth.valueOf(newBandwidth)));
+                        Bandwidth.bps(newBandwidth)));
                 break;
             case LAMBDA:
                 final boolean lambdaAvailable = freeRes.remove(res);
@@ -198,7 +198,7 @@
                 double newBandwidth = ba.bandwidth().toDouble() + requestedBandwidth;
                 freeRes.remove(ba);
                 freeRes.add(new BandwidthResourceAllocation(
-                        Bandwidth.valueOf(newBandwidth)));
+                        Bandwidth.bps(newBandwidth)));
                 break;
             case LAMBDA:
                 checkState(freeRes.add(res));
diff --git a/core/store/trivial/src/test/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStoreTest.java b/core/store/trivial/src/test/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStoreTest.java
index 9638f3f..4f1bcab 100644
--- a/core/store/trivial/src/test/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStoreTest.java
+++ b/core/store/trivial/src/test/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStoreTest.java
@@ -73,7 +73,7 @@
     private static Link newLink(String dev1, int port1, String dev2, int port2) {
         Annotations annotations = DefaultAnnotations.builder()
                 .set(AnnotationKeys.OPTICAL_WAVES, "80")
-                .set(AnnotationKeys.BANDWIDTH, "1000000")
+                .set(AnnotationKeys.BANDWIDTH, "1000")
                 .build();
         return new DefaultLink(
                 new ProviderId("of", "foo"),
@@ -159,7 +159,7 @@
         final BandwidthResourceAllocation alloc = getBandwidthObj(freeRes);
         assertNotNull(alloc);
 
-        assertEquals(Bandwidth.valueOf(1000000.0), alloc.bandwidth());
+        assertEquals(Bandwidth.mbps(1000.0), alloc.bandwidth());
     }
 
     /**
@@ -184,7 +184,7 @@
         @Override
         public Set<ResourceAllocation> getResourceAllocation(Link link) {
             final ResourceAllocation allocation =
-                    new BandwidthResourceAllocation(Bandwidth.valueOf(allocationAmount));
+                    new BandwidthResourceAllocation(Bandwidth.bps(allocationAmount));
             final Set<ResourceAllocation> allocations = new HashSet<>();
             allocations.add(allocation);
             return allocations;
diff --git a/web/api/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java b/web/api/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java
index d96f481..8814add 100644
--- a/web/api/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java
+++ b/web/api/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java
@@ -138,7 +138,7 @@
 
         final List<Constraint> constraints =
                 ImmutableList.of(
-                    new BandwidthConstraint(Bandwidth.valueOf(1.0)),
+                    new BandwidthConstraint(Bandwidth.bps(1.0)),
                     new LambdaConstraint(Lambda.valueOf(3)),
                     new AnnotationConstraint("key", 33.0),
                     new AsymmetricPathConstraint(),