33570063c73850cf995606890ac0c3e9e97f67f5
[controller.git] / third-party / openflowj_netty / src / main / java / org / openflow / protocol / OFFlowRemoved.java
1 /**
2 *    Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
3 *    University
4
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
8 *
9 *         http://www.apache.org/licenses/LICENSE-2.0
10 *
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
15 *    under the License.
16 **/
17
18 package org.openflow.protocol;
19
20
21 import org.jboss.netty.buffer.ChannelBuffer;
22 import org.openflow.util.U16;
23
24 /**
25  * Represents an ofp_flow_removed message
26  * @author David Erickson (daviderickson@cs.stanford.edu)
27  *
28  */
29 public class OFFlowRemoved extends OFMessage {
30     public static int MINIMUM_LENGTH = 88;
31
32     public enum OFFlowRemovedReason {
33         OFPRR_IDLE_TIMEOUT,
34         OFPRR_HARD_TIMEOUT,
35         OFPRR_DELETE
36     }
37
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;
47     
48     public OFFlowRemoved() {
49         super();
50         this.type = OFType.FLOW_REMOVED;
51         this.length = U16.t(MINIMUM_LENGTH);
52     }
53
54     /**
55      * Get cookie
56      * @return
57      */
58     public long getCookie() {
59         return this.cookie;
60     }
61
62     /**
63      * Set cookie
64      * @param cookie
65      */
66     public void setCookie(long cookie) {
67         this.cookie = cookie;
68     }
69
70     /**
71      * Get idle_timeout
72      * @return
73      */
74     public short getIdleTimeout() {
75         return this.idleTimeout;
76     }
77
78     /**
79      * Set idle_timeout
80      * @param idleTimeout
81      */
82     public void setIdleTimeout(short idleTimeout) {
83         this.idleTimeout = idleTimeout;
84     }
85
86     /**
87      * Gets a copy of the OFMatch object for this FlowMod, changes to this
88      * object do not modify the FlowMod
89      * @return
90      */
91     public OFMatch getMatch() {
92         return this.match;
93     }
94
95     /**
96      * Set match
97      * @param match
98      */
99     public void setMatch(OFMatch match) {
100         this.match = match;
101     }
102
103     /**
104      * Get priority
105      * @return
106      */
107     public short getPriority() {
108         return this.priority;
109     }
110
111     /**
112      * Set priority
113      * @param priority
114      */
115     public void setPriority(short priority) {
116         this.priority = priority;
117     }
118
119     /**
120      * @return the reason
121      */
122     public OFFlowRemovedReason getReason() {
123         return reason;
124     }
125
126     /**
127      * @param reason the reason to set
128      */
129     public void setReason(OFFlowRemovedReason reason) {
130         this.reason = reason;
131     }
132
133     /**
134      * @return the durationSeconds
135      */
136     public int getDurationSeconds() {
137         return durationSeconds;
138     }
139
140     /**
141      * @param durationSeconds the durationSeconds to set
142      */
143     public void setDurationSeconds(int durationSeconds) {
144         this.durationSeconds = durationSeconds;
145     }
146
147     /**
148      * @return the durationNanoseconds
149      */
150     public int getDurationNanoseconds() {
151         return durationNanoseconds;
152     }
153
154     /**
155      * @param durationNanoseconds the durationNanoseconds to set
156      */
157     public void setDurationNanoseconds(int durationNanoseconds) {
158         this.durationNanoseconds = durationNanoseconds;
159     }
160
161     /**
162      * @return the packetCount
163      */
164     public long getPacketCount() {
165         return packetCount;
166     }
167
168     /**
169      * @param packetCount the packetCount to set
170      */
171     public void setPacketCount(long packetCount) {
172         this.packetCount = packetCount;
173     }
174
175     /**
176      * @return the byteCount
177      */
178     public long getByteCount() {
179         return byteCount;
180     }
181
182     /**
183      * @param byteCount the byteCount to set
184      */
185     public void setByteCount(long byteCount) {
186         this.byteCount = byteCount;
187     }
188
189     @Override
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;
200         }
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();
210     }
211
212     @Override
213     public void writeTo(ChannelBuffer data) {
214         super.writeTo(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);
227     }
228
229     @Override
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());
242         return result;
243     }
244
245     @Override
246     public boolean equals(Object obj) {
247         if (this == obj) {
248             return true;
249         }
250         if (!super.equals(obj)) {
251             return false;
252         }
253         if (!(obj instanceof OFFlowRemoved)) {
254             return false;
255         }
256         OFFlowRemoved other = (OFFlowRemoved) obj;
257         if (byteCount != other.byteCount) {
258             return false;
259         }
260         if (cookie != other.cookie) {
261             return false;
262         }
263         if (durationNanoseconds != other.durationNanoseconds) {
264             return false;
265         }
266         if (durationSeconds != other.durationSeconds) {
267             return false;
268         }
269         if (idleTimeout != other.idleTimeout) {
270             return false;
271         }
272         if (match == null) {
273             if (other.match != null) {
274                 return false;
275             }
276         } else if (!match.equals(other.match)) {
277             return false;
278         }
279         if (packetCount != other.packetCount) {
280             return false;
281         }
282         if (priority != other.priority) {
283             return false;
284         }
285         if (reason == null) {
286             if (other.reason != null) {
287                 return false;
288             }
289         } else if (!reason.equals(other.reason)) {
290             return false;
291         }
292         return true;
293     }
294 }