Merge IntentInstaller's role into IntentCompiler
It resolves naming mismatch in naming of IntentProcessPhases and states
handled in the phases. It is described in ONOS-1064.
- Define FlowRuleIntent that enables flow rule level operation
as an intent.
- Remove IntentInstaller interface
- Existing installable intents such as PathIntent, LinkCollectionIntent,
OpticalPathIntent and MplsPathIntent now become non installable intents.
Only FlowRuleIntent is categorized as installable intent now.
- Implement intent compilers for PathIntent, LinkCollectionIntent,
OpticalPathIntent and MplsPathIntent. They generates FlowRuleIntents.
- Write unit tests for the newly created intent compilers according to
the intent installers' unit tests
- Remove all intent installers and their unit tests
Change-Id: I22d6c7acb65a4c066145de0018bd0727f44bd54a
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/InstallerRegistry.java b/core/net/src/main/java/org/onosproject/net/intent/impl/InstallerRegistry.java
deleted file mode 100644
index e0103ce..0000000
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/InstallerRegistry.java
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.net.intent.impl;
-
-import com.google.common.collect.ImmutableMap;
-import org.onosproject.net.flow.FlowRuleOperation;
-import org.onosproject.net.flow.FlowRuleOperations;
-import org.onosproject.net.flow.FlowRuleOperationsContext;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.IntentData;
-import org.onosproject.net.intent.IntentException;
-import org.onosproject.net.intent.IntentInstaller;
-import org.onosproject.net.intent.IntentStore;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import static com.google.common.base.Preconditions.checkState;
-import static org.onlab.util.Tools.isNullOrEmpty;
-import static org.onosproject.net.intent.IntentState.FAILED;
-import static org.onosproject.net.intent.IntentState.INSTALLED;
-import static org.onosproject.net.intent.IntentState.WITHDRAWN;
-
-// TODO: consider a better name
-class InstallerRegistry {
-
- private static final Logger log = LoggerFactory.getLogger(InstallerRegistry.class);
-
- private final ConcurrentMap<Class<? extends Intent>,
- IntentInstaller<? extends Intent>> installers = new ConcurrentHashMap<>();
- /**
- * Registers the specified installer for the given installable intent class.
- *
- * @param cls installable intent class
- * @param installer intent installer
- * @param <T> the type of installable intent
- */
- <T extends Intent> void registerInstaller(Class<T> cls, IntentInstaller<T> installer) {
- installers.put(cls, installer);
- }
-
- /**
- * Unregisters the installer for the given installable intent class.
- *
- * @param cls installable intent class
- * @param <T> the type of installable intent
- */
- <T extends Intent> void unregisterInstaller(Class<T> cls) {
- installers.remove(cls);
- }
-
- /**
- * Returns immutable set of bindings of currently registered intent installers.
- *
- * @return the set of installer bindings
- */
- Map<Class<? extends Intent>, IntentInstaller<? extends Intent>> getInstallers() {
- return ImmutableMap.copyOf(installers);
- }
-
- /**
- * Returns the corresponding intent installer to the specified installable intent.
- *
- * @param intent intent
- * @param <T> the type of installable intent
- * @return intent installer corresponding to the specified installable intent
- */
- private <T extends Intent> IntentInstaller<T> getInstaller(T intent) {
- @SuppressWarnings("unchecked")
- IntentInstaller<T> installer = (IntentInstaller<T>) installers.get(intent.getClass());
- if (installer == null) {
- throw new IntentException("no installer for class " + intent.getClass());
- }
- return installer;
- }
-
- /**
- * Registers an intent installer of the specified intent if an intent installer
- * for the intent is not registered. This method traverses the class hierarchy of
- * the intent. Once an intent installer for a parent type is found, this method
- * registers the found intent installer.
- *
- * @param intent intent
- */
- private void registerSubclassInstallerIfNeeded(Intent intent) {
- if (!installers.containsKey(intent.getClass())) {
- Class<?> cls = intent.getClass();
- while (cls != Object.class) {
- // As long as we're within the Intent class descendants
- if (Intent.class.isAssignableFrom(cls)) {
- IntentInstaller<?> installer = installers.get(cls);
- if (installer != null) {
- installers.put(intent.getClass(), installer);
- return;
- }
- }
- cls = cls.getSuperclass();
- }
- }
- }
-
- /**
- * Generate a {@link FlowRuleOperations} instance from the specified intent data.
- *
- * @param current intent data stored in the store
- * @param pending intent data being processed
- * @param store intent store saving the intent state in this method
- * @param trackerService objective tracker that is used in this method
- * @return flow rule operations
- */
- public FlowRuleOperations coordinate(IntentData current, IntentData pending,
- IntentStore store, ObjectiveTrackerService trackerService) {
- List<Intent> oldInstallables = (current != null) ? current.installables() : null;
- List<Intent> newInstallables = pending.installables();
-
- checkState(isNullOrEmpty(oldInstallables) ||
- oldInstallables.size() == newInstallables.size(),
- "Old and New Intent must have equivalent installable intents.");
-
- List<List<Collection<FlowRuleOperation>>> plans = new ArrayList<>();
- for (int i = 0; i < newInstallables.size(); i++) {
- Intent newInstallable = newInstallables.get(i);
- registerSubclassInstallerIfNeeded(newInstallable);
- //TODO consider migrating installers to FlowRuleOperations
- /* FIXME
- - we need to do another pass on this method about that doesn't
- require the length of installables to be equal, and also doesn't
- depend on ordering
- - we should also reconsider when to start/stop tracking resources
- */
- if (isNullOrEmpty(oldInstallables)) {
- plans.add(getInstaller(newInstallable).install(newInstallable));
- } else {
- Intent oldInstallable = oldInstallables.get(i);
- checkState(oldInstallable.getClass().equals(newInstallable.getClass()),
- "Installable Intent type mismatch.");
- trackerService.removeTrackedResources(pending.key(), oldInstallable.resources());
- plans.add(getInstaller(newInstallable).replace(oldInstallable, newInstallable));
- }
- trackerService.addTrackedResources(pending.key(), newInstallable.resources());
-// } catch (IntentException e) {
-// log.warn("Unable to update intent {} due to:", oldIntent.id(), e);
-// //FIXME... we failed. need to uninstall (if same) or revert (if different)
-// trackerService.removeTrackedResources(newIntent.id(), newInstallable.resources());
-// exception = e;
-// batches = uninstallIntent(oldIntent, oldInstallables);
-// }
- }
-
- return merge(plans).build(new FlowRuleOperationsContext() { // TODO move this out
- @Override
- public void onSuccess(FlowRuleOperations ops) {
- log.debug("Completed installing: {}", pending.key());
- pending.setState(INSTALLED);
- store.write(pending);
- }
-
- @Override
- public void onError(FlowRuleOperations ops) {
- log.warn("Failed installation: {} {} on {}", pending.key(),
- pending.intent(), ops);
- //TODO store.write(pending.setState(BROKEN));
- pending.setState(FAILED);
- store.write(pending);
- }
- });
- }
-
- /**
- * Generate a {@link FlowRuleOperations} instance from the specified intent data.
- *
- * @param current intent data stored in the store
- * @param pending intent date being processed
- * @param store intent store saving the intent state in this method
- * @param trackerService objective tracker that is used in this method
- * @return flow rule operations
- */
- FlowRuleOperations uninstallCoordinate(IntentData current, IntentData pending,
- IntentStore store, ObjectiveTrackerService trackerService) {
- List<Intent> installables = current.installables();
- List<List<Collection<FlowRuleOperation>>> plans = new ArrayList<>();
- for (Intent installable : installables) {
- plans.add(getInstaller(installable).uninstall(installable));
- trackerService.removeTrackedResources(pending.key(), installable.resources());
- }
-
- return merge(plans).build(new FlowRuleOperationsContext() {
- @Override
- public void onSuccess(FlowRuleOperations ops) {
- log.debug("Completed withdrawing: {}", pending.key());
- pending.setState(WITHDRAWN);
- pending.setInstallables(Collections.emptyList());
- store.write(pending);
- }
-
- @Override
- public void onError(FlowRuleOperations ops) {
- log.warn("Failed withdraw: {}", pending.key());
- pending.setState(FAILED);
- store.write(pending);
- }
- });
- }
-
-
- // TODO needs tests... or maybe it's just perfect
- private FlowRuleOperations.Builder merge(List<List<Collection<FlowRuleOperation>>> plans) {
- FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
- // Build a batch one stage at a time
- for (int stageNumber = 0;; stageNumber++) {
- // Get the sub-stage from each plan (List<Set<FlowRuleOperation>)
- for (Iterator<List<Collection<FlowRuleOperation>>> itr = plans.iterator(); itr.hasNext();) {
- List<Collection<FlowRuleOperation>> plan = itr.next();
- if (plan.size() <= stageNumber) {
- // we have consumed all stages from this plan, so remove it
- itr.remove();
- continue;
- }
- // write operations from this sub-stage into the builder
- Collection<FlowRuleOperation> stage = plan.get(stageNumber);
- for (FlowRuleOperation entry : stage) {
- builder.operation(entry);
- }
- }
- // we are done with the stage, start the next one...
- if (plans.isEmpty()) {
- break; // we don't need to start a new stage, we are done.
- }
- builder.newStage();
- }
- return builder;
- }
-}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
index 982aa0c..351016d 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
@@ -26,15 +26,17 @@
import org.onosproject.core.IdGenerator;
import org.onosproject.event.AbstractListenerRegistry;
import org.onosproject.event.EventDeliveryService;
+import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.FlowRuleOperations;
+import org.onosproject.net.flow.FlowRuleOperationsContext;
import org.onosproject.net.flow.FlowRuleService;
+import org.onosproject.net.intent.FlowRuleIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentBatchDelegate;
import org.onosproject.net.intent.IntentCompiler;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentEvent;
import org.onosproject.net.intent.IntentExtensionService;
-import org.onosproject.net.intent.IntentInstaller;
import org.onosproject.net.intent.IntentListener;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentState;
@@ -47,6 +49,7 @@
import org.slf4j.Logger;
import java.util.Collection;
+import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
@@ -60,7 +63,9 @@
import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.net.intent.IntentState.FAILED;
+import static org.onosproject.net.intent.IntentState.INSTALLED;
import static org.onosproject.net.intent.IntentState.INSTALL_REQ;
+import static org.onosproject.net.intent.IntentState.WITHDRAWN;
import static org.onosproject.net.intent.IntentState.WITHDRAW_REQ;
import static org.onosproject.net.intent.impl.phase.IntentProcessPhase.newInitialPhase;
import static org.slf4j.LoggerFactory.getLogger;
@@ -105,7 +110,6 @@
private ExecutorService workerExecutor;
private final CompilerRegistry compilerRegistry = new CompilerRegistry();
- private final InstallerRegistry installerRegistry = new InstallerRegistry();
private final InternalIntentProcessor processor = new InternalIntentProcessor();
private final IntentStoreDelegate delegate = new InternalStoreDelegate();
private final TopologyChangeDelegate topoDelegate = new InternalTopoChangeDelegate();
@@ -215,21 +219,6 @@
}
@Override
- public <T extends Intent> void registerInstaller(Class<T> cls, IntentInstaller<T> installer) {
- installerRegistry.registerInstaller(cls, installer);
- }
-
- @Override
- public <T extends Intent> void unregisterInstaller(Class<T> cls) {
- installerRegistry.unregisterInstaller(cls);
- }
-
- @Override
- public Map<Class<? extends Intent>, IntentInstaller<? extends Intent>> getInstallers() {
- return installerRegistry.getInstallers();
- }
-
- @Override
public Iterable<Intent> getPending() {
return store.getPending();
}
@@ -370,18 +359,92 @@
}
@Override
- public FlowRuleOperations coordinate(IntentData current, IntentData pending) {
- return installerRegistry.coordinate(current, pending, store, trackerService);
+ public void install(IntentData data) {
+ IntentManager.this.install(data);
}
@Override
- public FlowRuleOperations uninstallCoordinate(IntentData current, IntentData pending) {
- return installerRegistry.uninstallCoordinate(current, pending, store, trackerService);
+ public void uninstall(IntentData data) {
+ IntentManager.this.uninstall(data);
}
- @Override
- public void applyFlowRules(FlowRuleOperations flowRules) {
- flowRuleService.apply(flowRules);
+ }
+
+ private void install(IntentData data) {
+ // need to consider if FlowRuleIntent is only one as installable intent or not
+ List<Intent> installables = data.installables();
+ if (!installables.stream().allMatch(x -> x instanceof FlowRuleIntent)) {
+ throw new IllegalStateException("installable intents must be FlowRuleIntent");
}
+
+ installables.forEach(x -> trackerService.addTrackedResources(data.key(), x.resources()));
+
+ List<Collection<FlowRule>> stages = installables.stream()
+ .map(x -> (FlowRuleIntent) x)
+ .map(FlowRuleIntent::flowRules)
+ .collect(Collectors.toList());
+
+ FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
+ for (Collection<FlowRule> rules : stages) {
+ rules.forEach(builder::add);
+ builder.newStage();
+ }
+
+ FlowRuleOperations operations = builder.build(new FlowRuleOperationsContext() {
+ @Override
+ public void onSuccess(FlowRuleOperations ops) {
+ log.debug("Completed installing: {}", data.key());
+ data.setState(INSTALLED);
+ store.write(data);
+ }
+
+ @Override
+ public void onError(FlowRuleOperations ops) {
+ log.warn("Failed installation: {} {} on {}", data.key(), data.intent(), ops);
+ data.setState(FAILED);
+ store.write(data);
+ }
+ });
+
+ flowRuleService.apply(operations);
+ }
+
+ private void uninstall(IntentData data) {
+ List<Intent> installables = data.installables();
+ if (!installables.stream().allMatch(x -> x instanceof FlowRuleIntent)) {
+ throw new IllegalStateException("installable intents must be FlowRuleIntent");
+ }
+
+ installables.forEach(x -> trackerService.removeTrackedResources(data.intent().key(), x.resources()));
+
+ List<Collection<FlowRule>> stages = installables.stream()
+ .map(x -> (FlowRuleIntent) x)
+ .map(FlowRuleIntent::flowRules)
+ .collect(Collectors.toList());
+
+ FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
+ for (Collection<FlowRule> rules : stages) {
+ rules.forEach(builder::remove);
+ builder.newStage();
+ }
+
+ FlowRuleOperations operations = builder.build(new FlowRuleOperationsContext() {
+ @Override
+ public void onSuccess(FlowRuleOperations ops) {
+ log.debug("Completed withdrawing: {}", data.key());
+ data.setState(WITHDRAWN);
+ data.setInstallables(Collections.emptyList());
+ store.write(data);
+ }
+
+ @Override
+ public void onError(FlowRuleOperations ops) {
+ log.warn("Failed withdraw: {}", data.key());
+ data.setState(FAILED);
+ store.write(data);
+ }
+ });
+
+ flowRuleService.apply(operations);
}
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentProcessor.java b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentProcessor.java
index c613a8d..d946804 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentProcessor.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentProcessor.java
@@ -15,7 +15,6 @@
*/
package org.onosproject.net.intent.impl;
-import org.onosproject.net.flow.FlowRuleOperations;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentData;
@@ -39,30 +38,16 @@
List<Intent> compile(Intent intent, List<Intent> previousInstallables);
/**
- * Generate a {@link FlowRuleOperations} instance from the specified intent data.
+ * Installs an intent included in the specified intent data.
*
- * @param current intent data stored in the store
- * @param pending intent data being processed
- * @return flow rule operations
+ * @param data intent data containing an intent to be installed
*/
- FlowRuleOperations coordinate(IntentData current, IntentData pending);
+ void install(IntentData data);
/**
- * Generate a {@link FlowRuleOperations} instance from the specified intent data.
+ * Uninstalls an intent included in the specified intent data.
*
- * @param current intent data stored in the store
- * @param pending intent data being processed
- * @return flow rule operations
+ * @param data intent data containing an intent to be uninstalled
*/
- FlowRuleOperations uninstallCoordinate(IntentData current, IntentData pending);
-
- /**
- * Applies a batch operation of FlowRules.
- *
- * @param flowRules batch operation to apply
- */
- // TODO: consider a better name
- // This methods gives strangeness a bit because
- // it doesn't receive/return intent related information
- void applyFlowRules(FlowRuleOperations flowRules);
+ void uninstall(IntentData data);
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java
new file mode 100644
index 0000000..e9e319e
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.compiler;
+
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.SetMultimap;
+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;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.core.DefaultGroupId;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Link;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.flow.DefaultFlowRule;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.intent.FlowRuleIntent;
+import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.IntentCompiler;
+import org.onosproject.net.intent.IntentExtensionService;
+import org.onosproject.net.intent.LinkCollectionIntent;
+import org.onosproject.net.resource.LinkResourceAllocations;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@Component(immediate = true)
+public class LinkCollectionIntentCompiler implements IntentCompiler<LinkCollectionIntent> {
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected IntentExtensionService intentManager;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ private ApplicationId appId;
+
+ @Activate
+ public void activate() {
+ appId = coreService.registerApplication("org.onosproject.net.intent");
+ intentManager.registerCompiler(LinkCollectionIntent.class, this);
+ }
+
+ @Deactivate
+ public void deactivate() {
+ intentManager.unregisterCompiler(LinkCollectionIntent.class);
+ }
+
+ @Override
+ public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable,
+ Set<LinkResourceAllocations> resources) {
+ SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create();
+ SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();
+
+ for (Link link : intent.links()) {
+ inputPorts.put(link.dst().deviceId(), link.dst().port());
+ outputPorts.put(link.src().deviceId(), link.src().port());
+ }
+
+ for (ConnectPoint ingressPoint : intent.ingressPoints()) {
+ inputPorts.put(ingressPoint.deviceId(), ingressPoint.port());
+ }
+
+ for (ConnectPoint egressPoint : intent.egressPoints()) {
+ outputPorts.put(egressPoint.deviceId(), egressPoint.port());
+ }
+
+ List<FlowRule> rules = new ArrayList<>();
+ for (DeviceId deviceId: outputPorts.keys()) {
+ rules.addAll(createRules(intent, deviceId, inputPorts.get(deviceId), outputPorts.get(deviceId)));
+ }
+ return Arrays.asList(new FlowRuleIntent(appId, rules));
+ }
+
+ private List<FlowRule> createRules(LinkCollectionIntent intent, DeviceId deviceId,
+ Set<PortNumber> inPorts, Set<PortNumber> outPorts) {
+ Set<PortNumber> ingressPorts = intent.ingressPoints().stream()
+ .filter(point -> point.deviceId().equals(deviceId))
+ .map(ConnectPoint::port)
+ .collect(Collectors.toSet());
+
+ TrafficTreatment.Builder defaultTreatmentBuilder = DefaultTrafficTreatment.builder();
+ outPorts.stream()
+ .forEach(defaultTreatmentBuilder::setOutput);
+ TrafficTreatment defaultTreatment = defaultTreatmentBuilder.build();
+
+ TrafficTreatment.Builder ingressTreatmentBuilder = DefaultTrafficTreatment.builder(intent.treatment());
+ outPorts.stream()
+ .forEach(ingressTreatmentBuilder::setOutput);
+ TrafficTreatment ingressTreatment = ingressTreatmentBuilder.build();
+
+ List<FlowRule> rules = new ArrayList<>(inPorts.size());
+ for (PortNumber inPort: inPorts) {
+ TrafficSelector selector = DefaultTrafficSelector.builder(intent.selector()).matchInPort(inPort).build();
+ TrafficTreatment treatment;
+ if (ingressPorts.contains(inPort)) {
+ treatment = ingressTreatment;
+ } else {
+ treatment = defaultTreatment;
+ }
+
+ DefaultFlowRule rule = new DefaultFlowRule(deviceId, selector, treatment, 123, appId,
+ new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)), 0, true);
+
+ rules.add(rule);
+ }
+
+ return rules;
+ }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstaller.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
similarity index 61%
rename from core/net/src/main/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstaller.java
rename to core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
index bb38fa5..b3bd864 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstaller.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
@@ -1,7 +1,20 @@
-package org.onosproject.net.intent.impl.installer;
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.compiler;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -19,14 +32,14 @@
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.FlowRule;
-import org.onosproject.net.flow.FlowRuleOperation;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.flow.criteria.Criteria.EthTypeCriterion;
+import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flow.criteria.Criterion;
-import org.onosproject.net.flow.criteria.Criterion.Type;
+import org.onosproject.net.intent.FlowRuleIntent;
+import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.IntentCompiler;
import org.onosproject.net.intent.IntentExtensionService;
-import org.onosproject.net.intent.IntentInstaller;
import org.onosproject.net.intent.MplsPathIntent;
import org.onosproject.net.link.LinkStore;
import org.onosproject.net.resource.DefaultLinkResourceRequest;
@@ -39,24 +52,22 @@
import org.onosproject.net.resource.ResourceType;
import org.slf4j.Logger;
-import java.util.Collection;
+import java.util.Arrays;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
-/**
- * Installer for {@link MplsPathIntent packet path connectivity intents}.
- */
@Component(immediate = true)
-public class MplsPathIntentInstaller implements IntentInstaller<MplsPathIntent> {
+public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> {
private final Logger log = getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected IntentExtensionService intentManager;
+ protected IntentExtensionService intentExtensionService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
@@ -69,45 +80,27 @@
protected ApplicationId appId;
+ @Override
+ public List<Intent> compile(MplsPathIntent intent, List<Intent> installable,
+ Set<LinkResourceAllocations> resources) {
+ LinkResourceAllocations allocations = assignMplsLabel(intent);
+ List<FlowRule> rules = generateRules(intent, allocations);
+
+ return Arrays.asList(new FlowRuleIntent(appId, rules));
+ }
+
@Activate
public void activate() {
appId = coreService.registerApplication("org.onosproject.net.intent");
- intentManager.registerInstaller(MplsPathIntent.class, this);
+ intentExtensionService.registerCompiler(MplsPathIntent.class, this);
}
@Deactivate
public void deactivate() {
- intentManager.unregisterInstaller(MplsPathIntent.class);
- }
-
- @Override
- public List<Collection<FlowRuleOperation>> install(MplsPathIntent intent) {
- LinkResourceAllocations allocations = assignMplsLabel(intent);
- return generateRules(intent, allocations, FlowRuleOperation.Type.ADD);
-
- }
-
- @Override
- public List<Collection<FlowRuleOperation>> uninstall(MplsPathIntent intent) {
- LinkResourceAllocations allocations = resourceService
- .getAllocations(intent.id());
- resourceService.releaseResources(allocations);
-
- return generateRules(intent, allocations, FlowRuleOperation.Type.REMOVE);
- }
-
- @Override
- public List<Collection<FlowRuleOperation>> replace(MplsPathIntent oldIntent,
- MplsPathIntent newIntent) {
- //FIXME this is brute force
- List<Collection<FlowRuleOperation>> batches = Lists.newArrayList();
- batches.addAll(uninstall(oldIntent));
- batches.addAll(install(newIntent));
- return batches;
+ intentExtensionService.unregisterCompiler(MplsPathIntent.class);
}
private LinkResourceAllocations assignMplsLabel(MplsPathIntent intent) {
-
// TODO: do it better... Suggestions?
Set<Link> linkRequest = Sets.newHashSetWithExpectedSize(intent.path()
.links().size() - 2);
@@ -126,9 +119,7 @@
return reqMpls;
}
- private MplsLabel getMplsLabel(LinkResourceAllocations allocations,
- Link link) {
-
+ private MplsLabel getMplsLabel(LinkResourceAllocations allocations, Link link) {
for (ResourceAllocation allocation : allocations
.getResourceAllocation(link)) {
if (allocation.type() == ResourceType.MPLS_LABEL) {
@@ -140,9 +131,8 @@
return null;
}
- private List<Collection<FlowRuleOperation>> generateRules(MplsPathIntent intent,
- LinkResourceAllocations allocations,
- FlowRuleOperation.Type operation) {
+ private List<FlowRule> generateRules(MplsPathIntent intent,
+ LinkResourceAllocations allocations) {
Iterator<Link> links = intent.path().links().iterator();
Link srcLink = links.next();
@@ -150,14 +140,14 @@
Link link = links.next();
// List of flow rules to be installed
- List<FlowRuleOperation> rules = Lists.newLinkedList();
+ List<FlowRule> rules = new LinkedList<>();
// Ingress traffic
// Get the new MPLS label
MplsLabel mpls = getMplsLabel(allocations, link);
checkNotNull(mpls);
MplsLabel prevLabel = mpls;
- rules.add(ingressFlow(prev.port(), link, intent, mpls, operation));
+ rules.add(ingressFlow(prev.port(), link, intent, mpls));
prev = link.dst();
@@ -171,24 +161,22 @@
mpls = getMplsLabel(allocations, link);
checkNotNull(mpls);
rules.add(transitFlow(prev.port(), link, intent,
- prevLabel, mpls, operation));
+ prevLabel, mpls));
prevLabel = mpls;
} else {
// Egress traffic
rules.add(egressFlow(prev.port(), link, intent,
- prevLabel, operation));
+ prevLabel));
}
prev = link.dst();
}
- return Lists.newArrayList(ImmutableSet.of(rules));
+ return rules;
}
- private FlowRuleOperation ingressFlow(PortNumber inPort, Link link,
- MplsPathIntent intent,
- MplsLabel label,
- FlowRuleOperation.Type operation) {
+ private FlowRule ingressFlow(PortNumber inPort, Link link,
+ MplsPathIntent intent, MplsLabel label) {
TrafficSelector.Builder ingressSelector = DefaultTrafficSelector
.builder(intent.selector());
@@ -208,16 +196,13 @@
// Add the output action
treat.setOutput(link.src().port());
- return flowRuleOperation(intent, link.src().deviceId(),
- ingressSelector.build(), treat.build(),
- operation);
+ return createFlowRule(intent, link.src().deviceId(), ingressSelector.build(), treat.build());
}
- private FlowRuleOperation transitFlow(PortNumber inPort, Link link,
- MplsPathIntent intent,
- MplsLabel prevLabel,
- MplsLabel outLabel,
- FlowRuleOperation.Type operation) {
+ private FlowRule transitFlow(PortNumber inPort, Link link,
+ MplsPathIntent intent,
+ MplsLabel prevLabel,
+ MplsLabel outLabel) {
// Ignore the ingress Traffic Selector and use only the MPLS label
// assigned in the previous link
@@ -233,14 +218,12 @@
}
treat.setOutput(link.src().port());
- return flowRuleOperation(intent, link.src().deviceId(),
- selector.build(), treat.build(), operation);
+ return createFlowRule(intent, link.src().deviceId(), selector.build(), treat.build());
}
- private FlowRuleOperation egressFlow(PortNumber inPort, Link link,
- MplsPathIntent intent,
- MplsLabel prevLabel,
- FlowRuleOperation.Type operation) {
+ private FlowRule egressFlow(PortNumber inPort, Link link,
+ MplsPathIntent intent,
+ MplsLabel prevLabel) {
// egress point: either set the egress MPLS label or pop the
// MPLS label based on the intent annotations
@@ -257,9 +240,9 @@
} else {
// if the ingress ethertype is defined, the egress traffic
// will be use that value, otherwise the IPv4 ethertype is used.
- Criterion c = intent.selector().getCriterion(Type.ETH_TYPE);
- if (c != null && c instanceof EthTypeCriterion) {
- EthTypeCriterion ethertype = (EthTypeCriterion) c;
+ Criterion c = intent.selector().getCriterion(Criterion.Type.ETH_TYPE);
+ if (c != null && c instanceof Criteria.EthTypeCriterion) {
+ Criteria.EthTypeCriterion ethertype = (Criteria.EthTypeCriterion) c;
treat.popMpls((short) ethertype.ethType());
} else {
treat.popMpls(Ethernet.TYPE_IPV4);
@@ -267,24 +250,12 @@
}
treat.setOutput(link.src().port());
- return flowRuleOperation(intent, link.src().deviceId(),
- selector.build(), treat.build(), operation);
+ return createFlowRule(intent, link.src().deviceId(),
+ selector.build(), treat.build());
}
- protected FlowRuleOperation flowRuleOperation(MplsPathIntent intent,
- DeviceId deviceId,
- TrafficSelector selector,
- TrafficTreatment treat,
- FlowRuleOperation.Type operation) {
- FlowRule rule = new DefaultFlowRule(
- deviceId,
- selector,
- treat,
- intent.priority(),
- appId,
- 0,
- true);
- return new FlowRuleOperation(rule, operation);
-
+ protected FlowRule createFlowRule(MplsPathIntent intent, DeviceId deviceId,
+ TrafficSelector selector, TrafficTreatment treat) {
+ return new DefaultFlowRule(deviceId, selector, treat, intent.priority(), appId, 0, true);
}
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompiler.java
new file mode 100644
index 0000000..856499c
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompiler.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.compiler;
+
+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;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Link;
+import org.onosproject.net.flow.DefaultFlowRule;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.intent.FlowRuleIntent;
+import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.IntentCompiler;
+import org.onosproject.net.intent.IntentExtensionService;
+import org.onosproject.net.intent.OpticalPathIntent;
+import org.onosproject.net.intent.impl.IntentCompilationException;
+import org.onosproject.net.resource.DefaultLinkResourceRequest;
+import org.onosproject.net.resource.Lambda;
+import org.onosproject.net.resource.LambdaResourceAllocation;
+import org.onosproject.net.resource.LinkResourceAllocations;
+import org.onosproject.net.resource.LinkResourceRequest;
+import org.onosproject.net.resource.LinkResourceService;
+import org.onosproject.net.resource.ResourceAllocation;
+import org.onosproject.net.resource.ResourceType;
+import org.onosproject.net.topology.TopologyService;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
+
+@Component(immediate = true)
+public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathIntent> {
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected IntentExtensionService intentManager;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected TopologyService topologyService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected LinkResourceService resourceService;
+
+ private ApplicationId appId;
+
+ static final short SIGNAL_TYPE = (short) 1;
+
+ @Activate
+ public void activate() {
+ appId = coreService.registerApplication("org.onosproject.net.intent");
+ intentManager.registerCompiler(OpticalPathIntent.class, this);
+ }
+
+ @Deactivate
+ public void deactivate() {
+ intentManager.unregisterCompiler(OpticalPathIntent.class);
+ }
+
+ @Override
+ public List<Intent> compile(OpticalPathIntent intent, List<Intent> installable,
+ Set<LinkResourceAllocations> resources) {
+ LinkResourceAllocations allocations = assignWavelength(intent);
+
+ return Arrays.asList(new FlowRuleIntent(appId, createRules(intent, allocations)));
+ }
+
+ private LinkResourceAllocations assignWavelength(OpticalPathIntent intent) {
+ LinkResourceRequest.Builder request = DefaultLinkResourceRequest
+ .builder(intent.id(), intent.path().links())
+ .addLambdaRequest();
+ return resourceService.requestResources(request.build());
+ }
+
+ private List<FlowRule> createRules(OpticalPathIntent intent, LinkResourceAllocations allocations) {
+ TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
+ selectorBuilder.matchInPort(intent.src().port());
+
+ List<FlowRule> rules = new LinkedList<>();
+ ConnectPoint prev = intent.src();
+
+ for (Link link : intent.path().links()) {
+ ResourceAllocation allocation = allocations.getResourceAllocation(link).stream()
+ .filter(x -> x.type() == ResourceType.LAMBDA)
+ .findFirst()
+ .orElseThrow(() -> new IntentCompilationException("Lambda was not assigned successfully"));
+ Lambda la = ((LambdaResourceAllocation) allocation).lambda();
+
+ TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
+ treatmentBuilder.setLambda((short) la.toInt());
+ treatmentBuilder.setOutput(link.src().port());
+
+ FlowRule rule = new DefaultFlowRule(prev.deviceId(),
+ selectorBuilder.build(),
+ treatmentBuilder.build(),
+ 100,
+ appId,
+ 100,
+ true);
+
+ rules.add(rule);
+
+ prev = link.dst();
+ selectorBuilder.matchInPort(link.dst().port());
+ selectorBuilder.matchOpticalSignalType(SIGNAL_TYPE);
+ selectorBuilder.matchLambda((short) la.toInt());
+
+ }
+
+ // build the last T port rule
+ TrafficTreatment.Builder treatmentLast = builder();
+ treatmentLast.setOutput(intent.dst().port());
+ FlowRule rule = new DefaultFlowRule(intent.dst().deviceId(),
+ selectorBuilder.build(),
+ treatmentLast.build(),
+ 100,
+ appId,
+ 100,
+ true);
+ rules.add(rule);
+
+ return rules;
+ }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
new file mode 100644
index 0000000..56515ec
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.compiler;
+
+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;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Link;
+import org.onosproject.net.flow.DefaultFlowRule;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.intent.FlowRuleIntent;
+import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.IntentCompiler;
+import org.onosproject.net.intent.IntentExtensionService;
+import org.onosproject.net.intent.PathIntent;
+import org.onosproject.net.resource.LinkResourceAllocations;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+@Component(immediate = true)
+public class PathIntentCompiler implements IntentCompiler<PathIntent> {
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected IntentExtensionService intentManager;
+
+ private ApplicationId appId;
+
+ @Activate
+ public void activate() {
+ appId = coreService.registerApplication("org.onosproject.net.intent");
+ intentManager.registerCompiler(PathIntent.class, this);
+ }
+
+ @Deactivate
+ public void deactivate() {
+ intentManager.unregisterCompiler(PathIntent.class);
+ }
+
+ @Override
+ public List<Intent> compile(PathIntent intent, List<Intent> installable,
+ Set<LinkResourceAllocations> resources) {
+ // Note: right now recompile is not considered
+ // TODO: implement recompile behavior
+
+ List<Link> links = intent.path().links();
+ List<FlowRule> rules = new ArrayList<>(links.size() - 1);
+
+ for (int i = 0; i < links.size() - 1; i++) {
+ ConnectPoint ingress = links.get(i).dst();
+ ConnectPoint egress = links.get(i + 1).src();
+ FlowRule rule = createFlowRule(intent.selector(), intent.treatment(), ingress, egress, isLast(links, i));
+ rules.add(rule);
+ }
+
+ return Arrays.asList(new FlowRuleIntent(appId, rules));
+ }
+
+ private FlowRule createFlowRule(TrafficSelector originalSelector, TrafficTreatment originalTreatment,
+ ConnectPoint ingress, ConnectPoint egress, boolean last) {
+ TrafficSelector selector = DefaultTrafficSelector.builder(originalSelector)
+ .matchInPort(ingress.port())
+ .build();
+
+ TrafficTreatment.Builder treatmentBuilder;
+ if (last) {
+ treatmentBuilder = DefaultTrafficTreatment.builder(originalTreatment);
+ } else {
+ treatmentBuilder = DefaultTrafficTreatment.builder();
+ }
+ TrafficTreatment treatment = treatmentBuilder.setOutput(egress.port()).build();
+
+ return new DefaultFlowRule(ingress.deviceId(), selector, treatment, 123, appId, 0, true);
+ }
+
+ private boolean isLast(List<Link> links, int i) {
+ return i == links.size() - 2;
+ }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstaller.java b/core/net/src/main/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstaller.java
deleted file mode 100644
index e715b87..0000000
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstaller.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Copyright 2014 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.net.intent.impl.installer;
-
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-import com.google.common.collect.SetMultimap;
-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;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.core.DefaultGroupId;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.Link;
-import org.onosproject.net.PortNumber;
-import org.onosproject.net.flow.DefaultFlowRule;
-import org.onosproject.net.flow.DefaultTrafficSelector;
-import org.onosproject.net.flow.DefaultTrafficTreatment;
-import org.onosproject.net.flow.FlowRule;
-import org.onosproject.net.flow.FlowRuleOperation;
-import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.intent.IntentExtensionService;
-import org.onosproject.net.intent.IntentInstaller;
-import org.onosproject.net.intent.LinkCollectionIntent;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Installer for {@link org.onosproject.net.intent.LinkCollectionIntent} path
- * segment intents.
- */
-@Component(immediate = true)
-public class LinkCollectionIntentInstaller
- implements IntentInstaller<LinkCollectionIntent> {
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected IntentExtensionService intentManager;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected CoreService coreService;
-
- private ApplicationId appId;
-
- @Activate
- public void activate() {
- appId = coreService.registerApplication("org.onosproject.net.intent");
- intentManager.registerInstaller(LinkCollectionIntent.class, this);
- }
-
- @Deactivate
- public void deactivate() {
- intentManager.unregisterInstaller(LinkCollectionIntent.class);
- }
-
- @Override
- public List<Collection<FlowRuleOperation>> install(LinkCollectionIntent intent) {
- return generateBatchOperations(intent, FlowRuleOperation.Type.ADD);
- }
-
- @Override
- public List<Collection<FlowRuleOperation>> uninstall(LinkCollectionIntent intent) {
- return generateBatchOperations(intent, FlowRuleOperation.Type.REMOVE);
- }
-
- private List<Collection<FlowRuleOperation>> generateBatchOperations(
- LinkCollectionIntent intent, FlowRuleOperation.Type operation) {
-
- //TODO do we need a set here?
- SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create();
- SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();
-
- for (Link link : intent.links()) {
- inputPorts.put(link.dst().deviceId(), link.dst().port());
- outputPorts.put(link.src().deviceId(), link.src().port());
- }
-
- for (ConnectPoint ingressPoint : intent.ingressPoints()) {
- inputPorts.put(ingressPoint.deviceId(), ingressPoint.port());
- }
-
- for (ConnectPoint egressPoint : intent.egressPoints()) {
- outputPorts.put(egressPoint.deviceId(), egressPoint.port());
- }
-
- List<FlowRuleOperation> rules = Lists.newArrayList();
- outputPorts.keys().stream()
- .map(deviceId -> createBatchEntries(operation,
- intent, deviceId,
- inputPorts.get(deviceId),
- outputPorts.get(deviceId)))
- .forEach(rules::addAll);
-
- return Lists.newArrayList(ImmutableSet.of(rules));
- }
-
- @Override
- public List<Collection<FlowRuleOperation>> replace(LinkCollectionIntent oldIntent,
- LinkCollectionIntent newIntent) {
- // FIXME: implement this in a more intelligent/less brute force way
- List<Collection<FlowRuleOperation>> batches = Lists.newArrayList();
- batches.addAll(uninstall(oldIntent));
- batches.addAll(install(newIntent));
- return batches;
- }
-
- /**
- * Creates a collection of FlowRuleOperation based on the provided
- * parameters.
- *
- * @param operation the FlowRuleOperation type to use
- * @param intent the link collection intent
- * @param deviceId the device ID for the flow rule
- * @param inPorts the logical input ports of the flow rule
- * @param outPorts the set of output ports for the flow rule
- * @return a collection with the new flow rule batch entries
- */
- private Collection<FlowRuleOperation> createBatchEntries(
- FlowRuleOperation.Type operation,
- LinkCollectionIntent intent,
- DeviceId deviceId,
- Set<PortNumber> inPorts,
- Set<PortNumber> outPorts) {
- Collection<FlowRuleOperation> result = Lists.newLinkedList();
- Set<PortNumber> ingressPorts = new HashSet<PortNumber>();
-
- //
- // Collect all ingress ports for this device.
- // The intent treatment is applied only on those ports.
- //
- for (ConnectPoint cp : intent.ingressPoints()) {
- if (cp.deviceId().equals(deviceId)) {
- ingressPorts.add(cp.port());
- }
- }
-
- //
- // Create two treatments: one for setting the output ports,
- // and a second one that applies the intent treatment and sets the
- // output ports.
- // NOTE: The second one is created only if there are ingress ports.
- //
- TrafficTreatment.Builder defaultTreatmentBuilder =
- DefaultTrafficTreatment.builder();
- for (PortNumber outPort : outPorts) {
- defaultTreatmentBuilder.setOutput(outPort);
- }
- TrafficTreatment defaultTreatment = defaultTreatmentBuilder.build();
- TrafficTreatment intentTreatment = null;
- if (!ingressPorts.isEmpty()) {
- TrafficTreatment.Builder intentTreatmentBuilder =
- DefaultTrafficTreatment.builder(intent.treatment());
- for (PortNumber outPort : outPorts) {
- intentTreatmentBuilder.setOutput(outPort);
- }
- intentTreatment = intentTreatmentBuilder.build();
- }
-
- for (PortNumber inPort : inPorts) {
- TrafficSelector selector = DefaultTrafficSelector
- .builder(intent.selector()).matchInPort(inPort).build();
- TrafficTreatment treatment = defaultTreatment;
- if (ingressPorts.contains(inPort)) {
- // Use the intent treatment if this is ingress port
- treatment = intentTreatment;
- }
- FlowRule rule = new DefaultFlowRule(deviceId,
- selector, treatment, intent.priority(), appId,
- new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)),
- 0, true);
- result.add(new FlowRuleOperation(rule, operation));
- }
-
- return result;
- }
-}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/installer/OpticalPathIntentInstaller.java b/core/net/src/main/java/org/onosproject/net/intent/impl/installer/OpticalPathIntentInstaller.java
deleted file mode 100644
index 43f6bfe..0000000
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/installer/OpticalPathIntentInstaller.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Copyright 2014 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.net.intent.impl.installer;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-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;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.Link;
-import org.onosproject.net.flow.DefaultFlowRule;
-import org.onosproject.net.flow.DefaultTrafficSelector;
-import org.onosproject.net.flow.DefaultTrafficTreatment;
-import org.onosproject.net.flow.FlowRule;
-import org.onosproject.net.flow.FlowRuleOperation;
-import org.onosproject.net.flow.FlowRuleService;
-import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.intent.IntentExtensionService;
-import org.onosproject.net.intent.IntentInstaller;
-import org.onosproject.net.intent.OpticalPathIntent;
-import org.onosproject.net.resource.DefaultLinkResourceRequest;
-import org.onosproject.net.resource.Lambda;
-import org.onosproject.net.resource.LambdaResourceAllocation;
-import org.onosproject.net.resource.LinkResourceAllocations;
-import org.onosproject.net.resource.LinkResourceRequest;
-import org.onosproject.net.resource.LinkResourceService;
-import org.onosproject.net.resource.ResourceAllocation;
-import org.onosproject.net.resource.ResourceType;
-import org.onosproject.net.topology.TopologyService;
-import org.slf4j.Logger;
-
-import java.util.Collection;
-import java.util.List;
-
-import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * Installer for {@link org.onosproject.net.intent.OpticalPathIntent optical path connectivity intents}.
- */
-@Component(immediate = true)
-public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIntent> {
- private final Logger log = getLogger(getClass());
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected IntentExtensionService intentManager;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected FlowRuleService flowRuleService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected CoreService coreService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected TopologyService topologyService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected LinkResourceService resourceService;
-
- private ApplicationId appId;
-
- static final short SIGNAL_TYPE = (short) 1;
-
- @Activate
- public void activate() {
- appId = coreService.registerApplication("org.onosproject.net.intent");
- intentManager.registerInstaller(OpticalPathIntent.class, this);
- }
-
- @Deactivate
- public void deactivate() {
- intentManager.unregisterInstaller(OpticalPathIntent.class);
- }
-
- @Override
- public List<Collection<FlowRuleOperation>> install(OpticalPathIntent intent) {
- LinkResourceAllocations allocations = assignWavelength(intent);
- return generateRules(intent, allocations, FlowRuleOperation.Type.ADD);
- }
-
- @Override
- public List<Collection<FlowRuleOperation>> uninstall(OpticalPathIntent intent) {
- LinkResourceAllocations allocations = resourceService.getAllocations(intent.id());
- List<Collection<FlowRuleOperation>> rules = generateRules(intent, allocations, FlowRuleOperation.Type.REMOVE);
- log.info("uninstall rules: {}", rules);
- return rules;
- }
-
- @Override
- public List<Collection<FlowRuleOperation>> replace(OpticalPathIntent oldIntent,
- OpticalPathIntent newIntent) {
- // FIXME: implement this
- List<Collection<FlowRuleOperation>> batches = Lists.newArrayList();
- batches.addAll(uninstall(oldIntent));
- batches.addAll(install(newIntent));
- return batches;
- }
-
- private LinkResourceAllocations assignWavelength(OpticalPathIntent intent) {
- LinkResourceRequest.Builder request = DefaultLinkResourceRequest.builder(intent.id(),
- intent.path().links())
- .addLambdaRequest();
- LinkResourceAllocations retLambda = resourceService.requestResources(request.build());
- return retLambda;
- }
-
- private List<Collection<FlowRuleOperation>> generateRules(OpticalPathIntent intent,
- LinkResourceAllocations allocations,
- FlowRuleOperation.Type operation) {
- TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
- selectorBuilder.matchInPort(intent.src().port());
-
- List<FlowRuleOperation> rules = Lists.newLinkedList();
- ConnectPoint prev = intent.src();
-
- //FIXME check for null allocations
- //TODO throw exception if the lambda was not assigned successfully
- for (Link link : intent.path().links()) {
- Lambda la = null;
- for (ResourceAllocation allocation : allocations.getResourceAllocation(link)) {
- if (allocation.type() == ResourceType.LAMBDA) {
- la = ((LambdaResourceAllocation) allocation).lambda();
- break;
- }
- }
-
- if (la == null) {
- log.info("Lambda was not assigned successfully");
- return null;
- }
-
- TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
- treatmentBuilder.setLambda((short) la.toInt());
- treatmentBuilder.setOutput(link.src().port());
-
- FlowRule rule = new DefaultFlowRule(prev.deviceId(),
- selectorBuilder.build(),
- treatmentBuilder.build(),
- 100,
- appId,
- 100,
- true);
-
- rules.add(new FlowRuleOperation(rule, operation));
-
- prev = link.dst();
- selectorBuilder.matchInPort(link.dst().port());
- selectorBuilder.matchOpticalSignalType(SIGNAL_TYPE); //todo
- selectorBuilder.matchLambda((short) la.toInt());
-
- }
-
- // build the last T port rule
- TrafficTreatment.Builder treatmentLast = builder();
- treatmentLast.setOutput(intent.dst().port());
- FlowRule rule = new DefaultFlowRule(intent.dst().deviceId(),
- selectorBuilder.build(),
- treatmentLast.build(),
- 100,
- appId,
- 100,
- true);
- rules.add(new FlowRuleOperation(rule, operation));
-
- //FIXME change to new api
- return Lists.newArrayList(ImmutableSet.of(rules));
- }
-}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/installer/PathIntentInstaller.java b/core/net/src/main/java/org/onosproject/net/intent/impl/installer/PathIntentInstaller.java
deleted file mode 100644
index 7a06024..0000000
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/installer/PathIntentInstaller.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Copyright 2014 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.net.intent.impl.installer;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-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;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.core.DefaultGroupId;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.Link;
-import org.onosproject.net.flow.DefaultFlowRule;
-import org.onosproject.net.flow.DefaultTrafficSelector;
-import org.onosproject.net.flow.FlowRule;
-import org.onosproject.net.flow.FlowRuleOperation;
-import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.intent.Constraint;
-import org.onosproject.net.intent.IntentExtensionService;
-import org.onosproject.net.intent.IntentInstaller;
-import org.onosproject.net.intent.PathIntent;
-import org.onosproject.net.resource.DefaultLinkResourceRequest;
-import org.onosproject.net.resource.LinkResourceAllocations;
-import org.onosproject.net.resource.LinkResourceRequest;
-import org.onosproject.net.resource.LinkResourceService;
-import org.slf4j.Logger;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * Installer for {@link PathIntent packet path connectivity intents}.
- */
-@Component(immediate = true)
-public class PathIntentInstaller implements IntentInstaller<PathIntent> {
-
- private final Logger log = getLogger(getClass());
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected IntentExtensionService intentManager;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected CoreService coreService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected LinkResourceService resourceService;
-
- protected ApplicationId appId;
-
- @Activate
- public void activate() {
- appId = coreService.registerApplication("org.onosproject.net.intent");
- intentManager.registerInstaller(PathIntent.class, this);
- }
-
- @Deactivate
- public void deactivate() {
- intentManager.unregisterInstaller(PathIntent.class);
- }
-
- @Override
- public List<Collection<FlowRuleOperation>> install(PathIntent intent) {
- LinkResourceAllocations allocations = allocateResources(intent);
-
- TrafficSelector.Builder builder =
- DefaultTrafficSelector.builder(intent.selector());
- Iterator<Link> links = intent.path().links().iterator();
- ConnectPoint prev = links.next().dst();
- List<FlowRuleOperation> rules = Lists.newLinkedList();
- // TODO Generate multiple batches
- while (links.hasNext()) {
- builder.matchInPort(prev.port());
- Link link = links.next();
- // if this is the last flow rule, apply the intent's treatments
- TrafficTreatment treatment =
- (links.hasNext() ? builder() : builder(intent.treatment()))
- .setOutput(link.src().port()).build();
-
- FlowRule rule = new DefaultFlowRule(link.src().deviceId(),
- builder.build(), treatment, intent.priority(),
- appId,
- new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)),
- 0, true);
- rules.add(new FlowRuleOperation(rule, FlowRuleOperation.Type.ADD));
- prev = link.dst();
- }
-
- return Lists.newArrayList(ImmutableSet.of(rules));
- }
-
- @Override
- public List<Collection<FlowRuleOperation>> uninstall(PathIntent intent) {
- deallocateResources(intent);
- TrafficSelector.Builder builder =
- DefaultTrafficSelector.builder(intent.selector());
- Iterator<Link> links = intent.path().links().iterator();
- ConnectPoint prev = links.next().dst();
- List<FlowRuleOperation> rules = Lists.newLinkedList();
- // TODO Generate multiple batches
- while (links.hasNext()) {
- builder.matchInPort(prev.port());
- Link link = links.next();
- // if this is the last flow rule, apply the intent's treatments
- TrafficTreatment treatment =
- (links.hasNext() ? builder() : builder(intent.treatment()))
- .setOutput(link.src().port()).build();
- FlowRule rule = new DefaultFlowRule(link.src().deviceId(),
- builder.build(), treatment, intent.priority(), appId,
- new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)),
- 0, true);
- rules.add(new FlowRuleOperation(rule, FlowRuleOperation.Type.REMOVE));
- prev = link.dst();
- }
- // FIXME this should change to new api
- return Lists.newArrayList(ImmutableSet.of(rules));
- }
-
- @Override
- public List<Collection<FlowRuleOperation>> replace(PathIntent oldIntent, PathIntent newIntent) {
- // FIXME: implement this
- List<Collection<FlowRuleOperation>> batches = Lists.newArrayList();
- batches.addAll(uninstall(oldIntent));
- batches.addAll(install(newIntent));
- return batches;
- }
-
- /**
- * Allocate resources required for an intent.
- *
- * @param intent intent to allocate resource for
- * @return allocated resources if any are required, null otherwise
- */
- private LinkResourceAllocations allocateResources(PathIntent intent) {
- LinkResourceRequest.Builder builder =
- DefaultLinkResourceRequest.builder(intent.id(), intent.path().links());
- for (Constraint constraint : intent.constraints()) {
- builder.addConstraint(constraint);
- }
- LinkResourceRequest request = builder.build();
- return request.resources().isEmpty() ? null : resourceService.requestResources(request);
- }
-
- /**
- * Deallocate resources held by an intent.
- *
- * @param intent intent to deallocate resources for
- */
- private void deallocateResources(PathIntent intent) {
- if (intent.constraints().isEmpty()) {
- return;
- }
-
- LinkResourceAllocations allocatedResources = resourceService.getAllocations(intent.id());
- if (allocatedResources != null) {
- resourceService.releaseResources(allocatedResources);
- }
- }
-}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/CompilingFailed.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/CompileFailed.java
similarity index 89%
rename from core/net/src/main/java/org/onosproject/net/intent/impl/phase/CompilingFailed.java
rename to core/net/src/main/java/org/onosproject/net/intent/impl/phase/CompileFailed.java
index e537308..234e222 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/CompilingFailed.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/CompileFailed.java
@@ -20,14 +20,14 @@
/**
* Represents a phase where the compile has failed.
*/
-public class CompilingFailed extends AbstractFailed {
+public class CompileFailed extends AbstractFailed {
/**
* Create an instance with the specified data.
*
* @param intentData intentData
*/
- public CompilingFailed(IntentData intentData) {
+ public CompileFailed(IntentData intentData) {
super(intentData);
}
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java
index 97ea18e..060ae53 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java
@@ -15,14 +15,12 @@
*/
package org.onosproject.net.intent.impl.phase;
-import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentException;
import org.onosproject.net.intent.impl.IntentProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.List;
import java.util.Optional;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -35,24 +33,27 @@
private static final Logger log = LoggerFactory.getLogger(Compiling.class);
private final IntentProcessor processor;
- private final IntentData pending;
- private final IntentData current;
+ private final IntentData data;
- Compiling(IntentProcessor processor, IntentData pending, IntentData current) {
+ /**
+ * Creates an compiling phase.
+ *
+ * @param processor intent processor that does work for compiling
+ * @param data intent data containing an intent to be compiled
+ */
+ Compiling(IntentProcessor processor, IntentData data) {
this.processor = checkNotNull(processor);
- this.pending = checkNotNull(pending);
- this.current = current;
+ this.data = checkNotNull(data);
}
@Override
public Optional<IntentProcessPhase> execute() {
try {
- List<Intent> installables = (current != null) ? current.installables() : null;
- pending.setInstallables(processor.compile(pending.intent(), installables));
- return Optional.of(new InstallCoordinating(processor, pending, current));
+ data.setInstallables(processor.compile(data.intent(), null));
+ return Optional.of(new Installing(processor, data));
} catch (IntentException e) {
- log.debug("Unable to compile intent {} due to: {}", pending.intent(), e);
- return Optional.of(new CompilingFailed(pending));
+ log.debug("Unable to compile intent {} due to: {}", data.intent(), e);
+ return Optional.of(new CompileFailed(data));
}
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/FinalIntentProcessPhase.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/FinalIntentProcessPhase.java
index 72451a5..c67b93b 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/FinalIntentProcessPhase.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/FinalIntentProcessPhase.java
@@ -26,8 +26,19 @@
@Override
public final Optional<IntentProcessPhase> execute() {
+ preExecute();
return Optional.empty();
}
+ /**
+ * Executes operations that must take place before the phase starts.
+ */
+ protected void preExecute() {}
+
+ /**
+ * Returns the IntentData object being acted on by this phase.
+ *
+ * @return intent data object for the phase
+ */
public abstract IntentData data();
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallCoordinating.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallCoordinating.java
deleted file mode 100644
index 645fe6c..0000000
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallCoordinating.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.net.intent.impl.phase;
-
-import org.onosproject.net.flow.FlowRuleOperations;
-import org.onosproject.net.intent.IntentData;
-import org.onosproject.net.intent.IntentException;
-import org.onosproject.net.intent.impl.IntentProcessor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Optional;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * Represents a phase to create a {@link FlowRuleOperations} instance
- * with using registered intent installers.
- */
-final class InstallCoordinating implements IntentProcessPhase {
-
- private static final Logger log = LoggerFactory.getLogger(InstallCoordinating.class);
-
- private final IntentProcessor processor;
- private final IntentData pending;
- private final IntentData current;
-
- InstallCoordinating(IntentProcessor processor, IntentData pending, IntentData current) {
- this.processor = checkNotNull(processor);
- this.pending = checkNotNull(pending);
- this.current = current;
- }
-
- @Override
- public Optional<IntentProcessPhase> execute() {
- try {
- //FIXME we orphan flow rules that are currently on the data plane
- // ... should either reuse them or remove them
- FlowRuleOperations flowRules = processor.coordinate(current, pending);
- return Optional.of(new Installing(processor, pending, flowRules));
- } catch (IntentException e) {
- log.warn("Unable to generate a FlowRuleOperations from intent {} due to:", pending.intent().id(), e);
- return Optional.of(new InstallingFailed(pending));
- }
- }
-}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallRequest.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallRequest.java
index 1944aad..9e09788 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallRequest.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallRequest.java
@@ -27,18 +27,30 @@
*/
final class InstallRequest implements IntentProcessPhase {
- private final IntentProcessor intentManager;
- private final IntentData pending;
- private final Optional<IntentData> current;
+ private final IntentProcessor processor;
+ private final IntentData data;
+ private final Optional<IntentData> stored;
- InstallRequest(IntentProcessor processor, IntentData intentData, Optional<IntentData> current) {
- this.intentManager = checkNotNull(processor);
- this.pending = checkNotNull(intentData);
- this.current = checkNotNull(current);
+ /**
+ * Creates an install request phase.
+ *
+ * @param processor intent processor to be passed to intent process phases
+ * generated after this phase
+ * @param intentData intent data to be processed
+ * @param stored intent data stored in the store
+ */
+ InstallRequest(IntentProcessor processor, IntentData intentData, Optional<IntentData> stored) {
+ this.processor = checkNotNull(processor);
+ this.data = checkNotNull(intentData);
+ this.stored = checkNotNull(stored);
}
@Override
public Optional<IntentProcessPhase> execute() {
- return Optional.of(new Compiling(intentManager, pending, current.orElse(null)));
+ if (!stored.isPresent() || stored.get().installables() == null || stored.get().installables().isEmpty()) {
+ return Optional.of(new Compiling(processor, data));
+ } else {
+ return Optional.of(new Recompiling(processor, data, stored.get()));
+ }
}
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Installed.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Installed.java
deleted file mode 100644
index cd4d14e..0000000
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Installed.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.net.intent.impl.phase;
-
-import org.onosproject.net.intent.IntentData;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onosproject.net.intent.IntentState.INSTALLING;
-
-/**
- * Represent a phase where an intent has been installed.
- */
-class Installed extends FinalIntentProcessPhase {
-
- private final IntentData intentData;
-
- Installed(IntentData intentData) {
- this.intentData = checkNotNull(intentData);
- this.intentData.setState(INSTALLING);
- }
-
- @Override
- public IntentData data() {
- return intentData;
- }
-}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Installing.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Installing.java
index 3a290ae..de042e5 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Installing.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Installing.java
@@ -15,45 +15,39 @@
*/
package org.onosproject.net.intent.impl.phase;
-import org.onosproject.net.flow.FlowRuleOperations;
import org.onosproject.net.intent.IntentData;
-import org.onosproject.net.intent.IntentException;
import org.onosproject.net.intent.impl.IntentProcessor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Optional;
import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.net.intent.IntentState.INSTALLING;
/**
- * Represents a phase of installing an intent with calling
- * {@link org.onosproject.net.flow.FlowRuleService}.
+ * Represents a phase where an intent is being installed.
*/
-final class Installing implements IntentProcessPhase {
-
- private static final Logger log = LoggerFactory.getLogger(Installing.class);
+class Installing extends FinalIntentProcessPhase {
private final IntentProcessor processor;
- private final IntentData pending;
- private final FlowRuleOperations flowRules;
+ private final IntentData data;
- Installing(IntentProcessor processor, IntentData pending, FlowRuleOperations flowRules) {
+ /**
+ * Create an installing phase.
+ *
+ * @param processor intent processor that does work for installing
+ * @param data intent data containing an intent to be installed
+ */
+ Installing(IntentProcessor processor, IntentData data) {
this.processor = checkNotNull(processor);
- this.pending = checkNotNull(pending);
- this.flowRules = flowRules;
+ this.data = checkNotNull(data);
+ this.data.setState(INSTALLING);
}
@Override
- public Optional<IntentProcessPhase> execute() {
- try {
- processor.applyFlowRules(flowRules);
- return Optional.of(new Installed(pending));
- // What kinds of exceptions are thrown by FlowRuleService.apply()?
- // Is IntentException a correct exception abstraction?
- } catch (IntentException e) {
- log.warn("Unable to install intent {} due to: {}", pending.intent().id(), e);
- return Optional.of(new InstallingFailed(pending));
- }
+ public void preExecute() {
+ processor.install(data);
+ }
+
+ @Override
+ public IntentData data() {
+ return data;
}
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/IntentProcessPhase.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/IntentProcessPhase.java
index dfa9d11..ea5a590 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/IntentProcessPhase.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/IntentProcessPhase.java
@@ -21,7 +21,6 @@
import java.util.Optional;
import static org.onlab.util.Tools.isNullOrEmpty;
-import static org.onosproject.net.intent.IntentState.WITHDRAWN;
/**
* Represents a phase of processing an intent.
@@ -52,7 +51,7 @@
return new InstallRequest(processor, data, Optional.ofNullable(current));
case WITHDRAW_REQ:
if (current == null || isNullOrEmpty(current.installables())) {
- return new Withdrawn(data, WITHDRAWN);
+ return new Withdrawn(data);
} else {
return new WithdrawRequest(processor, data, current);
}
@@ -60,7 +59,7 @@
return new PurgeRequest(data, current);
default:
// illegal state
- return new CompilingFailed(data);
+ return new CompileFailed(data);
}
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Recompiling.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Recompiling.java
new file mode 100644
index 0000000..110f42f
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Recompiling.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.phase;
+
+import org.onosproject.net.intent.Intent;
+import org.onosproject.net.intent.IntentData;
+import org.onosproject.net.intent.impl.IntentProcessor;
+
+import java.util.List;
+import java.util.Optional;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Represents a phase where an intent is being recompiled.
+ */
+class Recompiling implements IntentProcessPhase {
+
+ private final IntentProcessor processor;
+ private final IntentData data;
+ private final IntentData stored;
+
+ /**
+ * Creates a intent recompiling phase.
+ *
+ * @param processor intent processor that does work for recompiling
+ * @param data intent data containing an intent to be recompiled
+ * @param stored intent data stored in the store
+ */
+ Recompiling(IntentProcessor processor, IntentData data, IntentData stored) {
+ this.processor = checkNotNull(processor);
+ this.data = checkNotNull(data);
+ this.stored = checkNotNull(stored);
+ }
+
+ @Override
+ public Optional<IntentProcessPhase> execute() {
+ List<Intent> compiled = processor.compile(data.intent(), stored.installables());
+ data.setInstallables(compiled);
+ return Optional.of(new Replacing(processor, data, stored));
+ }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallingFailed.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/ReplaceFailed.java
similarity index 90%
rename from core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallingFailed.java
rename to core/net/src/main/java/org/onosproject/net/intent/impl/phase/ReplaceFailed.java
index b3bf3a3..3fcf97b 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallingFailed.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/ReplaceFailed.java
@@ -20,14 +20,14 @@
/**
* Represent a phase where the install has failed.
*/
-class InstallingFailed extends AbstractFailed {
+class ReplaceFailed extends AbstractFailed {
/**
* Create an instance with the specified data.
*
* @param intentData intentData
*/
- InstallingFailed(IntentData intentData) {
+ ReplaceFailed(IntentData intentData) {
super(intentData);
}
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Replacing.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Replacing.java
new file mode 100644
index 0000000..911139c
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Replacing.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.impl.phase;
+
+import org.onosproject.net.intent.IntentData;
+import org.onosproject.net.intent.IntentException;
+import org.onosproject.net.intent.impl.IntentProcessor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Represents a phase to replace an intent.
+ */
+final class Replacing implements IntentProcessPhase {
+
+ private static final Logger log = LoggerFactory.getLogger(Replacing.class);
+
+ private final IntentProcessor processor;
+ private final IntentData data;
+ private final IntentData stored;
+
+ /**
+ * Creates a replacing phase.
+ *
+ * @param processor intent processor that does work for replacing
+ * @param data intent data containing an intent to be replaced
+ * @param stored intent data stored in the store
+ */
+ Replacing(IntentProcessor processor, IntentData data, IntentData stored) {
+ this.processor = checkNotNull(processor);
+ this.data = checkNotNull(data);
+ this.stored = checkNotNull(stored);
+ }
+
+ @Override
+ public Optional<IntentProcessPhase> execute() {
+ try {
+ processor.uninstall(stored);
+ return Optional.of(new Installing(processor, data));
+ } catch (IntentException e) {
+ log.warn("Unable to generate a FlowRuleOperations from intent {} due to:", data.intent().id(), e);
+ return Optional.of(new ReplaceFailed(data));
+ }
+ }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawCoordinating.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawCoordinating.java
deleted file mode 100644
index ee854c8..0000000
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawCoordinating.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.net.intent.impl.phase;
-
-import org.onosproject.net.flow.FlowRuleOperations;
-import org.onosproject.net.intent.IntentData;
-import org.onosproject.net.intent.IntentException;
-import org.onosproject.net.intent.impl.IntentProcessor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Optional;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * Represents a phase to create a {@link FlowRuleOperations} instance
- * with using registered intent installers.
- */
-final class WithdrawCoordinating implements IntentProcessPhase {
-
- private static final Logger log = LoggerFactory.getLogger(WithdrawCoordinating.class);
-
- private final IntentProcessor processor;
- private final IntentData pending;
- private final IntentData current;
-
- WithdrawCoordinating(IntentProcessor processor, IntentData pending, IntentData current) {
- this.processor = checkNotNull(processor);
- this.pending = checkNotNull(pending);
- this.current = checkNotNull(current);
- }
-
- @Override
- public Optional<IntentProcessPhase> execute() {
- try {
- // Note: current.installables() are not null or empty due to createIntentUpdate check
- FlowRuleOperations flowRules = processor.uninstallCoordinate(current, pending);
- pending.setInstallables(current.installables());
- return Optional.of(new Withdrawing(processor, pending, flowRules));
- } catch (IntentException e) {
- log.warn("Unable to generate generate a FlowRuleOperations from intent {} due to:", pending.intent(), e);
- return Optional.of(new WithdrawingFailed(pending));
- }
- }
-}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawRequest.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawRequest.java
index 7940cf7..004bb33 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawRequest.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawRequest.java
@@ -28,13 +28,21 @@
final class WithdrawRequest implements IntentProcessPhase {
private final IntentProcessor processor;
- private final IntentData pending;
- private final IntentData current;
+ private final IntentData data;
+ private final IntentData stored;
- WithdrawRequest(IntentProcessor processor, IntentData intentData, IntentData current) {
+ /**
+ * Creates a withdraw request phase.
+ *
+ * @param processor intent processor to be passed to intent process phases
+ * generated after this phase
+ * @param intentData intent data to be processed
+ * @param stored intent data stored in the store
+ */
+ WithdrawRequest(IntentProcessor processor, IntentData intentData, IntentData stored) {
this.processor = checkNotNull(processor);
- this.pending = checkNotNull(intentData);
- this.current = checkNotNull(current);
+ this.data = checkNotNull(intentData);
+ this.stored = checkNotNull(stored);
}
@Override
@@ -42,6 +50,7 @@
//TODO perhaps we want to validate that the pending and current are the
// same version i.e. they are the same
// Note: this call is not just the symmetric version of submit
- return Optional.of(new WithdrawCoordinating(processor, pending, current));
+ data.setInstallables(stored.installables());
+ return Optional.of(new Withdrawing(processor, data));
}
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawing.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawing.java
index 9198d0e..9351a96 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawing.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawing.java
@@ -15,33 +15,40 @@
*/
package org.onosproject.net.intent.impl.phase;
-import org.onosproject.net.flow.FlowRuleOperations;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.impl.IntentProcessor;
-import java.util.Optional;
-
import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.net.intent.IntentState.WITHDRAWING;
/**
- * Represents a phase of withdrawing an intent with calling
- * {@link org.onosproject.net.flow.FlowRuleService}.
+ * Represents a phase where an intent is withdrawing.
*/
-class Withdrawing implements IntentProcessPhase {
+class Withdrawing extends FinalIntentProcessPhase {
private final IntentProcessor processor;
- private final IntentData pending;
- private final FlowRuleOperations flowRules;
+ private final IntentData data;
- Withdrawing(IntentProcessor processor, IntentData pending, FlowRuleOperations flowRules) {
+ /**
+ * Creates a withdrawing phase.
+ *
+ * @param processor intent processor that does work for withdrawing
+ * @param data intent data containing an intent to be withdrawn
+ */
+ Withdrawing(IntentProcessor processor, IntentData data) {
this.processor = checkNotNull(processor);
- this.pending = checkNotNull(pending);
- this.flowRules = checkNotNull(flowRules);
+ this.data = checkNotNull(data);
+
+ this.data.setState(WITHDRAWING);
}
@Override
- public Optional<IntentProcessPhase> execute() {
- processor.applyFlowRules(flowRules);
- return Optional.of(new Withdrawn(pending));
+ protected void preExecute() {
+ processor.uninstall(data);
+ }
+
+ @Override
+ public IntentData data() {
+ return data;
}
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawingFailed.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawingFailed.java
deleted file mode 100644
index 4e6874e..0000000
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawingFailed.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.net.intent.impl.phase;
-
-import org.onosproject.net.intent.IntentData;
-
-/**
- * Represents a phase where the withdraw has failed.
- */
-final class WithdrawingFailed extends AbstractFailed {
-
- /**
- * Create an instance with the specified data.
- *
- * @param intentData intentData
- */
- WithdrawingFailed(IntentData intentData) {
- super(intentData);
- }
-}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawn.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawn.java
index b8e724b..264f74c 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawn.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawn.java
@@ -16,29 +16,29 @@
package org.onosproject.net.intent.impl.phase;
import org.onosproject.net.intent.IntentData;
-import org.onosproject.net.intent.IntentState;
import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onosproject.net.intent.IntentState.WITHDRAWING;
+import static org.onosproject.net.intent.IntentState.WITHDRAWN;
/**
* Represents a phase where an intent has been withdrawn.
*/
final class Withdrawn extends FinalIntentProcessPhase {
- private final IntentData intentData;
+ private final IntentData data;
- Withdrawn(IntentData intentData) {
- this(intentData, WITHDRAWING);
- }
-
- Withdrawn(IntentData intentData, IntentState newState) {
- this.intentData = checkNotNull(intentData);
- this.intentData.setState(newState);
+ /**
+ * Create a withdrawn phase.
+ *
+ * @param data intent data containing an intent to be withdrawn
+ */
+ Withdrawn(IntentData data) {
+ this.data = checkNotNull(data);
+ this.data.setState(WITHDRAWN);
}
@Override
public IntentData data() {
- return intentData;
+ return data;
}
}