blob: 2b4801c478c191386dd8cd7d1255ee03370628b0 [file] [log] [blame]
Andreas Wundsam40e14f72013-05-06 14:49:08 -07001//:: # Copyright 2013, Big Switch Networks, Inc.
2//:: #
3//:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
4//:: # the following special exception:
5//:: #
6//:: # LOXI Exception
7//:: #
8//:: # As a special exception to the terms of the EPL, you may distribute libraries
9//:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
10//:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
11//:: # from the LoxiGen Libraries and the notice provided below is (i) included in
12//:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
13//:: # documentation for the LoxiGen Libraries, if distributed in binary form.
14//:: #
15//:: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
16//:: #
17//:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
18//:: # a copy of the EPL at:
19//:: #
20//:: # http::: #www.eclipse.org/legal/epl-v10.html
21//:: #
22//:: # Unless required by applicable law or agreed to in writing, software
23//:: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24//:: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
25//:: # EPL for the specific language governing permissions and limitations
26//:: # under the EPL.
27//::
28//:: import itertools
29//:: import of_g
30//:: include('_copyright.java')
31
32//:: include('_autogen.java')
33
34package org.openflow.protocol;
35import java.util.Collections;
36import java.util.List;
37import org.openflow.protocol.actions.OFAction;
38import org.openflow.protocol.instructions.OFInstruction;
39import org.openflow.protocol.match.*;
40import org.openflow.types.*;
41import org.openflow.types.*;
42import org.openflow.util.*;
43import org.openflow.exceptions.*;
44import org.jboss.netty.buffer.ChannelBuffer;
45
46class ${impl_class} implements ${msg.interface_name} {
47//:: if msg.is_fixed_length(version):
48 private static final int LENGTH = ${msg.min_length(version) };
49//:: else:
50 private static final int MINIMUM_LENGTH = ${msg.min_length(version) };
51//:: #endif
52
53//:: for prop in msg.properties_for_version(version):
54 private final static ${prop.java_type.public_type} ${prop.default_name} = ${prop.default_value};
55//:: #end
56 private boolean xidSet;
57 private final int xid;
58
59 // OF message fields
60//:: for prop in msg.properties_for_version(version):
61 private final ${prop.java_type.public_type} ${prop.name};
62//:: #endfor
63
64 // Constructor
65 ${impl_class}(${
66 ", ".join(["int xid" ] + [ "%s %s" %(prop.java_type.public_type, prop.name) for prop in msg.properties_for_version(version) ])}) {
67 this.xidSet = true;
68 this.xid = xid;
69//:: for prop in msg.properties_for_version(version):
70 this.${prop.name} = ${prop.name};
71//:: #endfor
72 }
73
74 ${impl_class}(${
75 ", ".join("%s %s" %(prop.java_type.public_type, prop.name) for prop in msg.properties_for_version(version)) }) {
76 this.xidSet = false;
77 this.xid = 0;
78//:: for prop in msg.properties_for_version(version):
79 this.${prop.name} = ${prop.name};
80//:: #endfor
81 }
82
83 @Override
84 public int getXid() {
85 return xid;
86 }
87
88 @Override
89 public boolean isXidSet() {
90 return xidSet;
91 }
92
93 @Override
94 public OFType getType() {
95 return OFType.${msg.constant_name};
96 }
97
98 @Override
99 public OFVersion getVersion() {
100 return OFVersion.${version.constant_version};
101 }
102
103 // Accessors for OF message fields
104//:: for prop in msg.all_properties():
105 @Override
106 public ${prop.java_type.public_type} get${prop.title_name}()${ "" if msg.property_in_version(prop, version) else "throws UnsupportedOperationException"} {
107//:: if msg.property_in_version(prop, version):
108 return ${prop.name};
109//:: else:
110 throw new UnsupportedOperationException("Property ${prop.name} not supported in version #{version}");
111//:: #endif
112 }
113//:: #endfor
114
115 public ${msg.interface_name}.Builder createBuilder() {
116 return new BuilderImplWithParent(this);
117 }
118
119 static class BuilderImplWithParent implements ${msg.interface_name}.Builder {
120 final ${impl_class} parentMessage;
121 private boolean xidSet;
122 private int xid;
123
124 // OF message fields
125//:: for prop in msg.properties_for_version(version):
126 private boolean ${prop.name}Set;
127 private ${prop.java_type.public_type} ${prop.name};
128//:: #endfor
129
130 BuilderImplWithParent(${impl_class} parentMessage) {
131 this.parentMessage = parentMessage;
132 }
133
134//:: for prop in msg.all_properties():
135 @Override
136 public ${prop.java_type.public_type} get${prop.title_name}()${ "" if msg.property_in_version(prop, version) else " throws UnsupportedOperationException"} {
137//:: if msg.property_in_version(prop, version):
138 return ${prop.name};
139//:: else:
140 throw new UnsupportedOperationException("Property ${prop.name} not supported in version #{version}");
141//:: #endif
142 }
143 @Override
144 public ${msg.interface_name}.Builder set${prop.title_name}(${prop.java_type.public_type} ${prop.name})${ "" if msg.property_in_version(prop, version) else " throws UnsupportedOperationException"} {
145//:: if msg.property_in_version(prop, version):
146 this.${prop.name} = ${prop.name};
147 this.${prop.name}Set = true;
148 return this;
149//:: else:
150 throw new UnsupportedOperationException("Property ${prop.name} not supported in version #{version}");
151//:: #endif
152 }
153//:: #endfor
154 @Override
155 public ${msg.interface_name} getMessage() {
156 if(this.xidSet) {
157 return new ${impl_class}(
158 ${",\n ".join(
159 [ "xid" ] +
160 [ "this.{0}Set ? this.{0} : parentMessage.{0}".format(prop.name)
161 for prop in msg.properties_for_version(version)])}
162 );
163 } else {
164 return new ${impl_class}(
165 ${",\n ".join(
166 [ "this.{0}Set ? this.{0} : parentMessage.{0}".format(prop.name)
167 for prop in msg.properties_for_version(version)])}
168 );
169 }
170 }
171 }
172
173 static class BuilderImpl implements ${msg.interface_name}.Builder {
174 private boolean xidSet;
175 private int xid;
176
177 // OF message fields
178//:: for prop in msg.properties_for_version(version):
179 private boolean ${prop.name}Set;
180 private ${prop.java_type.public_type} ${prop.name};
181//:: #endfor
182
183//:: for prop in msg.all_properties():
184 @Override
185 public ${prop.java_type.public_type} get${prop.title_name}()${ "" if msg.property_in_version(prop, version) else " throws UnsupportedOperationException"} {
186//:: if msg.property_in_version(prop, version):
187 return ${prop.name};
188//:: else:
189 throw new UnsupportedOperationException("Property ${prop.name} not supported in version #{version}");
190//:: #endif
191 }
192 @Override
193 public ${msg.interface_name}.Builder set${prop.title_name}(${prop.java_type.public_type} ${prop.name})${ "" if msg.property_in_version(prop, version) else " throws UnsupportedOperationException"} {
194//:: if msg.property_in_version(prop, version):
195 this.${prop.name} = ${prop.name};
196 this.${prop.name}Set = true;
197 return this;
198//:: else:
199 throw new UnsupportedOperationException("Property ${prop.name} not supported in version #{version}");
200//:: #endif
201 }
202//:: #endfor
203 @Override
204 public ${msg.interface_name} getMessage() {
205 if(this.xidSet) {
206 return new ${impl_class}(
207 ${",\n ".join(
208 [ "xid" ] +
209 [ "this.{0}Set ? this.{0} : {1}.{2}".format(prop.name, impl_class, prop.default_name)
210 for prop in msg.properties_for_version(version)])}
211 );
212 } else {
213 return new ${impl_class}(
214 ${",\n ".join(
215 [ "this.{0}Set ? this.{0} : {1}.{2}".format(prop.name, impl_class, prop.default_name)
216 for prop in msg.properties_for_version(version)])}
217 );
218 }
219 }
220 }
221
222 final static Reader READER = new Reader();
223 static class Reader implements OFMessageReader<${msg.interface_name}> {
224 @Override
225 public ${msg.interface_name} readFrom(ChannelBuffer bb) throws OFParseError {
226 byte version = bb.readByte();
227 if (version != (byte) ${version.int_version})
228 throw new OFParseError("Wrong version: Expected=${version.int_version}, got="+version);
229
230 byte type = bb.readByte();
231 if(type != ${msg.wire_type(version)})
232 throw new OFParseError("Wrong message type: Expected=${msg.constant_name}, got="+type);
233
234 int length = bb.readUnsignedShort();
235//:: if msg.is_fixed_length(version):
236 if(length != LENGTH)
237 throw new OFParseError("Wrong message length: Expected="+LENGTH +", got="+length);
238//:: else:
239 if(length < MINIMUM_LENGTH)
240 throw new OFParseError("Insufficient message length: minimum length="+MINIMUM_LENGTH +", got="+length);
241//:: #endif
242 int xid = bb.readInt();
243//:: for prop in msg.properties_for_version(version, skip_pads=False):
244//:: if prop.is_pad:
245 // pad: ${prop.length} bytes
246 bb.skipBytes(${prop.length});
247//:: else:
248 ${prop.java_type.public_type} ${prop.name} = ${prop.java_type.read_op(version)};
249//:: #endif
250//:: #endfor
251 return new ${impl_class}(
252 ${",\n ".join(
253 [ "xid" ] + [ prop.name for prop in msg.properties_for_version(version)])}
254 );
255 }
256 }
257
258}