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 | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 64 | request = ofp.message.flow_mod() |
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 | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 82 | act = ofp.action.output() |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 83 | act.port = lb_port + 1 |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 84 | msg.actions.append(act) |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 85 | logging.info("Sleeping before starting storm") |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 86 | time.sleep(1) # Root causing issue with fast disconnects |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 87 | logging.info("Sending packet out to %d" % (lb_port + 1)) |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 88 | self.controller.message_send(msg) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 89 | |
| 90 | for idx in range(0, barrier_count): |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 91 | do_barrier(self.controller) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 92 | # To do: Add some interesting functionality here |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 93 | logging.info("Barrier %d completed" % idx) |
Dan Talayco | 942f530 | 2012-04-12 22:32:34 -0700 | [diff] [blame] | 94 | |
| 95 | # Clear the flow table when done |
Rich Lane | 9a00381 | 2012-10-04 17:17:59 -0700 | [diff] [blame] | 96 | logging.debug("Deleting all flows from switch") |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 97 | delete_all_flows(self.controller) |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 98 | |
| 99 | class PacketInLoad(base_tests.SimpleDataPlane): |
| 100 | """ |
| 101 | Generate lots of packet-in messages |
| 102 | |
| 103 | Test packet-in function by sending lots of packets to the dataplane. |
| 104 | This test tracks the number of pkt-ins received but does not enforce |
| 105 | any requirements about the number received. |
| 106 | """ |
| 107 | def runTest(self): |
| 108 | # Construct packet to send to dataplane |
| 109 | # Send packet to dataplane, once to each port |
| 110 | # Poll controller with expect message type packet in |
| 111 | |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 112 | delete_all_flows(self.controller) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 113 | do_barrier(self.controller) |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 114 | out_count = 0 |
| 115 | in_count = 0 |
| 116 | |
| 117 | of_ports = config["port_map"].keys() |
| 118 | for of_port in of_ports: |
| 119 | for pkt, pt in [ |
| 120 | (simple_tcp_packet(), "simple TCP packet"), |
| 121 | (simple_tcp_packet(dl_vlan_enable=True,pktlen=108), |
| 122 | "simple tagged TCP packet"), |
| 123 | (simple_eth_packet(), "simple Ethernet packet"), |
| 124 | (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]: |
| 125 | |
| 126 | logging.info("PKT IN test with %s, port %s" % (pt, of_port)) |
| 127 | for count in range(100): |
| 128 | out_count += 1 |
| 129 | self.dataplane.send(of_port, str(pkt)) |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 130 | while True: |
Ed Swierk | a9e12ab | 2013-01-16 07:35:25 -0800 | [diff] [blame] | 131 | (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN) |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 132 | if not response: |
| 133 | break |
| 134 | in_count += 1 |
| 135 | logging.info("PacketInLoad Sent %d. Got %d." % (out_count, in_count)) |
| 136 | |
| 137 | |
| 138 | |
| 139 | class PacketOutLoad(base_tests.SimpleDataPlane): |
| 140 | """ |
| 141 | Generate lots of packet-out messages |
| 142 | |
| 143 | Test packet-out function by sending lots of packet-out msgs |
| 144 | to the switch. This test tracks the number of packets received in |
| 145 | the dataplane, but does not enforce any requirements about the |
| 146 | number received. |
| 147 | """ |
| 148 | def runTest(self): |
| 149 | # Construct packet to send to dataplane |
| 150 | # Send packet to dataplane |
| 151 | # Poll controller with expect message type packet in |
| 152 | |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 153 | delete_all_flows(self.controller) |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 154 | |
| 155 | # These will get put into function |
| 156 | of_ports = config["port_map"].keys() |
| 157 | of_ports.sort() |
| 158 | out_count = 0 |
| 159 | in_count = 0 |
| 160 | xid = 100 |
| 161 | for dp_port in of_ports: |
| 162 | for outpkt, opt in [ |
| 163 | (simple_tcp_packet(), "simple TCP packet"), |
| 164 | (simple_eth_packet(), "simple Ethernet packet"), |
| 165 | (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]: |
| 166 | |
| 167 | logging.info("PKT OUT test with %s, port %s" % (opt, dp_port)) |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 168 | msg = ofp.message.packet_out() |
Rich Lane | afcf467 | 2012-11-14 13:19:27 -0800 | [diff] [blame] | 169 | msg.in_port = ofp.OFPP_NONE |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 170 | msg.data = str(outpkt) |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 171 | act = ofp.action.output() |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 172 | act.port = dp_port |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 173 | msg.actions.append(act) |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 174 | |
| 175 | logging.info("PacketOutLoad to: " + str(dp_port)) |
| 176 | for count in range(100): |
| 177 | msg.xid = xid |
| 178 | xid += 1 |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 179 | self.controller.message_send(msg) |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 180 | out_count += 1 |
| 181 | |
| 182 | exp_pkt_arg = None |
| 183 | exp_port = None |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 184 | while True: |
Ed Swierk | a9e12ab | 2013-01-16 07:35:25 -0800 | [diff] [blame] | 185 | (of_port, pkt, pkt_time) = self.dataplane.poll() |
Dan Talayco | d083285 | 2012-10-10 09:49:53 -0700 | [diff] [blame] | 186 | if pkt is None: |
| 187 | break |
| 188 | in_count += 1 |
| 189 | logging.info("PacketOutLoad Sent %d. Got %d." % (out_count, in_count)) |
Ed Swierk | e6fca64 | 2012-11-30 12:00:54 -0800 | [diff] [blame] | 190 | |
| 191 | class FlowModLoad(base_tests.SimpleProtocol): |
| 192 | |
| 193 | def checkBarrier(self): |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 194 | msg, pkt = self.controller.transact(ofp.message.barrier_request(), timeout=60) |
Ed Swierk | e6fca64 | 2012-11-30 12:00:54 -0800 | [diff] [blame] | 195 | self.assertNotEqual(msg, None, "Barrier failed") |
| 196 | while self.controller.packets: |
| 197 | msg = self.controller.packets.pop(0)[0] |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 198 | self.assertNotEqual(msg.header.type, ofp.message.OFPT_ERROR, |
Ed Swierk | e6fca64 | 2012-11-30 12:00:54 -0800 | [diff] [blame] | 199 | "Error received") |
| 200 | |
| 201 | def runTest(self): |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 202 | msg, pkt = self.controller.transact(ofp.message.table_stats_request()) |
Rich Lane | 30ca70c | 2012-12-31 16:53:55 -0800 | [diff] [blame] | 203 | |
| 204 | # Some switches report an extremely high max_entries that would cause |
| 205 | # us to run out of memory attempting to create all the flow-mods. |
| 206 | num_flows = min(msg.stats[0].max_entries, 32678) |
| 207 | |
| 208 | logging.info("Creating %d flow-mods messages", num_flows) |
Ed Swierk | e6fca64 | 2012-11-30 12:00:54 -0800 | [diff] [blame] | 209 | |
| 210 | requests = [] |
| 211 | for i in range(num_flows): |
| 212 | match = ofp.ofp_match() |
| 213 | 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^] | 214 | match.vlan_vid = ofp.OFP_VLAN_NONE |
| 215 | match.eth_dst = [0, 1, 2, 3, i / 256, i % 256] |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 216 | act = ofp.action.output() |
Ed Swierk | e6fca64 | 2012-11-30 12:00:54 -0800 | [diff] [blame] | 217 | act.port = ofp.OFPP_CONTROLLER |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 218 | request = ofp.message.flow_mod() |
Ed Swierk | e6fca64 | 2012-11-30 12:00:54 -0800 | [diff] [blame] | 219 | request.command = ofp.OFPFC_ADD |
| 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() |