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.ver12; |
| 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 java.util.Set; |
| 30 | import org.jboss.netty.buffer.ChannelBuffer; |
| 31 | import com.google.common.hash.PrimitiveSink; |
| 32 | import com.google.common.hash.Funnel; |
| 33 | |
| 34 | class OFHelloVer12 implements OFHello { |
| 35 | private static final Logger logger = LoggerFactory.getLogger(OFHelloVer12.class); |
| 36 | // version: 1.2 |
| 37 | final static byte WIRE_VERSION = 3; |
| 38 | final static int LENGTH = 8; |
| 39 | |
| 40 | private final static long DEFAULT_XID = 0x0L; |
| 41 | |
| 42 | // OF message fields |
| 43 | private final long xid; |
| 44 | // |
| 45 | // Immutable default instance |
| 46 | final static OFHelloVer12 DEFAULT = new OFHelloVer12( |
| 47 | DEFAULT_XID |
| 48 | ); |
| 49 | |
| 50 | // package private constructor - used by readers, builders, and factory |
| 51 | OFHelloVer12(long xid) { |
| 52 | this.xid = xid; |
| 53 | } |
| 54 | |
| 55 | // Accessors for OF message fields |
| 56 | @Override |
| 57 | public OFVersion getVersion() { |
| 58 | return OFVersion.OF_12; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public OFType getType() { |
| 63 | return OFType.HELLO; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public long getXid() { |
| 68 | return xid; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public List<OFHelloElem> getElements()throws UnsupportedOperationException { |
| 73 | throw new UnsupportedOperationException("Property elements not supported in version 1.2"); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | |
| 78 | public OFHello.Builder createBuilder() { |
| 79 | return new BuilderWithParent(this); |
| 80 | } |
| 81 | |
| 82 | static class BuilderWithParent implements OFHello.Builder { |
| 83 | final OFHelloVer12 parentMessage; |
| 84 | |
| 85 | // OF message fields |
| 86 | private boolean xidSet; |
| 87 | private long xid; |
| 88 | |
| 89 | BuilderWithParent(OFHelloVer12 parentMessage) { |
| 90 | this.parentMessage = parentMessage; |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public OFVersion getVersion() { |
| 95 | return OFVersion.OF_12; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public OFType getType() { |
| 100 | return OFType.HELLO; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public long getXid() { |
| 105 | return xid; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public OFHello.Builder setXid(long xid) { |
| 110 | this.xid = xid; |
| 111 | this.xidSet = true; |
| 112 | return this; |
| 113 | } |
| 114 | @Override |
| 115 | public List<OFHelloElem> getElements()throws UnsupportedOperationException { |
| 116 | throw new UnsupportedOperationException("Property elements not supported in version 1.2"); |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public OFHello.Builder setElements(List<OFHelloElem> elements) throws UnsupportedOperationException { |
| 121 | throw new UnsupportedOperationException("Property elements not supported in version 1.2"); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | @Override |
| 126 | public OFHello build() { |
| 127 | long xid = this.xidSet ? this.xid : parentMessage.xid; |
| 128 | |
| 129 | // |
| 130 | return new OFHelloVer12( |
| 131 | xid |
| 132 | ); |
| 133 | } |
| 134 | |
| 135 | } |
| 136 | |
| 137 | static class Builder implements OFHello.Builder { |
| 138 | // OF message fields |
| 139 | private boolean xidSet; |
| 140 | private long xid; |
| 141 | |
| 142 | @Override |
| 143 | public OFVersion getVersion() { |
| 144 | return OFVersion.OF_12; |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public OFType getType() { |
| 149 | return OFType.HELLO; |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public long getXid() { |
| 154 | return xid; |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public OFHello.Builder setXid(long xid) { |
| 159 | this.xid = xid; |
| 160 | this.xidSet = true; |
| 161 | return this; |
| 162 | } |
| 163 | @Override |
| 164 | public List<OFHelloElem> getElements()throws UnsupportedOperationException { |
| 165 | throw new UnsupportedOperationException("Property elements not supported in version 1.2"); |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public OFHello.Builder setElements(List<OFHelloElem> elements) throws UnsupportedOperationException { |
| 170 | throw new UnsupportedOperationException("Property elements not supported in version 1.2"); |
| 171 | } |
| 172 | // |
| 173 | @Override |
| 174 | public OFHello build() { |
| 175 | long xid = this.xidSet ? this.xid : DEFAULT_XID; |
| 176 | |
| 177 | |
| 178 | return new OFHelloVer12( |
| 179 | xid |
| 180 | ); |
| 181 | } |
| 182 | |
| 183 | } |
| 184 | |
| 185 | |
| 186 | final static Reader READER = new Reader(); |
| 187 | static class Reader implements OFMessageReader<OFHello> { |
| 188 | @Override |
| 189 | public OFHello readFrom(ChannelBuffer bb) throws OFParseError { |
| 190 | int start = bb.readerIndex(); |
| 191 | // fixed value property version == 3 |
| 192 | byte version = bb.readByte(); |
| 193 | if(version != (byte) 0x3) |
| 194 | throw new OFParseError("Wrong version: Expected=OFVersion.OF_12(3), got="+version); |
| 195 | // fixed value property type == 0 |
| 196 | byte type = bb.readByte(); |
| 197 | if(type != (byte) 0x0) |
| 198 | throw new OFParseError("Wrong type: Expected=OFType.HELLO(0), got="+type); |
| 199 | int length = U16.f(bb.readShort()); |
| 200 | if(length != 8) |
| 201 | throw new OFParseError("Wrong length: Expected=8(8), got="+length); |
| 202 | if(bb.readableBytes() + (bb.readerIndex() - start) < length) { |
| 203 | // Buffer does not have all data yet |
| 204 | bb.readerIndex(start); |
| 205 | return null; |
| 206 | } |
| 207 | if(logger.isTraceEnabled()) |
| 208 | logger.trace("readFrom - length={}", length); |
| 209 | long xid = U32.f(bb.readInt()); |
| 210 | |
| 211 | OFHelloVer12 helloVer12 = new OFHelloVer12( |
| 212 | xid |
| 213 | ); |
| 214 | if(logger.isTraceEnabled()) |
| 215 | logger.trace("readFrom - read={}", helloVer12); |
| 216 | return helloVer12; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | public void putTo(PrimitiveSink sink) { |
| 221 | FUNNEL.funnel(this, sink); |
| 222 | } |
| 223 | |
| 224 | final static OFHelloVer12Funnel FUNNEL = new OFHelloVer12Funnel(); |
| 225 | static class OFHelloVer12Funnel implements Funnel<OFHelloVer12> { |
| 226 | private static final long serialVersionUID = 1L; |
| 227 | @Override |
| 228 | public void funnel(OFHelloVer12 message, PrimitiveSink sink) { |
| 229 | // fixed value property version = 3 |
| 230 | sink.putByte((byte) 0x3); |
| 231 | // fixed value property type = 0 |
| 232 | sink.putByte((byte) 0x0); |
| 233 | // fixed value property length = 8 |
| 234 | sink.putShort((short) 0x8); |
| 235 | sink.putLong(message.xid); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | |
| 240 | public void writeTo(ChannelBuffer bb) { |
| 241 | WRITER.write(bb, this); |
| 242 | } |
| 243 | |
| 244 | final static Writer WRITER = new Writer(); |
| 245 | static class Writer implements OFMessageWriter<OFHelloVer12> { |
| 246 | @Override |
| 247 | public void write(ChannelBuffer bb, OFHelloVer12 message) { |
| 248 | // fixed value property version = 3 |
| 249 | bb.writeByte((byte) 0x3); |
| 250 | // fixed value property type = 0 |
| 251 | bb.writeByte((byte) 0x0); |
| 252 | // fixed value property length = 8 |
| 253 | bb.writeShort((short) 0x8); |
| 254 | bb.writeInt(U32.t(message.xid)); |
| 255 | |
| 256 | |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | @Override |
| 261 | public String toString() { |
| 262 | StringBuilder b = new StringBuilder("OFHelloVer12("); |
| 263 | b.append("xid=").append(xid); |
| 264 | b.append(")"); |
| 265 | return b.toString(); |
| 266 | } |
| 267 | |
| 268 | @Override |
| 269 | public boolean equals(Object obj) { |
| 270 | if (this == obj) |
| 271 | return true; |
| 272 | if (obj == null) |
| 273 | return false; |
| 274 | if (getClass() != obj.getClass()) |
| 275 | return false; |
| 276 | OFHelloVer12 other = (OFHelloVer12) obj; |
| 277 | |
| 278 | if( xid != other.xid) |
| 279 | return false; |
| 280 | return true; |
| 281 | } |
| 282 | |
| 283 | @Override |
| 284 | public int hashCode() { |
| 285 | final int prime = 31; |
| 286 | int result = 1; |
| 287 | |
| 288 | result = prime * (int) (xid ^ (xid >>> 32)); |
| 289 | return result; |
| 290 | } |
| 291 | |
| 292 | } |