1 package org.openflow.codec.protocol.statistics;
3 import java.io.Serializable;
4 import java.util.ArrayList;
7 import org.openflow.codec.io.IDataBuffer;
8 import org.openflow.codec.protocol.action.OFPBucketCounter;
9 import org.openflow.codec.util.U16;
12 * Represents an ofp_group_stats structure
14 * @author Yugandhar Sarraju (ysarraju@in.ibm.com)
16 public class OFPGroupStatisticsReply implements OFPStatistics, Serializable {
17 public static int MINIMUM_LENGTH = 40;
19 protected short length = (short) MINIMUM_LENGTH;
20 protected int group_id;
21 protected int ref_count;
22 protected long packet_count;
23 protected long byte_count;
24 protected int duration_sec;
25 protected int duration_nsec;
26 protected List<OFPBucketCounter> bucket_stats;
28 public void setLength(short length) {
33 public int getLength() {
37 public int getGroup_id() {
41 public void setGroup_id(int group_id) {
42 this.group_id = group_id;
45 public int getRef_count() {
49 public void setRef_count(int ref_count) {
50 this.ref_count = ref_count;
53 public long getPacket_count() {
57 public void setPacket_count(long packet_count) {
58 this.packet_count = packet_count;
61 public long getByte_count() {
65 public void setByte_count(long byte_count) {
66 this.byte_count = byte_count;
69 public int getDuration_sec() {
73 public void setDuration_sec(int duration_sec) {
74 this.duration_sec = duration_sec;
77 public int getDuration_nsec() {
81 public void setDuration_nsec(int duration_nsec) {
82 this.duration_nsec = duration_nsec;
85 public List<OFPBucketCounter> getBucket_stats() {
89 public void setBucket_stats(List<OFPBucketCounter> bucket_stats) {
90 this.bucket_stats = bucket_stats;
91 if (bucket_stats == null) {
92 this.setLength((short) MINIMUM_LENGTH);
94 this.setLength((short) (MINIMUM_LENGTH + bucket_stats.size() * OFPBucketCounter.MINIMUM_LENGTH));
99 public void readFrom(IDataBuffer data) {
100 this.length = data.getShort();
102 this.group_id = data.getInt();
103 this.ref_count = data.getInt();
105 this.packet_count = data.getLong();
106 this.byte_count = data.getLong();
107 this.duration_sec = data.getInt();
108 this.duration_nsec = data.getInt();
109 if (this.bucket_stats == null) {
110 this.bucket_stats = new ArrayList<OFPBucketCounter>();
112 this.bucket_stats.clear();
114 int bucketCounterCount = (this.getLength() - 38) / OFPBucketCounter.MINIMUM_LENGTH;
115 OFPBucketCounter bucketCounter;
116 for (int i = 0; i < bucketCounterCount; ++i) {
117 bucketCounter = new OFPBucketCounter();
118 bucketCounter.readFrom(data);
119 this.bucket_stats.add(bucketCounter);
124 public void writeTo(IDataBuffer data) {
125 data.putShort(length);
126 data.putShort((short) 0);
127 data.putInt(group_id);
128 data.putInt(ref_count);
130 data.putLong(packet_count);
131 data.putLong(byte_count);
132 data.putInt(duration_sec);
133 data.putInt(duration_nsec);
134 if (bucket_stats != null) {
135 for (OFPBucketCounter bucketCounter : bucket_stats) {
136 bucketCounter.writeTo(data);
142 public int hashCode() {
143 final int prime = 419;
145 result = prime * result + ((bucket_stats == null) ? 0 : bucket_stats.hashCode());
146 result = prime * result + length;
147 result = prime * result + group_id;
148 result = prime * result + ref_count;
149 result = prime * result + (int) (packet_count ^ (packet_count >>> 32));
150 result = prime * result + (int) (byte_count ^ (byte_count >>> 32));
151 result = prime * result + duration_sec;
152 result = prime * result + duration_nsec;
157 public boolean equals(Object obj) {
164 if (!(obj instanceof OFPGroupStatisticsReply)) {
167 OFPGroupStatisticsReply other = (OFPGroupStatisticsReply) obj;
168 if (bucket_stats == null) {
169 if (other.bucket_stats != null) {
172 } else if (!bucket_stats.equals(other.bucket_stats)) {
175 if (length != other.length) {
178 if (group_id != other.group_id) {
181 if (ref_count != other.ref_count) {
184 if (packet_count != other.packet_count) {
187 if (byte_count != other.byte_count) {
190 if (duration_sec != other.duration_sec) {
193 if (duration_nsec != other.duration_nsec) {