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.ver10; |
| 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.Set; |
| 29 | import org.jboss.netty.buffer.ChannelBuffer; |
| 30 | import com.google.common.hash.PrimitiveSink; |
| 31 | import com.google.common.hash.Funnel; |
| 32 | import java.util.Arrays; |
| 33 | |
| 34 | class OFBsnShellCommandVer10 implements OFBsnShellCommand { |
| 35 | private static final Logger logger = LoggerFactory.getLogger(OFBsnShellCommandVer10.class); |
| 36 | // version: 1.0 |
| 37 | final static byte WIRE_VERSION = 1; |
| 38 | final static int MINIMUM_LENGTH = 20; |
| 39 | |
| 40 | private final static long DEFAULT_XID = 0x0L; |
| 41 | private final static long DEFAULT_SERVICE = 0x0L; |
| 42 | private final static byte[] DEFAULT_DATA = new byte[0]; |
| 43 | |
| 44 | // OF message fields |
| 45 | private final long xid; |
| 46 | private final long service; |
| 47 | private final byte[] data; |
| 48 | // |
| 49 | // Immutable default instance |
| 50 | final static OFBsnShellCommandVer10 DEFAULT = new OFBsnShellCommandVer10( |
| 51 | DEFAULT_XID, DEFAULT_SERVICE, DEFAULT_DATA |
| 52 | ); |
| 53 | |
| 54 | // package private constructor - used by readers, builders, and factory |
| 55 | OFBsnShellCommandVer10(long xid, long service, byte[] data) { |
| 56 | this.xid = xid; |
| 57 | this.service = service; |
| 58 | this.data = data; |
| 59 | } |
| 60 | |
| 61 | // Accessors for OF message fields |
| 62 | @Override |
| 63 | public OFVersion getVersion() { |
| 64 | return OFVersion.OF_10; |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public OFType getType() { |
| 69 | return OFType.EXPERIMENTER; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public long getXid() { |
| 74 | return xid; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public long getExperimenter() { |
| 79 | return 0x5c16c7L; |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public long getSubtype() { |
| 84 | return 0x6L; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public long getService() { |
| 89 | return service; |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public byte[] getData() { |
| 94 | return data; |
| 95 | } |
| 96 | |
| 97 | |
| 98 | |
| 99 | public OFBsnShellCommand.Builder createBuilder() { |
| 100 | return new BuilderWithParent(this); |
| 101 | } |
| 102 | |
| 103 | static class BuilderWithParent implements OFBsnShellCommand.Builder { |
| 104 | final OFBsnShellCommandVer10 parentMessage; |
| 105 | |
| 106 | // OF message fields |
| 107 | private boolean xidSet; |
| 108 | private long xid; |
| 109 | private boolean serviceSet; |
| 110 | private long service; |
| 111 | private boolean dataSet; |
| 112 | private byte[] data; |
| 113 | |
| 114 | BuilderWithParent(OFBsnShellCommandVer10 parentMessage) { |
| 115 | this.parentMessage = parentMessage; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public OFVersion getVersion() { |
| 120 | return OFVersion.OF_10; |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public OFType getType() { |
| 125 | return OFType.EXPERIMENTER; |
| 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public long getXid() { |
| 130 | return xid; |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public OFBsnShellCommand.Builder setXid(long xid) { |
| 135 | this.xid = xid; |
| 136 | this.xidSet = true; |
| 137 | return this; |
| 138 | } |
| 139 | @Override |
| 140 | public long getExperimenter() { |
| 141 | return 0x5c16c7L; |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public long getSubtype() { |
| 146 | return 0x6L; |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public long getService() { |
| 151 | return service; |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public OFBsnShellCommand.Builder setService(long service) { |
| 156 | this.service = service; |
| 157 | this.serviceSet = true; |
| 158 | return this; |
| 159 | } |
| 160 | @Override |
| 161 | public byte[] getData() { |
| 162 | return data; |
| 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public OFBsnShellCommand.Builder setData(byte[] data) { |
| 167 | this.data = data; |
| 168 | this.dataSet = true; |
| 169 | return this; |
| 170 | } |
| 171 | |
| 172 | |
| 173 | @Override |
| 174 | public OFBsnShellCommand build() { |
| 175 | long xid = this.xidSet ? this.xid : parentMessage.xid; |
| 176 | long service = this.serviceSet ? this.service : parentMessage.service; |
| 177 | byte[] data = this.dataSet ? this.data : parentMessage.data; |
| 178 | if(data == null) |
| 179 | throw new NullPointerException("Property data must not be null"); |
| 180 | |
| 181 | // |
| 182 | return new OFBsnShellCommandVer10( |
| 183 | xid, |
| 184 | service, |
| 185 | data |
| 186 | ); |
| 187 | } |
| 188 | |
| 189 | } |
| 190 | |
| 191 | static class Builder implements OFBsnShellCommand.Builder { |
| 192 | // OF message fields |
| 193 | private boolean xidSet; |
| 194 | private long xid; |
| 195 | private boolean serviceSet; |
| 196 | private long service; |
| 197 | private boolean dataSet; |
| 198 | private byte[] data; |
| 199 | |
| 200 | @Override |
| 201 | public OFVersion getVersion() { |
| 202 | return OFVersion.OF_10; |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public OFType getType() { |
| 207 | return OFType.EXPERIMENTER; |
| 208 | } |
| 209 | |
| 210 | @Override |
| 211 | public long getXid() { |
| 212 | return xid; |
| 213 | } |
| 214 | |
| 215 | @Override |
| 216 | public OFBsnShellCommand.Builder setXid(long xid) { |
| 217 | this.xid = xid; |
| 218 | this.xidSet = true; |
| 219 | return this; |
| 220 | } |
| 221 | @Override |
| 222 | public long getExperimenter() { |
| 223 | return 0x5c16c7L; |
| 224 | } |
| 225 | |
| 226 | @Override |
| 227 | public long getSubtype() { |
| 228 | return 0x6L; |
| 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public long getService() { |
| 233 | return service; |
| 234 | } |
| 235 | |
| 236 | @Override |
| 237 | public OFBsnShellCommand.Builder setService(long service) { |
| 238 | this.service = service; |
| 239 | this.serviceSet = true; |
| 240 | return this; |
| 241 | } |
| 242 | @Override |
| 243 | public byte[] getData() { |
| 244 | return data; |
| 245 | } |
| 246 | |
| 247 | @Override |
| 248 | public OFBsnShellCommand.Builder setData(byte[] data) { |
| 249 | this.data = data; |
| 250 | this.dataSet = true; |
| 251 | return this; |
| 252 | } |
| 253 | // |
| 254 | @Override |
| 255 | public OFBsnShellCommand build() { |
| 256 | long xid = this.xidSet ? this.xid : DEFAULT_XID; |
| 257 | long service = this.serviceSet ? this.service : DEFAULT_SERVICE; |
| 258 | byte[] data = this.dataSet ? this.data : DEFAULT_DATA; |
| 259 | if(data == null) |
| 260 | throw new NullPointerException("Property data must not be null"); |
| 261 | |
| 262 | |
| 263 | return new OFBsnShellCommandVer10( |
| 264 | xid, |
| 265 | service, |
| 266 | data |
| 267 | ); |
| 268 | } |
| 269 | |
| 270 | } |
| 271 | |
| 272 | |
| 273 | final static Reader READER = new Reader(); |
| 274 | static class Reader implements OFMessageReader<OFBsnShellCommand> { |
| 275 | @Override |
| 276 | public OFBsnShellCommand readFrom(ChannelBuffer bb) throws OFParseError { |
| 277 | int start = bb.readerIndex(); |
| 278 | // fixed value property version == 1 |
| 279 | byte version = bb.readByte(); |
| 280 | if(version != (byte) 0x1) |
| 281 | throw new OFParseError("Wrong version: Expected=OFVersion.OF_10(1), got="+version); |
| 282 | // fixed value property type == 4 |
| 283 | byte type = bb.readByte(); |
| 284 | if(type != (byte) 0x4) |
| 285 | throw new OFParseError("Wrong type: Expected=OFType.EXPERIMENTER(4), got="+type); |
| 286 | int length = U16.f(bb.readShort()); |
| 287 | if(length < MINIMUM_LENGTH) |
| 288 | throw new OFParseError("Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length); |
| 289 | if(bb.readableBytes() + (bb.readerIndex() - start) < length) { |
| 290 | // Buffer does not have all data yet |
| 291 | bb.readerIndex(start); |
| 292 | return null; |
| 293 | } |
| 294 | if(logger.isTraceEnabled()) |
| 295 | logger.trace("readFrom - length={}", length); |
| 296 | long xid = U32.f(bb.readInt()); |
| 297 | // fixed value property experimenter == 0x5c16c7L |
| 298 | int experimenter = bb.readInt(); |
| 299 | if(experimenter != 0x5c16c7) |
| 300 | throw new OFParseError("Wrong experimenter: Expected=0x5c16c7L(0x5c16c7L), got="+experimenter); |
| 301 | // fixed value property subtype == 0x6L |
| 302 | int subtype = bb.readInt(); |
| 303 | if(subtype != 0x6) |
| 304 | throw new OFParseError("Wrong subtype: Expected=0x6L(0x6L), got="+subtype); |
| 305 | long service = U32.f(bb.readInt()); |
| 306 | byte[] data = ChannelUtils.readBytes(bb, length - (bb.readerIndex() - start)); |
| 307 | |
| 308 | OFBsnShellCommandVer10 bsnShellCommandVer10 = new OFBsnShellCommandVer10( |
| 309 | xid, |
| 310 | service, |
| 311 | data |
| 312 | ); |
| 313 | if(logger.isTraceEnabled()) |
| 314 | logger.trace("readFrom - read={}", bsnShellCommandVer10); |
| 315 | return bsnShellCommandVer10; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | public void putTo(PrimitiveSink sink) { |
| 320 | FUNNEL.funnel(this, sink); |
| 321 | } |
| 322 | |
| 323 | final static OFBsnShellCommandVer10Funnel FUNNEL = new OFBsnShellCommandVer10Funnel(); |
| 324 | static class OFBsnShellCommandVer10Funnel implements Funnel<OFBsnShellCommandVer10> { |
| 325 | private static final long serialVersionUID = 1L; |
| 326 | @Override |
| 327 | public void funnel(OFBsnShellCommandVer10 message, PrimitiveSink sink) { |
| 328 | // fixed value property version = 1 |
| 329 | sink.putByte((byte) 0x1); |
| 330 | // fixed value property type = 4 |
| 331 | sink.putByte((byte) 0x4); |
| 332 | // FIXME: skip funnel of length |
| 333 | sink.putLong(message.xid); |
| 334 | // fixed value property experimenter = 0x5c16c7L |
| 335 | sink.putInt(0x5c16c7); |
| 336 | // fixed value property subtype = 0x6L |
| 337 | sink.putInt(0x6); |
| 338 | sink.putLong(message.service); |
| 339 | sink.putBytes(message.data); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | |
| 344 | public void writeTo(ChannelBuffer bb) { |
| 345 | WRITER.write(bb, this); |
| 346 | } |
| 347 | |
| 348 | final static Writer WRITER = new Writer(); |
| 349 | static class Writer implements OFMessageWriter<OFBsnShellCommandVer10> { |
| 350 | @Override |
| 351 | public void write(ChannelBuffer bb, OFBsnShellCommandVer10 message) { |
| 352 | int startIndex = bb.writerIndex(); |
| 353 | // fixed value property version = 1 |
| 354 | bb.writeByte((byte) 0x1); |
| 355 | // fixed value property type = 4 |
| 356 | bb.writeByte((byte) 0x4); |
| 357 | // length is length of variable message, will be updated at the end |
| 358 | int lengthIndex = bb.writerIndex(); |
| 359 | bb.writeShort(U16.t(0)); |
| 360 | |
| 361 | bb.writeInt(U32.t(message.xid)); |
| 362 | // fixed value property experimenter = 0x5c16c7L |
| 363 | bb.writeInt(0x5c16c7); |
| 364 | // fixed value property subtype = 0x6L |
| 365 | bb.writeInt(0x6); |
| 366 | bb.writeInt(U32.t(message.service)); |
| 367 | bb.writeBytes(message.data); |
| 368 | |
| 369 | // update length field |
| 370 | int length = bb.writerIndex() - startIndex; |
| 371 | bb.setShort(lengthIndex, length); |
| 372 | |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | @Override |
| 377 | public String toString() { |
| 378 | StringBuilder b = new StringBuilder("OFBsnShellCommandVer10("); |
| 379 | b.append("xid=").append(xid); |
| 380 | b.append(", "); |
| 381 | b.append("service=").append(service); |
| 382 | b.append(", "); |
| 383 | b.append("data=").append(Arrays.toString(data)); |
| 384 | b.append(")"); |
| 385 | return b.toString(); |
| 386 | } |
| 387 | |
| 388 | @Override |
| 389 | public boolean equals(Object obj) { |
| 390 | if (this == obj) |
| 391 | return true; |
| 392 | if (obj == null) |
| 393 | return false; |
| 394 | if (getClass() != obj.getClass()) |
| 395 | return false; |
| 396 | OFBsnShellCommandVer10 other = (OFBsnShellCommandVer10) obj; |
| 397 | |
| 398 | if( xid != other.xid) |
| 399 | return false; |
| 400 | if( service != other.service) |
| 401 | return false; |
| 402 | if (!Arrays.equals(data, other.data)) |
| 403 | return false; |
| 404 | return true; |
| 405 | } |
| 406 | |
| 407 | @Override |
| 408 | public int hashCode() { |
| 409 | final int prime = 31; |
| 410 | int result = 1; |
| 411 | |
| 412 | result = prime * (int) (xid ^ (xid >>> 32)); |
| 413 | result = prime * (int) (service ^ (service >>> 32)); |
| 414 | result = prime * result + Arrays.hashCode(data); |
| 415 | return result; |
| 416 | } |
| 417 | |
| 418 | } |