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