Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 1 | """ |
| 2 | Prototype test cases related to operation under load |
| 3 | |
| 4 | It is recommended that these definitions be kept in their own |
| 5 | namespace as different groups of tests will likely define |
| 6 | similar identifiers. |
| 7 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 8 | The switch is actively attempting to contact the controller at the address |
| 9 | indicated in config. |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 10 | |
| 11 | In general these test cases make some assumption about the external |
| 12 | configuration of the switch under test. For now, the assumption is |
| 13 | that the first two OF ports are connected by a loopback cable. |
| 14 | """ |
| 15 | |
| 16 | import copy |
| 17 | |
| 18 | import logging |
| 19 | |
| 20 | import unittest |
| 21 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 22 | from oftest import config |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 23 | import oftest.controller as controller |
| 24 | import oftest.cstruct as ofp |
| 25 | import oftest.message as message |
| 26 | import oftest.dataplane as dataplane |
| 27 | import oftest.action as action |
| 28 | import oftest.parse as parse |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 29 | import oftest.base_tests as base_tests |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 30 | import time |
| 31 | |
Rich Lane | da3b5ad | 2012-10-03 09:05:32 -0700 | [diff] [blame] | 32 | from oftest.testutils import * |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 33 | |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 34 | class LoadBarrier(base_tests.SimpleProtocol): |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 35 | """ |
| 36 | Test barrier under load with loopback |
| 37 | |
| 38 | This test assumes there is a pair of ports on the switch with |
| 39 | a loopback cable connected and that spanning tree is disabled. |
| 40 | A flow is installed to cause a storm of packet-in messages |
| 41 | when a packet is sent to the loopbacked interface. After causing |
| 42 | this storm, a barrier request is sent. |
| 43 | |
| 44 | The test succeeds if the barrier response is received. Otherwise |
| 45 | the test fails. |
| 46 | """ |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame] | 47 | |
| 48 | priority = -1 |
| 49 | |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 50 | def runTest(self): |
| 51 | # Set up flow to send from port 1 to port 2 and copy to CPU |
| 52 | # Test parameter gives LB port base (assumes consecutive) |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 53 | lb_port = test_param_get(config, 'lb_port', default=1) |
| 54 | barrier_count = test_param_get(config, 'barrier_count', |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 55 | default=10) |
| 56 | |
| 57 | # Set controller to filter packet ins |
| 58 | self.controller.filter_packet_in = True |
| 59 | self.controller.pkt_in_filter_limit = 10 |
| 60 | |
| 61 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 62 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 63 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 64 | match.in_port = lb_port |
| 65 | act = action.action_output() |
| 66 | act.port = lb_port + 1 |
| 67 | |
| 68 | request = message.flow_mod() |
| 69 | request.match = match |
| 70 | request.hard_timeout = 2 * barrier_count |
| 71 | |
| 72 | request.buffer_id = 0xffffffff |
| 73 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 74 | |
| 75 | act = action.action_output() |
| 76 | act.port = ofp.OFPP_CONTROLLER |
| 77 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 78 | |
| 79 | rv = self.controller.message_send(request) |
| 80 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 81 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 82 | |
| 83 | # Create packet out and send to port lb_port + 1 |
| 84 | msg = message.packet_out() |
| 85 | msg.data = str(pkt) |
| 86 | act = action.action_output() |
| 87 | act.port = lb_port + 1 |
| 88 | self.assertTrue(msg.actions.add(act), 'Could not add action to msg') |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 89 | logging.info("Sleeping before starting storm") |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 90 | time.sleep(1) # Root causing issue with fast disconnects |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 91 | logging.info("Sending packet out to %d" % (lb_port + 1)) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 92 | rv = self.controller.message_send(msg) |
| 93 | self.assertTrue(rv == 0, "Error sending out message") |
| 94 | |
| 95 | for idx in range(0, barrier_count): |
| 96 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 97 | # To do: Add some interesting functionality here |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 98 | logging.info("Barrier %d completed" % idx) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 99 | |
| 100 | # Clear the flow table when done |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 101 | logging.debug("Deleting all flows from switch") |
| 102 | rc = delete_all_flows(self.controller) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 103 | self.assertEqual(rc, 0, "Failed to delete all flows") |