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