e9e6756ce4da577f09d89ee699f3d0cec664e69d
[openflowjava.git] / third-party / openflow-codec / src / main / java / org / openflow / codec / protocol / statistics / OFPFlowStatisticsRequest.java
1 package org.openflow.codec.protocol.statistics;
2
3 import java.io.Serializable;
4
5 import org.openflow.codec.io.IDataBuffer;
6 import org.openflow.codec.protocol.OFPMatch;
7
8 /**
9  * Represents an ofp_flow_stats_request structure
10  *
11  * @author David Erickson (daviderickson@cs.stanford.edu)
12  * @author AnilGujele
13  */
14 public class OFPFlowStatisticsRequest implements OFPStatistics, Serializable {
15     private static final int MINIMUM_LENGTH = 40;
16
17     protected byte tableId;
18     protected int outPort;
19     private int outGroup;
20     private long cookie;
21     private long cookieMask;
22     protected OFPMatch match;
23
24     /**
25      * @return the match
26      */
27     public OFPMatch getMatch() {
28         return match;
29     }
30
31     /**
32      * @param match
33      *            the match to set
34      */
35     public void setMatch(OFPMatch match) {
36         this.match = match;
37     }
38
39     /**
40      * @return the tableId
41      */
42     public byte getTableId() {
43         return tableId;
44     }
45
46     /**
47      * @param tableId
48      *            the tableId to set
49      */
50     public void setTableId(byte tableId) {
51         this.tableId = tableId;
52     }
53
54     /**
55      * @return the outPort
56      */
57     public int getOutPort() {
58         return outPort;
59     }
60
61     /**
62      * @param outPort
63      *            the outPort to set
64      */
65     public void setOutPort(int outPort) {
66         this.outPort = outPort;
67     }
68
69     /**
70      *
71      * @return
72      */
73     public int getOutGroup() {
74         return outGroup;
75     }
76
77     /**
78      *
79      * @param outGroup
80      */
81
82     public void setOutGroup(int outGroup) {
83         this.outGroup = outGroup;
84     }
85
86     /**
87      *
88      * @return
89      */
90     public long getCookie() {
91         return cookie;
92     }
93
94     /**
95      *
96      * @param cookie
97      */
98     public void setCookie(long cookie) {
99         this.cookie = cookie;
100     }
101
102     /**
103      *
104      * @return
105      */
106     public long getCookieMask() {
107         return cookieMask;
108     }
109
110     /**
111      *
112      * @param cookieMask
113      */
114     public void setCookieMask(long cookieMask) {
115         this.cookieMask = cookieMask;
116     }
117
118     @Override
119     public int getLength() {
120         return MINIMUM_LENGTH;
121     }
122
123     @Override
124     public void readFrom(IDataBuffer data) {
125
126         this.tableId = data.get();
127         data.get(); // pad
128         data.getShort(); // pad
129         this.outPort = data.getInt();
130         this.setOutGroup(data.getInt());
131         data.getInt(); // pad
132         this.setCookie(data.getLong());
133         this.setCookieMask(data.getLong());
134         if (this.match == null)
135             this.match = new OFPMatch();
136         this.match.readFrom(data);
137     }
138
139     @Override
140     public void writeTo(IDataBuffer data) {
141         data.put(this.tableId);
142         data.put((byte) 0);
143         data.putShort((short) 0);
144         data.putInt(this.outPort);
145         data.putInt(this.getOutGroup());
146         data.putInt(0);
147         data.putLong(this.getCookie());
148         data.putLong(this.getCookieMask());
149         this.match.writeTo(data);
150     }
151
152     @Override
153     public int hashCode() {
154         final int prime = 421;
155         int result = 1;
156         result = prime * result + ((match == null) ? 0 : match.hashCode());
157         result = prime * result + (int) (cookie ^ (cookie >>> 32));
158         result = prime * result + (int) (cookieMask ^ (cookieMask >>> 32));
159         result = prime * result + outPort;
160         result = prime * result + outGroup;
161         result = prime * result + tableId;
162         return result;
163     }
164
165     @Override
166     public boolean equals(Object obj) {
167         if (this == obj) {
168             return true;
169         }
170         if (obj == null) {
171             return false;
172         }
173         if (!(obj instanceof OFPFlowStatisticsRequest)) {
174             return false;
175         }
176         OFPFlowStatisticsRequest other = (OFPFlowStatisticsRequest) obj;
177         if (tableId != other.tableId) {
178             return false;
179         }
180         if (outPort != other.outPort) {
181             return false;
182         }
183         if (getOutGroup() != other.getOutGroup()) {
184             return false;
185         }
186         if (getCookie() != other.getCookie()) {
187             return false;
188         }
189         if (getCookieMask() != other.getCookieMask()) {
190             return false;
191         }
192         if (match == null) {
193             if (other.match != null) {
194                 return false;
195             }
196         } else if (!match.equals(other.match)) {
197             return false;
198         }
199
200         return true;
201     }
202 }