vcl: fix iperf3 server crash issue when it runs over vpp host stack.
[vpp.git] / test / test_vcl.py
1 #!/usr/bin/env python3
2 """ Vpp VCL tests """
3
4 import unittest
5 import os
6 import subprocess
7 import signal
8 import glob
9 from config import config
10 from framework import VppTestCase, VppTestRunner, Worker
11 from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath, FibPathProto
12
13 iperf3 = "/usr/bin/iperf3"
14
15
16 def have_app(app):
17     try:
18         subprocess.check_output([app, "-v"])
19     except (subprocess.CalledProcessError, OSError):
20         return False
21     return True
22
23
24 _have_iperf3 = have_app(iperf3)
25
26
27 class VCLAppWorker(Worker):
28     """VCL Test Application Worker"""
29
30     libname = "libvcl_ldpreload.so"
31
32     class LibraryNotFound(Exception):
33         pass
34
35     def __init__(
36         self, appname, executable_args, logger, env=None, role=None, *args, **kwargs
37     ):
38         self.role = role
39         vcl_ldpreload_glob = f"{config.vpp_install_dir}/**/{self.libname}"
40         vcl_ldpreload_so = glob.glob(vcl_ldpreload_glob, recursive=True)
41
42         if len(vcl_ldpreload_so) < 1:
43             raise LibraryNotFound("cannot locate library: {}".format(self.libname))
44
45         vcl_ldpreload_so = vcl_ldpreload_so[0]
46
47         if env is None:
48             env = {}
49         if "iperf" in appname:
50             app = appname
51             env.update({"LD_PRELOAD": vcl_ldpreload_so})
52         elif "sock" in appname:
53             app = f"{config.vpp_build_dir}/vpp/bin/{appname}"
54             env.update({"LD_PRELOAD": vcl_ldpreload_so})
55         else:
56             app = f"{config.vpp_build_dir}/vpp/bin/{appname}"
57         self.args = [app] + executable_args
58         super(VCLAppWorker, self).__init__(self.args, logger, env, *args, **kwargs)
59
60
61 class VCLTestCase(VppTestCase):
62     """VCL Test Class"""
63
64     session_startup = ["poll-main"]
65
66     @classmethod
67     def setUpClass(cls):
68         if cls.session_startup:
69             conf = "session {" + " ".join(cls.session_startup) + "}"
70             cls.extra_vpp_punt_config = [conf]
71         super(VCLTestCase, cls).setUpClass()
72
73     @classmethod
74     def tearDownClass(cls):
75         super(VCLTestCase, cls).tearDownClass()
76
77     def setUp(self):
78         self.vppDebug = "vpp_debug" in config.vpp_install_dir
79         self.server_addr = "127.0.0.1"
80         self.server_port = "22000"
81         self.server_args = [self.server_port]
82         self.server_ipv6_addr = "::1"
83         self.server_ipv6_args = ["-6", self.server_port]
84         self.timeout = 20
85         self.echo_phrase = "Hello, world! Jenny is a friend of mine."
86         self.pre_test_sleep = 0.3
87         self.post_test_sleep = 0.2
88         self.sapi_client_sock = ""
89         self.sapi_server_sock = ""
90
91         if os.path.isfile("/tmp/ldp_server_af_unix_socket"):
92             os.remove("/tmp/ldp_server_af_unix_socket")
93
94         super(VCLTestCase, self).setUp()
95
96     def update_vcl_app_env(self, ns_id, ns_secret, attach_sock):
97         if not ns_id:
98             if "VCL_APP_NAMESPACE_ID" in self.vcl_app_env:
99                 del self.vcl_app_env["VCL_APP_NAMESPACE_ID"]
100         else:
101             self.vcl_app_env["VCL_APP_NAMESPACE_ID"] = ns_id
102
103         if not ns_secret:
104             if "VCL_APP_NAMESPACE_SECRET" in self.vcl_app_env:
105                 del self.vcl_app_env["VCL_APP_NAMESPACE_SECRET"]
106         else:
107             self.vcl_app_env["VCL_APP_NAMESPACE_SECRET"] = ns_secret
108
109         if not attach_sock:
110             self.vcl_app_env["VCL_VPP_API_SOCKET"] = self.get_api_sock_path()
111             if "VCL_VPP_SAPI_SOCKET" in self.vcl_app_env:
112                 del self.vcl_app_env["VCL_VPP_SAPI_SOCKET"]
113         else:
114             sapi_sock = "%s/app_ns_sockets/%s" % (self.tempdir, attach_sock)
115             self.vcl_app_env["VCL_VPP_SAPI_SOCKET"] = sapi_sock
116             if "VCL_VPP_API_SOCKET" in self.vcl_app_env:
117                 del self.vcl_app_env["VCL_VPP_API_SOCKET"]
118
119     def cut_thru_setup(self):
120         self.vapi.session_enable_disable(is_enable=1)
121
122     def cut_thru_tear_down(self):
123         self.vapi.session_enable_disable(is_enable=0)
124
125     def cut_thru_test(self, server_app, server_args, client_app, client_args):
126         self.vcl_app_env = {"VCL_APP_SCOPE_LOCAL": "true"}
127
128         self.update_vcl_app_env("", "", self.sapi_server_sock)
129         worker_server = VCLAppWorker(
130             server_app, server_args, self.logger, self.vcl_app_env, "server"
131         )
132         worker_server.start()
133         self.sleep(self.pre_test_sleep)
134
135         self.update_vcl_app_env("", "", self.sapi_client_sock)
136         worker_client = VCLAppWorker(
137             client_app, client_args, self.logger, self.vcl_app_env, "client"
138         )
139         worker_client.start()
140         worker_client.join(self.timeout)
141         try:
142             self.validateResults(worker_client, worker_server, self.timeout)
143         except Exception as error:
144             self.fail("Failed with %s" % error)
145         self.sleep(self.post_test_sleep)
146
147     def thru_host_stack_setup(self):
148         self.vapi.session_enable_disable(is_enable=1)
149         self.create_loopback_interfaces(2)
150
151         table_id = 1
152
153         for i in self.lo_interfaces:
154             i.admin_up()
155
156             if table_id != 0:
157                 tbl = VppIpTable(self, table_id)
158                 tbl.add_vpp_config()
159
160             i.set_table_ip4(table_id)
161             i.config_ip4()
162             table_id += 1
163
164         # Configure namespaces
165         self.vapi.app_namespace_add_del(
166             namespace_id="1", secret=1234, sw_if_index=self.loop0.sw_if_index
167         )
168         self.vapi.app_namespace_add_del(
169             namespace_id="2", secret=5678, sw_if_index=self.loop1.sw_if_index
170         )
171
172         # Add inter-table routes
173         ip_t01 = VppIpRoute(
174             self,
175             self.loop1.local_ip4,
176             32,
177             [VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=2)],
178             table_id=1,
179         )
180         ip_t10 = VppIpRoute(
181             self,
182             self.loop0.local_ip4,
183             32,
184             [VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=1)],
185             table_id=2,
186         )
187         ip_t01.add_vpp_config()
188         ip_t10.add_vpp_config()
189         self.logger.debug(self.vapi.cli("show ip fib"))
190
191     def thru_host_stack_tear_down(self):
192         for i in self.lo_interfaces:
193             i.unconfig_ip4()
194             i.set_table_ip4(0)
195             i.admin_down()
196             i.remove_vpp_config()
197
198     def thru_host_stack_ipv6_setup(self):
199         self.vapi.session_enable_disable(is_enable=1)
200         self.create_loopback_interfaces(2)
201
202         table_id = 1
203
204         for i in self.lo_interfaces:
205             i.admin_up()
206
207             tbl = VppIpTable(self, table_id, is_ip6=1)
208             tbl.add_vpp_config()
209
210             i.set_table_ip6(table_id)
211             i.config_ip6()
212             table_id += 1
213
214         # Configure namespaces
215         self.vapi.app_namespace_add_del(
216             namespace_id="1", secret=1234, sw_if_index=self.loop0.sw_if_index
217         )
218         self.vapi.app_namespace_add_del(
219             namespace_id="2", secret=5678, sw_if_index=self.loop1.sw_if_index
220         )
221
222         # Add inter-table routes
223         ip_t01 = VppIpRoute(
224             self,
225             self.loop1.local_ip6,
226             128,
227             [VppRoutePath("::0", 0xFFFFFFFF, nh_table_id=2)],
228             table_id=1,
229         )
230         ip_t10 = VppIpRoute(
231             self,
232             self.loop0.local_ip6,
233             128,
234             [VppRoutePath("::0", 0xFFFFFFFF, nh_table_id=1)],
235             table_id=2,
236         )
237         ip_t01.add_vpp_config()
238         ip_t10.add_vpp_config()
239         self.logger.debug(self.vapi.cli("show interface addr"))
240         self.logger.debug(self.vapi.cli("show ip6 fib"))
241
242     def thru_host_stack_ipv6_tear_down(self):
243         for i in self.lo_interfaces:
244             i.unconfig_ip6()
245             i.set_table_ip6(0)
246             i.admin_down()
247
248         self.vapi.session_enable_disable(is_enable=0)
249
250     @unittest.skipUnless(_have_iperf3, "'%s' not found, Skipping.")
251     def thru_host_stack_test(self, server_app, server_args, client_app, client_args):
252         self.vcl_app_env = {"VCL_APP_SCOPE_GLOBAL": "true"}
253
254         self.update_vcl_app_env("1", "1234", self.sapi_server_sock)
255         worker_server = VCLAppWorker(
256             server_app, server_args, self.logger, self.vcl_app_env, "server"
257         )
258         worker_server.start()
259         self.sleep(self.pre_test_sleep)
260
261         self.update_vcl_app_env("2", "5678", self.sapi_client_sock)
262         worker_client = VCLAppWorker(
263             client_app, client_args, self.logger, self.vcl_app_env, "client"
264         )
265         worker_client.start()
266         worker_client.join(self.timeout)
267
268         try:
269             self.validateResults(worker_client, worker_server, self.timeout)
270         except Exception as error:
271             self.fail("Failed with %s" % error)
272         self.sleep(self.post_test_sleep)
273
274     def validateResults(self, worker_client, worker_server, timeout):
275         if worker_server.process is None:
276             raise RuntimeError("worker_server is not running.")
277         if os.path.isdir("/proc/{}".format(worker_server.process.pid)):
278             self.logger.info(
279                 "Killing server worker process (pid %d)" % worker_server.process.pid
280             )
281             os.killpg(os.getpgid(worker_server.process.pid), signal.SIGTERM)
282             worker_server.join()
283         self.logger.info("Client worker result is `%s'" % worker_client.result)
284         error = False
285         if worker_client.result is None:
286             try:
287                 error = True
288                 self.logger.error(
289                     "Timeout: %ss! Killing client worker process (pid %d)"
290                     % (timeout, worker_client.process.pid)
291                 )
292                 os.killpg(os.getpgid(worker_client.process.pid), signal.SIGKILL)
293                 worker_client.join()
294             except OSError:
295                 self.logger.debug("Couldn't kill client worker process")
296                 raise
297         if error:
298             raise RuntimeError("Timeout! Client worker did not finish in %ss" % timeout)
299         self.assert_equal(worker_client.result, 0, "Binary test return code")
300
301
302 class LDPCutThruTestCase(VCLTestCase):
303     """LDP Cut Thru Tests"""
304
305     @classmethod
306     def setUpClass(cls):
307         cls.session_startup = ["poll-main", "use-app-socket-api"]
308         super(LDPCutThruTestCase, cls).setUpClass()
309
310     @classmethod
311     def tearDownClass(cls):
312         super(LDPCutThruTestCase, cls).tearDownClass()
313
314     def setUp(self):
315         super(LDPCutThruTestCase, self).setUp()
316
317         self.cut_thru_setup()
318         self.client_echo_test_args = [
319             "-E",
320             self.echo_phrase,
321             "-X",
322             self.server_addr,
323             self.server_port,
324         ]
325         self.client_iperf3_timeout = 20
326         self.client_iperf3_args = ["-4", "-t 2", "-c", self.server_addr]
327         self.server_iperf3_args = ["-4", "-s"]
328         self.client_uni_dir_nsock_timeout = 20
329         self.client_uni_dir_nsock_test_args = [
330             "-N",
331             "1000",
332             "-U",
333             "-X",
334             "-I",
335             "2",
336             self.server_addr,
337             self.server_port,
338         ]
339         self.client_bi_dir_nsock_timeout = 20
340         self.client_bi_dir_nsock_test_args = [
341             "-N",
342             "1000",
343             "-B",
344             "-X",
345             "-I",
346             "2",
347             self.server_addr,
348             self.server_port,
349         ]
350         self.sapi_client_sock = "default"
351         self.sapi_server_sock = "default"
352
353     def tearDown(self):
354         super(LDPCutThruTestCase, self).tearDown()
355         self.cut_thru_tear_down()
356
357     def show_commands_at_teardown(self):
358         self.logger.debug(self.vapi.cli("show session verbose 2"))
359         self.logger.debug(self.vapi.cli("show app mq"))
360
361     @unittest.skipUnless(config.extended, "part of extended tests")
362     def test_ldp_cut_thru_echo(self):
363         """run LDP cut thru echo test"""
364
365         self.cut_thru_test(
366             "sock_test_server",
367             self.server_args,
368             "sock_test_client",
369             self.client_echo_test_args,
370         )
371
372     def test_ldp_cut_thru_iperf3(self):
373         """run LDP cut thru iperf3 test"""
374
375         self.timeout = self.client_iperf3_timeout
376         self.cut_thru_test(
377             iperf3, self.server_iperf3_args, iperf3, self.client_iperf3_args
378         )
379
380     @unittest.skipUnless(config.extended, "part of extended tests")
381     def test_ldp_cut_thru_uni_dir_nsock(self):
382         """run LDP cut thru uni-directional (multiple sockets) test"""
383
384         self.timeout = self.client_uni_dir_nsock_timeout
385         self.cut_thru_test(
386             "sock_test_server",
387             self.server_args,
388             "sock_test_client",
389             self.client_uni_dir_nsock_test_args,
390         )
391
392     @unittest.skipUnless(config.extended, "part of extended tests")
393     @unittest.skip("sock test apps need to be improved")
394     def test_ldp_cut_thru_bi_dir_nsock(self):
395         """run LDP cut thru bi-directional (multiple sockets) test"""
396
397         self.timeout = self.client_bi_dir_nsock_timeout
398         self.cut_thru_test(
399             "sock_test_server",
400             self.server_args,
401             "sock_test_client",
402             self.client_bi_dir_nsock_test_args,
403         )
404
405
406 class VCLCutThruTestCase(VCLTestCase):
407     """VCL Cut Thru Tests"""
408
409     @classmethod
410     def setUpClass(cls):
411         super(VCLCutThruTestCase, cls).setUpClass()
412
413     @classmethod
414     def tearDownClass(cls):
415         super(VCLCutThruTestCase, cls).tearDownClass()
416
417     def setUp(self):
418         super(VCLCutThruTestCase, self).setUp()
419
420         self.cut_thru_setup()
421         self.client_echo_test_args = [
422             "-E",
423             self.echo_phrase,
424             "-X",
425             self.server_addr,
426             self.server_port,
427         ]
428
429         self.client_uni_dir_nsock_timeout = 20
430         self.client_uni_dir_nsock_test_args = [
431             "-N",
432             "1000",
433             "-U",
434             "-X",
435             "-I",
436             "2",
437             self.server_addr,
438             self.server_port,
439         ]
440         self.client_bi_dir_nsock_timeout = 20
441         self.client_bi_dir_nsock_test_args = [
442             "-N",
443             "1000",
444             "-B",
445             "-X",
446             "-I",
447             "2",
448             self.server_addr,
449             self.server_port,
450         ]
451
452     def tearDown(self):
453         super(VCLCutThruTestCase, self).tearDown()
454
455     def show_commands_at_teardown(self):
456         self.logger.debug(self.vapi.cli("show session verbose 2"))
457         self.logger.debug(self.vapi.cli("show app mq"))
458
459     def test_vcl_cut_thru_echo(self):
460         """run VCL cut thru echo test"""
461
462         self.cut_thru_test(
463             "vcl_test_server",
464             self.server_args,
465             "vcl_test_client",
466             self.client_echo_test_args,
467         )
468
469     def test_vcl_cut_thru_uni_dir_nsock(self):
470         """run VCL cut thru uni-directional (multiple sockets) test"""
471
472         self.timeout = self.client_uni_dir_nsock_timeout
473         self.cut_thru_test(
474             "vcl_test_server",
475             self.server_args,
476             "vcl_test_client",
477             self.client_uni_dir_nsock_test_args,
478         )
479
480     def test_vcl_cut_thru_bi_dir_nsock(self):
481         """run VCL cut thru bi-directional (multiple sockets) test"""
482
483         self.timeout = self.client_bi_dir_nsock_timeout
484         self.cut_thru_test(
485             "vcl_test_server",
486             self.server_args,
487             "vcl_test_client",
488             self.client_bi_dir_nsock_test_args,
489         )
490
491
492 class VCLThruHostStackEcho(VCLTestCase):
493     """VCL Thru Host Stack Echo"""
494
495     @classmethod
496     def setUpClass(cls):
497         super(VCLThruHostStackEcho, cls).setUpClass()
498
499     @classmethod
500     def tearDownClass(cls):
501         super(VCLThruHostStackEcho, cls).tearDownClass()
502
503     def setUp(self):
504         super(VCLThruHostStackEcho, self).setUp()
505
506         self.thru_host_stack_setup()
507         self.client_bi_dir_nsock_timeout = 20
508         self.client_bi_dir_nsock_test_args = [
509             "-N",
510             "1000",
511             "-B",
512             "-X",
513             "-I",
514             "2",
515             self.loop0.local_ip4,
516             self.server_port,
517         ]
518         self.client_echo_test_args = [
519             "-E",
520             self.echo_phrase,
521             "-X",
522             self.loop0.local_ip4,
523             self.server_port,
524         ]
525
526     def tearDown(self):
527         self.thru_host_stack_tear_down()
528         super(VCLThruHostStackEcho, self).tearDown()
529
530     def test_vcl_thru_host_stack_echo(self):
531         """run VCL IPv4 thru host stack echo test"""
532
533         self.thru_host_stack_test(
534             "vcl_test_server",
535             self.server_args,
536             "vcl_test_client",
537             self.client_echo_test_args,
538         )
539
540     def show_commands_at_teardown(self):
541         self.logger.debug(self.vapi.cli("show app server"))
542         self.logger.debug(self.vapi.cli("show session verbose"))
543         self.logger.debug(self.vapi.cli("show app mq"))
544
545
546 class VCLThruHostStackTLS(VCLTestCase):
547     """VCL Thru Host Stack TLS"""
548
549     @classmethod
550     def setUpClass(cls):
551         cls.session_startup = ["poll-main", "use-app-socket-api"]
552         super(VCLThruHostStackTLS, cls).setUpClass()
553
554     @classmethod
555     def tearDownClass(cls):
556         super(VCLThruHostStackTLS, cls).tearDownClass()
557
558     def setUp(self):
559         super(VCLThruHostStackTLS, self).setUp()
560
561         self.thru_host_stack_setup()
562         self.client_uni_dir_tls_timeout = 20
563         self.server_tls_args = ["-L", self.server_port]
564         self.client_uni_dir_tls_test_args = [
565             "-N",
566             "1000",
567             "-U",
568             "-X",
569             "-L",
570             self.loop0.local_ip4,
571             self.server_port,
572         ]
573         self.sapi_server_sock = "1"
574         self.sapi_client_sock = "2"
575
576     def test_vcl_thru_host_stack_tls_uni_dir(self):
577         """run VCL thru host stack uni-directional TLS test"""
578
579         self.timeout = self.client_uni_dir_tls_timeout
580         self.thru_host_stack_test(
581             "vcl_test_server",
582             self.server_tls_args,
583             "vcl_test_client",
584             self.client_uni_dir_tls_test_args,
585         )
586
587     def tearDown(self):
588         self.thru_host_stack_tear_down()
589         super(VCLThruHostStackTLS, self).tearDown()
590
591     def show_commands_at_teardown(self):
592         self.logger.debug(self.vapi.cli("show app server"))
593         self.logger.debug(self.vapi.cli("show session verbose 2"))
594         self.logger.debug(self.vapi.cli("show app mq"))
595
596
597 class VCLThruHostStackDTLS(VCLTestCase):
598     """VCL Thru Host Stack DTLS"""
599
600     @classmethod
601     def setUpClass(cls):
602         super(VCLThruHostStackDTLS, cls).setUpClass()
603
604     @classmethod
605     def tearDownClass(cls):
606         super(VCLThruHostStackDTLS, cls).tearDownClass()
607
608     def setUp(self):
609         super(VCLThruHostStackDTLS, self).setUp()
610
611         self.thru_host_stack_setup()
612         self.client_uni_dir_dtls_timeout = 20
613         self.server_dtls_args = ["-p", "dtls", self.server_port]
614         self.client_uni_dir_dtls_test_args = [
615             "-N",
616             "1000",
617             "-U",
618             "-X",
619             "-p",
620             "dtls",
621             "-T 1400",
622             self.loop0.local_ip4,
623             self.server_port,
624         ]
625
626     def test_vcl_thru_host_stack_dtls_uni_dir(self):
627         """run VCL thru host stack uni-directional DTLS test"""
628
629         self.timeout = self.client_uni_dir_dtls_timeout
630         self.thru_host_stack_test(
631             "vcl_test_server",
632             self.server_dtls_args,
633             "vcl_test_client",
634             self.client_uni_dir_dtls_test_args,
635         )
636
637     def tearDown(self):
638         self.thru_host_stack_tear_down()
639         super(VCLThruHostStackDTLS, self).tearDown()
640
641     def show_commands_at_teardown(self):
642         self.logger.debug(self.vapi.cli("show app server"))
643         self.logger.debug(self.vapi.cli("show session verbose 2"))
644         self.logger.debug(self.vapi.cli("show app mq"))
645
646
647 class VCLThruHostStackQUIC(VCLTestCase):
648     """VCL Thru Host Stack QUIC"""
649
650     @classmethod
651     def setUpClass(cls):
652         cls.extra_vpp_plugin_config.append("plugin quic_plugin.so { enable }")
653         super(VCLThruHostStackQUIC, cls).setUpClass()
654
655     @classmethod
656     def tearDownClass(cls):
657         super(VCLThruHostStackQUIC, cls).tearDownClass()
658
659     def setUp(self):
660         super(VCLThruHostStackQUIC, self).setUp()
661
662         self.thru_host_stack_setup()
663         self.client_uni_dir_quic_timeout = 20
664         self.server_quic_args = ["-p", "quic", self.server_port]
665         self.client_uni_dir_quic_test_args = [
666             "-N",
667             "1000",
668             "-U",
669             "-X",
670             "-p",
671             "quic",
672             self.loop0.local_ip4,
673             self.server_port,
674         ]
675
676     @unittest.skipUnless(config.extended, "part of extended tests")
677     def test_vcl_thru_host_stack_quic_uni_dir(self):
678         """run VCL thru host stack uni-directional QUIC test"""
679
680         self.timeout = self.client_uni_dir_quic_timeout
681         self.thru_host_stack_test(
682             "vcl_test_server",
683             self.server_quic_args,
684             "vcl_test_client",
685             self.client_uni_dir_quic_test_args,
686         )
687
688     def tearDown(self):
689         self.thru_host_stack_tear_down()
690         super(VCLThruHostStackQUIC, self).tearDown()
691
692     def show_commands_at_teardown(self):
693         self.logger.debug(self.vapi.cli("show app server"))
694         self.logger.debug(self.vapi.cli("show session verbose 2"))
695         self.logger.debug(self.vapi.cli("show app mq"))
696
697
698 class VCLThruHostStackBidirNsock(VCLTestCase):
699     """VCL Thru Host Stack Bidir Nsock"""
700
701     @classmethod
702     def setUpClass(cls):
703         super(VCLThruHostStackBidirNsock, cls).setUpClass()
704
705     @classmethod
706     def tearDownClass(cls):
707         super(VCLThruHostStackBidirNsock, cls).tearDownClass()
708
709     def setUp(self):
710         super(VCLThruHostStackBidirNsock, self).setUp()
711
712         self.thru_host_stack_setup()
713         self.client_bi_dir_nsock_timeout = 20
714         self.client_bi_dir_nsock_test_args = [
715             "-N",
716             "1000",
717             "-B",
718             "-X",
719             "-I",
720             "2",
721             self.loop0.local_ip4,
722             self.server_port,
723         ]
724         self.client_echo_test_args = [
725             "-E",
726             self.echo_phrase,
727             "-X",
728             self.loop0.local_ip4,
729             self.server_port,
730         ]
731
732     def tearDown(self):
733         self.thru_host_stack_tear_down()
734         super(VCLThruHostStackBidirNsock, self).tearDown()
735
736     def show_commands_at_teardown(self):
737         self.logger.debug(self.vapi.cli("show session verbose 2"))
738         self.logger.debug(self.vapi.cli("show app mq"))
739
740     def test_vcl_thru_host_stack_bi_dir_nsock(self):
741         """run VCL thru host stack bi-directional (multiple sockets) test"""
742
743         self.timeout = self.client_bi_dir_nsock_timeout
744         self.thru_host_stack_test(
745             "vcl_test_server",
746             self.server_args,
747             "vcl_test_client",
748             self.client_bi_dir_nsock_test_args,
749         )
750
751
752 class LDPThruHostStackBidirNsock(VCLTestCase):
753     """LDP Thru Host Stack Bidir Nsock"""
754
755     @classmethod
756     def setUpClass(cls):
757         super(LDPThruHostStackBidirNsock, cls).setUpClass()
758
759     @classmethod
760     def tearDownClass(cls):
761         super(LDPThruHostStackBidirNsock, cls).tearDownClass()
762
763     def setUp(self):
764         super(LDPThruHostStackBidirNsock, self).setUp()
765
766         self.thru_host_stack_setup()
767         self.client_bi_dir_nsock_timeout = 20
768         self.client_bi_dir_nsock_test_args = [
769             "-N",
770             "1000",
771             "-B",
772             "-X",
773             # OUCH! Host Stack Bug?
774             # Only fails when running
775             # 'make test TEST_JOBS=auto'
776             # or TEST_JOBS > 1
777             # "-I", "2",
778             self.loop0.local_ip4,
779             self.server_port,
780         ]
781
782     def tearDown(self):
783         self.thru_host_stack_tear_down()
784         super(LDPThruHostStackBidirNsock, self).tearDown()
785
786     def show_commands_at_teardown(self):
787         self.logger.debug(self.vapi.cli("show session verbose 2"))
788         self.logger.debug(self.vapi.cli("show app mq"))
789
790     def test_ldp_thru_host_stack_bi_dir_nsock(self):
791         """run LDP thru host stack bi-directional (multiple sockets) test"""
792
793         self.timeout = self.client_bi_dir_nsock_timeout
794         self.thru_host_stack_test(
795             "sock_test_server",
796             self.server_args,
797             "sock_test_client",
798             self.client_bi_dir_nsock_test_args,
799         )
800
801
802 class LDPThruHostStackNsock(VCLTestCase):
803     """LDP Thru Host Stack Nsock"""
804
805     @classmethod
806     def setUpClass(cls):
807         super(LDPThruHostStackNsock, cls).setUpClass()
808
809     @classmethod
810     def tearDownClass(cls):
811         super(LDPThruHostStackNsock, cls).tearDownClass()
812
813     def setUp(self):
814         super(LDPThruHostStackNsock, self).setUp()
815
816         self.thru_host_stack_setup()
817         if self.vppDebug:
818             self.client_uni_dir_nsock_timeout = 20
819             self.numSockets = "2"
820         else:
821             self.client_uni_dir_nsock_timeout = 20
822             self.numSockets = "5"
823
824         self.client_uni_dir_nsock_test_args = [
825             "-N",
826             "1000",
827             "-U",
828             "-X",
829             "-I",
830             self.numSockets,
831             self.loop0.local_ip4,
832             self.server_port,
833         ]
834
835     def tearDown(self):
836         self.thru_host_stack_tear_down()
837         super(LDPThruHostStackNsock, self).tearDown()
838
839     def test_ldp_thru_host_stack_uni_dir_nsock(self):
840         """run LDP thru host stack uni-directional (multiple sockets) test"""
841
842         self.timeout = self.client_uni_dir_nsock_timeout
843         self.thru_host_stack_test(
844             "sock_test_server",
845             self.server_args,
846             "sock_test_client",
847             self.client_uni_dir_nsock_test_args,
848         )
849
850
851 class VCLThruHostStackNsock(VCLTestCase):
852     """VCL Thru Host Stack Nsock"""
853
854     @classmethod
855     def setUpClass(cls):
856         super(VCLThruHostStackNsock, cls).setUpClass()
857
858     @classmethod
859     def tearDownClass(cls):
860         super(VCLThruHostStackNsock, cls).tearDownClass()
861
862     def setUp(self):
863         super(VCLThruHostStackNsock, self).setUp()
864
865         self.thru_host_stack_setup()
866         if self.vppDebug:
867             self.client_uni_dir_nsock_timeout = 20
868             self.numSockets = "2"
869         else:
870             self.client_uni_dir_nsock_timeout = 20
871             self.numSockets = "5"
872
873         self.client_uni_dir_nsock_test_args = [
874             "-N",
875             "1000",
876             "-U",
877             "-X",
878             "-I",
879             self.numSockets,
880             self.loop0.local_ip4,
881             self.server_port,
882         ]
883
884     def tearDown(self):
885         self.thru_host_stack_tear_down()
886         super(VCLThruHostStackNsock, self).tearDown()
887
888     def test_vcl_thru_host_stack_uni_dir_nsock(self):
889         """run VCL thru host stack uni-directional (multiple sockets) test"""
890
891         self.timeout = self.client_uni_dir_nsock_timeout
892         self.thru_host_stack_test(
893             "vcl_test_server",
894             self.server_args,
895             "vcl_test_client",
896             self.client_uni_dir_nsock_test_args,
897         )
898
899
900 class LDPThruHostStackIperf(VCLTestCase):
901     """LDP Thru Host Stack Iperf"""
902
903     @classmethod
904     def setUpClass(cls):
905         super(LDPThruHostStackIperf, cls).setUpClass()
906
907     @classmethod
908     def tearDownClass(cls):
909         super(LDPThruHostStackIperf, cls).tearDownClass()
910
911     def setUp(self):
912         super(LDPThruHostStackIperf, self).setUp()
913
914         self.thru_host_stack_setup()
915         self.client_iperf3_timeout = 20
916         self.client_iperf3_args = ["-4", "-t 2", "-c", self.loop0.local_ip4]
917         self.server_iperf3_args = ["-4", "-s"]
918
919     def tearDown(self):
920         self.thru_host_stack_tear_down()
921         super(LDPThruHostStackIperf, self).tearDown()
922
923     def show_commands_at_teardown(self):
924         self.logger.debug(self.vapi.cli("show session verbose 2"))
925         self.logger.debug(self.vapi.cli("show app mq"))
926
927     @unittest.skipUnless(_have_iperf3, "'%s' not found, Skipping.")
928     def test_ldp_thru_host_stack_iperf3(self):
929         """run LDP thru host stack iperf3 test"""
930
931         self.timeout = self.client_iperf3_timeout
932         self.thru_host_stack_test(
933             iperf3, self.server_iperf3_args, iperf3, self.client_iperf3_args
934         )
935
936     @unittest.skipUnless(_have_iperf3, "'%s' not found, Skipping.")
937     def test_ldp_thru_host_stack_iperf3_mss(self):
938         """run LDP thru host stack iperf3 test with mss option"""
939
940         self.timeout = self.client_iperf3_timeout
941         self.client_iperf3_args.append("-M 1000")
942         self.thru_host_stack_test(
943             iperf3, self.server_iperf3_args, iperf3, self.client_iperf3_args
944         )
945
946
947 class LDPThruHostStackIperfUdp(VCLTestCase):
948     """LDP Thru Host Stack Iperf UDP"""
949
950     @classmethod
951     def setUpClass(cls):
952         super(LDPThruHostStackIperfUdp, cls).setUpClass()
953
954     @classmethod
955     def tearDownClass(cls):
956         super(LDPThruHostStackIperfUdp, cls).tearDownClass()
957
958     def setUp(self):
959         super(LDPThruHostStackIperfUdp, self).setUp()
960
961         self.thru_host_stack_setup()
962         self.client_iperf3_timeout = 20
963         self.client_iperf3_args = [
964             "-4",
965             "-t 2",
966             "-u",
967             "-l 1400",
968             "-c",
969             self.loop0.local_ip4,
970         ]
971         self.server_iperf3_args = ["-4", "-s"]
972
973     def tearDown(self):
974         self.thru_host_stack_tear_down()
975         super(LDPThruHostStackIperfUdp, self).tearDown()
976
977     def show_commands_at_teardown(self):
978         self.logger.debug(self.vapi.cli("show session verbose 2"))
979         self.logger.debug(self.vapi.cli("show app mq"))
980
981     @unittest.skipUnless(_have_iperf3, "'%s' not found, Skipping.")
982     def test_ldp_thru_host_stack_iperf3_udp(self):
983         """run LDP thru host stack iperf3 UDP test"""
984
985         self.timeout = self.client_iperf3_timeout
986         self.thru_host_stack_test(
987             iperf3, self.server_iperf3_args, iperf3, self.client_iperf3_args
988         )
989
990
991 class LDPIpv6CutThruTestCase(VCLTestCase):
992     """LDP IPv6 Cut Thru Tests"""
993
994     @classmethod
995     def setUpClass(cls):
996         super(LDPIpv6CutThruTestCase, cls).setUpClass()
997
998     @classmethod
999     def tearDownClass(cls):
1000         super(LDPIpv6CutThruTestCase, cls).tearDownClass()
1001
1002     def show_commands_at_teardown(self):
1003         self.logger.debug(self.vapi.cli("show session verbose 2"))
1004         self.logger.debug(self.vapi.cli("show app mq"))
1005
1006     def setUp(self):
1007         super(LDPIpv6CutThruTestCase, self).setUp()
1008
1009         self.cut_thru_setup()
1010         self.client_iperf3_timeout = 20
1011         self.client_uni_dir_nsock_timeout = 20
1012         self.client_bi_dir_nsock_timeout = 20
1013         self.client_ipv6_echo_test_args = [
1014             "-6",
1015             "-E",
1016             self.echo_phrase,
1017             "-X",
1018             self.server_ipv6_addr,
1019             self.server_port,
1020         ]
1021         self.client_ipv6_iperf3_args = ["-6", "-t 2", "-c", self.server_ipv6_addr]
1022         self.server_ipv6_iperf3_args = ["-6", "-s"]
1023         self.client_ipv6_uni_dir_nsock_test_args = [
1024             "-N",
1025             "1000",
1026             "-U",
1027             "-X",
1028             "-6",
1029             "-I",
1030             "2",
1031             self.server_ipv6_addr,
1032             self.server_port,
1033         ]
1034         self.client_ipv6_bi_dir_nsock_test_args = [
1035             "-N",
1036             "1000",
1037             "-B",
1038             "-X",
1039             "-6",
1040             "-I",
1041             "2",
1042             self.server_ipv6_addr,
1043             self.server_port,
1044         ]
1045
1046     def tearDown(self):
1047         super(LDPIpv6CutThruTestCase, self).tearDown()
1048         self.cut_thru_tear_down()
1049
1050     @unittest.skipUnless(config.extended, "part of extended tests")
1051     def test_ldp_ipv6_cut_thru_echo(self):
1052         """run LDP IPv6 cut thru echo test"""
1053
1054         self.cut_thru_test(
1055             "sock_test_server",
1056             self.server_ipv6_args,
1057             "sock_test_client",
1058             self.client_ipv6_echo_test_args,
1059         )
1060
1061     @unittest.skipUnless(_have_iperf3, "'%s' not found, Skipping.")
1062     def test_ldp_ipv6_cut_thru_iperf3(self):
1063         """run LDP IPv6 cut thru iperf3 test"""
1064
1065         self.timeout = self.client_iperf3_timeout
1066         self.cut_thru_test(
1067             iperf3, self.server_ipv6_iperf3_args, iperf3, self.client_ipv6_iperf3_args
1068         )
1069
1070     @unittest.skipUnless(config.extended, "part of extended tests")
1071     def test_ldp_ipv6_cut_thru_uni_dir_nsock(self):
1072         """run LDP IPv6 cut thru uni-directional (multiple sockets) test"""
1073
1074         self.timeout = self.client_uni_dir_nsock_timeout
1075         self.cut_thru_test(
1076             "sock_test_server",
1077             self.server_ipv6_args,
1078             "sock_test_client",
1079             self.client_ipv6_uni_dir_nsock_test_args,
1080         )
1081
1082     @unittest.skipUnless(config.extended, "part of extended tests")
1083     @unittest.skip("sock test apps need to be improved")
1084     def test_ldp_ipv6_cut_thru_bi_dir_nsock(self):
1085         """run LDP IPv6 cut thru bi-directional (multiple sockets) test"""
1086
1087         self.timeout = self.client_bi_dir_nsock_timeout
1088         self.cut_thru_test(
1089             "sock_test_server",
1090             self.server_ipv6_args,
1091             "sock_test_client",
1092             self.client_ipv6_bi_dir_nsock_test_args,
1093         )
1094
1095
1096 class VCLIpv6CutThruTestCase(VCLTestCase):
1097     """VCL IPv6 Cut Thru Tests"""
1098
1099     @classmethod
1100     def setUpClass(cls):
1101         super(VCLIpv6CutThruTestCase, cls).setUpClass()
1102
1103     @classmethod
1104     def tearDownClass(cls):
1105         super(VCLIpv6CutThruTestCase, cls).tearDownClass()
1106
1107     def show_commands_at_teardown(self):
1108         self.logger.debug(self.vapi.cli("show session verbose 2"))
1109         self.logger.debug(self.vapi.cli("show app mq"))
1110
1111     def setUp(self):
1112         super(VCLIpv6CutThruTestCase, self).setUp()
1113
1114         self.cut_thru_setup()
1115         self.client_uni_dir_nsock_timeout = 20
1116         self.client_bi_dir_nsock_timeout = 20
1117         self.client_ipv6_echo_test_args = [
1118             "-6",
1119             "-E",
1120             self.echo_phrase,
1121             "-X",
1122             self.server_ipv6_addr,
1123             self.server_port,
1124         ]
1125         self.client_ipv6_uni_dir_nsock_test_args = [
1126             "-N",
1127             "1000",
1128             "-U",
1129             "-X",
1130             "-6",
1131             "-I",
1132             "2",
1133             self.server_ipv6_addr,
1134             self.server_port,
1135         ]
1136         self.client_ipv6_bi_dir_nsock_test_args = [
1137             "-N",
1138             "1000",
1139             "-B",
1140             "-X",
1141             "-6",
1142             "-I",
1143             "2",
1144             self.server_ipv6_addr,
1145             self.server_port,
1146         ]
1147
1148     def tearDown(self):
1149         super(VCLIpv6CutThruTestCase, self).tearDown()
1150         self.cut_thru_tear_down()
1151
1152     def show_commands_at_teardown(self):
1153         self.logger.debug(self.vapi.cli("show session verbose 2"))
1154         self.logger.debug(self.vapi.cli("show app mq"))
1155
1156     def test_vcl_ipv6_cut_thru_echo(self):
1157         """run VCL IPv6 cut thru echo test"""
1158
1159         self.cut_thru_test(
1160             "vcl_test_server",
1161             self.server_ipv6_args,
1162             "vcl_test_client",
1163             self.client_ipv6_echo_test_args,
1164         )
1165
1166     @unittest.skipUnless(config.extended, "part of extended tests")
1167     def test_vcl_ipv6_cut_thru_uni_dir_nsock(self):
1168         """run VCL IPv6 cut thru uni-directional (multiple sockets) test"""
1169
1170         self.timeout = self.client_uni_dir_nsock_timeout
1171         self.cut_thru_test(
1172             "vcl_test_server",
1173             self.server_ipv6_args,
1174             "vcl_test_client",
1175             self.client_ipv6_uni_dir_nsock_test_args,
1176         )
1177
1178     @unittest.skipUnless(config.extended, "part of extended tests")
1179     def test_vcl_ipv6_cut_thru_bi_dir_nsock(self):
1180         """run VCL IPv6 cut thru bi-directional (multiple sockets) test"""
1181
1182         self.timeout = self.client_bi_dir_nsock_timeout
1183         self.cut_thru_test(
1184             "vcl_test_server",
1185             self.server_ipv6_args,
1186             "vcl_test_client",
1187             self.client_ipv6_bi_dir_nsock_test_args,
1188         )
1189
1190
1191 class VCLIpv6ThruHostStackEcho(VCLTestCase):
1192     """VCL IPv6 Thru Host Stack Echo"""
1193
1194     @classmethod
1195     def setUpClass(cls):
1196         super(VCLIpv6ThruHostStackEcho, cls).setUpClass()
1197
1198     @classmethod
1199     def tearDownClass(cls):
1200         super(VCLIpv6ThruHostStackEcho, cls).tearDownClass()
1201
1202     def setUp(self):
1203         super(VCLIpv6ThruHostStackEcho, self).setUp()
1204
1205         self.thru_host_stack_ipv6_setup()
1206         self.client_ipv6_echo_test_args = [
1207             "-6",
1208             "-E",
1209             self.echo_phrase,
1210             "-X",
1211             self.loop0.local_ip6,
1212             self.server_port,
1213         ]
1214
1215     def tearDown(self):
1216         self.thru_host_stack_ipv6_tear_down()
1217         super(VCLIpv6ThruHostStackEcho, self).tearDown()
1218
1219     def test_vcl_ipv6_thru_host_stack_echo(self):
1220         """run VCL IPv6 thru host stack echo test"""
1221
1222         self.thru_host_stack_test(
1223             "vcl_test_server",
1224             self.server_ipv6_args,
1225             "vcl_test_client",
1226             self.client_ipv6_echo_test_args,
1227         )
1228
1229
1230 if __name__ == "__main__":
1231     unittest.main(testRunner=VppTestRunner)