blob: ca4ce7056f1f97598357739ff6b10b90a3233ed3 [file] [log] [blame]
Matteo Scandoloa229eca2017-08-08 13:05:28 -07001
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 Lane0ccd9752014-11-24 14:11:59 -080017# Distributed under the OpenFlow Software License (see LICENSE)
18# Copyright (c) 2014 Big Switch Networks, Inc.
19"""
20Bundle test cases
21"""
22
23import logging
24
25from oftest import config
26import oftest.base_tests as base_tests
27import ofp
Rich Lane0ccd9752014-11-24 14:11:59 -080028
29from oftest.testutils import *
30
31class 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 Lanea0afb5c2014-11-24 16:27:29 -080036 request = ofp.message.bundle_ctrl_msg(
37 bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST,
Rich Lane0ccd9752014-11-24 14:11:59 -080038 bundle_id=1)
39
40 response, _ = self.controller.transact(request)
Rich Lanea0afb5c2014-11-24 16:27:29 -080041 self.assertIsInstance(response, ofp.message.bundle_ctrl_msg)
42 self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY)
Rich Lane0ccd9752014-11-24 14:11:59 -080043 self.assertEqual(response.bundle_id, 1)
44
45 for i in xrange(0, 10):
Rich Lanea0afb5c2014-11-24 16:27:29 -080046 request = ofp.message.bundle_add_msg(
Rich Lane0ccd9752014-11-24 14:11:59 -080047 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 Lanea0afb5c2014-11-24 16:27:29 -080056 request = ofp.message.bundle_ctrl_msg(
57 bundle_ctrl_type=ofp.OFPBCT_COMMIT_REQUEST,
Rich Lane0ccd9752014-11-24 14:11:59 -080058 bundle_id=1)
59
60 response, _ = self.controller.transact(request)
Rich Lanea0afb5c2014-11-24 16:27:29 -080061 self.assertIsInstance(response, ofp.message.bundle_ctrl_msg)
62 self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_COMMIT_REPLY)
Rich Lane0ccd9752014-11-24 14:11:59 -080063 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
70class Discard(base_tests.SimpleProtocol):
71 """
72 Verify that messages in a discarded bundle are not executed
73 """
74 def runTest(self):
Rich Lanea0afb5c2014-11-24 16:27:29 -080075 request = ofp.message.bundle_ctrl_msg(
76 bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST,
Rich Lane0ccd9752014-11-24 14:11:59 -080077 bundle_id=1)
78
79 response, _ = self.controller.transact(request)
Rich Lanea0afb5c2014-11-24 16:27:29 -080080 self.assertIsInstance(response, ofp.message.bundle_ctrl_msg)
81 self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY)
Rich Lane0ccd9752014-11-24 14:11:59 -080082 self.assertEqual(response.bundle_id, 1)
83
84 for i in xrange(0, 10):
Rich Lanea0afb5c2014-11-24 16:27:29 -080085 request = ofp.message.bundle_add_msg(
Rich Lane0ccd9752014-11-24 14:11:59 -080086 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 Lanea0afb5c2014-11-24 16:27:29 -080095 request = ofp.message.bundle_ctrl_msg(
96 bundle_ctrl_type=ofp.OFPBCT_DISCARD_REQUEST,
Rich Lane0ccd9752014-11-24 14:11:59 -080097 bundle_id=1)
98
99 response, _ = self.controller.transact(request)
Rich Lanea0afb5c2014-11-24 16:27:29 -0800100 self.assertIsInstance(response, ofp.message.bundle_ctrl_msg)
101 self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_DISCARD_REPLY)
Rich Lane0ccd9752014-11-24 14:11:59 -0800102 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
108class Disconnect(base_tests.SimpleProtocol):
109 """
110 Disconnect without explicitly discarding the bundle
111 """
112 def runTest(self):
Rich Lanea0afb5c2014-11-24 16:27:29 -0800113 request = ofp.message.bundle_ctrl_msg(
114 bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST,
Rich Lane0ccd9752014-11-24 14:11:59 -0800115 bundle_id=1)
116
117 response, _ = self.controller.transact(request)
Rich Lanea0afb5c2014-11-24 16:27:29 -0800118 self.assertIsInstance(response, ofp.message.bundle_ctrl_msg)
119 self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY)
Rich Lane0ccd9752014-11-24 14:11:59 -0800120 self.assertEqual(response.bundle_id, 1)
121
122 for i in xrange(0, 10):
Rich Lanea0afb5c2014-11-24 16:27:29 -0800123 request = ofp.message.bundle_add_msg(
Rich Lane0ccd9752014-11-24 14:11:59 -0800124 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
131class 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 Lanea0afb5c2014-11-24 16:27:29 -0800138 request = ofp.message.bundle_ctrl_msg(
139 bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST,
Rich Lane0ccd9752014-11-24 14:11:59 -0800140 bundle_id=1)
141
142 response, _ = self.controller.transact(request)
Rich Lanea0afb5c2014-11-24 16:27:29 -0800143 self.assertIsInstance(response, ofp.message.bundle_ctrl_msg)
144 self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY)
Rich Lane0ccd9752014-11-24 14:11:59 -0800145 self.assertEqual(response.bundle_id, 1)
146
Rich Lanea0afb5c2014-11-24 16:27:29 -0800147 request = ofp.message.bundle_add_msg(
Rich Lane0ccd9752014-11-24 14:11:59 -0800148 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 Lanea0afb5c2014-11-24 16:27:29 -0800168 request = ofp.message.bundle_add_msg(
Rich Lane0ccd9752014-11-24 14:11:59 -0800169 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 Lanea0afb5c2014-11-24 16:27:29 -0800176 msg, _ = self.controller.poll(exp_msg=ofp.message.error_msg)
Rich Lane0ccd9752014-11-24 14:11:59 -0800177 self.assertIsNotNone(msg)
178
179class 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 Lanea0afb5c2014-11-24 16:27:29 -0800186 request = ofp.message.bundle_ctrl_msg(
187 bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST,
Rich Lane0ccd9752014-11-24 14:11:59 -0800188 bundle_id=1)
189
190 response, _ = self.controller.transact(request)
Rich Lanea0afb5c2014-11-24 16:27:29 -0800191 self.assertIsInstance(response, ofp.message.bundle_ctrl_msg)
192 self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY)
Rich Lane0ccd9752014-11-24 14:11:59 -0800193 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 Lanea0afb5c2014-11-24 16:27:29 -0800198 request = ofp.message.bundle_add_msg(
Rich Lane0ccd9752014-11-24 14:11:59 -0800199 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 Lanea0afb5c2014-11-24 16:27:29 -0800222 request = ofp.message.bundle_add_msg(
Rich Lane0ccd9752014-11-24 14:11:59 -0800223 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 Lanea0afb5c2014-11-24 16:27:29 -0800230 msg, _ = self.controller.poll(exp_msg=ofp.message.error_msg)
Rich Lane0ccd9752014-11-24 14:11:59 -0800231 self.assertIsNotNone(msg)
Rich Lane4fe21212015-03-24 12:56:26 -0700232
233class 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)