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) |
Praseed Balakrishnan | 7f71878 | 2014-09-18 17:02:48 -0700 | [diff] [blame] | 358 | app_code = gen_fixed_length_string_jtype(15) |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 359 | desc_str = gen_fixed_length_string_jtype(256) |
| 360 | serial_num = gen_fixed_length_string_jtype(32) |
| 361 | table_name = gen_fixed_length_string_jtype(32) |
Rich Lane | f8a3d00 | 2014-03-19 13:33:52 -0700 | [diff] [blame] | 362 | str64 = gen_fixed_length_string_jtype(64) |
Brian O'Connor | 58a73e3 | 2015-05-28 11:51:27 -0700 | [diff] [blame] | 363 | str32 = gen_fixed_length_string_jtype(32) |
| 364 | str6 = gen_fixed_length_string_jtype(6) |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 365 | ipv4 = JType("IPv4Address") \ |
| 366 | .op(read="IPv4Address.read4Bytes(bb)", \ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 367 | write="$name.write4Bytes(bb)", |
| 368 | default='IPv4Address.NONE') |
Byungjoon Lee | ba92e29 | 2014-07-18 13:13:26 +0900 | [diff] [blame] | 369 | ipv4_list = JType('List<IPv4Address>') \ |
| 370 | .op(read='ChannelUtils.readList(bb, $length, IPv4Address.READER)', |
| 371 | write='ChannelUtils.writeList(bb, $name)', |
| 372 | default='ImmutableList.<IPv4Address>of()', |
| 373 | funnel="FunnelUtils.putList($name, sink)") |
Yotam Harchol | a289d55 | 2013-09-16 10:10:40 -0700 | [diff] [blame] | 374 | ipv6 = JType("IPv6Address") \ |
| 375 | .op(read="IPv6Address.read16Bytes(bb)", \ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 376 | write="$name.write16Bytes(bb)", |
| 377 | default='IPv6Address.NONE') |
Byungjoon Lee | ba92e29 | 2014-07-18 13:13:26 +0900 | [diff] [blame] | 378 | ipv6_list = JType('List<IPv46ddress>') \ |
| 379 | .op(read='ChannelUtils.readList(bb, $length, IPv6Address.READER)', |
| 380 | write='ChannelUtils.writeList(bb, $name)', |
| 381 | default='ImmutableList.<IPv6Address>of()', |
| 382 | funnel="FunnelUtils.putList($name, sink)") |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 383 | packetin_reason = gen_enum_jtype("OFPacketInReason") |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 384 | transport_port = JType("TransportPort")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 385 | .op(read="TransportPort.read2Bytes(bb)", |
| 386 | write="$name.write2Bytes(bb)", |
| 387 | default="TransportPort.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 388 | eth_type = JType("EthType")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 389 | .op(read="EthType.read2Bytes(bb)", |
| 390 | write="$name.write2Bytes(bb)", |
| 391 | default="EthType.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 392 | vlan_vid = JType("VlanVid")\ |
Andreas Wundsam | 98a1863 | 2013-11-05 11:34:24 -0800 | [diff] [blame] | 393 | .op(version=ANY, read="VlanVid.read2Bytes(bb)", write="$name.write2Bytes(bb)", default="VlanVid.ZERO") |
| 394 | vlan_vid_match = JType("OFVlanVidMatch")\ |
| 395 | .op(version=1, read="OFVlanVidMatch.read2BytesOF10(bb)", write="$name.write2BytesOF10(bb)", default="OFVlanVidMatch.NONE") \ |
| 396 | .op(version=2, read="OFVlanVidMatch.read2BytesOF10(bb)", write="$name.write2BytesOF10(bb)", default="OFVlanVidMatch.NONE") \ |
| 397 | .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] | 398 | vlan_pcp = JType("VlanPcp")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 399 | .op(read="VlanPcp.readByte(bb)", |
| 400 | write="$name.writeByte(bb)", |
| 401 | default="VlanPcp.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 402 | ip_dscp = JType("IpDscp")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 403 | .op(read="IpDscp.readByte(bb)", |
| 404 | write="$name.writeByte(bb)", |
| 405 | default="IpDscp.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 406 | ip_ecn = JType("IpEcn")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 407 | .op(read="IpEcn.readByte(bb)", |
| 408 | write="$name.writeByte(bb)", |
| 409 | default="IpEcn.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 410 | ip_proto = JType("IpProtocol")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 411 | .op(read="IpProtocol.readByte(bb)", |
| 412 | write="$name.writeByte(bb)", |
| 413 | default="IpProtocol.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 414 | icmpv4_type = JType("ICMPv4Type")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 415 | .op(read="ICMPv4Type.readByte(bb)", |
| 416 | write="$name.writeByte(bb)", |
| 417 | default="ICMPv4Type.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 418 | icmpv4_code = JType("ICMPv4Code")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 419 | .op(read="ICMPv4Code.readByte(bb)", |
| 420 | write="$name.writeByte(bb)", |
| 421 | default="ICMPv4Code.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 422 | arp_op = JType("ArpOpcode")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 423 | .op(read="ArpOpcode.read2Bytes(bb)", |
| 424 | write="$name.write2Bytes(bb)", |
| 425 | default="ArpOpcode.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 426 | ipv6_flabel = JType("IPv6FlowLabel")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 427 | .op(read="IPv6FlowLabel.read4Bytes(bb)", |
| 428 | write="$name.write4Bytes(bb)", |
| 429 | default="IPv6FlowLabel.NONE") |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 430 | metadata = JType("OFMetadata")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 431 | .op(read="OFMetadata.read8Bytes(bb)", |
| 432 | write="$name.write8Bytes(bb)", |
| 433 | default="OFMetadata.NONE") |
Andreas Wundsam | 2be7da5 | 2013-08-22 07:34:25 -0700 | [diff] [blame] | 434 | oxm = JType("OFOxm<?>")\ |
| 435 | .op( read="OFOxmVer$version.READER.readFrom(bb)", |
| 436 | write="$name.writeTo(bb)") |
| 437 | oxm_list = JType("OFOxmList") \ |
| 438 | .op( |
| 439 | read= 'OFOxmList.readFrom(bb, $length, OFOxmVer$version.READER)', \ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 440 | write='$name.writeTo(bb)', |
| 441 | default="OFOxmList.EMPTY") |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 442 | meter_features = JType("OFMeterFeatures")\ |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 443 | .op(read="OFMeterFeaturesVer$version.READER.readFrom(bb)", |
| 444 | write="$name.writeTo(bb)") |
Wilson Ng | d618188 | 2014-04-14 16:28:35 -0700 | [diff] [blame] | 445 | bsn_vport = JType("OFBsnVport")\ |
| 446 | .op(read="OFBsnVportVer$version.READER.readFrom(bb)", |
Andreas Wundsam | 113d25b | 2014-01-22 20:17:37 -0800 | [diff] [blame] | 447 | write="$name.writeTo(bb)") |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 448 | flow_wildcards = JType("int") \ |
| 449 | .op(read='bb.readInt()', |
| 450 | write='bb.writeInt($name)', |
| 451 | default="OFFlowWildcardsSerializerVer$version.ALL_VAL") |
| 452 | table_stats_wildcards = JType("int") \ |
| 453 | .op(read='bb.readInt()', |
| 454 | write='bb.writeInt($name)') |
Sovietaced | 25021ec | 2014-12-31 15:44:21 -0500 | [diff] [blame] | 455 | port_bitmap_128 = JType('OFBitMask128') \ |
Yotam Harchol | 2c53558 | 2013-10-01 15:50:20 -0700 | [diff] [blame] | 456 | .op(read='OFBitMask128.read16Bytes(bb)', |
Yotam Harchol | a11f38b | 2013-09-26 15:38:17 -0700 | [diff] [blame] | 457 | write='$name.write16Bytes(bb)', |
Yotam Harchol | 2c53558 | 2013-10-01 15:50:20 -0700 | [diff] [blame] | 458 | default='OFBitMask128.NONE') |
Jimmy Jin | 646d122 | 2016-05-13 10:47:24 -0700 | [diff] [blame] | 459 | port_bitmap_256 = JType('OFBitMask256') \ |
| 460 | .op(read='OFBitMask256.read32Bytes(bb)', |
| 461 | write='$name.write32Bytes(bb)', |
| 462 | default='OFBitMask256.NONE') |
Sovietaced | 25021ec | 2014-12-31 15:44:21 -0500 | [diff] [blame] | 463 | port_bitmap_512 = JType('OFBitMask512') \ |
| 464 | .op(read='OFBitMask512.read64Bytes(bb)', |
| 465 | write='$name.write64Bytes(bb)', |
| 466 | default='OFBitMask512.NONE') |
Andreas Wundsam | 37e0fb1 | 2013-09-28 18:57:57 -0700 | [diff] [blame] | 467 | table_id = JType("TableId") \ |
| 468 | .op(read='TableId.readByte(bb)', |
| 469 | write='$name.writeByte(bb)', |
| 470 | default='TableId.ALL') |
Andreas Wundsam | 45c95f8 | 2013-10-08 15:04:23 -0700 | [diff] [blame] | 471 | table_id_default_zero = JType("TableId") \ |
| 472 | .op(read='TableId.readByte(bb)', |
| 473 | write='$name.writeByte(bb)', |
| 474 | default='TableId.ZERO') |
Sovietaced | 0f9dddf | 2014-01-28 19:45:07 -0800 | [diff] [blame] | 475 | of_aux_id = JType("OFAuxId") \ |
| 476 | .op(read='OFAuxId.readByte(bb)', |
Sovietaced | 92603b0 | 2014-01-28 18:23:24 -0800 | [diff] [blame] | 477 | write='$name.writeByte(bb)', |
Sovietaced | 0f9dddf | 2014-01-28 19:45:07 -0800 | [diff] [blame] | 478 | default='OFAuxId.MAIN') |
Andreas Wundsam | a098102 | 2013-10-02 18:15:06 -0700 | [diff] [blame] | 479 | of_version = JType("OFVersion", 'byte') \ |
| 480 | .op(read='bb.readByte()', write='bb.writeByte($name)') |
Rob Vaterlaus | b10ae55 | 2013-09-23 14:39:39 -0700 | [diff] [blame] | 481 | |
Andreas Wundsam | 8ec3bcc | 2013-09-16 19:44:00 -0700 | [diff] [blame] | 482 | port_speed = JType("PortSpeed") |
Rob Vaterlaus | 4d31194 | 2013-09-24 13:41:44 -0700 | [diff] [blame] | 483 | error_type = JType("OFErrorType") |
Andreas Wundsam | 73d7d67 | 2014-11-12 17:07:33 -0800 | [diff] [blame] | 484 | of_message = JType("OFMessage")\ |
| 485 | .op(read="OFMessageVer$version.READER.readFrom(bb)", |
| 486 | write="$name.writeTo(bb)") |
| 487 | |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 488 | of_type = JType("OFType", 'byte') \ |
| 489 | .op(read='bb.readByte()', write='bb.writeByte($name)') |
| 490 | action_type= gen_enum_jtype("OFActionType")\ |
| 491 | .set_priv_type("short")\ |
| 492 | .op(read='bb.readShort()', write='bb.writeShort($name)', pub_type=False) |
| 493 | instruction_type = gen_enum_jtype("OFInstructionType")\ |
| 494 | .set_priv_type('short') \ |
| 495 | .op(read='bb.readShort()', write='bb.writeShort($name)', pub_type=False) |
| 496 | buffer_id = JType("OFBufferId") \ |
| 497 | .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] | 498 | boolean = JType("boolean", "byte") \ |
| 499 | .op(read='(bb.readByte() != 0)', |
| 500 | write='bb.writeByte($name ? 1 : 0)', |
| 501 | default="false") |
| 502 | datapath_id = JType("DatapathId") \ |
| 503 | .op(read='DatapathId.of(bb.readLong())', |
| 504 | write='bb.writeLong($name.getLong())', |
| 505 | default='DatapathId.NONE') |
Andreas Wundsam | 5ea1aca | 2013-10-07 17:00:24 -0700 | [diff] [blame] | 506 | action_type_set = JType("Set<OFActionType>") \ |
| 507 | .op(read='ChannelUtilsVer10.readSupportedActions(bb)', |
| 508 | write='ChannelUtilsVer10.writeSupportedActions(bb, $name)', |
| 509 | default='ImmutableSet.<OFActionType>of()', |
| 510 | funnel='ChannelUtilsVer10.putSupportedActionsTo($name, sink)') |
Andreas Wundsam | acd57d5 | 2013-10-18 17:35:01 -0700 | [diff] [blame] | 511 | of_group = JType("OFGroup") \ |
| 512 | .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] | 513 | of_group_default_any = JType("OFGroup") \ |
| 514 | .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] | 515 | # the outgroup field of of_flow_stats_request has a special default value |
| 516 | of_group_default_any = JType("OFGroup") \ |
| 517 | .op(version=ANY, read="OFGroup.read4Bytes(bb)", write="$name.write4Bytes(bb)", default="OFGroup.ANY") |
| 518 | buffer_id = JType("OFBufferId") \ |
| 519 | .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] | 520 | lag_id = JType("LagId") \ |
| 521 | .op(version=ANY, read="LagId.read4Bytes(bb)", write="$name.write4Bytes(bb)", default="LagId.NONE") |
Yafit Hadar | f8caac0 | 2015-08-25 10:21:44 +0300 | [diff] [blame] | 522 | odu_sig_id = JType("OduSignalID") \ |
| 523 | .op(read="OduSignalID.readFrom(bb)", \ |
| 524 | write="$name.writeTo(bb)", |
| 525 | default='OduSignalID.DEFAULT') |
Praseed Balakrishnan | 2ed6da0 | 2014-09-18 17:02:48 -0700 | [diff] [blame] | 526 | sig_id = JType("CircuitSignalID") \ |
| 527 | .op(version=ANY, read="CircuitSignalID.read6Bytes(bb)", write="$name.write6Bytes(bb)", default="CircuitSignalID.NONE") |
Rich Lane | eb21c4f | 2013-10-28 17:34:41 -0700 | [diff] [blame] | 528 | vrf = JType("VRF") \ |
| 529 | .op(version=ANY, read="VRF.read4Bytes(bb)", write="$name.write4Bytes(bb)", default="VRF.ZERO") |
| 530 | class_id = JType("ClassId") \ |
| 531 | .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] | 532 | boolean_value = JType('OFBooleanValue', 'OFBooleanValue') \ |
| 533 | .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] | 534 | gen_table_id = JType("GenTableId") \ |
| 535 | .op(read='GenTableId.read2Bytes(bb)', |
| 536 | write='$name.write2Bytes(bb)', |
| 537 | ) |
Andreas Wundsam | 73d7d67 | 2014-11-12 17:07:33 -0800 | [diff] [blame] | 538 | bundle_id = JType("BundleId") \ |
| 539 | .op(read='BundleId.read4Bytes(bb)', |
| 540 | write='$name.write4Bytes(bb)', |
| 541 | ) |
Rich Lane | 53ddf5c | 2014-03-20 15:24:08 -0700 | [diff] [blame] | 542 | udf = JType("UDF") \ |
| 543 | .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] | 544 | error_cause_data = JType("OFErrorCauseData") \ |
Andreas Wundsam | 39efd1c | 2014-05-13 19:41:51 -0700 | [diff] [blame] | 545 | .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] | 546 | |
Andreas Wundsam | e2fd7ce | 2014-06-26 20:56:42 -0700 | [diff] [blame] | 547 | var_string = JType('String').op( |
| 548 | read='ChannelUtils.readFixedLengthString(bb, $length)', |
| 549 | write='ChannelUtils.writeFixedLengthString(bb, $name, $name.length())', |
| 550 | default='""', |
| 551 | funnel='sink.putUnencodedChars($name)' |
| 552 | ) |
| 553 | |
Andreas Wundsam | 2be7da5 | 2013-08-22 07:34:25 -0700 | [diff] [blame] | 554 | generic_t = JType("T") |
| 555 | |
Marc De Leenheer | 88c0bcb | 2015-07-24 15:49:19 -0700 | [diff] [blame] | 556 | calient_port_desc_stats_entry = JType('OFCalientPortDescStatsEntry').op(read='OFCalientPortDescStatsEntryVer$version.READER.readFrom(bb)', write='$name.writeTo(bb)') |
| 557 | |
Rich Lane | 0b1698d | 2014-10-17 18:35:37 -0700 | [diff] [blame] | 558 | table_desc = JType('OFTableDesc') \ |
| 559 | .op(read='OFTableDescVer$version.READER.readFrom(bb)', \ |
| 560 | write='$name.writeTo(bb)') |
| 561 | |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 562 | |
| 563 | default_mtype_to_jtype_convert_map = { |
| 564 | 'uint8_t' : u8, |
| 565 | 'uint16_t' : u16, |
| 566 | 'uint32_t' : u32, |
| 567 | 'uint64_t' : u64, |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 568 | 'of_port_no_t' : of_port, |
| 569 | 'list(of_action_t)' : actions_list, |
| 570 | 'list(of_instruction_t)' : instructions_list, |
| 571 | 'list(of_bucket_t)': buckets_list, |
| 572 | 'list(of_port_desc_t)' : port_desc_list, |
| 573 | 'list(of_packet_queue_t)' : packet_queue_list, |
xinwu | f08ef68 | 2013-12-05 18:29:20 -0800 | [diff] [blame] | 574 | 'list(of_uint64_t)' : u64_list, |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 575 | 'list(of_uint32_t)' : u32_list, |
| 576 | 'list(of_uint8_t)' : u8_list, |
Andreas Wundsam | 2be7da5 | 2013-08-22 07:34:25 -0700 | [diff] [blame] | 577 | 'list(of_oxm_t)' : oxm_list, |
Byungjoon Lee | ba92e29 | 2014-07-18 13:13:26 +0900 | [diff] [blame] | 578 | 'list(of_ipv4_t)' : ipv4_list, |
| 579 | 'list(of_ipv6_t)' : ipv6_list, |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 580 | 'of_octets_t' : octets, |
| 581 | 'of_match_t': of_match, |
| 582 | 'of_fm_cmd_t': flow_mod_cmd, |
| 583 | 'of_mac_addr_t': mac_addr, |
| 584 | 'of_port_desc_t': port_desc, |
| 585 | 'of_desc_str_t': desc_str, |
| 586 | 'of_serial_num_t': serial_num, |
| 587 | 'of_port_name_t': port_name, |
| 588 | 'of_table_name_t': table_name, |
Rich Lane | f8a3d00 | 2014-03-19 13:33:52 -0700 | [diff] [blame] | 589 | 'of_str64_t': str64, |
Brian O'Connor | 58a73e3 | 2015-05-28 11:51:27 -0700 | [diff] [blame] | 590 | 'of_str32_t': str32, |
| 591 | 'of_str6_t': str6, |
Marc De Leenheer | 88c0bcb | 2015-07-24 15:49:19 -0700 | [diff] [blame] | 592 | 'of_calient_port_desc_stats_entry_t': calient_port_desc_stats_entry, |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 593 | 'of_ipv4_t': ipv4, |
| 594 | 'of_ipv6_t': ipv6, |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 595 | 'of_wc_bmap_t': flow_wildcards, |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 596 | 'of_oxm_t': oxm, |
| 597 | 'of_meter_features_t': meter_features, |
Sovietaced | 25021ec | 2014-12-31 15:44:21 -0500 | [diff] [blame] | 598 | 'of_bitmap_128_t': port_bitmap_128, |
Jimmy Jin | 646d122 | 2016-05-13 10:47:24 -0700 | [diff] [blame] | 599 | 'of_bitmap_256_t': port_bitmap_256, |
Sovietaced | 25021ec | 2014-12-31 15:44:21 -0500 | [diff] [blame] | 600 | 'of_bitmap_512_t': port_bitmap_512, |
Andreas Wundsam | 7c15b17 | 2014-04-24 19:02:40 -0700 | [diff] [blame] | 601 | 'of_checksum_128_t': u128, |
Wilson Ng | d618188 | 2014-04-14 16:28:35 -0700 | [diff] [blame] | 602 | 'of_bsn_vport_t': bsn_vport, |
Praseed Balakrishnan | 7f71878 | 2014-09-18 17:02:48 -0700 | [diff] [blame] | 603 | 'of_app_code_t': app_code, |
Praseed Balakrishnan | 2ed6da0 | 2014-09-18 17:02:48 -0700 | [diff] [blame] | 604 | 'of_sig_id_t': sig_id, |
Rich Lane | 0b1698d | 2014-10-17 18:35:37 -0700 | [diff] [blame] | 605 | 'of_table_desc_t': table_desc, |
Yafit Hadar | f8caac0 | 2015-08-25 10:21:44 +0300 | [diff] [blame] | 606 | 'of_odu_sig_id_t': odu_sig_id, |
| 607 | 'of_och_sig_id_t' : sig_id, |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 610 | ## Map that defines exceptions from the standard loxi->java mapping scheme |
| 611 | # map of {<loxi_class_name> : { <loxi_member_name> : <JType instance> } } |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 612 | exceptions = { |
Yotam Harchol | c742e20 | 2013-08-15 12:16:24 -0700 | [diff] [blame] | 613 | 'of_packet_in': { 'data' : octets, 'reason': packetin_reason }, |
| 614 | 'of_oxm_tcp_src' : { 'value' : transport_port }, |
| 615 | 'of_oxm_tcp_src_masked' : { 'value' : transport_port, 'value_mask' : transport_port }, |
| 616 | 'of_oxm_tcp_dst' : { 'value' : transport_port }, |
| 617 | 'of_oxm_tcp_dst_masked' : { 'value' : transport_port, 'value_mask' : transport_port }, |
| 618 | 'of_oxm_udp_src' : { 'value' : transport_port }, |
| 619 | 'of_oxm_udp_src_masked' : { 'value' : transport_port, 'value_mask' : transport_port }, |
| 620 | 'of_oxm_udp_dst' : { 'value' : transport_port }, |
| 621 | 'of_oxm_udp_dst_masked' : { 'value' : transport_port, 'value_mask' : transport_port }, |
| 622 | 'of_oxm_sctp_src' : { 'value' : transport_port }, |
| 623 | 'of_oxm_sctp_src_masked' : { 'value' : transport_port, 'value_mask' : transport_port }, |
| 624 | 'of_oxm_sctp_dst' : { 'value' : transport_port }, |
| 625 | 'of_oxm_sctp_dst_masked' : { 'value' : transport_port, 'value_mask' : transport_port }, |
| 626 | 'of_oxm_eth_type' : { 'value' : eth_type }, |
| 627 | 'of_oxm_eth_type_masked' : { 'value' : eth_type, 'value_mask' : eth_type }, |
Andreas Wundsam | 98a1863 | 2013-11-05 11:34:24 -0800 | [diff] [blame] | 628 | 'of_oxm_vlan_vid' : { 'value' : vlan_vid_match }, |
| 629 | '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] | 630 | 'of_oxm_vlan_pcp' : { 'value' : vlan_pcp }, |
| 631 | 'of_oxm_vlan_pcp_masked' : { 'value' : vlan_pcp, 'value_mask' : vlan_pcp }, |
| 632 | 'of_oxm_ip_dscp' : { 'value' : ip_dscp }, |
| 633 | 'of_oxm_ip_dscp_masked' : { 'value' : ip_dscp, 'value_mask' : ip_dscp }, |
| 634 | 'of_oxm_ip_ecn' : { 'value' : ip_ecn }, |
| 635 | 'of_oxm_ip_ecn_masked' : { 'value' : ip_ecn, 'value_mask' : ip_ecn }, |
| 636 | 'of_oxm_ip_proto' : { 'value' : ip_proto }, |
| 637 | 'of_oxm_ip_proto_masked' : { 'value' : ip_proto, 'value_mask' : ip_proto }, |
| 638 | 'of_oxm_icmpv4_type' : { 'value' : icmpv4_type }, |
| 639 | 'of_oxm_icmpv4_type_masked' : { 'value' : icmpv4_type, 'value_mask' : icmpv4_type }, |
| 640 | 'of_oxm_icmpv4_code' : { 'value' : icmpv4_code }, |
| 641 | 'of_oxm_icmpv4_code_masked' : { 'value' : icmpv4_code, 'value_mask' : icmpv4_code }, |
| 642 | 'of_oxm_arp_op' : { 'value' : arp_op }, |
| 643 | 'of_oxm_arp_op_masked' : { 'value' : arp_op, 'value_mask' : arp_op }, |
| 644 | 'of_oxm_arp_spa' : { 'value' : ipv4 }, |
| 645 | 'of_oxm_arp_spa_masked' : { 'value' : ipv4, 'value_mask' : ipv4 }, |
| 646 | 'of_oxm_arp_tpa' : { 'value' : ipv4 }, |
| 647 | 'of_oxm_arp_tpa_masked' : { 'value' : ipv4, 'value_mask' : ipv4 }, |
| 648 | 'of_oxm_ipv6_flabel' : { 'value' : ipv6_flabel }, |
| 649 | 'of_oxm_ipv6_flabel_masked' : { 'value' : ipv6_flabel, 'value_mask' : ipv6_flabel }, |
| 650 | 'of_oxm_metadata' : { 'value' : metadata }, |
| 651 | 'of_oxm_metadata_masked' : { 'value' : metadata, 'value_mask' : metadata }, |
Yotam Harchol | 5804f77 | 2013-08-21 17:35:31 -0700 | [diff] [blame] | 652 | |
| 653 | 'of_oxm_icmpv6_code' : { 'value' : u8obj }, |
| 654 | 'of_oxm_icmpv6_code_masked' : { 'value' : u8obj, 'value_mask' : u8obj }, |
| 655 | 'of_oxm_icmpv6_type' : { 'value' : u8obj }, |
| 656 | 'of_oxm_icmpv6_type_masked' : { 'value' : u8obj, 'value_mask' : u8obj }, |
| 657 | 'of_oxm_mpls_label' : { 'value' : u32obj }, |
| 658 | 'of_oxm_mpls_label_masked' : { 'value' : u32obj, 'value_mask' : u32obj }, |
| 659 | 'of_oxm_mpls_tc' : { 'value' : u8obj }, |
| 660 | 'of_oxm_mpls_tc_masked' : { 'value' : u8obj, 'value_mask' : u8obj }, |
Saurav Das | bc26674 | 2014-10-09 16:45:27 -0700 | [diff] [blame] | 661 | 'of_oxm_mpls_bos' : { 'value' : boolean_value }, |
| 662 | 'of_oxm_mpls_bos_masked' : { 'value' : boolean_value, 'value_mask' : boolean_value }, |
Rich Lane | 9f59504 | 2014-10-31 15:56:34 -0700 | [diff] [blame] | 663 | 'of_oxm_ipv6_exthdr' : { 'value' : u16obj }, |
| 664 | 'of_oxm_ipv6_exthdr_masked' : { 'value' : u16obj, 'value_mask' : u16obj }, |
| 665 | 'of_oxm_pbb_uca' : { 'value' : boolean_value }, |
| 666 | 'of_oxm_pbb_uca_masked' : { 'value' : boolean_value, 'value_mask' : boolean_value }, |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 667 | |
Sovietaced | 25021ec | 2014-12-31 15:44:21 -0500 | [diff] [blame] | 668 | 'of_oxm_bsn_in_ports_128' : { 'value': port_bitmap_128 }, |
| 669 | 'of_oxm_bsn_in_ports_128_masked' : { 'value': port_bitmap_128, 'value_mask': port_bitmap_128 }, |
Jimmy Jin | 646d122 | 2016-05-13 10:47:24 -0700 | [diff] [blame] | 670 | |
| 671 | 'of_oxm_bsn_in_ports_256' : { 'value': port_bitmap_256 }, |
| 672 | 'of_oxm_bsn_in_ports_256_masked' : { 'value': port_bitmap_256, 'value_mask': port_bitmap_256 }, |
Sovietaced | 25021ec | 2014-12-31 15:44:21 -0500 | [diff] [blame] | 673 | |
| 674 | 'of_oxm_bsn_in_ports_512' : { 'value': port_bitmap_512 }, |
| 675 | '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] | 676 | |
Rich Lane | 376cafe | 2013-10-27 21:49:14 -0700 | [diff] [blame] | 677 | 'of_oxm_bsn_lag_id' : { 'value' : lag_id }, |
| 678 | '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] | 679 | |
Rich Lane | eb21c4f | 2013-10-28 17:34:41 -0700 | [diff] [blame] | 680 | 'of_oxm_bsn_vrf' : { 'value' : vrf }, |
| 681 | 'of_oxm_bsn_vrf_masked' : { 'value' : vrf, 'value_mask' : vrf }, |
| 682 | |
Rich Lane | 9c27b5d | 2013-10-30 17:14:32 -0700 | [diff] [blame] | 683 | 'of_oxm_bsn_global_vrf_allowed' : { 'value' : boolean_value }, |
| 684 | '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] | 685 | |
| 686 | 'of_oxm_bsn_l3_interface_class_id' : { 'value' : class_id }, |
| 687 | 'of_oxm_bsn_l3_interface_class_id_masked' : { 'value' : class_id, 'value_mask' : class_id }, |
| 688 | |
| 689 | 'of_oxm_bsn_l3_src_class_id' : { 'value' : class_id }, |
| 690 | 'of_oxm_bsn_l3_src_class_id_masked' : { 'value' : class_id, 'value_mask' : class_id }, |
| 691 | |
| 692 | 'of_oxm_bsn_l3_dst_class_id' : { 'value' : class_id }, |
| 693 | 'of_oxm_bsn_l3_dst_class_id_masked' : { 'value' : class_id, 'value_mask' : class_id }, |
| 694 | |
Rich Lane | 917bb9a | 2014-03-11 17:49:56 -0700 | [diff] [blame] | 695 | 'of_oxm_bsn_egr_port_group_id' : { 'value' : class_id }, |
| 696 | 'of_oxm_bsn_egr_port_group_id_masked' : { 'value' : class_id, 'value_mask' : class_id }, |
| 697 | |
Rich Lane | 75d235a | 2015-02-03 17:40:10 -0800 | [diff] [blame] | 698 | 'of_oxm_bsn_ingress_port_group_id' : { 'value' : class_id }, |
| 699 | 'of_oxm_bsn_ingress_port_group_id_masked' : { 'value' : class_id, 'value_mask' : class_id }, |
| 700 | |
Rich Lane | 53ddf5c | 2014-03-20 15:24:08 -0700 | [diff] [blame] | 701 | 'of_oxm_bsn_udf0' : { 'value' : udf }, |
| 702 | 'of_oxm_bsn_udf0_masked' : { 'value' : udf, 'value_mask' : udf }, |
| 703 | |
| 704 | 'of_oxm_bsn_udf1' : { 'value' : udf }, |
| 705 | 'of_oxm_bsn_udf1_masked' : { 'value' : udf, 'value_mask' : udf }, |
| 706 | |
| 707 | 'of_oxm_bsn_udf2' : { 'value' : udf }, |
| 708 | 'of_oxm_bsn_udf2_masked' : { 'value' : udf, 'value_mask' : udf }, |
| 709 | |
| 710 | 'of_oxm_bsn_udf3' : { 'value' : udf }, |
| 711 | 'of_oxm_bsn_udf3_masked' : { 'value' : udf, 'value_mask' : udf }, |
| 712 | |
| 713 | 'of_oxm_bsn_udf4' : { 'value' : udf }, |
| 714 | 'of_oxm_bsn_udf4_masked' : { 'value' : udf, 'value_mask' : udf }, |
| 715 | |
| 716 | 'of_oxm_bsn_udf5' : { 'value' : udf }, |
| 717 | 'of_oxm_bsn_udf5_masked' : { 'value' : udf, 'value_mask' : udf }, |
| 718 | |
| 719 | 'of_oxm_bsn_udf6' : { 'value' : udf }, |
| 720 | 'of_oxm_bsn_udf6_masked' : { 'value' : udf, 'value_mask' : udf }, |
| 721 | |
| 722 | 'of_oxm_bsn_udf7' : { 'value' : udf }, |
| 723 | 'of_oxm_bsn_udf7_masked' : { 'value' : udf, 'value_mask' : udf }, |
| 724 | |
Rich Lane | 9b17807 | 2014-05-19 15:31:55 -0700 | [diff] [blame] | 725 | 'of_oxm_bsn_tcp_flags' : { 'value' : u16obj }, |
| 726 | 'of_oxm_bsn_tcp_flags_masked' : { 'value' : u16obj, 'value_mask' : u16obj }, |
| 727 | |
Rich Lane | a5eeae3 | 2014-06-26 19:59:04 -0700 | [diff] [blame] | 728 | 'of_oxm_bsn_vlan_xlate_port_group_id' : { 'value' : class_id }, |
| 729 | 'of_oxm_bsn_vlan_xlate_port_group_id_masked' : { 'value' : class_id, 'value_mask' : class_id }, |
| 730 | |
Wilson Ng | 15efef9 | 2014-11-05 14:27:35 -0800 | [diff] [blame] | 731 | 'of_oxm_bsn_l2_cache_hit' : { 'value' : boolean_value }, |
| 732 | '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] | 733 | |
Ken Chiang | 8df4a11 | 2015-05-12 10:15:44 -0700 | [diff] [blame] | 734 | 'of_oxm_bsn_vxlan_network_id' : { 'value' : u32obj }, |
| 735 | 'of_oxm_bsn_vxlan_network_id_masked' : { 'value' : u32obj, 'value_mask' : u32obj }, |
| 736 | |
| 737 | 'of_oxm_bsn_inner_eth_dst' : { 'value' : mac_addr }, |
| 738 | 'of_oxm_bsn_inner_eth_dst_masked' : { 'value' : mac_addr, 'value_mask' : mac_addr }, |
| 739 | |
| 740 | 'of_oxm_bsn_inner_eth_src' : { 'value' : mac_addr }, |
| 741 | 'of_oxm_bsn_inner_eth_src_masked' : { 'value' : mac_addr, 'value_mask' : mac_addr }, |
| 742 | |
Wilson Ng | 95afd51 | 2015-07-13 14:31:00 -0700 | [diff] [blame] | 743 | 'of_oxm_bsn_inner_vlan_vid' : { 'value' : vlan_vid_match }, |
| 744 | 'of_oxm_bsn_inner_vlan_vid_masked' : { 'value' : vlan_vid_match, 'value_mask' : vlan_vid_match }, |
| 745 | |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 746 | 'of_table_stats_entry': { 'wildcards': table_stats_wildcards }, |
Andreas Wundsam | 98a1863 | 2013-11-05 11:34:24 -0800 | [diff] [blame] | 747 | 'of_match_v1': { 'vlan_vid' : vlan_vid_match, 'vlan_pcp': vlan_pcp, |
Andreas Wundsam | b3ed3ff | 2013-09-23 14:46:29 -0700 | [diff] [blame] | 748 | 'eth_type': eth_type, 'ip_dscp': ip_dscp, 'ip_proto': ip_proto, |
Andreas Wundsam | e962d37 | 2013-10-02 18:15:58 -0700 | [diff] [blame] | 749 | 'tcp_src': transport_port, 'tcp_dst': transport_port, |
| 750 | 'in_port': of_port_match_v1 |
Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame] | 751 | }, |
| 752 | 'of_bsn_set_l2_table_request': { 'l2_table_enable': boolean }, |
| 753 | 'of_bsn_set_l2_table_reply': { 'l2_table_enable': boolean }, |
Rob Vaterlaus | e1b8684 | 2013-10-18 13:29:19 -0700 | [diff] [blame] | 754 | 'of_bsn_set_pktin_suppression_request': { 'enabled': boolean }, |
Sovietaced | 768c3e2 | 2014-04-04 16:46:48 -0700 | [diff] [blame] | 755 | 'of_bsn_controller_connection': { 'auxiliary_id' : of_aux_id}, |
Andreas Wundsam | acd57d5 | 2013-10-18 17:35:01 -0700 | [diff] [blame] | 756 | 'of_flow_stats_request': { 'out_group': of_group_default_any }, |
Andreas Wundsam | 384ccc1 | 2014-03-12 14:52:42 -0700 | [diff] [blame] | 757 | 'of_aggregate_stats_request': { 'out_group': of_group_default_any }, |
Andreas Wundsam | 98a1863 | 2013-11-05 11:34:24 -0800 | [diff] [blame] | 758 | |
| 759 | 'of_action_bsn_mirror': { 'dest_port': of_port }, |
| 760 | 'of_action_push_mpls': { 'ethertype': eth_type }, |
| 761 | 'of_action_push_pbb': { 'ethertype': eth_type }, |
| 762 | 'of_action_push_vlan': { 'ethertype': eth_type }, |
Ronald Li | 4fb8abb | 2013-11-21 19:53:02 -0800 | [diff] [blame] | 763 | 'of_action_pop_mpls': { 'ethertype': eth_type }, |
Andreas Wundsam | 98a1863 | 2013-11-05 11:34:24 -0800 | [diff] [blame] | 764 | 'of_action_set_nw_dst': { 'nw_addr': ipv4 }, |
| 765 | 'of_action_set_nw_ecn': { 'nw_ecn': ip_ecn }, |
| 766 | 'of_action_set_nw_src': { 'nw_addr': ipv4 }, |
Andreas Wundsam | 98a1863 | 2013-11-05 11:34:24 -0800 | [diff] [blame] | 767 | 'of_action_set_tp_dst': { 'tp_port': transport_port }, |
| 768 | 'of_action_set_tp_src': { 'tp_port': transport_port }, |
| 769 | 'of_action_set_vlan_pcp': { 'vlan_pcp': vlan_pcp }, |
| 770 | 'of_action_set_vlan_vid': { 'vlan_vid': vlan_vid }, |
Andreas Wundsam | 5812cf3 | 2013-11-15 13:51:24 -0800 | [diff] [blame] | 771 | |
| 772 | 'of_group_mod' : { 'command' : group_mod_cmd }, |
| 773 | 'of_group_add' : { 'command' : group_mod_cmd }, |
| 774 | 'of_group_modify' : { 'command' : group_mod_cmd }, |
| 775 | 'of_group_delete' : { 'command' : group_mod_cmd }, |
| 776 | |
| 777 | 'of_bucket' : { 'watch_group': of_group }, |
Andreas Wundsam | d4b2269 | 2014-01-14 14:17:26 -0800 | [diff] [blame] | 778 | |
| 779 | 'of_bsn_tlv_vlan_vid' : { 'value' : vlan_vid }, |
Andreas Wundsam | ec1f661 | 2014-06-25 15:48:12 -0700 | [diff] [blame] | 780 | 'of_bsn_table_set_buckets_size' : { 'table_id' : table_id }, |
Andreas Wundsam | d4b2269 | 2014-01-14 14:17:26 -0800 | [diff] [blame] | 781 | 'of_bsn_gentable_entry_add' : { 'table_id' : gen_table_id }, |
Andreas Wundsam | e2fd7ce | 2014-06-26 20:56:42 -0700 | [diff] [blame] | 782 | 'of_bsn_log': { 'data': var_string }, |
Sovietaced | 92603b0 | 2014-01-28 18:23:24 -0800 | [diff] [blame] | 783 | |
Sovietaced | 0f9dddf | 2014-01-28 19:45:07 -0800 | [diff] [blame] | 784 | 'of_features_reply' : { 'auxiliary_id' : of_aux_id}, |
Praseed Balakrishnan | 2ed6da0 | 2014-09-18 17:02:48 -0700 | [diff] [blame] | 785 | 'of_oxm_och_sigtype' : { 'value' : u8obj }, |
| 786 | 'of_oxm_och_sigtype_basic' : { 'value' : u8obj }, |
alshabib | 78e24b9 | 2015-01-28 14:28:18 -0800 | [diff] [blame] | 787 | 'of_oxm_och_sigid' : {'value' : sig_id}, |
BitOhenry | 83b5323 | 2015-11-18 17:26:55 +0800 | [diff] [blame] | 788 | 'of_oxm_och_sigid_basic' : {'value' : sig_id}, |
Andreas Wundsam | 73d7d67 | 2014-11-12 17:07:33 -0800 | [diff] [blame] | 789 | |
Jimmy Jin | 4fd3902 | 2016-01-15 12:39:01 -0800 | [diff] [blame] | 790 | 'of_oxm_och_sigatt' : { 'value' : u32obj }, |
| 791 | 'of_oxm_och_sigatt_basic' : { 'value' : u32obj }, |
| 792 | |
Andreas Wundsam | 73d7d67 | 2014-11-12 17:07:33 -0800 | [diff] [blame] | 793 | 'of_bundle_add_msg' : { 'data' : of_message }, |
Yafit Hadar | f8caac0 | 2015-08-25 10:21:44 +0300 | [diff] [blame] | 794 | |
| 795 | 'of_oxm_exp_odu_sigtype' : { 'value' : u8obj }, |
BitOhenry | 83b5323 | 2015-11-18 17:26:55 +0800 | [diff] [blame] | 796 | 'of_oxm_exp_och_sigtype' : { 'value' : u8obj }, |
| 797 | |
| 798 | 'of_oxm_reg0' : { 'value' : u32obj }, |
| 799 | 'of_oxm_reg0_masked' : { 'value' : u32obj, 'value_mask' : u32obj }, |
| 800 | |
| 801 | 'of_oxm_reg1' : { 'value' : u32obj }, |
| 802 | 'of_oxm_reg1_masked' : { 'value' : u32obj, 'value_mask' : u32obj }, |
| 803 | |
| 804 | 'of_oxm_reg2' : { 'value' : u32obj }, |
| 805 | 'of_oxm_reg2_masked' : { 'value' : u32obj, 'value_mask' : u32obj }, |
| 806 | |
| 807 | 'of_oxm_reg3' : { 'value' : u32obj }, |
| 808 | 'of_oxm_reg3_masked' : { 'value' : u32obj, 'value_mask' : u32obj }, |
| 809 | |
| 810 | 'of_oxm_reg4' : { 'value' : u32obj }, |
| 811 | 'of_oxm_reg4_masked' : { 'value' : u32obj, 'value_mask' : u32obj }, |
| 812 | |
| 813 | 'of_oxm_reg5' : { 'value' : u32obj }, |
| 814 | 'of_oxm_reg5_masked' : { 'value' : u32obj, 'value_mask' : u32obj }, |
| 815 | |
| 816 | 'of_oxm_reg6' : { 'value' : u32obj }, |
| 817 | 'of_oxm_reg6_masked' : { 'value' : u32obj, 'value_mask' : u32obj }, |
| 818 | |
| 819 | 'of_oxm_reg7' : { 'value' : u32obj }, |
| 820 | 'of_oxm_reg7_masked' : { 'value' : u32obj, 'value_mask' : u32obj }, |
Phanendra Manda | 4c728b3 | 2015-12-09 23:04:16 +0530 | [diff] [blame] | 821 | |
Phaneendra Manda | adcb3e7 | 2016-05-12 21:53:48 +0530 | [diff] [blame] | 822 | 'of_oxm_nsp' : { 'value' : u32obj }, |
| 823 | 'of_oxm_nsp_masked' : { 'value' : u32obj, 'value_mask' : u32obj }, |
Phanendra Manda | 4c728b3 | 2015-12-09 23:04:16 +0530 | [diff] [blame] | 824 | |
Phaneendra Manda | adcb3e7 | 2016-05-12 21:53:48 +0530 | [diff] [blame] | 825 | 'of_oxm_nsi' : { 'value' : u8obj }, |
| 826 | 'of_oxm_nsi_masked' : { 'value' : u8obj, 'value_mask' : u8obj }, |
Phanendra Manda | 4c728b3 | 2015-12-09 23:04:16 +0530 | [diff] [blame] | 827 | |
Phaneendra Manda | adcb3e7 | 2016-05-12 21:53:48 +0530 | [diff] [blame] | 828 | 'of_oxm_nsh_c1' : { 'value' : u32obj }, |
| 829 | 'of_oxm_nsh_c1_masked' : { 'value' : u32obj, 'value_mask' : u32obj }, |
Phanendra Manda | 4c728b3 | 2015-12-09 23:04:16 +0530 | [diff] [blame] | 830 | |
Phaneendra Manda | adcb3e7 | 2016-05-12 21:53:48 +0530 | [diff] [blame] | 831 | 'of_oxm_nsh_c2' : { 'value' : u32obj }, |
| 832 | 'of_oxm_nsh_c2_masked' : { 'value' : u32obj, 'value_mask' : u32obj }, |
Phanendra Manda | 4c728b3 | 2015-12-09 23:04:16 +0530 | [diff] [blame] | 833 | |
Phaneendra Manda | adcb3e7 | 2016-05-12 21:53:48 +0530 | [diff] [blame] | 834 | 'of_oxm_nsh_c3' : { 'value' : u32obj }, |
| 835 | 'of_oxm_nsh_c3_masked' : { 'value' : u32obj, 'value_mask' : u32obj }, |
Phanendra Manda | 4c728b3 | 2015-12-09 23:04:16 +0530 | [diff] [blame] | 836 | |
Phaneendra Manda | adcb3e7 | 2016-05-12 21:53:48 +0530 | [diff] [blame] | 837 | 'of_oxm_nsh_c4' : { 'value' : u32obj }, |
| 838 | 'of_oxm_nsh_c4_masked' : { 'value' : u32obj, 'value_mask' : u32obj }, |
| 839 | |
| 840 | 'of_oxm_nsh_mdtype' : { 'value' : u8obj }, |
| 841 | 'of_oxm_nsh_mdtype_masked' : { 'value' : u8obj, 'value_mask' : u8obj }, |
| 842 | |
| 843 | 'of_oxm_nsh_np' : { 'value' : u8obj }, |
| 844 | 'of_oxm_nsh_np_masked' : { 'value' : u8obj, 'value_mask' : u8obj }, |
| 845 | |
| 846 | 'of_oxm_encap_eth_src' : { 'value' : mac_addr }, |
| 847 | 'of_oxm_encap_eth_src_masked' : { 'value' : mac_addr, 'value_mask' : mac_addr }, |
| 848 | |
| 849 | 'of_oxm_encap_eth_dst' : { 'value' : mac_addr }, |
| 850 | 'of_oxm_encap_eth_dst_masked' : { 'value' : mac_addr, 'value_mask' : mac_addr }, |
| 851 | |
| 852 | 'of_oxm_encap_eth_type' : { 'value' : u16obj }, |
| 853 | 'of_oxm_encap_eth_type_masked' : { 'value' : u16obj, 'value_mask' : u16obj }, |
| 854 | |
| 855 | 'of_oxm_tun_flags' : { 'value' : u16obj }, |
| 856 | 'of_oxm_tun_flags_masked' : { 'value' : u16obj, 'value_mask' : u16obj }, |
| 857 | |
| 858 | 'of_oxm_tun_gbp_id' : { 'value' : u16obj }, |
| 859 | 'of_oxm_tun_gbp_id_masked' : { 'value' : u16obj, 'value_mask' : u16obj }, |
| 860 | |
| 861 | 'of_oxm_tun_gbp_flags' : { 'value' : u8obj }, |
| 862 | 'of_oxm_tun_gbp_flags_masked' : { 'value' : u8obj, 'value_mask' : u8obj }, |
| 863 | |
| 864 | 'of_oxm_tun_gpe_np' : { 'value' : u8obj }, |
| 865 | 'of_oxm_tun_gpe_np_masked' : { 'value' : u8obj, 'value_mask' : u8obj }, |
| 866 | |
| 867 | 'of_oxm_tun_gpe_flags' : { 'value' : u8obj }, |
| 868 | 'of_oxm_tun_gpe_flags_masked' : { 'value' : u8obj, 'value_mask' : u8obj }, |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Andreas Wundsam | 7cfeac3 | 2013-09-17 13:53:48 -0700 | [diff] [blame] | 871 | |
| 872 | @memoize |
| 873 | def enum_java_types(): |
| 874 | enum_types = {} |
Andreas Wundsam | c8912c1 | 2013-11-15 13:44:48 -0800 | [diff] [blame] | 875 | for enum in loxi_globals.unified.enums: |
| 876 | java_name = name_c_to_caps_camel(re.sub(r'_t$', "", enum.name)) |
| 877 | enum_types[enum.name] = gen_enum_jtype(java_name, enum.is_bitmask) |
Andreas Wundsam | 7cfeac3 | 2013-09-17 13:53:48 -0700 | [diff] [blame] | 878 | return enum_types |
| 879 | |
Andreas Wundsam | 2be7da5 | 2013-08-22 07:34:25 -0700 | [diff] [blame] | 880 | def make_match_field_jtype(sub_type_name="?"): |
| 881 | return JType("MatchField<{}>".format(sub_type_name)) |
| 882 | |
Andreas Wundsam | 661a222 | 2013-11-05 17:18:59 -0800 | [diff] [blame] | 883 | def make_oxm_jtype(sub_type_name="?"): |
| 884 | return JType("OFOxm<{}>".format(sub_type_name)) |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 885 | |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 886 | def list_cname_to_java_name(c_type): |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 887 | m = re.match(r'list\(of_([a-zA-Z_]+)_t\)', c_type) |
| 888 | if not m: |
| 889 | raise Exception("Not a recgonized standard list type declaration: %s" % c_type) |
| 890 | base_name = m.group(1) |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 891 | return "OF" + name_c_to_caps_camel(base_name) |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 892 | |
| 893 | #### main entry point for conversion of LOXI types (c_types) Java types. |
| 894 | # FIXME: This badly needs a refactoring |
| 895 | |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 896 | def convert_to_jtype(obj_name, field_name, c_type): |
| 897 | """ Convert from a C type ("uint_32") to a java type ("U32") |
| 898 | and return a JType object with the size, internal type, and marshalling functions""" |
| 899 | if obj_name in exceptions and field_name in exceptions[obj_name]: |
| 900 | return exceptions[obj_name][field_name] |
Andreas Wundsam | 46d230f | 2013-08-02 22:24:06 -0700 | [diff] [blame] | 901 | 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] | 902 | return of_type |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 903 | elif field_name == "type" and re.match(r'of_action.*', obj_name): |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 904 | return action_type |
Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame] | 905 | elif field_name == "err_type": |
| 906 | return JType("OFErrorType", 'short') \ |
| 907 | .op(read='bb.readShort()', write='bb.writeShort($name)') |
Andreas Wundsam | 62cbcff | 2014-05-09 16:35:00 -0700 | [diff] [blame] | 908 | elif loxi_utils.class_is(obj_name, "of_error_msg") and field_name == "data": |
| 909 | return error_cause_data |
Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame] | 910 | elif field_name == "stats_type": |
| 911 | return JType("OFStatsType", 'short') \ |
| 912 | .op(read='bb.readShort()', write='bb.writeShort($name)') |
Andreas Wundsam | 999c073 | 2013-10-01 19:29:16 -0700 | [diff] [blame] | 913 | elif field_name == "type" and re.match(r'of_instruction.*', obj_name): |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 914 | return instruction_type |
Andreas Wundsam | ee8b42c | 2014-01-24 17:38:19 -0800 | [diff] [blame] | 915 | 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] | 916 | return table_id_default_zero |
Andreas Wundsam | ee8b42c | 2014-01-24 17:38:19 -0800 | [diff] [blame] | 917 | elif loxi_utils.class_is(obj_name, "of_flow_mod") and field_name == "out_group" and c_type == "uint32_t": |
| 918 | return of_group_default_any |
Andreas Wundsam | 37e0fb1 | 2013-09-28 18:57:57 -0700 | [diff] [blame] | 919 | elif field_name == "table_id" and c_type == "uint8_t": |
| 920 | return table_id |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 921 | elif field_name == "version" and c_type == "uint8_t": |
Andreas Wundsam | a098102 | 2013-10-02 18:15:06 -0700 | [diff] [blame] | 922 | return of_version |
Rob Vaterlaus | b10ae55 | 2013-09-23 14:39:39 -0700 | [diff] [blame] | 923 | elif field_name == "buffer_id" and c_type == "uint32_t": |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 924 | return buffer_id |
Andreas Wundsam | acd57d5 | 2013-10-18 17:35:01 -0700 | [diff] [blame] | 925 | elif field_name == "group_id" and c_type == "uint32_t": |
| 926 | return of_group |
Rob Vaterlaus | feee371 | 2013-09-30 11:24:19 -0700 | [diff] [blame] | 927 | elif field_name == 'datapath_id': |
| 928 | return datapath_id |
| 929 | elif field_name == 'actions' and obj_name == 'of_features_reply': |
Andreas Wundsam | 5ea1aca | 2013-10-07 17:00:24 -0700 | [diff] [blame] | 930 | return action_type_set |
Andreas Wundsam | d4b2269 | 2014-01-14 14:17:26 -0800 | [diff] [blame] | 931 | elif field_name == "table_id" and re.match(r'of_bsn_gentable.*', obj_name): |
| 932 | return gen_table_id |
Andreas Wundsam | 73d7d67 | 2014-11-12 17:07:33 -0800 | [diff] [blame] | 933 | elif field_name == "bundle_id" and re.match(r'of_bundle_.*', obj_name): |
| 934 | return bundle_id |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 935 | elif c_type in default_mtype_to_jtype_convert_map: |
| 936 | return default_mtype_to_jtype_convert_map[c_type] |
| 937 | elif re.match(r'list\(of_([a-zA-Z_]+)_t\)', c_type): |
Andreas Wundsam | 22ba3af | 2013-10-04 16:00:30 -0700 | [diff] [blame] | 938 | return gen_list_jtype(list_cname_to_java_name(c_type)) |
Andreas Wundsam | 7cfeac3 | 2013-09-17 13:53:48 -0700 | [diff] [blame] | 939 | elif c_type in enum_java_types(): |
| 940 | return enum_java_types()[c_type] |
Andreas Wundsam | 2730346 | 2013-07-16 12:52:35 -0700 | [diff] [blame] | 941 | else: |
| 942 | print "WARN: Couldn't find java type conversion for '%s' in %s:%s" % (c_type, obj_name, field_name) |
| 943 | jtype = name_c_to_caps_camel(re.sub(r'_t$', "", c_type)) |
| 944 | return JType(jtype) |
Andreas Wundsam | d8bcedf | 2013-08-03 21:23:37 -0700 | [diff] [blame] | 945 | |
| 946 | |
| 947 | #### Enum specific wiretype definitions |
| 948 | enum_wire_types = { |
| 949 | "uint8_t": JType("byte").op(read="bb.readByte()", write="bb.writeByte($name)"), |
| 950 | "uint16_t": JType("short").op(read="bb.readShort()", write="bb.writeShort($name)"), |
| 951 | "uint32_t": JType("int").op(read="bb.readInt()", write="bb.writeInt($name)"), |
| 952 | "uint64_t": JType("long").op(read="bb.readLong()", write="bb.writeLong($name)"), |
| 953 | } |
| 954 | |
| 955 | def convert_enum_wire_type_to_jtype(wire_type): |
| 956 | return enum_wire_types[wire_type] |