Checkstyle enforcer
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / vendorextension / v6extension / V6StatsRequest.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension;
11
12 import java.nio.ByteBuffer;
13
14 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
15 import org.openflow.protocol.statistics.OFVendorStatistics;
16
17
18 /**
19  * This Class creates the OpenFlow Vendor Extension IPv6 Flow Stats Request
20  * messages and also reads the Reply of a stats request message.
21  *
22  */
23
24 public class V6StatsRequest extends OFVendorStatistics {
25     private static final long serialVersionUID = 1L;
26     protected int msgsubtype;
27     protected short outPort;
28     protected short match_len;
29     protected byte tableId;
30
31     public static final int NICIRA_VENDOR_ID = 0x00002320; //Nicira ID
32     private static final int NXST_FLOW = 0x0; //Nicira Flow Stats Request Id
33
34     public V6StatsRequest() {
35         this.vendor = NICIRA_VENDOR_ID;
36         this.msgsubtype = NXST_FLOW;
37         this.match_len = 0;
38     }
39
40     /**
41      * @param None. Being set with local variable (TBD).
42      */
43     public void setVendorId() {
44         this.vendor = NICIRA_VENDOR_ID;
45     }
46
47     /**
48      * @return vendor id
49      */
50     public int getVendorId() {
51         return vendor;
52     }
53
54     /**
55      * @param None. Being set with local variable (TBD).
56      */
57     public void setMsgtype() {
58         this.msgsubtype = NXST_FLOW;
59     }
60
61     /**
62      * @return vendor_msgtype
63      */
64     public int getMsgtype() {
65         return msgsubtype;
66     }
67
68     /**
69      * @param outPort the outPort to set
70      */
71     public void setOutPort(short outPort) {
72         this.outPort = outPort;
73     }
74
75     /**
76      * @return the outPort
77      */
78     public short getOutPort() {
79         return outPort;
80     }
81
82     /**
83      * @param match_len the match_len to set
84      */
85     public void setMatchLen(short match_len) {
86         this.match_len = match_len;
87     }
88
89     /**
90      * @return the match_len
91      */
92     public short getMatchLen() {
93         return match_len;
94     }
95
96     /**
97      * @param tableId the tableId to set
98      */
99     public void setTableId(byte tableId) {
100         this.tableId = tableId;
101     }
102
103     /**
104      * @return the tableId
105      */
106     public byte getTableId() {
107         return tableId;
108     }
109
110     @Override
111     public int getLength() {
112         return 20;// 4(vendor)+4(msgsubtype)+4(pad)+2(outPort)+2(match_len)+1(tableid)+3(pad)
113     }
114
115     @Override
116     public void readFrom(ByteBuffer data) {
117         this.vendor = data.getInt();
118         this.msgsubtype = data.getInt();
119         data.getInt();//pad 4 bytes
120         this.outPort = data.getShort();
121         this.match_len = data.getShort();
122         this.tableId = data.get();
123         for (int i = 0; i < 3; i++)
124             data.get();//pad byte
125
126     }
127
128     @Override
129     public void writeTo(ByteBuffer data) {
130         data.putInt(this.vendor);
131         data.putInt(this.msgsubtype);
132         data.putInt((int) 0x0);//pad0
133         data.putShort(this.outPort);
134         data.putShort(this.match_len);
135         data.put(this.tableId);
136         for (int i = 0; i < 3; i++)
137             data.put((byte) 0x0);//pad byte
138     }
139
140     @Override
141     public int hashCode() {
142         final int prime = 31;
143         int result = super.hashCode();
144         result = prime * result + match_len;
145         result = prime * result + msgsubtype;
146         result = prime * result + outPort;
147         result = prime * result + tableId;
148         return result;
149     }
150
151     @Override
152     public String toString() {
153         return "V6StatsRequest[" + ReflectionToStringBuilder.toString(this)
154                 + "]";
155     }
156
157     @Override
158     public boolean equals(Object obj) {
159         if (this == obj)
160             return true;
161         if (!super.equals(obj))
162             return false;
163         if (getClass() != obj.getClass())
164             return false;
165         V6StatsRequest other = (V6StatsRequest) obj;
166         if (match_len != other.match_len)
167             return false;
168         if (msgsubtype != other.msgsubtype)
169             return false;
170         if (outPort != other.outPort)
171             return false;
172         if (tableId != other.tableId)
173             return false;
174         return true;
175     }
176 }