blob: be6456c24c3e20b0fe305190d6c398cf270ce4a2 [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.ver13;
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.List;
29import com.google.common.collect.ImmutableList;
30import java.util.Set;
31import org.jboss.netty.buffer.ChannelBuffer;
32import com.google.common.hash.PrimitiveSink;
33import com.google.common.hash.Funnel;
34
35class OFBucketVer13 implements OFBucket {
36 private static final Logger logger = LoggerFactory.getLogger(OFBucketVer13.class);
37 // version: 1.3
38 final static byte WIRE_VERSION = 4;
39 final static int MINIMUM_LENGTH = 16;
40
41 private final static int DEFAULT_WEIGHT = 0x0;
42 private final static OFPort DEFAULT_WATCH_PORT = OFPort.ANY;
43 private final static OFGroup DEFAULT_WATCH_GROUP = OFGroup.ALL;
44 private final static List<OFAction> DEFAULT_ACTIONS = ImmutableList.<OFAction>of();
45
46 // OF message fields
47 private final int weight;
48 private final OFPort watchPort;
49 private final OFGroup watchGroup;
50 private final List<OFAction> actions;
51//
52 // Immutable default instance
53 final static OFBucketVer13 DEFAULT = new OFBucketVer13(
54 DEFAULT_WEIGHT, DEFAULT_WATCH_PORT, DEFAULT_WATCH_GROUP, DEFAULT_ACTIONS
55 );
56
57 // package private constructor - used by readers, builders, and factory
58 OFBucketVer13(int weight, OFPort watchPort, OFGroup watchGroup, List<OFAction> actions) {
59 this.weight = weight;
60 this.watchPort = watchPort;
61 this.watchGroup = watchGroup;
62 this.actions = actions;
63 }
64
65 // Accessors for OF message fields
66 @Override
67 public int getWeight() {
68 return weight;
69 }
70
71 @Override
72 public OFPort getWatchPort() {
73 return watchPort;
74 }
75
76 @Override
77 public OFGroup getWatchGroup() {
78 return watchGroup;
79 }
80
81 @Override
82 public List<OFAction> getActions() {
83 return actions;
84 }
85
86 @Override
87 public OFVersion getVersion() {
88 return OFVersion.OF_13;
89 }
90
91
92
93 public OFBucket.Builder createBuilder() {
94 return new BuilderWithParent(this);
95 }
96
97 static class BuilderWithParent implements OFBucket.Builder {
98 final OFBucketVer13 parentMessage;
99
100 // OF message fields
101 private boolean weightSet;
102 private int weight;
103 private boolean watchPortSet;
104 private OFPort watchPort;
105 private boolean watchGroupSet;
106 private OFGroup watchGroup;
107 private boolean actionsSet;
108 private List<OFAction> actions;
109
110 BuilderWithParent(OFBucketVer13 parentMessage) {
111 this.parentMessage = parentMessage;
112 }
113
114 @Override
115 public int getWeight() {
116 return weight;
117 }
118
119 @Override
120 public OFBucket.Builder setWeight(int weight) {
121 this.weight = weight;
122 this.weightSet = true;
123 return this;
124 }
125 @Override
126 public OFPort getWatchPort() {
127 return watchPort;
128 }
129
130 @Override
131 public OFBucket.Builder setWatchPort(OFPort watchPort) {
132 this.watchPort = watchPort;
133 this.watchPortSet = true;
134 return this;
135 }
136 @Override
137 public OFGroup getWatchGroup() {
138 return watchGroup;
139 }
140
141 @Override
142 public OFBucket.Builder setWatchGroup(OFGroup watchGroup) {
143 this.watchGroup = watchGroup;
144 this.watchGroupSet = true;
145 return this;
146 }
147 @Override
148 public List<OFAction> getActions() {
149 return actions;
150 }
151
152 @Override
153 public OFBucket.Builder setActions(List<OFAction> actions) {
154 this.actions = actions;
155 this.actionsSet = true;
156 return this;
157 }
158 @Override
159 public OFVersion getVersion() {
160 return OFVersion.OF_13;
161 }
162
163
164
165 @Override
166 public OFBucket build() {
167 int weight = this.weightSet ? this.weight : parentMessage.weight;
168 OFPort watchPort = this.watchPortSet ? this.watchPort : parentMessage.watchPort;
169 if(watchPort == null)
170 throw new NullPointerException("Property watchPort must not be null");
171 OFGroup watchGroup = this.watchGroupSet ? this.watchGroup : parentMessage.watchGroup;
172 if(watchGroup == null)
173 throw new NullPointerException("Property watchGroup must not be null");
174 List<OFAction> actions = this.actionsSet ? this.actions : parentMessage.actions;
175 if(actions == null)
176 throw new NullPointerException("Property actions must not be null");
177
178 //
179 return new OFBucketVer13(
180 weight,
181 watchPort,
182 watchGroup,
183 actions
184 );
185 }
186
187 }
188
189 static class Builder implements OFBucket.Builder {
190 // OF message fields
191 private boolean weightSet;
192 private int weight;
193 private boolean watchPortSet;
194 private OFPort watchPort;
195 private boolean watchGroupSet;
196 private OFGroup watchGroup;
197 private boolean actionsSet;
198 private List<OFAction> actions;
199
200 @Override
201 public int getWeight() {
202 return weight;
203 }
204
205 @Override
206 public OFBucket.Builder setWeight(int weight) {
207 this.weight = weight;
208 this.weightSet = true;
209 return this;
210 }
211 @Override
212 public OFPort getWatchPort() {
213 return watchPort;
214 }
215
216 @Override
217 public OFBucket.Builder setWatchPort(OFPort watchPort) {
218 this.watchPort = watchPort;
219 this.watchPortSet = true;
220 return this;
221 }
222 @Override
223 public OFGroup getWatchGroup() {
224 return watchGroup;
225 }
226
227 @Override
228 public OFBucket.Builder setWatchGroup(OFGroup watchGroup) {
229 this.watchGroup = watchGroup;
230 this.watchGroupSet = true;
231 return this;
232 }
233 @Override
234 public List<OFAction> getActions() {
235 return actions;
236 }
237
238 @Override
239 public OFBucket.Builder setActions(List<OFAction> actions) {
240 this.actions = actions;
241 this.actionsSet = true;
242 return this;
243 }
244 @Override
245 public OFVersion getVersion() {
246 return OFVersion.OF_13;
247 }
248
249//
250 @Override
251 public OFBucket build() {
252 int weight = this.weightSet ? this.weight : DEFAULT_WEIGHT;
253 OFPort watchPort = this.watchPortSet ? this.watchPort : DEFAULT_WATCH_PORT;
254 if(watchPort == null)
255 throw new NullPointerException("Property watchPort must not be null");
256 OFGroup watchGroup = this.watchGroupSet ? this.watchGroup : DEFAULT_WATCH_GROUP;
257 if(watchGroup == null)
258 throw new NullPointerException("Property watchGroup must not be null");
259 List<OFAction> actions = this.actionsSet ? this.actions : DEFAULT_ACTIONS;
260 if(actions == null)
261 throw new NullPointerException("Property actions must not be null");
262
263
264 return new OFBucketVer13(
265 weight,
266 watchPort,
267 watchGroup,
268 actions
269 );
270 }
271
272 }
273
274
275 final static Reader READER = new Reader();
276 static class Reader implements OFMessageReader<OFBucket> {
277 @Override
278 public OFBucket readFrom(ChannelBuffer bb) throws OFParseError {
279 int start = bb.readerIndex();
280 int length = U16.f(bb.readShort());
281 if(length < MINIMUM_LENGTH)
282 throw new OFParseError("Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length);
283 if(bb.readableBytes() + (bb.readerIndex() - start) < length) {
284 // Buffer does not have all data yet
285 bb.readerIndex(start);
286 return null;
287 }
288 if(logger.isTraceEnabled())
289 logger.trace("readFrom - length={}", length);
290 int weight = U16.f(bb.readShort());
291 OFPort watchPort = OFPort.read4Bytes(bb);
292 OFGroup watchGroup = OFGroup.read4Bytes(bb);
293 // pad: 4 bytes
294 bb.skipBytes(4);
295 List<OFAction> actions = ChannelUtils.readList(bb, length - (bb.readerIndex() - start), OFActionVer13.READER);
296
297 OFBucketVer13 bucketVer13 = new OFBucketVer13(
298 weight,
299 watchPort,
300 watchGroup,
301 actions
302 );
303 if(logger.isTraceEnabled())
304 logger.trace("readFrom - read={}", bucketVer13);
305 return bucketVer13;
306 }
307 }
308
309 public void putTo(PrimitiveSink sink) {
310 FUNNEL.funnel(this, sink);
311 }
312
313 final static OFBucketVer13Funnel FUNNEL = new OFBucketVer13Funnel();
314 static class OFBucketVer13Funnel implements Funnel<OFBucketVer13> {
315 private static final long serialVersionUID = 1L;
316 @Override
317 public void funnel(OFBucketVer13 message, PrimitiveSink sink) {
318 // FIXME: skip funnel of length
319 sink.putInt(message.weight);
320 message.watchPort.putTo(sink);
321 message.watchGroup.putTo(sink);
322 // skip pad (4 bytes)
323 FunnelUtils.putList(message.actions, sink);
324 }
325 }
326
327
328 public void writeTo(ChannelBuffer bb) {
329 WRITER.write(bb, this);
330 }
331
332 final static Writer WRITER = new Writer();
333 static class Writer implements OFMessageWriter<OFBucketVer13> {
334 @Override
335 public void write(ChannelBuffer bb, OFBucketVer13 message) {
336 int startIndex = bb.writerIndex();
337 // length is length of variable message, will be updated at the end
338 int lengthIndex = bb.writerIndex();
339 bb.writeShort(U16.t(0));
340
341 bb.writeShort(U16.t(message.weight));
342 message.watchPort.write4Bytes(bb);
343 message.watchGroup.write4Bytes(bb);
344 // pad: 4 bytes
345 bb.writeZero(4);
346 ChannelUtils.writeList(bb, message.actions);
347
348 // update length field
349 int length = bb.writerIndex() - startIndex;
350 bb.setShort(lengthIndex, length);
351
352 }
353 }
354
355 @Override
356 public String toString() {
357 StringBuilder b = new StringBuilder("OFBucketVer13(");
358 b.append("weight=").append(weight);
359 b.append(", ");
360 b.append("watchPort=").append(watchPort);
361 b.append(", ");
362 b.append("watchGroup=").append(watchGroup);
363 b.append(", ");
364 b.append("actions=").append(actions);
365 b.append(")");
366 return b.toString();
367 }
368
369 @Override
370 public boolean equals(Object obj) {
371 if (this == obj)
372 return true;
373 if (obj == null)
374 return false;
375 if (getClass() != obj.getClass())
376 return false;
377 OFBucketVer13 other = (OFBucketVer13) obj;
378
379 if( weight != other.weight)
380 return false;
381 if (watchPort == null) {
382 if (other.watchPort != null)
383 return false;
384 } else if (!watchPort.equals(other.watchPort))
385 return false;
386 if (watchGroup == null) {
387 if (other.watchGroup != null)
388 return false;
389 } else if (!watchGroup.equals(other.watchGroup))
390 return false;
391 if (actions == null) {
392 if (other.actions != null)
393 return false;
394 } else if (!actions.equals(other.actions))
395 return false;
396 return true;
397 }
398
399 @Override
400 public int hashCode() {
401 final int prime = 31;
402 int result = 1;
403
404 result = prime * result + weight;
405 result = prime * result + ((watchPort == null) ? 0 : watchPort.hashCode());
406 result = prime * result + ((watchGroup == null) ? 0 : watchGroup.hashCode());
407 result = prime * result + ((actions == null) ? 0 : actions.hashCode());
408 return result;
409 }
410
411}