summaryrefslogtreecommitdiffstats
path: root/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl')
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/CompilerRegistry.java128
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentAccumulator.java82
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentCleanup.java256
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentCompilationException.java37
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentInstallationException.java37
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java489
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentProcessor.java46
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentRemovalException.java37
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java455
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTrackerService.java69
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/PathNotFoundException.java46
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/TopologyChangeDelegate.java37
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/ConnectivityIntentCompiler.java152
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java110
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java138
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java106
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java320
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java151
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java390
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java281
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompiler.java191
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java116
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java104
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java85
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/TwoWayP2PIntentCompiler.java72
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/package-info.java20
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/package-info.java21
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java73
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Corrupt.java44
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Failed.java44
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/FinalIntentProcessPhase.java44
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallRequest.java55
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Installing.java58
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/IntentProcessPhase.java73
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/IntentWorker.java52
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/PurgeRequest.java70
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawRequest.java70
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawing.java55
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawn.java44
-rw-r--r--framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/package-info.java20
40 files changed, 0 insertions, 4678 deletions
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/CompilerRegistry.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/CompilerRegistry.java
deleted file mode 100644
index 1b70bc67..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/CompilerRegistry.java
+++ /dev/null
@@ -1,128 +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.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.IntentCompiler;
-import org.onosproject.net.intent.IntentException;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-// TODO: consider a better name
-class CompilerRegistry {
-
- private final ConcurrentMap<Class<? extends Intent>,
- IntentCompiler<? extends Intent>> compilers = new ConcurrentHashMap<>();
-
- /**
- * Registers the specified compiler for the given intent class.
- *
- * @param cls intent class
- * @param compiler intent compiler
- * @param <T> the type of intent
- */
- public <T extends Intent> void registerCompiler(Class<T> cls, IntentCompiler<T> compiler) {
- compilers.put(cls, compiler);
- }
-
- /**
- * Unregisters the compiler for the specified intent class.
- *
- * @param cls intent class
- * @param <T> the type of intent
- */
- public <T extends Intent> void unregisterCompiler(Class<T> cls) {
- compilers.remove(cls);
- }
-
- /**
- * Returns immutable set of bindings of currently registered intent compilers.
- *
- * @return the set of compiler bindings
- */
- public Map<Class<? extends Intent>, IntentCompiler<? extends Intent>> getCompilers() {
- return ImmutableMap.copyOf(compilers);
- }
-
- /**
- * Compiles an intent recursively.
- *
- * @param intent intent
- * @param previousInstallables previous intent installables
- * @return result of compilation
- */
- List<Intent> compile(Intent intent, List<Intent> previousInstallables) {
- if (intent.isInstallable()) {
- return ImmutableList.of(intent);
- }
-
- registerSubclassCompilerIfNeeded(intent);
- // FIXME: get previous resources
- List<Intent> installable = new ArrayList<>();
- for (Intent compiled : getCompiler(intent).compile(intent, previousInstallables, null)) {
- installable.addAll(compile(compiled, previousInstallables));
- }
- return installable;
- }
-
- /**
- * Returns the corresponding intent compiler to the specified intent.
- *
- * @param intent intent
- * @param <T> the type of intent
- * @return intent compiler corresponding to the specified intent
- */
- private <T extends Intent> IntentCompiler<T> getCompiler(T intent) {
- @SuppressWarnings("unchecked")
- IntentCompiler<T> compiler = (IntentCompiler<T>) compilers.get(intent.getClass());
- if (compiler == null) {
- throw new IntentException("no compiler for class " + intent.getClass());
- }
- return compiler;
- }
-
- /**
- * Registers an intent compiler of the specified intent if an intent compiler
- * for the intent is not registered. This method traverses the class hierarchy of
- * the intent. Once an intent compiler for a parent type is found, this method
- * registers the found intent compiler.
- *
- * @param intent intent
- */
- private void registerSubclassCompilerIfNeeded(Intent intent) {
- if (!compilers.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)) {
- IntentCompiler<?> compiler = compilers.get(cls);
- if (compiler != null) {
- compilers.put(intent.getClass(), compiler);
- return;
- }
- }
- cls = cls.getSuperclass();
- }
- }
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentAccumulator.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentAccumulator.java
deleted file mode 100644
index 54276ad4..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentAccumulator.java
+++ /dev/null
@@ -1,82 +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.Maps;
-import org.onlab.util.AbstractAccumulator;
-import org.onosproject.net.intent.IntentBatchDelegate;
-import org.onosproject.net.intent.IntentData;
-import org.onosproject.net.intent.Key;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Timer;
-
-/**
- * An accumulator for building batches of intent operations. Only one batch should
- * be in process per instance at a time.
- */
-public class IntentAccumulator extends AbstractAccumulator<IntentData> {
-
- private static final int DEFAULT_MAX_EVENTS = 1000;
- private static final int DEFAULT_MAX_IDLE_MS = 10;
- private static final int DEFAULT_MAX_BATCH_MS = 50;
-
- // FIXME: Replace with a system-wide timer instance;
- // TODO: Convert to use HashedWheelTimer or produce a variant of that; then decide which we want to adopt
- private static final Timer TIMER = new Timer("onos-intent-op-batching");
-
- private final IntentBatchDelegate delegate;
-
- private volatile boolean ready;
-
- /**
- * Creates an intent operation accumulator.
- *
- * @param delegate the intent batch delegate
- */
- protected IntentAccumulator(IntentBatchDelegate delegate) {
- super(TIMER, DEFAULT_MAX_EVENTS, DEFAULT_MAX_BATCH_MS, DEFAULT_MAX_IDLE_MS);
- this.delegate = delegate;
- // Assume that the delegate is ready for work at the start
- ready = true; //TODO validate the assumption that delegate is ready
- }
-
- @Override
- public void processItems(List<IntentData> items) {
- ready = false;
- delegate.execute(reduce(items));
- }
-
- private Collection<IntentData> reduce(List<IntentData> ops) {
- Map<Key, IntentData> map = Maps.newHashMap();
- for (IntentData op : ops) {
- map.put(op.key(), op);
- }
- //TODO check the version... or maybe store will handle this.
- return map.values();
- }
-
- @Override
- public boolean isReady() {
- return ready;
- }
-
- public void ready() {
- ready = true;
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentCleanup.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentCleanup.java
deleted file mode 100644
index a387d6f4..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentCleanup.java
+++ /dev/null
@@ -1,256 +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 org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Modified;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.onosproject.cfg.ComponentConfigService;
-import org.onosproject.net.intent.IntentData;
-import org.onosproject.net.intent.IntentEvent;
-import org.onosproject.net.intent.IntentListener;
-import org.onosproject.net.intent.IntentService;
-import org.onosproject.net.intent.IntentStore;
-import org.onosproject.net.intent.Key;
-import org.osgi.service.component.ComponentContext;
-import org.slf4j.Logger;
-
-import java.util.Dictionary;
-import java.util.Properties;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.ExecutorService;
-
-import static com.google.common.base.Strings.isNullOrEmpty;
-import static java.util.concurrent.Executors.newSingleThreadExecutor;
-import static org.onlab.util.Tools.get;
-import static org.onlab.util.Tools.groupedThreads;
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * This component cleans up intents that have encountered errors or otherwise
- * stalled during installation or withdrawal.
- * <p>
- * It periodically polls (based on configured period) for pending and CORRUPT
- * intents from the store and retries. It also listens for CORRUPT event
- * notifications, which signify errors in processing, and retries.
- * </p>
- */
-@Component(immediate = true)
-public class IntentCleanup implements Runnable, IntentListener {
-
- private static final Logger log = getLogger(IntentCleanup.class);
-
- private static final int DEFAULT_PERIOD = 5; //seconds
- private static final int DEFAULT_THRESHOLD = 5; //tries
-
- @Property(name = "enabled", boolValue = true,
- label = "Enables/disables the intent cleanup component")
- private boolean enabled = true;
-
- @Property(name = "period", intValue = DEFAULT_PERIOD,
- label = "Frequency in ms between cleanup runs")
- protected int period = DEFAULT_PERIOD;
- private long periodMs;
-
- @Property(name = "retryThreshold", intValue = DEFAULT_THRESHOLD,
- label = "Number of times to retry CORRUPT intent without delay")
- protected int retryThreshold = DEFAULT_THRESHOLD;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected IntentService service;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected IntentStore store;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected ComponentConfigService cfgService;
-
- private ExecutorService executor;
- private Timer timer;
- private TimerTask timerTask;
-
- @Activate
- public void activate() {
- cfgService.registerProperties(getClass());
- executor = newSingleThreadExecutor(groupedThreads("onos/intent", "cleanup"));
- timer = new Timer("onos-intent-cleanup-timer");
- service.addListener(this);
- adjustRate();
- log.info("Started");
- }
-
- @Deactivate
- public void deactivate() {
- cfgService.unregisterProperties(getClass(), false);
- service.removeListener(this);
- timer.cancel();
- timerTask = null;
- executor.shutdown();
- log.info("Stopped");
- }
-
- @Modified
- public void modified(ComponentContext context) {
- Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
-
- int newPeriod;
- boolean newEnabled;
- try {
- String s = get(properties, "period");
- newPeriod = isNullOrEmpty(s) ? period : Integer.parseInt(s.trim());
-
- s = get(properties, "retryThreshold");
- retryThreshold = isNullOrEmpty(s) ? retryThreshold : Integer.parseInt(s.trim());
-
- s = get(properties, "enabled");
- newEnabled = isNullOrEmpty(s) ? enabled : Boolean.parseBoolean(s.trim());
- } catch (NumberFormatException e) {
- log.warn(e.getMessage());
- newPeriod = period;
- newEnabled = enabled;
- }
-
- // Any change in the following parameters implies hard restart
- if (newPeriod != period || enabled != newEnabled) {
- period = newPeriod;
- enabled = newEnabled;
- adjustRate();
- }
-
- log.info("Settings: enabled={}, period={}, retryThreshold={}",
- enabled, period, retryThreshold);
- }
-
- protected void adjustRate() {
- if (timerTask != null) {
- timerTask.cancel();
- timerTask = null;
- }
-
- if (enabled) {
- timerTask = new TimerTask() {
- @Override
- public void run() {
- executor.submit(IntentCleanup.this);
- }
- };
-
- periodMs = period * 1_000; //convert to ms
- timer.scheduleAtFixedRate(timerTask, periodMs, periodMs);
- }
- }
-
-
- @Override
- public void run() {
- try {
- cleanup();
- } catch (Exception e) {
- log.warn("Caught exception during Intent cleanup", e);
- }
- }
-
- private void resubmitCorrupt(IntentData intentData, boolean checkThreshold) {
- if (checkThreshold && intentData.errorCount() >= retryThreshold) {
- return; // threshold met or exceeded
- }
-
- switch (intentData.request()) {
- case INSTALL_REQ:
- service.submit(intentData.intent());
- break;
- case WITHDRAW_REQ:
- service.withdraw(intentData.intent());
- break;
- default:
- log.warn("Trying to resubmit corrupt/failed intent {} in state {} with request {}",
- intentData.key(), intentData.state(), intentData.request());
- break;
- }
- }
-
- private void resubmitPendingRequest(IntentData intentData) {
- switch (intentData.request()) {
- case INSTALL_REQ:
- service.submit(intentData.intent());
- break;
- case WITHDRAW_REQ:
- service.withdraw(intentData.intent());
- break;
- default:
- log.warn("Failed to resubmit pending intent {} in state {} with request {}",
- intentData.key(), intentData.state(), intentData.request());
- break;
- }
- }
-
- /**
- * Iterates through corrupt, failed and pending intents and
- * re-submit/withdraw appropriately.
- */
- private void cleanup() {
- int corruptCount = 0, failedCount = 0, stuckCount = 0, pendingCount = 0;
-
- for (IntentData intentData : store.getIntentData(true, periodMs)) {
- switch (intentData.state()) {
- case FAILED:
- resubmitCorrupt(intentData, false);
- failedCount++;
- break;
- case CORRUPT:
- resubmitCorrupt(intentData, false);
- corruptCount++;
- break;
- case INSTALLING: //FALLTHROUGH
- case WITHDRAWING:
- resubmitPendingRequest(intentData);
- stuckCount++;
- break;
- default:
- //NOOP
- break;
- }
- }
-
- for (IntentData intentData : store.getPendingData(true, periodMs)) {
- resubmitPendingRequest(intentData);
- stuckCount++;
- }
-
- if (corruptCount + failedCount + stuckCount + pendingCount > 0) {
- log.debug("Intent cleanup ran and resubmitted {} corrupt, {} failed, {} stuck, and {} pending intents",
- corruptCount, failedCount, stuckCount, pendingCount);
- }
- }
-
- @Override
- public void event(IntentEvent event) {
- // this is the fast path for CORRUPT intents, retry on event notification.
- //TODO we might consider using the timer to back off for subsequent retries
- if (enabled && event.type() == IntentEvent.Type.CORRUPT) {
- Key key = event.subject().key();
- if (store.isMaster(key)) {
- IntentData data = store.getIntentData(event.subject().key());
- resubmitCorrupt(data, true);
- }
- }
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentCompilationException.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentCompilationException.java
deleted file mode 100644
index ae93336c..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentCompilationException.java
+++ /dev/null
@@ -1,37 +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;
-
-import org.onosproject.net.intent.IntentException;
-
-/**
- * An exception thrown when a intent compilation fails.
- */
-public class IntentCompilationException extends IntentException {
- private static final long serialVersionUID = 235237603018210810L;
-
- public IntentCompilationException() {
- super();
- }
-
- public IntentCompilationException(String message) {
- super(message);
- }
-
- public IntentCompilationException(String message, Throwable cause) {
- super(message, cause);
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentInstallationException.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentInstallationException.java
deleted file mode 100644
index db21fe4a..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentInstallationException.java
+++ /dev/null
@@ -1,37 +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;
-
-import org.onosproject.net.intent.IntentException;
-
-/**
- * An exception thrown when intent installation fails.
- */
-public class IntentInstallationException extends IntentException {
- private static final long serialVersionUID = 3720268258616014168L;
-
- public IntentInstallationException() {
- super();
- }
-
- public IntentInstallationException(String message) {
- super(message);
- }
-
- public IntentInstallationException(String message, Throwable cause) {
- super(message, cause);
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
deleted file mode 100644
index baa3bf4d..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
+++ /dev/null
@@ -1,489 +0,0 @@
-/*
- * Copyright 2014-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.ImmutableList;
-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.apache.felix.scr.annotations.Service;
-import org.onosproject.event.AbstractListenerManager;
-import org.onosproject.core.CoreService;
-import org.onosproject.core.IdGenerator;
-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.IntentListener;
-import org.onosproject.net.intent.IntentService;
-import org.onosproject.net.intent.IntentState;
-import org.onosproject.net.intent.IntentStore;
-import org.onosproject.net.intent.IntentStoreDelegate;
-import org.onosproject.net.intent.Key;
-import org.onosproject.net.intent.impl.phase.FinalIntentProcessPhase;
-import org.onosproject.net.intent.impl.phase.IntentProcessPhase;
-import org.onosproject.net.intent.impl.phase.IntentWorker;
-import org.slf4j.Logger;
-
-import java.util.Collection;
-import java.util.EnumSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-import java.util.stream.Collectors;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static java.util.concurrent.Executors.newFixedThreadPool;
-import static java.util.concurrent.Executors.newSingleThreadExecutor;
-import static org.onlab.util.Tools.groupedThreads;
-import static org.onosproject.net.intent.IntentState.*;
-import static org.onosproject.net.intent.constraint.PartialFailureConstraint.intentAllowsPartialFailure;
-import static org.onosproject.net.intent.impl.phase.IntentProcessPhase.newInitialPhase;
-import static org.onosproject.security.AppGuard.checkPermission;
-import static org.slf4j.LoggerFactory.getLogger;
-import static org.onosproject.security.AppPermission.Type.*;
-
-
-/**
- * An implementation of intent service.
- */
-@Component(immediate = true)
-@Service
-public class IntentManager
- extends AbstractListenerManager<IntentEvent, IntentListener>
- implements IntentService, IntentExtensionService {
-
- private static final Logger log = getLogger(IntentManager.class);
-
- public static final String INTENT_NULL = "Intent cannot be null";
- public static final String INTENT_ID_NULL = "Intent key cannot be null";
-
- private static final int NUM_THREADS = 12;
-
- private static final EnumSet<IntentState> RECOMPILE
- = EnumSet.of(INSTALL_REQ, FAILED, WITHDRAW_REQ);
- private static final EnumSet<IntentState> WITHDRAW
- = EnumSet.of(WITHDRAW_REQ, WITHDRAWING, WITHDRAWN);
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected CoreService coreService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected IntentStore store;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected ObjectiveTrackerService trackerService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected FlowRuleService flowRuleService;
-
- private ExecutorService batchExecutor;
- private ExecutorService workerExecutor;
-
- private final CompilerRegistry compilerRegistry = new CompilerRegistry();
- private final InternalIntentProcessor processor = new InternalIntentProcessor();
- private final IntentStoreDelegate delegate = new InternalStoreDelegate();
- private final TopologyChangeDelegate topoDelegate = new InternalTopoChangeDelegate();
- private final IntentBatchDelegate batchDelegate = new InternalBatchDelegate();
- private IdGenerator idGenerator;
-
- private final IntentAccumulator accumulator = new IntentAccumulator(batchDelegate);
-
- @Activate
- public void activate() {
- store.setDelegate(delegate);
- trackerService.setDelegate(topoDelegate);
- eventDispatcher.addSink(IntentEvent.class, listenerRegistry);
- batchExecutor = newSingleThreadExecutor(groupedThreads("onos/intent", "batch"));
- workerExecutor = newFixedThreadPool(NUM_THREADS, groupedThreads("onos/intent", "worker-%d"));
- idGenerator = coreService.getIdGenerator("intent-ids");
- Intent.bindIdGenerator(idGenerator);
- log.info("Started");
- }
-
- @Deactivate
- public void deactivate() {
- store.unsetDelegate(delegate);
- trackerService.unsetDelegate(topoDelegate);
- eventDispatcher.removeSink(IntentEvent.class);
- batchExecutor.shutdown();
- workerExecutor.shutdown();
- Intent.unbindIdGenerator(idGenerator);
- log.info("Stopped");
- }
-
- @Override
- public void submit(Intent intent) {
- checkPermission(INTENT_WRITE);
- checkNotNull(intent, INTENT_NULL);
- IntentData data = new IntentData(intent, IntentState.INSTALL_REQ, null);
- store.addPending(data);
- }
-
- @Override
- public void withdraw(Intent intent) {
- checkPermission(INTENT_WRITE);
- checkNotNull(intent, INTENT_NULL);
- IntentData data = new IntentData(intent, IntentState.WITHDRAW_REQ, null);
- store.addPending(data);
- }
-
- @Override
- public void purge(Intent intent) {
- checkPermission(INTENT_WRITE);
- checkNotNull(intent, INTENT_NULL);
- IntentData data = new IntentData(intent, IntentState.PURGE_REQ, null);
- store.addPending(data);
- }
-
- @Override
- public Intent getIntent(Key key) {
- checkPermission(INTENT_READ);
- return store.getIntent(key);
- }
-
- @Override
- public Iterable<Intent> getIntents() {
- checkPermission(INTENT_READ);
- return store.getIntents();
- }
-
- @Override
- public Iterable<IntentData> getIntentData() {
- checkPermission(INTENT_READ);
- return store.getIntentData(false, 0);
- }
-
- @Override
- public long getIntentCount() {
- checkPermission(INTENT_READ);
- return store.getIntentCount();
- }
-
- @Override
- public IntentState getIntentState(Key intentKey) {
- checkPermission(INTENT_READ);
- checkNotNull(intentKey, INTENT_ID_NULL);
- return store.getIntentState(intentKey);
- }
-
- @Override
- public List<Intent> getInstallableIntents(Key intentKey) {
- checkPermission(INTENT_READ);
- checkNotNull(intentKey, INTENT_ID_NULL);
- return store.getInstallableIntents(intentKey);
- }
-
- @Override
- public boolean isLocal(Key intentKey) {
- checkPermission(INTENT_READ);
- return store.isMaster(intentKey);
- }
-
- @Override
- public <T extends Intent> void registerCompiler(Class<T> cls, IntentCompiler<T> compiler) {
- compilerRegistry.registerCompiler(cls, compiler);
- }
-
- @Override
- public <T extends Intent> void unregisterCompiler(Class<T> cls) {
- compilerRegistry.unregisterCompiler(cls);
- }
-
- @Override
- public Map<Class<? extends Intent>, IntentCompiler<? extends Intent>> getCompilers() {
- return compilerRegistry.getCompilers();
- }
-
- @Override
- public Iterable<Intent> getPending() {
- checkPermission(INTENT_READ);
-
- return store.getPending();
- }
-
- // Store delegate to re-post events emitted from the store.
- private class InternalStoreDelegate implements IntentStoreDelegate {
- @Override
- public void notify(IntentEvent event) {
- post(event);
- }
-
- @Override
- public void process(IntentData data) {
- accumulator.add(data);
- }
-
- @Override
- public void onUpdate(IntentData intentData) {
- trackerService.trackIntent(intentData);
- }
- }
-
- private void buildAndSubmitBatches(Iterable<Key> intentKeys,
- boolean compileAllFailed) {
- // Attempt recompilation of the specified intents first.
- for (Key key : intentKeys) {
- Intent intent = store.getIntent(key);
- if (intent == null) {
- continue;
- }
- submit(intent);
- }
-
- if (compileAllFailed) {
- // If required, compile all currently failed intents.
- for (Intent intent : getIntents()) {
- IntentState state = getIntentState(intent.key());
- if (RECOMPILE.contains(state) || intentAllowsPartialFailure(intent)) {
- if (WITHDRAW.contains(state)) {
- withdraw(intent);
- } else {
- submit(intent);
- }
- }
- }
- }
-
- //FIXME
-// for (ApplicationId appId : batches.keySet()) {
-// if (batchService.isLocalLeader(appId)) {
-// execute(batches.get(appId).build());
-// }
-// }
- }
-
- // Topology change delegate
- private class InternalTopoChangeDelegate implements TopologyChangeDelegate {
- @Override
- public void triggerCompile(Iterable<Key> intentKeys,
- boolean compileAllFailed) {
- buildAndSubmitBatches(intentKeys, compileAllFailed);
- }
- }
-
- private Future<FinalIntentProcessPhase> submitIntentData(IntentData data) {
- IntentData current = store.getIntentData(data.key());
- IntentProcessPhase initial = newInitialPhase(processor, data, current);
- return workerExecutor.submit(new IntentWorker(initial));
- }
-
- private class IntentBatchProcess implements Runnable {
-
- protected final Collection<IntentData> data;
-
- IntentBatchProcess(Collection<IntentData> data) {
- this.data = checkNotNull(data);
- }
-
- @Override
- public void run() {
- try {
- /*
- 1. wrap each intentdata in a runnable and submit
- 2. wait for completion of all the work
- 3. accumulate results and submit batch write of IntentData to store
- (we can also try to update these individually)
- */
- submitUpdates(waitForFutures(createIntentUpdates()));
- } catch (Exception e) {
- log.error("Error submitting batches:", e);
- // FIXME incomplete Intents should be cleaned up
- // (transition to FAILED, etc.)
-
- // the batch has failed
- // TODO: maybe we should do more?
- log.error("Walk the plank, matey...");
- //FIXME
-// batchService.removeIntentOperations(data);
- }
- accumulator.ready();
- }
-
- private List<Future<FinalIntentProcessPhase>> createIntentUpdates() {
- return data.stream()
- .map(IntentManager.this::submitIntentData)
- .collect(Collectors.toList());
- }
-
- private List<FinalIntentProcessPhase> waitForFutures(List<Future<FinalIntentProcessPhase>> futures) {
- ImmutableList.Builder<FinalIntentProcessPhase> updateBuilder = ImmutableList.builder();
- for (Future<FinalIntentProcessPhase> future : futures) {
- try {
- updateBuilder.add(future.get());
- } catch (InterruptedException | ExecutionException e) {
- //FIXME
- log.warn("Future failed: {}", e);
- }
- }
- return updateBuilder.build();
- }
-
- private void submitUpdates(List<FinalIntentProcessPhase> updates) {
- store.batchWrite(updates.stream()
- .map(FinalIntentProcessPhase::data)
- .collect(Collectors.toList()));
- }
- }
-
- private class InternalBatchDelegate implements IntentBatchDelegate {
- @Override
- public void execute(Collection<IntentData> operations) {
- log.debug("Execute {} operation(s).", operations.size());
- log.trace("Execute operations: {}", operations);
-
- // batchExecutor is single-threaded, so only one batch is in flight at a time
- batchExecutor.execute(new IntentBatchProcess(operations));
- }
- }
-
- private class InternalIntentProcessor implements IntentProcessor {
- @Override
- public List<Intent> compile(Intent intent, List<Intent> previousInstallables) {
- return compilerRegistry.compile(intent, previousInstallables);
- }
-
- @Override
- public void apply(Optional<IntentData> toUninstall, Optional<IntentData> toInstall) {
- IntentManager.this.apply(toUninstall, toInstall);
- }
- }
-
- private enum Direction {
- ADD,
- REMOVE
- }
-
- private void applyIntentData(Optional<IntentData> intentData,
- FlowRuleOperations.Builder builder,
- Direction direction) {
- if (!intentData.isPresent()) {
- return;
- }
- IntentData data = intentData.get();
-
- List<Intent> intentsToApply = data.installables();
- if (!intentsToApply.stream().allMatch(x -> x instanceof FlowRuleIntent)) {
- throw new IllegalStateException("installable intents must be FlowRuleIntent");
- }
-
- if (direction == Direction.ADD) {
- trackerService.addTrackedResources(data.key(), data.intent().resources());
- intentsToApply.forEach(installable ->
- trackerService.addTrackedResources(data.key(), installable.resources()));
- } else {
- trackerService.removeTrackedResources(data.key(), data.intent().resources());
- intentsToApply.forEach(installable ->
- trackerService.removeTrackedResources(data.intent().key(),
- installable.resources()));
- }
-
- // FIXME do FlowRuleIntents have stages??? Can we do uninstall work in parallel? I think so.
- builder.newStage();
-
- List<Collection<FlowRule>> stages = intentsToApply.stream()
- .map(x -> (FlowRuleIntent) x)
- .map(FlowRuleIntent::flowRules)
- .collect(Collectors.toList());
-
- for (Collection<FlowRule> rules : stages) {
- if (direction == Direction.ADD) {
- rules.forEach(builder::add);
- } else {
- rules.forEach(builder::remove);
- }
- }
-
- }
-
- private void apply(Optional<IntentData> toUninstall, Optional<IntentData> toInstall) {
- // need to consider if FlowRuleIntent is only one as installable intent or not
-
- FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
- applyIntentData(toUninstall, builder, Direction.REMOVE);
- applyIntentData(toInstall, builder, Direction.ADD);
-
- FlowRuleOperations operations = builder.build(new FlowRuleOperationsContext() {
- @Override
- public void onSuccess(FlowRuleOperations ops) {
- if (toInstall.isPresent()) {
- IntentData installData = toInstall.get();
- log.debug("Completed installing: {}", installData.key());
- installData.setState(INSTALLED);
- store.write(installData);
- } else if (toUninstall.isPresent()) {
- IntentData uninstallData = toUninstall.get();
- log.debug("Completed withdrawing: {}", uninstallData.key());
- switch (uninstallData.request()) {
- case INSTALL_REQ:
- uninstallData.setState(FAILED);
- break;
- case WITHDRAW_REQ:
- default: //TODO "default" case should not happen
- uninstallData.setState(WITHDRAWN);
- break;
- }
- store.write(uninstallData);
- }
- }
-
- @Override
- public void onError(FlowRuleOperations ops) {
- // if toInstall was cause of error, then recompile (manage/increment counter, when exceeded -> CORRUPT)
- if (toInstall.isPresent()) {
- IntentData installData = toInstall.get();
- log.warn("Failed installation: {} {} on {}",
- installData.key(), installData.intent(), ops);
- installData.setState(CORRUPT);
- installData.incrementErrorCount();
- store.write(installData);
- }
- // if toUninstall was cause of error, then CORRUPT (another job will clean this up)
- if (toUninstall.isPresent()) {
- IntentData uninstallData = toUninstall.get();
- log.warn("Failed withdrawal: {} {} on {}",
- uninstallData.key(), uninstallData.intent(), ops);
- uninstallData.setState(CORRUPT);
- uninstallData.incrementErrorCount();
- store.write(uninstallData);
- }
- }
- });
-
- if (log.isTraceEnabled()) {
- log.trace("applying intent {} -> {} with {} rules: {}",
- toUninstall.isPresent() ? toUninstall.get().key() : "<empty>",
- toInstall.isPresent() ? toInstall.get().key() : "<empty>",
- operations.stages().stream().mapToLong(i -> i.size()).sum(),
- operations.stages());
- }
-
- flowRuleService.apply(operations);
- }
-
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentProcessor.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentProcessor.java
deleted file mode 100644
index 5469c766..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentProcessor.java
+++ /dev/null
@@ -1,46 +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 org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.IntentData;
-
-import java.util.List;
-import java.util.Optional;
-
-/**
- * A collection of methods to process an intent.
- *
- * This interface is public, but intended to be used only by IntentManager and
- * IntentProcessPhase subclasses stored under phase package.
- */
-public interface IntentProcessor {
-
- /**
- * Compiles an intent recursively.
- *
- * @param intent intent
- * @param previousInstallables previous intent installables
- * @return result of compilation
- */
- List<Intent> compile(Intent intent, List<Intent> previousInstallables);
-
- /**
- * @param toUninstall Intent data describing flows to uninstall.
- * @param toInstall Intent data describing flows to install.
- */
- void apply(Optional<IntentData> toUninstall, Optional<IntentData> toInstall);
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentRemovalException.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentRemovalException.java
deleted file mode 100644
index 20530c0c..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/IntentRemovalException.java
+++ /dev/null
@@ -1,37 +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;
-
-import org.onosproject.net.intent.IntentException;
-
-/**
- * An exception thrown when intent removal failed.
- */
-public class IntentRemovalException extends IntentException {
- private static final long serialVersionUID = -5259226322037891951L;
-
- public IntentRemovalException() {
- super();
- }
-
- public IntentRemovalException(String message) {
- super(message);
- }
-
- public IntentRemovalException(String message, Throwable cause) {
- super(message, cause);
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java
deleted file mode 100644
index ff711a02..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java
+++ /dev/null
@@ -1,455 +0,0 @@
-/*
- * Copyright 2014-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.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.apache.felix.scr.annotations.ReferencePolicy;
-import org.apache.felix.scr.annotations.Service;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.event.Event;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.ElementId;
-import org.onosproject.net.HostId;
-import org.onosproject.net.Link;
-import org.onosproject.net.LinkKey;
-import org.onosproject.net.NetworkResource;
-import org.onosproject.net.PortNumber;
-import org.onosproject.net.device.DeviceEvent;
-import org.onosproject.net.device.DeviceListener;
-import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.host.HostEvent;
-import org.onosproject.net.host.HostListener;
-import org.onosproject.net.host.HostService;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.IntentData;
-import org.onosproject.net.intent.IntentService;
-import org.onosproject.net.intent.Key;
-import org.onosproject.net.intent.PartitionEvent;
-import org.onosproject.net.intent.PartitionEventListener;
-import org.onosproject.net.intent.PartitionService;
-import org.onosproject.net.link.LinkEvent;
-import org.onosproject.net.newresource.ResourceEvent;
-import org.onosproject.net.newresource.ResourceListener;
-import org.onosproject.net.newresource.ResourceService;
-import org.onosproject.net.topology.TopologyEvent;
-import org.onosproject.net.topology.TopologyListener;
-import org.onosproject.net.topology.TopologyService;
-import org.slf4j.Logger;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Multimaps.synchronizedSetMultimap;
-import static java.util.concurrent.Executors.newSingleThreadExecutor;
-import static org.onlab.util.Tools.groupedThreads;
-import static org.onlab.util.Tools.isNullOrEmpty;
-import static org.onosproject.net.LinkKey.linkKey;
-import static org.onosproject.net.intent.IntentState.INSTALLED;
-import static org.onosproject.net.intent.IntentState.INSTALLING;
-import static org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED;
-import static org.onosproject.net.link.LinkEvent.Type.LINK_UPDATED;
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * Entity responsible for tracking installed flows and for monitoring topology
- * events to determine what flows are affected by topology changes.
- */
-@Component(immediate = true)
-@Service
-public class ObjectiveTracker implements ObjectiveTrackerService {
-
- private final Logger log = getLogger(getClass());
-
- private final SetMultimap<LinkKey, Key> intentsByLink =
- //TODO this could be slow as a point of synchronization
- synchronizedSetMultimap(HashMultimap.<LinkKey, Key>create());
-
- private final SetMultimap<ElementId, Key> intentsByDevice =
- synchronizedSetMultimap(HashMultimap.<ElementId, Key>create());
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected TopologyService topologyService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected ResourceService resourceService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected DeviceService deviceService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected HostService hostService;
-
- @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY,
- policy = ReferencePolicy.DYNAMIC)
- protected IntentService intentService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected PartitionService partitionService;
-
- private ExecutorService executorService =
- newSingleThreadExecutor(groupedThreads("onos/intent", "objectivetracker"));
- private ScheduledExecutorService executor = Executors
- .newScheduledThreadPool(1);
-
- private TopologyListener listener = new InternalTopologyListener();
- private ResourceListener resourceListener = new InternalResourceListener();
- private DeviceListener deviceListener = new InternalDeviceListener();
- private HostListener hostListener = new InternalHostListener();
- private PartitionEventListener partitionListener = new InternalPartitionListener();
- private TopologyChangeDelegate delegate;
-
- protected final AtomicBoolean updateScheduled = new AtomicBoolean(false);
-
- @Activate
- public void activate() {
- topologyService.addListener(listener);
- resourceService.addListener(resourceListener);
- deviceService.addListener(deviceListener);
- hostService.addListener(hostListener);
- partitionService.addListener(partitionListener);
- log.info("Started");
- }
-
- @Deactivate
- public void deactivate() {
- topologyService.removeListener(listener);
- resourceService.removeListener(resourceListener);
- deviceService.removeListener(deviceListener);
- hostService.removeListener(hostListener);
- partitionService.removeListener(partitionListener);
- log.info("Stopped");
- }
-
- protected void bindIntentService(IntentService service) {
- if (intentService == null) {
- intentService = service;
- }
- }
-
- protected void unbindIntentService(IntentService service) {
- if (intentService == service) {
- intentService = null;
- }
- }
-
- @Override
- public void setDelegate(TopologyChangeDelegate delegate) {
- checkNotNull(delegate, "Delegate cannot be null");
- checkArgument(this.delegate == null || this.delegate == delegate,
- "Another delegate already set");
- this.delegate = delegate;
- }
-
- @Override
- public void unsetDelegate(TopologyChangeDelegate delegate) {
- checkArgument(this.delegate == delegate, "Not the current delegate");
- this.delegate = null;
- }
-
- @Override
- public void addTrackedResources(Key intentKey,
- Collection<NetworkResource> resources) {
- for (NetworkResource resource : resources) {
- if (resource instanceof Link) {
- intentsByLink.put(linkKey((Link) resource), intentKey);
- } else if (resource instanceof ElementId) {
- intentsByDevice.put((ElementId) resource, intentKey);
- }
- }
- }
-
- @Override
- public void removeTrackedResources(Key intentKey,
- Collection<NetworkResource> resources) {
- for (NetworkResource resource : resources) {
- if (resource instanceof Link) {
- intentsByLink.remove(linkKey((Link) resource), intentKey);
- } else if (resource instanceof ElementId) {
- intentsByDevice.remove(resource, intentKey);
- }
- }
- }
-
- @Override
- public void trackIntent(IntentData intentData) {
-
- //NOTE: This will be called for intents that are being added to the store
- // locally (i.e. every intent update)
-
- Key key = intentData.key();
- Intent intent = intentData.intent();
- boolean isLocal = intentService.isLocal(key);
- boolean isInstalled = intentData.state() == INSTALLING ||
- intentData.state() == INSTALLED;
- List<Intent> installables = intentData.installables();
-
- if (log.isTraceEnabled()) {
- log.trace("intent {}, old: {}, new: {}, installableCount: {}, resourceCount: {}",
- key,
- intentsByDevice.values().contains(key),
- isLocal && isInstalled,
- installables.size(),
- intent.resources().size() +
- installables.stream()
- .mapToLong(i -> i.resources().size()).sum());
- }
-
- if (isNullOrEmpty(installables) && intentData.state() == INSTALLED) {
- log.warn("Intent {} is INSTALLED with no installables", key);
- }
-
- // FIXME Intents will be added 3 times (once directly using addTracked,
- // then when installing and when installed)
- if (isLocal && isInstalled) {
- addTrackedResources(key, intent.resources());
- for (Intent installable : installables) {
- addTrackedResources(key, installable.resources());
- }
- // FIXME check all resources against current topo service(s); recompile if necessary
- } else {
- removeTrackedResources(key, intent.resources());
- for (Intent installable : installables) {
- removeTrackedResources(key, installable.resources());
- }
- }
- }
-
- // Internal re-actor to topology change events.
- private class InternalTopologyListener implements TopologyListener {
- @Override
- public void event(TopologyEvent event) {
- executorService.execute(new TopologyChangeHandler(event));
- }
- }
-
- // Re-dispatcher of topology change events.
- private class TopologyChangeHandler implements Runnable {
-
- private final TopologyEvent event;
-
- TopologyChangeHandler(TopologyEvent event) {
- this.event = event;
- }
-
- @Override
- public void run() {
- // If there is no delegate, why bother? Just bail.
- if (delegate == null) {
- return;
- }
-
- if (event.reasons() == null || event.reasons().isEmpty()) {
- delegate.triggerCompile(Collections.emptySet(), true);
-
- } else {
- Set<Key> intentsToRecompile = new HashSet<>();
- boolean dontRecompileAllFailedIntents = true;
-
- // Scan through the list of reasons and keep accruing all
- // intents that need to be recompiled.
- for (Event reason : event.reasons()) {
- if (reason instanceof LinkEvent) {
- LinkEvent linkEvent = (LinkEvent) reason;
- final LinkKey linkKey = linkKey(linkEvent.subject());
- synchronized (intentsByLink) {
- Set<Key> intentKeys = intentsByLink.get(linkKey);
- log.debug("recompile triggered by LinkEvent {} ({}) for {}",
- linkKey, linkEvent.type(), intentKeys);
- intentsToRecompile.addAll(intentKeys);
- }
- dontRecompileAllFailedIntents = dontRecompileAllFailedIntents &&
- (linkEvent.type() == LINK_REMOVED ||
- (linkEvent.type() == LINK_UPDATED &&
- linkEvent.subject().isDurable()));
- }
- }
- delegate.triggerCompile(intentsToRecompile, !dontRecompileAllFailedIntents);
- }
- }
- }
-
- private class InternalResourceListener implements ResourceListener {
- @Override
- public void event(ResourceEvent event) {
- Optional<Class<?>> deviceEvent = event.subject().components().stream()
- .map(Object::getClass)
- .filter(x -> x == PortNumber.class)
- .findFirst();
- if (deviceEvent.isPresent()) {
- executorService.execute(() -> {
- if (delegate == null) {
- return;
- }
-
- delegate.triggerCompile(Collections.emptySet(), true);
- });
- }
- }
- }
-
- //TODO consider adding flow rule event tracking
-
- private void updateTrackedResources(ApplicationId appId, boolean track) {
- if (intentService == null) {
- log.warn("Intent service is not bound yet");
- return;
- }
- intentService.getIntents().forEach(intent -> {
- if (intent.appId().equals(appId)) {
- Key key = intent.key();
- Collection<NetworkResource> resources = Lists.newArrayList();
- intentService.getInstallableIntents(key).stream()
- .map(installable -> installable.resources())
- .forEach(resources::addAll);
- if (track) {
- addTrackedResources(key, resources);
- } else {
- removeTrackedResources(key, resources);
- }
- }
- });
- }
-
- /*
- * Re-dispatcher of device and host events.
- */
- private class DeviceAvailabilityHandler implements Runnable {
-
- private final ElementId id;
- private final boolean available;
-
- DeviceAvailabilityHandler(ElementId id, boolean available) {
- this.id = checkNotNull(id);
- this.available = available;
- }
-
- @Override
- public void run() {
- // If there is no delegate, why bother? Just bail.
- if (delegate == null) {
- return;
- }
-
- // TODO should we recompile on available==true?
-
- final ImmutableSet<Key> snapshot;
- synchronized (intentsByDevice) {
- snapshot = ImmutableSet.copyOf(intentsByDevice.get(id));
- }
- delegate.triggerCompile(snapshot, available);
- }
- }
-
-
- private class InternalDeviceListener implements DeviceListener {
- @Override
- public void event(DeviceEvent event) {
- DeviceEvent.Type type = event.type();
- switch (type) {
- case DEVICE_ADDED:
- case DEVICE_AVAILABILITY_CHANGED:
- case DEVICE_REMOVED:
- case DEVICE_SUSPENDED:
- case DEVICE_UPDATED:
- DeviceId id = event.subject().id();
- // TODO we need to check whether AVAILABILITY_CHANGED means up or down
- boolean available = (type == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED ||
- type == DeviceEvent.Type.DEVICE_ADDED ||
- type == DeviceEvent.Type.DEVICE_UPDATED);
- executorService.execute(new DeviceAvailabilityHandler(id, available));
- break;
- case PORT_ADDED:
- case PORT_REMOVED:
- case PORT_UPDATED:
- case PORT_STATS_UPDATED:
- default:
- // Don't handle port events for now
- break;
- }
- }
- }
-
- private class InternalHostListener implements HostListener {
- @Override
- public void event(HostEvent event) {
- HostId id = event.subject().id();
- switch (event.type()) {
- case HOST_ADDED:
- case HOST_MOVED:
- case HOST_REMOVED:
- executorService.execute(new DeviceAvailabilityHandler(id, false));
- break;
- case HOST_UPDATED:
- default:
- // DO NOTHING
- break;
- }
- }
- }
-
- protected void doIntentUpdate() {
- updateScheduled.set(false);
- if (intentService == null) {
- log.warn("Intent service is not bound yet");
- return;
- }
- try {
- //FIXME very inefficient
- for (IntentData intentData : intentService.getIntentData()) {
- try {
- trackIntent(intentData);
- } catch (NullPointerException npe) {
- log.warn("intent error {}", intentData.key(), npe);
- }
- }
- } catch (Exception e) {
- log.warn("Exception caught during update task", e);
- }
- }
-
- private void scheduleIntentUpdate(int afterDelaySec) {
- if (updateScheduled.compareAndSet(false, true)) {
- executor.schedule(this::doIntentUpdate, afterDelaySec, TimeUnit.SECONDS);
- }
- }
-
- private final class InternalPartitionListener implements PartitionEventListener {
- @Override
- public void event(PartitionEvent event) {
- log.debug("got message {}", event.subject());
- scheduleIntentUpdate(1);
- }
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTrackerService.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTrackerService.java
deleted file mode 100644
index b7d367d7..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTrackerService.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2014-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 org.onosproject.net.NetworkResource;
-import org.onosproject.net.intent.IntentData;
-import org.onosproject.net.intent.Key;
-
-import java.util.Collection;
-
-/**
- * Auxiliary service for tracking intent path flows and for notifying the
- * intent service of environment changes via topology change delegate.
- */
-public interface ObjectiveTrackerService {
-
- /**
- * Sets a topology change delegate.
- *
- * @param delegate topology change delegate
- */
- void setDelegate(TopologyChangeDelegate delegate);
-
- /**
- * Unsets topology change delegate.
- *
- * @param delegate topology change delegate
- */
- void unsetDelegate(TopologyChangeDelegate delegate);
-
- /**
- * Adds a path flow to be tracked.
- *
- * @param intentKey intent identity on whose behalf the path is being tracked
- * @param resources resources to track
- */
- // TODO consider using the IntentData here rather than just the key
- void addTrackedResources(Key intentKey,
- Collection<NetworkResource> resources);
-
- /**
- * Removes a path flow to be tracked.
- *
- * @param intentKey intent identity on whose behalf the path is being tracked
- * @param resources resources to stop tracking
- */
- void removeTrackedResources(Key intentKey,
- Collection<NetworkResource> resources);
-
- /**
- * Submits the specified intent data to be tracked.
- *
- * @param intentData intent data object to be tracked
- */
- void trackIntent(IntentData intentData);
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/PathNotFoundException.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/PathNotFoundException.java
deleted file mode 100644
index c06e9fd2..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/PathNotFoundException.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2014-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.base.MoreObjects;
-import org.onosproject.net.ElementId;
-import org.onosproject.net.intent.IntentException;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * An exception thrown when a path is not found.
- */
-public class PathNotFoundException extends IntentException {
- private static final long serialVersionUID = -2087045731049914733L;
-
- private final ElementId source;
- private final ElementId destination;
-
- public PathNotFoundException(ElementId source, ElementId destination) {
- super(String.format("No path from %s to %s", source, destination));
- this.source = checkNotNull(source);
- this.destination = checkNotNull(destination);
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(this)
- .add("source", source)
- .add("destination", destination)
- .toString();
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/TopologyChangeDelegate.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/TopologyChangeDelegate.java
deleted file mode 100644
index 49b114d5..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/TopologyChangeDelegate.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2014-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 org.onosproject.net.intent.Key;
-
-/**
- * Auxiliary delegate for integration of intent manager and flow trackerService.
- */
-public interface TopologyChangeDelegate {
-
- /**
- * Notifies that topology has changed in such a way that the specified
- * intents should be recompiled. If the {@code compileAllFailed} parameter
- * is true, then all intents in {@link org.onosproject.net.intent.IntentState#FAILED}
- * state should be compiled as well.
- *
- * @param intentIds intents that should be recompiled
- * @param compileAllFailed true implies full compile of all failed intents
- * is required; false for selective recompile only
- */
- void triggerCompile(Iterable<Key> intentIds, boolean compileAllFailed);
-
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/ConnectivityIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/ConnectivityIntentCompiler.java
deleted file mode 100644
index 6de4cfdc..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/ConnectivityIntentCompiler.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright 2014-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.FluentIterable;
-import com.google.common.collect.ImmutableList;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.onosproject.net.ElementId;
-import org.onosproject.net.Path;
-import org.onosproject.net.intent.ConnectivityIntent;
-import org.onosproject.net.intent.Constraint;
-import org.onosproject.net.intent.IntentCompiler;
-import org.onosproject.net.intent.IntentExtensionService;
-import org.onosproject.net.intent.impl.PathNotFoundException;
-import org.onosproject.net.provider.ProviderId;
-import org.onosproject.net.resource.link.LinkResourceService;
-import org.onosproject.net.topology.LinkWeight;
-import org.onosproject.net.topology.PathService;
-import org.onosproject.net.topology.TopologyEdge;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Base class for compilers of various
- * {@link org.onosproject.net.intent.ConnectivityIntent connectivity intents}.
- */
-@Component(immediate = true)
-public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent>
- implements IntentCompiler<T> {
-
- private static final ProviderId PID = new ProviderId("core", "org.onosproject.core", true);
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected IntentExtensionService intentManager;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected PathService pathService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected LinkResourceService resourceService;
-
- /**
- * Returns an edge-weight capable of evaluating links on the basis of the
- * specified constraints.
- *
- * @param constraints path constraints
- * @return edge-weight function
- */
- protected LinkWeight weight(List<Constraint> constraints) {
- return new ConstraintBasedLinkWeight(constraints);
- }
-
- /**
- * Validates the specified path against the given constraints.
- *
- * @param path path to be checked
- * @param constraints path constraints
- * @return true if the path passes all constraints
- */
- protected boolean checkPath(Path path, List<Constraint> constraints) {
- for (Constraint constraint : constraints) {
- if (!constraint.validate(path, resourceService)) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Computes a path between two ConnectPoints.
- *
- * @param intent intent on which behalf path is being computed
- * @param one start of the path
- * @param two end of the path
- * @return Path between the two
- * @throws PathNotFoundException if a path cannot be found
- */
- protected Path getPath(ConnectivityIntent intent,
- ElementId one, ElementId two) {
- Set<Path> paths = pathService.getPaths(one, two, weight(intent.constraints()));
- final List<Constraint> constraints = intent.constraints();
- ImmutableList<Path> filtered = FluentIterable.from(paths)
- .filter(path -> checkPath(path, constraints))
- .toList();
- if (filtered.isEmpty()) {
- throw new PathNotFoundException(one, two);
- }
- // TODO: let's be more intelligent about this eventually
- return filtered.iterator().next();
- }
-
- /**
- * Edge-weight capable of evaluating link cost using a set of constraints.
- */
- protected class ConstraintBasedLinkWeight implements LinkWeight {
-
- private final List<Constraint> constraints;
-
- /**
- * Creates a new edge-weight function capable of evaluating links
- * on the basis of the specified constraints.
- *
- * @param constraints path constraints
- */
- ConstraintBasedLinkWeight(List<Constraint> constraints) {
- if (constraints == null) {
- this.constraints = Collections.emptyList();
- } else {
- this.constraints = ImmutableList.copyOf(constraints);
- }
- }
-
- @Override
- public double weight(TopologyEdge edge) {
- if (!constraints.iterator().hasNext()) {
- return 1.0;
- }
-
- // iterate over all constraints in order and return the weight of
- // the first one with fast fail over the first failure
- Iterator<Constraint> it = constraints.iterator();
-
- double cost = it.next().cost(edge.link(), resourceService);
- while (it.hasNext() && cost > 0) {
- if (it.next().cost(edge.link(), resourceService) < 0) {
- return -1;
- }
- }
- return cost;
-
- }
- }
-
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
deleted file mode 100644
index 41168258..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2014-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.net.DefaultLink;
-import org.onosproject.net.DefaultPath;
-import org.onosproject.net.Host;
-import org.onosproject.net.Link;
-import org.onosproject.net.Path;
-import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.net.host.HostService;
-import org.onosproject.net.intent.HostToHostIntent;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.PathIntent;
-import org.onosproject.net.intent.constraint.AsymmetricPathConstraint;
-import org.onosproject.net.resource.link.LinkResourceAllocations;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
-
-import static org.onosproject.net.flow.DefaultTrafficSelector.builder;
-
-/**
- * A intent compiler for {@link HostToHostIntent}.
- */
-@Component(immediate = true)
-public class HostToHostIntentCompiler
- extends ConnectivityIntentCompiler<HostToHostIntent> {
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected HostService hostService;
-
- @Activate
- public void activate() {
- intentManager.registerCompiler(HostToHostIntent.class, this);
- }
-
- @Deactivate
- public void deactivate() {
- intentManager.unregisterCompiler(HostToHostIntent.class);
- }
-
- @Override
- public List<Intent> compile(HostToHostIntent intent, List<Intent> installable,
- Set<LinkResourceAllocations> resources) {
- boolean isAsymmetric = intent.constraints().contains(new AsymmetricPathConstraint());
- Path pathOne = getPath(intent, intent.one(), intent.two());
- Path pathTwo = isAsymmetric ?
- getPath(intent, intent.two(), intent.one()) : invertPath(pathOne);
-
- Host one = hostService.getHost(intent.one());
- Host two = hostService.getHost(intent.two());
-
- return Arrays.asList(createPathIntent(pathOne, one, two, intent),
- createPathIntent(pathTwo, two, one, intent));
- }
-
- // Inverts the specified path. This makes an assumption that each link in
- // the path has a reverse link available. Under most circumstances, this
- // assumption will hold.
- private Path invertPath(Path path) {
- List<Link> reverseLinks = new ArrayList<>(path.links().size());
- for (Link link : path.links()) {
- reverseLinks.add(0, reverseLink(link));
- }
- return new DefaultPath(path.providerId(), reverseLinks, path.cost());
- }
-
- // Produces a reverse variant of the specified link.
- private Link reverseLink(Link link) {
- return new DefaultLink(link.providerId(), link.dst(), link.src(),
- link.type(), link.state(), link.isDurable());
- }
-
- // Creates a path intent from the specified path and original connectivity intent.
- private Intent createPathIntent(Path path, Host src, Host dst,
- HostToHostIntent intent) {
- TrafficSelector selector = builder(intent.selector())
- .matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
- return PathIntent.builder()
- .appId(intent.appId())
- .selector(selector)
- .treatment(intent.treatment())
- .path(path)
- .constraints(intent.constraints())
- .priority(intent.priority())
- .build();
- }
-
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java
deleted file mode 100644
index 76c5736d..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java
+++ /dev/null
@@ -1,138 +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.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.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.link.LinkResourceAllocations;
-
-import java.util.ArrayList;
-import java.util.Collections;
-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 Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources()));
- }
-
- 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;
- }
-
- FlowRule rule = DefaultFlowRule.builder()
- .forDevice(deviceId)
- .withSelector(selector)
- .withTreatment(treatment)
- .withPriority(intent.priority())
- .fromApp(appId)
- .makePermanent()
- .build();
- rules.add(rule);
- }
-
- return rules;
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java
deleted file mode 100644
index 52621e2f..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java
+++ /dev/null
@@ -1,106 +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.compiler;
-
-import static java.util.Arrays.asList;
-import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DefaultPath;
-import org.onosproject.net.Link;
-import org.onosproject.net.Path;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.MplsIntent;
-import org.onosproject.net.intent.MplsPathIntent;
-import org.onosproject.net.provider.ProviderId;
-import org.onosproject.net.resource.link.LinkResourceAllocations;
-
-
-@Component(immediate = true)
-public class MplsIntentCompiler extends ConnectivityIntentCompiler<MplsIntent> {
-
- // TODO: use off-the-shell core provider ID
- private static final ProviderId PID =
- new ProviderId("core", "org.onosproject.core", true);
- // TODO: consider whether the default cost is appropriate or not
- public static final int DEFAULT_COST = 1;
-
-
- @Activate
- public void activate() {
- intentManager.registerCompiler(MplsIntent.class, this);
- }
-
- @Deactivate
- public void deactivate() {
- intentManager.unregisterCompiler(MplsIntent.class);
- }
-
- @Override
- public List<Intent> compile(MplsIntent intent, List<Intent> installable,
- Set<LinkResourceAllocations> resources) {
- ConnectPoint ingressPoint = intent.ingressPoint();
- ConnectPoint egressPoint = intent.egressPoint();
-
- if (ingressPoint.deviceId().equals(egressPoint.deviceId())) {
- List<Link> links = asList(createEdgeLink(ingressPoint, true), createEdgeLink(egressPoint, false));
- return asList(createPathIntent(new DefaultPath(PID, links, DEFAULT_COST), intent));
- }
-
- List<Link> links = new ArrayList<>();
- Path path = getPath(intent, ingressPoint.deviceId(),
- egressPoint.deviceId());
-
- links.add(createEdgeLink(ingressPoint, true));
- links.addAll(path.links());
-
- links.add(createEdgeLink(egressPoint, false));
-
- return asList(createPathIntent(new DefaultPath(PID, links, path.cost(),
- path.annotations()), intent));
- }
-
- /**
- * Creates a path intent from the specified path and original
- * connectivity intent.
- *
- * @param path path to create an intent for
- * @param intent original intent
- */
- private Intent createPathIntent(Path path,
- MplsIntent intent) {
- return MplsPathIntent.builder()
- .appId(intent.appId())
- .selector(intent.selector())
- .treatment(intent.treatment())
- .path(path)
- .ingressLabel(intent.ingressLabel())
- .egressLabel(intent.egressLabel())
- .constraints(intent.constraints())
- .priority(intent.priority())
- .build();
- }
-
-
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
deleted file mode 100644
index 5549918c..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
+++ /dev/null
@@ -1,320 +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.compiler;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Sets;
-
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.onlab.packet.EthType;
-import org.onlab.packet.Ethernet;
-import org.onlab.packet.MplsLabel;
-import org.onlab.packet.VlanId;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.Link;
-import org.onosproject.net.LinkKey;
-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.flow.criteria.Criterion;
-import org.onosproject.net.flow.criteria.EthTypeCriterion;
-import org.onosproject.net.flow.instructions.Instruction;
-import org.onosproject.net.flow.instructions.L2ModificationInstruction;
-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.MplsPathIntent;
-import org.onosproject.net.newresource.ResourcePath;
-import org.onosproject.net.newresource.ResourceService;
-import org.onosproject.net.resource.link.LinkResourceAllocations;
-import org.slf4j.Logger;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onosproject.net.LinkKey.linkKey;
-import static org.slf4j.LoggerFactory.getLogger;
-
-@Component(immediate = true)
-public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> {
-
- private final Logger log = getLogger(getClass());
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected IntentExtensionService intentExtensionService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected CoreService coreService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected ResourceService resourceService;
-
- protected ApplicationId appId;
-
- @Override
- public List<Intent> compile(MplsPathIntent intent, List<Intent> installable,
- Set<LinkResourceAllocations> resources) {
- Map<LinkKey, MplsLabel> labels = assignMplsLabel(intent);
- List<FlowRule> rules = generateRules(intent, labels);
-
- return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources()));
- }
-
- @Activate
- public void activate() {
- appId = coreService.registerApplication("org.onosproject.net.intent");
- intentExtensionService.registerCompiler(MplsPathIntent.class, this);
- }
-
- @Deactivate
- public void deactivate() {
- intentExtensionService.unregisterCompiler(MplsPathIntent.class);
- }
-
- private Map<LinkKey, MplsLabel> assignMplsLabel(MplsPathIntent intent) {
- // TODO: do it better... Suggestions?
- Set<LinkKey> linkRequest = Sets.newHashSetWithExpectedSize(intent.path()
- .links().size() - 2);
- for (int i = 1; i <= intent.path().links().size() - 2; i++) {
- LinkKey link = linkKey(intent.path().links().get(i));
- linkRequest.add(link);
- // add the inverse link. I want that the label is reserved both for
- // the direct and inverse link
- linkRequest.add(linkKey(link.dst(), link.src()));
- }
-
- Map<LinkKey, MplsLabel> labels = findMplsLabels(linkRequest);
- if (labels.isEmpty()) {
- return Collections.emptyMap();
- }
-
- // for short term solution: same label is used for both directions
- // TODO: introduce the concept of Tx and Rx resources of a port
- Set<ResourcePath> resources = labels.entrySet().stream()
- .flatMap(x -> Stream.of(
- ResourcePath.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue()),
- ResourcePath.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue())
- ))
- .collect(Collectors.toSet());
- List<org.onosproject.net.newresource.ResourceAllocation> allocations =
- resourceService.allocate(intent.id(), ImmutableList.copyOf(resources));
- if (allocations.isEmpty()) {
- Collections.emptyMap();
- }
-
- return labels;
- }
-
- private Map<LinkKey, MplsLabel> findMplsLabels(Set<LinkKey> links) {
- Map<LinkKey, MplsLabel> labels = new HashMap<>();
- for (LinkKey link : links) {
- Set<MplsLabel> forward = findMplsLabel(link.src());
- Set<MplsLabel> backward = findMplsLabel(link.dst());
- Set<MplsLabel> common = Sets.intersection(forward, backward);
- if (common.isEmpty()) {
- continue;
- }
- labels.put(link, common.iterator().next());
- }
-
- return labels;
- }
-
- private Set<MplsLabel> findMplsLabel(ConnectPoint cp) {
- return resourceService.getAvailableResources(ResourcePath.discrete(cp.deviceId(), cp.port())).stream()
- .filter(x -> x.last() instanceof MplsLabel)
- .map(x -> (MplsLabel) x.last())
- .collect(Collectors.toSet());
- }
-
- private MplsLabel getMplsLabel(Map<LinkKey, MplsLabel> labels, LinkKey link) {
- return labels.get(link);
- }
-
- private List<FlowRule> generateRules(MplsPathIntent intent,
- Map<LinkKey, MplsLabel> labels) {
-
- Iterator<Link> links = intent.path().links().iterator();
- Link srcLink = links.next();
- ConnectPoint prev = srcLink.dst();
-
- Link link = links.next();
- // List of flow rules to be installed
- List<FlowRule> rules = new LinkedList<>();
-
- // Ingress traffic
- // Get the new MPLS label
- MplsLabel mpls = getMplsLabel(labels, linkKey(link));
- checkNotNull(mpls);
- MplsLabel prevLabel = mpls;
- rules.add(ingressFlow(prev.port(), link, intent, mpls));
-
- prev = link.dst();
-
- while (links.hasNext()) {
-
- link = links.next();
-
- if (links.hasNext()) {
- // Transit traffic
- // Get the new MPLS label
- mpls = getMplsLabel(labels, linkKey(link));
- checkNotNull(mpls);
- rules.add(transitFlow(prev.port(), link, intent,
- prevLabel, mpls));
- prevLabel = mpls;
-
- } else {
- // Egress traffic
- rules.add(egressFlow(prev.port(), link, intent,
- prevLabel));
- }
-
- prev = link.dst();
- }
- return rules;
- }
-
- private FlowRule ingressFlow(PortNumber inPort, Link link,
- MplsPathIntent intent,
- MplsLabel label) {
-
- TrafficSelector.Builder ingressSelector = DefaultTrafficSelector
- .builder(intent.selector());
- TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder();
- ingressSelector.matchInPort(inPort);
-
- if (intent.ingressLabel().isPresent()) {
- ingressSelector.matchEthType(Ethernet.MPLS_UNICAST)
- .matchMplsLabel(intent.ingressLabel().get());
-
- // Swap the MPLS label
- treat.setMpls(label);
- } else {
- // Push and set the MPLS label
- treat.pushMpls().setMpls(label);
- }
- // Add the output action
- treat.setOutput(link.src().port());
-
- return createFlowRule(intent, link.src().deviceId(), ingressSelector.build(), treat.build());
- }
-
- 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
- TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
- selector.matchInPort(inPort).matchEthType(Ethernet.MPLS_UNICAST)
- .matchMplsLabel(prevLabel);
- TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder();
-
- // Set the new label only if the label on the packet is
- // different
- if (!prevLabel.equals(outLabel)) {
- treat.setMpls(outLabel);
- }
-
- treat.setOutput(link.src().port());
- return createFlowRule(intent, link.src().deviceId(), selector.build(), treat.build());
- }
-
- 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
-
- TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
- selector.matchInPort(inPort).matchEthType(Ethernet.MPLS_UNICAST)
- .matchMplsLabel(prevLabel);
-
- // apply the intent's treatments
- TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder(intent
- .treatment());
-
- // check if the treatement is popVlan or setVlan (rewrite),
- // than selector needs to match any VlanId
- for (Instruction instruct : intent.treatment().allInstructions()) {
- if (instruct instanceof L2ModificationInstruction) {
- L2ModificationInstruction l2Mod = (L2ModificationInstruction) instruct;
- if (l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_PUSH) {
- break;
- }
- if (l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_POP ||
- l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) {
- selector.matchVlanId(VlanId.ANY);
- }
- }
- }
-
- if (intent.egressLabel().isPresent()) {
- treat.setMpls(intent.egressLabel().get());
- } else {
- treat.popMpls(outputEthType(intent.selector()));
- }
- treat.setOutput(link.src().port());
- return createFlowRule(intent, link.src().deviceId(),
- selector.build(), treat.build());
- }
-
- protected FlowRule createFlowRule(MplsPathIntent intent, DeviceId deviceId,
- TrafficSelector selector, TrafficTreatment treat) {
- return DefaultFlowRule.builder()
- .forDevice(deviceId)
- .withSelector(selector)
- .withTreatment(treat)
- .withPriority(intent.priority())
- .fromApp(appId)
- .makePermanent()
- .build();
- }
-
- // if the ingress ethertype is defined, the egress traffic
- // will be use that value, otherwise the IPv4 ethertype is used.
- private EthType outputEthType(TrafficSelector selector) {
- Criterion c = selector.getCriterion(Criterion.Type.ETH_TYPE);
- if (c != null && c instanceof EthTypeCriterion) {
- EthTypeCriterion ethertype = (EthTypeCriterion) c;
- return ethertype.ethType();
- } else {
- return EthType.EtherType.IPV4.ethType();
- }
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
deleted file mode 100644
index 06d0e9a2..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Copyright 2014-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.Sets;
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.Link;
-import org.onosproject.net.Path;
-import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.IntentCompiler;
-import org.onosproject.net.intent.IntentException;
-import org.onosproject.net.intent.IntentExtensionService;
-import org.onosproject.net.intent.LinkCollectionIntent;
-import org.onosproject.net.intent.MultiPointToSinglePointIntent;
-import org.onosproject.net.intent.PointToPointIntent;
-import org.onosproject.net.resource.link.LinkResourceAllocations;
-import org.onosproject.net.topology.PathService;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import static org.onosproject.net.intent.constraint.PartialFailureConstraint.intentAllowsPartialFailure;
-
-
-/**
- * An intent compiler for
- * {@link org.onosproject.net.intent.MultiPointToSinglePointIntent}.
- */
-@Component(immediate = true)
-public class MultiPointToSinglePointIntentCompiler
- implements IntentCompiler<MultiPointToSinglePointIntent> {
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected IntentExtensionService intentManager;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected PathService pathService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected DeviceService deviceService;
-
- @Activate
- public void activate() {
- intentManager.registerCompiler(MultiPointToSinglePointIntent.class, this);
- }
-
- @Deactivate
- public void deactivate() {
- intentManager.unregisterCompiler(PointToPointIntent.class);
- }
-
- @Override
- public List<Intent> compile(MultiPointToSinglePointIntent intent, List<Intent> installable,
- Set<LinkResourceAllocations> resources) {
- Map<DeviceId, Link> links = new HashMap<>();
- ConnectPoint egressPoint = intent.egressPoint();
-
- final boolean allowMissingPaths = intentAllowsPartialFailure(intent);
- boolean partialTree = false;
- boolean anyMissingPaths = false;
- for (ConnectPoint ingressPoint : intent.ingressPoints()) {
- if (ingressPoint.deviceId().equals(egressPoint.deviceId())) {
- if (deviceService.isAvailable(ingressPoint.deviceId())) {
- partialTree = true;
- } else {
- anyMissingPaths = true;
- }
-
- continue;
- }
-
- Path path = getPath(ingressPoint, intent.egressPoint());
- if (path != null) {
- partialTree = true;
-
- for (Link link : path.links()) {
- if (links.containsKey(link.dst().deviceId())) {
- // We've already reached the existing tree with the first
- // part of this path. Add the merging point with different
- // incoming port, but don't add the remainder of the path
- // in case it differs from the path we already have.
- links.put(link.src().deviceId(), link);
- break;
- }
- links.put(link.src().deviceId(), link);
- }
- } else {
- anyMissingPaths = true;
- }
- }
-
- if (!partialTree) {
- throw new IntentException("Could not find any paths between ingress and egress points.");
- } else if (!allowMissingPaths && anyMissingPaths) {
- throw new IntentException("Missing some paths between ingress and egress ports.");
- }
-
- Intent result = LinkCollectionIntent.builder()
- .appId(intent.appId())
- .selector(intent.selector())
- .treatment(intent.treatment())
- .links(Sets.newHashSet(links.values()))
- .ingressPoints(intent.ingressPoints())
- .egressPoints(ImmutableSet.of(intent.egressPoint()))
- .priority(intent.priority())
- .constraints(intent.constraints())
- .build();
-
- return Collections.singletonList(result);
- }
-
- /**
- * Computes a path between two ConnectPoints.
- *
- * @param one start of the path
- * @param two end of the path
- * @return Path between the two
- */
- private Path getPath(ConnectPoint one, ConnectPoint two) {
- Set<Path> paths = pathService.getPaths(one.deviceId(), two.deviceId());
- if (paths.isEmpty()) {
- return null;
- }
- // TODO: let's be more intelligent about this eventually
- return paths.iterator().next();
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java
deleted file mode 100644
index ee04aab5..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java
+++ /dev/null
@@ -1,390 +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.compiler;
-
-import org.apache.commons.lang3.tuple.Pair;
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Modified;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.onlab.util.Tools;
-import org.onosproject.cfg.ComponentConfigService;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.net.AnnotationKeys;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.OchPort;
-import org.onosproject.net.OduCltPort;
-import org.onosproject.net.OduSignalType;
-import org.onosproject.net.Port;
-import org.onosproject.net.device.DeviceService;
-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.IntentId;
-import org.onosproject.net.intent.IntentService;
-import org.onosproject.net.intent.OpticalCircuitIntent;
-import org.onosproject.net.intent.OpticalConnectivityIntent;
-import org.onosproject.net.intent.impl.IntentCompilationException;
-import org.onosproject.net.newresource.ResourceAllocation;
-import org.onosproject.net.newresource.ResourcePath;
-import org.onosproject.net.newresource.ResourceService;
-import org.onosproject.net.resource.device.IntentSetMultimap;
-import org.onosproject.net.resource.link.LinkResourceAllocations;
-import org.osgi.service.component.ComponentContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-/**
- * An intent compiler for {@link org.onosproject.net.intent.OpticalCircuitIntent}.
- */
-// For now, remove component designation until dependency on the new resource manager is available.
-@Component(immediate = true)
-public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircuitIntent> {
-
- private static final Logger log = LoggerFactory.getLogger(OpticalCircuitIntentCompiler.class);
-
- private static final int DEFAULT_MAX_CAPACITY = 10;
-
- @Property(name = "maxCapacity", intValue = DEFAULT_MAX_CAPACITY,
- label = "Maximum utilization of an optical connection.")
-
- private int maxCapacity = DEFAULT_MAX_CAPACITY;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected ComponentConfigService cfgService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected IntentExtensionService intentManager;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected CoreService coreService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected DeviceService deviceService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected ResourceService resourceService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected IntentSetMultimap intentSetMultimap;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected IntentService intentService;
-
- private ApplicationId appId;
-
- @Modified
- public void modified(ComponentContext context) {
- Dictionary properties = context.getProperties();
-
- //TODO for reduction check if the new capacity is smaller than the size of the current mapping
- String propertyString = Tools.get(properties, "maxCapacity");
-
- //Ignore if propertyString is empty
- if (!propertyString.isEmpty()) {
- try {
- int temp = Integer.parseInt(propertyString);
- //Ensure value is non-negative but allow zero as a way to shutdown the link
- if (temp >= 0) {
- maxCapacity = temp;
- }
- } catch (NumberFormatException e) {
- //Malformed arguments lead to no change of value (user should be notified of error)
- log.error("The value '{}' for maxCapacity was not parsable as an integer.", propertyString, e);
- }
- } else {
- //Notify of empty value but do not return (other properties will also go in this function)
- log.error("The value for maxCapacity was set to an empty value.");
- }
-
- }
-
- @Activate
- public void activate(ComponentContext context) {
- appId = coreService.registerApplication("org.onosproject.net.intent");
- intentManager.registerCompiler(OpticalCircuitIntent.class, this);
- cfgService.registerProperties(getClass());
- modified(context);
- }
-
- @Deactivate
- public void deactivate() {
- intentManager.unregisterCompiler(OpticalCircuitIntent.class);
- cfgService.unregisterProperties(getClass(), false);
- }
-
- @Override
- public List<Intent> compile(OpticalCircuitIntent intent, List<Intent> installable,
- Set<LinkResourceAllocations> resources) {
- // Check if ports are OduClt ports
- ConnectPoint src = intent.getSrc();
- ConnectPoint dst = intent.getDst();
- Port srcPort = deviceService.getPort(src.deviceId(), src.port());
- Port dstPort = deviceService.getPort(dst.deviceId(), dst.port());
- checkArgument(srcPort instanceof OduCltPort);
- checkArgument(dstPort instanceof OduCltPort);
-
- log.debug("Compiling optical circuit intent between {} and {}", src, dst);
-
- // Reserve OduClt ports
- ResourcePath srcPortPath = ResourcePath.discrete(src.deviceId(), src.port());
- ResourcePath dstPortPath = ResourcePath.discrete(dst.deviceId(), dst.port());
- List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortPath, dstPortPath);
- if (allocation.isEmpty()) {
- throw new IntentCompilationException("Unable to reserve ports for intent " + intent);
- }
-
- LinkedList<Intent> intents = new LinkedList<>();
-
- FlowRuleIntent circuitIntent;
- OpticalConnectivityIntent connIntent = findOpticalConnectivityIntent(intent);
-
- // Create optical connectivity intent if needed
- if (connIntent == null) {
- // Find OCh ports with available resources
- Pair<OchPort, OchPort> ochPorts = findPorts(intent);
-
- if (ochPorts == null) {
- return Collections.emptyList();
- }
-
- // Create optical connectivity intent
- ConnectPoint srcCP = new ConnectPoint(src.elementId(), ochPorts.getLeft().number());
- ConnectPoint dstCP = new ConnectPoint(dst.elementId(), ochPorts.getRight().number());
- // FIXME: hardcoded ODU signal type
- connIntent = OpticalConnectivityIntent.builder()
- .appId(appId)
- .src(srcCP)
- .dst(dstCP)
- .signalType(OduSignalType.ODU4)
- .bidirectional(intent.isBidirectional())
- .build();
- intentService.submit(connIntent);
- }
-
- // Create optical circuit intent
- List<FlowRule> rules = new LinkedList<>();
- rules.add(connectPorts(src, connIntent.getSrc(), intent.priority()));
- rules.add(connectPorts(connIntent.getDst(), dst, intent.priority()));
-
- // Create flow rules for reverse path
- if (intent.isBidirectional()) {
- rules.add(connectPorts(connIntent.getSrc(), src, intent.priority()));
- rules.add(connectPorts(dst, connIntent.getDst(), intent.priority()));
- }
-
- circuitIntent = new FlowRuleIntent(appId, rules, intent.resources());
-
- // Save circuit to connectivity intent mapping
- intentSetMultimap.allocateMapping(connIntent.id(), intent.id());
- intents.add(circuitIntent);
-
- return intents;
- }
-
- /**
- * Checks if current allocations on given resource can satisfy request.
- * If the resource is null, return true.
- *
- * @param resource the resource on which to map the intent
- * @return true if the resource can accept the request, false otherwise
- */
- private boolean isAvailable(IntentId resource) {
- if (resource == null) {
- return true;
- }
-
- Set<IntentId> mapping = intentSetMultimap.getMapping(resource);
-
- if (mapping == null) {
- return true;
- }
-
- return mapping.size() < maxCapacity;
- }
-
- private boolean isAllowed(OpticalCircuitIntent circuitIntent, OpticalConnectivityIntent connIntent) {
- ConnectPoint srcStaticPort = staticPort(circuitIntent.getSrc());
- if (srcStaticPort != null) {
- if (!srcStaticPort.equals(connIntent.getSrc())) {
- return false;
- }
- }
-
- ConnectPoint dstStaticPort = staticPort(circuitIntent.getDst());
- if (dstStaticPort != null) {
- if (!dstStaticPort.equals(connIntent.getDst())) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Returns existing and available optical connectivity intent that matches the given circuit intent.
- *
- * @param circuitIntent optical circuit intent
- * @return existing optical connectivity intent, null otherwise.
- */
- private OpticalConnectivityIntent findOpticalConnectivityIntent(OpticalCircuitIntent circuitIntent) {
- for (Intent intent : intentService.getIntents()) {
- if (!(intent instanceof OpticalConnectivityIntent)) {
- continue;
- }
-
- OpticalConnectivityIntent connIntent = (OpticalConnectivityIntent) intent;
-
- ConnectPoint src = circuitIntent.getSrc();
- ConnectPoint dst = circuitIntent.getDst();
- // Ignore if the intents don't have identical src and dst devices
- if (!src.deviceId().equals(connIntent.getSrc().deviceId()) &&
- !dst.deviceId().equals(connIntent.getDst().deviceId())) {
- continue;
- }
-
- if (!isAllowed(circuitIntent, connIntent)) {
- continue;
- }
-
- if (isAvailable(connIntent.id())) {
- return connIntent;
- }
- }
-
- return null;
- }
-
- private ConnectPoint staticPort(ConnectPoint connectPoint) {
- Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port());
-
- String staticPort = port.annotations().value(AnnotationKeys.STATIC_PORT);
-
- // FIXME: need a better way to match the port
- if (staticPort != null) {
- for (Port p : deviceService.getPorts(connectPoint.deviceId())) {
- if (staticPort.equals(p.number().name())) {
- return new ConnectPoint(p.element().id(), p.number());
- }
- }
- }
-
- return null;
- }
-
- private OchPort findAvailableOchPort(ConnectPoint oduPort) {
- // First see if the port mappings are constrained
- ConnectPoint ochCP = staticPort(oduPort);
-
- if (ochCP != null) {
- OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port());
- Optional<IntentId> intentId =
- resourceService.getResourceAllocation(ResourcePath.discrete(ochCP.deviceId(), ochCP.port()))
- .map(ResourceAllocation::consumer)
- .filter(x -> x instanceof IntentId)
- .map(x -> (IntentId) x);
-
- if (isAvailable(intentId.orElse(null))) {
- return ochPort;
- }
- }
-
- // No port constraints, so find any port that works
- List<Port> ports = deviceService.getPorts(oduPort.deviceId());
-
- for (Port port : ports) {
- if (!(port instanceof OchPort)) {
- continue;
- }
-
- Optional<IntentId> intentId =
- resourceService.getResourceAllocation(ResourcePath.discrete(oduPort.deviceId(), port.number()))
- .map(ResourceAllocation::consumer)
- .filter(x -> x instanceof IntentId)
- .map(x -> (IntentId) x);
- if (isAvailable(intentId.orElse(null))) {
- return (OchPort) port;
- }
- }
-
- return null;
- }
-
- private Pair<OchPort, OchPort> findPorts(OpticalCircuitIntent intent) {
-
- OchPort srcPort = findAvailableOchPort(intent.getSrc());
- if (srcPort == null) {
- return null;
- }
-
- OchPort dstPort = findAvailableOchPort(intent.getDst());
- if (dstPort == null) {
- return null;
- }
-
- return Pair.of(srcPort, dstPort);
- }
-
- /**
- * Builds flow rule for mapping between two ports.
- *
- * @param src source port
- * @param dst destination port
- * @return flow rules
- */
- private FlowRule connectPorts(ConnectPoint src, ConnectPoint dst, int priority) {
- checkArgument(src.deviceId().equals(dst.deviceId()));
-
- TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
- TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
-
- selectorBuilder.matchInPort(src.port());
- //selectorBuilder.add(Criteria.matchCltSignalType)
- treatmentBuilder.setOutput(dst.port());
- //treatmentBuilder.add(Instructions.modL1OduSignalType)
-
- FlowRule flowRule = DefaultFlowRule.builder()
- .forDevice(src.deviceId())
- .withSelector(selectorBuilder.build())
- .withTreatment(treatmentBuilder.build())
- .withPriority(priority)
- .fromApp(appId)
- .makePermanent()
- .build();
-
- return flowRule;
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
deleted file mode 100644
index e017ac58..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * Copyright 2014-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.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.onlab.util.Frequency;
-import org.onosproject.net.AnnotationKeys;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.IndexedLambda;
-import org.onosproject.net.Link;
-import org.onosproject.net.OchPort;
-import org.onosproject.net.OchSignal;
-import org.onosproject.net.OchSignalType;
-import org.onosproject.net.OmsPort;
-import org.onosproject.net.Path;
-import org.onosproject.net.Port;
-import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.IntentCompiler;
-import org.onosproject.net.intent.IntentExtensionService;
-import org.onosproject.net.intent.OpticalConnectivityIntent;
-import org.onosproject.net.intent.OpticalPathIntent;
-import org.onosproject.net.intent.impl.IntentCompilationException;
-import org.onosproject.net.newresource.ResourceAllocation;
-import org.onosproject.net.newresource.ResourcePath;
-import org.onosproject.net.newresource.ResourceService;
-import org.onosproject.net.resource.link.LinkResourceAllocations;
-import org.onosproject.net.topology.LinkWeight;
-import org.onosproject.net.topology.Topology;
-import org.onosproject.net.topology.TopologyService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-/**
- * An intent compiler for {@link org.onosproject.net.intent.OpticalConnectivityIntent}.
- */
-// For now, remove component designation until dependency on the new resource manager is available.
-@Component(immediate = true)
-public class OpticalConnectivityIntentCompiler implements IntentCompiler<OpticalConnectivityIntent> {
-
- protected static final Logger log = LoggerFactory.getLogger(OpticalConnectivityIntentCompiler.class);
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected IntentExtensionService intentManager;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected TopologyService topologyService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected DeviceService deviceService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected ResourceService resourceService;
-
- @Activate
- public void activate() {
- intentManager.registerCompiler(OpticalConnectivityIntent.class, this);
- }
-
- @Deactivate
- public void deactivate() {
- intentManager.unregisterCompiler(OpticalConnectivityIntent.class);
- }
-
- @Override
- public List<Intent> compile(OpticalConnectivityIntent intent,
- List<Intent> installable,
- Set<LinkResourceAllocations> resources) {
- // Check if source and destination are optical OCh ports
- ConnectPoint src = intent.getSrc();
- ConnectPoint dst = intent.getDst();
- Port srcPort = deviceService.getPort(src.deviceId(), src.port());
- Port dstPort = deviceService.getPort(dst.deviceId(), dst.port());
- checkArgument(srcPort instanceof OchPort);
- checkArgument(dstPort instanceof OchPort);
-
- log.debug("Compiling optical connectivity intent between {} and {}", src, dst);
-
- // Reserve OCh ports
- ResourcePath srcPortPath = ResourcePath.discrete(src.deviceId(), src.port());
- ResourcePath dstPortPath = ResourcePath.discrete(dst.deviceId(), dst.port());
- List<org.onosproject.net.newresource.ResourceAllocation> allocation =
- resourceService.allocate(intent.id(), srcPortPath, dstPortPath);
- if (allocation.isEmpty()) {
- throw new IntentCompilationException("Unable to reserve ports for intent " + intent);
- }
-
- // Calculate available light paths
- Set<Path> paths = getOpticalPaths(intent);
-
- // Use first path that can be successfully reserved
- for (Path path : paths) {
-
- // Static or dynamic lambda allocation
- String staticLambda = srcPort.annotations().value(AnnotationKeys.STATIC_LAMBDA);
- OchPort srcOchPort = (OchPort) srcPort;
- OchPort dstOchPort = (OchPort) dstPort;
- OchSignal ochSignal;
-
- // FIXME: need to actually reserve the lambda for static lambda's
- if (staticLambda != null) {
- ochSignal = new OchSignal(Frequency.ofHz(Long.parseLong(staticLambda)),
- srcOchPort.lambda().channelSpacing(),
- srcOchPort.lambda().slotGranularity());
- } else if (!srcOchPort.isTunable() || !dstOchPort.isTunable()) {
- // FIXME: also check OCh port
- ochSignal = srcOchPort.lambda();
- } else {
- // Request and reserve lambda on path
- IndexedLambda lambda = assignWavelength(intent, path);
- if (lambda == null) {
- continue;
- }
- OmsPort omsPort = (OmsPort) deviceService.getPort(path.src().deviceId(), path.src().port());
- ochSignal = new OchSignal((int) lambda.index(), omsPort.maxFrequency(), omsPort.grid());
- }
-
- // Create installable optical path intent
- // Only support fixed grid for now
- OchSignalType signalType = OchSignalType.FIXED_GRID;
-
- Intent newIntent = OpticalPathIntent.builder()
- .appId(intent.appId())
- .src(intent.getSrc())
- .dst(intent.getDst())
- .path(path)
- .lambda(ochSignal)
- .signalType(signalType)
- .bidirectional(intent.isBidirectional())
- .build();
-
- return ImmutableList.of(newIntent);
- }
-
- // Release port allocations if unsuccessful
- resourceService.release(intent.id());
-
- throw new IntentCompilationException("Unable to find suitable lightpath for intent " + intent);
- }
-
- /**
- * Request and reserve first available wavelength across path.
- *
- * @param path path in WDM topology
- * @return first available lambda allocated
- */
- private IndexedLambda assignWavelength(Intent intent, Path path) {
- Set<IndexedLambda> lambdas = findCommonLambdasOverLinks(path.links());
- if (lambdas.isEmpty()) {
- return null;
- }
-
- IndexedLambda minLambda = findFirstLambda(lambdas);
- List<ResourcePath> lambdaResources = path.links().stream()
- .flatMap(x -> Stream.of(
- ResourcePath.discrete(x.src().deviceId(), x.src().port()),
- ResourcePath.discrete(x.dst().deviceId(), x.dst().port())
- ))
- .map(x -> x.child(minLambda))
- .collect(Collectors.toList());
-
- List<ResourceAllocation> allocations = resourceService.allocate(intent.id(), lambdaResources);
- if (allocations.isEmpty()) {
- log.info("Resource allocation for {} failed (resource request: {})", intent, lambdaResources);
- return null;
- }
-
- return minLambda;
- }
-
- private Set<IndexedLambda> findCommonLambdasOverLinks(List<Link> links) {
- return links.stream()
- .flatMap(x -> Stream.of(
- ResourcePath.discrete(x.src().deviceId(), x.src().port()),
- ResourcePath.discrete(x.dst().deviceId(), x.dst().port())
- ))
- .map(resourceService::getAvailableResources)
- .map(x -> Iterables.filter(x, r -> r.last() instanceof IndexedLambda))
- .map(x -> Iterables.transform(x, r -> (IndexedLambda) r.last()))
- .map(x -> (Set<IndexedLambda>) ImmutableSet.copyOf(x))
- .reduce(Sets::intersection)
- .orElse(Collections.emptySet());
- }
-
- private IndexedLambda findFirstLambda(Set<IndexedLambda> lambdas) {
- return lambdas.stream()
- .findFirst()
- .get();
- }
-
- private ConnectPoint staticPort(ConnectPoint connectPoint) {
- Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port());
-
- String staticPort = port.annotations().value(AnnotationKeys.STATIC_PORT);
-
- // FIXME: need a better way to match the port
- if (staticPort != null) {
- for (Port p : deviceService.getPorts(connectPoint.deviceId())) {
- if (staticPort.equals(p.number().name())) {
- return new ConnectPoint(p.element().id(), p.number());
- }
- }
- }
-
- return null;
- }
-
- /**
- * Calculates optical paths in WDM topology.
- *
- * @param intent optical connectivity intent
- * @return set of paths in WDM topology
- */
- private Set<Path> getOpticalPaths(OpticalConnectivityIntent intent) {
- // Route in WDM topology
- Topology topology = topologyService.currentTopology();
- LinkWeight weight = edge -> {
- // Disregard inactive or non-optical links
- if (edge.link().state() == Link.State.INACTIVE) {
- return -1;
- }
- if (edge.link().type() != Link.Type.OPTICAL) {
- return -1;
- }
- // Adhere to static port mappings
- DeviceId srcDeviceId = edge.link().src().deviceId();
- if (srcDeviceId.equals(intent.getSrc().deviceId())) {
- ConnectPoint srcStaticPort = staticPort(intent.getSrc());
- if (srcStaticPort != null) {
- return srcStaticPort.equals(edge.link().src()) ? 1 : -1;
- }
- }
- DeviceId dstDeviceId = edge.link().dst().deviceId();
- if (dstDeviceId.equals(intent.getDst().deviceId())) {
- ConnectPoint dstStaticPort = staticPort(intent.getDst());
- if (dstStaticPort != null) {
- return dstStaticPort.equals(edge.link().dst()) ? 1 : -1;
- }
- }
-
- return 1;
- };
-
- ConnectPoint start = intent.getSrc();
- ConnectPoint end = intent.getDst();
- Set<Path> paths = topologyService.getPaths(topology, start.deviceId(),
- end.deviceId(), weight);
-
- return paths;
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompiler.java
deleted file mode 100644
index 2cc45e79..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalPathIntentCompiler.java
+++ /dev/null
@@ -1,191 +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.compiler;
-
-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.TrafficSelector;
-import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.flow.criteria.Criteria;
-import org.onosproject.net.flow.instructions.Instructions;
-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.resource.link.LinkResourceAllocations;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-@Component(immediate = true)
-public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathIntent> {
-
- private static final Logger log = LoggerFactory.getLogger(OpticalPathIntentCompiler.class);
-
- @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(OpticalPathIntent.class, this);
- }
-
- @Deactivate
- public void deactivate() {
- intentManager.unregisterCompiler(OpticalPathIntent.class);
- }
-
- @Override
- public List<Intent> compile(OpticalPathIntent intent, List<Intent> installable,
- Set<LinkResourceAllocations> resources) {
- log.debug("Compiling optical path intent between {} and {}", intent.src(), intent.dst());
-
- // Create rules for forward and reverse path
- List<FlowRule> rules = createRules(intent);
- if (intent.isBidirectional()) {
- rules.addAll(createReverseRules(intent));
- }
-
- return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources()));
- }
-
- /**
- * Create rules for the forward path of the intent.
- *
- * @param intent the intent
- * @return list of flow rules
- */
- private List<FlowRule> createRules(OpticalPathIntent intent) {
- TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
- selectorBuilder.matchInPort(intent.src().port());
-
- List<FlowRule> rules = new LinkedList<>();
- ConnectPoint current = intent.src();
-
- for (Link link : intent.path().links()) {
- TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
- treatmentBuilder.add(Instructions.modL0Lambda(intent.lambda()));
- treatmentBuilder.setOutput(link.src().port());
-
- FlowRule rule = DefaultFlowRule.builder()
- .forDevice(current.deviceId())
- .withSelector(selectorBuilder.build())
- .withTreatment(treatmentBuilder.build())
- .withPriority(intent.priority())
- .fromApp(appId)
- .makePermanent()
- .build();
-
- rules.add(rule);
-
- current = link.dst();
- selectorBuilder.matchInPort(link.dst().port());
- selectorBuilder.add(Criteria.matchLambda(intent.lambda()));
- selectorBuilder.add(Criteria.matchOchSignalType(intent.signalType()));
- }
-
- // Build the egress ROADM rule
- TrafficTreatment.Builder treatmentLast = DefaultTrafficTreatment.builder();
- treatmentLast.setOutput(intent.dst().port());
-
- FlowRule rule = new DefaultFlowRule.Builder()
- .forDevice(intent.dst().deviceId())
- .withSelector(selectorBuilder.build())
- .withTreatment(treatmentLast.build())
- .withPriority(intent.priority())
- .fromApp(appId)
- .makePermanent()
- .build();
- rules.add(rule);
-
- return rules;
- }
-
- /**
- * Create rules for the reverse path of the intent.
- *
- * @param intent the intent
- * @return list of flow rules
- */
- private List<FlowRule> createReverseRules(OpticalPathIntent intent) {
- TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
- selectorBuilder.matchInPort(intent.dst().port());
-
- List<FlowRule> rules = new LinkedList<>();
- ConnectPoint current = intent.dst();
-
- for (Link link : Lists.reverse(intent.path().links())) {
- TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
- treatmentBuilder.add(Instructions.modL0Lambda(intent.lambda()));
- treatmentBuilder.setOutput(link.dst().port());
-
- FlowRule rule = DefaultFlowRule.builder()
- .forDevice(current.deviceId())
- .withSelector(selectorBuilder.build())
- .withTreatment(treatmentBuilder.build())
- .withPriority(intent.priority())
- .fromApp(appId)
- .makePermanent()
- .build();
-
- rules.add(rule);
-
- current = link.src();
- selectorBuilder.matchInPort(link.src().port());
- selectorBuilder.add(Criteria.matchLambda(intent.lambda()));
- selectorBuilder.add(Criteria.matchOchSignalType(intent.signalType()));
- }
-
- // Build the egress ROADM rule
- TrafficTreatment.Builder treatmentLast = DefaultTrafficTreatment.builder();
- treatmentLast.setOutput(intent.src().port());
-
- FlowRule rule = new DefaultFlowRule.Builder()
- .forDevice(intent.src().deviceId())
- .withSelector(selectorBuilder.build())
- .withTreatment(treatmentLast.build())
- .withPriority(intent.priority())
- .fromApp(appId)
- .makePermanent()
- .build();
- rules.add(rule);
-
- return rules;
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
deleted file mode 100644
index 7add2173..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
+++ /dev/null
@@ -1,116 +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.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.link.LinkResourceAllocations;
-
-import java.util.ArrayList;
-import java.util.Collections;
-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, intent.priority(),
- isLast(links, i));
- rules.add(rule);
- }
-
- return Collections.singletonList(new FlowRuleIntent(appId, null, rules, intent.resources()));
- }
-
- private FlowRule createFlowRule(TrafficSelector originalSelector, TrafficTreatment originalTreatment,
- ConnectPoint ingress, ConnectPoint egress,
- int priority, 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 DefaultFlowRule.builder()
- .forDevice(ingress.deviceId())
- .withSelector(selector)
- .withTreatment(treatment)
- .withPriority(priority)
- .fromApp(appId)
- .makePermanent()
- .build();
- }
-
- private boolean isLast(List<Link> links, int i) {
- return i == links.size() - 2;
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
deleted file mode 100644
index 5644ee22..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 2014-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.onosproject.net.ConnectPoint;
-import org.onosproject.net.DefaultPath;
-import org.onosproject.net.Link;
-import org.onosproject.net.Path;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.PathIntent;
-import org.onosproject.net.intent.PointToPointIntent;
-import org.onosproject.net.provider.ProviderId;
-import org.onosproject.net.resource.link.LinkResourceAllocations;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import static java.util.Arrays.asList;
-import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
-
-/**
- * An intent compiler for {@link org.onosproject.net.intent.PointToPointIntent}.
- */
-@Component(immediate = true)
-public class PointToPointIntentCompiler
- extends ConnectivityIntentCompiler<PointToPointIntent> {
-
- // TODO: use off-the-shell core provider ID
- private static final ProviderId PID =
- new ProviderId("core", "org.onosproject.core", true);
- // TODO: consider whether the default cost is appropriate or not
- public static final int DEFAULT_COST = 1;
-
- @Activate
- public void activate() {
- intentManager.registerCompiler(PointToPointIntent.class, this);
- }
-
- @Deactivate
- public void deactivate() {
- intentManager.unregisterCompiler(PointToPointIntent.class);
- }
-
- @Override
- public List<Intent> compile(PointToPointIntent intent, List<Intent> installable,
- Set<LinkResourceAllocations> resources) {
-
- ConnectPoint ingressPoint = intent.ingressPoint();
- ConnectPoint egressPoint = intent.egressPoint();
-
- if (ingressPoint.deviceId().equals(egressPoint.deviceId())) {
- List<Link> links = asList(createEdgeLink(ingressPoint, true), createEdgeLink(egressPoint, false));
- return asList(createPathIntent(new DefaultPath(PID, links, DEFAULT_COST), intent));
- }
-
- List<Link> links = new ArrayList<>();
- Path path = getPath(intent, ingressPoint.deviceId(),
- egressPoint.deviceId());
-
- links.add(createEdgeLink(ingressPoint, true));
- links.addAll(path.links());
- links.add(createEdgeLink(egressPoint, false));
-
- return asList(createPathIntent(new DefaultPath(PID, links, path.cost(),
- path.annotations()), intent));
- }
-
- /**
- * Creates a path intent from the specified path and original
- * connectivity intent.
- *
- * @param path path to create an intent for
- * @param intent original intent
- */
- private Intent createPathIntent(Path path,
- PointToPointIntent intent) {
- return PathIntent.builder()
- .appId(intent.appId())
- .selector(intent.selector())
- .treatment(intent.treatment())
- .path(path)
- .constraints(intent.constraints())
- .priority(intent.priority())
- .build();
- }
-
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java
deleted file mode 100644
index 56565908..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2014-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 org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.Link;
-import org.onosproject.net.Path;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.LinkCollectionIntent;
-import org.onosproject.net.intent.SinglePointToMultiPointIntent;
-import org.onosproject.net.provider.ProviderId;
-import org.onosproject.net.resource.link.LinkResourceAllocations;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-@Component(immediate = true)
-public class SinglePointToMultiPointIntentCompiler
- extends ConnectivityIntentCompiler<SinglePointToMultiPointIntent> {
-
- // TODO: use off-the-shell core provider ID
- private static final ProviderId PID =
- new ProviderId("core", "org.onosproject.core", true);
-
- @Activate
- public void activate() {
- intentManager.registerCompiler(SinglePointToMultiPointIntent.class,
- this);
- }
-
- @Deactivate
- public void deactivate() {
- intentManager.unregisterCompiler(SinglePointToMultiPointIntent.class);
- }
-
-
- @Override
- public List<Intent> compile(SinglePointToMultiPointIntent intent,
- List<Intent> installable,
- Set<LinkResourceAllocations> resources) {
- Set<Link> links = new HashSet<>();
-
- for (ConnectPoint egressPoint : intent.egressPoints()) {
- if (egressPoint.deviceId().equals(intent.ingressPoint().deviceId())) {
- continue;
- }
-
- Path path = getPath(intent, intent.ingressPoint().deviceId(), egressPoint.deviceId());
- links.addAll(path.links());
- }
-
- Intent result = LinkCollectionIntent.builder()
- .appId(intent.appId())
- .key(intent.key())
- .selector(intent.selector())
- .treatment(intent.treatment())
- .links(links)
- .ingressPoints(ImmutableSet.of(intent.ingressPoint()))
- .egressPoints(intent.egressPoints())
- .priority(intent.priority())
- .constraints(intent.constraints())
- .build();
-
- return Collections.singletonList(result);
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/TwoWayP2PIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/TwoWayP2PIntentCompiler.java
deleted file mode 100644
index 50a67546..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/TwoWayP2PIntentCompiler.java
+++ /dev/null
@@ -1,72 +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.compiler;
-
-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.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.PointToPointIntent;
-import org.onosproject.net.intent.TwoWayP2PIntent;
-import org.onosproject.net.resource.link.LinkResourceAllocations;
-
-import java.util.List;
-import java.util.Set;
-
-/**
- * A intent compiler for {@link org.onosproject.net.intent.TwoWayP2PIntent}.
- */
-@Component(immediate = true)
-public class TwoWayP2PIntentCompiler
- extends ConnectivityIntentCompiler<TwoWayP2PIntent> {
-
- @Activate
- public void activate() {
- intentManager.registerCompiler(TwoWayP2PIntent.class, this);
- }
-
- @Deactivate
- public void deactivate() {
- intentManager.unregisterCompiler(TwoWayP2PIntent.class);
- }
-
- @Override
- public List<Intent> compile(TwoWayP2PIntent intent, List<Intent> installable,
- Set<LinkResourceAllocations> resources) {
- return Lists.newArrayList(
- PointToPointIntent.builder()
- .appId(intent.appId())
- .key(intent.key())
- .selector(intent.selector())
- .treatment(intent.treatment())
- .ingressPoint(intent.one())
- .egressPoint(intent.two())
- .constraints(intent.constraints())
- .priority(intent.priority())
- .build(),
- PointToPointIntent.builder()
- .appId(intent.appId())
- .key(intent.key())
- .selector(intent.selector())
- .treatment(intent.treatment())
- .ingressPoint(intent.two())
- .egressPoint(intent.one())
- .constraints(intent.constraints())
- .priority(intent.priority())
- .build());
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/package-info.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/package-info.java
deleted file mode 100644
index beaf5ed0..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/package-info.java
+++ /dev/null
@@ -1,20 +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.
- */
-
-/**
- * Implementations of builtin intent compilers.
- */
-package org.onosproject.net.intent.impl.compiler; \ No newline at end of file
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/package-info.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/package-info.java
deleted file mode 100644
index 8c516c64..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/package-info.java
+++ /dev/null
@@ -1,21 +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.
- */
-
-/**
- * Core subsystem for tracking high-level intents for treatment of selected
- * network traffic.
- */
-package org.onosproject.net.intent.impl;
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java
deleted file mode 100644
index 5078b5dc..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java
+++ /dev/null
@@ -1,73 +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.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;
-
-/**
- * Represents a phase where an intent is being compiled or recompiled.
- */
-class Compiling implements IntentProcessPhase {
-
- private static final Logger log = LoggerFactory.getLogger(Compiling.class);
-
- private final IntentProcessor processor;
- private final IntentData data;
- private final Optional<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
- */
- Compiling(IntentProcessor processor, IntentData data, Optional<IntentData> stored) {
- this.processor = checkNotNull(processor);
- this.data = checkNotNull(data);
- this.stored = checkNotNull(stored);
- }
-
- @Override
- public Optional<IntentProcessPhase> execute() {
- try {
- List<Intent> compiled = processor.compile(data.intent(),
- //TODO consider passing an optional here in the future
- stored.isPresent() ? stored.get().installables() : null);
- data.setInstallables(compiled);
- return Optional.of(new Installing(processor, data, stored));
- } catch (IntentException e) {
- log.debug("Unable to compile intent {} due to: {}", data.intent(), e);
- if (stored.isPresent() && !stored.get().installables().isEmpty()) {
- // removing orphaned flows and deallocating resources
- data.setInstallables(stored.get().installables());
- return Optional.of(new Withdrawing(processor, data));
- } else {
- return Optional.of(new Failed(data));
- }
- }
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Corrupt.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Corrupt.java
deleted file mode 100644
index 2fbe1641..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Corrupt.java
+++ /dev/null
@@ -1,44 +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.CORRUPT;
-
-/**
- * A class representing errors removing or installing intents.
- */
-public class Corrupt extends FinalIntentProcessPhase {
-
- private final IntentData intentData;
-
- /**
- * Create an instance with the specified data.
- *
- * @param intentData intentData
- */
- Corrupt(IntentData intentData) {
- this.intentData = checkNotNull(intentData);
- this.intentData.setState(CORRUPT);
- }
-
- @Override
- public IntentData data() {
- return intentData;
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Failed.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Failed.java
deleted file mode 100644
index 7f628e3c..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Failed.java
+++ /dev/null
@@ -1,44 +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.FAILED;
-
-/**
- * Represents a phase where the compile has failed.
- */
-public class Failed extends FinalIntentProcessPhase {
-
- private final IntentData intentData;
-
- /**
- * Create an instance with the specified data.
- *
- * @param intentData intentData
- */
- Failed(IntentData intentData) {
- this.intentData = checkNotNull(intentData);
- this.intentData.setState(FAILED);
- }
-
- @Override
- public IntentData data() {
- return intentData;
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/FinalIntentProcessPhase.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/FinalIntentProcessPhase.java
deleted file mode 100644
index c67b93b5..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/FinalIntentProcessPhase.java
+++ /dev/null
@@ -1,44 +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 java.util.Optional;
-
-/**
- * Represents a final phase of processing an intent.
- */
-public abstract class FinalIntentProcessPhase implements IntentProcessPhase {
-
- @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/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallRequest.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallRequest.java
deleted file mode 100644
index a75d7cc8..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/InstallRequest.java
+++ /dev/null
@@ -1,55 +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 org.onosproject.net.intent.impl.IntentProcessor;
-
-import java.util.Optional;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onosproject.net.intent.impl.phase.IntentProcessPhase.transferErrorCount;
-
-/**
- * Represents a phase where intent installation has been requested.
- */
-final class InstallRequest implements IntentProcessPhase {
-
- private final IntentProcessor processor;
- private final IntentData data;
- private final Optional<IntentData> stored;
-
- /**
- * 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() {
- transferErrorCount(data, stored);
-
- return Optional.of(new Compiling(processor, data, stored));
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Installing.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Installing.java
deleted file mode 100644
index 2ff7ca8b..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Installing.java
+++ /dev/null
@@ -1,58 +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 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.INSTALLING;
-
-/**
- * Represents a phase where an intent is being installed.
- */
-class Installing extends FinalIntentProcessPhase {
-
- private final IntentProcessor processor;
- private final IntentData data;
- private final Optional<IntentData> stored;
-
- /**
- * Create an installing phase.
- *
- * @param processor intent processor that does work for installing
- * @param data intent data containing an intent to be installed
- * @param stored intent data already stored
- */
- Installing(IntentProcessor processor, IntentData data, Optional<IntentData> stored) {
- this.processor = checkNotNull(processor);
- this.data = checkNotNull(data);
- this.stored = checkNotNull(stored);
- this.data.setState(INSTALLING);
- }
-
- @Override
- public void preExecute() {
- processor.apply(stored, Optional.of(data));
- }
-
- @Override
- public IntentData data() {
- return data;
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/IntentProcessPhase.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/IntentProcessPhase.java
deleted file mode 100644
index bce572c6..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/IntentProcessPhase.java
+++ /dev/null
@@ -1,73 +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 org.onosproject.net.intent.impl.IntentProcessor;
-
-import java.util.Objects;
-import java.util.Optional;
-
-/**
- * Represents a phase of processing an intent.
- */
-public interface IntentProcessPhase {
-
- /**
- * Execute the procedure represented by the instance
- * and generates the next update instance.
- *
- * @return next update
- */
- Optional<IntentProcessPhase> execute();
-
- /**
- * Create a starting intent process phase according to intent data this class holds.
- *
- * @param processor intent processor to be passed to intent process phases
- * generated while this instance is working
- * @param data intent data to be processed
- * @param current intent date that is stored in the store
- * @return starting intent process phase
- */
- static IntentProcessPhase newInitialPhase(IntentProcessor processor,
- IntentData data, IntentData current) {
- switch (data.request()) {
- case INSTALL_REQ:
- return new InstallRequest(processor, data, Optional.ofNullable(current));
- case WITHDRAW_REQ:
- return new WithdrawRequest(processor, data, Optional.ofNullable(current));
- case PURGE_REQ:
- return new PurgeRequest(data, Optional.ofNullable(current));
- default:
- // illegal state
- return new Failed(data);
- }
- }
-
- static void transferErrorCount(IntentData data, Optional<IntentData> stored) {
- if (stored.isPresent()) {
- IntentData storedData = stored.get();
- if (Objects.equals(data.intent(), storedData.intent()) &&
- Objects.equals(data.request(), storedData.request())) {
- data.setErrorCount(storedData.errorCount());
- } else {
- data.setErrorCount(0);
- }
- }
- }
-
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/IntentWorker.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/IntentWorker.java
deleted file mode 100644
index 9ddcf40e..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/IntentWorker.java
+++ /dev/null
@@ -1,52 +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 java.util.Optional;
-import java.util.concurrent.Callable;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * Worker to process a submitted intent. {@link #call()} method generates
- */
-public final class IntentWorker implements Callable<FinalIntentProcessPhase> {
-
- private final IntentProcessPhase initial;
-
- /**
- * Create an instance with the specified arguments.
- *
- * @param initial initial intent process phase
- */
- public IntentWorker(IntentProcessPhase initial) {
- this.initial = checkNotNull(initial);
- }
-
- @Override
- public FinalIntentProcessPhase call() throws Exception {
- IntentProcessPhase update = initial;
- Optional<IntentProcessPhase> currentPhase = Optional.of(update);
- IntentProcessPhase previousPhase = update;
-
- while (currentPhase.isPresent()) {
- previousPhase = currentPhase.get();
- currentPhase = previousPhase.execute();
- }
- return (FinalIntentProcessPhase) previousPhase;
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/PurgeRequest.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/PurgeRequest.java
deleted file mode 100644
index 69126dfb..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/PurgeRequest.java
+++ /dev/null
@@ -1,70 +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 org.onosproject.net.intent.IntentState;
-import org.slf4j.Logger;
-
-import java.util.Optional;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * Represents a phase of requesting a purge of an intent.
- * <p>
- * Note: The purge will only succeed if the intent is FAILED or WITHDRAWN.
- * </p>
- */
-final class PurgeRequest extends FinalIntentProcessPhase {
-
- private static final Logger log = getLogger(PurgeRequest.class);
-
- private final IntentData data;
- private final Optional<IntentData> stored;
-
- PurgeRequest(IntentData intentData, Optional<IntentData> stored) {
- this.data = checkNotNull(intentData);
- this.stored = checkNotNull(stored);
- }
-
- private boolean shouldAcceptPurge() {
- if (!stored.isPresent()) {
- log.info("Purge for intent {}, but intent is not present",
- data.key());
- return true;
- }
-
- IntentData storedData = stored.get();
- if (storedData.state() == IntentState.WITHDRAWN
- || storedData.state() == IntentState.FAILED) {
- return true;
- }
- log.info("Purge for intent {} is rejected because intent state is {}",
- data.key(), storedData.state());
- return false;
- }
-
- @Override
- public IntentData data() {
- if (shouldAcceptPurge()) {
- return data;
- } else {
- return stored.get();
- }
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawRequest.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawRequest.java
deleted file mode 100644
index 8a0709e6..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/WithdrawRequest.java
+++ /dev/null
@@ -1,70 +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 org.onosproject.net.intent.impl.IntentProcessor;
-
-import java.util.Optional;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onosproject.net.intent.impl.phase.IntentProcessPhase.transferErrorCount;
-
-/**
- * Represents a phase of requesting a withdraw of an intent.
- */
-final class WithdrawRequest implements IntentProcessPhase {
-
- private final IntentProcessor processor;
- private final IntentData data;
- private final Optional<IntentData> stored;
-
- /**
- * 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, Optional<IntentData> stored) {
- this.processor = checkNotNull(processor);
- this.data = checkNotNull(intentData);
- this.stored = checkNotNull(stored);
- }
-
- @Override
- public Optional<IntentProcessPhase> execute() {
- //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
-
- transferErrorCount(data, stored);
-
- if (!stored.isPresent() || stored.get().installables().isEmpty()) {
- switch (data.request()) {
- case INSTALL_REQ:
- return Optional.of(new Failed(data));
- case WITHDRAW_REQ:
- default: //TODO "default" case should not happen
- return Optional.of(new Withdrawn(data));
- }
- }
-
- data.setInstallables(stored.get().installables());
- return Optional.of(new Withdrawing(processor, data));
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawing.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawing.java
deleted file mode 100644
index 29bc4711..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawing.java
+++ /dev/null
@@ -1,55 +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 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 where an intent is withdrawing.
- */
-class Withdrawing extends FinalIntentProcessPhase {
-
- private final IntentProcessor processor;
- private final IntentData data;
-
- /**
- * 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.data = checkNotNull(data);
- this.data.setState(WITHDRAWING);
- }
-
- @Override
- protected void preExecute() {
- processor.apply(Optional.of(data), Optional.empty());
- }
-
- @Override
- public IntentData data() {
- return data;
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawn.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawn.java
deleted file mode 100644
index 264f74c6..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawn.java
+++ /dev/null
@@ -1,44 +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.WITHDRAWN;
-
-/**
- * Represents a phase where an intent has been withdrawn.
- */
-final class Withdrawn extends FinalIntentProcessPhase {
-
- private final IntentData data;
-
- /**
- * 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 data;
- }
-}
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/package-info.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/package-info.java
deleted file mode 100644
index 56e54308..00000000
--- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/phase/package-info.java
+++ /dev/null
@@ -1,20 +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.
- */
-
-/**
- * Implementations of various intent processing phases.
- */
-package org.onosproject.net.intent.impl.phase; \ No newline at end of file