blob: a846eb85984771648a2a3460011585270c28d001 [file] [log] [blame]
Rich Lane0ccd9752014-11-24 14:11:59 -08001# Distributed under the OpenFlow Software License (see LICENSE)
2# Copyright (c) 2014 Big Switch Networks, Inc.
3"""
4Bundle test cases
5"""
6
7import logging
8
9from oftest import config
10import oftest.base_tests as base_tests
11import ofp
Rich Lane0ccd9752014-11-24 14:11:59 -080012
13from oftest.testutils import *
14
15class 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 Lanea0afb5c2014-11-24 16:27:29 -080020 request = ofp.message.bundle_ctrl_msg(
21 bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST,
Rich Lane0ccd9752014-11-24 14:11:59 -080022 bundle_id=1)
23
24 response, _ = self.controller.transact(request)
Rich Lanea0afb5c2014-11-24 16:27:29 -080025 self.assertIsInstance(response, ofp.message.bundle_ctrl_msg)
26 self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY)
Rich Lane0ccd9752014-11-24 14:11:59 -080027 self.assertEqual(response.bundle_id, 1)
28
29 for i in xrange(0, 10):
Rich Lanea0afb5c2014-11-24 16:27:29 -080030 request = ofp.message.bundle_add_msg(
Rich Lane0ccd9752014-11-24 14:11:59 -080031 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 Lanea0afb5c2014-11-24 16:27:29 -080040 request = ofp.message.bundle_ctrl_msg(
41 bundle_ctrl_type=ofp.OFPBCT_COMMIT_REQUEST,
Rich Lane0ccd9752014-11-24 14:11:59 -080042 bundle_id=1)
43
44 response, _ = self.controller.transact(request)
Rich Lanea0afb5c2014-11-24 16:27:29 -080045 self.assertIsInstance(response, ofp.message.bundle_ctrl_msg)
46 self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_COMMIT_REPLY)
Rich Lane0ccd9752014-11-24 14:11:59 -080047 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
54class Discard(base_tests.SimpleProtocol):
55 """
56 Verify that messages in a discarded bundle are not executed
57 """
58 def runTest(self):
Rich Lanea0afb5c2014-11-24 16:27:29 -080059 request = ofp.message.bundle_ctrl_msg(
60 bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST,
Rich Lane0ccd9752014-11-24 14:11:59 -080061 bundle_id=1)
62
63 response, _ = self.controller.transact(request)
Rich Lanea0afb5c2014-11-24 16:27:29 -080064 self.assertIsInstance(response, ofp.message.bundle_ctrl_msg)
65 self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY)
Rich Lane0ccd9752014-11-24 14:11:59 -080066 self.assertEqual(response.bundle_id, 1)
67
68 for i in xrange(0, 10):
Rich Lanea0afb5c2014-11-24 16:27:29 -080069 request = ofp.message.bundle_add_msg(
Rich Lane0ccd9752014-11-24 14:11:59 -080070 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 Lanea0afb5c2014-11-24 16:27:29 -080079 request = ofp.message.bundle_ctrl_msg(
80 bundle_ctrl_type=ofp.OFPBCT_DISCARD_REQUEST,
Rich Lane0ccd9752014-11-24 14:11:59 -080081 bundle_id=1)
82
83 response, _ = self.controller.transact(request)
Rich Lanea0afb5c2014-11-24 16:27:29 -080084 self.assertIsInstance(response, ofp.message.bundle_ctrl_msg)
85 self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_DISCARD_REPLY)
Rich Lane0ccd9752014-11-24 14:11:59 -080086 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
92class Disconnect(base_tests.SimpleProtocol):
93 """
94 Disconnect without explicitly discarding the bundle
95 """
96 def runTest(self):
Rich Lanea0afb5c2014-11-24 16:27:29 -080097 request = ofp.message.bundle_ctrl_msg(
98 bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST,
Rich Lane0ccd9752014-11-24 14:11:59 -080099 bundle_id=1)
100
101 response, _ = self.controller.transact(request)
Rich Lanea0afb5c2014-11-24 16:27:29 -0800102 self.assertIsInstance(response, ofp.message.bundle_ctrl_msg)
103 self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY)
Rich Lane0ccd9752014-11-24 14:11:59 -0800104 self.assertEqual(response.bundle_id, 1)
105
106 for i in xrange(0, 10):
Rich Lanea0afb5c2014-11-24 16:27:29 -0800107 request = ofp.message.bundle_add_msg(
Rich Lane0ccd9752014-11-24 14:11:59 -0800108 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
115class 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 Lanea0afb5c2014-11-24 16:27:29 -0800122 request = ofp.message.bundle_ctrl_msg(
123 bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST,
Rich Lane0ccd9752014-11-24 14:11:59 -0800124 bundle_id=1)
125
126 response, _ = self.controller.transact(request)
Rich Lanea0afb5c2014-11-24 16:27:29 -0800127 self.assertIsInstance(response, ofp.message.bundle_ctrl_msg)
128 self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY)
Rich Lane0ccd9752014-11-24 14:11:59 -0800129 self.assertEqual(response.bundle_id, 1)
130
Rich Lanea0afb5c2014-11-24 16:27:29 -0800131 request = ofp.message.bundle_add_msg(
Rich Lane0ccd9752014-11-24 14:11:59 -0800132 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 Lanea0afb5c2014-11-24 16:27:29 -0800152 request = ofp.message.bundle_add_msg(
Rich Lane0ccd9752014-11-24 14:11:59 -0800153 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 Lanea0afb5c2014-11-24 16:27:29 -0800160 msg, _ = self.controller.poll(exp_msg=ofp.message.error_msg)
Rich Lane0ccd9752014-11-24 14:11:59 -0800161 self.assertIsNotNone(msg)
162
163class 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 Lanea0afb5c2014-11-24 16:27:29 -0800170 request = ofp.message.bundle_ctrl_msg(
171 bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST,
Rich Lane0ccd9752014-11-24 14:11:59 -0800172 bundle_id=1)
173
174 response, _ = self.controller.transact(request)
Rich Lanea0afb5c2014-11-24 16:27:29 -0800175 self.assertIsInstance(response, ofp.message.bundle_ctrl_msg)
176 self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY)
Rich Lane0ccd9752014-11-24 14:11:59 -0800177 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 Lanea0afb5c2014-11-24 16:27:29 -0800182 request = ofp.message.bundle_add_msg(
Rich Lane0ccd9752014-11-24 14:11:59 -0800183 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 Lanea0afb5c2014-11-24 16:27:29 -0800206 request = ofp.message.bundle_add_msg(
Rich Lane0ccd9752014-11-24 14:11:59 -0800207 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 Lanea0afb5c2014-11-24 16:27:29 -0800214 msg, _ = self.controller.poll(exp_msg=ofp.message.error_msg)
Rich Lane0ccd9752014-11-24 14:11:59 -0800215 self.assertIsNotNone(msg)
Rich Lane4fe21212015-03-24 12:56:26 -0700216
217class Barrier(base_tests.SimpleProtocol):
218 """
219 Verify that barriers are allowed in a bundle
220 """
221 def runTest(self):
222 request = ofp.message.bundle_ctrl_msg(
223 bundle_ctrl_type=ofp.OFPBCT_OPEN_REQUEST,
224 bundle_id=1)
225
226 response, _ = self.controller.transact(request)
227 self.assertIsInstance(response, ofp.message.bundle_ctrl_msg)
228 self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_OPEN_REPLY)
229 self.assertEqual(response.bundle_id, 1)
230
231 request = ofp.message.bundle_add_msg(
232 xid=1,
233 bundle_id=1,
234 data=ofp.message.flow_stats_request(xid=1).pack())
235 self.controller.message_send(request)
236
237 request = ofp.message.bundle_add_msg(
238 xid=2,
239 bundle_id=1,
240 data=ofp.message.barrier_request(xid=2).pack())
241 self.controller.message_send(request)
242
243 # Make sure the messages aren't executed
244 msg, _ = self.controller.poll(ofp.message.echo_reply)
245 self.assertIsNone(msg)
246
247 request = ofp.message.bundle_ctrl_msg(
248 bundle_ctrl_type=ofp.OFPBCT_COMMIT_REQUEST,
249 bundle_id=1)
250
251 response, _ = self.controller.transact(request)
252 self.assertIsInstance(response, ofp.message.bundle_ctrl_msg)
253 self.assertEqual(response.bundle_ctrl_type, ofp.OFPBCT_COMMIT_REPLY)
254 self.assertEqual(response.bundle_id, 1)
255
256 response, _ = self.controller.poll(ofp.message.flow_stats_reply)
257 self.assertIsNotNone(response)
258 self.assertEquals(response.xid, 1)
259
260 response, _ = self.controller.poll(ofp.message.barrier_reply)
261 self.assertIsNotNone(response)
262 self.assertEquals(response.xid, 2)