b9521d09aa2d7dfb0fe6f8b6592f42feacb92e5e
[controller.git] / third-party / openflowj_netty / src / main / java / org / openflow / protocol / action / OFActionOutput.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 import org.openflow.util.U16;
26
27 /**
28  * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
29  * @author Rob Sherwood (rob.sherwood@stanford.edu)
30  */
31 public class OFActionOutput extends OFAction implements Cloneable {
32     public static int MINIMUM_LENGTH = 8;
33
34     protected short port;
35     protected short maxLength;
36
37     public OFActionOutput() {
38         super.setType(OFActionType.OUTPUT);
39         super.setLength((short) MINIMUM_LENGTH);
40     }
41
42     /**
43      * Create an Output Action sending packets out the specified
44      * OpenFlow port.
45      *
46      * This is the most common creation pattern for OFActions.
47      *
48      * @param port
49      */
50
51     public OFActionOutput(short port) {
52         this(port, (short) 65535);
53     }
54
55     /**
56      * Create an Output Action specifying both the port AND
57      * the snaplen of the packet to send out that port.
58      * The length field is only meaningful when port == OFPort.OFPP_CONTROLLER
59      * @param port
60      * @param maxLength The maximum number of bytes of the packet to send.
61      * Most hardware only supports this value for OFPP_CONTROLLER
62      */
63
64     public OFActionOutput(short port, short maxLength) {
65         super();
66         super.setType(OFActionType.OUTPUT);
67         super.setLength((short) MINIMUM_LENGTH);
68         this.port = port;
69         this.maxLength = maxLength;
70     }
71
72     /**
73      * Get the output port
74      * @return
75      */
76     public short getPort() {
77         return this.port;
78     }
79
80     /**
81      * Set the output port
82      * @param port
83      */
84     public OFActionOutput setPort(short port) {
85         this.port = port;
86         return this;
87     }
88
89     /**
90      * Get the max length to send to the controller
91      * @return
92      */
93     public short getMaxLength() {
94         return this.maxLength;
95     }
96
97     /**
98      * Set the max length to send to the controller
99      * @param maxLength
100      */
101     public OFActionOutput setMaxLength(short maxLength) {
102         this.maxLength = maxLength;
103         return this;
104     }
105
106     @Override
107     public void readFrom(ChannelBuffer data) {
108         super.readFrom(data);
109         this.port = data.readShort();
110         this.maxLength = data.readShort();
111     }
112
113     @Override
114     public void writeTo(ChannelBuffer data) {
115         super.writeTo(data);
116         data.writeShort(port);
117         data.writeShort(maxLength);
118     }
119
120     @Override
121     public int hashCode() {
122         final int prime = 367;
123         int result = super.hashCode();
124         result = prime * result + maxLength;
125         result = prime * result + port;
126         return result;
127     }
128
129     @Override
130     public boolean equals(Object obj) {
131         if (this == obj) {
132             return true;
133         }
134         if (!super.equals(obj)) {
135             return false;
136         }
137         if (!(obj instanceof OFActionOutput)) {
138             return false;
139         }
140         OFActionOutput other = (OFActionOutput) obj;
141         if (maxLength != other.maxLength) {
142             return false;
143         }
144         if (port != other.port) {
145             return false;
146         }
147         return true;
148     }
149
150     /* (non-Javadoc)
151      * @see java.lang.Object#toString()
152      */
153     @Override
154     public String toString() {
155         return "OFActionOutput [maxLength=" + maxLength + ", port=" + U16.f(port)
156                 + ", length=" + length + ", type=" + type + "]";
157     }
158 }