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