Initial opendaylight infrastructure commit!!
[controller.git] / third-party / openflowj / src / main / java / org / openflow / protocol / OFFlowRemoved.java
1 package org.openflow.protocol;
2
3 import java.nio.ByteBuffer;
4
5 import org.openflow.util.U16;
6
7 /**
8  * Represents an ofp_flow_removed message
9  * @author David Erickson (daviderickson@cs.stanford.edu)
10  *
11  */
12 public class OFFlowRemoved extends OFMessage {
13     public static int MINIMUM_LENGTH = 88;
14
15     public enum OFFlowRemovedReason {
16         OFPRR_IDLE_TIMEOUT,
17         OFPRR_HARD_TIMEOUT,
18         OFPRR_DELETE
19     }
20
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;
30     
31     public OFFlowRemoved() {
32         super();
33         this.type = OFType.FLOW_REMOVED;
34         this.length = U16.t(MINIMUM_LENGTH);
35     }
36
37     /**
38      * Get cookie
39      * @return
40      */
41     public long getCookie() {
42         return this.cookie;
43     }
44
45     /**
46      * Set cookie
47      * @param cookie
48      */
49     public void setCookie(long cookie) {
50         this.cookie = cookie;
51     }
52
53     /**
54      * Get idle_timeout
55      * @return
56      */
57     public short getIdleTimeout() {
58         return this.idleTimeout;
59     }
60
61     /**
62      * Set idle_timeout
63      * @param idleTimeout
64      */
65     public void setIdleTimeout(short idleTimeout) {
66         this.idleTimeout = idleTimeout;
67     }
68
69     /**
70      * Gets a copy of the OFMatch object for this FlowMod, changes to this
71      * object do not modify the FlowMod
72      * @return
73      */
74     public OFMatch getMatch() {
75         return this.match;
76     }
77
78     /**
79      * Set match
80      * @param match
81      */
82     public void setMatch(OFMatch match) {
83         this.match = match;
84     }
85
86     /**
87      * Get priority
88      * @return
89      */
90     public short getPriority() {
91         return this.priority;
92     }
93
94     /**
95      * Set priority
96      * @param priority
97      */
98     public void setPriority(short priority) {
99         this.priority = priority;
100     }
101
102     /**
103      * @return the reason
104      */
105     public OFFlowRemovedReason getReason() {
106         return reason;
107     }
108
109     /**
110      * @param reason the reason to set
111      */
112     public void setReason(OFFlowRemovedReason reason) {
113         this.reason = reason;
114     }
115
116     /**
117      * @return the durationSeconds
118      */
119     public int getDurationSeconds() {
120         return durationSeconds;
121     }
122
123     /**
124      * @param durationSeconds the durationSeconds to set
125      */
126     public void setDurationSeconds(int durationSeconds) {
127         this.durationSeconds = durationSeconds;
128     }
129
130     /**
131      * @return the durationNanoseconds
132      */
133     public int getDurationNanoseconds() {
134         return durationNanoseconds;
135     }
136
137     /**
138      * @param durationNanoseconds the durationNanoseconds to set
139      */
140     public void setDurationNanoseconds(int durationNanoseconds) {
141         this.durationNanoseconds = durationNanoseconds;
142     }
143
144     /**
145      * @return the packetCount
146      */
147     public long getPacketCount() {
148         return packetCount;
149     }
150
151     /**
152      * @param packetCount the packetCount to set
153      */
154     public void setPacketCount(long packetCount) {
155         this.packetCount = packetCount;
156     }
157
158     /**
159      * @return the byteCount
160      */
161     public long getByteCount() {
162         return byteCount;
163     }
164
165     /**
166      * @param byteCount the byteCount to set
167      */
168     public void setByteCount(long byteCount) {
169         this.byteCount = byteCount;
170     }
171
172     @Override
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())];
181         data.get(); // pad
182         this.durationSeconds = data.getInt();
183         this.durationNanoseconds = data.getInt();
184         this.idleTimeout = data.getShort();
185         data.get(); // pad
186         data.get(); // pad
187         this.packetCount = data.getLong();
188         this.byteCount = data.getLong();
189     }
190
191     @Override
192     public void writeTo(ByteBuffer data) {
193         super.writeTo(data);
194         this.match.writeTo(data);
195         data.putLong(cookie);
196         data.putShort(priority);
197         data.put((byte) this.reason.ordinal());
198         data.put((byte) 0);
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);
206     }
207
208     @Override
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());
221         return result;
222     }
223
224     @Override
225     public boolean equals(Object obj) {
226         if (this == obj) {
227             return true;
228         }
229         if (!super.equals(obj)) {
230             return false;
231         }
232         if (!(obj instanceof OFFlowRemoved)) {
233             return false;
234         }
235         OFFlowRemoved other = (OFFlowRemoved) obj;
236         if (byteCount != other.byteCount) {
237             return false;
238         }
239         if (cookie != other.cookie) {
240             return false;
241         }
242         if (durationNanoseconds != other.durationNanoseconds) {
243             return false;
244         }
245         if (durationSeconds != other.durationSeconds) {
246             return false;
247         }
248         if (idleTimeout != other.idleTimeout) {
249             return false;
250         }
251         if (match == null) {
252             if (other.match != null) {
253                 return false;
254             }
255         } else if (!match.equals(other.match)) {
256             return false;
257         }
258         if (packetCount != other.packetCount) {
259             return false;
260         }
261         if (priority != other.priority) {
262             return false;
263         }
264         if (reason == null) {
265             if (other.reason != null) {
266                 return false;
267             }
268         } else if (!reason.equals(other.reason)) {
269             return false;
270         }
271         return true;
272     }
273 }