Matteo Scandolo | a229eca | 2017-08-08 13:05:28 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 17 | # Distributed under the OpenFlow Software License (see LICENSE) |
| 18 | # Copyright (c) 2014 Big Switch Networks, Inc. |
| 19 | """ |
| 20 | Bundle test cases |
| 21 | """ |
| 22 | |
| 23 | import logging |
| 24 | |
| 25 | from oftest import config |
| 26 | import oftest.base_tests as base_tests |
| 27 | import ofp |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 28 | |
| 29 | from oftest.testutils import * |
| 30 | |
| 31 | class Commit(base_tests.SimpleProtocol): |
| 32 | """ |
| 33 | Verify that messages added to a bundle are executed only after a commit |
| 34 | """ |
| 35 | def runTest(self): |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 36 | request = ofp.message.bundle_ctrl_msg( |
| 37 | bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST, |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 38 | bundle_id=1) |
| 39 | |
| 40 | response, _ = self.controller.transact(request) |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 41 | self.assertIsInstance(response, ofp.message.bundle_ctrl_msg) |
| 42 | self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 43 | self.assertEqual(response.bundle_id, 1) |
| 44 | |
| 45 | for i in xrange(0, 10): |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 46 | request = ofp.message.bundle_add_msg( |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 47 | xid=i, |
| 48 | bundle_id=1, |
| 49 | data=ofp.message.echo_request(xid=i).pack()) |
| 50 | self.controller.message_send(request) |
| 51 | |
| 52 | # Make sure the messages aren't executed |
| 53 | msg, _ = self.controller.poll(ofp.message.echo_reply) |
| 54 | self.assertIsNone(msg) |
| 55 | |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 56 | request = ofp.message.bundle_ctrl_msg( |
| 57 | bundle_ctrl_type=ofp.OFPBCT_COMMIT_REQUEST, |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 58 | bundle_id=1) |
| 59 | |
| 60 | response, _ = self.controller.transact(request) |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 61 | self.assertIsInstance(response, ofp.message.bundle_ctrl_msg) |
| 62 | self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_COMMIT_REPLY) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 63 | self.assertEqual(response.bundle_id, 1) |
| 64 | |
| 65 | for i in xrange(0, 10): |
| 66 | response, _ = self.controller.poll(ofp.message.echo_reply) |
| 67 | self.assertIsNotNone(response) |
| 68 | self.assertEquals(response.xid, i) |
| 69 | |
| 70 | class Discard(base_tests.SimpleProtocol): |
| 71 | """ |
| 72 | Verify that messages in a discarded bundle are not executed |
| 73 | """ |
| 74 | def runTest(self): |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 75 | request = ofp.message.bundle_ctrl_msg( |
| 76 | bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST, |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 77 | bundle_id=1) |
| 78 | |
| 79 | response, _ = self.controller.transact(request) |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 80 | self.assertIsInstance(response, ofp.message.bundle_ctrl_msg) |
| 81 | self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 82 | self.assertEqual(response.bundle_id, 1) |
| 83 | |
| 84 | for i in xrange(0, 10): |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 85 | request = ofp.message.bundle_add_msg( |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 86 | xid=i, |
| 87 | bundle_id=1, |
| 88 | data=ofp.message.echo_request(xid=i).pack()) |
| 89 | self.controller.message_send(request) |
| 90 | |
| 91 | # Make sure the messages aren't executed |
| 92 | msg, _ = self.controller.poll(ofp.message.echo_reply) |
| 93 | self.assertIsNone(msg) |
| 94 | |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 95 | request = ofp.message.bundle_ctrl_msg( |
| 96 | bundle_ctrl_type=ofp.OFPBCT_DISCARD_REQUEST, |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 97 | bundle_id=1) |
| 98 | |
| 99 | response, _ = self.controller.transact(request) |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 100 | self.assertIsInstance(response, ofp.message.bundle_ctrl_msg) |
| 101 | self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_DISCARD_REPLY) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 102 | self.assertEqual(response.bundle_id, 1) |
| 103 | |
| 104 | # Make sure the messages aren't executed |
| 105 | msg, _ = self.controller.poll(ofp.message.echo_reply) |
| 106 | self.assertIsNone(msg) |
| 107 | |
| 108 | class Disconnect(base_tests.SimpleProtocol): |
| 109 | """ |
| 110 | Disconnect without explicitly discarding the bundle |
| 111 | """ |
| 112 | def runTest(self): |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 113 | request = ofp.message.bundle_ctrl_msg( |
| 114 | bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST, |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 115 | bundle_id=1) |
| 116 | |
| 117 | response, _ = self.controller.transact(request) |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 118 | self.assertIsInstance(response, ofp.message.bundle_ctrl_msg) |
| 119 | self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 120 | self.assertEqual(response.bundle_id, 1) |
| 121 | |
| 122 | for i in xrange(0, 10): |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 123 | request = ofp.message.bundle_add_msg( |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 124 | xid=i, |
| 125 | bundle_id=1, |
| 126 | data=ofp.message.echo_request(xid=i).pack()) |
| 127 | self.controller.message_send(request) |
| 128 | |
| 129 | # Disconnect without committing/discarding |
| 130 | |
| 131 | class TooManyMsgs(base_tests.SimpleProtocol): |
| 132 | """ |
| 133 | Verify that exactly 262144 messages can be added to a bundle |
| 134 | |
| 135 | This is tied to the limit in Indigo. |
| 136 | """ |
| 137 | def runTest(self): |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 138 | request = ofp.message.bundle_ctrl_msg( |
| 139 | bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST, |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 140 | bundle_id=1) |
| 141 | |
| 142 | response, _ = self.controller.transact(request) |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 143 | self.assertIsInstance(response, ofp.message.bundle_ctrl_msg) |
| 144 | self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 145 | self.assertEqual(response.bundle_id, 1) |
| 146 | |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 147 | request = ofp.message.bundle_add_msg( |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 148 | xid=0, |
| 149 | bundle_id=1, |
| 150 | data=ofp.message.echo_request(xid=0).pack()) |
| 151 | |
| 152 | buf = request.pack() |
| 153 | |
| 154 | logging.debug("Sending bundle-add messages") |
| 155 | |
| 156 | count = 0 |
| 157 | for i in xrange(0, 256*1024): |
| 158 | with self.controller.tx_lock: |
| 159 | if self.controller.switch_socket.sendall(buf) is not None: |
| 160 | raise AssertionError("failed to send message to switch") |
| 161 | count += 1 |
| 162 | |
| 163 | logging.debug("Sent %d bundle-add messages", count) |
| 164 | |
| 165 | do_barrier(self.controller) |
| 166 | verify_no_errors(self.controller) |
| 167 | |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 168 | request = ofp.message.bundle_add_msg( |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 169 | xid=1, |
| 170 | bundle_id=1, |
| 171 | data=ofp.message.echo_request(xid=1).pack()) |
| 172 | self.controller.message_send(request) |
| 173 | |
| 174 | do_barrier(self.controller) |
| 175 | |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 176 | msg, _ = self.controller.poll(exp_msg=ofp.message.error_msg) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 177 | self.assertIsNotNone(msg) |
| 178 | |
| 179 | class TooManyBytes(base_tests.SimpleProtocol): |
| 180 | """ |
| 181 | Verify that 50 MB of messages can be added to a bundle |
| 182 | |
| 183 | This is tied to the limit in Indigo. |
| 184 | """ |
| 185 | def runTest(self): |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 186 | request = ofp.message.bundle_ctrl_msg( |
| 187 | bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST, |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 188 | bundle_id=1) |
| 189 | |
| 190 | response, _ = self.controller.transact(request) |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 191 | self.assertIsInstance(response, ofp.message.bundle_ctrl_msg) |
| 192 | self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 193 | self.assertEqual(response.bundle_id, 1) |
| 194 | |
| 195 | echo_buf = ofp.message.echo_request(xid=0, data="\x00" * 1016).pack() |
| 196 | self.assertEquals(len(echo_buf), 1024) |
| 197 | |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 198 | request = ofp.message.bundle_add_msg( |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 199 | xid=0, |
| 200 | bundle_id=1, |
| 201 | data=echo_buf) |
| 202 | |
| 203 | buf = request.pack() |
| 204 | |
| 205 | max_bytes = 50*1024*1024 |
| 206 | num_msgs = max_bytes / len(echo_buf) |
| 207 | |
| 208 | logging.debug("Sending bundle-add messages") |
| 209 | |
| 210 | count = 0 |
| 211 | for i in xrange(0, num_msgs): |
| 212 | with self.controller.tx_lock: |
| 213 | if self.controller.switch_socket.sendall(buf) is not None: |
| 214 | raise AssertionError("failed to send message to switch") |
| 215 | count += 1 |
| 216 | |
| 217 | logging.debug("Sent %d bundle-add messages", count) |
| 218 | |
| 219 | do_barrier(self.controller) |
| 220 | verify_no_errors(self.controller) |
| 221 | |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 222 | request = ofp.message.bundle_add_msg( |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 223 | xid=1, |
| 224 | bundle_id=1, |
| 225 | data=ofp.message.echo_request(xid=1).pack()) |
| 226 | self.controller.message_send(request) |
| 227 | |
| 228 | do_barrier(self.controller) |
| 229 | |
Rich Lane | a0afb5c | 2014-11-24 16:27:29 -0800 | [diff] [blame] | 230 | msg, _ = self.controller.poll(exp_msg=ofp.message.error_msg) |
Rich Lane | 0ccd975 | 2014-11-24 14:11:59 -0800 | [diff] [blame] | 231 | self.assertIsNotNone(msg) |
Rich Lane | 4fe2121 | 2015-03-24 12:56:26 -0700 | [diff] [blame] | 232 | |
| 233 | class Barrier(base_tests.SimpleProtocol): |
| 234 | """ |
| 235 | Verify that barriers are allowed in a bundle |
| 236 | """ |
| 237 | def runTest(self): |
| 238 | request = ofp.message.bundle_ctrl_msg( |
| 239 | bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST, |
| 240 | bundle_id=1) |
| 241 | |
| 242 | response, _ = self.controller.transact(request) |
| 243 | self.assertIsInstance(response, ofp.message.bundle_ctrl_msg) |
| 244 | self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY) |
| 245 | self.assertEqual(response.bundle_id, 1) |
| 246 | |
| 247 | request = ofp.message.bundle_add_msg( |
| 248 | xid=1, |
| 249 | bundle_id=1, |
| 250 | data=ofp.message.flow_stats_request(xid=1).pack()) |
| 251 | self.controller.message_send(request) |
| 252 | |
| 253 | request = ofp.message.bundle_add_msg( |
| 254 | xid=2, |
| 255 | bundle_id=1, |
| 256 | data=ofp.message.barrier_request(xid=2).pack()) |
| 257 | self.controller.message_send(request) |
| 258 | |
| 259 | # Make sure the messages aren't executed |
| 260 | msg, _ = self.controller.poll(ofp.message.echo_reply) |
| 261 | self.assertIsNone(msg) |
| 262 | |
| 263 | request = ofp.message.bundle_ctrl_msg( |
| 264 | bundle_ctrl_type=ofp.OFPBCT_COMMIT_REQUEST, |
| 265 | bundle_id=1) |
| 266 | |
| 267 | response, _ = self.controller.transact(request) |
| 268 | self.assertIsInstance(response, ofp.message.bundle_ctrl_msg) |
| 269 | self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_COMMIT_REPLY) |
| 270 | self.assertEqual(response.bundle_id, 1) |
| 271 | |
| 272 | response, _ = self.controller.poll(ofp.message.flow_stats_reply) |
| 273 | self.assertIsNotNone(response) |
| 274 | self.assertEquals(response.xid, 1) |
| 275 | |
| 276 | response, _ = self.controller.poll(ofp.message.barrier_reply) |
| 277 | self.assertIsNotNone(response) |
| 278 | self.assertEquals(response.xid, 2) |