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 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 16 | import util |
| 17 | import loxi.generic_util |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 18 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 19 | class instruction(loxi.OFObject): |
| 20 | subtypes = {} |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 21 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 22 | @staticmethod |
| 23 | def unpack(reader): |
| 24 | subtype, = reader.peek('!H', 0) |
| 25 | try: |
| 26 | subclass = instruction.subtypes[subtype] |
| 27 | except KeyError: |
| 28 | raise loxi.ProtocolError("unknown instruction subtype %#x" % subtype) |
| 29 | return subclass.unpack(reader) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 30 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 31 | |
| 32 | class apply_actions(instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 33 | type = 4 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 34 | |
| 35 | def __init__(self, actions=None): |
| 36 | if actions != None: |
| 37 | self.actions = actions |
| 38 | else: |
| 39 | self.actions = [] |
| 40 | return |
| 41 | |
| 42 | def pack(self): |
| 43 | packed = [] |
| 44 | packed.append(struct.pack("!H", self.type)) |
| 45 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 46 | packed.append('\x00' * 4) |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 47 | packed.append(loxi.generic_util.pack_list(self.actions)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 48 | length = sum([len(x) for x in packed]) |
| 49 | packed[1] = struct.pack("!H", length) |
| 50 | return ''.join(packed) |
| 51 | |
| 52 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 53 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 54 | obj = apply_actions() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 55 | _type = reader.read("!H")[0] |
| 56 | assert(_type == 4) |
| 57 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 58 | orig_reader = reader |
| 59 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 60 | reader.skip(4) |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 61 | obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 62 | return obj |
| 63 | |
| 64 | def __eq__(self, other): |
| 65 | if type(self) != type(other): return False |
| 66 | if self.actions != other.actions: return False |
| 67 | return True |
| 68 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 69 | def pretty_print(self, q): |
| 70 | q.text("apply_actions {") |
| 71 | with q.group(): |
| 72 | with q.indent(2): |
| 73 | q.breakable() |
| 74 | q.text("actions = "); |
| 75 | q.pp(self.actions) |
| 76 | q.breakable() |
| 77 | q.text('}') |
| 78 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 79 | instruction.subtypes[4] = apply_actions |
| 80 | |
| 81 | class clear_actions(instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 82 | type = 5 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 83 | |
| 84 | def __init__(self): |
| 85 | return |
| 86 | |
| 87 | def pack(self): |
| 88 | packed = [] |
| 89 | packed.append(struct.pack("!H", self.type)) |
| 90 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 91 | packed.append('\x00' * 4) |
| 92 | length = sum([len(x) for x in packed]) |
| 93 | packed[1] = struct.pack("!H", length) |
| 94 | return ''.join(packed) |
| 95 | |
| 96 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 97 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 98 | obj = clear_actions() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 99 | _type = reader.read("!H")[0] |
| 100 | assert(_type == 5) |
| 101 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 102 | orig_reader = reader |
| 103 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 104 | reader.skip(4) |
| 105 | return obj |
| 106 | |
| 107 | def __eq__(self, other): |
| 108 | if type(self) != type(other): return False |
| 109 | return True |
| 110 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 111 | def pretty_print(self, q): |
| 112 | q.text("clear_actions {") |
| 113 | with q.group(): |
| 114 | with q.indent(2): |
| 115 | q.breakable() |
| 116 | q.breakable() |
| 117 | q.text('}') |
| 118 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 119 | instruction.subtypes[5] = clear_actions |
| 120 | |
| 121 | class experimenter(instruction): |
| 122 | subtypes = {} |
| 123 | |
| 124 | @staticmethod |
| 125 | def unpack(reader): |
| 126 | subtype, = reader.peek('!L', 4) |
| 127 | try: |
| 128 | subclass = experimenter.subtypes[subtype] |
| 129 | except KeyError: |
| 130 | raise loxi.ProtocolError("unknown experimenter instruction subtype %#x" % subtype) |
| 131 | return subclass.unpack(reader) |
| 132 | |
| 133 | instruction.subtypes[65535] = experimenter |
| 134 | |
| 135 | class goto_table(instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 136 | type = 1 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 137 | |
| 138 | def __init__(self, table_id=None): |
| 139 | if table_id != None: |
| 140 | self.table_id = table_id |
| 141 | else: |
| 142 | self.table_id = 0 |
| 143 | return |
| 144 | |
| 145 | def pack(self): |
| 146 | packed = [] |
| 147 | packed.append(struct.pack("!H", self.type)) |
| 148 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 149 | packed.append(struct.pack("!B", self.table_id)) |
| 150 | packed.append('\x00' * 3) |
| 151 | length = sum([len(x) for x in packed]) |
| 152 | packed[1] = struct.pack("!H", length) |
| 153 | return ''.join(packed) |
| 154 | |
| 155 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 156 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 157 | obj = goto_table() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 158 | _type = reader.read("!H")[0] |
| 159 | assert(_type == 1) |
| 160 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 161 | orig_reader = reader |
| 162 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 163 | obj.table_id = reader.read("!B")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 164 | reader.skip(3) |
| 165 | return obj |
| 166 | |
| 167 | def __eq__(self, other): |
| 168 | if type(self) != type(other): return False |
| 169 | if self.table_id != other.table_id: return False |
| 170 | return True |
| 171 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 172 | def pretty_print(self, q): |
| 173 | q.text("goto_table {") |
| 174 | with q.group(): |
| 175 | with q.indent(2): |
| 176 | q.breakable() |
| 177 | q.text("table_id = "); |
| 178 | q.text("%#x" % self.table_id) |
| 179 | q.breakable() |
| 180 | q.text('}') |
| 181 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 182 | instruction.subtypes[1] = goto_table |
| 183 | |
| 184 | class write_actions(instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 185 | type = 3 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 186 | |
| 187 | def __init__(self, actions=None): |
| 188 | if actions != None: |
| 189 | self.actions = actions |
| 190 | else: |
| 191 | self.actions = [] |
| 192 | return |
| 193 | |
| 194 | def pack(self): |
| 195 | packed = [] |
| 196 | packed.append(struct.pack("!H", self.type)) |
| 197 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 198 | packed.append('\x00' * 4) |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 199 | packed.append(loxi.generic_util.pack_list(self.actions)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 200 | length = sum([len(x) for x in packed]) |
| 201 | packed[1] = struct.pack("!H", length) |
| 202 | return ''.join(packed) |
| 203 | |
| 204 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 205 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 206 | obj = write_actions() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 207 | _type = reader.read("!H")[0] |
| 208 | assert(_type == 3) |
| 209 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 210 | orig_reader = reader |
| 211 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 212 | reader.skip(4) |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 213 | obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 214 | return obj |
| 215 | |
| 216 | def __eq__(self, other): |
| 217 | if type(self) != type(other): return False |
| 218 | if self.actions != other.actions: return False |
| 219 | return True |
| 220 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 221 | def pretty_print(self, q): |
| 222 | q.text("write_actions {") |
| 223 | with q.group(): |
| 224 | with q.indent(2): |
| 225 | q.breakable() |
| 226 | q.text("actions = "); |
| 227 | q.pp(self.actions) |
| 228 | q.breakable() |
| 229 | q.text('}') |
| 230 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 231 | instruction.subtypes[3] = write_actions |
| 232 | |
| 233 | class write_metadata(instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 234 | type = 2 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 235 | |
| 236 | def __init__(self, metadata=None, metadata_mask=None): |
| 237 | if metadata != None: |
| 238 | self.metadata = metadata |
| 239 | else: |
| 240 | self.metadata = 0 |
| 241 | if metadata_mask != None: |
| 242 | self.metadata_mask = metadata_mask |
| 243 | else: |
| 244 | self.metadata_mask = 0 |
| 245 | return |
| 246 | |
| 247 | def pack(self): |
| 248 | packed = [] |
| 249 | packed.append(struct.pack("!H", self.type)) |
| 250 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 251 | packed.append('\x00' * 4) |
| 252 | packed.append(struct.pack("!Q", self.metadata)) |
| 253 | packed.append(struct.pack("!Q", self.metadata_mask)) |
| 254 | length = sum([len(x) for x in packed]) |
| 255 | packed[1] = struct.pack("!H", length) |
| 256 | return ''.join(packed) |
| 257 | |
| 258 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 259 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 260 | obj = write_metadata() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 261 | _type = reader.read("!H")[0] |
| 262 | assert(_type == 2) |
| 263 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 264 | orig_reader = reader |
| 265 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 266 | reader.skip(4) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 267 | obj.metadata = reader.read("!Q")[0] |
| 268 | obj.metadata_mask = reader.read("!Q")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 269 | return obj |
| 270 | |
| 271 | def __eq__(self, other): |
| 272 | if type(self) != type(other): return False |
| 273 | if self.metadata != other.metadata: return False |
| 274 | if self.metadata_mask != other.metadata_mask: return False |
| 275 | return True |
| 276 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 277 | def pretty_print(self, q): |
| 278 | q.text("write_metadata {") |
| 279 | with q.group(): |
| 280 | with q.indent(2): |
| 281 | q.breakable() |
| 282 | q.text("metadata = "); |
| 283 | q.text("%#x" % self.metadata) |
| 284 | q.text(","); q.breakable() |
| 285 | q.text("metadata_mask = "); |
| 286 | q.text("%#x" % self.metadata_mask) |
| 287 | q.breakable() |
| 288 | q.text('}') |
| 289 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 290 | instruction.subtypes[2] = write_metadata |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 291 | |
Rich Lane | 7b0f201 | 2013-11-22 14:15:26 -0800 | [diff] [blame] | 292 | |