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