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 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 OFPortStatsRequestVer10 implements OFPortStatsRequest { |
| 35 | private static final Logger logger = LoggerFactory.getLogger(OFPortStatsRequestVer10.class); |
| 36 | // version: 1.0 |
| 37 | final static byte WIRE_VERSION = 1; |
| 38 | final static int LENGTH = 20; |
| 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 OFPortStatsRequestVer10 DEFAULT = new OFPortStatsRequestVer10( |
| 51 | DEFAULT_XID, DEFAULT_FLAGS, DEFAULT_PORT_NO |
| 52 | ); |
| 53 | |
| 54 | // package private constructor - used by readers, builders, and factory |
| 55 | OFPortStatsRequestVer10(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_10; |
| 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 OFPortStatsRequestVer10 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(OFPortStatsRequestVer10 parentMessage) { |
| 110 | this.parentMessage = parentMessage; |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public OFVersion getVersion() { |
| 115 | return OFVersion.OF_10; |
| 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 OFPortStatsRequestVer10( |
| 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_10; |
| 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 OFPortStatsRequestVer10( |
| 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 == 1 |
| 268 | byte version = bb.readByte(); |
| 269 | if(version != (byte) 0x1) |
| 270 | throw new OFParseError("Wrong version: Expected=OFVersion.OF_10(1), got="+version); |
| 271 | // fixed value property type == 16 |
| 272 | byte type = bb.readByte(); |
| 273 | if(type != (byte) 0x10) |
| 274 | throw new OFParseError("Wrong type: Expected=OFType.STATS_REQUEST(16), got="+type); |
| 275 | int length = U16.f(bb.readShort()); |
| 276 | if(length != 20) |
| 277 | throw new OFParseError("Wrong length: Expected=20(20), 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 = OFStatsRequestFlagsSerializerVer10.readFrom(bb); |
| 291 | OFPort portNo = OFPort.read2Bytes(bb); |
| 292 | // pad: 6 bytes |
| 293 | bb.skipBytes(6); |
| 294 | |
| 295 | OFPortStatsRequestVer10 portStatsRequestVer10 = new OFPortStatsRequestVer10( |
| 296 | xid, |
| 297 | flags, |
| 298 | portNo |
| 299 | ); |
| 300 | if(logger.isTraceEnabled()) |
| 301 | logger.trace("readFrom - read={}", portStatsRequestVer10); |
| 302 | return portStatsRequestVer10; |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | public void putTo(PrimitiveSink sink) { |
| 307 | FUNNEL.funnel(this, sink); |
| 308 | } |
| 309 | |
| 310 | final static OFPortStatsRequestVer10Funnel FUNNEL = new OFPortStatsRequestVer10Funnel(); |
| 311 | static class OFPortStatsRequestVer10Funnel implements Funnel<OFPortStatsRequestVer10> { |
| 312 | private static final long serialVersionUID = 1L; |
| 313 | @Override |
| 314 | public void funnel(OFPortStatsRequestVer10 message, PrimitiveSink sink) { |
| 315 | // fixed value property version = 1 |
| 316 | sink.putByte((byte) 0x1); |
| 317 | // fixed value property type = 16 |
| 318 | sink.putByte((byte) 0x10); |
| 319 | // fixed value property length = 20 |
| 320 | sink.putShort((short) 0x14); |
| 321 | sink.putLong(message.xid); |
| 322 | // fixed value property statsType = 4 |
| 323 | sink.putShort((short) 0x4); |
| 324 | OFStatsRequestFlagsSerializerVer10.putTo(message.flags, sink); |
| 325 | message.portNo.putTo(sink); |
| 326 | // skip pad (6 bytes) |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | |
| 331 | public void writeTo(ChannelBuffer bb) { |
| 332 | WRITER.write(bb, this); |
| 333 | } |
| 334 | |
| 335 | final static Writer WRITER = new Writer(); |
| 336 | static class Writer implements OFMessageWriter<OFPortStatsRequestVer10> { |
| 337 | @Override |
| 338 | public void write(ChannelBuffer bb, OFPortStatsRequestVer10 message) { |
| 339 | // fixed value property version = 1 |
| 340 | bb.writeByte((byte) 0x1); |
| 341 | // fixed value property type = 16 |
| 342 | bb.writeByte((byte) 0x10); |
| 343 | // fixed value property length = 20 |
| 344 | bb.writeShort((short) 0x14); |
| 345 | bb.writeInt(U32.t(message.xid)); |
| 346 | // fixed value property statsType = 4 |
| 347 | bb.writeShort((short) 0x4); |
| 348 | OFStatsRequestFlagsSerializerVer10.writeTo(bb, message.flags); |
| 349 | message.portNo.write2Bytes(bb); |
| 350 | // pad: 6 bytes |
| 351 | bb.writeZero(6); |
| 352 | |
| 353 | |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | @Override |
| 358 | public String toString() { |
| 359 | StringBuilder b = new StringBuilder("OFPortStatsRequestVer10("); |
| 360 | b.append("xid=").append(xid); |
| 361 | b.append(", "); |
| 362 | b.append("flags=").append(flags); |
| 363 | b.append(", "); |
| 364 | b.append("portNo=").append(portNo); |
| 365 | b.append(")"); |
| 366 | return b.toString(); |
| 367 | } |
| 368 | |
| 369 | @Override |
| 370 | public boolean equals(Object obj) { |
| 371 | if (this == obj) |
| 372 | return true; |
| 373 | if (obj == null) |
| 374 | return false; |
| 375 | if (getClass() != obj.getClass()) |
| 376 | return false; |
| 377 | OFPortStatsRequestVer10 other = (OFPortStatsRequestVer10) obj; |
| 378 | |
| 379 | if( xid != other.xid) |
| 380 | return false; |
| 381 | if (flags == null) { |
| 382 | if (other.flags != null) |
| 383 | return false; |
| 384 | } else if (!flags.equals(other.flags)) |
| 385 | return false; |
| 386 | if (portNo == null) { |
| 387 | if (other.portNo != null) |
| 388 | return false; |
| 389 | } else if (!portNo.equals(other.portNo)) |
| 390 | return false; |
| 391 | return true; |
| 392 | } |
| 393 | |
| 394 | @Override |
| 395 | public int hashCode() { |
| 396 | final int prime = 31; |
| 397 | int result = 1; |
| 398 | |
| 399 | result = prime * (int) (xid ^ (xid >>> 32)); |
| 400 | result = prime * result + ((flags == null) ? 0 : flags.hashCode()); |
| 401 | result = prime * result + ((portNo == null) ? 0 : portNo.hashCode()); |
| 402 | return result; |
| 403 | } |
| 404 | |
| 405 | } |