Rich Lane | c2ee4b8 | 2013-04-24 17:12:38 -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. |
| 4 | |
| 5 | # Automatically generated by LOXI from template common.py |
| 6 | # Do not modify |
| 7 | |
| 8 | import sys |
| 9 | import struct |
| 10 | import action |
| 11 | import instruction # for unpack_list |
| 12 | import const |
| 13 | import util |
| 14 | import loxi.generic_util |
| 15 | |
| 16 | |
| 17 | # HACK make this module visible as 'common' to simplify code generation |
| 18 | common = sys.modules[__name__] |
| 19 | |
| 20 | def unpack_list_flow_stats_entry(reader): |
| 21 | return loxi.generic_util.unpack_list_lv16(reader, flow_stats_entry.unpack) |
| 22 | |
| 23 | def unpack_list_queue_prop(reader): |
| 24 | def deserializer(reader, typ): |
| 25 | if typ == const.OFPQT_MIN_RATE: |
| 26 | return queue_prop_min_rate.unpack(reader) |
| 27 | else: |
| 28 | raise loxi.ProtocolError("unknown queue prop %d" % typ) |
| 29 | return loxi.generic_util.unpack_list_tlv16(reader, deserializer) |
| 30 | |
| 31 | def unpack_list_packet_queue(reader): |
| 32 | def wrapper(reader): |
| 33 | length, = reader.peek('!4xH') |
| 34 | return packet_queue.unpack(reader.slice(length)) |
| 35 | return loxi.generic_util.unpack_list(reader, wrapper) |
| 36 | |
| 37 | def unpack_list_hello_elem(reader): |
| 38 | def deserializer(reader, typ): |
| 39 | if typ == const.OFPHET_VERSIONBITMAP: |
| 40 | return hello_elem_versionbitmap.unpack(reader) |
| 41 | else: |
| 42 | return None |
| 43 | return [x for x in loxi.generic_util.unpack_list_tlv16(reader, deserializer) if x != None] |
| 44 | |
| 45 | def unpack_list_bucket(reader): |
| 46 | return loxi.generic_util.unpack_list_lv16(reader, bucket.unpack) |
| 47 | |
| 48 | def unpack_list_group_desc_stats_entry(reader): |
| 49 | return loxi.generic_util.unpack_list_lv16(reader, group_desc_stats_entry.unpack) |
| 50 | |
| 51 | def unpack_list_group_stats_entry(reader): |
| 52 | return loxi.generic_util.unpack_list_lv16(reader, group_stats_entry.unpack) |
| 53 | |
| 54 | def unpack_list_meter_stats(reader): |
| 55 | def wrapper(reader): |
| 56 | length, = reader.peek('!4xH') |
| 57 | return meter_stats.unpack(reader.slice(length)) |
| 58 | return loxi.generic_util.unpack_list(reader, wrapper) |
| 59 | |
| 60 | class bsn_interface(object): |
| 61 | |
| 62 | def __init__(self, hw_addr=None, name=None, ipv4_addr=None, ipv4_netmask=None): |
| 63 | if hw_addr != None: |
| 64 | self.hw_addr = hw_addr |
| 65 | else: |
| 66 | self.hw_addr = [0,0,0,0,0,0] |
| 67 | if name != None: |
| 68 | self.name = name |
| 69 | else: |
| 70 | self.name = "" |
| 71 | if ipv4_addr != None: |
| 72 | self.ipv4_addr = ipv4_addr |
| 73 | else: |
| 74 | self.ipv4_addr = 0 |
| 75 | if ipv4_netmask != None: |
| 76 | self.ipv4_netmask = ipv4_netmask |
| 77 | else: |
| 78 | self.ipv4_netmask = 0 |
| 79 | return |
| 80 | |
| 81 | def pack(self): |
| 82 | packed = [] |
| 83 | packed.append(struct.pack("!6B", *self.hw_addr)) |
| 84 | packed.append('\x00' * 2) |
| 85 | packed.append(struct.pack("!16s", self.name)) |
| 86 | packed.append(struct.pack("!L", self.ipv4_addr)) |
| 87 | packed.append(struct.pack("!L", self.ipv4_netmask)) |
| 88 | return ''.join(packed) |
| 89 | |
| 90 | @staticmethod |
| 91 | def unpack(buf): |
| 92 | obj = bsn_interface() |
| 93 | if type(buf) == loxi.generic_util.OFReader: |
| 94 | reader = buf |
| 95 | else: |
| 96 | reader = loxi.generic_util.OFReader(buf) |
| 97 | obj.hw_addr = list(reader.read('!6B')) |
| 98 | reader.skip(2) |
| 99 | obj.name = reader.read("!16s")[0].rstrip("\x00") |
| 100 | obj.ipv4_addr = reader.read('!L')[0] |
| 101 | obj.ipv4_netmask = reader.read('!L')[0] |
| 102 | return obj |
| 103 | |
| 104 | def __eq__(self, other): |
| 105 | if type(self) != type(other): return False |
| 106 | if self.hw_addr != other.hw_addr: return False |
| 107 | if self.name != other.name: return False |
| 108 | if self.ipv4_addr != other.ipv4_addr: return False |
| 109 | if self.ipv4_netmask != other.ipv4_netmask: return False |
| 110 | return True |
| 111 | |
| 112 | def __ne__(self, other): |
| 113 | return not self.__eq__(other) |
| 114 | |
| 115 | def show(self): |
| 116 | import loxi.pp |
| 117 | return loxi.pp.pp(self) |
| 118 | |
| 119 | def pretty_print(self, q): |
| 120 | q.text("bsn_interface {") |
| 121 | with q.group(): |
| 122 | with q.indent(2): |
| 123 | q.breakable() |
| 124 | q.text("hw_addr = "); |
| 125 | q.text(util.pretty_mac(self.hw_addr)) |
| 126 | q.text(","); q.breakable() |
| 127 | q.text("name = "); |
| 128 | q.pp(self.name) |
| 129 | q.text(","); q.breakable() |
| 130 | q.text("ipv4_addr = "); |
| 131 | q.text(util.pretty_ipv4(self.ipv4_addr)) |
| 132 | q.text(","); q.breakable() |
| 133 | q.text("ipv4_netmask = "); |
| 134 | q.text(util.pretty_ipv4(self.ipv4_netmask)) |
| 135 | q.breakable() |
| 136 | q.text('}') |
| 137 | |
| 138 | class bucket(object): |
| 139 | |
| 140 | def __init__(self, weight=None, watch_port=None, watch_group=None, actions=None): |
| 141 | if weight != None: |
| 142 | self.weight = weight |
| 143 | else: |
| 144 | self.weight = 0 |
| 145 | if watch_port != None: |
| 146 | self.watch_port = watch_port |
| 147 | else: |
| 148 | self.watch_port = 0 |
| 149 | if watch_group != None: |
| 150 | self.watch_group = watch_group |
| 151 | else: |
| 152 | self.watch_group = 0 |
| 153 | if actions != None: |
| 154 | self.actions = actions |
| 155 | else: |
| 156 | self.actions = [] |
| 157 | return |
| 158 | |
| 159 | def pack(self): |
| 160 | packed = [] |
| 161 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 0 |
| 162 | packed.append(struct.pack("!H", self.weight)) |
| 163 | packed.append(struct.pack("!L", self.watch_port)) |
| 164 | packed.append(struct.pack("!L", self.watch_group)) |
| 165 | packed.append('\x00' * 4) |
| 166 | packed.append("".join([x.pack() for x in self.actions])) |
| 167 | length = sum([len(x) for x in packed]) |
| 168 | packed[0] = struct.pack("!H", length) |
| 169 | return ''.join(packed) |
| 170 | |
| 171 | @staticmethod |
| 172 | def unpack(buf): |
| 173 | obj = bucket() |
| 174 | if type(buf) == loxi.generic_util.OFReader: |
| 175 | reader = buf |
| 176 | else: |
| 177 | reader = loxi.generic_util.OFReader(buf) |
| 178 | _len = reader.read('!H')[0] |
| 179 | obj.weight = reader.read('!H')[0] |
| 180 | obj.watch_port = reader.read('!L')[0] |
| 181 | obj.watch_group = reader.read('!L')[0] |
| 182 | reader.skip(4) |
| 183 | obj.actions = action.unpack_list(reader) |
| 184 | return obj |
| 185 | |
| 186 | def __eq__(self, other): |
| 187 | if type(self) != type(other): return False |
| 188 | if self.weight != other.weight: return False |
| 189 | if self.watch_port != other.watch_port: return False |
| 190 | if self.watch_group != other.watch_group: return False |
| 191 | if self.actions != other.actions: return False |
| 192 | return True |
| 193 | |
| 194 | def __ne__(self, other): |
| 195 | return not self.__eq__(other) |
| 196 | |
| 197 | def show(self): |
| 198 | import loxi.pp |
| 199 | return loxi.pp.pp(self) |
| 200 | |
| 201 | def pretty_print(self, q): |
| 202 | q.text("bucket {") |
| 203 | with q.group(): |
| 204 | with q.indent(2): |
| 205 | q.breakable() |
| 206 | q.text("weight = "); |
| 207 | q.text("%#x" % self.weight) |
| 208 | q.text(","); q.breakable() |
| 209 | q.text("watch_port = "); |
| 210 | q.text(util.pretty_port(self.watch_port)) |
| 211 | q.text(","); q.breakable() |
| 212 | q.text("watch_group = "); |
| 213 | q.text("%#x" % self.watch_group) |
| 214 | q.text(","); q.breakable() |
| 215 | q.text("actions = "); |
| 216 | q.pp(self.actions) |
| 217 | q.breakable() |
| 218 | q.text('}') |
| 219 | |
| 220 | class bucket_counter(object): |
| 221 | |
| 222 | def __init__(self, packet_count=None, byte_count=None): |
| 223 | if packet_count != None: |
| 224 | self.packet_count = packet_count |
| 225 | else: |
| 226 | self.packet_count = 0 |
| 227 | if byte_count != None: |
| 228 | self.byte_count = byte_count |
| 229 | else: |
| 230 | self.byte_count = 0 |
| 231 | return |
| 232 | |
| 233 | def pack(self): |
| 234 | packed = [] |
| 235 | packed.append(struct.pack("!Q", self.packet_count)) |
| 236 | packed.append(struct.pack("!Q", self.byte_count)) |
| 237 | return ''.join(packed) |
| 238 | |
| 239 | @staticmethod |
| 240 | def unpack(buf): |
| 241 | obj = bucket_counter() |
| 242 | if type(buf) == loxi.generic_util.OFReader: |
| 243 | reader = buf |
| 244 | else: |
| 245 | reader = loxi.generic_util.OFReader(buf) |
| 246 | obj.packet_count = reader.read('!Q')[0] |
| 247 | obj.byte_count = reader.read('!Q')[0] |
| 248 | return obj |
| 249 | |
| 250 | def __eq__(self, other): |
| 251 | if type(self) != type(other): return False |
| 252 | if self.packet_count != other.packet_count: return False |
| 253 | if self.byte_count != other.byte_count: return False |
| 254 | return True |
| 255 | |
| 256 | def __ne__(self, other): |
| 257 | return not self.__eq__(other) |
| 258 | |
| 259 | def show(self): |
| 260 | import loxi.pp |
| 261 | return loxi.pp.pp(self) |
| 262 | |
| 263 | def pretty_print(self, q): |
| 264 | q.text("bucket_counter {") |
| 265 | with q.group(): |
| 266 | with q.indent(2): |
| 267 | q.breakable() |
| 268 | q.text("packet_count = "); |
| 269 | q.text("%#x" % self.packet_count) |
| 270 | q.text(","); q.breakable() |
| 271 | q.text("byte_count = "); |
| 272 | q.text("%#x" % self.byte_count) |
| 273 | q.breakable() |
| 274 | q.text('}') |
| 275 | |
| 276 | class flow_stats_entry(object): |
| 277 | |
| 278 | def __init__(self, table_id=None, duration_sec=None, duration_nsec=None, priority=None, idle_timeout=None, hard_timeout=None, cookie=None, packet_count=None, byte_count=None, match=None, instructions=None): |
| 279 | if table_id != None: |
| 280 | self.table_id = table_id |
| 281 | else: |
| 282 | self.table_id = 0 |
| 283 | if duration_sec != None: |
| 284 | self.duration_sec = duration_sec |
| 285 | else: |
| 286 | self.duration_sec = 0 |
| 287 | if duration_nsec != None: |
| 288 | self.duration_nsec = duration_nsec |
| 289 | else: |
| 290 | self.duration_nsec = 0 |
| 291 | if priority != None: |
| 292 | self.priority = priority |
| 293 | else: |
| 294 | self.priority = 0 |
| 295 | if idle_timeout != None: |
| 296 | self.idle_timeout = idle_timeout |
| 297 | else: |
| 298 | self.idle_timeout = 0 |
| 299 | if hard_timeout != None: |
| 300 | self.hard_timeout = hard_timeout |
| 301 | else: |
| 302 | self.hard_timeout = 0 |
| 303 | if cookie != None: |
| 304 | self.cookie = cookie |
| 305 | else: |
| 306 | self.cookie = 0 |
| 307 | if packet_count != None: |
| 308 | self.packet_count = packet_count |
| 309 | else: |
| 310 | self.packet_count = 0 |
| 311 | if byte_count != None: |
| 312 | self.byte_count = byte_count |
| 313 | else: |
| 314 | self.byte_count = 0 |
| 315 | if match != None: |
| 316 | self.match = match |
| 317 | else: |
| 318 | self.match = common.match() |
| 319 | if instructions != None: |
| 320 | self.instructions = instructions |
| 321 | else: |
| 322 | self.instructions = [] |
| 323 | return |
| 324 | |
| 325 | def pack(self): |
| 326 | packed = [] |
| 327 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 0 |
| 328 | packed.append(struct.pack("!B", self.table_id)) |
| 329 | packed.append('\x00' * 1) |
| 330 | packed.append(struct.pack("!L", self.duration_sec)) |
| 331 | packed.append(struct.pack("!L", self.duration_nsec)) |
| 332 | packed.append(struct.pack("!H", self.priority)) |
| 333 | packed.append(struct.pack("!H", self.idle_timeout)) |
| 334 | packed.append(struct.pack("!H", self.hard_timeout)) |
| 335 | packed.append('\x00' * 6) |
| 336 | packed.append(struct.pack("!Q", self.cookie)) |
| 337 | packed.append(struct.pack("!Q", self.packet_count)) |
| 338 | packed.append(struct.pack("!Q", self.byte_count)) |
| 339 | packed.append(self.match.pack()) |
| 340 | packed.append("".join([x.pack() for x in self.instructions])) |
| 341 | length = sum([len(x) for x in packed]) |
| 342 | packed[0] = struct.pack("!H", length) |
| 343 | return ''.join(packed) |
| 344 | |
| 345 | @staticmethod |
| 346 | def unpack(buf): |
| 347 | obj = flow_stats_entry() |
| 348 | if type(buf) == loxi.generic_util.OFReader: |
| 349 | reader = buf |
| 350 | else: |
| 351 | reader = loxi.generic_util.OFReader(buf) |
| 352 | _length = reader.read('!H')[0] |
| 353 | obj.table_id = reader.read('!B')[0] |
| 354 | reader.skip(1) |
| 355 | obj.duration_sec = reader.read('!L')[0] |
| 356 | obj.duration_nsec = reader.read('!L')[0] |
| 357 | obj.priority = reader.read('!H')[0] |
| 358 | obj.idle_timeout = reader.read('!H')[0] |
| 359 | obj.hard_timeout = reader.read('!H')[0] |
| 360 | reader.skip(6) |
| 361 | obj.cookie = reader.read('!Q')[0] |
| 362 | obj.packet_count = reader.read('!Q')[0] |
| 363 | obj.byte_count = reader.read('!Q')[0] |
| 364 | obj.match = common.match.unpack(reader) |
| 365 | obj.instructions = instruction.unpack_list(reader) |
| 366 | return obj |
| 367 | |
| 368 | def __eq__(self, other): |
| 369 | if type(self) != type(other): return False |
| 370 | if self.table_id != other.table_id: return False |
| 371 | if self.duration_sec != other.duration_sec: return False |
| 372 | if self.duration_nsec != other.duration_nsec: return False |
| 373 | if self.priority != other.priority: return False |
| 374 | if self.idle_timeout != other.idle_timeout: return False |
| 375 | if self.hard_timeout != other.hard_timeout: return False |
| 376 | if self.cookie != other.cookie: return False |
| 377 | if self.packet_count != other.packet_count: return False |
| 378 | if self.byte_count != other.byte_count: return False |
| 379 | if self.match != other.match: return False |
| 380 | if self.instructions != other.instructions: return False |
| 381 | return True |
| 382 | |
| 383 | def __ne__(self, other): |
| 384 | return not self.__eq__(other) |
| 385 | |
| 386 | def show(self): |
| 387 | import loxi.pp |
| 388 | return loxi.pp.pp(self) |
| 389 | |
| 390 | def pretty_print(self, q): |
| 391 | q.text("flow_stats_entry {") |
| 392 | with q.group(): |
| 393 | with q.indent(2): |
| 394 | q.breakable() |
| 395 | q.text("table_id = "); |
| 396 | q.text("%#x" % self.table_id) |
| 397 | q.text(","); q.breakable() |
| 398 | q.text("duration_sec = "); |
| 399 | q.text("%#x" % self.duration_sec) |
| 400 | q.text(","); q.breakable() |
| 401 | q.text("duration_nsec = "); |
| 402 | q.text("%#x" % self.duration_nsec) |
| 403 | q.text(","); q.breakable() |
| 404 | q.text("priority = "); |
| 405 | q.text("%#x" % self.priority) |
| 406 | q.text(","); q.breakable() |
| 407 | q.text("idle_timeout = "); |
| 408 | q.text("%#x" % self.idle_timeout) |
| 409 | q.text(","); q.breakable() |
| 410 | q.text("hard_timeout = "); |
| 411 | q.text("%#x" % self.hard_timeout) |
| 412 | q.text(","); q.breakable() |
| 413 | q.text("cookie = "); |
| 414 | q.text("%#x" % self.cookie) |
| 415 | q.text(","); q.breakable() |
| 416 | q.text("packet_count = "); |
| 417 | q.text("%#x" % self.packet_count) |
| 418 | q.text(","); q.breakable() |
| 419 | q.text("byte_count = "); |
| 420 | q.text("%#x" % self.byte_count) |
| 421 | q.text(","); q.breakable() |
| 422 | q.text("match = "); |
| 423 | q.pp(self.match) |
| 424 | q.text(","); q.breakable() |
| 425 | q.text("instructions = "); |
| 426 | q.pp(self.instructions) |
| 427 | q.breakable() |
| 428 | q.text('}') |
| 429 | |
| 430 | class group_desc_stats_entry(object): |
| 431 | |
| 432 | def __init__(self, type=None, group_id=None, buckets=None): |
| 433 | if type != None: |
| 434 | self.type = type |
| 435 | else: |
| 436 | self.type = 0 |
| 437 | if group_id != None: |
| 438 | self.group_id = group_id |
| 439 | else: |
| 440 | self.group_id = 0 |
| 441 | if buckets != None: |
| 442 | self.buckets = buckets |
| 443 | else: |
| 444 | self.buckets = [] |
| 445 | return |
| 446 | |
| 447 | def pack(self): |
| 448 | packed = [] |
| 449 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 0 |
| 450 | packed.append(struct.pack("!B", self.type)) |
| 451 | packed.append('\x00' * 1) |
| 452 | packed.append(struct.pack("!L", self.group_id)) |
| 453 | packed.append("".join([x.pack() for x in self.buckets])) |
| 454 | length = sum([len(x) for x in packed]) |
| 455 | packed[0] = struct.pack("!H", length) |
| 456 | return ''.join(packed) |
| 457 | |
| 458 | @staticmethod |
| 459 | def unpack(buf): |
| 460 | obj = group_desc_stats_entry() |
| 461 | if type(buf) == loxi.generic_util.OFReader: |
| 462 | reader = buf |
| 463 | else: |
| 464 | reader = loxi.generic_util.OFReader(buf) |
| 465 | _length = reader.read('!H')[0] |
| 466 | obj.type = reader.read('!B')[0] |
| 467 | reader.skip(1) |
| 468 | obj.group_id = reader.read('!L')[0] |
| 469 | obj.buckets = common.unpack_list_bucket(reader) |
| 470 | return obj |
| 471 | |
| 472 | def __eq__(self, other): |
| 473 | if type(self) != type(other): return False |
| 474 | if self.type != other.type: return False |
| 475 | if self.group_id != other.group_id: return False |
| 476 | if self.buckets != other.buckets: return False |
| 477 | return True |
| 478 | |
| 479 | def __ne__(self, other): |
| 480 | return not self.__eq__(other) |
| 481 | |
| 482 | def show(self): |
| 483 | import loxi.pp |
| 484 | return loxi.pp.pp(self) |
| 485 | |
| 486 | def pretty_print(self, q): |
| 487 | q.text("group_desc_stats_entry {") |
| 488 | with q.group(): |
| 489 | with q.indent(2): |
| 490 | q.breakable() |
| 491 | q.text("type = "); |
| 492 | q.text("%#x" % self.type) |
| 493 | q.text(","); q.breakable() |
| 494 | q.text("group_id = "); |
| 495 | q.text("%#x" % self.group_id) |
| 496 | q.text(","); q.breakable() |
| 497 | q.text("buckets = "); |
| 498 | q.pp(self.buckets) |
| 499 | q.breakable() |
| 500 | q.text('}') |
| 501 | |
| 502 | class group_stats_entry(object): |
| 503 | |
| 504 | def __init__(self, group_id=None, ref_count=None, packet_count=None, byte_count=None, bucket_stats=None): |
| 505 | if group_id != None: |
| 506 | self.group_id = group_id |
| 507 | else: |
| 508 | self.group_id = 0 |
| 509 | if ref_count != None: |
| 510 | self.ref_count = ref_count |
| 511 | else: |
| 512 | self.ref_count = 0 |
| 513 | if packet_count != None: |
| 514 | self.packet_count = packet_count |
| 515 | else: |
| 516 | self.packet_count = 0 |
| 517 | if byte_count != None: |
| 518 | self.byte_count = byte_count |
| 519 | else: |
| 520 | self.byte_count = 0 |
| 521 | if bucket_stats != None: |
| 522 | self.bucket_stats = bucket_stats |
| 523 | else: |
| 524 | self.bucket_stats = [] |
| 525 | return |
| 526 | |
| 527 | def pack(self): |
| 528 | packed = [] |
| 529 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 0 |
| 530 | packed.append('\x00' * 2) |
| 531 | packed.append(struct.pack("!L", self.group_id)) |
| 532 | packed.append(struct.pack("!L", self.ref_count)) |
| 533 | packed.append('\x00' * 4) |
| 534 | packed.append(struct.pack("!Q", self.packet_count)) |
| 535 | packed.append(struct.pack("!Q", self.byte_count)) |
| 536 | packed.append("".join([x.pack() for x in self.bucket_stats])) |
| 537 | length = sum([len(x) for x in packed]) |
| 538 | packed[0] = struct.pack("!H", length) |
| 539 | return ''.join(packed) |
| 540 | |
| 541 | @staticmethod |
| 542 | def unpack(buf): |
| 543 | obj = group_stats_entry() |
| 544 | if type(buf) == loxi.generic_util.OFReader: |
| 545 | reader = buf |
| 546 | else: |
| 547 | reader = loxi.generic_util.OFReader(buf) |
| 548 | _length = reader.read('!H')[0] |
| 549 | reader.skip(2) |
| 550 | obj.group_id = reader.read('!L')[0] |
| 551 | obj.ref_count = reader.read('!L')[0] |
| 552 | reader.skip(4) |
| 553 | obj.packet_count = reader.read('!Q')[0] |
| 554 | obj.byte_count = reader.read('!Q')[0] |
| 555 | obj.bucket_stats = loxi.generic_util.unpack_list(reader, common.bucket_counter.unpack) |
| 556 | return obj |
| 557 | |
| 558 | def __eq__(self, other): |
| 559 | if type(self) != type(other): return False |
| 560 | if self.group_id != other.group_id: return False |
| 561 | if self.ref_count != other.ref_count: return False |
| 562 | if self.packet_count != other.packet_count: return False |
| 563 | if self.byte_count != other.byte_count: return False |
| 564 | if self.bucket_stats != other.bucket_stats: return False |
| 565 | return True |
| 566 | |
| 567 | def __ne__(self, other): |
| 568 | return not self.__eq__(other) |
| 569 | |
| 570 | def show(self): |
| 571 | import loxi.pp |
| 572 | return loxi.pp.pp(self) |
| 573 | |
| 574 | def pretty_print(self, q): |
| 575 | q.text("group_stats_entry {") |
| 576 | with q.group(): |
| 577 | with q.indent(2): |
| 578 | q.breakable() |
| 579 | q.text("group_id = "); |
| 580 | q.text("%#x" % self.group_id) |
| 581 | q.text(","); q.breakable() |
| 582 | q.text("ref_count = "); |
| 583 | q.text("%#x" % self.ref_count) |
| 584 | q.text(","); q.breakable() |
| 585 | q.text("packet_count = "); |
| 586 | q.text("%#x" % self.packet_count) |
| 587 | q.text(","); q.breakable() |
| 588 | q.text("byte_count = "); |
| 589 | q.text("%#x" % self.byte_count) |
| 590 | q.text(","); q.breakable() |
| 591 | q.text("bucket_stats = "); |
| 592 | q.pp(self.bucket_stats) |
| 593 | q.breakable() |
| 594 | q.text('}') |
| 595 | |
| 596 | class match_v2(object): |
| 597 | type = 0 |
| 598 | |
| 599 | def __init__(self, in_port=None, wildcards=None, eth_src=None, eth_src_mask=None, eth_dst=None, eth_dst_mask=None, vlan_vid=None, vlan_pcp=None, eth_type=None, ip_dscp=None, ip_proto=None, ipv4_src=None, ipv4_src_mask=None, ipv4_dst=None, ipv4_dst_mask=None, tcp_src=None, tcp_dst=None, mpls_label=None, mpls_tc=None, metadata=None, metadata_mask=None): |
| 600 | if in_port != None: |
| 601 | self.in_port = in_port |
| 602 | else: |
| 603 | self.in_port = 0 |
| 604 | if wildcards != None: |
| 605 | self.wildcards = wildcards |
| 606 | else: |
| 607 | self.wildcards = const.OFPFW_ALL |
| 608 | if eth_src != None: |
| 609 | self.eth_src = eth_src |
| 610 | else: |
| 611 | self.eth_src = [0,0,0,0,0,0] |
| 612 | if eth_src_mask != None: |
| 613 | self.eth_src_mask = eth_src_mask |
| 614 | else: |
| 615 | self.eth_src_mask = [0,0,0,0,0,0] |
| 616 | if eth_dst != None: |
| 617 | self.eth_dst = eth_dst |
| 618 | else: |
| 619 | self.eth_dst = [0,0,0,0,0,0] |
| 620 | if eth_dst_mask != None: |
| 621 | self.eth_dst_mask = eth_dst_mask |
| 622 | else: |
| 623 | self.eth_dst_mask = [0,0,0,0,0,0] |
| 624 | if vlan_vid != None: |
| 625 | self.vlan_vid = vlan_vid |
| 626 | else: |
| 627 | self.vlan_vid = 0 |
| 628 | if vlan_pcp != None: |
| 629 | self.vlan_pcp = vlan_pcp |
| 630 | else: |
| 631 | self.vlan_pcp = 0 |
| 632 | if eth_type != None: |
| 633 | self.eth_type = eth_type |
| 634 | else: |
| 635 | self.eth_type = 0 |
| 636 | if ip_dscp != None: |
| 637 | self.ip_dscp = ip_dscp |
| 638 | else: |
| 639 | self.ip_dscp = 0 |
| 640 | if ip_proto != None: |
| 641 | self.ip_proto = ip_proto |
| 642 | else: |
| 643 | self.ip_proto = 0 |
| 644 | if ipv4_src != None: |
| 645 | self.ipv4_src = ipv4_src |
| 646 | else: |
| 647 | self.ipv4_src = 0 |
| 648 | if ipv4_src_mask != None: |
| 649 | self.ipv4_src_mask = ipv4_src_mask |
| 650 | else: |
| 651 | self.ipv4_src_mask = 0 |
| 652 | if ipv4_dst != None: |
| 653 | self.ipv4_dst = ipv4_dst |
| 654 | else: |
| 655 | self.ipv4_dst = 0 |
| 656 | if ipv4_dst_mask != None: |
| 657 | self.ipv4_dst_mask = ipv4_dst_mask |
| 658 | else: |
| 659 | self.ipv4_dst_mask = 0 |
| 660 | if tcp_src != None: |
| 661 | self.tcp_src = tcp_src |
| 662 | else: |
| 663 | self.tcp_src = 0 |
| 664 | if tcp_dst != None: |
| 665 | self.tcp_dst = tcp_dst |
| 666 | else: |
| 667 | self.tcp_dst = 0 |
| 668 | if mpls_label != None: |
| 669 | self.mpls_label = mpls_label |
| 670 | else: |
| 671 | self.mpls_label = 0 |
| 672 | if mpls_tc != None: |
| 673 | self.mpls_tc = mpls_tc |
| 674 | else: |
| 675 | self.mpls_tc = 0 |
| 676 | if metadata != None: |
| 677 | self.metadata = metadata |
| 678 | else: |
| 679 | self.metadata = 0 |
| 680 | if metadata_mask != None: |
| 681 | self.metadata_mask = metadata_mask |
| 682 | else: |
| 683 | self.metadata_mask = 0 |
| 684 | return |
| 685 | |
| 686 | def pack(self): |
| 687 | packed = [] |
| 688 | packed.append(struct.pack("!H", self.type)) |
| 689 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 1 |
| 690 | packed.append(struct.pack("!L", self.in_port)) |
| 691 | packed.append(struct.pack("!L", self.wildcards)) |
| 692 | packed.append(struct.pack("!6B", *self.eth_src)) |
| 693 | packed.append(struct.pack("!6B", *self.eth_src_mask)) |
| 694 | packed.append(struct.pack("!6B", *self.eth_dst)) |
| 695 | packed.append(struct.pack("!6B", *self.eth_dst_mask)) |
| 696 | packed.append(struct.pack("!H", self.vlan_vid)) |
| 697 | packed.append(struct.pack("!B", self.vlan_pcp)) |
| 698 | packed.append('\x00' * 1) |
| 699 | packed.append(struct.pack("!H", self.eth_type)) |
| 700 | packed.append(struct.pack("!B", self.ip_dscp)) |
| 701 | packed.append(struct.pack("!B", self.ip_proto)) |
| 702 | packed.append(struct.pack("!L", self.ipv4_src)) |
| 703 | packed.append(struct.pack("!L", self.ipv4_src_mask)) |
| 704 | packed.append(struct.pack("!L", self.ipv4_dst)) |
| 705 | packed.append(struct.pack("!L", self.ipv4_dst_mask)) |
| 706 | packed.append(struct.pack("!H", self.tcp_src)) |
| 707 | packed.append(struct.pack("!H", self.tcp_dst)) |
| 708 | packed.append(struct.pack("!L", self.mpls_label)) |
| 709 | packed.append(struct.pack("!B", self.mpls_tc)) |
| 710 | packed.append('\x00' * 3) |
| 711 | packed.append(struct.pack("!Q", self.metadata)) |
| 712 | packed.append(struct.pack("!Q", self.metadata_mask)) |
| 713 | length = sum([len(x) for x in packed]) |
| 714 | packed[1] = struct.pack("!H", length) |
| 715 | return ''.join(packed) |
| 716 | |
| 717 | @staticmethod |
| 718 | def unpack(buf): |
| 719 | obj = match_v2() |
| 720 | if type(buf) == loxi.generic_util.OFReader: |
| 721 | reader = buf |
| 722 | else: |
| 723 | reader = loxi.generic_util.OFReader(buf) |
| 724 | _type = reader.read('!H')[0] |
| 725 | assert(_type == 0) |
| 726 | _length = reader.read('!H')[0] |
| 727 | obj.in_port = reader.read('!L')[0] |
| 728 | obj.wildcards = reader.read('!L')[0] |
| 729 | obj.eth_src = list(reader.read('!6B')) |
| 730 | obj.eth_src_mask = list(reader.read('!6B')) |
| 731 | obj.eth_dst = list(reader.read('!6B')) |
| 732 | obj.eth_dst_mask = list(reader.read('!6B')) |
| 733 | obj.vlan_vid = reader.read('!H')[0] |
| 734 | obj.vlan_pcp = reader.read('!B')[0] |
| 735 | reader.skip(1) |
| 736 | obj.eth_type = reader.read('!H')[0] |
| 737 | obj.ip_dscp = reader.read('!B')[0] |
| 738 | obj.ip_proto = reader.read('!B')[0] |
| 739 | obj.ipv4_src = reader.read('!L')[0] |
| 740 | obj.ipv4_src_mask = reader.read('!L')[0] |
| 741 | obj.ipv4_dst = reader.read('!L')[0] |
| 742 | obj.ipv4_dst_mask = reader.read('!L')[0] |
| 743 | obj.tcp_src = reader.read('!H')[0] |
| 744 | obj.tcp_dst = reader.read('!H')[0] |
| 745 | obj.mpls_label = reader.read('!L')[0] |
| 746 | obj.mpls_tc = reader.read('!B')[0] |
| 747 | reader.skip(3) |
| 748 | obj.metadata = reader.read('!Q')[0] |
| 749 | obj.metadata_mask = reader.read('!Q')[0] |
| 750 | return obj |
| 751 | |
| 752 | def __eq__(self, other): |
| 753 | if type(self) != type(other): return False |
| 754 | if self.in_port != other.in_port: return False |
| 755 | if self.wildcards != other.wildcards: return False |
| 756 | if self.eth_src != other.eth_src: return False |
| 757 | if self.eth_src_mask != other.eth_src_mask: return False |
| 758 | if self.eth_dst != other.eth_dst: return False |
| 759 | if self.eth_dst_mask != other.eth_dst_mask: return False |
| 760 | if self.vlan_vid != other.vlan_vid: return False |
| 761 | if self.vlan_pcp != other.vlan_pcp: return False |
| 762 | if self.eth_type != other.eth_type: return False |
| 763 | if self.ip_dscp != other.ip_dscp: return False |
| 764 | if self.ip_proto != other.ip_proto: return False |
| 765 | if self.ipv4_src != other.ipv4_src: return False |
| 766 | if self.ipv4_src_mask != other.ipv4_src_mask: return False |
| 767 | if self.ipv4_dst != other.ipv4_dst: return False |
| 768 | if self.ipv4_dst_mask != other.ipv4_dst_mask: return False |
| 769 | if self.tcp_src != other.tcp_src: return False |
| 770 | if self.tcp_dst != other.tcp_dst: return False |
| 771 | if self.mpls_label != other.mpls_label: return False |
| 772 | if self.mpls_tc != other.mpls_tc: return False |
| 773 | if self.metadata != other.metadata: return False |
| 774 | if self.metadata_mask != other.metadata_mask: return False |
| 775 | return True |
| 776 | |
| 777 | def __ne__(self, other): |
| 778 | return not self.__eq__(other) |
| 779 | |
| 780 | def show(self): |
| 781 | import loxi.pp |
| 782 | return loxi.pp.pp(self) |
| 783 | |
| 784 | def pretty_print(self, q): |
| 785 | q.text("match_v2 {") |
| 786 | with q.group(): |
| 787 | with q.indent(2): |
| 788 | q.breakable() |
| 789 | q.text("in_port = "); |
| 790 | q.text(util.pretty_port(self.in_port)) |
| 791 | q.text(","); q.breakable() |
| 792 | q.text("wildcards = "); |
| 793 | q.text(util.pretty_wildcards(self.wildcards)) |
| 794 | q.text(","); q.breakable() |
| 795 | q.text("eth_src = "); |
| 796 | q.text(util.pretty_mac(self.eth_src)) |
| 797 | q.text(","); q.breakable() |
| 798 | q.text("eth_src_mask = "); |
| 799 | q.text(util.pretty_mac(self.eth_src_mask)) |
| 800 | q.text(","); q.breakable() |
| 801 | q.text("eth_dst = "); |
| 802 | q.text(util.pretty_mac(self.eth_dst)) |
| 803 | q.text(","); q.breakable() |
| 804 | q.text("eth_dst_mask = "); |
| 805 | q.text(util.pretty_mac(self.eth_dst_mask)) |
| 806 | q.text(","); q.breakable() |
| 807 | q.text("vlan_vid = "); |
| 808 | q.text("%#x" % self.vlan_vid) |
| 809 | q.text(","); q.breakable() |
| 810 | q.text("vlan_pcp = "); |
| 811 | q.text("%#x" % self.vlan_pcp) |
| 812 | q.text(","); q.breakable() |
| 813 | q.text("eth_type = "); |
| 814 | q.text("%#x" % self.eth_type) |
| 815 | q.text(","); q.breakable() |
| 816 | q.text("ip_dscp = "); |
| 817 | q.text("%#x" % self.ip_dscp) |
| 818 | q.text(","); q.breakable() |
| 819 | q.text("ip_proto = "); |
| 820 | q.text("%#x" % self.ip_proto) |
| 821 | q.text(","); q.breakable() |
| 822 | q.text("ipv4_src = "); |
| 823 | q.text(util.pretty_ipv4(self.ipv4_src)) |
| 824 | q.text(","); q.breakable() |
| 825 | q.text("ipv4_src_mask = "); |
| 826 | q.text(util.pretty_ipv4(self.ipv4_src_mask)) |
| 827 | q.text(","); q.breakable() |
| 828 | q.text("ipv4_dst = "); |
| 829 | q.text(util.pretty_ipv4(self.ipv4_dst)) |
| 830 | q.text(","); q.breakable() |
| 831 | q.text("ipv4_dst_mask = "); |
| 832 | q.text(util.pretty_ipv4(self.ipv4_dst_mask)) |
| 833 | q.text(","); q.breakable() |
| 834 | q.text("tcp_src = "); |
| 835 | q.text("%#x" % self.tcp_src) |
| 836 | q.text(","); q.breakable() |
| 837 | q.text("tcp_dst = "); |
| 838 | q.text("%#x" % self.tcp_dst) |
| 839 | q.text(","); q.breakable() |
| 840 | q.text("mpls_label = "); |
| 841 | q.text("%#x" % self.mpls_label) |
| 842 | q.text(","); q.breakable() |
| 843 | q.text("mpls_tc = "); |
| 844 | q.text("%#x" % self.mpls_tc) |
| 845 | q.text(","); q.breakable() |
| 846 | q.text("metadata = "); |
| 847 | q.text("%#x" % self.metadata) |
| 848 | q.text(","); q.breakable() |
| 849 | q.text("metadata_mask = "); |
| 850 | q.text("%#x" % self.metadata_mask) |
| 851 | q.breakable() |
| 852 | q.text('}') |
| 853 | |
| 854 | class packet_queue(object): |
| 855 | |
| 856 | def __init__(self, queue_id=None, properties=None): |
| 857 | if queue_id != None: |
| 858 | self.queue_id = queue_id |
| 859 | else: |
| 860 | self.queue_id = 0 |
| 861 | if properties != None: |
| 862 | self.properties = properties |
| 863 | else: |
| 864 | self.properties = [] |
| 865 | return |
| 866 | |
| 867 | def pack(self): |
| 868 | packed = [] |
| 869 | packed.append(struct.pack("!L", self.queue_id)) |
| 870 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 871 | packed.append('\x00' * 2) |
| 872 | packed.append("".join([x.pack() for x in self.properties])) |
| 873 | length = sum([len(x) for x in packed]) |
| 874 | packed[1] = struct.pack("!H", length) |
| 875 | return ''.join(packed) |
| 876 | |
| 877 | @staticmethod |
| 878 | def unpack(buf): |
| 879 | obj = packet_queue() |
| 880 | if type(buf) == loxi.generic_util.OFReader: |
| 881 | reader = buf |
| 882 | else: |
| 883 | reader = loxi.generic_util.OFReader(buf) |
| 884 | obj.queue_id = reader.read('!L')[0] |
| 885 | _len = reader.read('!H')[0] |
| 886 | reader.skip(2) |
| 887 | obj.properties = common.unpack_list_queue_prop(reader) |
| 888 | return obj |
| 889 | |
| 890 | def __eq__(self, other): |
| 891 | if type(self) != type(other): return False |
| 892 | if self.queue_id != other.queue_id: return False |
| 893 | if self.properties != other.properties: return False |
| 894 | return True |
| 895 | |
| 896 | def __ne__(self, other): |
| 897 | return not self.__eq__(other) |
| 898 | |
| 899 | def show(self): |
| 900 | import loxi.pp |
| 901 | return loxi.pp.pp(self) |
| 902 | |
| 903 | def pretty_print(self, q): |
| 904 | q.text("packet_queue {") |
| 905 | with q.group(): |
| 906 | with q.indent(2): |
| 907 | q.breakable() |
| 908 | q.text("queue_id = "); |
| 909 | q.text("%#x" % self.queue_id) |
| 910 | q.text(","); q.breakable() |
| 911 | q.text("properties = "); |
| 912 | q.pp(self.properties) |
| 913 | q.breakable() |
| 914 | q.text('}') |
| 915 | |
| 916 | class port_desc(object): |
| 917 | |
| 918 | def __init__(self, port_no=None, hw_addr=None, name=None, config=None, state=None, curr=None, advertised=None, supported=None, peer=None, curr_speed=None, max_speed=None): |
| 919 | if port_no != None: |
| 920 | self.port_no = port_no |
| 921 | else: |
| 922 | self.port_no = 0 |
| 923 | if hw_addr != None: |
| 924 | self.hw_addr = hw_addr |
| 925 | else: |
| 926 | self.hw_addr = [0,0,0,0,0,0] |
| 927 | if name != None: |
| 928 | self.name = name |
| 929 | else: |
| 930 | self.name = "" |
| 931 | if config != None: |
| 932 | self.config = config |
| 933 | else: |
| 934 | self.config = 0 |
| 935 | if state != None: |
| 936 | self.state = state |
| 937 | else: |
| 938 | self.state = 0 |
| 939 | if curr != None: |
| 940 | self.curr = curr |
| 941 | else: |
| 942 | self.curr = 0 |
| 943 | if advertised != None: |
| 944 | self.advertised = advertised |
| 945 | else: |
| 946 | self.advertised = 0 |
| 947 | if supported != None: |
| 948 | self.supported = supported |
| 949 | else: |
| 950 | self.supported = 0 |
| 951 | if peer != None: |
| 952 | self.peer = peer |
| 953 | else: |
| 954 | self.peer = 0 |
| 955 | if curr_speed != None: |
| 956 | self.curr_speed = curr_speed |
| 957 | else: |
| 958 | self.curr_speed = 0 |
| 959 | if max_speed != None: |
| 960 | self.max_speed = max_speed |
| 961 | else: |
| 962 | self.max_speed = 0 |
| 963 | return |
| 964 | |
| 965 | def pack(self): |
| 966 | packed = [] |
| 967 | packed.append(struct.pack("!L", self.port_no)) |
| 968 | packed.append('\x00' * 4) |
| 969 | packed.append(struct.pack("!6B", *self.hw_addr)) |
| 970 | packed.append('\x00' * 2) |
| 971 | packed.append(struct.pack("!16s", self.name)) |
| 972 | packed.append(struct.pack("!L", self.config)) |
| 973 | packed.append(struct.pack("!L", self.state)) |
| 974 | packed.append(struct.pack("!L", self.curr)) |
| 975 | packed.append(struct.pack("!L", self.advertised)) |
| 976 | packed.append(struct.pack("!L", self.supported)) |
| 977 | packed.append(struct.pack("!L", self.peer)) |
| 978 | packed.append(struct.pack("!L", self.curr_speed)) |
| 979 | packed.append(struct.pack("!L", self.max_speed)) |
| 980 | return ''.join(packed) |
| 981 | |
| 982 | @staticmethod |
| 983 | def unpack(buf): |
| 984 | obj = port_desc() |
| 985 | if type(buf) == loxi.generic_util.OFReader: |
| 986 | reader = buf |
| 987 | else: |
| 988 | reader = loxi.generic_util.OFReader(buf) |
| 989 | obj.port_no = reader.read('!L')[0] |
| 990 | reader.skip(4) |
| 991 | obj.hw_addr = list(reader.read('!6B')) |
| 992 | reader.skip(2) |
| 993 | obj.name = reader.read("!16s")[0].rstrip("\x00") |
| 994 | obj.config = reader.read('!L')[0] |
| 995 | obj.state = reader.read('!L')[0] |
| 996 | obj.curr = reader.read('!L')[0] |
| 997 | obj.advertised = reader.read('!L')[0] |
| 998 | obj.supported = reader.read('!L')[0] |
| 999 | obj.peer = reader.read('!L')[0] |
| 1000 | obj.curr_speed = reader.read('!L')[0] |
| 1001 | obj.max_speed = reader.read('!L')[0] |
| 1002 | return obj |
| 1003 | |
| 1004 | def __eq__(self, other): |
| 1005 | if type(self) != type(other): return False |
| 1006 | if self.port_no != other.port_no: return False |
| 1007 | if self.hw_addr != other.hw_addr: return False |
| 1008 | if self.name != other.name: return False |
| 1009 | if self.config != other.config: return False |
| 1010 | if self.state != other.state: return False |
| 1011 | if self.curr != other.curr: return False |
| 1012 | if self.advertised != other.advertised: return False |
| 1013 | if self.supported != other.supported: return False |
| 1014 | if self.peer != other.peer: return False |
| 1015 | if self.curr_speed != other.curr_speed: return False |
| 1016 | if self.max_speed != other.max_speed: return False |
| 1017 | return True |
| 1018 | |
| 1019 | def __ne__(self, other): |
| 1020 | return not self.__eq__(other) |
| 1021 | |
| 1022 | def show(self): |
| 1023 | import loxi.pp |
| 1024 | return loxi.pp.pp(self) |
| 1025 | |
| 1026 | def pretty_print(self, q): |
| 1027 | q.text("port_desc {") |
| 1028 | with q.group(): |
| 1029 | with q.indent(2): |
| 1030 | q.breakable() |
| 1031 | q.text("port_no = "); |
| 1032 | q.text(util.pretty_port(self.port_no)) |
| 1033 | q.text(","); q.breakable() |
| 1034 | q.text("hw_addr = "); |
| 1035 | q.text(util.pretty_mac(self.hw_addr)) |
| 1036 | q.text(","); q.breakable() |
| 1037 | q.text("name = "); |
| 1038 | q.pp(self.name) |
| 1039 | q.text(","); q.breakable() |
| 1040 | q.text("config = "); |
| 1041 | q.text("%#x" % self.config) |
| 1042 | q.text(","); q.breakable() |
| 1043 | q.text("state = "); |
| 1044 | q.text("%#x" % self.state) |
| 1045 | q.text(","); q.breakable() |
| 1046 | q.text("curr = "); |
| 1047 | q.text("%#x" % self.curr) |
| 1048 | q.text(","); q.breakable() |
| 1049 | q.text("advertised = "); |
| 1050 | q.text("%#x" % self.advertised) |
| 1051 | q.text(","); q.breakable() |
| 1052 | q.text("supported = "); |
| 1053 | q.text("%#x" % self.supported) |
| 1054 | q.text(","); q.breakable() |
| 1055 | q.text("peer = "); |
| 1056 | q.text("%#x" % self.peer) |
| 1057 | q.text(","); q.breakable() |
| 1058 | q.text("curr_speed = "); |
| 1059 | q.text("%#x" % self.curr_speed) |
| 1060 | q.text(","); q.breakable() |
| 1061 | q.text("max_speed = "); |
| 1062 | q.text("%#x" % self.max_speed) |
| 1063 | q.breakable() |
| 1064 | q.text('}') |
| 1065 | |
| 1066 | class port_stats_entry(object): |
| 1067 | |
| 1068 | def __init__(self, port_no=None, rx_packets=None, tx_packets=None, rx_bytes=None, tx_bytes=None, rx_dropped=None, tx_dropped=None, rx_errors=None, tx_errors=None, rx_frame_err=None, rx_over_err=None, rx_crc_err=None, collisions=None): |
| 1069 | if port_no != None: |
| 1070 | self.port_no = port_no |
| 1071 | else: |
| 1072 | self.port_no = 0 |
| 1073 | if rx_packets != None: |
| 1074 | self.rx_packets = rx_packets |
| 1075 | else: |
| 1076 | self.rx_packets = 0 |
| 1077 | if tx_packets != None: |
| 1078 | self.tx_packets = tx_packets |
| 1079 | else: |
| 1080 | self.tx_packets = 0 |
| 1081 | if rx_bytes != None: |
| 1082 | self.rx_bytes = rx_bytes |
| 1083 | else: |
| 1084 | self.rx_bytes = 0 |
| 1085 | if tx_bytes != None: |
| 1086 | self.tx_bytes = tx_bytes |
| 1087 | else: |
| 1088 | self.tx_bytes = 0 |
| 1089 | if rx_dropped != None: |
| 1090 | self.rx_dropped = rx_dropped |
| 1091 | else: |
| 1092 | self.rx_dropped = 0 |
| 1093 | if tx_dropped != None: |
| 1094 | self.tx_dropped = tx_dropped |
| 1095 | else: |
| 1096 | self.tx_dropped = 0 |
| 1097 | if rx_errors != None: |
| 1098 | self.rx_errors = rx_errors |
| 1099 | else: |
| 1100 | self.rx_errors = 0 |
| 1101 | if tx_errors != None: |
| 1102 | self.tx_errors = tx_errors |
| 1103 | else: |
| 1104 | self.tx_errors = 0 |
| 1105 | if rx_frame_err != None: |
| 1106 | self.rx_frame_err = rx_frame_err |
| 1107 | else: |
| 1108 | self.rx_frame_err = 0 |
| 1109 | if rx_over_err != None: |
| 1110 | self.rx_over_err = rx_over_err |
| 1111 | else: |
| 1112 | self.rx_over_err = 0 |
| 1113 | if rx_crc_err != None: |
| 1114 | self.rx_crc_err = rx_crc_err |
| 1115 | else: |
| 1116 | self.rx_crc_err = 0 |
| 1117 | if collisions != None: |
| 1118 | self.collisions = collisions |
| 1119 | else: |
| 1120 | self.collisions = 0 |
| 1121 | return |
| 1122 | |
| 1123 | def pack(self): |
| 1124 | packed = [] |
| 1125 | packed.append(struct.pack("!L", self.port_no)) |
| 1126 | packed.append('\x00' * 4) |
| 1127 | packed.append(struct.pack("!Q", self.rx_packets)) |
| 1128 | packed.append(struct.pack("!Q", self.tx_packets)) |
| 1129 | packed.append(struct.pack("!Q", self.rx_bytes)) |
| 1130 | packed.append(struct.pack("!Q", self.tx_bytes)) |
| 1131 | packed.append(struct.pack("!Q", self.rx_dropped)) |
| 1132 | packed.append(struct.pack("!Q", self.tx_dropped)) |
| 1133 | packed.append(struct.pack("!Q", self.rx_errors)) |
| 1134 | packed.append(struct.pack("!Q", self.tx_errors)) |
| 1135 | packed.append(struct.pack("!Q", self.rx_frame_err)) |
| 1136 | packed.append(struct.pack("!Q", self.rx_over_err)) |
| 1137 | packed.append(struct.pack("!Q", self.rx_crc_err)) |
| 1138 | packed.append(struct.pack("!Q", self.collisions)) |
| 1139 | return ''.join(packed) |
| 1140 | |
| 1141 | @staticmethod |
| 1142 | def unpack(buf): |
| 1143 | obj = port_stats_entry() |
| 1144 | if type(buf) == loxi.generic_util.OFReader: |
| 1145 | reader = buf |
| 1146 | else: |
| 1147 | reader = loxi.generic_util.OFReader(buf) |
| 1148 | obj.port_no = reader.read('!L')[0] |
| 1149 | reader.skip(4) |
| 1150 | obj.rx_packets = reader.read('!Q')[0] |
| 1151 | obj.tx_packets = reader.read('!Q')[0] |
| 1152 | obj.rx_bytes = reader.read('!Q')[0] |
| 1153 | obj.tx_bytes = reader.read('!Q')[0] |
| 1154 | obj.rx_dropped = reader.read('!Q')[0] |
| 1155 | obj.tx_dropped = reader.read('!Q')[0] |
| 1156 | obj.rx_errors = reader.read('!Q')[0] |
| 1157 | obj.tx_errors = reader.read('!Q')[0] |
| 1158 | obj.rx_frame_err = reader.read('!Q')[0] |
| 1159 | obj.rx_over_err = reader.read('!Q')[0] |
| 1160 | obj.rx_crc_err = reader.read('!Q')[0] |
| 1161 | obj.collisions = reader.read('!Q')[0] |
| 1162 | return obj |
| 1163 | |
| 1164 | def __eq__(self, other): |
| 1165 | if type(self) != type(other): return False |
| 1166 | if self.port_no != other.port_no: return False |
| 1167 | if self.rx_packets != other.rx_packets: return False |
| 1168 | if self.tx_packets != other.tx_packets: return False |
| 1169 | if self.rx_bytes != other.rx_bytes: return False |
| 1170 | if self.tx_bytes != other.tx_bytes: return False |
| 1171 | if self.rx_dropped != other.rx_dropped: return False |
| 1172 | if self.tx_dropped != other.tx_dropped: return False |
| 1173 | if self.rx_errors != other.rx_errors: return False |
| 1174 | if self.tx_errors != other.tx_errors: return False |
| 1175 | if self.rx_frame_err != other.rx_frame_err: return False |
| 1176 | if self.rx_over_err != other.rx_over_err: return False |
| 1177 | if self.rx_crc_err != other.rx_crc_err: return False |
| 1178 | if self.collisions != other.collisions: return False |
| 1179 | return True |
| 1180 | |
| 1181 | def __ne__(self, other): |
| 1182 | return not self.__eq__(other) |
| 1183 | |
| 1184 | def show(self): |
| 1185 | import loxi.pp |
| 1186 | return loxi.pp.pp(self) |
| 1187 | |
| 1188 | def pretty_print(self, q): |
| 1189 | q.text("port_stats_entry {") |
| 1190 | with q.group(): |
| 1191 | with q.indent(2): |
| 1192 | q.breakable() |
| 1193 | q.text("port_no = "); |
| 1194 | q.text(util.pretty_port(self.port_no)) |
| 1195 | q.text(","); q.breakable() |
| 1196 | q.text("rx_packets = "); |
| 1197 | q.text("%#x" % self.rx_packets) |
| 1198 | q.text(","); q.breakable() |
| 1199 | q.text("tx_packets = "); |
| 1200 | q.text("%#x" % self.tx_packets) |
| 1201 | q.text(","); q.breakable() |
| 1202 | q.text("rx_bytes = "); |
| 1203 | q.text("%#x" % self.rx_bytes) |
| 1204 | q.text(","); q.breakable() |
| 1205 | q.text("tx_bytes = "); |
| 1206 | q.text("%#x" % self.tx_bytes) |
| 1207 | q.text(","); q.breakable() |
| 1208 | q.text("rx_dropped = "); |
| 1209 | q.text("%#x" % self.rx_dropped) |
| 1210 | q.text(","); q.breakable() |
| 1211 | q.text("tx_dropped = "); |
| 1212 | q.text("%#x" % self.tx_dropped) |
| 1213 | q.text(","); q.breakable() |
| 1214 | q.text("rx_errors = "); |
| 1215 | q.text("%#x" % self.rx_errors) |
| 1216 | q.text(","); q.breakable() |
| 1217 | q.text("tx_errors = "); |
| 1218 | q.text("%#x" % self.tx_errors) |
| 1219 | q.text(","); q.breakable() |
| 1220 | q.text("rx_frame_err = "); |
| 1221 | q.text("%#x" % self.rx_frame_err) |
| 1222 | q.text(","); q.breakable() |
| 1223 | q.text("rx_over_err = "); |
| 1224 | q.text("%#x" % self.rx_over_err) |
| 1225 | q.text(","); q.breakable() |
| 1226 | q.text("rx_crc_err = "); |
| 1227 | q.text("%#x" % self.rx_crc_err) |
| 1228 | q.text(","); q.breakable() |
| 1229 | q.text("collisions = "); |
| 1230 | q.text("%#x" % self.collisions) |
| 1231 | q.breakable() |
| 1232 | q.text('}') |
| 1233 | |
| 1234 | class queue_prop_min_rate(object): |
| 1235 | type = const.OFPQT_MIN_RATE |
| 1236 | |
| 1237 | def __init__(self, rate=None): |
| 1238 | if rate != None: |
| 1239 | self.rate = rate |
| 1240 | else: |
| 1241 | self.rate = 0 |
| 1242 | return |
| 1243 | |
| 1244 | def pack(self): |
| 1245 | packed = [] |
| 1246 | packed.append(struct.pack("!H", self.type)) |
| 1247 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 1248 | packed.append('\x00' * 4) |
| 1249 | packed.append(struct.pack("!H", self.rate)) |
| 1250 | packed.append('\x00' * 6) |
| 1251 | length = sum([len(x) for x in packed]) |
| 1252 | packed[1] = struct.pack("!H", length) |
| 1253 | return ''.join(packed) |
| 1254 | |
| 1255 | @staticmethod |
| 1256 | def unpack(buf): |
| 1257 | obj = queue_prop_min_rate() |
| 1258 | if type(buf) == loxi.generic_util.OFReader: |
| 1259 | reader = buf |
| 1260 | else: |
| 1261 | reader = loxi.generic_util.OFReader(buf) |
| 1262 | _type = reader.read('!H')[0] |
| 1263 | assert(_type == const.OFPQT_MIN_RATE) |
| 1264 | _len = reader.read('!H')[0] |
| 1265 | reader.skip(4) |
| 1266 | obj.rate = reader.read('!H')[0] |
| 1267 | reader.skip(6) |
| 1268 | return obj |
| 1269 | |
| 1270 | def __eq__(self, other): |
| 1271 | if type(self) != type(other): return False |
| 1272 | if self.rate != other.rate: return False |
| 1273 | return True |
| 1274 | |
| 1275 | def __ne__(self, other): |
| 1276 | return not self.__eq__(other) |
| 1277 | |
| 1278 | def show(self): |
| 1279 | import loxi.pp |
| 1280 | return loxi.pp.pp(self) |
| 1281 | |
| 1282 | def pretty_print(self, q): |
| 1283 | q.text("queue_prop_min_rate {") |
| 1284 | with q.group(): |
| 1285 | with q.indent(2): |
| 1286 | q.breakable() |
| 1287 | q.text("rate = "); |
| 1288 | q.text("%#x" % self.rate) |
| 1289 | q.breakable() |
| 1290 | q.text('}') |
| 1291 | |
| 1292 | class queue_stats_entry(object): |
| 1293 | |
| 1294 | def __init__(self, port_no=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None): |
| 1295 | if port_no != None: |
| 1296 | self.port_no = port_no |
| 1297 | else: |
| 1298 | self.port_no = 0 |
| 1299 | if queue_id != None: |
| 1300 | self.queue_id = queue_id |
| 1301 | else: |
| 1302 | self.queue_id = 0 |
| 1303 | if tx_bytes != None: |
| 1304 | self.tx_bytes = tx_bytes |
| 1305 | else: |
| 1306 | self.tx_bytes = 0 |
| 1307 | if tx_packets != None: |
| 1308 | self.tx_packets = tx_packets |
| 1309 | else: |
| 1310 | self.tx_packets = 0 |
| 1311 | if tx_errors != None: |
| 1312 | self.tx_errors = tx_errors |
| 1313 | else: |
| 1314 | self.tx_errors = 0 |
| 1315 | return |
| 1316 | |
| 1317 | def pack(self): |
| 1318 | packed = [] |
| 1319 | packed.append(struct.pack("!L", self.port_no)) |
| 1320 | packed.append(struct.pack("!L", self.queue_id)) |
| 1321 | packed.append(struct.pack("!Q", self.tx_bytes)) |
| 1322 | packed.append(struct.pack("!Q", self.tx_packets)) |
| 1323 | packed.append(struct.pack("!Q", self.tx_errors)) |
| 1324 | return ''.join(packed) |
| 1325 | |
| 1326 | @staticmethod |
| 1327 | def unpack(buf): |
| 1328 | obj = queue_stats_entry() |
| 1329 | if type(buf) == loxi.generic_util.OFReader: |
| 1330 | reader = buf |
| 1331 | else: |
| 1332 | reader = loxi.generic_util.OFReader(buf) |
| 1333 | obj.port_no = reader.read('!L')[0] |
| 1334 | obj.queue_id = reader.read('!L')[0] |
| 1335 | obj.tx_bytes = reader.read('!Q')[0] |
| 1336 | obj.tx_packets = reader.read('!Q')[0] |
| 1337 | obj.tx_errors = reader.read('!Q')[0] |
| 1338 | return obj |
| 1339 | |
| 1340 | def __eq__(self, other): |
| 1341 | if type(self) != type(other): return False |
| 1342 | if self.port_no != other.port_no: return False |
| 1343 | if self.queue_id != other.queue_id: return False |
| 1344 | if self.tx_bytes != other.tx_bytes: return False |
| 1345 | if self.tx_packets != other.tx_packets: return False |
| 1346 | if self.tx_errors != other.tx_errors: return False |
| 1347 | return True |
| 1348 | |
| 1349 | def __ne__(self, other): |
| 1350 | return not self.__eq__(other) |
| 1351 | |
| 1352 | def show(self): |
| 1353 | import loxi.pp |
| 1354 | return loxi.pp.pp(self) |
| 1355 | |
| 1356 | def pretty_print(self, q): |
| 1357 | q.text("queue_stats_entry {") |
| 1358 | with q.group(): |
| 1359 | with q.indent(2): |
| 1360 | q.breakable() |
| 1361 | q.text("port_no = "); |
| 1362 | q.text(util.pretty_port(self.port_no)) |
| 1363 | q.text(","); q.breakable() |
| 1364 | q.text("queue_id = "); |
| 1365 | q.text("%#x" % self.queue_id) |
| 1366 | q.text(","); q.breakable() |
| 1367 | q.text("tx_bytes = "); |
| 1368 | q.text("%#x" % self.tx_bytes) |
| 1369 | q.text(","); q.breakable() |
| 1370 | q.text("tx_packets = "); |
| 1371 | q.text("%#x" % self.tx_packets) |
| 1372 | q.text(","); q.breakable() |
| 1373 | q.text("tx_errors = "); |
| 1374 | q.text("%#x" % self.tx_errors) |
| 1375 | q.breakable() |
| 1376 | q.text('}') |
| 1377 | |
| 1378 | class table_stats_entry(object): |
| 1379 | |
| 1380 | def __init__(self, table_id=None, name=None, wildcards=None, match=None, instructions=None, write_actions=None, apply_actions=None, config=None, max_entries=None, active_count=None, lookup_count=None, matched_count=None): |
| 1381 | if table_id != None: |
| 1382 | self.table_id = table_id |
| 1383 | else: |
| 1384 | self.table_id = 0 |
| 1385 | if name != None: |
| 1386 | self.name = name |
| 1387 | else: |
| 1388 | self.name = "" |
| 1389 | if wildcards != None: |
| 1390 | self.wildcards = wildcards |
| 1391 | else: |
| 1392 | self.wildcards = const.OFPFW_ALL |
| 1393 | if match != None: |
| 1394 | self.match = match |
| 1395 | else: |
| 1396 | self.match = const.OFPFW_ALL |
| 1397 | if instructions != None: |
| 1398 | self.instructions = instructions |
| 1399 | else: |
| 1400 | self.instructions = 0 |
| 1401 | if write_actions != None: |
| 1402 | self.write_actions = write_actions |
| 1403 | else: |
| 1404 | self.write_actions = 0 |
| 1405 | if apply_actions != None: |
| 1406 | self.apply_actions = apply_actions |
| 1407 | else: |
| 1408 | self.apply_actions = 0 |
| 1409 | if config != None: |
| 1410 | self.config = config |
| 1411 | else: |
| 1412 | self.config = 0 |
| 1413 | if max_entries != None: |
| 1414 | self.max_entries = max_entries |
| 1415 | else: |
| 1416 | self.max_entries = 0 |
| 1417 | if active_count != None: |
| 1418 | self.active_count = active_count |
| 1419 | else: |
| 1420 | self.active_count = 0 |
| 1421 | if lookup_count != None: |
| 1422 | self.lookup_count = lookup_count |
| 1423 | else: |
| 1424 | self.lookup_count = 0 |
| 1425 | if matched_count != None: |
| 1426 | self.matched_count = matched_count |
| 1427 | else: |
| 1428 | self.matched_count = 0 |
| 1429 | return |
| 1430 | |
| 1431 | def pack(self): |
| 1432 | packed = [] |
| 1433 | packed.append(struct.pack("!B", self.table_id)) |
| 1434 | packed.append('\x00' * 7) |
| 1435 | packed.append(struct.pack("!32s", self.name)) |
| 1436 | packed.append(struct.pack("!L", self.wildcards)) |
| 1437 | packed.append(struct.pack("!L", self.match)) |
| 1438 | packed.append(struct.pack("!L", self.instructions)) |
| 1439 | packed.append(struct.pack("!L", self.write_actions)) |
| 1440 | packed.append(struct.pack("!L", self.apply_actions)) |
| 1441 | packed.append(struct.pack("!L", self.config)) |
| 1442 | packed.append(struct.pack("!L", self.max_entries)) |
| 1443 | packed.append(struct.pack("!L", self.active_count)) |
| 1444 | packed.append(struct.pack("!Q", self.lookup_count)) |
| 1445 | packed.append(struct.pack("!Q", self.matched_count)) |
| 1446 | return ''.join(packed) |
| 1447 | |
| 1448 | @staticmethod |
| 1449 | def unpack(buf): |
| 1450 | obj = table_stats_entry() |
| 1451 | if type(buf) == loxi.generic_util.OFReader: |
| 1452 | reader = buf |
| 1453 | else: |
| 1454 | reader = loxi.generic_util.OFReader(buf) |
| 1455 | obj.table_id = reader.read('!B')[0] |
| 1456 | reader.skip(7) |
| 1457 | obj.name = reader.read("!32s")[0].rstrip("\x00") |
| 1458 | obj.wildcards = reader.read('!L')[0] |
| 1459 | obj.match = reader.read('!L')[0] |
| 1460 | obj.instructions = reader.read('!L')[0] |
| 1461 | obj.write_actions = reader.read('!L')[0] |
| 1462 | obj.apply_actions = reader.read('!L')[0] |
| 1463 | obj.config = reader.read('!L')[0] |
| 1464 | obj.max_entries = reader.read('!L')[0] |
| 1465 | obj.active_count = reader.read('!L')[0] |
| 1466 | obj.lookup_count = reader.read('!Q')[0] |
| 1467 | obj.matched_count = reader.read('!Q')[0] |
| 1468 | return obj |
| 1469 | |
| 1470 | def __eq__(self, other): |
| 1471 | if type(self) != type(other): return False |
| 1472 | if self.table_id != other.table_id: return False |
| 1473 | if self.name != other.name: return False |
| 1474 | if self.wildcards != other.wildcards: return False |
| 1475 | if self.match != other.match: return False |
| 1476 | if self.instructions != other.instructions: return False |
| 1477 | if self.write_actions != other.write_actions: return False |
| 1478 | if self.apply_actions != other.apply_actions: return False |
| 1479 | if self.config != other.config: return False |
| 1480 | if self.max_entries != other.max_entries: return False |
| 1481 | if self.active_count != other.active_count: return False |
| 1482 | if self.lookup_count != other.lookup_count: return False |
| 1483 | if self.matched_count != other.matched_count: return False |
| 1484 | return True |
| 1485 | |
| 1486 | def __ne__(self, other): |
| 1487 | return not self.__eq__(other) |
| 1488 | |
| 1489 | def show(self): |
| 1490 | import loxi.pp |
| 1491 | return loxi.pp.pp(self) |
| 1492 | |
| 1493 | def pretty_print(self, q): |
| 1494 | q.text("table_stats_entry {") |
| 1495 | with q.group(): |
| 1496 | with q.indent(2): |
| 1497 | q.breakable() |
| 1498 | q.text("table_id = "); |
| 1499 | q.text("%#x" % self.table_id) |
| 1500 | q.text(","); q.breakable() |
| 1501 | q.text("name = "); |
| 1502 | q.pp(self.name) |
| 1503 | q.text(","); q.breakable() |
| 1504 | q.text("wildcards = "); |
| 1505 | q.text(util.pretty_wildcards(self.wildcards)) |
| 1506 | q.text(","); q.breakable() |
| 1507 | q.text("match = "); |
| 1508 | q.pp(self.match) |
| 1509 | q.text(","); q.breakable() |
| 1510 | q.text("instructions = "); |
| 1511 | q.text("%#x" % self.instructions) |
| 1512 | q.text(","); q.breakable() |
| 1513 | q.text("write_actions = "); |
| 1514 | q.text("%#x" % self.write_actions) |
| 1515 | q.text(","); q.breakable() |
| 1516 | q.text("apply_actions = "); |
| 1517 | q.text("%#x" % self.apply_actions) |
| 1518 | q.text(","); q.breakable() |
| 1519 | q.text("config = "); |
| 1520 | q.text("%#x" % self.config) |
| 1521 | q.text(","); q.breakable() |
| 1522 | q.text("max_entries = "); |
| 1523 | q.text("%#x" % self.max_entries) |
| 1524 | q.text(","); q.breakable() |
| 1525 | q.text("active_count = "); |
| 1526 | q.text("%#x" % self.active_count) |
| 1527 | q.text(","); q.breakable() |
| 1528 | q.text("lookup_count = "); |
| 1529 | q.text("%#x" % self.lookup_count) |
| 1530 | q.text(","); q.breakable() |
| 1531 | q.text("matched_count = "); |
| 1532 | q.text("%#x" % self.matched_count) |
| 1533 | q.breakable() |
| 1534 | q.text('}') |
| 1535 | |
| 1536 | |
| 1537 | match = match_v2 |