Implement event listeners of the FlowManager.
- This commit adds two types of event objects: FlowBatchStateChangedEvent and FlowStatesChangedEvent.
- Listeners for these objects are defined by FlowManagerListener interface.
- FlowBatchStateChangedEvent notifies state changes of the flow batch operation.
-- The state is defined by FlowBatchState.
- FlowStatesChangedEvent notifies state changes of the set of Flow objects.
-- The state is defined by FlowState.
- This task is a part of ONOS-1739.
Change-Id: Ie8b3bb1c58dbe6bc608936e4a269e1de12dee96c
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchHandle.java b/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchHandle.java
new file mode 100644
index 0000000..166a12f
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchHandle.java
@@ -0,0 +1,29 @@
+package net.onrc.onos.api.flowmanager;
+
+/**
+ * Handle class to handle flow batch operation.
+ */
+public class FlowBatchHandle {
+ private final FlowBatchId batchId;
+
+ /**
+ * Creates a handle using batch operation ID.
+ * <p>
+ * The ID is automatically generated and assigned by FlowManager, and used
+ * as an internal key for the flow batch operation map.
+ *
+ * @param id the batch operation ID
+ */
+ public FlowBatchHandle(FlowBatchId id) {
+ batchId = id;
+ }
+
+ /**
+ * Gets the flow batch operation ID.
+ *
+ * @return the flow batch operation ID
+ */
+ public FlowBatchId getBatchOperationId() {
+ return batchId;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchId.java b/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchId.java
new file mode 100644
index 0000000..9899adf
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchId.java
@@ -0,0 +1,8 @@
+package net.onrc.onos.api.flowmanager;
+
+/**
+ * Represents ID for {@link FlowBatchOperation}.
+ */
+public class FlowBatchId {
+ // TODO implement it
+}
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchState.java b/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchState.java
new file mode 100644
index 0000000..fd62a97
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchState.java
@@ -0,0 +1,27 @@
+package net.onrc.onos.api.flowmanager;
+
+/**
+ * Represents the state of {@link FlowBatchOperation}.
+ */
+public enum FlowBatchState {
+ /**
+ * The operation has been submitted, but the FlowManager is not executing
+ * yet.
+ */
+ SUBMITTED,
+
+ /**
+ * The FlowManager is executing the operation, but not completed yet.
+ */
+ EXECUTING,
+
+ /**
+ * The operation has been executed successfully.
+ */
+ COMPLETED,
+
+ /**
+ * The operation has been failed to be submitted or executed.
+ */
+ FAILED,
+}
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchStateChangedEvent.java b/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchStateChangedEvent.java
new file mode 100644
index 0000000..7b169e6
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchStateChangedEvent.java
@@ -0,0 +1,64 @@
+package net.onrc.onos.api.flowmanager;
+
+/**
+ * Event class which notifies the state change of flow batch operation.
+ */
+public class FlowBatchStateChangedEvent {
+ private final long time;
+ private final FlowBatchHandle handle;
+ private final FlowBatchState current;
+ private final FlowBatchState previous;
+
+ /**
+ * Creates the {@link FlowBatchStateChangedEvent} instance.
+ *
+ * @param time the time at which the event was created in milliseconds since
+ * start of epoch
+ * @param handle the handle for the flow batch operation
+ * @param current the current state of the flow batch operation
+ * @param previous the previous state of the flow batch operation
+ */
+ FlowBatchStateChangedEvent(long time, FlowBatchHandle handle,
+ FlowBatchState current, FlowBatchState previous) {
+ this.time = time;
+ this.handle = handle;
+ this.current = current;
+ this.previous = previous;
+ }
+
+ /**
+ * Gets the time at which the event was created.
+ *
+ * @return the time in milliseconds since start of epoch
+ */
+ public long getTime() {
+ return time;
+ }
+
+ /**
+ * Gets the handle for the flow batch operation.
+ *
+ * @return the handle for the flow batch operation
+ */
+ public FlowBatchHandle getFlowBatchHandle() {
+ return handle;
+ }
+
+ /**
+ * Gets the current state of the flow batch operation.
+ *
+ * @return the current state of the flow batch operation
+ */
+ public FlowBatchState getCurrentState() {
+ return current;
+ }
+
+ /**
+ * Gets the previous state of the flow batch operation.
+ *
+ * @return the previous state of the flow batch operation
+ */
+ public FlowBatchState getPreviousState() {
+ return previous;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/FlowManagerListener.java b/src/main/java/net/onrc/onos/api/flowmanager/FlowManagerListener.java
new file mode 100644
index 0000000..0e70867
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/flowmanager/FlowManagerListener.java
@@ -0,0 +1,20 @@
+package net.onrc.onos.api.flowmanager;
+
+/**
+ * An interface to the FlowManager's listener.
+ */
+public interface FlowManagerListener {
+ /**
+ * Handles flow state changes.
+ *
+ * @param event the state changes of the flow objects
+ */
+ public void flowStatesChanged(FlowStatesChangedEvent event);
+
+ /**
+ * Handles flow batch operation's state changes.
+ *
+ * @param event the state changes of the flow batch operations
+ */
+ public void flowBatchStateChanged(FlowBatchStateChangedEvent event);
+}
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/FlowManagerService.java b/src/main/java/net/onrc/onos/api/flowmanager/FlowManagerService.java
index b8e14f4..4812de2 100644
--- a/src/main/java/net/onrc/onos/api/flowmanager/FlowManagerService.java
+++ b/src/main/java/net/onrc/onos/api/flowmanager/FlowManagerService.java
@@ -1,7 +1,6 @@
package net.onrc.onos.api.flowmanager;
import java.util.Collection;
-import java.util.EventListener;
/**
* An interface class for flow manager. The role of the flow manager is to
@@ -71,14 +70,14 @@
/**
* Adds event listener to this service.
*
- * @param listener EventListener to be added
+ * @param listener the listener to be added
*/
- void addEventListener(EventListener listener);
+ void addListener(FlowManagerListener listener);
/**
* Removes event listener from this service.
*
- * @param listener EventListener to be removed
+ * @param listener the listener to be removed
*/
- void removeEventListener(EventListener listener);
+ void removeListener(FlowManagerListener listener);
}
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/FlowState.java b/src/main/java/net/onrc/onos/api/flowmanager/FlowState.java
new file mode 100644
index 0000000..4cb03c7
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/flowmanager/FlowState.java
@@ -0,0 +1,38 @@
+package net.onrc.onos.api.flowmanager;
+
+/**
+ * Represents the state of the Flow object.
+ */
+public enum FlowState {
+
+ /**
+ * The flow object is submitted, but not compiled yet.
+ */
+ SUBMITTED,
+
+ /**
+ * The match-action plan has been compiled from the flow object, but not
+ * installed yet.
+ */
+ COMPILED,
+
+ /**
+ * The compiled match-action plan has been installed successfully.
+ */
+ INSTALLED,
+
+ /**
+ * The installed flow is withdrawing.
+ */
+ WITHDRAWING,
+
+ /**
+ * The installed flow has been withdrawn successfully.
+ */
+ WITHDRAWN,
+
+ /**
+ * The FlowManager has failed to compile, install or withdraw the flow.
+ */
+ FAILED,
+}
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/FlowStateChange.java b/src/main/java/net/onrc/onos/api/flowmanager/FlowStateChange.java
new file mode 100644
index 0000000..9d7f0d6
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/flowmanager/FlowStateChange.java
@@ -0,0 +1,50 @@
+package net.onrc.onos.api.flowmanager;
+
+/**
+ * The class which expresses the state changes of Flow object.
+ */
+public class FlowStateChange {
+ private final FlowId flowId;
+ private final FlowState current;
+ private final FlowState previous;
+
+ /**
+ * Creates {@link FlowStateChange} instance.
+ *
+ * @param flowId the ID of the target flow
+ * @param current the current state of the flow
+ * @param previous the previous state of the flow
+ */
+ FlowStateChange(FlowId flowId, FlowState current, FlowState previous) {
+ this.flowId = flowId;
+ this.current = current;
+ this.previous = previous;
+ }
+
+ /**
+ * Gets the ID of the flow.
+ *
+ * @return the flow ID
+ */
+ public FlowId getFlowId() {
+ return flowId;
+ }
+
+ /**
+ * Gets the current state of the flow.
+ *
+ * @return the current state of the flow
+ */
+ public FlowState getCurrentState() {
+ return current;
+ }
+
+ /**
+ * Gets the previous state of the flow.
+ *
+ * @return the previous state of the flow
+ */
+ public FlowState getPreviousState() {
+ return previous;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/FlowStatesChangedEvent.java b/src/main/java/net/onrc/onos/api/flowmanager/FlowStatesChangedEvent.java
new file mode 100644
index 0000000..d078fcb
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/flowmanager/FlowStatesChangedEvent.java
@@ -0,0 +1,44 @@
+package net.onrc.onos.api.flowmanager;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Set;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * The event class which notifies the set of the flow state transitions.
+ */
+public class FlowStatesChangedEvent {
+ private final long time;
+ private final Set<FlowStateChange> changes;
+
+ /**
+ * Creates the {@link FlowStatesChangedEvent} instance.
+ *
+ * @param time the time at which the event was created in milliseconds since start of epoch
+ * @param changes the set of {@link FlowStateChange} objects
+ */
+ FlowStatesChangedEvent(long time, Set<FlowStateChange> changes) {
+ this.time = time;
+ this.changes = ImmutableSet.copyOf(checkNotNull(changes));
+ }
+
+ /**
+ * Gets the time at which the event was created.
+ *
+ * @return the time at which the event was created in milliseconds since start of epoch
+ */
+ public long getTime() {
+ return time;
+ }
+
+ /**
+ * Gets the set of state changes happened at once.
+ *
+ * @return the set of {@link FlowStateChange} objects
+ */
+ public Set<FlowStateChange> getStateChanges() {
+ return changes;
+ }
+}
diff --git a/src/main/java/net/onrc/onos/core/flowmanager/FlowManagerModule.java b/src/main/java/net/onrc/onos/core/flowmanager/FlowManagerModule.java
index 2d184f8..8336095 100644
--- a/src/main/java/net/onrc/onos/core/flowmanager/FlowManagerModule.java
+++ b/src/main/java/net/onrc/onos/core/flowmanager/FlowManagerModule.java
@@ -1,12 +1,12 @@
package net.onrc.onos.core.flowmanager;
import java.util.Collection;
-import java.util.EventListener;
import net.onrc.onos.api.flowmanager.ConflictDetectionPolicy;
+import net.onrc.onos.api.flowmanager.Flow;
import net.onrc.onos.api.flowmanager.FlowBatchOperation;
import net.onrc.onos.api.flowmanager.FlowId;
-import net.onrc.onos.api.flowmanager.Flow;
+import net.onrc.onos.api.flowmanager.FlowManagerListener;
import net.onrc.onos.api.flowmanager.FlowManagerService;
/**
@@ -73,13 +73,13 @@
}
@Override
- public void addEventListener(EventListener listener) {
+ public void addListener(FlowManagerListener listener) {
// TODO Auto-generated method stub
}
@Override
- public void removeEventListener(EventListener listener) {
+ public void removeListener(FlowManagerListener listener) {
// TODO Auto-generated method stub
}
diff --git a/src/main/java/net/onrc/onos/core/flowmanager/FlowOperationMap.java b/src/main/java/net/onrc/onos/core/flowmanager/FlowOperationMap.java
new file mode 100644
index 0000000..744c65e
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/flowmanager/FlowOperationMap.java
@@ -0,0 +1,8 @@
+package net.onrc.onos.core.flowmanager;
+
+/**
+ * Manages the set of flow operations throughout the ONOS instances.
+ */
+public class FlowOperationMap {
+ // TODO implement it
+}