blob: 0bcde9e0790ae78c06db6b926f7d08f4251c7ca8 [file] [log] [blame]
tom0eb04ca2014-08-25 14:34:51 -07001// 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
10package org.projectfloodlight.openflow.protocol.ver10;
11
12import org.projectfloodlight.openflow.protocol.*;
13import org.projectfloodlight.openflow.protocol.action.*;
14import org.projectfloodlight.openflow.protocol.actionid.*;
15import org.projectfloodlight.openflow.protocol.bsntlv.*;
16import org.projectfloodlight.openflow.protocol.errormsg.*;
17import org.projectfloodlight.openflow.protocol.meterband.*;
18import org.projectfloodlight.openflow.protocol.instruction.*;
19import org.projectfloodlight.openflow.protocol.instructionid.*;
20import org.projectfloodlight.openflow.protocol.match.*;
21import org.projectfloodlight.openflow.protocol.oxm.*;
22import org.projectfloodlight.openflow.protocol.queueprop.*;
23import org.projectfloodlight.openflow.types.*;
24import org.projectfloodlight.openflow.util.*;
25import org.projectfloodlight.openflow.exceptions.*;
26import org.slf4j.Logger;
27import org.slf4j.LoggerFactory;
28import java.util.Set;
29import com.google.common.collect.ImmutableSet;
30import java.util.List;
31import com.google.common.collect.ImmutableList;
32import org.jboss.netty.buffer.ChannelBuffer;
33import com.google.common.hash.PrimitiveSink;
34import com.google.common.hash.Funnel;
35
36class OFPortStatsReplyVer10 implements OFPortStatsReply {
37 private static final Logger logger = LoggerFactory.getLogger(OFPortStatsReplyVer10.class);
38 // version: 1.0
39 final static byte WIRE_VERSION = 1;
40 final static int MINIMUM_LENGTH = 12;
41
42 private final static long DEFAULT_XID = 0x0L;
43 private final static Set<OFStatsReplyFlags> DEFAULT_FLAGS = ImmutableSet.<OFStatsReplyFlags>of();
44 private final static List<OFPortStatsEntry> DEFAULT_ENTRIES = ImmutableList.<OFPortStatsEntry>of();
45
46 // OF message fields
47 private final long xid;
48 private final Set<OFStatsReplyFlags> flags;
49 private final List<OFPortStatsEntry> entries;
50//
51 // Immutable default instance
52 final static OFPortStatsReplyVer10 DEFAULT = new OFPortStatsReplyVer10(
53 DEFAULT_XID, DEFAULT_FLAGS, DEFAULT_ENTRIES
54 );
55
56 // package private constructor - used by readers, builders, and factory
57 OFPortStatsReplyVer10(long xid, Set<OFStatsReplyFlags> flags, List<OFPortStatsEntry> entries) {
58 this.xid = xid;
59 this.flags = flags;
60 this.entries = entries;
61 }
62
63 // Accessors for OF message fields
64 @Override
65 public OFVersion getVersion() {
66 return OFVersion.OF_10;
67 }
68
69 @Override
70 public OFType getType() {
71 return OFType.STATS_REPLY;
72 }
73
74 @Override
75 public long getXid() {
76 return xid;
77 }
78
79 @Override
80 public OFStatsType getStatsType() {
81 return OFStatsType.PORT;
82 }
83
84 @Override
85 public Set<OFStatsReplyFlags> getFlags() {
86 return flags;
87 }
88
89 @Override
90 public List<OFPortStatsEntry> getEntries() {
91 return entries;
92 }
93
94
95
96 public OFPortStatsReply.Builder createBuilder() {
97 return new BuilderWithParent(this);
98 }
99
100 static class BuilderWithParent implements OFPortStatsReply.Builder {
101 final OFPortStatsReplyVer10 parentMessage;
102
103 // OF message fields
104 private boolean xidSet;
105 private long xid;
106 private boolean flagsSet;
107 private Set<OFStatsReplyFlags> flags;
108 private boolean entriesSet;
109 private List<OFPortStatsEntry> entries;
110
111 BuilderWithParent(OFPortStatsReplyVer10 parentMessage) {
112 this.parentMessage = parentMessage;
113 }
114
115 @Override
116 public OFVersion getVersion() {
117 return OFVersion.OF_10;
118 }
119
120 @Override
121 public OFType getType() {
122 return OFType.STATS_REPLY;
123 }
124
125 @Override
126 public long getXid() {
127 return xid;
128 }
129
130 @Override
131 public OFPortStatsReply.Builder setXid(long xid) {
132 this.xid = xid;
133 this.xidSet = true;
134 return this;
135 }
136 @Override
137 public OFStatsType getStatsType() {
138 return OFStatsType.PORT;
139 }
140
141 @Override
142 public Set<OFStatsReplyFlags> getFlags() {
143 return flags;
144 }
145
146 @Override
147 public OFPortStatsReply.Builder setFlags(Set<OFStatsReplyFlags> flags) {
148 this.flags = flags;
149 this.flagsSet = true;
150 return this;
151 }
152 @Override
153 public List<OFPortStatsEntry> getEntries() {
154 return entries;
155 }
156
157 @Override
158 public OFPortStatsReply.Builder setEntries(List<OFPortStatsEntry> entries) {
159 this.entries = entries;
160 this.entriesSet = true;
161 return this;
162 }
163
164
165 @Override
166 public OFPortStatsReply build() {
167 long xid = this.xidSet ? this.xid : parentMessage.xid;
168 Set<OFStatsReplyFlags> flags = this.flagsSet ? this.flags : parentMessage.flags;
169 if(flags == null)
170 throw new NullPointerException("Property flags must not be null");
171 List<OFPortStatsEntry> entries = this.entriesSet ? this.entries : parentMessage.entries;
172 if(entries == null)
173 throw new NullPointerException("Property entries must not be null");
174
175 //
176 return new OFPortStatsReplyVer10(
177 xid,
178 flags,
179 entries
180 );
181 }
182
183 }
184
185 static class Builder implements OFPortStatsReply.Builder {
186 // OF message fields
187 private boolean xidSet;
188 private long xid;
189 private boolean flagsSet;
190 private Set<OFStatsReplyFlags> flags;
191 private boolean entriesSet;
192 private List<OFPortStatsEntry> entries;
193
194 @Override
195 public OFVersion getVersion() {
196 return OFVersion.OF_10;
197 }
198
199 @Override
200 public OFType getType() {
201 return OFType.STATS_REPLY;
202 }
203
204 @Override
205 public long getXid() {
206 return xid;
207 }
208
209 @Override
210 public OFPortStatsReply.Builder setXid(long xid) {
211 this.xid = xid;
212 this.xidSet = true;
213 return this;
214 }
215 @Override
216 public OFStatsType getStatsType() {
217 return OFStatsType.PORT;
218 }
219
220 @Override
221 public Set<OFStatsReplyFlags> getFlags() {
222 return flags;
223 }
224
225 @Override
226 public OFPortStatsReply.Builder setFlags(Set<OFStatsReplyFlags> flags) {
227 this.flags = flags;
228 this.flagsSet = true;
229 return this;
230 }
231 @Override
232 public List<OFPortStatsEntry> getEntries() {
233 return entries;
234 }
235
236 @Override
237 public OFPortStatsReply.Builder setEntries(List<OFPortStatsEntry> entries) {
238 this.entries = entries;
239 this.entriesSet = true;
240 return this;
241 }
242//
243 @Override
244 public OFPortStatsReply build() {
245 long xid = this.xidSet ? this.xid : DEFAULT_XID;
246 Set<OFStatsReplyFlags> flags = this.flagsSet ? this.flags : DEFAULT_FLAGS;
247 if(flags == null)
248 throw new NullPointerException("Property flags must not be null");
249 List<OFPortStatsEntry> entries = this.entriesSet ? this.entries : DEFAULT_ENTRIES;
250 if(entries == null)
251 throw new NullPointerException("Property entries must not be null");
252
253
254 return new OFPortStatsReplyVer10(
255 xid,
256 flags,
257 entries
258 );
259 }
260
261 }
262
263
264 final static Reader READER = new Reader();
265 static class Reader implements OFMessageReader<OFPortStatsReply> {
266 @Override
267 public OFPortStatsReply readFrom(ChannelBuffer bb) throws OFParseError {
268 int start = bb.readerIndex();
269 // fixed value property version == 1
270 byte version = bb.readByte();
271 if(version != (byte) 0x1)
272 throw new OFParseError("Wrong version: Expected=OFVersion.OF_10(1), got="+version);
273 // fixed value property type == 17
274 byte type = bb.readByte();
275 if(type != (byte) 0x11)
276 throw new OFParseError("Wrong type: Expected=OFType.STATS_REPLY(17), got="+type);
277 int length = U16.f(bb.readShort());
278 if(length < MINIMUM_LENGTH)
279 throw new OFParseError("Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length);
280 if(bb.readableBytes() + (bb.readerIndex() - start) < length) {
281 // Buffer does not have all data yet
282 bb.readerIndex(start);
283 return null;
284 }
285 if(logger.isTraceEnabled())
286 logger.trace("readFrom - length={}", length);
287 long xid = U32.f(bb.readInt());
288 // fixed value property statsType == 4
289 short statsType = bb.readShort();
290 if(statsType != (short) 0x4)
291 throw new OFParseError("Wrong statsType: Expected=OFStatsType.PORT(4), got="+statsType);
292 Set<OFStatsReplyFlags> flags = OFStatsReplyFlagsSerializerVer10.readFrom(bb);
293 List<OFPortStatsEntry> entries = ChannelUtils.readList(bb, length - (bb.readerIndex() - start), OFPortStatsEntryVer10.READER);
294
295 OFPortStatsReplyVer10 portStatsReplyVer10 = new OFPortStatsReplyVer10(
296 xid,
297 flags,
298 entries
299 );
300 if(logger.isTraceEnabled())
301 logger.trace("readFrom - read={}", portStatsReplyVer10);
302 return portStatsReplyVer10;
303 }
304 }
305
306 public void putTo(PrimitiveSink sink) {
307 FUNNEL.funnel(this, sink);
308 }
309
310 final static OFPortStatsReplyVer10Funnel FUNNEL = new OFPortStatsReplyVer10Funnel();
311 static class OFPortStatsReplyVer10Funnel implements Funnel<OFPortStatsReplyVer10> {
312 private static final long serialVersionUID = 1L;
313 @Override
314 public void funnel(OFPortStatsReplyVer10 message, PrimitiveSink sink) {
315 // fixed value property version = 1
316 sink.putByte((byte) 0x1);
317 // fixed value property type = 17
318 sink.putByte((byte) 0x11);
319 // FIXME: skip funnel of length
320 sink.putLong(message.xid);
321 // fixed value property statsType = 4
322 sink.putShort((short) 0x4);
323 OFStatsReplyFlagsSerializerVer10.putTo(message.flags, sink);
324 FunnelUtils.putList(message.entries, sink);
325 }
326 }
327
328
329 public void writeTo(ChannelBuffer bb) {
330 WRITER.write(bb, this);
331 }
332
333 final static Writer WRITER = new Writer();
334 static class Writer implements OFMessageWriter<OFPortStatsReplyVer10> {
335 @Override
336 public void write(ChannelBuffer bb, OFPortStatsReplyVer10 message) {
337 int startIndex = bb.writerIndex();
338 // fixed value property version = 1
339 bb.writeByte((byte) 0x1);
340 // fixed value property type = 17
341 bb.writeByte((byte) 0x11);
342 // length is length of variable message, will be updated at the end
343 int lengthIndex = bb.writerIndex();
344 bb.writeShort(U16.t(0));
345
346 bb.writeInt(U32.t(message.xid));
347 // fixed value property statsType = 4
348 bb.writeShort((short) 0x4);
349 OFStatsReplyFlagsSerializerVer10.writeTo(bb, message.flags);
350 ChannelUtils.writeList(bb, message.entries);
351
352 // update length field
353 int length = bb.writerIndex() - startIndex;
354 bb.setShort(lengthIndex, length);
355
356 }
357 }
358
359 @Override
360 public String toString() {
361 StringBuilder b = new StringBuilder("OFPortStatsReplyVer10(");
362 b.append("xid=").append(xid);
363 b.append(", ");
364 b.append("flags=").append(flags);
365 b.append(", ");
366 b.append("entries=").append(entries);
367 b.append(")");
368 return b.toString();
369 }
370
371 @Override
372 public boolean equals(Object obj) {
373 if (this == obj)
374 return true;
375 if (obj == null)
376 return false;
377 if (getClass() != obj.getClass())
378 return false;
379 OFPortStatsReplyVer10 other = (OFPortStatsReplyVer10) obj;
380
381 if( xid != other.xid)
382 return false;
383 if (flags == null) {
384 if (other.flags != null)
385 return false;
386 } else if (!flags.equals(other.flags))
387 return false;
388 if (entries == null) {
389 if (other.entries != null)
390 return false;
391 } else if (!entries.equals(other.entries))
392 return false;
393 return true;
394 }
395
396 @Override
397 public int hashCode() {
398 final int prime = 31;
399 int result = 1;
400
401 result = prime * (int) (xid ^ (xid >>> 32));
402 result = prime * result + ((flags == null) ? 0 : flags.hashCode());
403 result = prime * result + ((entries == null) ? 0 : entries.hashCode());
404 return result;
405 }
406
407}