6ae7ce4ac818f4016931be81bdeba56500486927
[openflowjava.git] / third-party / openflow-codec / src / main / java / org / openflow / codec / protocol / OFPSwitchFeaturesReply.java
1 package org.openflow.codec.protocol;
2
3 import java.io.Serializable;
4
5 import org.openflow.codec.io.IDataBuffer;
6 import org.openflow.codec.util.U16;
7
8 /**
9  * Represents a features reply message struct ofp_switch_features
10  *
11  * @author David Erickson (daviderickson@cs.stanford.edu)
12  *
13  */
14 public class OFPSwitchFeaturesReply extends OFPMessage implements Serializable {
15     public static int MINIMUM_LENGTH = 32;
16
17     /**
18      * Corresponds to bits on the capabilities field enum ofp_capabilities
19      */
20     public enum OFCapabilities {
21         OFPC_FLOW_STATS(1 << 0), OFPC_TABLE_STATS(1 << 1), OFPC_PORT_STATS(1 << 2), OFPC_GROUP_STATS(1 << 3), OFPC_IP_REASM(
22                 1 << 5), OFPC_QUEUE_STATS(1 << 6), OFPC_PORT_BLOCKED(1 << 8);
23
24         protected int value;
25
26         private OFCapabilities(int value) {
27             this.value = value;
28         }
29
30         /**
31          * @return the value
32          */
33         public int getValue() {
34             return value;
35         }
36     }
37
38     protected long datapathId;
39     protected int buffers;
40     protected byte tables;
41     protected byte auxiliaryId;
42     protected int capabilities;
43     protected int reserved;
44
45     public OFPSwitchFeaturesReply() {
46         super();
47         this.type = OFPType.FEATURES_REPLY;
48         this.length = U16.t(MINIMUM_LENGTH);
49     }
50
51     /**
52      * @return the datapathId
53      */
54     public long getDatapathId() {
55         return datapathId;
56     }
57
58     /**
59      * @param datapathId
60      *            the datapathId to set
61      */
62     public void setDatapathId(long datapathId) {
63         this.datapathId = datapathId;
64     }
65
66     /**
67      * @return the buffers
68      */
69     public int getBuffers() {
70         return buffers;
71     }
72
73     /**
74      * @param buffers
75      *            the buffers to set
76      */
77     public void setBuffers(int buffers) {
78         this.buffers = buffers;
79     }
80
81     /**
82      * @return the tables
83      */
84     public byte getTables() {
85         return tables;
86     }
87
88     /**
89      * @param tables
90      *            the tables to set
91      */
92     public void setTables(byte tables) {
93         this.tables = tables;
94     }
95
96     /**
97      * type of connection with switch.
98      *
99      * @return 0 - main connection , non zero - auxiliary connection
100      */
101     public byte getAuxiliaryId() {
102         return auxiliaryId;
103     }
104
105     /**
106      *
107      * @param auxiliaryId
108      */
109     public void setAuxiliaryId(byte auxiliaryId) {
110         this.auxiliaryId = auxiliaryId;
111     }
112
113     /**
114      * @return the capabilities
115      */
116     public int getCapabilities() {
117         return capabilities;
118     }
119
120     /**
121      * @param capabilities
122      *            the capabilities to set
123      */
124     public void setCapabilities(int capabilities) {
125         this.capabilities = capabilities;
126     }
127
128     public int getReserved() {
129         return reserved;
130     }
131
132     public void setReserved(int reserved) {
133         this.reserved = reserved;
134     }
135
136     @Override
137     public void readFrom(IDataBuffer data) {
138         super.readFrom(data);
139         this.datapathId = data.getLong();
140         this.buffers = data.getInt();
141         this.tables = data.get();
142         this.auxiliaryId = data.get();
143         data.getShort(); // pad
144         this.capabilities = data.getInt();
145         this.reserved = data.getInt();
146     }
147
148     @Override
149     public void writeTo(IDataBuffer data) {
150         super.writeTo(data);
151         data.putLong(this.datapathId);
152         data.putInt(this.buffers);
153         data.put(this.tables);
154         data.put(this.auxiliaryId);
155         data.putShort((short) 0); // pad
156         data.putInt(this.capabilities);
157         data.putInt(this.reserved);
158     }
159
160     @Override
161     public int hashCode() {
162         final int prime = 139;
163         int result = super.hashCode();
164         result = prime * result + auxiliaryId;
165         result = prime * result + buffers;
166         result = prime * result + capabilities;
167         result = prime * result + reserved;
168         result = prime * result + (int) (datapathId ^ (datapathId >>> 32));
169         result = prime * result + tables;
170         return result;
171     }
172
173     @Override
174     public boolean equals(Object obj) {
175         if (this == obj) {
176             return true;
177         }
178         if (!super.equals(obj)) {
179             return false;
180         }
181         if (!(obj instanceof OFPSwitchFeaturesReply)) {
182             return false;
183         }
184         OFPSwitchFeaturesReply other = (OFPSwitchFeaturesReply) obj;
185         if (auxiliaryId != other.auxiliaryId) {
186             return false;
187         }
188         if (reserved != other.reserved) {
189             return false;
190         }
191         if (buffers != other.buffers) {
192             return false;
193         }
194         if (capabilities != other.capabilities) {
195             return false;
196         }
197         if (datapathId != other.datapathId) {
198             return false;
199         }
200         if (tables != other.tables) {
201             return false;
202         }
203         return true;
204     }
205 }