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 OFPacketQueueVer13 implements OFPacketQueue { |
| 36 | private static final Logger logger = LoggerFactory.getLogger(OFPacketQueueVer13.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_QUEUE_ID = 0x0L; |
| 42 | private final static OFPort DEFAULT_PORT = OFPort.ANY; |
| 43 | private final static List<OFQueueProp> DEFAULT_PROPERTIES = ImmutableList.<OFQueueProp>of(); |
| 44 | |
| 45 | // OF message fields |
| 46 | private final long queueId; |
| 47 | private final OFPort port; |
| 48 | private final List<OFQueueProp> properties; |
| 49 | // |
| 50 | // Immutable default instance |
| 51 | final static OFPacketQueueVer13 DEFAULT = new OFPacketQueueVer13( |
| 52 | DEFAULT_QUEUE_ID, DEFAULT_PORT, DEFAULT_PROPERTIES |
| 53 | ); |
| 54 | |
| 55 | // package private constructor - used by readers, builders, and factory |
| 56 | OFPacketQueueVer13(long queueId, OFPort port, List<OFQueueProp> properties) { |
| 57 | this.queueId = queueId; |
| 58 | this.port = port; |
| 59 | this.properties = properties; |
| 60 | } |
| 61 | |
| 62 | // Accessors for OF message fields |
| 63 | @Override |
| 64 | public long getQueueId() { |
| 65 | return queueId; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public OFPort getPort() { |
| 70 | return port; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public List<OFQueueProp> getProperties() { |
| 75 | return properties; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public OFVersion getVersion() { |
| 80 | return OFVersion.OF_13; |
| 81 | } |
| 82 | |
| 83 | |
| 84 | |
| 85 | public OFPacketQueue.Builder createBuilder() { |
| 86 | return new BuilderWithParent(this); |
| 87 | } |
| 88 | |
| 89 | static class BuilderWithParent implements OFPacketQueue.Builder { |
| 90 | final OFPacketQueueVer13 parentMessage; |
| 91 | |
| 92 | // OF message fields |
| 93 | private boolean queueIdSet; |
| 94 | private long queueId; |
| 95 | private boolean portSet; |
| 96 | private OFPort port; |
| 97 | private boolean propertiesSet; |
| 98 | private List<OFQueueProp> properties; |
| 99 | |
| 100 | BuilderWithParent(OFPacketQueueVer13 parentMessage) { |
| 101 | this.parentMessage = parentMessage; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public long getQueueId() { |
| 106 | return queueId; |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public OFPacketQueue.Builder setQueueId(long queueId) { |
| 111 | this.queueId = queueId; |
| 112 | this.queueIdSet = true; |
| 113 | return this; |
| 114 | } |
| 115 | @Override |
| 116 | public OFPort getPort() { |
| 117 | return port; |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public OFPacketQueue.Builder setPort(OFPort port) { |
| 122 | this.port = port; |
| 123 | this.portSet = true; |
| 124 | return this; |
| 125 | } |
| 126 | @Override |
| 127 | public List<OFQueueProp> getProperties() { |
| 128 | return properties; |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public OFPacketQueue.Builder setProperties(List<OFQueueProp> properties) { |
| 133 | this.properties = properties; |
| 134 | this.propertiesSet = true; |
| 135 | return this; |
| 136 | } |
| 137 | @Override |
| 138 | public OFVersion getVersion() { |
| 139 | return OFVersion.OF_13; |
| 140 | } |
| 141 | |
| 142 | |
| 143 | |
| 144 | @Override |
| 145 | public OFPacketQueue build() { |
| 146 | long queueId = this.queueIdSet ? this.queueId : parentMessage.queueId; |
| 147 | OFPort port = this.portSet ? this.port : parentMessage.port; |
| 148 | if(port == null) |
| 149 | throw new NullPointerException("Property port must not be null"); |
| 150 | List<OFQueueProp> properties = this.propertiesSet ? this.properties : parentMessage.properties; |
| 151 | if(properties == null) |
| 152 | throw new NullPointerException("Property properties must not be null"); |
| 153 | |
| 154 | // |
| 155 | return new OFPacketQueueVer13( |
| 156 | queueId, |
| 157 | port, |
| 158 | properties |
| 159 | ); |
| 160 | } |
| 161 | |
| 162 | } |
| 163 | |
| 164 | static class Builder implements OFPacketQueue.Builder { |
| 165 | // OF message fields |
| 166 | private boolean queueIdSet; |
| 167 | private long queueId; |
| 168 | private boolean portSet; |
| 169 | private OFPort port; |
| 170 | private boolean propertiesSet; |
| 171 | private List<OFQueueProp> properties; |
| 172 | |
| 173 | @Override |
| 174 | public long getQueueId() { |
| 175 | return queueId; |
| 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public OFPacketQueue.Builder setQueueId(long queueId) { |
| 180 | this.queueId = queueId; |
| 181 | this.queueIdSet = true; |
| 182 | return this; |
| 183 | } |
| 184 | @Override |
| 185 | public OFPort getPort() { |
| 186 | return port; |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public OFPacketQueue.Builder setPort(OFPort port) { |
| 191 | this.port = port; |
| 192 | this.portSet = true; |
| 193 | return this; |
| 194 | } |
| 195 | @Override |
| 196 | public List<OFQueueProp> getProperties() { |
| 197 | return properties; |
| 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public OFPacketQueue.Builder setProperties(List<OFQueueProp> properties) { |
| 202 | this.properties = properties; |
| 203 | this.propertiesSet = true; |
| 204 | return this; |
| 205 | } |
| 206 | @Override |
| 207 | public OFVersion getVersion() { |
| 208 | return OFVersion.OF_13; |
| 209 | } |
| 210 | |
| 211 | // |
| 212 | @Override |
| 213 | public OFPacketQueue build() { |
| 214 | long queueId = this.queueIdSet ? this.queueId : DEFAULT_QUEUE_ID; |
| 215 | OFPort port = this.portSet ? this.port : DEFAULT_PORT; |
| 216 | if(port == null) |
| 217 | throw new NullPointerException("Property port must not be null"); |
| 218 | List<OFQueueProp> properties = this.propertiesSet ? this.properties : DEFAULT_PROPERTIES; |
| 219 | if(properties == null) |
| 220 | throw new NullPointerException("Property properties must not be null"); |
| 221 | |
| 222 | |
| 223 | return new OFPacketQueueVer13( |
| 224 | queueId, |
| 225 | port, |
| 226 | properties |
| 227 | ); |
| 228 | } |
| 229 | |
| 230 | } |
| 231 | |
| 232 | |
| 233 | final static Reader READER = new Reader(); |
| 234 | static class Reader implements OFMessageReader<OFPacketQueue> { |
| 235 | @Override |
| 236 | public OFPacketQueue readFrom(ChannelBuffer bb) throws OFParseError { |
| 237 | int start = bb.readerIndex(); |
| 238 | long queueId = U32.f(bb.readInt()); |
| 239 | OFPort port = OFPort.read4Bytes(bb); |
| 240 | int length = U16.f(bb.readShort()); |
| 241 | if(length < MINIMUM_LENGTH) |
| 242 | throw new OFParseError("Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length); |
| 243 | if(bb.readableBytes() + (bb.readerIndex() - start) < length) { |
| 244 | // Buffer does not have all data yet |
| 245 | bb.readerIndex(start); |
| 246 | return null; |
| 247 | } |
| 248 | if(logger.isTraceEnabled()) |
| 249 | logger.trace("readFrom - length={}", length); |
| 250 | // pad: 6 bytes |
| 251 | bb.skipBytes(6); |
| 252 | List<OFQueueProp> properties = ChannelUtils.readList(bb, length - (bb.readerIndex() - start), OFQueuePropVer13.READER); |
| 253 | |
| 254 | OFPacketQueueVer13 packetQueueVer13 = new OFPacketQueueVer13( |
| 255 | queueId, |
| 256 | port, |
| 257 | properties |
| 258 | ); |
| 259 | if(logger.isTraceEnabled()) |
| 260 | logger.trace("readFrom - read={}", packetQueueVer13); |
| 261 | return packetQueueVer13; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | public void putTo(PrimitiveSink sink) { |
| 266 | FUNNEL.funnel(this, sink); |
| 267 | } |
| 268 | |
| 269 | final static OFPacketQueueVer13Funnel FUNNEL = new OFPacketQueueVer13Funnel(); |
| 270 | static class OFPacketQueueVer13Funnel implements Funnel<OFPacketQueueVer13> { |
| 271 | private static final long serialVersionUID = 1L; |
| 272 | @Override |
| 273 | public void funnel(OFPacketQueueVer13 message, PrimitiveSink sink) { |
| 274 | sink.putLong(message.queueId); |
| 275 | message.port.putTo(sink); |
| 276 | // FIXME: skip funnel of length |
| 277 | // skip pad (6 bytes) |
| 278 | FunnelUtils.putList(message.properties, sink); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | |
| 283 | public void writeTo(ChannelBuffer bb) { |
| 284 | WRITER.write(bb, this); |
| 285 | } |
| 286 | |
| 287 | final static Writer WRITER = new Writer(); |
| 288 | static class Writer implements OFMessageWriter<OFPacketQueueVer13> { |
| 289 | @Override |
| 290 | public void write(ChannelBuffer bb, OFPacketQueueVer13 message) { |
| 291 | int startIndex = bb.writerIndex(); |
| 292 | bb.writeInt(U32.t(message.queueId)); |
| 293 | message.port.write4Bytes(bb); |
| 294 | // length is length of variable message, will be updated at the end |
| 295 | int lengthIndex = bb.writerIndex(); |
| 296 | bb.writeShort(U16.t(0)); |
| 297 | |
| 298 | // pad: 6 bytes |
| 299 | bb.writeZero(6); |
| 300 | ChannelUtils.writeList(bb, message.properties); |
| 301 | |
| 302 | // update length field |
| 303 | int length = bb.writerIndex() - startIndex; |
| 304 | bb.setShort(lengthIndex, length); |
| 305 | |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | @Override |
| 310 | public String toString() { |
| 311 | StringBuilder b = new StringBuilder("OFPacketQueueVer13("); |
| 312 | b.append("queueId=").append(queueId); |
| 313 | b.append(", "); |
| 314 | b.append("port=").append(port); |
| 315 | b.append(", "); |
| 316 | b.append("properties=").append(properties); |
| 317 | b.append(")"); |
| 318 | return b.toString(); |
| 319 | } |
| 320 | |
| 321 | @Override |
| 322 | public boolean equals(Object obj) { |
| 323 | if (this == obj) |
| 324 | return true; |
| 325 | if (obj == null) |
| 326 | return false; |
| 327 | if (getClass() != obj.getClass()) |
| 328 | return false; |
| 329 | OFPacketQueueVer13 other = (OFPacketQueueVer13) obj; |
| 330 | |
| 331 | if( queueId != other.queueId) |
| 332 | return false; |
| 333 | if (port == null) { |
| 334 | if (other.port != null) |
| 335 | return false; |
| 336 | } else if (!port.equals(other.port)) |
| 337 | return false; |
| 338 | if (properties == null) { |
| 339 | if (other.properties != null) |
| 340 | return false; |
| 341 | } else if (!properties.equals(other.properties)) |
| 342 | return false; |
| 343 | return true; |
| 344 | } |
| 345 | |
| 346 | @Override |
| 347 | public int hashCode() { |
| 348 | final int prime = 31; |
| 349 | int result = 1; |
| 350 | |
| 351 | result = prime * (int) (queueId ^ (queueId >>> 32)); |
| 352 | result = prime * result + ((port == null) ? 0 : port.hashCode()); |
| 353 | result = prime * result + ((properties == null) ? 0 : properties.hashCode()); |
| 354 | return result; |
| 355 | } |
| 356 | |
| 357 | } |