alshabib | 86ac11c | 2014-08-14 16:14:41 -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 org.jboss.netty.buffer.ChannelBuffer; |
| 30 | import com.google.common.hash.PrimitiveSink; |
| 31 | import com.google.common.hash.Funnel; |
| 32 | |
| 33 | class OFActionOutputVer11 implements OFActionOutput { |
| 34 | private static final Logger logger = LoggerFactory.getLogger(OFActionOutputVer11.class); |
| 35 | // version: 1.1 |
| 36 | final static byte WIRE_VERSION = 2; |
| 37 | final static int LENGTH = 16; |
| 38 | |
| 39 | private final static OFPort DEFAULT_PORT = OFPort.ANY; |
| 40 | private final static int DEFAULT_MAX_LEN = 0x0; |
| 41 | |
| 42 | // OF message fields |
| 43 | private final OFPort port; |
| 44 | private final int maxLen; |
| 45 | // |
| 46 | // Immutable default instance |
| 47 | final static OFActionOutputVer11 DEFAULT = new OFActionOutputVer11( |
| 48 | DEFAULT_PORT, DEFAULT_MAX_LEN |
| 49 | ); |
| 50 | |
| 51 | // package private constructor - used by readers, builders, and factory |
| 52 | OFActionOutputVer11(OFPort port, int maxLen) { |
| 53 | this.port = port; |
| 54 | this.maxLen = maxLen; |
| 55 | } |
| 56 | |
| 57 | // Accessors for OF message fields |
| 58 | @Override |
| 59 | public OFActionType getType() { |
| 60 | return OFActionType.OUTPUT; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public OFPort getPort() { |
| 65 | return port; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public int getMaxLen() { |
| 70 | return maxLen; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public OFVersion getVersion() { |
| 75 | return OFVersion.OF_11; |
| 76 | } |
| 77 | |
| 78 | |
| 79 | |
| 80 | public OFActionOutput.Builder createBuilder() { |
| 81 | return new BuilderWithParent(this); |
| 82 | } |
| 83 | |
| 84 | static class BuilderWithParent implements OFActionOutput.Builder { |
| 85 | final OFActionOutputVer11 parentMessage; |
| 86 | |
| 87 | // OF message fields |
| 88 | private boolean portSet; |
| 89 | private OFPort port; |
| 90 | private boolean maxLenSet; |
| 91 | private int maxLen; |
| 92 | |
| 93 | BuilderWithParent(OFActionOutputVer11 parentMessage) { |
| 94 | this.parentMessage = parentMessage; |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public OFActionType getType() { |
| 99 | return OFActionType.OUTPUT; |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public OFPort getPort() { |
| 104 | return port; |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public OFActionOutput.Builder setPort(OFPort port) { |
| 109 | this.port = port; |
| 110 | this.portSet = true; |
| 111 | return this; |
| 112 | } |
| 113 | @Override |
| 114 | public int getMaxLen() { |
| 115 | return maxLen; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public OFActionOutput.Builder setMaxLen(int maxLen) { |
| 120 | this.maxLen = maxLen; |
| 121 | this.maxLenSet = true; |
| 122 | return this; |
| 123 | } |
| 124 | @Override |
| 125 | public OFVersion getVersion() { |
| 126 | return OFVersion.OF_11; |
| 127 | } |
| 128 | |
| 129 | |
| 130 | |
| 131 | @Override |
| 132 | public OFActionOutput build() { |
| 133 | OFPort port = this.portSet ? this.port : parentMessage.port; |
| 134 | if(port == null) |
| 135 | throw new NullPointerException("Property port must not be null"); |
| 136 | int maxLen = this.maxLenSet ? this.maxLen : parentMessage.maxLen; |
| 137 | |
| 138 | // |
| 139 | return new OFActionOutputVer11( |
| 140 | port, |
| 141 | maxLen |
| 142 | ); |
| 143 | } |
| 144 | |
| 145 | } |
| 146 | |
| 147 | static class Builder implements OFActionOutput.Builder { |
| 148 | // OF message fields |
| 149 | private boolean portSet; |
| 150 | private OFPort port; |
| 151 | private boolean maxLenSet; |
| 152 | private int maxLen; |
| 153 | |
| 154 | @Override |
| 155 | public OFActionType getType() { |
| 156 | return OFActionType.OUTPUT; |
| 157 | } |
| 158 | |
| 159 | @Override |
| 160 | public OFPort getPort() { |
| 161 | return port; |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public OFActionOutput.Builder setPort(OFPort port) { |
| 166 | this.port = port; |
| 167 | this.portSet = true; |
| 168 | return this; |
| 169 | } |
| 170 | @Override |
| 171 | public int getMaxLen() { |
| 172 | return maxLen; |
| 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public OFActionOutput.Builder setMaxLen(int maxLen) { |
| 177 | this.maxLen = maxLen; |
| 178 | this.maxLenSet = true; |
| 179 | return this; |
| 180 | } |
| 181 | @Override |
| 182 | public OFVersion getVersion() { |
| 183 | return OFVersion.OF_11; |
| 184 | } |
| 185 | |
| 186 | // |
| 187 | @Override |
| 188 | public OFActionOutput build() { |
| 189 | OFPort port = this.portSet ? this.port : DEFAULT_PORT; |
| 190 | if(port == null) |
| 191 | throw new NullPointerException("Property port must not be null"); |
| 192 | int maxLen = this.maxLenSet ? this.maxLen : DEFAULT_MAX_LEN; |
| 193 | |
| 194 | |
| 195 | return new OFActionOutputVer11( |
| 196 | port, |
| 197 | maxLen |
| 198 | ); |
| 199 | } |
| 200 | |
| 201 | } |
| 202 | |
| 203 | |
| 204 | final static Reader READER = new Reader(); |
| 205 | static class Reader implements OFMessageReader<OFActionOutput> { |
| 206 | @Override |
| 207 | public OFActionOutput readFrom(ChannelBuffer bb) throws OFParseError { |
| 208 | int start = bb.readerIndex(); |
| 209 | // fixed value property type == 0 |
| 210 | short type = bb.readShort(); |
| 211 | if(type != (short) 0x0) |
| 212 | throw new OFParseError("Wrong type: Expected=OFActionType.OUTPUT(0), got="+type); |
| 213 | int length = U16.f(bb.readShort()); |
| 214 | if(length != 16) |
| 215 | throw new OFParseError("Wrong length: Expected=16(16), got="+length); |
| 216 | if(bb.readableBytes() + (bb.readerIndex() - start) < length) { |
| 217 | // Buffer does not have all data yet |
| 218 | bb.readerIndex(start); |
| 219 | return null; |
| 220 | } |
| 221 | if(logger.isTraceEnabled()) |
| 222 | logger.trace("readFrom - length={}", length); |
| 223 | OFPort port = OFPort.read4Bytes(bb); |
| 224 | int maxLen = U16.f(bb.readShort()); |
| 225 | // pad: 6 bytes |
| 226 | bb.skipBytes(6); |
| 227 | |
| 228 | OFActionOutputVer11 actionOutputVer11 = new OFActionOutputVer11( |
| 229 | port, |
| 230 | maxLen |
| 231 | ); |
| 232 | if(logger.isTraceEnabled()) |
| 233 | logger.trace("readFrom - read={}", actionOutputVer11); |
| 234 | return actionOutputVer11; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | public void putTo(PrimitiveSink sink) { |
| 239 | FUNNEL.funnel(this, sink); |
| 240 | } |
| 241 | |
| 242 | final static OFActionOutputVer11Funnel FUNNEL = new OFActionOutputVer11Funnel(); |
| 243 | static class OFActionOutputVer11Funnel implements Funnel<OFActionOutputVer11> { |
| 244 | private static final long serialVersionUID = 1L; |
| 245 | @Override |
| 246 | public void funnel(OFActionOutputVer11 message, PrimitiveSink sink) { |
| 247 | // fixed value property type = 0 |
| 248 | sink.putShort((short) 0x0); |
| 249 | // fixed value property length = 16 |
| 250 | sink.putShort((short) 0x10); |
| 251 | message.port.putTo(sink); |
| 252 | sink.putInt(message.maxLen); |
| 253 | // skip pad (6 bytes) |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | |
| 258 | public void writeTo(ChannelBuffer bb) { |
| 259 | WRITER.write(bb, this); |
| 260 | } |
| 261 | |
| 262 | final static Writer WRITER = new Writer(); |
| 263 | static class Writer implements OFMessageWriter<OFActionOutputVer11> { |
| 264 | @Override |
| 265 | public void write(ChannelBuffer bb, OFActionOutputVer11 message) { |
| 266 | // fixed value property type = 0 |
| 267 | bb.writeShort((short) 0x0); |
| 268 | // fixed value property length = 16 |
| 269 | bb.writeShort((short) 0x10); |
| 270 | message.port.write4Bytes(bb); |
| 271 | bb.writeShort(U16.t(message.maxLen)); |
| 272 | // pad: 6 bytes |
| 273 | bb.writeZero(6); |
| 274 | |
| 275 | |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | @Override |
| 280 | public String toString() { |
| 281 | StringBuilder b = new StringBuilder("OFActionOutputVer11("); |
| 282 | b.append("port=").append(port); |
| 283 | b.append(", "); |
| 284 | b.append("maxLen=").append(maxLen); |
| 285 | b.append(")"); |
| 286 | return b.toString(); |
| 287 | } |
| 288 | |
| 289 | @Override |
| 290 | public boolean equals(Object obj) { |
| 291 | if (this == obj) |
| 292 | return true; |
| 293 | if (obj == null) |
| 294 | return false; |
| 295 | if (getClass() != obj.getClass()) |
| 296 | return false; |
| 297 | OFActionOutputVer11 other = (OFActionOutputVer11) obj; |
| 298 | |
| 299 | if (port == null) { |
| 300 | if (other.port != null) |
| 301 | return false; |
| 302 | } else if (!port.equals(other.port)) |
| 303 | return false; |
| 304 | if( maxLen != other.maxLen) |
| 305 | return false; |
| 306 | return true; |
| 307 | } |
| 308 | |
| 309 | @Override |
| 310 | public int hashCode() { |
| 311 | final int prime = 31; |
| 312 | int result = 1; |
| 313 | |
| 314 | result = prime * result + ((port == null) ? 0 : port.hashCode()); |
| 315 | result = prime * result + maxLen; |
| 316 | return result; |
| 317 | } |
| 318 | |
| 319 | } |