2 * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain
7 * a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations
18 package org.openflow.protocol.statistics;
20 import java.util.List;
22 import org.jboss.netty.buffer.ChannelBuffer;
23 import org.openflow.protocol.OFMatch;
24 import org.openflow.protocol.action.OFAction;
25 import org.openflow.protocol.factory.OFActionFactory;
26 import org.openflow.protocol.factory.OFActionFactoryAware;
27 import org.openflow.util.U16;
30 * Represents an ofp_flow_stats structure
31 * @author David Erickson (daviderickson@cs.stanford.edu)
33 public class OFFlowStatisticsReply implements OFStatistics, OFActionFactoryAware {
34 public static int MINIMUM_LENGTH = 88;
36 protected OFActionFactory actionFactory;
37 protected short length = (short) MINIMUM_LENGTH;
38 protected byte tableId;
39 protected OFMatch match;
40 protected int durationSeconds;
41 protected int durationNanoseconds;
42 protected short priority;
43 protected short idleTimeout;
44 protected short hardTimeout;
45 protected long cookie;
46 protected long packetCount;
47 protected long byteCount;
48 protected List<OFAction> actions;
53 public byte getTableId() {
58 * @param tableId the tableId to set
60 public void setTableId(byte tableId) {
61 this.tableId = tableId;
67 public OFMatch getMatch() {
72 * @param match the match to set
74 public void setMatch(OFMatch match) {
79 * @return the durationSeconds
81 public int getDurationSeconds() {
82 return durationSeconds;
86 * @param durationSeconds the durationSeconds to set
88 public void setDurationSeconds(int durationSeconds) {
89 this.durationSeconds = durationSeconds;
93 * @return the durationNanoseconds
95 public int getDurationNanoseconds() {
96 return durationNanoseconds;
100 * @param durationNanoseconds the durationNanoseconds to set
102 public void setDurationNanoseconds(int durationNanoseconds) {
103 this.durationNanoseconds = durationNanoseconds;
107 * @return the priority
109 public short getPriority() {
114 * @param priority the priority to set
116 public void setPriority(short priority) {
117 this.priority = priority;
121 * @return the idleTimeout
123 public short getIdleTimeout() {
128 * @param idleTimeout the idleTimeout to set
130 public void setIdleTimeout(short idleTimeout) {
131 this.idleTimeout = idleTimeout;
135 * @return the hardTimeout
137 public short getHardTimeout() {
142 * @param hardTimeout the hardTimeout to set
144 public void setHardTimeout(short hardTimeout) {
145 this.hardTimeout = hardTimeout;
151 public long getCookie() {
156 * @param cookie the cookie to set
158 public void setCookie(long cookie) {
159 this.cookie = cookie;
163 * @return the packetCount
165 public long getPacketCount() {
170 * @param packetCount the packetCount to set
172 public void setPacketCount(long packetCount) {
173 this.packetCount = packetCount;
177 * @return the byteCount
179 public long getByteCount() {
184 * @param byteCount the byteCount to set
186 public void setByteCount(long byteCount) {
187 this.byteCount = byteCount;
191 * @param length the length to set
193 public void setLength(short length) {
194 this.length = length;
198 public int getLength() {
199 return U16.f(length);
203 * @param actionFactory the actionFactory to set
206 public void setActionFactory(OFActionFactory actionFactory) {
207 this.actionFactory = actionFactory;
211 * @return the actions
213 public List<OFAction> getActions() {
218 * @param actions the actions to set
220 public void setActions(List<OFAction> actions) {
221 this.actions = actions;
225 public void readFrom(ChannelBuffer data) {
226 this.length = data.readShort();
227 this.tableId = data.readByte();
228 data.readByte(); // pad
229 if (this.match == null)
230 this.match = new OFMatch();
231 this.match.readFrom(data);
232 this.durationSeconds = data.readInt();
233 this.durationNanoseconds = data.readInt();
234 this.priority = data.readShort();
235 this.idleTimeout = data.readShort();
236 this.hardTimeout = data.readShort();
237 data.readInt(); // pad
238 data.readShort(); // pad
239 this.cookie = data.readLong();
240 this.packetCount = data.readLong();
241 this.byteCount = data.readLong();
242 if (this.actionFactory == null)
243 throw new RuntimeException("OFActionFactory not set");
244 this.actions = this.actionFactory.parseActions(data, getLength() -
249 public void writeTo(ChannelBuffer data) {
250 data.writeShort(this.length);
251 data.writeByte(this.tableId);
252 data.writeByte((byte) 0);
253 this.match.writeTo(data);
254 data.writeInt(this.durationSeconds);
255 data.writeInt(this.durationNanoseconds);
256 data.writeShort(this.priority);
257 data.writeShort(this.idleTimeout);
258 data.writeShort(this.hardTimeout);
259 data.writeInt(0); // pad
260 data.writeShort((short)0); // pad
261 data.writeLong(this.cookie);
262 data.writeLong(this.packetCount);
263 data.writeLong(this.byteCount);
264 if (actions != null) {
265 for (OFAction action : actions) {
266 action.writeTo(data);
272 public String toString() {
273 String str = "match=" + this.match;
274 str += " tableId=" + this.tableId;
275 str += " durationSeconds=" + this.durationSeconds;
276 str += " durationNanoseconds=" + this.durationNanoseconds;
277 str += " priority=" + this.priority;
278 str += " idleTimeout=" + this.idleTimeout;
279 str += " hardTimeout=" + this.hardTimeout;
280 str += " cookie=" + this.cookie;
281 str += " packetCount=" + this.packetCount;
282 str += " byteCount=" + this.byteCount;
283 str += " action=" + this.actions;
289 public int hashCode() {
290 final int prime = 419;
292 result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
293 result = prime * result + (int) (cookie ^ (cookie >>> 32));
294 result = prime * result + durationNanoseconds;
295 result = prime * result + durationSeconds;
296 result = prime * result + hardTimeout;
297 result = prime * result + idleTimeout;
298 result = prime * result + length;
299 result = prime * result + ((match == null) ? 0 : match.hashCode());
300 result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
301 result = prime * result + priority;
302 result = prime * result + tableId;
307 public boolean equals(Object obj) {
314 if (!(obj instanceof OFFlowStatisticsReply)) {
317 OFFlowStatisticsReply other = (OFFlowStatisticsReply) obj;
318 if (byteCount != other.byteCount) {
321 if (cookie != other.cookie) {
324 if (durationNanoseconds != other.durationNanoseconds) {
327 if (durationSeconds != other.durationSeconds) {
330 if (hardTimeout != other.hardTimeout) {
333 if (idleTimeout != other.idleTimeout) {
336 if (length != other.length) {
340 if (other.match != null) {
343 } else if (!match.equals(other.match)) {
346 if (packetCount != other.packetCount) {
349 if (priority != other.priority) {
352 if (tableId != other.tableId) {