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