1 package org.openflow.codec.protocol;
3 import java.util.ArrayList;
4 import java.util.LinkedList;
7 import org.openflow.codec.io.IDataBuffer;
8 import org.openflow.codec.protocol.action.OFPBucket;
9 import org.openflow.codec.util.U16;
12 * Represents an ofp_group_mod message
14 * @author Yugandhar Sarraju (ysarraju@in.ibm.com)
17 public class OFPGroupMod extends OFPMessage implements Cloneable {
18 public static int MINIMUM_LENGTH = 16;
20 public static final short OFPGC_ADD = 0; /* New group. */
21 public static final short OFPGC_MODIFY = 1; /* Modify all matching groups. */
22 public static final short OFPGC_DELETE = 2; /* Delete all matching groups. */
24 public static final short OFPGT_ALL = 0; /* All (multicast/broadcast) group. */
25 public static final short OFPGT_SELECT = 1; /* Select group. */
26 public static final short OFPGT_INDIRECT = 2; /* Indirect group. */
27 public static final short OFPGT_FF = 3; /* Fast failover group. */
29 protected short groupCommand;
30 protected byte groupType;
31 protected int group_id;
32 protected List<OFPBucket> buckets;
34 public OFPGroupMod() {
36 this.type = OFPType.GROUP_MOD;
37 this.length = U16.t(MINIMUM_LENGTH);
40 public short getGroupCommand() {
44 public OFPGroupMod setGroupCommand(short groupCommand) {
45 this.groupCommand = groupCommand;
49 public byte getGroupType() {
53 public OFPGroupMod setGroupType(byte groupType) {
54 this.groupType = groupType;
58 public int getGroup_id() {
62 public OFPGroupMod setGroup_id(int group_id) {
63 this.group_id = group_id;
67 public List<OFPBucket> getBuckets() {
75 public OFPGroupMod setBuckets(List<OFPBucket> buckets) {
76 this.buckets = buckets;
77 if (buckets == null) {
78 this.setLengthU(MINIMUM_LENGTH);
80 this.setLengthU(MINIMUM_LENGTH + buckets.size() * OFPBucket.MINIMUM_LENGTH);
86 public void readFrom(IDataBuffer data) {
88 this.groupCommand = data.getShort();
89 this.groupType = data.get();
91 this.group_id = data.getInt();
92 if (this.buckets == null) {
93 this.buckets = new ArrayList<OFPBucket>();
97 int bucketCount = (super.getLengthU() - 16) / OFPBucket.MINIMUM_LENGTH;
99 for (int i = 0; i < bucketCount; ++i) {
100 bucket = new OFPBucket();
101 bucket.readFrom(data);
102 this.buckets.add(bucket);
107 public void writeTo(IDataBuffer data) {
109 data.putShort(groupCommand);
112 data.putInt(group_id);
113 if (buckets != null) {
114 for (OFPBucket bucket : buckets) {
115 bucket.writeTo(data);
121 public int hashCode() {
122 final int prime = 227;
123 int result = super.hashCode();
124 result = prime * result + ((buckets == null) ? 0 : buckets.hashCode());
125 result = prime * result + groupCommand;
126 result = prime * result + groupType;
127 result = prime * result + group_id;
132 public boolean equals(Object obj) {
136 if (!super.equals(obj)) {
139 if (!(obj instanceof OFPGroupMod)) {
142 OFPGroupMod other = (OFPGroupMod) obj;
143 if (buckets == null) {
144 if (other.buckets != null) {
147 } else if (!buckets.equals(other.buckets)) {
150 if (groupCommand != other.groupCommand) {
153 if (groupType != other.groupType) {
156 if (group_id != other.group_id) {
165 * @see java.lang.Object#clone()
168 public OFPGroupMod clone() {
170 OFPGroupMod groupMod = (OFPGroupMod) super.clone();
171 List<OFPBucket> neoBuckets = new LinkedList<OFPBucket>();
172 for (OFPBucket bucket : this.buckets)
173 neoBuckets.add((OFPBucket) bucket.clone());
174 groupMod.setBuckets(neoBuckets);
176 } catch (CloneNotSupportedException e) {
178 throw new RuntimeException(e);
185 * @see java.lang.Object#toString()
188 public String toString() {
189 return "OFPGroupMod [ buckets=" + buckets + ", groupCommand=" + groupCommand + ", groupType=" + groupType
190 + ", group_id=" + group_id + "]";