tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame^] | 1 | // Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University |
| 2 | // Copyright (c) 2011, 2012 Open Networking Foundation |
| 3 | // Copyright (c) 2012, 2013 Big Switch Networks, Inc. |
| 4 | // This library was generated by the LoxiGen Compiler. |
| 5 | // See the file LICENSE.txt which should have been included in the source distribution |
| 6 | |
| 7 | // Automatically generated by LOXI from template of_class.java |
| 8 | // Do not modify |
| 9 | |
| 10 | package org.projectfloodlight.openflow.protocol.ver13; |
| 11 | |
| 12 | import org.projectfloodlight.openflow.protocol.*; |
| 13 | import org.projectfloodlight.openflow.protocol.action.*; |
| 14 | import org.projectfloodlight.openflow.protocol.actionid.*; |
| 15 | import org.projectfloodlight.openflow.protocol.bsntlv.*; |
| 16 | import org.projectfloodlight.openflow.protocol.errormsg.*; |
| 17 | import org.projectfloodlight.openflow.protocol.meterband.*; |
| 18 | import org.projectfloodlight.openflow.protocol.instruction.*; |
| 19 | import org.projectfloodlight.openflow.protocol.instructionid.*; |
| 20 | import org.projectfloodlight.openflow.protocol.match.*; |
| 21 | import org.projectfloodlight.openflow.protocol.oxm.*; |
| 22 | import org.projectfloodlight.openflow.protocol.queueprop.*; |
| 23 | import org.projectfloodlight.openflow.types.*; |
| 24 | import org.projectfloodlight.openflow.util.*; |
| 25 | import org.projectfloodlight.openflow.exceptions.*; |
| 26 | import org.slf4j.Logger; |
| 27 | import org.slf4j.LoggerFactory; |
| 28 | import java.util.List; |
| 29 | import com.google.common.collect.ImmutableList; |
| 30 | import java.util.Set; |
| 31 | import org.jboss.netty.buffer.ChannelBuffer; |
| 32 | import com.google.common.hash.PrimitiveSink; |
| 33 | import com.google.common.hash.Funnel; |
| 34 | import java.util.Arrays; |
| 35 | |
| 36 | class OFPacketOutVer13 implements OFPacketOut { |
| 37 | private static final Logger logger = LoggerFactory.getLogger(OFPacketOutVer13.class); |
| 38 | // version: 1.3 |
| 39 | final static byte WIRE_VERSION = 4; |
| 40 | final static int MINIMUM_LENGTH = 24; |
| 41 | |
| 42 | private final static long DEFAULT_XID = 0x0L; |
| 43 | private final static OFBufferId DEFAULT_BUFFER_ID = OFBufferId.NO_BUFFER; |
| 44 | private final static OFPort DEFAULT_IN_PORT = OFPort.ANY; |
| 45 | private final static List<OFAction> DEFAULT_ACTIONS = ImmutableList.<OFAction>of(); |
| 46 | private final static byte[] DEFAULT_DATA = new byte[0]; |
| 47 | |
| 48 | // OF message fields |
| 49 | private final long xid; |
| 50 | private final OFBufferId bufferId; |
| 51 | private final OFPort inPort; |
| 52 | private final List<OFAction> actions; |
| 53 | private final byte[] data; |
| 54 | // |
| 55 | // Immutable default instance |
| 56 | final static OFPacketOutVer13 DEFAULT = new OFPacketOutVer13( |
| 57 | DEFAULT_XID, DEFAULT_BUFFER_ID, DEFAULT_IN_PORT, DEFAULT_ACTIONS, DEFAULT_DATA |
| 58 | ); |
| 59 | |
| 60 | // package private constructor - used by readers, builders, and factory |
| 61 | OFPacketOutVer13(long xid, OFBufferId bufferId, OFPort inPort, List<OFAction> actions, byte[] data) { |
| 62 | this.xid = xid; |
| 63 | this.bufferId = bufferId; |
| 64 | this.inPort = inPort; |
| 65 | this.actions = actions; |
| 66 | this.data = data; |
| 67 | } |
| 68 | |
| 69 | // Accessors for OF message fields |
| 70 | @Override |
| 71 | public OFVersion getVersion() { |
| 72 | return OFVersion.OF_13; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public OFType getType() { |
| 77 | return OFType.PACKET_OUT; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public long getXid() { |
| 82 | return xid; |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public OFBufferId getBufferId() { |
| 87 | return bufferId; |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public OFPort getInPort() { |
| 92 | return inPort; |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public List<OFAction> getActions() { |
| 97 | return actions; |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public byte[] getData() { |
| 102 | return data; |
| 103 | } |
| 104 | |
| 105 | |
| 106 | |
| 107 | public OFPacketOut.Builder createBuilder() { |
| 108 | return new BuilderWithParent(this); |
| 109 | } |
| 110 | |
| 111 | static class BuilderWithParent implements OFPacketOut.Builder { |
| 112 | final OFPacketOutVer13 parentMessage; |
| 113 | |
| 114 | // OF message fields |
| 115 | private boolean xidSet; |
| 116 | private long xid; |
| 117 | private boolean bufferIdSet; |
| 118 | private OFBufferId bufferId; |
| 119 | private boolean inPortSet; |
| 120 | private OFPort inPort; |
| 121 | private boolean actionsSet; |
| 122 | private List<OFAction> actions; |
| 123 | private boolean dataSet; |
| 124 | private byte[] data; |
| 125 | |
| 126 | BuilderWithParent(OFPacketOutVer13 parentMessage) { |
| 127 | this.parentMessage = parentMessage; |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public OFVersion getVersion() { |
| 132 | return OFVersion.OF_13; |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public OFType getType() { |
| 137 | return OFType.PACKET_OUT; |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public long getXid() { |
| 142 | return xid; |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public OFPacketOut.Builder setXid(long xid) { |
| 147 | this.xid = xid; |
| 148 | this.xidSet = true; |
| 149 | return this; |
| 150 | } |
| 151 | @Override |
| 152 | public OFBufferId getBufferId() { |
| 153 | return bufferId; |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public OFPacketOut.Builder setBufferId(OFBufferId bufferId) { |
| 158 | this.bufferId = bufferId; |
| 159 | this.bufferIdSet = true; |
| 160 | return this; |
| 161 | } |
| 162 | @Override |
| 163 | public OFPort getInPort() { |
| 164 | return inPort; |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public OFPacketOut.Builder setInPort(OFPort inPort) { |
| 169 | this.inPort = inPort; |
| 170 | this.inPortSet = true; |
| 171 | return this; |
| 172 | } |
| 173 | @Override |
| 174 | public List<OFAction> getActions() { |
| 175 | return actions; |
| 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public OFPacketOut.Builder setActions(List<OFAction> actions) { |
| 180 | this.actions = actions; |
| 181 | this.actionsSet = true; |
| 182 | return this; |
| 183 | } |
| 184 | @Override |
| 185 | public byte[] getData() { |
| 186 | return data; |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public OFPacketOut.Builder setData(byte[] data) { |
| 191 | this.data = data; |
| 192 | this.dataSet = true; |
| 193 | return this; |
| 194 | } |
| 195 | |
| 196 | |
| 197 | @Override |
| 198 | public OFPacketOut build() { |
| 199 | long xid = this.xidSet ? this.xid : parentMessage.xid; |
| 200 | OFBufferId bufferId = this.bufferIdSet ? this.bufferId : parentMessage.bufferId; |
| 201 | if(bufferId == null) |
| 202 | throw new NullPointerException("Property bufferId must not be null"); |
| 203 | OFPort inPort = this.inPortSet ? this.inPort : parentMessage.inPort; |
| 204 | if(inPort == null) |
| 205 | throw new NullPointerException("Property inPort must not be null"); |
| 206 | List<OFAction> actions = this.actionsSet ? this.actions : parentMessage.actions; |
| 207 | if(actions == null) |
| 208 | throw new NullPointerException("Property actions must not be null"); |
| 209 | byte[] data = this.dataSet ? this.data : parentMessage.data; |
| 210 | if(data == null) |
| 211 | throw new NullPointerException("Property data must not be null"); |
| 212 | |
| 213 | // |
| 214 | return new OFPacketOutVer13( |
| 215 | xid, |
| 216 | bufferId, |
| 217 | inPort, |
| 218 | actions, |
| 219 | data |
| 220 | ); |
| 221 | } |
| 222 | |
| 223 | } |
| 224 | |
| 225 | static class Builder implements OFPacketOut.Builder { |
| 226 | // OF message fields |
| 227 | private boolean xidSet; |
| 228 | private long xid; |
| 229 | private boolean bufferIdSet; |
| 230 | private OFBufferId bufferId; |
| 231 | private boolean inPortSet; |
| 232 | private OFPort inPort; |
| 233 | private boolean actionsSet; |
| 234 | private List<OFAction> actions; |
| 235 | private boolean dataSet; |
| 236 | private byte[] data; |
| 237 | |
| 238 | @Override |
| 239 | public OFVersion getVersion() { |
| 240 | return OFVersion.OF_13; |
| 241 | } |
| 242 | |
| 243 | @Override |
| 244 | public OFType getType() { |
| 245 | return OFType.PACKET_OUT; |
| 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public long getXid() { |
| 250 | return xid; |
| 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public OFPacketOut.Builder setXid(long xid) { |
| 255 | this.xid = xid; |
| 256 | this.xidSet = true; |
| 257 | return this; |
| 258 | } |
| 259 | @Override |
| 260 | public OFBufferId getBufferId() { |
| 261 | return bufferId; |
| 262 | } |
| 263 | |
| 264 | @Override |
| 265 | public OFPacketOut.Builder setBufferId(OFBufferId bufferId) { |
| 266 | this.bufferId = bufferId; |
| 267 | this.bufferIdSet = true; |
| 268 | return this; |
| 269 | } |
| 270 | @Override |
| 271 | public OFPort getInPort() { |
| 272 | return inPort; |
| 273 | } |
| 274 | |
| 275 | @Override |
| 276 | public OFPacketOut.Builder setInPort(OFPort inPort) { |
| 277 | this.inPort = inPort; |
| 278 | this.inPortSet = true; |
| 279 | return this; |
| 280 | } |
| 281 | @Override |
| 282 | public List<OFAction> getActions() { |
| 283 | return actions; |
| 284 | } |
| 285 | |
| 286 | @Override |
| 287 | public OFPacketOut.Builder setActions(List<OFAction> actions) { |
| 288 | this.actions = actions; |
| 289 | this.actionsSet = true; |
| 290 | return this; |
| 291 | } |
| 292 | @Override |
| 293 | public byte[] getData() { |
| 294 | return data; |
| 295 | } |
| 296 | |
| 297 | @Override |
| 298 | public OFPacketOut.Builder setData(byte[] data) { |
| 299 | this.data = data; |
| 300 | this.dataSet = true; |
| 301 | return this; |
| 302 | } |
| 303 | // |
| 304 | @Override |
| 305 | public OFPacketOut build() { |
| 306 | long xid = this.xidSet ? this.xid : DEFAULT_XID; |
| 307 | OFBufferId bufferId = this.bufferIdSet ? this.bufferId : DEFAULT_BUFFER_ID; |
| 308 | if(bufferId == null) |
| 309 | throw new NullPointerException("Property bufferId must not be null"); |
| 310 | OFPort inPort = this.inPortSet ? this.inPort : DEFAULT_IN_PORT; |
| 311 | if(inPort == null) |
| 312 | throw new NullPointerException("Property inPort must not be null"); |
| 313 | List<OFAction> actions = this.actionsSet ? this.actions : DEFAULT_ACTIONS; |
| 314 | if(actions == null) |
| 315 | throw new NullPointerException("Property actions must not be null"); |
| 316 | byte[] data = this.dataSet ? this.data : DEFAULT_DATA; |
| 317 | if(data == null) |
| 318 | throw new NullPointerException("Property data must not be null"); |
| 319 | |
| 320 | |
| 321 | return new OFPacketOutVer13( |
| 322 | xid, |
| 323 | bufferId, |
| 324 | inPort, |
| 325 | actions, |
| 326 | data |
| 327 | ); |
| 328 | } |
| 329 | |
| 330 | } |
| 331 | |
| 332 | |
| 333 | final static Reader READER = new Reader(); |
| 334 | static class Reader implements OFMessageReader<OFPacketOut> { |
| 335 | @Override |
| 336 | public OFPacketOut readFrom(ChannelBuffer bb) throws OFParseError { |
| 337 | int start = bb.readerIndex(); |
| 338 | // fixed value property version == 4 |
| 339 | byte version = bb.readByte(); |
| 340 | if(version != (byte) 0x4) |
| 341 | throw new OFParseError("Wrong version: Expected=OFVersion.OF_13(4), got="+version); |
| 342 | // fixed value property type == 13 |
| 343 | byte type = bb.readByte(); |
| 344 | if(type != (byte) 0xd) |
| 345 | throw new OFParseError("Wrong type: Expected=OFType.PACKET_OUT(13), got="+type); |
| 346 | int length = U16.f(bb.readShort()); |
| 347 | if(length < MINIMUM_LENGTH) |
| 348 | throw new OFParseError("Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length); |
| 349 | if(bb.readableBytes() + (bb.readerIndex() - start) < length) { |
| 350 | // Buffer does not have all data yet |
| 351 | bb.readerIndex(start); |
| 352 | return null; |
| 353 | } |
| 354 | if(logger.isTraceEnabled()) |
| 355 | logger.trace("readFrom - length={}", length); |
| 356 | long xid = U32.f(bb.readInt()); |
| 357 | OFBufferId bufferId = OFBufferId.of(bb.readInt()); |
| 358 | OFPort inPort = OFPort.read4Bytes(bb); |
| 359 | int actionsLen = U16.f(bb.readShort()); |
| 360 | // pad: 6 bytes |
| 361 | bb.skipBytes(6); |
| 362 | List<OFAction> actions = ChannelUtils.readList(bb, actionsLen, OFActionVer13.READER); |
| 363 | byte[] data = ChannelUtils.readBytes(bb, length - (bb.readerIndex() - start)); |
| 364 | |
| 365 | OFPacketOutVer13 packetOutVer13 = new OFPacketOutVer13( |
| 366 | xid, |
| 367 | bufferId, |
| 368 | inPort, |
| 369 | actions, |
| 370 | data |
| 371 | ); |
| 372 | if(logger.isTraceEnabled()) |
| 373 | logger.trace("readFrom - read={}", packetOutVer13); |
| 374 | return packetOutVer13; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | public void putTo(PrimitiveSink sink) { |
| 379 | FUNNEL.funnel(this, sink); |
| 380 | } |
| 381 | |
| 382 | final static OFPacketOutVer13Funnel FUNNEL = new OFPacketOutVer13Funnel(); |
| 383 | static class OFPacketOutVer13Funnel implements Funnel<OFPacketOutVer13> { |
| 384 | private static final long serialVersionUID = 1L; |
| 385 | @Override |
| 386 | public void funnel(OFPacketOutVer13 message, PrimitiveSink sink) { |
| 387 | // fixed value property version = 4 |
| 388 | sink.putByte((byte) 0x4); |
| 389 | // fixed value property type = 13 |
| 390 | sink.putByte((byte) 0xd); |
| 391 | // FIXME: skip funnel of length |
| 392 | sink.putLong(message.xid); |
| 393 | message.bufferId.putTo(sink); |
| 394 | message.inPort.putTo(sink); |
| 395 | // FIXME: skip funnel of actionsLen |
| 396 | // skip pad (6 bytes) |
| 397 | FunnelUtils.putList(message.actions, sink); |
| 398 | sink.putBytes(message.data); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | |
| 403 | public void writeTo(ChannelBuffer bb) { |
| 404 | WRITER.write(bb, this); |
| 405 | } |
| 406 | |
| 407 | final static Writer WRITER = new Writer(); |
| 408 | static class Writer implements OFMessageWriter<OFPacketOutVer13> { |
| 409 | @Override |
| 410 | public void write(ChannelBuffer bb, OFPacketOutVer13 message) { |
| 411 | int startIndex = bb.writerIndex(); |
| 412 | // fixed value property version = 4 |
| 413 | bb.writeByte((byte) 0x4); |
| 414 | // fixed value property type = 13 |
| 415 | bb.writeByte((byte) 0xd); |
| 416 | // length is length of variable message, will be updated at the end |
| 417 | int lengthIndex = bb.writerIndex(); |
| 418 | bb.writeShort(U16.t(0)); |
| 419 | |
| 420 | bb.writeInt(U32.t(message.xid)); |
| 421 | bb.writeInt(message.bufferId.getInt()); |
| 422 | message.inPort.write4Bytes(bb); |
| 423 | // actionsLen is length indicator for actions, will be |
| 424 | // udpated when actions has been written |
| 425 | int actionsLenIndex = bb.writerIndex(); |
| 426 | bb.writeShort(0); |
| 427 | // pad: 6 bytes |
| 428 | bb.writeZero(6); |
| 429 | int actionsStartIndex = bb.writerIndex(); |
| 430 | ChannelUtils.writeList(bb, message.actions); |
| 431 | // update field length member actionsLen |
| 432 | int actionsLength = bb.writerIndex() - actionsStartIndex; |
| 433 | bb.setShort(actionsLenIndex, actionsLength); |
| 434 | bb.writeBytes(message.data); |
| 435 | |
| 436 | // update length field |
| 437 | int length = bb.writerIndex() - startIndex; |
| 438 | bb.setShort(lengthIndex, length); |
| 439 | |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | @Override |
| 444 | public String toString() { |
| 445 | StringBuilder b = new StringBuilder("OFPacketOutVer13("); |
| 446 | b.append("xid=").append(xid); |
| 447 | b.append(", "); |
| 448 | b.append("bufferId=").append(bufferId); |
| 449 | b.append(", "); |
| 450 | b.append("inPort=").append(inPort); |
| 451 | b.append(", "); |
| 452 | b.append("actions=").append(actions); |
| 453 | b.append(", "); |
| 454 | b.append("data=").append(Arrays.toString(data)); |
| 455 | b.append(")"); |
| 456 | return b.toString(); |
| 457 | } |
| 458 | |
| 459 | @Override |
| 460 | public boolean equals(Object obj) { |
| 461 | if (this == obj) |
| 462 | return true; |
| 463 | if (obj == null) |
| 464 | return false; |
| 465 | if (getClass() != obj.getClass()) |
| 466 | return false; |
| 467 | OFPacketOutVer13 other = (OFPacketOutVer13) obj; |
| 468 | |
| 469 | if( xid != other.xid) |
| 470 | return false; |
| 471 | if (bufferId == null) { |
| 472 | if (other.bufferId != null) |
| 473 | return false; |
| 474 | } else if (!bufferId.equals(other.bufferId)) |
| 475 | return false; |
| 476 | if (inPort == null) { |
| 477 | if (other.inPort != null) |
| 478 | return false; |
| 479 | } else if (!inPort.equals(other.inPort)) |
| 480 | return false; |
| 481 | if (actions == null) { |
| 482 | if (other.actions != null) |
| 483 | return false; |
| 484 | } else if (!actions.equals(other.actions)) |
| 485 | return false; |
| 486 | if (!Arrays.equals(data, other.data)) |
| 487 | return false; |
| 488 | return true; |
| 489 | } |
| 490 | |
| 491 | @Override |
| 492 | public int hashCode() { |
| 493 | final int prime = 31; |
| 494 | int result = 1; |
| 495 | |
| 496 | result = prime * (int) (xid ^ (xid >>> 32)); |
| 497 | result = prime * result + ((bufferId == null) ? 0 : bufferId.hashCode()); |
| 498 | result = prime * result + ((inPort == null) ? 0 : inPort.hashCode()); |
| 499 | result = prime * result + ((actions == null) ? 0 : actions.hashCode()); |
| 500 | result = prime * result + Arrays.hashCode(data); |
| 501 | return result; |
| 502 | } |
| 503 | |
| 504 | } |