Sho SHIMIZU
Committed by Thomas Vachuska

Remove dependency on LinkResourceService from Constraint

Change-Id: Ib9c488331b22eef6769a767c6186ef7d2e8b1501
Showing 20 changed files with 201 additions and 197 deletions
......@@ -18,7 +18,6 @@ package org.onosproject.net.intent;
import com.google.common.annotations.Beta;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import org.onosproject.net.resource.link.LinkResourceService;
/**
* Representation of a connectivity constraint capable of evaluating a link
......@@ -33,21 +32,19 @@ public interface Constraint {
/**
* Evaluates the specified link and provides the cost for its traversal.
*
* @param link link to be evaluated
* @param resourceService resource service for validating availability of
* link resources
* @param link link to be evaluated
* @param context resource context for validating availability of resources
* @return cost of link traversal
*/
double cost(Link link, LinkResourceService resourceService);
double cost(Link link, ResourceContext context);
/**
* Validates that the specified path satisfies the constraint.
*
* @param path path to be validated
* @param resourceService resource service for validating availability of
* link resources
* @param context resource context for validating availability of resources
* @return cost of link traversal
*/
boolean validate(Path path, LinkResourceService resourceService);
boolean validate(Path path, ResourceContext context);
}
......
/*
* Copyright 2016 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;
import com.google.common.annotations.Beta;
import org.onosproject.net.newresource.Resource;
/**
* Class providing resource information to constraints.
* This class is subject to be removed during refactorings on Constraint.
*/
@Beta
public interface ResourceContext {
/**
* Returns the availability of the specified resource.
*
* @param resource resource to check the availability
* @return true if available, otherwise false
*/
boolean isAvailable(Resource resource);
}
......@@ -18,7 +18,7 @@ package org.onosproject.net.intent.constraint;
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import org.onosproject.net.Link;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.intent.ResourceContext;
import java.util.Objects;
......@@ -68,16 +68,28 @@ public class AnnotationConstraint extends BooleanConstraint {
return threshold;
}
// doesn't use LinkResourceService
@Override
public boolean isValid(Link link, LinkResourceService resourceService) {
public boolean isValid(Link link, ResourceContext context) {
// explicitly call a method not depending on LinkResourceService
return isValid(link);
}
private boolean isValid(Link link) {
double value = getAnnotatedValue(link, key);
return value <= threshold;
}
// doesn't use LinkResourceService
@Override
public double cost(Link link, LinkResourceService resourceService) {
if (isValid(link, resourceService)) {
public double cost(Link link, ResourceContext context) {
// explicitly call a method not depending on LinkResourceService
return cost(link);
}
private double cost(Link link) {
if (isValid(link)) {
return getAnnotatedValue(link, key);
} else {
return -1;
......
......@@ -19,7 +19,7 @@ import com.google.common.annotations.Beta;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.intent.ResourceContext;
import java.util.Objects;
......@@ -31,13 +31,15 @@ import static com.google.common.base.MoreObjects.toStringHelper;
@Beta
public class AsymmetricPathConstraint implements Constraint {
// doesn't use LinkResourceService
@Override
public double cost(Link link, LinkResourceService resourceService) {
public double cost(Link link, ResourceContext context) {
return 1;
}
// doesn't use LinkResourceService
@Override
public boolean validate(Path path, LinkResourceService resourceService) {
public boolean validate(Path path, ResourceContext context) {
return true;
}
......
......@@ -20,12 +20,11 @@ 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.BandwidthResourceRequest;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.resource.ResourceRequest;
import org.onosproject.net.resource.ResourceType;
import org.onosproject.net.intent.ResourceContext;
import org.onosproject.net.newresource.Resources;
import java.util.Objects;
import java.util.stream.Stream;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
......@@ -64,16 +63,10 @@ public final class BandwidthConstraint extends BooleanConstraint {
}
@Override
public boolean isValid(Link link, LinkResourceService resourceService) {
for (ResourceRequest request : resourceService.getAvailableResources(link)) {
if (request.type() == ResourceType.BANDWIDTH) {
BandwidthResourceRequest brr = (BandwidthResourceRequest) request;
if (brr.bandwidth().toDouble() >= bandwidth.bps()) {
return true;
}
}
}
return false;
public boolean isValid(Link link, ResourceContext context) {
return Stream.of(link.src(), link.dst())
.map(cp -> Resources.continuous(cp.deviceId(), cp.port(), Bandwidth.class).resource(bandwidth.bps()))
.allMatch(context::isAvailable);
}
/**
......
......@@ -19,7 +19,7 @@ import com.google.common.annotations.Beta;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.intent.ResourceContext;
/**
* Abstract base class for various constraints that evaluate link viability
......@@ -32,10 +32,10 @@ public abstract class BooleanConstraint implements Constraint {
* Returns true if the specified link satisfies the constraint.
*
* @param link link to be validated
* @param resourceService resource service for checking available link resources
* @param context resource context for checking available resources
* @return true if link is viable
*/
public abstract boolean isValid(Link link, LinkResourceService resourceService);
public abstract boolean isValid(Link link, ResourceContext context);
/**
* {@inheritDoc}
......@@ -43,18 +43,18 @@ public abstract class BooleanConstraint implements Constraint {
* Negative return value means the specified link does not satisfy this constraint.
*
* @param link {@inheritDoc}
* @param resourceService {@inheritDoc}
* @param context {@inheritDoc}
* @return {@inheritDoc}
*/
@Override
public double cost(Link link, LinkResourceService resourceService) {
return isValid(link, resourceService) ? +1 : -1;
public double cost(Link link, ResourceContext context) {
return isValid(link, context) ? +1 : -1;
}
@Override
public boolean validate(Path path, LinkResourceService resourceService) {
public boolean validate(Path path, ResourceContext context) {
return path.links().stream()
.allMatch(link -> isValid(link, resourceService));
.allMatch(link -> isValid(link, context));
}
}
......
......@@ -19,7 +19,7 @@ package org.onosproject.net.intent.constraint;
import org.onosproject.net.EncapsulationType;
import org.onosproject.net.Link;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.intent.ResourceContext;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
......@@ -42,8 +42,9 @@ public class EncapsulationConstraint extends BooleanConstraint {
}
// doesn't use LinkResourceService
@Override
public boolean isValid(Link link, LinkResourceService resourceService) {
public boolean isValid(Link link, ResourceContext context) {
//TODO: validate the availability of the resources for each link in the path.
//e.g., availability of MPLSlabels, VLANID
......
......@@ -20,7 +20,7 @@ import com.google.common.base.MoreObjects;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.intent.ResourceContext;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
......@@ -54,14 +54,26 @@ public class LatencyConstraint implements Constraint {
return latency;
}
// doesn't use LinkResourceService
@Override
public double cost(Link link, LinkResourceService resourceService) {
public double cost(Link link, ResourceContext context) {
// explicitly call a method not depending on LinkResourceService
return cost(link);
}
private double cost(Link link) {
return getAnnotatedValue(link, LATENCY);
}
// doesn't use LinkResourceService
@Override
public boolean validate(Path path, LinkResourceService resourceService) {
double pathLatency = path.links().stream().mapToDouble(link -> cost(link, resourceService)).sum();
public boolean validate(Path path, ResourceContext context) {
// explicitly call a method not depending on LinkResourceService
return validate(path);
}
private boolean validate(Path path) {
double pathLatency = path.links().stream().mapToDouble(this::cost).sum();
return Duration.of((long) pathLatency, ChronoUnit.MICROS).compareTo(latency) <= 0;
}
......
......@@ -18,7 +18,7 @@ package org.onosproject.net.intent.constraint;
import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableSet;
import org.onosproject.net.Link;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.intent.ResourceContext;
import java.util.Objects;
import java.util.Set;
......@@ -57,8 +57,14 @@ public class LinkTypeConstraint extends BooleanConstraint {
this.isInclusive = false;
}
// doesn't use LinkResourceService
@Override
public boolean isValid(Link link, LinkResourceService resourceService) {
public boolean isValid(Link link, ResourceContext context) {
// explicitly call a method not depending on LinkResourceService
return isValid(link);
}
private boolean isValid(Link link) {
boolean contains = types.contains(link.type());
return isInclusive == contains;
}
......
......@@ -20,7 +20,7 @@ import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.intent.ResourceContext;
import java.util.Collections;
import java.util.Objects;
......@@ -56,8 +56,14 @@ public class ObstacleConstraint extends BooleanConstraint {
return obstacles;
}
// doesn't use LinkResourceService
@Override
public boolean isValid(Link link, LinkResourceService resourceService) {
public boolean isValid(Link link, ResourceContext context) {
// explicitly call a method not depending on LinkResourceService
return isValid(link);
}
private boolean isValid(Link link) {
DeviceId src = link.src().deviceId();
DeviceId dst = link.dst().deviceId();
......
......@@ -20,7 +20,7 @@ import org.onosproject.net.Path;
import org.onosproject.net.intent.ConnectivityIntent;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.intent.ResourceContext;
/**
* A constraint that allows intents that can only be partially compiled
......@@ -28,13 +28,15 @@ import org.onosproject.net.resource.link.LinkResourceService;
* to be installed when some endpoints or paths are not found.
*/
public class PartialFailureConstraint implements Constraint {
// doesn't use LinkResourceService
@Override
public double cost(Link link, LinkResourceService resourceService) {
public double cost(Link link, ResourceContext context) {
return 1;
}
// doesn't use LinkResourceService
@Override
public boolean validate(Path path, LinkResourceService resourceService) {
public boolean validate(Path path, ResourceContext context) {
return true;
}
......
......@@ -22,7 +22,7 @@ import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.intent.ResourceContext;
import java.util.Collections;
import java.util.LinkedList;
......@@ -60,14 +60,21 @@ public class WaypointConstraint implements Constraint {
return waypoints;
}
// doesn't use LinkResourceService
@Override
public double cost(Link link, LinkResourceService resourceService) {
public double cost(Link link, ResourceContext context) {
// Always consider the number of hops
return 1;
}
// doesn't use LinkResourceService
@Override
public boolean validate(Path path, LinkResourceService resourceService) {
public boolean validate(Path path, ResourceContext context) {
// explicitly call a method not depending on LinkResourceService
return validate(path);
}
private boolean validate(Path path) {
LinkedList<DeviceId> waypoints = new LinkedList<>(this.waypoints);
DeviceId current = waypoints.poll();
// This is safe because Path class ensures the number of links are more than 0
......
......@@ -16,7 +16,6 @@
package org.onosproject.net.intent;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
import org.onlab.util.Bandwidth;
import org.onosproject.core.DefaultGroupId;
import org.onosproject.core.GroupId;
......@@ -36,20 +35,13 @@ import org.onosproject.net.flow.criteria.Criterion.Type;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flow.instructions.Instructions;
import org.onosproject.net.flow.instructions.Instructions.MetadataInstruction;
import org.onosproject.net.resource.ResourceAllocation;
import org.onosproject.net.resource.ResourceRequest;
import org.onosproject.net.resource.ResourceType;
import org.onosproject.net.resource.link.BandwidthResource;
import org.onosproject.net.resource.link.BandwidthResourceRequest;
import org.onosproject.net.resource.link.LambdaResource;
import org.onosproject.net.resource.link.LambdaResourceAllocation;
import org.onosproject.net.resource.link.LambdaResourceRequest;
import org.onosproject.net.resource.link.LinkResourceAllocations;
import org.onosproject.net.resource.link.LinkResourceListener;
import org.onosproject.net.resource.link.LinkResourceRequest;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.resource.link.MplsLabel;
import org.onosproject.net.resource.link.MplsLabelResourceAllocation;
import org.onosproject.net.newresource.DiscreteResourceId;
import org.onosproject.net.newresource.Resource;
import org.onosproject.net.newresource.ResourceAllocation;
import org.onosproject.net.newresource.ResourceConsumer;
import org.onosproject.net.newresource.ResourceId;
import org.onosproject.net.newresource.ResourceListener;
import org.onosproject.net.newresource.ResourceService;
import org.onosproject.net.topology.DefaultTopologyEdge;
import org.onosproject.net.topology.DefaultTopologyVertex;
import org.onosproject.net.topology.LinkWeight;
......@@ -61,9 +53,9 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
......@@ -184,145 +176,84 @@ public class IntentTestsMocks {
}
}
public static class MockLinkResourceAllocations implements LinkResourceAllocations {
@Override
public Set<ResourceAllocation> getResourceAllocation(Link link) {
return ImmutableSet.of(
new LambdaResourceAllocation(LambdaResource.valueOf(77)),
new MplsLabelResourceAllocation(MplsLabel.valueOf(10)));
}
public static final class MockResourceService implements ResourceService {
@Override
public IntentId intentId() {
return null;
}
private final double bandwidth;
@Override
public Collection<Link> links() {
return null;
public static ResourceService makeBandwidthResourceService(double bandwidth) {
return new MockResourceService(bandwidth);
}
@Override
public Set<ResourceRequest> resources() {
return null;
private MockResourceService(double bandwidth) {
this.bandwidth = bandwidth;
}
@Override
public ResourceType type() {
public List<ResourceAllocation> allocate(ResourceConsumer consumer, List<Resource> resources) {
return null;
}
}
public static class MockedAllocationFailure extends RuntimeException { }
public static class MockResourceService implements LinkResourceService {
double availableBandwidth = -1.0;
int availableLambda = -1;
/**
* Allocates a resource service that will allow bandwidth allocations
* up to a limit.
*
* @param bandwidth available bandwidth limit
* @return resource manager for bandwidth requests
*/
public static MockResourceService makeBandwidthResourceService(double bandwidth) {
final MockResourceService result = new MockResourceService();
result.availableBandwidth = bandwidth;
return result;
}
/**
* Allocates a resource service that will allow lambda allocations.
*
* @param lambda Lambda to return for allocation requests. Currently unused
* @return resource manager for lambda requests
*/
public static MockResourceService makeLambdaResourceService(int lambda) {
final MockResourceService result = new MockResourceService();
result.availableLambda = lambda;
return result;
@Override
public boolean release(List<ResourceAllocation> allocations) {
return false;
}
@Override
public LinkResourceAllocations requestResources(LinkResourceRequest req) {
int lambda = -1;
double bandwidth = -1.0;
for (ResourceRequest resourceRequest : req.resources()) {
if (resourceRequest.type() == ResourceType.BANDWIDTH) {
final BandwidthResourceRequest brr = (BandwidthResourceRequest) resourceRequest;
bandwidth = brr.bandwidth().toDouble();
} else if (resourceRequest.type() == ResourceType.LAMBDA) {
lambda = 1;
}
}
if (availableBandwidth < bandwidth) {
throw new MockedAllocationFailure();
}
if (lambda > 0 && availableLambda == 0) {
throw new MockedAllocationFailure();
}
return new IntentTestsMocks.MockLinkResourceAllocations();
public boolean release(ResourceConsumer consumer) {
return false;
}
@Override
public void releaseResources(LinkResourceAllocations allocations) {
// Mock
public List<ResourceAllocation> getResourceAllocations(ResourceId id) {
return null;
}
@Override
public LinkResourceAllocations updateResources(LinkResourceRequest req,
LinkResourceAllocations oldAllocations) {
public <T> Collection<ResourceAllocation> getResourceAllocations(DiscreteResourceId parent, Class<T> cls) {
return null;
}
@Override
public Iterable<LinkResourceAllocations> getAllocations() {
return ImmutableSet.of(
new IntentTestsMocks.MockLinkResourceAllocations());
public Collection<ResourceAllocation> getResourceAllocations(ResourceConsumer consumer) {
return null;
}
@Override
public Iterable<LinkResourceAllocations> getAllocations(Link link) {
return ImmutableSet.of(
new IntentTestsMocks.MockLinkResourceAllocations());
public Set<Resource> getAvailableResources(DiscreteResourceId parent) {
return null;
}
@Override
public LinkResourceAllocations getAllocations(IntentId intentId) {
return new IntentTestsMocks.MockLinkResourceAllocations();
public <T> Set<Resource> getAvailableResources(DiscreteResourceId parent, Class<T> cls) {
return null;
}
@Override
public Iterable<ResourceRequest> getAvailableResources(Link link) {
final List<ResourceRequest> result = new LinkedList<>();
if (availableBandwidth > 0.0) {
result.add(new BandwidthResourceRequest(
new BandwidthResource(Bandwidth.bps(availableBandwidth))));
}
if (availableLambda > 0) {
result.add(new LambdaResourceRequest());
}
return result;
public <T> Set<T> getAvailableResourceValues(DiscreteResourceId parent, Class<T> cls) {
return null;
}
@Override
public Iterable<ResourceRequest> getAvailableResources(Link link, LinkResourceAllocations allocations) {
public Set<Resource> getRegisteredResources(DiscreteResourceId parent) {
return null;
}
@Override
public void addListener(LinkResourceListener listener) {
public boolean isAvailable(Resource resource) {
if (!resource.isTypeOf(Bandwidth.class)) {
return false;
}
Optional<Double> value = resource.valueAs(Double.class);
return value.filter(requested -> requested <= bandwidth).isPresent();
}
@Override
public void removeListener(LinkResourceListener listener) {
public void addListener(ResourceListener listener) {
}
@Override
public void removeListener(ResourceListener listener) {
}
}
......
......@@ -23,8 +23,8 @@ import org.onosproject.net.DefaultLink;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.PortNumber;
import org.onosproject.net.intent.ResourceContext;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.net.resource.link.LinkResourceService;
import static org.easymock.EasyMock.createMock;
import static org.hamcrest.Matchers.closeTo;
......@@ -51,11 +51,11 @@ public class AnnotationConstraintTest {
private AnnotationConstraint sut;
private Link link;
private LinkResourceService linkResourceService;
private ResourceContext resourceContext;
@Before
public void setUp() {
linkResourceService = createMock(LinkResourceService.class);
resourceContext = createMock(ResourceContext.class);
DefaultAnnotations annotations = DefaultAnnotations.builder().set(KEY, String.valueOf(VALUE)).build();
......@@ -75,8 +75,8 @@ public class AnnotationConstraintTest {
double value = 120;
sut = new AnnotationConstraint(KEY, value);
assertThat(sut.isValid(link, linkResourceService), is(true));
assertThat(sut.cost(link, linkResourceService), is(closeTo(VALUE, 1.0e-6)));
assertThat(sut.isValid(link, resourceContext), is(true));
assertThat(sut.cost(link, resourceContext), is(closeTo(VALUE, 1.0e-6)));
}
/**
......@@ -87,8 +87,8 @@ public class AnnotationConstraintTest {
double value = 80;
sut = new AnnotationConstraint(KEY, value);
assertThat(sut.isValid(link, linkResourceService), is(false));
assertThat(sut.cost(link, linkResourceService), is(lessThan(0.0)));
assertThat(sut.isValid(link, resourceContext), is(false));
assertThat(sut.cost(link, resourceContext), is(lessThan(0.0)));
}
@Test
......
......@@ -26,8 +26,8 @@ import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import org.onosproject.net.PortNumber;
import org.onosproject.net.intent.ResourceContext;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.net.resource.link.LinkResourceService;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
......@@ -56,7 +56,7 @@ public class LatencyConstraintTest {
private static final String LATENCY2 = "4.0";
private LatencyConstraint sut;
private LinkResourceService linkResourceService;
private ResourceContext resourceContext;
private Path path;
private Link link1;
......@@ -64,7 +64,7 @@ public class LatencyConstraintTest {
@Before
public void setUp() {
linkResourceService = createMock(LinkResourceService.class);
resourceContext = createMock(ResourceContext.class);
Annotations annotations1 = DefaultAnnotations.builder().set(LATENCY, LATENCY1).build();
Annotations annotations2 = DefaultAnnotations.builder().set(LATENCY, LATENCY2).build();
......@@ -93,7 +93,7 @@ public class LatencyConstraintTest {
public void testLessThanLatency() {
sut = new LatencyConstraint(Duration.of(10, ChronoUnit.MICROS));
assertThat(sut.validate(path, linkResourceService), is(true));
assertThat(sut.validate(path, resourceContext), is(true));
}
/**
......@@ -103,7 +103,7 @@ public class LatencyConstraintTest {
public void testMoreThanLatency() {
sut = new LatencyConstraint(Duration.of(3, ChronoUnit.MICROS));
assertThat(sut.validate(path, linkResourceService), is(false));
assertThat(sut.validate(path, resourceContext), is(false));
}
/**
......@@ -113,8 +113,8 @@ public class LatencyConstraintTest {
public void testCost() {
sut = new LatencyConstraint(Duration.of(10, ChronoUnit.MICROS));
assertThat(sut.cost(link1, linkResourceService), is(closeTo(Double.parseDouble(LATENCY1), 1.0e-6)));
assertThat(sut.cost(link2, linkResourceService), is(closeTo(Double.parseDouble(LATENCY2), 1.0e-6)));
assertThat(sut.cost(link1, resourceContext), is(closeTo(Double.parseDouble(LATENCY1), 1.0e-6)));
assertThat(sut.cost(link2, resourceContext), is(closeTo(Double.parseDouble(LATENCY2), 1.0e-6)));
}
/**
......
......@@ -26,8 +26,8 @@ import org.onosproject.net.DefaultPath;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Path;
import org.onosproject.net.PortNumber;
import org.onosproject.net.intent.ResourceContext;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.net.resource.link.LinkResourceService;
import java.util.Arrays;
......@@ -50,7 +50,7 @@ public class ObstacleConstraintTest {
private static final PortNumber PN4 = PortNumber.portNumber(4);
private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo");
private LinkResourceService linkResourceService;
private ResourceContext resourceContext;
private Path path;
private DefaultLink link2;
......@@ -60,7 +60,7 @@ public class ObstacleConstraintTest {
@Before
public void setUp() {
linkResourceService = createMock(LinkResourceService.class);
resourceContext = createMock(ResourceContext.class);
link1 = DefaultLink.builder()
.providerId(PROVIDER_ID)
......@@ -97,7 +97,7 @@ public class ObstacleConstraintTest {
public void testPathNotThroughObstacles() {
sut = new ObstacleConstraint(DID4);
assertThat(sut.validate(path, linkResourceService), is(true));
assertThat(sut.validate(path, resourceContext), is(true));
}
/**
......@@ -107,6 +107,6 @@ public class ObstacleConstraintTest {
public void testPathThroughObstacle() {
sut = new ObstacleConstraint(DID1);
assertThat(sut.validate(path, linkResourceService), is(false));
assertThat(sut.validate(path, resourceContext), is(false));
}
}
......
......@@ -24,8 +24,8 @@ import org.onosproject.net.DeviceId;
import org.onosproject.net.Path;
import org.onosproject.net.PortNumber;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.ResourceContext;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.net.resource.link.LinkResourceService;
import java.util.Arrays;
......@@ -52,7 +52,7 @@ public class WaypointConstraintTest {
private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo");
private WaypointConstraint sut;
private LinkResourceService linkResourceService;
private ResourceContext resourceContext;
private Path path;
private DefaultLink link2;
......@@ -60,7 +60,7 @@ public class WaypointConstraintTest {
@Before
public void setUp() {
linkResourceService = createMock(LinkResourceService.class);
resourceContext = createMock(ResourceContext.class);
link1 = DefaultLink.builder()
.providerId(PROVIDER_ID)
......@@ -85,7 +85,7 @@ public class WaypointConstraintTest {
public void testSatisfyWaypoints() {
sut = new WaypointConstraint(DID1, DID2, DID3);
assertThat(sut.validate(path, linkResourceService), is(true));
assertThat(sut.validate(path, resourceContext), is(true));
}
/**
......@@ -95,7 +95,7 @@ public class WaypointConstraintTest {
public void testNotSatisfyWaypoint() {
sut = new WaypointConstraint(DID4);
assertThat(sut.validate(path, linkResourceService), is(false));
assertThat(sut.validate(path, resourceContext), is(false));
}
@Test
......
......@@ -27,8 +27,8 @@ import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.IntentCompiler;
import org.onosproject.net.intent.IntentExtensionService;
import org.onosproject.net.intent.impl.PathNotFoundException;
import org.onosproject.net.newresource.ResourceService;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.topology.LinkWeight;
import org.onosproject.net.topology.PathService;
import org.onosproject.net.topology.TopologyEdge;
......@@ -55,7 +55,7 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent>
protected PathService pathService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected LinkResourceService resourceService;
protected ResourceService resourceService;
/**
* Returns an edge-weight capable of evaluating links on the basis of the
......@@ -77,7 +77,7 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent>
*/
protected boolean checkPath(Path path, List<Constraint> constraints) {
for (Constraint constraint : constraints) {
if (!constraint.validate(path, resourceService)) {
if (!constraint.validate(path, resourceService::isAvailable)) {
return false;
}
}
......@@ -138,9 +138,9 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent>
// the first one with fast fail over the first failure
Iterator<Constraint> it = constraints.iterator();
double cost = it.next().cost(edge.link(), resourceService);
double cost = it.next().cost(edge.link(), resourceService::isAvailable);
while (it.hasNext() && cost > 0) {
if (it.next().cost(edge.link(), resourceService) < 0) {
if (it.next().cost(edge.link(), resourceService::isAvailable) < 0) {
return -1;
}
}
......
......@@ -110,6 +110,7 @@ public class HostToHostIntentCompilerTest extends AbstractIntentTest {
new HostToHostIntentCompiler();
compiler.pathService = new IntentTestsMocks.MockPathService(hops);
compiler.hostService = mockHostService;
compiler.resourceService = new MockResourceService();
return compiler;
}
......
......@@ -33,7 +33,7 @@ import org.onosproject.net.intent.PathIntent;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.intent.impl.PathNotFoundException;
import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.newresource.ResourceService;
import java.util.Collections;
import java.util.List;
......@@ -118,7 +118,7 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
* @param resourceService service to use for resource allocation requests
* @return point to point compiler
*/
private PointToPointIntentCompiler makeCompiler(String[] hops, LinkResourceService resourceService) {
private PointToPointIntentCompiler makeCompiler(String[] hops, ResourceService resourceService) {
final PointToPointIntentCompiler compiler = new PointToPointIntentCompiler();
compiler.resourceService = resourceService;
compiler.pathService = new IntentTestsMocks.MockPathService(hops);
......@@ -223,7 +223,7 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
@Test
public void testBandwidthConstrainedIntentSuccess() {
final LinkResourceService resourceService =
final ResourceService resourceService =
IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0);
final List<Constraint> constraints =
Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(100.0)));
......@@ -245,7 +245,7 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest {
@Test
public void testBandwidthConstrainedIntentFailure() {
final LinkResourceService resourceService =
final ResourceService resourceService =
IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0);
final List<Constraint> constraints =
Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(100.0)));
......