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