Sho SHIMIZU
Committed by Gerrit Code Review

Remove dependency on LinkResourceService from optical intent compiler

Change-Id: I1fae0a33817de973676a02cf40d4bb378aac0460
...@@ -28,6 +28,7 @@ import org.onlab.util.Frequency; ...@@ -28,6 +28,7 @@ import org.onlab.util.Frequency;
28 import org.onosproject.net.AnnotationKeys; 28 import org.onosproject.net.AnnotationKeys;
29 import org.onosproject.net.ConnectPoint; 29 import org.onosproject.net.ConnectPoint;
30 import org.onosproject.net.DeviceId; 30 import org.onosproject.net.DeviceId;
31 +import org.onosproject.net.IndexedLambda;
31 import org.onosproject.net.Link; 32 import org.onosproject.net.Link;
32 import org.onosproject.net.OchPort; 33 import org.onosproject.net.OchPort;
33 import org.onosproject.net.OchSignal; 34 import org.onosproject.net.OchSignal;
...@@ -42,16 +43,10 @@ import org.onosproject.net.intent.IntentExtensionService; ...@@ -42,16 +43,10 @@ import org.onosproject.net.intent.IntentExtensionService;
42 import org.onosproject.net.intent.OpticalConnectivityIntent; 43 import org.onosproject.net.intent.OpticalConnectivityIntent;
43 import org.onosproject.net.intent.OpticalPathIntent; 44 import org.onosproject.net.intent.OpticalPathIntent;
44 import org.onosproject.net.intent.impl.IntentCompilationException; 45 import org.onosproject.net.intent.impl.IntentCompilationException;
46 +import org.onosproject.net.newresource.ResourceAllocation;
45 import org.onosproject.net.newresource.ResourcePath; 47 import org.onosproject.net.newresource.ResourcePath;
46 import org.onosproject.net.newresource.ResourceService; 48 import org.onosproject.net.newresource.ResourceService;
47 -import org.onosproject.net.resource.ResourceType;
48 -import org.onosproject.net.resource.link.DefaultLinkResourceRequest;
49 -import org.onosproject.net.resource.link.LambdaResource;
50 -import org.onosproject.net.resource.link.LambdaResourceAllocation;
51 -import org.onosproject.net.resource.link.LambdaResourceRequest;
52 import org.onosproject.net.resource.link.LinkResourceAllocations; 49 import org.onosproject.net.resource.link.LinkResourceAllocations;
53 -import org.onosproject.net.resource.link.LinkResourceRequest;
54 -import org.onosproject.net.resource.link.LinkResourceService;
55 import org.onosproject.net.topology.LinkWeight; 50 import org.onosproject.net.topology.LinkWeight;
56 import org.onosproject.net.topology.Topology; 51 import org.onosproject.net.topology.Topology;
57 import org.onosproject.net.topology.TopologyService; 52 import org.onosproject.net.topology.TopologyService;
...@@ -64,6 +59,7 @@ import java.util.Set; ...@@ -64,6 +59,7 @@ import java.util.Set;
64 import java.util.stream.Collectors; 59 import java.util.stream.Collectors;
65 60
66 import static com.google.common.base.Preconditions.checkArgument; 61 import static com.google.common.base.Preconditions.checkArgument;
62 +import static org.onosproject.net.LinkKey.linkKey;
67 63
68 /** 64 /**
69 * An intent compiler for {@link org.onosproject.net.intent.OpticalConnectivityIntent}. 65 * An intent compiler for {@link org.onosproject.net.intent.OpticalConnectivityIntent}.
...@@ -86,9 +82,6 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical ...@@ -86,9 +82,6 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
86 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 82 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
87 protected ResourceService resourceService; 83 protected ResourceService resourceService;
88 84
89 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
90 - protected LinkResourceService linkResourceService;
91 -
92 @Activate 85 @Activate
93 public void activate() { 86 public void activate() {
94 intentManager.registerCompiler(OpticalConnectivityIntent.class, this); 87 intentManager.registerCompiler(OpticalConnectivityIntent.class, this);
...@@ -144,13 +137,12 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical ...@@ -144,13 +137,12 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
144 ochSignal = srcOchPort.lambda(); 137 ochSignal = srcOchPort.lambda();
145 } else { 138 } else {
146 // Request and reserve lambda on path 139 // Request and reserve lambda on path
147 - LinkResourceAllocations linkAllocs = assignWavelength(intent, path); 140 + IndexedLambda lambda = assignWavelength(intent, path);
148 - if (linkAllocs == null) { 141 + if (lambda == null) {
149 continue; 142 continue;
150 } 143 }
151 - LambdaResourceAllocation lambdaAlloc = getWavelength(path, linkAllocs);
152 OmsPort omsPort = (OmsPort) deviceService.getPort(path.src().deviceId(), path.src().port()); 144 OmsPort omsPort = (OmsPort) deviceService.getPort(path.src().deviceId(), path.src().port());
153 - ochSignal = new OchSignal(lambdaAlloc.lambda().toInt(), omsPort.maxFrequency(), omsPort.grid()); 145 + ochSignal = new OchSignal((int) lambda.index(), omsPort.maxFrequency(), omsPort.grid());
154 } 146 }
155 147
156 // Create installable optical path intent 148 // Create installable optical path intent
...@@ -177,99 +169,48 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical ...@@ -177,99 +169,48 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
177 } 169 }
178 170
179 /** 171 /**
180 - * Find the lambda allocated to the path.
181 - *
182 - * @param path the path
183 - * @param linkAllocs the link allocations
184 - * @return lambda allocated to the given path
185 - */
186 - private LambdaResourceAllocation getWavelength(Path path, LinkResourceAllocations linkAllocs) {
187 - return path.links().stream()
188 - .flatMap(x -> linkAllocs.getResourceAllocation(x).stream())
189 - .filter(x -> x.type() == ResourceType.LAMBDA)
190 - .findFirst()
191 - .map(x -> (LambdaResourceAllocation) x)
192 - .orElse(null);
193 - }
194 -
195 - /**
196 * Request and reserve first available wavelength across path. 172 * Request and reserve first available wavelength across path.
197 * 173 *
198 * @param path path in WDM topology 174 * @param path path in WDM topology
199 - * @return first available lambda resource allocation 175 + * @return first available lambda allocated
200 */ 176 */
201 - private LinkResourceAllocations assignWavelength(Intent intent, Path path) { 177 + private IndexedLambda assignWavelength(Intent intent, Path path) {
202 - Set<LambdaResource> lambdas = findCommonLambdasOverLinks(path.links()); 178 + Set<IndexedLambda> lambdas = findCommonLambdasOverLinks(path.links());
203 if (lambdas.isEmpty()) { 179 if (lambdas.isEmpty()) {
204 return null; 180 return null;
205 } 181 }
206 182
207 - LambdaResource minLambda = findFirstLambda(lambdas); 183 + IndexedLambda minLambda = findFirstLambda(lambdas);
208 - 184 + List<ResourcePath> lambdaResources = path.links().stream()
209 - LinkResourceRequest request = 185 + .map(x -> new ResourcePath(linkKey(x.src(), x.dst())))
210 - DefaultLinkResourceRequest.builder(intent.id(), path.links()) 186 + .map(x -> ResourcePath.child(x, minLambda))
211 - .addLambdaRequest(minLambda) 187 + .collect(Collectors.toList());
212 - .build();
213 -
214 - LinkResourceAllocations allocations = linkResourceService.requestResources(request);
215 188
216 - if (!checkWavelengthContinuity(allocations, path)) { 189 + List<ResourceAllocation> allocations = resourceService.allocate(intent.id(), lambdaResources);
217 - linkResourceService.releaseResources(allocations); 190 + if (allocations.isEmpty()) {
218 - return null; 191 + log.info("Resource allocation for {} failed (resource request: {})", intent, lambdaResources);
219 } 192 }
220 193
221 - return allocations; 194 + return minLambda;
222 } 195 }
223 196
224 - private Set<LambdaResource> findCommonLambdasOverLinks(List<Link> links) { 197 + private Set<IndexedLambda> findCommonLambdasOverLinks(List<Link> links) {
225 return links.stream() 198 return links.stream()
226 - .map(x -> ImmutableSet.copyOf(linkResourceService.getAvailableResources(x))) 199 + .map(x -> new ResourcePath(linkKey(x.src(), x.dst())))
227 - .map(x -> Sets.filter(x, req -> req instanceof LambdaResourceRequest)) 200 + .map(resourceService::getAvailableResources)
228 - .map(x -> Iterables.transform(x, req -> (LambdaResourceRequest) req)) 201 + .map(x -> Iterables.filter(x, r -> r.lastComponent() instanceof IndexedLambda))
229 - .map(x -> Iterables.transform(x, LambdaResourceRequest::lambda)) 202 + .map(x -> Iterables.transform(x, r -> (IndexedLambda) r.lastComponent()))
230 - .map(x -> (Set<LambdaResource>) ImmutableSet.copyOf(x)) 203 + .map(x -> (Set<IndexedLambda>) ImmutableSet.copyOf(x))
231 .reduce(Sets::intersection) 204 .reduce(Sets::intersection)
232 .orElse(Collections.emptySet()); 205 .orElse(Collections.emptySet());
233 } 206 }
234 207
235 - private LambdaResource findFirstLambda(Set<LambdaResource> lambdas) { 208 + private IndexedLambda findFirstLambda(Set<IndexedLambda> lambdas) {
236 return lambdas.stream() 209 return lambdas.stream()
237 .findFirst() 210 .findFirst()
238 .get(); 211 .get();
239 } 212 }
240 213
241 - /**
242 - * Checks wavelength continuity constraint across path, i.e., an identical lambda is used on all links.
243 - * @return true if wavelength continuity is met, false otherwise
244 - */
245 - private boolean checkWavelengthContinuity(LinkResourceAllocations allocations, Path path) {
246 - if (allocations == null) {
247 - return false;
248 - }
249 -
250 - List<LambdaResource> lambdas = path.links().stream()
251 - .flatMap(x -> allocations.getResourceAllocation(x).stream())
252 - .filter(x -> x.type() == ResourceType.LAMBDA)
253 - .map(x -> ((LambdaResourceAllocation) x).lambda())
254 - .collect(Collectors.toList());
255 -
256 - LambdaResource lambda = null;
257 - for (LambdaResource nextLambda: lambdas) {
258 - if (nextLambda == null) {
259 - return false;
260 - }
261 - if (lambda == null) {
262 - lambda = nextLambda;
263 - continue;
264 - }
265 - if (!lambda.equals(nextLambda)) {
266 - return false;
267 - }
268 - }
269 -
270 - return true;
271 - }
272 -
273 private ConnectPoint staticPort(ConnectPoint connectPoint) { 214 private ConnectPoint staticPort(ConnectPoint connectPoint) {
274 Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port()); 215 Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port());
275 216
......