Five more Equals/HashCode/StringBuilder replacements
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / vendorextension / v6extension / V6StatsReply.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension;
11
12 import java.nio.ByteBuffer;
13 import java.util.List;
14
15 import org.apache.commons.lang3.builder.EqualsBuilder;
16 import org.apache.commons.lang3.builder.HashCodeBuilder;
17 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
18 import org.openflow.protocol.action.OFAction;
19 import org.openflow.protocol.statistics.OFVendorStatistics;
20 import org.openflow.util.U16;
21
22 /**
23  * This Class processes the OpenFlow Vendor Extension Reply message of a Stats
24  * Request. It parses the reply message and initializes fields of  V6StatsReply
25  * object. Multiple instances of this class objects are created and used by 
26  * OpenDaylight's Troubleshooting Application.
27  * 
28  */
29
30 public class V6StatsReply extends OFVendorStatistics {
31     private static final long serialVersionUID = 1L;
32
33     public static int MINIMUM_LENGTH = 48; //48 for nx_flow_stats
34
35     protected short length = (short) MINIMUM_LENGTH;
36     protected byte tableId;
37     protected int durationSeconds;
38     protected int durationNanoseconds;
39     protected short priority;
40     protected short idleTimeout;
41     protected short hardTimeout;
42     protected short match_len;
43     protected short idleAge;
44     protected short hardAge;
45     protected long cookie;
46     protected long packetCount;
47     protected long byteCount;
48     protected V6Match match;
49     protected List<OFAction> actions;
50
51     /**
52      * @return vendor id
53      */
54     public int getVendorId() {
55         return vendor;
56     }
57
58     /**
59      * @param vendor the vendor to set
60      */
61     public void setVendorId(int vendor) {
62         this.vendor = vendor;
63     }
64
65     /**
66      * @return the tableId
67      */
68     public byte getTableId() {
69         return tableId;
70     }
71
72     /**
73      * @param tableId the tableId to set
74      */
75     public void setTableId(byte tableId) {
76         this.tableId = tableId;
77     }
78
79     /**
80      * @return the durationSeconds
81      */
82     public int getDurationSeconds() {
83         return durationSeconds;
84     }
85
86     /**
87      * @param durationSeconds the durationSeconds to set
88      */
89     public void setDurationSeconds(int durationSeconds) {
90         this.durationSeconds = durationSeconds;
91     }
92
93     /**
94      * @return the durationNanoseconds
95      */
96     public int getDurationNanoseconds() {
97         return durationNanoseconds;
98     }
99
100     /**
101      * @param durationNanoseconds the durationNanoseconds to set
102      */
103     public void setDurationNanoseconds(int durationNanoseconds) {
104         this.durationNanoseconds = durationNanoseconds;
105     }
106
107     /**
108      * @return the priority
109      */
110     public short getPriority() {
111         return priority;
112     }
113
114     /**
115      * @param priority the priority to set
116      */
117     public void setPriority(short priority) {
118         this.priority = priority;
119     }
120
121     /**
122      * @return the idleTimeout
123      */
124     public short getIdleTimeout() {
125         return idleTimeout;
126     }
127
128     /**
129      * @param idleTimeout the idleTimeout to set
130      */
131     public void setIdleTimeout(short idleTimeout) {
132         this.idleTimeout = idleTimeout;
133     }
134
135     /**
136      * @return the hardTimeout
137      */
138     public short getHardTimeout() {
139         return hardTimeout;
140     }
141
142     /**
143      * @param hardTimeout the hardTimeout to set
144      */
145     public void setHardTimeout(short hardTimeout) {
146         this.hardTimeout = hardTimeout;
147     }
148
149     /**
150      * @param match_len the match_len to set
151      */
152     public void setMatchLen(short match_len) {
153         this.match_len = match_len;
154     }
155
156     /**
157      * @return the match_len
158      */
159     public short getMatchLen() {
160         return match_len;
161     }
162
163     /**
164      * @return the idleAge
165      */
166     public short getIdleAge() {
167         return idleAge;
168     }
169
170     /**
171      * @param idleAge the idleAge to set
172      */
173     public void setIdleAge(short idleAge) {
174         this.idleAge = idleAge;
175     }
176
177     /**
178      * @return the hardAge
179      */
180     public short getHardAge() {
181         return hardAge;
182     }
183
184     /**
185      * @param hardAge the hardAge to set
186      */
187     public void setHardAge(short hardAge) {
188         this.hardAge = hardAge;
189     }
190
191     /**
192      * @return the cookie
193      */
194     public long getCookie() {
195         return cookie;
196     }
197
198     /**
199      * @param cookie the cookie to set
200      */
201     public void setCookie(long cookie) {
202         this.cookie = cookie;
203     }
204
205     /**
206      * @return the packetCount
207      */
208     public long getPacketCount() {
209         return packetCount;
210     }
211
212     /**
213      * @param packetCount the packetCount to set
214      */
215     public void setPacketCount(long packetCount) {
216         this.packetCount = packetCount;
217     }
218
219     /**
220      * @return the byteCount
221      */
222     public long getByteCount() {
223         return byteCount;
224     }
225
226     /**
227      * @param byteCount the byteCount to set
228      */
229     public void setByteCount(long byteCount) {
230         this.byteCount = byteCount;
231     }
232
233     /**
234      * @param length the length to set
235      */
236     public void setLength(short length) {
237         this.length = length;
238     }
239
240     @Override
241     public int getLength() {
242         return U16.f(length);
243     }
244
245     /**
246      * @return the match
247      */
248     public V6Match getMatch() {
249         return match;
250     }
251
252     /**
253      * @return the actions
254      */
255     public List<OFAction> getActions() {
256         return actions;
257     }
258
259     /**
260      * @param actions the actions to set
261      */
262     public void setActions(List<OFAction> actions) {
263         this.actions = actions;
264     }
265
266     @Override
267     public void readFrom(ByteBuffer data) {
268         short i;
269         this.length = data.getShort();
270         if (length < MINIMUM_LENGTH)
271             return; //TBD - Spurious Packet?
272         this.tableId = data.get();
273         data.get(); // pad
274         this.durationSeconds = data.getInt();
275         this.durationNanoseconds = data.getInt();
276         this.priority = data.getShort();
277         this.idleTimeout = data.getShort();
278         this.hardTimeout = data.getShort();
279         this.match_len = data.getShort();
280         this.idleAge = data.getShort();
281         this.hardAge = data.getShort();
282         this.cookie = data.getLong();
283         this.packetCount = data.getLong();
284         this.byteCount = data.getLong();
285         if (this.length == MINIMUM_LENGTH) {
286             return; //TBD - can this happen??
287         }
288         if (this.match == null)
289             this.match = new V6Match();
290         ByteBuffer mbuf = ByteBuffer.allocate(match_len);
291         for (i = 0; i < match_len; i++) {
292             mbuf.put(data.get());
293         }
294         mbuf.rewind();
295         this.match.readFrom(mbuf);
296         if (this.actionFactory == null)
297             throw new RuntimeException("OFActionFactory not set");
298         /*
299          * action list may be preceded by a padding of 0 to 7 bytes based upon this:
300          */
301         short pad_size = (short) (((match_len + 7) / 8) * 8 - match_len);
302         for (i = 0; i < pad_size; i++)
303             data.get();
304         int action_len = this.length - MINIMUM_LENGTH - (match_len + pad_size);
305         if (action_len > 0)
306             this.actions = this.actionFactory.parseActions(data, action_len);
307     }
308
309     @Override
310     public void writeTo(ByteBuffer data) {
311         super.writeTo(data);//TBD. This Fn needs work. Should never get called though.
312
313     }
314
315     @Override
316     public int hashCode() {
317         final int prime = 31;
318         int result = super.hashCode();
319         result = prime * result + ((actions == null) ? 0 : actions.hashCode());
320         result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
321         result = prime * result + (int) (cookie ^ (cookie >>> 32));
322         result = prime * result + durationNanoseconds;
323         result = prime * result + durationSeconds;
324         result = prime * result + hardAge;
325         result = prime * result + hardTimeout;
326         result = prime * result + idleAge;
327         result = prime * result + idleTimeout;
328         result = prime * result + length;
329         result = prime * result + ((match == null) ? 0 : match.hashCode());
330         result = prime * result + match_len;
331         result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
332         result = prime * result + priority;
333         result = prime * result + tableId;
334         return result;
335     }
336
337     @Override
338     public String toString() {
339         return "V6StatsReply [length=" + length + ", tableId=" + tableId
340                 + ", durationSeconds=" + durationSeconds
341                 + ", durationNanoseconds=" + durationNanoseconds
342                 + ", priority=" + priority + ", idleTimeout=" + idleTimeout
343                 + ", hardTimeout=" + hardTimeout + ", match_len=" + match_len
344                 + ", idleAge=" + idleAge + ", hardAge=" + hardAge + ", cookie="
345                 + cookie + ", packetCount=" + packetCount + ", byteCount="
346                 + byteCount + ", match=" + match + ", actions=" + actions + "]";
347     }
348
349     @Override
350     public boolean equals(Object obj) {
351         if (this == obj)
352             return true;
353         if (!super.equals(obj))
354             return false;
355         if (getClass() != obj.getClass())
356             return false;
357         V6StatsReply other = (V6StatsReply) obj;
358         if (actions == null) {
359             if (other.actions != null)
360                 return false;
361         } else if (!actions.equals(other.actions))
362             return false;
363         if (byteCount != other.byteCount)
364             return false;
365         if (cookie != other.cookie)
366             return false;
367         if (durationNanoseconds != other.durationNanoseconds)
368             return false;
369         if (durationSeconds != other.durationSeconds)
370             return false;
371         if (hardAge != other.hardAge)
372             return false;
373         if (hardTimeout != other.hardTimeout)
374             return false;
375         if (idleAge != other.idleAge)
376             return false;
377         if (idleTimeout != other.idleTimeout)
378             return false;
379         if (length != other.length)
380             return false;
381         if (match == null) {
382             if (other.match != null)
383                 return false;
384         } else if (!match.equals(other.match))
385             return false;
386         if (match_len != other.match_len)
387             return false;
388         if (packetCount != other.packetCount)
389             return false;
390         if (priority != other.priority)
391             return false;
392         if (tableId != other.tableId)
393             return false;
394         return true;
395     }
396
397 }