1 package org.openflow.codec.protocol.statistics;
3 import java.io.Serializable;
6 import org.openflow.codec.io.IDataBuffer;
7 import org.openflow.codec.protocol.OFPMatch;
8 import org.openflow.codec.protocol.factory.OFPInstructionFactory;
9 import org.openflow.codec.protocol.factory.OFPInstructionFactoryAware;
10 import org.openflow.codec.protocol.instruction.OFPInstruction;
11 import org.openflow.codec.util.U16;
14 * Represents an ofp_flow_stats structure
16 * @author David Erickson (daviderickson@cs.stanford.edu)
19 public class OFPFlowStatisticsReply implements OFPStatistics, OFPInstructionFactoryAware, Serializable {
20 public static final int MINIMUM_LENGTH = 56;
21 private static final int MIN_LENGTH_WITHOUT_MATCH = MINIMUM_LENGTH - 8;
23 protected transient OFPInstructionFactory instructionFactory;
24 protected short length = (short) MINIMUM_LENGTH;
25 protected byte tableId;
26 protected int durationSeconds;
27 protected int durationNanoseconds;
28 protected short priority;
29 protected short idleTimeout;
30 protected short hardTimeout;
31 protected short flags;
32 protected long cookie;
33 protected long packetCount;
34 protected long byteCount;
35 protected OFPMatch match;
36 private List<OFPInstruction> instructions;
41 public byte getTableId() {
49 public void setTableId(byte tableId) {
50 this.tableId = tableId;
56 public OFPMatch getMatch() {
64 public void setMatch(OFPMatch match) {
72 public List<OFPInstruction> getInstructions() {
80 public void setInstructions(List<OFPInstruction> instructions) {
81 this.instructions = instructions;
85 * @return the durationSeconds
87 public int getDurationSeconds() {
88 return durationSeconds;
92 * @param durationSeconds
93 * the durationSeconds to set
95 public void setDurationSeconds(int durationSeconds) {
96 this.durationSeconds = durationSeconds;
100 * @return the durationNanoseconds
102 public int getDurationNanoseconds() {
103 return durationNanoseconds;
107 * @param durationNanoseconds
108 * the durationNanoseconds to set
110 public void setDurationNanoseconds(int durationNanoseconds) {
111 this.durationNanoseconds = durationNanoseconds;
115 * @return the priority
117 public short getPriority() {
123 * the priority to set
125 public void setPriority(short priority) {
126 this.priority = priority;
130 * @return the idleTimeout
132 public short getIdleTimeout() {
138 * the idleTimeout to set
140 public void setIdleTimeout(short idleTimeout) {
141 this.idleTimeout = idleTimeout;
145 * @return the hardTimeout
147 public short getHardTimeout() {
153 * the hardTimeout to set
155 public void setHardTimeout(short hardTimeout) {
156 this.hardTimeout = hardTimeout;
163 public short getFlags() {
171 public void setFlags(short flags) {
178 public long getCookie() {
186 public void setCookie(long cookie) {
187 this.cookie = cookie;
191 * @return the packetCount
193 public long getPacketCount() {
199 * the packetCount to set
201 public void setPacketCount(long packetCount) {
202 this.packetCount = packetCount;
206 * @return the byteCount
208 public long getByteCount() {
214 * the byteCount to set
216 public void setByteCount(long byteCount) {
217 this.byteCount = byteCount;
224 public void setLength(short length) {
225 this.length = length;
229 public int getLength() {
230 return U16.f(length);
234 public void readFrom(IDataBuffer data) {
235 this.length = data.getShort();
236 this.tableId = data.get();
238 this.durationSeconds = data.getInt();
239 this.durationNanoseconds = data.getInt();
240 this.priority = data.getShort();
241 this.idleTimeout = data.getShort();
242 this.hardTimeout = data.getShort();
243 this.flags = data.getShort();
244 data.getInt(); // pad
245 this.cookie = data.getLong();
246 this.packetCount = data.getLong();
247 this.byteCount = data.getLong();
248 if (this.match == null)
249 this.match = new OFPMatch();
250 this.match.readFrom(data);
251 if (null == this.instructionFactory)
252 throw new RuntimeException("OFPInstructionFactory is not set");
253 int instrLength = getLength() - MIN_LENGTH_WITHOUT_MATCH - match.getLengthWithPadding();
254 this.instructions = this.instructionFactory.parseInstructions(data, instrLength);
258 public void writeTo(IDataBuffer data) {
259 data.putShort(this.length);
260 data.put(this.tableId);
261 data.put((byte) 0); // pad
262 data.putInt(this.durationSeconds);
263 data.putInt(this.durationNanoseconds);
264 data.putShort(this.priority);
265 data.putShort(this.idleTimeout);
266 data.putShort(this.hardTimeout);
267 data.putShort(this.flags);
268 data.putInt(0); // pad
269 data.putLong(this.cookie);
270 data.putLong(this.packetCount);
271 data.putLong(this.byteCount);
272 this.match.writeTo(data);
273 if (instructions != null) {
274 for (OFPInstruction instr : instructions) {
281 public int hashCode() {
282 final int prime = 419;
284 result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
285 result = prime * result + (int) (cookie ^ (cookie >>> 32));
286 result = prime * result + durationNanoseconds;
287 result = prime * result + durationSeconds;
288 result = prime * result + flags;
289 result = prime * result + hardTimeout;
290 result = prime * result + idleTimeout;
291 result = prime * result + length;
292 result = prime * result + ((match == null) ? 0 : match.hashCode());
293 result = prime * result + ((instructions == null) ? 0 : instructions.hashCode());
294 result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
295 result = prime * result + priority;
296 result = prime * result + tableId;
301 public boolean equals(Object obj) {
308 if (!(obj instanceof OFPFlowStatisticsReply)) {
311 OFPFlowStatisticsReply other = (OFPFlowStatisticsReply) obj;
312 if (byteCount != other.byteCount) {
315 if (cookie != other.cookie) {
318 if (durationNanoseconds != other.durationNanoseconds) {
321 if (durationSeconds != other.durationSeconds) {
324 if (flags != other.flags) {
327 if (hardTimeout != other.hardTimeout) {
330 if (idleTimeout != other.idleTimeout) {
333 if (length != other.length) {
337 if (other.match != null) {
340 } else if (!match.equals(other.match)) {
343 if (instructions == null) {
344 if (other.instructions != null) {
347 } else if (!instructions.equals(other.instructions)) {
350 if (packetCount != other.packetCount) {
353 if (priority != other.priority) {
356 if (tableId != other.tableId) {
363 public void setInstructionFactory(OFPInstructionFactory instructionFactory) {
364 this.instructionFactory = instructionFactory;