-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
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;
/**
* Represent a flow: match + actions + flow specific properties
- *
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class Flow implements Cloneable, Serializable {
- protected static final Logger logger = LoggerFactory
- .getLogger(Flow.class);
- private static final long serialVersionUID = 1L;
- @XmlElement
+ protected static final Logger logger = LoggerFactory.getLogger(Flow.class);
+ private static final long serialVersionUID = 1L;
+ @XmlElement
private Match match;
@XmlElement
private List<Action> actions;
try {
throw new Exception("Conflicting Match and Action list");
} catch (Exception e) {
- logger.error("",e);
+ logger.error("", e);
}
} else {
this.match = match;
}
/**
- * 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
*/
/**
* Returns a copy of the actions list of this flow
+ *
* @return
*/
public List<Action> getActions() {
}
/**
- * 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
*/
}
/**
- * 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
*/
}
/**
- * 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
*/
}
break;
case SET_DL_TYPE:
- if (((SetDlType) action).getDlType() == EtherTypes.IPv6
- .intValue()) {
+ if (((SetDlType) action).getDlType() == EtherTypes.IPv6.intValue()) {
return true;
}
break;
cloned.match = this.getMatch();
cloned.actions = this.getActions();
} catch (CloneNotSupportedException e) {
- logger.error("",e);
+ 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() {
* 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()) {
}
/**
- * 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;