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 5b73b293b1..d0633e6c82 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 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { // 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 6ccb5190f3..8b55fa3db0 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 @@ public final class AnnotationKeys { /** * 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 19ceff4cb3..dd6000eff1 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 @@ package org.onosproject.net.resource; 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,15 +39,56 @@ public final class Bandwidth extends LinkResource { } /** - * 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. * 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 9acd200a03..20dc9aea46 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 @@ public class BandwidthResourceRequest implements ResourceRequest { * * @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 cc7f2dca37..0a380a13e6 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 @@ public class ConstraintObjectsTest { // 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 cb654c32ec..d54789a05e 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 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { 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 compiledIntents = compileIntent(constraint, resourceService); assertThat(compiledIntents, notNullValue()); @@ -131,7 +131,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { 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 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { 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 compiledIntents = compileIntent(constraint, resourceService); assertThat(compiledIntents, notNullValue()); @@ -208,7 +208,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { 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 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 2835c152df..0119e1f4e9 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 @@ public class DistributedLinkResourceStore implements LinkResourceStore { 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. */ @@ -89,7 +89,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { /** 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 @@ public class DistributedLinkResourceStore implements LinkResourceStore { @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 @@ public class DistributedLinkResourceStore implements LinkResourceStore { 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 @@ public class DistributedLinkResourceStore implements LinkResourceStore { } } - 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 5a2ce9acbe..734486267b 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 @@ public class HazelcastLinkResourceStore 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. */ @@ -166,7 +166,7 @@ public class HazelcastLinkResourceStore 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 @@ public class HazelcastLinkResourceStore } } - 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 c15018f7e9..53bef7edbc 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 @@ public class HazelcastLinkResourceStoreTest { 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 @@ public class HazelcastLinkResourceStoreTest { 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 @@ public class HazelcastLinkResourceStoreTest { ImmutableSet.of(link)) .build(); final ResourceAllocation allocation = - new BandwidthResourceAllocation(Bandwidth.valueOf(900000.0)); + new BandwidthResourceAllocation(Bandwidth.mbps(900.0)); final Set allocationSet = ImmutableSet.of(allocation); final LinkResourceAllocations allocations = @@ -233,7 +233,7 @@ public class HazelcastLinkResourceStoreTest { ImmutableSet.of(link)) .build(); final ResourceAllocation allocation = - new BandwidthResourceAllocation(Bandwidth.valueOf(9000000.0)); + new BandwidthResourceAllocation(Bandwidth.mbps(9000.0)); final Set allocationSet = ImmutableSet.of(allocation); final LinkResourceAllocations allocations = @@ -261,7 +261,7 @@ public class HazelcastLinkResourceStoreTest { ImmutableSet.of(link)) .build(); final ResourceAllocation allocation = - new BandwidthResourceAllocation(Bandwidth.valueOf(900000.0)); + new BandwidthResourceAllocation(Bandwidth.mbps(900.0)); final Set 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 86ed13f168..d32119ccca 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 @@ public class KryoSerializerTest { .build(); Map> 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 @@ public class KryoSerializerTest { @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 64e18e2451..b31face3a7 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 @@ import static org.slf4j.LoggerFactory.getLogger; @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 linkResourceAllocationsMap; @@ -96,14 +96,14 @@ public class SimpleLinkResourceStore implements LinkResourceStore { 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 @@ public class SimpleLinkResourceStore implements LinkResourceStore { return (BandwidthResourceAllocation) res; } } - return new BandwidthResourceAllocation(Bandwidth.valueOf(0)); + return new BandwidthResourceAllocation(Bandwidth.bps(0)); } /** @@ -156,7 +156,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { } 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 @@ public class SimpleLinkResourceStore implements LinkResourceStore { 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 9638f3f27e..4f1bcabe24 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 @@ public class SimpleLinkResourceStoreTest { 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 @@ public class SimpleLinkResourceStoreTest { 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 @@ public class SimpleLinkResourceStoreTest { @Override public Set getResourceAllocation(Link link) { final ResourceAllocation allocation = - new BandwidthResourceAllocation(Bandwidth.valueOf(allocationAmount)); + new BandwidthResourceAllocation(Bandwidth.bps(allocationAmount)); final Set 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 d96f48121e..8814add381 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 @@ public class IntentCodecTest extends AbstractIntentTest { final List 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(),