Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior |
| 3 | * University |
| 4 | * |
| 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 |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 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 |
| 15 | * under the License. |
| 16 | **/ |
| 17 | |
| 18 | package org.openflow.protocol.statistics; |
| 19 | |
| 20 | import java.util.List; |
| 21 | |
| 22 | import org.codehaus.jackson.annotate.JsonIgnore; |
| 23 | import org.jboss.netty.buffer.ChannelBuffer; |
| 24 | import org.openflow.protocol.OFMatch; |
| 25 | import org.openflow.protocol.action.OFAction; |
| 26 | import org.openflow.protocol.factory.OFActionFactory; |
| 27 | import org.openflow.protocol.factory.OFActionFactoryAware; |
| 28 | import org.openflow.util.U16; |
| 29 | |
| 30 | /** |
| 31 | * Represents an ofp_flow_stats structure |
| 32 | * @author David Erickson (daviderickson@cs.stanford.edu) |
| 33 | */ |
| 34 | public class OFFlowStatisticsReply implements OFStatistics, OFActionFactoryAware { |
| 35 | public static int MINIMUM_LENGTH = 88; |
| 36 | |
| 37 | protected OFActionFactory actionFactory; |
| 38 | protected short length = (short) MINIMUM_LENGTH; |
| 39 | protected byte tableId; |
| 40 | protected OFMatch match; |
| 41 | protected int durationSeconds; |
| 42 | protected int durationNanoseconds; |
| 43 | protected short priority; |
| 44 | protected short idleTimeout; |
| 45 | protected short hardTimeout; |
| 46 | protected long cookie; |
| 47 | protected long packetCount; |
| 48 | protected long byteCount; |
| 49 | protected List<OFAction> actions; |
| 50 | |
| 51 | /** |
| 52 | * @return the tableId |
| 53 | */ |
| 54 | public byte getTableId() { |
| 55 | return tableId; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @param tableId the tableId to set |
| 60 | */ |
| 61 | public void setTableId(byte tableId) { |
| 62 | this.tableId = tableId; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @return the match |
| 67 | */ |
| 68 | public OFMatch getMatch() { |
| 69 | return match; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @param match the match to set |
| 74 | */ |
| 75 | public void setMatch(OFMatch match) { |
| 76 | this.match = match; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @return the durationSeconds |
| 81 | */ |
| 82 | public int getDurationSeconds() { |
| 83 | return durationSeconds; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @param durationSeconds the durationSeconds to set |
| 88 | */ |
| 89 | public void setDurationSeconds(int durationSeconds) { |
| 90 | this.durationSeconds = durationSeconds; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @return the durationNanoseconds |
| 95 | */ |
| 96 | public int getDurationNanoseconds() { |
| 97 | return durationNanoseconds; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @param durationNanoseconds the durationNanoseconds to set |
| 102 | */ |
| 103 | public void setDurationNanoseconds(int durationNanoseconds) { |
| 104 | this.durationNanoseconds = durationNanoseconds; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * @return the priority |
| 109 | */ |
| 110 | public short getPriority() { |
| 111 | return priority; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * @param priority the priority to set |
| 116 | */ |
| 117 | public void setPriority(short priority) { |
| 118 | this.priority = priority; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * @return the idleTimeout |
| 123 | */ |
| 124 | public short getIdleTimeout() { |
| 125 | return idleTimeout; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * @param idleTimeout the idleTimeout to set |
| 130 | */ |
| 131 | public void setIdleTimeout(short idleTimeout) { |
| 132 | this.idleTimeout = idleTimeout; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * @return the hardTimeout |
| 137 | */ |
| 138 | public short getHardTimeout() { |
| 139 | return hardTimeout; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * @param hardTimeout the hardTimeout to set |
| 144 | */ |
| 145 | public void setHardTimeout(short hardTimeout) { |
| 146 | this.hardTimeout = hardTimeout; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * @return the cookie |
| 151 | */ |
| 152 | public long getCookie() { |
| 153 | return cookie; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * @param cookie the cookie to set |
| 158 | */ |
| 159 | public void setCookie(long cookie) { |
| 160 | this.cookie = cookie; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * @return the packetCount |
| 165 | */ |
| 166 | public long getPacketCount() { |
| 167 | return packetCount; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * @param packetCount the packetCount to set |
| 172 | */ |
| 173 | public void setPacketCount(long packetCount) { |
| 174 | this.packetCount = packetCount; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * @return the byteCount |
| 179 | */ |
| 180 | public long getByteCount() { |
| 181 | return byteCount; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * @param byteCount the byteCount to set |
| 186 | */ |
| 187 | public void setByteCount(long byteCount) { |
| 188 | this.byteCount = byteCount; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * @param length the length to set |
| 193 | */ |
| 194 | public void setLength(short length) { |
| 195 | this.length = length; |
| 196 | } |
| 197 | |
| 198 | @Override |
| 199 | @JsonIgnore |
| 200 | public int getLength() { |
| 201 | return U16.f(length); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * @param actionFactory the actionFactory to set |
| 206 | */ |
| 207 | @Override |
| 208 | public void setActionFactory(OFActionFactory actionFactory) { |
| 209 | this.actionFactory = actionFactory; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * @return the actions |
| 214 | */ |
| 215 | public List<OFAction> getActions() { |
| 216 | return actions; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * @param actions the actions to set |
| 221 | */ |
| 222 | public void setActions(List<OFAction> actions) { |
| 223 | this.actions = actions; |
| 224 | } |
| 225 | |
| 226 | @Override |
| 227 | public void readFrom(ChannelBuffer data) { |
| 228 | this.length = data.readShort(); |
| 229 | this.tableId = data.readByte(); |
| 230 | data.readByte(); // pad |
| 231 | if (this.match == null) |
| 232 | this.match = new OFMatch(); |
| 233 | this.match.readFrom(data); |
| 234 | this.durationSeconds = data.readInt(); |
| 235 | this.durationNanoseconds = data.readInt(); |
| 236 | this.priority = data.readShort(); |
| 237 | this.idleTimeout = data.readShort(); |
| 238 | this.hardTimeout = data.readShort(); |
| 239 | data.readInt(); // pad |
| 240 | data.readShort(); // pad |
| 241 | this.cookie = data.readLong(); |
| 242 | this.packetCount = data.readLong(); |
| 243 | this.byteCount = data.readLong(); |
| 244 | if (this.actionFactory == null) |
| 245 | throw new RuntimeException("OFActionFactory not set"); |
| 246 | this.actions = this.actionFactory.parseActions(data, getLength() - |
| 247 | MINIMUM_LENGTH); |
| 248 | } |
| 249 | |
| 250 | @Override |
| 251 | public void writeTo(ChannelBuffer data) { |
| 252 | data.writeShort(this.length); |
| 253 | data.writeByte(this.tableId); |
| 254 | data.writeByte((byte) 0); |
| 255 | this.match.writeTo(data); |
| 256 | data.writeInt(this.durationSeconds); |
| 257 | data.writeInt(this.durationNanoseconds); |
| 258 | data.writeShort(this.priority); |
| 259 | data.writeShort(this.idleTimeout); |
| 260 | data.writeShort(this.hardTimeout); |
| 261 | data.writeInt(0); // pad |
| 262 | data.writeShort((short)0); // pad |
| 263 | data.writeLong(this.cookie); |
| 264 | data.writeLong(this.packetCount); |
| 265 | data.writeLong(this.byteCount); |
| 266 | if (actions != null) { |
| 267 | for (OFAction action : actions) { |
| 268 | action.writeTo(data); |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | @Override |
| 274 | public String toString() { |
| 275 | String str = "match=" + this.match; |
| 276 | str += " tableId=" + this.tableId; |
| 277 | str += " durationSeconds=" + this.durationSeconds; |
| 278 | str += " durationNanoseconds=" + this.durationNanoseconds; |
| 279 | str += " priority=" + this.priority; |
| 280 | str += " idleTimeout=" + this.idleTimeout; |
| 281 | str += " hardTimeout=" + this.hardTimeout; |
| 282 | str += " cookie=" + this.cookie; |
| 283 | str += " packetCount=" + this.packetCount; |
| 284 | str += " byteCount=" + this.byteCount; |
| 285 | str += " action=" + this.actions; |
| 286 | |
| 287 | return str; |
| 288 | } |
| 289 | |
| 290 | @Override |
| 291 | public int hashCode() { |
| 292 | final int prime = 419; |
| 293 | int result = 1; |
| 294 | result = prime * result + (int) (byteCount ^ (byteCount >>> 32)); |
| 295 | result = prime * result + (int) (cookie ^ (cookie >>> 32)); |
| 296 | result = prime * result + durationNanoseconds; |
| 297 | result = prime * result + durationSeconds; |
| 298 | result = prime * result + hardTimeout; |
| 299 | result = prime * result + idleTimeout; |
| 300 | result = prime * result + length; |
| 301 | result = prime * result + ((match == null) ? 0 : match.hashCode()); |
| 302 | result = prime * result + (int) (packetCount ^ (packetCount >>> 32)); |
| 303 | result = prime * result + priority; |
| 304 | result = prime * result + tableId; |
| 305 | return result; |
| 306 | } |
| 307 | |
| 308 | @Override |
| 309 | public boolean equals(Object obj) { |
| 310 | if (this == obj) { |
| 311 | return true; |
| 312 | } |
| 313 | if (obj == null) { |
| 314 | return false; |
| 315 | } |
| 316 | if (!(obj instanceof OFFlowStatisticsReply)) { |
| 317 | return false; |
| 318 | } |
| 319 | OFFlowStatisticsReply other = (OFFlowStatisticsReply) obj; |
| 320 | if (byteCount != other.byteCount) { |
| 321 | return false; |
| 322 | } |
| 323 | if (cookie != other.cookie) { |
| 324 | return false; |
| 325 | } |
| 326 | if (durationNanoseconds != other.durationNanoseconds) { |
| 327 | return false; |
| 328 | } |
| 329 | if (durationSeconds != other.durationSeconds) { |
| 330 | return false; |
| 331 | } |
| 332 | if (hardTimeout != other.hardTimeout) { |
| 333 | return false; |
| 334 | } |
| 335 | if (idleTimeout != other.idleTimeout) { |
| 336 | return false; |
| 337 | } |
| 338 | if (length != other.length) { |
| 339 | return false; |
| 340 | } |
| 341 | if (match == null) { |
| 342 | if (other.match != null) { |
| 343 | return false; |
| 344 | } |
| 345 | } else if (!match.equals(other.match)) { |
| 346 | return false; |
| 347 | } |
| 348 | if (packetCount != other.packetCount) { |
| 349 | return false; |
| 350 | } |
| 351 | if (priority != other.priority) { |
| 352 | return false; |
| 353 | } |
| 354 | if (tableId != other.tableId) { |
| 355 | return false; |
| 356 | } |
| 357 | return true; |
| 358 | } |
| 359 | } |