0ec2fa3312887224e4647f8ebce96cfdd366be8d
[controller.git] / third-party / openflowj_netty / src / main / java / org / openflow / protocol / action / OFActionEnqueue.java
1 /**
2 *    Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
3 *    University
4
5 *    Licensed under the Apache License, Version 2.0 (the "License"); you may
6 *    not use this file except in compliance with the License. You may obtain
7 *    a copy of the License at
8 *
9 *         http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *    Unless required by applicable law or agreed to in writing, software
12 *    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 *    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 *    License for the specific language governing permissions and limitations
15 *    under the License.
16 **/
17
18 /**
19  * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
20  */
21 package org.openflow.protocol.action;
22
23
24 import org.jboss.netty.buffer.ChannelBuffer;
25
26 /**
27  * Represents an ofp_action_enqueue
28  * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
29  */
30 public class OFActionEnqueue extends OFAction {
31     public static int MINIMUM_LENGTH = 16;
32
33     protected short port;
34     protected int queueId;
35
36     public OFActionEnqueue() {
37         super.setType(OFActionType.OPAQUE_ENQUEUE);
38         super.setLength((short) MINIMUM_LENGTH);
39     }
40     
41     public OFActionEnqueue(short port, int queueId) {
42         this();
43         this.port = port;
44         this.queueId = queueId;
45     }
46
47     /**
48      * Get the output port
49      * @return
50      */
51     public short getPort() {
52         return this.port;
53     }
54
55     /**
56      * Set the output port
57      * @param port
58      */
59     public void setPort(short port) {
60         this.port = port;
61     }
62
63     /**
64      * @return the queueId
65      */
66     public int getQueueId() {
67         return queueId;
68     }
69
70     /**
71      * @param queueId the queueId to set
72      */
73     public void setQueueId(int queueId) {
74         this.queueId = queueId;
75     }
76
77     @Override
78     public void readFrom(ChannelBuffer data) {
79         super.readFrom(data);
80         this.port = data.readShort();
81         data.readShort();
82         data.readInt();
83         this.queueId = data.readInt();
84     }
85
86     @Override
87     public void writeTo(ChannelBuffer data) {
88         super.writeTo(data);
89         data.writeShort(this.port);
90         data.writeShort((short) 0);
91         data.writeInt(0);
92         data.writeInt(this.queueId);
93     }
94
95     @Override
96     public int hashCode() {
97         final int prime = 349;
98         int result = super.hashCode();
99         result = prime * result + port;
100         result = prime * result + queueId;
101         return result;
102     }
103
104     @Override
105     public boolean equals(Object obj) {
106         if (this == obj) {
107             return true;
108         }
109         if (!super.equals(obj)) {
110             return false;
111         }
112         if (!(obj instanceof OFActionEnqueue)) {
113             return false;
114         }
115         OFActionEnqueue other = (OFActionEnqueue) obj;
116         if (port != other.port) {
117             return false;
118         }
119         if (queueId != other.queueId) {
120             return false;
121         }
122         return true;
123     }
124 }