blob: a11c9dd4aa7bc8ab6502a8e46557b168f31b0060 [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 Lane7dcdf022013-12-11 14:45:27 -080026 @staticmethod
27 def unpack(reader):
28 subtype, = reader.peek('!H', 0)
29 try:
30 subclass = meter_band.subtypes[subtype]
31 except KeyError:
32 raise loxi.ProtocolError("unknown meter_band subtype %#x" % subtype)
33 return subclass.unpack(reader)
Rich Laneca3da272013-05-05 09:07:33 -070034
Rich Lane7dcdf022013-12-11 14:45:27 -080035
36class drop(meter_band):
Dan Talaycof6202252013-07-02 01:00:29 -070037 type = 1
Rich Laneca3da272013-05-05 09:07:33 -070038
39 def __init__(self, rate=None, burst_size=None):
40 if rate != None:
41 self.rate = rate
42 else:
43 self.rate = 0
44 if burst_size != None:
45 self.burst_size = burst_size
46 else:
47 self.burst_size = 0
48 return
49
50 def pack(self):
51 packed = []
52 packed.append(struct.pack("!H", self.type))
53 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
54 packed.append(struct.pack("!L", self.rate))
55 packed.append(struct.pack("!L", self.burst_size))
56 packed.append('\x00' * 4)
57 length = sum([len(x) for x in packed])
58 packed[1] = struct.pack("!H", length)
59 return ''.join(packed)
60
61 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -080062 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -070063 obj = drop()
Dan Talaycof6202252013-07-02 01:00:29 -070064 _type = reader.read("!H")[0]
65 assert(_type == 1)
66 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -080067 orig_reader = reader
68 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -070069 obj.rate = reader.read("!L")[0]
70 obj.burst_size = reader.read("!L")[0]
Rich Laneca3da272013-05-05 09:07:33 -070071 reader.skip(4)
72 return obj
73
74 def __eq__(self, other):
75 if type(self) != type(other): return False
76 if self.rate != other.rate: return False
77 if self.burst_size != other.burst_size: return False
78 return True
79
Rich Laneca3da272013-05-05 09:07:33 -070080 def pretty_print(self, q):
81 q.text("drop {")
82 with q.group():
83 with q.indent(2):
84 q.breakable()
85 q.text("rate = ");
86 q.text("%#x" % self.rate)
87 q.text(","); q.breakable()
88 q.text("burst_size = ");
89 q.text("%#x" % self.burst_size)
90 q.breakable()
91 q.text('}')
92
Rich Lane7dcdf022013-12-11 14:45:27 -080093meter_band.subtypes[1] = drop
94
95class dscp_remark(meter_band):
Dan Talaycof6202252013-07-02 01:00:29 -070096 type = 2
Rich Laneca3da272013-05-05 09:07:33 -070097
98 def __init__(self, rate=None, burst_size=None, prec_level=None):
99 if rate != None:
100 self.rate = rate
101 else:
102 self.rate = 0
103 if burst_size != None:
104 self.burst_size = burst_size
105 else:
106 self.burst_size = 0
107 if prec_level != None:
108 self.prec_level = prec_level
109 else:
110 self.prec_level = 0
111 return
112
113 def pack(self):
114 packed = []
115 packed.append(struct.pack("!H", self.type))
116 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
117 packed.append(struct.pack("!L", self.rate))
118 packed.append(struct.pack("!L", self.burst_size))
119 packed.append(struct.pack("!B", self.prec_level))
120 packed.append('\x00' * 3)
121 length = sum([len(x) for x in packed])
122 packed[1] = struct.pack("!H", length)
123 return ''.join(packed)
124
125 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800126 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700127 obj = dscp_remark()
Dan Talaycof6202252013-07-02 01:00:29 -0700128 _type = reader.read("!H")[0]
129 assert(_type == 2)
130 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800131 orig_reader = reader
132 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700133 obj.rate = reader.read("!L")[0]
134 obj.burst_size = reader.read("!L")[0]
135 obj.prec_level = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700136 reader.skip(3)
137 return obj
138
139 def __eq__(self, other):
140 if type(self) != type(other): return False
141 if self.rate != other.rate: return False
142 if self.burst_size != other.burst_size: return False
143 if self.prec_level != other.prec_level: return False
144 return True
145
Rich Laneca3da272013-05-05 09:07:33 -0700146 def pretty_print(self, q):
147 q.text("dscp_remark {")
148 with q.group():
149 with q.indent(2):
150 q.breakable()
151 q.text("rate = ");
152 q.text("%#x" % self.rate)
153 q.text(","); q.breakable()
154 q.text("burst_size = ");
155 q.text("%#x" % self.burst_size)
156 q.text(","); q.breakable()
157 q.text("prec_level = ");
158 q.text("%#x" % self.prec_level)
159 q.breakable()
160 q.text('}')
161
Rich Lane7dcdf022013-12-11 14:45:27 -0800162meter_band.subtypes[2] = dscp_remark
163
164class experimenter(meter_band):
Dan Talaycof6202252013-07-02 01:00:29 -0700165 type = 65535
Rich Laneca3da272013-05-05 09:07:33 -0700166
167 def __init__(self, rate=None, burst_size=None, experimenter=None):
168 if rate != None:
169 self.rate = rate
170 else:
171 self.rate = 0
172 if burst_size != None:
173 self.burst_size = burst_size
174 else:
175 self.burst_size = 0
176 if experimenter != None:
177 self.experimenter = experimenter
178 else:
179 self.experimenter = 0
180 return
181
182 def pack(self):
183 packed = []
184 packed.append(struct.pack("!H", self.type))
185 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
186 packed.append(struct.pack("!L", self.rate))
187 packed.append(struct.pack("!L", self.burst_size))
188 packed.append(struct.pack("!L", self.experimenter))
189 length = sum([len(x) for x in packed])
190 packed[1] = struct.pack("!H", length)
191 return ''.join(packed)
192
193 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800194 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700195 obj = experimenter()
Dan Talaycof6202252013-07-02 01:00:29 -0700196 _type = reader.read("!H")[0]
197 assert(_type == 65535)
198 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800199 orig_reader = reader
200 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700201 obj.rate = reader.read("!L")[0]
202 obj.burst_size = reader.read("!L")[0]
203 obj.experimenter = reader.read("!L")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700204 return obj
205
206 def __eq__(self, other):
207 if type(self) != type(other): return False
208 if self.rate != other.rate: return False
209 if self.burst_size != other.burst_size: return False
210 if self.experimenter != other.experimenter: return False
211 return True
212
Rich Laneca3da272013-05-05 09:07:33 -0700213 def pretty_print(self, q):
214 q.text("experimenter {")
215 with q.group():
216 with q.indent(2):
217 q.breakable()
218 q.text("rate = ");
219 q.text("%#x" % self.rate)
220 q.text(","); q.breakable()
221 q.text("burst_size = ");
222 q.text("%#x" % self.burst_size)
223 q.text(","); q.breakable()
224 q.text("experimenter = ");
225 q.text("%#x" % self.experimenter)
226 q.breakable()
227 q.text('}')
228
Rich Lane7dcdf022013-12-11 14:45:27 -0800229meter_band.subtypes[65535] = experimenter
Rich Laneca3da272013-05-05 09:07:33 -0700230
Rich Lane7dcdf022013-12-11 14:45:27 -0800231