Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 1 | import errno |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 2 | import os |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 3 | import re |
| 4 | import subprocess |
| 5 | import time |
| 6 | |
Andreas Wundsam | c8912c1 | 2013-11-15 13:44:48 -0800 | [diff] [blame] | 7 | import loxi_globals |
Andreas Wundsam | 7cfeac3 | 2013-09-17 13:53:48 -0700 | [diff] [blame] | 8 | from generic_utils import memoize |
| 9 | import loxi_utils.loxi_utils as loxi_utils |
Andreas Wundsam | 7cfeac3 | 2013-09-17 13:53:48 -0700 | [diff] [blame] | 10 | |
Andreas Wundsam | 2be7da5 | 2013-08-22 07:34:25 -0700 | [diff] [blame] | 11 | def erase_type_annotation(class_name): |
| 12 | m=re.match(r'(.*)<.*>', class_name) |
| 13 | if m: |
| 14 | return m.group(1) |
| 15 | else: |
| 16 | return class_name |
| 17 | |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 18 | def name_c_to_camel(name): |
| 19 | """ 'of_stats_reply' -> 'ofStatsReply' """ |
| 20 | name = re.sub(r'^_','', name) |
| 21 | tokens = name.split('_') |
| 22 | for i in range(1, len(tokens)): |
| 23 | tokens[i] = tokens[i].title() |
| 24 | return "".join(tokens) |
| 25 | |
| 26 | def name_c_to_caps_camel(name): |
| 27 | """ 'of_stats_reply' to 'OFStatsReply' """ |
| 28 | camel = name_c_to_camel(name.title()) |
Andreas Wundsam | 7cfeac3 | 2013-09-17 13:53:48 -0700 | [diff] [blame] | 29 | if camel.startswith('Ofp'): |
| 30 | return camel.replace('Ofp','OF',1) |
| 31 | elif camel.startswith('Of'): |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 32 | return camel.replace('Of','OF',1) |
| 33 | else: |
| 34 | return camel |
| 35 | |
Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame] | 36 | java_primitive_types = set("boolean byte char short int long".split(" ")) |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 37 | |
| 38 | ### info table about java primitive types, for casting literals in the source code |
| 39 | # { name : (signed?, length_in_bits) } |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 40 | java_primitives_info = { |
Andreas Wundsam | 438a9c3 | 2013-10-07 16:18:52 -0700 | [diff] [blame] | 41 | 'boolean' : (False, 8, False), |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 42 | 'byte' : (True, 8, True), |
| 43 | 'char' : (False, 16, True), |
| 44 | 'short' : (True, 16, True), |
| 45 | 'int' : (True, 32, False), |
| 46 | 'long' : (True, 64, False), |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 49 | def format_primitive_literal(t, value): |
| 50 | """ Format a primitive numeric literal for inclusion in the |
| 51 | java source code. Takes care of casting the literal |
Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame] | 52 | appropriately for correct representation despite Java's |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 53 | signed-craziness |
| 54 | """ |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 55 | signed, bits, cast_needed = java_primitives_info[t] |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 56 | max = (1 << bits)-1 |
| 57 | if value > max: |
| 58 | raise Exception("Value %d to large for type %s" % (value, t)) |
| 59 | |
| 60 | if signed: |
| 61 | max_pos = (1 << (bits-1)) - 1 |
| 62 | |
| 63 | if value > max_pos: |
| 64 | if t == "long": |
| 65 | return str((1 << bits) - value) |
| 66 | else: |
| 67 | return "(%s) 0x%x" % (t, value) |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 68 | return "%s0x%x%s" % ("(%s) " % t if cast_needed else "", value, "L" if t=="long" else "") |
| 69 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 70 | |
Andreas Wundsam | e916d6f | 2013-07-30 11:33:58 -0700 | [diff] [blame] | 71 | ANY = 0xFFFFFFFFFFFFFFFF |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 72 | |
| 73 | class VersionOp: |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 74 | def __init__(self, version=ANY, read=None, write=None, default=None, funnel=None): |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 75 | self.version = version |
| 76 | self.read = read |
| 77 | self.write = write |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 78 | self.default = default |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 79 | self.funnel = funnel |
Andreas Wundsam | e916d6f | 2013-07-30 11:33:58 -0700 | [diff] [blame] | 80 | |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 81 | def __str__(self): |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 82 | return "[Version: %d, Read: '%s', Write: '%s', Default: '%s', Funnel: '%s' ]" % (self.version, self.read, self.write, self.default, self.funnel ) |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 83 | |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 84 | ### FIXME: This class should really be cleaned up |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 85 | class JType(object): |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 86 | """ Wrapper class to hold C to Java type conversion information. JTypes can have a 'public' |
| 87 | and or 'private' java type associated with them and can define how those types can be |
| 88 | read from and written to ChannelBuffers. |
| 89 | |
| 90 | """ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 91 | def __init__(self, pub_type, priv_type=None): |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 92 | self.pub_type = pub_type # the type we expose externally, e.g. 'U8' |
| 93 | if priv_type is None: |
| 94 | priv_type = pub_type |
| 95 | self.priv_type = priv_type # the internal storage type |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 96 | self.ops = {} |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 97 | |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 98 | def set_priv_type(self, priv_type): |
| 99 | self.priv_type = priv_type |
| 100 | return self |
| 101 | |
| 102 | def op(self, version=ANY, read=None, write=None, default=None, funnel=None, pub_type=ANY): |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 103 | """ |
| 104 | define operations to be performed for reading and writing this type |
| 105 | (when read_op, write_op is called). The operations 'read' and 'write' |
| 106 | can either be strings ($name, and $version and $length will be replaced), |
| 107 | or callables (name, version and length) will be passed. |
| 108 | |
| 109 | @param version int OF version to define operation for, or ANY for all |
| 110 | @param pub_type boolean whether to define operations for the public type (True), the |
| 111 | private type(False) or both (ALL) |
| 112 | @param read read expression (either string or callable)s |
| 113 | @param write write expression (either string or callable) |
| 114 | """ |
| 115 | |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 116 | pub_types = [ pub_type ] if pub_type is not ANY else [ False, True ] |
| 117 | for pub_type in pub_types: |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 118 | self.ops[(version, pub_type)] = VersionOp(version, read, write, default, funnel) |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 119 | return self |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 120 | |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 121 | def format_value(self, value, pub_type=True): |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 122 | # Format a constant value of this type, for inclusion in the java source code |
| 123 | # For primitive types, takes care of casting the value appropriately, to |
| 124 | # cope with java's signedness limitation |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 125 | t = self.pub_type if pub_type else self.priv_type |
| 126 | if t in java_primitive_types: |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 127 | return format_primitive_literal(t, value) |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 128 | else: |
| 129 | return value |
Andreas Wundsam | bf1dbbd | 2013-07-30 11:07:59 -0700 | [diff] [blame] | 130 | |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 131 | @property |
| 132 | def public_type(self): |
| 133 | """ return the public type """ |
| 134 | return self.pub_type |
| 135 | |
| 136 | def priv(self): |
| 137 | """ return the public type """ |
| 138 | return self.priv_type |
| 139 | |
| 140 | def has_priv(self): |
| 141 | """ Is the private type different from the public one?""" |
| 142 | return self.pub_type != self.priv_type |
| 143 | |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 144 | def get_op(self, op_type, version, pub_type, default_value, arguments): |
| 145 | ver = ANY if version is None else version.int_version |
| 146 | |
| 147 | if not "version" in arguments: |
Andreas Wundsam | c8912c1 | 2013-11-15 13:44:48 -0800 | [diff] [blame] | 148 | arguments["version"] = version.dotless_version |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 149 | |
| 150 | def lookup(ver, pub_type): |
| 151 | if (ver, pub_type) in self.ops: |
| 152 | return getattr(self.ops[(ver, pub_type)], op_type) |
| 153 | else: |
| 154 | return None |
| 155 | |
| 156 | _op = lookup(ver, pub_type) or lookup(ANY, pub_type) or default_value |
| 157 | if callable(_op): |
| 158 | return _op(**arguments) |
| 159 | else: |
| 160 | return reduce(lambda a,repl: a.replace("$%s" % repl[0], str(repl[1])), arguments.items(), _op) |
| 161 | |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 162 | def read_op(self, version=None, length=None, pub_type=True): |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 163 | """ return a Java stanza that reads a value of this JType from ChannelBuffer bb. |
| 164 | @param version int - OF wire version to generate expression for |
| 165 | @param pub_type boolean use this JTypes 'public' (True), or private (False) representation |
| 166 | @param length string, for operations that need it (e.g., read a list of unknown length) |
| 167 | Java expression evaluating to the byte length to be read. Defaults to the remainig |
| 168 | length of the message. |
| 169 | @return string containing generated Java expression. |
| 170 | """ |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 171 | if length is None: |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 172 | # assumes that |
| 173 | # (1) length of the message has been read to 'length' |
| 174 | # (2) readerIndex at the start of the message has been stored in 'start' |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 175 | length = "length - (bb.readerIndex() - start)" |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 176 | |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 177 | return self.get_op("read", version, pub_type, |
| 178 | default_value='ChannelUtilsVer$version.read%s(bb)' % self.pub_type, |
| 179 | arguments=dict(length=length) |
| 180 | ) |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 181 | |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 182 | def write_op(self, version=None, name=None, pub_type=True): |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 183 | """ return a Java stanza that writes a value of this JType contained in Java expression |
| 184 | 'name' to ChannelBuffer bb. |
| 185 | @param name string containing Java expression that evaluations to the value to be written |
| 186 | @param version int - OF wire version to generate expression for |
| 187 | @param pub_type boolean use this JTypes 'public' (True), or private (False) representation |
| 188 | @return string containing generated Java expression. |
| 189 | """ |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 190 | |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 191 | return self.get_op("write", version, pub_type, |
| 192 | default_value='ChannelUtilsVer$version.write%s(bb, $name)' % self.pub_type, |
| 193 | arguments=dict(name=name) |
| 194 | ) |
| 195 | |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 196 | |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 197 | def default_op(self, version=None, pub_type=True): |
| 198 | """ return a Java stanza that returns a default value of this JType. |
| 199 | @param version JavaOFVersion |
| 200 | @return string containing generated Java expression. |
| 201 | """ |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 202 | return self.get_op("default", version, pub_type, |
| 203 | arguments = dict(), |
| 204 | default_value = self.format_value(0) if self.is_primitive else "null" |
| 205 | ) |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 206 | |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 207 | def skip_op(self, version=None, length=None): |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 208 | """ return a java stanza that skips an instance of JType in the input ChannelBuffer 'bb'. |
| 209 | This is used in the Reader implementations for virtual classes (because after the |
| 210 | discriminator field, the concrete Reader instance will re-read all the fields) |
| 211 | Currently just delegates to read_op + throws away the result.""" |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 212 | return self.read_op(version, length) |
| 213 | |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 214 | def funnel_op(self, version=None, name=None, pub_type=True): |
| 215 | t = self.pub_type if pub_type else self.priv_type |
| 216 | return self.get_op("funnel", version, pub_type, |
| 217 | arguments = dict(name=name), |
| 218 | default_value = '$name.putTo(sink)' if not self._is_primitive(pub_type) else "sink.put{}($name)".format(t[0].upper() + t[1:]) |
| 219 | ) |
| 220 | |
Andreas Wundsam | e916d6f | 2013-07-30 11:33:58 -0700 | [diff] [blame] | 221 | @property |
| 222 | def is_primitive(self): |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 223 | return self._is_primitive() |
| 224 | |
| 225 | def _is_primitive(self, pub_type=True): |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 226 | """ return true if the pub_type is a java primitive type (and thus needs |
| 227 | special treatment, because it doesn't have methods)""" |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 228 | t = self.pub_type if pub_type else self.priv_type |
| 229 | return t in java_primitive_types |
Andreas Wundsam | e916d6f | 2013-07-30 11:33:58 -0700 | [diff] [blame] | 230 | |
| 231 | @property |
| 232 | def is_array(self): |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 233 | return self._is_array() |
Andreas Wundsam | e916d6f | 2013-07-30 11:33:58 -0700 | [diff] [blame] | 234 | |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 235 | def _is_array(self, pub_type=True): |
| 236 | t = self.pub_type if pub_type else self.priv_type |
| 237 | return t.endswith("[]") |
| 238 | |
| 239 | # Create a default mapping for a list type. Type defauls to List<${java_mapping_of_name}> |
| 240 | def gen_enum_jtype(java_name, is_bitmask=False): |
| 241 | if is_bitmask: |
| 242 | java_type = "Set<{}>".format(java_name) |
| 243 | default_value = "ImmutableSet.<{}>of()".format(java_name) |
| 244 | else: |
| 245 | java_type = java_name |
| 246 | default_value = "null" |
| 247 | |
| 248 | serializer = "{}SerializerVer$version".format(java_name) |
| 249 | |
| 250 | return JType(java_type)\ |
| 251 | .op(read="{}.readFrom(bb)".format(serializer), |
| 252 | write="{}.writeTo(bb, $name)".format(serializer), |
| 253 | default=default_value, |
| 254 | funnel="{}.putTo($name, sink)".format(serializer) |
| 255 | ) |
| 256 | |
| 257 | def gen_list_jtype(java_base_name): |
| 258 | # read op assumes the class has a public final static field READER that implements |
| 259 | # OFMessageReader<$class> i.e., can deserialize an instance of class from a ChannelBuffer |
| 260 | # write op assumes class implements Writeable |
| 261 | return JType("List<{}>".format(java_base_name)) \ |
| 262 | .op( |
| 263 | read= 'ChannelUtils.readList(bb, $length, {}Ver$version.READER)'.format(java_base_name), \ |
| 264 | write='ChannelUtils.writeList(bb, $name)', |
| 265 | default="ImmutableList.<{}>of()".format(java_base_name), |
| 266 | funnel='FunnelUtils.putList($name, sink)' |
| 267 | ) |
| 268 | |
| 269 | def gen_fixed_length_string_jtype(length): |
| 270 | return JType('String').op( |
| 271 | read='ChannelUtils.readFixedLengthString(bb, {})'.format(length), |
| 272 | write='ChannelUtils.writeFixedLengthString(bb, $name, {})'.format(length), |
| 273 | default='""', |
| 274 | funnel='sink.putUnencodedChars($name)' |
| 275 | ) |
Andreas Wundsam | e916d6f | 2013-07-30 11:33:58 -0700 | [diff] [blame] | 276 | |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 277 | ##### Predefined JType mappings |
| 278 | # FIXME: This list needs to be pruned / cleaned up. Most of these are schematic. |
| 279 | |
Andreas Wundsam | 2bf357c | 2013-08-03 22:50:40 -0700 | [diff] [blame] | 280 | u8 = JType('short', 'byte') \ |
Andreas Wundsam | 83d877a | 2013-09-30 14:26:44 -0700 | [diff] [blame] | 281 | .op(read='U8.f(bb.readByte())', write='bb.writeByte(U8.t($name))', pub_type=True) \ |
| 282 | .op(read='bb.readByte()', write='bb.writeByte($name)', pub_type=False) |
Andreas Wundsam | 2bf357c | 2013-08-03 22:50:40 -0700 | [diff] [blame] | 283 | u8_list = JType('List<U8>') \ |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 284 | .op(read='ChannelUtils.readList(bb, $length, U8.READER)', |
| 285 | write='ChannelUtils.writeList(bb, $name)', |
| 286 | default='ImmutableList.<U8>of()', |
| 287 | funnel='FunnelUtils.putList($name, sink)' |
| 288 | ) |
Andreas Wundsam | 2bf357c | 2013-08-03 22:50:40 -0700 | [diff] [blame] | 289 | u16 = JType('int', 'short') \ |
| 290 | .op(read='U16.f(bb.readShort())', write='bb.writeShort(U16.t($name))', pub_type=True) \ |
| 291 | .op(read='bb.readShort()', write='bb.writeShort($name)', pub_type=False) |
| 292 | u32 = JType('long', 'int') \ |
| 293 | .op(read='U32.f(bb.readInt())', write='bb.writeInt(U32.t($name))', pub_type=True) \ |
| 294 | .op(read='bb.readInt()', write='bb.writeInt($name)', pub_type=False) |
| 295 | u32_list = JType('List<U32>', 'int[]') \ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 296 | .op( |
| 297 | read='ChannelUtils.readList(bb, $length, U32.READER)', |
| 298 | write='ChannelUtils.writeList(bb, $name)', |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 299 | default="ImmutableList.<U32>of()", |
| 300 | funnel="FunnelUtils.putList($name, sink)") |
xinwu | f08ef68 | 2013-12-05 18:29:20 -0800 | [diff] [blame] | 301 | u64_list = JType('List<U64>', 'int[]') \ |
| 302 | .op( |
| 303 | read='ChannelUtils.readList(bb, $length, U64.READER)', |
| 304 | write='ChannelUtils.writeList(bb, $name)', |
| 305 | default="ImmutableList.<U64>of()", |
| 306 | funnel="FunnelUtils.putList($name, sink)") |
Yotam Harchol | 5804f77 | 2013-08-21 17:35:31 -0700 | [diff] [blame] | 307 | u8obj = JType('U8', 'U8') \ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 308 | .op(read='U8.of(bb.readByte())', write='bb.writeByte($name.getRaw())', default="U8.ZERO") |
Yotam Harchol | 5804f77 | 2013-08-21 17:35:31 -0700 | [diff] [blame] | 309 | u32obj = JType('U32', 'U32') \ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 310 | .op(read='U32.of(bb.readInt())', write='bb.writeInt($name.getRaw())', default="U32.ZERO") |
Sovietaced | 3d42dbe | 2014-01-23 15:55:48 -0800 | [diff] [blame] | 311 | u64 = JType('U64', 'long') \ |
| 312 | .op(read='U64.ofRaw(bb.readLong())', write='bb.writeLong($name.getValue())', default="U64.ZERO", pub_type=True) \ |
| 313 | .op(read='bb.readLong()', write='bb.writeLong($name)', pub_type=False) |
Andreas Wundsam | 7c15b17 | 2014-04-24 19:02:40 -0700 | [diff] [blame] | 314 | u128 = JType("U128") \ |
| 315 | .op(read='U128.read16Bytes(bb)', |
| 316 | write='$name.write16Bytes(bb)', |
| 317 | default='U128.ZERO') |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 318 | of_port = JType("OFPort") \ |
Andreas Wundsam | ad499c9 | 2013-09-28 18:56:49 -0700 | [diff] [blame] | 319 | .op(version=1, read="OFPort.read2Bytes(bb)", write="$name.write2Bytes(bb)", default="OFPort.ANY") \ |
| 320 | .op(version=ANY, read="OFPort.read4Bytes(bb)", write="$name.write4Bytes(bb)", default="OFPort.ANY") |
Andreas Wundsam | e962d37 | 2013-10-02 18:15:58 -0700 | [diff] [blame] | 321 | # the same OFPort, but with a default value of ZERO, only for OF10 match |
| 322 | of_port_match_v1 = JType("OFPort") \ |
| 323 | .op(version=1, read="OFPort.read2Bytes(bb)", write="$name.write2Bytes(bb)", default="OFPort.ZERO") |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 324 | actions_list = gen_list_jtype("OFAction") |
| 325 | instructions_list = gen_list_jtype("OFInstruction") |
| 326 | buckets_list = gen_list_jtype("OFBucket") |
| 327 | port_desc_list = gen_list_jtype("OFPortDesc") |
| 328 | packet_queue_list = gen_list_jtype("OFPacketQueue") |
Andreas Wundsam | 2bf357c | 2013-08-03 22:50:40 -0700 | [diff] [blame] | 329 | port_desc = JType('OFPortDesc') \ |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 330 | .op(read='OFPortDescVer$version.READER.readFrom(bb)', \ |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 331 | write='$name.writeTo(bb)') |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 332 | octets = JType('byte[]')\ |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 333 | .op(read='ChannelUtils.readBytes(bb, $length)', \ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 334 | write='bb.writeBytes($name)', \ |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 335 | default="new byte[0]", |
| 336 | funnel="sink.putBytes($name)" |
| 337 | ); |
Andreas Wundsam | 2bf357c | 2013-08-03 22:50:40 -0700 | [diff] [blame] | 338 | of_match = JType('Match') \ |
Andreas Wundsam | 951ada3 | 2013-08-01 22:05:38 -0700 | [diff] [blame] | 339 | .op(read='ChannelUtilsVer$version.readOFMatch(bb)', \ |
Andreas Wundsam | e962d37 | 2013-10-02 18:15:58 -0700 | [diff] [blame] | 340 | write='$name.writeTo(bb)', |
| 341 | default="OFFactoryVer$version.MATCH_WILDCARD_ALL"); |
Andreas Wundsam | 5812cf3 | 2013-11-15 13:51:24 -0800 | [diff] [blame] | 342 | group_mod_cmd = JType('OFGroupModCommand', 'short') \ |
| 343 | .op(version=ANY, read="bb.readShort()", write="bb.writeShort($name)") |
Andreas Wundsam | 2bf357c | 2013-08-03 22:50:40 -0700 | [diff] [blame] | 344 | flow_mod_cmd = JType('OFFlowModCommand', 'short') \ |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 345 | .op(version=1, read="bb.readShort()", write="bb.writeShort($name)") \ |
| 346 | .op(version=ANY, read="bb.readByte()", write="bb.writeByte($name)") |
Andreas Wundsam | 2bf357c | 2013-08-03 22:50:40 -0700 | [diff] [blame] | 347 | mac_addr = JType('MacAddress') \ |
Yotam Harchol | d7b8420 | 2013-07-26 16:08:10 -0700 | [diff] [blame] | 348 | .op(read="MacAddress.read6Bytes(bb)", \ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 349 | write="$name.write6Bytes(bb)", |
| 350 | default="MacAddress.NONE") |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 351 | |
| 352 | port_name = gen_fixed_length_string_jtype(16) |
| 353 | desc_str = gen_fixed_length_string_jtype(256) |
| 354 | serial_num = gen_fixed_length_string_jtype(32) |
| 355 | table_name = gen_fixed_length_string_jtype(32) |
Rich Lane | f8a3d00 | 2014-03-19 13:33:52 -0700 | [diff] [blame] | 356 | str64 = gen_fixed_length_string_jtype(64) |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 357 | ipv4 = JType("IPv4Address") \ |
| 358 | .op(read="IPv4Address.read4Bytes(bb)", \ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 359 | write="$name.write4Bytes(bb)", |
| 360 | default='IPv4Address.NONE') |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 361 | ipv6 = JType("IPv6Address") \ |
| 362 | .op(read="IPv6Address.read16Bytes(bb)", \ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 363 | write="$name.write16Bytes(bb)", |
| 364 | default='IPv6Address.NONE') |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 365 | packetin_reason = gen_enum_jtype("OFPacketInReason") |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 366 | transport_port = JType("TransportPort")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 367 | .op(read="TransportPort.read2Bytes(bb)", |
| 368 | write="$name.write2Bytes(bb)", |
| 369 | default="TransportPort.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 370 | eth_type = JType("EthType")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 371 | .op(read="EthType.read2Bytes(bb)", |
| 372 | write="$name.write2Bytes(bb)", |
| 373 | default="EthType.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 374 | vlan_vid = JType("VlanVid")\ |
Andreas Wundsam | 98a1863 | 2013-11-05 11:34:24 -0800 | [diff] [blame] | 375 | .op(version=ANY, read="VlanVid.read2Bytes(bb)", write="$name.write2Bytes(bb)", default="VlanVid.ZERO") |
| 376 | vlan_vid_match = JType("OFVlanVidMatch")\ |
| 377 | .op(version=1, read="OFVlanVidMatch.read2BytesOF10(bb)", write="$name.write2BytesOF10(bb)", default="OFVlanVidMatch.NONE") \ |
| 378 | .op(version=2, read="OFVlanVidMatch.read2BytesOF10(bb)", write="$name.write2BytesOF10(bb)", default="OFVlanVidMatch.NONE") \ |
| 379 | .op(version=ANY, read="OFVlanVidMatch.read2Bytes(bb)", write="$name.write2Bytes(bb)", default="OFVlanVidMatch.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 380 | vlan_pcp = JType("VlanPcp")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 381 | .op(read="VlanPcp.readByte(bb)", |
| 382 | write="$name.writeByte(bb)", |
| 383 | default="VlanPcp.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 384 | ip_dscp = JType("IpDscp")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 385 | .op(read="IpDscp.readByte(bb)", |
| 386 | write="$name.writeByte(bb)", |
| 387 | default="IpDscp.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 388 | ip_ecn = JType("IpEcn")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 389 | .op(read="IpEcn.readByte(bb)", |
| 390 | write="$name.writeByte(bb)", |
| 391 | default="IpEcn.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 392 | ip_proto = JType("IpProtocol")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 393 | .op(read="IpProtocol.readByte(bb)", |
| 394 | write="$name.writeByte(bb)", |
| 395 | default="IpProtocol.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 396 | icmpv4_type = JType("ICMPv4Type")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 397 | .op(read="ICMPv4Type.readByte(bb)", |
| 398 | write="$name.writeByte(bb)", |
| 399 | default="ICMPv4Type.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 400 | icmpv4_code = JType("ICMPv4Code")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 401 | .op(read="ICMPv4Code.readByte(bb)", |
| 402 | write="$name.writeByte(bb)", |
| 403 | default="ICMPv4Code.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 404 | arp_op = JType("ArpOpcode")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 405 | .op(read="ArpOpcode.read2Bytes(bb)", |
| 406 | write="$name.write2Bytes(bb)", |
| 407 | default="ArpOpcode.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 408 | ipv6_flabel = JType("IPv6FlowLabel")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 409 | .op(read="IPv6FlowLabel.read4Bytes(bb)", |
| 410 | write="$name.write4Bytes(bb)", |
| 411 | default="IPv6FlowLabel.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 412 | metadata = JType("OFMetadata")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 413 | .op(read="OFMetadata.read8Bytes(bb)", |
| 414 | write="$name.write8Bytes(bb)", |
| 415 | default="OFMetadata.NONE") |
Andreas Wundsam | 2be7da5 | 2013-08-22 07:34:25 -0700 | [diff] [blame] | 416 | oxm = JType("OFOxm<?>")\ |
| 417 | .op( read="OFOxmVer$version.READER.readFrom(bb)", |
| 418 | write="$name.writeTo(bb)") |
| 419 | oxm_list = JType("OFOxmList") \ |
| 420 | .op( |
| 421 | read= 'OFOxmList.readFrom(bb, $length, OFOxmVer$version.READER)', \ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 422 | write='$name.writeTo(bb)', |
| 423 | default="OFOxmList.EMPTY") |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 424 | meter_features = JType("OFMeterFeatures")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 425 | .op(read="OFMeterFeaturesVer$version.READER.readFrom(bb)", |
| 426 | write="$name.writeTo(bb)") |
Wilson Ng | d618188 | 2014-04-14 16:28:35 -0700 | [diff] [blame] | 427 | bsn_vport = JType("OFBsnVport")\ |
| 428 | .op(read="OFBsnVportVer$version.READER.readFrom(bb)", |
Andreas Wundsam | 113d25b | 2014-01-22 20:17:37 -0800 | [diff] [blame] | 429 | write="$name.writeTo(bb)") |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 430 | flow_wildcards = JType("int") \ |
| 431 | .op(read='bb.readInt()', |
| 432 | write='bb.writeInt($name)', |
| 433 | default="OFFlowWildcardsSerializerVer$version.ALL_VAL") |
| 434 | table_stats_wildcards = JType("int") \ |
| 435 | .op(read='bb.readInt()', |
| 436 | write='bb.writeInt($name)') |
Yotam Harchol | 2c53558 | 2013-10-01 15:50:20 -0700 | [diff] [blame] | 437 | port_bitmap = JType('OFBitMask128') \ |
| 438 | .op(read='OFBitMask128.read16Bytes(bb)', |
Yotam Harchol | a11f38b | 2013-09-26 15:38:17 -0700 | [diff] [blame] | 439 | write='$name.write16Bytes(bb)', |
Yotam Harchol | 2c53558 | 2013-10-01 15:50:20 -0700 | [diff] [blame] | 440 | default='OFBitMask128.NONE') |
Andreas Wundsam | 37e0fb1 | 2013-09-28 18:57:57 -0700 | [diff] [blame] | 441 | table_id = JType("TableId") \ |
| 442 | .op(read='TableId.readByte(bb)', |
| 443 | write='$name.writeByte(bb)', |
| 444 | default='TableId.ALL') |
Andreas Wundsam | 45c95f8 | 2013-10-08 15:04:23 -0700 | [diff] [blame] | 445 | table_id_default_zero = JType("TableId") \ |
| 446 | .op(read='TableId.readByte(bb)', |
| 447 | write='$name.writeByte(bb)', |
| 448 | default='TableId.ZERO') |
Sovietaced | 0f9dddf | 2014-01-28 19:45:07 -0800 | [diff] [blame] | 449 | of_aux_id = JType("OFAuxId") \ |
| 450 | .op(read='OFAuxId.readByte(bb)', |
Sovietaced | 92603b0 | 2014-01-28 18:23:24 -0800 | [diff] [blame] | 451 | write='$name.writeByte(bb)', |
Sovietaced | 0f9dddf | 2014-01-28 19:45:07 -0800 | [diff] [blame] | 452 | default='OFAuxId.MAIN') |
Andreas Wundsam | a098102 | 2013-10-02 18:15:06 -0700 | [diff] [blame] | 453 | of_version = JType("OFVersion", 'byte') \ |
| 454 | .op(read='bb.readByte()', write='bb.writeByte($name)') |
Rob Vaterlaus | b10ae55 | 2013-09-23 14:39:39 -0700 | [diff] [blame] | 455 | |
Andreas Wundsam | 8ec3bcc | 2013-09-16 19:44:00 -0700 | [diff] [blame] | 456 | port_speed = JType("PortSpeed") |
Rob Vaterlaus | 4d31194 | 2013-09-24 13:41:44 -0700 | [diff] [blame] | 457 | error_type = JType("OFErrorType") |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 458 | of_type = JType("OFType", 'byte') \ |
| 459 | .op(read='bb.readByte()', write='bb.writeByte($name)') |
| 460 | action_type= gen_enum_jtype("OFActionType")\ |
| 461 | .set_priv_type("short")\ |
| 462 | .op(read='bb.readShort()', write='bb.writeShort($name)', pub_type=False) |
| 463 | instruction_type = gen_enum_jtype("OFInstructionType")\ |
| 464 | .set_priv_type('short') \ |
| 465 | .op(read='bb.readShort()', write='bb.writeShort($name)', pub_type=False) |
| 466 | buffer_id = JType("OFBufferId") \ |
| 467 | .op(read="OFBufferId.of(bb.readInt())", write="bb.writeInt($name.getInt())", default="OFBufferId.NO_BUFFER") |
Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame] | 468 | boolean = JType("boolean", "byte") \ |
| 469 | .op(read='(bb.readByte() != 0)', |
| 470 | write='bb.writeByte($name ? 1 : 0)', |
| 471 | default="false") |
| 472 | datapath_id = JType("DatapathId") \ |
| 473 | .op(read='DatapathId.of(bb.readLong())', |
| 474 | write='bb.writeLong($name.getLong())', |
| 475 | default='DatapathId.NONE') |
Andreas Wundsam | 5ea1aca | 2013-10-07 17:00:24 -0700 | [diff] [blame] | 476 | action_type_set = JType("Set<OFActionType>") \ |
| 477 | .op(read='ChannelUtilsVer10.readSupportedActions(bb)', |
| 478 | write='ChannelUtilsVer10.writeSupportedActions(bb, $name)', |
| 479 | default='ImmutableSet.<OFActionType>of()', |
| 480 | funnel='ChannelUtilsVer10.putSupportedActionsTo($name, sink)') |
Andreas Wundsam | acd57d5 | 2013-10-18 17:35:01 -0700 | [diff] [blame] | 481 | of_group = JType("OFGroup") \ |
| 482 | .op(version=ANY, read="OFGroup.read4Bytes(bb)", write="$name.write4Bytes(bb)", default="OFGroup.ALL") |
Andreas Wundsam | ee8b42c | 2014-01-24 17:38:19 -0800 | [diff] [blame] | 483 | of_group_default_any = JType("OFGroup") \ |
| 484 | .op(version=ANY, read="OFGroup.read4Bytes(bb)", write="$name.write4Bytes(bb)", default="OFGroup.ANY") |
Andreas Wundsam | acd57d5 | 2013-10-18 17:35:01 -0700 | [diff] [blame] | 485 | # the outgroup field of of_flow_stats_request has a special default value |
| 486 | of_group_default_any = JType("OFGroup") \ |
| 487 | .op(version=ANY, read="OFGroup.read4Bytes(bb)", write="$name.write4Bytes(bb)", default="OFGroup.ANY") |
| 488 | buffer_id = JType("OFBufferId") \ |
| 489 | .op(read="OFBufferId.of(bb.readInt())", write="bb.writeInt($name.getInt())", default="OFBufferId.NO_BUFFER") |
Rich Lane | 376cafe | 2013-10-27 21:49:14 -0700 | [diff] [blame] | 490 | lag_id = JType("LagId") \ |
| 491 | .op(version=ANY, read="LagId.read4Bytes(bb)", write="$name.write4Bytes(bb)", default="LagId.NONE") |
Rich Lane | eb21c4f | 2013-10-28 17:34:41 -0700 | [diff] [blame] | 492 | vrf = JType("VRF") \ |
| 493 | .op(version=ANY, read="VRF.read4Bytes(bb)", write="$name.write4Bytes(bb)", default="VRF.ZERO") |
| 494 | class_id = JType("ClassId") \ |
| 495 | .op(version=ANY, read="ClassId.read4Bytes(bb)", write="$name.write4Bytes(bb)", default="ClassId.NONE") |
Rich Lane | 9c27b5d | 2013-10-30 17:14:32 -0700 | [diff] [blame] | 496 | boolean_value = JType('OFBooleanValue', 'OFBooleanValue') \ |
| 497 | .op(read='OFBooleanValue.of(bb.readByte() != 0)', write='bb.writeByte($name.getInt())', default="OFBooleanValue.FALSE") |
Andreas Wundsam | d4b2269 | 2014-01-14 14:17:26 -0800 | [diff] [blame] | 498 | gen_table_id = JType("GenTableId") \ |
| 499 | .op(read='GenTableId.read2Bytes(bb)', |
| 500 | write='$name.write2Bytes(bb)', |
| 501 | ) |
Rich Lane | 53ddf5c | 2014-03-20 15:24:08 -0700 | [diff] [blame] | 502 | udf = JType("UDF") \ |
| 503 | .op(version=ANY, read="UDF.read4Bytes(bb)", write="$name.write4Bytes(bb)", default="UDF.ZERO") |
Andreas Wundsam | 62cbcff | 2014-05-09 16:35:00 -0700 | [diff] [blame] | 504 | error_cause_data = JType("OFErrorCauseData") \ |
Andreas Wundsam | 39efd1c | 2014-05-13 19:41:51 -0700 | [diff] [blame] | 505 | .op(version=ANY, read="OFErrorCauseData.read(bb, $length, OFVersion.OF_$version)", write="$name.writeTo(bb)", default="OFErrorCauseData.NONE"); |
Andreas Wundsam | 2be7da5 | 2013-08-22 07:34:25 -0700 | [diff] [blame] | 506 | |
| 507 | generic_t = JType("T") |
| 508 | |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 509 | |
| 510 | default_mtype_to_jtype_convert_map = { |
| 511 | 'uint8_t' : u8, |
| 512 | 'uint16_t' : u16, |
| 513 | 'uint32_t' : u32, |
| 514 | 'uint64_t' : u64, |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 515 | 'of_port_no_t' : of_port, |
| 516 | 'list(of_action_t)' : actions_list, |
| 517 | 'list(of_instruction_t)' : instructions_list, |
| 518 | 'list(of_bucket_t)': buckets_list, |
| 519 | 'list(of_port_desc_t)' : port_desc_list, |
| 520 | 'list(of_packet_queue_t)' : packet_queue_list, |
xinwu | f08ef68 | 2013-12-05 18:29:20 -0800 | [diff] [blame] | 521 | 'list(of_uint64_t)' : u64_list, |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 522 | 'list(of_uint32_t)' : u32_list, |
| 523 | 'list(of_uint8_t)' : u8_list, |
Andreas Wundsam | 2be7da5 | 2013-08-22 07:34:25 -0700 | [diff] [blame] | 524 | 'list(of_oxm_t)' : oxm_list, |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 525 | 'of_octets_t' : octets, |
| 526 | 'of_match_t': of_match, |
| 527 | 'of_fm_cmd_t': flow_mod_cmd, |
| 528 | 'of_mac_addr_t': mac_addr, |
| 529 | 'of_port_desc_t': port_desc, |
| 530 | 'of_desc_str_t': desc_str, |
| 531 | 'of_serial_num_t': serial_num, |
| 532 | 'of_port_name_t': port_name, |
| 533 | 'of_table_name_t': table_name, |
Rich Lane | f8a3d00 | 2014-03-19 13:33:52 -0700 | [diff] [blame] | 534 | 'of_str64_t': str64, |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 535 | 'of_ipv4_t': ipv4, |
| 536 | 'of_ipv6_t': ipv6, |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 537 | 'of_wc_bmap_t': flow_wildcards, |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 538 | 'of_oxm_t': oxm, |
| 539 | 'of_meter_features_t': meter_features, |
Rich Lane | 2d1c5c7 | 2013-12-03 13:02:10 -0800 | [diff] [blame] | 540 | 'of_bitmap_128_t': port_bitmap, |
Andreas Wundsam | 7c15b17 | 2014-04-24 19:02:40 -0700 | [diff] [blame] | 541 | 'of_checksum_128_t': u128, |
Wilson Ng | d618188 | 2014-04-14 16:28:35 -0700 | [diff] [blame] | 542 | 'of_bsn_vport_t': bsn_vport, |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 545 | ## Map that defines exceptions from the standard loxi->java mapping scheme |
| 546 | # map of {<loxi_class_name> : { <loxi_member_name> : <JType instance> } } |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 547 | exceptions = { |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 548 | 'of_packet_in': { 'data' : octets, 'reason': packetin_reason }, |
| 549 | 'of_oxm_tcp_src' : { 'value' : transport_port }, |
| 550 | 'of_oxm_tcp_src_masked' : { 'value' : transport_port, 'value_mask' : transport_port }, |
| 551 | 'of_oxm_tcp_dst' : { 'value' : transport_port }, |
| 552 | 'of_oxm_tcp_dst_masked' : { 'value' : transport_port, 'value_mask' : transport_port }, |
| 553 | 'of_oxm_udp_src' : { 'value' : transport_port }, |
| 554 | 'of_oxm_udp_src_masked' : { 'value' : transport_port, 'value_mask' : transport_port }, |
| 555 | 'of_oxm_udp_dst' : { 'value' : transport_port }, |
| 556 | 'of_oxm_udp_dst_masked' : { 'value' : transport_port, 'value_mask' : transport_port }, |
| 557 | 'of_oxm_sctp_src' : { 'value' : transport_port }, |
| 558 | 'of_oxm_sctp_src_masked' : { 'value' : transport_port, 'value_mask' : transport_port }, |
| 559 | 'of_oxm_sctp_dst' : { 'value' : transport_port }, |
| 560 | 'of_oxm_sctp_dst_masked' : { 'value' : transport_port, 'value_mask' : transport_port }, |
| 561 | 'of_oxm_eth_type' : { 'value' : eth_type }, |
| 562 | 'of_oxm_eth_type_masked' : { 'value' : eth_type, 'value_mask' : eth_type }, |
Andreas Wundsam | 98a1863 | 2013-11-05 11:34:24 -0800 | [diff] [blame] | 563 | 'of_oxm_vlan_vid' : { 'value' : vlan_vid_match }, |
| 564 | 'of_oxm_vlan_vid_masked' : { 'value' : vlan_vid_match, 'value_mask' : vlan_vid_match }, |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 565 | 'of_oxm_vlan_pcp' : { 'value' : vlan_pcp }, |
| 566 | 'of_oxm_vlan_pcp_masked' : { 'value' : vlan_pcp, 'value_mask' : vlan_pcp }, |
| 567 | 'of_oxm_ip_dscp' : { 'value' : ip_dscp }, |
| 568 | 'of_oxm_ip_dscp_masked' : { 'value' : ip_dscp, 'value_mask' : ip_dscp }, |
| 569 | 'of_oxm_ip_ecn' : { 'value' : ip_ecn }, |
| 570 | 'of_oxm_ip_ecn_masked' : { 'value' : ip_ecn, 'value_mask' : ip_ecn }, |
| 571 | 'of_oxm_ip_proto' : { 'value' : ip_proto }, |
| 572 | 'of_oxm_ip_proto_masked' : { 'value' : ip_proto, 'value_mask' : ip_proto }, |
| 573 | 'of_oxm_icmpv4_type' : { 'value' : icmpv4_type }, |
| 574 | 'of_oxm_icmpv4_type_masked' : { 'value' : icmpv4_type, 'value_mask' : icmpv4_type }, |
| 575 | 'of_oxm_icmpv4_code' : { 'value' : icmpv4_code }, |
| 576 | 'of_oxm_icmpv4_code_masked' : { 'value' : icmpv4_code, 'value_mask' : icmpv4_code }, |
| 577 | 'of_oxm_arp_op' : { 'value' : arp_op }, |
| 578 | 'of_oxm_arp_op_masked' : { 'value' : arp_op, 'value_mask' : arp_op }, |
| 579 | 'of_oxm_arp_spa' : { 'value' : ipv4 }, |
| 580 | 'of_oxm_arp_spa_masked' : { 'value' : ipv4, 'value_mask' : ipv4 }, |
| 581 | 'of_oxm_arp_tpa' : { 'value' : ipv4 }, |
| 582 | 'of_oxm_arp_tpa_masked' : { 'value' : ipv4, 'value_mask' : ipv4 }, |
| 583 | 'of_oxm_ipv6_flabel' : { 'value' : ipv6_flabel }, |
| 584 | 'of_oxm_ipv6_flabel_masked' : { 'value' : ipv6_flabel, 'value_mask' : ipv6_flabel }, |
| 585 | 'of_oxm_metadata' : { 'value' : metadata }, |
| 586 | 'of_oxm_metadata_masked' : { 'value' : metadata, 'value_mask' : metadata }, |
Yotam Harchol | 5804f77 | 2013-08-21 17:35:31 -0700 | [diff] [blame] | 587 | |
| 588 | 'of_oxm_icmpv6_code' : { 'value' : u8obj }, |
| 589 | 'of_oxm_icmpv6_code_masked' : { 'value' : u8obj, 'value_mask' : u8obj }, |
| 590 | 'of_oxm_icmpv6_type' : { 'value' : u8obj }, |
| 591 | 'of_oxm_icmpv6_type_masked' : { 'value' : u8obj, 'value_mask' : u8obj }, |
| 592 | 'of_oxm_mpls_label' : { 'value' : u32obj }, |
| 593 | 'of_oxm_mpls_label_masked' : { 'value' : u32obj, 'value_mask' : u32obj }, |
| 594 | 'of_oxm_mpls_tc' : { 'value' : u8obj }, |
| 595 | 'of_oxm_mpls_tc_masked' : { 'value' : u8obj, 'value_mask' : u8obj }, |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 596 | |
Yotam Harchol | 595c644 | 2013-09-27 16:29:08 -0700 | [diff] [blame] | 597 | 'of_oxm_bsn_in_ports_128' : { 'value': port_bitmap }, |
| 598 | 'of_oxm_bsn_in_ports_128_masked' : { 'value': port_bitmap, 'value_mask': port_bitmap }, |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 599 | |
Rich Lane | 376cafe | 2013-10-27 21:49:14 -0700 | [diff] [blame] | 600 | 'of_oxm_bsn_lag_id' : { 'value' : lag_id }, |
| 601 | 'of_oxm_bsn_lag_id_masked' : { 'value' : lag_id, 'value_mask' : lag_id }, |
Rich Lane | 1424d0b | 2013-10-24 17:16:24 -0700 | [diff] [blame] | 602 | |
Rich Lane | eb21c4f | 2013-10-28 17:34:41 -0700 | [diff] [blame] | 603 | 'of_oxm_bsn_vrf' : { 'value' : vrf }, |
| 604 | 'of_oxm_bsn_vrf_masked' : { 'value' : vrf, 'value_mask' : vrf }, |
| 605 | |
Rich Lane | 9c27b5d | 2013-10-30 17:14:32 -0700 | [diff] [blame] | 606 | 'of_oxm_bsn_global_vrf_allowed' : { 'value' : boolean_value }, |
| 607 | 'of_oxm_bsn_global_vrf_allowed_masked' : { 'value' : boolean_value, 'value_mask' : boolean_value }, |
Rich Lane | eb21c4f | 2013-10-28 17:34:41 -0700 | [diff] [blame] | 608 | |
| 609 | 'of_oxm_bsn_l3_interface_class_id' : { 'value' : class_id }, |
| 610 | 'of_oxm_bsn_l3_interface_class_id_masked' : { 'value' : class_id, 'value_mask' : class_id }, |
| 611 | |
| 612 | 'of_oxm_bsn_l3_src_class_id' : { 'value' : class_id }, |
| 613 | 'of_oxm_bsn_l3_src_class_id_masked' : { 'value' : class_id, 'value_mask' : class_id }, |
| 614 | |
| 615 | 'of_oxm_bsn_l3_dst_class_id' : { 'value' : class_id }, |
| 616 | 'of_oxm_bsn_l3_dst_class_id_masked' : { 'value' : class_id, 'value_mask' : class_id }, |
| 617 | |
Rich Lane | 917bb9a | 2014-03-11 17:49:56 -0700 | [diff] [blame] | 618 | 'of_oxm_bsn_egr_port_group_id' : { 'value' : class_id }, |
| 619 | 'of_oxm_bsn_egr_port_group_id_masked' : { 'value' : class_id, 'value_mask' : class_id }, |
| 620 | |
Rich Lane | 53ddf5c | 2014-03-20 15:24:08 -0700 | [diff] [blame] | 621 | 'of_oxm_bsn_udf0' : { 'value' : udf }, |
| 622 | 'of_oxm_bsn_udf0_masked' : { 'value' : udf, 'value_mask' : udf }, |
| 623 | |
| 624 | 'of_oxm_bsn_udf1' : { 'value' : udf }, |
| 625 | 'of_oxm_bsn_udf1_masked' : { 'value' : udf, 'value_mask' : udf }, |
| 626 | |
| 627 | 'of_oxm_bsn_udf2' : { 'value' : udf }, |
| 628 | 'of_oxm_bsn_udf2_masked' : { 'value' : udf, 'value_mask' : udf }, |
| 629 | |
| 630 | 'of_oxm_bsn_udf3' : { 'value' : udf }, |
| 631 | 'of_oxm_bsn_udf3_masked' : { 'value' : udf, 'value_mask' : udf }, |
| 632 | |
| 633 | 'of_oxm_bsn_udf4' : { 'value' : udf }, |
| 634 | 'of_oxm_bsn_udf4_masked' : { 'value' : udf, 'value_mask' : udf }, |
| 635 | |
| 636 | 'of_oxm_bsn_udf5' : { 'value' : udf }, |
| 637 | 'of_oxm_bsn_udf5_masked' : { 'value' : udf, 'value_mask' : udf }, |
| 638 | |
| 639 | 'of_oxm_bsn_udf6' : { 'value' : udf }, |
| 640 | 'of_oxm_bsn_udf6_masked' : { 'value' : udf, 'value_mask' : udf }, |
| 641 | |
| 642 | 'of_oxm_bsn_udf7' : { 'value' : udf }, |
| 643 | 'of_oxm_bsn_udf7_masked' : { 'value' : udf, 'value_mask' : udf }, |
| 644 | |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 645 | 'of_table_stats_entry': { 'wildcards': table_stats_wildcards }, |
Andreas Wundsam | 98a1863 | 2013-11-05 11:34:24 -0800 | [diff] [blame] | 646 | 'of_match_v1': { 'vlan_vid' : vlan_vid_match, 'vlan_pcp': vlan_pcp, |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 647 | 'eth_type': eth_type, 'ip_dscp': ip_dscp, 'ip_proto': ip_proto, |
Andreas Wundsam | e962d37 | 2013-10-02 18:15:58 -0700 | [diff] [blame] | 648 | 'tcp_src': transport_port, 'tcp_dst': transport_port, |
| 649 | 'in_port': of_port_match_v1 |
Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame] | 650 | }, |
| 651 | 'of_bsn_set_l2_table_request': { 'l2_table_enable': boolean }, |
| 652 | 'of_bsn_set_l2_table_reply': { 'l2_table_enable': boolean }, |
Rob Vaterlaus | e1b8684 | 2013-10-18 13:29:19 -0700 | [diff] [blame] | 653 | 'of_bsn_set_pktin_suppression_request': { 'enabled': boolean }, |
Sovietaced | 768c3e2 | 2014-04-04 16:46:48 -0700 | [diff] [blame] | 654 | 'of_bsn_controller_connection': { 'auxiliary_id' : of_aux_id}, |
Andreas Wundsam | acd57d5 | 2013-10-18 17:35:01 -0700 | [diff] [blame] | 655 | 'of_flow_stats_request': { 'out_group': of_group_default_any }, |
Andreas Wundsam | 384ccc1 | 2014-03-12 14:52:42 -0700 | [diff] [blame] | 656 | 'of_aggregate_stats_request': { 'out_group': of_group_default_any }, |
Andreas Wundsam | 98a1863 | 2013-11-05 11:34:24 -0800 | [diff] [blame] | 657 | |
| 658 | 'of_action_bsn_mirror': { 'dest_port': of_port }, |
| 659 | 'of_action_push_mpls': { 'ethertype': eth_type }, |
| 660 | 'of_action_push_pbb': { 'ethertype': eth_type }, |
| 661 | 'of_action_push_vlan': { 'ethertype': eth_type }, |
Ronald Li | 4fb8abb | 2013-11-21 19:53:02 -0800 | [diff] [blame] | 662 | 'of_action_pop_mpls': { 'ethertype': eth_type }, |
Andreas Wundsam | 98a1863 | 2013-11-05 11:34:24 -0800 | [diff] [blame] | 663 | 'of_action_set_nw_dst': { 'nw_addr': ipv4 }, |
| 664 | 'of_action_set_nw_ecn': { 'nw_ecn': ip_ecn }, |
| 665 | 'of_action_set_nw_src': { 'nw_addr': ipv4 }, |
Andreas Wundsam | 98a1863 | 2013-11-05 11:34:24 -0800 | [diff] [blame] | 666 | 'of_action_set_tp_dst': { 'tp_port': transport_port }, |
| 667 | 'of_action_set_tp_src': { 'tp_port': transport_port }, |
| 668 | 'of_action_set_vlan_pcp': { 'vlan_pcp': vlan_pcp }, |
| 669 | 'of_action_set_vlan_vid': { 'vlan_vid': vlan_vid }, |
Andreas Wundsam | 5812cf3 | 2013-11-15 13:51:24 -0800 | [diff] [blame] | 670 | |
| 671 | 'of_group_mod' : { 'command' : group_mod_cmd }, |
| 672 | 'of_group_add' : { 'command' : group_mod_cmd }, |
| 673 | 'of_group_modify' : { 'command' : group_mod_cmd }, |
| 674 | 'of_group_delete' : { 'command' : group_mod_cmd }, |
| 675 | |
| 676 | 'of_bucket' : { 'watch_group': of_group }, |
Andreas Wundsam | d4b2269 | 2014-01-14 14:17:26 -0800 | [diff] [blame] | 677 | |
| 678 | 'of_bsn_tlv_vlan_vid' : { 'value' : vlan_vid }, |
| 679 | 'of_bsn_gentable_entry_add' : { 'table_id' : gen_table_id }, |
Sovietaced | 92603b0 | 2014-01-28 18:23:24 -0800 | [diff] [blame] | 680 | |
Sovietaced | 0f9dddf | 2014-01-28 19:45:07 -0800 | [diff] [blame] | 681 | 'of_features_reply' : { 'auxiliary_id' : of_aux_id}, |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Andreas Wundsam | 7cfeac3 | 2013-09-17 13:53:48 -0700 | [diff] [blame] | 684 | |
| 685 | @memoize |
| 686 | def enum_java_types(): |
| 687 | enum_types = {} |
Andreas Wundsam | c8912c1 | 2013-11-15 13:44:48 -0800 | [diff] [blame] | 688 | for enum in loxi_globals.unified.enums: |
| 689 | java_name = name_c_to_caps_camel(re.sub(r'_t$', "", enum.name)) |
| 690 | enum_types[enum.name] = gen_enum_jtype(java_name, enum.is_bitmask) |
Andreas Wundsam | 7cfeac3 | 2013-09-17 13:53:48 -0700 | [diff] [blame] | 691 | return enum_types |
| 692 | |
Andreas Wundsam | 2be7da5 | 2013-08-22 07:34:25 -0700 | [diff] [blame] | 693 | def make_match_field_jtype(sub_type_name="?"): |
| 694 | return JType("MatchField<{}>".format(sub_type_name)) |
| 695 | |
Andreas Wundsam | 661a222 | 2013-11-05 17:18:59 -0800 | [diff] [blame] | 696 | def make_oxm_jtype(sub_type_name="?"): |
| 697 | return JType("OFOxm<{}>".format(sub_type_name)) |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 698 | |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 699 | def list_cname_to_java_name(c_type): |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 700 | m = re.match(r'list\(of_([a-zA-Z_]+)_t\)', c_type) |
| 701 | if not m: |
| 702 | raise Exception("Not a recgonized standard list type declaration: %s" % c_type) |
| 703 | base_name = m.group(1) |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 704 | return "OF" + name_c_to_caps_camel(base_name) |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 705 | |
| 706 | #### main entry point for conversion of LOXI types (c_types) Java types. |
| 707 | # FIXME: This badly needs a refactoring |
| 708 | |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 709 | def convert_to_jtype(obj_name, field_name, c_type): |
| 710 | """ Convert from a C type ("uint_32") to a java type ("U32") |
| 711 | and return a JType object with the size, internal type, and marshalling functions""" |
| 712 | if obj_name in exceptions and field_name in exceptions[obj_name]: |
| 713 | return exceptions[obj_name][field_name] |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 714 | elif ( obj_name == "of_header" or loxi_utils.class_is_message(obj_name)) and field_name == "type" and c_type == "uint8_t": |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 715 | return of_type |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 716 | elif field_name == "type" and re.match(r'of_action.*', obj_name): |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 717 | return action_type |
Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame] | 718 | elif field_name == "err_type": |
| 719 | return JType("OFErrorType", 'short') \ |
| 720 | .op(read='bb.readShort()', write='bb.writeShort($name)') |
Andreas Wundsam | 62cbcff | 2014-05-09 16:35:00 -0700 | [diff] [blame] | 721 | elif loxi_utils.class_is(obj_name, "of_error_msg") and field_name == "data": |
| 722 | return error_cause_data |
Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame] | 723 | elif field_name == "stats_type": |
| 724 | return JType("OFStatsType", 'short') \ |
| 725 | .op(read='bb.readShort()', write='bb.writeShort($name)') |
Andreas Wundsam | 999c073 | 2013-10-01 19:29:16 -0700 | [diff] [blame] | 726 | elif field_name == "type" and re.match(r'of_instruction.*', obj_name): |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 727 | return instruction_type |
Andreas Wundsam | ee8b42c | 2014-01-24 17:38:19 -0800 | [diff] [blame] | 728 | elif loxi_utils.class_is(obj_name, "of_flow_mod") and field_name == "table_id" and c_type == "uint8_t": |
Andreas Wundsam | 45c95f8 | 2013-10-08 15:04:23 -0700 | [diff] [blame] | 729 | return table_id_default_zero |
Andreas Wundsam | ee8b42c | 2014-01-24 17:38:19 -0800 | [diff] [blame] | 730 | elif loxi_utils.class_is(obj_name, "of_flow_mod") and field_name == "out_group" and c_type == "uint32_t": |
| 731 | return of_group_default_any |
Andreas Wundsam | 37e0fb1 | 2013-09-28 18:57:57 -0700 | [diff] [blame] | 732 | elif field_name == "table_id" and c_type == "uint8_t": |
| 733 | return table_id |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 734 | elif field_name == "version" and c_type == "uint8_t": |
Andreas Wundsam | a098102 | 2013-10-02 18:15:06 -0700 | [diff] [blame] | 735 | return of_version |
Rob Vaterlaus | b10ae55 | 2013-09-23 14:39:39 -0700 | [diff] [blame] | 736 | elif field_name == "buffer_id" and c_type == "uint32_t": |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 737 | return buffer_id |
Andreas Wundsam | acd57d5 | 2013-10-18 17:35:01 -0700 | [diff] [blame] | 738 | elif field_name == "group_id" and c_type == "uint32_t": |
| 739 | return of_group |
Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame] | 740 | elif field_name == 'datapath_id': |
| 741 | return datapath_id |
| 742 | elif field_name == 'actions' and obj_name == 'of_features_reply': |
Andreas Wundsam | 5ea1aca | 2013-10-07 17:00:24 -0700 | [diff] [blame] | 743 | return action_type_set |
Andreas Wundsam | d4b2269 | 2014-01-14 14:17:26 -0800 | [diff] [blame] | 744 | elif field_name == "table_id" and re.match(r'of_bsn_gentable.*', obj_name): |
| 745 | return gen_table_id |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 746 | elif c_type in default_mtype_to_jtype_convert_map: |
| 747 | return default_mtype_to_jtype_convert_map[c_type] |
| 748 | elif re.match(r'list\(of_([a-zA-Z_]+)_t\)', c_type): |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 749 | return gen_list_jtype(list_cname_to_java_name(c_type)) |
Andreas Wundsam | 7cfeac3 | 2013-09-17 13:53:48 -0700 | [diff] [blame] | 750 | elif c_type in enum_java_types(): |
| 751 | return enum_java_types()[c_type] |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 752 | else: |
| 753 | print "WARN: Couldn't find java type conversion for '%s' in %s:%s" % (c_type, obj_name, field_name) |
| 754 | jtype = name_c_to_caps_camel(re.sub(r'_t$', "", c_type)) |
| 755 | return JType(jtype) |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 756 | |
| 757 | |
| 758 | #### Enum specific wiretype definitions |
| 759 | enum_wire_types = { |
| 760 | "uint8_t": JType("byte").op(read="bb.readByte()", write="bb.writeByte($name)"), |
| 761 | "uint16_t": JType("short").op(read="bb.readShort()", write="bb.writeShort($name)"), |
| 762 | "uint32_t": JType("int").op(read="bb.readInt()", write="bb.writeInt($name)"), |
| 763 | "uint64_t": JType("long").op(read="bb.readLong()", write="bb.writeLong($name)"), |
| 764 | } |
| 765 | |
| 766 | def convert_enum_wire_type_to_jtype(wire_type): |
| 767 | return enum_wire_types[wire_type] |