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