Merge "Bug 2347: DOMConcurrentDataCommitCoordinator uses wrong phase name"
[controller.git] / third-party / openflowj / src / main / java / org / openflow / protocol / statistics / OFFlowStatisticsReply.java
1 package org.openflow.protocol.statistics;
2
3 import java.io.Serializable;
4 import java.nio.ByteBuffer;
5 import java.util.List;
6
7 import org.openflow.protocol.OFMatch;
8 import org.openflow.protocol.action.OFAction;
9 import org.openflow.protocol.factory.OFActionFactory;
10 import org.openflow.protocol.factory.OFActionFactoryAware;
11 import org.openflow.util.U16;
12
13 /**
14  * Represents an ofp_flow_stats structure
15  * @author David Erickson (daviderickson@cs.stanford.edu)
16  */
17 public class OFFlowStatisticsReply implements OFStatistics, OFActionFactoryAware, Serializable {
18     public static int MINIMUM_LENGTH = 88;
19
20     protected transient OFActionFactory actionFactory;
21     protected short length = (short) MINIMUM_LENGTH;
22     protected byte tableId;
23     protected OFMatch match;
24     protected int durationSeconds;
25     protected int durationNanoseconds;
26     protected short priority;
27     protected short idleTimeout;
28     protected short hardTimeout;
29     protected long cookie;
30     protected long packetCount;
31     protected long byteCount;
32     protected List<OFAction> actions;
33
34     /**
35      * @return the tableId
36      */
37     public byte getTableId() {
38         return tableId;
39     }
40
41     /**
42      * @param tableId the tableId to set
43      */
44     public void setTableId(byte tableId) {
45         this.tableId = tableId;
46     }
47
48     /**
49      * @return the match
50      */
51     public OFMatch getMatch() {
52         return match;
53     }
54
55     /**
56      * @param match the match to set
57      */
58     public void setMatch(OFMatch match) {
59         this.match = match;
60     }
61
62     /**
63      * @return the durationSeconds
64      */
65     public int getDurationSeconds() {
66         return durationSeconds;
67     }
68
69     /**
70      * @param durationSeconds the durationSeconds to set
71      */
72     public void setDurationSeconds(int durationSeconds) {
73         this.durationSeconds = durationSeconds;
74     }
75
76     /**
77      * @return the durationNanoseconds
78      */
79     public int getDurationNanoseconds() {
80         return durationNanoseconds;
81     }
82
83     /**
84      * @param durationNanoseconds the durationNanoseconds to set
85      */
86     public void setDurationNanoseconds(int durationNanoseconds) {
87         this.durationNanoseconds = durationNanoseconds;
88     }
89
90     /**
91      * @return the priority
92      */
93     public short getPriority() {
94         return priority;
95     }
96
97     /**
98      * @param priority the priority to set
99      */
100     public void setPriority(short priority) {
101         this.priority = priority;
102     }
103
104     /**
105      * @return the idleTimeout
106      */
107     public short getIdleTimeout() {
108         return idleTimeout;
109     }
110
111     /**
112      * @param idleTimeout the idleTimeout to set
113      */
114     public void setIdleTimeout(short idleTimeout) {
115         this.idleTimeout = idleTimeout;
116     }
117
118     /**
119      * @return the hardTimeout
120      */
121     public short getHardTimeout() {
122         return hardTimeout;
123     }
124
125     /**
126      * @param hardTimeout the hardTimeout to set
127      */
128     public void setHardTimeout(short hardTimeout) {
129         this.hardTimeout = hardTimeout;
130     }
131
132     /**
133      * @return the cookie
134      */
135     public long getCookie() {
136         return cookie;
137     }
138
139     /**
140      * @param cookie the cookie to set
141      */
142     public void setCookie(long cookie) {
143         this.cookie = cookie;
144     }
145
146     /**
147      * @return the packetCount
148      */
149     public long getPacketCount() {
150         return packetCount;
151     }
152
153     /**
154      * @param packetCount the packetCount to set
155      */
156     public void setPacketCount(long packetCount) {
157         this.packetCount = packetCount;
158     }
159
160     /**
161      * @return the byteCount
162      */
163     public long getByteCount() {
164         return byteCount;
165     }
166
167     /**
168      * @param byteCount the byteCount to set
169      */
170     public void setByteCount(long byteCount) {
171         this.byteCount = byteCount;
172     }
173
174     /**
175      * @param length the length to set
176      */
177     public void setLength(short length) {
178         this.length = length;
179     }
180
181     @Override
182     public int getLength() {
183         return U16.f(length);
184     }
185
186     /**
187      * @param actionFactory the actionFactory to set
188      */
189     @Override
190     public void setActionFactory(OFActionFactory actionFactory) {
191         this.actionFactory = actionFactory;
192     }
193
194     /**
195      * @return the actions
196      */
197     public List<OFAction> getActions() {
198         return actions;
199     }
200
201     /**
202      * @param actions the actions to set
203      */
204     public void setActions(List<OFAction> actions) {
205         this.actions = actions;
206     }
207
208     @Override
209     public void readFrom(ByteBuffer data) {
210         this.length = data.getShort();
211         this.tableId = data.get();
212         data.get(); // pad
213         if (this.match == null)
214             this.match = new OFMatch();
215         this.match.readFrom(data);
216         this.durationSeconds = data.getInt();
217         this.durationNanoseconds = data.getInt();
218         this.priority = data.getShort();
219         this.idleTimeout = data.getShort();
220         this.hardTimeout = data.getShort();
221         data.getInt(); // pad
222         data.getShort(); // pad
223         this.cookie = data.getLong();
224         this.packetCount = data.getLong();
225         this.byteCount = data.getLong();
226         if (this.actionFactory == null)
227             throw new RuntimeException("OFActionFactory not set");
228         this.actions = this.actionFactory.parseActions(data, getLength() -
229                 MINIMUM_LENGTH);
230     }
231
232     @Override
233     public void writeTo(ByteBuffer data) {
234         data.putShort(this.length);
235         data.put(this.tableId);
236         data.put((byte) 0);
237         this.match.writeTo(data);
238         data.putInt(this.durationSeconds);
239         data.putInt(this.durationNanoseconds);
240         data.putShort(this.priority);
241         data.putShort(this.idleTimeout);
242         data.putShort(this.hardTimeout);
243         data.getInt(); // pad
244         data.getShort(); // pad
245         data.putLong(this.cookie);
246         data.putLong(this.packetCount);
247         data.putLong(this.byteCount);
248         if (actions != null) {
249             for (OFAction action : actions) {
250                 action.writeTo(data);
251             }
252         }
253     }
254
255     @Override
256     public int hashCode() {
257         final int prime = 419;
258         int result = 1;
259         result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
260         result = prime * result + (int) (cookie ^ (cookie >>> 32));
261         result = prime * result + durationNanoseconds;
262         result = prime * result + durationSeconds;
263         result = prime * result + hardTimeout;
264         result = prime * result + idleTimeout;
265         result = prime * result + length;
266         result = prime * result + ((match == null) ? 0 : match.hashCode());
267         result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
268         result = prime * result + priority;
269         result = prime * result + tableId;
270         return result;
271     }
272
273     @Override
274     public boolean equals(Object obj) {
275         if (this == obj) {
276             return true;
277         }
278         if (obj == null) {
279             return false;
280         }
281         if (!(obj instanceof OFFlowStatisticsReply)) {
282             return false;
283         }
284         OFFlowStatisticsReply other = (OFFlowStatisticsReply) obj;
285         if (byteCount != other.byteCount) {
286             return false;
287         }
288         if (cookie != other.cookie) {
289             return false;
290         }
291         if (durationNanoseconds != other.durationNanoseconds) {
292             return false;
293         }
294         if (durationSeconds != other.durationSeconds) {
295             return false;
296         }
297         if (hardTimeout != other.hardTimeout) {
298             return false;
299         }
300         if (idleTimeout != other.idleTimeout) {
301             return false;
302         }
303         if (length != other.length) {
304             return false;
305         }
306         if (match == null) {
307             if (other.match != null) {
308                 return false;
309             }
310         } else if (!match.equals(other.match)) {
311             return false;
312         }
313         if (packetCount != other.packetCount) {
314             return false;
315         }
316         if (priority != other.priority) {
317             return false;
318         }
319         if (tableId != other.tableId) {
320             return false;
321         }
322         return true;
323     }
324 }