Updating Intent Manager to deal with failures.
Added ids to Flow batch futures.
Adding some basic unit tests for IntentManger
Adding failedIds to the completedOperation in FlowRuleManager
Change-Id: I7645cead193299f70d319d254cd1e82d96909e7b
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/CompletedBatchOperation.java b/core/api/src/main/java/org/onlab/onos/net/flow/CompletedBatchOperation.java
index b988744..a7bffe7 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/CompletedBatchOperation.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/CompletedBatchOperation.java
@@ -15,6 +15,9 @@
*/
package org.onlab.onos.net.flow;
+
+import java.util.Collections;
+
import java.util.Set;
import com.google.common.collect.ImmutableSet;
@@ -26,6 +29,21 @@
private final boolean success;
private final Set<FlowRule> failures;
+ private final Set<Long> failedIds;
+
+ /**
+ * Creates a new batch completion result.
+ *
+ * @param success indicates whether the completion is successful.
+ * @param failures set of any failures encountered
+ * @param failedIds (optional) set of failed operation ids
+ */
+ public CompletedBatchOperation(boolean success, Set<? extends FlowRule> failures,
+ Set<Long> failedIds) {
+ this.success = success;
+ this.failures = ImmutableSet.copyOf(failures);
+ this.failedIds = ImmutableSet.copyOf(failedIds);
+ }
/**
* Creates a new batch completion result.
@@ -36,8 +54,11 @@
public CompletedBatchOperation(boolean success, Set<? extends FlowRule> failures) {
this.success = success;
this.failures = ImmutableSet.copyOf(failures);
+ this.failedIds = Collections.emptySet();
}
+
+
@Override
public boolean isSuccess() {
return success;
@@ -48,4 +69,8 @@
return failures;
}
+ public Set<Long> failedIds() {
+ return failedIds;
+ }
+
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleBatchEntry.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleBatchEntry.java
index d84e51b..7a635e7 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleBatchEntry.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleBatchEntry.java
@@ -21,8 +21,20 @@
public class FlowRuleBatchEntry
extends BatchOperationEntry<FlowRuleOperation, FlowRule> {
+ private final Long id; // FIXME: consider using Optional<Long>
+
public FlowRuleBatchEntry(FlowRuleOperation operator, FlowRule target) {
super(operator, target);
+ this.id = null;
+ }
+
+ public FlowRuleBatchEntry(FlowRuleOperation operator, FlowRule target, Long id) {
+ super(operator, target);
+ this.id = id;
+ }
+
+ public Long id() {
+ return id;
}
public enum FlowRuleOperation {
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleBatchRequest.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleBatchRequest.java
index f75c663..09698a4 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleBatchRequest.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleBatchRequest.java
@@ -18,38 +18,52 @@
import java.util.Collections;
import java.util.List;
-import org.onlab.onos.net.flow.FlowRuleBatchEntry.FlowRuleOperation;
+import com.google.common.base.Function;
+import com.google.common.collect.FluentIterable;
+
+
import com.google.common.collect.Lists;
public class FlowRuleBatchRequest {
private final int batchId;
- private final List<FlowRule> toAdd;
- private final List<FlowRule> toRemove;
+ private final List<FlowRuleBatchEntry> toAdd;
+ private final List<FlowRuleBatchEntry> toRemove;
- public FlowRuleBatchRequest(int batchId, List<? extends FlowRule> toAdd, List<? extends FlowRule> toRemove) {
+ public FlowRuleBatchRequest(int batchId, List<FlowRuleBatchEntry> toAdd,
+ List<FlowRuleBatchEntry> toRemove) {
this.batchId = batchId;
this.toAdd = Collections.unmodifiableList(toAdd);
this.toRemove = Collections.unmodifiableList(toRemove);
}
public List<FlowRule> toAdd() {
- return toAdd;
+ return FluentIterable.from(toAdd).transform(
+ new Function<FlowRuleBatchEntry, FlowRule>() {
+
+ @Override
+ public FlowRule apply(FlowRuleBatchEntry input) {
+ return input.getTarget();
+ }
+ }).toList();
}
public List<FlowRule> toRemove() {
- return toRemove;
+ return FluentIterable.from(toRemove).transform(
+ new Function<FlowRuleBatchEntry, FlowRule>() {
+
+ @Override
+ public FlowRule apply(FlowRuleBatchEntry input) {
+ return input.getTarget();
+ }
+ }).toList();
}
public FlowRuleBatchOperation asBatchOperation() {
List<FlowRuleBatchEntry> entries = Lists.newArrayList();
- for (FlowRule e : toAdd) {
- entries.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, e));
- }
- for (FlowRule e : toRemove) {
- entries.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, e));
- }
+ entries.addAll(toAdd);
+ entries.addAll(toRemove);
return new FlowRuleBatchOperation(entries);
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/IntentBatchService.java b/core/api/src/main/java/org/onlab/onos/net/intent/IntentBatchService.java
index 37a1d4a..0364ad7 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/IntentBatchService.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/IntentBatchService.java
@@ -37,10 +37,16 @@
void removeIntentOperations(IntentOperations operations);
/**
- * Returns the set of intent batches currently being tracked.
+ * Returns the set of intent batches that are pending.
* @return set of batches
*/
- Set<IntentOperations> getIntentOperations();
+ Set<IntentOperations> getPendingOperations();
+
+ /**
+ * Returns the set of intent batches currently being processed.
+ * @return set of batches
+ */
+ Set<IntentOperations> getCurrentOperations();
/**
* Sets the batch service delegate.
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/IntentState.java b/core/api/src/main/java/org/onlab/onos/net/intent/IntentState.java
index 3fbe82d..0e9211d 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/IntentState.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/IntentState.java
@@ -67,6 +67,18 @@
RECOMPILING,
/**
+ * TODO: Indicated that an intent will soon be recompiled.
+ */
+ //UPDATE,
+
+ /**
+ * TODO.
+ * Indicates that an application has requested that an intent be withdrawn.
+ * It will start withdrawing short, but not necessarily on this instance.
+ */
+ //WITHDRAW_REQ,
+
+ /**
* Indicates that the intent is being withdrawn. This is a transitional
* state, triggered by invocation of the
* {@link IntentService#withdraw(Intent)} but one with only one outcome,
diff --git a/core/api/src/test/java/org/onlab/onos/net/flow/FlowRuleBatchRequestTest.java b/core/api/src/test/java/org/onlab/onos/net/flow/FlowRuleBatchRequestTest.java
index 7541692..6710f18 100644
--- a/core/api/src/test/java/org/onlab/onos/net/flow/FlowRuleBatchRequestTest.java
+++ b/core/api/src/test/java/org/onlab/onos/net/flow/FlowRuleBatchRequestTest.java
@@ -21,6 +21,8 @@
import org.junit.Test;
import org.onlab.onos.net.intent.IntentTestsMocks;
+import static org.onlab.onos.net.flow.FlowRuleBatchEntry.FlowRuleOperation.*;
+
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
@@ -38,10 +40,10 @@
public void testConstruction() {
final FlowRule rule1 = new IntentTestsMocks.MockFlowRule(1);
final FlowRule rule2 = new IntentTestsMocks.MockFlowRule(2);
- final List<FlowRule> toAdd = new LinkedList<>();
- toAdd.add(rule1);
- final List<FlowRule> toRemove = new LinkedList<>();
- toRemove.add(rule2);
+ final List<FlowRuleBatchEntry> toAdd = new LinkedList<>();
+ toAdd.add(new FlowRuleBatchEntry(ADD, rule1));
+ final List<FlowRuleBatchEntry> toRemove = new LinkedList<>();
+ toRemove.add(new FlowRuleBatchEntry(REMOVE, rule2));
final FlowRuleBatchRequest request =
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/IntentTestsMocks.java b/core/api/src/test/java/org/onlab/onos/net/intent/IntentTestsMocks.java
index cc2ef75..c5483c9 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/IntentTestsMocks.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/IntentTestsMocks.java
@@ -26,6 +26,7 @@
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
import org.onlab.onos.net.DeviceId;
@@ -331,7 +332,22 @@
return false;
}
+ @Override
+ public int hashCode() {
+ return Objects.hash(priority);
+ }
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ final MockFlowRule other = (MockFlowRule) obj;
+ return Objects.equals(this.priority, other.priority);
+ }
}