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 | |
| 8 | The function test_set_init is called with a complete configuration |
| 9 | dictionary prior to the invocation of any tests from this file. |
| 10 | |
| 11 | The switch is actively attempting to contact the controller at the address |
| 12 | indicated in oft_config |
| 13 | |
| 14 | In general these test cases make some assumption about the external |
| 15 | configuration of the switch under test. For now, the assumption is |
| 16 | that the first two OF ports are connected by a loopback cable. |
| 17 | """ |
| 18 | |
| 19 | import copy |
| 20 | |
| 21 | import logging |
| 22 | |
| 23 | import unittest |
| 24 | |
| 25 | import oftest.controller as controller |
| 26 | import oftest.cstruct as ofp |
| 27 | import oftest.message as message |
| 28 | import oftest.dataplane as dataplane |
| 29 | import oftest.action as action |
| 30 | import oftest.parse as parse |
| 31 | import basic |
| 32 | import time |
| 33 | |
Rich Lane | da3b5ad | 2012-10-03 09:05:32 -0700 | [diff] [blame] | 34 | from oftest.testutils import * |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 35 | |
| 36 | #@var load_port_map Local copy of the configuration map from OF port |
| 37 | # numbers to OS interfaces |
| 38 | load_port_map = None |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 39 | #@var load_config Local copy of global configuration data |
| 40 | load_config = None |
| 41 | |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 42 | |
| 43 | def test_set_init(config): |
| 44 | """ |
| 45 | Set up function for packet action test classes |
| 46 | |
| 47 | @param config The configuration dictionary; see oft |
| 48 | """ |
| 49 | |
| 50 | global load_port_map |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 51 | global load_config |
| 52 | |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 53 | load_port_map = config["port_map"] |
| 54 | load_config = config |
| 55 | |
| 56 | class LoadBarrier(basic.SimpleProtocol): |
| 57 | """ |
| 58 | Test barrier under load with loopback |
| 59 | |
| 60 | This test assumes there is a pair of ports on the switch with |
| 61 | a loopback cable connected and that spanning tree is disabled. |
| 62 | A flow is installed to cause a storm of packet-in messages |
| 63 | when a packet is sent to the loopbacked interface. After causing |
| 64 | this storm, a barrier request is sent. |
| 65 | |
| 66 | The test succeeds if the barrier response is received. Otherwise |
| 67 | the test fails. |
| 68 | """ |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame^] | 69 | |
| 70 | priority = -1 |
| 71 | |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 72 | def runTest(self): |
| 73 | # Set up flow to send from port 1 to port 2 and copy to CPU |
| 74 | # Test parameter gives LB port base (assumes consecutive) |
| 75 | lb_port = test_param_get(self.config, 'lb_port', default=1) |
| 76 | barrier_count = test_param_get(self.config, 'barrier_count', |
| 77 | default=10) |
| 78 | |
| 79 | # Set controller to filter packet ins |
| 80 | self.controller.filter_packet_in = True |
| 81 | self.controller.pkt_in_filter_limit = 10 |
| 82 | |
| 83 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 84 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 85 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 86 | match.in_port = lb_port |
| 87 | act = action.action_output() |
| 88 | act.port = lb_port + 1 |
| 89 | |
| 90 | request = message.flow_mod() |
| 91 | request.match = match |
| 92 | request.hard_timeout = 2 * barrier_count |
| 93 | |
| 94 | request.buffer_id = 0xffffffff |
| 95 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 96 | |
| 97 | act = action.action_output() |
| 98 | act.port = ofp.OFPP_CONTROLLER |
| 99 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 100 | |
| 101 | rv = self.controller.message_send(request) |
| 102 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 103 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 104 | |
| 105 | # Create packet out and send to port lb_port + 1 |
| 106 | msg = message.packet_out() |
| 107 | msg.data = str(pkt) |
| 108 | act = action.action_output() |
| 109 | act.port = lb_port + 1 |
| 110 | self.assertTrue(msg.actions.add(act), 'Could not add action to msg') |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 111 | logging.info("Sleeping before starting storm") |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 112 | time.sleep(1) # Root causing issue with fast disconnects |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 113 | logging.info("Sending packet out to %d" % (lb_port + 1)) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 114 | rv = self.controller.message_send(msg) |
| 115 | self.assertTrue(rv == 0, "Error sending out message") |
| 116 | |
| 117 | for idx in range(0, barrier_count): |
| 118 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 119 | # To do: Add some interesting functionality here |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 120 | logging.info("Barrier %d completed" % idx) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 121 | |
| 122 | # Clear the flow table when done |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 123 | logging.debug("Deleting all flows from switch") |
| 124 | rc = delete_all_flows(self.controller) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 125 | self.assertEqual(rc, 0, "Failed to delete all flows") |