blob: c676cf01488cc52f5346e0619d6bd169292d2e67 [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 Lane2e079da2014-10-29 15:30:24 -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.
20# See the file LICENSE.pyloxi which should have been included in the source distribution
21
22# Automatically generated by LOXI from template module.py
23# Do not modify
24
25import struct
26import loxi
Rich Lane2e079da2014-10-29 15:30:24 -070027import util
28import loxi.generic_util
29
Rich Lanee2567702015-01-26 15:04:35 -080030import sys
31ofp = sys.modules['loxi.of14']
32
Rich Lane2e079da2014-10-29 15:30:24 -070033class meter_band(loxi.OFObject):
34 subtypes = {}
35
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
52 @staticmethod
53 def unpack(reader):
54 subtype, = reader.peek('!H', 0)
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 Lanecb18dbd2014-12-18 10:02:29 -080063 reader = orig_reader.slice(_len, 4)
Rich Lane2e079da2014-10-29 15:30:24 -070064 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('}')
78
79
80class drop(meter_band):
81 type = 1
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
106 def unpack(reader):
107 obj = drop()
108 _type = reader.read("!H")[0]
109 assert(_type == 1)
110 _len = reader.read("!H")[0]
111 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800112 reader = orig_reader.slice(_len, 4)
Rich Lane2e079da2014-10-29 15:30:24 -0700113 obj.rate = reader.read("!L")[0]
114 obj.burst_size = reader.read("!L")[0]
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
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
137meter_band.subtypes[1] = drop
138
139class dscp_remark(meter_band):
140 type = 2
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
170 def unpack(reader):
171 obj = dscp_remark()
172 _type = reader.read("!H")[0]
173 assert(_type == 2)
174 _len = reader.read("!H")[0]
175 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800176 reader = orig_reader.slice(_len, 4)
Rich Lane2e079da2014-10-29 15:30:24 -0700177 obj.rate = reader.read("!L")[0]
178 obj.burst_size = reader.read("!L")[0]
179 obj.prec_level = reader.read("!B")[0]
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
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
206meter_band.subtypes[2] = dscp_remark
207
208class experimenter(meter_band):
209 type = 65535
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
238 def unpack(reader):
239 obj = experimenter()
240 _type = reader.read("!H")[0]
241 assert(_type == 65535)
242 _len = reader.read("!H")[0]
243 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800244 reader = orig_reader.slice(_len, 4)
Rich Lane2e079da2014-10-29 15:30:24 -0700245 obj.rate = reader.read("!L")[0]
246 obj.burst_size = reader.read("!L")[0]
247 obj.experimenter = reader.read("!L")[0]
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
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
273meter_band.subtypes[65535] = experimenter
274
275