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