blob: ed15cdcd8ed31b7bea6e861580dcbcf6171b5c5f [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 """
Dave Wallace47e77302019-06-05 10:40:07 -040015 process = None
Dave Wallace3bffd4b2019-05-13 15:51:52 -040016
Nathan Skrzypczake82a7ad2019-05-22 18:41:50 +020017 def __init__(self, build_dir, appname, args, logger, env={}):
Dave Wallace3bffd4b2019-05-13 15:51:52 -040018 app = "%s/vpp/bin/%s" % (build_dir, appname)
19 self.args = [app] + args
20 super(QUICAppWorker, self).__init__(self.args, logger, env)
21
Dave Wallace47e77302019-06-05 10:40:07 -040022 def run(self):
23 super(QUICAppWorker, self).run()
Dave Wallace47e77302019-06-05 10:40:07 -040024
25 def teardown(self, logger, timeout):
26 if self.process is None:
Chore464e1dc2019-06-25 14:21:26 +043027 return False
Dave Wallace47e77302019-06-05 10:40:07 -040028 try:
29 logger.debug("Killing worker process (pid %d)" % self.process.pid)
30 os.killpg(os.getpgid(self.process.pid), signal.SIGKILL)
31 self.join(timeout)
32 except OSError as e:
33 logger.debug("Couldn't kill worker process")
34 return True
35 return False
36
Dave Wallace3bffd4b2019-05-13 15:51:52 -040037
Dave Wallace211b28a2019-05-08 20:46:33 -040038class QUICTestCase(VppTestCase):
Dave Wallaceb063ad02019-04-09 21:01:09 -040039 """ QUIC Test Case """
40
Dave Wallaceb063ad02019-04-09 21:01:09 -040041 def setUp(self):
Dave Wallace47e77302019-06-05 10:40:07 -040042 super(QUICTestCase, self).setUp()
Dave Wallace211b28a2019-05-08 20:46:33 -040043 var = "VPP_BUILD_DIR"
44 self.build_dir = os.getenv(var, None)
45 if self.build_dir is None:
46 raise Exception("Environment variable `%s' not set" % var)
47 self.vppDebug = 'vpp_debug' in self.build_dir
48 self.timeout = 20
Dave Wallaceb063ad02019-04-09 21:01:09 -040049 self.vapi.session_enable_disable(is_enabled=1)
Dave Wallace47e77302019-06-05 10:40:07 -040050 self.pre_test_sleep = 0.3
51 self.post_test_sleep = 0.2
Dave Wallace211b28a2019-05-08 20:46:33 -040052
Dave Wallaceb063ad02019-04-09 21:01:09 -040053 self.create_loopback_interfaces(2)
Dave Wallace211b28a2019-05-08 20:46:33 -040054 self.uri = "quic://%s/1234" % self.loop0.local_ip4
Dave Wallaceb063ad02019-04-09 21:01:09 -040055 table_id = 1
Dave Wallaceb063ad02019-04-09 21:01:09 -040056 for i in self.lo_interfaces:
57 i.admin_up()
58
59 if table_id != 0:
60 tbl = VppIpTable(self, table_id)
61 tbl.add_vpp_config()
62
63 i.set_table_ip4(table_id)
64 i.config_ip4()
65 table_id += 1
66
67 # Configure namespaces
Dave Wallace211b28a2019-05-08 20:46:33 -040068 self.vapi.app_namespace_add_del(namespace_id=b"server",
Dave Wallaceb063ad02019-04-09 21:01:09 -040069 sw_if_index=self.loop0.sw_if_index)
Dave Wallace211b28a2019-05-08 20:46:33 -040070 self.vapi.app_namespace_add_del(namespace_id=b"client",
Dave Wallaceb063ad02019-04-09 21:01:09 -040071 sw_if_index=self.loop1.sw_if_index)
72
Dave Wallace211b28a2019-05-08 20:46:33 -040073 # Add inter-table routes
74 self.ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32,
75 [VppRoutePath("0.0.0.0",
76 0xffffffff,
77 nh_table_id=2)], table_id=1)
78 self.ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32,
79 [VppRoutePath("0.0.0.0",
80 0xffffffff,
81 nh_table_id=1)], table_id=2)
82 self.ip_t01.add_vpp_config()
83 self.ip_t10.add_vpp_config()
84 self.logger.debug(self.vapi.cli("show ip fib"))
85
Dave Wallace47e77302019-06-05 10:40:07 -040086 def tearDown(self):
87 self.vapi.session_enable_disable(is_enabled=0)
Dave Wallace211b28a2019-05-08 20:46:33 -040088 # 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 Wallace47e77302019-06-05 10:40:07 -040096 super(QUICTestCase, self).tearDown()
Dave Wallace3bffd4b2019-05-13 15:51:52 -040097
Dave Wallace211b28a2019-05-08 20:46:33 -040098
Dave Wallace47e77302019-06-05 10:40:07 -040099class QUICEchoInternalTestCase(QUICTestCase):
100 """QUIC Echo Internal Test Case"""
Chore464e1dc2019-06-25 14:21:26 +0430101
Dave Wallace211b28a2019-05-08 20:46:33 -0400102 def setUp(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400103 super(QUICEchoInternalTestCase, self).setUp()
Chore464e1dc2019-06-25 14:21:26 +0430104 self.client_args = "uri %s fifo-size 64 test-bytes appns client" \
105 % self.uri
Dave Wallace47e77302019-06-05 10:40:07 -0400106 self.server_args = "uri %s fifo-size 64 appns server" % self.uri
Dave Wallace211b28a2019-05-08 20:46:33 -0400107
Dave Wallace47e77302019-06-05 10:40:07 -0400108 def server(self, *args):
Chore464e1dc2019-06-25 14:21:26 +0430109 error = self.vapi.cli(
110 "test echo server %s %s" %
111 (self.server_args, ' '.join(args)))
Dave Wallace47e77302019-06-05 10:40:07 -0400112 if error:
113 self.logger.critical(error)
114 self.assertNotIn("failed", error)
Dave Wallace211b28a2019-05-08 20:46:33 -0400115
Dave Wallace47e77302019-06-05 10:40:07 -0400116 def client(self, *args):
Chore464e1dc2019-06-25 14:21:26 +0430117 error = self.vapi.cli(
118 "test echo client %s %s" %
119 (self.client_args, ' '.join(args)))
Dave Wallace47e77302019-06-05 10:40:07 -0400120 if error:
121 self.logger.critical(error)
122 self.assertNotIn("failed", error)
Dave Wallaceb063ad02019-04-09 21:01:09 -0400123
Chore464e1dc2019-06-25 14:21:26 +0430124
Dave Wallace47e77302019-06-05 10:40:07 -0400125class QUICEchoInternalTransferTestCase(QUICEchoInternalTestCase):
126 """QUIC Echo Internal Transfer Test Case"""
Dave Wallaceb063ad02019-04-09 21:01:09 -0400127 @unittest.skipUnless(running_extended_tests, "part of extended tests")
Dave Wallace211b28a2019-05-08 20:46:33 -0400128 def test_quic_internal_transfer(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400129 self.server()
Aloys Augustin706079c2019-06-27 16:10:23 +0200130 self.client("no-output", "mbytes", "2")
Dave Wallaceb063ad02019-04-09 21:01:09 -0400131
Chore464e1dc2019-06-25 14:21:26 +0430132
Dave Wallace47e77302019-06-05 10:40:07 -0400133class QUICEchoInternalSerialTestCase(QUICEchoInternalTestCase):
134 """QUIC Echo Internal Serial Transfer Test Case"""
Dave Wallace0d144c72019-05-15 21:41:23 -0400135 @unittest.skipUnless(running_extended_tests, "part of extended tests")
136 def test_quic_serial_internal_transfer(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400137 self.server()
Aloys Augustin706079c2019-06-27 16:10:23 +0200138 self.client("no-output", "mbytes", "2")
139 self.client("no-output", "mbytes", "2")
140 self.client("no-output", "mbytes", "2")
141 self.client("no-output", "mbytes", "2")
142 self.client("no-output", "mbytes", "2")
Dave Wallace0d144c72019-05-15 21:41:23 -0400143
Chore464e1dc2019-06-25 14:21:26 +0430144
Dave Wallace47e77302019-06-05 10:40:07 -0400145class QUICEchoInternalMStreamTestCase(QUICEchoInternalTestCase):
146 """QUIC Echo Internal MultiStream Test Case"""
Dave Wallace211b28a2019-05-08 20:46:33 -0400147 @unittest.skipUnless(running_extended_tests, "part of extended tests")
148 def test_quic_internal_multistream_transfer(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400149 self.server()
150 self.client("nclients", "10", "mbytes", "1", "no-output")
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400151
152
Dave Wallace47e77302019-06-05 10:40:07 -0400153class QUICEchoExternalTestCase(QUICTestCase):
154 extra_vpp_punt_config = ["session", "{", "evt_qs_memfd_seg", "}"]
155 quic_setup = "default"
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400156
157 def setUp(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400158 super(QUICEchoExternalTestCase, self).setUp()
Chore464e1dc2019-06-25 14:21:26 +0430159 common_args = [
160 "uri",
161 self.uri,
162 "fifo-size",
163 "64",
164 "test-bytes:assert",
165 "socket-name",
166 self.api_sock]
167 self.server_echo_test_args = common_args + \
168 ["server", "appns", "server", "quic-setup", self.quic_setup]
169 self.client_echo_test_args = common_args + \
170 ["client", "appns", "client", "quic-setup", self.quic_setup]
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400171
Dave Wallace47e77302019-06-05 10:40:07 -0400172 def server(self, *args):
173 _args = self.server_echo_test_args + list(args)
Chore464e1dc2019-06-25 14:21:26 +0430174 self.worker_server = QUICAppWorker(
175 self.build_dir,
176 "quic_echo",
177 _args,
Nathan Skrzypczake82a7ad2019-05-22 18:41:50 +0200178 self.logger)
Dave Wallace47e77302019-06-05 10:40:07 -0400179 self.worker_server.start()
180 self.sleep(self.pre_test_sleep)
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400181
Dave Wallace47e77302019-06-05 10:40:07 -0400182 def client(self, *args):
183 _args = self.client_echo_test_args + list(args)
184 # self.client_echo_test_args += "use-svm-api"
Chore464e1dc2019-06-25 14:21:26 +0430185 self.worker_client = QUICAppWorker(
186 self.build_dir,
187 "quic_echo",
188 _args,
Nathan Skrzypczake82a7ad2019-05-22 18:41:50 +0200189 self.logger)
Dave Wallace47e77302019-06-05 10:40:07 -0400190 self.worker_client.start()
Nathan Skrzypczak24cbf772019-07-09 14:36:31 +0200191 self.worker_client.join(self.timeout)
192 self.worker_server.join(self.timeout)
Dave Wallace47e77302019-06-05 10:40:07 -0400193 self.sleep(self.post_test_sleep)
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400194
Dave Wallace47e77302019-06-05 10:40:07 -0400195 def validate_external_test_results(self):
Chore464e1dc2019-06-25 14:21:26 +0430196 self.logger.info(
197 "Client worker result is `%s'" %
198 self.worker_client.result)
Dave Wallace47e77302019-06-05 10:40:07 -0400199 server_result = self.worker_server.result
200 client_result = self.worker_client.result
201 server_kill_error = False
202 if self.worker_server.result is None:
Chore464e1dc2019-06-25 14:21:26 +0430203 server_kill_error = self.worker_server.teardown(
204 self.logger, self.timeout)
Dave Wallace47e77302019-06-05 10:40:07 -0400205 if self.worker_client.result is None:
206 self.worker_client.teardown(self.logger, self.timeout)
Nathan Skrzypczake82a7ad2019-05-22 18:41:50 +0200207 self.assertEqual(server_result, 0, "Wrong server worker return code")
Chore464e1dc2019-06-25 14:21:26 +0430208 self.assertIsNotNone(
209 client_result,
210 "Timeout! Client worker did not finish in %ss" %
211 self.timeout)
Dave Wallace47e77302019-06-05 10:40:07 -0400212 self.assertEqual(client_result, 0, "Wrong client worker return code")
213 self.assertFalse(server_kill_error, "Server kill errored")
214
215
216class QUICEchoExternalTransferTestCase(QUICEchoExternalTestCase):
217 """QUIC Echo External Transfer Test Case"""
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400218 @unittest.skipUnless(running_extended_tests, "part of extended tests")
219 def test_quic_external_transfer(self):
Dave Wallace47e77302019-06-05 10:40:07 -0400220 self.server()
221 self.client()
222 self.validate_external_test_results()
Dave Wallace3bffd4b2019-05-13 15:51:52 -0400223
Chore464e1dc2019-06-25 14:21:26 +0430224
Dave Wallace47e77302019-06-05 10:40:07 -0400225class QUICEchoExternalServerStreamTestCase(QUICEchoExternalTestCase):
226 """QUIC Echo External Transfer Server Stream Test Case"""
227 quic_setup = "serverstream"
228
229 @unittest.skipUnless(running_extended_tests, "part of extended tests")
230 def test_quic_external_transfer_server_stream(self):
Nathan Skrzypczake82a7ad2019-05-22 18:41:50 +0200231 self.server("TX=1Kb", "RX=0")
232 self.client("TX=0", "RX=1Kb")
Dave Wallace47e77302019-06-05 10:40:07 -0400233 self.validate_external_test_results()
234
Chore464e1dc2019-06-25 14:21:26 +0430235
Dave Wallace47e77302019-06-05 10:40:07 -0400236class QUICEchoExternalServerStreamWorkersTestCase(QUICEchoExternalTestCase):
237 """QUIC Echo External Transfer Server Stream MultiWorker Test Case"""
238 quic_setup = "serverstream"
239
240 @unittest.skipUnless(running_extended_tests, "part of extended tests")
241 def test_quic_external_transfer_server_stream_multi_workers(self):
Nathan Skrzypczake82a7ad2019-05-22 18:41:50 +0200242 self.server("nclients", "4/4", "TX=1Kb", "RX=0")
243 self.client("nclients", "4/4", "TX=0", "RX=1Kb")
Dave Wallace47e77302019-06-05 10:40:07 -0400244 self.validate_external_test_results()
Dave Wallace211b28a2019-05-08 20:46:33 -0400245
Dave Wallaceb063ad02019-04-09 21:01:09 -0400246
247if __name__ == '__main__':
248 unittest.main(testRunner=VppTestRunner)