tests: make tests less make dependent
[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__(self, appname, executable_args, logger, env=None,
36                  role=None, *args, **kwargs):
37         self.role = role
38         vcl_ldpreload_glob = f"{config.vpp_install_dir}/**/{self.libname}"
39         vcl_ldpreload_so = glob.glob(vcl_ldpreload_glob, recursive=True)
40
41         if len(vcl_ldpreload_so) < 1:
42             raise LibraryNotFound("cannot locate library: {}".format(
43                 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,
59                                            *args, **kwargs)
60
61
62 class VCLTestCase(VppTestCase):
63     """ VCL Test Class """
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(server_app, server_args,
130                                      self.logger, self.vcl_app_env, "server")
131         worker_server.start()
132         self.sleep(self.pre_test_sleep)
133
134         self.update_vcl_app_env("", "", self.sapi_client_sock)
135         worker_client = VCLAppWorker(client_app, client_args,
136                                      self.logger, self.vcl_app_env, "client")
137         worker_client.start()
138         worker_client.join(self.timeout)
139         try:
140             self.validateResults(worker_client, worker_server, self.timeout)
141         except Exception as error:
142             self.fail("Failed with %s" % error)
143         self.sleep(self.post_test_sleep)
144
145     def thru_host_stack_setup(self):
146         self.vapi.session_enable_disable(is_enable=1)
147         self.create_loopback_interfaces(2)
148
149         table_id = 1
150
151         for i in self.lo_interfaces:
152             i.admin_up()
153
154             if table_id != 0:
155                 tbl = VppIpTable(self, table_id)
156                 tbl.add_vpp_config()
157
158             i.set_table_ip4(table_id)
159             i.config_ip4()
160             table_id += 1
161
162         # Configure namespaces
163         self.vapi.app_namespace_add_del(namespace_id="1", secret=1234,
164                                         sw_if_index=self.loop0.sw_if_index)
165         self.vapi.app_namespace_add_del(namespace_id="2", secret=5678,
166                                         sw_if_index=self.loop1.sw_if_index)
167
168         # Add inter-table routes
169         ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32,
170                             [VppRoutePath("0.0.0.0",
171                                           0xffffffff,
172                                           nh_table_id=2)], table_id=1)
173         ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32,
174                             [VppRoutePath("0.0.0.0",
175                                           0xffffffff,
176                                           nh_table_id=1)], table_id=2)
177         ip_t01.add_vpp_config()
178         ip_t10.add_vpp_config()
179         self.logger.debug(self.vapi.cli("show ip fib"))
180
181     def thru_host_stack_tear_down(self):
182         for i in self.lo_interfaces:
183             i.unconfig_ip4()
184             i.set_table_ip4(0)
185             i.admin_down()
186
187     def thru_host_stack_ipv6_setup(self):
188         self.vapi.session_enable_disable(is_enable=1)
189         self.create_loopback_interfaces(2)
190
191         table_id = 1
192
193         for i in self.lo_interfaces:
194             i.admin_up()
195
196             tbl = VppIpTable(self, table_id, is_ip6=1)
197             tbl.add_vpp_config()
198
199             i.set_table_ip6(table_id)
200             i.config_ip6()
201             table_id += 1
202
203         # Configure namespaces
204         self.vapi.app_namespace_add_del(namespace_id="1", secret=1234,
205                                         sw_if_index=self.loop0.sw_if_index)
206         self.vapi.app_namespace_add_del(namespace_id="2", secret=5678,
207                                         sw_if_index=self.loop1.sw_if_index)
208
209         # Add inter-table routes
210         ip_t01 = VppIpRoute(self, self.loop1.local_ip6, 128,
211                             [VppRoutePath("::0", 0xffffffff,
212                                           nh_table_id=2)],
213                             table_id=1)
214         ip_t10 = VppIpRoute(self, self.loop0.local_ip6, 128,
215                             [VppRoutePath("::0", 0xffffffff,
216                                           nh_table_id=1)],
217                             table_id=2)
218         ip_t01.add_vpp_config()
219         ip_t10.add_vpp_config()
220         self.logger.debug(self.vapi.cli("show interface addr"))
221         self.logger.debug(self.vapi.cli("show ip6 fib"))
222
223     def thru_host_stack_ipv6_tear_down(self):
224         for i in self.lo_interfaces:
225             i.unconfig_ip6()
226             i.set_table_ip6(0)
227             i.admin_down()
228
229         self.vapi.session_enable_disable(is_enable=0)
230
231     @unittest.skipUnless(_have_iperf3, "'%s' not found, Skipping.")
232     def thru_host_stack_test(self, server_app, server_args,
233                              client_app, client_args):
234         self.vcl_app_env = {'VCL_APP_SCOPE_GLOBAL': "true"}
235
236         self.update_vcl_app_env("1", "1234", self.sapi_server_sock)
237         worker_server = VCLAppWorker(server_app, server_args,
238                                      self.logger, self.vcl_app_env, "server")
239         worker_server.start()
240         self.sleep(self.pre_test_sleep)
241
242         self.update_vcl_app_env("2", "5678", self.sapi_client_sock)
243         worker_client = VCLAppWorker(client_app, client_args,
244                                      self.logger, self.vcl_app_env, "client")
245         worker_client.start()
246         worker_client.join(self.timeout)
247
248         try:
249             self.validateResults(worker_client, worker_server, self.timeout)
250         except Exception as error:
251             self.fail("Failed with %s" % error)
252         self.sleep(self.post_test_sleep)
253
254     def validateResults(self, worker_client, worker_server, timeout):
255         if worker_server.process is None:
256             raise RuntimeError('worker_server is not running.')
257         if os.path.isdir('/proc/{}'.format(worker_server.process.pid)):
258             self.logger.info("Killing server worker process (pid %d)" %
259                              worker_server.process.pid)
260             os.killpg(os.getpgid(worker_server.process.pid), signal.SIGTERM)
261             worker_server.join()
262         self.logger.info("Client worker result is `%s'" % worker_client.result)
263         error = False
264         if worker_client.result is None:
265             try:
266                 error = True
267                 self.logger.error(
268                     "Timeout: %ss! Killing client worker process (pid %d)" %
269                     (timeout, worker_client.process.pid))
270                 os.killpg(os.getpgid(worker_client.process.pid),
271                           signal.SIGKILL)
272                 worker_client.join()
273             except OSError:
274                 self.logger.debug(
275                     "Couldn't kill client worker process")
276                 raise
277         if error:
278             raise RuntimeError(
279                 "Timeout! Client worker did not finish in %ss" % timeout)
280         self.assert_equal(worker_client.result, 0, "Binary test return code")
281
282
283 class LDPCutThruTestCase(VCLTestCase):
284     """ LDP Cut Thru Tests """
285
286     @classmethod
287     def setUpClass(cls):
288         cls.session_startup = ["poll-main", "use-app-socket-api"]
289         super(LDPCutThruTestCase, cls).setUpClass()
290
291     @classmethod
292     def tearDownClass(cls):
293         super(LDPCutThruTestCase, cls).tearDownClass()
294
295     def setUp(self):
296         super(LDPCutThruTestCase, self).setUp()
297
298         self.cut_thru_setup()
299         self.client_echo_test_args = ["-E", self.echo_phrase, "-X",
300                                       self.server_addr, self.server_port]
301         self.client_iperf3_timeout = 20
302         self.client_iperf3_args = ["-4", "-t 2", "-c", self.server_addr]
303         self.server_iperf3_args = ["-4", "-s"]
304         self.client_uni_dir_nsock_timeout = 20
305         self.client_uni_dir_nsock_test_args = ["-N", "1000", "-U", "-X",
306                                                "-I", "2",
307                                                self.server_addr,
308                                                self.server_port]
309         self.client_bi_dir_nsock_timeout = 20
310         self.client_bi_dir_nsock_test_args = ["-N", "1000", "-B", "-X",
311                                               "-I", "2",
312                                               self.server_addr,
313                                               self.server_port]
314         self.sapi_client_sock = "default"
315         self.sapi_server_sock = "default"
316
317     def tearDown(self):
318         super(LDPCutThruTestCase, self).tearDown()
319         self.cut_thru_tear_down()
320
321     def show_commands_at_teardown(self):
322         self.logger.debug(self.vapi.cli("show session verbose 2"))
323         self.logger.debug(self.vapi.cli("show app mq"))
324
325     @unittest.skipUnless(config.extended, "part of extended tests")
326     def test_ldp_cut_thru_echo(self):
327         """ run LDP cut thru echo test """
328
329         self.cut_thru_test("sock_test_server", self.server_args,
330                            "sock_test_client", self.client_echo_test_args)
331
332     def test_ldp_cut_thru_iperf3(self):
333         """ run LDP cut thru iperf3 test """
334
335         self.timeout = self.client_iperf3_timeout
336         self.cut_thru_test(iperf3, self.server_iperf3_args,
337                            iperf3, self.client_iperf3_args)
338
339     @unittest.skipUnless(config.extended, "part of extended tests")
340     def test_ldp_cut_thru_uni_dir_nsock(self):
341         """ run LDP cut thru uni-directional (multiple sockets) test """
342
343         self.timeout = self.client_uni_dir_nsock_timeout
344         self.cut_thru_test("sock_test_server", self.server_args,
345                            "sock_test_client",
346                            self.client_uni_dir_nsock_test_args)
347
348     @unittest.skipUnless(config.extended, "part of extended tests")
349     @unittest.skip("sock test apps need to be improved")
350     def test_ldp_cut_thru_bi_dir_nsock(self):
351         """ run LDP cut thru bi-directional (multiple sockets) test """
352
353         self.timeout = self.client_bi_dir_nsock_timeout
354         self.cut_thru_test("sock_test_server", self.server_args,
355                            "sock_test_client",
356                            self.client_bi_dir_nsock_test_args)
357
358
359 class VCLCutThruTestCase(VCLTestCase):
360     """ VCL Cut Thru Tests """
361
362     @classmethod
363     def setUpClass(cls):
364         super(VCLCutThruTestCase, cls).setUpClass()
365
366     @classmethod
367     def tearDownClass(cls):
368         super(VCLCutThruTestCase, cls).tearDownClass()
369
370     def setUp(self):
371         super(VCLCutThruTestCase, self).setUp()
372
373         self.cut_thru_setup()
374         self.client_echo_test_args = ["-E", self.echo_phrase, "-X",
375                                       self.server_addr, self.server_port]
376
377         self.client_uni_dir_nsock_timeout = 20
378         self.client_uni_dir_nsock_test_args = ["-N", "1000", "-U", "-X",
379                                                "-I", "2",
380                                                self.server_addr,
381                                                self.server_port]
382         self.client_bi_dir_nsock_timeout = 20
383         self.client_bi_dir_nsock_test_args = ["-N", "1000", "-B", "-X",
384                                               "-I", "2",
385                                               self.server_addr,
386                                               self.server_port]
387
388     def tearDown(self):
389         super(VCLCutThruTestCase, self).tearDown()
390
391     def show_commands_at_teardown(self):
392         self.logger.debug(self.vapi.cli("show session verbose 2"))
393         self.logger.debug(self.vapi.cli("show app mq"))
394
395     def test_vcl_cut_thru_echo(self):
396         """ run VCL cut thru echo test """
397
398         self.cut_thru_test("vcl_test_server", self.server_args,
399                            "vcl_test_client", self.client_echo_test_args)
400
401     def test_vcl_cut_thru_uni_dir_nsock(self):
402         """ run VCL cut thru uni-directional (multiple sockets) test """
403
404         self.timeout = self.client_uni_dir_nsock_timeout
405         self.cut_thru_test("vcl_test_server", self.server_args,
406                            "vcl_test_client",
407                            self.client_uni_dir_nsock_test_args)
408
409     def test_vcl_cut_thru_bi_dir_nsock(self):
410         """ run VCL cut thru bi-directional (multiple sockets) test """
411
412         self.timeout = self.client_bi_dir_nsock_timeout
413         self.cut_thru_test("vcl_test_server", self.server_args,
414                            "vcl_test_client",
415                            self.client_bi_dir_nsock_test_args)
416
417
418 class VCLThruHostStackEcho(VCLTestCase):
419     """ VCL Thru Host Stack Echo """
420
421     @classmethod
422     def setUpClass(cls):
423         super(VCLThruHostStackEcho, cls).setUpClass()
424
425     @classmethod
426     def tearDownClass(cls):
427         super(VCLThruHostStackEcho, cls).tearDownClass()
428
429     def setUp(self):
430         super(VCLThruHostStackEcho, self).setUp()
431
432         self.thru_host_stack_setup()
433         self.client_bi_dir_nsock_timeout = 20
434         self.client_bi_dir_nsock_test_args = ["-N", "1000", "-B", "-X",
435                                               "-I", "2",
436                                               self.loop0.local_ip4,
437                                               self.server_port]
438         self.client_echo_test_args = ["-E", self.echo_phrase, "-X",
439                                       self.loop0.local_ip4,
440                                       self.server_port]
441
442     def tearDown(self):
443         self.thru_host_stack_tear_down()
444         super(VCLThruHostStackEcho, self).tearDown()
445
446     def test_vcl_thru_host_stack_echo(self):
447         """ run VCL IPv4 thru host stack echo test """
448
449         self.thru_host_stack_test("vcl_test_server",
450                                   self.server_args,
451                                   "vcl_test_client",
452                                   self.client_echo_test_args)
453
454     def show_commands_at_teardown(self):
455         self.logger.debug(self.vapi.cli("show app server"))
456         self.logger.debug(self.vapi.cli("show session verbose"))
457         self.logger.debug(self.vapi.cli("show app mq"))
458
459
460 class VCLThruHostStackTLS(VCLTestCase):
461     """ VCL Thru Host Stack TLS """
462
463     @classmethod
464     def setUpClass(cls):
465         cls.session_startup = ["poll-main", "use-app-socket-api"]
466         super(VCLThruHostStackTLS, cls).setUpClass()
467
468     @classmethod
469     def tearDownClass(cls):
470         super(VCLThruHostStackTLS, cls).tearDownClass()
471
472     def setUp(self):
473         super(VCLThruHostStackTLS, self).setUp()
474
475         self.thru_host_stack_setup()
476         self.client_uni_dir_tls_timeout = 20
477         self.server_tls_args = ["-L", self.server_port]
478         self.client_uni_dir_tls_test_args = ["-N", "1000", "-U", "-X", "-L",
479                                              self.loop0.local_ip4,
480                                              self.server_port]
481         self.sapi_server_sock = "1"
482         self.sapi_client_sock = "2"
483
484     def test_vcl_thru_host_stack_tls_uni_dir(self):
485         """ run VCL thru host stack uni-directional TLS test """
486
487         self.timeout = self.client_uni_dir_tls_timeout
488         self.thru_host_stack_test("vcl_test_server", self.server_tls_args,
489                                   "vcl_test_client",
490                                   self.client_uni_dir_tls_test_args)
491
492     def tearDown(self):
493         self.thru_host_stack_tear_down()
494         super(VCLThruHostStackTLS, self).tearDown()
495
496     def show_commands_at_teardown(self):
497         self.logger.debug(self.vapi.cli("show app server"))
498         self.logger.debug(self.vapi.cli("show session verbose 2"))
499         self.logger.debug(self.vapi.cli("show app mq"))
500
501
502 class VCLThruHostStackDTLS(VCLTestCase):
503     """ VCL Thru Host Stack DTLS """
504
505     @classmethod
506     def setUpClass(cls):
507         super(VCLThruHostStackDTLS, cls).setUpClass()
508
509     @classmethod
510     def tearDownClass(cls):
511         super(VCLThruHostStackDTLS, cls).tearDownClass()
512
513     def setUp(self):
514         super(VCLThruHostStackDTLS, self).setUp()
515
516         self.thru_host_stack_setup()
517         self.client_uni_dir_dtls_timeout = 20
518         self.server_dtls_args = ["-p", "dtls", self.server_port]
519         self.client_uni_dir_dtls_test_args = ["-N", "1000", "-U", "-X",
520                                               "-p", "dtls", "-T 1400",
521                                               self.loop0.local_ip4,
522                                               self.server_port]
523
524     def test_vcl_thru_host_stack_dtls_uni_dir(self):
525         """ run VCL thru host stack uni-directional DTLS test """
526
527         self.timeout = self.client_uni_dir_dtls_timeout
528         self.thru_host_stack_test("vcl_test_server", self.server_dtls_args,
529                                   "vcl_test_client",
530                                   self.client_uni_dir_dtls_test_args)
531
532     def tearDown(self):
533         self.thru_host_stack_tear_down()
534         super(VCLThruHostStackDTLS, self).tearDown()
535
536     def show_commands_at_teardown(self):
537         self.logger.debug(self.vapi.cli("show app server"))
538         self.logger.debug(self.vapi.cli("show session verbose 2"))
539         self.logger.debug(self.vapi.cli("show app mq"))
540
541
542 class VCLThruHostStackQUIC(VCLTestCase):
543     """ VCL Thru Host Stack QUIC """
544
545     @classmethod
546     def setUpClass(cls):
547         cls.extra_vpp_plugin_config.append("plugin quic_plugin.so { enable }")
548         super(VCLThruHostStackQUIC, cls).setUpClass()
549
550     @classmethod
551     def tearDownClass(cls):
552         super(VCLThruHostStackQUIC, cls).tearDownClass()
553
554     def setUp(self):
555         super(VCLThruHostStackQUIC, self).setUp()
556
557         self.thru_host_stack_setup()
558         self.client_uni_dir_quic_timeout = 20
559         self.server_quic_args = ["-p", "quic", self.server_port]
560         self.client_uni_dir_quic_test_args = ["-N", "1000", "-U", "-X",
561                                               "-p", "quic",
562                                               self.loop0.local_ip4,
563                                               self.server_port]
564
565     @unittest.skipUnless(config.extended, "part of extended tests")
566     def test_vcl_thru_host_stack_quic_uni_dir(self):
567         """ run VCL thru host stack uni-directional QUIC test """
568
569         self.timeout = self.client_uni_dir_quic_timeout
570         self.thru_host_stack_test("vcl_test_server", self.server_quic_args,
571                                   "vcl_test_client",
572                                   self.client_uni_dir_quic_test_args)
573
574     def tearDown(self):
575         self.thru_host_stack_tear_down()
576         super(VCLThruHostStackQUIC, self).tearDown()
577
578     def show_commands_at_teardown(self):
579         self.logger.debug(self.vapi.cli("show app server"))
580         self.logger.debug(self.vapi.cli("show session verbose 2"))
581         self.logger.debug(self.vapi.cli("show app mq"))
582
583
584 class VCLThruHostStackBidirNsock(VCLTestCase):
585     """ VCL Thru Host Stack Bidir Nsock """
586
587     @classmethod
588     def setUpClass(cls):
589         super(VCLThruHostStackBidirNsock, cls).setUpClass()
590
591     @classmethod
592     def tearDownClass(cls):
593         super(VCLThruHostStackBidirNsock, cls).tearDownClass()
594
595     def setUp(self):
596         super(VCLThruHostStackBidirNsock, self).setUp()
597
598         self.thru_host_stack_setup()
599         self.client_bi_dir_nsock_timeout = 20
600         self.client_bi_dir_nsock_test_args = ["-N", "1000", "-B", "-X",
601                                               "-I", "2",
602                                               self.loop0.local_ip4,
603                                               self.server_port]
604         self.client_echo_test_args = ["-E", self.echo_phrase, "-X",
605                                       self.loop0.local_ip4,
606                                       self.server_port]
607
608     def tearDown(self):
609         self.thru_host_stack_tear_down()
610         super(VCLThruHostStackBidirNsock, self).tearDown()
611
612     def show_commands_at_teardown(self):
613         self.logger.debug(self.vapi.cli("show session verbose 2"))
614         self.logger.debug(self.vapi.cli("show app mq"))
615
616     def test_vcl_thru_host_stack_bi_dir_nsock(self):
617         """ run VCL thru host stack bi-directional (multiple sockets) test """
618
619         self.timeout = self.client_bi_dir_nsock_timeout
620         self.thru_host_stack_test("vcl_test_server", self.server_args,
621                                   "vcl_test_client",
622                                   self.client_bi_dir_nsock_test_args)
623
624
625 class LDPThruHostStackBidirNsock(VCLTestCase):
626     """ LDP Thru Host Stack Bidir Nsock """
627
628     @classmethod
629     def setUpClass(cls):
630         super(LDPThruHostStackBidirNsock, cls).setUpClass()
631
632     @classmethod
633     def tearDownClass(cls):
634         super(LDPThruHostStackBidirNsock, cls).tearDownClass()
635
636     def setUp(self):
637         super(LDPThruHostStackBidirNsock, self).setUp()
638
639         self.thru_host_stack_setup()
640         self.client_bi_dir_nsock_timeout = 20
641         self.client_bi_dir_nsock_test_args = ["-N", "1000", "-B", "-X",
642                                               # OUCH! Host Stack Bug?
643                                               # Only fails when running
644                                               # 'make test TEST_JOBS=auto'
645                                               # or TEST_JOBS > 1
646                                               # "-I", "2",
647                                               self.loop0.local_ip4,
648                                               self.server_port]
649
650     def tearDown(self):
651         self.thru_host_stack_tear_down()
652         super(LDPThruHostStackBidirNsock, self).tearDown()
653
654     def show_commands_at_teardown(self):
655         self.logger.debug(self.vapi.cli("show session verbose 2"))
656         self.logger.debug(self.vapi.cli("show app mq"))
657
658     def test_ldp_thru_host_stack_bi_dir_nsock(self):
659         """ run LDP thru host stack bi-directional (multiple sockets) test """
660
661         self.timeout = self.client_bi_dir_nsock_timeout
662         self.thru_host_stack_test("sock_test_server", self.server_args,
663                                   "sock_test_client",
664                                   self.client_bi_dir_nsock_test_args)
665
666
667 class LDPThruHostStackNsock(VCLTestCase):
668     """ LDP Thru Host Stack Nsock """
669
670     @classmethod
671     def setUpClass(cls):
672         super(LDPThruHostStackNsock, cls).setUpClass()
673
674     @classmethod
675     def tearDownClass(cls):
676         super(LDPThruHostStackNsock, cls).tearDownClass()
677
678     def setUp(self):
679         super(LDPThruHostStackNsock, self).setUp()
680
681         self.thru_host_stack_setup()
682         if self.vppDebug:
683             self.client_uni_dir_nsock_timeout = 20
684             self.numSockets = "2"
685         else:
686             self.client_uni_dir_nsock_timeout = 20
687             self.numSockets = "5"
688
689         self.client_uni_dir_nsock_test_args = ["-N", "1000", "-U", "-X",
690                                                "-I", self.numSockets,
691                                                self.loop0.local_ip4,
692                                                self.server_port]
693
694     def tearDown(self):
695         self.thru_host_stack_tear_down()
696         super(LDPThruHostStackNsock, self).tearDown()
697
698     def test_ldp_thru_host_stack_uni_dir_nsock(self):
699         """ run LDP thru host stack uni-directional (multiple sockets) test """
700
701         self.timeout = self.client_uni_dir_nsock_timeout
702         self.thru_host_stack_test("sock_test_server", self.server_args,
703                                   "sock_test_client",
704                                   self.client_uni_dir_nsock_test_args)
705
706
707 class VCLThruHostStackNsock(VCLTestCase):
708     """ VCL Thru Host Stack Nsock """
709
710     @classmethod
711     def setUpClass(cls):
712         super(VCLThruHostStackNsock, cls).setUpClass()
713
714     @classmethod
715     def tearDownClass(cls):
716         super(VCLThruHostStackNsock, cls).tearDownClass()
717
718     def setUp(self):
719         super(VCLThruHostStackNsock, self).setUp()
720
721         self.thru_host_stack_setup()
722         if self.vppDebug:
723             self.client_uni_dir_nsock_timeout = 20
724             self.numSockets = "2"
725         else:
726             self.client_uni_dir_nsock_timeout = 20
727             self.numSockets = "5"
728
729         self.client_uni_dir_nsock_test_args = ["-N", "1000", "-U", "-X",
730                                                "-I", self.numSockets,
731                                                self.loop0.local_ip4,
732                                                self.server_port]
733
734     def tearDown(self):
735         self.thru_host_stack_tear_down()
736         super(VCLThruHostStackNsock, self).tearDown()
737
738     def test_vcl_thru_host_stack_uni_dir_nsock(self):
739         """ run VCL thru host stack uni-directional (multiple sockets) test """
740
741         self.timeout = self.client_uni_dir_nsock_timeout
742         self.thru_host_stack_test("vcl_test_server", self.server_args,
743                                   "vcl_test_client",
744                                   self.client_uni_dir_nsock_test_args)
745
746
747 class LDPThruHostStackIperf(VCLTestCase):
748     """ LDP Thru Host Stack Iperf  """
749
750     @classmethod
751     def setUpClass(cls):
752         super(LDPThruHostStackIperf, cls).setUpClass()
753
754     @classmethod
755     def tearDownClass(cls):
756         super(LDPThruHostStackIperf, cls).tearDownClass()
757
758     def setUp(self):
759         super(LDPThruHostStackIperf, self).setUp()
760
761         self.thru_host_stack_setup()
762         self.client_iperf3_timeout = 20
763         self.client_iperf3_args = ["-4", "-t 2", "-c", self.loop0.local_ip4]
764         self.server_iperf3_args = ["-4", "-s"]
765
766     def tearDown(self):
767         self.thru_host_stack_tear_down()
768         super(LDPThruHostStackIperf, self).tearDown()
769
770     def show_commands_at_teardown(self):
771         self.logger.debug(self.vapi.cli("show session verbose 2"))
772         self.logger.debug(self.vapi.cli("show app mq"))
773
774     @unittest.skipUnless(_have_iperf3, "'%s' not found, Skipping.")
775     def test_ldp_thru_host_stack_iperf3(self):
776         """ run LDP thru host stack iperf3 test """
777
778         self.timeout = self.client_iperf3_timeout
779         self.thru_host_stack_test(iperf3, self.server_iperf3_args,
780                                   iperf3, self.client_iperf3_args)
781
782
783 class LDPThruHostStackIperfUdp(VCLTestCase):
784     """ LDP Thru Host Stack Iperf UDP """
785
786     @classmethod
787     def setUpClass(cls):
788         super(LDPThruHostStackIperfUdp, cls).setUpClass()
789
790     @classmethod
791     def tearDownClass(cls):
792         super(LDPThruHostStackIperfUdp, cls).tearDownClass()
793
794     def setUp(self):
795         super(LDPThruHostStackIperfUdp, self).setUp()
796
797         self.thru_host_stack_setup()
798         self.client_iperf3_timeout = 20
799         self.client_iperf3_args = ["-4", "-t 2", "-u", "-l 1400",
800                                    "-c", self.loop0.local_ip4]
801         self.server_iperf3_args = ["-4", "-s"]
802
803     def tearDown(self):
804         self.thru_host_stack_tear_down()
805         super(LDPThruHostStackIperfUdp, self).tearDown()
806
807     def show_commands_at_teardown(self):
808         self.logger.debug(self.vapi.cli("show session verbose 2"))
809         self.logger.debug(self.vapi.cli("show app mq"))
810
811     @unittest.skipUnless(_have_iperf3, "'%s' not found, Skipping.")
812     def test_ldp_thru_host_stack_iperf3_udp(self):
813         """ run LDP thru host stack iperf3 UDP test """
814
815         self.timeout = self.client_iperf3_timeout
816         self.thru_host_stack_test(iperf3, self.server_iperf3_args,
817                                   iperf3, self.client_iperf3_args)
818
819
820 class LDPIpv6CutThruTestCase(VCLTestCase):
821     """ LDP IPv6 Cut Thru Tests """
822
823     @classmethod
824     def setUpClass(cls):
825         super(LDPIpv6CutThruTestCase, cls).setUpClass()
826
827     @classmethod
828     def tearDownClass(cls):
829         super(LDPIpv6CutThruTestCase, cls).tearDownClass()
830
831     def show_commands_at_teardown(self):
832         self.logger.debug(self.vapi.cli("show session verbose 2"))
833         self.logger.debug(self.vapi.cli("show app mq"))
834
835     def setUp(self):
836         super(LDPIpv6CutThruTestCase, self).setUp()
837
838         self.cut_thru_setup()
839         self.client_iperf3_timeout = 20
840         self.client_uni_dir_nsock_timeout = 20
841         self.client_bi_dir_nsock_timeout = 20
842         self.client_ipv6_echo_test_args = ["-6", "-E", self.echo_phrase, "-X",
843                                            self.server_ipv6_addr,
844                                            self.server_port]
845         self.client_ipv6_iperf3_args = ["-6", "-t 2", "-c",
846                                         self.server_ipv6_addr]
847         self.server_ipv6_iperf3_args = ["-6", "-s"]
848         self.client_ipv6_uni_dir_nsock_test_args = ["-N", "1000", "-U", "-X",
849                                                     "-6",
850                                                     "-I", "2",
851                                                     self.server_ipv6_addr,
852                                                     self.server_port]
853         self.client_ipv6_bi_dir_nsock_test_args = ["-N", "1000", "-B", "-X",
854                                                    "-6",
855                                                    "-I", "2",
856                                                    self.server_ipv6_addr,
857                                                    self.server_port]
858
859     def tearDown(self):
860         super(LDPIpv6CutThruTestCase, self).tearDown()
861         self.cut_thru_tear_down()
862
863     @unittest.skipUnless(config.extended, "part of extended tests")
864     def test_ldp_ipv6_cut_thru_echo(self):
865         """ run LDP IPv6 cut thru echo test """
866
867         self.cut_thru_test("sock_test_server",
868                            self.server_ipv6_args,
869                            "sock_test_client",
870                            self.client_ipv6_echo_test_args)
871
872     @unittest.skipUnless(_have_iperf3, "'%s' not found, Skipping.")
873     def test_ldp_ipv6_cut_thru_iperf3(self):
874         """ run LDP IPv6 cut thru iperf3 test """
875
876         self.timeout = self.client_iperf3_timeout
877         self.cut_thru_test(iperf3, self.server_ipv6_iperf3_args,
878                            iperf3, self.client_ipv6_iperf3_args)
879
880     @unittest.skipUnless(config.extended, "part of extended tests")
881     def test_ldp_ipv6_cut_thru_uni_dir_nsock(self):
882         """ run LDP IPv6 cut thru uni-directional (multiple sockets) test """
883
884         self.timeout = self.client_uni_dir_nsock_timeout
885         self.cut_thru_test("sock_test_server", self.server_ipv6_args,
886                            "sock_test_client",
887                            self.client_ipv6_uni_dir_nsock_test_args)
888
889     @unittest.skipUnless(config.extended, "part of extended tests")
890     @unittest.skip("sock test apps need to be improved")
891     def test_ldp_ipv6_cut_thru_bi_dir_nsock(self):
892         """ run LDP IPv6 cut thru bi-directional (multiple sockets) test """
893
894         self.timeout = self.client_bi_dir_nsock_timeout
895         self.cut_thru_test("sock_test_server", self.server_ipv6_args,
896                            "sock_test_client",
897                            self.client_ipv6_bi_dir_nsock_test_args)
898
899
900 class VCLIpv6CutThruTestCase(VCLTestCase):
901     """ VCL IPv6 Cut Thru Tests """
902
903     @classmethod
904     def setUpClass(cls):
905         super(VCLIpv6CutThruTestCase, cls).setUpClass()
906
907     @classmethod
908     def tearDownClass(cls):
909         super(VCLIpv6CutThruTestCase, cls).tearDownClass()
910
911     def show_commands_at_teardown(self):
912         self.logger.debug(self.vapi.cli("show session verbose 2"))
913         self.logger.debug(self.vapi.cli("show app mq"))
914
915     def setUp(self):
916         super(VCLIpv6CutThruTestCase, self).setUp()
917
918         self.cut_thru_setup()
919         self.client_uni_dir_nsock_timeout = 20
920         self.client_bi_dir_nsock_timeout = 20
921         self.client_ipv6_echo_test_args = ["-6", "-E", self.echo_phrase, "-X",
922                                            self.server_ipv6_addr,
923                                            self.server_port]
924         self.client_ipv6_uni_dir_nsock_test_args = ["-N", "1000", "-U", "-X",
925                                                     "-6",
926                                                     "-I", "2",
927                                                     self.server_ipv6_addr,
928                                                     self.server_port]
929         self.client_ipv6_bi_dir_nsock_test_args = ["-N", "1000", "-B", "-X",
930                                                    "-6",
931                                                    "-I", "2",
932                                                    self.server_ipv6_addr,
933                                                    self.server_port]
934
935     def tearDown(self):
936         super(VCLIpv6CutThruTestCase, self).tearDown()
937         self.cut_thru_tear_down()
938
939     def show_commands_at_teardown(self):
940         self.logger.debug(self.vapi.cli("show session verbose 2"))
941         self.logger.debug(self.vapi.cli("show app mq"))
942
943     def test_vcl_ipv6_cut_thru_echo(self):
944         """ run VCL IPv6 cut thru echo test """
945
946         self.cut_thru_test("vcl_test_server",
947                            self.server_ipv6_args,
948                            "vcl_test_client",
949                            self.client_ipv6_echo_test_args)
950
951     @unittest.skipUnless(config.extended, "part of extended tests")
952     def test_vcl_ipv6_cut_thru_uni_dir_nsock(self):
953         """ run VCL IPv6 cut thru uni-directional (multiple sockets) test """
954
955         self.timeout = self.client_uni_dir_nsock_timeout
956         self.cut_thru_test("vcl_test_server", self.server_ipv6_args,
957                            "vcl_test_client",
958                            self.client_ipv6_uni_dir_nsock_test_args)
959
960     @unittest.skipUnless(config.extended, "part of extended tests")
961     def test_vcl_ipv6_cut_thru_bi_dir_nsock(self):
962         """ run VCL IPv6 cut thru bi-directional (multiple sockets) test """
963
964         self.timeout = self.client_bi_dir_nsock_timeout
965         self.cut_thru_test("vcl_test_server", self.server_ipv6_args,
966                            "vcl_test_client",
967                            self.client_ipv6_bi_dir_nsock_test_args)
968
969
970 class VCLIpv6ThruHostStackEcho(VCLTestCase):
971     """ VCL IPv6 Thru Host Stack Echo """
972
973     @classmethod
974     def setUpClass(cls):
975         super(VCLIpv6ThruHostStackEcho, cls).setUpClass()
976
977     @classmethod
978     def tearDownClass(cls):
979         super(VCLIpv6ThruHostStackEcho, cls).tearDownClass()
980
981     def setUp(self):
982         super(VCLIpv6ThruHostStackEcho, self).setUp()
983
984         self.thru_host_stack_ipv6_setup()
985         self.client_ipv6_echo_test_args = ["-6", "-E", self.echo_phrase, "-X",
986                                            self.loop0.local_ip6,
987                                            self.server_port]
988
989     def tearDown(self):
990         self.thru_host_stack_ipv6_tear_down()
991         super(VCLIpv6ThruHostStackEcho, self).tearDown()
992
993     def test_vcl_ipv6_thru_host_stack_echo(self):
994         """ run VCL IPv6 thru host stack echo test """
995
996         self.thru_host_stack_test("vcl_test_server",
997                                   self.server_ipv6_args,
998                                   "vcl_test_client",
999                                   self.client_ipv6_echo_test_args)
1000
1001
1002 if __name__ == '__main__':
1003     unittest.main(testRunner=VppTestRunner)