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; |
| 19 | |
| 20 | |
| 21 | import org.jboss.netty.buffer.ChannelBuffer; |
| 22 | import org.openflow.util.U16; |
| 23 | |
| 24 | /** |
| 25 | * Represents an ofp_flow_removed message |
| 26 | * @author David Erickson (daviderickson@cs.stanford.edu) |
| 27 | * |
| 28 | */ |
| 29 | public class OFFlowRemoved extends OFMessage { |
| 30 | public static int MINIMUM_LENGTH = 88; |
| 31 | |
| 32 | public enum OFFlowRemovedReason { |
| 33 | OFPRR_IDLE_TIMEOUT, |
| 34 | OFPRR_HARD_TIMEOUT, |
| 35 | OFPRR_DELETE |
| 36 | } |
| 37 | |
| 38 | protected OFMatch match; |
| 39 | protected long cookie; |
| 40 | protected short priority; |
| 41 | protected OFFlowRemovedReason reason; |
| 42 | protected int durationSeconds; |
| 43 | protected int durationNanoseconds; |
| 44 | protected short idleTimeout; |
| 45 | protected long packetCount; |
| 46 | protected long byteCount; |
| 47 | |
| 48 | public OFFlowRemoved() { |
| 49 | super(); |
| 50 | this.type = OFType.FLOW_REMOVED; |
| 51 | this.length = U16.t(MINIMUM_LENGTH); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Get cookie |
| 56 | * @return |
| 57 | */ |
| 58 | public long getCookie() { |
| 59 | return this.cookie; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Set cookie |
| 64 | * @param cookie |
| 65 | */ |
| 66 | public void setCookie(long cookie) { |
| 67 | this.cookie = cookie; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Get idle_timeout |
| 72 | * @return |
| 73 | */ |
| 74 | public short getIdleTimeout() { |
| 75 | return this.idleTimeout; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Set idle_timeout |
| 80 | * @param idleTimeout |
| 81 | */ |
| 82 | public void setIdleTimeout(short idleTimeout) { |
| 83 | this.idleTimeout = idleTimeout; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Gets a copy of the OFMatch object for this FlowMod, changes to this |
| 88 | * object do not modify the FlowMod |
| 89 | * @return |
| 90 | */ |
| 91 | public OFMatch getMatch() { |
| 92 | return this.match; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Set match |
| 97 | * @param match |
| 98 | */ |
| 99 | public void setMatch(OFMatch match) { |
| 100 | this.match = match; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Get priority |
| 105 | * @return |
| 106 | */ |
| 107 | public short getPriority() { |
| 108 | return this.priority; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Set priority |
| 113 | * @param priority |
| 114 | */ |
| 115 | public void setPriority(short priority) { |
| 116 | this.priority = priority; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * @return the reason |
| 121 | */ |
| 122 | public OFFlowRemovedReason getReason() { |
| 123 | return reason; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * @param reason the reason to set |
| 128 | */ |
| 129 | public void setReason(OFFlowRemovedReason reason) { |
| 130 | this.reason = reason; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * @return the durationSeconds |
| 135 | */ |
| 136 | public int getDurationSeconds() { |
| 137 | return durationSeconds; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * @param durationSeconds the durationSeconds to set |
| 142 | */ |
| 143 | public void setDurationSeconds(int durationSeconds) { |
| 144 | this.durationSeconds = durationSeconds; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * @return the durationNanoseconds |
| 149 | */ |
| 150 | public int getDurationNanoseconds() { |
| 151 | return durationNanoseconds; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * @param durationNanoseconds the durationNanoseconds to set |
| 156 | */ |
| 157 | public void setDurationNanoseconds(int durationNanoseconds) { |
| 158 | this.durationNanoseconds = durationNanoseconds; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * @return the packetCount |
| 163 | */ |
| 164 | public long getPacketCount() { |
| 165 | return packetCount; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * @param packetCount the packetCount to set |
| 170 | */ |
| 171 | public void setPacketCount(long packetCount) { |
| 172 | this.packetCount = packetCount; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * @return the byteCount |
| 177 | */ |
| 178 | public long getByteCount() { |
| 179 | return byteCount; |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * @param byteCount the byteCount to set |
| 184 | */ |
| 185 | public void setByteCount(long byteCount) { |
| 186 | this.byteCount = byteCount; |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public void readFrom(ChannelBuffer data) { |
| 191 | super.readFrom(data); |
| 192 | if (this.match == null) |
| 193 | this.match = new OFMatch(); |
| 194 | this.match.readFrom(data); |
| 195 | this.cookie = data.readLong(); |
| 196 | this.priority = data.readShort(); |
| 197 | this.reason = OFFlowRemovedReason.values()[(0xff & data.readByte())]; |
| 198 | data.readByte(); // pad |
| 199 | this.durationSeconds = data.readInt(); |
| 200 | this.durationNanoseconds = data.readInt(); |
| 201 | this.idleTimeout = data.readShort(); |
| 202 | data.readByte(); // pad |
| 203 | data.readByte(); // pad |
| 204 | this.packetCount = data.readLong(); |
| 205 | this.byteCount = data.readLong(); |
| 206 | } |
| 207 | |
| 208 | @Override |
| 209 | public void writeTo(ChannelBuffer data) { |
| 210 | super.writeTo(data); |
| 211 | this.match.writeTo(data); |
| 212 | data.writeLong(cookie); |
| 213 | data.writeShort(priority); |
| 214 | data.writeByte((byte) this.reason.ordinal()); |
| 215 | data.writeByte((byte) 0); |
| 216 | data.writeInt(this.durationSeconds); |
| 217 | data.writeInt(this.durationNanoseconds); |
| 218 | data.writeShort(idleTimeout); |
| 219 | data.writeByte((byte) 0); // pad |
| 220 | data.writeByte((byte) 0); // pad |
| 221 | data.writeLong(this.packetCount); |
| 222 | data.writeLong(this.byteCount); |
| 223 | } |
| 224 | |
| 225 | @Override |
| 226 | public int hashCode() { |
| 227 | final int prime = 271; |
| 228 | int result = super.hashCode(); |
| 229 | result = prime * result + (int) (byteCount ^ (byteCount >>> 32)); |
| 230 | result = prime * result + (int) (cookie ^ (cookie >>> 32)); |
| 231 | result = prime * result + durationNanoseconds; |
| 232 | result = prime * result + durationSeconds; |
| 233 | result = prime * result + idleTimeout; |
| 234 | result = prime * result + ((match == null) ? 0 : match.hashCode()); |
| 235 | result = prime * result + (int) (packetCount ^ (packetCount >>> 32)); |
| 236 | result = prime * result + priority; |
| 237 | result = prime * result + ((reason == null) ? 0 : reason.hashCode()); |
| 238 | return result; |
| 239 | } |
| 240 | |
| 241 | @Override |
| 242 | public boolean equals(Object obj) { |
| 243 | if (this == obj) { |
| 244 | return true; |
| 245 | } |
| 246 | if (!super.equals(obj)) { |
| 247 | return false; |
| 248 | } |
| 249 | if (!(obj instanceof OFFlowRemoved)) { |
| 250 | return false; |
| 251 | } |
| 252 | OFFlowRemoved other = (OFFlowRemoved) obj; |
| 253 | if (byteCount != other.byteCount) { |
| 254 | return false; |
| 255 | } |
| 256 | if (cookie != other.cookie) { |
| 257 | return false; |
| 258 | } |
| 259 | if (durationNanoseconds != other.durationNanoseconds) { |
| 260 | return false; |
| 261 | } |
| 262 | if (durationSeconds != other.durationSeconds) { |
| 263 | return false; |
| 264 | } |
| 265 | if (idleTimeout != other.idleTimeout) { |
| 266 | return false; |
| 267 | } |
| 268 | if (match == null) { |
| 269 | if (other.match != null) { |
| 270 | return false; |
| 271 | } |
| 272 | } else if (!match.equals(other.match)) { |
| 273 | return false; |
| 274 | } |
| 275 | if (packetCount != other.packetCount) { |
| 276 | return false; |
| 277 | } |
| 278 | if (priority != other.priority) { |
| 279 | return false; |
| 280 | } |
| 281 | if (reason == null) { |
| 282 | if (other.reason != null) { |
| 283 | return false; |
| 284 | } |
| 285 | } else if (!reason.equals(other.reason)) { |
| 286 | return false; |
| 287 | } |
| 288 | return true; |
| 289 | } |
| 290 | } |