Initial opendaylight infrastructure commit!!
[controller.git] / third-party / openflowj / src / main / java / org / openflow / protocol / action / OFActionOutput.java
1 /**
2  * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
3  */
4 package org.openflow.protocol.action;
5
6 import java.nio.ByteBuffer;
7
8 import org.openflow.util.U16;
9
10 /**
11  * @author David Erickson (daviderickson@cs.stanford.edu) - Mar 11, 2010
12  * @author Rob Sherwood (rob.sherwood@stanford.edu)
13  */
14 public class OFActionOutput extends OFAction implements Cloneable {
15     public static int MINIMUM_LENGTH = 8;
16
17     protected short port;
18     protected short maxLength;
19
20     public OFActionOutput() {
21         super.setType(OFActionType.OUTPUT);
22         super.setLength((short) MINIMUM_LENGTH);
23     }
24
25     public OFActionOutput(short port, short maxLength) {
26         super();
27         super.setType(OFActionType.OUTPUT);
28         super.setLength((short) MINIMUM_LENGTH);
29         this.port = port;
30         this.maxLength = maxLength;
31     }
32
33     /**
34      * Get the output port
35      * @return
36      */
37     public short getPort() {
38         return this.port;
39     }
40
41     /**
42      * Set the output port
43      * @param port
44      */
45     public OFActionOutput setPort(short port) {
46         this.port = port;
47         return this;
48     }
49
50     /**
51      * Get the max length to send to the controller
52      * @return
53      */
54     public short getMaxLength() {
55         return this.maxLength;
56     }
57
58     /**
59      * Set the max length to send to the controller
60      * @param maxLength
61      */
62     public OFActionOutput setMaxLength(short maxLength) {
63         this.maxLength = maxLength;
64         return this;
65     }
66
67     @Override
68     public void readFrom(ByteBuffer data) {
69         super.readFrom(data);
70         this.port = data.getShort();
71         this.maxLength = data.getShort();
72     }
73
74     @Override
75     public void writeTo(ByteBuffer data) {
76         super.writeTo(data);
77         data.putShort(port);
78         data.putShort(maxLength);
79     }
80
81     @Override
82     public int hashCode() {
83         final int prime = 367;
84         int result = super.hashCode();
85         result = prime * result + maxLength;
86         result = prime * result + port;
87         return result;
88     }
89
90     @Override
91     public boolean equals(Object obj) {
92         if (this == obj) {
93             return true;
94         }
95         if (!super.equals(obj)) {
96             return false;
97         }
98         if (!(obj instanceof OFActionOutput)) {
99             return false;
100         }
101         OFActionOutput other = (OFActionOutput) obj;
102         if (maxLength != other.maxLength) {
103             return false;
104         }
105         if (port != other.port) {
106             return false;
107         }
108         return true;
109     }
110
111     /* (non-Javadoc)
112      * @see java.lang.Object#toString()
113      */
114     @Override
115     public String toString() {
116         return "OFActionOutput [maxLength=" + maxLength + ", port=" + U16.f(port)
117                 + ", length=" + length + ", type=" + type + "]";
118     }
119 }