1 package org.openflow.protocol.queue;
3 import java.nio.ByteBuffer;
4 import java.util.ArrayList;
7 import org.openflow.protocol.factory.OFQueuePropertyFactory;
8 import org.openflow.protocol.factory.OFQueuePropertyFactoryAware;
9 import org.openflow.util.U16;
12 * Corresponds to the struct ofp_packet_queue OpenFlow structure
14 * @author David Erickson (daviderickson@cs.stanford.edu)
16 public class OFPacketQueue implements Cloneable, OFQueuePropertyFactoryAware {
17 public static int MINIMUM_LENGTH = 8;
19 protected OFQueuePropertyFactory queuePropertyFactory;
21 protected int queueId;
22 protected short length;
23 protected List<OFQueueProperty> properties;
28 public int getQueueId() {
33 * @param queueId the queueId to set
35 public OFPacketQueue setQueueId(int queueId) {
36 this.queueId = queueId;
43 public short getLength() {
48 * @param length the length to set
50 public void setLength(short length) {
55 * @return the properties
57 public List<OFQueueProperty> getProperties() {
62 * @param properties the properties to set
64 public OFPacketQueue setProperties(List<OFQueueProperty> properties) {
65 this.properties = properties;
69 public void readFrom(ByteBuffer data) {
70 this.queueId = data.getInt();
71 this.length = data.getShort();
72 data.getShort(); // pad
73 if (this.queuePropertyFactory == null)
74 throw new RuntimeException("OFQueuePropertyFactory not set");
75 this.properties = queuePropertyFactory.parseQueueProperties(data,
76 U16.f(this.length) - MINIMUM_LENGTH);
79 public void writeTo(ByteBuffer data) {
80 data.putInt(this.queueId);
81 data.putShort(this.length);
82 data.putShort((short) 0); // pad
83 if (this.properties != null) {
84 for (OFQueueProperty queueProperty : this.properties) {
85 queueProperty.writeTo(data);
91 public int hashCode() {
92 final int prime = 6367;
94 result = prime * result + length;
95 result = prime * result
96 + ((properties == null) ? 0 : properties.hashCode());
97 result = prime * result + queueId;
102 public boolean equals(Object obj) {
107 if (!(obj instanceof OFPacketQueue))
109 OFPacketQueue other = (OFPacketQueue) obj;
110 if (length != other.length)
112 if (properties == null) {
113 if (other.properties != null)
115 } else if (!properties.equals(other.properties))
117 if (queueId != other.queueId)
123 public OFPacketQueue clone() {
125 OFPacketQueue clone = (OFPacketQueue) super.clone();
126 if (this.properties != null) {
127 List<OFQueueProperty> queueProps = new ArrayList<OFQueueProperty>();
128 for (OFQueueProperty prop : this.properties) {
129 queueProps.add(prop.clone());
131 clone.setProperties(queueProps);
134 } catch (CloneNotSupportedException e) {
135 throw new RuntimeException(e);
140 public void setQueuePropertyFactory(
141 OFQueuePropertyFactory queuePropertyFactory) {
142 this.queuePropertyFactory = queuePropertyFactory;
146 * @see java.lang.Object#toString()
149 public String toString() {
150 return "OFPacketQueue [queueId=" + queueId + ", properties="