Refactor ForwardingRulesmanager
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / flowprogrammer / Flow.java
index 16c85a105ad832080a52ea222428cafc49e9a316..0df6d4cec47a778cf4645f9fd342f63250ce9855 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
  *
@@ -9,6 +8,7 @@
 
 package org.opendaylight.controller.sal.flowprogrammer;
 
+import java.io.Serializable;
 import java.net.Inet6Address;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -19,8 +19,6 @@ import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
 import org.opendaylight.controller.sal.action.Action;
 import org.opendaylight.controller.sal.action.ActionType;
 import org.opendaylight.controller.sal.action.SetDlType;
@@ -28,14 +26,17 @@ import org.opendaylight.controller.sal.action.SetNwDst;
 import org.opendaylight.controller.sal.action.SetNwSrc;
 import org.opendaylight.controller.sal.match.Match;
 import org.opendaylight.controller.sal.utils.EtherTypes;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Represent a flow: match + actions + flow specific properties
- *
  */
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
-public class Flow implements Cloneable {
+public class Flow implements Cloneable, Serializable {
+    protected static final Logger logger = LoggerFactory.getLogger(Flow.class);
+    private static final long serialVersionUID = 1L;
     @XmlElement
     private Match match;
     @XmlElement
@@ -59,7 +60,7 @@ public class Flow implements Cloneable {
             try {
                 throw new Exception("Conflicting Match and Action list");
             } catch (Exception e) {
-                e.printStackTrace();
+                logger.error("", e);
             }
         } else {
             this.match = match;
@@ -77,8 +78,8 @@ public class Flow implements Cloneable {
     }
 
     /**
-     * Set the Match for this flow
-     * This operation will overwrite an existing Match if present
+     * Set the Match for this flow This operation will overwrite an existing
+     * Match if present
      *
      * @param match
      */
@@ -88,6 +89,7 @@ public class Flow implements Cloneable {
 
     /**
      * Returns a copy of the actions list of this flow
+     *
      * @return
      */
     public List<Action> getActions() {
@@ -95,12 +97,10 @@ public class Flow implements Cloneable {
     }
 
     /**
-     * Set the actions list for this flow
-     * If a list is already present, it will be
-     * replaced with the passed one. During
-     * addition, only the valid actions will be added
-     * It is a no op if the passed actions is null
-     * An empty actions is a vlaid input
+     * Set the actions list for this flow If a list is already present, it will
+     * be replaced with the passed one. During addition, only the valid actions
+     * will be added It is a no op if the passed actions is null An empty
+     * actions is a vlaid input
      *
      * @param actions
      */
@@ -118,8 +118,8 @@ public class Flow implements Cloneable {
     }
 
     /**
-     * Returns whether the Flow is for IPv4 or IPv6
-     * Information is derived from match and actions list
+     * Returns whether the Flow is for IPv4 or IPv6 Information is derived from
+     * match and actions list
      *
      * @return
      */
@@ -128,8 +128,8 @@ public class Flow implements Cloneable {
     }
 
     /**
-     * Returns true if it finds at least one action which is for IPv6
-     * in the list of actions for this Flow
+     * Returns true if it finds at least one action which is for IPv6 in the
+     * list of actions for this Flow
      *
      * @return
      */
@@ -148,8 +148,7 @@ public class Flow implements Cloneable {
                     }
                     break;
                 case SET_DL_TYPE:
-                    if (((SetDlType) action).getDlType() == EtherTypes.IPv6
-                            .intValue()) {
+                    if (((SetDlType) action).getDlType() == EtherTypes.IPv6.intValue()) {
                         return true;
                     }
                     break;
@@ -168,27 +167,69 @@ public class Flow implements Cloneable {
             cloned.match = this.getMatch();
             cloned.actions = this.getActions();
         } catch (CloneNotSupportedException e) {
-            e.printStackTrace();
+            logger.error("", e);
         }
         return cloned;
     }
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((actions == null) ? 0 : actions.hashCode());
+        result = prime * result + hardTimeout;
+        result = prime * result + (int) (id ^ (id >>> 32));
+        result = prime * result + idleTimeout;
+        result = prime * result + ((match == null) ? 0 : match.hashCode());
+        result = prime * result + priority;
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        Flow other = (Flow) obj;
+        if (actions == null) {
+            if (other.actions != null) {
+                return false;
+            }
+        } else if (!actions.equals(other.actions)) {
+            return false;
+        }
+        if (hardTimeout != other.hardTimeout) {
+            return false;
+        }
+        if (id != other.id) {
+            return false;
+        }
+        if (idleTimeout != other.idleTimeout) {
+            return false;
+        }
+        if (match == null) {
+            if (other.match != null) {
+                return false;
+            }
+        } else if (!match.equals(other.match)) {
+            return false;
+        }
+        if (priority != other.priority) {
+            return false;
+        }
+        return true;
     }
 
     @Override
     public String toString() {
-        return "Flow[match = " + match + ", actions = " + actions
-                + ", priority = " + priority + ", id = " + id
-                + ", idleTimeout = " + idleTimeout + ", hardTimeout = "
-                + hardTimeout + "]";
+        return "Flow[match = " + match + ", actions = " + actions + ", priority = " + priority + ", id = " + id
+                + ", idleTimeout = " + idleTimeout + ", hardTimeout = " + hardTimeout + "]";
     }
 
     public short getPriority() {
@@ -227,7 +268,8 @@ public class Flow implements Cloneable {
      * Adds the specified action to the list of action of this flow
      *
      * @param action
-     * @return false if the passed action is null or not valid or if it fails to add it
+     * @return false if the passed action is null or not valid or if it fails to
+     *         add it
      */
     public boolean addAction(Action action) {
         if (action == null || !action.isValid()) {
@@ -244,18 +286,21 @@ public class Flow implements Cloneable {
     }
 
     /**
-     * remove ALL actions of type actionType from the list of actions of this flow
+     * remove ALL actions of type actionType from the list of actions of this
+     * flow
      *
      * @param actionType
-     * @return false if an action of that type is present and it fails to remove it
+     * @return false if an action of that type is present and it fails to remove
+     *         it
      */
     public boolean removeAction(ActionType actionType) {
         Iterator<Action> actionIter = this.getActions().iterator();
         while (actionIter.hasNext()) {
             Action action = actionIter.next();
             if (action.getType() == actionType) {
-                if (!this.removeAction(action))
+                if (!this.removeAction(action)) {
                     return false;
+                }
             }
         }
         return true;