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.controller.protocol_plugin.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++) {
302 int action_len = this.length - MINIMUM_LENGTH - (match_len + pad_size);
304 this.actions = this.actionFactory.parseActions(data, action_len);
308 public int hashCode() {
309 final int prime = 31;
310 int result = super.hashCode();
311 result = prime * result + ((actions == null) ? 0 : actions.hashCode());
312 result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
313 result = prime * result + (int) (cookie ^ (cookie >>> 32));
314 result = prime * result + durationNanoseconds;
315 result = prime * result + durationSeconds;
316 result = prime * result + hardAge;
317 result = prime * result + hardTimeout;
318 result = prime * result + idleAge;
319 result = prime * result + idleTimeout;
320 result = prime * result + length;
321 result = prime * result + ((match == null) ? 0 : match.hashCode());
322 result = prime * result + match_len;
323 result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
324 result = prime * result + priority;
325 result = prime * result + tableId;
330 public String toString() {
331 return "V6StatsReply [length=" + length + ", tableId=" + tableId
332 + ", durationSeconds=" + durationSeconds
333 + ", durationNanoseconds=" + durationNanoseconds
334 + ", priority=" + priority + ", idleTimeout=" + idleTimeout
335 + ", hardTimeout=" + hardTimeout + ", match_len=" + match_len
336 + ", idleAge=" + idleAge + ", hardAge=" + hardAge + ", cookie="
337 + cookie + ", packetCount=" + packetCount + ", byteCount="
338 + byteCount + ", match=" + match + ", actions=" + actions + "]";
342 public boolean equals(Object obj) {
345 if (!super.equals(obj))
347 if (getClass() != obj.getClass())
349 V6StatsReply other = (V6StatsReply) obj;
350 if (actions == null) {
351 if (other.actions != null)
353 } else if (!actions.equals(other.actions))
355 if (byteCount != other.byteCount)
357 if (cookie != other.cookie)
359 if (durationNanoseconds != other.durationNanoseconds)
361 if (durationSeconds != other.durationSeconds)
363 if (hardAge != other.hardAge)
365 if (hardTimeout != other.hardTimeout)
367 if (idleAge != other.idleAge)
369 if (idleTimeout != other.idleTimeout)
371 if (length != other.length)
374 if (other.match != null)
376 } else if (!match.equals(other.match))
378 if (match_len != other.match_len)
380 if (packetCount != other.packetCount)
382 if (priority != other.priority)
384 if (tableId != other.tableId)