diff options
Diffstat (limited to 'framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl')
6 files changed, 99 insertions, 74 deletions
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentCleanup.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentCleanup.java index d7fa3223..417627ad 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentCleanup.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentCleanup.java @@ -196,7 +196,7 @@ public class IntentCleanup implements Runnable, IntentListener { service.withdraw(intentData.intent()); break; default: - log.warn("Trying to resubmit pending intent {} in state {} with request {}", + log.warn("Failed to resubmit pending intent {} in state {} with request {}", intentData.key(), intentData.state(), intentData.request()); break; } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java index 4c828e77..baa3bf4d 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java @@ -256,15 +256,16 @@ public class IntentManager submit(intent); } - // If required, compile all currently failed intents. - for (Intent intent : getIntents()) { - IntentState state = getIntentState(intent.key()); - if ((compileAllFailed && RECOMPILE.contains(state)) - || intentAllowsPartialFailure(intent)) { - if (WITHDRAW.contains(state)) { - withdraw(intent); - } else { - submit(intent); + if (compileAllFailed) { + // If required, compile all currently failed intents. + for (Intent intent : getIntents()) { + IntentState state = getIntentState(intent.key()); + if (RECOMPILE.contains(state) || intentAllowsPartialFailure(intent)) { + if (WITHDRAW.contains(state)) { + withdraw(intent); + } else { + submit(intent); + } } } } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java index 5710aced..5ebc812e 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java @@ -16,8 +16,8 @@ package org.onosproject.net.intent.impl; import com.google.common.collect.HashMultimap; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.common.collect.SetMultimap; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; @@ -61,7 +61,6 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -91,8 +90,6 @@ public class ObjectiveTracker implements ObjectiveTrackerService { private final Logger log = getLogger(getClass()); - private final ConcurrentMap<Key, Intent> intents = Maps.newConcurrentMap(); - private final SetMultimap<LinkKey, Key> intentsByLink = //TODO this could be slow as a point of synchronization synchronizedSetMultimap(HashMultimap.<LinkKey, Key>create()); @@ -378,7 +375,12 @@ public class ObjectiveTracker implements ObjectiveTrackerService { } // TODO should we recompile on available==true? - delegate.triggerCompile(intentsByDevice.get(id), available); + + final ImmutableSet<Key> snapshot; + synchronized (intentsByDevice) { + snapshot = ImmutableSet.copyOf(intentsByDevice.get(id)); + } + delegate.triggerCompile(snapshot, available); } } @@ -415,9 +417,17 @@ public class ObjectiveTracker implements ObjectiveTrackerService { @Override public void event(HostEvent event) { HostId id = event.subject().id(); - HostEvent.Type type = event.type(); - boolean available = (type == HostEvent.Type.HOST_ADDED); - executorService.execute(new DeviceAvailabilityHandler(id, available)); + switch (event.type()) { + case HOST_ADDED: + case HOST_MOVED: + case HOST_REMOVED: + executorService.execute(new DeviceAvailabilityHandler(id, false)); + break; + case HOST_UPDATED: + default: + // DO NOTHING + break; + } } } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java index 99f58df7..c6eb7c5a 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java @@ -15,10 +15,8 @@ */ package org.onosproject.net.intent.impl.compiler; -import com.google.common.collect.Sets; import org.apache.commons.lang3.tuple.Pair; 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.Modified; import org.apache.felix.scr.annotations.Property; @@ -50,7 +48,10 @@ import org.onosproject.net.intent.IntentService; import org.onosproject.net.intent.OpticalCircuitIntent; import org.onosproject.net.intent.OpticalConnectivityIntent; import org.onosproject.net.intent.impl.IntentCompilationException; -import org.onosproject.net.resource.device.DeviceResourceService; +import org.onosproject.net.newresource.ResourceAllocation; +import org.onosproject.net.newresource.ResourcePath; +import org.onosproject.net.newresource.ResourceService; +import org.onosproject.net.resource.device.IntentSetMultimap; import org.onosproject.net.resource.link.LinkResourceAllocations; import org.osgi.service.component.ComponentContext; import org.slf4j.Logger; @@ -60,6 +61,7 @@ import java.util.Collections; import java.util.Dictionary; import java.util.LinkedList; import java.util.List; +import java.util.Optional; import java.util.Set; import static com.google.common.base.Preconditions.checkArgument; @@ -67,7 +69,8 @@ import static com.google.common.base.Preconditions.checkArgument; /** * An intent compiler for {@link org.onosproject.net.intent.OpticalCircuitIntent}. */ -@Component(immediate = true) +// For now, remove component designation until dependency on the new resource manager is available. +// @Component(immediate = true) public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircuitIntent> { private static final Logger log = LoggerFactory.getLogger(OpticalCircuitIntentCompiler.class); @@ -92,7 +95,10 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu protected DeviceService deviceService; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceResourceService deviceResourceService; + protected ResourceService resourceService; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected IntentSetMultimap intentSetMultimap; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected IntentService intentService; @@ -153,7 +159,10 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu log.debug("Compiling optical circuit intent between {} and {}", src, dst); // Reserve OduClt ports - if (!deviceResourceService.requestPorts(Sets.newHashSet(srcPort, dstPort), intent)) { + ResourcePath srcPortPath = new ResourcePath(src.deviceId(), src.port()); + ResourcePath dstPortPath = new ResourcePath(dst.deviceId(), dst.port()); + List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortPath, dstPortPath); + if (allocation.isEmpty()) { throw new IntentCompilationException("Unable to reserve ports for intent " + intent); } @@ -199,7 +208,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu circuitIntent = new FlowRuleIntent(appId, rules, intent.resources()); // Save circuit to connectivity intent mapping - deviceResourceService.requestMapping(connIntent.id(), intent.id()); + intentSetMultimap.allocateMapping(connIntent.id(), intent.id()); intents.add(circuitIntent); return intents; @@ -209,16 +218,15 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu * Checks if current allocations on given resource can satisfy request. * If the resource is null, return true. * - * @param request the intent making the request * @param resource the resource on which to map the intent * @return true if the resource can accept the request, false otherwise */ - private boolean isAvailable(Intent request, IntentId resource) { + private boolean isAvailable(IntentId resource) { if (resource == null) { return true; } - Set<IntentId> mapping = deviceResourceService.getMapping(resource); + Set<IntentId> mapping = intentSetMultimap.getMapping(resource); if (mapping == null) { return true; @@ -271,7 +279,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu continue; } - if (isAvailable(circuitIntent, connIntent.id())) { + if (isAvailable(connIntent.id())) { return connIntent; } } @@ -296,14 +304,19 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu return null; } - private OchPort findAvailableOchPort(ConnectPoint oduPort, OpticalCircuitIntent circuitIntent) { + private OchPort findAvailableOchPort(ConnectPoint oduPort) { // First see if the port mappings are constrained ConnectPoint ochCP = staticPort(oduPort); if (ochCP != null) { OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port()); - IntentId intentId = deviceResourceService.getAllocations(ochPort); - if (isAvailable(circuitIntent, intentId)) { + Optional<IntentId> intentId = + resourceService.getResourceAllocation(new ResourcePath(ochCP.deviceId(), ochCP.port())) + .map(ResourceAllocation::consumer) + .filter(x -> x instanceof IntentId) + .map(x -> (IntentId) x); + + if (isAvailable(intentId.orElse(null))) { return ochPort; } } @@ -316,8 +329,12 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu continue; } - IntentId intentId = deviceResourceService.getAllocations(port); - if (isAvailable(circuitIntent, intentId)) { + Optional<IntentId> intentId = + resourceService.getResourceAllocation(new ResourcePath(oduPort.deviceId(), port.number())) + .map(ResourceAllocation::consumer) + .filter(x -> x instanceof IntentId) + .map(x -> (IntentId) x); + if (isAvailable(intentId.orElse(null))) { return (OchPort) port; } } @@ -327,12 +344,12 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu private Pair<OchPort, OchPort> findPorts(OpticalCircuitIntent intent) { - OchPort srcPort = findAvailableOchPort(intent.getSrc(), intent); + OchPort srcPort = findAvailableOchPort(intent.getSrc()); if (srcPort == null) { return null; } - OchPort dstPort = findAvailableOchPort(intent.getDst(), intent); + OchPort dstPort = findAvailableOchPort(intent.getDst()); if (dstPort == null) { return null; } 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 05a20f96..eb5b4af8 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,9 +16,7 @@ package org.onosproject.net.intent.impl.compiler; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; 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; @@ -40,9 +38,9 @@ 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.resource.ResourceAllocation; +import org.onosproject.net.newresource.ResourcePath; +import org.onosproject.net.newresource.ResourceService; import org.onosproject.net.resource.ResourceType; -import org.onosproject.net.resource.device.DeviceResourceService; import org.onosproject.net.resource.link.DefaultLinkResourceRequest; import org.onosproject.net.resource.link.LambdaResource; import org.onosproject.net.resource.link.LambdaResourceAllocation; @@ -57,13 +55,15 @@ import org.slf4j.LoggerFactory; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkArgument; /** * An intent compiler for {@link org.onosproject.net.intent.OpticalConnectivityIntent}. */ -@Component(immediate = true) +// For now, remove component designation until dependency on the new resource manager is available. +// @Component(immediate = true) public class OpticalConnectivityIntentCompiler implements IntentCompiler<OpticalConnectivityIntent> { protected static final Logger log = LoggerFactory.getLogger(OpticalConnectivityIntentCompiler.class); @@ -78,10 +78,10 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical protected DeviceService deviceService; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected LinkResourceService linkResourceService; + protected ResourceService resourceService; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceResourceService deviceResourceService; + protected LinkResourceService linkResourceService; @Activate public void activate() { @@ -108,7 +108,11 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical log.debug("Compiling optical connectivity intent between {} and {}", src, dst); // Reserve OCh ports - if (!deviceResourceService.requestPorts(ImmutableSet.of(srcPort, dstPort), intent)) { + ResourcePath srcPortPath = new ResourcePath(src.deviceId(), src.port()); + ResourcePath dstPortPath = new ResourcePath(dst.deviceId(), dst.port()); + List<org.onosproject.net.newresource.ResourceAllocation> allocation = + resourceService.allocate(intent.id(), srcPortPath, dstPortPath); + if (allocation.isEmpty()) { throw new IntentCompilationException("Unable to reserve ports for intent " + intent); } @@ -161,7 +165,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical } // Release port allocations if unsuccessful - deviceResourceService.releasePorts(intent.id()); + resourceService.release(intent.id()); throw new IntentCompilationException("Unable to find suitable lightpath for intent " + intent); } @@ -174,15 +178,12 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical * @return lambda allocated to the given path */ private LambdaResourceAllocation getWavelength(Path path, LinkResourceAllocations linkAllocs) { - for (Link link : path.links()) { - for (ResourceAllocation alloc : linkAllocs.getResourceAllocation(link)) { - if (alloc.type() == ResourceType.LAMBDA) { - return (LambdaResourceAllocation) alloc; - } - } - } - - return null; + return path.links().stream() + .flatMap(x -> linkAllocs.getResourceAllocation(x).stream()) + .filter(x -> x.type() == ResourceType.LAMBDA) + .findFirst() + .map(x -> (LambdaResourceAllocation) x) + .orElse(null); } /** @@ -215,23 +216,23 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical return false; } - LambdaResource lambda = null; + 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()); - for (Link link : path.links()) { - for (ResourceAllocation alloc : allocations.getResourceAllocation(link)) { - if (alloc.type() == ResourceType.LAMBDA) { - LambdaResource nextLambda = ((LambdaResourceAllocation) alloc).lambda(); - if (nextLambda == null) { - return false; - } - if (lambda == null) { - lambda = nextLambda; - continue; - } - if (!lambda.equals(nextLambda)) { - return false; - } - } + LambdaResource lambda = null; + for (LambdaResource nextLambda: lambdas) { + if (nextLambda == null) { + return false; + } + if (lambda == null) { + lambda = nextLambda; + continue; + } + if (!lambda.equals(nextLambda)) { + return false; } } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompiler.java index ca9ae5cc..2cc45e79 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompiler.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompiler.java @@ -39,7 +39,6 @@ import org.onosproject.net.intent.IntentCompiler; import org.onosproject.net.intent.IntentExtensionService; import org.onosproject.net.intent.OpticalPathIntent; import org.onosproject.net.resource.link.LinkResourceAllocations; -import org.onosproject.net.resource.link.LinkResourceService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,9 +58,6 @@ public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathInte @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected CoreService coreService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected LinkResourceService resourceService; - private ApplicationId appId; @Activate |