blob: f0ed68382a16ca33b624e1183394da725eb25c02 [file] [log] [blame]
Matteo Scandoloa229eca2017-08-08 13:05:28 -07001
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 Laneca3da272013-05-05 09:07:33 -070017# 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 Talaycof6202252013-07-02 01:00:29 -070020# See the file LICENSE.pyloxi which should have been included in the source distribution
Rich Laneca3da272013-05-05 09:07:33 -070021
Rich Lane7dcdf022013-12-11 14:45:27 -080022# Automatically generated by LOXI from template module.py
Rich Laneca3da272013-05-05 09:07:33 -070023# Do not modify
24
25import struct
Rich Lane7dcdf022013-12-11 14:45:27 -080026import loxi
Rich Laneca3da272013-05-05 09:07:33 -070027import util
28import loxi.generic_util
Rich Laneca3da272013-05-05 09:07:33 -070029
Rich Lanee2567702015-01-26 15:04:35 -080030import sys
31ofp = sys.modules['loxi.of13']
32
Rich Lane7dcdf022013-12-11 14:45:27 -080033class meter_band(loxi.OFObject):
34 subtypes = {}
Rich Laneca3da272013-05-05 09:07:33 -070035
Rich Lane95f7fc92014-01-27 17:08:16 -080036
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 Lane7dcdf022013-12-11 14:45:27 -080052 @staticmethod
53 def unpack(reader):
54 subtype, = reader.peek('!H', 0)
Rich Lane95f7fc92014-01-27 17:08:16 -080055 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 Lanecb18dbd2014-12-18 10:02:29 -080063 reader = orig_reader.slice(_len, 4)
Rich Lane95f7fc92014-01-27 17:08:16 -080064 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 Laneca3da272013-05-05 09:07:33 -070078
Rich Lane7dcdf022013-12-11 14:45:27 -080079
80class drop(meter_band):
Dan Talaycof6202252013-07-02 01:00:29 -070081 type = 1
Rich Laneca3da272013-05-05 09:07:33 -070082
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 Lane7dcdf022013-12-11 14:45:27 -0800106 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700107 obj = drop()
Dan Talaycof6202252013-07-02 01:00:29 -0700108 _type = reader.read("!H")[0]
109 assert(_type == 1)
110 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800111 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800112 reader = orig_reader.slice(_len, 4)
Dan Talaycof6202252013-07-02 01:00:29 -0700113 obj.rate = reader.read("!L")[0]
114 obj.burst_size = reader.read("!L")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700115 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 Laneca3da272013-05-05 09:07:33 -0700124 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 Lane7dcdf022013-12-11 14:45:27 -0800137meter_band.subtypes[1] = drop
138
139class dscp_remark(meter_band):
Dan Talaycof6202252013-07-02 01:00:29 -0700140 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700141
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 Lane7dcdf022013-12-11 14:45:27 -0800170 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700171 obj = dscp_remark()
Dan Talaycof6202252013-07-02 01:00:29 -0700172 _type = reader.read("!H")[0]
173 assert(_type == 2)
174 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800175 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800176 reader = orig_reader.slice(_len, 4)
Dan Talaycof6202252013-07-02 01:00:29 -0700177 obj.rate = reader.read("!L")[0]
178 obj.burst_size = reader.read("!L")[0]
179 obj.prec_level = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700180 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 Laneca3da272013-05-05 09:07:33 -0700190 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 Lane7dcdf022013-12-11 14:45:27 -0800206meter_band.subtypes[2] = dscp_remark
207
208class experimenter(meter_band):
Dan Talaycof6202252013-07-02 01:00:29 -0700209 type = 65535
Rich Laneca3da272013-05-05 09:07:33 -0700210
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 Lane7dcdf022013-12-11 14:45:27 -0800238 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700239 obj = experimenter()
Dan Talaycof6202252013-07-02 01:00:29 -0700240 _type = reader.read("!H")[0]
241 assert(_type == 65535)
242 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800243 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800244 reader = orig_reader.slice(_len, 4)
Dan Talaycof6202252013-07-02 01:00:29 -0700245 obj.rate = reader.read("!L")[0]
246 obj.burst_size = reader.read("!L")[0]
247 obj.experimenter = reader.read("!L")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700248 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 Laneca3da272013-05-05 09:07:33 -0700257 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 Lane7dcdf022013-12-11 14:45:27 -0800273meter_band.subtypes[65535] = experimenter
Rich Laneca3da272013-05-05 09:07:33 -0700274
Rich Lane7dcdf022013-12-11 14:45:27 -0800275