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