Towards a distributed flow rule store
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/BatchOperationResult.java b/core/api/src/main/java/org/onlab/onos/net/flow/BatchOperationResult.java
index 43fd694..33f1845 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/BatchOperationResult.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/BatchOperationResult.java
@@ -1,6 +1,6 @@
package org.onlab.onos.net.flow;
-import java.util.List;
+import java.util.Set;
/**
* Interface capturing the result of a batch operation.
@@ -15,9 +15,9 @@
boolean isSuccess();
/**
- * Obtains a list of items which failed.
- * @return a list of failures
+ * Obtains a set of items which failed.
+ * @return a set of failures
*/
- List<T> failedItems();
+ Set<T> failedItems();
}
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 e9889cd..4e671e3 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
@@ -1,18 +1,18 @@
package org.onlab.onos.net.flow;
-import java.util.List;
+import java.util.Set;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
public class CompletedBatchOperation implements BatchOperationResult<FlowEntry> {
private final boolean success;
- private final List<FlowEntry> failures;
+ private final Set<FlowEntry> failures;
- public CompletedBatchOperation(boolean success, List<FlowEntry> failures) {
+ public CompletedBatchOperation(boolean success, Set<FlowEntry> failures) {
this.success = success;
- this.failures = ImmutableList.copyOf(failures);
+ this.failures = ImmutableSet.copyOf(failures);
}
@Override
@@ -21,7 +21,7 @@
}
@Override
- public List<FlowEntry> failedItems() {
+ public Set<FlowEntry> failedItems() {
return failures;
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleBatchEvent.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleBatchEvent.java
new file mode 100644
index 0000000..4ba3366
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleBatchEvent.java
@@ -0,0 +1,67 @@
+package org.onlab.onos.net.flow;
+
+import org.onlab.onos.event.AbstractEvent;
+
+/**
+ * Describes flow rule batch event.
+ */
+public final class FlowRuleBatchEvent extends AbstractEvent<FlowRuleBatchEvent.Type, FlowRuleBatchRequest> {
+
+ /**
+ * Type of flow rule events.
+ */
+ public enum Type {
+
+ /**
+ * Signifies that a batch operation has been initiated.
+ */
+ BATCH_OPERATION_REQUESTED,
+
+ /**
+ * Signifies that a batch operation has completed.
+ */
+ BATCH_OPERATION_COMPLETED,
+ }
+
+ private final CompletedBatchOperation result;
+
+ /**
+ * Constructs a new FlowRuleBatchEvent.
+ * @param request batch operation request.
+ * @return event.
+ */
+ public static FlowRuleBatchEvent create(FlowRuleBatchRequest request) {
+ FlowRuleBatchEvent event = new FlowRuleBatchEvent(Type.BATCH_OPERATION_REQUESTED, request, null);
+ return event;
+ }
+
+ /**
+ * Constructs a new FlowRuleBatchEvent.
+ * @param request batch operation request.
+ * @param result completed batch operation result.
+ * @return event.
+ */
+ public static FlowRuleBatchEvent create(FlowRuleBatchRequest request, CompletedBatchOperation result) {
+ FlowRuleBatchEvent event = new FlowRuleBatchEvent(Type.BATCH_OPERATION_COMPLETED, request, result);
+ return event;
+ }
+
+ /**
+ * Returns the result of this batch operation.
+ * @return batch operation result.
+ */
+ public CompletedBatchOperation result() {
+ return result;
+ }
+
+ /**
+ * Creates an event of a given type and for the specified flow rule batch.
+ *
+ * @param type flow rule batch event type
+ * @param batch event flow rule batch subject
+ */
+ private FlowRuleBatchEvent(Type type, FlowRuleBatchRequest request, CompletedBatchOperation result) {
+ super(type, request);
+ this.result = result;
+ }
+}
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
new file mode 100644
index 0000000..0414fcb
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleBatchRequest.java
@@ -0,0 +1,38 @@
+package org.onlab.onos.net.flow;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.onlab.onos.net.flow.FlowRuleBatchEntry.FlowRuleOperation;
+
+import com.google.common.collect.Lists;
+
+public class FlowRuleBatchRequest {
+
+ private final List<FlowEntry> toAdd;
+ private final List<FlowEntry> toRemove;
+
+ public FlowRuleBatchRequest(List<FlowEntry> toAdd, List<FlowEntry> toRemove) {
+ this.toAdd = Collections.unmodifiableList(toAdd);
+ this.toRemove = Collections.unmodifiableList(toRemove);
+ }
+
+ public List<FlowEntry> toAdd() {
+ return toAdd;
+ }
+
+ public List<FlowEntry> toRemove() {
+ return toRemove;
+ }
+
+ public FlowRuleBatchOperation asBatchOperation() {
+ List<FlowRuleBatchEntry> entries = Lists.newArrayList();
+ for (FlowEntry e : toAdd) {
+ entries.add(new FlowRuleBatchEntry(FlowRuleOperation.ADD, e));
+ }
+ for (FlowEntry e : toRemove) {
+ entries.add(new FlowRuleBatchEntry(FlowRuleOperation.REMOVE, e));
+ }
+ return new FlowRuleBatchOperation(entries);
+ }
+}
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProvider.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProvider.java
index 3592e39..5a57b88 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProvider.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleProvider.java
@@ -1,11 +1,11 @@
package org.onlab.onos.net.flow;
-import java.util.concurrent.Future;
-
import org.onlab.onos.ApplicationId;
import org.onlab.onos.net.intent.BatchOperation;
import org.onlab.onos.net.provider.Provider;
+import com.google.common.util.concurrent.ListenableFuture;
+
/**
* Abstraction of a flow rule provider.
*/
@@ -43,6 +43,6 @@
* @param batch a batch of flow rules
* @return a future indicating the status of this execution
*/
- Future<CompletedBatchOperation> executeBatch(BatchOperation<FlowRuleBatchEntry> batch);
+ ListenableFuture<CompletedBatchOperation> executeBatch(BatchOperation<FlowRuleBatchEntry> batch);
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStore.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStore.java
index abb9a10..c53a32d 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStore.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStore.java
@@ -1,5 +1,7 @@
package org.onlab.onos.net.flow;
+import java.util.concurrent.Future;
+
import org.onlab.onos.ApplicationId;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.store.Store;
@@ -7,7 +9,7 @@
/**
* Manages inventory of flow rules; not intended for direct use.
*/
-public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegate> {
+public interface FlowRuleStore extends Store<FlowRuleBatchEvent, FlowRuleStoreDelegate> {
/**
* Returns the number of flow rule in the store.
@@ -41,12 +43,26 @@
Iterable<FlowRule> getFlowRulesByAppId(ApplicationId appId);
/**
+ // TODO: Better description of method behavior.
* Stores a new flow rule without generating events.
*
* @param rule the flow rule to add
- * @return true if the rule should be handled locally
*/
- boolean storeFlowRule(FlowRule rule);
+ void storeFlowRule(FlowRule rule);
+
+ /**
+ * Stores a batch of flow rules.
+ * @param batchOperation batch of flow rules.
+ * @return Future response indicating success/failure of the batch operation
+ * all the way down to the device.
+ */
+ Future<CompletedBatchOperation> storeBatch(FlowRuleBatchOperation batchOperation);
+
+ /**
+ * Invoked on the completion of a storeBatch operation.
+ * @param result
+ */
+ void batchOperationComplete(FlowRuleBatchEvent event);
/**
* Marks a flow rule for deletion. Actual deletion will occur
@@ -55,7 +71,7 @@
* @param rule the flow rule to delete
* @return true if the rule should be handled locally
*/
- boolean deleteFlowRule(FlowRule rule);
+ void deleteFlowRule(FlowRule rule);
/**
* Stores a new flow rule, or updates an existing entry.
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStoreDelegate.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStoreDelegate.java
index 119712b..66973dd 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStoreDelegate.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRuleStoreDelegate.java
@@ -5,5 +5,5 @@
/**
* Flow rule store delegate abstraction.
*/
-public interface FlowRuleStoreDelegate extends StoreDelegate<FlowRuleEvent> {
+public interface FlowRuleStoreDelegate extends StoreDelegate<FlowRuleBatchEvent> {
}