blob: 21f2fd730918ebe62cdd98c98381bd7a9adce4e5 [file] [log] [blame]
Dave Wallaceb063ad02019-04-09 21:01:09 -04001#!/usr/bin/env python
Dave Wallace3bffd4b2019-05-13 15:51:52 -04002""" Vpp QUIC tests """
Dave Wallaceb063ad02019-04-09 21:01:09 -04003
4import unittest
Dave Wallace211b28a2019-05-08 20:46:33 -04005import os
Dave Wallace3bffd4b2019-05-13 15:51:52 -04006import subprocess
7import signal
8from framework import VppTestCase, VppTestRunner, running_extended_tests, \
9 Worker
Dave Wallaceb063ad02019-04-09 21:01:09 -040010from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
11
12
Dave Wallace3bffd4b2019-05-13 15:51:52 -040013class QUICAppWorker(Worker):
14 """ QUIC Test Application Worker """
15
16 def __init__(self, build_dir, appname, args, logger, env={}):
17 app = "%s/vpp/bin/%s" % (build_dir, appname)
18 self.args = [app] + args
19 super(QUICAppWorker, self).__init__(self.args, logger, env)
20
21
Dave Wallace211b28a2019-05-08 20:46:33 -040022class QUICTestCase(VppTestCase):
Dave Wallaceb063ad02019-04-09 21:01:09 -040023 """ QUIC Test Case """
24
25 @classmethod
26 def setUpClass(cls):
Dave Wallace211b28a2019-05-08 20:46:33 -040027 super(QUICTestCase, cls).setUpClass()
Dave Wallaceb063ad02019-04-09 21:01:09 -040028
29 @classmethod
30 def tearDownClass(cls):
Dave Wallace211b28a2019-05-08 20:46:33 -040031 super(QUICTestCase, cls).tearDownClass()
Dave Wallaceb063ad02019-04-09 21:01:09 -040032
33 def setUp(self):
Dave Wallace211b28a2019-05-08 20:46:33 -040034 var = "VPP_BUILD_DIR"
35 self.build_dir = os.getenv(var, None)
36 if self.build_dir is None:
37 raise Exception("Environment variable `%s' not set" % var)
38 self.vppDebug = 'vpp_debug' in self.build_dir
39 self.timeout = 20
40 self.pre_test_sleep = 0.3
41 self.post_test_sleep = 0.3
Dave Wallaceb063ad02019-04-09 21:01:09 -040042 self.vapi.session_enable_disable(is_enabled=1)
Dave Wallace211b28a2019-05-08 20:46:33 -040043
44 def tearDown(self):
45 self.vapi.session_enable_disable(is_enabled=0)
46
47 def thru_host_stack_ipv4_setup(self):
48 super(QUICTestCase, self).setUp()
49
Dave Wallaceb063ad02019-04-09 21:01:09 -040050 self.create_loopback_interfaces(2)
Dave Wallace211b28a2019-05-08 20:46:33 -040051 self.uri = "quic://%s/1234" % self.loop0.local_ip4
Dave Wallace3bffd4b2019-05-13 15:51:52 -040052 common_args = ["uri", self.uri, "fifo-size", "64"]
Dave Wallace211b28a2019-05-08 20:46:33 -040053 self.server_echo_test_args = common_args + ["appns", "server"]
54 self.client_echo_test_args = common_args + ["appns", "client",
Dave Wallace3bffd4b2019-05-13 15:51:52 -040055 "test-bytes"]
Dave Wallaceb063ad02019-04-09 21:01:09 -040056 table_id = 1
Dave Wallaceb063ad02019-04-09 21:01:09 -040057 for i in self.lo_interfaces:
58 i.admin_up()
59
60 if table_id != 0:
61 tbl = VppIpTable(self, table_id)
62 tbl.add_vpp_config()
63
64 i.set_table_ip4(table_id)
65 i.config_ip4()
66 table_id += 1
67
68 # Configure namespaces
Dave Wallace211b28a2019-05-08 20:46:33 -040069 self.vapi.app_namespace_add_del(namespace_id=b"server",
Dave Wallaceb063ad02019-04-09 21:01:09 -040070 sw_if_index=self.loop0.sw_if_index)
Dave Wallace211b28a2019-05-08 20:46:33 -040071 self.vapi.app_namespace_add_del(namespace_id=b"client",
Dave Wallaceb063ad02019-04-09 21:01:09 -040072 sw_if_index=self.loop1.sw_if_index)
73
Dave Wallace211b28a2019-05-08 20:46:33 -040074 # Add inter-table routes
75 self.ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32,
76 [VppRoutePath("0.0.0.0",
77 0xffffffff,
78 nh_table_id=2)], table_id=1)
79 self.ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32,
80 [VppRoutePath("0.0.0.0",
81 0xffffffff,
82 nh_table_id=1)], table_id=2)
83 self.ip_t01.add_vpp_config()
84 self.ip_t10.add_vpp_config()
85 self.logger.debug(self.vapi.cli("show ip fib"))
86
87 def thru_host_stack_ipv4_tear_down(self):
88 # Delete inter-table routes
89 self.ip_t01.remove_vpp_config()
90 self.ip_t10.remove_vpp_config()
91
Dave Wallaceb063ad02019-04-09 21:01:09 -040092 for i in self.lo_interfaces:
93 i.unconfig_ip4()
94 i.set_table_ip4(0)
95 i.admin_down()
Dave Wallace211b28a2019-05-08 20:46:33 -040096
97 def start_internal_echo_server(self, args):
98 error = self.vapi.cli("test echo server %s" % ' '.join(args))
99 if error:
100 self.logger.critical(error)
101 self.assertNotIn("failed", error)
102
103 def start_internal_echo_client(self, args):
104 error = self.vapi.cli("test echo client %s" % ' '.join(args))
105 if error:
106 self.logger.critical(error)
107 self.assertNotIn("failed", error)
108
109 def internal_ipv4_transfer_test(self, server_args, client_args):
110 self.start_internal_echo_server(server_args)
Dave Wallace211b28a2019-05-08 20:46:33 -0400111 self.start_internal_echo_client(client_args)
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400112
113 def start_external_echo_server(self, args):
114 self.worker_server = QUICAppWorker(self.build_dir, "quic_echo",
115 args, self.logger)
116 self.worker_server.start()
117
118 def start_external_echo_client(self, args):
119 self.client_echo_test_args += "use-svm-api"
120 self.worker_client = QUICAppWorker(self.build_dir, "quic_echo",
121 args, self.logger)
122 self.worker_client.start()
123 self.worker_client.join(self.timeout)
124 try:
125 self.validateExternalTestResults()
126 except Exception as error:
127 self.fail("Failed with %s" % error)
128
129 def external_ipv4_transfer_test(self, server_args, client_args):
130 self.start_external_echo_server(server_args)
131 self.sleep(self.pre_test_sleep)
132 self.start_external_echo_client(client_args)
Dave Wallace211b28a2019-05-08 20:46:33 -0400133 self.sleep(self.post_test_sleep)
134
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400135 def validateExternalTestResults(self):
136 if os.path.isdir('/proc/{}'.format(self.worker_server.process.pid)):
137 self.logger.info("Killing server worker process (pid %d)" %
138 self.worker_server.process.pid)
139 os.killpg(os.getpgid(self.worker_server.process.pid),
140 signal.SIGTERM)
141 self.worker_server.join()
142 self.logger.info("Client worker result is `%s'" %
143 self.worker_client.result)
144 error = False
145 if self.worker_client.result is None:
146 try:
147 error = True
148 self.logger.error(
149 "Timeout: %ss! Killing client worker process (pid %d)" %
150 (self.timeout, self.worker_client.process.pid))
151 os.killpg(os.getpgid(self.worker_client.process.pid),
152 signal.SIGKILL)
153 self.worker_client.join()
154 except OSError:
155 self.logger.debug(
156 "Couldn't kill client worker process")
157 raise
158 if error:
159 raise Exception(
Dave Wallace1f37a7b2019-05-20 15:57:28 -0400160 "Timeout! Client worker did not finish in %ss" % self.timeout)
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400161 self.assert_equal(self.worker_client.result, 0,
162 "Binary test return code")
163
Dave Wallace211b28a2019-05-08 20:46:33 -0400164
165class QUICInternalEchoIPv4TestCase(QUICTestCase):
166 """ QUIC Internal Echo IPv4 Transfer Test Cases """
167
168 @classmethod
169 def setUpClass(cls):
170 super(QUICInternalEchoIPv4TestCase, cls).setUpClass()
171
172 @classmethod
173 def tearDownClass(cls):
174 super(QUICInternalEchoIPv4TestCase, cls).tearDownClass()
175
176 def setUp(self):
177 super(QUICInternalEchoIPv4TestCase, self).setUp()
178 self.thru_host_stack_ipv4_setup()
179
180 def tearDown(self):
Dave Wallace211b28a2019-05-08 20:46:33 -0400181 super(QUICInternalEchoIPv4TestCase, self).tearDown()
Dave Wallace0d144c72019-05-15 21:41:23 -0400182 self.thru_host_stack_ipv4_tear_down()
Dave Wallace211b28a2019-05-08 20:46:33 -0400183
184 def show_commands_at_teardown(self):
185 self.logger.debug(self.vapi.cli("show session verbose 2"))
Dave Wallaceb063ad02019-04-09 21:01:09 -0400186
187 @unittest.skipUnless(running_extended_tests, "part of extended tests")
Dave Wallace211b28a2019-05-08 20:46:33 -0400188 def test_quic_internal_transfer(self):
189 """ QUIC internal echo client/server transfer """
Dave Wallaceb063ad02019-04-09 21:01:09 -0400190
Dave Wallace211b28a2019-05-08 20:46:33 -0400191 self.internal_ipv4_transfer_test(self.server_echo_test_args,
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400192 self.client_echo_test_args +
193 ["no-output", "mbytes", "10"])
Dave Wallaceb063ad02019-04-09 21:01:09 -0400194
Dave Wallaceb063ad02019-04-09 21:01:09 -0400195
Dave Wallace0d144c72019-05-15 21:41:23 -0400196class QUICInternalSerialEchoIPv4TestCase(QUICTestCase):
197 """ QUIC Internal Serial Echo IPv4 Transfer Test Cases """
198
199 @classmethod
200 def setUpClass(cls):
201 super(QUICInternalSerialEchoIPv4TestCase, cls).setUpClass()
202
203 @classmethod
204 def tearDownClass(cls):
205 super(QUICInternalSerialEchoIPv4TestCase, cls).tearDownClass()
206
207 def setUp(self):
208 super(QUICInternalSerialEchoIPv4TestCase, self).setUp()
209 self.thru_host_stack_ipv4_setup()
210
211 def tearDown(self):
212 super(QUICInternalSerialEchoIPv4TestCase, self).tearDown()
213 self.thru_host_stack_ipv4_tear_down()
214
215 def show_commands_at_teardown(self):
216 self.logger.debug(self.vapi.cli("show session verbose 2"))
217
218 @unittest.skipUnless(running_extended_tests, "part of extended tests")
219 def test_quic_serial_internal_transfer(self):
220 """ QUIC serial internal echo client/server transfer """
221
222 client_args = (self.client_echo_test_args +
223 ["no-output", "mbytes", "10"])
224 self.internal_ipv4_transfer_test(self.server_echo_test_args,
225 client_args)
226 self.start_internal_echo_client(client_args)
227 self.start_internal_echo_client(client_args)
228 self.start_internal_echo_client(client_args)
229 self.start_internal_echo_client(client_args)
230
231
Dave Wallace211b28a2019-05-08 20:46:33 -0400232class QUICInternalEchoIPv4MultiStreamTestCase(QUICTestCase):
233 """ QUIC Internal Echo IPv4 Transfer Test Cases """
234
235 @classmethod
236 def setUpClass(cls):
237 super(QUICInternalEchoIPv4MultiStreamTestCase, cls).setUpClass()
238
239 @classmethod
240 def tearDownClass(cls):
241 super(QUICInternalEchoIPv4MultiStreamTestCase, cls).tearDownClass()
242
243 def setUp(self):
244 super(QUICInternalEchoIPv4MultiStreamTestCase, self).setUp()
245 self.thru_host_stack_ipv4_setup()
246
247 def tearDown(self):
Dave Wallace211b28a2019-05-08 20:46:33 -0400248 super(QUICInternalEchoIPv4MultiStreamTestCase, self).tearDown()
Dave Wallace0d144c72019-05-15 21:41:23 -0400249 self.thru_host_stack_ipv4_tear_down()
Dave Wallace211b28a2019-05-08 20:46:33 -0400250
251 def show_commands_at_teardown(self):
252 self.logger.debug(self.vapi.cli("show session verbose 2"))
253
254 @unittest.skipUnless(running_extended_tests, "part of extended tests")
255 def test_quic_internal_multistream_transfer(self):
256 """ QUIC internal echo client/server multi-stream transfer """
257
258 self.internal_ipv4_transfer_test(self.server_echo_test_args,
259 self.client_echo_test_args +
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400260 ["quic-streams", "10",
261 "mbytes", "1",
262 "no-output"])
263
264
265class QUICExternalEchoIPv4TestCase(QUICTestCase):
266 """ QUIC External Echo IPv4 Transfer Test Cases """
267
268 @classmethod
Dave Wallace1f37a7b2019-05-20 15:57:28 -0400269 def setUpConstants(cls):
270 super(QUICExternalEchoIPv4TestCase, cls).setUpConstants()
271 cls.vpp_cmdline.extend(["session", "{", "evt_qs_memfd_seg", "}"])
272
273 @classmethod
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400274 def setUpClass(cls):
275 super(QUICExternalEchoIPv4TestCase, cls).setUpClass()
276
277 @classmethod
278 def tearDownClass(cls):
279 super(QUICExternalEchoIPv4TestCase, cls).tearDownClass()
280
281 def setUp(self):
282 super(QUICExternalEchoIPv4TestCase, self).setUp()
283 self.thru_host_stack_ipv4_setup()
284
285 def tearDown(self):
286 super(QUICExternalEchoIPv4TestCase, self).tearDown()
287 self.thru_host_stack_ipv4_tear_down()
288
289 def show_commands_at_teardown(self):
290 self.logger.debug(self.vapi.cli("show session verbose 2"))
291
292 @unittest.skipUnless(running_extended_tests, "part of extended tests")
293 def test_quic_external_transfer(self):
294 """ QUIC external echo client/server transfer """
295
296 self.external_ipv4_transfer_test(self.server_echo_test_args +
Dave Wallace1f37a7b2019-05-20 15:57:28 -0400297 ["socket-name", self.api_sock,
298 "server"],
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400299 self.client_echo_test_args +
300 ["socket-name", self.api_sock,
Dave Wallace1f37a7b2019-05-20 15:57:28 -0400301 "client", "mbytes", "10"])
Dave Wallace211b28a2019-05-08 20:46:33 -0400302
Dave Wallaceb063ad02019-04-09 21:01:09 -0400303
304if __name__ == '__main__':
305 unittest.main(testRunner=VppTestRunner)