1 package org.openflow.protocol;
3 import java.nio.ByteBuffer;
5 import org.openflow.util.U16;
8 * Represents an ofp_flow_removed message
9 * @author David Erickson (daviderickson@cs.stanford.edu)
12 public class OFFlowRemoved extends OFMessage {
13 public static int MINIMUM_LENGTH = 88;
15 public enum OFFlowRemovedReason {
21 protected OFMatch match;
22 protected long cookie;
23 protected short priority;
24 protected OFFlowRemovedReason reason;
25 protected int durationSeconds;
26 protected int durationNanoseconds;
27 protected short idleTimeout;
28 protected long packetCount;
29 protected long byteCount;
31 public OFFlowRemoved() {
33 this.type = OFType.FLOW_REMOVED;
34 this.length = U16.t(MINIMUM_LENGTH);
41 public long getCookie() {
49 public void setCookie(long cookie) {
57 public short getIdleTimeout() {
58 return this.idleTimeout;
65 public void setIdleTimeout(short idleTimeout) {
66 this.idleTimeout = idleTimeout;
70 * Gets a copy of the OFMatch object for this FlowMod, changes to this
71 * object do not modify the FlowMod
74 public OFMatch getMatch() {
82 public void setMatch(OFMatch match) {
90 public short getPriority() {
98 public void setPriority(short priority) {
99 this.priority = priority;
105 public OFFlowRemovedReason getReason() {
110 * @param reason the reason to set
112 public void setReason(OFFlowRemovedReason reason) {
113 this.reason = reason;
117 * @return the durationSeconds
119 public int getDurationSeconds() {
120 return durationSeconds;
124 * @param durationSeconds the durationSeconds to set
126 public void setDurationSeconds(int durationSeconds) {
127 this.durationSeconds = durationSeconds;
131 * @return the durationNanoseconds
133 public int getDurationNanoseconds() {
134 return durationNanoseconds;
138 * @param durationNanoseconds the durationNanoseconds to set
140 public void setDurationNanoseconds(int durationNanoseconds) {
141 this.durationNanoseconds = durationNanoseconds;
145 * @return the packetCount
147 public long getPacketCount() {
152 * @param packetCount the packetCount to set
154 public void setPacketCount(long packetCount) {
155 this.packetCount = packetCount;
159 * @return the byteCount
161 public long getByteCount() {
166 * @param byteCount the byteCount to set
168 public void setByteCount(long byteCount) {
169 this.byteCount = byteCount;
173 public void readFrom(ByteBuffer data) {
174 super.readFrom(data);
175 if (this.match == null)
176 this.match = new OFMatch();
177 this.match.readFrom(data);
178 this.cookie = data.getLong();
179 this.priority = data.getShort();
180 this.reason = OFFlowRemovedReason.values()[(0xff & data.get())];
182 this.durationSeconds = data.getInt();
183 this.durationNanoseconds = data.getInt();
184 this.idleTimeout = data.getShort();
187 this.packetCount = data.getLong();
188 this.byteCount = data.getLong();
192 public void writeTo(ByteBuffer data) {
194 this.match.writeTo(data);
195 data.putLong(cookie);
196 data.putShort(priority);
197 data.put((byte) this.reason.ordinal());
199 data.putInt(this.durationSeconds);
200 data.putInt(this.durationNanoseconds);
201 data.putShort(idleTimeout);
202 data.put((byte) 0); // pad
203 data.put((byte) 0); // pad
204 data.putLong(this.packetCount);
205 data.putLong(this.byteCount);
209 public int hashCode() {
210 final int prime = 271;
211 int result = super.hashCode();
212 result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
213 result = prime * result + (int) (cookie ^ (cookie >>> 32));
214 result = prime * result + durationNanoseconds;
215 result = prime * result + durationSeconds;
216 result = prime * result + idleTimeout;
217 result = prime * result + ((match == null) ? 0 : match.hashCode());
218 result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
219 result = prime * result + priority;
220 result = prime * result + ((reason == null) ? 0 : reason.hashCode());
225 public boolean equals(Object obj) {
229 if (!super.equals(obj)) {
232 if (!(obj instanceof OFFlowRemoved)) {
235 OFFlowRemoved other = (OFFlowRemoved) obj;
236 if (byteCount != other.byteCount) {
239 if (cookie != other.cookie) {
242 if (durationNanoseconds != other.durationNanoseconds) {
245 if (durationSeconds != other.durationSeconds) {
248 if (idleTimeout != other.idleTimeout) {
252 if (other.match != null) {
255 } else if (!match.equals(other.match)) {
258 if (packetCount != other.packetCount) {
261 if (priority != other.priority) {
264 if (reason == null) {
265 if (other.reason != null) {
268 } else if (!reason.equals(other.reason)) {