Committed by
Ray Milkey
Move wavelength selection logic to OpticalConnectivityIntentCompiler
Now, LinkResourceManager doesn't have a logic to select lambda(s) Change-Id: I008d770f4f142f3d67afa734e50bd8761a0aafd2
Showing
5 changed files
with
94 additions
and
52 deletions
... | @@ -20,6 +20,7 @@ import java.util.HashSet; | ... | @@ -20,6 +20,7 @@ import java.util.HashSet; |
20 | import java.util.Set; | 20 | import java.util.Set; |
21 | import java.util.Objects; | 21 | import java.util.Objects; |
22 | 22 | ||
23 | +import com.google.common.annotations.Beta; | ||
23 | import org.onlab.util.Bandwidth; | 24 | import org.onlab.util.Bandwidth; |
24 | import org.onosproject.net.Link; | 25 | import org.onosproject.net.Link; |
25 | import org.onosproject.net.intent.Constraint; | 26 | import org.onosproject.net.intent.Constraint; |
... | @@ -114,13 +115,22 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { | ... | @@ -114,13 +115,22 @@ public final class DefaultLinkResourceRequest implements LinkResourceRequest { |
114 | * Adds lambda request. | 115 | * Adds lambda request. |
115 | * | 116 | * |
116 | * @return self | 117 | * @return self |
118 | + * @deprecated in Emu Release | ||
117 | */ | 119 | */ |
120 | + @Deprecated | ||
118 | @Override | 121 | @Override |
119 | public Builder addLambdaRequest() { | 122 | public Builder addLambdaRequest() { |
120 | resources.add(new LambdaResourceRequest()); | 123 | resources.add(new LambdaResourceRequest()); |
121 | return this; | 124 | return this; |
122 | } | 125 | } |
123 | 126 | ||
127 | + @Beta | ||
128 | + @Override | ||
129 | + public LinkResourceRequest.Builder addLambdaRequest(LambdaResource lambda) { | ||
130 | + resources.add(new LambdaResourceRequest(lambda)); | ||
131 | + return this; | ||
132 | + } | ||
133 | + | ||
124 | /** | 134 | /** |
125 | * Adds Mpls request. | 135 | * Adds Mpls request. |
126 | * | 136 | * | ... | ... |
... | @@ -15,15 +15,50 @@ | ... | @@ -15,15 +15,50 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.resource.link; | 16 | package org.onosproject.net.resource.link; |
17 | 17 | ||
18 | +import com.google.common.annotations.Beta; | ||
18 | import com.google.common.base.MoreObjects; | 19 | import com.google.common.base.MoreObjects; |
19 | import org.onosproject.net.resource.ResourceRequest; | 20 | import org.onosproject.net.resource.ResourceRequest; |
20 | import org.onosproject.net.resource.ResourceType; | 21 | import org.onosproject.net.resource.ResourceType; |
21 | 22 | ||
23 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
24 | + | ||
22 | /** | 25 | /** |
23 | * Representation of a request for lambda resource. | 26 | * Representation of a request for lambda resource. |
24 | */ | 27 | */ |
25 | public class LambdaResourceRequest implements ResourceRequest { | 28 | public class LambdaResourceRequest implements ResourceRequest { |
26 | 29 | ||
30 | + private final LambdaResource lambda; | ||
31 | + | ||
32 | + /** | ||
33 | + * Constructs a request specifying the given lambda. | ||
34 | + * | ||
35 | + * @param lambda lambda to be requested | ||
36 | + */ | ||
37 | + @Beta | ||
38 | + public LambdaResourceRequest(LambdaResource lambda) { | ||
39 | + this.lambda = checkNotNull(lambda); | ||
40 | + } | ||
41 | + | ||
42 | + /** | ||
43 | + * Constructs a request asking an arbitrary available lambda. | ||
44 | + * | ||
45 | + * @deprecated in Emu Release | ||
46 | + */ | ||
47 | + @Deprecated | ||
48 | + public LambdaResourceRequest() { | ||
49 | + this.lambda = null; | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * Returns the lambda this request expects. | ||
54 | + * | ||
55 | + * @return the lambda this request expects | ||
56 | + */ | ||
57 | + @Beta | ||
58 | + public LambdaResource lambda() { | ||
59 | + return lambda; | ||
60 | + } | ||
61 | + | ||
27 | @Override | 62 | @Override |
28 | public ResourceType type() { | 63 | public ResourceType type() { |
29 | return ResourceType.LAMBDA; | 64 | return ResourceType.LAMBDA; | ... | ... |
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.resource.link; | 16 | package org.onosproject.net.resource.link; |
17 | 17 | ||
18 | +import com.google.common.annotations.Beta; | ||
18 | import org.onosproject.net.Link; | 19 | import org.onosproject.net.Link; |
19 | import org.onosproject.net.intent.Constraint; | 20 | import org.onosproject.net.intent.Constraint; |
20 | import org.onosproject.net.intent.IntentId; | 21 | import org.onosproject.net.intent.IntentId; |
... | @@ -57,10 +58,21 @@ public interface LinkResourceRequest extends ResourceRequest { | ... | @@ -57,10 +58,21 @@ public interface LinkResourceRequest extends ResourceRequest { |
57 | * Adds lambda request. | 58 | * Adds lambda request. |
58 | * | 59 | * |
59 | * @return self | 60 | * @return self |
61 | + * @deprecated in Emu Release | ||
60 | */ | 62 | */ |
63 | + @Deprecated | ||
61 | Builder addLambdaRequest(); | 64 | Builder addLambdaRequest(); |
62 | 65 | ||
63 | /** | 66 | /** |
67 | + * Adds lambda request. | ||
68 | + * | ||
69 | + * @param lambda lambda to be requested | ||
70 | + * @return self | ||
71 | + */ | ||
72 | + @Beta | ||
73 | + Builder addLambdaRequest(LambdaResource lambda); | ||
74 | + | ||
75 | + /** | ||
64 | * Adds MPLS request. | 76 | * Adds MPLS request. |
65 | * | 77 | * |
66 | * @return self | 78 | * @return self | ... | ... |
... | @@ -16,6 +16,9 @@ | ... | @@ -16,6 +16,9 @@ |
16 | package org.onosproject.net.intent.impl.compiler; | 16 | package org.onosproject.net.intent.impl.compiler; |
17 | 17 | ||
18 | import com.google.common.collect.ImmutableList; | 18 | import com.google.common.collect.ImmutableList; |
19 | +import com.google.common.collect.ImmutableSet; | ||
20 | +import com.google.common.collect.Iterables; | ||
21 | +import com.google.common.collect.Sets; | ||
19 | import org.apache.felix.scr.annotations.Activate; | 22 | import org.apache.felix.scr.annotations.Activate; |
20 | import org.apache.felix.scr.annotations.Component; | 23 | import org.apache.felix.scr.annotations.Component; |
21 | import org.apache.felix.scr.annotations.Deactivate; | 24 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -45,6 +48,7 @@ import org.onosproject.net.resource.ResourceType; | ... | @@ -45,6 +48,7 @@ import org.onosproject.net.resource.ResourceType; |
45 | import org.onosproject.net.resource.link.DefaultLinkResourceRequest; | 48 | import org.onosproject.net.resource.link.DefaultLinkResourceRequest; |
46 | import org.onosproject.net.resource.link.LambdaResource; | 49 | import org.onosproject.net.resource.link.LambdaResource; |
47 | import org.onosproject.net.resource.link.LambdaResourceAllocation; | 50 | import org.onosproject.net.resource.link.LambdaResourceAllocation; |
51 | +import org.onosproject.net.resource.link.LambdaResourceRequest; | ||
48 | import org.onosproject.net.resource.link.LinkResourceAllocations; | 52 | import org.onosproject.net.resource.link.LinkResourceAllocations; |
49 | import org.onosproject.net.resource.link.LinkResourceRequest; | 53 | import org.onosproject.net.resource.link.LinkResourceRequest; |
50 | import org.onosproject.net.resource.link.LinkResourceService; | 54 | import org.onosproject.net.resource.link.LinkResourceService; |
... | @@ -54,6 +58,7 @@ import org.onosproject.net.topology.TopologyService; | ... | @@ -54,6 +58,7 @@ import org.onosproject.net.topology.TopologyService; |
54 | import org.slf4j.Logger; | 58 | import org.slf4j.Logger; |
55 | import org.slf4j.LoggerFactory; | 59 | import org.slf4j.LoggerFactory; |
56 | 60 | ||
61 | +import java.util.Collections; | ||
57 | import java.util.List; | 62 | import java.util.List; |
58 | import java.util.Set; | 63 | import java.util.Set; |
59 | import java.util.stream.Collectors; | 64 | import java.util.stream.Collectors; |
... | @@ -194,11 +199,19 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical | ... | @@ -194,11 +199,19 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical |
194 | * @return first available lambda resource allocation | 199 | * @return first available lambda resource allocation |
195 | */ | 200 | */ |
196 | private LinkResourceAllocations assignWavelength(Intent intent, Path path) { | 201 | private LinkResourceAllocations assignWavelength(Intent intent, Path path) { |
197 | - LinkResourceRequest.Builder request = | 202 | + Set<LambdaResource> lambdas = findCommonLambdasOverLinks(path.links()); |
203 | + if (lambdas.isEmpty()) { | ||
204 | + return null; | ||
205 | + } | ||
206 | + | ||
207 | + LambdaResource minLambda = findFirstLambda(lambdas); | ||
208 | + | ||
209 | + LinkResourceRequest request = | ||
198 | DefaultLinkResourceRequest.builder(intent.id(), path.links()) | 210 | DefaultLinkResourceRequest.builder(intent.id(), path.links()) |
199 | - .addLambdaRequest(); | 211 | + .addLambdaRequest(minLambda) |
212 | + .build(); | ||
200 | 213 | ||
201 | - LinkResourceAllocations allocations = linkResourceService.requestResources(request.build()); | 214 | + LinkResourceAllocations allocations = linkResourceService.requestResources(request); |
202 | 215 | ||
203 | if (!checkWavelengthContinuity(allocations, path)) { | 216 | if (!checkWavelengthContinuity(allocations, path)) { |
204 | linkResourceService.releaseResources(allocations); | 217 | linkResourceService.releaseResources(allocations); |
... | @@ -208,6 +221,23 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical | ... | @@ -208,6 +221,23 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical |
208 | return allocations; | 221 | return allocations; |
209 | } | 222 | } |
210 | 223 | ||
224 | + private Set<LambdaResource> findCommonLambdasOverLinks(List<Link> links) { | ||
225 | + return links.stream() | ||
226 | + .map(x -> ImmutableSet.copyOf(linkResourceService.getAvailableResources(x))) | ||
227 | + .map(x -> Sets.filter(x, req -> req instanceof LambdaResourceRequest)) | ||
228 | + .map(x -> Iterables.transform(x, req -> (LambdaResourceRequest) req)) | ||
229 | + .map(x -> Iterables.transform(x, LambdaResourceRequest::lambda)) | ||
230 | + .map(x -> (Set<LambdaResource>) ImmutableSet.copyOf(x)) | ||
231 | + .reduce(Sets::intersection) | ||
232 | + .orElse(Collections.emptySet()); | ||
233 | + } | ||
234 | + | ||
235 | + private LambdaResource findFirstLambda(Set<LambdaResource> lambdas) { | ||
236 | + return lambdas.stream() | ||
237 | + .findFirst() | ||
238 | + .get(); | ||
239 | + } | ||
240 | + | ||
211 | /** | 241 | /** |
212 | * Checks wavelength continuity constraint across path, i.e., an identical lambda is used on all links. | 242 | * Checks wavelength continuity constraint across path, i.e., an identical lambda is used on all links. |
213 | * @return true if wavelength continuity is met, false otherwise | 243 | * @return true if wavelength continuity is met, false otherwise | ... | ... |
... | @@ -15,7 +15,6 @@ | ... | @@ -15,7 +15,6 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.resource.impl; | 16 | package org.onosproject.net.resource.impl; |
17 | 17 | ||
18 | -import com.google.common.collect.ImmutableList; | ||
19 | import com.google.common.collect.Sets; | 18 | import com.google.common.collect.Sets; |
20 | import org.apache.felix.scr.annotations.Activate; | 19 | import org.apache.felix.scr.annotations.Activate; |
21 | import org.apache.felix.scr.annotations.Component; | 20 | import org.apache.felix.scr.annotations.Component; |
... | @@ -32,7 +31,6 @@ import org.onosproject.net.resource.ResourceType; | ... | @@ -32,7 +31,6 @@ import org.onosproject.net.resource.ResourceType; |
32 | import org.onosproject.net.resource.link.BandwidthResourceAllocation; | 31 | import org.onosproject.net.resource.link.BandwidthResourceAllocation; |
33 | import org.onosproject.net.resource.link.BandwidthResourceRequest; | 32 | import org.onosproject.net.resource.link.BandwidthResourceRequest; |
34 | import org.onosproject.net.resource.link.DefaultLinkResourceAllocations; | 33 | import org.onosproject.net.resource.link.DefaultLinkResourceAllocations; |
35 | -import org.onosproject.net.resource.link.LambdaResource; | ||
36 | import org.onosproject.net.resource.link.LambdaResourceAllocation; | 34 | import org.onosproject.net.resource.link.LambdaResourceAllocation; |
37 | import org.onosproject.net.resource.link.LambdaResourceRequest; | 35 | import org.onosproject.net.resource.link.LambdaResourceRequest; |
38 | import org.onosproject.net.resource.link.LinkResourceAllocations; | 36 | import org.onosproject.net.resource.link.LinkResourceAllocations; |
... | @@ -47,7 +45,6 @@ import org.onosproject.net.resource.link.MplsLabelResourceAllocation; | ... | @@ -47,7 +45,6 @@ import org.onosproject.net.resource.link.MplsLabelResourceAllocation; |
47 | import org.onosproject.net.resource.link.MplsLabelResourceRequest; | 45 | import org.onosproject.net.resource.link.MplsLabelResourceRequest; |
48 | import org.slf4j.Logger; | 46 | import org.slf4j.Logger; |
49 | 47 | ||
50 | -import java.util.Collection; | ||
51 | import java.util.Collections; | 48 | import java.util.Collections; |
52 | import java.util.HashMap; | 49 | import java.util.HashMap; |
53 | import java.util.HashSet; | 50 | import java.util.HashSet; |
... | @@ -55,7 +52,6 @@ import java.util.Iterator; | ... | @@ -55,7 +52,6 @@ import java.util.Iterator; |
55 | import java.util.Map; | 52 | import java.util.Map; |
56 | import java.util.Set; | 53 | import java.util.Set; |
57 | 54 | ||
58 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
59 | import static org.onosproject.security.AppGuard.checkPermission; | 55 | import static org.onosproject.security.AppGuard.checkPermission; |
60 | import static org.slf4j.LoggerFactory.getLogger; | 56 | import static org.slf4j.LoggerFactory.getLogger; |
61 | import static org.onosproject.security.AppPermission.Type.*; | 57 | import static org.onosproject.security.AppPermission.Type.*; |
... | @@ -87,42 +83,6 @@ public class LinkResourceManager | ... | @@ -87,42 +83,6 @@ public class LinkResourceManager |
87 | log.info("Stopped"); | 83 | log.info("Stopped"); |
88 | } | 84 | } |
89 | 85 | ||
90 | - /** | ||
91 | - * Returns available lambdas on specified link. | ||
92 | - * | ||
93 | - * @param link the link | ||
94 | - * @return available lambdas on specified link | ||
95 | - */ | ||
96 | - private Set<LambdaResource> getAvailableLambdas(Link link) { | ||
97 | - checkNotNull(link); | ||
98 | - Set<ResourceAllocation> resAllocs = store.getFreeResources(link); | ||
99 | - if (resAllocs == null) { | ||
100 | - return Collections.emptySet(); | ||
101 | - } | ||
102 | - Set<LambdaResource> lambdas = new HashSet<>(); | ||
103 | - for (ResourceAllocation res : resAllocs) { | ||
104 | - if (res.type() == ResourceType.LAMBDA) { | ||
105 | - lambdas.add(((LambdaResourceAllocation) res).lambda()); | ||
106 | - } | ||
107 | - } | ||
108 | - return lambdas; | ||
109 | - } | ||
110 | - | ||
111 | - | ||
112 | - /** | ||
113 | - * Returns available lambdas on specified links. | ||
114 | - * | ||
115 | - * @param links the links | ||
116 | - * @return available lambdas on specified links | ||
117 | - */ | ||
118 | - private Collection<LambdaResource> getAvailableLambdas(Iterable<Link> links) { | ||
119 | - checkNotNull(links); | ||
120 | - return ImmutableList.copyOf(links).stream() | ||
121 | - .map(this::getAvailableLambdas) | ||
122 | - .reduce(Sets::intersection) | ||
123 | - .orElse(Collections.emptySet()); | ||
124 | - } | ||
125 | - | ||
126 | 86 | ||
127 | /** | 87 | /** |
128 | * Returns available MPLS label on specified link. | 88 | * Returns available MPLS label on specified link. |
... | @@ -162,14 +122,8 @@ public class LinkResourceManager | ... | @@ -162,14 +122,8 @@ public class LinkResourceManager |
162 | allocs.add(new BandwidthResourceAllocation(br.bandwidth())); | 122 | allocs.add(new BandwidthResourceAllocation(br.bandwidth())); |
163 | break; | 123 | break; |
164 | case LAMBDA: | 124 | case LAMBDA: |
165 | - Iterator<LambdaResource> lambdaIterator = | 125 | + LambdaResourceRequest lr = (LambdaResourceRequest) r; |
166 | - getAvailableLambdas(req.links()).iterator(); | 126 | + allocs.add(new LambdaResourceAllocation(lr.lambda())); |
167 | - if (lambdaIterator.hasNext()) { | ||
168 | - allocs.add(new LambdaResourceAllocation(lambdaIterator.next())); | ||
169 | - } else { | ||
170 | - log.info("Failed to allocate lambda resource."); | ||
171 | - return null; | ||
172 | - } | ||
173 | break; | 127 | break; |
174 | case MPLS_LABEL: | 128 | case MPLS_LABEL: |
175 | for (Link link : req.links()) { | 129 | for (Link link : req.links()) { |
... | @@ -256,7 +210,8 @@ public class LinkResourceManager | ... | @@ -256,7 +210,8 @@ public class LinkResourceManager |
256 | ((BandwidthResourceAllocation) alloc).bandwidth())); | 210 | ((BandwidthResourceAllocation) alloc).bandwidth())); |
257 | break; | 211 | break; |
258 | case LAMBDA: | 212 | case LAMBDA: |
259 | - result.add(new LambdaResourceRequest()); | 213 | + result.add(new LambdaResourceRequest( |
214 | + ((LambdaResourceAllocation) alloc).lambda())); | ||
260 | break; | 215 | break; |
261 | case MPLS_LABEL: | 216 | case MPLS_LABEL: |
262 | result.add(new MplsLabelResourceRequest()); | 217 | result.add(new MplsLabelResourceRequest()); | ... | ... |
-
Please register or login to post a comment