aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java')
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java108
1 files changed, 40 insertions, 68 deletions
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
index eb5b4af8..d6725b7c 100644
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
+++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
@@ -16,7 +16,11 @@
package org.onosproject.net.intent.impl.compiler;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
@@ -24,6 +28,7 @@ import org.onlab.util.Frequency;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
+import org.onosproject.net.IndexedLambda;
import org.onosproject.net.Link;
import org.onosproject.net.OchPort;
import org.onosproject.net.OchSignal;
@@ -38,32 +43,29 @@ import org.onosproject.net.intent.IntentExtensionService;
import org.onosproject.net.intent.OpticalConnectivityIntent;
import org.onosproject.net.intent.OpticalPathIntent;
import org.onosproject.net.intent.impl.IntentCompilationException;
+import org.onosproject.net.newresource.ResourceAllocation;
import org.onosproject.net.newresource.ResourcePath;
import org.onosproject.net.newresource.ResourceService;
-import org.onosproject.net.resource.ResourceType;
-import org.onosproject.net.resource.link.DefaultLinkResourceRequest;
-import org.onosproject.net.resource.link.LambdaResource;
-import org.onosproject.net.resource.link.LambdaResourceAllocation;
import org.onosproject.net.resource.link.LinkResourceAllocations;
-import org.onosproject.net.resource.link.LinkResourceRequest;
-import org.onosproject.net.resource.link.LinkResourceService;
import org.onosproject.net.topology.LinkWeight;
import org.onosproject.net.topology.Topology;
import org.onosproject.net.topology.TopologyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkArgument;
+import static org.onosproject.net.LinkKey.linkKey;
/**
* An intent compiler for {@link org.onosproject.net.intent.OpticalConnectivityIntent}.
*/
// For now, remove component designation until dependency on the new resource manager is available.
-// @Component(immediate = true)
+@Component(immediate = true)
public class OpticalConnectivityIntentCompiler implements IntentCompiler<OpticalConnectivityIntent> {
protected static final Logger log = LoggerFactory.getLogger(OpticalConnectivityIntentCompiler.class);
@@ -80,9 +82,6 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ResourceService resourceService;
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected LinkResourceService linkResourceService;
-
@Activate
public void activate() {
intentManager.registerCompiler(OpticalConnectivityIntent.class, this);
@@ -138,13 +137,12 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
ochSignal = srcOchPort.lambda();
} else {
// Request and reserve lambda on path
- LinkResourceAllocations linkAllocs = assignWavelength(intent, path);
- if (linkAllocs == null) {
+ IndexedLambda lambda = assignWavelength(intent, path);
+ if (lambda == null) {
continue;
}
- LambdaResourceAllocation lambdaAlloc = getWavelength(path, linkAllocs);
OmsPort omsPort = (OmsPort) deviceService.getPort(path.src().deviceId(), path.src().port());
- ochSignal = new OchSignal(lambdaAlloc.lambda().toInt(), omsPort.maxFrequency(), omsPort.grid());
+ ochSignal = new OchSignal((int) lambda.index(), omsPort.maxFrequency(), omsPort.grid());
}
// Create installable optical path intent
@@ -171,72 +169,46 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
}
/**
- * Find the lambda allocated to the path.
- *
- * @param path the path
- * @param linkAllocs the link allocations
- * @return lambda allocated to the given path
- */
- private LambdaResourceAllocation getWavelength(Path path, LinkResourceAllocations linkAllocs) {
- return path.links().stream()
- .flatMap(x -> linkAllocs.getResourceAllocation(x).stream())
- .filter(x -> x.type() == ResourceType.LAMBDA)
- .findFirst()
- .map(x -> (LambdaResourceAllocation) x)
- .orElse(null);
- }
-
- /**
* Request and reserve first available wavelength across path.
*
* @param path path in WDM topology
- * @return first available lambda resource allocation
+ * @return first available lambda allocated
*/
- private LinkResourceAllocations assignWavelength(Intent intent, Path path) {
- LinkResourceRequest.Builder request =
- DefaultLinkResourceRequest.builder(intent.id(), path.links())
- .addLambdaRequest();
-
- LinkResourceAllocations allocations = linkResourceService.requestResources(request.build());
-
- if (!checkWavelengthContinuity(allocations, path)) {
- linkResourceService.releaseResources(allocations);
+ private IndexedLambda assignWavelength(Intent intent, Path path) {
+ Set<IndexedLambda> lambdas = findCommonLambdasOverLinks(path.links());
+ if (lambdas.isEmpty()) {
return null;
}
- return allocations;
- }
+ IndexedLambda minLambda = findFirstLambda(lambdas);
+ List<ResourcePath> lambdaResources = path.links().stream()
+ .map(x -> new ResourcePath(linkKey(x.src(), x.dst())))
+ .map(x -> ResourcePath.child(x, minLambda))
+ .collect(Collectors.toList());
- /**
- * Checks wavelength continuity constraint across path, i.e., an identical lambda is used on all links.
- * @return true if wavelength continuity is met, false otherwise
- */
- private boolean checkWavelengthContinuity(LinkResourceAllocations allocations, Path path) {
- if (allocations == null) {
- return false;
+ List<ResourceAllocation> allocations = resourceService.allocate(intent.id(), lambdaResources);
+ if (allocations.isEmpty()) {
+ log.info("Resource allocation for {} failed (resource request: {})", intent, lambdaResources);
}
- List<LambdaResource> lambdas = path.links().stream()
- .flatMap(x -> allocations.getResourceAllocation(x).stream())
- .filter(x -> x.type() == ResourceType.LAMBDA)
- .map(x -> ((LambdaResourceAllocation) x).lambda())
- .collect(Collectors.toList());
+ return minLambda;
+ }
- LambdaResource lambda = null;
- for (LambdaResource nextLambda: lambdas) {
- if (nextLambda == null) {
- return false;
- }
- if (lambda == null) {
- lambda = nextLambda;
- continue;
- }
- if (!lambda.equals(nextLambda)) {
- return false;
- }
- }
+ private Set<IndexedLambda> findCommonLambdasOverLinks(List<Link> links) {
+ return links.stream()
+ .map(x -> new ResourcePath(linkKey(x.src(), x.dst())))
+ .map(resourceService::getAvailableResources)
+ .map(x -> Iterables.filter(x, r -> r.lastComponent() instanceof IndexedLambda))
+ .map(x -> Iterables.transform(x, r -> (IndexedLambda) r.lastComponent()))
+ .map(x -> (Set<IndexedLambda>) ImmutableSet.copyOf(x))
+ .reduce(Sets::intersection)
+ .orElse(Collections.emptySet());
+ }
- return true;
+ private IndexedLambda findFirstLambda(Set<IndexedLambda> lambdas) {
+ return lambdas.stream()
+ .findFirst()
+ .get();
}
private ConnectPoint staticPort(ConnectPoint connectPoint) {