0bb2b6d01f07151c47ae12d4cb0e9fc85b829a49
[openflowjava.git] / third-party / openflow-codec / src / main / java / org / openflow / codec / protocol / statistics / OFPTableStatistics.java
1 package org.openflow.codec.protocol.statistics;
2
3 import java.io.Serializable;
4
5 import org.openflow.codec.io.IDataBuffer;
6
7 /**
8  * Represents an ofp_table_stats structure
9  *
10  * @author David Erickson (daviderickson@cs.stanford.edu)
11  * @author AnilGujele
12  */
13 public class OFPTableStatistics implements OFPStatistics, Serializable {
14     private static final int MINIMUM_LENGTH = 24;
15
16     protected byte tableId;
17     protected int activeCount;
18     protected long lookupCount;
19     protected long matchedCount;
20
21     /**
22      * @return the tableId
23      */
24     public byte getTableId() {
25         return tableId;
26     }
27
28     /**
29      * @param tableId
30      *            the tableId to set
31      */
32     public void setTableId(byte tableId) {
33         this.tableId = tableId;
34     }
35
36     /**
37      * @return the activeCount
38      */
39     public int getActiveCount() {
40         return activeCount;
41     }
42
43     /**
44      * @param activeCount
45      *            the activeCount to set
46      */
47     public void setActiveCount(int activeCount) {
48         this.activeCount = activeCount;
49     }
50
51     /**
52      * @return the lookupCount
53      */
54     public long getLookupCount() {
55         return lookupCount;
56     }
57
58     /**
59      * @param lookupCount
60      *            the lookupCount to set
61      */
62     public void setLookupCount(long lookupCount) {
63         this.lookupCount = lookupCount;
64     }
65
66     /**
67      * @return the matchedCount
68      */
69     public long getMatchedCount() {
70         return matchedCount;
71     }
72
73     /**
74      * @param matchedCount
75      *            the matchedCount to set
76      */
77     public void setMatchedCount(long matchedCount) {
78         this.matchedCount = matchedCount;
79     }
80
81     @Override
82     public int getLength() {
83         return MINIMUM_LENGTH;
84     }
85
86     @Override
87     public void readFrom(IDataBuffer data) {
88         this.tableId = data.get();
89         data.get(); // pad
90         data.get(); // pad
91         data.get(); // pad
92         this.activeCount = data.getInt();
93         this.lookupCount = data.getLong();
94         this.matchedCount = data.getLong();
95     }
96
97     @Override
98     public void writeTo(IDataBuffer data) {
99         data.put(this.tableId);
100         data.put((byte) 0); // pad
101         data.put((byte) 0); // pad
102         data.put((byte) 0); // pad
103         data.putInt(this.activeCount);
104         data.putLong(this.lookupCount);
105         data.putLong(this.matchedCount);
106     }
107
108     @Override
109     public int hashCode() {
110         final int prime = 449;
111         int result = 1;
112         result = prime * result + activeCount;
113         result = prime * result + (int) (lookupCount ^ (lookupCount >>> 32));
114         result = prime * result + (int) (matchedCount ^ (matchedCount >>> 32));
115         result = prime * result + tableId;
116         return result;
117     }
118
119     @Override
120     public boolean equals(Object obj) {
121         if (this == obj) {
122             return true;
123         }
124         if (obj == null) {
125             return false;
126         }
127         if (!(obj instanceof OFPTableStatistics)) {
128             return false;
129         }
130         OFPTableStatistics other = (OFPTableStatistics) obj;
131         if (activeCount != other.activeCount) {
132             return false;
133         }
134         if (lookupCount != other.lookupCount) {
135             return false;
136         }
137         if (matchedCount != other.matchedCount) {
138             return false;
139         }
140         if (tableId != other.tableId) {
141             return false;
142         }
143         return true;
144     }
145 }