1 package org.openflow.codec.protocol.statistics;
3 import java.io.Serializable;
6 import org.openflow.codec.io.IDataBuffer;
7 import org.openflow.codec.protocol.factory.OFPTableFeaturePropFactory;
8 import org.openflow.codec.protocol.factory.OFPTableFeaturePropFactoryAware;
9 import org.openflow.codec.protocol.statistics.table.OFPTableFeaturePropHeader;
10 import org.openflow.codec.util.StringByteSerializer;
13 * Represents an ofp_table_features structure
17 public class OFPTableFeatures implements OFPStatistics,
18 OFPTableFeaturePropFactoryAware, Serializable
20 private static final int MINIMUM_LENGTH = 64;
21 private static final int MAX_TABLE_NAME_LEN = 32;
23 private short length = MINIMUM_LENGTH;
26 private long metadataMatch;
27 private long metadataWrite;
29 private int maxEntries;
30 private List<OFPTableFeaturePropHeader> properties;
32 private OFPTableFeaturePropFactory tableFeaturePropFactory;
37 public byte getTableId()
46 public void setTableId(byte tableId)
48 this.tableId = tableId;
55 public String getName()
64 public void setName(String name)
73 public long getMetadataMatch()
80 * @param metadataMatch
82 public void setMetadataMatch(long metadataMatch)
84 this.metadataMatch = metadataMatch;
91 public long getMetadataWrite()
98 * @param metadataWrite
100 public void setMetadataWrite(long metadataWrite)
102 this.metadataWrite = metadataWrite;
109 public int getConfig()
118 public void setConfig(int config)
120 this.config = config;
127 public int getMaxEntries()
136 public void setMaxEntries(int maxEntries)
138 this.maxEntries = maxEntries;
145 public List<OFPTableFeaturePropHeader> getProperties()
154 public void setProperties(List<OFPTableFeaturePropHeader> properties)
156 this.properties = properties;
161 * update length TODO: All the associated properties are 8 byte (64 bits)
162 * aligned. Length of each property excludes the padding, if we sum up each
163 * associated property length it will give us length excluding the total
164 * bytes of padding added to make it align. We assume that table feature
165 * response message switch will send in response to OFPMP_TABLE_FEATURES
166 * request, will also consider padding in the message lengh. Something to
167 * cross check with switch implementation.
169 private void updateLength()
171 length = MINIMUM_LENGTH;
172 if (null != properties)
174 for (OFPTableFeaturePropHeader prop : properties)
176 int len = prop.getLengthU();
177 /* Add the aligned length, including padding */
178 length += len + (8 - (len % 8));
185 public int getLength()
191 public void readFrom(IDataBuffer data)
194 this.length = data.getShort();
195 this.tableId = data.get();
197 data.getInt(); // pad
198 this.name = StringByteSerializer.readFrom(data, MAX_TABLE_NAME_LEN);
199 this.metadataMatch = data.getLong();
200 this.metadataWrite = data.getLong();
201 this.config = data.getInt();
202 this.maxEntries = data.getInt();
203 int propLength = this.length - OFPTableFeatures.MINIMUM_LENGTH;
204 if (null == this.tableFeaturePropFactory)
205 throw new RuntimeException("OFPTableFeaturePropFactory is not set");
206 this.properties = tableFeaturePropFactory.parseTableFeatureProp(data,
208 if (this.properties.isEmpty())
216 public void writeTo(IDataBuffer data)
219 data.putShort(length);
220 data.put(this.tableId);
221 data.put((byte) 0); // pad
222 data.putInt(0); // pad
223 StringByteSerializer.writeTo(data, MAX_TABLE_NAME_LEN, this.name);
224 data.putLong(this.metadataMatch);
225 data.putLong(this.metadataWrite);
226 data.putInt(this.config);
227 data.putInt(this.maxEntries);
228 if (null != properties)
230 for (OFPTableFeaturePropHeader prop : properties)
238 public int hashCode()
240 final int prime = 4491;
242 result = prime * result + maxEntries;
243 result = prime * result + config;
244 result = prime * result
245 + (int) (metadataMatch ^ (metadataMatch >>> 32));
246 result = prime * result
247 + (int) (metadataWrite ^ (metadataWrite >>> 32));
248 result = prime * result + ((name == null) ? 0 : name.hashCode());
249 result = prime * result + tableId;
250 result = prime * result + length;
251 result = prime * result
252 + ((properties == null) ? 0 : properties.hashCode());
257 public boolean equals(Object obj)
267 if (!(obj instanceof OFPTableFeatures))
271 OFPTableFeatures other = (OFPTableFeatures) obj;
272 if (maxEntries != other.maxEntries)
276 if (config != other.config)
280 if (metadataMatch != other.metadataMatch)
284 if (metadataWrite != other.metadataWrite)
288 if (length != other.length)
292 if (tableId != other.tableId)
298 if (other.name != null)
302 } else if (!name.equals(other.name))
306 if (properties == null)
308 if (other.properties != null)
312 } else if (!properties.equals(other.properties))
320 public void setTableFeaturePropFactory(
321 OFPTableFeaturePropFactory tableFeaturePropFactory)
324 this.tableFeaturePropFactory = tableFeaturePropFactory;