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 |
Rich Lane | d9ef7c3 | 2012-12-31 11:00:30 -0800 | [diff] [blame] | 17 | import random |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 18 | import logging |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 19 | import unittest |
| 20 | |
Rich Lane | 477f481 | 2012-10-04 22:49:00 -0700 | [diff] [blame] | 21 | from oftest import config |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 22 | import oftest.controller as controller |
Rich Lane | d7b0ffa | 2013-03-08 15:53:42 -0800 | [diff] [blame] | 23 | import ofp |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 24 | import oftest.dataplane as dataplane |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 25 | import oftest.parse as parse |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 26 | import oftest.base_tests as base_tests |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 27 | import time |
| 28 | |
Rich Lane | da3b5ad | 2012-10-03 09:05:32 -0700 | [diff] [blame] | 29 | from oftest.testutils import * |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 30 | |
Rich Lane | 0a4f637 | 2013-01-02 14:40:22 -0800 | [diff] [blame] | 31 | @nonstandard |
Rich Lane | b90a1c4 | 2012-10-05 09:16:05 -0700 | [diff] [blame] | 32 | class LoadBarrier(base_tests.SimpleProtocol): |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 33 | """ |
| 34 | Test barrier under load with loopback |
| 35 | |
| 36 | This test assumes there is a pair of ports on the switch with |
| 37 | a loopback cable connected and that spanning tree is disabled. |
| 38 | A flow is installed to cause a storm of packet-in messages |
| 39 | when a packet is sent to the loopbacked interface. After causing |
| 40 | this storm, a barrier request is sent. |
| 41 | |
| 42 | The test succeeds if the barrier response is received. Otherwise |
| 43 | the test fails. |
| 44 | """ |
Rich Lane | d1d9c28 | 2012-10-04 22:07:10 -0700 | [diff] [blame] | 45 | |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 46 | def runTest(self): |
| 47 | # Set up flow to send from port 1 to port 2 and copy to CPU |
| 48 | # Test parameter gives LB port base (assumes consecutive) |
Rich Lane | 2014f9b | 2012-10-05 15:29:40 -0700 | [diff] [blame] | 49 | lb_port = test_param_get('lb_port', default=1) |
| 50 | barrier_count = test_param_get('barrier_count', |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 51 | default=10) |
| 52 | |
| 53 | # Set controller to filter packet ins |
| 54 | self.controller.filter_packet_in = True |
| 55 | self.controller.pkt_in_filter_limit = 10 |
| 56 | |
| 57 | pkt = simple_tcp_packet() |
Ed Swierk | 99a74de | 2012-08-22 06:40:54 -0700 | [diff] [blame] | 58 | match = packet_to_flow_match(self, pkt) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 59 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 60 | match.in_port = lb_port |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 61 | act = ofp.action.output() |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 62 | act.port = lb_port + 1 |
| 63 | |
Rich Lane | ba3f0e2 | 2013-03-11 16:43:57 -0700 | [diff] [blame] | 64 | request = ofp.message.flow_add() |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 65 | request.match = match |
| 66 | request.hard_timeout = 2 * barrier_count |
| 67 | |
| 68 | request.buffer_id = 0xffffffff |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 69 | request.actions.append(act) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 70 | |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 71 | act = ofp.action.output() |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 72 | act.port = ofp.OFPP_CONTROLLER |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 73 | request.actions.append(act) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 74 | |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 75 | self.controller.message_send(request) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 76 | do_barrier(self.controller) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 77 | |
| 78 | # Create packet out and send to port lb_port + 1 |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 79 | msg = ofp.message.packet_out() |
Rich Lane | afcf467 | 2012-11-14 13:19:27 -0800 | [diff] [blame] | 80 | msg.in_port = lb_port |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 81 | msg.data = str(pkt) |
Rich Lane | ea8c472 | 2013-04-04 15:30:20 -0700 | [diff] [blame] | 82 | msg.buffer_id = 0xffffffff |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 83 | act = ofp.action.output() |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 84 | act.port = lb_port + 1 |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 85 | msg.actions.append(act) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 86 | logging.info("Sleeping before starting storm") |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 87 | time.sleep(1) # Root causing issue with fast disconnects |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 88 | logging.info("Sending packet out to %d" % (lb_port + 1)) |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 89 | self.controller.message_send(msg) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 90 | |
| 91 | for idx in range(0, barrier_count): |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 92 | do_barrier(self.controller) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 93 | # To do: Add some interesting functionality here |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 94 | logging.info("Barrier %d completed" % idx) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 95 | |
| 96 | # Clear the flow table when done |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 97 | logging.debug("Deleting all flows from switch") |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 98 | delete_all_flows(self.controller) |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 99 | |
| 100 | class PacketInLoad(base_tests.SimpleDataPlane): |
| 101 | """ |
| 102 | Generate lots of packet-in messages |
| 103 | |
| 104 | Test packet-in function by sending lots of packets to the dataplane. |
| 105 | This test tracks the number of pkt-ins received but does not enforce |
| 106 | any requirements about the number received. |
| 107 | """ |
| 108 | def runTest(self): |
| 109 | # Construct packet to send to dataplane |
| 110 | # Send packet to dataplane, once to each port |
| 111 | # Poll controller with expect message type packet in |
| 112 | |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 113 | delete_all_flows(self.controller) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 114 | do_barrier(self.controller) |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 115 | out_count = 0 |
| 116 | in_count = 0 |
| 117 | |
| 118 | of_ports = config["port_map"].keys() |
| 119 | for of_port in of_ports: |
| 120 | for pkt, pt in [ |
| 121 | (simple_tcp_packet(), "simple TCP packet"), |
| 122 | (simple_tcp_packet(dl_vlan_enable=True,pktlen=108), |
| 123 | "simple tagged TCP packet"), |
| 124 | (simple_eth_packet(), "simple Ethernet packet"), |
| 125 | (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]: |
| 126 | |
| 127 | logging.info("PKT IN test with %s, port %s" % (pt, of_port)) |
| 128 | for count in range(100): |
| 129 | out_count += 1 |
| 130 | self.dataplane.send(of_port, str(pkt)) |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 131 | while True: |
Ed Swierk | a9e12ab | 2013-01-16 07:35:25 -0800 | [diff] [blame] | 132 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN) |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 133 | if not response: |
| 134 | break |
| 135 | in_count += 1 |
| 136 | logging.info("PacketInLoad Sent %d. Got %d." % (out_count, in_count)) |
| 137 | |
| 138 | |
| 139 | |
| 140 | class PacketOutLoad(base_tests.SimpleDataPlane): |
| 141 | """ |
| 142 | Generate lots of packet-out messages |
| 143 | |
| 144 | Test packet-out function by sending lots of packet-out msgs |
| 145 | to the switch. This test tracks the number of packets received in |
| 146 | the dataplane, but does not enforce any requirements about the |
| 147 | number received. |
| 148 | """ |
| 149 | def runTest(self): |
| 150 | # Construct packet to send to dataplane |
| 151 | # Send packet to dataplane |
| 152 | # Poll controller with expect message type packet in |
| 153 | |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 154 | delete_all_flows(self.controller) |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 155 | |
| 156 | # These will get put into function |
| 157 | of_ports = config["port_map"].keys() |
| 158 | of_ports.sort() |
| 159 | out_count = 0 |
| 160 | in_count = 0 |
| 161 | xid = 100 |
| 162 | for dp_port in of_ports: |
| 163 | for outpkt, opt in [ |
| 164 | (simple_tcp_packet(), "simple TCP packet"), |
| 165 | (simple_eth_packet(), "simple Ethernet packet"), |
| 166 | (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]: |
| 167 | |
| 168 | logging.info("PKT OUT test with %s, port %s" % (opt, dp_port)) |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 169 | msg = ofp.message.packet_out() |
Rich Lane | afcf467 | 2012-11-14 13:19:27 -0800 | [diff] [blame] | 170 | msg.in_port = ofp.OFPP_NONE |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 171 | msg.data = str(outpkt) |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 172 | act = ofp.action.output() |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 173 | act.port = dp_port |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 174 | msg.actions.append(act) |
Rich Lane | ea8c472 | 2013-04-04 15:30:20 -0700 | [diff] [blame] | 175 | msg.buffer_id = 0xffffffff |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 176 | |
| 177 | logging.info("PacketOutLoad to: " + str(dp_port)) |
| 178 | for count in range(100): |
| 179 | msg.xid = xid |
| 180 | xid += 1 |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 181 | self.controller.message_send(msg) |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 182 | out_count += 1 |
| 183 | |
| 184 | exp_pkt_arg = None |
| 185 | exp_port = None |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 186 | while True: |
Ed Swierk | a9e12ab | 2013-01-16 07:35:25 -0800 | [diff] [blame] | 187 | (of_port, pkt, pkt_time) = self.dataplane.poll() |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 188 | if pkt is None: |
| 189 | break |
| 190 | in_count += 1 |
| 191 | logging.info("PacketOutLoad Sent %d. Got %d." % (out_count, in_count)) |
Ed Swierk | e6fca64 | 2012-11-30 12:00:54 -0800 | [diff] [blame] | 192 | |
| 193 | class FlowModLoad(base_tests.SimpleProtocol): |
| 194 | |
| 195 | def checkBarrier(self): |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 196 | msg, pkt = self.controller.transact(ofp.message.barrier_request(), timeout=60) |
Ed Swierk | e6fca64 | 2012-11-30 12:00:54 -0800 | [diff] [blame] | 197 | self.assertNotEqual(msg, None, "Barrier failed") |
| 198 | while self.controller.packets: |
| 199 | msg = self.controller.packets.pop(0)[0] |
Rich Lane | f9f6b51 | 2013-03-11 22:35:28 -0700 | [diff] [blame] | 200 | self.assertNotEqual(msg.type, ofp.OFPT_ERROR, "Error received") |
Ed Swierk | e6fca64 | 2012-11-30 12:00:54 -0800 | [diff] [blame] | 201 | |
| 202 | def runTest(self): |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 203 | msg, pkt = self.controller.transact(ofp.message.table_stats_request()) |
Rich Lane | 30ca70c | 2012-12-31 16:53:55 -0800 | [diff] [blame] | 204 | |
| 205 | # Some switches report an extremely high max_entries that would cause |
| 206 | # us to run out of memory attempting to create all the flow-mods. |
Rich Lane | 5fd6faf | 2013-03-11 13:30:20 -0700 | [diff] [blame] | 207 | num_flows = min(msg.entries[0].max_entries, 32678) |
Rich Lane | 30ca70c | 2012-12-31 16:53:55 -0800 | [diff] [blame] | 208 | |
| 209 | logging.info("Creating %d flow-mods messages", num_flows) |
Ed Swierk | e6fca64 | 2012-11-30 12:00:54 -0800 | [diff] [blame] | 210 | |
| 211 | requests = [] |
| 212 | for i in range(num_flows): |
Rich Lane | 0237baf | 2013-03-11 22:34:59 -0700 | [diff] [blame] | 213 | match = ofp.match() |
Ed Swierk | e6fca64 | 2012-11-30 12:00:54 -0800 | [diff] [blame] | 214 | match.wildcards = ofp.OFPFW_ALL & ~ofp.OFPFW_DL_VLAN & ~ofp.OFPFW_DL_DST |
Rich Lane | d0478ff | 2013-03-11 12:46:58 -0700 | [diff] [blame] | 215 | match.vlan_vid = ofp.OFP_VLAN_NONE |
| 216 | match.eth_dst = [0, 1, 2, 3, i / 256, i % 256] |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 217 | act = ofp.action.output() |
Ed Swierk | e6fca64 | 2012-11-30 12:00:54 -0800 | [diff] [blame] | 218 | act.port = ofp.OFPP_CONTROLLER |
Rich Lane | ba3f0e2 | 2013-03-11 16:43:57 -0700 | [diff] [blame] | 219 | request = ofp.message.flow_add() |
Ed Swierk | e6fca64 | 2012-11-30 12:00:54 -0800 | [diff] [blame] | 220 | request.buffer_id = 0xffffffff |
| 221 | request.priority = num_flows - i |
| 222 | request.out_port = ofp.OFPP_NONE |
| 223 | request.match = match |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 224 | request.actions.append(act) |
Ed Swierk | e6fca64 | 2012-11-30 12:00:54 -0800 | [diff] [blame] | 225 | requests.append(request) |
| 226 | |
Rich Lane | 82c35e8 | 2012-12-31 10:59:36 -0800 | [diff] [blame] | 227 | for i in range(3): |
Ed Swierk | e6fca64 | 2012-11-30 12:00:54 -0800 | [diff] [blame] | 228 | logging.info("Iteration %d: delete all flows" % i) |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 229 | delete_all_flows(self.controller) |
Ed Swierk | e6fca64 | 2012-11-30 12:00:54 -0800 | [diff] [blame] | 230 | self.checkBarrier() |
| 231 | |
| 232 | logging.info("Iteration %d: add %s flows" % (i, num_flows)) |
Rich Lane | d9ef7c3 | 2012-12-31 11:00:30 -0800 | [diff] [blame] | 233 | random.shuffle(requests) |
Ed Swierk | e6fca64 | 2012-11-30 12:00:54 -0800 | [diff] [blame] | 234 | for request in requests: |
| 235 | self.assertNotEqual(self.controller.message_send(request), -1, |
| 236 | "Error installing flow mod") |
| 237 | self.checkBarrier() |
Rich Lane | 9c49160 | 2013-04-15 16:00:46 -0700 | [diff] [blame] | 238 | |
| 239 | class FlowRemovedLoad(base_tests.SimpleDataPlane): |
| 240 | """ |
| 241 | Generate lots of flow-removed messages |
| 242 | |
| 243 | We keep track of the number of flow-removed messages we get but do not |
| 244 | assert on it. The goal of this test is just to make sure the controller |
| 245 | stays connected. |
| 246 | """ |
| 247 | |
| 248 | def checkBarrier(self): |
| 249 | msg, pkt = self.controller.transact(ofp.message.barrier_request(), timeout=60) |
| 250 | self.assertNotEqual(msg, None, "Barrier failed") |
| 251 | while self.controller.packets: |
| 252 | msg = self.controller.packets.pop(0)[0] |
| 253 | self.assertNotEqual(msg.type, ofp.OFPT_ERROR, "Error received") |
| 254 | |
| 255 | def runTest(self): |
| 256 | delete_all_flows(self.controller) |
| 257 | self.checkBarrier() |
| 258 | msg, _ = self.controller.transact(ofp.message.table_stats_request()) |
| 259 | |
| 260 | # Some switches report an extremely high max_entries that would cause |
| 261 | # us to run out of memory attempting to create all the flow-mods. |
| 262 | num_flows = min(msg.entries[0].max_entries, 32678) |
| 263 | |
| 264 | logging.info("Creating %d flow-mods messages", num_flows) |
| 265 | |
| 266 | requests = [] |
| 267 | for i in range(num_flows): |
| 268 | match = ofp.match() |
| 269 | match.wildcards = ofp.OFPFW_ALL & ~ofp.OFPFW_DL_VLAN & ~ofp.OFPFW_DL_DST |
| 270 | match.vlan_vid = ofp.OFP_VLAN_NONE |
| 271 | match.eth_dst = [0, 1, 2, 3, i / 256, i % 256] |
| 272 | act = ofp.action.output() |
| 273 | act.port = ofp.OFPP_CONTROLLER |
| 274 | request = ofp.message.flow_add() |
| 275 | request.buffer_id = 0xffffffff |
| 276 | request.priority = num_flows - i |
| 277 | request.out_port = ofp.OFPP_NONE |
| 278 | request.flags = ofp.OFPFF_SEND_FLOW_REM |
| 279 | request.match = match |
| 280 | request.actions.append(act) |
| 281 | requests.append(request) |
| 282 | |
| 283 | logging.info("Adding %d flows", num_flows) |
| 284 | random.shuffle(requests) |
| 285 | for request in requests: |
| 286 | self.controller.message_send(request) |
| 287 | self.checkBarrier() |
| 288 | |
| 289 | # Trigger a flood of flow-removed messages |
Tony van der Peet | 80c5b20 | 2013-11-20 11:47:48 +1300 | [diff] [blame] | 290 | delete_all_flows(self.controller, send_barrier=False) |
Rich Lane | 9c49160 | 2013-04-15 16:00:46 -0700 | [diff] [blame] | 291 | |
| 292 | count = 0 |
| 293 | while True: |
| 294 | (response, raw) = self.controller.poll(ofp.OFPT_FLOW_REMOVED) |
| 295 | if not response: |
| 296 | break |
| 297 | count += 1 |
| 298 | |
| 299 | # Make sure the switch is still connected |
| 300 | self.checkBarrier() |
| 301 | |
| 302 | logging.info("FlowRemovedLoad got %d/%d flow_removed messages." % (count, num_flows)) |