2 * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain
7 * a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations
18 package org.openflow.protocol;
21 import org.jboss.netty.buffer.ChannelBuffer;
22 import org.openflow.util.U16;
25 * Represents an ofp_flow_removed message
26 * @author David Erickson (daviderickson@cs.stanford.edu)
29 public class OFFlowRemoved extends OFMessage {
30 public static int MINIMUM_LENGTH = 88;
32 public enum OFFlowRemovedReason {
38 protected OFMatch match;
39 protected long cookie;
40 protected short priority;
41 protected OFFlowRemovedReason reason;
42 protected int durationSeconds;
43 protected int durationNanoseconds;
44 protected short idleTimeout;
45 protected long packetCount;
46 protected long byteCount;
48 public OFFlowRemoved() {
50 this.type = OFType.FLOW_REMOVED;
51 this.length = U16.t(MINIMUM_LENGTH);
58 public long getCookie() {
66 public void setCookie(long cookie) {
74 public short getIdleTimeout() {
75 return this.idleTimeout;
82 public void setIdleTimeout(short idleTimeout) {
83 this.idleTimeout = idleTimeout;
87 * Gets a copy of the OFMatch object for this FlowMod, changes to this
88 * object do not modify the FlowMod
91 public OFMatch getMatch() {
99 public void setMatch(OFMatch match) {
107 public short getPriority() {
108 return this.priority;
115 public void setPriority(short priority) {
116 this.priority = priority;
122 public OFFlowRemovedReason getReason() {
127 * @param reason the reason to set
129 public void setReason(OFFlowRemovedReason reason) {
130 this.reason = reason;
134 * @return the durationSeconds
136 public int getDurationSeconds() {
137 return durationSeconds;
141 * @param durationSeconds the durationSeconds to set
143 public void setDurationSeconds(int durationSeconds) {
144 this.durationSeconds = durationSeconds;
148 * @return the durationNanoseconds
150 public int getDurationNanoseconds() {
151 return durationNanoseconds;
155 * @param durationNanoseconds the durationNanoseconds to set
157 public void setDurationNanoseconds(int durationNanoseconds) {
158 this.durationNanoseconds = durationNanoseconds;
162 * @return the packetCount
164 public long getPacketCount() {
169 * @param packetCount the packetCount to set
171 public void setPacketCount(long packetCount) {
172 this.packetCount = packetCount;
176 * @return the byteCount
178 public long getByteCount() {
183 * @param byteCount the byteCount to set
185 public void setByteCount(long byteCount) {
186 this.byteCount = byteCount;
190 public void readFrom(ChannelBuffer data) {
191 super.readFrom(data);
192 if (this.match == null)
193 this.match = new OFMatch();
194 this.match.readFrom(data);
195 this.cookie = data.readLong();
196 this.priority = data.readShort();
197 int reasonIndex = (int)(0xff & data.readByte());
198 if (reasonIndex >= OFFlowRemovedReason.values().length) {
199 reasonIndex = OFFlowRemovedReason.values().length - 1;
201 this.reason = OFFlowRemovedReason.values()[reasonIndex];
202 data.readByte(); // pad
203 this.durationSeconds = data.readInt();
204 this.durationNanoseconds = data.readInt();
205 this.idleTimeout = data.readShort();
206 data.readByte(); // pad
207 data.readByte(); // pad
208 this.packetCount = data.readLong();
209 this.byteCount = data.readLong();
213 public void writeTo(ChannelBuffer data) {
215 this.match.writeTo(data);
216 data.writeLong(cookie);
217 data.writeShort(priority);
218 data.writeByte((byte) this.reason.ordinal());
219 data.writeByte((byte) 0);
220 data.writeInt(this.durationSeconds);
221 data.writeInt(this.durationNanoseconds);
222 data.writeShort(idleTimeout);
223 data.writeByte((byte) 0); // pad
224 data.writeByte((byte) 0); // pad
225 data.writeLong(this.packetCount);
226 data.writeLong(this.byteCount);
230 public int hashCode() {
231 final int prime = 271;
232 int result = super.hashCode();
233 result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
234 result = prime * result + (int) (cookie ^ (cookie >>> 32));
235 result = prime * result + durationNanoseconds;
236 result = prime * result + durationSeconds;
237 result = prime * result + idleTimeout;
238 result = prime * result + ((match == null) ? 0 : match.hashCode());
239 result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
240 result = prime * result + priority;
241 result = prime * result + ((reason == null) ? 0 : reason.hashCode());
246 public boolean equals(Object obj) {
250 if (!super.equals(obj)) {
253 if (!(obj instanceof OFFlowRemoved)) {
256 OFFlowRemoved other = (OFFlowRemoved) obj;
257 if (byteCount != other.byteCount) {
260 if (cookie != other.cookie) {
263 if (durationNanoseconds != other.durationNanoseconds) {
266 if (durationSeconds != other.durationSeconds) {
269 if (idleTimeout != other.idleTimeout) {
273 if (other.match != null) {
276 } else if (!match.equals(other.match)) {
279 if (packetCount != other.packetCount) {
282 if (priority != other.priority) {
285 if (reason == null) {
286 if (other.reason != null) {
289 } else if (!reason.equals(other.reason)) {