blob: 9c7a23f2dc8f6a401a98ff1761461833e543f700 [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 Laneca3da272013-05-05 09:07:33 -070019import util
20import loxi.generic_util
Rich Laneca3da272013-05-05 09:07:33 -070021
Rich Lane7dcdf022013-12-11 14:45:27 -080022class meter_band(loxi.OFObject):
23 subtypes = {}
Rich Laneca3da272013-05-05 09:07:33 -070024
Rich Lane7dcdf022013-12-11 14:45:27 -080025 @staticmethod
26 def unpack(reader):
27 subtype, = reader.peek('!H', 0)
28 try:
29 subclass = meter_band.subtypes[subtype]
30 except KeyError:
31 raise loxi.ProtocolError("unknown meter_band subtype %#x" % subtype)
32 return subclass.unpack(reader)
Rich Laneca3da272013-05-05 09:07:33 -070033
Rich Lane7dcdf022013-12-11 14:45:27 -080034
35class drop(meter_band):
Dan Talaycof6202252013-07-02 01:00:29 -070036 type = 1
Rich Laneca3da272013-05-05 09:07:33 -070037
38 def __init__(self, rate=None, burst_size=None):
39 if rate != None:
40 self.rate = rate
41 else:
42 self.rate = 0
43 if burst_size != None:
44 self.burst_size = burst_size
45 else:
46 self.burst_size = 0
47 return
48
49 def pack(self):
50 packed = []
51 packed.append(struct.pack("!H", self.type))
52 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
53 packed.append(struct.pack("!L", self.rate))
54 packed.append(struct.pack("!L", self.burst_size))
55 packed.append('\x00' * 4)
56 length = sum([len(x) for x in packed])
57 packed[1] = struct.pack("!H", length)
58 return ''.join(packed)
59
60 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -080061 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -070062 obj = drop()
Dan Talaycof6202252013-07-02 01:00:29 -070063 _type = reader.read("!H")[0]
64 assert(_type == 1)
65 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -080066 orig_reader = reader
67 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -070068 obj.rate = reader.read("!L")[0]
69 obj.burst_size = reader.read("!L")[0]
Rich Laneca3da272013-05-05 09:07:33 -070070 reader.skip(4)
71 return obj
72
73 def __eq__(self, other):
74 if type(self) != type(other): return False
75 if self.rate != other.rate: return False
76 if self.burst_size != other.burst_size: return False
77 return True
78
Rich Laneca3da272013-05-05 09:07:33 -070079 def pretty_print(self, q):
80 q.text("drop {")
81 with q.group():
82 with q.indent(2):
83 q.breakable()
84 q.text("rate = ");
85 q.text("%#x" % self.rate)
86 q.text(","); q.breakable()
87 q.text("burst_size = ");
88 q.text("%#x" % self.burst_size)
89 q.breakable()
90 q.text('}')
91
Rich Lane7dcdf022013-12-11 14:45:27 -080092meter_band.subtypes[1] = drop
93
94class dscp_remark(meter_band):
Dan Talaycof6202252013-07-02 01:00:29 -070095 type = 2
Rich Laneca3da272013-05-05 09:07:33 -070096
97 def __init__(self, rate=None, burst_size=None, prec_level=None):
98 if rate != None:
99 self.rate = rate
100 else:
101 self.rate = 0
102 if burst_size != None:
103 self.burst_size = burst_size
104 else:
105 self.burst_size = 0
106 if prec_level != None:
107 self.prec_level = prec_level
108 else:
109 self.prec_level = 0
110 return
111
112 def pack(self):
113 packed = []
114 packed.append(struct.pack("!H", self.type))
115 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
116 packed.append(struct.pack("!L", self.rate))
117 packed.append(struct.pack("!L", self.burst_size))
118 packed.append(struct.pack("!B", self.prec_level))
119 packed.append('\x00' * 3)
120 length = sum([len(x) for x in packed])
121 packed[1] = struct.pack("!H", length)
122 return ''.join(packed)
123
124 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800125 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700126 obj = dscp_remark()
Dan Talaycof6202252013-07-02 01:00:29 -0700127 _type = reader.read("!H")[0]
128 assert(_type == 2)
129 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800130 orig_reader = reader
131 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700132 obj.rate = reader.read("!L")[0]
133 obj.burst_size = reader.read("!L")[0]
134 obj.prec_level = reader.read("!B")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700135 reader.skip(3)
136 return obj
137
138 def __eq__(self, other):
139 if type(self) != type(other): return False
140 if self.rate != other.rate: return False
141 if self.burst_size != other.burst_size: return False
142 if self.prec_level != other.prec_level: return False
143 return True
144
Rich Laneca3da272013-05-05 09:07:33 -0700145 def pretty_print(self, q):
146 q.text("dscp_remark {")
147 with q.group():
148 with q.indent(2):
149 q.breakable()
150 q.text("rate = ");
151 q.text("%#x" % self.rate)
152 q.text(","); q.breakable()
153 q.text("burst_size = ");
154 q.text("%#x" % self.burst_size)
155 q.text(","); q.breakable()
156 q.text("prec_level = ");
157 q.text("%#x" % self.prec_level)
158 q.breakable()
159 q.text('}')
160
Rich Lane7dcdf022013-12-11 14:45:27 -0800161meter_band.subtypes[2] = dscp_remark
162
163class experimenter(meter_band):
Dan Talaycof6202252013-07-02 01:00:29 -0700164 type = 65535
Rich Laneca3da272013-05-05 09:07:33 -0700165
166 def __init__(self, rate=None, burst_size=None, experimenter=None):
167 if rate != None:
168 self.rate = rate
169 else:
170 self.rate = 0
171 if burst_size != None:
172 self.burst_size = burst_size
173 else:
174 self.burst_size = 0
175 if experimenter != None:
176 self.experimenter = experimenter
177 else:
178 self.experimenter = 0
179 return
180
181 def pack(self):
182 packed = []
183 packed.append(struct.pack("!H", self.type))
184 packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
185 packed.append(struct.pack("!L", self.rate))
186 packed.append(struct.pack("!L", self.burst_size))
187 packed.append(struct.pack("!L", self.experimenter))
188 length = sum([len(x) for x in packed])
189 packed[1] = struct.pack("!H", length)
190 return ''.join(packed)
191
192 @staticmethod
Rich Lane7dcdf022013-12-11 14:45:27 -0800193 def unpack(reader):
Rich Laneca3da272013-05-05 09:07:33 -0700194 obj = experimenter()
Dan Talaycof6202252013-07-02 01:00:29 -0700195 _type = reader.read("!H")[0]
196 assert(_type == 65535)
197 _len = reader.read("!H")[0]
Rich Lane7dcdf022013-12-11 14:45:27 -0800198 orig_reader = reader
199 reader = orig_reader.slice(_len - (2 + 2))
Dan Talaycof6202252013-07-02 01:00:29 -0700200 obj.rate = reader.read("!L")[0]
201 obj.burst_size = reader.read("!L")[0]
202 obj.experimenter = reader.read("!L")[0]
Rich Laneca3da272013-05-05 09:07:33 -0700203 return obj
204
205 def __eq__(self, other):
206 if type(self) != type(other): return False
207 if self.rate != other.rate: return False
208 if self.burst_size != other.burst_size: return False
209 if self.experimenter != other.experimenter: return False
210 return True
211
Rich Laneca3da272013-05-05 09:07:33 -0700212 def pretty_print(self, q):
213 q.text("experimenter {")
214 with q.group():
215 with q.indent(2):
216 q.breakable()
217 q.text("rate = ");
218 q.text("%#x" % self.rate)
219 q.text(","); q.breakable()
220 q.text("burst_size = ");
221 q.text("%#x" % self.burst_size)
222 q.text(","); q.breakable()
223 q.text("experimenter = ");
224 q.text("%#x" % self.experimenter)
225 q.breakable()
226 q.text('}')
227
Rich Lane7dcdf022013-12-11 14:45:27 -0800228meter_band.subtypes[65535] = experimenter
Rich Laneca3da272013-05-05 09:07:33 -0700229
Rich Lane7dcdf022013-12-11 14:45:27 -0800230