Rich Lane | 2e079da | 2014-10-29 15:30:24 -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 | # See the file LICENSE.pyloxi which should have been included in the source distribution |
| 5 | |
| 6 | # Automatically generated by LOXI from template module.py |
| 7 | # Do not modify |
| 8 | |
| 9 | import struct |
| 10 | import loxi |
| 11 | import const |
| 12 | import port_desc_prop |
Rich Lane | ccd32ed | 2014-11-10 17:48:24 -0800 | [diff] [blame^] | 13 | import bsn_tlv |
Rich Lane | 2e079da | 2014-10-29 15:30:24 -0700 | [diff] [blame] | 14 | import meter_band |
| 15 | import table_mod_prop |
| 16 | import instruction |
| 17 | import queue_desc_prop |
| 18 | import oxm |
| 19 | import bundle_prop |
| 20 | import common |
| 21 | import instruction_id |
| 22 | import action |
| 23 | import role_prop |
| 24 | import message |
| 25 | import queue_stats_prop |
| 26 | import port_stats_prop |
| 27 | import port_mod_prop |
| 28 | import async_config_prop |
| 29 | import action_id |
| 30 | import util |
| 31 | import loxi.generic_util |
| 32 | |
| 33 | class meter_band(loxi.OFObject): |
| 34 | subtypes = {} |
| 35 | |
| 36 | |
| 37 | def __init__(self, type=None): |
| 38 | if type != None: |
| 39 | self.type = type |
| 40 | else: |
| 41 | self.type = 0 |
| 42 | return |
| 43 | |
| 44 | def pack(self): |
| 45 | packed = [] |
| 46 | packed.append(struct.pack("!H", self.type)) |
| 47 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 48 | length = sum([len(x) for x in packed]) |
| 49 | packed[1] = struct.pack("!H", length) |
| 50 | return ''.join(packed) |
| 51 | |
| 52 | @staticmethod |
| 53 | def unpack(reader): |
| 54 | subtype, = reader.peek('!H', 0) |
| 55 | subclass = meter_band.subtypes.get(subtype) |
| 56 | if subclass: |
| 57 | return subclass.unpack(reader) |
| 58 | |
| 59 | obj = meter_band() |
| 60 | obj.type = reader.read("!H")[0] |
| 61 | _len = reader.read("!H")[0] |
| 62 | orig_reader = reader |
| 63 | reader = orig_reader.slice(_len - (2 + 2)) |
| 64 | return obj |
| 65 | |
| 66 | def __eq__(self, other): |
| 67 | if type(self) != type(other): return False |
| 68 | if self.type != other.type: return False |
| 69 | return True |
| 70 | |
| 71 | def pretty_print(self, q): |
| 72 | q.text("meter_band {") |
| 73 | with q.group(): |
| 74 | with q.indent(2): |
| 75 | q.breakable() |
| 76 | q.breakable() |
| 77 | q.text('}') |
| 78 | |
| 79 | |
| 80 | class drop(meter_band): |
| 81 | type = 1 |
| 82 | |
| 83 | def __init__(self, rate=None, burst_size=None): |
| 84 | if rate != None: |
| 85 | self.rate = rate |
| 86 | else: |
| 87 | self.rate = 0 |
| 88 | if burst_size != None: |
| 89 | self.burst_size = burst_size |
| 90 | else: |
| 91 | self.burst_size = 0 |
| 92 | return |
| 93 | |
| 94 | def pack(self): |
| 95 | packed = [] |
| 96 | packed.append(struct.pack("!H", self.type)) |
| 97 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 98 | packed.append(struct.pack("!L", self.rate)) |
| 99 | packed.append(struct.pack("!L", self.burst_size)) |
| 100 | packed.append('\x00' * 4) |
| 101 | length = sum([len(x) for x in packed]) |
| 102 | packed[1] = struct.pack("!H", length) |
| 103 | return ''.join(packed) |
| 104 | |
| 105 | @staticmethod |
| 106 | def unpack(reader): |
| 107 | obj = drop() |
| 108 | _type = reader.read("!H")[0] |
| 109 | assert(_type == 1) |
| 110 | _len = reader.read("!H")[0] |
| 111 | orig_reader = reader |
| 112 | reader = orig_reader.slice(_len - (2 + 2)) |
| 113 | obj.rate = reader.read("!L")[0] |
| 114 | obj.burst_size = reader.read("!L")[0] |
| 115 | reader.skip(4) |
| 116 | return obj |
| 117 | |
| 118 | def __eq__(self, other): |
| 119 | if type(self) != type(other): return False |
| 120 | if self.rate != other.rate: return False |
| 121 | if self.burst_size != other.burst_size: return False |
| 122 | return True |
| 123 | |
| 124 | def pretty_print(self, q): |
| 125 | q.text("drop {") |
| 126 | with q.group(): |
| 127 | with q.indent(2): |
| 128 | q.breakable() |
| 129 | q.text("rate = "); |
| 130 | q.text("%#x" % self.rate) |
| 131 | q.text(","); q.breakable() |
| 132 | q.text("burst_size = "); |
| 133 | q.text("%#x" % self.burst_size) |
| 134 | q.breakable() |
| 135 | q.text('}') |
| 136 | |
| 137 | meter_band.subtypes[1] = drop |
| 138 | |
| 139 | class dscp_remark(meter_band): |
| 140 | type = 2 |
| 141 | |
| 142 | def __init__(self, rate=None, burst_size=None, prec_level=None): |
| 143 | if rate != None: |
| 144 | self.rate = rate |
| 145 | else: |
| 146 | self.rate = 0 |
| 147 | if burst_size != None: |
| 148 | self.burst_size = burst_size |
| 149 | else: |
| 150 | self.burst_size = 0 |
| 151 | if prec_level != None: |
| 152 | self.prec_level = prec_level |
| 153 | else: |
| 154 | self.prec_level = 0 |
| 155 | return |
| 156 | |
| 157 | def pack(self): |
| 158 | packed = [] |
| 159 | packed.append(struct.pack("!H", self.type)) |
| 160 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 161 | packed.append(struct.pack("!L", self.rate)) |
| 162 | packed.append(struct.pack("!L", self.burst_size)) |
| 163 | packed.append(struct.pack("!B", self.prec_level)) |
| 164 | packed.append('\x00' * 3) |
| 165 | length = sum([len(x) for x in packed]) |
| 166 | packed[1] = struct.pack("!H", length) |
| 167 | return ''.join(packed) |
| 168 | |
| 169 | @staticmethod |
| 170 | def unpack(reader): |
| 171 | obj = dscp_remark() |
| 172 | _type = reader.read("!H")[0] |
| 173 | assert(_type == 2) |
| 174 | _len = reader.read("!H")[0] |
| 175 | orig_reader = reader |
| 176 | reader = orig_reader.slice(_len - (2 + 2)) |
| 177 | obj.rate = reader.read("!L")[0] |
| 178 | obj.burst_size = reader.read("!L")[0] |
| 179 | obj.prec_level = reader.read("!B")[0] |
| 180 | reader.skip(3) |
| 181 | return obj |
| 182 | |
| 183 | def __eq__(self, other): |
| 184 | if type(self) != type(other): return False |
| 185 | if self.rate != other.rate: return False |
| 186 | if self.burst_size != other.burst_size: return False |
| 187 | if self.prec_level != other.prec_level: return False |
| 188 | return True |
| 189 | |
| 190 | def pretty_print(self, q): |
| 191 | q.text("dscp_remark {") |
| 192 | with q.group(): |
| 193 | with q.indent(2): |
| 194 | q.breakable() |
| 195 | q.text("rate = "); |
| 196 | q.text("%#x" % self.rate) |
| 197 | q.text(","); q.breakable() |
| 198 | q.text("burst_size = "); |
| 199 | q.text("%#x" % self.burst_size) |
| 200 | q.text(","); q.breakable() |
| 201 | q.text("prec_level = "); |
| 202 | q.text("%#x" % self.prec_level) |
| 203 | q.breakable() |
| 204 | q.text('}') |
| 205 | |
| 206 | meter_band.subtypes[2] = dscp_remark |
| 207 | |
| 208 | class experimenter(meter_band): |
| 209 | type = 65535 |
| 210 | |
| 211 | def __init__(self, rate=None, burst_size=None, experimenter=None): |
| 212 | if rate != None: |
| 213 | self.rate = rate |
| 214 | else: |
| 215 | self.rate = 0 |
| 216 | if burst_size != None: |
| 217 | self.burst_size = burst_size |
| 218 | else: |
| 219 | self.burst_size = 0 |
| 220 | if experimenter != None: |
| 221 | self.experimenter = experimenter |
| 222 | else: |
| 223 | self.experimenter = 0 |
| 224 | return |
| 225 | |
| 226 | def pack(self): |
| 227 | packed = [] |
| 228 | packed.append(struct.pack("!H", self.type)) |
| 229 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 230 | packed.append(struct.pack("!L", self.rate)) |
| 231 | packed.append(struct.pack("!L", self.burst_size)) |
| 232 | packed.append(struct.pack("!L", self.experimenter)) |
| 233 | length = sum([len(x) for x in packed]) |
| 234 | packed[1] = struct.pack("!H", length) |
| 235 | return ''.join(packed) |
| 236 | |
| 237 | @staticmethod |
| 238 | def unpack(reader): |
| 239 | obj = experimenter() |
| 240 | _type = reader.read("!H")[0] |
| 241 | assert(_type == 65535) |
| 242 | _len = reader.read("!H")[0] |
| 243 | orig_reader = reader |
| 244 | reader = orig_reader.slice(_len - (2 + 2)) |
| 245 | obj.rate = reader.read("!L")[0] |
| 246 | obj.burst_size = reader.read("!L")[0] |
| 247 | obj.experimenter = reader.read("!L")[0] |
| 248 | return obj |
| 249 | |
| 250 | def __eq__(self, other): |
| 251 | if type(self) != type(other): return False |
| 252 | if self.rate != other.rate: return False |
| 253 | if self.burst_size != other.burst_size: return False |
| 254 | if self.experimenter != other.experimenter: return False |
| 255 | return True |
| 256 | |
| 257 | def pretty_print(self, q): |
| 258 | q.text("experimenter {") |
| 259 | with q.group(): |
| 260 | with q.indent(2): |
| 261 | q.breakable() |
| 262 | q.text("rate = "); |
| 263 | q.text("%#x" % self.rate) |
| 264 | q.text(","); q.breakable() |
| 265 | q.text("burst_size = "); |
| 266 | q.text("%#x" % self.burst_size) |
| 267 | q.text(","); q.breakable() |
| 268 | q.text("experimenter = "); |
| 269 | q.text("%#x" % self.experimenter) |
| 270 | q.breakable() |
| 271 | q.text('}') |
| 272 | |
| 273 | meter_band.subtypes[65535] = experimenter |
| 274 | |
| 275 | |