0f7da4b2d55b86323de4ffd0a2c96b442e208330
[openflowjava.git] / third-party / openflow-codec / src / main / java / org / openflow / codec / protocol / statistics / OFPGroupStatisticsReply.java
1 package org.openflow.codec.protocol.statistics;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import org.openflow.codec.io.IDataBuffer;
8 import org.openflow.codec.protocol.action.OFPBucketCounter;
9 import org.openflow.codec.util.U16;
10
11 /**
12  * Represents an ofp_group_stats structure
13  *
14  * @author Yugandhar Sarraju (ysarraju@in.ibm.com)
15  */
16 public class OFPGroupStatisticsReply implements OFPStatistics, Serializable {
17     public static int MINIMUM_LENGTH = 40;
18
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;
27
28     public void setLength(short length) {
29         this.length = length;
30     }
31
32     @Override
33     public int getLength() {
34         return U16.f(length);
35     }
36
37     public int getGroup_id() {
38         return group_id;
39     }
40
41     public void setGroup_id(int group_id) {
42         this.group_id = group_id;
43     }
44
45     public int getRef_count() {
46         return ref_count;
47     }
48
49     public void setRef_count(int ref_count) {
50         this.ref_count = ref_count;
51     }
52
53     public long getPacket_count() {
54         return packet_count;
55     }
56
57     public void setPacket_count(long packet_count) {
58         this.packet_count = packet_count;
59     }
60
61     public long getByte_count() {
62         return byte_count;
63     }
64
65     public void setByte_count(long byte_count) {
66         this.byte_count = byte_count;
67     }
68
69     public int getDuration_sec() {
70         return duration_sec;
71     }
72
73     public void setDuration_sec(int duration_sec) {
74         this.duration_sec = duration_sec;
75     }
76
77     public int getDuration_nsec() {
78         return duration_nsec;
79     }
80
81     public void setDuration_nsec(int duration_nsec) {
82         this.duration_nsec = duration_nsec;
83     }
84
85     public List<OFPBucketCounter> getBucket_stats() {
86         return bucket_stats;
87     }
88
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);
93         } else {
94             this.setLength((short) (MINIMUM_LENGTH + bucket_stats.size() * OFPBucketCounter.MINIMUM_LENGTH));
95         }
96     }
97
98     @Override
99     public void readFrom(IDataBuffer data) {
100         this.length = data.getShort();
101         data.getShort();
102         this.group_id = data.getInt();
103         this.ref_count = data.getInt();
104         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>();
111         } else {
112             this.bucket_stats.clear();
113         }
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);
120         }
121     }
122
123     @Override
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);
129         data.putInt(0);
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);
137             }
138         }
139     }
140
141     @Override
142     public int hashCode() {
143         final int prime = 419;
144         int result = 1;
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;
153         return result;
154     }
155
156     @Override
157     public boolean equals(Object obj) {
158         if (this == obj) {
159             return true;
160         }
161         if (obj == null) {
162             return false;
163         }
164         if (!(obj instanceof OFPGroupStatisticsReply)) {
165             return false;
166         }
167         OFPGroupStatisticsReply other = (OFPGroupStatisticsReply) obj;
168         if (bucket_stats == null) {
169             if (other.bucket_stats != null) {
170                 return false;
171             }
172         } else if (!bucket_stats.equals(other.bucket_stats)) {
173             return false;
174         }
175         if (length != other.length) {
176             return false;
177         }
178         if (group_id != other.group_id) {
179             return false;
180         }
181         if (ref_count != other.ref_count) {
182             return false;
183         }
184         if (packet_count != other.packet_count) {
185             return false;
186         }
187         if (byte_count != other.byte_count) {
188             return false;
189         }
190         if (duration_sec != other.duration_sec) {
191             return false;
192         }
193         if (duration_nsec != other.duration_nsec) {
194             return false;
195         }
196         return true;
197     }
198 }