blob: 512d4aa74f3d165b08eff08ca2832fe1c6f289d1 [file] [log] [blame]
Rich Lane3f075972013-03-15 22:56:29 -07001#!/usr/bin/env python
2# Copyright 2013, Big Switch Networks, Inc.
3#
4# LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
5# the following special exception:
6#
7# LOXI Exception
8#
9# As a special exception to the terms of the EPL, you may distribute libraries
10# generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
11# that copyright and licensing notices generated by LoxiGen are not altered or removed
12# from the LoxiGen Libraries and the notice provided below is (i) included in
13# the LoxiGen Libraries, if distributed in source code form and (ii) included in any
14# documentation for the LoxiGen Libraries, if distributed in binary form.
15#
16# Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
17#
18# You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
19# a copy of the EPL at:
20#
21# http://www.eclipse.org/legal/epl-v10.html
22#
23# Unless required by applicable law or agreed to in writing, software
24# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
25# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
26# EPL for the specific language governing permissions and limitations
27# under the EPL.
28import unittest
29
30try:
31 import loxi.of13 as ofp
32except ImportError:
33 exit("loxi package not found. Try setting PYTHONPATH.")
34
35class TestImports(unittest.TestCase):
36 def test_toplevel(self):
37 import loxi
38 self.assertTrue(hasattr(loxi, "ProtocolError"))
39 ofp = loxi.protocol(4)
40 self.assertEquals(ofp.OFP_VERSION, 4)
41 self.assertTrue(hasattr(ofp, "action"))
42 self.assertTrue(hasattr(ofp, "common"))
43 self.assertTrue(hasattr(ofp, "const"))
44 self.assertTrue(hasattr(ofp, "message"))
45
46 def test_version(self):
47 import loxi
48 self.assertTrue(hasattr(loxi.of13, "ProtocolError"))
49 self.assertTrue(hasattr(loxi.of13, "OFP_VERSION"))
50 self.assertEquals(loxi.of13.OFP_VERSION, 4)
51 self.assertTrue(hasattr(loxi.of13, "action"))
52 self.assertTrue(hasattr(loxi.of13, "common"))
53 self.assertTrue(hasattr(loxi.of13, "const"))
54 self.assertTrue(hasattr(loxi.of13, "message"))
55
56class TestAllOF13(unittest.TestCase):
57 """
58 Round-trips every class through serialization/deserialization.
59 Not a replacement for handcoded tests because it only uses the
60 default member values.
61 """
62
63 def setUp(self):
64 mods = [ofp.action,ofp.message,ofp.common]
65 self.klasses = [klass for mod in mods
66 for klass in mod.__dict__.values()
67 if hasattr(klass, 'show')]
68 self.klasses.sort(key=lambda x: str(x))
69
70 def test_serialization(self):
71 expected_failures = [
72 ofp.common.action_id,
73 ofp.common.action_id_bsn_mirror,
74 ofp.common.action_id_bsn_set_tunnel_dst,
75 ofp.common.action_id_copy_ttl_in,
76 ofp.common.action_id_copy_ttl_out,
77 ofp.common.action_id_dec_mpls_ttl,
78 ofp.common.action_id_dec_nw_ttl,
79 ofp.common.action_id_experimenter,
80 ofp.common.action_id_group,
81 ofp.common.action_id_header,
82 ofp.common.action_id_nicira_dec_ttl,
83 ofp.common.action_id_output,
84 ofp.common.action_id_pop_mpls,
85 ofp.common.action_id_pop_pbb,
86 ofp.common.action_id_pop_vlan,
87 ofp.common.action_id_push_mpls,
88 ofp.common.action_id_push_pbb,
89 ofp.common.action_id_push_vlan,
90 ofp.common.action_id_set_field,
91 ofp.common.action_id_set_mpls_ttl,
92 ofp.common.action_id_set_nw_ttl,
93 ofp.common.action_id_set_queue,
94 ofp.common.flow_stats_entry,
95 ofp.common.group_desc_stats_entry,
96 ofp.common.hello_elem,
97 ofp.common.hello_elem_header,
98 ofp.common.hello_elem_versionbitmap,
99 ofp.common.instruction,
100 ofp.common.instruction_apply_actions,
101 ofp.common.instruction_clear_actions,
102 ofp.common.instruction_experimenter,
103 ofp.common.instruction_goto_table,
104 ofp.common.instruction_header,
105 ofp.common.instruction_meter,
106 ofp.common.instruction_write_actions,
107 ofp.common.instruction_write_metadata,
108 ofp.common.match_v3,
109 ofp.common.meter_band,
110 ofp.common.meter_band_drop,
111 ofp.common.meter_band_dscp_remark,
112 ofp.common.meter_band_experimenter,
113 ofp.common.meter_band_header,
114 ofp.common.oxm_arp_op,
115 ofp.common.oxm_arp_op_masked,
116 ofp.common.oxm_arp_sha,
117 ofp.common.oxm_arp_sha_masked,
118 ofp.common.oxm_arp_spa,
119 ofp.common.oxm_arp_spa_masked,
120 ofp.common.oxm_arp_tha,
121 ofp.common.oxm_arp_tha_masked,
122 ofp.common.oxm_arp_tpa,
123 ofp.common.oxm_arp_tpa_masked,
124 ofp.common.oxm_eth_dst,
125 ofp.common.oxm_eth_dst_masked,
126 ofp.common.oxm_eth_src,
127 ofp.common.oxm_eth_src_masked,
128 ofp.common.oxm_eth_type,
129 ofp.common.oxm_eth_type_masked,
130 ofp.common.oxm_header,
131 ofp.common.oxm_icmpv4_code,
132 ofp.common.oxm_icmpv4_code_masked,
133 ofp.common.oxm_icmpv4_type,
134 ofp.common.oxm_icmpv4_type_masked,
135 ofp.common.oxm_icmpv6_code,
136 ofp.common.oxm_icmpv6_code_masked,
137 ofp.common.oxm_icmpv6_type,
138 ofp.common.oxm_icmpv6_type_masked,
139 ofp.common.oxm_in_phy_port,
140 ofp.common.oxm_in_phy_port_masked,
141 ofp.common.oxm_in_port,
142 ofp.common.oxm_in_port_masked,
143 ofp.common.oxm_ip_dscp,
144 ofp.common.oxm_ip_dscp_masked,
145 ofp.common.oxm_ip_ecn,
146 ofp.common.oxm_ip_ecn_masked,
147 ofp.common.oxm_ip_proto,
148 ofp.common.oxm_ip_proto_masked,
149 ofp.common.oxm_ipv4_dst,
150 ofp.common.oxm_ipv4_dst_masked,
151 ofp.common.oxm_ipv4_src,
152 ofp.common.oxm_ipv4_src_masked,
153 ofp.common.oxm_ipv6_dst,
154 ofp.common.oxm_ipv6_dst_masked,
155 ofp.common.oxm_ipv6_flabel,
156 ofp.common.oxm_ipv6_flabel_masked,
157 ofp.common.oxm_ipv6_nd_sll,
158 ofp.common.oxm_ipv6_nd_sll_masked,
159 ofp.common.oxm_ipv6_nd_target,
160 ofp.common.oxm_ipv6_nd_target_masked,
161 ofp.common.oxm_ipv6_nd_tll,
162 ofp.common.oxm_ipv6_nd_tll_masked,
163 ofp.common.oxm_ipv6_src,
164 ofp.common.oxm_ipv6_src_masked,
165 ofp.common.oxm_metadata,
166 ofp.common.oxm_metadata_masked,
167 ofp.common.oxm_mpls_label,
168 ofp.common.oxm_mpls_label_masked,
169 ofp.common.oxm_mpls_tc,
170 ofp.common.oxm_mpls_tc_masked,
171 ofp.common.oxm_sctp_dst,
172 ofp.common.oxm_sctp_dst_masked,
173 ofp.common.oxm_sctp_src,
174 ofp.common.oxm_sctp_src_masked,
175 ofp.common.oxm_tcp_dst,
176 ofp.common.oxm_tcp_dst_masked,
177 ofp.common.oxm_tcp_src,
178 ofp.common.oxm_tcp_src_masked,
179 ofp.common.oxm_udp_dst,
180 ofp.common.oxm_udp_dst_masked,
181 ofp.common.oxm_udp_src,
182 ofp.common.oxm_udp_src_masked,
183 ofp.common.oxm_vlan_pcp,
184 ofp.common.oxm_vlan_pcp_masked,
185 ofp.common.oxm_vlan_vid,
186 ofp.common.oxm_vlan_vid_masked,
187 ofp.common.table_feature_prop,
188 ofp.common.table_feature_prop_apply_actions,
189 ofp.common.table_feature_prop_apply_actions_miss,
190 ofp.common.table_feature_prop_apply_setfield,
191 ofp.common.table_feature_prop_apply_setfield_miss,
192 ofp.common.table_feature_prop_experimenter,
193 ofp.common.table_feature_prop_header,
194 ofp.common.table_feature_prop_instructions,
195 ofp.common.table_feature_prop_instructions_miss,
196 ofp.common.table_feature_prop_match,
197 ofp.common.table_feature_prop_next_tables,
198 ofp.common.table_feature_prop_next_tables_miss,
199 ofp.common.table_feature_prop_wildcards,
200 ofp.common.table_feature_prop_write_actions,
201 ofp.common.table_feature_prop_write_actions_miss,
202 ofp.common.table_feature_prop_write_setfield,
203 ofp.common.table_feature_prop_write_setfield_miss,
204 ofp.message.aggregate_stats_request,
205 ofp.message.flow_add,
206 ofp.message.flow_delete,
207 ofp.message.flow_delete_strict,
208 ofp.message.flow_modify,
209 ofp.message.flow_modify_strict,
210 ofp.message.flow_removed,
211 ofp.message.flow_stats_request,
212 ofp.message.group_desc_stats_reply,
213 ofp.message.group_mod,
214 ofp.message.group_stats_reply,
215 ofp.message.meter_features_stats_reply,
216 ofp.message.meter_stats_reply,
217 ofp.message.packet_in,
218 ofp.message.table_features_stats_reply,
219 ofp.message.table_features_stats_request,
220 ]
221 for klass in self.klasses:
222 def fn():
223 obj = klass()
224 if hasattr(obj, "xid"): obj.xid = 42
225 buf = obj.pack()
226 obj2 = klass.unpack(buf)
227 self.assertEquals(obj, obj2)
228 if klass in expected_failures:
229 self.assertRaises(Exception, fn)
230 else:
231 fn()
232
233 def test_show(self):
234 expected_failures = [
235 ofp.common.action_id,
236 ofp.common.action_id_bsn_mirror,
237 ofp.common.action_id_bsn_set_tunnel_dst,
238 ofp.common.action_id_copy_ttl_in,
239 ofp.common.action_id_copy_ttl_out,
240 ofp.common.action_id_dec_mpls_ttl,
241 ofp.common.action_id_dec_nw_ttl,
242 ofp.common.action_id_experimenter,
243 ofp.common.action_id_group,
244 ofp.common.action_id_header,
245 ofp.common.action_id_nicira_dec_ttl,
246 ofp.common.action_id_output,
247 ofp.common.action_id_pop_mpls,
248 ofp.common.action_id_pop_pbb,
249 ofp.common.action_id_pop_vlan,
250 ofp.common.action_id_push_mpls,
251 ofp.common.action_id_push_pbb,
252 ofp.common.action_id_push_vlan,
253 ofp.common.action_id_set_field,
254 ofp.common.action_id_set_mpls_ttl,
255 ofp.common.action_id_set_nw_ttl,
256 ofp.common.action_id_set_queue,
257 ofp.common.flow_stats_entry,
258 ofp.common.group_desc_stats_entry,
259 ofp.common.hello_elem,
260 ofp.common.hello_elem_header,
261 ofp.common.hello_elem_versionbitmap,
262 ofp.common.instruction,
263 ofp.common.instruction_apply_actions,
264 ofp.common.instruction_clear_actions,
265 ofp.common.instruction_experimenter,
266 ofp.common.instruction_goto_table,
267 ofp.common.instruction_header,
268 ofp.common.instruction_meter,
269 ofp.common.instruction_write_actions,
270 ofp.common.instruction_write_metadata,
271 ofp.common.match_v3,
272 ofp.common.meter_band,
273 ofp.common.meter_band_drop,
274 ofp.common.meter_band_dscp_remark,
275 ofp.common.meter_band_experimenter,
276 ofp.common.meter_band_header,
277 ofp.common.oxm_arp_op,
278 ofp.common.oxm_arp_op_masked,
279 ofp.common.oxm_arp_sha,
280 ofp.common.oxm_arp_sha_masked,
281 ofp.common.oxm_arp_spa,
282 ofp.common.oxm_arp_spa_masked,
283 ofp.common.oxm_arp_tha,
284 ofp.common.oxm_arp_tha_masked,
285 ofp.common.oxm_arp_tpa,
286 ofp.common.oxm_arp_tpa_masked,
287 ofp.common.oxm_eth_dst,
288 ofp.common.oxm_eth_dst_masked,
289 ofp.common.oxm_eth_src,
290 ofp.common.oxm_eth_src_masked,
291 ofp.common.oxm_eth_type,
292 ofp.common.oxm_eth_type_masked,
293 ofp.common.oxm_header,
294 ofp.common.oxm_icmpv4_code,
295 ofp.common.oxm_icmpv4_code_masked,
296 ofp.common.oxm_icmpv4_type,
297 ofp.common.oxm_icmpv4_type_masked,
298 ofp.common.oxm_icmpv6_code,
299 ofp.common.oxm_icmpv6_code_masked,
300 ofp.common.oxm_icmpv6_type,
301 ofp.common.oxm_icmpv6_type_masked,
302 ofp.common.oxm_in_phy_port,
303 ofp.common.oxm_in_phy_port_masked,
304 ofp.common.oxm_in_port,
305 ofp.common.oxm_in_port_masked,
306 ofp.common.oxm_ip_dscp,
307 ofp.common.oxm_ip_dscp_masked,
308 ofp.common.oxm_ip_ecn,
309 ofp.common.oxm_ip_ecn_masked,
310 ofp.common.oxm_ip_proto,
311 ofp.common.oxm_ip_proto_masked,
312 ofp.common.oxm_ipv4_dst,
313 ofp.common.oxm_ipv4_dst_masked,
314 ofp.common.oxm_ipv4_src,
315 ofp.common.oxm_ipv4_src_masked,
316 ofp.common.oxm_ipv6_dst,
317 ofp.common.oxm_ipv6_dst_masked,
318 ofp.common.oxm_ipv6_flabel,
319 ofp.common.oxm_ipv6_flabel_masked,
320 ofp.common.oxm_ipv6_nd_sll,
321 ofp.common.oxm_ipv6_nd_sll_masked,
322 ofp.common.oxm_ipv6_nd_target,
323 ofp.common.oxm_ipv6_nd_target_masked,
324 ofp.common.oxm_ipv6_nd_tll,
325 ofp.common.oxm_ipv6_nd_tll_masked,
326 ofp.common.oxm_ipv6_src,
327 ofp.common.oxm_ipv6_src_masked,
328 ofp.common.oxm_metadata,
329 ofp.common.oxm_metadata_masked,
330 ofp.common.oxm_mpls_label,
331 ofp.common.oxm_mpls_label_masked,
332 ofp.common.oxm_mpls_tc,
333 ofp.common.oxm_mpls_tc_masked,
334 ofp.common.oxm_sctp_dst,
335 ofp.common.oxm_sctp_dst_masked,
336 ofp.common.oxm_sctp_src,
337 ofp.common.oxm_sctp_src_masked,
338 ofp.common.oxm_tcp_dst,
339 ofp.common.oxm_tcp_dst_masked,
340 ofp.common.oxm_tcp_src,
341 ofp.common.oxm_tcp_src_masked,
342 ofp.common.oxm_udp_dst,
343 ofp.common.oxm_udp_dst_masked,
344 ofp.common.oxm_udp_src,
345 ofp.common.oxm_udp_src_masked,
346 ofp.common.oxm_vlan_pcp,
347 ofp.common.oxm_vlan_pcp_masked,
348 ofp.common.oxm_vlan_vid,
349 ofp.common.oxm_vlan_vid_masked,
350 ofp.common.table_feature_prop,
351 ofp.common.table_feature_prop_apply_actions,
352 ofp.common.table_feature_prop_apply_actions_miss,
353 ofp.common.table_feature_prop_apply_setfield,
354 ofp.common.table_feature_prop_apply_setfield_miss,
355 ofp.common.table_feature_prop_experimenter,
356 ofp.common.table_feature_prop_header,
357 ofp.common.table_feature_prop_instructions,
358 ofp.common.table_feature_prop_instructions_miss,
359 ofp.common.table_feature_prop_match,
360 ofp.common.table_feature_prop_next_tables,
361 ofp.common.table_feature_prop_next_tables_miss,
362 ofp.common.table_feature_prop_wildcards,
363 ofp.common.table_feature_prop_write_actions,
364 ofp.common.table_feature_prop_write_actions_miss,
365 ofp.common.table_feature_prop_write_setfield,
366 ofp.common.table_feature_prop_write_setfield_miss,
367 ofp.message.aggregate_stats_request,
368 ofp.message.flow_add,
369 ofp.message.flow_delete,
370 ofp.message.flow_delete_strict,
371 ofp.message.flow_modify,
372 ofp.message.flow_modify_strict,
373 ofp.message.flow_removed,
374 ofp.message.flow_stats_request,
375 ofp.message.packet_in,
376 ]
377 for klass in self.klasses:
378 def fn():
379 obj = klass()
380 if hasattr(obj, "xid"): obj.xid = 42
381 obj.show()
382 if klass in expected_failures:
383 self.assertRaises(Exception, fn)
384 else:
385 fn()
386
387if __name__ == '__main__':
388 unittest.main()