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