1 package org.openflow.codec.protocol;
3 import org.openflow.codec.io.IDataBuffer;
4 import org.openflow.codec.util.U16;
7 * Represents an ofp_flow_removed message
9 * @author David Erickson (daviderickson@cs.stanford.edu)
13 public class OFPFlowRemoved extends OFPMessage {
14 public static final int MINIMUM_LENGTH = 56;
15 public static final int MATCH_DEFAULT_LENGTH = 8;
16 public static final int MINIMUM_LENGTH_WITHOUT_MATCH = MINIMUM_LENGTH - MATCH_DEFAULT_LENGTH;
19 * correspond to enum ofp_flow_removed_reason
24 public enum OFFlowRemovedReason {
25 OFPRR_IDLE_TIMEOUT, OFPRR_HARD_TIMEOUT, OFPRR_DELETE, OFPRR_GROUP_DELETE
28 protected long cookie;
29 protected short priority;
30 protected OFFlowRemovedReason reason;
31 protected byte tableId;
32 protected int durationSeconds;
33 protected int durationNanoseconds;
34 protected short idleTimeout;
35 protected short hardTimeout;
36 protected long packetCount;
37 protected long byteCount;
38 protected OFPMatch match;
40 public OFPFlowRemoved() {
42 this.type = OFPType.FLOW_REMOVED;
43 this.length = U16.t(MINIMUM_LENGTH);
51 public long getCookie() {
60 public void setCookie(long cookie) {
69 public short getIdleTimeout() {
70 return this.idleTimeout;
78 public void setIdleTimeout(short idleTimeout) {
79 this.idleTimeout = idleTimeout;
87 public short getHardTimeout() {
96 public void setHardTimeout(short hardTimeout) {
97 this.hardTimeout = hardTimeout;
101 * Gets a copy of the OFPMatch object for this FlowMod, changes to this
102 * object do not modify the FlowMod
106 public OFPMatch getMatch() {
115 public void setMatch(OFPMatch match) {
120 private void updateLength() {
121 int matchLength = (null == this.match) ? MATCH_DEFAULT_LENGTH : this.match.getLengthWithPadding();
122 this.length = (short) (OFPFlowRemoved.MINIMUM_LENGTH_WITHOUT_MATCH + matchLength);
130 public short getPriority() {
131 return this.priority;
139 public void setPriority(short priority) {
140 this.priority = priority;
146 public OFFlowRemovedReason getReason() {
154 public void setReason(OFFlowRemovedReason reason) {
155 this.reason = reason;
163 public byte getTableId() {
172 public void setTableId(byte tableId) {
173 this.tableId = tableId;
177 * @return the durationSeconds
179 public int getDurationSeconds() {
180 return durationSeconds;
184 * @param durationSeconds
185 * the durationSeconds to set
187 public void setDurationSeconds(int durationSeconds) {
188 this.durationSeconds = durationSeconds;
192 * @return the durationNanoseconds
194 public int getDurationNanoseconds() {
195 return durationNanoseconds;
199 * @param durationNanoseconds
200 * the durationNanoseconds to set
202 public void setDurationNanoseconds(int durationNanoseconds) {
203 this.durationNanoseconds = durationNanoseconds;
207 * @return the packetCount
209 public long getPacketCount() {
215 * the packetCount to set
217 public void setPacketCount(long packetCount) {
218 this.packetCount = packetCount;
222 * @return the byteCount
224 public long getByteCount() {
230 * the byteCount to set
232 public void setByteCount(long byteCount) {
233 this.byteCount = byteCount;
237 public void readFrom(IDataBuffer data) {
238 super.readFrom(data);
239 this.cookie = data.getLong();
240 this.priority = data.getShort();
241 this.reason = OFFlowRemovedReason.values()[(0xff & data.get())];
242 this.tableId = data.get();
243 this.durationSeconds = data.getInt();
244 this.durationNanoseconds = data.getInt();
245 this.idleTimeout = data.getShort();
246 this.hardTimeout = data.getShort();
247 this.packetCount = data.getLong();
248 this.byteCount = data.getLong();
249 if (this.match == null)
250 this.match = new OFPMatch();
251 this.match.readFrom(data);
255 public void writeTo(IDataBuffer data) {
257 data.putLong(cookie);
258 data.putShort(priority);
259 data.put((byte) this.reason.ordinal());
260 data.put((byte) tableId);
261 data.putInt(this.durationSeconds);
262 data.putInt(this.durationNanoseconds);
263 data.putShort(idleTimeout);
264 data.putShort(hardTimeout);
265 data.putLong(this.packetCount);
266 data.putLong(this.byteCount);
267 this.match.writeTo(data);
271 public int hashCode() {
272 final int prime = 271;
273 int result = super.hashCode();
274 result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
275 result = prime * result + (int) (cookie ^ (cookie >>> 32));
276 result = prime * result + durationNanoseconds;
277 result = prime * result + durationSeconds;
278 result = prime * result + idleTimeout;
279 result = prime * result + hardTimeout;
280 result = prime * result + ((match == null) ? 0 : match.hashCode());
281 result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
282 result = prime * result + priority;
283 result = prime * result + tableId;
284 result = prime * result + ((reason == null) ? 0 : reason.hashCode());
289 public boolean equals(Object obj) {
293 if (!super.equals(obj)) {
296 if (!(obj instanceof OFPFlowRemoved)) {
299 OFPFlowRemoved other = (OFPFlowRemoved) obj;
300 if (byteCount != other.byteCount) {
303 if (cookie != other.cookie) {
306 if (durationNanoseconds != other.durationNanoseconds) {
309 if (durationSeconds != other.durationSeconds) {
312 if (idleTimeout != other.idleTimeout) {
315 if (hardTimeout != other.hardTimeout) {
320 if (other.match != null) {
323 } else if (!match.equals(other.match)) {
326 if (packetCount != other.packetCount) {
329 if (priority != other.priority) {
332 if (tableId != other.tableId) {
335 if (reason == null) {
336 if (other.reason != null) {
339 } else if (!reason.equals(other.reason)) {