Fixed build failure in openflow_netty project
[openflowplugin.git] / openflow-codec / src / main / java / org / openflow / codec / protocol / action / OFPActionSetField.java
1 /**
2  * @author Yugandhar Sarraju (ysarraju@in.ibm.com) - July 21, 2013
3  */
4 package org.openflow.codec.protocol.action;
5
6 import org.openflow.codec.io.IDataBuffer;
7 import org.openflow.codec.protocol.OFBMatchFields;
8 import org.openflow.codec.protocol.OXMClass;
9 import org.openflow.codec.protocol.OXMField;
10
11 /**
12  * Represents an action struct ofp_action_set_field
13  */
14 public class OFPActionSetField extends OFPAction {
15     public static int MINIMUM_LENGTH = 8;
16
17     // OXM TLV
18     OXMField oxmtlvField;
19
20     // Contructors
21     public OFPActionSetField() {
22         super.setType(OFPActionType.SET_FIELD);
23         super.setLength((short) MINIMUM_LENGTH);
24         oxmtlvField = new OXMField();
25     }
26
27     public OFPActionSetField(OXMClass classType, OFBMatchFields matchField, boolean hasMask, byte[] data) {
28         oxmtlvField = new OXMField(classType, matchField, hasMask, data);
29     }
30
31     // Get Set Methods
32     public OXMClass getOXMClassType() {
33         return this.oxmtlvField.getOXMClassType();
34     }
35
36     public void setOXMClassType(OXMClass OXMClassType) {
37         this.oxmtlvField.setOXMClassType(OXMClassType);
38     }
39
40     public OFBMatchFields getMatchField() {
41         return this.oxmtlvField.getMatchField();
42     }
43
44     public void setMatchField(OFBMatchFields matchField) {
45         this.oxmtlvField.setMatchField(matchField);
46     }
47
48     public boolean isHasMask() {
49         return this.oxmtlvField.isHasMask();
50     }
51
52     public void setHasMask(boolean hasMask) {
53         this.oxmtlvField.setHasMask(hasMask);
54     }
55
56     /**
57      * to get the total length of match field (or TLV) including header in bytes
58      *
59      * @return
60      */
61     public byte getFieldLength() {
62         // Type + Lenghth + Value
63         return this.oxmtlvField.getLength();
64     }
65
66     public byte[] getData() {
67         return this.oxmtlvField.getData();
68     }
69
70     public void setData(byte[] data) {
71         this.oxmtlvField.setData(data);
72     }
73
74     @Override
75     public void readFrom(IDataBuffer data) {
76         super.readFrom(data);
77         if (oxmtlvField == null)
78             oxmtlvField = new OXMField();
79         oxmtlvField.readFrom(data);
80     }
81
82     @Override
83     public void writeTo(IDataBuffer data) {
84         super.writeTo(data);
85         oxmtlvField.writeTo(data);
86     }
87
88     @Override
89     public int hashCode() {
90         final int prime = 353;
91         int result = super.hashCode();
92         result = prime * result + (oxmtlvField == null ? 0 : oxmtlvField.hashCode());
93         return result;
94     }
95
96     @Override
97     public boolean equals(Object obj) {
98         if (this == obj) {
99             return true;
100         }
101         if (!super.equals(obj)) {
102             return false;
103         }
104         if (!(obj instanceof OFPActionSetField)) {
105             return false;
106         }
107         OFPActionSetField other = (OFPActionSetField) obj;
108         if (this.oxmtlvField.getMatchField() != other.oxmtlvField.getMatchField()) {
109             return false;
110         }
111         return true;
112     }
113
114 }