Merge "Updated pom.xml to build documentation only on jenkins merge-job"
[openflowjava.git] / third-party / openflowj_netty / src / main / java / org / openflow / protocol / statistics / OFTableStatistics.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 package org.openflow.protocol.statistics;
19
20
21 import org.jboss.netty.buffer.ChannelBuffer;
22 import org.openflow.util.StringByteSerializer;
23
24 /**
25  * Represents an ofp_table_stats structure
26  * @author David Erickson (daviderickson@cs.stanford.edu)
27  */
28 public class OFTableStatistics implements OFStatistics {
29     public static int MAX_TABLE_NAME_LEN = 32;
30
31     protected byte tableId;
32     protected String name;
33     protected int wildcards;
34     protected int maximumEntries;
35     protected int activeCount;
36     protected long lookupCount;
37     protected long matchedCount;
38
39     /**
40      * @return the tableId
41      */
42     public byte getTableId() {
43         return tableId;
44     }
45
46     /**
47      * @param tableId the tableId to set
48      */
49     public void setTableId(byte tableId) {
50         this.tableId = tableId;
51     }
52
53     /**
54      * @return the name
55      */
56     public String getName() {
57         return name;
58     }
59
60     /**
61      * @param name the name to set
62      */
63     public void setName(String name) {
64         this.name = name;
65     }
66
67     /**
68      * @return the wildcards
69      */
70     public int getWildcards() {
71         return wildcards;
72     }
73
74     /**
75      * @param wildcards the wildcards to set
76      */
77     public void setWildcards(int wildcards) {
78         this.wildcards = wildcards;
79     }
80
81     /**
82      * @return the maximumEntries
83      */
84     public int getMaximumEntries() {
85         return maximumEntries;
86     }
87
88     /**
89      * @param maximumEntries the maximumEntries to set
90      */
91     public void setMaximumEntries(int maximumEntries) {
92         this.maximumEntries = maximumEntries;
93     }
94
95     /**
96      * @return the activeCount
97      */
98     public int getActiveCount() {
99         return activeCount;
100     }
101
102     /**
103      * @param activeCount the activeCount to set
104      */
105     public void setActiveCount(int activeCount) {
106         this.activeCount = activeCount;
107     }
108
109     /**
110      * @return the lookupCount
111      */
112     public long getLookupCount() {
113         return lookupCount;
114     }
115
116     /**
117      * @param lookupCount the lookupCount to set
118      */
119     public void setLookupCount(long lookupCount) {
120         this.lookupCount = lookupCount;
121     }
122
123     /**
124      * @return the matchedCount
125      */
126     public long getMatchedCount() {
127         return matchedCount;
128     }
129
130     /**
131      * @param matchedCount the matchedCount to set
132      */
133     public void setMatchedCount(long matchedCount) {
134         this.matchedCount = matchedCount;
135     }
136
137     @Override
138     public int getLength() {
139         return 64;
140     }
141
142     @Override
143     public void readFrom(ChannelBuffer data) {
144         this.tableId = data.readByte();
145         data.readByte(); // pad
146         data.readByte(); // pad
147         data.readByte(); // pad
148         this.name = StringByteSerializer.readFrom(data, MAX_TABLE_NAME_LEN);
149         this.wildcards = data.readInt();
150         this.maximumEntries = data.readInt();
151         this.activeCount = data.readInt();
152         this.lookupCount = data.readLong();
153         this.matchedCount = data.readLong();
154     }
155
156     @Override
157     public void writeTo(ChannelBuffer data) {
158         data.writeByte(this.tableId);
159         data.writeByte((byte) 0); // pad
160         data.writeByte((byte) 0); // pad
161         data.writeByte((byte) 0); // pad
162         StringByteSerializer.writeTo(data, MAX_TABLE_NAME_LEN, this.name);
163         data.writeInt(this.wildcards);
164         data.writeInt(this.maximumEntries);
165         data.writeInt(this.activeCount);
166         data.writeLong(this.lookupCount);
167         data.writeLong(this.matchedCount);
168     }
169
170     @Override
171     public int hashCode() {
172         final int prime = 449;
173         int result = 1;
174         result = prime * result + activeCount;
175         result = prime * result + (int) (lookupCount ^ (lookupCount >>> 32));
176         result = prime * result + (int) (matchedCount ^ (matchedCount >>> 32));
177         result = prime * result + maximumEntries;
178         result = prime * result + ((name == null) ? 0 : name.hashCode());
179         result = prime * result + tableId;
180         result = prime * result + wildcards;
181         return result;
182     }
183
184     @Override
185     public boolean equals(Object obj) {
186         if (this == obj) {
187             return true;
188         }
189         if (obj == null) {
190             return false;
191         }
192         if (!(obj instanceof OFTableStatistics)) {
193             return false;
194         }
195         OFTableStatistics other = (OFTableStatistics) obj;
196         if (activeCount != other.activeCount) {
197             return false;
198         }
199         if (lookupCount != other.lookupCount) {
200             return false;
201         }
202         if (matchedCount != other.matchedCount) {
203             return false;
204         }
205         if (maximumEntries != other.maximumEntries) {
206             return false;
207         }
208         if (name == null) {
209             if (other.name != null) {
210                 return false;
211             }
212         } else if (!name.equals(other.name)) {
213             return false;
214         }
215         if (tableId != other.tableId) {
216             return false;
217         }
218         if (wildcards != other.wildcards) {
219             return false;
220         }
221         return true;
222     }
223 }