Committed by
Gerrit Code Review
ONOS-426 - make the unit of Bandwidth clear
Change-Id: I6f23f01306ece906fb6a6a894a52a6369983eeed
Showing
13 changed files
with
80 additions
and
38 deletions
| ... | @@ -169,7 +169,7 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { | ... | @@ -169,7 +169,7 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { |
| 169 | // Check for a bandwidth specification | 169 | // Check for a bandwidth specification |
| 170 | if (!isNullOrEmpty(bandwidthString)) { | 170 | if (!isNullOrEmpty(bandwidthString)) { |
| 171 | final double bandwidthValue = Double.parseDouble(bandwidthString); | 171 | final double bandwidthValue = Double.parseDouble(bandwidthString); |
| 172 | - constraints.add(new BandwidthConstraint(Bandwidth.valueOf(bandwidthValue))); | 172 | + constraints.add(new BandwidthConstraint(Bandwidth.bps(bandwidthValue))); |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | // Check for a lambda specification | 175 | // Check for a lambda specification | ... | ... |
| ... | @@ -61,6 +61,7 @@ public final class AnnotationKeys { | ... | @@ -61,6 +61,7 @@ public final class AnnotationKeys { |
| 61 | 61 | ||
| 62 | /** | 62 | /** |
| 63 | * Annotation key for bandwidth. | 63 | * Annotation key for bandwidth. |
| 64 | + * The value for this key is interpreted as Mbps. | ||
| 64 | */ | 65 | */ |
| 65 | public static final String BANDWIDTH = "bandwidth"; | 66 | public static final String BANDWIDTH = "bandwidth"; |
| 66 | 67 | ... | ... |
| ... | @@ -17,9 +17,8 @@ package org.onosproject.net.resource; | ... | @@ -17,9 +17,8 @@ package org.onosproject.net.resource; |
| 17 | 17 | ||
| 18 | import java.util.Objects; | 18 | import java.util.Objects; |
| 19 | 19 | ||
| 20 | -// FIXME: Document what is the unit? Mbps? | ||
| 21 | /** | 20 | /** |
| 22 | - * Representation of bandwidth resource. | 21 | + * Representation of bandwidth resource in bps. |
| 23 | */ | 22 | */ |
| 24 | public final class Bandwidth extends LinkResource { | 23 | public final class Bandwidth extends LinkResource { |
| 25 | 24 | ||
| ... | @@ -40,16 +39,57 @@ public final class Bandwidth extends LinkResource { | ... | @@ -40,16 +39,57 @@ public final class Bandwidth extends LinkResource { |
| 40 | } | 39 | } |
| 41 | 40 | ||
| 42 | /** | 41 | /** |
| 43 | - * Creates a new instance with given bandwidth. | 42 | + * Creates a new instance with given bandwidth in bps. |
| 44 | * | 43 | * |
| 45 | * @param bandwidth bandwidth value to be assigned | 44 | * @param bandwidth bandwidth value to be assigned |
| 46 | * @return {@link Bandwidth} instance with given bandwidth | 45 | * @return {@link Bandwidth} instance with given bandwidth |
| 47 | */ | 46 | */ |
| 47 | + @Deprecated | ||
| 48 | public static Bandwidth valueOf(double bandwidth) { | 48 | public static Bandwidth valueOf(double bandwidth) { |
| 49 | + return bps(bandwidth); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * Creates a new instance with given bandwidth in bps. | ||
| 54 | + * | ||
| 55 | + * @param bandwidth bandwidth value to be assigned | ||
| 56 | + * @return {@link Bandwidth} instance with given bandwidth | ||
| 57 | + */ | ||
| 58 | + public static Bandwidth bps(double bandwidth) { | ||
| 49 | return new Bandwidth(bandwidth); | 59 | return new Bandwidth(bandwidth); |
| 50 | } | 60 | } |
| 51 | 61 | ||
| 52 | /** | 62 | /** |
| 63 | + * Creates a new instance with given bandwidth in Kbps. | ||
| 64 | + * | ||
| 65 | + * @param bandwidth bandwidth value to be assigned | ||
| 66 | + * @return {@link Bandwidth} instance with given bandwidth | ||
| 67 | + */ | ||
| 68 | + public static Bandwidth kbps(double bandwidth) { | ||
| 69 | + return new Bandwidth(bandwidth * 1_000L); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * Creates a new instance with given bandwidth in Mbps. | ||
| 74 | + * | ||
| 75 | + * @param bandwidth bandwidth value to be assigned | ||
| 76 | + * @return {@link Bandwidth} instance with given bandwidth | ||
| 77 | + */ | ||
| 78 | + public static Bandwidth mbps(double bandwidth) { | ||
| 79 | + return new Bandwidth(bandwidth * 1_000_000L); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * Creates a new instance with given bandwidth in Gbps. | ||
| 84 | + * | ||
| 85 | + * @param bandwidth bandwidth value to be assigned | ||
| 86 | + * @return {@link Bandwidth} instance with given bandwidth | ||
| 87 | + */ | ||
| 88 | + public static Bandwidth gbps(double bandwidth) { | ||
| 89 | + return new Bandwidth(bandwidth * 1_000_000_000L); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + /** | ||
| 53 | * Returns bandwidth as a double value. | 93 | * Returns bandwidth as a double value. |
| 54 | * | 94 | * |
| 55 | * @return bandwidth as a double value | 95 | * @return bandwidth as a double value | ... | ... |
| ... | @@ -38,6 +38,7 @@ public class BandwidthResourceRequest implements ResourceRequest { | ... | @@ -38,6 +38,7 @@ public class BandwidthResourceRequest implements ResourceRequest { |
| 38 | * | 38 | * |
| 39 | * @param bandwidth bandwidth value to be requested | 39 | * @param bandwidth bandwidth value to be requested |
| 40 | */ | 40 | */ |
| 41 | + @Deprecated | ||
| 41 | public BandwidthResourceRequest(double bandwidth) { | 42 | public BandwidthResourceRequest(double bandwidth) { |
| 42 | this.bandwidth = Bandwidth.valueOf(bandwidth); | 43 | this.bandwidth = Bandwidth.valueOf(bandwidth); |
| 43 | } | 44 | } | ... | ... |
| ... | @@ -35,11 +35,11 @@ public class ConstraintObjectsTest { | ... | @@ -35,11 +35,11 @@ public class ConstraintObjectsTest { |
| 35 | // Bandwidth Constraint | 35 | // Bandwidth Constraint |
| 36 | 36 | ||
| 37 | final BandwidthConstraint bandwidthConstraint1 = | 37 | final BandwidthConstraint bandwidthConstraint1 = |
| 38 | - new BandwidthConstraint(Bandwidth.valueOf(100.0)); | 38 | + new BandwidthConstraint(Bandwidth.bps(100.0)); |
| 39 | final BandwidthConstraint bandwidthConstraintSameAs1 = | 39 | final BandwidthConstraint bandwidthConstraintSameAs1 = |
| 40 | - new BandwidthConstraint(Bandwidth.valueOf(100.0)); | 40 | + new BandwidthConstraint(Bandwidth.bps(100.0)); |
| 41 | final BandwidthConstraint bandwidthConstraint2 = | 41 | final BandwidthConstraint bandwidthConstraint2 = |
| 42 | - new BandwidthConstraint(Bandwidth.valueOf(200.0)); | 42 | + new BandwidthConstraint(Bandwidth.bps(200.0)); |
| 43 | 43 | ||
| 44 | /** | 44 | /** |
| 45 | * Checks that the objects were created properly. | 45 | * Checks that the objects were created properly. | ... | ... |
| ... | @@ -116,7 +116,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { | ... | @@ -116,7 +116,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { |
| 116 | 116 | ||
| 117 | final LinkResourceService resourceService = | 117 | final LinkResourceService resourceService = |
| 118 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0); | 118 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0); |
| 119 | - final Constraint constraint = new BandwidthConstraint(Bandwidth.valueOf(100.0)); | 119 | + final Constraint constraint = new BandwidthConstraint(Bandwidth.bps(100.0)); |
| 120 | 120 | ||
| 121 | final List<Intent> compiledIntents = compileIntent(constraint, resourceService); | 121 | final List<Intent> compiledIntents = compileIntent(constraint, resourceService); |
| 122 | assertThat(compiledIntents, notNullValue()); | 122 | assertThat(compiledIntents, notNullValue()); |
| ... | @@ -131,7 +131,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { | ... | @@ -131,7 +131,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { |
| 131 | 131 | ||
| 132 | final LinkResourceService resourceService = | 132 | final LinkResourceService resourceService = |
| 133 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0); | 133 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0); |
| 134 | - final Constraint constraint = new BandwidthConstraint(Bandwidth.valueOf(100.0)); | 134 | + final Constraint constraint = new BandwidthConstraint(Bandwidth.bps(100.0)); |
| 135 | 135 | ||
| 136 | try { | 136 | try { |
| 137 | compileIntent(constraint, resourceService); | 137 | compileIntent(constraint, resourceService); |
| ... | @@ -186,7 +186,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { | ... | @@ -186,7 +186,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { |
| 186 | 186 | ||
| 187 | final IntentTestsMocks.MockResourceService resourceService = | 187 | final IntentTestsMocks.MockResourceService resourceService = |
| 188 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0); | 188 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0); |
| 189 | - final Constraint constraint = new BandwidthConstraint(Bandwidth.valueOf(100.0)); | 189 | + final Constraint constraint = new BandwidthConstraint(Bandwidth.bps(100.0)); |
| 190 | 190 | ||
| 191 | final List<Intent> compiledIntents = compileIntent(constraint, resourceService); | 191 | final List<Intent> compiledIntents = compileIntent(constraint, resourceService); |
| 192 | assertThat(compiledIntents, notNullValue()); | 192 | assertThat(compiledIntents, notNullValue()); |
| ... | @@ -208,7 +208,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { | ... | @@ -208,7 +208,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { |
| 208 | 208 | ||
| 209 | final IntentTestsMocks.MockResourceService resourceService = | 209 | final IntentTestsMocks.MockResourceService resourceService = |
| 210 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0); | 210 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0); |
| 211 | - final Constraint constraint = new BandwidthConstraint(Bandwidth.valueOf(100.0)); | 211 | + final Constraint constraint = new BandwidthConstraint(Bandwidth.bps(100.0)); |
| 212 | 212 | ||
| 213 | final List<Intent> compiledIntents = compileIntent(constraint, resourceService); | 213 | final List<Intent> compiledIntents = compileIntent(constraint, resourceService); |
| 214 | assertThat(compiledIntents, notNullValue()); | 214 | assertThat(compiledIntents, notNullValue()); | ... | ... |
| ... | @@ -80,7 +80,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -80,7 +80,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
| 80 | 80 | ||
| 81 | private final Logger log = getLogger(getClass()); | 81 | private final Logger log = getLogger(getClass()); |
| 82 | 82 | ||
| 83 | - private static final Bandwidth DEFAULT_BANDWIDTH = Bandwidth.valueOf(1_000); | 83 | + private static final Bandwidth DEFAULT_BANDWIDTH = Bandwidth.mbps(1_000); |
| 84 | 84 | ||
| 85 | // table to store current allocations | 85 | // table to store current allocations |
| 86 | /** LinkKey -> List<LinkResourceAllocations>. */ | 86 | /** LinkKey -> List<LinkResourceAllocations>. */ |
| ... | @@ -89,7 +89,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -89,7 +89,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
| 89 | /** IntentId -> LinkResourceAllocations. */ | 89 | /** IntentId -> LinkResourceAllocations. */ |
| 90 | private static final String INTENT_ALLOCATIONS = "IntentAllocations"; | 90 | private static final String INTENT_ALLOCATIONS = "IntentAllocations"; |
| 91 | 91 | ||
| 92 | - private static final Bandwidth EMPTY_BW = Bandwidth.valueOf(0); | 92 | + private static final Bandwidth EMPTY_BW = Bandwidth.bps(0); |
| 93 | 93 | ||
| 94 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 94 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 95 | protected DatabaseAdminService databaseAdminService; | 95 | protected DatabaseAdminService databaseAdminService; |
| ... | @@ -100,7 +100,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -100,7 +100,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
| 100 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 100 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 101 | protected LinkService linkService; | 101 | protected LinkService linkService; |
| 102 | 102 | ||
| 103 | - // Link annotation key name to use as bandwidth | 103 | + // Link annotation key name to use as bandwidth in Mbps |
| 104 | private String bandwidthAnnotation = AnnotationKeys.BANDWIDTH; | 104 | private String bandwidthAnnotation = AnnotationKeys.BANDWIDTH; |
| 105 | // Link annotation key name to use as max lambda | 105 | // Link annotation key name to use as max lambda |
| 106 | private String wavesAnnotation = AnnotationKeys.OPTICAL_WAVES; | 106 | private String wavesAnnotation = AnnotationKeys.OPTICAL_WAVES; |
| ... | @@ -175,7 +175,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -175,7 +175,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
| 175 | String strBw = link.annotations().value(bandwidthAnnotation); | 175 | String strBw = link.annotations().value(bandwidthAnnotation); |
| 176 | if (strBw != null) { | 176 | if (strBw != null) { |
| 177 | try { | 177 | try { |
| 178 | - bandwidth = Bandwidth.valueOf(Double.parseDouble(strBw)); | 178 | + bandwidth = Bandwidth.mbps(Double.parseDouble(strBw)); |
| 179 | } catch (NumberFormatException e) { | 179 | } catch (NumberFormatException e) { |
| 180 | // do nothings | 180 | // do nothings |
| 181 | bandwidth = null; | 181 | bandwidth = null; |
| ... | @@ -242,7 +242,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -242,7 +242,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
| 242 | } | 242 | } |
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | - free.put(type, Sets.newHashSet(new BandwidthResourceAllocation(Bandwidth.valueOf(freeBw)))); | 245 | + free.put(type, Sets.newHashSet(new BandwidthResourceAllocation(Bandwidth.bps(freeBw)))); |
| 246 | break; | 246 | break; |
| 247 | } | 247 | } |
| 248 | 248 | ... | ... |
| ... | @@ -78,9 +78,9 @@ public class HazelcastLinkResourceStore | ... | @@ -78,9 +78,9 @@ public class HazelcastLinkResourceStore |
| 78 | 78 | ||
| 79 | private final Logger log = getLogger(getClass()); | 79 | private final Logger log = getLogger(getClass()); |
| 80 | 80 | ||
| 81 | - private static final Bandwidth DEFAULT_BANDWIDTH = Bandwidth.valueOf(1_000); | 81 | + private static final Bandwidth DEFAULT_BANDWIDTH = Bandwidth.mbps(1_000); |
| 82 | 82 | ||
| 83 | - private static final Bandwidth EMPTY_BW = Bandwidth.valueOf(0); | 83 | + private static final Bandwidth EMPTY_BW = Bandwidth.bps(0); |
| 84 | 84 | ||
| 85 | // table to store current allocations | 85 | // table to store current allocations |
| 86 | /** LinkKey -> List<LinkResourceAllocations>. */ | 86 | /** LinkKey -> List<LinkResourceAllocations>. */ |
| ... | @@ -166,7 +166,7 @@ public class HazelcastLinkResourceStore | ... | @@ -166,7 +166,7 @@ public class HazelcastLinkResourceStore |
| 166 | String strBw = link.annotations().value(bandwidthAnnotation); | 166 | String strBw = link.annotations().value(bandwidthAnnotation); |
| 167 | if (strBw != null) { | 167 | if (strBw != null) { |
| 168 | try { | 168 | try { |
| 169 | - bandwidth = Bandwidth.valueOf(Double.parseDouble(strBw)); | 169 | + bandwidth = Bandwidth.mbps(Double.parseDouble(strBw)); |
| 170 | } catch (NumberFormatException e) { | 170 | } catch (NumberFormatException e) { |
| 171 | // do nothings | 171 | // do nothings |
| 172 | bandwidth = null; | 172 | bandwidth = null; |
| ... | @@ -243,7 +243,7 @@ public class HazelcastLinkResourceStore | ... | @@ -243,7 +243,7 @@ public class HazelcastLinkResourceStore |
| 243 | } | 243 | } |
| 244 | } | 244 | } |
| 245 | 245 | ||
| 246 | - free.put(type, Sets.newHashSet(new BandwidthResourceAllocation(Bandwidth.valueOf(freeBw)))); | 246 | + free.put(type, Sets.newHashSet(new BandwidthResourceAllocation(Bandwidth.bps(freeBw)))); |
| 247 | break; | 247 | break; |
| 248 | } | 248 | } |
| 249 | 249 | ... | ... |
| ... | @@ -80,7 +80,7 @@ public class HazelcastLinkResourceStoreTest { | ... | @@ -80,7 +80,7 @@ public class HazelcastLinkResourceStoreTest { |
| 80 | private Link newLink(String dev1, int port1, String dev2, int port2) { | 80 | private Link newLink(String dev1, int port1, String dev2, int port2) { |
| 81 | Annotations annotations = DefaultAnnotations.builder() | 81 | Annotations annotations = DefaultAnnotations.builder() |
| 82 | .set(AnnotationKeys.OPTICAL_WAVES, "80") | 82 | .set(AnnotationKeys.OPTICAL_WAVES, "80") |
| 83 | - .set(AnnotationKeys.BANDWIDTH, "1000000") | 83 | + .set(AnnotationKeys.BANDWIDTH, "1000") |
| 84 | .build(); | 84 | .build(); |
| 85 | return new DefaultLink( | 85 | return new DefaultLink( |
| 86 | new ProviderId("of", "foo"), | 86 | new ProviderId("of", "foo"), |
| ... | @@ -175,7 +175,7 @@ public class HazelcastLinkResourceStoreTest { | ... | @@ -175,7 +175,7 @@ public class HazelcastLinkResourceStoreTest { |
| 175 | final BandwidthResourceAllocation alloc = getBandwidthObj(freeRes); | 175 | final BandwidthResourceAllocation alloc = getBandwidthObj(freeRes); |
| 176 | assertNotNull(alloc); | 176 | assertNotNull(alloc); |
| 177 | 177 | ||
| 178 | - assertEquals(Bandwidth.valueOf(1000000.0), alloc.bandwidth()); | 178 | + assertEquals(Bandwidth.mbps(1000.0), alloc.bandwidth()); |
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | /** | 181 | /** |
| ... | @@ -212,7 +212,7 @@ public class HazelcastLinkResourceStoreTest { | ... | @@ -212,7 +212,7 @@ public class HazelcastLinkResourceStoreTest { |
| 212 | ImmutableSet.of(link)) | 212 | ImmutableSet.of(link)) |
| 213 | .build(); | 213 | .build(); |
| 214 | final ResourceAllocation allocation = | 214 | final ResourceAllocation allocation = |
| 215 | - new BandwidthResourceAllocation(Bandwidth.valueOf(900000.0)); | 215 | + new BandwidthResourceAllocation(Bandwidth.mbps(900.0)); |
| 216 | final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation); | 216 | final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation); |
| 217 | 217 | ||
| 218 | final LinkResourceAllocations allocations = | 218 | final LinkResourceAllocations allocations = |
| ... | @@ -233,7 +233,7 @@ public class HazelcastLinkResourceStoreTest { | ... | @@ -233,7 +233,7 @@ public class HazelcastLinkResourceStoreTest { |
| 233 | ImmutableSet.of(link)) | 233 | ImmutableSet.of(link)) |
| 234 | .build(); | 234 | .build(); |
| 235 | final ResourceAllocation allocation = | 235 | final ResourceAllocation allocation = |
| 236 | - new BandwidthResourceAllocation(Bandwidth.valueOf(9000000.0)); | 236 | + new BandwidthResourceAllocation(Bandwidth.mbps(9000.0)); |
| 237 | final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation); | 237 | final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation); |
| 238 | 238 | ||
| 239 | final LinkResourceAllocations allocations = | 239 | final LinkResourceAllocations allocations = |
| ... | @@ -261,7 +261,7 @@ public class HazelcastLinkResourceStoreTest { | ... | @@ -261,7 +261,7 @@ public class HazelcastLinkResourceStoreTest { |
| 261 | ImmutableSet.of(link)) | 261 | ImmutableSet.of(link)) |
| 262 | .build(); | 262 | .build(); |
| 263 | final ResourceAllocation allocation = | 263 | final ResourceAllocation allocation = |
| 264 | - new BandwidthResourceAllocation(Bandwidth.valueOf(900000.0)); | 264 | + new BandwidthResourceAllocation(Bandwidth.mbps(900.0)); |
| 265 | final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation); | 265 | final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation); |
| 266 | 266 | ||
| 267 | final LinkResourceAllocations allocations = | 267 | final LinkResourceAllocations allocations = | ... | ... |
| ... | @@ -312,7 +312,7 @@ public class KryoSerializerTest { | ... | @@ -312,7 +312,7 @@ public class KryoSerializerTest { |
| 312 | .build(); | 312 | .build(); |
| 313 | Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>(); | 313 | Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>(); |
| 314 | allocations.put(new DefaultLink(PID, CP1, CP2, Type.DIRECT), | 314 | allocations.put(new DefaultLink(PID, CP1, CP2, Type.DIRECT), |
| 315 | - ImmutableSet.of(new BandwidthResourceAllocation(Bandwidth.valueOf(10.0)), | 315 | + ImmutableSet.of(new BandwidthResourceAllocation(Bandwidth.bps(10.0)), |
| 316 | new LambdaResourceAllocation(Lambda.valueOf(1)))); | 316 | new LambdaResourceAllocation(Lambda.valueOf(1)))); |
| 317 | testSerializable(new DefaultLinkResourceAllocations(request, allocations)); | 317 | testSerializable(new DefaultLinkResourceAllocations(request, allocations)); |
| 318 | } | 318 | } |
| ... | @@ -324,7 +324,7 @@ public class KryoSerializerTest { | ... | @@ -324,7 +324,7 @@ public class KryoSerializerTest { |
| 324 | 324 | ||
| 325 | @Test | 325 | @Test |
| 326 | public void testBandwidthConstraint() { | 326 | public void testBandwidthConstraint() { |
| 327 | - testSerializable(new BandwidthConstraint(Bandwidth.valueOf(1000.0))); | 327 | + testSerializable(new BandwidthConstraint(Bandwidth.bps(1000.0))); |
| 328 | } | 328 | } |
| 329 | 329 | ||
| 330 | @Test | 330 | @Test | ... | ... |
| ... | @@ -55,7 +55,7 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -55,7 +55,7 @@ import static org.slf4j.LoggerFactory.getLogger; |
| 55 | @Component(immediate = true) | 55 | @Component(immediate = true) |
| 56 | @Service | 56 | @Service |
| 57 | public class SimpleLinkResourceStore implements LinkResourceStore { | 57 | public class SimpleLinkResourceStore implements LinkResourceStore { |
| 58 | - private static final int DEFAULT_BANDWIDTH = 1_000; | 58 | + private static final Bandwidth DEFAULT_BANDWIDTH = Bandwidth.mbps(1_000); |
| 59 | private final Logger log = getLogger(getClass()); | 59 | private final Logger log = getLogger(getClass()); |
| 60 | 60 | ||
| 61 | private Map<IntentId, LinkResourceAllocations> linkResourceAllocationsMap; | 61 | private Map<IntentId, LinkResourceAllocations> linkResourceAllocationsMap; |
| ... | @@ -96,14 +96,14 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -96,14 +96,14 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
| 96 | log.debug("No optical.wave annotation on link %s", link); | 96 | log.debug("No optical.wave annotation on link %s", link); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | - int bandwidth = DEFAULT_BANDWIDTH; | 99 | + Bandwidth bandwidth = DEFAULT_BANDWIDTH; |
| 100 | try { | 100 | try { |
| 101 | - bandwidth = Integer.parseInt(annotations.value(AnnotationKeys.BANDWIDTH)); | 101 | + bandwidth = Bandwidth.mbps((Double.parseDouble(annotations.value(AnnotationKeys.BANDWIDTH)))); |
| 102 | } catch (NumberFormatException e) { | 102 | } catch (NumberFormatException e) { |
| 103 | log.debug("No bandwidth annotation on link %s", link); | 103 | log.debug("No bandwidth annotation on link %s", link); |
| 104 | } | 104 | } |
| 105 | allocations.add( | 105 | allocations.add( |
| 106 | - new BandwidthResourceAllocation(Bandwidth.valueOf(bandwidth))); | 106 | + new BandwidthResourceAllocation(bandwidth)); |
| 107 | return allocations; | 107 | return allocations; |
| 108 | } | 108 | } |
| 109 | 109 | ||
| ... | @@ -123,7 +123,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -123,7 +123,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
| 123 | return (BandwidthResourceAllocation) res; | 123 | return (BandwidthResourceAllocation) res; |
| 124 | } | 124 | } |
| 125 | } | 125 | } |
| 126 | - return new BandwidthResourceAllocation(Bandwidth.valueOf(0)); | 126 | + return new BandwidthResourceAllocation(Bandwidth.bps(0)); |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | /** | 129 | /** |
| ... | @@ -156,7 +156,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -156,7 +156,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
| 156 | } | 156 | } |
| 157 | freeRes.remove(ba); | 157 | freeRes.remove(ba); |
| 158 | freeRes.add(new BandwidthResourceAllocation( | 158 | freeRes.add(new BandwidthResourceAllocation( |
| 159 | - Bandwidth.valueOf(newBandwidth))); | 159 | + Bandwidth.bps(newBandwidth))); |
| 160 | break; | 160 | break; |
| 161 | case LAMBDA: | 161 | case LAMBDA: |
| 162 | final boolean lambdaAvailable = freeRes.remove(res); | 162 | final boolean lambdaAvailable = freeRes.remove(res); |
| ... | @@ -198,7 +198,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -198,7 +198,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
| 198 | double newBandwidth = ba.bandwidth().toDouble() + requestedBandwidth; | 198 | double newBandwidth = ba.bandwidth().toDouble() + requestedBandwidth; |
| 199 | freeRes.remove(ba); | 199 | freeRes.remove(ba); |
| 200 | freeRes.add(new BandwidthResourceAllocation( | 200 | freeRes.add(new BandwidthResourceAllocation( |
| 201 | - Bandwidth.valueOf(newBandwidth))); | 201 | + Bandwidth.bps(newBandwidth))); |
| 202 | break; | 202 | break; |
| 203 | case LAMBDA: | 203 | case LAMBDA: |
| 204 | checkState(freeRes.add(res)); | 204 | checkState(freeRes.add(res)); | ... | ... |
core/store/trivial/src/test/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStoreTest.java
| ... | @@ -73,7 +73,7 @@ public class SimpleLinkResourceStoreTest { | ... | @@ -73,7 +73,7 @@ public class SimpleLinkResourceStoreTest { |
| 73 | private static Link newLink(String dev1, int port1, String dev2, int port2) { | 73 | private static Link newLink(String dev1, int port1, String dev2, int port2) { |
| 74 | Annotations annotations = DefaultAnnotations.builder() | 74 | Annotations annotations = DefaultAnnotations.builder() |
| 75 | .set(AnnotationKeys.OPTICAL_WAVES, "80") | 75 | .set(AnnotationKeys.OPTICAL_WAVES, "80") |
| 76 | - .set(AnnotationKeys.BANDWIDTH, "1000000") | 76 | + .set(AnnotationKeys.BANDWIDTH, "1000") |
| 77 | .build(); | 77 | .build(); |
| 78 | return new DefaultLink( | 78 | return new DefaultLink( |
| 79 | new ProviderId("of", "foo"), | 79 | new ProviderId("of", "foo"), |
| ... | @@ -159,7 +159,7 @@ public class SimpleLinkResourceStoreTest { | ... | @@ -159,7 +159,7 @@ public class SimpleLinkResourceStoreTest { |
| 159 | final BandwidthResourceAllocation alloc = getBandwidthObj(freeRes); | 159 | final BandwidthResourceAllocation alloc = getBandwidthObj(freeRes); |
| 160 | assertNotNull(alloc); | 160 | assertNotNull(alloc); |
| 161 | 161 | ||
| 162 | - assertEquals(Bandwidth.valueOf(1000000.0), alloc.bandwidth()); | 162 | + assertEquals(Bandwidth.mbps(1000.0), alloc.bandwidth()); |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | /** | 165 | /** |
| ... | @@ -184,7 +184,7 @@ public class SimpleLinkResourceStoreTest { | ... | @@ -184,7 +184,7 @@ public class SimpleLinkResourceStoreTest { |
| 184 | @Override | 184 | @Override |
| 185 | public Set<ResourceAllocation> getResourceAllocation(Link link) { | 185 | public Set<ResourceAllocation> getResourceAllocation(Link link) { |
| 186 | final ResourceAllocation allocation = | 186 | final ResourceAllocation allocation = |
| 187 | - new BandwidthResourceAllocation(Bandwidth.valueOf(allocationAmount)); | 187 | + new BandwidthResourceAllocation(Bandwidth.bps(allocationAmount)); |
| 188 | final Set<ResourceAllocation> allocations = new HashSet<>(); | 188 | final Set<ResourceAllocation> allocations = new HashSet<>(); |
| 189 | allocations.add(allocation); | 189 | allocations.add(allocation); |
| 190 | return allocations; | 190 | return allocations; | ... | ... |
| ... | @@ -138,7 +138,7 @@ public class IntentCodecTest extends AbstractIntentTest { | ... | @@ -138,7 +138,7 @@ public class IntentCodecTest extends AbstractIntentTest { |
| 138 | 138 | ||
| 139 | final List<Constraint> constraints = | 139 | final List<Constraint> constraints = |
| 140 | ImmutableList.of( | 140 | ImmutableList.of( |
| 141 | - new BandwidthConstraint(Bandwidth.valueOf(1.0)), | 141 | + new BandwidthConstraint(Bandwidth.bps(1.0)), |
| 142 | new LambdaConstraint(Lambda.valueOf(3)), | 142 | new LambdaConstraint(Lambda.valueOf(3)), |
| 143 | new AnnotationConstraint("key", 33.0), | 143 | new AnnotationConstraint("key", 33.0), |
| 144 | new AsymmetricPathConstraint(), | 144 | new AsymmetricPathConstraint(), | ... | ... |
-
Please register or login to post a comment