Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 1 | # Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University |
| 2 | # Copyright (c) 2011, 2012 Open Networking Foundation |
| 3 | # Copyright (c) 2012, 2013 Big Switch Networks, Inc. |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 4 | # See the file LICENSE.pyloxi which should have been included in the source distribution |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 5 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 6 | # Automatically generated by LOXI from template module.py |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 7 | # Do not modify |
| 8 | |
| 9 | import struct |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 10 | import loxi |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 11 | import const |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 12 | import common |
| 13 | import action |
| 14 | import instruction |
| 15 | import oxm |
| 16 | import action_id |
| 17 | import instruction_id |
| 18 | import meter_band |
Rich Lane | 5454b68 | 2014-01-14 17:07:36 -0800 | [diff] [blame] | 19 | import bsn_tlv |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 20 | import util |
| 21 | import loxi.generic_util |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 22 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 23 | class instruction(loxi.OFObject): |
| 24 | subtypes = {} |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 25 | |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 26 | |
| 27 | def __init__(self, type=None): |
| 28 | if type != None: |
| 29 | self.type = type |
| 30 | else: |
| 31 | self.type = 0 |
| 32 | return |
| 33 | |
| 34 | def pack(self): |
| 35 | packed = [] |
| 36 | packed.append(struct.pack("!H", self.type)) |
| 37 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 38 | length = sum([len(x) for x in packed]) |
| 39 | packed[1] = struct.pack("!H", length) |
| 40 | return ''.join(packed) |
| 41 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 42 | @staticmethod |
| 43 | def unpack(reader): |
| 44 | subtype, = reader.peek('!H', 0) |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 45 | subclass = instruction.subtypes.get(subtype) |
| 46 | if subclass: |
| 47 | return subclass.unpack(reader) |
| 48 | |
| 49 | obj = instruction() |
| 50 | obj.type = reader.read("!H")[0] |
| 51 | _len = reader.read("!H")[0] |
| 52 | orig_reader = reader |
| 53 | reader = orig_reader.slice(_len - (2 + 2)) |
| 54 | return obj |
| 55 | |
| 56 | def __eq__(self, other): |
| 57 | if type(self) != type(other): return False |
| 58 | if self.type != other.type: return False |
| 59 | return True |
| 60 | |
| 61 | def pretty_print(self, q): |
| 62 | q.text("instruction {") |
| 63 | with q.group(): |
| 64 | with q.indent(2): |
| 65 | q.breakable() |
| 66 | q.breakable() |
| 67 | q.text('}') |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 68 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 69 | |
| 70 | class apply_actions(instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 71 | type = 4 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 72 | |
| 73 | def __init__(self, actions=None): |
| 74 | if actions != None: |
| 75 | self.actions = actions |
| 76 | else: |
| 77 | self.actions = [] |
| 78 | return |
| 79 | |
| 80 | def pack(self): |
| 81 | packed = [] |
| 82 | packed.append(struct.pack("!H", self.type)) |
| 83 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 84 | packed.append('\x00' * 4) |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 85 | packed.append(loxi.generic_util.pack_list(self.actions)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 86 | length = sum([len(x) for x in packed]) |
| 87 | packed[1] = struct.pack("!H", length) |
| 88 | return ''.join(packed) |
| 89 | |
| 90 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 91 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 92 | obj = apply_actions() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 93 | _type = reader.read("!H")[0] |
| 94 | assert(_type == 4) |
| 95 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 96 | orig_reader = reader |
| 97 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 98 | reader.skip(4) |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 99 | obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 100 | return obj |
| 101 | |
| 102 | def __eq__(self, other): |
| 103 | if type(self) != type(other): return False |
| 104 | if self.actions != other.actions: return False |
| 105 | return True |
| 106 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 107 | def pretty_print(self, q): |
| 108 | q.text("apply_actions {") |
| 109 | with q.group(): |
| 110 | with q.indent(2): |
| 111 | q.breakable() |
| 112 | q.text("actions = "); |
| 113 | q.pp(self.actions) |
| 114 | q.breakable() |
| 115 | q.text('}') |
| 116 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 117 | instruction.subtypes[4] = apply_actions |
| 118 | |
| 119 | class experimenter(instruction): |
| 120 | subtypes = {} |
| 121 | |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 122 | type = 65535 |
| 123 | |
| 124 | def __init__(self, experimenter=None, data=None): |
| 125 | if experimenter != None: |
| 126 | self.experimenter = experimenter |
| 127 | else: |
| 128 | self.experimenter = 0 |
| 129 | if data != None: |
| 130 | self.data = data |
| 131 | else: |
| 132 | self.data = '' |
| 133 | return |
| 134 | |
| 135 | def pack(self): |
| 136 | packed = [] |
| 137 | packed.append(struct.pack("!H", self.type)) |
| 138 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 139 | packed.append(struct.pack("!L", self.experimenter)) |
| 140 | packed.append(self.data) |
| 141 | length = sum([len(x) for x in packed]) |
| 142 | packed[1] = struct.pack("!H", length) |
| 143 | return ''.join(packed) |
| 144 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 145 | @staticmethod |
| 146 | def unpack(reader): |
| 147 | subtype, = reader.peek('!L', 4) |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 148 | subclass = experimenter.subtypes.get(subtype) |
| 149 | if subclass: |
| 150 | return subclass.unpack(reader) |
| 151 | |
| 152 | obj = experimenter() |
| 153 | _type = reader.read("!H")[0] |
| 154 | assert(_type == 65535) |
| 155 | _len = reader.read("!H")[0] |
| 156 | orig_reader = reader |
| 157 | reader = orig_reader.slice(_len - (2 + 2)) |
| 158 | obj.experimenter = reader.read("!L")[0] |
| 159 | obj.data = str(reader.read_all()) |
| 160 | return obj |
| 161 | |
| 162 | def __eq__(self, other): |
| 163 | if type(self) != type(other): return False |
| 164 | if self.experimenter != other.experimenter: return False |
| 165 | if self.data != other.data: return False |
| 166 | return True |
| 167 | |
| 168 | def pretty_print(self, q): |
| 169 | q.text("experimenter {") |
| 170 | with q.group(): |
| 171 | with q.indent(2): |
| 172 | q.breakable() |
| 173 | q.text("data = "); |
| 174 | q.pp(self.data) |
| 175 | q.breakable() |
| 176 | q.text('}') |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 177 | |
| 178 | instruction.subtypes[65535] = experimenter |
| 179 | |
| 180 | class bsn(experimenter): |
| 181 | subtypes = {} |
| 182 | |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 183 | type = 65535 |
| 184 | experimenter = 6035143 |
| 185 | |
| 186 | def __init__(self, subtype=None): |
| 187 | if subtype != None: |
| 188 | self.subtype = subtype |
| 189 | else: |
| 190 | self.subtype = 0 |
| 191 | return |
| 192 | |
| 193 | def pack(self): |
| 194 | packed = [] |
| 195 | packed.append(struct.pack("!H", self.type)) |
| 196 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 197 | packed.append(struct.pack("!L", self.experimenter)) |
| 198 | packed.append(struct.pack("!L", self.subtype)) |
| 199 | packed.append('\x00' * 4) |
| 200 | length = sum([len(x) for x in packed]) |
| 201 | packed[1] = struct.pack("!H", length) |
| 202 | return ''.join(packed) |
| 203 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 204 | @staticmethod |
| 205 | def unpack(reader): |
| 206 | subtype, = reader.peek('!L', 8) |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 207 | subclass = bsn.subtypes.get(subtype) |
| 208 | if subclass: |
| 209 | return subclass.unpack(reader) |
| 210 | |
| 211 | obj = bsn() |
| 212 | _type = reader.read("!H")[0] |
| 213 | assert(_type == 65535) |
| 214 | _len = reader.read("!H")[0] |
| 215 | orig_reader = reader |
| 216 | reader = orig_reader.slice(_len - (2 + 2)) |
| 217 | _experimenter = reader.read("!L")[0] |
| 218 | assert(_experimenter == 6035143) |
| 219 | obj.subtype = reader.read("!L")[0] |
| 220 | reader.skip(4) |
| 221 | return obj |
| 222 | |
| 223 | def __eq__(self, other): |
| 224 | if type(self) != type(other): return False |
| 225 | if self.subtype != other.subtype: return False |
| 226 | return True |
| 227 | |
| 228 | def pretty_print(self, q): |
| 229 | q.text("bsn {") |
| 230 | with q.group(): |
| 231 | with q.indent(2): |
| 232 | q.breakable() |
| 233 | q.breakable() |
| 234 | q.text('}') |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 235 | |
| 236 | experimenter.subtypes[6035143] = bsn |
| 237 | |
Rich Lane | 5454b68 | 2014-01-14 17:07:36 -0800 | [diff] [blame] | 238 | class bsn_arp_offload(bsn): |
| 239 | type = 65535 |
| 240 | experimenter = 6035143 |
| 241 | subtype = 1 |
| 242 | |
| 243 | def __init__(self): |
| 244 | return |
| 245 | |
| 246 | def pack(self): |
| 247 | packed = [] |
| 248 | packed.append(struct.pack("!H", self.type)) |
| 249 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 250 | packed.append(struct.pack("!L", self.experimenter)) |
| 251 | packed.append(struct.pack("!L", self.subtype)) |
| 252 | packed.append('\x00' * 4) |
| 253 | length = sum([len(x) for x in packed]) |
| 254 | packed[1] = struct.pack("!H", length) |
| 255 | return ''.join(packed) |
| 256 | |
| 257 | @staticmethod |
| 258 | def unpack(reader): |
| 259 | obj = bsn_arp_offload() |
| 260 | _type = reader.read("!H")[0] |
| 261 | assert(_type == 65535) |
| 262 | _len = reader.read("!H")[0] |
| 263 | orig_reader = reader |
| 264 | reader = orig_reader.slice(_len - (2 + 2)) |
| 265 | _experimenter = reader.read("!L")[0] |
| 266 | assert(_experimenter == 6035143) |
| 267 | _subtype = reader.read("!L")[0] |
| 268 | assert(_subtype == 1) |
| 269 | reader.skip(4) |
| 270 | return obj |
| 271 | |
| 272 | def __eq__(self, other): |
| 273 | if type(self) != type(other): return False |
| 274 | return True |
| 275 | |
| 276 | def pretty_print(self, q): |
| 277 | q.text("bsn_arp_offload {") |
| 278 | with q.group(): |
| 279 | with q.indent(2): |
| 280 | q.breakable() |
| 281 | q.breakable() |
| 282 | q.text('}') |
| 283 | |
| 284 | bsn.subtypes[1] = bsn_arp_offload |
| 285 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 286 | class bsn_disable_src_mac_check(bsn): |
Rich Lane | 7b0f201 | 2013-11-22 14:15:26 -0800 | [diff] [blame] | 287 | type = 65535 |
| 288 | experimenter = 6035143 |
| 289 | subtype = 0 |
| 290 | |
| 291 | def __init__(self): |
| 292 | return |
| 293 | |
| 294 | def pack(self): |
| 295 | packed = [] |
| 296 | packed.append(struct.pack("!H", self.type)) |
| 297 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 298 | packed.append(struct.pack("!L", self.experimenter)) |
| 299 | packed.append(struct.pack("!L", self.subtype)) |
| 300 | packed.append('\x00' * 4) |
| 301 | length = sum([len(x) for x in packed]) |
| 302 | packed[1] = struct.pack("!H", length) |
| 303 | return ''.join(packed) |
| 304 | |
| 305 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 306 | def unpack(reader): |
Rich Lane | 7b0f201 | 2013-11-22 14:15:26 -0800 | [diff] [blame] | 307 | obj = bsn_disable_src_mac_check() |
Rich Lane | 7b0f201 | 2013-11-22 14:15:26 -0800 | [diff] [blame] | 308 | _type = reader.read("!H")[0] |
| 309 | assert(_type == 65535) |
| 310 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 311 | orig_reader = reader |
| 312 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | 7b0f201 | 2013-11-22 14:15:26 -0800 | [diff] [blame] | 313 | _experimenter = reader.read("!L")[0] |
| 314 | assert(_experimenter == 6035143) |
| 315 | _subtype = reader.read("!L")[0] |
| 316 | assert(_subtype == 0) |
| 317 | reader.skip(4) |
| 318 | return obj |
| 319 | |
| 320 | def __eq__(self, other): |
| 321 | if type(self) != type(other): return False |
| 322 | return True |
| 323 | |
Rich Lane | 7b0f201 | 2013-11-22 14:15:26 -0800 | [diff] [blame] | 324 | def pretty_print(self, q): |
| 325 | q.text("bsn_disable_src_mac_check {") |
| 326 | with q.group(): |
| 327 | with q.indent(2): |
| 328 | q.breakable() |
| 329 | q.breakable() |
| 330 | q.text('}') |
| 331 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 332 | bsn.subtypes[0] = bsn_disable_src_mac_check |
| 333 | |
| 334 | class clear_actions(instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 335 | type = 5 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 336 | |
| 337 | def __init__(self): |
| 338 | return |
| 339 | |
| 340 | def pack(self): |
| 341 | packed = [] |
| 342 | packed.append(struct.pack("!H", self.type)) |
| 343 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 344 | packed.append('\x00' * 4) |
| 345 | length = sum([len(x) for x in packed]) |
| 346 | packed[1] = struct.pack("!H", length) |
| 347 | return ''.join(packed) |
| 348 | |
| 349 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 350 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 351 | obj = clear_actions() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 352 | _type = reader.read("!H")[0] |
| 353 | assert(_type == 5) |
| 354 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 355 | orig_reader = reader |
| 356 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 357 | reader.skip(4) |
| 358 | return obj |
| 359 | |
| 360 | def __eq__(self, other): |
| 361 | if type(self) != type(other): return False |
| 362 | return True |
| 363 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 364 | def pretty_print(self, q): |
| 365 | q.text("clear_actions {") |
| 366 | with q.group(): |
| 367 | with q.indent(2): |
| 368 | q.breakable() |
| 369 | q.breakable() |
| 370 | q.text('}') |
| 371 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 372 | instruction.subtypes[5] = clear_actions |
| 373 | |
| 374 | class goto_table(instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 375 | type = 1 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 376 | |
| 377 | def __init__(self, table_id=None): |
| 378 | if table_id != None: |
| 379 | self.table_id = table_id |
| 380 | else: |
| 381 | self.table_id = 0 |
| 382 | return |
| 383 | |
| 384 | def pack(self): |
| 385 | packed = [] |
| 386 | packed.append(struct.pack("!H", self.type)) |
| 387 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 388 | packed.append(struct.pack("!B", self.table_id)) |
| 389 | packed.append('\x00' * 3) |
| 390 | length = sum([len(x) for x in packed]) |
| 391 | packed[1] = struct.pack("!H", length) |
| 392 | return ''.join(packed) |
| 393 | |
| 394 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 395 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 396 | obj = goto_table() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 397 | _type = reader.read("!H")[0] |
| 398 | assert(_type == 1) |
| 399 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 400 | orig_reader = reader |
| 401 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 402 | obj.table_id = reader.read("!B")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 403 | reader.skip(3) |
| 404 | return obj |
| 405 | |
| 406 | def __eq__(self, other): |
| 407 | if type(self) != type(other): return False |
| 408 | if self.table_id != other.table_id: return False |
| 409 | return True |
| 410 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 411 | def pretty_print(self, q): |
| 412 | q.text("goto_table {") |
| 413 | with q.group(): |
| 414 | with q.indent(2): |
| 415 | q.breakable() |
| 416 | q.text("table_id = "); |
| 417 | q.text("%#x" % self.table_id) |
| 418 | q.breakable() |
| 419 | q.text('}') |
| 420 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 421 | instruction.subtypes[1] = goto_table |
| 422 | |
| 423 | class meter(instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 424 | type = 6 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 425 | |
| 426 | def __init__(self, meter_id=None): |
| 427 | if meter_id != None: |
| 428 | self.meter_id = meter_id |
| 429 | else: |
| 430 | self.meter_id = 0 |
| 431 | return |
| 432 | |
| 433 | def pack(self): |
| 434 | packed = [] |
| 435 | packed.append(struct.pack("!H", self.type)) |
| 436 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 437 | packed.append(struct.pack("!L", self.meter_id)) |
| 438 | length = sum([len(x) for x in packed]) |
| 439 | packed[1] = struct.pack("!H", length) |
| 440 | return ''.join(packed) |
| 441 | |
| 442 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 443 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 444 | obj = meter() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 445 | _type = reader.read("!H")[0] |
| 446 | assert(_type == 6) |
| 447 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 448 | orig_reader = reader |
| 449 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 450 | obj.meter_id = reader.read("!L")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 451 | return obj |
| 452 | |
| 453 | def __eq__(self, other): |
| 454 | if type(self) != type(other): return False |
| 455 | if self.meter_id != other.meter_id: return False |
| 456 | return True |
| 457 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 458 | def pretty_print(self, q): |
| 459 | q.text("meter {") |
| 460 | with q.group(): |
| 461 | with q.indent(2): |
| 462 | q.breakable() |
| 463 | q.text("meter_id = "); |
| 464 | q.text("%#x" % self.meter_id) |
| 465 | q.breakable() |
| 466 | q.text('}') |
| 467 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 468 | instruction.subtypes[6] = meter |
| 469 | |
| 470 | class write_actions(instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 471 | type = 3 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 472 | |
| 473 | def __init__(self, actions=None): |
| 474 | if actions != None: |
| 475 | self.actions = actions |
| 476 | else: |
| 477 | self.actions = [] |
| 478 | return |
| 479 | |
| 480 | def pack(self): |
| 481 | packed = [] |
| 482 | packed.append(struct.pack("!H", self.type)) |
| 483 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 484 | packed.append('\x00' * 4) |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 485 | packed.append(loxi.generic_util.pack_list(self.actions)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 486 | length = sum([len(x) for x in packed]) |
| 487 | packed[1] = struct.pack("!H", length) |
| 488 | return ''.join(packed) |
| 489 | |
| 490 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 491 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 492 | obj = write_actions() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 493 | _type = reader.read("!H")[0] |
| 494 | assert(_type == 3) |
| 495 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 496 | orig_reader = reader |
| 497 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 498 | reader.skip(4) |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 499 | obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 500 | return obj |
| 501 | |
| 502 | def __eq__(self, other): |
| 503 | if type(self) != type(other): return False |
| 504 | if self.actions != other.actions: return False |
| 505 | return True |
| 506 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 507 | def pretty_print(self, q): |
| 508 | q.text("write_actions {") |
| 509 | with q.group(): |
| 510 | with q.indent(2): |
| 511 | q.breakable() |
| 512 | q.text("actions = "); |
| 513 | q.pp(self.actions) |
| 514 | q.breakable() |
| 515 | q.text('}') |
| 516 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 517 | instruction.subtypes[3] = write_actions |
| 518 | |
| 519 | class write_metadata(instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 520 | type = 2 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 521 | |
| 522 | def __init__(self, metadata=None, metadata_mask=None): |
| 523 | if metadata != None: |
| 524 | self.metadata = metadata |
| 525 | else: |
| 526 | self.metadata = 0 |
| 527 | if metadata_mask != None: |
| 528 | self.metadata_mask = metadata_mask |
| 529 | else: |
| 530 | self.metadata_mask = 0 |
| 531 | return |
| 532 | |
| 533 | def pack(self): |
| 534 | packed = [] |
| 535 | packed.append(struct.pack("!H", self.type)) |
| 536 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 537 | packed.append('\x00' * 4) |
| 538 | packed.append(struct.pack("!Q", self.metadata)) |
| 539 | packed.append(struct.pack("!Q", self.metadata_mask)) |
| 540 | length = sum([len(x) for x in packed]) |
| 541 | packed[1] = struct.pack("!H", length) |
| 542 | return ''.join(packed) |
| 543 | |
| 544 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 545 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 546 | obj = write_metadata() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 547 | _type = reader.read("!H")[0] |
| 548 | assert(_type == 2) |
| 549 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 550 | orig_reader = reader |
| 551 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 552 | reader.skip(4) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 553 | obj.metadata = reader.read("!Q")[0] |
| 554 | obj.metadata_mask = reader.read("!Q")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 555 | return obj |
| 556 | |
| 557 | def __eq__(self, other): |
| 558 | if type(self) != type(other): return False |
| 559 | if self.metadata != other.metadata: return False |
| 560 | if self.metadata_mask != other.metadata_mask: return False |
| 561 | return True |
| 562 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 563 | def pretty_print(self, q): |
| 564 | q.text("write_metadata {") |
| 565 | with q.group(): |
| 566 | with q.indent(2): |
| 567 | q.breakable() |
| 568 | q.text("metadata = "); |
| 569 | q.text("%#x" % self.metadata) |
| 570 | q.text(","); q.breakable() |
| 571 | q.text("metadata_mask = "); |
| 572 | q.text("%#x" % self.metadata_mask) |
| 573 | q.breakable() |
| 574 | q.text('}') |
| 575 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 576 | instruction.subtypes[2] = write_metadata |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 577 | |
Rich Lane | 7b0f201 | 2013-11-22 14:15:26 -0800 | [diff] [blame] | 578 | |