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