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