mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-17 02:11:38 +02:00
ONOS-426 - make the unit of Bandwidth clear
Change-Id: I6f23f01306ece906fb6a6a894a52a6369983eeed
This commit is contained in:
parent
d0f13eb8bd
commit
0ce220af4f
@ -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
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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<Intent> 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<Intent> 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<Intent> compiledIntents = compileIntent(constraint, resourceService);
|
||||
assertThat(compiledIntents, notNullValue());
|
||||
|
@ -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<LinkResourceAllocations>. */
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<LinkResourceAllocations>. */
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<ResourceAllocation> 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<ResourceAllocation> 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<ResourceAllocation> allocationSet = ImmutableSet.of(allocation);
|
||||
|
||||
final LinkResourceAllocations allocations =
|
||||
|
@ -312,7 +312,7 @@ public class KryoSerializerTest {
|
||||
.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 @@ public class KryoSerializerTest {
|
||||
|
||||
@Test
|
||||
public void testBandwidthConstraint() {
|
||||
testSerializable(new BandwidthConstraint(Bandwidth.valueOf(1000.0)));
|
||||
testSerializable(new BandwidthConstraint(Bandwidth.bps(1000.0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -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<IntentId, LinkResourceAllocations> 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));
|
||||
|
@ -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<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;
|
||||
|
@ -138,7 +138,7 @@ public class IntentCodecTest extends AbstractIntentTest {
|
||||
|
||||
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(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user