2 * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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
18 package org.openflow.protocol;
20 import java.util.ArrayList;
21 import java.util.List;
25 import org.jboss.netty.buffer.ChannelBuffer;
26 import org.openflow.util.U16;
30 * Represents a features reply message
31 * @author David Erickson (daviderickson@cs.stanford.edu)
35 public class OFFeaturesReply extends OFMessage {
36 public static int MINIMUM_LENGTH = 32;
39 * Corresponds to bits on the capabilities field
41 public enum OFCapabilities {
42 OFPC_FLOW_STATS (1 << 0),
43 OFPC_TABLE_STATS (1 << 1),
44 OFPC_PORT_STATS (1 << 2),
46 OFPC_RESERVED (1 << 4),
47 OFPC_IP_REASM (1 << 5),
48 OFPC_QUEUE_STATS (1 << 6),
49 OFPC_ARP_MATCH_IP (1 << 7);
53 private OFCapabilities(int value) {
60 public int getValue() {
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;
72 public OFFeaturesReply() {
74 this.type = OFType.FEATURES_REPLY;
75 this.length = U16.t(MINIMUM_LENGTH);
79 * @return the datapathId
81 public long getDatapathId() {
86 * @param datapathId the datapathId to set
88 public void setDatapathId(long datapathId) {
89 this.datapathId = datapathId;
95 public int getBuffers() {
100 * @param buffers the buffers to set
102 public void setBuffers(int buffers) {
103 this.buffers = buffers;
109 public byte getTables() {
114 * @param tables the tables to set
116 public void setTables(byte tables) {
117 this.tables = tables;
121 * @return the capabilities
123 public int getCapabilities() {
128 * @param capabilities the capabilities to set
130 public void setCapabilities(int capabilities) {
131 this.capabilities = capabilities;
135 * @return the actions
137 public int getActions() {
142 * @param actions the actions to set
144 public void setActions(int actions) {
145 this.actions = actions;
151 public List<OFPhysicalPort> getPorts() {
156 * @param ports the ports to set
158 public void setPorts(List<OFPhysicalPort> ports) {
161 this.setLengthU(MINIMUM_LENGTH);
163 this.setLengthU(MINIMUM_LENGTH + ports.size()
164 * OFPhysicalPort.MINIMUM_LENGTH);
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>();
182 int portCount = (super.getLengthU() - 32)
183 / OFPhysicalPort.MINIMUM_LENGTH;
185 for (int i = 0; i < portCount; ++i) {
186 port = new OFPhysicalPort();
188 this.ports.add(port);
193 public void writeTo(ChannelBuffer 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) {
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;
222 public boolean equals(Object obj) {
226 if (!super.equals(obj)) {
229 if (!(obj instanceof OFFeaturesReply)) {
232 OFFeaturesReply other = (OFFeaturesReply) obj;
233 if (actions != other.actions) {
236 if (buffers != other.buffers) {
239 if (capabilities != other.capabilities) {
242 if (datapathId != other.datapathId) {
246 if (other.ports != null) {
249 } else if (!ports.equals(other.ports)) {
252 if (tables != other.tables) {