Rich Lane | 1a82041 | 2014-01-06 14:15:07 -0800 | [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. |
| 4 | # See the file LICENSE.pyloxi which should have been included in the source distribution |
| 5 | |
| 6 | # Automatically generated by LOXI from template module.py |
| 7 | # Do not modify |
| 8 | |
| 9 | import struct |
| 10 | import loxi |
| 11 | import const |
| 12 | import common |
| 13 | import action |
| 14 | import instruction |
| 15 | import oxm |
| 16 | import action_id |
| 17 | import instruction_id |
| 18 | import meter_band |
| 19 | import bsn_tlv |
| 20 | import util |
| 21 | import loxi.generic_util |
| 22 | |
| 23 | class bsn_tlv(loxi.OFObject): |
| 24 | subtypes = {} |
| 25 | |
| 26 | @staticmethod |
| 27 | def unpack(reader): |
| 28 | subtype, = reader.peek('!H', 0) |
| 29 | try: |
| 30 | subclass = bsn_tlv.subtypes[subtype] |
| 31 | except KeyError: |
| 32 | raise loxi.ProtocolError("unknown bsn_tlv subtype %#x" % subtype) |
| 33 | return subclass.unpack(reader) |
| 34 | |
| 35 | |
| 36 | class idle_notification(bsn_tlv): |
| 37 | type = 7 |
| 38 | |
| 39 | def __init__(self): |
| 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 length at index 1 |
| 46 | length = sum([len(x) for x in packed]) |
| 47 | packed[1] = struct.pack("!H", length) |
| 48 | return ''.join(packed) |
| 49 | |
| 50 | @staticmethod |
| 51 | def unpack(reader): |
| 52 | obj = idle_notification() |
| 53 | _type = reader.read("!H")[0] |
| 54 | assert(_type == 7) |
| 55 | _length = reader.read("!H")[0] |
| 56 | orig_reader = reader |
| 57 | reader = orig_reader.slice(_length - (2 + 2)) |
| 58 | return obj |
| 59 | |
| 60 | def __eq__(self, other): |
| 61 | if type(self) != type(other): return False |
| 62 | return True |
| 63 | |
| 64 | def pretty_print(self, q): |
| 65 | q.text("idle_notification {") |
| 66 | with q.group(): |
| 67 | with q.indent(2): |
| 68 | q.breakable() |
| 69 | q.breakable() |
| 70 | q.text('}') |
| 71 | |
| 72 | bsn_tlv.subtypes[7] = idle_notification |
| 73 | |
| 74 | class idle_time(bsn_tlv): |
| 75 | type = 5 |
| 76 | |
| 77 | def __init__(self, value=None): |
| 78 | if value != None: |
| 79 | self.value = value |
| 80 | else: |
| 81 | self.value = 0 |
| 82 | return |
| 83 | |
| 84 | def pack(self): |
| 85 | packed = [] |
| 86 | packed.append(struct.pack("!H", self.type)) |
| 87 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 1 |
| 88 | packed.append(struct.pack("!Q", self.value)) |
| 89 | length = sum([len(x) for x in packed]) |
| 90 | packed[1] = struct.pack("!H", length) |
| 91 | return ''.join(packed) |
| 92 | |
| 93 | @staticmethod |
| 94 | def unpack(reader): |
| 95 | obj = idle_time() |
| 96 | _type = reader.read("!H")[0] |
| 97 | assert(_type == 5) |
| 98 | _length = reader.read("!H")[0] |
| 99 | orig_reader = reader |
| 100 | reader = orig_reader.slice(_length - (2 + 2)) |
| 101 | obj.value = reader.read("!Q")[0] |
| 102 | return obj |
| 103 | |
| 104 | def __eq__(self, other): |
| 105 | if type(self) != type(other): return False |
| 106 | if self.value != other.value: return False |
| 107 | return True |
| 108 | |
| 109 | def pretty_print(self, q): |
| 110 | q.text("idle_time {") |
| 111 | with q.group(): |
| 112 | with q.indent(2): |
| 113 | q.breakable() |
| 114 | q.text("value = "); |
| 115 | q.text("%#x" % self.value) |
| 116 | q.breakable() |
| 117 | q.text('}') |
| 118 | |
| 119 | bsn_tlv.subtypes[5] = idle_time |
| 120 | |
| 121 | class ipv4(bsn_tlv): |
| 122 | type = 4 |
| 123 | |
| 124 | def __init__(self, value=None): |
| 125 | if value != None: |
| 126 | self.value = value |
| 127 | else: |
| 128 | self.value = 0 |
| 129 | return |
| 130 | |
| 131 | def pack(self): |
| 132 | packed = [] |
| 133 | packed.append(struct.pack("!H", self.type)) |
| 134 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 1 |
| 135 | packed.append(struct.pack("!L", self.value)) |
| 136 | length = sum([len(x) for x in packed]) |
| 137 | packed[1] = struct.pack("!H", length) |
| 138 | return ''.join(packed) |
| 139 | |
| 140 | @staticmethod |
| 141 | def unpack(reader): |
| 142 | obj = ipv4() |
| 143 | _type = reader.read("!H")[0] |
| 144 | assert(_type == 4) |
| 145 | _length = reader.read("!H")[0] |
| 146 | orig_reader = reader |
| 147 | reader = orig_reader.slice(_length - (2 + 2)) |
| 148 | obj.value = reader.read("!L")[0] |
| 149 | return obj |
| 150 | |
| 151 | def __eq__(self, other): |
| 152 | if type(self) != type(other): return False |
| 153 | if self.value != other.value: return False |
| 154 | return True |
| 155 | |
| 156 | def pretty_print(self, q): |
| 157 | q.text("ipv4 {") |
| 158 | with q.group(): |
| 159 | with q.indent(2): |
| 160 | q.breakable() |
| 161 | q.text("value = "); |
| 162 | q.text(util.pretty_ipv4(self.value)) |
| 163 | q.breakable() |
| 164 | q.text('}') |
| 165 | |
| 166 | bsn_tlv.subtypes[4] = ipv4 |
| 167 | |
| 168 | class mac(bsn_tlv): |
| 169 | type = 1 |
| 170 | |
| 171 | def __init__(self, value=None): |
| 172 | if value != None: |
| 173 | self.value = value |
| 174 | else: |
| 175 | self.value = [0,0,0,0,0,0] |
| 176 | return |
| 177 | |
| 178 | def pack(self): |
| 179 | packed = [] |
| 180 | packed.append(struct.pack("!H", self.type)) |
| 181 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 1 |
| 182 | packed.append(struct.pack("!6B", *self.value)) |
| 183 | length = sum([len(x) for x in packed]) |
| 184 | packed[1] = struct.pack("!H", length) |
| 185 | return ''.join(packed) |
| 186 | |
| 187 | @staticmethod |
| 188 | def unpack(reader): |
| 189 | obj = mac() |
| 190 | _type = reader.read("!H")[0] |
| 191 | assert(_type == 1) |
| 192 | _length = reader.read("!H")[0] |
| 193 | orig_reader = reader |
| 194 | reader = orig_reader.slice(_length - (2 + 2)) |
| 195 | obj.value = list(reader.read('!6B')) |
| 196 | return obj |
| 197 | |
| 198 | def __eq__(self, other): |
| 199 | if type(self) != type(other): return False |
| 200 | if self.value != other.value: return False |
| 201 | return True |
| 202 | |
| 203 | def pretty_print(self, q): |
| 204 | q.text("mac {") |
| 205 | with q.group(): |
| 206 | with q.indent(2): |
| 207 | q.breakable() |
| 208 | q.text("value = "); |
| 209 | q.text(util.pretty_mac(self.value)) |
| 210 | q.breakable() |
| 211 | q.text('}') |
| 212 | |
| 213 | bsn_tlv.subtypes[1] = mac |
| 214 | |
| 215 | class port(bsn_tlv): |
| 216 | type = 0 |
| 217 | |
| 218 | def __init__(self, value=None): |
| 219 | if value != None: |
| 220 | self.value = value |
| 221 | else: |
| 222 | self.value = 0 |
| 223 | return |
| 224 | |
| 225 | def pack(self): |
| 226 | packed = [] |
| 227 | packed.append(struct.pack("!H", self.type)) |
| 228 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 1 |
| 229 | packed.append(util.pack_port_no(self.value)) |
| 230 | length = sum([len(x) for x in packed]) |
| 231 | packed[1] = struct.pack("!H", length) |
| 232 | return ''.join(packed) |
| 233 | |
| 234 | @staticmethod |
| 235 | def unpack(reader): |
| 236 | obj = port() |
| 237 | _type = reader.read("!H")[0] |
| 238 | assert(_type == 0) |
| 239 | _length = reader.read("!H")[0] |
| 240 | orig_reader = reader |
| 241 | reader = orig_reader.slice(_length - (2 + 2)) |
| 242 | obj.value = util.unpack_port_no(reader) |
| 243 | return obj |
| 244 | |
| 245 | def __eq__(self, other): |
| 246 | if type(self) != type(other): return False |
| 247 | if self.value != other.value: return False |
| 248 | return True |
| 249 | |
| 250 | def pretty_print(self, q): |
| 251 | q.text("port {") |
| 252 | with q.group(): |
| 253 | with q.indent(2): |
| 254 | q.breakable() |
| 255 | q.text("value = "); |
| 256 | q.text(util.pretty_port(self.value)) |
| 257 | q.breakable() |
| 258 | q.text('}') |
| 259 | |
| 260 | bsn_tlv.subtypes[0] = port |
| 261 | |
| 262 | class rx_packets(bsn_tlv): |
| 263 | type = 2 |
| 264 | |
| 265 | def __init__(self, value=None): |
| 266 | if value != None: |
| 267 | self.value = value |
| 268 | else: |
| 269 | self.value = 0 |
| 270 | return |
| 271 | |
| 272 | def pack(self): |
| 273 | packed = [] |
| 274 | packed.append(struct.pack("!H", self.type)) |
| 275 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 1 |
| 276 | packed.append(struct.pack("!Q", self.value)) |
| 277 | length = sum([len(x) for x in packed]) |
| 278 | packed[1] = struct.pack("!H", length) |
| 279 | return ''.join(packed) |
| 280 | |
| 281 | @staticmethod |
| 282 | def unpack(reader): |
| 283 | obj = rx_packets() |
| 284 | _type = reader.read("!H")[0] |
| 285 | assert(_type == 2) |
| 286 | _length = reader.read("!H")[0] |
| 287 | orig_reader = reader |
| 288 | reader = orig_reader.slice(_length - (2 + 2)) |
| 289 | obj.value = reader.read("!Q")[0] |
| 290 | return obj |
| 291 | |
| 292 | def __eq__(self, other): |
| 293 | if type(self) != type(other): return False |
| 294 | if self.value != other.value: return False |
| 295 | return True |
| 296 | |
| 297 | def pretty_print(self, q): |
| 298 | q.text("rx_packets {") |
| 299 | with q.group(): |
| 300 | with q.indent(2): |
| 301 | q.breakable() |
| 302 | q.text("value = "); |
| 303 | q.text("%#x" % self.value) |
| 304 | q.breakable() |
| 305 | q.text('}') |
| 306 | |
| 307 | bsn_tlv.subtypes[2] = rx_packets |
| 308 | |
| 309 | class tx_packets(bsn_tlv): |
| 310 | type = 3 |
| 311 | |
| 312 | def __init__(self, value=None): |
| 313 | if value != None: |
| 314 | self.value = value |
| 315 | else: |
| 316 | self.value = 0 |
| 317 | return |
| 318 | |
| 319 | def pack(self): |
| 320 | packed = [] |
| 321 | packed.append(struct.pack("!H", self.type)) |
| 322 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 1 |
| 323 | packed.append(struct.pack("!Q", self.value)) |
| 324 | length = sum([len(x) for x in packed]) |
| 325 | packed[1] = struct.pack("!H", length) |
| 326 | return ''.join(packed) |
| 327 | |
| 328 | @staticmethod |
| 329 | def unpack(reader): |
| 330 | obj = tx_packets() |
| 331 | _type = reader.read("!H")[0] |
| 332 | assert(_type == 3) |
| 333 | _length = reader.read("!H")[0] |
| 334 | orig_reader = reader |
| 335 | reader = orig_reader.slice(_length - (2 + 2)) |
| 336 | obj.value = reader.read("!Q")[0] |
| 337 | return obj |
| 338 | |
| 339 | def __eq__(self, other): |
| 340 | if type(self) != type(other): return False |
| 341 | if self.value != other.value: return False |
| 342 | return True |
| 343 | |
| 344 | def pretty_print(self, q): |
| 345 | q.text("tx_packets {") |
| 346 | with q.group(): |
| 347 | with q.indent(2): |
| 348 | q.breakable() |
| 349 | q.text("value = "); |
| 350 | q.text("%#x" % self.value) |
| 351 | q.breakable() |
| 352 | q.text('}') |
| 353 | |
| 354 | bsn_tlv.subtypes[3] = tx_packets |
| 355 | |
| 356 | class vlan_vid(bsn_tlv): |
| 357 | type = 6 |
| 358 | |
| 359 | def __init__(self, value=None): |
| 360 | if value != None: |
| 361 | self.value = value |
| 362 | else: |
| 363 | self.value = 0 |
| 364 | return |
| 365 | |
| 366 | def pack(self): |
| 367 | packed = [] |
| 368 | packed.append(struct.pack("!H", self.type)) |
| 369 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 1 |
| 370 | packed.append(struct.pack("!H", self.value)) |
| 371 | length = sum([len(x) for x in packed]) |
| 372 | packed[1] = struct.pack("!H", length) |
| 373 | return ''.join(packed) |
| 374 | |
| 375 | @staticmethod |
| 376 | def unpack(reader): |
| 377 | obj = vlan_vid() |
| 378 | _type = reader.read("!H")[0] |
| 379 | assert(_type == 6) |
| 380 | _length = reader.read("!H")[0] |
| 381 | orig_reader = reader |
| 382 | reader = orig_reader.slice(_length - (2 + 2)) |
| 383 | obj.value = reader.read("!H")[0] |
| 384 | return obj |
| 385 | |
| 386 | def __eq__(self, other): |
| 387 | if type(self) != type(other): return False |
| 388 | if self.value != other.value: return False |
| 389 | return True |
| 390 | |
| 391 | def pretty_print(self, q): |
| 392 | q.text("vlan_vid {") |
| 393 | with q.group(): |
| 394 | with q.indent(2): |
| 395 | q.breakable() |
| 396 | q.text("value = "); |
| 397 | q.text("%#x" % self.value) |
| 398 | q.breakable() |
| 399 | q.text('}') |
| 400 | |
| 401 | bsn_tlv.subtypes[6] = vlan_vid |
| 402 | |
| 403 | |