940b36dd19c13950cfa7917e0c626a464e4ec72f
[openflowjava.git] / third-party / openflow-codec / src / main / java / org / openflow / codec / protocol / statistics / OFPGroupFeatures.java
1 package org.openflow.codec.protocol.statistics;
2
3 import java.io.Serializable;
4 import java.util.Arrays;
5
6 import org.openflow.codec.io.IDataBuffer;
7
8 /**
9  * Represents an ofp_group_features structure
10  *
11  * @author Yugandhar Sarraju
12  */
13 public class OFPGroupFeatures implements OFPStatistics, Serializable {
14
15     private static final int MINIMUM_LENGTH = 40;
16
17     /**
18      * represents ofp_group_capabilities
19      *
20      */
21     public enum OFGroupCapabilities {
22         OFPGFC_SELECT_WEIGHT(1 << 0), /* Support weight for select groups */
23         OFPGFC_SELECT_LIVENESS(1 << 1), /* Support liveness for select groups */
24         OFPGFC_CHAINING(1 << 2), /* Support chaining groups */
25         OFPGFC_CHAINING_CHECKS(1 << 3); /* Check chaining for loops and delete */
26
27         protected int value;
28
29         private OFGroupCapabilities(int value) {
30             this.value = value;
31         }
32
33         /**
34          * @return the value
35          */
36         public int getValue() {
37             return value;
38         }
39     }
40
41     private short length = MINIMUM_LENGTH;
42     private int types;
43     private int capabilities;
44     private int[] max_groups;
45     private int[] actions;
46
47     public int getTypes() {
48         return types;
49     }
50
51     public void setTypes(int types) {
52         this.types = types;
53     }
54
55     public int getCapabilities() {
56         return capabilities;
57     }
58
59     public void setCapabilities(int capabilities) {
60         this.capabilities = capabilities;
61     }
62
63     public int[] getMax_groups() {
64         return max_groups;
65     }
66
67     public void setMax_groups(int[] max_groups) {
68         if (max_groups.length != 4)
69             throw new RuntimeException("Max Groups must have length " + 4);
70         this.max_groups = max_groups;
71     }
72
73     public int[] getActions() {
74         return actions;
75     }
76
77     public void setActions(int[] actions) {
78         if (actions.length != 4)
79             throw new RuntimeException("Actions must have length " + 4);
80         this.actions = actions;
81     }
82
83     @Override
84     public int getLength() {
85         return length;
86     }
87
88     @Override
89     public void readFrom(IDataBuffer data) {
90
91         this.types = data.getInt();
92         this.capabilities = data.getInt();
93         if (this.max_groups == null)
94             this.max_groups = new int[4];
95         for (int i = 0; i < 4; i++) {
96             this.max_groups[i] = data.getInt();
97         }
98         if (this.actions == null)
99             this.actions = new int[4];
100         for (int i = 0; i < 4; i++) {
101             this.actions[i] = data.getInt();
102         }
103     }
104
105     @Override
106     public void writeTo(IDataBuffer data) {
107
108         data.putInt(this.types);
109         data.putInt(this.capabilities);
110         for (int i = 0; i < 4; i++) {
111             data.putInt(this.max_groups[i]);
112         }
113         for (int i = 0; i < 4; i++) {
114             data.putInt(this.actions[i]);
115         }
116     }
117
118     @Override
119     public int hashCode() {
120         final int prime = 457;
121         int result = 1;
122         result = prime * result + types;
123         result = prime * result + capabilities;
124         result = prime * Arrays.hashCode(getMax_groups());
125         result = prime * Arrays.hashCode(actions);
126         return result;
127     }
128
129     @Override
130     public boolean equals(Object obj) {
131         if (this == obj) {
132             return true;
133         }
134         if (obj == null) {
135             return false;
136         }
137         if (!(obj instanceof OFPGroupFeatures)) {
138             return false;
139         }
140         OFPGroupFeatures other = (OFPGroupFeatures) obj;
141         if (types != other.types) {
142             return false;
143         }
144         if (capabilities != other.capabilities) {
145             return false;
146         }
147         if (!Arrays.equals(max_groups, other.max_groups)) {
148             return false;
149         }
150         if (!Arrays.equals(actions, other.actions)) {
151             return false;
152         }
153         return true;
154     }
155
156 }