Inline static factory methods in BandwidthResource
Change-Id: I8ac7fbaea5c81c9558f88f6ac88bcf581466d073
Showing
13 changed files
with
52 additions
and
87 deletions
| ... | @@ -24,6 +24,7 @@ import java.util.List; | ... | @@ -24,6 +24,7 @@ import java.util.List; |
| 24 | import org.apache.karaf.shell.commands.Option; | 24 | import org.apache.karaf.shell.commands.Option; |
| 25 | import org.onlab.packet.Ip6Address; | 25 | import org.onlab.packet.Ip6Address; |
| 26 | import org.onlab.packet.IpAddress; | 26 | import org.onlab.packet.IpAddress; |
| 27 | +import org.onlab.util.Bandwidth; | ||
| 27 | import org.onosproject.cli.AbstractShellCommand; | 28 | import org.onosproject.cli.AbstractShellCommand; |
| 28 | import org.onosproject.core.ApplicationId; | 29 | import org.onosproject.core.ApplicationId; |
| 29 | import org.onosproject.core.CoreService; | 30 | import org.onosproject.core.CoreService; |
| ... | @@ -306,8 +307,8 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { | ... | @@ -306,8 +307,8 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { |
| 306 | 307 | ||
| 307 | // Check for a bandwidth specification | 308 | // Check for a bandwidth specification |
| 308 | if (!isNullOrEmpty(bandwidthString)) { | 309 | if (!isNullOrEmpty(bandwidthString)) { |
| 309 | - final double bandwidthValue = Double.parseDouble(bandwidthString); | 310 | + final Bandwidth bandwidth = Bandwidth.bps(Double.parseDouble(bandwidthString)); |
| 310 | - constraints.add(new BandwidthConstraint(BandwidthResource.bps(bandwidthValue))); | 311 | + constraints.add(new BandwidthConstraint(new BandwidthResource(bandwidth))); |
| 311 | } | 312 | } |
| 312 | 313 | ||
| 313 | // Check for a lambda specification | 314 | // Check for a lambda specification | ... | ... |
| ... | @@ -33,7 +33,7 @@ public final class BandwidthResource extends LinkResource { | ... | @@ -33,7 +33,7 @@ public final class BandwidthResource extends LinkResource { |
| 33 | * | 33 | * |
| 34 | * @param bandwidth bandwidth value to be assigned | 34 | * @param bandwidth bandwidth value to be assigned |
| 35 | */ | 35 | */ |
| 36 | - private BandwidthResource(Bandwidth bandwidth) { | 36 | + public BandwidthResource(Bandwidth bandwidth) { |
| 37 | this.bandwidth = checkNotNull(bandwidth); | 37 | this.bandwidth = checkNotNull(bandwidth); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| ... | @@ -43,61 +43,6 @@ public final class BandwidthResource extends LinkResource { | ... | @@ -43,61 +43,6 @@ public final class BandwidthResource extends LinkResource { |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | /** | 45 | /** |
| 46 | - * Creates a new instance with given bandwidth in bps. | ||
| 47 | - * | ||
| 48 | - * @param bandwidth bandwidth value to be assigned | ||
| 49 | - * @return {@link BandwidthResource} instance with given bandwidth | ||
| 50 | - */ | ||
| 51 | - @Deprecated | ||
| 52 | - public static BandwidthResource valueOf(double bandwidth) { | ||
| 53 | - return bps(bandwidth); | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - public static BandwidthResource from(Bandwidth bandwidth) { | ||
| 57 | - return new BandwidthResource(bandwidth); | ||
| 58 | - } | ||
| 59 | - | ||
| 60 | - /** | ||
| 61 | - * Creates a new instance with given bandwidth in bps. | ||
| 62 | - * | ||
| 63 | - * @param bps bandwidth value to be assigned | ||
| 64 | - * @return {@link BandwidthResource} instance with given bandwidth | ||
| 65 | - */ | ||
| 66 | - public static BandwidthResource bps(double bps) { | ||
| 67 | - return from(Bandwidth.bps(bps)); | ||
| 68 | - } | ||
| 69 | - | ||
| 70 | - /** | ||
| 71 | - * Creates a new instance with given bandwidth in Kbps. | ||
| 72 | - * | ||
| 73 | - * @param kbps bandwidth value to be assigned | ||
| 74 | - * @return {@link BandwidthResource} instance with given bandwidth | ||
| 75 | - */ | ||
| 76 | - public static BandwidthResource kbps(double kbps) { | ||
| 77 | - return from(Bandwidth.kbps(kbps)); | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | - /** | ||
| 81 | - * Creates a new instance with given bandwidth in Mbps. | ||
| 82 | - * | ||
| 83 | - * @param mbps bandwidth value to be assigned | ||
| 84 | - * @return {@link BandwidthResource} instance with given bandwidth | ||
| 85 | - */ | ||
| 86 | - public static BandwidthResource mbps(double mbps) { | ||
| 87 | - return from(Bandwidth.mbps(mbps)); | ||
| 88 | - } | ||
| 89 | - | ||
| 90 | - /** | ||
| 91 | - * Creates a new instance with given bandwidth in Gbps. | ||
| 92 | - * | ||
| 93 | - * @param gbps bandwidth value to be assigned | ||
| 94 | - * @return {@link BandwidthResource} instance with given bandwidth | ||
| 95 | - */ | ||
| 96 | - public static BandwidthResource gbps(double gbps) { | ||
| 97 | - return from(Bandwidth.gbps(gbps)); | ||
| 98 | - } | ||
| 99 | - | ||
| 100 | - /** | ||
| 101 | * Returns bandwidth as a double value. | 46 | * Returns bandwidth as a double value. |
| 102 | * | 47 | * |
| 103 | * @return bandwidth as a double value | 48 | * @return bandwidth as a double value | ... | ... |
| ... | @@ -20,6 +20,7 @@ import java.util.HashSet; | ... | @@ -20,6 +20,7 @@ import java.util.HashSet; |
| 20 | import java.util.Set; | 20 | import java.util.Set; |
| 21 | import java.util.Objects; | 21 | import java.util.Objects; |
| 22 | 22 | ||
| 23 | +import org.onlab.util.Bandwidth; | ||
| 23 | import org.onosproject.net.Link; | 24 | import org.onosproject.net.Link; |
| 24 | import org.onosproject.net.intent.Constraint; | 25 | import org.onosproject.net.intent.Constraint; |
| 25 | import org.onosproject.net.intent.IntentId; | 26 | import org.onosproject.net.intent.IntentId; |
| ... | @@ -137,7 +138,7 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { | ... | @@ -137,7 +138,7 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { |
| 137 | */ | 138 | */ |
| 138 | @Override | 139 | @Override |
| 139 | public Builder addBandwidthRequest(double bandwidth) { | 140 | public Builder addBandwidthRequest(double bandwidth) { |
| 140 | - resources.add(new BandwidthResourceRequest(BandwidthResource.bps(bandwidth))); | 141 | + resources.add(new BandwidthResourceRequest(new BandwidthResource(Bandwidth.bps(bandwidth)))); |
| 141 | return this; | 142 | return this; |
| 142 | } | 143 | } |
| 143 | 144 | ... | ... |
| ... | @@ -18,6 +18,7 @@ package org.onosproject.net.intent; | ... | @@ -18,6 +18,7 @@ package org.onosproject.net.intent; |
| 18 | import com.google.common.base.MoreObjects; | 18 | import com.google.common.base.MoreObjects; |
| 19 | import com.google.common.collect.ImmutableSet; | 19 | import com.google.common.collect.ImmutableSet; |
| 20 | 20 | ||
| 21 | +import org.onlab.util.Bandwidth; | ||
| 21 | import org.onosproject.core.DefaultGroupId; | 22 | import org.onosproject.core.DefaultGroupId; |
| 22 | import org.onosproject.core.GroupId; | 23 | import org.onosproject.core.GroupId; |
| 23 | import org.onosproject.net.DeviceId; | 24 | import org.onosproject.net.DeviceId; |
| ... | @@ -302,7 +303,7 @@ public class IntentTestsMocks { | ... | @@ -302,7 +303,7 @@ public class IntentTestsMocks { |
| 302 | final List<ResourceRequest> result = new LinkedList<>(); | 303 | final List<ResourceRequest> result = new LinkedList<>(); |
| 303 | if (availableBandwidth > 0.0) { | 304 | if (availableBandwidth > 0.0) { |
| 304 | result.add(new BandwidthResourceRequest( | 305 | result.add(new BandwidthResourceRequest( |
| 305 | - BandwidthResource.bps(availableBandwidth))); | 306 | + new BandwidthResource(Bandwidth.bps(availableBandwidth)))); |
| 306 | } | 307 | } |
| 307 | if (availableLambda > 0) { | 308 | if (availableLambda > 0) { |
| 308 | result.add(new LambdaResourceRequest()); | 309 | result.add(new LambdaResourceRequest()); | ... | ... |
| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | package org.onosproject.net.intent.constraint; | 16 | package org.onosproject.net.intent.constraint; |
| 17 | 17 | ||
| 18 | import org.junit.Test; | 18 | import org.junit.Test; |
| 19 | +import org.onlab.util.Bandwidth; | ||
| 19 | import org.onosproject.net.Link; | 20 | import org.onosproject.net.Link; |
| 20 | import org.onosproject.net.resource.BandwidthResource; | 21 | import org.onosproject.net.resource.BandwidthResource; |
| 21 | import org.onosproject.net.resource.LambdaResource; | 22 | import org.onosproject.net.resource.LambdaResource; |
| ... | @@ -34,12 +35,16 @@ public class ConstraintObjectsTest { | ... | @@ -34,12 +35,16 @@ public class ConstraintObjectsTest { |
| 34 | 35 | ||
| 35 | // Bandwidth Constraint | 36 | // Bandwidth Constraint |
| 36 | 37 | ||
| 38 | + private final Bandwidth bandwidth1 = Bandwidth.bps(100.0); | ||
| 39 | + private final Bandwidth sameAsBandwidth1 = Bandwidth.bps(100.0); | ||
| 40 | + private final Bandwidth bandwidth2 = Bandwidth.bps(200.0); | ||
| 41 | + | ||
| 37 | final BandwidthConstraint bandwidthConstraint1 = | 42 | final BandwidthConstraint bandwidthConstraint1 = |
| 38 | - new BandwidthConstraint(BandwidthResource.bps(100.0)); | 43 | + new BandwidthConstraint(new BandwidthResource(bandwidth1)); |
| 39 | final BandwidthConstraint bandwidthConstraintSameAs1 = | 44 | final BandwidthConstraint bandwidthConstraintSameAs1 = |
| 40 | - new BandwidthConstraint(BandwidthResource.bps(100.0)); | 45 | + new BandwidthConstraint(new BandwidthResource(sameAsBandwidth1)); |
| 41 | final BandwidthConstraint bandwidthConstraint2 = | 46 | final BandwidthConstraint bandwidthConstraint2 = |
| 42 | - new BandwidthConstraint(BandwidthResource.bps(200.0)); | 47 | + new BandwidthConstraint(new BandwidthResource(bandwidth2)); |
| 43 | 48 | ||
| 44 | /** | 49 | /** |
| 45 | * Checks that the objects were created properly. | 50 | * Checks that the objects were created properly. | ... | ... |
| ... | @@ -22,6 +22,7 @@ import org.junit.Test; | ... | @@ -22,6 +22,7 @@ import org.junit.Test; |
| 22 | import org.onlab.packet.IpPrefix; | 22 | import org.onlab.packet.IpPrefix; |
| 23 | import org.onlab.packet.MacAddress; | 23 | import org.onlab.packet.MacAddress; |
| 24 | import org.onlab.packet.MplsLabel; | 24 | import org.onlab.packet.MplsLabel; |
| 25 | +import org.onlab.util.Bandwidth; | ||
| 25 | import org.onosproject.codec.CodecContext; | 26 | import org.onosproject.codec.CodecContext; |
| 26 | import org.onosproject.codec.JsonCodec; | 27 | import org.onosproject.codec.JsonCodec; |
| 27 | import org.onosproject.core.ApplicationId; | 28 | import org.onosproject.core.ApplicationId; |
| ... | @@ -145,7 +146,7 @@ public class IntentCodecTest extends AbstractIntentTest { | ... | @@ -145,7 +146,7 @@ public class IntentCodecTest extends AbstractIntentTest { |
| 145 | 146 | ||
| 146 | final List<Constraint> constraints = | 147 | final List<Constraint> constraints = |
| 147 | ImmutableList.of( | 148 | ImmutableList.of( |
| 148 | - new BandwidthConstraint(BandwidthResource.bps(1.0)), | 149 | + new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(1.0))), |
| 149 | new LambdaConstraint(LambdaResource.valueOf(3)), | 150 | new LambdaConstraint(LambdaResource.valueOf(3)), |
| 150 | new AnnotationConstraint("key", 33.0), | 151 | new AnnotationConstraint("key", 33.0), |
| 151 | new AsymmetricPathConstraint(), | 152 | new AsymmetricPathConstraint(), | ... | ... |
| ... | @@ -17,6 +17,7 @@ package org.onosproject.net.intent.impl.compiler; | ... | @@ -17,6 +17,7 @@ package org.onosproject.net.intent.impl.compiler; |
| 17 | 17 | ||
| 18 | import org.hamcrest.Matchers; | 18 | import org.hamcrest.Matchers; |
| 19 | import org.junit.Test; | 19 | import org.junit.Test; |
| 20 | +import org.onlab.util.Bandwidth; | ||
| 20 | import org.onosproject.TestApplicationId; | 21 | import org.onosproject.TestApplicationId; |
| 21 | import org.onosproject.core.ApplicationId; | 22 | import org.onosproject.core.ApplicationId; |
| 22 | import org.onosproject.net.ConnectPoint; | 23 | import org.onosproject.net.ConnectPoint; |
| ... | @@ -227,7 +228,8 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { | ... | @@ -227,7 +228,8 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { |
| 227 | 228 | ||
| 228 | final LinkResourceService resourceService = | 229 | final LinkResourceService resourceService = |
| 229 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0); | 230 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0); |
| 230 | - final List<Constraint> constraints = Arrays.asList(new BandwidthConstraint(BandwidthResource.bps(100.0))); | 231 | + final List<Constraint> constraints = Arrays.asList( |
| 232 | + new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(100.0)))); | ||
| 231 | 233 | ||
| 232 | final PointToPointIntent intent = makeIntent("s1", "s3", constraints); | 234 | final PointToPointIntent intent = makeIntent("s1", "s3", constraints); |
| 233 | 235 | ||
| ... | @@ -248,7 +250,8 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { | ... | @@ -248,7 +250,8 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { |
| 248 | 250 | ||
| 249 | final LinkResourceService resourceService = | 251 | final LinkResourceService resourceService = |
| 250 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0); | 252 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0); |
| 251 | - final List<Constraint> constraints = Arrays.asList(new BandwidthConstraint(BandwidthResource.bps(100.0))); | 253 | + final List<Constraint> constraints = Arrays.asList( |
| 254 | + new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(100.0)))); | ||
| 252 | 255 | ||
| 253 | try { | 256 | try { |
| 254 | final PointToPointIntent intent = makeIntent("s1", "s3", constraints); | 257 | final PointToPointIntent intent = makeIntent("s1", "s3", constraints); | ... | ... |
| ... | @@ -16,6 +16,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; | ... | @@ -16,6 +16,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 16 | import org.apache.felix.scr.annotations.Service; | 16 | import org.apache.felix.scr.annotations.Service; |
| 17 | import org.apache.felix.scr.annotations.Activate; | 17 | import org.apache.felix.scr.annotations.Activate; |
| 18 | import org.apache.felix.scr.annotations.Deactivate; | 18 | import org.apache.felix.scr.annotations.Deactivate; |
| 19 | +import org.onlab.util.Bandwidth; | ||
| 19 | import org.slf4j.Logger; | 20 | import org.slf4j.Logger; |
| 20 | import org.onlab.util.KryoNamespace; | 21 | import org.onlab.util.KryoNamespace; |
| 21 | import org.onlab.util.PositionalParameterStringFormatter; | 22 | import org.onlab.util.PositionalParameterStringFormatter; |
| ... | @@ -67,8 +68,8 @@ public class ConsistentLinkResourceStore extends | ... | @@ -67,8 +68,8 @@ public class ConsistentLinkResourceStore extends |
| 67 | 68 | ||
| 68 | private final Logger log = getLogger(getClass()); | 69 | private final Logger log = getLogger(getClass()); |
| 69 | 70 | ||
| 70 | - private static final BandwidthResource DEFAULT_BANDWIDTH = BandwidthResource.mbps(1_000); | 71 | + private static final BandwidthResource DEFAULT_BANDWIDTH = new BandwidthResource(Bandwidth.mbps(1_000)); |
| 71 | - private static final BandwidthResource EMPTY_BW = BandwidthResource.bps(0); | 72 | + private static final BandwidthResource EMPTY_BW = new BandwidthResource(Bandwidth.bps(0)); |
| 72 | 73 | ||
| 73 | // Smallest non-reserved MPLS label | 74 | // Smallest non-reserved MPLS label |
| 74 | private static final int MIN_UNRESERVED_LABEL = 0x10; | 75 | private static final int MIN_UNRESERVED_LABEL = 0x10; |
| ... | @@ -154,7 +155,7 @@ public class ConsistentLinkResourceStore extends | ... | @@ -154,7 +155,7 @@ public class ConsistentLinkResourceStore extends |
| 154 | String strBw = link.annotations().value(BANDWIDTH); | 155 | String strBw = link.annotations().value(BANDWIDTH); |
| 155 | if (strBw != null) { | 156 | if (strBw != null) { |
| 156 | try { | 157 | try { |
| 157 | - bandwidth = BandwidthResource.mbps(Double.parseDouble(strBw)); | 158 | + bandwidth = new BandwidthResource(Bandwidth.mbps(Double.parseDouble(strBw))); |
| 158 | } catch (NumberFormatException e) { | 159 | } catch (NumberFormatException e) { |
| 159 | // do nothings | 160 | // do nothings |
| 160 | bandwidth = null; | 161 | bandwidth = null; |
| ... | @@ -237,7 +238,8 @@ public class ConsistentLinkResourceStore extends | ... | @@ -237,7 +238,8 @@ public class ConsistentLinkResourceStore extends |
| 237 | } | 238 | } |
| 238 | } | 239 | } |
| 239 | 240 | ||
| 240 | - free.put(type, Sets.newHashSet(new BandwidthResourceAllocation(BandwidthResource.bps(freeBw)))); | 241 | + free.put(type, Sets.newHashSet( |
| 242 | + new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(freeBw))))); | ||
| 241 | break; | 243 | break; |
| 242 | case LAMBDA: | 244 | case LAMBDA: |
| 243 | Set<? extends ResourceAllocation> lmd = caps.get(type); | 245 | Set<? extends ResourceAllocation> lmd = caps.get(type); | ... | ... |
| ... | @@ -30,6 +30,7 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -30,6 +30,7 @@ import org.apache.felix.scr.annotations.Deactivate; |
| 30 | import org.apache.felix.scr.annotations.Reference; | 30 | import org.apache.felix.scr.annotations.Reference; |
| 31 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 31 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 32 | import org.apache.felix.scr.annotations.Service; | 32 | import org.apache.felix.scr.annotations.Service; |
| 33 | +import org.onlab.util.Bandwidth; | ||
| 33 | import org.onlab.util.PositionalParameterStringFormatter; | 34 | import org.onlab.util.PositionalParameterStringFormatter; |
| 34 | import org.onosproject.net.AnnotationKeys; | 35 | import org.onosproject.net.AnnotationKeys; |
| 35 | import org.onosproject.net.Link; | 36 | import org.onosproject.net.Link; |
| ... | @@ -80,9 +81,9 @@ public class HazelcastLinkResourceStore | ... | @@ -80,9 +81,9 @@ public class HazelcastLinkResourceStore |
| 80 | 81 | ||
| 81 | private final Logger log = getLogger(getClass()); | 82 | private final Logger log = getLogger(getClass()); |
| 82 | 83 | ||
| 83 | - private static final BandwidthResource DEFAULT_BANDWIDTH = BandwidthResource.mbps(1_000); | 84 | + private static final BandwidthResource DEFAULT_BANDWIDTH = new BandwidthResource(Bandwidth.mbps(1_000)); |
| 84 | 85 | ||
| 85 | - private static final BandwidthResource EMPTY_BW = BandwidthResource.bps(0); | 86 | + private static final BandwidthResource EMPTY_BW = new BandwidthResource(Bandwidth.bps(0)); |
| 86 | 87 | ||
| 87 | // table to store current allocations | 88 | // table to store current allocations |
| 88 | /** LinkKey -> List<LinkResourceAllocations>. */ | 89 | /** LinkKey -> List<LinkResourceAllocations>. */ |
| ... | @@ -174,7 +175,7 @@ public class HazelcastLinkResourceStore | ... | @@ -174,7 +175,7 @@ public class HazelcastLinkResourceStore |
| 174 | String strBw = link.annotations().value(bandwidthAnnotation); | 175 | String strBw = link.annotations().value(bandwidthAnnotation); |
| 175 | if (strBw != null) { | 176 | if (strBw != null) { |
| 176 | try { | 177 | try { |
| 177 | - bandwidth = BandwidthResource.mbps(Double.parseDouble(strBw)); | 178 | + bandwidth = new BandwidthResource(Bandwidth.mbps(Double.parseDouble(strBw))); |
| 178 | } catch (NumberFormatException e) { | 179 | } catch (NumberFormatException e) { |
| 179 | // do nothings | 180 | // do nothings |
| 180 | bandwidth = null; | 181 | bandwidth = null; |
| ... | @@ -262,7 +263,8 @@ public class HazelcastLinkResourceStore | ... | @@ -262,7 +263,8 @@ public class HazelcastLinkResourceStore |
| 262 | } | 263 | } |
| 263 | } | 264 | } |
| 264 | 265 | ||
| 265 | - free.put(type, Sets.newHashSet(new BandwidthResourceAllocation(BandwidthResource.bps(freeBw)))); | 266 | + free.put(type, Sets.newHashSet( |
| 267 | + new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(freeBw))))); | ||
| 266 | break; | 268 | break; |
| 267 | } | 269 | } |
| 268 | 270 | ... | ... |
| ... | @@ -21,6 +21,7 @@ import java.util.Set; | ... | @@ -21,6 +21,7 @@ import java.util.Set; |
| 21 | import org.junit.After; | 21 | import org.junit.After; |
| 22 | import org.junit.Before; | 22 | import org.junit.Before; |
| 23 | import org.junit.Test; | 23 | import org.junit.Test; |
| 24 | +import org.onlab.util.Bandwidth; | ||
| 24 | import org.onosproject.net.AnnotationKeys; | 25 | import org.onosproject.net.AnnotationKeys; |
| 25 | import org.onosproject.net.Annotations; | 26 | import org.onosproject.net.Annotations; |
| 26 | import org.onosproject.net.ConnectPoint; | 27 | import org.onosproject.net.ConnectPoint; |
| ... | @@ -172,7 +173,7 @@ public class HazelcastLinkResourceStoreTest { | ... | @@ -172,7 +173,7 @@ public class HazelcastLinkResourceStoreTest { |
| 172 | final BandwidthResourceAllocation alloc = getBandwidthObj(freeRes); | 173 | final BandwidthResourceAllocation alloc = getBandwidthObj(freeRes); |
| 173 | assertNotNull(alloc); | 174 | assertNotNull(alloc); |
| 174 | 175 | ||
| 175 | - assertEquals(BandwidthResource.mbps(1000.0), alloc.bandwidth()); | 176 | + assertEquals(new BandwidthResource(Bandwidth.mbps(1000.0)), alloc.bandwidth()); |
| 176 | } | 177 | } |
| 177 | 178 | ||
| 178 | /** | 179 | /** |
| ... | @@ -209,7 +210,7 @@ public class HazelcastLinkResourceStoreTest { | ... | @@ -209,7 +210,7 @@ public class HazelcastLinkResourceStoreTest { |
| 209 | ImmutableSet.of(link)) | 210 | ImmutableSet.of(link)) |
| 210 | .build(); | 211 | .build(); |
| 211 | final ResourceAllocation allocation = | 212 | final ResourceAllocation allocation = |
| 212 | - new BandwidthResourceAllocation(BandwidthResource.mbps(900.0)); | 213 | + new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.mbps(900.0))); |
| 213 | final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation); | 214 | final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation); |
| 214 | 215 | ||
| 215 | final LinkResourceAllocations allocations = | 216 | final LinkResourceAllocations allocations = |
| ... | @@ -230,7 +231,7 @@ public class HazelcastLinkResourceStoreTest { | ... | @@ -230,7 +231,7 @@ public class HazelcastLinkResourceStoreTest { |
| 230 | ImmutableSet.of(link)) | 231 | ImmutableSet.of(link)) |
| 231 | .build(); | 232 | .build(); |
| 232 | final ResourceAllocation allocation = | 233 | final ResourceAllocation allocation = |
| 233 | - new BandwidthResourceAllocation(BandwidthResource.mbps(9000.0)); | 234 | + new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.mbps(9000.0))); |
| 234 | final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation); | 235 | final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation); |
| 235 | 236 | ||
| 236 | final LinkResourceAllocations allocations = | 237 | final LinkResourceAllocations allocations = |
| ... | @@ -258,7 +259,7 @@ public class HazelcastLinkResourceStoreTest { | ... | @@ -258,7 +259,7 @@ public class HazelcastLinkResourceStoreTest { |
| 258 | ImmutableSet.of(link)) | 259 | ImmutableSet.of(link)) |
| 259 | .build(); | 260 | .build(); |
| 260 | final ResourceAllocation allocation = | 261 | final ResourceAllocation allocation = |
| 261 | - new BandwidthResourceAllocation(BandwidthResource.mbps(900.0)); | 262 | + new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.mbps(900.0))); |
| 262 | final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation); | 263 | final Set<ResourceAllocation> allocationSet = ImmutableSet.of(allocation); |
| 263 | 264 | ||
| 264 | final LinkResourceAllocations allocations = | 265 | final LinkResourceAllocations allocations = | ... | ... |
| ... | @@ -355,7 +355,7 @@ public class KryoSerializerTest { | ... | @@ -355,7 +355,7 @@ public class KryoSerializerTest { |
| 355 | .build(); | 355 | .build(); |
| 356 | Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>(); | 356 | Map<Link, Set<ResourceAllocation>> allocations = new HashMap<>(); |
| 357 | allocations.put(new DefaultLink(PID, CP1, CP2, Type.DIRECT), | 357 | allocations.put(new DefaultLink(PID, CP1, CP2, Type.DIRECT), |
| 358 | - ImmutableSet.of(new BandwidthResourceAllocation(BandwidthResource.bps(10.0)), | 358 | + ImmutableSet.of(new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(10.0))), |
| 359 | new LambdaResourceAllocation(LambdaResource.valueOf(1)))); | 359 | new LambdaResourceAllocation(LambdaResource.valueOf(1)))); |
| 360 | testSerializable(new DefaultLinkResourceAllocations(request, allocations)); | 360 | testSerializable(new DefaultLinkResourceAllocations(request, allocations)); |
| 361 | } | 361 | } |
| ... | @@ -378,7 +378,7 @@ public class KryoSerializerTest { | ... | @@ -378,7 +378,7 @@ public class KryoSerializerTest { |
| 378 | 378 | ||
| 379 | @Test | 379 | @Test |
| 380 | public void testBandwidthConstraint() { | 380 | public void testBandwidthConstraint() { |
| 381 | - testSerializable(new BandwidthConstraint(BandwidthResource.bps(1000.0))); | 381 | + testSerializable(new BandwidthConstraint(new BandwidthResource(Bandwidth.bps(1000.0)))); |
| 382 | } | 382 | } |
| 383 | 383 | ||
| 384 | @Test | 384 | @Test | ... | ... |
| ... | @@ -26,6 +26,7 @@ import org.apache.felix.scr.annotations.Activate; | ... | @@ -26,6 +26,7 @@ import org.apache.felix.scr.annotations.Activate; |
| 26 | import org.apache.felix.scr.annotations.Component; | 26 | import org.apache.felix.scr.annotations.Component; |
| 27 | import org.apache.felix.scr.annotations.Deactivate; | 27 | import org.apache.felix.scr.annotations.Deactivate; |
| 28 | import org.apache.felix.scr.annotations.Service; | 28 | import org.apache.felix.scr.annotations.Service; |
| 29 | +import org.onlab.util.Bandwidth; | ||
| 29 | import org.onlab.util.PositionalParameterStringFormatter; | 30 | import org.onlab.util.PositionalParameterStringFormatter; |
| 30 | import org.onosproject.net.AnnotationKeys; | 31 | import org.onosproject.net.AnnotationKeys; |
| 31 | import org.onosproject.net.Annotations; | 32 | import org.onosproject.net.Annotations; |
| ... | @@ -55,7 +56,7 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -55,7 +56,7 @@ import static org.slf4j.LoggerFactory.getLogger; |
| 55 | @Component(immediate = true) | 56 | @Component(immediate = true) |
| 56 | @Service | 57 | @Service |
| 57 | public class SimpleLinkResourceStore implements LinkResourceStore { | 58 | public class SimpleLinkResourceStore implements LinkResourceStore { |
| 58 | - private static final BandwidthResource DEFAULT_BANDWIDTH = BandwidthResource.mbps(1_000); | 59 | + private static final BandwidthResource DEFAULT_BANDWIDTH = new BandwidthResource(Bandwidth.mbps(1_000)); |
| 59 | private final Logger log = getLogger(getClass()); | 60 | private final Logger log = getLogger(getClass()); |
| 60 | 61 | ||
| 61 | private Map<IntentId, LinkResourceAllocations> linkResourceAllocationsMap; | 62 | private Map<IntentId, LinkResourceAllocations> linkResourceAllocationsMap; |
| ... | @@ -98,7 +99,8 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -98,7 +99,8 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
| 98 | 99 | ||
| 99 | BandwidthResource bandwidth = DEFAULT_BANDWIDTH; | 100 | BandwidthResource bandwidth = DEFAULT_BANDWIDTH; |
| 100 | try { | 101 | try { |
| 101 | - bandwidth = BandwidthResource.mbps((Double.parseDouble(annotations.value(AnnotationKeys.BANDWIDTH)))); | 102 | + bandwidth = new BandwidthResource( |
| 103 | + Bandwidth.mbps((Double.parseDouble(annotations.value(AnnotationKeys.BANDWIDTH))))); | ||
| 102 | } catch (NumberFormatException e) { | 104 | } catch (NumberFormatException e) { |
| 103 | log.debug("No bandwidth annotation on link %s", link); | 105 | log.debug("No bandwidth annotation on link %s", link); |
| 104 | } | 106 | } |
| ... | @@ -123,7 +125,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -123,7 +125,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
| 123 | return (BandwidthResourceAllocation) res; | 125 | return (BandwidthResourceAllocation) res; |
| 124 | } | 126 | } |
| 125 | } | 127 | } |
| 126 | - return new BandwidthResourceAllocation(BandwidthResource.bps(0)); | 128 | + return new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(0))); |
| 127 | } | 129 | } |
| 128 | 130 | ||
| 129 | /** | 131 | /** |
| ... | @@ -156,7 +158,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -156,7 +158,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
| 156 | } | 158 | } |
| 157 | freeRes.remove(ba); | 159 | freeRes.remove(ba); |
| 158 | freeRes.add(new BandwidthResourceAllocation( | 160 | freeRes.add(new BandwidthResourceAllocation( |
| 159 | - BandwidthResource.bps(newBandwidth))); | 161 | + new BandwidthResource(Bandwidth.bps(newBandwidth)))); |
| 160 | break; | 162 | break; |
| 161 | case LAMBDA: | 163 | case LAMBDA: |
| 162 | final boolean lambdaAvailable = freeRes.remove(res); | 164 | final boolean lambdaAvailable = freeRes.remove(res); |
| ... | @@ -198,7 +200,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -198,7 +200,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
| 198 | double newBandwidth = ba.bandwidth().toDouble() + requestedBandwidth; | 200 | double newBandwidth = ba.bandwidth().toDouble() + requestedBandwidth; |
| 199 | freeRes.remove(ba); | 201 | freeRes.remove(ba); |
| 200 | freeRes.add(new BandwidthResourceAllocation( | 202 | freeRes.add(new BandwidthResourceAllocation( |
| 201 | - BandwidthResource.bps(newBandwidth))); | 203 | + new BandwidthResource(Bandwidth.bps(newBandwidth)))); |
| 202 | break; | 204 | break; |
| 203 | case LAMBDA: | 205 | case LAMBDA: |
| 204 | checkState(freeRes.add(res)); | 206 | checkState(freeRes.add(res)); | ... | ... |
core/store/trivial/src/test/java/org/onosproject/store/trivial/impl/SimpleLinkResourceStoreTest.java
| ... | @@ -22,6 +22,7 @@ import java.util.Set; | ... | @@ -22,6 +22,7 @@ import java.util.Set; |
| 22 | import org.junit.After; | 22 | import org.junit.After; |
| 23 | import org.junit.Before; | 23 | import org.junit.Before; |
| 24 | import org.junit.Test; | 24 | import org.junit.Test; |
| 25 | +import org.onlab.util.Bandwidth; | ||
| 25 | import org.onosproject.net.AnnotationKeys; | 26 | import org.onosproject.net.AnnotationKeys; |
| 26 | import org.onosproject.net.Annotations; | 27 | import org.onosproject.net.Annotations; |
| 27 | import org.onosproject.net.ConnectPoint; | 28 | import org.onosproject.net.ConnectPoint; |
| ... | @@ -159,7 +160,7 @@ public class SimpleLinkResourceStoreTest { | ... | @@ -159,7 +160,7 @@ public class SimpleLinkResourceStoreTest { |
| 159 | final BandwidthResourceAllocation alloc = getBandwidthObj(freeRes); | 160 | final BandwidthResourceAllocation alloc = getBandwidthObj(freeRes); |
| 160 | assertNotNull(alloc); | 161 | assertNotNull(alloc); |
| 161 | 162 | ||
| 162 | - assertEquals(BandwidthResource.mbps(1000.0), alloc.bandwidth()); | 163 | + assertEquals(new BandwidthResource(Bandwidth.mbps(1000.0)), alloc.bandwidth()); |
| 163 | } | 164 | } |
| 164 | 165 | ||
| 165 | /** | 166 | /** |
| ... | @@ -184,7 +185,7 @@ public class SimpleLinkResourceStoreTest { | ... | @@ -184,7 +185,7 @@ public class SimpleLinkResourceStoreTest { |
| 184 | @Override | 185 | @Override |
| 185 | public Set<ResourceAllocation> getResourceAllocation(Link link) { | 186 | public Set<ResourceAllocation> getResourceAllocation(Link link) { |
| 186 | final ResourceAllocation allocation = | 187 | final ResourceAllocation allocation = |
| 187 | - new BandwidthResourceAllocation(BandwidthResource.bps(allocationAmount)); | 188 | + new BandwidthResourceAllocation(new BandwidthResource(Bandwidth.bps(allocationAmount))); |
| 188 | final Set<ResourceAllocation> allocations = new HashSet<>(); | 189 | final Set<ResourceAllocation> allocations = new HashSet<>(); |
| 189 | allocations.add(allocation); | 190 | allocations.add(allocation); |
| 190 | return allocations; | 191 | return allocations; | ... | ... |
-
Please register or login to post a comment