Sho SHIMIZU
Committed by Gerrit Code Review

Avoid double wrap of IndexedLambda

Change-Id: I2acaa255529949e8443542904df465e6b0fbb72a
......@@ -16,8 +16,8 @@
package org.onosproject.net.intent.constraint;
import com.google.common.annotations.Beta;
import org.onosproject.net.IndexedLambda;
import org.onosproject.net.Link;
import org.onosproject.net.resource.link.LambdaResource;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.resource.ResourceRequest;
import org.onosproject.net.resource.ResourceType;
......@@ -32,14 +32,14 @@ import static com.google.common.base.MoreObjects.toStringHelper;
@Beta
public class LambdaConstraint extends BooleanConstraint {
private final LambdaResource lambda;
private final IndexedLambda lambda;
/**
* Creates a new optical lambda constraint.
*
* @param lambda optional lambda to indicate a specific lambda
*/
public LambdaConstraint(LambdaResource lambda) {
public LambdaConstraint(IndexedLambda lambda) {
this.lambda = lambda;
}
......@@ -63,7 +63,7 @@ public class LambdaConstraint extends BooleanConstraint {
*
* @return required lambda
*/
public LambdaResource lambda() {
public IndexedLambda lambda() {
return lambda;
}
......
......@@ -22,11 +22,11 @@ import java.util.Set;
import org.junit.Test;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.IndexedLambda;
import org.onosproject.net.Link;
import org.onosproject.net.NetTestTools;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.intent.constraint.LambdaConstraint;
import org.onosproject.net.resource.link.LambdaResource;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
......@@ -132,7 +132,7 @@ public class LinkCollectionIntentTest extends IntentTest {
final LinkedList<Constraint> constraints = new LinkedList<>();
links1.add(link("src", 1, "dst", 2));
constraints.add(new LambdaConstraint(LambdaResource.valueOf(23)));
constraints.add(new LambdaConstraint(new IndexedLambda(23)));
final LinkCollectionIntent collectionIntent =
LinkCollectionIntent.builder()
.appId(APP_ID)
......
......@@ -17,8 +17,8 @@ package org.onosproject.net.intent.constraint;
import org.junit.Test;
import org.onlab.util.Bandwidth;
import org.onosproject.net.IndexedLambda;
import org.onosproject.net.Link;
import org.onosproject.net.resource.link.LambdaResource;
import com.google.common.testing.EqualsTester;
......@@ -66,20 +66,20 @@ public class ConstraintObjectsTest {
// Lambda Constraint
final LambdaConstraint lambdaConstraint1 =
new LambdaConstraint(LambdaResource.valueOf(100));
new LambdaConstraint(new IndexedLambda(100));
final LambdaConstraint lambdaConstraintSameAs1 =
new LambdaConstraint(LambdaResource.valueOf(100));
new LambdaConstraint(new IndexedLambda(100));
final LambdaConstraint lambdaConstraint2 =
new LambdaConstraint(LambdaResource.valueOf(200));
new LambdaConstraint(new IndexedLambda(200));
/**
* Checks that the objects were created properly.
*/
@Test
public void testLambdaConstraintCreation() {
assertThat(lambdaConstraint1.lambda().toInt(), is(equalTo(100)));
assertThat(lambdaConstraintSameAs1.lambda().toInt(), is(equalTo(100)));
assertThat(lambdaConstraint2.lambda().toInt(), is(equalTo(200)));
assertThat(lambdaConstraint1.lambda().index(), is(equalTo(100L)));
assertThat(lambdaConstraintSameAs1.lambda().index(), is(equalTo(100L)));
assertThat(lambdaConstraint2.lambda().index(), is(equalTo(200L)));
}
/**
......
......@@ -32,7 +32,6 @@ import org.onosproject.net.intent.constraint.LatencyConstraint;
import org.onosproject.net.intent.constraint.LinkTypeConstraint;
import org.onosproject.net.intent.constraint.ObstacleConstraint;
import org.onosproject.net.intent.constraint.WaypointConstraint;
import org.onosproject.net.resource.link.LambdaResource;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
......@@ -105,7 +104,7 @@ public final class DecodeConstraintCodecHelper {
ConstraintCodec.LAMBDA + ConstraintCodec.MISSING_MEMBER_MESSAGE)
.asLong();
return new LambdaConstraint(LambdaResource.valueOf(new IndexedLambda(lambda)));
return new LambdaConstraint(new IndexedLambda(lambda));
}
/**
......
......@@ -142,7 +142,7 @@ public final class EncodeConstraintCodecHelper {
(LambdaConstraint) constraint;
return context.mapper().createObjectNode()
.put("lambda", lambdaConstraint.lambda().toInt());
.put("lambda", lambdaConstraint.lambda().index());
}
/**
......
......@@ -146,7 +146,7 @@ public class ConstraintCodecTest {
assertThat(constraint, instanceOf(LambdaConstraint.class));
LambdaConstraint lambdaConstraint = (LambdaConstraint) constraint;
assertThat(lambdaConstraint.lambda().toInt(), is(444));
assertThat(lambdaConstraint.lambda().index(), is(444L));
}
/**
......
......@@ -63,7 +63,6 @@ import org.onosproject.net.intent.constraint.LambdaConstraint;
import org.onosproject.net.intent.constraint.LatencyConstraint;
import org.onosproject.net.intent.constraint.ObstacleConstraint;
import org.onosproject.net.intent.constraint.WaypointConstraint;
import org.onosproject.net.resource.link.LambdaResource;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
......@@ -181,7 +180,7 @@ public class IntentCodecTest extends AbstractIntentTest {
final List<Constraint> constraints =
ImmutableList.of(
new BandwidthConstraint(Bandwidth.bps(1.0)),
new LambdaConstraint(LambdaResource.valueOf(3)),
new LambdaConstraint(new IndexedLambda(3)),
new AnnotationConstraint("key", 33.0),
new AsymmetricPathConstraint(),
new LatencyConstraint(Duration.ofSeconds(2)),
......
......@@ -157,7 +157,7 @@ public final class IntentJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode>
final JsonNode lambdaJson = constraintJson.get("lambda");
return lambdaJson != null
&& constraintJson.get("lambda").asInt()
== lambdaConstraint.lambda().toInt();
== lambdaConstraint.lambda().index();
}
/**
......
......@@ -21,6 +21,7 @@ import org.onlab.util.Bandwidth;
import org.onosproject.TestApplicationId;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.IndexedLambda;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import org.onosproject.net.flow.TrafficSelector;
......@@ -34,7 +35,6 @@ import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.intent.constraint.LambdaConstraint;
import org.onosproject.net.intent.impl.PathNotFoundException;
import org.onosproject.net.resource.link.LambdaResource;
import org.onosproject.net.resource.link.LinkResourceService;
import java.util.Collections;
......@@ -274,7 +274,7 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
public void testLambdaConstrainedIntentSuccess() {
final List<Constraint> constraints =
Collections.singletonList(new LambdaConstraint(LambdaResource.valueOf(1)));
Collections.singletonList(new LambdaConstraint(new IndexedLambda(1)));
final LinkResourceService resourceService =
IntentTestsMocks.MockResourceService.makeLambdaResourceService(1);
......@@ -298,7 +298,7 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
public void testLambdaConstrainedIntentFailure() {
final List<Constraint> constraints =
Collections.singletonList(new LambdaConstraint(LambdaResource.valueOf(1)));
Collections.singletonList(new LambdaConstraint(new IndexedLambda(1)));
final LinkResourceService resourceService =
IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0);
try {
......
......@@ -43,6 +43,7 @@ import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.GridType;
import org.onosproject.net.HostLocation;
import org.onosproject.net.IndexedLambda;
import org.onosproject.net.Link;
import org.onosproject.net.Link.Type;
import org.onosproject.net.LinkKey;
......@@ -395,7 +396,7 @@ public class KryoSerializerTest {
@Test
public void testLambdaConstraint() {
testSerializable(new LambdaConstraint(LambdaResource.valueOf(1)));
testSerializable(new LambdaConstraint(new IndexedLambda(1)));
}
@Test
......