blob: f5a836e7f73cadbee56f28a6824eccefdaccb639 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
3* University
4*
5* Licensed under the Apache License, Version 2.0 (the "License"); you may
6* not use this file except in compliance with the License. You may obtain
7* a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14* License for the specific language governing permissions and limitations
15* under the License.
16**/
17
18package org.openflow.protocol;
19
20import java.util.ArrayList;
21import java.util.List;
22
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080023import org.codehaus.jackson.map.annotate.JsonSerialize;
24import org.jboss.netty.buffer.ChannelBuffer;
25import org.openflow.protocol.serializers.OFFeaturesReplyJSONSerializer;
26import org.openflow.util.U16;
27
28
29/**
30 * Represents a features reply message
31 * @author David Erickson (daviderickson@cs.stanford.edu)
32 *
33 */
34@JsonSerialize(using=OFFeaturesReplyJSONSerializer.class)
35public class OFFeaturesReply extends OFMessage {
36 public static int MINIMUM_LENGTH = 32;
37
38 /**
39 * Corresponds to bits on the capabilities field
40 */
41 public enum OFCapabilities {
42 OFPC_FLOW_STATS (1 << 0),
43 OFPC_TABLE_STATS (1 << 1),
44 OFPC_PORT_STATS (1 << 2),
45 OFPC_STP (1 << 3),
46 OFPC_RESERVED (1 << 4),
47 OFPC_IP_REASM (1 << 5),
48 OFPC_QUEUE_STATS (1 << 6),
49 OFPC_ARP_MATCH_IP (1 << 7);
50
51 protected int value;
52
53 private OFCapabilities(int value) {
54 this.value = value;
55 }
56
57 /**
58 * @return the value
59 */
60 public int getValue() {
61 return value;
62 }
63 }
64
65 protected long datapathId;
66 protected int buffers;
67 protected byte tables;
68 protected int capabilities;
69 protected int actions;
70 protected List<OFPhysicalPort> ports;
71
72 public OFFeaturesReply() {
73 super();
74 this.type = OFType.FEATURES_REPLY;
75 this.length = U16.t(MINIMUM_LENGTH);
76 }
77
78 /**
79 * @return the datapathId
80 */
81 public long getDatapathId() {
82 return datapathId;
83 }
84
85 /**
86 * @param datapathId the datapathId to set
87 */
88 public void setDatapathId(long datapathId) {
89 this.datapathId = datapathId;
90 }
91
92 /**
93 * @return the buffers
94 */
95 public int getBuffers() {
96 return buffers;
97 }
98
99 /**
100 * @param buffers the buffers to set
101 */
102 public void setBuffers(int buffers) {
103 this.buffers = buffers;
104 }
105
106 /**
107 * @return the tables
108 */
109 public byte getTables() {
110 return tables;
111 }
112
113 /**
114 * @param tables the tables to set
115 */
116 public void setTables(byte tables) {
117 this.tables = tables;
118 }
119
120 /**
121 * @return the capabilities
122 */
123 public int getCapabilities() {
124 return capabilities;
125 }
126
127 /**
128 * @param capabilities the capabilities to set
129 */
130 public void setCapabilities(int capabilities) {
131 this.capabilities = capabilities;
132 }
133
134 /**
135 * @return the actions
136 */
137 public int getActions() {
138 return actions;
139 }
140
141 /**
142 * @param actions the actions to set
143 */
144 public void setActions(int actions) {
145 this.actions = actions;
146 }
147
148 /**
149 * @return the ports
150 */
151 public List<OFPhysicalPort> getPorts() {
152 return ports;
153 }
154
155 /**
156 * @param ports the ports to set
157 */
158 public void setPorts(List<OFPhysicalPort> ports) {
159 this.ports = ports;
160 if (ports == null) {
161 this.setLengthU(MINIMUM_LENGTH);
162 } else {
163 this.setLengthU(MINIMUM_LENGTH + ports.size()
164 * OFPhysicalPort.MINIMUM_LENGTH);
165 }
166 }
167
168 @Override
169 public void readFrom(ChannelBuffer data) {
170 super.readFrom(data);
171 this.datapathId = data.readLong();
172 this.buffers = data.readInt();
173 this.tables = data.readByte();
174 data.readerIndex(data.readerIndex() + 3); // pad
175 this.capabilities = data.readInt();
176 this.actions = data.readInt();
177 if (this.ports == null) {
178 this.ports = new ArrayList<OFPhysicalPort>();
179 } else {
180 this.ports.clear();
181 }
182 int portCount = (super.getLengthU() - 32)
183 / OFPhysicalPort.MINIMUM_LENGTH;
184 OFPhysicalPort port;
185 for (int i = 0; i < portCount; ++i) {
186 port = new OFPhysicalPort();
187 port.readFrom(data);
188 this.ports.add(port);
189 }
190 }
191
192 @Override
193 public void writeTo(ChannelBuffer data) {
194 super.writeTo(data);
195 data.writeLong(this.datapathId);
196 data.writeInt(this.buffers);
197 data.writeByte(this.tables);
198 data.writeShort((short) 0); // pad
199 data.writeByte((byte) 0); // pad
200 data.writeInt(this.capabilities);
201 data.writeInt(this.actions);
202 if (this.ports != null)
203 for (OFPhysicalPort port : this.ports) {
204 port.writeTo(data);
205 }
206 }
207
208 @Override
209 public int hashCode() {
210 final int prime = 139;
211 int result = super.hashCode();
212 result = prime * result + actions;
213 result = prime * result + buffers;
214 result = prime * result + capabilities;
215 result = prime * result + (int) (datapathId ^ (datapathId >>> 32));
216 result = prime * result + ((ports == null) ? 0 : ports.hashCode());
217 result = prime * result + tables;
218 return result;
219 }
220
221 @Override
222 public boolean equals(Object obj) {
223 if (this == obj) {
224 return true;
225 }
226 if (!super.equals(obj)) {
227 return false;
228 }
229 if (!(obj instanceof OFFeaturesReply)) {
230 return false;
231 }
232 OFFeaturesReply other = (OFFeaturesReply) obj;
233 if (actions != other.actions) {
234 return false;
235 }
236 if (buffers != other.buffers) {
237 return false;
238 }
239 if (capabilities != other.capabilities) {
240 return false;
241 }
242 if (datapathId != other.datapathId) {
243 return false;
244 }
245 if (ports == null) {
246 if (other.ports != null) {
247 return false;
248 }
249 } else if (!ports.equals(other.ports)) {
250 return false;
251 }
252 if (tables != other.tables) {
253 return false;
254 }
255 return true;
256 }
257}