blob: 0b417e2adaab6a886433ff8f69adf5d4490d7509 [file] [log] [blame]
Rich Laneea873262013-01-11 08:15:55 -08001"""
2Group table test cases.
3"""
Rich Laneea873262013-01-11 08:15:55 -08004import logging
Rich Laneea873262013-01-11 08:15:55 -08005
6from oftest import config
Rich Lane48e447e2013-05-07 15:23:35 -07007import ofp
Rich Laneea873262013-01-11 08:15:55 -08008import oftest.oft12.testutils as testutils
9import oftest.base_tests as base_tests
Rich Lane48e447e2013-05-07 15:23:35 -070010import oftest.parse
Rich Laneea873262013-01-11 08:15:55 -080011
12def create_group_desc_stats_req():
13 # XXX Zoltan: hack, remove if message module is fixed
14 m = ofp.message.group_desc_stats_request()
15
16 return m
17
18
19
20def create_group_stats_req(group_id = 0):
21 m = ofp.message.group_stats_request()
22 m.group_id = group_id
23
24 return m
25
26
27
28def create_group_mod_msg(command = ofp.OFPGC_ADD, type = ofp.OFPGT_ALL,
29 group_id = 0, buckets = []):
30 m = ofp.message.group_mod()
31 m.command = command
Rich Lane48e447e2013-05-07 15:23:35 -070032 m.group_type = type
Rich Laneea873262013-01-11 08:15:55 -080033 m.group_id = group_id
34 for b in buckets:
Rich Lane48e447e2013-05-07 15:23:35 -070035 m.buckets.append(b)
Rich Laneea873262013-01-11 08:15:55 -080036
37 return m
38
39
40
41# XXX Zoltan: watch_port/_group off ?
42def create_bucket(weight = 0, watch_port = 0, watch_group = 0, actions=[]):
Rich Lane48e447e2013-05-07 15:23:35 -070043 b = ofp.bucket()
Rich Laneea873262013-01-11 08:15:55 -080044 b.weight = weight
45 b.watch_port = watch_port
46 b.watch_group = watch_group
47 for a in actions:
Rich Lane48e447e2013-05-07 15:23:35 -070048 b.actions.append(a)
Rich Laneea873262013-01-11 08:15:55 -080049
50 return b
51
52
53
54def create_action(**kwargs):
55 a = kwargs.get('action')
56 if a == ofp.OFPAT_OUTPUT:
Rich Lane63393492013-01-11 09:21:12 -080057 act = ofp.action.output()
Rich Laneea873262013-01-11 08:15:55 -080058 act.port = kwargs.get('port', 1)
59 return act
60 if a == ofp.OFPAT_GROUP:
Rich Lane63393492013-01-11 09:21:12 -080061 act = ofp.action.group()
Rich Laneea873262013-01-11 08:15:55 -080062 act.group_id = kwargs.get('group_id', 0)
63 return act
64 if a == ofp.OFPAT_SET_FIELD:
65 port = kwargs.get('tcp_sport', 0)
Rich Lane48e447e2013-05-07 15:23:35 -070066 field_2b_set = ofp.oxm.tcp_src(port)
Rich Lane63393492013-01-11 09:21:12 -080067 act = ofp.action.set_field()
Rich Lane48e447e2013-05-07 15:23:35 -070068 act.field = field_2b_set.pack() + '\x00' * 6 # HACK
Rich Laneea873262013-01-11 08:15:55 -080069 return act;
70
71
72
73def create_flow_msg(packet = None, in_port = None, match = None, apply_action_list = []):
74
Rich Lane48e447e2013-05-07 15:23:35 -070075 apply_inst = ofp.instruction.apply_actions()
Rich Laneea873262013-01-11 08:15:55 -080076
77 if apply_action_list is not None:
78 for act in apply_action_list:
Rich Lane48e447e2013-05-07 15:23:35 -070079 apply_inst.actions.append(act)
Rich Laneea873262013-01-11 08:15:55 -080080
Rich Lane48e447e2013-05-07 15:23:35 -070081 request = ofp.message.flow_add()
Rich Laneea873262013-01-11 08:15:55 -080082
83 if match is None:
Rich Lane48e447e2013-05-07 15:23:35 -070084 match = oftest.parse.packet_to_flow_match(packet)
Rich Laneea873262013-01-11 08:15:55 -080085
Rich Lane48e447e2013-05-07 15:23:35 -070086 request.match = match
Rich Laneea873262013-01-11 08:15:55 -080087
88 if in_port != None:
Rich Lane48e447e2013-05-07 15:23:35 -070089 match_port = ofp.oxm.in_port(in_port)
90 request.match.oxm_list.append(match_port)
Rich Laneea873262013-01-11 08:15:55 -080091 request.buffer_id = 0xffffffff
92 request.priority = 1000
93
Rich Lane48e447e2013-05-07 15:23:35 -070094 request.instructions.append(apply_inst)
Rich Laneea873262013-01-11 08:15:55 -080095
96 return request
97
98
99
100class GroupTest(base_tests.SimpleDataPlane):
101
102 def clear_switch(self):
103 testutils.delete_all_flows(self.controller, logging)
104 testutils.delete_all_groups(self.controller, logging)
105
106 def send_ctrl_exp_noerror(self, msg, log = ''):
107 logging.info('Sending message ' + log)
108# logging.debug(msg.show())
109 rv = self.controller.message_send(msg)
110 self.assertTrue(rv != -1, 'Error sending!')
111
112 logging.info('Waiting for error messages...')
113 (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 1)
114
115 self.assertTrue(response is None, 'Unexpected error message received')
116
117 testutils.do_barrier(self.controller);
118
119
120
121 def send_ctrl_exp_error(self, msg, log = '', type = 0, code = 0):
122 logging.info('Sending message ' + log)
123 logging.debug(msg.show())
124 rv = self.controller.message_send(msg)
125 self.assertTrue(rv != -1, 'Error sending!')
126
127 logging.info('Waiting for error messages...')
128 (response, raw) = self.controller.poll(ofp.OFPT_ERROR, 1)
129
130 self.assertTrue(response is not None,
131 'Did not receive an error message')
132
Rich Lane48e447e2013-05-07 15:23:35 -0700133 self.assertEqual(response.type, ofp.OFPT_ERROR,
Rich Laneea873262013-01-11 08:15:55 -0800134 'Did not receive an error message')
135
136 if type != 0:
Rich Lane48e447e2013-05-07 15:23:35 -0700137 self.assertEqual(response.err_type, type,
Rich Laneea873262013-01-11 08:15:55 -0800138 'Did not receive a ' + str(type) + ' type error message')
139
140 if code != 0:
141 self.assertEqual(response.code, code,
142 'Did not receive a ' + str(code) + ' code error message')
143
144 testutils.do_barrier(self.controller);
145
146
147
148 def send_ctrl_exp_reply(self, msg, resp_type = ofp.OFPT_ERROR, log = ''):
149 logging.info('Sending message ' + log)
150 logging.debug(msg.show())
151 rv = self.controller.message_send(msg)
152 self.assertTrue(rv != -1, 'Error sending!')
153
154 logging.info('Waiting for error messages...')
155 (response, raw) = self.controller.poll(resp_type, 1)
156
157 self.assertTrue(response is not None, 'Did not receive expected message')
158
159 return response
160
161
162
163 def send_data(self, packet, in_port):
ederlffdedc072013-01-18 09:32:00 -0200164 logging.debug("Send packet on port " + str(in_port))
Rich Laneea873262013-01-11 08:15:55 -0800165 self.dataplane.send(in_port, str(packet))
166
167
168 def recv_data(self, port, expected = None):
169 pkt = testutils.receive_pkt_verify(self, port, expected)
170 return pkt
171
172"""
173Management
174"""
175
176class GroupAdd(GroupTest):
177 """
178 A regular group should be added successfully (without errors)
179 """
180
181 def runTest(self):
182 self.clear_switch()
183
184 group_add_msg = \
185 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 0, buckets = [
186 create_bucket(0, 0, 0, [
187 create_action(action= ofp.OFPAT_OUTPUT, port= 1)
188 ])
189 ])
190
191 self.send_ctrl_exp_noerror(group_add_msg, 'group add')
192
193
194
195class GroupAddInvalidAction(GroupTest):
196 """
197 If any action in the buckets is invalid, OFPET_BAD_ACTION/<code> should be returned
198 """
199
200 def runTest(self):
201 self.clear_switch()
202
203 group_add_msg = \
204 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 0, buckets = [
205 create_bucket(0, 0, 0, [
206 create_action(action= ofp.OFPAT_OUTPUT, port= ofp.OFPP_ANY)
207 ])
208 ])
209
210 self.send_ctrl_exp_error(group_add_msg, 'group add',
211 ofp.OFPET_BAD_ACTION,
212 ofp.OFPBAC_BAD_OUT_PORT)
213
214
215
216class GroupAddExisting(GroupTest):
217 """
218 An addition with existing group id should result in OFPET_GROUP_MOD_FAILED/OFPGMFC_GROUP_EXISTS
219 """
220
221 def runTest(self):
222 self.clear_switch()
223
224 group_add_msg = \
225 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 0, buckets = [
226 create_bucket(0, 0, 0, [
227 create_action(action= ofp.OFPAT_OUTPUT, port= 1)
228 ])
229 ])
230
231 self.send_ctrl_exp_noerror(group_add_msg, 'group add 1')
232
233 group_mod_msg2 = \
234 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 0, buckets = [
235 create_bucket(0, 0, 0, [
236 create_action(action= ofp.OFPAT_OUTPUT, port= 1)
237 ])
238 ])
239
240 self.send_ctrl_exp_error(group_add_msg, 'group add 2',
241 ofp.OFPET_GROUP_MOD_FAILED,
242 ofp.OFPGMFC_GROUP_EXISTS)
243
244
245
246class GroupAddInvalidID(GroupTest):
247 """
248 An addition with invalid group id (reserved) should result in OFPET_GROUP_MOD_FAILED/OFPGMFC_INVALID_GROUP
249 """
250
251 def runTest(self):
252 self.clear_switch()
253
254 group_add_msg = \
255 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = ofp.OFPG_ALL, buckets = [
256 create_bucket(0, 0, 0, [
257 create_action(action= ofp.OFPAT_OUTPUT, port= 1)
258 ])
259 ])
260
261 self.send_ctrl_exp_error(group_add_msg, 'group add',
262 ofp.OFPET_GROUP_MOD_FAILED,
263 ofp.OFPGMFC_INVALID_GROUP)
264
265
266
267class GroupMod(GroupTest):
268 """
269 A regular group modification should be successful (no errors)
270 """
271
272 def runTest(self):
273 self.clear_switch()
274
275 group_add_msg = \
276 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 0, buckets = [
277 create_bucket(0, 0, 0, [
278 create_action(action= ofp.OFPAT_OUTPUT, port= 1)
279 ])
280 ])
281
282 self.send_ctrl_exp_noerror(group_add_msg, 'group add')
283
284 group_mod_msg = \
285 create_group_mod_msg(ofp.OFPGC_MODIFY, ofp.OFPGT_ALL, group_id = 0, buckets = [
286 create_bucket(0, 0, 0, [
287 create_action(action= ofp.OFPAT_OUTPUT, port= 1)
288 ])
289 ])
290
291 self.send_ctrl_exp_noerror(group_mod_msg, 'group mod')
292
293
294
295class GroupModNonexisting(GroupTest):
296 """
297 A modification for non-existing group should result in OFPET_GROUP_MOD_FAILED/OFPGMFC_UNKNOWN_GROUP
298 """
299
300 def runTest(self):
301 self.clear_switch()
302
303 group_add_msg = \
304 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 0, buckets = [
305 create_bucket(0, 0, 0, [
306 create_action(action= ofp.OFPAT_OUTPUT, port= 1)
307 ])
308 ])
309
310 self.send_ctrl_exp_noerror(group_add_msg, 'group add')
311
312 group_mod_msg = \
313 create_group_mod_msg(ofp.OFPGC_MODIFY, ofp.OFPGT_ALL, group_id = 1, buckets = [
314 create_bucket(0, 0, 0, [
315 create_action(action= ofp.OFPAT_OUTPUT, port= 1)
316 ])
317 ])
318
319 self.send_ctrl_exp_error(group_mod_msg, 'group mod',
320 ofp.OFPET_GROUP_MOD_FAILED,
321 ofp.OFPGMFC_UNKNOWN_GROUP)
322
323
324
325class GroupModLoop(GroupTest):
326 """
327 A modification causing loop should result in OFPET_GROUP_MOD_FAILED/OFPGMFC_LOOP
328 """
329
330 def runTest(self):
331 self.clear_switch()
332
333 group_add_msg1 = \
334 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 0, buckets = [
335 create_bucket(0, 0, 0, [
336 create_action(action= ofp.OFPAT_OUTPUT, port= 1)
337 ])
338 ])
339
340 self.send_ctrl_exp_noerror(group_add_msg1, 'group add 1')
341
342 group_add_msg2 = \
343 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 1, buckets = [
344 create_bucket(0, 0, 0, [
345 create_action(action= ofp.OFPAT_GROUP, group_id= 0)
346 ])
347 ])
348
349 self.send_ctrl_exp_noerror(group_add_msg2, 'group add 2')
350
351 group_add_msg3 = \
352 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 2, buckets = [
353 create_bucket(0, 0, 0, [
354 create_action(action= ofp.OFPAT_GROUP, group_id= 0)
355 ])
356 ])
357
358 self.send_ctrl_exp_noerror(group_add_msg3, 'group add 3')
359
360
361 group_mod_msg = \
362 create_group_mod_msg(ofp.OFPGC_MODIFY, ofp.OFPGT_ALL, group_id = 0, buckets = [
363 create_bucket(0, 0, 0, [
364 create_action(action= ofp.OFPAT_GROUP, group_id= 2)
365 ])
366 ])
367
368 self.send_ctrl_exp_error(group_mod_msg, 'group mod',
369 ofp.OFPET_GROUP_MOD_FAILED,
370 ofp.OFPGMFC_LOOP)
371
372
373
374class GroupModInvalidID(GroupTest):
375 """
376 A modification for reserved group should result in OFPET_BAD_ACTION/OFPGMFC_INVALID_GROUP
377 """
378
379 def runTest(self):
380 self.clear_switch()
381
382 group_mod_msg = \
383 create_group_mod_msg(ofp.OFPGC_MODIFY, ofp.OFPGT_ALL, group_id = ofp.OFPG_ALL, buckets = [
384 create_bucket(0, 0, 0, [
385 create_action(action= ofp.OFPAT_OUTPUT, port= 1)
386 ])
387 ])
388
389 self.send_ctrl_exp_error(group_mod_msg, 'group mod',
390 ofp.OFPET_GROUP_MOD_FAILED,
391 ofp.OFPGMFC_INVALID_GROUP)
392
393
394
395class GroupModEmpty(GroupTest):
396 """
397 A modification for existing group with no buckets should be accepted
398 """
399
400 def runTest(self):
401 self.clear_switch()
402
403 group_add_msg = \
404 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 0, buckets = [
405 create_bucket(0, 0, 0, [
406 create_action(action= ofp.OFPAT_OUTPUT, port= 1)
407 ])
408 ])
409
410 self.send_ctrl_exp_noerror(group_add_msg, 'group add')
411
412 group_mod_msg = \
413 create_group_mod_msg(ofp.OFPGC_MODIFY, ofp.OFPGT_ALL, group_id = 0, buckets = [
414 ])
415
416 self.send_ctrl_exp_noerror(group_mod_msg, 'group mod')
417
418
419
420class GroupDelExisting(GroupTest):
421 """
422 A deletion for existing group should remove the group
423 """
424
425 def runTest(self):
426 #self.clear_switch()
427
428 group_add_msg = \
429 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 10, buckets = [
430 create_bucket(0, 0, 0, [
431 create_action(action= ofp.OFPAT_OUTPUT, port= 1)
432 ])
433 ])
434
435 self.send_ctrl_exp_noerror(group_add_msg, 'group add')
436
437 group_del_msg = \
438 create_group_mod_msg(ofp.OFPGC_DELETE, ofp.OFPGT_ALL, group_id = 10, buckets = [
439 ])
440
441 self.send_ctrl_exp_noerror(group_del_msg, 'group del')
442
443# self.send_ctrl_exp_noerror(group_add_msg, 'group add')
444
445
446
447
448class GroupDelNonexisting(GroupTest):
449 """
450 A deletion for nonexisting group should result in no error
451 """
452
453 def runTest(self):
454 #self.clear_switch()
455
456 group_add_msg = \
457 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 0, buckets = [
458 create_bucket(0, 0, 0, [
459 create_action(action= ofp.OFPAT_OUTPUT, port= 1)
460 ])
461 ])
462
463# self.send_ctrl_exp_noerror(group_add_msg, 'group add')
464
465 group_del_msg = \
466 create_group_mod_msg(ofp.OFPGC_DELETE, ofp.OFPGT_ALL, group_id = 10, buckets = [
467 ])
468
469 self.send_ctrl_exp_noerror(group_del_msg, 'group del')
470
471
472
473class GroupDelAll(GroupTest):
474 """
475 #@todo: A deletion for OFGP_ALL should remove all groups
476 """
477
478 def runTest(self):
479 self.clear_switch()
480
481 group_add_msg1 = \
482 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 1, buckets = [
483 create_bucket(0, 0, 0, [
484 create_action(action= ofp.OFPAT_OUTPUT, port= 1)
485 ])
486 ])
487
488 self.send_ctrl_exp_noerror(group_add_msg1, 'group add 1')
489
490 group_add_msg2 = \
491 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 2, buckets = [
492 create_bucket(0, 0, 0, [
493 create_action(action= ofp.OFPAT_OUTPUT, port= 1)
494 ])
495 ])
496
497 self.send_ctrl_exp_noerror(group_add_msg2, 'group add 2')
498
499 group_del_msg = \
500 create_group_mod_msg(ofp.OFPGC_DELETE, group_id = ofp.OFPG_ALL)
501
502 self.send_ctrl_exp_noerror(group_del_msg, 'group del')
503
504# self.send_ctrl_exp_noerror(group_add_msg1, 'group add 1')
505# self.send_ctrl_exp_noerror(group_add_msg2, 'group add 2')
506
507
508"""
509Management (specific)
510"""
511
512class GroupAddAllWeight(GroupTest):
513 """
514 An ALL group with weights for buckets should result in OFPET_GROUP_MOD_FAILED, OFPGMFC_INVALID_GROUP
515 """
516
517 def runTest(self):
518 self.clear_switch()
519
520 group_add_msg = \
521 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 0, buckets = [
522 create_bucket(1, 0, 0, [
523 create_action(action= ofp.OFPAT_OUTPUT, port= 2)
524 ]),
525 create_bucket(2, 0, 0, [
526 create_action(action= ofp.OFPAT_OUTPUT, port= 2)
527 ])
528 ])
529
530 self.send_ctrl_exp_error(group_add_msg, 'group add',
531 ofp.OFPET_GROUP_MOD_FAILED,
532 ofp.OFPGMFC_INVALID_GROUP)
533
534
535
536class GroupAddIndirectWeight(GroupTest):
537 """
538 An INDIRECT group with weights for buckets should result in OFPET_GROUP_MOD_FAILED, OFPGMFC_INVALID_GROUP
539 """
540
541 def runTest(self):
542 self.clear_switch()
543
544 group_add_msg = \
545 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_INDIRECT, group_id = 0, buckets = [
546 create_bucket(1, 0, 0, [
547 create_action(action= ofp.OFPAT_OUTPUT, port= 2)
548 ])
549 ])
550
551 self.send_ctrl_exp_error(group_add_msg, 'group add',
552 ofp.OFPET_GROUP_MOD_FAILED,
553 ofp.OFPGMFC_INVALID_GROUP)
554
555
556
557class GroupAddIndirectBuckets(GroupTest):
558 """
559 An INDIRECT group with <>1 bucket should result in OFPET_GROUP_MOD_FAILED, OFPGMFC_INVALID_GROUP
560 """
561
562 def runTest(self):
563 self.clear_switch()
564
565 group_add_msg = \
566 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_INDIRECT, group_id = 0, buckets = [
567 create_bucket(0, 0, 0, [
568 create_action(action= ofp.OFPAT_OUTPUT, port= 2)
569 ]),
570 create_bucket(0, 0, 0, [
571 create_action(action= ofp.OFPAT_OUTPUT, port= 2)
572 ])
573 ])
574
575 self.send_ctrl_exp_error(group_add_msg, 'group add',
576 ofp.OFPET_GROUP_MOD_FAILED,
577 ofp.OFPGMFC_INVALID_GROUP)
578
579
580
581class GroupAddSelectNoWeight(GroupTest):
582 """
583 A SELECT group with ==0 weights should result in OFPET_GROUP_MOD_FAILED, OFPGMFC_INVALID_GROUP
584 """
585
586 def runTest(self):
587 self.clear_switch()
588
589 group_add_msg = \
590 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_SELECT, group_id = 0, buckets = [
591 create_bucket(0, 0, 0, [
592 create_action(action= ofp.OFPAT_OUTPUT, port= 2)
593 ]),
594 create_bucket(0, 0, 0, [
595 create_action(action= ofp.OFPAT_OUTPUT, port= 2)
596 ])
597 ])
598
599 self.send_ctrl_exp_error(group_add_msg, 'group add',
600 ofp.OFPET_GROUP_MOD_FAILED,
601 ofp.OFPGMFC_INVALID_GROUP)
602
603
604"""
605Action
606"""
607
608#@todo: A group action with invalid id should result in error
609#@todo: A group action for nonexisting group should result in error
610
611
612"""
613Working
614"""
615
616class GroupProcEmpty(GroupTest):
617 """
618 A group with no buckets should not alter the action set of the packet
619 """
620
621 def runTest(self):
622
623 self.clear_switch()
624
625 group_add_msg = \
626 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 1, buckets = [
627 ])
628
629 self.send_ctrl_exp_noerror(group_add_msg, 'group add')
630
631 packet_in = testutils.simple_tcp_packet()
632
633 flow_add_msg = \
634 create_flow_msg(packet = packet_in, in_port = 1, apply_action_list = [
635 create_action(action = ofp.OFPAT_GROUP, group_id = 1)
636 ])
637
638 self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')
639
640 self.send_data(packet_in, 1)
641
642 self.recv_data(2, None)
643
644class GroupProcSimple(GroupTest):
645 """
646 A group should apply its actions on packets
647 """
648
649 def runTest(self):
650# self.clear_switch()
651 testutils.clear_switch(self,config["port_map"],logging)
652
653 group_add_msg = \
654 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 1, buckets = [
655 create_bucket(0, 0, 0, [
656 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
657 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
658 ])
659 ])
660
661 self.send_ctrl_exp_noerror(group_add_msg, 'group add')
662
663 packet_in = testutils.simple_tcp_packet(tcp_sport=1000)
664 packet_out = testutils.simple_tcp_packet(tcp_sport=2000)
665
666 flow_add_msg = \
667 testutils.flow_msg_create(self,packet_in,ing_port = 1,action_list = [
668 create_action(action = ofp.OFPAT_GROUP, group_id = 1)
669 ])
670
671 self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')
672
673 self.send_data(packet_in, 1)
674
675 self.recv_data(2, packet_out)
676
677
678
679class GroupProcMod(GroupTest):
680 """
681 A modification for existing group should modify the group
682 """
683
684 def runTest(self):
685 testutils.clear_switch(self,config["port_map"],logging)
686# self.clear_switch()
687
688 group_add_msg = \
689 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 1, buckets = [
690 create_bucket(0, 0, 0, [
691 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
692 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
693 ])
694 ])
695
696 self.send_ctrl_exp_noerror(group_add_msg, 'group add')
697
698 group_mod_msg = \
699 create_group_mod_msg(ofp.OFPGC_MODIFY, ofp.OFPGT_ALL, group_id = 1, buckets = [
700 create_bucket(0, 0, 0, [
701 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 3000),
702 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
703 ])
704 ])
705
706 self.send_ctrl_exp_noerror(group_mod_msg, 'group mod')
707
708
709 packet_in = testutils.simple_tcp_packet(tcp_sport=1000)
710 packet_out = testutils.simple_tcp_packet(tcp_sport=3000)
711
712 flow_add_msg = \
713 testutils.flow_msg_create(self,packet_in,ing_port = 1,action_list = [
714 create_action(action = ofp.OFPAT_GROUP, group_id = 1)
715 ])
716
717 self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')
718
719 self.send_data(packet_in, 1)
720
721 self.recv_data(2, packet_out)
722
723
724
725class GroupProcChain(GroupTest):
726 """
727 A group after a group should apply its actions on packets
728 """
729
730 def runTest(self):
731 self.clear_switch()
732
733 group_add_msg2 = \
734 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 2, buckets = [
735 create_bucket(0, 0, 0, [
736 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
737 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
738 ])
739 ])
740
741 self.send_ctrl_exp_noerror(group_add_msg2, 'group add')
742
743 group_add_msg1 = \
744 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 1, buckets = [
745 create_bucket(0, 0, 0, [
746 create_action(action = ofp.OFPAT_GROUP, group_id = 2),
747 ])
748 ])
749
750 self.send_ctrl_exp_noerror(group_add_msg1, 'group add')
751
752 packet_in = testutils.simple_tcp_packet(tcp_sport=1000)
753 packet_out = testutils.simple_tcp_packet(tcp_sport=2000)
754
755 flow_add_msg = \
756 testutils.flow_msg_create(self,packet_in,ing_port = 1,action_list = [
757 create_action(action = ofp.OFPAT_GROUP, group_id = 1)
758 ])
759
760 self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')
761
762 self.send_data(packet_in, 1)
763
764 self.recv_data(2, packet_out)
765
766
767
768"""
769Working (specific)
770"""
771
772class GroupProcAll(GroupTest):
773 """
774 An ALL group should use all of its buckets, modifying the resulting packet(s)
775 """
776
777 def runTest(self):
778 self.clear_switch()
779
780 group_add_msg = \
781 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 1, buckets = [
782 create_bucket(0, 0, 0, [
783 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
784 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
785 ]),
786 create_bucket(0, 0, 0, [
787 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 3000),
788 create_action(action = ofp.OFPAT_OUTPUT, port = 3)
789 ]),
790 create_bucket(0, 0, 0, [
791 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 4000),
792 create_action(action = ofp.OFPAT_OUTPUT, port = 4)
793 ])
794 ])
795
796 self.send_ctrl_exp_noerror(group_add_msg, 'group add')
797
798 packet_in = testutils.simple_tcp_packet(tcp_sport=1000)
799 packet_out1 = testutils.simple_tcp_packet(tcp_sport=2000)
800 packet_out2 = testutils.simple_tcp_packet(tcp_sport=3000)
801 packet_out3 = testutils.simple_tcp_packet(tcp_sport=4000)
802
803 flow_add_msg = \
804 testutils.flow_msg_create(self,packet_in,ing_port = 1,action_list = [
805 create_action(action = ofp.OFPAT_GROUP, group_id = 1)
806 ])
807
808 self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')
809
810 self.send_data(packet_in, 1)
811
812 self.recv_data(2, packet_out1)
813 self.recv_data(3, packet_out2)
814 self.recv_data(4, packet_out3)
815
816
817
818class GroupProcAllChain(GroupTest):
819 """
820 An ALL group should use all of its buckets, modifying the resulting packet(s)
821 """
822
823 def runTest(self):
824 self.clear_switch()
825
826 group_add_msg2 = \
827 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 2, buckets = [
828 create_bucket(0, 0, 0, [
829 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
830 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
831 ])
832 ])
833
834 self.send_ctrl_exp_noerror(group_add_msg2, 'group add 2')
835
836 group_add_msg3 = \
837 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 3, buckets = [
838 create_bucket(0, 0, 0, [
839 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 3000),
840 create_action(action = ofp.OFPAT_OUTPUT, port = 3)
841 ]),
842 create_bucket(0, 0, 0, [
843 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 4000),
844 create_action(action = ofp.OFPAT_OUTPUT, port = 4)
845 ])
846 ])
847
848 self.send_ctrl_exp_noerror(group_add_msg3, 'group add 3')
849
850 group_add_msg1 = \
851 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 1, buckets = [
852 create_bucket(0, 0, 0, [
853 create_action(action = ofp.OFPAT_GROUP, group_id = 2),
854 ]),
855 create_bucket(0, 0, 0, [
856 create_action(action = ofp.OFPAT_GROUP, group_id = 3),
857 ])
858 ])
859
860 self.send_ctrl_exp_noerror(group_add_msg1, 'group add 1')
861
862 packet_in = testutils.simple_tcp_packet(tcp_sport=1000)
863 packet_out1 = testutils.simple_tcp_packet(tcp_sport=2000)
864 packet_out2 = testutils.simple_tcp_packet(tcp_sport=3000)
865 packet_out3 = testutils.simple_tcp_packet(tcp_sport=4000)
866
867 flow_add_msg = \
868 testutils.flow_msg_create(self,packet_in,ing_port = 1,action_list = [
869 create_action(action = ofp.OFPAT_GROUP, group_id = 1)
870 ])
871
872 self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')
873
874 self.send_data(packet_in, 1)
875
876 self.recv_data(2, packet_out1)
877 self.recv_data(3, packet_out2)
878 self.recv_data(4, packet_out3)
879
880
881
882class GroupProcIndirect(GroupTest):
883 """
884 An INDIRECT group should use its only bucket
885 """
886
887 def runTest(self):
888 testutils.clear_switch(self,config["port_map"],logging)
889# self.clear_switch()
890
891 group_add_msg = \
892 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_INDIRECT, group_id = 1, buckets = [
893 create_bucket(0, 0, 0, [
894 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
895 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
896 ])
897 ])
898
899 self.send_ctrl_exp_noerror(group_add_msg, 'group add')
900
901 packet_in = testutils.simple_tcp_packet(tcp_sport=1000)
902 packet_out = testutils.simple_tcp_packet(tcp_sport=2000)
903
904 flow_add_msg = \
905 testutils.flow_msg_create(self,packet_in,ing_port = 1,action_list = [
906 create_action(action = ofp.OFPAT_GROUP, group_id = 1)
907 ])
908
909 self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')
910
911 self.send_data(packet_in, 1)
912
913 self.recv_data(2, packet_out)
914
915
916
917class GroupProcSelect(GroupTest):
918 """
919 An ALL group should use all of its buckets, modifying the resulting packet(s)
920 """
921
922 def runTest(self):
923 testutils.clear_switch(self,config["port_map"],logging)
924# self.clear_switch()
925
926 group_add_msg = \
927 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_SELECT, group_id = 1, buckets = [
928 create_bucket(1, 0, 0, [
929 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
930 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
931 ]),
932 create_bucket(1, 0, 0, [
933 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 3000),
934 create_action(action = ofp.OFPAT_OUTPUT, port = 3)
935 ]),
936 create_bucket(1, 0, 0, [
937 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 4000),
938 create_action(action = ofp.OFPAT_OUTPUT, port = 4)
939 ])
940 ])
941
942 self.send_ctrl_exp_noerror(group_add_msg, 'group add')
943
944 packet_in = testutils.simple_tcp_packet(tcp_sport=1000)
945 packet_out1 = testutils.simple_tcp_packet(tcp_sport=2000)
946 packet_out2 = testutils.simple_tcp_packet(tcp_sport=3000)
947 packet_out3 = testutils.simple_tcp_packet(tcp_sport=4000)
948
949 flow_add_msg = \
950 testutils.flow_msg_create(self,packet_in,ing_port = 1,action_list = [
951 create_action(action = ofp.OFPAT_GROUP, group_id = 1)
952 ])
953
954 self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')
955
956 self.send_data(packet_in, 1)
957
958 recv1 = self.recv_data(2)
959 recv2 = self.recv_data(3)
960 recv3 = self.recv_data(4)
961
962 self.assertTrue(((recv1 is not None) or (recv2 is not None) or (recv3 is not None)),
963 "Did not receive a packet")
964
965 self.assertTrue(((recv1 is not None) and (recv2 is None) and (recv3 is None)) or \
966 ((recv1 is None) and (recv2 is not None) and (recv3 is None)) or \
967 ((recv1 is None) and (recv2 is None) and (recv3 is not None)),
968 "Received too many packets")
969
970 self.assertTrue(((recv1 is not None) and testutils.pkt_verify(self, recv1, packet_out1)) or \
971 ((recv2 is not None) and testutils.pkt_verify(self, recv2, packet_out2)) or \
972 ((recv3 is not None) and testutils.pkt_verify(self, recv3, packet_out3)),
973 "Received unexpected packet")
974
975#@todo: A FF group should always use its first alive bucket
976
977
978"""
979Statistics
980"""
981
982#@todo A regular group added should increase the number of groups and buckets
983
984class GroupStats(GroupTest):
985 """
986 A packet sent to the group should increase byte/packet counters of group
987 """
988
989 def runTest(self):
990# self.clear_switch()
991 testutils.clear_switch(self,config["port_map"],logging)
992
993 group_add_msg = \
994 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 10, buckets = [
995 create_bucket(0, 0, 0, [
996 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
997 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
998 ]),
999 create_bucket(0, 0, 0, [
1000 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 3000),
1001 create_action(action = ofp.OFPAT_OUTPUT, port = 3)
1002 ])
1003 ])
1004
1005 self.send_ctrl_exp_noerror(group_add_msg, 'group add')
1006
1007 packet_in = testutils.simple_tcp_packet(tcp_sport=1000)
1008
1009 flow_add_msg = \
1010 testutils.flow_msg_create(self,packet_in,ing_port = 1,action_list = [
1011 create_action(action = ofp.OFPAT_GROUP, group_id = 10)
1012 ])
1013
1014 self.send_ctrl_exp_noerror(flow_add_msg, 'flow add')
1015
1016 self.send_data(packet_in, 1)
1017 self.send_data(packet_in, 1)
1018 self.send_data(packet_in, 1)
1019
1020 group_stats_req = \
1021 create_group_stats_req(10)
1022
1023 response = \
1024 self.send_ctrl_exp_reply(group_stats_req,
1025 ofp.OFPT_STATS_REPLY, 'group stat')
1026
Rich Lane36414ba2013-05-07 15:01:57 -07001027 self.assertEqual(len(response.entries), 1, 'Incorrect number of groups')
1028 self.assertEqual(len(response.entries[0].bucket_stats), 2, 'Incorrect number of groups')
1029 self.assertEqual(response.entries[0].packet_count, 3, 'Incorrect group packet count')
1030 self.assertEqual(response.entries[0].byte_count, 300, 'Incorrect group byte count')
1031 for bucket_stat in response.entries[0].bucket_stats:
1032 self.assertEqual(bucket_stat.packet_count, 3, 'Incorrect bucket packet count')
1033 self.assertEqual(bucket_stat.byte_count, 300, 'Incorrect bucket byte count')
Rich Laneea873262013-01-11 08:15:55 -08001034
Rich Laneea873262013-01-11 08:15:55 -08001035
1036
1037
1038class GroupStatsAll(GroupTest):
1039 """
1040 A packet sent to the group should increase byte/packet counters of group
1041 """
1042
1043 def runTest(self):
1044# self.clear_switch()
1045 testutils.clear_switch(self,config["port_map"],logging)
1046
1047 group_add_msg1 = \
1048 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 10, buckets = [
1049 create_bucket(0, 0, 0, [
1050 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
1051 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
1052 ]),
1053 create_bucket(0, 0, 0, [
1054 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 3000),
1055 create_action(action = ofp.OFPAT_OUTPUT, port = 3)
1056 ])
1057 ])
1058
1059 self.send_ctrl_exp_noerror(group_add_msg1, 'group add 1')
1060
1061 group_add_msg2 = \
1062 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 20, buckets = [
1063 create_bucket(0, 0, 0, [
1064 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
1065 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
1066 ]),
1067 create_bucket(0, 0, 0, [
1068 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 3000),
1069 create_action(action = ofp.OFPAT_OUTPUT, port = 3)
1070 ])
1071 ])
1072
1073 self.send_ctrl_exp_noerror(group_add_msg2, 'group add 2')
1074
1075 packet_in = testutils.simple_tcp_packet(tcp_sport=1000)
1076
1077 flow_add_msg1 = \
1078 testutils.flow_msg_create(self,packet_in,ing_port = 1,action_list = [
1079 create_action(action = ofp.OFPAT_GROUP, group_id = 10)
1080 ])
1081
1082 self.send_ctrl_exp_noerror(flow_add_msg1, 'flow add 1')
1083
1084 flow_add_msg2 = \
1085 testutils.flow_msg_create(self,packet_in,ing_port = 2,action_list = [
1086 create_action(action = ofp.OFPAT_GROUP, group_id = 20)
1087 ])
1088
1089 self.send_ctrl_exp_noerror(flow_add_msg2, 'flow add 2')
1090
1091 self.send_data(packet_in, 1)
1092 self.send_data(packet_in, 1)
1093 self.send_data(packet_in, 2)
1094 self.send_data(packet_in, 2)
1095 self.send_data(packet_in, 2)
1096
1097 group_stats_req = \
1098 create_group_stats_req(ofp.OFPG_ALL)
1099
1100 response = \
1101 self.send_ctrl_exp_reply(group_stats_req,
1102 ofp.OFPT_STATS_REPLY, 'group stat')
1103
Rich Lane36414ba2013-05-07 15:01:57 -07001104 self.assertEqual(len(response.entries), 2)
1105 group10, group20 = sorted(response.entries, key=lambda x: x.group_id)
Rich Laneea873262013-01-11 08:15:55 -08001106
Rich Lane36414ba2013-05-07 15:01:57 -07001107 # Check stats for group 10
1108 self.assertEqual(group10.group_id, 10)
1109 self.assertEqual(group10.ref_count, 1)
1110 self.assertEqual(group10.packet_count, 2)
1111 self.assertEqual(group10.byte_count, 200)
1112 self.assertEqual(len(group10.bucket_stats), 2)
1113 for bucket_stat in group10.bucket_stats:
1114 self.assertEqual(bucket_stat.packet_count, 2)
1115 self.assertEqual(bucket_stat.byte_count, 200)
1116
1117 # Check stats for group 20
1118 self.assertEqual(group20.group_id, 20)
1119 self.assertEqual(group20.ref_count, 1)
1120 self.assertEqual(group20.packet_count, 3)
1121 self.assertEqual(group20.byte_count, 300)
1122 self.assertEqual(len(group20.bucket_stats), 2)
1123 for bucket_stat in group20.bucket_stats:
1124 self.assertEqual(bucket_stat.packet_count, 3)
1125 self.assertEqual(bucket_stat.byte_count, 300)
Rich Laneea873262013-01-11 08:15:55 -08001126
1127
1128
1129class GroupDescStats(GroupTest):
1130 """
1131 Desc stats of a group should work
1132 """
1133
1134 def runTest(self):
1135 self.clear_switch()
1136
1137 b1 = create_bucket(0, 0, 0, [
1138 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 2000),
1139 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
1140 ])
1141 b2 = create_bucket(0, 0, 0, [
1142 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 3000),
1143 create_action(action = ofp.OFPAT_OUTPUT, port = 3)
1144 ])
1145 b3 = create_bucket(0, 0, 0, [
1146 create_action(action = ofp.OFPAT_SET_FIELD, tcp_sport = 4000),
1147 create_action(action = ofp.OFPAT_OUTPUT, port = 4)
1148 ])
1149
1150 group_add_msg = \
1151 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 10, buckets = [b1, b2, b3])
1152
1153 self.send_ctrl_exp_noerror(group_add_msg, 'group add')
1154
1155 group_desc_stats_req = \
1156 create_group_desc_stats_req()
1157
1158 response = \
1159 self.send_ctrl_exp_reply(group_desc_stats_req,
1160 ofp.OFPT_STATS_REPLY, 'group desc stat')
1161
Rich Lane36414ba2013-05-07 15:01:57 -07001162 self.assertEquals(len(response.entries), 1)
1163 group = response.entries[0]
1164 self.assertEquals(group.group_id, 10)
1165 self.assertEquals(len(group.buckets), 3)
1166 self.assertEquals(group.buckets[0], b1)
1167 self.assertEquals(group.buckets[1], b2)
1168 self.assertEquals(group.buckets[2], b3)
Rich Laneea873262013-01-11 08:15:55 -08001169
1170
1171#@todo: A flow added with group action should increase the ref counter of the ref. group
1172#@todo: A flow removed with group action should decrease the ref counter of the ref. group
1173#@todo: A group added with group action should increase the ref counter of the ref. group
1174#@todo: A group removed with group action should decrease the ref counter of the ref. group
1175
1176
1177"""
1178Flows
1179"""
1180
1181#@todo: A deletion for existing group should remove flows referring to that group
1182#@todo: A flow added referencing a nonexisting group should return an error
1183
1184"""
1185Flow select
1186"""
1187
1188class GroupFlowSelect(GroupTest):
1189 """
1190 A group action select with group id should select the correct flows only
1191 """
1192
1193 def runTest(self):
1194 self.clear_switch()
1195
1196 group_add_msg1 = \
1197 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 1, buckets = [])
1198
1199 self.send_ctrl_exp_noerror(group_add_msg1, 'group add 1')
1200
1201 group_add_msg2 = \
1202 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 2, buckets = [])
1203
1204 self.send_ctrl_exp_noerror(group_add_msg2, 'group add 2')
1205
1206 packet_in1 = testutils.simple_tcp_packet(tcp_sport=1000)
1207
1208 flow_add_msg1 = \
1209 testutils.flow_msg_create(self,packet_in1,ing_port = 1,action_list = [
1210 create_action(action = ofp.OFPAT_GROUP, group_id = 1),
1211 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
1212 ])
1213
1214 self.send_ctrl_exp_noerror(flow_add_msg1, 'flow add 1')
1215
1216 packet_in2 = testutils.simple_tcp_packet(tcp_sport=2000)
1217
1218 flow_add_msg2 = \
1219 testutils.flow_msg_create(self,packet_in2,ing_port = 1,action_list = [
1220 create_action(action = ofp.OFPAT_GROUP, group_id = 2),
1221 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
1222 ])
1223
1224 self.send_ctrl_exp_noerror(flow_add_msg2, 'flow add 2')
1225
1226 packet_in3 = testutils.simple_tcp_packet(tcp_sport=3000)
1227
1228 flow_add_msg3 = \
1229 testutils.flow_msg_create(self,packet_in3,ing_port = 1,action_list = [
1230 create_action(action = ofp.OFPAT_GROUP, group_id = 2),
1231 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
1232 ])
1233
1234 self.send_ctrl_exp_noerror(flow_add_msg3, 'flow add 3')
1235
1236 packet_in4 = testutils.simple_tcp_packet(tcp_sport=4000)
1237
1238 flow_add_msg4 = \
1239 testutils.flow_msg_create(self,packet_in4,ing_port = 1,action_list = [
1240 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
1241 ])
1242
1243 self.send_ctrl_exp_noerror(flow_add_msg4, 'flow add 4')
1244
1245 aggr_stat_req = ofp.message.aggregate_stats_request()
1246 aggr_stat_req.table_id = 0xff
1247 aggr_stat_req.out_port = ofp.OFPP_ANY
1248 aggr_stat_req.out_group = 2
1249
1250 response = \
1251 self.send_ctrl_exp_reply(aggr_stat_req,
1252 ofp.OFPT_STATS_REPLY, 'aggr stat')
1253
Rich Lane48e447e2013-05-07 15:23:35 -07001254 self.assertEqual(response.flow_count, 2,
Rich Laneea873262013-01-11 08:15:55 -08001255 'Did not match expected flow count')
1256
1257class GroupFlowSelectAll(GroupTest):
1258 """
1259 A group action select with OFPG_ALL should ignore output group action
1260 """
1261
1262 def runTest(self):
1263 self.clear_switch()
1264
1265 group_add_msg1 = \
1266 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 1, buckets = [])
1267
1268 self.send_ctrl_exp_noerror(group_add_msg1, 'group add 1')
1269
1270 group_add_msg2 = \
1271 create_group_mod_msg(ofp.OFPGC_ADD, ofp.OFPGT_ALL, group_id = 2, buckets = [])
1272
1273 self.send_ctrl_exp_noerror(group_add_msg2, 'group add 2')
1274
1275 packet_in1 = testutils.simple_tcp_packet(tcp_sport=1000)
1276
1277 flow_add_msg1 = \
1278 testutils.flow_msg_create(self,packet_in1,ing_port = 1,action_list = [
1279 create_action(action = ofp.OFPAT_GROUP, group_id = 1),
1280 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
1281 ])
1282
1283 self.send_ctrl_exp_noerror(flow_add_msg1, 'flow add 1')
1284
1285 packet_in2 = testutils.simple_tcp_packet(tcp_sport=2000)
1286
1287 flow_add_msg2 = \
1288 testutils.flow_msg_create(self,packet_in2,ing_port = 1,action_list = [
1289 create_action(action = ofp.OFPAT_GROUP, group_id = 2),
1290 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
1291 ])
1292
1293 self.send_ctrl_exp_noerror(flow_add_msg2, 'flow add 2')
1294
1295 packet_in3 = testutils.simple_tcp_packet(tcp_sport=3000)
1296
1297 flow_add_msg3 = \
1298 testutils.flow_msg_create(self,packet_in3,ing_port = 1,action_list = [
1299 create_action(action = ofp.OFPAT_GROUP, group_id = 2),
1300 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
1301 ])
1302
1303 self.send_ctrl_exp_noerror(flow_add_msg3, 'flow add 3')
1304
1305 packet_in4 = testutils.simple_tcp_packet(tcp_sport=4000)
1306
1307 flow_add_msg4 = \
1308 testutils.flow_msg_create(self,packet_in4,ing_port = 1,action_list = [
1309 create_action(action = ofp.OFPAT_OUTPUT, port = 2)
1310 ])
1311
1312 self.send_ctrl_exp_noerror(flow_add_msg4, 'flow add 4')
1313
1314 aggr_stat_req = ofp.message.aggregate_stats_request()
1315 aggr_stat_req.table_id = 0xff
1316 aggr_stat_req.out_port = ofp.OFPP_ANY
1317 aggr_stat_req.out_group = ofp.OFPG_ANY
1318
1319 response = \
1320 self.send_ctrl_exp_reply(aggr_stat_req,
1321 ofp.OFPT_STATS_REPLY, 'group desc stat')
1322
Rich Lane48e447e2013-05-07 15:23:35 -07001323 self.assertEqual(response.flow_count, 4,
Rich Laneea873262013-01-11 08:15:55 -08001324 'Did not match expected flow count')
1325
1326
1327
1328
1329if __name__ == "__main__":
1330 print "Please run through oft script: ./oft --test_spec=basic"