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