8f2c6cf388e7a0a37b8fb13c6a5f55d95d506b05
[openflowjava.git] / third-party / openflow-codec / src / main / java / org / openflow / codec / protocol / OFPTableMod.java
1 package org.openflow.codec.protocol;
2
3 import org.openflow.codec.io.IDataBuffer;
4 import org.openflow.codec.util.U16;
5
6 /**
7  * Class representing message structure ofp_table_mod
8  *
9  * @author AnilGujele
10  *
11  */
12 public class OFPTableMod extends OFPMessage {
13
14     private static final long serialVersionUID = -5972069012765334899L;
15
16     public static int MINIMUM_LENGTH = 16;
17
18     // table number as per ofp_table
19     enum OFTable {
20         /* Last usable table number. */
21         OFPTT_MAX(0xfe),
22
23         /* Fake tables. */
24         OFPTT_ALL(0xff);
25
26         private int value;
27
28         OFTable(int value) {
29             this.value = value;
30         }
31
32         public short value() {
33             return (short) this.value;
34         }
35     }
36
37     // Flags to configure the table as per ofp_table_config
38     public static final int OFPTC_DEPRECATED_MASK = 3;
39
40     private byte tableId;
41     private int config;
42
43     /**
44      * constructor
45      */
46     public OFPTableMod() {
47         super();
48         this.type = OFPType.TABLE_MOD;
49         this.length = U16.t(MINIMUM_LENGTH);
50
51     }
52
53     /**
54      * get table id
55      *
56      * @return
57      */
58     public byte getTableId() {
59         return tableId;
60     }
61
62     /**
63      * set table id OFPTT_ALL is for all the table OFPTT_MAX is Max table number
64      * limit
65      *
66      * @param tableId
67      */
68     public void setTableId(byte tableId) {
69
70         this.tableId = tableId;
71     }
72
73     /**
74      *
75      * @return
76      */
77     public int getConfig() {
78         return config;
79     }
80
81     /**
82      *
83      * @param config
84      */
85     public void setConfig(int config) {
86         this.config = config;
87     }
88
89     @Override
90     public void readFrom(IDataBuffer data) {
91         super.readFrom(data);
92         this.tableId = data.get();
93         data.getShort(); // pad
94         data.get(); // pad
95         this.config = data.getInt();
96     }
97
98     @Override
99     public void writeTo(IDataBuffer data) {
100         super.writeTo(data);
101         data.put(this.tableId);
102         data.putShort((short) 0); // pad
103         data.put((byte) 0); // pad
104         data.putInt(this.config);
105     }
106
107     @Override
108     public int hashCode() {
109         final int prime = 811;
110         int result = super.hashCode();
111         result = prime * result + tableId;
112         result = prime * result + config;
113         return result;
114     }
115
116     @Override
117     public boolean equals(Object obj) {
118         if (this == obj) {
119             return true;
120         }
121         if (!super.equals(obj)) {
122             return false;
123         }
124         if (!(obj instanceof OFPTableMod)) {
125             return false;
126         }
127         OFPTableMod other = (OFPTableMod) obj;
128         if (tableId != other.tableId) {
129             return false;
130         }
131         if (config != other.config) {
132             return false;
133         }
134         return true;
135     }
136 }