3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
10 package org.opendaylight.openflowplugin.openflow.vendorextension.v6extension;
12 import java.nio.ByteBuffer;
13 import java.util.List;
15 import org.openflow.protocol.action.OFAction;
16 import org.openflow.protocol.statistics.OFVendorStatistics;
17 import org.openflow.util.U16;
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.
27 public class V6StatsReply extends OFVendorStatistics {
28 private static final long serialVersionUID = 1L;
30 public static int MINIMUM_LENGTH = 48; //48 for nx_flow_stats
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;
51 public int getVendorId() {
56 * @param vendor the vendor to set
58 public void setVendorId(int vendor) {
65 public byte getTableId() {
70 * @param tableId the tableId to set
72 public void setTableId(byte tableId) {
73 this.tableId = tableId;
77 * @return the durationSeconds
79 public int getDurationSeconds() {
80 return durationSeconds;
84 * @param durationSeconds the durationSeconds to set
86 public void setDurationSeconds(int durationSeconds) {
87 this.durationSeconds = durationSeconds;
91 * @return the durationNanoseconds
93 public int getDurationNanoseconds() {
94 return durationNanoseconds;
98 * @param durationNanoseconds the durationNanoseconds to set
100 public void setDurationNanoseconds(int durationNanoseconds) {
101 this.durationNanoseconds = durationNanoseconds;
105 * @return the priority
107 public short getPriority() {
112 * @param priority the priority to set
114 public void setPriority(short priority) {
115 this.priority = priority;
119 * @return the idleTimeout
121 public short getIdleTimeout() {
126 * @param idleTimeout the idleTimeout to set
128 public void setIdleTimeout(short idleTimeout) {
129 this.idleTimeout = idleTimeout;
133 * @return the hardTimeout
135 public short getHardTimeout() {
140 * @param hardTimeout the hardTimeout to set
142 public void setHardTimeout(short hardTimeout) {
143 this.hardTimeout = hardTimeout;
147 * @param match_len the match_len to set
149 public void setMatchLen(short match_len) {
150 this.match_len = match_len;
154 * @return the match_len
156 public short getMatchLen() {
161 * @return the idleAge
163 public short getIdleAge() {
168 * @param idleAge the idleAge to set
170 public void setIdleAge(short idleAge) {
171 this.idleAge = idleAge;
175 * @return the hardAge
177 public short getHardAge() {
182 * @param hardAge the hardAge to set
184 public void setHardAge(short hardAge) {
185 this.hardAge = hardAge;
191 public long getCookie() {
196 * @param cookie the cookie to set
198 public void setCookie(long cookie) {
199 this.cookie = cookie;
203 * @return the packetCount
205 public long getPacketCount() {
210 * @param packetCount the packetCount to set
212 public void setPacketCount(long packetCount) {
213 this.packetCount = packetCount;
217 * @return the byteCount
219 public long getByteCount() {
224 * @param byteCount the byteCount to set
226 public void setByteCount(long byteCount) {
227 this.byteCount = byteCount;
231 * @param length the length to set
233 public void setLength(short length) {
234 this.length = length;
238 public int getLength() {
239 return U16.f(length);
245 public V6Match getMatch() {
250 * @return the actions
252 public List<OFAction> getActions() {
257 * @param actions the actions to set
259 public void setActions(List<OFAction> actions) {
260 this.actions = actions;
264 public void readFrom(ByteBuffer data) {
266 this.length = data.getShort();
267 if (length < MINIMUM_LENGTH)
268 return; //TBD - Spurious Packet?
269 this.tableId = data.get();
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??
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());
292 this.match.readFrom(mbuf);
293 if (this.actionFactory == null)
294 throw new RuntimeException("OFActionFactory not set");
296 * action list may be preceded by a padding of 0 to 7 bytes based upon this:
298 short pad_size = (short) (((match_len + 7) / 8) * 8 - match_len);
299 for (i = 0; i < pad_size; i++)
301 int action_len = this.length - MINIMUM_LENGTH - (match_len + pad_size);
303 this.actions = this.actionFactory.parseActions(data, action_len);
307 public void writeTo(ByteBuffer data) {
308 super.writeTo(data);//TBD. This Fn needs work. Should never get called though.
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;
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 + "]";
347 public boolean equals(Object obj) {
350 if (!super.equals(obj))
352 if (getClass() != obj.getClass())
354 V6StatsReply other = (V6StatsReply) obj;
355 if (actions == null) {
356 if (other.actions != null)
358 } else if (!actions.equals(other.actions))
360 if (byteCount != other.byteCount)
362 if (cookie != other.cookie)
364 if (durationNanoseconds != other.durationNanoseconds)
366 if (durationSeconds != other.durationSeconds)
368 if (hardAge != other.hardAge)
370 if (hardTimeout != other.hardTimeout)
372 if (idleAge != other.idleAge)
374 if (idleTimeout != other.idleTimeout)
376 if (length != other.length)
379 if (other.match != null)
381 } else if (!match.equals(other.match))
383 if (match_len != other.match_len)
385 if (packetCount != other.packetCount)
387 if (priority != other.priority)
389 if (tableId != other.tableId)