1 package org.openflow.protocol;
3 import java.io.Serializable;
4 import java.nio.ByteBuffer;
5 import java.util.ArrayList;
8 import org.openflow.util.U16;
12 * Represents a features reply message
13 * @author David Erickson (daviderickson@cs.stanford.edu)
16 public class OFFeaturesReply extends OFMessage implements Serializable {
17 public static int MINIMUM_LENGTH = 32;
20 * Corresponds to bits on the capabilities field
22 public enum OFCapabilities {
23 OFPC_FLOW_STATS (1 << 0),
24 OFPC_TABLE_STATS (1 << 1),
25 OFPC_PORT_STATS (1 << 2),
27 OFPC_RESERVED (1 << 4),
28 OFPC_IP_REASM (1 << 5),
29 OFPC_QUEUE_STATS (1 << 6),
30 OFPC_ARP_MATCH_IP (1 << 7);
34 private OFCapabilities(int value) {
41 public int getValue() {
46 protected long datapathId;
47 protected int buffers;
48 protected byte tables;
49 protected int capabilities;
50 protected int actions;
51 protected List<OFPhysicalPort> ports;
53 public OFFeaturesReply() {
55 this.type = OFType.FEATURES_REPLY;
56 this.length = U16.t(MINIMUM_LENGTH);
60 * @return the datapathId
62 public long getDatapathId() {
67 * @param datapathId the datapathId to set
69 public void setDatapathId(long datapathId) {
70 this.datapathId = datapathId;
76 public int getBuffers() {
81 * @param buffers the buffers to set
83 public void setBuffers(int buffers) {
84 this.buffers = buffers;
90 public byte getTables() {
95 * @param tables the tables to set
97 public void setTables(byte tables) {
102 * @return the capabilities
104 public int getCapabilities() {
109 * @param capabilities the capabilities to set
111 public void setCapabilities(int capabilities) {
112 this.capabilities = capabilities;
116 * @return the actions
118 public int getActions() {
123 * @param actions the actions to set
125 public void setActions(int actions) {
126 this.actions = actions;
132 public List<OFPhysicalPort> getPorts() {
137 * @param ports the ports to set
139 public void setPorts(List<OFPhysicalPort> ports) {
142 this.setLengthU(MINIMUM_LENGTH);
144 this.setLengthU(MINIMUM_LENGTH + ports.size()
145 * OFPhysicalPort.MINIMUM_LENGTH);
150 public void readFrom(ByteBuffer data) {
151 super.readFrom(data);
152 this.datapathId = data.getLong();
153 this.buffers = data.getInt();
154 this.tables = data.get();
155 data.position(data.position() + 3); // pad
156 this.capabilities = data.getInt();
157 this.actions = data.getInt();
158 if (this.ports == null) {
159 this.ports = new ArrayList<OFPhysicalPort>();
163 int portCount = (super.getLengthU() - 32)
164 / OFPhysicalPort.MINIMUM_LENGTH;
166 for (int i = 0; i < portCount; ++i) {
167 port = new OFPhysicalPort();
169 this.ports.add(port);
174 public void writeTo(ByteBuffer data) {
176 data.putLong(this.datapathId);
177 data.putInt(this.buffers);
178 data.put(this.tables);
179 data.putShort((short) 0); // pad
180 data.put((byte) 0); // pad
181 data.putInt(this.capabilities);
182 data.putInt(this.actions);
183 if (this.ports != null)
184 for (OFPhysicalPort port : this.ports) {
190 public int hashCode() {
191 final int prime = 139;
192 int result = super.hashCode();
193 result = prime * result + actions;
194 result = prime * result + buffers;
195 result = prime * result + capabilities;
196 result = prime * result + (int) (datapathId ^ (datapathId >>> 32));
197 result = prime * result + ((ports == null) ? 0 : ports.hashCode());
198 result = prime * result + tables;
203 public boolean equals(Object obj) {
207 if (!super.equals(obj)) {
210 if (!(obj instanceof OFFeaturesReply)) {
213 OFFeaturesReply other = (OFFeaturesReply) obj;
214 if (actions != other.actions) {
217 if (buffers != other.buffers) {
220 if (capabilities != other.capabilities) {
223 if (datapathId != other.datapathId) {
227 if (other.ports != null) {
230 } else if (!ports.equals(other.ports)) {
233 if (tables != other.tables) {