Sho SHIMIZU
Committed by Gerrit Code Review

Remove LambdaConstraint as IndexLambda is soon removed

Change-Id: I1b0a2b3e09d87bb2b8cf39136de15d0f3368f589
......@@ -27,7 +27,6 @@ import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.EncapsulationType;
import org.onosproject.net.Link;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
......@@ -38,8 +37,6 @@ import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.intent.constraint.EncapsulationConstraint;
import org.onosproject.net.intent.constraint.LambdaConstraint;
import org.onosproject.net.intent.constraint.LinkTypeConstraint;
import org.onosproject.net.intent.constraint.PartialFailureConstraint;
import java.util.LinkedList;
......@@ -171,10 +168,6 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
required = false, multiValued = false)
private String bandwidthString = null;
@Option(name = "-l", aliases = "--lambda", description = "Lambda",
required = false, multiValued = false)
private boolean lambda = false;
@Option(name = "--partial", description = "Allow partial installation",
required = false, multiValued = false)
private boolean partial = false;
......@@ -381,12 +374,6 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
constraints.add(new BandwidthConstraint(bandwidth));
}
// Check for a lambda specification
if (lambda) {
constraints.add(new LambdaConstraint(null));
}
constraints.add(new LinkTypeConstraint(lambda, Link.Type.OPTICAL));
// Check for partial failure specification
if (partial) {
constraints.add(new PartialFailureConstraint());
......
/*
* Copyright 2014 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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.LinkResourceService;
import org.onosproject.net.resource.ResourceRequest;
import org.onosproject.net.resource.ResourceType;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Constraint that evaluates links based on available lambda.
*/
@Beta
public class LambdaConstraint extends BooleanConstraint {
private final IndexedLambda lambda;
/**
* Creates a new optical lambda constraint.
*
* @param lambda optional lambda to indicate a specific lambda
*/
public LambdaConstraint(IndexedLambda lambda) {
this.lambda = lambda;
}
// Constructor for serialization
private LambdaConstraint() {
this.lambda = null;
}
@Override
public boolean isValid(Link link, LinkResourceService resourceService) {
for (ResourceRequest request : resourceService.getAvailableResources(link)) {
if (request.type() == ResourceType.LAMBDA) {
return true;
}
}
return false;
}
/**
* Returns the lambda required by this constraint.
*
* @return required lambda
*/
public IndexedLambda lambda() {
return lambda;
}
@Override
public int hashCode() {
return Objects.hashCode(lambda);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final LambdaConstraint other = (LambdaConstraint) obj;
return Objects.equals(this.lambda, other.lambda);
}
@Override
public String toString() {
return toStringHelper(this).add("lambda", lambda).toString();
}
}
......@@ -31,7 +31,6 @@ import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.intent.constraint.LambdaConstraint;
import org.onosproject.net.resource.ResourceRequest;
import org.onosproject.net.resource.ResourceType;
......@@ -197,9 +196,7 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest {
@Override
public LinkResourceRequest.Builder addConstraint(Constraint constraint) {
if (constraint instanceof LambdaConstraint) {
return addLambdaRequest();
} else if (constraint instanceof BandwidthConstraint) {
if (constraint instanceof BandwidthConstraint) {
BandwidthConstraint bw = (BandwidthConstraint) constraint;
return addBandwidthRequest(bw.bandwidth().bps());
}
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.net.intent;
import java.time.Duration;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
......@@ -22,20 +23,19 @@ 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 com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import org.onosproject.net.intent.constraint.LatencyConstraint;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
import static org.onosproject.net.NetTestTools.APP_ID;
import static org.onosproject.net.NetTestTools.link;
......@@ -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(new IndexedLambda(23)));
constraints.add(new LatencyConstraint(Duration.ofMillis(100)));
final LinkCollectionIntent collectionIntent =
LinkCollectionIntent.builder()
.appId(APP_ID)
......@@ -155,7 +155,7 @@ public class LinkCollectionIntentTest extends IntentTest {
final List<Constraint> createdConstraints = collectionIntent.constraints();
assertThat(createdConstraints, hasSize(1));
assertThat(createdConstraints.get(0).toString(), startsWith("LambdaConstraint"));
assertThat(createdConstraints.get(0), instanceOf(LatencyConstraint.class));
}
/**
......
......@@ -17,7 +17,6 @@ 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 com.google.common.testing.EqualsTester;
......@@ -63,36 +62,6 @@ public class ConstraintObjectsTest {
.testEquals();
}
// Lambda Constraint
final LambdaConstraint lambdaConstraint1 =
new LambdaConstraint(new IndexedLambda(100));
final LambdaConstraint lambdaConstraintSameAs1 =
new LambdaConstraint(new IndexedLambda(100));
final LambdaConstraint lambdaConstraint2 =
new LambdaConstraint(new IndexedLambda(200));
/**
* Checks that the objects were created properly.
*/
@Test
public void testLambdaConstraintCreation() {
assertThat(lambdaConstraint1.lambda().index(), is(equalTo(100L)));
assertThat(lambdaConstraintSameAs1.lambda().index(), is(equalTo(100L)));
assertThat(lambdaConstraint2.lambda().index(), is(equalTo(200L)));
}
/**
* Checks the correctness of the equals() method.
*/
@Test
public void testLambdaConstraintEquals() {
new EqualsTester()
.addEqualityGroup(lambdaConstraint1, lambdaConstraintSameAs1)
.addEqualityGroup(lambdaConstraint2)
.testEquals();
}
// LinkType Constraint
final LinkTypeConstraint linkTypeConstraint1 =
......
......@@ -21,13 +21,11 @@ import java.util.stream.IntStream;
import org.onlab.util.Bandwidth;
import org.onosproject.net.DeviceId;
import org.onosproject.net.IndexedLambda;
import org.onosproject.net.Link;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.constraint.AnnotationConstraint;
import org.onosproject.net.intent.constraint.AsymmetricPathConstraint;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.intent.constraint.LambdaConstraint;
import org.onosproject.net.intent.constraint.LatencyConstraint;
import org.onosproject.net.intent.constraint.LinkTypeConstraint;
import org.onosproject.net.intent.constraint.ObstacleConstraint;
......@@ -95,19 +93,6 @@ public final class DecodeConstraintCodecHelper {
}
/**
* Decodes a lambda constraint.
*
* @return lambda constraint object.
*/
private Constraint decodeLambdaConstraint() {
long lambda = nullIsIllegal(json.get(ConstraintCodec.LAMBDA),
ConstraintCodec.LAMBDA + ConstraintCodec.MISSING_MEMBER_MESSAGE)
.asLong();
return new LambdaConstraint(new IndexedLambda(lambda));
}
/**
* Decodes a latency constraint.
*
* @return latency constraint object.
......@@ -198,8 +183,6 @@ public final class DecodeConstraintCodecHelper {
if (type.equals(BandwidthConstraint.class.getSimpleName())) {
return decodeBandwidthConstraint();
} else if (type.equals(LambdaConstraint.class.getSimpleName())) {
return decodeLambdaConstraint();
} else if (type.equals(LinkTypeConstraint.class.getSimpleName())) {
return decodeLinkTypeConstraint();
} else if (type.equals(AnnotationConstraint.class.getSimpleName())) {
......
......@@ -21,7 +21,6 @@ import org.onosproject.net.Link;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.constraint.AnnotationConstraint;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.intent.constraint.LambdaConstraint;
import org.onosproject.net.intent.constraint.LatencyConstraint;
import org.onosproject.net.intent.constraint.LinkTypeConstraint;
import org.onosproject.net.intent.constraint.ObstacleConstraint;
......@@ -132,20 +131,6 @@ public final class EncodeConstraintCodecHelper {
}
/**
* Encodes a lambda constraint.
*
* @return JSON ObjectNode representing the constraint
*/
private ObjectNode encodeLambdaConstraint() {
checkNotNull(constraint, "Lambda constraint cannot be null");
final LambdaConstraint lambdaConstraint =
(LambdaConstraint) constraint;
return context.mapper().createObjectNode()
.put("lambda", lambdaConstraint.lambda().index());
}
/**
* Encodes a link type constraint.
*
* @return JSON ObjectNode representing the constraint
......@@ -179,8 +164,6 @@ public final class EncodeConstraintCodecHelper {
final ObjectNode result;
if (constraint instanceof BandwidthConstraint) {
result = encodeBandwidthConstraint();
} else if (constraint instanceof LambdaConstraint) {
result = encodeLambdaConstraint();
} else if (constraint instanceof LinkTypeConstraint) {
result = encodeLinkTypeConstraint();
} else if (constraint instanceof AnnotationConstraint) {
......
......@@ -28,7 +28,6 @@ import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.constraint.AnnotationConstraint;
import org.onosproject.net.intent.constraint.AsymmetricPathConstraint;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.intent.constraint.LambdaConstraint;
import org.onosproject.net.intent.constraint.LatencyConstraint;
import org.onosproject.net.intent.constraint.LinkTypeConstraint;
import org.onosproject.net.intent.constraint.ObstacleConstraint;
......@@ -138,18 +137,6 @@ public class ConstraintCodecTest {
}
/**
* Tests lambda constraint.
*/
@Test
public void lambdaConstraint() {
Constraint constraint = getConstraint("LambdaConstraint.json");
assertThat(constraint, instanceOf(LambdaConstraint.class));
LambdaConstraint lambdaConstraint = (LambdaConstraint) constraint;
assertThat(lambdaConstraint.lambda().index(), is(444L));
}
/**
* Tests latency constraint.
*/
@Test
......
......@@ -59,7 +59,6 @@ import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.constraint.AnnotationConstraint;
import org.onosproject.net.intent.constraint.AsymmetricPathConstraint;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
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;
......@@ -180,7 +179,6 @@ public class IntentCodecTest extends AbstractIntentTest {
final List<Constraint> constraints =
ImmutableList.of(
new BandwidthConstraint(Bandwidth.bps(1.0)),
new LambdaConstraint(new IndexedLambda(3)),
new AnnotationConstraint("key", 33.0),
new AsymmetricPathConstraint(),
new LatencyConstraint(Duration.ofSeconds(2)),
......
......@@ -35,7 +35,6 @@ import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.constraint.AnnotationConstraint;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.intent.constraint.LambdaConstraint;
import org.onosproject.net.intent.constraint.LatencyConstraint;
import org.onosproject.net.intent.constraint.LinkTypeConstraint;
import org.onosproject.net.intent.constraint.ObstacleConstraint;
......@@ -145,22 +144,6 @@ public final class IntentJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode>
}
/**
* Matches a lamdba constraint against a JSON representation of the
* constraint.
*
* @param lambdaConstraint constraint object to match
* @param constraintJson JSON representation of the constraint
* @return true if the constraint and JSON match, false otherwise.
*/
private boolean matchLambdaConstraint(LambdaConstraint lambdaConstraint,
JsonNode constraintJson) {
final JsonNode lambdaJson = constraintJson.get("lambda");
return lambdaJson != null
&& constraintJson.get("lambda").asInt()
== lambdaConstraint.lambda().index();
}
/**
* Matches a link type constraint against a JSON representation of the
* constraint.
*
......@@ -307,9 +290,6 @@ public final class IntentJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode>
if (constraint instanceof BandwidthConstraint) {
return matchBandwidthConstraint((BandwidthConstraint) constraint,
constraintJson);
} else if (constraint instanceof LambdaConstraint) {
return matchLambdaConstraint((LambdaConstraint) constraint,
constraintJson);
} else if (constraint instanceof LinkTypeConstraint) {
return matchLinkTypeConstraint((LinkTypeConstraint) constraint,
constraintJson);
......
......@@ -21,7 +21,6 @@ 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;
......@@ -33,7 +32,6 @@ import org.onosproject.net.intent.IntentTestsMocks;
import org.onosproject.net.intent.PathIntent;
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.LinkResourceService;
......@@ -266,54 +264,4 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
assertThat(noPath.getMessage(), containsString("No path"));
}
}
/**
* Tests that requests for available lambdas are successful.
*/
@Test
public void testLambdaConstrainedIntentSuccess() {
final List<Constraint> constraints =
Collections.singletonList(new LambdaConstraint(new IndexedLambda(1)));
final LinkResourceService resourceService =
IntentTestsMocks.MockResourceService.makeLambdaResourceService(1);
final PointToPointIntent intent = makeIntent("s1", "s3", constraints);
String[] hops = {"s1", "s2", "s3"};
final PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
final List<Intent> compiledIntents =
compiler.compile(intent, null, null);
assertThat(compiledIntents, Matchers.notNullValue());
assertThat(compiledIntents, hasSize(1));
}
/**
* Tests that requests for lambdas when there are no available lambdas
* fail.
*/
@Test
public void testLambdaConstrainedIntentFailure() {
final List<Constraint> constraints =
Collections.singletonList(new LambdaConstraint(new IndexedLambda(1)));
final LinkResourceService resourceService =
IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0);
try {
final PointToPointIntent intent = makeIntent("s1", "s3", constraints);
String[] hops = {"s1", "s2", "s3"};
final PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
compiler.compile(intent, null, null);
fail("Point to Point compilation with no available lambda does "
+ "not throw exception.");
} catch (PathNotFoundException noPath) {
assertThat(noPath.getMessage(), containsString("No path"));
}
}
}
......
......@@ -172,7 +172,6 @@ import org.onosproject.net.intent.SinglePointToMultiPointIntent;
import org.onosproject.net.intent.constraint.AnnotationConstraint;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.intent.constraint.BooleanConstraint;
import org.onosproject.net.intent.constraint.LambdaConstraint;
import org.onosproject.net.intent.constraint.LatencyConstraint;
import org.onosproject.net.intent.constraint.LinkTypeConstraint;
import org.onosproject.net.intent.constraint.ObstacleConstraint;
......@@ -454,7 +453,6 @@ public final class KryoNamespaces {
ContinuousResourceId.class,
ResourceAllocation.class,
// Constraints
LambdaConstraint.class,
BandwidthConstraint.class,
LinkTypeConstraint.class,
LatencyConstraint.class,
......
......@@ -44,7 +44,6 @@ 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;
......@@ -76,7 +75,6 @@ import org.onosproject.net.resource.link.LinkResourceRequest;
import org.onosproject.net.resource.ResourceAllocation;
import org.onosproject.net.intent.constraint.AnnotationConstraint;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.intent.constraint.LambdaConstraint;
import org.onosproject.net.intent.constraint.LatencyConstraint;
import org.onosproject.net.intent.constraint.LinkTypeConstraint;
import org.onosproject.net.intent.constraint.ObstacleConstraint;
......@@ -422,11 +420,6 @@ public class KryoSerializerTest {
}
@Test
public void testLambdaConstraint() {
testSerializable(new LambdaConstraint(new IndexedLambda(1)));
}
@Test
public void testBandwidthConstraint() {
testSerializable(new BandwidthConstraint(Bandwidth.bps(1000.0)));
}
......