1 package org.openflow.codec.protocol.statistics;
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.LinkedList;
8 import org.openflow.codec.io.IDataBuffer;
9 import org.openflow.codec.protocol.action.OFPBucket;
10 import org.openflow.codec.protocol.factory.OFPActionFactory;
11 import org.openflow.codec.protocol.factory.OFPActionFactoryAware;
14 * Represents an ofp_group_desc_stats structure
16 * @author Yugandhar Sarraju
18 public class OFPGroupDescription implements OFPStatistics, OFPActionFactoryAware, Serializable {
20 private static final int MINIMUM_LENGTH = 8;
22 protected OFPActionFactory actionFactory;
23 private short length = MINIMUM_LENGTH;
24 private byte groupType;
26 private List<OFPBucket> buckets;
28 public byte getGroupType() {
32 public OFPGroupDescription setGroupType(byte groupType) {
33 this.groupType = groupType;
37 public int getGroup_id() {
41 public OFPGroupDescription setGroup_id(int group_id) {
42 this.group_id = group_id;
46 public List<OFPBucket> getBuckets() {
51 public int getLength() {
55 public OFPGroupDescription setLength(int length) {
56 this.length = (short) length;
64 public OFPGroupDescription setBuckets(List<OFPBucket> buckets) {
65 this.buckets = buckets;
71 private void updateLength() {
72 int totalLength = MINIMUM_LENGTH;
73 if (buckets != null) {
74 for (OFPBucket bucket : buckets) {
75 totalLength += bucket.getLengthU();
78 this.setLength(totalLength);
82 public void readFrom(IDataBuffer data) {
83 this.length = data.getShort();
84 this.groupType = data.get();
86 this.group_id = data.getInt();
87 if (this.buckets == null) {
88 this.buckets = new ArrayList<OFPBucket>();
94 while (data.remaining() > 0) {
95 bucket = new OFPBucket();
96 bucket.setActionFactory(actionFactory);
97 bucket.readFrom(data);
98 this.buckets.add(bucket);
104 public void writeTo(IDataBuffer data) {
105 data.putShort(length);
108 data.putInt(group_id);
109 if (buckets != null) {
110 for (OFPBucket bucket : buckets) {
111 bucket.writeTo(data);
117 public int hashCode() {
118 final int prime = 461;
120 result = prime * result + length;
121 result = prime * result + ((buckets == null) ? 0 : buckets.hashCode());
122 result = prime * result + groupType;
123 result = prime * result + group_id;
128 public boolean equals(Object obj) {
135 if (!(obj instanceof OFPGroupDescription)) {
138 OFPGroupDescription other = (OFPGroupDescription) obj;
139 if (length != other.length) {
142 if (buckets == null) {
143 if (other.buckets != null) {
146 } else if (!buckets.equals(other.buckets)) {
149 if (groupType != other.groupType) {
152 if (group_id != other.group_id) {
161 * @see java.lang.Object#clone()
164 public OFPGroupDescription clone() {
166 OFPGroupDescription groupDes = (OFPGroupDescription) super.clone();
167 List<OFPBucket> neoBuckets = new LinkedList<OFPBucket>();
168 for (OFPBucket bucket : this.buckets)
169 neoBuckets.add((OFPBucket) bucket.clone());
170 groupDes.setBuckets(neoBuckets);
172 } catch (CloneNotSupportedException e) {
174 throw new RuntimeException(e);
181 * @see java.lang.Object#toString()
184 public String toString() {
185 return "OFPGroupDes [ buckets=" + buckets + ", length=" + length + ", groupType=" + groupType + ", group_id="
190 public void setActionFactory(OFPActionFactory actionFactory) {
191 this.actionFactory = actionFactory;