blob: a0fa47943662a2730d2ce49e1ee685b95853b272 [file] [log] [blame]
tom0eb04ca2014-08-25 14:34:51 -07001// Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
2// Copyright (c) 2011, 2012 Open Networking Foundation
3// Copyright (c) 2012, 2013 Big Switch Networks, Inc.
4// This library was generated by the LoxiGen Compiler.
5// See the file LICENSE.txt which should have been included in the source distribution
6
7// Automatically generated by LOXI from template of_class.java
8// Do not modify
9
10package org.projectfloodlight.openflow.protocol.ver12;
11
12import org.projectfloodlight.openflow.protocol.*;
13import org.projectfloodlight.openflow.protocol.action.*;
14import org.projectfloodlight.openflow.protocol.actionid.*;
15import org.projectfloodlight.openflow.protocol.bsntlv.*;
16import org.projectfloodlight.openflow.protocol.errormsg.*;
17import org.projectfloodlight.openflow.protocol.meterband.*;
18import org.projectfloodlight.openflow.protocol.instruction.*;
19import org.projectfloodlight.openflow.protocol.instructionid.*;
20import org.projectfloodlight.openflow.protocol.match.*;
21import org.projectfloodlight.openflow.protocol.oxm.*;
22import org.projectfloodlight.openflow.protocol.queueprop.*;
23import org.projectfloodlight.openflow.types.*;
24import org.projectfloodlight.openflow.util.*;
25import org.projectfloodlight.openflow.exceptions.*;
26import org.slf4j.Logger;
27import org.slf4j.LoggerFactory;
28import java.util.Set;
29import org.jboss.netty.buffer.ChannelBuffer;
30import com.google.common.hash.PrimitiveSink;
31import com.google.common.hash.Funnel;
32import java.util.Arrays;
33
34class OFEchoReplyVer12 implements OFEchoReply {
35 private static final Logger logger = LoggerFactory.getLogger(OFEchoReplyVer12.class);
36 // version: 1.2
37 final static byte WIRE_VERSION = 3;
38 final static int MINIMUM_LENGTH = 8;
39
40 private final static long DEFAULT_XID = 0x0L;
41 private final static byte[] DEFAULT_DATA = new byte[0];
42
43 // OF message fields
44 private final long xid;
45 private final byte[] data;
46//
47 // Immutable default instance
48 final static OFEchoReplyVer12 DEFAULT = new OFEchoReplyVer12(
49 DEFAULT_XID, DEFAULT_DATA
50 );
51
52 // package private constructor - used by readers, builders, and factory
53 OFEchoReplyVer12(long xid, byte[] data) {
54 this.xid = xid;
55 this.data = data;
56 }
57
58 // Accessors for OF message fields
59 @Override
60 public OFVersion getVersion() {
61 return OFVersion.OF_12;
62 }
63
64 @Override
65 public OFType getType() {
66 return OFType.ECHO_REPLY;
67 }
68
69 @Override
70 public long getXid() {
71 return xid;
72 }
73
74 @Override
75 public byte[] getData() {
76 return data;
77 }
78
79
80
81 public OFEchoReply.Builder createBuilder() {
82 return new BuilderWithParent(this);
83 }
84
85 static class BuilderWithParent implements OFEchoReply.Builder {
86 final OFEchoReplyVer12 parentMessage;
87
88 // OF message fields
89 private boolean xidSet;
90 private long xid;
91 private boolean dataSet;
92 private byte[] data;
93
94 BuilderWithParent(OFEchoReplyVer12 parentMessage) {
95 this.parentMessage = parentMessage;
96 }
97
98 @Override
99 public OFVersion getVersion() {
100 return OFVersion.OF_12;
101 }
102
103 @Override
104 public OFType getType() {
105 return OFType.ECHO_REPLY;
106 }
107
108 @Override
109 public long getXid() {
110 return xid;
111 }
112
113 @Override
114 public OFEchoReply.Builder setXid(long xid) {
115 this.xid = xid;
116 this.xidSet = true;
117 return this;
118 }
119 @Override
120 public byte[] getData() {
121 return data;
122 }
123
124 @Override
125 public OFEchoReply.Builder setData(byte[] data) {
126 this.data = data;
127 this.dataSet = true;
128 return this;
129 }
130
131
132 @Override
133 public OFEchoReply build() {
134 long xid = this.xidSet ? this.xid : parentMessage.xid;
135 byte[] data = this.dataSet ? this.data : parentMessage.data;
136 if(data == null)
137 throw new NullPointerException("Property data must not be null");
138
139 //
140 return new OFEchoReplyVer12(
141 xid,
142 data
143 );
144 }
145
146 }
147
148 static class Builder implements OFEchoReply.Builder {
149 // OF message fields
150 private boolean xidSet;
151 private long xid;
152 private boolean dataSet;
153 private byte[] data;
154
155 @Override
156 public OFVersion getVersion() {
157 return OFVersion.OF_12;
158 }
159
160 @Override
161 public OFType getType() {
162 return OFType.ECHO_REPLY;
163 }
164
165 @Override
166 public long getXid() {
167 return xid;
168 }
169
170 @Override
171 public OFEchoReply.Builder setXid(long xid) {
172 this.xid = xid;
173 this.xidSet = true;
174 return this;
175 }
176 @Override
177 public byte[] getData() {
178 return data;
179 }
180
181 @Override
182 public OFEchoReply.Builder setData(byte[] data) {
183 this.data = data;
184 this.dataSet = true;
185 return this;
186 }
187//
188 @Override
189 public OFEchoReply build() {
190 long xid = this.xidSet ? this.xid : DEFAULT_XID;
191 byte[] data = this.dataSet ? this.data : DEFAULT_DATA;
192 if(data == null)
193 throw new NullPointerException("Property data must not be null");
194
195
196 return new OFEchoReplyVer12(
197 xid,
198 data
199 );
200 }
201
202 }
203
204
205 final static Reader READER = new Reader();
206 static class Reader implements OFMessageReader<OFEchoReply> {
207 @Override
208 public OFEchoReply readFrom(ChannelBuffer bb) throws OFParseError {
209 int start = bb.readerIndex();
210 // fixed value property version == 3
211 byte version = bb.readByte();
212 if(version != (byte) 0x3)
213 throw new OFParseError("Wrong version: Expected=OFVersion.OF_12(3), got="+version);
214 // fixed value property type == 3
215 byte type = bb.readByte();
216 if(type != (byte) 0x3)
217 throw new OFParseError("Wrong type: Expected=OFType.ECHO_REPLY(3), got="+type);
218 int length = U16.f(bb.readShort());
219 if(length < MINIMUM_LENGTH)
220 throw new OFParseError("Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length);
221 if(bb.readableBytes() + (bb.readerIndex() - start) < length) {
222 // Buffer does not have all data yet
223 bb.readerIndex(start);
224 return null;
225 }
226 if(logger.isTraceEnabled())
227 logger.trace("readFrom - length={}", length);
228 long xid = U32.f(bb.readInt());
229 byte[] data = ChannelUtils.readBytes(bb, length - (bb.readerIndex() - start));
230
231 OFEchoReplyVer12 echoReplyVer12 = new OFEchoReplyVer12(
232 xid,
233 data
234 );
235 if(logger.isTraceEnabled())
236 logger.trace("readFrom - read={}", echoReplyVer12);
237 return echoReplyVer12;
238 }
239 }
240
241 public void putTo(PrimitiveSink sink) {
242 FUNNEL.funnel(this, sink);
243 }
244
245 final static OFEchoReplyVer12Funnel FUNNEL = new OFEchoReplyVer12Funnel();
246 static class OFEchoReplyVer12Funnel implements Funnel<OFEchoReplyVer12> {
247 private static final long serialVersionUID = 1L;
248 @Override
249 public void funnel(OFEchoReplyVer12 message, PrimitiveSink sink) {
250 // fixed value property version = 3
251 sink.putByte((byte) 0x3);
252 // fixed value property type = 3
253 sink.putByte((byte) 0x3);
254 // FIXME: skip funnel of length
255 sink.putLong(message.xid);
256 sink.putBytes(message.data);
257 }
258 }
259
260
261 public void writeTo(ChannelBuffer bb) {
262 WRITER.write(bb, this);
263 }
264
265 final static Writer WRITER = new Writer();
266 static class Writer implements OFMessageWriter<OFEchoReplyVer12> {
267 @Override
268 public void write(ChannelBuffer bb, OFEchoReplyVer12 message) {
269 int startIndex = bb.writerIndex();
270 // fixed value property version = 3
271 bb.writeByte((byte) 0x3);
272 // fixed value property type = 3
273 bb.writeByte((byte) 0x3);
274 // length is length of variable message, will be updated at the end
275 int lengthIndex = bb.writerIndex();
276 bb.writeShort(U16.t(0));
277
278 bb.writeInt(U32.t(message.xid));
279 bb.writeBytes(message.data);
280
281 // update length field
282 int length = bb.writerIndex() - startIndex;
283 bb.setShort(lengthIndex, length);
284
285 }
286 }
287
288 @Override
289 public String toString() {
290 StringBuilder b = new StringBuilder("OFEchoReplyVer12(");
291 b.append("xid=").append(xid);
292 b.append(", ");
293 b.append("data=").append(Arrays.toString(data));
294 b.append(")");
295 return b.toString();
296 }
297
298 @Override
299 public boolean equals(Object obj) {
300 if (this == obj)
301 return true;
302 if (obj == null)
303 return false;
304 if (getClass() != obj.getClass())
305 return false;
306 OFEchoReplyVer12 other = (OFEchoReplyVer12) obj;
307
308 if( xid != other.xid)
309 return false;
310 if (!Arrays.equals(data, other.data))
311 return false;
312 return true;
313 }
314
315 @Override
316 public int hashCode() {
317 final int prime = 31;
318 int result = 1;
319
320 result = prime * (int) (xid ^ (xid >>> 32));
321 result = prime * result + Arrays.hashCode(data);
322 return result;
323 }
324
325}