1 package org.openflow.protocol.statistics;
3 import java.io.Serializable;
4 import java.nio.ByteBuffer;
7 import org.openflow.protocol.OFMatch;
8 import org.openflow.protocol.action.OFAction;
9 import org.openflow.protocol.factory.OFActionFactory;
10 import org.openflow.protocol.factory.OFActionFactoryAware;
11 import org.openflow.util.U16;
14 * Represents an ofp_flow_stats structure
15 * @author David Erickson (daviderickson@cs.stanford.edu)
17 public class OFFlowStatisticsReply implements OFStatistics, OFActionFactoryAware, Serializable {
18 public static int MINIMUM_LENGTH = 88;
20 protected transient OFActionFactory actionFactory;
21 protected short length = (short) MINIMUM_LENGTH;
22 protected byte tableId;
23 protected OFMatch match;
24 protected int durationSeconds;
25 protected int durationNanoseconds;
26 protected short priority;
27 protected short idleTimeout;
28 protected short hardTimeout;
29 protected long cookie;
30 protected long packetCount;
31 protected long byteCount;
32 protected List<OFAction> actions;
37 public byte getTableId() {
42 * @param tableId the tableId to set
44 public void setTableId(byte tableId) {
45 this.tableId = tableId;
51 public OFMatch getMatch() {
56 * @param match the match to set
58 public void setMatch(OFMatch match) {
63 * @return the durationSeconds
65 public int getDurationSeconds() {
66 return durationSeconds;
70 * @param durationSeconds the durationSeconds to set
72 public void setDurationSeconds(int durationSeconds) {
73 this.durationSeconds = durationSeconds;
77 * @return the durationNanoseconds
79 public int getDurationNanoseconds() {
80 return durationNanoseconds;
84 * @param durationNanoseconds the durationNanoseconds to set
86 public void setDurationNanoseconds(int durationNanoseconds) {
87 this.durationNanoseconds = durationNanoseconds;
91 * @return the priority
93 public short getPriority() {
98 * @param priority the priority to set
100 public void setPriority(short priority) {
101 this.priority = priority;
105 * @return the idleTimeout
107 public short getIdleTimeout() {
112 * @param idleTimeout the idleTimeout to set
114 public void setIdleTimeout(short idleTimeout) {
115 this.idleTimeout = idleTimeout;
119 * @return the hardTimeout
121 public short getHardTimeout() {
126 * @param hardTimeout the hardTimeout to set
128 public void setHardTimeout(short hardTimeout) {
129 this.hardTimeout = hardTimeout;
135 public long getCookie() {
140 * @param cookie the cookie to set
142 public void setCookie(long cookie) {
143 this.cookie = cookie;
147 * @return the packetCount
149 public long getPacketCount() {
154 * @param packetCount the packetCount to set
156 public void setPacketCount(long packetCount) {
157 this.packetCount = packetCount;
161 * @return the byteCount
163 public long getByteCount() {
168 * @param byteCount the byteCount to set
170 public void setByteCount(long byteCount) {
171 this.byteCount = byteCount;
175 * @param length the length to set
177 public void setLength(short length) {
178 this.length = length;
182 public int getLength() {
183 return U16.f(length);
187 * @param actionFactory the actionFactory to set
190 public void setActionFactory(OFActionFactory actionFactory) {
191 this.actionFactory = actionFactory;
195 * @return the actions
197 public List<OFAction> getActions() {
202 * @param actions the actions to set
204 public void setActions(List<OFAction> actions) {
205 this.actions = actions;
209 public void readFrom(ByteBuffer data) {
210 this.length = data.getShort();
211 this.tableId = data.get();
213 if (this.match == null)
214 this.match = new OFMatch();
215 this.match.readFrom(data);
216 this.durationSeconds = data.getInt();
217 this.durationNanoseconds = data.getInt();
218 this.priority = data.getShort();
219 this.idleTimeout = data.getShort();
220 this.hardTimeout = data.getShort();
221 data.getInt(); // pad
222 data.getShort(); // pad
223 this.cookie = data.getLong();
224 this.packetCount = data.getLong();
225 this.byteCount = data.getLong();
226 if (this.actionFactory == null)
227 throw new RuntimeException("OFActionFactory not set");
228 this.actions = this.actionFactory.parseActions(data, getLength() -
233 public void writeTo(ByteBuffer data) {
234 data.putShort(this.length);
235 data.put(this.tableId);
237 this.match.writeTo(data);
238 data.putInt(this.durationSeconds);
239 data.putInt(this.durationNanoseconds);
240 data.putShort(this.priority);
241 data.putShort(this.idleTimeout);
242 data.putShort(this.hardTimeout);
243 data.getInt(); // pad
244 data.getShort(); // pad
245 data.putLong(this.cookie);
246 data.putLong(this.packetCount);
247 data.putLong(this.byteCount);
248 if (actions != null) {
249 for (OFAction action : actions) {
250 action.writeTo(data);
256 public int hashCode() {
257 final int prime = 419;
259 result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
260 result = prime * result + (int) (cookie ^ (cookie >>> 32));
261 result = prime * result + durationNanoseconds;
262 result = prime * result + durationSeconds;
263 result = prime * result + hardTimeout;
264 result = prime * result + idleTimeout;
265 result = prime * result + length;
266 result = prime * result + ((match == null) ? 0 : match.hashCode());
267 result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
268 result = prime * result + priority;
269 result = prime * result + tableId;
274 public boolean equals(Object obj) {
281 if (!(obj instanceof OFFlowStatisticsReply)) {
284 OFFlowStatisticsReply other = (OFFlowStatisticsReply) obj;
285 if (byteCount != other.byteCount) {
288 if (cookie != other.cookie) {
291 if (durationNanoseconds != other.durationNanoseconds) {
294 if (durationSeconds != other.durationSeconds) {
297 if (hardTimeout != other.hardTimeout) {
300 if (idleTimeout != other.idleTimeout) {
303 if (length != other.length) {
307 if (other.match != null) {
310 } else if (!match.equals(other.match)) {
313 if (packetCount != other.packetCount) {
316 if (priority != other.priority) {
319 if (tableId != other.tableId) {