Update the Flow classes.
- Changed all Flow classes to use FlowId object on its constructor for their ID.
- Implement equals() and hashCode() for all Flow classes based on FlowId.
- Changed SingleDstTreeFlow class to accept the list of Action objects on its constructor.
- Updated the Tree class's constructor to accept the list of links.
- This task is a part of ONOS-1841, ONOS-1694, ONOS-1741.
Change-Id: I930007ce7f92b5bbde4efef9eb9ab893c356abf1
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/Flow.java b/src/main/java/net/onrc/onos/api/flowmanager/Flow.java
index 0622be6..8fe9577 100644
--- a/src/main/java/net/onrc/onos/api/flowmanager/Flow.java
+++ b/src/main/java/net/onrc/onos/api/flowmanager/Flow.java
@@ -1,37 +1,83 @@
package net.onrc.onos.api.flowmanager;
+import static com.google.common.base.Preconditions.checkNotNull;
import net.onrc.onos.api.batchoperation.BatchOperationTarget;
import net.onrc.onos.core.matchaction.MatchActionOperations;
import net.onrc.onos.core.matchaction.match.Match;
/**
- * An interface class to define flow object which is managed by
+ * An abstract class to define flow object which is managed by
* FlowManagerModule.
- * <p>
- * The flow objects (eg. path, tree, disjoint-paths, etc.) must implement this
- * interface.
*/
-public interface Flow extends BatchOperationTarget {
+public abstract class Flow implements BatchOperationTarget {
+ private final FlowId id;
+
+ /**
+ * Creates Flow object using specified ID.
+ *
+ * @param id the ID to be assigned
+ */
+ public Flow(FlowId id) {
+ this.id = checkNotNull(id);
+ }
+
/**
* Gets ID for this flow object.
*
- * @return ID for this object.
+ * @return ID for this object
*/
- public FlowId getId();
+ public FlowId getId() {
+ return id;
+ }
/**
* Gets traffic filter for this flow object.
*
- * @return a traffic filter for this flow object.
+ * @return a traffic filter for this flow object
*/
- public Match getMatch();
+ public abstract Match getMatch();
/**
- * Compiles this object to MatchAction plan.
+ * Compiles this object to MatchAction operations.
* <p>
* This method is called by FlowManagerModule to create MatchAction operations.
*
- * @return a MatchAction plan of this flow object.
+ * @return a MatchActionOperations of this flow object
*/
- public MatchActionOperations compile();
+ public abstract MatchActionOperations compile();
+
+ /**
+ * Generates a hash code using the FlowId.
+ *
+ * @return hashcode
+ */
+ @Override
+ public int hashCode() {
+ return (id == null) ? 0 : id.hashCode();
+ }
+
+ /**
+ * Compares two flow objects by type (class) and FlowId.
+ *
+ * @param obj other Flow object
+ * @return true if equal, false otherwise
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if ((obj == null) || !(obj instanceof Flow)) {
+ return false;
+ }
+ Flow other = (Flow) obj;
+ if (id == null) {
+ if (other.id != null) {
+ return false;
+ }
+ } else if (!id.equals(other.id)) {
+ return false;
+ }
+ return true;
+ }
}