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