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