blob: a2ff50613c14dfe82b1ffb830ba4f28503dac34e [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 java.util.Set;
27import org.slf4j.Logger;
28import org.slf4j.LoggerFactory;
29import org.jboss.netty.buffer.ChannelBuffer;
30import com.google.common.hash.PrimitiveSink;
31import com.google.common.hash.Funnel;
32
33class OFActionSetFieldVer13 implements OFActionSetField {
34 private static final Logger logger = LoggerFactory.getLogger(OFActionSetFieldVer13.class);
35 // version: 1.3
36 final static byte WIRE_VERSION = 4;
37 final static int MINIMUM_LENGTH = 8;
38
39
40 // OF message fields
41 private final OFOxm<?> field;
42//
43
44 // package private constructor - used by readers, builders, and factory
45 OFActionSetFieldVer13(OFOxm<?> field) {
46 this.field = field;
47 }
48
49 // Accessors for OF message fields
50 @Override
51 public OFActionType getType() {
52 return OFActionType.SET_FIELD;
53 }
54
55 @Override
56 public OFOxm<?> getField() {
57 return field;
58 }
59
60 @Override
61 public OFVersion getVersion() {
62 return OFVersion.OF_13;
63 }
64
65
66
67 public OFActionSetField.Builder createBuilder() {
68 return new BuilderWithParent(this);
69 }
70
71 static class BuilderWithParent implements OFActionSetField.Builder {
72 final OFActionSetFieldVer13 parentMessage;
73
74 // OF message fields
75 private boolean fieldSet;
76 private OFOxm<?> field;
77
78 BuilderWithParent(OFActionSetFieldVer13 parentMessage) {
79 this.parentMessage = parentMessage;
80 }
81
82 @Override
83 public OFActionType getType() {
84 return OFActionType.SET_FIELD;
85 }
86
87 @Override
88 public OFOxm<?> getField() {
89 return field;
90 }
91
92 @Override
93 public OFActionSetField.Builder setField(OFOxm<?> field) {
94 this.field = field;
95 this.fieldSet = true;
96 return this;
97 }
98 @Override
99 public OFVersion getVersion() {
100 return OFVersion.OF_13;
101 }
102
103
104
105 @Override
106 public OFActionSetField build() {
107 OFOxm<?> field = this.fieldSet ? this.field : parentMessage.field;
108 if(field == null)
109 throw new NullPointerException("Property field must not be null");
110
111 //
112 return new OFActionSetFieldVer13(
113 field
114 );
115 }
116
117 }
118
119 static class Builder implements OFActionSetField.Builder {
120 // OF message fields
121 private boolean fieldSet;
122 private OFOxm<?> field;
123
124 @Override
125 public OFActionType getType() {
126 return OFActionType.SET_FIELD;
127 }
128
129 @Override
130 public OFOxm<?> getField() {
131 return field;
132 }
133
134 @Override
135 public OFActionSetField.Builder setField(OFOxm<?> field) {
136 this.field = field;
137 this.fieldSet = true;
138 return this;
139 }
140 @Override
141 public OFVersion getVersion() {
142 return OFVersion.OF_13;
143 }
144
145//
146 @Override
147 public OFActionSetField build() {
148 if(!this.fieldSet)
149 throw new IllegalStateException("Property field doesn't have default value -- must be set");
150 if(field == null)
151 throw new NullPointerException("Property field must not be null");
152
153
154 return new OFActionSetFieldVer13(
155 field
156 );
157 }
158
159 }
160
161
162 final static Reader READER = new Reader();
163 static class Reader implements OFMessageReader<OFActionSetField> {
164 @Override
165 public OFActionSetField readFrom(ChannelBuffer bb) throws OFParseError {
166 int start = bb.readerIndex();
167 // fixed value property type == 25
168 short type = bb.readShort();
169 if(type != (short) 0x19)
170 throw new OFParseError("Wrong type: Expected=OFActionType.SET_FIELD(25), got="+type);
171 int length = U16.f(bb.readShort());
172 if(length < MINIMUM_LENGTH)
173 throw new OFParseError("Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length);
174 if(bb.readableBytes() + (bb.readerIndex() - start) < length) {
175 // Buffer does not have all data yet
176 bb.readerIndex(start);
177 return null;
178 }
179 if(logger.isTraceEnabled())
180 logger.trace("readFrom - length={}", length);
181 OFOxm<?> field = OFOxmVer13.READER.readFrom(bb);
182 // align message to 8 bytes (length contains aligned value)
183 bb.skipBytes(length - (bb.readerIndex() - start));
184
185 OFActionSetFieldVer13 actionSetFieldVer13 = new OFActionSetFieldVer13(
186 field
187 );
188 if(logger.isTraceEnabled())
189 logger.trace("readFrom - read={}", actionSetFieldVer13);
190 return actionSetFieldVer13;
191 }
192 }
193
194 public void putTo(PrimitiveSink sink) {
195 FUNNEL.funnel(this, sink);
196 }
197
198 final static OFActionSetFieldVer13Funnel FUNNEL = new OFActionSetFieldVer13Funnel();
199 static class OFActionSetFieldVer13Funnel implements Funnel<OFActionSetFieldVer13> {
200 private static final long serialVersionUID = 1L;
201 @Override
202 public void funnel(OFActionSetFieldVer13 message, PrimitiveSink sink) {
203 // fixed value property type = 25
204 sink.putShort((short) 0x19);
205 // FIXME: skip funnel of length
206 message.field.putTo(sink);
207 }
208 }
209
210
211 public void writeTo(ChannelBuffer bb) {
212 WRITER.write(bb, this);
213 }
214
215 final static Writer WRITER = new Writer();
216 static class Writer implements OFMessageWriter<OFActionSetFieldVer13> {
217 @Override
218 public void write(ChannelBuffer bb, OFActionSetFieldVer13 message) {
219 int startIndex = bb.writerIndex();
220 // fixed value property type = 25
221 bb.writeShort((short) 0x19);
222 // length is length of variable message, will be updated at the end
223 int lengthIndex = bb.writerIndex();
224 bb.writeShort(U16.t(0));
225
226 message.field.writeTo(bb);
227
228 // update length field
229 int length = bb.writerIndex() - startIndex;
230 int alignedLength = ((length + 7)/8 * 8);
231 bb.setShort(lengthIndex, alignedLength);
232 // align message to 8 bytes
233 bb.writeZero(alignedLength - length);
234
235 }
236 }
237
238 @Override
239 public String toString() {
240 StringBuilder b = new StringBuilder("OFActionSetFieldVer13(");
241 b.append("field=").append(field);
242 b.append(")");
243 return b.toString();
244 }
245
246 @Override
247 public boolean equals(Object obj) {
248 if (this == obj)
249 return true;
250 if (obj == null)
251 return false;
252 if (getClass() != obj.getClass())
253 return false;
254 OFActionSetFieldVer13 other = (OFActionSetFieldVer13) obj;
255
256 if (field == null) {
257 if (other.field != null)
258 return false;
259 } else if (!field.equals(other.field))
260 return false;
261 return true;
262 }
263
264 @Override
265 public int hashCode() {
266 final int prime = 31;
267 int result = 1;
268
269 result = prime * result + ((field == null) ? 0 : field.hashCode());
270 return result;
271 }
272
273}