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