Performacne improvements via adding a netty-based openflowj and openflow plugin;...
[controller.git] / third-party / openflowj_netty / src / main / java / org / openflow / protocol / OFQueueGetConfigReply.java
1 /**
2 *    Copyright 2012, Andrew Ferguson, Brown University
3 *
4 *    Licensed under the Apache License, Version 2.0 (the "License"); you may
5 *    not use this file except in compliance with the License. You may obtain
6 *    a copy of the License at
7 *
8 *         http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *    Unless required by applicable law or agreed to in writing, software
11 *    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 *    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 *    License for the specific language governing permissions and limitations
14 *    under the License.
15 **/
16
17 package org.openflow.protocol;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.jboss.netty.buffer.ChannelBuffer;
23 import org.openflow.util.U16;
24
25 /**
26  * Represents an ofp_queue_get_config_request message
27  * @author Andrew Ferguson (adf@cs.brown.edu)
28  */
29 public class OFQueueGetConfigReply extends OFMessage {
30     public static int MINIMUM_LENGTH = 16;
31
32     protected short portNumber;
33     protected List<OFPacketQueue> queues = new ArrayList<OFPacketQueue>();
34
35     public OFQueueGetConfigReply() {
36         super();
37         this.type = OFType.QUEUE_GET_CONFIG_REPLY;
38         this.length = U16.t(MINIMUM_LENGTH);
39     }
40
41     /**
42      * @return the portNumber
43      */
44     public short getPortNumber() {
45         return portNumber;
46     }
47
48     /**
49      * @param portNumber the portNumber to set
50      */
51     public void setPortNumber(short portNumber) {
52         this.portNumber = portNumber;
53     }
54
55     /**
56      * @return the port's queues
57      */
58     public List<OFPacketQueue> getQueues() {
59         return queues;
60     }
61
62     /**
63      * @param queues the queues to set
64      */
65     public void setQueues(List<OFPacketQueue> queues) {
66         this.queues.clear();
67         this.queues.addAll(queues);
68     }
69
70     @Override
71     public void readFrom(ChannelBuffer data) {
72         super.readFrom(data);
73         this.portNumber = data.readShort();
74         data.readInt();   // pad
75         data.readShort(); // pad
76
77         int availLength = (this.length - MINIMUM_LENGTH);
78         this.queues.clear();
79
80         while (availLength > 0) {
81             OFPacketQueue queue = new OFPacketQueue();
82             queue.readFrom(data);
83             queues.add(queue);
84             availLength -= queue.getLength();
85         }
86     }
87
88     @Override
89     public void writeTo(ChannelBuffer data) {
90         super.writeTo(data);
91         data.writeShort(this.portNumber);
92         data.writeInt(0);   // pad
93         data.writeShort(0); // pad
94
95         for (OFPacketQueue queue : queues) {
96             queue.writeTo(data);
97         }
98     }
99
100     @Override
101     public int hashCode() {
102         final int prime = 349;
103         int result = super.hashCode();
104         result = prime * result + portNumber;
105         return result;
106     }
107
108     @Override
109     public boolean equals(Object obj) {
110         if (this == obj) {
111             return true;
112         }
113         if (!super.equals(obj)) {
114             return false;
115         }
116         if (!(obj instanceof OFQueueGetConfigReply)) {
117             return false;
118         }
119         OFQueueGetConfigReply other = (OFQueueGetConfigReply) obj;
120         if (portNumber != other.portNumber) {
121             return false;
122         }
123         return true;
124     }
125 }