blob: 8efba54035f2a68146d0d1c90614e61c96f5d22c [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
Harshmeet Singh1db46332014-10-14 16:29:13 -070012import bsn_tlv
13import meter_band
Rich Lane7dcdf022013-12-11 14:45:27 -080014import instruction
15import oxm
Harshmeet Singh1db46332014-10-14 16:29:13 -070016import common
Rich Lane7dcdf022013-12-11 14:45:27 -080017import instruction_id
Harshmeet Singh1db46332014-10-14 16:29:13 -070018import action
19import message
20import action_id
Rich Laneca3da272013-05-05 09:07:33 -070021import util
22import loxi.generic_util
Rich Laneca3da272013-05-05 09:07:33 -070023
Rich Lane7dcdf022013-12-11 14:45:27 -080024class meter_band(loxi.OFObject):
25 subtypes = {}
Rich Laneca3da272013-05-05 09:07:33 -070026
Rich Lane95f7fc92014-01-27 17:08:16 -080027
28 def __init__(self, type=None):
29 if type != None:
30 self.type = type
31 else:
32 self.type = 0
33 return
34
35 def pack(self):
36 packed = []
37 packed.append(struct.pack("!H", self.type))
38 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
39 length = sum([len(x) for x in packed])
40 packed[1] = struct.pack("!H", length)
41 return ''.join(packed)
42
Rich Lane7dcdf022013-12-11 14:45:27 -080043 @staticmethod
44 def unpack(reader):
45 subtype, = reader.peek('!H', 0)
Rich Lane95f7fc92014-01-27 17:08:16 -080046 subclass = meter_band.subtypes.get(subtype)
47 if subclass:
48 return subclass.unpack(reader)
49
50 obj = meter_band()
51 obj.type = reader.read("!H")[0]
52 _len = reader.read("!H")[0]
53 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -080054 reader = orig_reader.slice(_len, 4)
Rich Lane95f7fc92014-01-27 17:08:16 -080055 return obj
56
57 def __eq__(self, other):
58 if type(self) != type(other): return False
59 if self.type != other.type: return False
60 return True
61
62 def pretty_print(self, q):
63 q.text("meter_band {")
64 with q.group():
65 with q.indent(2):
66 q.breakable()
67 q.breakable()
68 q.text('}')
Rich Laneca3da272013-05-05 09:07:33 -070069
Rich Lane7dcdf022013-12-11 14:45:27 -080070
71class drop(meter_band):
Dan Talaycof6202252013-07-02 01:00:29 -070072 type = 1
Rich Laneca3da272013-05-05 09:07:33 -070073
74 def __init__(self, rate=None, burst_size=None):
75 if rate != None:
76 self.rate = rate
77 else:
78 self.rate = 0
79 if burst_size != None:
80 self.burst_size = burst_size
81 else:
82 self.burst_size = 0
83 return
84
85 def pack(self):
86 packed = []
87 packed.append(struct.pack("!H", self.type))
88 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
89 packed.append(struct.pack("!L", self.rate))
90 packed.append(struct.pack("!L", self.burst_size))
91 packed.append('\x00' * 4)
92 length = sum([len(x) for x in packed])
93 packed[1] = struct.pack("!H", length)
94 return ''.join(packed)
95
96 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -080097 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -070098 obj = drop()
Dan Talaycof6202252013-07-02 01:00:29 -070099 _type = reader.read("!H")[0]
100 assert(_type == 1)
101 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800102 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800103 reader = orig_reader.slice(_len, 4)
Dan Talaycof6202252013-07-02 01:00:29 -0700104 obj.rate = reader.read("!L")[0]
105 obj.burst_size = reader.read("!L")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700106 reader.skip(4)
107 return obj
108
109 def __eq__(self, other):
110 if type(self) != type(other): return False
111 if self.rate != other.rate: return False
112 if self.burst_size != other.burst_size: return False
113 return True
114
Rich Laneca3da272013-05-05 09:07:33 -0700115 def pretty_print(self, q):
116 q.text("drop {")
117 with q.group():
118 with q.indent(2):
119 q.breakable()
120 q.text("rate = ");
121 q.text("%#x" % self.rate)
122 q.text(","); q.breakable()
123 q.text("burst_size = ");
124 q.text("%#x" % self.burst_size)
125 q.breakable()
126 q.text('}')
127
Rich Lane7dcdf022013-12-11 14:45:27 -0800128meter_band.subtypes[1] = drop
129
130class dscp_remark(meter_band):
Dan Talaycof6202252013-07-02 01:00:29 -0700131 type = 2
Rich Laneca3da272013-05-05 09:07:33 -0700132
133 def __init__(self, rate=None, burst_size=None, prec_level=None):
134 if rate != None:
135 self.rate = rate
136 else:
137 self.rate = 0
138 if burst_size != None:
139 self.burst_size = burst_size
140 else:
141 self.burst_size = 0
142 if prec_level != None:
143 self.prec_level = prec_level
144 else:
145 self.prec_level = 0
146 return
147
148 def pack(self):
149 packed = []
150 packed.append(struct.pack("!H", self.type))
151 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
152 packed.append(struct.pack("!L", self.rate))
153 packed.append(struct.pack("!L", self.burst_size))
154 packed.append(struct.pack("!B", self.prec_level))
155 packed.append('\x00' * 3)
156 length = sum([len(x) for x in packed])
157 packed[1] = struct.pack("!H", length)
158 return ''.join(packed)
159
160 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800161 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700162 obj = dscp_remark()
Dan Talaycof6202252013-07-02 01:00:29 -0700163 _type = reader.read("!H")[0]
164 assert(_type == 2)
165 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800166 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800167 reader = orig_reader.slice(_len, 4)
Dan Talaycof6202252013-07-02 01:00:29 -0700168 obj.rate = reader.read("!L")[0]
169 obj.burst_size = reader.read("!L")[0]
170 obj.prec_level = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700171 reader.skip(3)
172 return obj
173
174 def __eq__(self, other):
175 if type(self) != type(other): return False
176 if self.rate != other.rate: return False
177 if self.burst_size != other.burst_size: return False
178 if self.prec_level != other.prec_level: return False
179 return True
180
Rich Laneca3da272013-05-05 09:07:33 -0700181 def pretty_print(self, q):
182 q.text("dscp_remark {")
183 with q.group():
184 with q.indent(2):
185 q.breakable()
186 q.text("rate = ");
187 q.text("%#x" % self.rate)
188 q.text(","); q.breakable()
189 q.text("burst_size = ");
190 q.text("%#x" % self.burst_size)
191 q.text(","); q.breakable()
192 q.text("prec_level = ");
193 q.text("%#x" % self.prec_level)
194 q.breakable()
195 q.text('}')
196
Rich Lane7dcdf022013-12-11 14:45:27 -0800197meter_band.subtypes[2] = dscp_remark
198
199class experimenter(meter_band):
Dan Talaycof6202252013-07-02 01:00:29 -0700200 type = 65535
Rich Laneca3da272013-05-05 09:07:33 -0700201
202 def __init__(self, rate=None, burst_size=None, experimenter=None):
203 if rate != None:
204 self.rate = rate
205 else:
206 self.rate = 0
207 if burst_size != None:
208 self.burst_size = burst_size
209 else:
210 self.burst_size = 0
211 if experimenter != None:
212 self.experimenter = experimenter
213 else:
214 self.experimenter = 0
215 return
216
217 def pack(self):
218 packed = []
219 packed.append(struct.pack("!H", self.type))
220 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
221 packed.append(struct.pack("!L", self.rate))
222 packed.append(struct.pack("!L", self.burst_size))
223 packed.append(struct.pack("!L", self.experimenter))
224 length = sum([len(x) for x in packed])
225 packed[1] = struct.pack("!H", length)
226 return ''.join(packed)
227
228 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800229 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700230 obj = experimenter()
Dan Talaycof6202252013-07-02 01:00:29 -0700231 _type = reader.read("!H")[0]
232 assert(_type == 65535)
233 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800234 orig_reader = reader
Rich Lanecb18dbd2014-12-18 10:02:29 -0800235 reader = orig_reader.slice(_len, 4)
Dan Talaycof6202252013-07-02 01:00:29 -0700236 obj.rate = reader.read("!L")[0]
237 obj.burst_size = reader.read("!L")[0]
238 obj.experimenter = reader.read("!L")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700239 return obj
240
241 def __eq__(self, other):
242 if type(self) != type(other): return False
243 if self.rate != other.rate: return False
244 if self.burst_size != other.burst_size: return False
245 if self.experimenter != other.experimenter: return False
246 return True
247
Rich Laneca3da272013-05-05 09:07:33 -0700248 def pretty_print(self, q):
249 q.text("experimenter {")
250 with q.group():
251 with q.indent(2):
252 q.breakable()
253 q.text("rate = ");
254 q.text("%#x" % self.rate)
255 q.text(","); q.breakable()
256 q.text("burst_size = ");
257 q.text("%#x" % self.burst_size)
258 q.text(","); q.breakable()
259 q.text("experimenter = ");
260 q.text("%#x" % self.experimenter)
261 q.breakable()
262 q.text('}')
263
Rich Lane7dcdf022013-12-11 14:45:27 -0800264meter_band.subtypes[65535] = experimenter
Rich Laneca3da272013-05-05 09:07:33 -0700265
Rich Lane7dcdf022013-12-11 14:45:27 -0800266