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