Matteo Scandolo | a229eca | 2017-08-08 13:05:28 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 17 | # Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University |
| 18 | # Copyright (c) 2011, 2012 Open Networking Foundation |
| 19 | # Copyright (c) 2012, 2013 Big Switch Networks, Inc. |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 20 | # 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] | 21 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 22 | # Automatically generated by LOXI from template module.py |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 23 | # Do not modify |
| 24 | |
| 25 | import struct |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 26 | import loxi |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 27 | import util |
| 28 | import loxi.generic_util |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 29 | |
Rich Lane | e256770 | 2015-01-26 15:04:35 -0800 | [diff] [blame] | 30 | import sys |
| 31 | ofp = sys.modules['loxi.of13'] |
| 32 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 33 | class meter_band(loxi.OFObject): |
| 34 | subtypes = {} |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 35 | |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 36 | |
| 37 | def __init__(self, type=None): |
| 38 | if type != None: |
| 39 | self.type = type |
| 40 | else: |
| 41 | self.type = 0 |
| 42 | return |
| 43 | |
| 44 | def pack(self): |
| 45 | packed = [] |
| 46 | packed.append(struct.pack("!H", self.type)) |
| 47 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 48 | length = sum([len(x) for x in packed]) |
| 49 | packed[1] = struct.pack("!H", length) |
| 50 | return ''.join(packed) |
| 51 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 52 | @staticmethod |
| 53 | def unpack(reader): |
| 54 | subtype, = reader.peek('!H', 0) |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 55 | subclass = meter_band.subtypes.get(subtype) |
| 56 | if subclass: |
| 57 | return subclass.unpack(reader) |
| 58 | |
| 59 | obj = meter_band() |
| 60 | obj.type = reader.read("!H")[0] |
| 61 | _len = reader.read("!H")[0] |
| 62 | orig_reader = reader |
Rich Lane | cb18dbd | 2014-12-18 10:02:29 -0800 | [diff] [blame] | 63 | reader = orig_reader.slice(_len, 4) |
Rich Lane | 95f7fc9 | 2014-01-27 17:08:16 -0800 | [diff] [blame] | 64 | return obj |
| 65 | |
| 66 | def __eq__(self, other): |
| 67 | if type(self) != type(other): return False |
| 68 | if self.type != other.type: return False |
| 69 | return True |
| 70 | |
| 71 | def pretty_print(self, q): |
| 72 | q.text("meter_band {") |
| 73 | with q.group(): |
| 74 | with q.indent(2): |
| 75 | q.breakable() |
| 76 | q.breakable() |
| 77 | q.text('}') |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 78 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 79 | |
| 80 | class drop(meter_band): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 81 | type = 1 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 82 | |
| 83 | def __init__(self, rate=None, burst_size=None): |
| 84 | if rate != None: |
| 85 | self.rate = rate |
| 86 | else: |
| 87 | self.rate = 0 |
| 88 | if burst_size != None: |
| 89 | self.burst_size = burst_size |
| 90 | else: |
| 91 | self.burst_size = 0 |
| 92 | return |
| 93 | |
| 94 | def pack(self): |
| 95 | packed = [] |
| 96 | packed.append(struct.pack("!H", self.type)) |
| 97 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 98 | packed.append(struct.pack("!L", self.rate)) |
| 99 | packed.append(struct.pack("!L", self.burst_size)) |
| 100 | packed.append('\x00' * 4) |
| 101 | length = sum([len(x) for x in packed]) |
| 102 | packed[1] = struct.pack("!H", length) |
| 103 | return ''.join(packed) |
| 104 | |
| 105 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 106 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 107 | obj = drop() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 108 | _type = reader.read("!H")[0] |
| 109 | assert(_type == 1) |
| 110 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 111 | orig_reader = reader |
Rich Lane | cb18dbd | 2014-12-18 10:02:29 -0800 | [diff] [blame] | 112 | reader = orig_reader.slice(_len, 4) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 113 | obj.rate = reader.read("!L")[0] |
| 114 | obj.burst_size = reader.read("!L")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 115 | reader.skip(4) |
| 116 | return obj |
| 117 | |
| 118 | def __eq__(self, other): |
| 119 | if type(self) != type(other): return False |
| 120 | if self.rate != other.rate: return False |
| 121 | if self.burst_size != other.burst_size: return False |
| 122 | return True |
| 123 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 124 | def pretty_print(self, q): |
| 125 | q.text("drop {") |
| 126 | with q.group(): |
| 127 | with q.indent(2): |
| 128 | q.breakable() |
| 129 | q.text("rate = "); |
| 130 | q.text("%#x" % self.rate) |
| 131 | q.text(","); q.breakable() |
| 132 | q.text("burst_size = "); |
| 133 | q.text("%#x" % self.burst_size) |
| 134 | q.breakable() |
| 135 | q.text('}') |
| 136 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 137 | meter_band.subtypes[1] = drop |
| 138 | |
| 139 | class dscp_remark(meter_band): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 140 | type = 2 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 141 | |
| 142 | def __init__(self, rate=None, burst_size=None, prec_level=None): |
| 143 | if rate != None: |
| 144 | self.rate = rate |
| 145 | else: |
| 146 | self.rate = 0 |
| 147 | if burst_size != None: |
| 148 | self.burst_size = burst_size |
| 149 | else: |
| 150 | self.burst_size = 0 |
| 151 | if prec_level != None: |
| 152 | self.prec_level = prec_level |
| 153 | else: |
| 154 | self.prec_level = 0 |
| 155 | return |
| 156 | |
| 157 | def pack(self): |
| 158 | packed = [] |
| 159 | packed.append(struct.pack("!H", self.type)) |
| 160 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 161 | packed.append(struct.pack("!L", self.rate)) |
| 162 | packed.append(struct.pack("!L", self.burst_size)) |
| 163 | packed.append(struct.pack("!B", self.prec_level)) |
| 164 | packed.append('\x00' * 3) |
| 165 | length = sum([len(x) for x in packed]) |
| 166 | packed[1] = struct.pack("!H", length) |
| 167 | return ''.join(packed) |
| 168 | |
| 169 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 170 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 171 | obj = dscp_remark() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 172 | _type = reader.read("!H")[0] |
| 173 | assert(_type == 2) |
| 174 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 175 | orig_reader = reader |
Rich Lane | cb18dbd | 2014-12-18 10:02:29 -0800 | [diff] [blame] | 176 | reader = orig_reader.slice(_len, 4) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 177 | obj.rate = reader.read("!L")[0] |
| 178 | obj.burst_size = reader.read("!L")[0] |
| 179 | obj.prec_level = reader.read("!B")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 180 | reader.skip(3) |
| 181 | return obj |
| 182 | |
| 183 | def __eq__(self, other): |
| 184 | if type(self) != type(other): return False |
| 185 | if self.rate != other.rate: return False |
| 186 | if self.burst_size != other.burst_size: return False |
| 187 | if self.prec_level != other.prec_level: return False |
| 188 | return True |
| 189 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 190 | def pretty_print(self, q): |
| 191 | q.text("dscp_remark {") |
| 192 | with q.group(): |
| 193 | with q.indent(2): |
| 194 | q.breakable() |
| 195 | q.text("rate = "); |
| 196 | q.text("%#x" % self.rate) |
| 197 | q.text(","); q.breakable() |
| 198 | q.text("burst_size = "); |
| 199 | q.text("%#x" % self.burst_size) |
| 200 | q.text(","); q.breakable() |
| 201 | q.text("prec_level = "); |
| 202 | q.text("%#x" % self.prec_level) |
| 203 | q.breakable() |
| 204 | q.text('}') |
| 205 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 206 | meter_band.subtypes[2] = dscp_remark |
| 207 | |
| 208 | class experimenter(meter_band): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 209 | type = 65535 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 210 | |
| 211 | def __init__(self, rate=None, burst_size=None, experimenter=None): |
| 212 | if rate != None: |
| 213 | self.rate = rate |
| 214 | else: |
| 215 | self.rate = 0 |
| 216 | if burst_size != None: |
| 217 | self.burst_size = burst_size |
| 218 | else: |
| 219 | self.burst_size = 0 |
| 220 | if experimenter != None: |
| 221 | self.experimenter = experimenter |
| 222 | else: |
| 223 | self.experimenter = 0 |
| 224 | return |
| 225 | |
| 226 | def pack(self): |
| 227 | packed = [] |
| 228 | packed.append(struct.pack("!H", self.type)) |
| 229 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 230 | packed.append(struct.pack("!L", self.rate)) |
| 231 | packed.append(struct.pack("!L", self.burst_size)) |
| 232 | packed.append(struct.pack("!L", self.experimenter)) |
| 233 | length = sum([len(x) for x in packed]) |
| 234 | packed[1] = struct.pack("!H", length) |
| 235 | return ''.join(packed) |
| 236 | |
| 237 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 238 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 239 | obj = experimenter() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 240 | _type = reader.read("!H")[0] |
| 241 | assert(_type == 65535) |
| 242 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 243 | orig_reader = reader |
Rich Lane | cb18dbd | 2014-12-18 10:02:29 -0800 | [diff] [blame] | 244 | reader = orig_reader.slice(_len, 4) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 245 | obj.rate = reader.read("!L")[0] |
| 246 | obj.burst_size = reader.read("!L")[0] |
| 247 | obj.experimenter = reader.read("!L")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 248 | return obj |
| 249 | |
| 250 | def __eq__(self, other): |
| 251 | if type(self) != type(other): return False |
| 252 | if self.rate != other.rate: return False |
| 253 | if self.burst_size != other.burst_size: return False |
| 254 | if self.experimenter != other.experimenter: return False |
| 255 | return True |
| 256 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 257 | def pretty_print(self, q): |
| 258 | q.text("experimenter {") |
| 259 | with q.group(): |
| 260 | with q.indent(2): |
| 261 | q.breakable() |
| 262 | q.text("rate = "); |
| 263 | q.text("%#x" % self.rate) |
| 264 | q.text(","); q.breakable() |
| 265 | q.text("burst_size = "); |
| 266 | q.text("%#x" % self.burst_size) |
| 267 | q.text(","); q.breakable() |
| 268 | q.text("experimenter = "); |
| 269 | q.text("%#x" % self.experimenter) |
| 270 | q.breakable() |
| 271 | q.text('}') |
| 272 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 273 | meter_band.subtypes[65535] = experimenter |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 274 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 275 | |