Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 1 | # Distributed under the OpenFlow Software License (see LICENSE) |
| 2 | # Copyright (c) 2014 Big Switch Networks, Inc. |
| 3 | """ |
| 4 | Bundle test cases |
| 5 | """ |
| 6 | |
| 7 | import logging |
| 8 | |
| 9 | from oftest import config |
| 10 | import oftest.base_tests as base_tests |
| 11 | import ofp |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 12 | |
| 13 | from oftest.testutils import * |
| 14 | |
| 15 | class Commit(base_tests.SimpleProtocol): |
| 16 | """ |
| 17 | Verify that messages added to a bundle are executed only after a commit |
| 18 | """ |
| 19 | def runTest(self): |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 20 | request = ofp.message.bundle_ctrl_msg( |
| 21 | bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST, |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 22 | bundle_id=1) |
| 23 | |
| 24 | response, _ = self.controller.transact(request) |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 25 | self.assertIsInstance(response, ofp.message.bundle_ctrl_msg) |
| 26 | self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 27 | self.assertEqual(response.bundle_id, 1) |
| 28 | |
| 29 | for i in xrange(0, 10): |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 30 | request = ofp.message.bundle_add_msg( |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 31 | xid=i, |
| 32 | bundle_id=1, |
| 33 | data=ofp.message.echo_request(xid=i).pack()) |
| 34 | self.controller.message_send(request) |
| 35 | |
| 36 | # Make sure the messages aren't executed |
| 37 | msg, _ = self.controller.poll(ofp.message.echo_reply) |
| 38 | self.assertIsNone(msg) |
| 39 | |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 40 | request = ofp.message.bundle_ctrl_msg( |
| 41 | bundle_ctrl_type=ofp.OFPBCT_COMMIT_REQUEST, |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 42 | bundle_id=1) |
| 43 | |
| 44 | response, _ = self.controller.transact(request) |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 45 | self.assertIsInstance(response, ofp.message.bundle_ctrl_msg) |
| 46 | self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_COMMIT_REPLY) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 47 | self.assertEqual(response.bundle_id, 1) |
| 48 | |
| 49 | for i in xrange(0, 10): |
| 50 | response, _ = self.controller.poll(ofp.message.echo_reply) |
| 51 | self.assertIsNotNone(response) |
| 52 | self.assertEquals(response.xid, i) |
| 53 | |
| 54 | class Discard(base_tests.SimpleProtocol): |
| 55 | """ |
| 56 | Verify that messages in a discarded bundle are not executed |
| 57 | """ |
| 58 | def runTest(self): |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 59 | request = ofp.message.bundle_ctrl_msg( |
| 60 | bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST, |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 61 | bundle_id=1) |
| 62 | |
| 63 | response, _ = self.controller.transact(request) |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 64 | self.assertIsInstance(response, ofp.message.bundle_ctrl_msg) |
| 65 | self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 66 | self.assertEqual(response.bundle_id, 1) |
| 67 | |
| 68 | for i in xrange(0, 10): |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 69 | request = ofp.message.bundle_add_msg( |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 70 | xid=i, |
| 71 | bundle_id=1, |
| 72 | data=ofp.message.echo_request(xid=i).pack()) |
| 73 | self.controller.message_send(request) |
| 74 | |
| 75 | # Make sure the messages aren't executed |
| 76 | msg, _ = self.controller.poll(ofp.message.echo_reply) |
| 77 | self.assertIsNone(msg) |
| 78 | |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 79 | request = ofp.message.bundle_ctrl_msg( |
| 80 | bundle_ctrl_type=ofp.OFPBCT_DISCARD_REQUEST, |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 81 | bundle_id=1) |
| 82 | |
| 83 | response, _ = self.controller.transact(request) |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 84 | self.assertIsInstance(response, ofp.message.bundle_ctrl_msg) |
| 85 | self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_DISCARD_REPLY) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 86 | self.assertEqual(response.bundle_id, 1) |
| 87 | |
| 88 | # Make sure the messages aren't executed |
| 89 | msg, _ = self.controller.poll(ofp.message.echo_reply) |
| 90 | self.assertIsNone(msg) |
| 91 | |
| 92 | class Disconnect(base_tests.SimpleProtocol): |
| 93 | """ |
| 94 | Disconnect without explicitly discarding the bundle |
| 95 | """ |
| 96 | def runTest(self): |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 97 | request = ofp.message.bundle_ctrl_msg( |
| 98 | bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST, |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 99 | bundle_id=1) |
| 100 | |
| 101 | response, _ = self.controller.transact(request) |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 102 | self.assertIsInstance(response, ofp.message.bundle_ctrl_msg) |
| 103 | self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 104 | self.assertEqual(response.bundle_id, 1) |
| 105 | |
| 106 | for i in xrange(0, 10): |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 107 | request = ofp.message.bundle_add_msg( |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 108 | xid=i, |
| 109 | bundle_id=1, |
| 110 | data=ofp.message.echo_request(xid=i).pack()) |
| 111 | self.controller.message_send(request) |
| 112 | |
| 113 | # Disconnect without committing/discarding |
| 114 | |
| 115 | class TooManyMsgs(base_tests.SimpleProtocol): |
| 116 | """ |
| 117 | Verify that exactly 262144 messages can be added to a bundle |
| 118 | |
| 119 | This is tied to the limit in Indigo. |
| 120 | """ |
| 121 | def runTest(self): |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 122 | request = ofp.message.bundle_ctrl_msg( |
| 123 | bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST, |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 124 | bundle_id=1) |
| 125 | |
| 126 | response, _ = self.controller.transact(request) |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 127 | self.assertIsInstance(response, ofp.message.bundle_ctrl_msg) |
| 128 | self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 129 | self.assertEqual(response.bundle_id, 1) |
| 130 | |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 131 | request = ofp.message.bundle_add_msg( |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 132 | xid=0, |
| 133 | bundle_id=1, |
| 134 | data=ofp.message.echo_request(xid=0).pack()) |
| 135 | |
| 136 | buf = request.pack() |
| 137 | |
| 138 | logging.debug("Sending bundle-add messages") |
| 139 | |
| 140 | count = 0 |
| 141 | for i in xrange(0, 256*1024): |
| 142 | with self.controller.tx_lock: |
| 143 | if self.controller.switch_socket.sendall(buf) is not None: |
| 144 | raise AssertionError("failed to send message to switch") |
| 145 | count += 1 |
| 146 | |
| 147 | logging.debug("Sent %d bundle-add messages", count) |
| 148 | |
| 149 | do_barrier(self.controller) |
| 150 | verify_no_errors(self.controller) |
| 151 | |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 152 | request = ofp.message.bundle_add_msg( |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 153 | xid=1, |
| 154 | bundle_id=1, |
| 155 | data=ofp.message.echo_request(xid=1).pack()) |
| 156 | self.controller.message_send(request) |
| 157 | |
| 158 | do_barrier(self.controller) |
| 159 | |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 160 | msg, _ = self.controller.poll(exp_msg=ofp.message.error_msg) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 161 | self.assertIsNotNone(msg) |
| 162 | |
| 163 | class TooManyBytes(base_tests.SimpleProtocol): |
| 164 | """ |
| 165 | Verify that 50 MB of messages can be added to a bundle |
| 166 | |
| 167 | This is tied to the limit in Indigo. |
| 168 | """ |
| 169 | def runTest(self): |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 170 | request = ofp.message.bundle_ctrl_msg( |
| 171 | bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST, |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 172 | bundle_id=1) |
| 173 | |
| 174 | response, _ = self.controller.transact(request) |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 175 | self.assertIsInstance(response, ofp.message.bundle_ctrl_msg) |
| 176 | self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 177 | self.assertEqual(response.bundle_id, 1) |
| 178 | |
| 179 | echo_buf = ofp.message.echo_request(xid=0, data="\x00" * 1016).pack() |
| 180 | self.assertEquals(len(echo_buf), 1024) |
| 181 | |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 182 | request = ofp.message.bundle_add_msg( |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 183 | xid=0, |
| 184 | bundle_id=1, |
| 185 | data=echo_buf) |
| 186 | |
| 187 | buf = request.pack() |
| 188 | |
| 189 | max_bytes = 50*1024*1024 |
| 190 | num_msgs = max_bytes / len(echo_buf) |
| 191 | |
| 192 | logging.debug("Sending bundle-add messages") |
| 193 | |
| 194 | count = 0 |
| 195 | for i in xrange(0, num_msgs): |
| 196 | with self.controller.tx_lock: |
| 197 | if self.controller.switch_socket.sendall(buf) is not None: |
| 198 | raise AssertionError("failed to send message to switch") |
| 199 | count += 1 |
| 200 | |
| 201 | logging.debug("Sent %d bundle-add messages", count) |
| 202 | |
| 203 | do_barrier(self.controller) |
| 204 | verify_no_errors(self.controller) |
| 205 | |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 206 | request = ofp.message.bundle_add_msg( |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 207 | xid=1, |
| 208 | bundle_id=1, |
| 209 | data=ofp.message.echo_request(xid=1).pack()) |
| 210 | self.controller.message_send(request) |
| 211 | |
| 212 | do_barrier(self.controller) |
| 213 | |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 214 | msg, _ = self.controller.poll(exp_msg=ofp.message.error_msg) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 215 | self.assertIsNotNone(msg) |