2 * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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
19 * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
21 package org.openflow.protocol.action;
24 import org.jboss.netty.buffer.ChannelBuffer;
25 import org.openflow.util.U16;
28 * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
29 * @author Rob Sherwood (rob.sherwood@stanford.edu)
31 public class OFActionOutput extends OFAction implements Cloneable {
32 public static int MINIMUM_LENGTH = 8;
35 protected short maxLength;
37 public OFActionOutput() {
38 super.setType(OFActionType.OUTPUT);
39 super.setLength((short) MINIMUM_LENGTH);
43 * Create an Output Action sending packets out the specified
46 * This is the most common creation pattern for OFActions.
51 public OFActionOutput(short port) {
52 this(port, (short) 65535);
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
60 * @param maxLength The maximum number of bytes of the packet to send.
61 * Most hardware only supports this value for OFPP_CONTROLLER
64 public OFActionOutput(short port, short maxLength) {
66 super.setType(OFActionType.OUTPUT);
67 super.setLength((short) MINIMUM_LENGTH);
69 this.maxLength = maxLength;
76 public short getPort() {
84 public OFActionOutput setPort(short port) {
90 * Get the max length to send to the controller
93 public short getMaxLength() {
94 return this.maxLength;
98 * Set the max length to send to the controller
101 public OFActionOutput setMaxLength(short maxLength) {
102 this.maxLength = maxLength;
107 public void readFrom(ChannelBuffer data) {
108 super.readFrom(data);
109 this.port = data.readShort();
110 this.maxLength = data.readShort();
114 public void writeTo(ChannelBuffer data) {
116 data.writeShort(port);
117 data.writeShort(maxLength);
121 public int hashCode() {
122 final int prime = 367;
123 int result = super.hashCode();
124 result = prime * result + maxLength;
125 result = prime * result + port;
130 public boolean equals(Object obj) {
134 if (!super.equals(obj)) {
137 if (!(obj instanceof OFActionOutput)) {
140 OFActionOutput other = (OFActionOutput) obj;
141 if (maxLength != other.maxLength) {
144 if (port != other.port) {
151 * @see java.lang.Object#toString()
154 public String toString() {
155 return "OFActionOutput [maxLength=" + maxLength + ", port=" + U16.f(port)
156 + ", length=" + length + ", type=" + type + "]";