Rich Lane | b658ddd | 2013-03-12 10:15:10 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2012, 2013, Big Switch Networks, Inc. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
| 16 | # Automatically generated by LOXI from template common.py |
| 17 | # Do not modify |
| 18 | |
| 19 | import sys |
| 20 | import struct |
| 21 | import action |
| 22 | import const |
| 23 | import util |
| 24 | |
| 25 | # HACK make this module visible as 'common' to simplify code generation |
| 26 | common = sys.modules[__name__] |
| 27 | |
| 28 | def unpack_list_flow_stats_entry(buf): |
| 29 | entries = [] |
| 30 | offset = 0 |
| 31 | while offset < len(buf): |
| 32 | length, = struct.unpack_from("!H", buf, offset) |
| 33 | if length == 0: raise loxi.ProtocolError("entry length is 0") |
| 34 | if offset + length > len(buf): raise loxi.ProtocolError("entry length overruns list length") |
| 35 | entries.append(flow_stats_entry.unpack(buffer(buf, offset, length))) |
| 36 | offset += length |
| 37 | return entries |
| 38 | |
| 39 | def unpack_list_queue_prop(buf): |
| 40 | entries = [] |
| 41 | offset = 0 |
| 42 | while offset < len(buf): |
| 43 | type, length, = struct.unpack_from("!HH", buf, offset) |
| 44 | if length == 0: raise loxi.ProtocolError("entry length is 0") |
| 45 | if offset + length > len(buf): raise loxi.ProtocolError("entry length overruns list length") |
| 46 | if type == const.OFPQT_MIN_RATE: |
| 47 | entry = queue_prop_min_rate.unpack(buffer(buf, offset, length)) |
| 48 | else: |
| 49 | raise loxi.ProtocolError("unknown queue prop %d" % type) |
| 50 | entries.append(entry) |
| 51 | offset += length |
| 52 | return entries |
| 53 | |
| 54 | def unpack_list_packet_queue(buf): |
| 55 | entries = [] |
| 56 | offset = 0 |
| 57 | while offset < len(buf): |
| 58 | _, length, = struct.unpack_from("!LH", buf, offset) |
| 59 | if length == 0: raise loxi.ProtocolError("entry length is 0") |
| 60 | if offset + length > len(buf): raise loxi.ProtocolError("entry length overruns list length") |
| 61 | entries.append(packet_queue.unpack(buffer(buf, offset, length))) |
| 62 | offset += length |
| 63 | return entries |
| 64 | |
| 65 | class bsn_interface(object): |
| 66 | |
| 67 | def __init__(self, hw_addr=None, pad=None, name=None, ipv4_addr=None, ipv4_netmask=None): |
| 68 | if hw_addr != None: |
| 69 | self.hw_addr = hw_addr |
| 70 | else: |
| 71 | self.hw_addr = [0,0,0,0,0,0] |
| 72 | if pad != None: |
| 73 | self.pad = pad |
| 74 | else: |
| 75 | self.pad = 0 |
| 76 | if name != None: |
| 77 | self.name = name |
| 78 | else: |
| 79 | self.name = "" |
| 80 | if ipv4_addr != None: |
| 81 | self.ipv4_addr = ipv4_addr |
| 82 | else: |
| 83 | self.ipv4_addr = 0 |
| 84 | if ipv4_netmask != None: |
| 85 | self.ipv4_netmask = ipv4_netmask |
| 86 | else: |
| 87 | self.ipv4_netmask = 0 |
| 88 | |
| 89 | def pack(self): |
| 90 | packed = [] |
| 91 | packed.append(struct.pack("!6B", *self.hw_addr)) |
| 92 | packed.append(struct.pack("!H", self.pad)) |
| 93 | packed.append(struct.pack("!16s", self.name)) |
| 94 | packed.append(struct.pack("!L", self.ipv4_addr)) |
| 95 | packed.append(struct.pack("!L", self.ipv4_netmask)) |
| 96 | return ''.join(packed) |
| 97 | |
| 98 | @staticmethod |
| 99 | def unpack(buf): |
| 100 | assert(len(buf) >= 32) # Should be verified by caller |
| 101 | obj = bsn_interface() |
| 102 | obj.hw_addr = list(struct.unpack_from('!6B', buf, 0)) |
| 103 | obj.pad = struct.unpack_from('!H', buf, 6)[0] |
| 104 | obj.name = str(buffer(buf, 8, 16)).rstrip("\x00") |
| 105 | obj.ipv4_addr = struct.unpack_from('!L', buf, 24)[0] |
| 106 | obj.ipv4_netmask = struct.unpack_from('!L', buf, 28)[0] |
| 107 | return obj |
| 108 | |
| 109 | def __eq__(self, other): |
| 110 | if type(self) != type(other): return False |
| 111 | if self.hw_addr != other.hw_addr: return False |
| 112 | if self.pad != other.pad: return False |
| 113 | if self.name != other.name: return False |
| 114 | if self.ipv4_addr != other.ipv4_addr: return False |
| 115 | if self.ipv4_netmask != other.ipv4_netmask: return False |
| 116 | return True |
| 117 | |
| 118 | def __ne__(self, other): |
| 119 | return not self.__eq__(other) |
| 120 | |
| 121 | def show(self): |
| 122 | import loxi.pp |
| 123 | return loxi.pp.pp(self) |
| 124 | |
| 125 | def pretty_print(self, q): |
| 126 | q.text("bsn_interface {") |
| 127 | with q.group(): |
| 128 | with q.indent(2): |
| 129 | q.breakable() |
| 130 | q.text("hw_addr = "); |
| 131 | q.text(util.pretty_mac(self.hw_addr)) |
| 132 | q.text(","); q.breakable() |
| 133 | q.text("pad = "); |
| 134 | q.text("%#x" % self.pad) |
| 135 | q.text(","); q.breakable() |
| 136 | q.text("name = "); |
| 137 | q.pp(self.name) |
| 138 | q.text(","); q.breakable() |
| 139 | q.text("ipv4_addr = "); |
| 140 | q.text(util.pretty_ipv4(self.ipv4_addr)) |
| 141 | q.text(","); q.breakable() |
| 142 | q.text("ipv4_netmask = "); |
| 143 | q.text(util.pretty_ipv4(self.ipv4_netmask)) |
| 144 | q.breakable() |
| 145 | q.text('}') |
| 146 | |
| 147 | class flow_stats_entry(object): |
| 148 | |
| 149 | def __init__(self, table_id=None, pad=None, match=None, duration_sec=None, duration_nsec=None, priority=None, idle_timeout=None, hard_timeout=None, pad2=None, cookie=None, packet_count=None, byte_count=None, actions=None): |
| 150 | if table_id != None: |
| 151 | self.table_id = table_id |
| 152 | else: |
| 153 | self.table_id = 0 |
| 154 | if pad != None: |
| 155 | self.pad = pad |
| 156 | else: |
| 157 | self.pad = 0 |
| 158 | if match != None: |
| 159 | self.match = match |
| 160 | else: |
| 161 | self.match = common.match() |
| 162 | if duration_sec != None: |
| 163 | self.duration_sec = duration_sec |
| 164 | else: |
| 165 | self.duration_sec = 0 |
| 166 | if duration_nsec != None: |
| 167 | self.duration_nsec = duration_nsec |
| 168 | else: |
| 169 | self.duration_nsec = 0 |
| 170 | if priority != None: |
| 171 | self.priority = priority |
| 172 | else: |
| 173 | self.priority = 0 |
| 174 | if idle_timeout != None: |
| 175 | self.idle_timeout = idle_timeout |
| 176 | else: |
| 177 | self.idle_timeout = 0 |
| 178 | if hard_timeout != None: |
| 179 | self.hard_timeout = hard_timeout |
| 180 | else: |
| 181 | self.hard_timeout = 0 |
| 182 | if pad2 != None: |
| 183 | self.pad2 = pad2 |
| 184 | else: |
| 185 | self.pad2 = [0,0,0,0,0,0] |
| 186 | if cookie != None: |
| 187 | self.cookie = cookie |
| 188 | else: |
| 189 | self.cookie = 0 |
| 190 | if packet_count != None: |
| 191 | self.packet_count = packet_count |
| 192 | else: |
| 193 | self.packet_count = 0 |
| 194 | if byte_count != None: |
| 195 | self.byte_count = byte_count |
| 196 | else: |
| 197 | self.byte_count = 0 |
| 198 | if actions != None: |
| 199 | self.actions = actions |
| 200 | else: |
| 201 | self.actions = [] |
| 202 | |
| 203 | def pack(self): |
| 204 | packed = [] |
| 205 | packed.append(struct.pack("!H", 0)) # placeholder for length at index 0 |
| 206 | packed.append(struct.pack("!B", self.table_id)) |
| 207 | packed.append(struct.pack("!B", self.pad)) |
| 208 | packed.append(self.match.pack()) |
| 209 | packed.append(struct.pack("!L", self.duration_sec)) |
| 210 | packed.append(struct.pack("!L", self.duration_nsec)) |
| 211 | packed.append(struct.pack("!H", self.priority)) |
| 212 | packed.append(struct.pack("!H", self.idle_timeout)) |
| 213 | packed.append(struct.pack("!H", self.hard_timeout)) |
| 214 | packed.append(struct.pack("!6B", *self.pad2)) |
| 215 | packed.append(struct.pack("!Q", self.cookie)) |
| 216 | packed.append(struct.pack("!Q", self.packet_count)) |
| 217 | packed.append(struct.pack("!Q", self.byte_count)) |
| 218 | packed.append("".join([x.pack() for x in self.actions])) |
| 219 | length = sum([len(x) for x in packed]) |
| 220 | packed[0] = struct.pack("!H", length) |
| 221 | return ''.join(packed) |
| 222 | |
| 223 | @staticmethod |
| 224 | def unpack(buf): |
| 225 | assert(len(buf) >= 88) # Should be verified by caller |
| 226 | obj = flow_stats_entry() |
| 227 | _length = struct.unpack_from('!H', buf, 0)[0] |
| 228 | assert(_length == len(buf)) |
| 229 | if _length < 88: raise loxi.ProtocolError("flow_stats_entry length is %d, should be at least 88" % _length) |
| 230 | obj.table_id = struct.unpack_from('!B', buf, 2)[0] |
| 231 | obj.pad = struct.unpack_from('!B', buf, 3)[0] |
| 232 | obj.match = common.match.unpack(buffer(buf, 4)) |
| 233 | obj.duration_sec = struct.unpack_from('!L', buf, 44)[0] |
| 234 | obj.duration_nsec = struct.unpack_from('!L', buf, 48)[0] |
| 235 | obj.priority = struct.unpack_from('!H', buf, 52)[0] |
| 236 | obj.idle_timeout = struct.unpack_from('!H', buf, 54)[0] |
| 237 | obj.hard_timeout = struct.unpack_from('!H', buf, 56)[0] |
| 238 | obj.pad2 = list(struct.unpack_from('!6B', buf, 58)) |
| 239 | obj.cookie = struct.unpack_from('!Q', buf, 64)[0] |
| 240 | obj.packet_count = struct.unpack_from('!Q', buf, 72)[0] |
| 241 | obj.byte_count = struct.unpack_from('!Q', buf, 80)[0] |
| 242 | obj.actions = action.unpack_list(buffer(buf, 88)) |
| 243 | return obj |
| 244 | |
| 245 | def __eq__(self, other): |
| 246 | if type(self) != type(other): return False |
| 247 | if self.table_id != other.table_id: return False |
| 248 | if self.pad != other.pad: return False |
| 249 | if self.match != other.match: return False |
| 250 | if self.duration_sec != other.duration_sec: return False |
| 251 | if self.duration_nsec != other.duration_nsec: return False |
| 252 | if self.priority != other.priority: return False |
| 253 | if self.idle_timeout != other.idle_timeout: return False |
| 254 | if self.hard_timeout != other.hard_timeout: return False |
| 255 | if self.pad2 != other.pad2: return False |
| 256 | if self.cookie != other.cookie: return False |
| 257 | if self.packet_count != other.packet_count: return False |
| 258 | if self.byte_count != other.byte_count: return False |
| 259 | if self.actions != other.actions: return False |
| 260 | return True |
| 261 | |
| 262 | def __ne__(self, other): |
| 263 | return not self.__eq__(other) |
| 264 | |
| 265 | def show(self): |
| 266 | import loxi.pp |
| 267 | return loxi.pp.pp(self) |
| 268 | |
| 269 | def pretty_print(self, q): |
| 270 | q.text("flow_stats_entry {") |
| 271 | with q.group(): |
| 272 | with q.indent(2): |
| 273 | q.breakable() |
| 274 | q.text("table_id = "); |
| 275 | q.text("%#x" % self.table_id) |
| 276 | q.text(","); q.breakable() |
| 277 | q.text("pad = "); |
| 278 | q.text("%#x" % self.pad) |
| 279 | q.text(","); q.breakable() |
| 280 | q.text("match = "); |
| 281 | q.pp(self.match) |
| 282 | q.text(","); q.breakable() |
| 283 | q.text("duration_sec = "); |
| 284 | q.text("%#x" % self.duration_sec) |
| 285 | q.text(","); q.breakable() |
| 286 | q.text("duration_nsec = "); |
| 287 | q.text("%#x" % self.duration_nsec) |
| 288 | q.text(","); q.breakable() |
| 289 | q.text("priority = "); |
| 290 | q.text("%#x" % self.priority) |
| 291 | q.text(","); q.breakable() |
| 292 | q.text("idle_timeout = "); |
| 293 | q.text("%#x" % self.idle_timeout) |
| 294 | q.text(","); q.breakable() |
| 295 | q.text("hard_timeout = "); |
| 296 | q.text("%#x" % self.hard_timeout) |
| 297 | q.text(","); q.breakable() |
| 298 | q.text("pad2 = "); |
| 299 | q.pp(self.pad2) |
| 300 | q.text(","); q.breakable() |
| 301 | q.text("cookie = "); |
| 302 | q.text("%#x" % self.cookie) |
| 303 | q.text(","); q.breakable() |
| 304 | q.text("packet_count = "); |
| 305 | q.text("%#x" % self.packet_count) |
| 306 | q.text(","); q.breakable() |
| 307 | q.text("byte_count = "); |
| 308 | q.text("%#x" % self.byte_count) |
| 309 | q.text(","); q.breakable() |
| 310 | q.text("actions = "); |
| 311 | q.pp(self.actions) |
| 312 | q.breakable() |
| 313 | q.text('}') |
| 314 | |
| 315 | class match_v1(object): |
| 316 | |
| 317 | def __init__(self, wildcards=None, in_port=None, eth_src=None, eth_dst=None, vlan_vid=None, vlan_pcp=None, pad1=None, eth_type=None, ip_dscp=None, ip_proto=None, pad2=None, ipv4_src=None, ipv4_dst=None, tcp_src=None, tcp_dst=None): |
| 318 | if wildcards != None: |
| 319 | self.wildcards = wildcards |
| 320 | else: |
| 321 | self.wildcards = const.OFPFW_ALL |
| 322 | if in_port != None: |
| 323 | self.in_port = in_port |
| 324 | else: |
| 325 | self.in_port = 0 |
| 326 | if eth_src != None: |
| 327 | self.eth_src = eth_src |
| 328 | else: |
| 329 | self.eth_src = [0,0,0,0,0,0] |
| 330 | if eth_dst != None: |
| 331 | self.eth_dst = eth_dst |
| 332 | else: |
| 333 | self.eth_dst = [0,0,0,0,0,0] |
| 334 | if vlan_vid != None: |
| 335 | self.vlan_vid = vlan_vid |
| 336 | else: |
| 337 | self.vlan_vid = 0 |
| 338 | if vlan_pcp != None: |
| 339 | self.vlan_pcp = vlan_pcp |
| 340 | else: |
| 341 | self.vlan_pcp = 0 |
| 342 | if pad1 != None: |
| 343 | self.pad1 = pad1 |
| 344 | else: |
| 345 | self.pad1 = 0 |
| 346 | if eth_type != None: |
| 347 | self.eth_type = eth_type |
| 348 | else: |
| 349 | self.eth_type = 0 |
| 350 | if ip_dscp != None: |
| 351 | self.ip_dscp = ip_dscp |
| 352 | else: |
| 353 | self.ip_dscp = 0 |
| 354 | if ip_proto != None: |
| 355 | self.ip_proto = ip_proto |
| 356 | else: |
| 357 | self.ip_proto = 0 |
| 358 | if pad2 != None: |
| 359 | self.pad2 = pad2 |
| 360 | else: |
| 361 | self.pad2 = [0,0] |
| 362 | if ipv4_src != None: |
| 363 | self.ipv4_src = ipv4_src |
| 364 | else: |
| 365 | self.ipv4_src = 0 |
| 366 | if ipv4_dst != None: |
| 367 | self.ipv4_dst = ipv4_dst |
| 368 | else: |
| 369 | self.ipv4_dst = 0 |
| 370 | if tcp_src != None: |
| 371 | self.tcp_src = tcp_src |
| 372 | else: |
| 373 | self.tcp_src = 0 |
| 374 | if tcp_dst != None: |
| 375 | self.tcp_dst = tcp_dst |
| 376 | else: |
| 377 | self.tcp_dst = 0 |
| 378 | |
| 379 | def pack(self): |
| 380 | packed = [] |
| 381 | packed.append(struct.pack("!L", self.wildcards)) |
| 382 | packed.append(struct.pack("!H", self.in_port)) |
| 383 | packed.append(struct.pack("!6B", *self.eth_src)) |
| 384 | packed.append(struct.pack("!6B", *self.eth_dst)) |
| 385 | packed.append(struct.pack("!H", self.vlan_vid)) |
| 386 | packed.append(struct.pack("!B", self.vlan_pcp)) |
| 387 | packed.append(struct.pack("!B", self.pad1)) |
| 388 | packed.append(struct.pack("!H", self.eth_type)) |
| 389 | packed.append(struct.pack("!B", self.ip_dscp)) |
| 390 | packed.append(struct.pack("!B", self.ip_proto)) |
| 391 | packed.append(struct.pack("!2B", *self.pad2)) |
| 392 | packed.append(struct.pack("!L", self.ipv4_src)) |
| 393 | packed.append(struct.pack("!L", self.ipv4_dst)) |
| 394 | packed.append(struct.pack("!H", self.tcp_src)) |
| 395 | packed.append(struct.pack("!H", self.tcp_dst)) |
| 396 | return ''.join(packed) |
| 397 | |
| 398 | @staticmethod |
| 399 | def unpack(buf): |
| 400 | assert(len(buf) >= 40) # Should be verified by caller |
| 401 | obj = match_v1() |
| 402 | obj.wildcards = struct.unpack_from('!L', buf, 0)[0] |
| 403 | obj.in_port = struct.unpack_from('!H', buf, 4)[0] |
| 404 | obj.eth_src = list(struct.unpack_from('!6B', buf, 6)) |
| 405 | obj.eth_dst = list(struct.unpack_from('!6B', buf, 12)) |
| 406 | obj.vlan_vid = struct.unpack_from('!H', buf, 18)[0] |
| 407 | obj.vlan_pcp = struct.unpack_from('!B', buf, 20)[0] |
| 408 | obj.pad1 = struct.unpack_from('!B', buf, 21)[0] |
| 409 | obj.eth_type = struct.unpack_from('!H', buf, 22)[0] |
| 410 | obj.ip_dscp = struct.unpack_from('!B', buf, 24)[0] |
| 411 | obj.ip_proto = struct.unpack_from('!B', buf, 25)[0] |
| 412 | obj.pad2 = list(struct.unpack_from('!2B', buf, 26)) |
| 413 | obj.ipv4_src = struct.unpack_from('!L', buf, 28)[0] |
| 414 | obj.ipv4_dst = struct.unpack_from('!L', buf, 32)[0] |
| 415 | obj.tcp_src = struct.unpack_from('!H', buf, 36)[0] |
| 416 | obj.tcp_dst = struct.unpack_from('!H', buf, 38)[0] |
| 417 | return obj |
| 418 | |
| 419 | def __eq__(self, other): |
| 420 | if type(self) != type(other): return False |
| 421 | if self.wildcards != other.wildcards: return False |
| 422 | if self.in_port != other.in_port: return False |
| 423 | if self.eth_src != other.eth_src: return False |
| 424 | if self.eth_dst != other.eth_dst: return False |
| 425 | if self.vlan_vid != other.vlan_vid: return False |
| 426 | if self.vlan_pcp != other.vlan_pcp: return False |
| 427 | if self.pad1 != other.pad1: return False |
| 428 | if self.eth_type != other.eth_type: return False |
| 429 | if self.ip_dscp != other.ip_dscp: return False |
| 430 | if self.ip_proto != other.ip_proto: return False |
| 431 | if self.pad2 != other.pad2: return False |
| 432 | if self.ipv4_src != other.ipv4_src: return False |
| 433 | if self.ipv4_dst != other.ipv4_dst: return False |
| 434 | if self.tcp_src != other.tcp_src: return False |
| 435 | if self.tcp_dst != other.tcp_dst: return False |
| 436 | return True |
| 437 | |
| 438 | def __ne__(self, other): |
| 439 | return not self.__eq__(other) |
| 440 | |
| 441 | def show(self): |
| 442 | import loxi.pp |
| 443 | return loxi.pp.pp(self) |
| 444 | |
| 445 | def pretty_print(self, q): |
| 446 | q.text("match_v1 {") |
| 447 | with q.group(): |
| 448 | with q.indent(2): |
| 449 | q.breakable() |
| 450 | q.text("wildcards = "); |
| 451 | q.text(util.pretty_wildcards(self.wildcards)) |
| 452 | q.text(","); q.breakable() |
| 453 | q.text("in_port = "); |
| 454 | q.text(util.pretty_port(self.in_port)) |
| 455 | q.text(","); q.breakable() |
| 456 | q.text("eth_src = "); |
| 457 | q.text(util.pretty_mac(self.eth_src)) |
| 458 | q.text(","); q.breakable() |
| 459 | q.text("eth_dst = "); |
| 460 | q.text(util.pretty_mac(self.eth_dst)) |
| 461 | q.text(","); q.breakable() |
| 462 | q.text("vlan_vid = "); |
| 463 | q.text("%#x" % self.vlan_vid) |
| 464 | q.text(","); q.breakable() |
| 465 | q.text("vlan_pcp = "); |
| 466 | q.text("%#x" % self.vlan_pcp) |
| 467 | q.text(","); q.breakable() |
| 468 | q.text("pad1 = "); |
| 469 | q.text("%#x" % self.pad1) |
| 470 | q.text(","); q.breakable() |
| 471 | q.text("eth_type = "); |
| 472 | q.text("%#x" % self.eth_type) |
| 473 | q.text(","); q.breakable() |
| 474 | q.text("ip_dscp = "); |
| 475 | q.text("%#x" % self.ip_dscp) |
| 476 | q.text(","); q.breakable() |
| 477 | q.text("ip_proto = "); |
| 478 | q.text("%#x" % self.ip_proto) |
| 479 | q.text(","); q.breakable() |
| 480 | q.text("pad2 = "); |
| 481 | q.pp(self.pad2) |
| 482 | q.text(","); q.breakable() |
| 483 | q.text("ipv4_src = "); |
| 484 | q.text(util.pretty_ipv4(self.ipv4_src)) |
| 485 | q.text(","); q.breakable() |
| 486 | q.text("ipv4_dst = "); |
| 487 | q.text(util.pretty_ipv4(self.ipv4_dst)) |
| 488 | q.text(","); q.breakable() |
| 489 | q.text("tcp_src = "); |
| 490 | q.text("%#x" % self.tcp_src) |
| 491 | q.text(","); q.breakable() |
| 492 | q.text("tcp_dst = "); |
| 493 | q.text("%#x" % self.tcp_dst) |
| 494 | q.breakable() |
| 495 | q.text('}') |
| 496 | |
| 497 | match = match_v1 |
| 498 | |
| 499 | class packet_queue(object): |
| 500 | |
| 501 | def __init__(self, queue_id=None, pad=None, properties=None): |
| 502 | if queue_id != None: |
| 503 | self.queue_id = queue_id |
| 504 | else: |
| 505 | self.queue_id = 0 |
| 506 | if pad != None: |
| 507 | self.pad = pad |
| 508 | else: |
| 509 | self.pad = [0,0] |
| 510 | if properties != None: |
| 511 | self.properties = properties |
| 512 | else: |
| 513 | self.properties = [] |
| 514 | |
| 515 | def pack(self): |
| 516 | packed = [] |
| 517 | packed.append(struct.pack("!L", self.queue_id)) |
| 518 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 519 | packed.append(struct.pack("!2B", *self.pad)) |
| 520 | packed.append("".join([x.pack() for x in self.properties])) |
| 521 | length = sum([len(x) for x in packed]) |
| 522 | packed[1] = struct.pack("!H", length) |
| 523 | return ''.join(packed) |
| 524 | |
| 525 | @staticmethod |
| 526 | def unpack(buf): |
| 527 | assert(len(buf) >= 8) # Should be verified by caller |
| 528 | obj = packet_queue() |
| 529 | obj.queue_id = struct.unpack_from('!L', buf, 0)[0] |
| 530 | _length = struct.unpack_from('!H', buf, 4)[0] |
| 531 | assert(_length == len(buf)) |
| 532 | if _length < 8: raise loxi.ProtocolError("packet_queue length is %d, should be at least 8" % _length) |
| 533 | obj.pad = list(struct.unpack_from('!2B', buf, 6)) |
| 534 | obj.properties = common.unpack_list_queue_prop(buffer(buf, 8)) |
| 535 | return obj |
| 536 | |
| 537 | def __eq__(self, other): |
| 538 | if type(self) != type(other): return False |
| 539 | if self.queue_id != other.queue_id: return False |
| 540 | if self.pad != other.pad: return False |
| 541 | if self.properties != other.properties: return False |
| 542 | return True |
| 543 | |
| 544 | def __ne__(self, other): |
| 545 | return not self.__eq__(other) |
| 546 | |
| 547 | def show(self): |
| 548 | import loxi.pp |
| 549 | return loxi.pp.pp(self) |
| 550 | |
| 551 | def pretty_print(self, q): |
| 552 | q.text("packet_queue {") |
| 553 | with q.group(): |
| 554 | with q.indent(2): |
| 555 | q.breakable() |
| 556 | q.text("queue_id = "); |
| 557 | q.text("%#x" % self.queue_id) |
| 558 | q.text(","); q.breakable() |
| 559 | q.text("pad = "); |
| 560 | q.pp(self.pad) |
| 561 | q.text(","); q.breakable() |
| 562 | q.text("properties = "); |
| 563 | q.pp(self.properties) |
| 564 | q.breakable() |
| 565 | q.text('}') |
| 566 | |
| 567 | class port_desc(object): |
| 568 | |
| 569 | def __init__(self, port_no=None, hw_addr=None, name=None, config=None, state=None, curr=None, advertised=None, supported=None, peer=None): |
| 570 | if port_no != None: |
| 571 | self.port_no = port_no |
| 572 | else: |
| 573 | self.port_no = 0 |
| 574 | if hw_addr != None: |
| 575 | self.hw_addr = hw_addr |
| 576 | else: |
| 577 | self.hw_addr = [0,0,0,0,0,0] |
| 578 | if name != None: |
| 579 | self.name = name |
| 580 | else: |
| 581 | self.name = "" |
| 582 | if config != None: |
| 583 | self.config = config |
| 584 | else: |
| 585 | self.config = 0 |
| 586 | if state != None: |
| 587 | self.state = state |
| 588 | else: |
| 589 | self.state = 0 |
| 590 | if curr != None: |
| 591 | self.curr = curr |
| 592 | else: |
| 593 | self.curr = 0 |
| 594 | if advertised != None: |
| 595 | self.advertised = advertised |
| 596 | else: |
| 597 | self.advertised = 0 |
| 598 | if supported != None: |
| 599 | self.supported = supported |
| 600 | else: |
| 601 | self.supported = 0 |
| 602 | if peer != None: |
| 603 | self.peer = peer |
| 604 | else: |
| 605 | self.peer = 0 |
| 606 | |
| 607 | def pack(self): |
| 608 | packed = [] |
| 609 | packed.append(struct.pack("!H", self.port_no)) |
| 610 | packed.append(struct.pack("!6B", *self.hw_addr)) |
| 611 | packed.append(struct.pack("!16s", self.name)) |
| 612 | packed.append(struct.pack("!L", self.config)) |
| 613 | packed.append(struct.pack("!L", self.state)) |
| 614 | packed.append(struct.pack("!L", self.curr)) |
| 615 | packed.append(struct.pack("!L", self.advertised)) |
| 616 | packed.append(struct.pack("!L", self.supported)) |
| 617 | packed.append(struct.pack("!L", self.peer)) |
| 618 | return ''.join(packed) |
| 619 | |
| 620 | @staticmethod |
| 621 | def unpack(buf): |
| 622 | assert(len(buf) >= 48) # Should be verified by caller |
| 623 | obj = port_desc() |
| 624 | obj.port_no = struct.unpack_from('!H', buf, 0)[0] |
| 625 | obj.hw_addr = list(struct.unpack_from('!6B', buf, 2)) |
| 626 | obj.name = str(buffer(buf, 8, 16)).rstrip("\x00") |
| 627 | obj.config = struct.unpack_from('!L', buf, 24)[0] |
| 628 | obj.state = struct.unpack_from('!L', buf, 28)[0] |
| 629 | obj.curr = struct.unpack_from('!L', buf, 32)[0] |
| 630 | obj.advertised = struct.unpack_from('!L', buf, 36)[0] |
| 631 | obj.supported = struct.unpack_from('!L', buf, 40)[0] |
| 632 | obj.peer = struct.unpack_from('!L', buf, 44)[0] |
| 633 | return obj |
| 634 | |
| 635 | def __eq__(self, other): |
| 636 | if type(self) != type(other): return False |
| 637 | if self.port_no != other.port_no: return False |
| 638 | if self.hw_addr != other.hw_addr: return False |
| 639 | if self.name != other.name: return False |
| 640 | if self.config != other.config: return False |
| 641 | if self.state != other.state: return False |
| 642 | if self.curr != other.curr: return False |
| 643 | if self.advertised != other.advertised: return False |
| 644 | if self.supported != other.supported: return False |
| 645 | if self.peer != other.peer: return False |
| 646 | return True |
| 647 | |
| 648 | def __ne__(self, other): |
| 649 | return not self.__eq__(other) |
| 650 | |
| 651 | def show(self): |
| 652 | import loxi.pp |
| 653 | return loxi.pp.pp(self) |
| 654 | |
| 655 | def pretty_print(self, q): |
| 656 | q.text("port_desc {") |
| 657 | with q.group(): |
| 658 | with q.indent(2): |
| 659 | q.breakable() |
| 660 | q.text("port_no = "); |
| 661 | q.text(util.pretty_port(self.port_no)) |
| 662 | q.text(","); q.breakable() |
| 663 | q.text("hw_addr = "); |
| 664 | q.text(util.pretty_mac(self.hw_addr)) |
| 665 | q.text(","); q.breakable() |
| 666 | q.text("name = "); |
| 667 | q.pp(self.name) |
| 668 | q.text(","); q.breakable() |
| 669 | q.text("config = "); |
| 670 | q.text("%#x" % self.config) |
| 671 | q.text(","); q.breakable() |
| 672 | q.text("state = "); |
| 673 | q.text("%#x" % self.state) |
| 674 | q.text(","); q.breakable() |
| 675 | q.text("curr = "); |
| 676 | q.text("%#x" % self.curr) |
| 677 | q.text(","); q.breakable() |
| 678 | q.text("advertised = "); |
| 679 | q.text("%#x" % self.advertised) |
| 680 | q.text(","); q.breakable() |
| 681 | q.text("supported = "); |
| 682 | q.text("%#x" % self.supported) |
| 683 | q.text(","); q.breakable() |
| 684 | q.text("peer = "); |
| 685 | q.text("%#x" % self.peer) |
| 686 | q.breakable() |
| 687 | q.text('}') |
| 688 | |
| 689 | class port_stats_entry(object): |
| 690 | |
| 691 | def __init__(self, port_no=None, pad=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): |
| 692 | if port_no != None: |
| 693 | self.port_no = port_no |
| 694 | else: |
| 695 | self.port_no = 0 |
| 696 | if pad != None: |
| 697 | self.pad = pad |
| 698 | else: |
| 699 | self.pad = [0,0,0,0,0,0] |
| 700 | if rx_packets != None: |
| 701 | self.rx_packets = rx_packets |
| 702 | else: |
| 703 | self.rx_packets = 0 |
| 704 | if tx_packets != None: |
| 705 | self.tx_packets = tx_packets |
| 706 | else: |
| 707 | self.tx_packets = 0 |
| 708 | if rx_bytes != None: |
| 709 | self.rx_bytes = rx_bytes |
| 710 | else: |
| 711 | self.rx_bytes = 0 |
| 712 | if tx_bytes != None: |
| 713 | self.tx_bytes = tx_bytes |
| 714 | else: |
| 715 | self.tx_bytes = 0 |
| 716 | if rx_dropped != None: |
| 717 | self.rx_dropped = rx_dropped |
| 718 | else: |
| 719 | self.rx_dropped = 0 |
| 720 | if tx_dropped != None: |
| 721 | self.tx_dropped = tx_dropped |
| 722 | else: |
| 723 | self.tx_dropped = 0 |
| 724 | if rx_errors != None: |
| 725 | self.rx_errors = rx_errors |
| 726 | else: |
| 727 | self.rx_errors = 0 |
| 728 | if tx_errors != None: |
| 729 | self.tx_errors = tx_errors |
| 730 | else: |
| 731 | self.tx_errors = 0 |
| 732 | if rx_frame_err != None: |
| 733 | self.rx_frame_err = rx_frame_err |
| 734 | else: |
| 735 | self.rx_frame_err = 0 |
| 736 | if rx_over_err != None: |
| 737 | self.rx_over_err = rx_over_err |
| 738 | else: |
| 739 | self.rx_over_err = 0 |
| 740 | if rx_crc_err != None: |
| 741 | self.rx_crc_err = rx_crc_err |
| 742 | else: |
| 743 | self.rx_crc_err = 0 |
| 744 | if collisions != None: |
| 745 | self.collisions = collisions |
| 746 | else: |
| 747 | self.collisions = 0 |
| 748 | |
| 749 | def pack(self): |
| 750 | packed = [] |
| 751 | packed.append(struct.pack("!H", self.port_no)) |
| 752 | packed.append(struct.pack("!6B", *self.pad)) |
| 753 | packed.append(struct.pack("!Q", self.rx_packets)) |
| 754 | packed.append(struct.pack("!Q", self.tx_packets)) |
| 755 | packed.append(struct.pack("!Q", self.rx_bytes)) |
| 756 | packed.append(struct.pack("!Q", self.tx_bytes)) |
| 757 | packed.append(struct.pack("!Q", self.rx_dropped)) |
| 758 | packed.append(struct.pack("!Q", self.tx_dropped)) |
| 759 | packed.append(struct.pack("!Q", self.rx_errors)) |
| 760 | packed.append(struct.pack("!Q", self.tx_errors)) |
| 761 | packed.append(struct.pack("!Q", self.rx_frame_err)) |
| 762 | packed.append(struct.pack("!Q", self.rx_over_err)) |
| 763 | packed.append(struct.pack("!Q", self.rx_crc_err)) |
| 764 | packed.append(struct.pack("!Q", self.collisions)) |
| 765 | return ''.join(packed) |
| 766 | |
| 767 | @staticmethod |
| 768 | def unpack(buf): |
| 769 | assert(len(buf) >= 104) # Should be verified by caller |
| 770 | obj = port_stats_entry() |
| 771 | obj.port_no = struct.unpack_from('!H', buf, 0)[0] |
| 772 | obj.pad = list(struct.unpack_from('!6B', buf, 2)) |
| 773 | obj.rx_packets = struct.unpack_from('!Q', buf, 8)[0] |
| 774 | obj.tx_packets = struct.unpack_from('!Q', buf, 16)[0] |
| 775 | obj.rx_bytes = struct.unpack_from('!Q', buf, 24)[0] |
| 776 | obj.tx_bytes = struct.unpack_from('!Q', buf, 32)[0] |
| 777 | obj.rx_dropped = struct.unpack_from('!Q', buf, 40)[0] |
| 778 | obj.tx_dropped = struct.unpack_from('!Q', buf, 48)[0] |
| 779 | obj.rx_errors = struct.unpack_from('!Q', buf, 56)[0] |
| 780 | obj.tx_errors = struct.unpack_from('!Q', buf, 64)[0] |
| 781 | obj.rx_frame_err = struct.unpack_from('!Q', buf, 72)[0] |
| 782 | obj.rx_over_err = struct.unpack_from('!Q', buf, 80)[0] |
| 783 | obj.rx_crc_err = struct.unpack_from('!Q', buf, 88)[0] |
| 784 | obj.collisions = struct.unpack_from('!Q', buf, 96)[0] |
| 785 | return obj |
| 786 | |
| 787 | def __eq__(self, other): |
| 788 | if type(self) != type(other): return False |
| 789 | if self.port_no != other.port_no: return False |
| 790 | if self.pad != other.pad: return False |
| 791 | if self.rx_packets != other.rx_packets: return False |
| 792 | if self.tx_packets != other.tx_packets: return False |
| 793 | if self.rx_bytes != other.rx_bytes: return False |
| 794 | if self.tx_bytes != other.tx_bytes: return False |
| 795 | if self.rx_dropped != other.rx_dropped: return False |
| 796 | if self.tx_dropped != other.tx_dropped: return False |
| 797 | if self.rx_errors != other.rx_errors: return False |
| 798 | if self.tx_errors != other.tx_errors: return False |
| 799 | if self.rx_frame_err != other.rx_frame_err: return False |
| 800 | if self.rx_over_err != other.rx_over_err: return False |
| 801 | if self.rx_crc_err != other.rx_crc_err: return False |
| 802 | if self.collisions != other.collisions: return False |
| 803 | return True |
| 804 | |
| 805 | def __ne__(self, other): |
| 806 | return not self.__eq__(other) |
| 807 | |
| 808 | def show(self): |
| 809 | import loxi.pp |
| 810 | return loxi.pp.pp(self) |
| 811 | |
| 812 | def pretty_print(self, q): |
| 813 | q.text("port_stats_entry {") |
| 814 | with q.group(): |
| 815 | with q.indent(2): |
| 816 | q.breakable() |
| 817 | q.text("port_no = "); |
| 818 | q.text(util.pretty_port(self.port_no)) |
| 819 | q.text(","); q.breakable() |
| 820 | q.text("pad = "); |
| 821 | q.pp(self.pad) |
| 822 | q.text(","); q.breakable() |
| 823 | q.text("rx_packets = "); |
| 824 | q.text("%#x" % self.rx_packets) |
| 825 | q.text(","); q.breakable() |
| 826 | q.text("tx_packets = "); |
| 827 | q.text("%#x" % self.tx_packets) |
| 828 | q.text(","); q.breakable() |
| 829 | q.text("rx_bytes = "); |
| 830 | q.text("%#x" % self.rx_bytes) |
| 831 | q.text(","); q.breakable() |
| 832 | q.text("tx_bytes = "); |
| 833 | q.text("%#x" % self.tx_bytes) |
| 834 | q.text(","); q.breakable() |
| 835 | q.text("rx_dropped = "); |
| 836 | q.text("%#x" % self.rx_dropped) |
| 837 | q.text(","); q.breakable() |
| 838 | q.text("tx_dropped = "); |
| 839 | q.text("%#x" % self.tx_dropped) |
| 840 | q.text(","); q.breakable() |
| 841 | q.text("rx_errors = "); |
| 842 | q.text("%#x" % self.rx_errors) |
| 843 | q.text(","); q.breakable() |
| 844 | q.text("tx_errors = "); |
| 845 | q.text("%#x" % self.tx_errors) |
| 846 | q.text(","); q.breakable() |
| 847 | q.text("rx_frame_err = "); |
| 848 | q.text("%#x" % self.rx_frame_err) |
| 849 | q.text(","); q.breakable() |
| 850 | q.text("rx_over_err = "); |
| 851 | q.text("%#x" % self.rx_over_err) |
| 852 | q.text(","); q.breakable() |
| 853 | q.text("rx_crc_err = "); |
| 854 | q.text("%#x" % self.rx_crc_err) |
| 855 | q.text(","); q.breakable() |
| 856 | q.text("collisions = "); |
| 857 | q.text("%#x" % self.collisions) |
| 858 | q.breakable() |
| 859 | q.text('}') |
| 860 | |
| 861 | class queue_prop_min_rate(object): |
| 862 | type = const.OFPQT_MIN_RATE |
| 863 | |
| 864 | def __init__(self, pad=None, rate=None, pad2=None): |
| 865 | if pad != None: |
| 866 | self.pad = pad |
| 867 | else: |
| 868 | self.pad = [0,0,0,0] |
| 869 | if rate != None: |
| 870 | self.rate = rate |
| 871 | else: |
| 872 | self.rate = 0 |
| 873 | if pad2 != None: |
| 874 | self.pad2 = pad2 |
| 875 | else: |
| 876 | self.pad2 = [0,0,0,0,0,0] |
| 877 | |
| 878 | def pack(self): |
| 879 | packed = [] |
| 880 | packed.append(struct.pack("!H", self.type)) |
| 881 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 882 | packed.append(struct.pack("!4B", *self.pad)) |
| 883 | packed.append(struct.pack("!H", self.rate)) |
| 884 | packed.append(struct.pack("!6B", *self.pad2)) |
| 885 | length = sum([len(x) for x in packed]) |
| 886 | packed[1] = struct.pack("!H", length) |
| 887 | return ''.join(packed) |
| 888 | |
| 889 | @staticmethod |
| 890 | def unpack(buf): |
| 891 | assert(len(buf) >= 16) # Should be verified by caller |
| 892 | obj = queue_prop_min_rate() |
| 893 | type = struct.unpack_from('!H', buf, 0)[0] |
| 894 | assert(type == const.OFPQT_MIN_RATE) |
| 895 | _length = struct.unpack_from('!H', buf, 2)[0] |
| 896 | assert(_length == len(buf)) |
| 897 | if _length != 16: raise loxi.ProtocolError("queue_prop_min_rate length is %d, should be 16" % _length) |
| 898 | obj.pad = list(struct.unpack_from('!4B', buf, 4)) |
| 899 | obj.rate = struct.unpack_from('!H', buf, 8)[0] |
| 900 | obj.pad2 = list(struct.unpack_from('!6B', buf, 10)) |
| 901 | return obj |
| 902 | |
| 903 | def __eq__(self, other): |
| 904 | if type(self) != type(other): return False |
| 905 | if self.pad != other.pad: return False |
| 906 | if self.rate != other.rate: return False |
| 907 | if self.pad2 != other.pad2: return False |
| 908 | return True |
| 909 | |
| 910 | def __ne__(self, other): |
| 911 | return not self.__eq__(other) |
| 912 | |
| 913 | def show(self): |
| 914 | import loxi.pp |
| 915 | return loxi.pp.pp(self) |
| 916 | |
| 917 | def pretty_print(self, q): |
| 918 | q.text("queue_prop_min_rate {") |
| 919 | with q.group(): |
| 920 | with q.indent(2): |
| 921 | q.breakable() |
| 922 | q.text("pad = "); |
| 923 | q.pp(self.pad) |
| 924 | q.text(","); q.breakable() |
| 925 | q.text("rate = "); |
| 926 | q.text("%#x" % self.rate) |
| 927 | q.text(","); q.breakable() |
| 928 | q.text("pad2 = "); |
| 929 | q.pp(self.pad2) |
| 930 | q.breakable() |
| 931 | q.text('}') |
| 932 | |
| 933 | class queue_stats_entry(object): |
| 934 | |
| 935 | def __init__(self, port_no=None, pad=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None): |
| 936 | if port_no != None: |
| 937 | self.port_no = port_no |
| 938 | else: |
| 939 | self.port_no = 0 |
| 940 | if pad != None: |
| 941 | self.pad = pad |
| 942 | else: |
| 943 | self.pad = [0,0] |
| 944 | if queue_id != None: |
| 945 | self.queue_id = queue_id |
| 946 | else: |
| 947 | self.queue_id = 0 |
| 948 | if tx_bytes != None: |
| 949 | self.tx_bytes = tx_bytes |
| 950 | else: |
| 951 | self.tx_bytes = 0 |
| 952 | if tx_packets != None: |
| 953 | self.tx_packets = tx_packets |
| 954 | else: |
| 955 | self.tx_packets = 0 |
| 956 | if tx_errors != None: |
| 957 | self.tx_errors = tx_errors |
| 958 | else: |
| 959 | self.tx_errors = 0 |
| 960 | |
| 961 | def pack(self): |
| 962 | packed = [] |
| 963 | packed.append(struct.pack("!H", self.port_no)) |
| 964 | packed.append(struct.pack("!2B", *self.pad)) |
| 965 | packed.append(struct.pack("!L", self.queue_id)) |
| 966 | packed.append(struct.pack("!Q", self.tx_bytes)) |
| 967 | packed.append(struct.pack("!Q", self.tx_packets)) |
| 968 | packed.append(struct.pack("!Q", self.tx_errors)) |
| 969 | return ''.join(packed) |
| 970 | |
| 971 | @staticmethod |
| 972 | def unpack(buf): |
| 973 | assert(len(buf) >= 32) # Should be verified by caller |
| 974 | obj = queue_stats_entry() |
| 975 | obj.port_no = struct.unpack_from('!H', buf, 0)[0] |
| 976 | obj.pad = list(struct.unpack_from('!2B', buf, 2)) |
| 977 | obj.queue_id = struct.unpack_from('!L', buf, 4)[0] |
| 978 | obj.tx_bytes = struct.unpack_from('!Q', buf, 8)[0] |
| 979 | obj.tx_packets = struct.unpack_from('!Q', buf, 16)[0] |
| 980 | obj.tx_errors = struct.unpack_from('!Q', buf, 24)[0] |
| 981 | return obj |
| 982 | |
| 983 | def __eq__(self, other): |
| 984 | if type(self) != type(other): return False |
| 985 | if self.port_no != other.port_no: return False |
| 986 | if self.pad != other.pad: return False |
| 987 | if self.queue_id != other.queue_id: return False |
| 988 | if self.tx_bytes != other.tx_bytes: return False |
| 989 | if self.tx_packets != other.tx_packets: return False |
| 990 | if self.tx_errors != other.tx_errors: return False |
| 991 | return True |
| 992 | |
| 993 | def __ne__(self, other): |
| 994 | return not self.__eq__(other) |
| 995 | |
| 996 | def show(self): |
| 997 | import loxi.pp |
| 998 | return loxi.pp.pp(self) |
| 999 | |
| 1000 | def pretty_print(self, q): |
| 1001 | q.text("queue_stats_entry {") |
| 1002 | with q.group(): |
| 1003 | with q.indent(2): |
| 1004 | q.breakable() |
| 1005 | q.text("port_no = "); |
| 1006 | q.text(util.pretty_port(self.port_no)) |
| 1007 | q.text(","); q.breakable() |
| 1008 | q.text("pad = "); |
| 1009 | q.pp(self.pad) |
| 1010 | q.text(","); q.breakable() |
| 1011 | q.text("queue_id = "); |
| 1012 | q.text("%#x" % self.queue_id) |
| 1013 | q.text(","); q.breakable() |
| 1014 | q.text("tx_bytes = "); |
| 1015 | q.text("%#x" % self.tx_bytes) |
| 1016 | q.text(","); q.breakable() |
| 1017 | q.text("tx_packets = "); |
| 1018 | q.text("%#x" % self.tx_packets) |
| 1019 | q.text(","); q.breakable() |
| 1020 | q.text("tx_errors = "); |
| 1021 | q.text("%#x" % self.tx_errors) |
| 1022 | q.breakable() |
| 1023 | q.text('}') |
| 1024 | |
| 1025 | class table_stats_entry(object): |
| 1026 | |
| 1027 | def __init__(self, table_id=None, pad=None, name=None, wildcards=None, max_entries=None, active_count=None, lookup_count=None, matched_count=None): |
| 1028 | if table_id != None: |
| 1029 | self.table_id = table_id |
| 1030 | else: |
| 1031 | self.table_id = 0 |
| 1032 | if pad != None: |
| 1033 | self.pad = pad |
| 1034 | else: |
| 1035 | self.pad = [0,0,0] |
| 1036 | if name != None: |
| 1037 | self.name = name |
| 1038 | else: |
| 1039 | self.name = "" |
| 1040 | if wildcards != None: |
| 1041 | self.wildcards = wildcards |
| 1042 | else: |
| 1043 | self.wildcards = const.OFPFW_ALL |
| 1044 | if max_entries != None: |
| 1045 | self.max_entries = max_entries |
| 1046 | else: |
| 1047 | self.max_entries = 0 |
| 1048 | if active_count != None: |
| 1049 | self.active_count = active_count |
| 1050 | else: |
| 1051 | self.active_count = 0 |
| 1052 | if lookup_count != None: |
| 1053 | self.lookup_count = lookup_count |
| 1054 | else: |
| 1055 | self.lookup_count = 0 |
| 1056 | if matched_count != None: |
| 1057 | self.matched_count = matched_count |
| 1058 | else: |
| 1059 | self.matched_count = 0 |
| 1060 | |
| 1061 | def pack(self): |
| 1062 | packed = [] |
| 1063 | packed.append(struct.pack("!B", self.table_id)) |
| 1064 | packed.append(struct.pack("!3B", *self.pad)) |
| 1065 | packed.append(struct.pack("!32s", self.name)) |
| 1066 | packed.append(struct.pack("!L", self.wildcards)) |
| 1067 | packed.append(struct.pack("!L", self.max_entries)) |
| 1068 | packed.append(struct.pack("!L", self.active_count)) |
| 1069 | packed.append(struct.pack("!Q", self.lookup_count)) |
| 1070 | packed.append(struct.pack("!Q", self.matched_count)) |
| 1071 | return ''.join(packed) |
| 1072 | |
| 1073 | @staticmethod |
| 1074 | def unpack(buf): |
| 1075 | assert(len(buf) >= 64) # Should be verified by caller |
| 1076 | obj = table_stats_entry() |
| 1077 | obj.table_id = struct.unpack_from('!B', buf, 0)[0] |
| 1078 | obj.pad = list(struct.unpack_from('!3B', buf, 1)) |
| 1079 | obj.name = str(buffer(buf, 4, 32)).rstrip("\x00") |
| 1080 | obj.wildcards = struct.unpack_from('!L', buf, 36)[0] |
| 1081 | obj.max_entries = struct.unpack_from('!L', buf, 40)[0] |
| 1082 | obj.active_count = struct.unpack_from('!L', buf, 44)[0] |
| 1083 | obj.lookup_count = struct.unpack_from('!Q', buf, 48)[0] |
| 1084 | obj.matched_count = struct.unpack_from('!Q', buf, 56)[0] |
| 1085 | return obj |
| 1086 | |
| 1087 | def __eq__(self, other): |
| 1088 | if type(self) != type(other): return False |
| 1089 | if self.table_id != other.table_id: return False |
| 1090 | if self.pad != other.pad: return False |
| 1091 | if self.name != other.name: return False |
| 1092 | if self.wildcards != other.wildcards: return False |
| 1093 | if self.max_entries != other.max_entries: return False |
| 1094 | if self.active_count != other.active_count: return False |
| 1095 | if self.lookup_count != other.lookup_count: return False |
| 1096 | if self.matched_count != other.matched_count: return False |
| 1097 | return True |
| 1098 | |
| 1099 | def __ne__(self, other): |
| 1100 | return not self.__eq__(other) |
| 1101 | |
| 1102 | def show(self): |
| 1103 | import loxi.pp |
| 1104 | return loxi.pp.pp(self) |
| 1105 | |
| 1106 | def pretty_print(self, q): |
| 1107 | q.text("table_stats_entry {") |
| 1108 | with q.group(): |
| 1109 | with q.indent(2): |
| 1110 | q.breakable() |
| 1111 | q.text("table_id = "); |
| 1112 | q.text("%#x" % self.table_id) |
| 1113 | q.text(","); q.breakable() |
| 1114 | q.text("pad = "); |
| 1115 | q.pp(self.pad) |
| 1116 | q.text(","); q.breakable() |
| 1117 | q.text("name = "); |
| 1118 | q.pp(self.name) |
| 1119 | q.text(","); q.breakable() |
| 1120 | q.text("wildcards = "); |
| 1121 | q.text(util.pretty_wildcards(self.wildcards)) |
| 1122 | q.text(","); q.breakable() |
| 1123 | q.text("max_entries = "); |
| 1124 | q.text("%#x" % self.max_entries) |
| 1125 | q.text(","); q.breakable() |
| 1126 | q.text("active_count = "); |
| 1127 | q.text("%#x" % self.active_count) |
| 1128 | q.text(","); q.breakable() |
| 1129 | q.text("lookup_count = "); |
| 1130 | q.text("%#x" % self.lookup_count) |
| 1131 | q.text(","); q.breakable() |
| 1132 | q.text("matched_count = "); |
| 1133 | q.text("%#x" % self.matched_count) |
| 1134 | q.breakable() |
| 1135 | q.text('}') |
| 1136 | |