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; | ... | @@ -18,7 +18,6 @@ package org.onosproject.net.intent; |
18 | import com.google.common.annotations.Beta; | 18 | import com.google.common.annotations.Beta; |
19 | import org.onosproject.net.Link; | 19 | import org.onosproject.net.Link; |
20 | import org.onosproject.net.Path; | 20 | import org.onosproject.net.Path; |
21 | -import org.onosproject.net.resource.link.LinkResourceService; | ||
22 | 21 | ||
23 | /** | 22 | /** |
24 | * Representation of a connectivity constraint capable of evaluating a link | 23 | * Representation of a connectivity constraint capable of evaluating a link |
... | @@ -33,21 +32,19 @@ public interface Constraint { | ... | @@ -33,21 +32,19 @@ public interface Constraint { |
33 | /** | 32 | /** |
34 | * Evaluates the specified link and provides the cost for its traversal. | 33 | * Evaluates the specified link and provides the cost for its traversal. |
35 | * | 34 | * |
36 | - * @param link link to be evaluated | 35 | + * @param link link to be evaluated |
37 | - * @param resourceService resource service for validating availability of | 36 | + * @param context resource context for validating availability of resources |
38 | - * link resources | ||
39 | * @return cost of link traversal | 37 | * @return cost of link traversal |
40 | */ | 38 | */ |
41 | - double cost(Link link, LinkResourceService resourceService); | 39 | + double cost(Link link, ResourceContext context); |
42 | 40 | ||
43 | /** | 41 | /** |
44 | * Validates that the specified path satisfies the constraint. | 42 | * Validates that the specified path satisfies the constraint. |
45 | * | 43 | * |
46 | * @param path path to be validated | 44 | * @param path path to be validated |
47 | - * @param resourceService resource service for validating availability of | 45 | + * @param context resource context for validating availability of resources |
48 | - * link resources | ||
49 | * @return cost of link traversal | 46 | * @return cost of link traversal |
50 | */ | 47 | */ |
51 | - boolean validate(Path path, LinkResourceService resourceService); | 48 | + boolean validate(Path path, ResourceContext context); |
52 | 49 | ||
53 | } | 50 | } | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.net.intent; | ||
17 | + | ||
18 | +import com.google.common.annotations.Beta; | ||
19 | +import org.onosproject.net.newresource.Resource; | ||
20 | + | ||
21 | +/** | ||
22 | + * Class providing resource information to constraints. | ||
23 | + * This class is subject to be removed during refactorings on Constraint. | ||
24 | + */ | ||
25 | +@Beta | ||
26 | +public interface ResourceContext { | ||
27 | + /** | ||
28 | + * Returns the availability of the specified resource. | ||
29 | + * | ||
30 | + * @param resource resource to check the availability | ||
31 | + * @return true if available, otherwise false | ||
32 | + */ | ||
33 | + boolean isAvailable(Resource resource); | ||
34 | +} |
... | @@ -18,7 +18,7 @@ package org.onosproject.net.intent.constraint; | ... | @@ -18,7 +18,7 @@ package org.onosproject.net.intent.constraint; |
18 | import com.google.common.annotations.Beta; | 18 | import com.google.common.annotations.Beta; |
19 | import com.google.common.base.MoreObjects; | 19 | import com.google.common.base.MoreObjects; |
20 | import org.onosproject.net.Link; | 20 | import org.onosproject.net.Link; |
21 | -import org.onosproject.net.resource.link.LinkResourceService; | 21 | +import org.onosproject.net.intent.ResourceContext; |
22 | 22 | ||
23 | import java.util.Objects; | 23 | import java.util.Objects; |
24 | 24 | ||
... | @@ -68,16 +68,28 @@ public class AnnotationConstraint extends BooleanConstraint { | ... | @@ -68,16 +68,28 @@ public class AnnotationConstraint extends BooleanConstraint { |
68 | return threshold; | 68 | return threshold; |
69 | } | 69 | } |
70 | 70 | ||
71 | + // doesn't use LinkResourceService | ||
71 | @Override | 72 | @Override |
72 | - public boolean isValid(Link link, LinkResourceService resourceService) { | 73 | + public boolean isValid(Link link, ResourceContext context) { |
74 | + // explicitly call a method not depending on LinkResourceService | ||
75 | + return isValid(link); | ||
76 | + } | ||
77 | + | ||
78 | + private boolean isValid(Link link) { | ||
73 | double value = getAnnotatedValue(link, key); | 79 | double value = getAnnotatedValue(link, key); |
74 | 80 | ||
75 | return value <= threshold; | 81 | return value <= threshold; |
76 | } | 82 | } |
77 | 83 | ||
84 | + // doesn't use LinkResourceService | ||
78 | @Override | 85 | @Override |
79 | - public double cost(Link link, LinkResourceService resourceService) { | 86 | + public double cost(Link link, ResourceContext context) { |
80 | - if (isValid(link, resourceService)) { | 87 | + // explicitly call a method not depending on LinkResourceService |
88 | + return cost(link); | ||
89 | + } | ||
90 | + | ||
91 | + private double cost(Link link) { | ||
92 | + if (isValid(link)) { | ||
81 | return getAnnotatedValue(link, key); | 93 | return getAnnotatedValue(link, key); |
82 | } else { | 94 | } else { |
83 | return -1; | 95 | return -1; | ... | ... |
... | @@ -19,7 +19,7 @@ import com.google.common.annotations.Beta; | ... | @@ -19,7 +19,7 @@ import com.google.common.annotations.Beta; |
19 | import org.onosproject.net.Link; | 19 | import org.onosproject.net.Link; |
20 | import org.onosproject.net.Path; | 20 | import org.onosproject.net.Path; |
21 | import org.onosproject.net.intent.Constraint; | 21 | import org.onosproject.net.intent.Constraint; |
22 | -import org.onosproject.net.resource.link.LinkResourceService; | 22 | +import org.onosproject.net.intent.ResourceContext; |
23 | 23 | ||
24 | import java.util.Objects; | 24 | import java.util.Objects; |
25 | 25 | ||
... | @@ -31,13 +31,15 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -31,13 +31,15 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
31 | @Beta | 31 | @Beta |
32 | public class AsymmetricPathConstraint implements Constraint { | 32 | public class AsymmetricPathConstraint implements Constraint { |
33 | 33 | ||
34 | + // doesn't use LinkResourceService | ||
34 | @Override | 35 | @Override |
35 | - public double cost(Link link, LinkResourceService resourceService) { | 36 | + public double cost(Link link, ResourceContext context) { |
36 | return 1; | 37 | return 1; |
37 | } | 38 | } |
38 | 39 | ||
40 | + // doesn't use LinkResourceService | ||
39 | @Override | 41 | @Override |
40 | - public boolean validate(Path path, LinkResourceService resourceService) { | 42 | + public boolean validate(Path path, ResourceContext context) { |
41 | return true; | 43 | return true; |
42 | } | 44 | } |
43 | 45 | ... | ... |
... | @@ -20,12 +20,11 @@ import com.google.common.annotations.Beta; | ... | @@ -20,12 +20,11 @@ import com.google.common.annotations.Beta; |
20 | import org.onlab.util.Bandwidth; | 20 | import org.onlab.util.Bandwidth; |
21 | import org.onlab.util.DataRateUnit; | 21 | import org.onlab.util.DataRateUnit; |
22 | import org.onosproject.net.Link; | 22 | import org.onosproject.net.Link; |
23 | -import org.onosproject.net.resource.link.BandwidthResourceRequest; | 23 | +import org.onosproject.net.intent.ResourceContext; |
24 | -import org.onosproject.net.resource.link.LinkResourceService; | 24 | +import org.onosproject.net.newresource.Resources; |
25 | -import org.onosproject.net.resource.ResourceRequest; | ||
26 | -import org.onosproject.net.resource.ResourceType; | ||
27 | 25 | ||
28 | import java.util.Objects; | 26 | import java.util.Objects; |
27 | +import java.util.stream.Stream; | ||
29 | 28 | ||
30 | import static com.google.common.base.MoreObjects.toStringHelper; | 29 | import static com.google.common.base.MoreObjects.toStringHelper; |
31 | import static com.google.common.base.Preconditions.checkNotNull; | 30 | import static com.google.common.base.Preconditions.checkNotNull; |
... | @@ -64,16 +63,10 @@ public final class BandwidthConstraint extends BooleanConstraint { | ... | @@ -64,16 +63,10 @@ public final class BandwidthConstraint extends BooleanConstraint { |
64 | } | 63 | } |
65 | 64 | ||
66 | @Override | 65 | @Override |
67 | - public boolean isValid(Link link, LinkResourceService resourceService) { | 66 | + public boolean isValid(Link link, ResourceContext context) { |
68 | - for (ResourceRequest request : resourceService.getAvailableResources(link)) { | 67 | + return Stream.of(link.src(), link.dst()) |
69 | - if (request.type() == ResourceType.BANDWIDTH) { | 68 | + .map(cp -> Resources.continuous(cp.deviceId(), cp.port(), Bandwidth.class).resource(bandwidth.bps())) |
70 | - BandwidthResourceRequest brr = (BandwidthResourceRequest) request; | 69 | + .allMatch(context::isAvailable); |
71 | - if (brr.bandwidth().toDouble() >= bandwidth.bps()) { | ||
72 | - return true; | ||
73 | - } | ||
74 | - } | ||
75 | - } | ||
76 | - return false; | ||
77 | } | 70 | } |
78 | 71 | ||
79 | /** | 72 | /** | ... | ... |
... | @@ -19,7 +19,7 @@ import com.google.common.annotations.Beta; | ... | @@ -19,7 +19,7 @@ import com.google.common.annotations.Beta; |
19 | import org.onosproject.net.Link; | 19 | import org.onosproject.net.Link; |
20 | import org.onosproject.net.Path; | 20 | import org.onosproject.net.Path; |
21 | import org.onosproject.net.intent.Constraint; | 21 | import org.onosproject.net.intent.Constraint; |
22 | -import org.onosproject.net.resource.link.LinkResourceService; | 22 | +import org.onosproject.net.intent.ResourceContext; |
23 | 23 | ||
24 | /** | 24 | /** |
25 | * Abstract base class for various constraints that evaluate link viability | 25 | * Abstract base class for various constraints that evaluate link viability |
... | @@ -32,10 +32,10 @@ public abstract class BooleanConstraint implements Constraint { | ... | @@ -32,10 +32,10 @@ public abstract class BooleanConstraint implements Constraint { |
32 | * Returns true if the specified link satisfies the constraint. | 32 | * Returns true if the specified link satisfies the constraint. |
33 | * | 33 | * |
34 | * @param link link to be validated | 34 | * @param link link to be validated |
35 | - * @param resourceService resource service for checking available link resources | 35 | + * @param context resource context for checking available resources |
36 | * @return true if link is viable | 36 | * @return true if link is viable |
37 | */ | 37 | */ |
38 | - public abstract boolean isValid(Link link, LinkResourceService resourceService); | 38 | + public abstract boolean isValid(Link link, ResourceContext context); |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * {@inheritDoc} | 41 | * {@inheritDoc} |
... | @@ -43,18 +43,18 @@ public abstract class BooleanConstraint implements Constraint { | ... | @@ -43,18 +43,18 @@ public abstract class BooleanConstraint implements Constraint { |
43 | * Negative return value means the specified link does not satisfy this constraint. | 43 | * Negative return value means the specified link does not satisfy this constraint. |
44 | * | 44 | * |
45 | * @param link {@inheritDoc} | 45 | * @param link {@inheritDoc} |
46 | - * @param resourceService {@inheritDoc} | 46 | + * @param context {@inheritDoc} |
47 | * @return {@inheritDoc} | 47 | * @return {@inheritDoc} |
48 | */ | 48 | */ |
49 | @Override | 49 | @Override |
50 | - public double cost(Link link, LinkResourceService resourceService) { | 50 | + public double cost(Link link, ResourceContext context) { |
51 | - return isValid(link, resourceService) ? +1 : -1; | 51 | + return isValid(link, context) ? +1 : -1; |
52 | } | 52 | } |
53 | 53 | ||
54 | @Override | 54 | @Override |
55 | - public boolean validate(Path path, LinkResourceService resourceService) { | 55 | + public boolean validate(Path path, ResourceContext context) { |
56 | return path.links().stream() | 56 | return path.links().stream() |
57 | - .allMatch(link -> isValid(link, resourceService)); | 57 | + .allMatch(link -> isValid(link, context)); |
58 | } | 58 | } |
59 | 59 | ||
60 | } | 60 | } | ... | ... |
... | @@ -19,7 +19,7 @@ package org.onosproject.net.intent.constraint; | ... | @@ -19,7 +19,7 @@ package org.onosproject.net.intent.constraint; |
19 | 19 | ||
20 | import org.onosproject.net.EncapsulationType; | 20 | import org.onosproject.net.EncapsulationType; |
21 | import org.onosproject.net.Link; | 21 | import org.onosproject.net.Link; |
22 | -import org.onosproject.net.resource.link.LinkResourceService; | 22 | +import org.onosproject.net.intent.ResourceContext; |
23 | 23 | ||
24 | import static com.google.common.base.MoreObjects.toStringHelper; | 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
25 | import static com.google.common.base.Preconditions.checkNotNull; | 25 | import static com.google.common.base.Preconditions.checkNotNull; |
... | @@ -42,8 +42,9 @@ public class EncapsulationConstraint extends BooleanConstraint { | ... | @@ -42,8 +42,9 @@ public class EncapsulationConstraint extends BooleanConstraint { |
42 | } | 42 | } |
43 | 43 | ||
44 | 44 | ||
45 | + // doesn't use LinkResourceService | ||
45 | @Override | 46 | @Override |
46 | - public boolean isValid(Link link, LinkResourceService resourceService) { | 47 | + public boolean isValid(Link link, ResourceContext context) { |
47 | //TODO: validate the availability of the resources for each link in the path. | 48 | //TODO: validate the availability of the resources for each link in the path. |
48 | //e.g., availability of MPLSlabels, VLANID | 49 | //e.g., availability of MPLSlabels, VLANID |
49 | 50 | ... | ... |
... | @@ -20,7 +20,7 @@ import com.google.common.base.MoreObjects; | ... | @@ -20,7 +20,7 @@ import com.google.common.base.MoreObjects; |
20 | import org.onosproject.net.Link; | 20 | import org.onosproject.net.Link; |
21 | import org.onosproject.net.Path; | 21 | import org.onosproject.net.Path; |
22 | import org.onosproject.net.intent.Constraint; | 22 | import org.onosproject.net.intent.Constraint; |
23 | -import org.onosproject.net.resource.link.LinkResourceService; | 23 | +import org.onosproject.net.intent.ResourceContext; |
24 | 24 | ||
25 | import java.time.Duration; | 25 | import java.time.Duration; |
26 | import java.time.temporal.ChronoUnit; | 26 | import java.time.temporal.ChronoUnit; |
... | @@ -54,14 +54,26 @@ public class LatencyConstraint implements Constraint { | ... | @@ -54,14 +54,26 @@ public class LatencyConstraint implements Constraint { |
54 | return latency; | 54 | return latency; |
55 | } | 55 | } |
56 | 56 | ||
57 | + // doesn't use LinkResourceService | ||
57 | @Override | 58 | @Override |
58 | - public double cost(Link link, LinkResourceService resourceService) { | 59 | + public double cost(Link link, ResourceContext context) { |
60 | + // explicitly call a method not depending on LinkResourceService | ||
61 | + return cost(link); | ||
62 | + } | ||
63 | + | ||
64 | + private double cost(Link link) { | ||
59 | return getAnnotatedValue(link, LATENCY); | 65 | return getAnnotatedValue(link, LATENCY); |
60 | } | 66 | } |
61 | 67 | ||
68 | + // doesn't use LinkResourceService | ||
62 | @Override | 69 | @Override |
63 | - public boolean validate(Path path, LinkResourceService resourceService) { | 70 | + public boolean validate(Path path, ResourceContext context) { |
64 | - double pathLatency = path.links().stream().mapToDouble(link -> cost(link, resourceService)).sum(); | 71 | + // explicitly call a method not depending on LinkResourceService |
72 | + return validate(path); | ||
73 | + } | ||
74 | + | ||
75 | + private boolean validate(Path path) { | ||
76 | + double pathLatency = path.links().stream().mapToDouble(this::cost).sum(); | ||
65 | return Duration.of((long) pathLatency, ChronoUnit.MICROS).compareTo(latency) <= 0; | 77 | return Duration.of((long) pathLatency, ChronoUnit.MICROS).compareTo(latency) <= 0; |
66 | } | 78 | } |
67 | 79 | ... | ... |
... | @@ -18,7 +18,7 @@ package org.onosproject.net.intent.constraint; | ... | @@ -18,7 +18,7 @@ package org.onosproject.net.intent.constraint; |
18 | import com.google.common.annotations.Beta; | 18 | import com.google.common.annotations.Beta; |
19 | import com.google.common.collect.ImmutableSet; | 19 | import com.google.common.collect.ImmutableSet; |
20 | import org.onosproject.net.Link; | 20 | import org.onosproject.net.Link; |
21 | -import org.onosproject.net.resource.link.LinkResourceService; | 21 | +import org.onosproject.net.intent.ResourceContext; |
22 | 22 | ||
23 | import java.util.Objects; | 23 | import java.util.Objects; |
24 | import java.util.Set; | 24 | import java.util.Set; |
... | @@ -57,8 +57,14 @@ public class LinkTypeConstraint extends BooleanConstraint { | ... | @@ -57,8 +57,14 @@ public class LinkTypeConstraint extends BooleanConstraint { |
57 | this.isInclusive = false; | 57 | this.isInclusive = false; |
58 | } | 58 | } |
59 | 59 | ||
60 | + // doesn't use LinkResourceService | ||
60 | @Override | 61 | @Override |
61 | - public boolean isValid(Link link, LinkResourceService resourceService) { | 62 | + public boolean isValid(Link link, ResourceContext context) { |
63 | + // explicitly call a method not depending on LinkResourceService | ||
64 | + return isValid(link); | ||
65 | + } | ||
66 | + | ||
67 | + private boolean isValid(Link link) { | ||
62 | boolean contains = types.contains(link.type()); | 68 | boolean contains = types.contains(link.type()); |
63 | return isInclusive == contains; | 69 | return isInclusive == contains; |
64 | } | 70 | } | ... | ... |
... | @@ -20,7 +20,7 @@ import com.google.common.base.MoreObjects; | ... | @@ -20,7 +20,7 @@ import com.google.common.base.MoreObjects; |
20 | import com.google.common.collect.ImmutableSet; | 20 | import com.google.common.collect.ImmutableSet; |
21 | import org.onosproject.net.DeviceId; | 21 | import org.onosproject.net.DeviceId; |
22 | import org.onosproject.net.Link; | 22 | import org.onosproject.net.Link; |
23 | -import org.onosproject.net.resource.link.LinkResourceService; | 23 | +import org.onosproject.net.intent.ResourceContext; |
24 | 24 | ||
25 | import java.util.Collections; | 25 | import java.util.Collections; |
26 | import java.util.Objects; | 26 | import java.util.Objects; |
... | @@ -56,8 +56,14 @@ public class ObstacleConstraint extends BooleanConstraint { | ... | @@ -56,8 +56,14 @@ public class ObstacleConstraint extends BooleanConstraint { |
56 | return obstacles; | 56 | return obstacles; |
57 | } | 57 | } |
58 | 58 | ||
59 | + // doesn't use LinkResourceService | ||
59 | @Override | 60 | @Override |
60 | - public boolean isValid(Link link, LinkResourceService resourceService) { | 61 | + public boolean isValid(Link link, ResourceContext context) { |
62 | + // explicitly call a method not depending on LinkResourceService | ||
63 | + return isValid(link); | ||
64 | + } | ||
65 | + | ||
66 | + private boolean isValid(Link link) { | ||
61 | DeviceId src = link.src().deviceId(); | 67 | DeviceId src = link.src().deviceId(); |
62 | DeviceId dst = link.dst().deviceId(); | 68 | DeviceId dst = link.dst().deviceId(); |
63 | 69 | ... | ... |
... | @@ -20,7 +20,7 @@ import org.onosproject.net.Path; | ... | @@ -20,7 +20,7 @@ import org.onosproject.net.Path; |
20 | import org.onosproject.net.intent.ConnectivityIntent; | 20 | import org.onosproject.net.intent.ConnectivityIntent; |
21 | import org.onosproject.net.intent.Constraint; | 21 | import org.onosproject.net.intent.Constraint; |
22 | import org.onosproject.net.intent.Intent; | 22 | import org.onosproject.net.intent.Intent; |
23 | -import org.onosproject.net.resource.link.LinkResourceService; | 23 | +import org.onosproject.net.intent.ResourceContext; |
24 | 24 | ||
25 | /** | 25 | /** |
26 | * A constraint that allows intents that can only be partially compiled | 26 | * A constraint that allows intents that can only be partially compiled |
... | @@ -28,13 +28,15 @@ import org.onosproject.net.resource.link.LinkResourceService; | ... | @@ -28,13 +28,15 @@ import org.onosproject.net.resource.link.LinkResourceService; |
28 | * to be installed when some endpoints or paths are not found. | 28 | * to be installed when some endpoints or paths are not found. |
29 | */ | 29 | */ |
30 | public class PartialFailureConstraint implements Constraint { | 30 | public class PartialFailureConstraint implements Constraint { |
31 | + // doesn't use LinkResourceService | ||
31 | @Override | 32 | @Override |
32 | - public double cost(Link link, LinkResourceService resourceService) { | 33 | + public double cost(Link link, ResourceContext context) { |
33 | return 1; | 34 | return 1; |
34 | } | 35 | } |
35 | 36 | ||
37 | + // doesn't use LinkResourceService | ||
36 | @Override | 38 | @Override |
37 | - public boolean validate(Path path, LinkResourceService resourceService) { | 39 | + public boolean validate(Path path, ResourceContext context) { |
38 | return true; | 40 | return true; |
39 | } | 41 | } |
40 | 42 | ... | ... |
... | @@ -22,7 +22,7 @@ import org.onosproject.net.DeviceId; | ... | @@ -22,7 +22,7 @@ import org.onosproject.net.DeviceId; |
22 | import org.onosproject.net.Link; | 22 | import org.onosproject.net.Link; |
23 | import org.onosproject.net.Path; | 23 | import org.onosproject.net.Path; |
24 | import org.onosproject.net.intent.Constraint; | 24 | import org.onosproject.net.intent.Constraint; |
25 | -import org.onosproject.net.resource.link.LinkResourceService; | 25 | +import org.onosproject.net.intent.ResourceContext; |
26 | 26 | ||
27 | import java.util.Collections; | 27 | import java.util.Collections; |
28 | import java.util.LinkedList; | 28 | import java.util.LinkedList; |
... | @@ -60,14 +60,21 @@ public class WaypointConstraint implements Constraint { | ... | @@ -60,14 +60,21 @@ public class WaypointConstraint implements Constraint { |
60 | return waypoints; | 60 | return waypoints; |
61 | } | 61 | } |
62 | 62 | ||
63 | + // doesn't use LinkResourceService | ||
63 | @Override | 64 | @Override |
64 | - public double cost(Link link, LinkResourceService resourceService) { | 65 | + public double cost(Link link, ResourceContext context) { |
65 | // Always consider the number of hops | 66 | // Always consider the number of hops |
66 | return 1; | 67 | return 1; |
67 | } | 68 | } |
68 | 69 | ||
70 | + // doesn't use LinkResourceService | ||
69 | @Override | 71 | @Override |
70 | - public boolean validate(Path path, LinkResourceService resourceService) { | 72 | + public boolean validate(Path path, ResourceContext context) { |
73 | + // explicitly call a method not depending on LinkResourceService | ||
74 | + return validate(path); | ||
75 | + } | ||
76 | + | ||
77 | + private boolean validate(Path path) { | ||
71 | LinkedList<DeviceId> waypoints = new LinkedList<>(this.waypoints); | 78 | LinkedList<DeviceId> waypoints = new LinkedList<>(this.waypoints); |
72 | DeviceId current = waypoints.poll(); | 79 | DeviceId current = waypoints.poll(); |
73 | // This is safe because Path class ensures the number of links are more than 0 | 80 | // This is safe because Path class ensures the number of links are more than 0 | ... | ... |
... | @@ -16,7 +16,6 @@ | ... | @@ -16,7 +16,6 @@ |
16 | package org.onosproject.net.intent; | 16 | package org.onosproject.net.intent; |
17 | 17 | ||
18 | import com.google.common.base.MoreObjects; | 18 | import com.google.common.base.MoreObjects; |
19 | -import com.google.common.collect.ImmutableSet; | ||
20 | import org.onlab.util.Bandwidth; | 19 | import org.onlab.util.Bandwidth; |
21 | import org.onosproject.core.DefaultGroupId; | 20 | import org.onosproject.core.DefaultGroupId; |
22 | import org.onosproject.core.GroupId; | 21 | import org.onosproject.core.GroupId; |
... | @@ -36,20 +35,13 @@ import org.onosproject.net.flow.criteria.Criterion.Type; | ... | @@ -36,20 +35,13 @@ import org.onosproject.net.flow.criteria.Criterion.Type; |
36 | import org.onosproject.net.flow.instructions.Instruction; | 35 | import org.onosproject.net.flow.instructions.Instruction; |
37 | import org.onosproject.net.flow.instructions.Instructions; | 36 | import org.onosproject.net.flow.instructions.Instructions; |
38 | import org.onosproject.net.flow.instructions.Instructions.MetadataInstruction; | 37 | import org.onosproject.net.flow.instructions.Instructions.MetadataInstruction; |
39 | -import org.onosproject.net.resource.ResourceAllocation; | 38 | +import org.onosproject.net.newresource.DiscreteResourceId; |
40 | -import org.onosproject.net.resource.ResourceRequest; | 39 | +import org.onosproject.net.newresource.Resource; |
41 | -import org.onosproject.net.resource.ResourceType; | 40 | +import org.onosproject.net.newresource.ResourceAllocation; |
42 | -import org.onosproject.net.resource.link.BandwidthResource; | 41 | +import org.onosproject.net.newresource.ResourceConsumer; |
43 | -import org.onosproject.net.resource.link.BandwidthResourceRequest; | 42 | +import org.onosproject.net.newresource.ResourceId; |
44 | -import org.onosproject.net.resource.link.LambdaResource; | 43 | +import org.onosproject.net.newresource.ResourceListener; |
45 | -import org.onosproject.net.resource.link.LambdaResourceAllocation; | 44 | +import org.onosproject.net.newresource.ResourceService; |
46 | -import org.onosproject.net.resource.link.LambdaResourceRequest; | ||
47 | -import org.onosproject.net.resource.link.LinkResourceAllocations; | ||
48 | -import org.onosproject.net.resource.link.LinkResourceListener; | ||
49 | -import org.onosproject.net.resource.link.LinkResourceRequest; | ||
50 | -import org.onosproject.net.resource.link.LinkResourceService; | ||
51 | -import org.onosproject.net.resource.link.MplsLabel; | ||
52 | -import org.onosproject.net.resource.link.MplsLabelResourceAllocation; | ||
53 | import org.onosproject.net.topology.DefaultTopologyEdge; | 45 | import org.onosproject.net.topology.DefaultTopologyEdge; |
54 | import org.onosproject.net.topology.DefaultTopologyVertex; | 46 | import org.onosproject.net.topology.DefaultTopologyVertex; |
55 | import org.onosproject.net.topology.LinkWeight; | 47 | import org.onosproject.net.topology.LinkWeight; |
... | @@ -61,9 +53,9 @@ import java.util.Arrays; | ... | @@ -61,9 +53,9 @@ import java.util.Arrays; |
61 | import java.util.Collection; | 53 | import java.util.Collection; |
62 | import java.util.Collections; | 54 | import java.util.Collections; |
63 | import java.util.HashSet; | 55 | import java.util.HashSet; |
64 | -import java.util.LinkedList; | ||
65 | import java.util.List; | 56 | import java.util.List; |
66 | import java.util.Objects; | 57 | import java.util.Objects; |
58 | +import java.util.Optional; | ||
67 | import java.util.Set; | 59 | import java.util.Set; |
68 | import java.util.concurrent.atomic.AtomicLong; | 60 | import java.util.concurrent.atomic.AtomicLong; |
69 | 61 | ||
... | @@ -184,145 +176,84 @@ public class IntentTestsMocks { | ... | @@ -184,145 +176,84 @@ public class IntentTestsMocks { |
184 | } | 176 | } |
185 | } | 177 | } |
186 | 178 | ||
187 | - public static class MockLinkResourceAllocations implements LinkResourceAllocations { | 179 | + public static final class MockResourceService implements ResourceService { |
188 | - @Override | ||
189 | - public Set<ResourceAllocation> getResourceAllocation(Link link) { | ||
190 | - return ImmutableSet.of( | ||
191 | - new LambdaResourceAllocation(LambdaResource.valueOf(77)), | ||
192 | - new MplsLabelResourceAllocation(MplsLabel.valueOf(10))); | ||
193 | - } | ||
194 | 180 | ||
195 | - @Override | 181 | + private final double bandwidth; |
196 | - public IntentId intentId() { | ||
197 | - return null; | ||
198 | - } | ||
199 | 182 | ||
200 | - @Override | 183 | + public static ResourceService makeBandwidthResourceService(double bandwidth) { |
201 | - public Collection<Link> links() { | 184 | + return new MockResourceService(bandwidth); |
202 | - return null; | ||
203 | } | 185 | } |
204 | 186 | ||
205 | - @Override | 187 | + private MockResourceService(double bandwidth) { |
206 | - public Set<ResourceRequest> resources() { | 188 | + this.bandwidth = bandwidth; |
207 | - return null; | ||
208 | } | 189 | } |
209 | 190 | ||
210 | @Override | 191 | @Override |
211 | - public ResourceType type() { | 192 | + public List<ResourceAllocation> allocate(ResourceConsumer consumer, List<Resource> resources) { |
212 | return null; | 193 | return null; |
213 | } | 194 | } |
214 | - } | ||
215 | - | ||
216 | - public static class MockedAllocationFailure extends RuntimeException { } | ||
217 | - | ||
218 | - public static class MockResourceService implements LinkResourceService { | ||
219 | 195 | ||
220 | - double availableBandwidth = -1.0; | 196 | + @Override |
221 | - int availableLambda = -1; | 197 | + public boolean release(List<ResourceAllocation> allocations) { |
222 | - | 198 | + return false; |
223 | - /** | ||
224 | - * Allocates a resource service that will allow bandwidth allocations | ||
225 | - * up to a limit. | ||
226 | - * | ||
227 | - * @param bandwidth available bandwidth limit | ||
228 | - * @return resource manager for bandwidth requests | ||
229 | - */ | ||
230 | - public static MockResourceService makeBandwidthResourceService(double bandwidth) { | ||
231 | - final MockResourceService result = new MockResourceService(); | ||
232 | - result.availableBandwidth = bandwidth; | ||
233 | - return result; | ||
234 | - } | ||
235 | - | ||
236 | - /** | ||
237 | - * Allocates a resource service that will allow lambda allocations. | ||
238 | - * | ||
239 | - * @param lambda Lambda to return for allocation requests. Currently unused | ||
240 | - * @return resource manager for lambda requests | ||
241 | - */ | ||
242 | - public static MockResourceService makeLambdaResourceService(int lambda) { | ||
243 | - final MockResourceService result = new MockResourceService(); | ||
244 | - result.availableLambda = lambda; | ||
245 | - return result; | ||
246 | } | 199 | } |
247 | 200 | ||
248 | @Override | 201 | @Override |
249 | - public LinkResourceAllocations requestResources(LinkResourceRequest req) { | 202 | + public boolean release(ResourceConsumer consumer) { |
250 | - int lambda = -1; | 203 | + return false; |
251 | - double bandwidth = -1.0; | ||
252 | - | ||
253 | - for (ResourceRequest resourceRequest : req.resources()) { | ||
254 | - if (resourceRequest.type() == ResourceType.BANDWIDTH) { | ||
255 | - final BandwidthResourceRequest brr = (BandwidthResourceRequest) resourceRequest; | ||
256 | - bandwidth = brr.bandwidth().toDouble(); | ||
257 | - } else if (resourceRequest.type() == ResourceType.LAMBDA) { | ||
258 | - lambda = 1; | ||
259 | - } | ||
260 | - } | ||
261 | - | ||
262 | - if (availableBandwidth < bandwidth) { | ||
263 | - throw new MockedAllocationFailure(); | ||
264 | - } | ||
265 | - if (lambda > 0 && availableLambda == 0) { | ||
266 | - throw new MockedAllocationFailure(); | ||
267 | - } | ||
268 | - | ||
269 | - return new IntentTestsMocks.MockLinkResourceAllocations(); | ||
270 | } | 204 | } |
271 | 205 | ||
272 | @Override | 206 | @Override |
273 | - public void releaseResources(LinkResourceAllocations allocations) { | 207 | + public List<ResourceAllocation> getResourceAllocations(ResourceId id) { |
274 | - // Mock | 208 | + return null; |
275 | } | 209 | } |
276 | 210 | ||
277 | @Override | 211 | @Override |
278 | - public LinkResourceAllocations updateResources(LinkResourceRequest req, | 212 | + public <T> Collection<ResourceAllocation> getResourceAllocations(DiscreteResourceId parent, Class<T> cls) { |
279 | - LinkResourceAllocations oldAllocations) { | ||
280 | return null; | 213 | return null; |
281 | } | 214 | } |
282 | 215 | ||
283 | @Override | 216 | @Override |
284 | - public Iterable<LinkResourceAllocations> getAllocations() { | 217 | + public Collection<ResourceAllocation> getResourceAllocations(ResourceConsumer consumer) { |
285 | - return ImmutableSet.of( | 218 | + return null; |
286 | - new IntentTestsMocks.MockLinkResourceAllocations()); | ||
287 | } | 219 | } |
288 | 220 | ||
289 | @Override | 221 | @Override |
290 | - public Iterable<LinkResourceAllocations> getAllocations(Link link) { | 222 | + public Set<Resource> getAvailableResources(DiscreteResourceId parent) { |
291 | - return ImmutableSet.of( | 223 | + return null; |
292 | - new IntentTestsMocks.MockLinkResourceAllocations()); | ||
293 | } | 224 | } |
294 | 225 | ||
295 | @Override | 226 | @Override |
296 | - public LinkResourceAllocations getAllocations(IntentId intentId) { | 227 | + public <T> Set<Resource> getAvailableResources(DiscreteResourceId parent, Class<T> cls) { |
297 | - return new IntentTestsMocks.MockLinkResourceAllocations(); | 228 | + return null; |
298 | } | 229 | } |
299 | 230 | ||
300 | @Override | 231 | @Override |
301 | - public Iterable<ResourceRequest> getAvailableResources(Link link) { | 232 | + public <T> Set<T> getAvailableResourceValues(DiscreteResourceId parent, Class<T> cls) { |
302 | - final List<ResourceRequest> result = new LinkedList<>(); | 233 | + return null; |
303 | - if (availableBandwidth > 0.0) { | ||
304 | - result.add(new BandwidthResourceRequest( | ||
305 | - new BandwidthResource(Bandwidth.bps(availableBandwidth)))); | ||
306 | - } | ||
307 | - if (availableLambda > 0) { | ||
308 | - result.add(new LambdaResourceRequest()); | ||
309 | - } | ||
310 | - return result; | ||
311 | } | 234 | } |
312 | 235 | ||
313 | @Override | 236 | @Override |
314 | - public Iterable<ResourceRequest> getAvailableResources(Link link, LinkResourceAllocations allocations) { | 237 | + public Set<Resource> getRegisteredResources(DiscreteResourceId parent) { |
315 | return null; | 238 | return null; |
316 | } | 239 | } |
317 | 240 | ||
318 | @Override | 241 | @Override |
319 | - public void addListener(LinkResourceListener listener) { | 242 | + public boolean isAvailable(Resource resource) { |
243 | + if (!resource.isTypeOf(Bandwidth.class)) { | ||
244 | + return false; | ||
245 | + } | ||
320 | 246 | ||
247 | + Optional<Double> value = resource.valueAs(Double.class); | ||
248 | + return value.filter(requested -> requested <= bandwidth).isPresent(); | ||
321 | } | 249 | } |
322 | 250 | ||
323 | @Override | 251 | @Override |
324 | - public void removeListener(LinkResourceListener listener) { | 252 | + public void addListener(ResourceListener listener) { |
253 | + } | ||
325 | 254 | ||
255 | + @Override | ||
256 | + public void removeListener(ResourceListener listener) { | ||
326 | } | 257 | } |
327 | } | 258 | } |
328 | 259 | ... | ... |
... | @@ -23,8 +23,8 @@ import org.onosproject.net.DefaultLink; | ... | @@ -23,8 +23,8 @@ import org.onosproject.net.DefaultLink; |
23 | import org.onosproject.net.DeviceId; | 23 | import org.onosproject.net.DeviceId; |
24 | import org.onosproject.net.Link; | 24 | import org.onosproject.net.Link; |
25 | import org.onosproject.net.PortNumber; | 25 | import org.onosproject.net.PortNumber; |
26 | +import org.onosproject.net.intent.ResourceContext; | ||
26 | import org.onosproject.net.provider.ProviderId; | 27 | import org.onosproject.net.provider.ProviderId; |
27 | -import org.onosproject.net.resource.link.LinkResourceService; | ||
28 | 28 | ||
29 | import static org.easymock.EasyMock.createMock; | 29 | import static org.easymock.EasyMock.createMock; |
30 | import static org.hamcrest.Matchers.closeTo; | 30 | import static org.hamcrest.Matchers.closeTo; |
... | @@ -51,11 +51,11 @@ public class AnnotationConstraintTest { | ... | @@ -51,11 +51,11 @@ public class AnnotationConstraintTest { |
51 | 51 | ||
52 | private AnnotationConstraint sut; | 52 | private AnnotationConstraint sut; |
53 | private Link link; | 53 | private Link link; |
54 | - private LinkResourceService linkResourceService; | 54 | + private ResourceContext resourceContext; |
55 | 55 | ||
56 | @Before | 56 | @Before |
57 | public void setUp() { | 57 | public void setUp() { |
58 | - linkResourceService = createMock(LinkResourceService.class); | 58 | + resourceContext = createMock(ResourceContext.class); |
59 | 59 | ||
60 | DefaultAnnotations annotations = DefaultAnnotations.builder().set(KEY, String.valueOf(VALUE)).build(); | 60 | DefaultAnnotations annotations = DefaultAnnotations.builder().set(KEY, String.valueOf(VALUE)).build(); |
61 | 61 | ||
... | @@ -75,8 +75,8 @@ public class AnnotationConstraintTest { | ... | @@ -75,8 +75,8 @@ public class AnnotationConstraintTest { |
75 | double value = 120; | 75 | double value = 120; |
76 | sut = new AnnotationConstraint(KEY, value); | 76 | sut = new AnnotationConstraint(KEY, value); |
77 | 77 | ||
78 | - assertThat(sut.isValid(link, linkResourceService), is(true)); | 78 | + assertThat(sut.isValid(link, resourceContext), is(true)); |
79 | - assertThat(sut.cost(link, linkResourceService), is(closeTo(VALUE, 1.0e-6))); | 79 | + assertThat(sut.cost(link, resourceContext), is(closeTo(VALUE, 1.0e-6))); |
80 | } | 80 | } |
81 | 81 | ||
82 | /** | 82 | /** |
... | @@ -87,8 +87,8 @@ public class AnnotationConstraintTest { | ... | @@ -87,8 +87,8 @@ public class AnnotationConstraintTest { |
87 | double value = 80; | 87 | double value = 80; |
88 | sut = new AnnotationConstraint(KEY, value); | 88 | sut = new AnnotationConstraint(KEY, value); |
89 | 89 | ||
90 | - assertThat(sut.isValid(link, linkResourceService), is(false)); | 90 | + assertThat(sut.isValid(link, resourceContext), is(false)); |
91 | - assertThat(sut.cost(link, linkResourceService), is(lessThan(0.0))); | 91 | + assertThat(sut.cost(link, resourceContext), is(lessThan(0.0))); |
92 | } | 92 | } |
93 | 93 | ||
94 | @Test | 94 | @Test | ... | ... |
... | @@ -26,8 +26,8 @@ import org.onosproject.net.DeviceId; | ... | @@ -26,8 +26,8 @@ import org.onosproject.net.DeviceId; |
26 | import org.onosproject.net.Link; | 26 | import org.onosproject.net.Link; |
27 | import org.onosproject.net.Path; | 27 | import org.onosproject.net.Path; |
28 | import org.onosproject.net.PortNumber; | 28 | import org.onosproject.net.PortNumber; |
29 | +import org.onosproject.net.intent.ResourceContext; | ||
29 | import org.onosproject.net.provider.ProviderId; | 30 | import org.onosproject.net.provider.ProviderId; |
30 | -import org.onosproject.net.resource.link.LinkResourceService; | ||
31 | 31 | ||
32 | import java.time.Duration; | 32 | import java.time.Duration; |
33 | import java.time.temporal.ChronoUnit; | 33 | import java.time.temporal.ChronoUnit; |
... | @@ -56,7 +56,7 @@ public class LatencyConstraintTest { | ... | @@ -56,7 +56,7 @@ public class LatencyConstraintTest { |
56 | private static final String LATENCY2 = "4.0"; | 56 | private static final String LATENCY2 = "4.0"; |
57 | 57 | ||
58 | private LatencyConstraint sut; | 58 | private LatencyConstraint sut; |
59 | - private LinkResourceService linkResourceService; | 59 | + private ResourceContext resourceContext; |
60 | 60 | ||
61 | private Path path; | 61 | private Path path; |
62 | private Link link1; | 62 | private Link link1; |
... | @@ -64,7 +64,7 @@ public class LatencyConstraintTest { | ... | @@ -64,7 +64,7 @@ public class LatencyConstraintTest { |
64 | 64 | ||
65 | @Before | 65 | @Before |
66 | public void setUp() { | 66 | public void setUp() { |
67 | - linkResourceService = createMock(LinkResourceService.class); | 67 | + resourceContext = createMock(ResourceContext.class); |
68 | 68 | ||
69 | Annotations annotations1 = DefaultAnnotations.builder().set(LATENCY, LATENCY1).build(); | 69 | Annotations annotations1 = DefaultAnnotations.builder().set(LATENCY, LATENCY1).build(); |
70 | Annotations annotations2 = DefaultAnnotations.builder().set(LATENCY, LATENCY2).build(); | 70 | Annotations annotations2 = DefaultAnnotations.builder().set(LATENCY, LATENCY2).build(); |
... | @@ -93,7 +93,7 @@ public class LatencyConstraintTest { | ... | @@ -93,7 +93,7 @@ public class LatencyConstraintTest { |
93 | public void testLessThanLatency() { | 93 | public void testLessThanLatency() { |
94 | sut = new LatencyConstraint(Duration.of(10, ChronoUnit.MICROS)); | 94 | sut = new LatencyConstraint(Duration.of(10, ChronoUnit.MICROS)); |
95 | 95 | ||
96 | - assertThat(sut.validate(path, linkResourceService), is(true)); | 96 | + assertThat(sut.validate(path, resourceContext), is(true)); |
97 | } | 97 | } |
98 | 98 | ||
99 | /** | 99 | /** |
... | @@ -103,7 +103,7 @@ public class LatencyConstraintTest { | ... | @@ -103,7 +103,7 @@ public class LatencyConstraintTest { |
103 | public void testMoreThanLatency() { | 103 | public void testMoreThanLatency() { |
104 | sut = new LatencyConstraint(Duration.of(3, ChronoUnit.MICROS)); | 104 | sut = new LatencyConstraint(Duration.of(3, ChronoUnit.MICROS)); |
105 | 105 | ||
106 | - assertThat(sut.validate(path, linkResourceService), is(false)); | 106 | + assertThat(sut.validate(path, resourceContext), is(false)); |
107 | } | 107 | } |
108 | 108 | ||
109 | /** | 109 | /** |
... | @@ -113,8 +113,8 @@ public class LatencyConstraintTest { | ... | @@ -113,8 +113,8 @@ public class LatencyConstraintTest { |
113 | public void testCost() { | 113 | public void testCost() { |
114 | sut = new LatencyConstraint(Duration.of(10, ChronoUnit.MICROS)); | 114 | sut = new LatencyConstraint(Duration.of(10, ChronoUnit.MICROS)); |
115 | 115 | ||
116 | - assertThat(sut.cost(link1, linkResourceService), is(closeTo(Double.parseDouble(LATENCY1), 1.0e-6))); | 116 | + assertThat(sut.cost(link1, resourceContext), is(closeTo(Double.parseDouble(LATENCY1), 1.0e-6))); |
117 | - assertThat(sut.cost(link2, linkResourceService), is(closeTo(Double.parseDouble(LATENCY2), 1.0e-6))); | 117 | + assertThat(sut.cost(link2, resourceContext), is(closeTo(Double.parseDouble(LATENCY2), 1.0e-6))); |
118 | } | 118 | } |
119 | 119 | ||
120 | /** | 120 | /** | ... | ... |
... | @@ -26,8 +26,8 @@ import org.onosproject.net.DefaultPath; | ... | @@ -26,8 +26,8 @@ import org.onosproject.net.DefaultPath; |
26 | import org.onosproject.net.DeviceId; | 26 | import org.onosproject.net.DeviceId; |
27 | import org.onosproject.net.Path; | 27 | import org.onosproject.net.Path; |
28 | import org.onosproject.net.PortNumber; | 28 | import org.onosproject.net.PortNumber; |
29 | +import org.onosproject.net.intent.ResourceContext; | ||
29 | import org.onosproject.net.provider.ProviderId; | 30 | import org.onosproject.net.provider.ProviderId; |
30 | -import org.onosproject.net.resource.link.LinkResourceService; | ||
31 | 31 | ||
32 | import java.util.Arrays; | 32 | import java.util.Arrays; |
33 | 33 | ||
... | @@ -50,7 +50,7 @@ public class ObstacleConstraintTest { | ... | @@ -50,7 +50,7 @@ public class ObstacleConstraintTest { |
50 | private static final PortNumber PN4 = PortNumber.portNumber(4); | 50 | private static final PortNumber PN4 = PortNumber.portNumber(4); |
51 | private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo"); | 51 | private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo"); |
52 | 52 | ||
53 | - private LinkResourceService linkResourceService; | 53 | + private ResourceContext resourceContext; |
54 | 54 | ||
55 | private Path path; | 55 | private Path path; |
56 | private DefaultLink link2; | 56 | private DefaultLink link2; |
... | @@ -60,7 +60,7 @@ public class ObstacleConstraintTest { | ... | @@ -60,7 +60,7 @@ public class ObstacleConstraintTest { |
60 | 60 | ||
61 | @Before | 61 | @Before |
62 | public void setUp() { | 62 | public void setUp() { |
63 | - linkResourceService = createMock(LinkResourceService.class); | 63 | + resourceContext = createMock(ResourceContext.class); |
64 | 64 | ||
65 | link1 = DefaultLink.builder() | 65 | link1 = DefaultLink.builder() |
66 | .providerId(PROVIDER_ID) | 66 | .providerId(PROVIDER_ID) |
... | @@ -97,7 +97,7 @@ public class ObstacleConstraintTest { | ... | @@ -97,7 +97,7 @@ public class ObstacleConstraintTest { |
97 | public void testPathNotThroughObstacles() { | 97 | public void testPathNotThroughObstacles() { |
98 | sut = new ObstacleConstraint(DID4); | 98 | sut = new ObstacleConstraint(DID4); |
99 | 99 | ||
100 | - assertThat(sut.validate(path, linkResourceService), is(true)); | 100 | + assertThat(sut.validate(path, resourceContext), is(true)); |
101 | } | 101 | } |
102 | 102 | ||
103 | /** | 103 | /** |
... | @@ -107,6 +107,6 @@ public class ObstacleConstraintTest { | ... | @@ -107,6 +107,6 @@ public class ObstacleConstraintTest { |
107 | public void testPathThroughObstacle() { | 107 | public void testPathThroughObstacle() { |
108 | sut = new ObstacleConstraint(DID1); | 108 | sut = new ObstacleConstraint(DID1); |
109 | 109 | ||
110 | - assertThat(sut.validate(path, linkResourceService), is(false)); | 110 | + assertThat(sut.validate(path, resourceContext), is(false)); |
111 | } | 111 | } |
112 | } | 112 | } | ... | ... |
... | @@ -24,8 +24,8 @@ import org.onosproject.net.DeviceId; | ... | @@ -24,8 +24,8 @@ import org.onosproject.net.DeviceId; |
24 | import org.onosproject.net.Path; | 24 | import org.onosproject.net.Path; |
25 | import org.onosproject.net.PortNumber; | 25 | import org.onosproject.net.PortNumber; |
26 | import org.onosproject.net.intent.Constraint; | 26 | import org.onosproject.net.intent.Constraint; |
27 | +import org.onosproject.net.intent.ResourceContext; | ||
27 | import org.onosproject.net.provider.ProviderId; | 28 | import org.onosproject.net.provider.ProviderId; |
28 | -import org.onosproject.net.resource.link.LinkResourceService; | ||
29 | 29 | ||
30 | import java.util.Arrays; | 30 | import java.util.Arrays; |
31 | 31 | ||
... | @@ -52,7 +52,7 @@ public class WaypointConstraintTest { | ... | @@ -52,7 +52,7 @@ public class WaypointConstraintTest { |
52 | private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo"); | 52 | private static final ProviderId PROVIDER_ID = new ProviderId("of", "foo"); |
53 | 53 | ||
54 | private WaypointConstraint sut; | 54 | private WaypointConstraint sut; |
55 | - private LinkResourceService linkResourceService; | 55 | + private ResourceContext resourceContext; |
56 | 56 | ||
57 | private Path path; | 57 | private Path path; |
58 | private DefaultLink link2; | 58 | private DefaultLink link2; |
... | @@ -60,7 +60,7 @@ public class WaypointConstraintTest { | ... | @@ -60,7 +60,7 @@ public class WaypointConstraintTest { |
60 | 60 | ||
61 | @Before | 61 | @Before |
62 | public void setUp() { | 62 | public void setUp() { |
63 | - linkResourceService = createMock(LinkResourceService.class); | 63 | + resourceContext = createMock(ResourceContext.class); |
64 | 64 | ||
65 | link1 = DefaultLink.builder() | 65 | link1 = DefaultLink.builder() |
66 | .providerId(PROVIDER_ID) | 66 | .providerId(PROVIDER_ID) |
... | @@ -85,7 +85,7 @@ public class WaypointConstraintTest { | ... | @@ -85,7 +85,7 @@ public class WaypointConstraintTest { |
85 | public void testSatisfyWaypoints() { | 85 | public void testSatisfyWaypoints() { |
86 | sut = new WaypointConstraint(DID1, DID2, DID3); | 86 | sut = new WaypointConstraint(DID1, DID2, DID3); |
87 | 87 | ||
88 | - assertThat(sut.validate(path, linkResourceService), is(true)); | 88 | + assertThat(sut.validate(path, resourceContext), is(true)); |
89 | } | 89 | } |
90 | 90 | ||
91 | /** | 91 | /** |
... | @@ -95,7 +95,7 @@ public class WaypointConstraintTest { | ... | @@ -95,7 +95,7 @@ public class WaypointConstraintTest { |
95 | public void testNotSatisfyWaypoint() { | 95 | public void testNotSatisfyWaypoint() { |
96 | sut = new WaypointConstraint(DID4); | 96 | sut = new WaypointConstraint(DID4); |
97 | 97 | ||
98 | - assertThat(sut.validate(path, linkResourceService), is(false)); | 98 | + assertThat(sut.validate(path, resourceContext), is(false)); |
99 | } | 99 | } |
100 | 100 | ||
101 | @Test | 101 | @Test | ... | ... |
... | @@ -27,8 +27,8 @@ import org.onosproject.net.intent.Constraint; | ... | @@ -27,8 +27,8 @@ import org.onosproject.net.intent.Constraint; |
27 | import org.onosproject.net.intent.IntentCompiler; | 27 | import org.onosproject.net.intent.IntentCompiler; |
28 | import org.onosproject.net.intent.IntentExtensionService; | 28 | import org.onosproject.net.intent.IntentExtensionService; |
29 | import org.onosproject.net.intent.impl.PathNotFoundException; | 29 | import org.onosproject.net.intent.impl.PathNotFoundException; |
30 | +import org.onosproject.net.newresource.ResourceService; | ||
30 | import org.onosproject.net.provider.ProviderId; | 31 | import org.onosproject.net.provider.ProviderId; |
31 | -import org.onosproject.net.resource.link.LinkResourceService; | ||
32 | import org.onosproject.net.topology.LinkWeight; | 32 | import org.onosproject.net.topology.LinkWeight; |
33 | import org.onosproject.net.topology.PathService; | 33 | import org.onosproject.net.topology.PathService; |
34 | import org.onosproject.net.topology.TopologyEdge; | 34 | import org.onosproject.net.topology.TopologyEdge; |
... | @@ -55,7 +55,7 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent> | ... | @@ -55,7 +55,7 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent> |
55 | protected PathService pathService; | 55 | protected PathService pathService; |
56 | 56 | ||
57 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 57 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
58 | - protected LinkResourceService resourceService; | 58 | + protected ResourceService resourceService; |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * Returns an edge-weight capable of evaluating links on the basis of the | 61 | * Returns an edge-weight capable of evaluating links on the basis of the |
... | @@ -77,7 +77,7 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent> | ... | @@ -77,7 +77,7 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent> |
77 | */ | 77 | */ |
78 | protected boolean checkPath(Path path, List<Constraint> constraints) { | 78 | protected boolean checkPath(Path path, List<Constraint> constraints) { |
79 | for (Constraint constraint : constraints) { | 79 | for (Constraint constraint : constraints) { |
80 | - if (!constraint.validate(path, resourceService)) { | 80 | + if (!constraint.validate(path, resourceService::isAvailable)) { |
81 | return false; | 81 | return false; |
82 | } | 82 | } |
83 | } | 83 | } |
... | @@ -138,9 +138,9 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent> | ... | @@ -138,9 +138,9 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent> |
138 | // the first one with fast fail over the first failure | 138 | // the first one with fast fail over the first failure |
139 | Iterator<Constraint> it = constraints.iterator(); | 139 | Iterator<Constraint> it = constraints.iterator(); |
140 | 140 | ||
141 | - double cost = it.next().cost(edge.link(), resourceService); | 141 | + double cost = it.next().cost(edge.link(), resourceService::isAvailable); |
142 | while (it.hasNext() && cost > 0) { | 142 | while (it.hasNext() && cost > 0) { |
143 | - if (it.next().cost(edge.link(), resourceService) < 0) { | 143 | + if (it.next().cost(edge.link(), resourceService::isAvailable) < 0) { |
144 | return -1; | 144 | return -1; |
145 | } | 145 | } |
146 | } | 146 | } | ... | ... |
... | @@ -110,6 +110,7 @@ public class HostToHostIntentCompilerTest extends AbstractIntentTest { | ... | @@ -110,6 +110,7 @@ public class HostToHostIntentCompilerTest extends AbstractIntentTest { |
110 | new HostToHostIntentCompiler(); | 110 | new HostToHostIntentCompiler(); |
111 | compiler.pathService = new IntentTestsMocks.MockPathService(hops); | 111 | compiler.pathService = new IntentTestsMocks.MockPathService(hops); |
112 | compiler.hostService = mockHostService; | 112 | compiler.hostService = mockHostService; |
113 | + compiler.resourceService = new MockResourceService(); | ||
113 | return compiler; | 114 | return compiler; |
114 | } | 115 | } |
115 | 116 | ... | ... |
... | @@ -33,7 +33,7 @@ import org.onosproject.net.intent.PathIntent; | ... | @@ -33,7 +33,7 @@ import org.onosproject.net.intent.PathIntent; |
33 | import org.onosproject.net.intent.PointToPointIntent; | 33 | import org.onosproject.net.intent.PointToPointIntent; |
34 | import org.onosproject.net.intent.constraint.BandwidthConstraint; | 34 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
35 | import org.onosproject.net.intent.impl.PathNotFoundException; | 35 | import org.onosproject.net.intent.impl.PathNotFoundException; |
36 | -import org.onosproject.net.resource.link.LinkResourceService; | 36 | +import org.onosproject.net.newresource.ResourceService; |
37 | 37 | ||
38 | import java.util.Collections; | 38 | import java.util.Collections; |
39 | import java.util.List; | 39 | import java.util.List; |
... | @@ -118,7 +118,7 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { | ... | @@ -118,7 +118,7 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { |
118 | * @param resourceService service to use for resource allocation requests | 118 | * @param resourceService service to use for resource allocation requests |
119 | * @return point to point compiler | 119 | * @return point to point compiler |
120 | */ | 120 | */ |
121 | - private PointToPointIntentCompiler makeCompiler(String[] hops, LinkResourceService resourceService) { | 121 | + private PointToPointIntentCompiler makeCompiler(String[] hops, ResourceService resourceService) { |
122 | final PointToPointIntentCompiler compiler = new PointToPointIntentCompiler(); | 122 | final PointToPointIntentCompiler compiler = new PointToPointIntentCompiler(); |
123 | compiler.resourceService = resourceService; | 123 | compiler.resourceService = resourceService; |
124 | compiler.pathService = new IntentTestsMocks.MockPathService(hops); | 124 | compiler.pathService = new IntentTestsMocks.MockPathService(hops); |
... | @@ -223,7 +223,7 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { | ... | @@ -223,7 +223,7 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { |
223 | @Test | 223 | @Test |
224 | public void testBandwidthConstrainedIntentSuccess() { | 224 | public void testBandwidthConstrainedIntentSuccess() { |
225 | 225 | ||
226 | - final LinkResourceService resourceService = | 226 | + final ResourceService resourceService = |
227 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0); | 227 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0); |
228 | final List<Constraint> constraints = | 228 | final List<Constraint> constraints = |
229 | Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(100.0))); | 229 | Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(100.0))); |
... | @@ -245,7 +245,7 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { | ... | @@ -245,7 +245,7 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { |
245 | @Test | 245 | @Test |
246 | public void testBandwidthConstrainedIntentFailure() { | 246 | public void testBandwidthConstrainedIntentFailure() { |
247 | 247 | ||
248 | - final LinkResourceService resourceService = | 248 | + final ResourceService resourceService = |
249 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0); | 249 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0); |
250 | final List<Constraint> constraints = | 250 | final List<Constraint> constraints = |
251 | Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(100.0))); | 251 | Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(100.0))); | ... | ... |
-
Please register or login to post a comment