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