blob: 6453c4f8bafa25441653d549ee8662ef41538215 [file] [log] [blame]
Rich Laneca3da272013-05-05 09:07:33 -07001# 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 Talaycof6202252013-07-02 01:00:29 -07004# See the file LICENSE.pyloxi which should have been included in the source distribution
Rich Laneca3da272013-05-05 09:07:33 -07005
Rich Lane7dcdf022013-12-11 14:45:27 -08006# Automatically generated by LOXI from template module.py
Rich Laneca3da272013-05-05 09:07:33 -07007# Do not modify
8
9import struct
Rich Lane7dcdf022013-12-11 14:45:27 -080010import loxi
Rich Laneca3da272013-05-05 09:07:33 -070011import const
Rich Lane7dcdf022013-12-11 14:45:27 -080012import common
13import action
14import instruction
15import oxm
16import action_id
17import instruction_id
18import meter_band
Rich Lane5454b682014-01-14 17:07:36 -080019import bsn_tlv
Rich Laneca3da272013-05-05 09:07:33 -070020import util
21import loxi.generic_util
Rich Laneca3da272013-05-05 09:07:33 -070022
Rich Lane7dcdf022013-12-11 14:45:27 -080023class meter_band(loxi.OFObject):
24 subtypes = {}
Rich Laneca3da272013-05-05 09:07:33 -070025
Rich Lane95f7fc92014-01-27 17:08:16 -080026
27 def __init__(self, type=None):
28 if type != None:
29 self.type = type
30 else:
31 self.type = 0
32 return
33
34 def pack(self):
35 packed = []
36 packed.append(struct.pack("!H", self.type))
37 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
38 length = sum([len(x) for x in packed])
39 packed[1] = struct.pack("!H", length)
40 return ''.join(packed)
41
Rich Lane7dcdf022013-12-11 14:45:27 -080042 @staticmethod
43 def unpack(reader):
44 subtype, = reader.peek('!H', 0)
Rich Lane95f7fc92014-01-27 17:08:16 -080045 subclass = meter_band.subtypes.get(subtype)
46 if subclass:
47 return subclass.unpack(reader)
48
49 obj = meter_band()
50 obj.type = reader.read("!H")[0]
51 _len = reader.read("!H")[0]
52 orig_reader = reader
53 reader = orig_reader.slice(_len - (2 + 2))
54 return obj
55
56 def __eq__(self, other):
57 if type(self) != type(other): return False
58 if self.type != other.type: return False
59 return True
60
61 def pretty_print(self, q):
62 q.text("meter_band {")
63 with q.group():
64 with q.indent(2):
65 q.breakable()
66 q.breakable()
67 q.text('}')
Rich Laneca3da272013-05-05 09:07:33 -070068
Rich Lane7dcdf022013-12-11 14:45:27 -080069
70class drop(meter_band):
Dan Talaycof6202252013-07-02 01:00:29 -070071 type = 1
Rich Laneca3da272013-05-05 09:07:33 -070072
73 def __init__(self, rate=None, burst_size=None):
74 if rate != None:
75 self.rate = rate
76 else:
77 self.rate = 0
78 if burst_size != None:
79 self.burst_size = burst_size
80 else:
81 self.burst_size = 0
82 return
83
84 def pack(self):
85 packed = []
86 packed.append(struct.pack("!H", self.type))
87 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
88 packed.append(struct.pack("!L", self.rate))
89 packed.append(struct.pack("!L", self.burst_size))
90 packed.append('\x00' * 4)
91 length = sum([len(x) for x in packed])
92 packed[1] = struct.pack("!H", length)
93 return ''.join(packed)
94
95 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -080096 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -070097 obj = drop()
Dan Talaycof6202252013-07-02 01:00:29 -070098 _type = reader.read("!H")[0]
99 assert(_type == 1)
100 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800101 orig_reader = reader
102 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700103 obj.rate = reader.read("!L")[0]
104 obj.burst_size = reader.read("!L")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700105 reader.skip(4)
106 return obj
107
108 def __eq__(self, other):
109 if type(self) != type(other): return False
110 if self.rate != other.rate: return False
111 if self.burst_size != other.burst_size: return False
112 return True
113
Rich Laneca3da272013-05-05 09:07:33 -0700114 def pretty_print(self, q):
115 q.text("drop {")
116 with q.group():
117 with q.indent(2):
118 q.breakable()
119 q.text("rate = ");
120 q.text("%#x" % self.rate)
121 q.text(","); q.breakable()
122 q.text("burst_size = ");
123 q.text("%#x" % self.burst_size)
124 q.breakable()
125 q.text('}')
126
Rich Lane7dcdf022013-12-11 14:45:27 -0800127meter_band.subtypes[1] = drop
128
129class dscp_remark(meter_band):
Dan Talaycof6202252013-07-02 01:00:29 -0700130 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700131
132 def __init__(self, rate=None, burst_size=None, prec_level=None):
133 if rate != None:
134 self.rate = rate
135 else:
136 self.rate = 0
137 if burst_size != None:
138 self.burst_size = burst_size
139 else:
140 self.burst_size = 0
141 if prec_level != None:
142 self.prec_level = prec_level
143 else:
144 self.prec_level = 0
145 return
146
147 def pack(self):
148 packed = []
149 packed.append(struct.pack("!H", self.type))
150 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
151 packed.append(struct.pack("!L", self.rate))
152 packed.append(struct.pack("!L", self.burst_size))
153 packed.append(struct.pack("!B", self.prec_level))
154 packed.append('\x00' * 3)
155 length = sum([len(x) for x in packed])
156 packed[1] = struct.pack("!H", length)
157 return ''.join(packed)
158
159 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800160 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700161 obj = dscp_remark()
Dan Talaycof6202252013-07-02 01:00:29 -0700162 _type = reader.read("!H")[0]
163 assert(_type == 2)
164 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800165 orig_reader = reader
166 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700167 obj.rate = reader.read("!L")[0]
168 obj.burst_size = reader.read("!L")[0]
169 obj.prec_level = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700170 reader.skip(3)
171 return obj
172
173 def __eq__(self, other):
174 if type(self) != type(other): return False
175 if self.rate != other.rate: return False
176 if self.burst_size != other.burst_size: return False
177 if self.prec_level != other.prec_level: return False
178 return True
179
Rich Laneca3da272013-05-05 09:07:33 -0700180 def pretty_print(self, q):
181 q.text("dscp_remark {")
182 with q.group():
183 with q.indent(2):
184 q.breakable()
185 q.text("rate = ");
186 q.text("%#x" % self.rate)
187 q.text(","); q.breakable()
188 q.text("burst_size = ");
189 q.text("%#x" % self.burst_size)
190 q.text(","); q.breakable()
191 q.text("prec_level = ");
192 q.text("%#x" % self.prec_level)
193 q.breakable()
194 q.text('}')
195
Rich Lane7dcdf022013-12-11 14:45:27 -0800196meter_band.subtypes[2] = dscp_remark
197
198class experimenter(meter_band):
Dan Talaycof6202252013-07-02 01:00:29 -0700199 type = 65535
Rich Laneca3da272013-05-05 09:07:33 -0700200
201 def __init__(self, rate=None, burst_size=None, experimenter=None):
202 if rate != None:
203 self.rate = rate
204 else:
205 self.rate = 0
206 if burst_size != None:
207 self.burst_size = burst_size
208 else:
209 self.burst_size = 0
210 if experimenter != None:
211 self.experimenter = experimenter
212 else:
213 self.experimenter = 0
214 return
215
216 def pack(self):
217 packed = []
218 packed.append(struct.pack("!H", self.type))
219 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
220 packed.append(struct.pack("!L", self.rate))
221 packed.append(struct.pack("!L", self.burst_size))
222 packed.append(struct.pack("!L", self.experimenter))
223 length = sum([len(x) for x in packed])
224 packed[1] = struct.pack("!H", length)
225 return ''.join(packed)
226
227 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800228 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700229 obj = experimenter()
Dan Talaycof6202252013-07-02 01:00:29 -0700230 _type = reader.read("!H")[0]
231 assert(_type == 65535)
232 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800233 orig_reader = reader
234 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700235 obj.rate = reader.read("!L")[0]
236 obj.burst_size = reader.read("!L")[0]
237 obj.experimenter = reader.read("!L")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700238 return obj
239
240 def __eq__(self, other):
241 if type(self) != type(other): return False
242 if self.rate != other.rate: return False
243 if self.burst_size != other.burst_size: return False
244 if self.experimenter != other.experimenter: return False
245 return True
246
Rich Laneca3da272013-05-05 09:07:33 -0700247 def pretty_print(self, q):
248 q.text("experimenter {")
249 with q.group():
250 with q.indent(2):
251 q.breakable()
252 q.text("rate = ");
253 q.text("%#x" % self.rate)
254 q.text(","); q.breakable()
255 q.text("burst_size = ");
256 q.text("%#x" % self.burst_size)
257 q.text(","); q.breakable()
258 q.text("experimenter = ");
259 q.text("%#x" % self.experimenter)
260 q.breakable()
261 q.text('}')
262
Rich Lane7dcdf022013-12-11 14:45:27 -0800263meter_band.subtypes[65535] = experimenter
Rich Laneca3da272013-05-05 09:07:33 -0700264
Rich Lane7dcdf022013-12-11 14:45:27 -0800265