1 package org.openflow.protocol;
3 import java.nio.ByteBuffer;
4 import java.util.ArrayList;
7 import org.openflow.util.U16;
8 import org.openflow.protocol.factory.OFQueuePropertyFactory;
9 import org.openflow.protocol.factory.OFQueuePropertyFactoryAware;
10 import org.openflow.protocol.queue.OFPacketQueue;
14 * @author David Erickson (daviderickson@cs.stanford.edu)
16 public class OFQueueConfigReply extends OFMessage implements Cloneable, OFQueuePropertyFactoryAware {
17 public static int MINIMUM_LENGTH = 16;
19 protected OFQueuePropertyFactory queuePropertyFactory;
22 protected List<OFPacketQueue> queues;
27 public OFQueueConfigReply() {
29 this.type = OFType.QUEUE_CONFIG_REPLY;
30 this.length = U16.t(MINIMUM_LENGTH);
36 public short getPort() {
41 * @param port the port to set
43 public OFQueueConfigReply setPort(short port) {
51 public List<OFPacketQueue> getQueues() {
56 * @param queues the queues to set
58 public void setQueues(List<OFPacketQueue> queues) {
63 public void readFrom(ByteBuffer data) {
65 this.port = data.getShort();
66 data.getShort(); // pad
68 int remaining = this.getLengthU() - MINIMUM_LENGTH;
69 if (data.remaining() < remaining)
70 remaining = data.remaining();
71 this.queues = new ArrayList<OFPacketQueue>();
72 while (remaining >= OFPacketQueue.MINIMUM_LENGTH) {
73 OFPacketQueue queue = new OFPacketQueue();
74 queue.setQueuePropertyFactory(this.queuePropertyFactory);
76 remaining -= U16.f(queue.getLength());
77 this.queues.add(queue);
82 public void writeTo(ByteBuffer data) {
84 data.putShort(this.port);
85 data.putShort((short) 0); // pad
86 data.putInt(0); // pad
87 if (this.queues != null) {
88 for (OFPacketQueue queue : this.queues) {
95 public int hashCode() {
96 final int prime = 4549;
97 int result = super.hashCode();
98 result = prime * result + port;
99 result = prime * result + ((queues == null) ? 0 : queues.hashCode());
104 public boolean equals(Object obj) {
107 if (!super.equals(obj))
109 if (!(obj instanceof OFQueueConfigReply))
111 OFQueueConfigReply other = (OFQueueConfigReply) obj;
112 if (port != other.port)
114 if (queues == null) {
115 if (other.queues != null)
117 } else if (!queues.equals(other.queues))
123 public void setQueuePropertyFactory(
124 OFQueuePropertyFactory queuePropertyFactory) {
125 this.queuePropertyFactory = queuePropertyFactory;
129 public OFQueueConfigReply clone() {
131 OFQueueConfigReply clone = (OFQueueConfigReply) super.clone();
132 if (this.queues != null) {
133 List<OFPacketQueue> queues = new ArrayList<OFPacketQueue>();
134 for (OFPacketQueue queue : this.queues) {
135 queues.add(queue.clone());
137 clone.setQueues(queues);
140 } catch (CloneNotSupportedException e) {
141 throw new RuntimeException(e);
146 public String toString() {
147 return "OFQueueConfigReply [port=" + U16.f(port) + ", queues=" + queues
148 + ", xid=" + xid + "]";