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