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