blob: e5f55916e9847cd38e51310b673a1cb750c73efc [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.ver13;
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.List;
29import com.google.common.collect.ImmutableList;
30import java.util.Set;
31import org.jboss.netty.buffer.ChannelBuffer;
32import com.google.common.hash.PrimitiveSink;
33import com.google.common.hash.Funnel;
34
35class OFMeterStatsVer13 implements OFMeterStats {
36 private static final Logger logger = LoggerFactory.getLogger(OFMeterStatsVer13.class);
37 // version: 1.3
38 final static byte WIRE_VERSION = 4;
39 final static int MINIMUM_LENGTH = 40;
40
41 private final static long DEFAULT_METER_ID = 0x0L;
42 private final static long DEFAULT_FLOW_COUNT = 0x0L;
43 private final static U64 DEFAULT_PACKET_IN_COUNT = U64.ZERO;
44 private final static U64 DEFAULT_BYTE_IN_COUNT = U64.ZERO;
45 private final static long DEFAULT_DURATION_SEC = 0x0L;
46 private final static long DEFAULT_DURATION_NSEC = 0x0L;
47 private final static List<OFMeterBandStats> DEFAULT_BAND_STATS = ImmutableList.<OFMeterBandStats>of();
48
49 // OF message fields
50 private final long meterId;
51 private final long flowCount;
52 private final U64 packetInCount;
53 private final U64 byteInCount;
54 private final long durationSec;
55 private final long durationNsec;
56 private final List<OFMeterBandStats> bandStats;
57//
58 // Immutable default instance
59 final static OFMeterStatsVer13 DEFAULT = new OFMeterStatsVer13(
60 DEFAULT_METER_ID, DEFAULT_FLOW_COUNT, DEFAULT_PACKET_IN_COUNT, DEFAULT_BYTE_IN_COUNT, DEFAULT_DURATION_SEC, DEFAULT_DURATION_NSEC, DEFAULT_BAND_STATS
61 );
62
63 // package private constructor - used by readers, builders, and factory
64 OFMeterStatsVer13(long meterId, long flowCount, U64 packetInCount, U64 byteInCount, long durationSec, long durationNsec, List<OFMeterBandStats> bandStats) {
65 this.meterId = meterId;
66 this.flowCount = flowCount;
67 this.packetInCount = packetInCount;
68 this.byteInCount = byteInCount;
69 this.durationSec = durationSec;
70 this.durationNsec = durationNsec;
71 this.bandStats = bandStats;
72 }
73
74 // Accessors for OF message fields
75 @Override
76 public long getMeterId() {
77 return meterId;
78 }
79
80 @Override
81 public long getFlowCount() {
82 return flowCount;
83 }
84
85 @Override
86 public U64 getPacketInCount() {
87 return packetInCount;
88 }
89
90 @Override
91 public U64 getByteInCount() {
92 return byteInCount;
93 }
94
95 @Override
96 public long getDurationSec() {
97 return durationSec;
98 }
99
100 @Override
101 public long getDurationNsec() {
102 return durationNsec;
103 }
104
105 @Override
106 public List<OFMeterBandStats> getBandStats() {
107 return bandStats;
108 }
109
110 @Override
111 public OFVersion getVersion() {
112 return OFVersion.OF_13;
113 }
114
115
116
117 public OFMeterStats.Builder createBuilder() {
118 return new BuilderWithParent(this);
119 }
120
121 static class BuilderWithParent implements OFMeterStats.Builder {
122 final OFMeterStatsVer13 parentMessage;
123
124 // OF message fields
125 private boolean meterIdSet;
126 private long meterId;
127 private boolean flowCountSet;
128 private long flowCount;
129 private boolean packetInCountSet;
130 private U64 packetInCount;
131 private boolean byteInCountSet;
132 private U64 byteInCount;
133 private boolean durationSecSet;
134 private long durationSec;
135 private boolean durationNsecSet;
136 private long durationNsec;
137 private boolean bandStatsSet;
138 private List<OFMeterBandStats> bandStats;
139
140 BuilderWithParent(OFMeterStatsVer13 parentMessage) {
141 this.parentMessage = parentMessage;
142 }
143
144 @Override
145 public long getMeterId() {
146 return meterId;
147 }
148
149 @Override
150 public OFMeterStats.Builder setMeterId(long meterId) {
151 this.meterId = meterId;
152 this.meterIdSet = true;
153 return this;
154 }
155 @Override
156 public long getFlowCount() {
157 return flowCount;
158 }
159
160 @Override
161 public OFMeterStats.Builder setFlowCount(long flowCount) {
162 this.flowCount = flowCount;
163 this.flowCountSet = true;
164 return this;
165 }
166 @Override
167 public U64 getPacketInCount() {
168 return packetInCount;
169 }
170
171 @Override
172 public OFMeterStats.Builder setPacketInCount(U64 packetInCount) {
173 this.packetInCount = packetInCount;
174 this.packetInCountSet = true;
175 return this;
176 }
177 @Override
178 public U64 getByteInCount() {
179 return byteInCount;
180 }
181
182 @Override
183 public OFMeterStats.Builder setByteInCount(U64 byteInCount) {
184 this.byteInCount = byteInCount;
185 this.byteInCountSet = true;
186 return this;
187 }
188 @Override
189 public long getDurationSec() {
190 return durationSec;
191 }
192
193 @Override
194 public OFMeterStats.Builder setDurationSec(long durationSec) {
195 this.durationSec = durationSec;
196 this.durationSecSet = true;
197 return this;
198 }
199 @Override
200 public long getDurationNsec() {
201 return durationNsec;
202 }
203
204 @Override
205 public OFMeterStats.Builder setDurationNsec(long durationNsec) {
206 this.durationNsec = durationNsec;
207 this.durationNsecSet = true;
208 return this;
209 }
210 @Override
211 public List<OFMeterBandStats> getBandStats() {
212 return bandStats;
213 }
214
215 @Override
216 public OFMeterStats.Builder setBandStats(List<OFMeterBandStats> bandStats) {
217 this.bandStats = bandStats;
218 this.bandStatsSet = true;
219 return this;
220 }
221 @Override
222 public OFVersion getVersion() {
223 return OFVersion.OF_13;
224 }
225
226
227
228 @Override
229 public OFMeterStats build() {
230 long meterId = this.meterIdSet ? this.meterId : parentMessage.meterId;
231 long flowCount = this.flowCountSet ? this.flowCount : parentMessage.flowCount;
232 U64 packetInCount = this.packetInCountSet ? this.packetInCount : parentMessage.packetInCount;
233 if(packetInCount == null)
234 throw new NullPointerException("Property packetInCount must not be null");
235 U64 byteInCount = this.byteInCountSet ? this.byteInCount : parentMessage.byteInCount;
236 if(byteInCount == null)
237 throw new NullPointerException("Property byteInCount must not be null");
238 long durationSec = this.durationSecSet ? this.durationSec : parentMessage.durationSec;
239 long durationNsec = this.durationNsecSet ? this.durationNsec : parentMessage.durationNsec;
240 List<OFMeterBandStats> bandStats = this.bandStatsSet ? this.bandStats : parentMessage.bandStats;
241 if(bandStats == null)
242 throw new NullPointerException("Property bandStats must not be null");
243
244 //
245 return new OFMeterStatsVer13(
246 meterId,
247 flowCount,
248 packetInCount,
249 byteInCount,
250 durationSec,
251 durationNsec,
252 bandStats
253 );
254 }
255
256 }
257
258 static class Builder implements OFMeterStats.Builder {
259 // OF message fields
260 private boolean meterIdSet;
261 private long meterId;
262 private boolean flowCountSet;
263 private long flowCount;
264 private boolean packetInCountSet;
265 private U64 packetInCount;
266 private boolean byteInCountSet;
267 private U64 byteInCount;
268 private boolean durationSecSet;
269 private long durationSec;
270 private boolean durationNsecSet;
271 private long durationNsec;
272 private boolean bandStatsSet;
273 private List<OFMeterBandStats> bandStats;
274
275 @Override
276 public long getMeterId() {
277 return meterId;
278 }
279
280 @Override
281 public OFMeterStats.Builder setMeterId(long meterId) {
282 this.meterId = meterId;
283 this.meterIdSet = true;
284 return this;
285 }
286 @Override
287 public long getFlowCount() {
288 return flowCount;
289 }
290
291 @Override
292 public OFMeterStats.Builder setFlowCount(long flowCount) {
293 this.flowCount = flowCount;
294 this.flowCountSet = true;
295 return this;
296 }
297 @Override
298 public U64 getPacketInCount() {
299 return packetInCount;
300 }
301
302 @Override
303 public OFMeterStats.Builder setPacketInCount(U64 packetInCount) {
304 this.packetInCount = packetInCount;
305 this.packetInCountSet = true;
306 return this;
307 }
308 @Override
309 public U64 getByteInCount() {
310 return byteInCount;
311 }
312
313 @Override
314 public OFMeterStats.Builder setByteInCount(U64 byteInCount) {
315 this.byteInCount = byteInCount;
316 this.byteInCountSet = true;
317 return this;
318 }
319 @Override
320 public long getDurationSec() {
321 return durationSec;
322 }
323
324 @Override
325 public OFMeterStats.Builder setDurationSec(long durationSec) {
326 this.durationSec = durationSec;
327 this.durationSecSet = true;
328 return this;
329 }
330 @Override
331 public long getDurationNsec() {
332 return durationNsec;
333 }
334
335 @Override
336 public OFMeterStats.Builder setDurationNsec(long durationNsec) {
337 this.durationNsec = durationNsec;
338 this.durationNsecSet = true;
339 return this;
340 }
341 @Override
342 public List<OFMeterBandStats> getBandStats() {
343 return bandStats;
344 }
345
346 @Override
347 public OFMeterStats.Builder setBandStats(List<OFMeterBandStats> bandStats) {
348 this.bandStats = bandStats;
349 this.bandStatsSet = true;
350 return this;
351 }
352 @Override
353 public OFVersion getVersion() {
354 return OFVersion.OF_13;
355 }
356
357//
358 @Override
359 public OFMeterStats build() {
360 long meterId = this.meterIdSet ? this.meterId : DEFAULT_METER_ID;
361 long flowCount = this.flowCountSet ? this.flowCount : DEFAULT_FLOW_COUNT;
362 U64 packetInCount = this.packetInCountSet ? this.packetInCount : DEFAULT_PACKET_IN_COUNT;
363 if(packetInCount == null)
364 throw new NullPointerException("Property packetInCount must not be null");
365 U64 byteInCount = this.byteInCountSet ? this.byteInCount : DEFAULT_BYTE_IN_COUNT;
366 if(byteInCount == null)
367 throw new NullPointerException("Property byteInCount must not be null");
368 long durationSec = this.durationSecSet ? this.durationSec : DEFAULT_DURATION_SEC;
369 long durationNsec = this.durationNsecSet ? this.durationNsec : DEFAULT_DURATION_NSEC;
370 List<OFMeterBandStats> bandStats = this.bandStatsSet ? this.bandStats : DEFAULT_BAND_STATS;
371 if(bandStats == null)
372 throw new NullPointerException("Property bandStats must not be null");
373
374
375 return new OFMeterStatsVer13(
376 meterId,
377 flowCount,
378 packetInCount,
379 byteInCount,
380 durationSec,
381 durationNsec,
382 bandStats
383 );
384 }
385
386 }
387
388
389 final static Reader READER = new Reader();
390 static class Reader implements OFMessageReader<OFMeterStats> {
391 @Override
392 public OFMeterStats readFrom(ChannelBuffer bb) throws OFParseError {
393 int start = bb.readerIndex();
394 long meterId = U32.f(bb.readInt());
395 int length = U16.f(bb.readShort());
396 if(length < MINIMUM_LENGTH)
397 throw new OFParseError("Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length);
398 if(bb.readableBytes() + (bb.readerIndex() - start) < length) {
399 // Buffer does not have all data yet
400 bb.readerIndex(start);
401 return null;
402 }
403 if(logger.isTraceEnabled())
404 logger.trace("readFrom - length={}", length);
405 // pad: 6 bytes
406 bb.skipBytes(6);
407 long flowCount = U32.f(bb.readInt());
408 U64 packetInCount = U64.ofRaw(bb.readLong());
409 U64 byteInCount = U64.ofRaw(bb.readLong());
410 long durationSec = U32.f(bb.readInt());
411 long durationNsec = U32.f(bb.readInt());
412 List<OFMeterBandStats> bandStats = ChannelUtils.readList(bb, length - (bb.readerIndex() - start), OFMeterBandStatsVer13.READER);
413
414 OFMeterStatsVer13 meterStatsVer13 = new OFMeterStatsVer13(
415 meterId,
416 flowCount,
417 packetInCount,
418 byteInCount,
419 durationSec,
420 durationNsec,
421 bandStats
422 );
423 if(logger.isTraceEnabled())
424 logger.trace("readFrom - read={}", meterStatsVer13);
425 return meterStatsVer13;
426 }
427 }
428
429 public void putTo(PrimitiveSink sink) {
430 FUNNEL.funnel(this, sink);
431 }
432
433 final static OFMeterStatsVer13Funnel FUNNEL = new OFMeterStatsVer13Funnel();
434 static class OFMeterStatsVer13Funnel implements Funnel<OFMeterStatsVer13> {
435 private static final long serialVersionUID = 1L;
436 @Override
437 public void funnel(OFMeterStatsVer13 message, PrimitiveSink sink) {
438 sink.putLong(message.meterId);
439 // FIXME: skip funnel of length
440 // skip pad (6 bytes)
441 sink.putLong(message.flowCount);
442 message.packetInCount.putTo(sink);
443 message.byteInCount.putTo(sink);
444 sink.putLong(message.durationSec);
445 sink.putLong(message.durationNsec);
446 FunnelUtils.putList(message.bandStats, sink);
447 }
448 }
449
450
451 public void writeTo(ChannelBuffer bb) {
452 WRITER.write(bb, this);
453 }
454
455 final static Writer WRITER = new Writer();
456 static class Writer implements OFMessageWriter<OFMeterStatsVer13> {
457 @Override
458 public void write(ChannelBuffer bb, OFMeterStatsVer13 message) {
459 int startIndex = bb.writerIndex();
460 bb.writeInt(U32.t(message.meterId));
461 // length is length of variable message, will be updated at the end
462 int lengthIndex = bb.writerIndex();
463 bb.writeShort(U16.t(0));
464
465 // pad: 6 bytes
466 bb.writeZero(6);
467 bb.writeInt(U32.t(message.flowCount));
468 bb.writeLong(message.packetInCount.getValue());
469 bb.writeLong(message.byteInCount.getValue());
470 bb.writeInt(U32.t(message.durationSec));
471 bb.writeInt(U32.t(message.durationNsec));
472 ChannelUtils.writeList(bb, message.bandStats);
473
474 // update length field
475 int length = bb.writerIndex() - startIndex;
476 bb.setShort(lengthIndex, length);
477
478 }
479 }
480
481 @Override
482 public String toString() {
483 StringBuilder b = new StringBuilder("OFMeterStatsVer13(");
484 b.append("meterId=").append(meterId);
485 b.append(", ");
486 b.append("flowCount=").append(flowCount);
487 b.append(", ");
488 b.append("packetInCount=").append(packetInCount);
489 b.append(", ");
490 b.append("byteInCount=").append(byteInCount);
491 b.append(", ");
492 b.append("durationSec=").append(durationSec);
493 b.append(", ");
494 b.append("durationNsec=").append(durationNsec);
495 b.append(", ");
496 b.append("bandStats=").append(bandStats);
497 b.append(")");
498 return b.toString();
499 }
500
501 @Override
502 public boolean equals(Object obj) {
503 if (this == obj)
504 return true;
505 if (obj == null)
506 return false;
507 if (getClass() != obj.getClass())
508 return false;
509 OFMeterStatsVer13 other = (OFMeterStatsVer13) obj;
510
511 if( meterId != other.meterId)
512 return false;
513 if( flowCount != other.flowCount)
514 return false;
515 if (packetInCount == null) {
516 if (other.packetInCount != null)
517 return false;
518 } else if (!packetInCount.equals(other.packetInCount))
519 return false;
520 if (byteInCount == null) {
521 if (other.byteInCount != null)
522 return false;
523 } else if (!byteInCount.equals(other.byteInCount))
524 return false;
525 if( durationSec != other.durationSec)
526 return false;
527 if( durationNsec != other.durationNsec)
528 return false;
529 if (bandStats == null) {
530 if (other.bandStats != null)
531 return false;
532 } else if (!bandStats.equals(other.bandStats))
533 return false;
534 return true;
535 }
536
537 @Override
538 public int hashCode() {
539 final int prime = 31;
540 int result = 1;
541
542 result = prime * (int) (meterId ^ (meterId >>> 32));
543 result = prime * (int) (flowCount ^ (flowCount >>> 32));
544 result = prime * result + ((packetInCount == null) ? 0 : packetInCount.hashCode());
545 result = prime * result + ((byteInCount == null) ? 0 : byteInCount.hashCode());
546 result = prime * (int) (durationSec ^ (durationSec >>> 32));
547 result = prime * (int) (durationNsec ^ (durationNsec >>> 32));
548 result = prime * result + ((bandStats == null) ? 0 : bandStats.hashCode());
549 return result;
550 }
551
552}