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