blob: 4158db6c19ee882ba99a21926d16737bcfba62c2 [file] [log] [blame]
macauleye7df6402015-07-16 17:38:20 +08001"""
2Group table test
3Verify each group table can created correctly
4"""
5from oftest import config
macauley68bd7682015-08-03 09:20:32 +08006
7import logging
8import random
9
10from oftest import config
11import oftest
macauleye7df6402015-07-16 17:38:20 +080012import oftest.base_tests as base_tests
13import ofp
macauley68bd7682015-08-03 09:20:32 +080014
macauleye7df6402015-07-16 17:38:20 +080015from oftest.testutils import *
16from accton_util import *
17
macauley68bd7682015-08-03 09:20:32 +080018def getkey(type):
19 def byGroupId(stats_entry):
20 return stats_entry.group_id
21
macauley6f6ceb22015-08-07 09:37:12 +080022 def byGroupType(stats_entry):
macauley68bd7682015-08-03 09:20:32 +080023 return stats_entry.group_type
24
25
26 if type == "group_id":
27 return byGroupId
28 elif type == "group_type":
29 return byGroupType
30
31 return byGroupId
32
33class L2InterfaceGroupOne(base_tests.SimpleDataPlane):
34 def runTest(self):
35 delete_all_flows(self.controller)
36 delete_all_groups(self.controller)
37
38 group_list1, msg1 = add_one_l2_interface_grouop(self.controller, config["port_map"].keys()[0], 1, False, False)
39 stats = get_stats(self, ofp.message.group_desc_stats_request())
40
41 verify_group_stats=[ofp.group_desc_stats_entry(
42 group_type=msg1.group_type,
43 group_id=msg1.group_id,
44 buckets=msg1.buckets)]
45
46 self.maxDiff=None
47
48 self.assertEquals(stats, verify_group_stats)
49
macauleye7df6402015-07-16 17:38:20 +080050class L2InterfaceGroup(base_tests.SimpleDataPlane):
51 def runTest(self):
macauleyfd08eda2015-07-17 15:59:04 +080052 delete_all_flows(self.controller)
53 delete_all_groups(self.controller)
macauleye7df6402015-07-16 17:38:20 +080054
macauleyfd08eda2015-07-17 15:59:04 +080055 group_list1, msg1 = add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, False)
56 group_list2, msg2 =add_l2_interface_grouop(self.controller, config["port_map"].keys(), 2, False, False)
macauley68bd7682015-08-03 09:20:32 +080057
macauleyfd08eda2015-07-17 15:59:04 +080058 stats = get_stats(self, ofp.message.group_desc_stats_request())
59
60 verify_group_stats=[]
macauley68bd7682015-08-03 09:20:32 +080061
macauleyfd08eda2015-07-17 15:59:04 +080062 for msg in msg1:
63 verify_group_stats.append(ofp.group_desc_stats_entry(
64 group_type=msg.group_type,
65 group_id=msg.group_id,
macauley68bd7682015-08-03 09:20:32 +080066 buckets=msg.buckets))
67
macauleyfd08eda2015-07-17 15:59:04 +080068 for msg in msg2:
69 verify_group_stats.append(ofp.group_desc_stats_entry(
70 group_type=msg.group_type,
71 group_id=msg.group_id,
macauley68bd7682015-08-03 09:20:32 +080072 buckets=msg.buckets))
macauleyfd08eda2015-07-17 15:59:04 +080073
macauley68bd7682015-08-03 09:20:32 +080074 verify_group_stats=sorted(verify_group_stats, key=getkey("group_id"))
75 stats=sorted(stats, key=getkey("group_id"))
macauley6f6ceb22015-08-07 09:37:12 +080076 #self.maxDiff=None
macauley68bd7682015-08-03 09:20:32 +080077 self.assertEquals(stats, verify_group_stats)
macauleyfd08eda2015-07-17 15:59:04 +080078
macauleye7df6402015-07-16 17:38:20 +080079class L2McastGroup(base_tests.SimpleDataPlane):
80 def runTest(self):
81 delete_all_flows(self.controller)
82 delete_all_groups(self.controller)
83
macauleyfd08eda2015-07-17 15:59:04 +080084 group_list1, msg1 = add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, False)
85 msg2=add_l2_mcast_group(self.controller, config["port_map"].keys(), 1, 1)
macauleye7df6402015-07-16 17:38:20 +080086
macauleyfd08eda2015-07-17 15:59:04 +080087 group_list1, msg3 = add_l2_interface_grouop(self.controller, config["port_map"].keys(), 2, False, False)
88 msg4=add_l2_mcast_group(self.controller, config["port_map"].keys(), 2, 2)
macauleye7df6402015-07-16 17:38:20 +080089
macauleyfd08eda2015-07-17 15:59:04 +080090 stats = get_stats(self, ofp.message.group_desc_stats_request())
91
92 verify_group_stats=[]
93 for msg in msg1:
94 verify_group_stats.append(ofp.group_desc_stats_entry(
95 group_type=msg.group_type,
96 group_id=msg.group_id,
97 buckets=msg.buckets)
98 )
99
100 verify_group_stats.append(ofp.group_desc_stats_entry(
101 group_type=msg2.group_type,
102 group_id=msg2.group_id,
103 buckets=msg2.buckets)
104 )
105
106 for msg in msg3:
107 verify_group_stats.append(ofp.group_desc_stats_entry(
108 group_type=msg.group_type,
109 group_id=msg.group_id,
110 buckets=msg.buckets)
111 )
112 verify_group_stats.append(ofp.group_desc_stats_entry(
113 group_type=msg4.group_type,
114 group_id=msg4.group_id,
115 buckets=msg4.buckets)
116 )
macauley68bd7682015-08-03 09:20:32 +0800117
118 verify_group_stats=sorted(verify_group_stats, key=getkey("group_id"))
119 stats=sorted(stats, key=getkey("group_id"))
120 self.maxDiff=None
macauleyfd08eda2015-07-17 15:59:04 +0800121 self.assertEquals(stats, verify_group_stats)
122
123
124class L2FloodGroup(base_tests.SimpleDataPlane):
125 def runTest(self):
126 delete_all_flows(self.controller)
127 delete_all_groups(self.controller)
128
129 group_list1, msg1 = add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, False)
130 msg2=add_l2_flood_group(self.controller, config["port_map"].keys(), 1, 1)
131
132 group_list1, msg3 = add_l2_interface_grouop(self.controller, config["port_map"].keys(), 2, False, False)
133 msg4=add_l2_flood_group(self.controller, config["port_map"].keys(), 2, 2)
134
135 stats = get_stats(self, ofp.message.group_desc_stats_request())
136
137 verify_group_stats=[]
138 for msg in msg1:
139 verify_group_stats.append(ofp.group_desc_stats_entry(
140 group_type=msg.group_type,
141 group_id=msg.group_id,
142 buckets=msg.buckets)
143 )
144
145 verify_group_stats.append(ofp.group_desc_stats_entry(
146 group_type=msg2.group_type,
147 group_id=msg2.group_id,
148 buckets=msg2.buckets)
149 )
150
151 for msg in msg3:
152 verify_group_stats.append(ofp.group_desc_stats_entry(
153 group_type=msg.group_type,
154 group_id=msg.group_id,
155 buckets=msg.buckets)
156 )
157 verify_group_stats.append(ofp.group_desc_stats_entry(
158 group_type=msg4.group_type,
159 group_id=msg4.group_id,
160 buckets=msg4.buckets)
161 )
macauley68bd7682015-08-03 09:20:32 +0800162
163 verify_group_stats=sorted(verify_group_stats, key=getkey("group_id"))
164 stats=sorted(stats, key=getkey("group_id"))
165 self.maxDiff=None
macauleyfd08eda2015-07-17 15:59:04 +0800166 self.assertEquals(stats, verify_group_stats)
167
168
169class L2RewriteGroup(base_tests.SimpleDataPlane):
170 def runTest(self):
171 delete_all_flows(self.controller)
172 delete_all_groups(self.controller)
173
174 group_list1, msg1 = add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, False)
175 msg2=add_l2_rewrite_group(self.controller, config["port_map"].keys()[0], 1, 1, [00,11,22,33,44,55], [00,22,22,22,22,22])
176
177 group_list1, msg3 = add_l2_interface_grouop(self.controller, config["port_map"].keys(), 2, False, False)
178 msg4=add_l2_rewrite_group(self.controller, config["port_map"].keys()[0], 2, 2, [00,11,22,33,44,55], [00,33,33,33,33,33])
179
180 stats = get_stats(self, ofp.message.group_desc_stats_request())
181
182 verify_group_stats=[]
183 for msg in msg1:
184 verify_group_stats.append(ofp.group_desc_stats_entry(
185 group_type=msg.group_type,
186 group_id=msg.group_id,
187 buckets=msg.buckets)
188 )
189
190 verify_group_stats.append(ofp.group_desc_stats_entry(
191 group_type=msg2.group_type,
192 group_id=msg2.group_id,
193 buckets=msg2.buckets)
194 )
195
196 for msg in msg3:
197 verify_group_stats.append(ofp.group_desc_stats_entry(
198 group_type=msg.group_type,
199 group_id=msg.group_id,
200 buckets=msg.buckets)
201 )
202 verify_group_stats.append(ofp.group_desc_stats_entry(
203 group_type=msg4.group_type,
204 group_id=msg4.group_id,
205 buckets=msg4.buckets)
206 )
207
macauley68bd7682015-08-03 09:20:32 +0800208 verify_group_stats=sorted(verify_group_stats, key=getkey("group_id"))
209 stats=sorted(stats, key=getkey("group_id"))
210
211 self.maxDiff=None
macauleyfd08eda2015-07-17 15:59:04 +0800212 self.assertEquals(stats, verify_group_stats)
213
214
215class L3UnicastGroup(base_tests.SimpleDataPlane):
216 def runTest(self):
217 delete_all_flows(self.controller)
218 delete_all_groups(self.controller)
219
220 group_list1, msg1 = add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, False)
221 msg2=add_l3_unicast_group(self.controller, config["port_map"].keys()[0], 1, 1, [0x00,0x11,0x22,0x33,0x44,0x55], [00,0x22,0x22,0x22,0x22,0x22])
222
223 group_list1, msg3 = add_l2_interface_grouop(self.controller, config["port_map"].keys(), 2, False, False)
224 msg4=add_l3_unicast_group(self.controller, config["port_map"].keys()[0], 2, 2, [0x00,0x11,0x22,0x33,0x44,0x55], [00,0x33,0x33,0x33,0x33,0x33])
225
226 stats = get_stats(self, ofp.message.group_desc_stats_request())
227
228 verify_group_stats=[]
229 for msg in msg1:
230 verify_group_stats.append(ofp.group_desc_stats_entry(
231 group_type=msg.group_type,
232 group_id=msg.group_id,
233 buckets=msg.buckets)
234 )
235
236 verify_group_stats.append(ofp.group_desc_stats_entry(
237 group_type=msg2.group_type,
238 group_id=msg2.group_id,
239 buckets=msg2.buckets)
240 )
241
242 for msg in msg3:
243 verify_group_stats.append(ofp.group_desc_stats_entry(
244 group_type=msg.group_type,
245 group_id=msg.group_id,
246 buckets=msg.buckets)
247 )
248 verify_group_stats.append(ofp.group_desc_stats_entry(
249 group_type=msg4.group_type,
250 group_id=msg4.group_id,
251 buckets=msg4.buckets)
252 )
macauley68bd7682015-08-03 09:20:32 +0800253
254 verify_group_stats=sorted(verify_group_stats, key=getkey("group_id"))
255 stats=sorted(stats, key=getkey("group_id"))
256
257 self.maxDiff=None
macauleyfd08eda2015-07-17 15:59:04 +0800258 self.assertEquals(stats, verify_group_stats)
259
260
261class L3ECMPGroup(base_tests.SimpleDataPlane):
262 def runTest(self):
263 delete_all_flows(self.controller)
264 delete_all_groups(self.controller)
265
266 group_list1, msg1 = add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, False)
267 msg2=add_l3_unicast_group(self.controller, config["port_map"].keys()[0], 1, 1, [0x00,0x11,0x22,0x33,0x44,0x55], [00,0x22,0x22,0x22,0x22,0x22])
268
269 group_list1, msg3 = add_l2_interface_grouop(self.controller, config["port_map"].keys(), 2, False, False)
270 msg4=add_l3_unicast_group(self.controller, config["port_map"].keys()[0], 2, 2, [0x00,0x11,0x22,0x33,0x44,0x55], [00,0x33,0x33,0x33,0x33,0x33])
271
272 group_ids=[msg2.group_id, msg4.group_id]
273
274 msg5=add_l3_ecmp_group(self.controller, 1, group_ids)
275
276 stats = get_stats(self, ofp.message.group_desc_stats_request())
277
278 verify_group_stats=[]
279 for msg in msg1:
280 verify_group_stats.append(ofp.group_desc_stats_entry(
281 group_type=msg.group_type,
282 group_id=msg.group_id,
283 buckets=msg.buckets)
284 )
285
286 verify_group_stats.append(ofp.group_desc_stats_entry(
287 group_type=msg2.group_type,
288 group_id=msg2.group_id,
289 buckets=msg2.buckets)
290 )
291
292 for msg in msg3:
293 verify_group_stats.append(ofp.group_desc_stats_entry(
294 group_type=msg.group_type,
295 group_id=msg.group_id,
296 buckets=msg.buckets)
297 )
298 verify_group_stats.append(ofp.group_desc_stats_entry(
299 group_type=msg4.group_type,
300 group_id=msg4.group_id,
301 buckets=msg4.buckets)
302 )
303 verify_group_stats.append(ofp.group_desc_stats_entry(
304 group_type=msg5.group_type,
305 group_id=msg5.group_id,
306 buckets=msg5.buckets)
307 )
308
macauley68bd7682015-08-03 09:20:32 +0800309 verify_group_stats=sorted(verify_group_stats, key=getkey("group_id"))
310 stats=sorted(stats, key=getkey("group_id"))
311
312 self.maxDiff=None
macauleyfd08eda2015-07-17 15:59:04 +0800313 self.assertEquals(stats, verify_group_stats)
314
315
316class L3InterfaceGroup(base_tests.SimpleDataPlane):
317 def runTest(self):
318 delete_all_flows(self.controller)
319 delete_all_groups(self.controller)
320
321 group_list1, msg1 = add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, False)
322 msg2=add_l3_interface_group(self.controller, config["port_map"].keys()[0], 1, 1, [0x00,0x11,0x22,0x33,0x44,0x55])
323 group_list1, msg3 = add_l2_interface_grouop(self.controller, config["port_map"].keys(), 2, False, False)
324 msg4=add_l3_interface_group(self.controller, config["port_map"].keys()[0], 2, 2, [0x00,0x11,0x22,0x33,0x44,0x66])
325
326 stats = get_stats(self, ofp.message.group_desc_stats_request())
327
328 verify_group_stats=[]
329 for msg in msg1:
330 verify_group_stats.append(ofp.group_desc_stats_entry(
331 group_type=msg.group_type,
332 group_id=msg.group_id,
333 buckets=msg.buckets)
334 )
335
336 verify_group_stats.append(ofp.group_desc_stats_entry(
337 group_type=msg2.group_type,
338 group_id=msg2.group_id,
339 buckets=msg2.buckets)
340 )
341
342 for msg in msg3:
343 verify_group_stats.append(ofp.group_desc_stats_entry(
344 group_type=msg.group_type,
345 group_id=msg.group_id,
346 buckets=msg.buckets)
347 )
348 verify_group_stats.append(ofp.group_desc_stats_entry(
349 group_type=msg4.group_type,
350 group_id=msg4.group_id,
351 buckets=msg4.buckets)
352 )
353
macauley68bd7682015-08-03 09:20:32 +0800354 verify_group_stats=sorted(verify_group_stats, key=getkey("group_id"))
355 stats=sorted(stats, key=getkey("group_id"))
356
357 self.maxDiff=None
macauleyfd08eda2015-07-17 15:59:04 +0800358 self.assertEquals(stats, verify_group_stats)
359
360
361class L3McastGroup(base_tests.SimpleDataPlane):
362 def runTest(self):
363 delete_all_flows(self.controller)
364 delete_all_groups(self.controller)
365
366 # Vlan 3 forward to vlan 3 port 1 and 2
367 # Vlan 3 foward to vlan 1 port 1
368 # Vlan 3 foward to vlan 2 port 1
369 # Vlan 3 foward to vlan 2 port 2
370 group_list1_1, msg1 = add_l2_interface_grouop(self.controller, [config["port_map"].keys()[0]], 1, False, False)
371 msg2=add_l3_interface_group(self.controller, config["port_map"].keys()[0], 1, 1, [0x00,0x11,0x22,0x33,0x44,0x11])
372 group_list1_2, msg3 = add_l2_interface_grouop(self.controller, [config["port_map"].keys()[0]], 2, False, False)
373 msg4=add_l3_interface_group(self.controller, config["port_map"].keys()[0], 2, 2, [0x00,0x11,0x22,0x33,0x44,0x22])
374 group_list2_1, msg5 = add_l2_interface_grouop(self.controller, [config["port_map"].keys()[1]], 2, False, False)
375 msg6=add_l3_interface_group(self.controller, config["port_map"].keys()[1], 2, 3, [0x00,0x11,0x22,0x33,0x44,0x33])
376 group_list3, msg7 = add_l2_interface_grouop(self.controller, config["port_map"].keys(), 3, False, False)
377
378 group_actions=[msg2.group_id, msg4.group_id, msg6.group_id]
379 group_actions.extend(group_list3)
380
381 msg8=add_l3_mcast_group(self.controller, 3, 1, group_actions)
382
383 stats = get_stats(self, ofp.message.group_desc_stats_request())
384
385 verify_group_stats=[]
386 for msg in msg1:
387 verify_group_stats.append(ofp.group_desc_stats_entry(
388 group_type=msg.group_type,
389 group_id=msg.group_id,
390 buckets=msg.buckets)
391 )
392
393 verify_group_stats.append(ofp.group_desc_stats_entry(
394 group_type=msg2.group_type,
395 group_id=msg2.group_id,
396 buckets=msg2.buckets)
397 )
398
399 for msg in msg3:
400 verify_group_stats.append(ofp.group_desc_stats_entry(
401 group_type=msg.group_type,
402 group_id=msg.group_id,
403 buckets=msg.buckets)
404 )
405 verify_group_stats.append(ofp.group_desc_stats_entry(
406 group_type=msg4.group_type,
407 group_id=msg4.group_id,
408 buckets=msg4.buckets)
409 )
410 for msg in msg5:
411 verify_group_stats.append(ofp.group_desc_stats_entry(
412 group_type=msg.group_type,
413 group_id=msg.group_id,
414 buckets=msg.buckets)
415 )
416 verify_group_stats.append(ofp.group_desc_stats_entry(
417 group_type=msg6.group_type,
418 group_id=msg6.group_id,
419 buckets=msg6.buckets)
420 )
421 for msg in msg7:
422 verify_group_stats.append(ofp.group_desc_stats_entry(
423 group_type=msg.group_type,
424 group_id=msg.group_id,
425 buckets=msg.buckets)
426 )
427
428 verify_group_stats.append(ofp.group_desc_stats_entry(
429 group_type=msg8.group_type,
430 group_id=msg8.group_id,
431 buckets=msg8.buckets)
432 )
macauley68bd7682015-08-03 09:20:32 +0800433
434 verify_group_stats=sorted(verify_group_stats, key=getkey("group_id"))
435 stats=sorted(stats, key=getkey("group_id"))
macauleyfd08eda2015-07-17 15:59:04 +0800436
macauley68bd7682015-08-03 09:20:32 +0800437 self.maxDiff=None
macauleyfd08eda2015-07-17 15:59:04 +0800438 self.assertEquals(stats, verify_group_stats)
439
440
441