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.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;
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.
30 public class V6StatsReply extends OFVendorStatistics {
31 private static final long serialVersionUID = 1L;
33 public static int MINIMUM_LENGTH = 48; //48 for nx_flow_stats
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;
54 public int getVendorId() {
59 * @param vendor the vendor to set
61 public void setVendorId(int vendor) {
68 public byte getTableId() {
73 * @param tableId the tableId to set
75 public void setTableId(byte tableId) {
76 this.tableId = tableId;
80 * @return the durationSeconds
82 public int getDurationSeconds() {
83 return durationSeconds;
87 * @param durationSeconds the durationSeconds to set
89 public void setDurationSeconds(int durationSeconds) {
90 this.durationSeconds = durationSeconds;
94 * @return the durationNanoseconds
96 public int getDurationNanoseconds() {
97 return durationNanoseconds;
101 * @param durationNanoseconds the durationNanoseconds to set
103 public void setDurationNanoseconds(int durationNanoseconds) {
104 this.durationNanoseconds = durationNanoseconds;
108 * @return the priority
110 public short getPriority() {
115 * @param priority the priority to set
117 public void setPriority(short priority) {
118 this.priority = priority;
122 * @return the idleTimeout
124 public short getIdleTimeout() {
129 * @param idleTimeout the idleTimeout to set
131 public void setIdleTimeout(short idleTimeout) {
132 this.idleTimeout = idleTimeout;
136 * @return the hardTimeout
138 public short getHardTimeout() {
143 * @param hardTimeout the hardTimeout to set
145 public void setHardTimeout(short hardTimeout) {
146 this.hardTimeout = hardTimeout;
150 * @param match_len the match_len to set
152 public void setMatchLen(short match_len) {
153 this.match_len = match_len;
157 * @return the match_len
159 public short getMatchLen() {
164 * @return the idleAge
166 public short getIdleAge() {
171 * @param idleAge the idleAge to set
173 public void setIdleAge(short idleAge) {
174 this.idleAge = idleAge;
178 * @return the hardAge
180 public short getHardAge() {
185 * @param hardAge the hardAge to set
187 public void setHardAge(short hardAge) {
188 this.hardAge = hardAge;
194 public long getCookie() {
199 * @param cookie the cookie to set
201 public void setCookie(long cookie) {
202 this.cookie = cookie;
206 * @return the packetCount
208 public long getPacketCount() {
213 * @param packetCount the packetCount to set
215 public void setPacketCount(long packetCount) {
216 this.packetCount = packetCount;
220 * @return the byteCount
222 public long getByteCount() {
227 * @param byteCount the byteCount to set
229 public void setByteCount(long byteCount) {
230 this.byteCount = byteCount;
234 * @param length the length to set
236 public void setLength(short length) {
237 this.length = length;
241 public int getLength() {
242 return U16.f(length);
248 public V6Match getMatch() {
253 * @return the actions
255 public List<OFAction> getActions() {
260 * @param actions the actions to set
262 public void setActions(List<OFAction> actions) {
263 this.actions = actions;
267 public void readFrom(ByteBuffer data) {
269 this.length = data.getShort();
270 if (length < MINIMUM_LENGTH)
271 return; //TBD - Spurious Packet?
272 this.tableId = data.get();
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??
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());
295 this.match.readFrom(mbuf);
296 if (this.actionFactory == null)
297 throw new RuntimeException("OFActionFactory not set");
299 * action list may be preceded by a padding of 0 to 7 bytes based upon this:
301 short pad_size = (short) (((match_len + 7) / 8) * 8 - match_len);
302 for (i = 0; i < pad_size; i++)
304 int action_len = this.length - MINIMUM_LENGTH - (match_len + pad_size);
306 this.actions = this.actionFactory.parseActions(data, action_len);
310 public void writeTo(ByteBuffer data) {
311 super.writeTo(data);//TBD. This Fn needs work. Should never get called though.
316 public int hashCode() {
317 return HashCodeBuilder.reflectionHashCode(this);
321 public String toString() {
322 return "V6StatsReply[" + ReflectionToStringBuilder.toString(this) + "]";
326 public boolean equals(Object obj) {
327 return EqualsBuilder.reflectionEquals(this, obj);