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