Avoid double wrap of Bandwidth class
Change-Id: I6bb95beafd55364499df64429c0788153a0b1624
diff --git a/core/api/src/main/java/org/onosproject/net/intent/constraint/BandwidthConstraint.java b/core/api/src/main/java/org/onosproject/net/intent/constraint/BandwidthConstraint.java
index 444feee..1b4a260 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/constraint/BandwidthConstraint.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/constraint/BandwidthConstraint.java
@@ -17,9 +17,9 @@
import com.google.common.annotations.Beta;
+import org.onlab.util.Bandwidth;
import org.onlab.util.DataRateUnit;
import org.onosproject.net.Link;
-import org.onosproject.net.resource.link.BandwidthResource;
import org.onosproject.net.resource.link.BandwidthResourceRequest;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.resource.ResourceRequest;
@@ -36,14 +36,14 @@
@Beta
public final class BandwidthConstraint extends BooleanConstraint {
- private final BandwidthResource bandwidth;
+ private final Bandwidth bandwidth;
/**
* Creates a new bandwidth constraint.
*
* @param bandwidth required bandwidth
*/
- public BandwidthConstraint(BandwidthResource bandwidth) {
+ public BandwidthConstraint(Bandwidth bandwidth) {
this.bandwidth = checkNotNull(bandwidth, "Bandwidth cannot be null");
}
@@ -55,7 +55,7 @@
* @return {@link BandwidthConstraint} instance with given bandwidth requirement
*/
public static BandwidthConstraint of(double v, DataRateUnit unit) {
- return new BandwidthConstraint(BandwidthResource.of(v, unit));
+ return new BandwidthConstraint(Bandwidth.of(v, unit));
}
// Constructor for serialization
@@ -68,7 +68,7 @@
for (ResourceRequest request : resourceService.getAvailableResources(link)) {
if (request.type() == ResourceType.BANDWIDTH) {
BandwidthResourceRequest brr = (BandwidthResourceRequest) request;
- if (brr.bandwidth().toDouble() >= bandwidth.toDouble()) {
+ if (brr.bandwidth().toDouble() >= bandwidth.bps()) {
return true;
}
}
@@ -81,7 +81,7 @@
*
* @return required bandwidth
*/
- public BandwidthResource bandwidth() {
+ public Bandwidth bandwidth() {
return bandwidth;
}
diff --git a/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceRequest.java b/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceRequest.java
index b57465f..583570f 100644
--- a/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceRequest.java
+++ b/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceRequest.java
@@ -201,7 +201,7 @@
return addLambdaRequest();
} else if (constraint instanceof BandwidthConstraint) {
BandwidthConstraint bw = (BandwidthConstraint) constraint;
- return addBandwidthRequest(bw.bandwidth().toDouble());
+ return addBandwidthRequest(bw.bandwidth().bps());
}
return this;
}
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 743fc252..4f86add 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
@@ -18,7 +18,6 @@
import org.junit.Test;
import org.onlab.util.Bandwidth;
import org.onosproject.net.Link;
-import org.onosproject.net.resource.link.BandwidthResource;
import org.onosproject.net.resource.link.LambdaResource;
import com.google.common.testing.EqualsTester;
@@ -39,21 +38,18 @@
private final Bandwidth sameAsBandwidth1 = Bandwidth.bps(100.0);
private final Bandwidth bandwidth2 = Bandwidth.bps(200.0);
- final BandwidthConstraint bandwidthConstraint1 =
- new BandwidthConstraint(new BandwidthResource(bandwidth1));
- final BandwidthConstraint bandwidthConstraintSameAs1 =
- new BandwidthConstraint(new BandwidthResource(sameAsBandwidth1));
- final BandwidthConstraint bandwidthConstraint2 =
- new BandwidthConstraint(new BandwidthResource(bandwidth2));
+ final BandwidthConstraint bandwidthConstraint1 = new BandwidthConstraint(bandwidth1);
+ final BandwidthConstraint bandwidthConstraintSameAs1 = new BandwidthConstraint(sameAsBandwidth1);
+ final BandwidthConstraint bandwidthConstraint2 = new BandwidthConstraint(bandwidth2);
/**
* Checks that the objects were created properly.
*/
@Test
public void testBandwidthConstraintCreation() {
- assertThat(bandwidthConstraint1.bandwidth().toDouble(), is(equalTo(100.0)));
- assertThat(bandwidthConstraintSameAs1.bandwidth().toDouble(), is(equalTo(100.0)));
- assertThat(bandwidthConstraint2.bandwidth().toDouble(), is(equalTo(200.0)));
+ assertThat(bandwidthConstraint1.bandwidth().bps(), is(equalTo(100.0)));
+ assertThat(bandwidthConstraintSameAs1.bandwidth().bps(), is(equalTo(100.0)));
+ assertThat(bandwidthConstraint2.bandwidth().bps(), is(equalTo(200.0)));
}
/**