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