Initial opendaylight infrastructure commit!!
[controller.git] / third-party / openflowj / src / main / java / org / openflow / protocol / OFQueueConfigReply.java
1 package org.openflow.protocol;
2
3 import java.nio.ByteBuffer;
4 import java.util.ArrayList;
5 import java.util.List;
6
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;
11
12 /**
13  *
14  * @author David Erickson (daviderickson@cs.stanford.edu)
15  */
16 public class OFQueueConfigReply extends OFMessage implements Cloneable, OFQueuePropertyFactoryAware {
17     public static int MINIMUM_LENGTH = 16;
18
19     protected OFQueuePropertyFactory queuePropertyFactory;
20
21     protected short port;
22     protected List<OFPacketQueue> queues;
23
24     /**
25      * 
26      */
27     public OFQueueConfigReply() {
28         super();
29         this.type = OFType.QUEUE_CONFIG_REPLY;
30         this.length = U16.t(MINIMUM_LENGTH);
31     }
32
33     /**
34      * @return the port
35      */
36     public short getPort() {
37         return port;
38     }
39
40     /**
41      * @param port the port to set
42      */
43     public OFQueueConfigReply setPort(short port) {
44         this.port = port;
45         return this;
46     }
47
48     /**
49      * @return the queues
50      */
51     public List<OFPacketQueue> getQueues() {
52         return queues;
53     }
54
55     /**
56      * @param queues the queues to set
57      */
58     public void setQueues(List<OFPacketQueue> queues) {
59         this.queues = queues;
60     }
61
62     @Override
63     public void readFrom(ByteBuffer data) {
64         super.readFrom(data);
65         this.port = data.getShort();
66         data.getShort(); // pad
67         data.getInt(); // 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);
75             queue.readFrom(data);
76             remaining -= U16.f(queue.getLength());
77             this.queues.add(queue);
78         }
79     }
80
81     @Override
82     public void writeTo(ByteBuffer data) {
83         super.writeTo(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) {
89                 queue.writeTo(data);
90             }
91         }
92     }
93
94     @Override
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());
100         return result;
101     }
102
103     @Override
104     public boolean equals(Object obj) {
105         if (this == obj)
106             return true;
107         if (!super.equals(obj))
108             return false;
109         if (!(obj instanceof OFQueueConfigReply))
110             return false;
111         OFQueueConfigReply other = (OFQueueConfigReply) obj;
112         if (port != other.port)
113             return false;
114         if (queues == null) {
115             if (other.queues != null)
116                 return false;
117         } else if (!queues.equals(other.queues))
118             return false;
119         return true;
120     }
121
122     @Override
123     public void setQueuePropertyFactory(
124             OFQueuePropertyFactory queuePropertyFactory) {
125         this.queuePropertyFactory = queuePropertyFactory;
126     }
127
128     @Override
129     public OFQueueConfigReply clone() {
130         try {
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());
136                 }
137                 clone.setQueues(queues);
138             }
139             return clone;
140         } catch (CloneNotSupportedException e) {
141             throw new RuntimeException(e);
142         }
143     }
144
145     @Override
146     public String toString() {
147         return "OFQueueConfigReply [port=" + U16.f(port) + ", queues=" + queues
148                 + ", xid=" + xid + "]";
149     }
150 }