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 |
| 39 | #@var load_logger Local logger object |
| 40 | load_logger = None |
| 41 | #@var load_config Local copy of global configuration data |
| 42 | load_config = None |
| 43 | |
| 44 | # For test priority |
| 45 | #@var test_prio Set test priority for local tests |
| 46 | test_prio = {} |
| 47 | |
| 48 | |
| 49 | def test_set_init(config): |
| 50 | """ |
| 51 | Set up function for packet action test classes |
| 52 | |
| 53 | @param config The configuration dictionary; see oft |
| 54 | """ |
| 55 | |
| 56 | global load_port_map |
| 57 | global load_logger |
| 58 | global load_config |
| 59 | |
| 60 | load_logger = logging.getLogger("load") |
| 61 | load_logger.info("Initializing test set") |
| 62 | load_port_map = config["port_map"] |
| 63 | load_config = config |
| 64 | |
| 65 | class LoadBarrier(basic.SimpleProtocol): |
| 66 | """ |
| 67 | Test barrier under load with loopback |
| 68 | |
| 69 | This test assumes there is a pair of ports on the switch with |
| 70 | a loopback cable connected and that spanning tree is disabled. |
| 71 | A flow is installed to cause a storm of packet-in messages |
| 72 | when a packet is sent to the loopbacked interface. After causing |
| 73 | this storm, a barrier request is sent. |
| 74 | |
| 75 | The test succeeds if the barrier response is received. Otherwise |
| 76 | the test fails. |
| 77 | """ |
| 78 | def runTest(self): |
| 79 | # Set up flow to send from port 1 to port 2 and copy to CPU |
| 80 | # Test parameter gives LB port base (assumes consecutive) |
| 81 | lb_port = test_param_get(self.config, 'lb_port', default=1) |
| 82 | barrier_count = test_param_get(self.config, 'barrier_count', |
| 83 | default=10) |
| 84 | |
| 85 | # Set controller to filter packet ins |
| 86 | self.controller.filter_packet_in = True |
| 87 | self.controller.pkt_in_filter_limit = 10 |
| 88 | |
| 89 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 90 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 91 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 92 | match.in_port = lb_port |
| 93 | act = action.action_output() |
| 94 | act.port = lb_port + 1 |
| 95 | |
| 96 | request = message.flow_mod() |
| 97 | request.match = match |
| 98 | request.hard_timeout = 2 * barrier_count |
| 99 | |
| 100 | request.buffer_id = 0xffffffff |
| 101 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 102 | |
| 103 | act = action.action_output() |
| 104 | act.port = ofp.OFPP_CONTROLLER |
| 105 | self.assertTrue(request.actions.add(act), "Could not add action") |
| 106 | |
| 107 | rv = self.controller.message_send(request) |
| 108 | self.assertTrue(rv != -1, "Error installing flow mod") |
| 109 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 110 | |
| 111 | # Create packet out and send to port lb_port + 1 |
| 112 | msg = message.packet_out() |
| 113 | msg.data = str(pkt) |
| 114 | act = action.action_output() |
| 115 | act.port = lb_port + 1 |
| 116 | self.assertTrue(msg.actions.add(act), 'Could not add action to msg') |
| 117 | load_logger.info("Sleeping before starting storm") |
| 118 | time.sleep(1) # Root causing issue with fast disconnects |
| 119 | load_logger.info("Sending packet out to %d" % (lb_port + 1)) |
| 120 | rv = self.controller.message_send(msg) |
| 121 | self.assertTrue(rv == 0, "Error sending out message") |
| 122 | |
| 123 | for idx in range(0, barrier_count): |
| 124 | self.assertEqual(do_barrier(self.controller), 0, "Barrier failed") |
| 125 | # To do: Add some interesting functionality here |
| 126 | load_logger.info("Barrier %d completed" % idx) |
| 127 | |
| 128 | # Clear the flow table when done |
| 129 | load_logger.debug("Deleting all flows from switch") |
| 130 | rc = delete_all_flows(self.controller, load_logger) |
| 131 | self.assertEqual(rc, 0, "Failed to delete all flows") |
| 132 | |
| 133 | # Do not run by default; still mysterious disconnects often |
| 134 | test_prio["LoadBarrier"] = -1 |