--- /dev/null
+package org.openflow.protocol.statistics;
+
+import java.io.Serializable;
+import java.nio.ByteBuffer;
+import java.util.List;
+
+import org.openflow.protocol.OFMatch;
+import org.openflow.protocol.action.OFAction;
+import org.openflow.protocol.factory.OFActionFactory;
+import org.openflow.protocol.factory.OFActionFactoryAware;
+import org.openflow.util.U16;
+
+/**
+ * Represents an ofp_flow_stats structure
+ * @author David Erickson (daviderickson@cs.stanford.edu)
+ */
+public class OFFlowStatisticsReply implements OFStatistics, OFActionFactoryAware, Serializable {
+ public static int MINIMUM_LENGTH = 88;
+
+ protected transient OFActionFactory actionFactory;
+ protected short length = (short) MINIMUM_LENGTH;
+ protected byte tableId;
+ protected OFMatch match;
+ protected int durationSeconds;
+ protected int durationNanoseconds;
+ protected short priority;
+ protected short idleTimeout;
+ protected short hardTimeout;
+ protected long cookie;
+ protected long packetCount;
+ protected long byteCount;
+ protected List<OFAction> actions;
+
+ /**
+ * @return the tableId
+ */
+ public byte getTableId() {
+ return tableId;
+ }
+
+ /**
+ * @param tableId the tableId to set
+ */
+ public void setTableId(byte tableId) {
+ this.tableId = tableId;
+ }
+
+ /**
+ * @return the match
+ */
+ public OFMatch getMatch() {
+ return match;
+ }
+
+ /**
+ * @param match the match to set
+ */
+ public void setMatch(OFMatch match) {
+ this.match = match;
+ }
+
+ /**
+ * @return the durationSeconds
+ */
+ public int getDurationSeconds() {
+ return durationSeconds;
+ }
+
+ /**
+ * @param durationSeconds the durationSeconds to set
+ */
+ public void setDurationSeconds(int durationSeconds) {
+ this.durationSeconds = durationSeconds;
+ }
+
+ /**
+ * @return the durationNanoseconds
+ */
+ public int getDurationNanoseconds() {
+ return durationNanoseconds;
+ }
+
+ /**
+ * @param durationNanoseconds the durationNanoseconds to set
+ */
+ public void setDurationNanoseconds(int durationNanoseconds) {
+ this.durationNanoseconds = durationNanoseconds;
+ }
+
+ /**
+ * @return the priority
+ */
+ public short getPriority() {
+ return priority;
+ }
+
+ /**
+ * @param priority the priority to set
+ */
+ public void setPriority(short priority) {
+ this.priority = priority;
+ }
+
+ /**
+ * @return the idleTimeout
+ */
+ public short getIdleTimeout() {
+ return idleTimeout;
+ }
+
+ /**
+ * @param idleTimeout the idleTimeout to set
+ */
+ public void setIdleTimeout(short idleTimeout) {
+ this.idleTimeout = idleTimeout;
+ }
+
+ /**
+ * @return the hardTimeout
+ */
+ public short getHardTimeout() {
+ return hardTimeout;
+ }
+
+ /**
+ * @param hardTimeout the hardTimeout to set
+ */
+ public void setHardTimeout(short hardTimeout) {
+ this.hardTimeout = hardTimeout;
+ }
+
+ /**
+ * @return the cookie
+ */
+ public long getCookie() {
+ return cookie;
+ }
+
+ /**
+ * @param cookie the cookie to set
+ */
+ public void setCookie(long cookie) {
+ this.cookie = cookie;
+ }
+
+ /**
+ * @return the packetCount
+ */
+ public long getPacketCount() {
+ return packetCount;
+ }
+
+ /**
+ * @param packetCount the packetCount to set
+ */
+ public void setPacketCount(long packetCount) {
+ this.packetCount = packetCount;
+ }
+
+ /**
+ * @return the byteCount
+ */
+ public long getByteCount() {
+ return byteCount;
+ }
+
+ /**
+ * @param byteCount the byteCount to set
+ */
+ public void setByteCount(long byteCount) {
+ this.byteCount = byteCount;
+ }
+
+ /**
+ * @param length the length to set
+ */
+ public void setLength(short length) {
+ this.length = length;
+ }
+
+ @Override
+ public int getLength() {
+ return U16.f(length);
+ }
+
+ /**
+ * @param actionFactory the actionFactory to set
+ */
+ @Override
+ public void setActionFactory(OFActionFactory actionFactory) {
+ this.actionFactory = actionFactory;
+ }
+
+ /**
+ * @return the actions
+ */
+ public List<OFAction> getActions() {
+ return actions;
+ }
+
+ /**
+ * @param actions the actions to set
+ */
+ public void setActions(List<OFAction> actions) {
+ this.actions = actions;
+ }
+
+ @Override
+ public void readFrom(ByteBuffer data) {
+ this.length = data.getShort();
+ this.tableId = data.get();
+ data.get(); // pad
+ if (this.match == null)
+ this.match = new OFMatch();
+ this.match.readFrom(data);
+ this.durationSeconds = data.getInt();
+ this.durationNanoseconds = data.getInt();
+ this.priority = data.getShort();
+ this.idleTimeout = data.getShort();
+ this.hardTimeout = data.getShort();
+ data.getInt(); // pad
+ data.getShort(); // pad
+ this.cookie = data.getLong();
+ this.packetCount = data.getLong();
+ this.byteCount = data.getLong();
+ if (this.actionFactory == null)
+ throw new RuntimeException("OFActionFactory not set");
+ this.actions = this.actionFactory.parseActions(data, getLength() -
+ MINIMUM_LENGTH);
+ }
+
+ @Override
+ public void writeTo(ByteBuffer data) {
+ data.putShort(this.length);
+ data.put(this.tableId);
+ data.put((byte) 0);
+ this.match.writeTo(data);
+ data.putInt(this.durationSeconds);
+ data.putInt(this.durationNanoseconds);
+ data.putShort(this.priority);
+ data.putShort(this.idleTimeout);
+ data.putShort(this.hardTimeout);
+ data.getInt(); // pad
+ data.getShort(); // pad
+ data.putLong(this.cookie);
+ data.putLong(this.packetCount);
+ data.putLong(this.byteCount);
+ if (actions != null) {
+ for (OFAction action : actions) {
+ action.writeTo(data);
+ }
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 419;
+ int result = 1;
+ result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
+ result = prime * result + (int) (cookie ^ (cookie >>> 32));
+ result = prime * result + durationNanoseconds;
+ result = prime * result + durationSeconds;
+ result = prime * result + hardTimeout;
+ result = prime * result + idleTimeout;
+ result = prime * result + length;
+ result = prime * result + ((match == null) ? 0 : match.hashCode());
+ result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
+ result = prime * result + priority;
+ result = prime * result + tableId;
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof OFFlowStatisticsReply)) {
+ return false;
+ }
+ OFFlowStatisticsReply other = (OFFlowStatisticsReply) obj;
+ if (byteCount != other.byteCount) {
+ return false;
+ }
+ if (cookie != other.cookie) {
+ return false;
+ }
+ if (durationNanoseconds != other.durationNanoseconds) {
+ return false;
+ }
+ if (durationSeconds != other.durationSeconds) {
+ return false;
+ }
+ if (hardTimeout != other.hardTimeout) {
+ return false;
+ }
+ if (idleTimeout != other.idleTimeout) {
+ return false;
+ }
+ if (length != other.length) {
+ return false;
+ }
+ if (match == null) {
+ if (other.match != null) {
+ return false;
+ }
+ } else if (!match.equals(other.match)) {
+ return false;
+ }
+ if (packetCount != other.packetCount) {
+ return false;
+ }
+ if (priority != other.priority) {
+ return false;
+ }
+ if (tableId != other.tableId) {
+ return false;
+ }
+ return true;
+ }
+}