Refactor ForwardingRulesmanager
[controller.git] / opendaylight / forwardingrulesmanager / api / src / main / java / org / opendaylight / controller / forwardingrulesmanager / FlowEntry.java
index 8a055329e1fcebc99c60a904b4dc547779010e56..e86e0186c61544b73763ff2fa3edc877ce14c5f7 100644 (file)
@@ -25,8 +25,7 @@ import org.slf4j.LoggerFactory;
  * instance the flows constituting a policy all share the same group name.
  */
 public class FlowEntry implements Cloneable, Serializable {
-    protected static final Logger logger = LoggerFactory
-            .getLogger(FlowEntry.class);
+    protected static final Logger logger = LoggerFactory.getLogger(FlowEntry.class);
     private static final long serialVersionUID = 1L;
     private static final Logger log = LoggerFactory.getLogger(FlowEntry.class);
     private String groupName; // group name
@@ -86,55 +85,65 @@ public class FlowEntry implements Cloneable, Serializable {
         return cloned;
     }
 
+    /*
+     * Only accounts fields which uniquely identify a flow for collision
+     * purposes: node, match and priority
+     */
     @Override
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((flow == null) ? 0 : flow.hashCode());
-        result = prime * result
-                + ((flowName == null) ? 0 : flowName.hashCode());
-        result = prime * result
-                + ((groupName == null) ? 0 : groupName.hashCode());
         result = prime * result + ((node == null) ? 0 : node.hashCode());
+        result = prime * result + ((flow == null) ? 0 : (int) flow.getPriority());
+        result = prime * result + ((flow == null || flow.getMatch() == null) ? 0 : flow.getMatch().hashCode());
+
         return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj) {
             return true;
-        if (obj == null)
+        }
+        if (obj == null) {
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()) {
             return false;
+        }
         FlowEntry other = (FlowEntry) obj;
-        if (flow == null) {
-            if (other.flow != null)
+
+        if (node == null) {
+            if (other.node != null) {
                 return false;
-        } else if (!flow.equals(other.flow))
+            }
+        } else if (!node.equals(other.node)) {
             return false;
-        if (flowName == null) {
-            if (other.flowName != null)
-                return false;
-        } else if (!flowName.equals(other.flowName))
+        }
+
+        if (flow == null) {
+            return (other.flow == null) ? true : false;
+        } else if (other.flow == null) {
             return false;
-        if (groupName == null) {
-            if (other.groupName != null)
-                return false;
-        } else if (!groupName.equals(other.groupName))
+        }
+        if (flow.getPriority() != other.flow.getPriority()) {
             return false;
-        if (node == null) {
-            if (other.node != null)
+        }
+        if (flow.getMatch() == null) {
+            if (other.flow.getMatch() != null) {
                 return false;
-        } else if (!node.equals(other.node))
+            }
+        } else if (!flow.getMatch().equals(other.flow.getMatch())) {
             return false;
+        }
+
         return true;
     }
 
     @Override
     public String toString() {
-        return "FlowEntry[flowName = " + flowName + ", groupName = "
-                + groupName + ",node = " + node + ", flow = " + flow + "]";
+        return "FlowEntry[flowName = " + flowName + ", groupName = " + groupName + ", node = " + node + ", flow = "
+                + flow + "]";
     }
 
     private String constructFlowName() {
@@ -170,4 +179,14 @@ public class FlowEntry implements Cloneable, Serializable {
 
         return this;
     }
+
+    /**
+     * Returns whether this entry is the result of an internal generated static
+     * flow
+     *
+     * @return true if internal generated static flow, false otherwise
+     */
+    public boolean isInternal() {
+        return flowName.startsWith(FlowConfig.internalStaticFlowBegin);
+    }
 }