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