lb: remove api boilerplate
[vpp.git] / test / test_vcl.py
1 #!/usr/bin/env python
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, args, logger, env={}):
30         vcl_lib_dir = "%s/vpp/lib" % build_dir
31         if "iperf" in appname:
32             app = appname
33             env.update({'LD_PRELOAD':
34                         "%s/libvcl_ldpreload.so" % vcl_lib_dir})
35         elif "sock" in appname:
36             app = "%s/vpp/bin/%s" % (build_dir, appname)
37             env.update({'LD_PRELOAD':
38                         "%s/libvcl_ldpreload.so" % vcl_lib_dir})
39         else:
40             app = "%s/vpp/bin/%s" % (build_dir, appname)
41         self.args = [app] + args
42         super(VCLAppWorker, self).__init__(self.args, logger, env)
43
44
45 class VCLTestCase(VppTestCase):
46     """ VCL Test Class """
47
48     @classmethod
49     def setUpClass(cls):
50         super(VCLTestCase, cls).setUpClass()
51
52     @classmethod
53     def tearDownClass(cls):
54         super(VCLTestCase, cls).tearDownClass()
55
56     def setUp(self):
57         var = "VPP_BUILD_DIR"
58         self.build_dir = os.getenv(var, None)
59         if self.build_dir is None:
60             raise EnvironmentError("Environment variable `%s' not set" % var)
61         self.vppDebug = 'vpp_debug' in self.build_dir
62         self.server_addr = "127.0.0.1"
63         self.server_port = "22000"
64         self.server_args = [self.server_port]
65         self.server_ipv6_addr = "::1"
66         self.server_ipv6_args = ["-6", self.server_port]
67         self.timeout = 20
68         self.echo_phrase = "Hello, world! Jenny is a friend of mine."
69         self.pre_test_sleep = 0.3
70         self.post_test_sleep = 0.2
71
72         if os.path.isfile("/tmp/ldp_server_af_unix_socket"):
73             os.remove("/tmp/ldp_server_af_unix_socket")
74
75         super(VCLTestCase, self).setUp()
76
77     def cut_thru_setup(self):
78         self.vapi.session_enable_disable(is_enabled=1)
79
80     def cut_thru_tear_down(self):
81         self.vapi.session_enable_disable(is_enabled=0)
82
83     def cut_thru_test(self, server_app, server_args, client_app, client_args):
84         self.env = {'VCL_API_PREFIX': self.shm_prefix,
85                     'VCL_APP_SCOPE_LOCAL': "true"}
86         worker_server = VCLAppWorker(self.build_dir, server_app, server_args,
87                                      self.logger, self.env)
88         worker_server.start()
89         self.sleep(self.pre_test_sleep)
90         worker_client = VCLAppWorker(self.build_dir, client_app, client_args,
91                                      self.logger, self.env)
92         worker_client.start()
93         worker_client.join(self.timeout)
94         try:
95             self.validateResults(worker_client, worker_server, self.timeout)
96         except Exception as error:
97             self.fail("Failed with %s" % error)
98         self.sleep(self.post_test_sleep)
99
100     def thru_host_stack_setup(self):
101         self.vapi.session_enable_disable(is_enabled=1)
102         self.create_loopback_interfaces(2)
103
104         table_id = 1
105
106         for i in self.lo_interfaces:
107             i.admin_up()
108
109             if table_id != 0:
110                 tbl = VppIpTable(self, table_id)
111                 tbl.add_vpp_config()
112
113             i.set_table_ip4(table_id)
114             i.config_ip4()
115             table_id += 1
116
117         # Configure namespaces
118         self.vapi.app_namespace_add_del(namespace_id=b"1", secret=1234,
119                                         sw_if_index=self.loop0.sw_if_index)
120         self.vapi.app_namespace_add_del(namespace_id=b"2", secret=5678,
121                                         sw_if_index=self.loop1.sw_if_index)
122
123         # Add inter-table routes
124         ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32,
125                             [VppRoutePath("0.0.0.0",
126                                           0xffffffff,
127                                           nh_table_id=2)], table_id=1)
128         ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32,
129                             [VppRoutePath("0.0.0.0",
130                                           0xffffffff,
131                                           nh_table_id=1)], table_id=2)
132         ip_t01.add_vpp_config()
133         ip_t10.add_vpp_config()
134         self.logger.debug(self.vapi.cli("show ip fib"))
135
136     def thru_host_stack_tear_down(self):
137         for i in self.lo_interfaces:
138             i.unconfig_ip4()
139             i.set_table_ip4(0)
140             i.admin_down()
141
142     def thru_host_stack_ipv6_setup(self):
143         self.vapi.session_enable_disable(is_enabled=1)
144         self.create_loopback_interfaces(2)
145
146         table_id = 1
147
148         for i in self.lo_interfaces:
149             i.admin_up()
150
151             tbl = VppIpTable(self, table_id, is_ip6=1)
152             tbl.add_vpp_config()
153
154             i.set_table_ip6(table_id)
155             i.config_ip6()
156             table_id += 1
157
158         # Configure namespaces
159         self.vapi.app_namespace_add_del(namespace_id=b"1", secret=1234,
160                                         sw_if_index=self.loop0.sw_if_index)
161         self.vapi.app_namespace_add_del(namespace_id=b"2", secret=5678,
162                                         sw_if_index=self.loop1.sw_if_index)
163
164         # Add inter-table routes
165         ip_t01 = VppIpRoute(self, self.loop1.local_ip6, 128,
166                             [VppRoutePath("::0", 0xffffffff,
167                                           nh_table_id=2)],
168                             table_id=1)
169         ip_t10 = VppIpRoute(self, self.loop0.local_ip6, 128,
170                             [VppRoutePath("::0", 0xffffffff,
171                                           nh_table_id=1)],
172                             table_id=2)
173         ip_t01.add_vpp_config()
174         ip_t10.add_vpp_config()
175         self.logger.debug(self.vapi.cli("show interface addr"))
176         self.logger.debug(self.vapi.cli("show ip6 fib"))
177
178     def thru_host_stack_ipv6_tear_down(self):
179         for i in self.lo_interfaces:
180             i.unconfig_ip6()
181             i.set_table_ip6(0)
182             i.admin_down()
183
184         self.vapi.session_enable_disable(is_enabled=0)
185
186     @unittest.skipUnless(_have_iperf3, "'%s' not found, Skipping.")
187     def thru_host_stack_test(self, server_app, server_args,
188                              client_app, client_args):
189         self.env = {'VCL_API_PREFIX': self.shm_prefix,
190                     'VCL_APP_SCOPE_GLOBAL': "true",
191                     'VCL_APP_NAMESPACE_ID': "1",
192                     'VCL_APP_NAMESPACE_SECRET': "1234"}
193
194         worker_server = VCLAppWorker(self.build_dir, server_app, server_args,
195                                      self.logger, self.env)
196         worker_server.start()
197         self.sleep(self.pre_test_sleep)
198
199         self.env.update({'VCL_APP_NAMESPACE_ID': "2",
200                          'VCL_APP_NAMESPACE_SECRET': "5678"})
201         worker_client = VCLAppWorker(self.build_dir, client_app, client_args,
202                                      self.logger, self.env)
203         worker_client.start()
204         worker_client.join(self.timeout)
205
206         try:
207             self.validateResults(worker_client, worker_server, self.timeout)
208         except Exception as error:
209             self.fail("Failed with %s" % error)
210         self.sleep(self.post_test_sleep)
211
212     def validateResults(self, worker_client, worker_server, timeout):
213         if worker_server.process is None:
214             raise RuntimeError('worker_server is not running.')
215         if os.path.isdir('/proc/{}'.format(worker_server.process.pid)):
216             self.logger.info("Killing server worker process (pid %d)" %
217                              worker_server.process.pid)
218             os.killpg(os.getpgid(worker_server.process.pid), signal.SIGTERM)
219             worker_server.join()
220         self.logger.info("Client worker result is `%s'" % worker_client.result)
221         error = False
222         if worker_client.result is None:
223             try:
224                 error = True
225                 self.logger.error(
226                     "Timeout: %ss! Killing client worker process (pid %d)" %
227                     (timeout, worker_client.process.pid))
228                 os.killpg(os.getpgid(worker_client.process.pid),
229                           signal.SIGKILL)
230                 worker_client.join()
231             except OSError:
232                 self.logger.debug(
233                     "Couldn't kill client worker process")
234                 raise
235         if error:
236             raise RuntimeError(
237                 "Timeout! Client worker did not finish in %ss" % timeout)
238         self.assert_equal(worker_client.result, 0, "Binary test return code")
239
240
241 class LDPCutThruTestCase(VCLTestCase):
242     """ LDP Cut Thru Tests """
243
244     @classmethod
245     def setUpClass(cls):
246         super(LDPCutThruTestCase, cls).setUpClass()
247
248     @classmethod
249     def tearDownClass(cls):
250         super(LDPCutThruTestCase, cls).tearDownClass()
251
252     def setUp(self):
253         super(LDPCutThruTestCase, self).setUp()
254
255         self.cut_thru_setup()
256         self.client_echo_test_args = ["-E", self.echo_phrase, "-X",
257                                       self.server_addr, self.server_port]
258         self.client_iperf3_timeout = 20
259         self.client_iperf3_args = ["-V4d", "-t 2", "-c", self.server_addr]
260         self.server_iperf3_args = ["-V4d", "-s"]
261         self.client_uni_dir_nsock_timeout = 20
262         self.client_uni_dir_nsock_test_args = ["-N", "1000", "-U", "-X",
263                                                "-I", "2",
264                                                self.server_addr,
265                                                self.server_port]
266         self.client_bi_dir_nsock_timeout = 20
267         self.client_bi_dir_nsock_test_args = ["-N", "1000", "-B", "-X",
268                                               "-I", "2",
269                                               self.server_addr,
270                                               self.server_port]
271
272     def tearDown(self):
273         super(LDPCutThruTestCase, self).tearDown()
274         self.cut_thru_tear_down()
275
276     def show_commands_at_teardown(self):
277         self.logger.debug(self.vapi.cli("show session verbose 2"))
278
279     @unittest.skipUnless(running_extended_tests, "part of extended tests")
280     def test_ldp_cut_thru_echo(self):
281         """ run LDP cut thru echo test """
282
283         self.cut_thru_test("sock_test_server", self.server_args,
284                            "sock_test_client", self.client_echo_test_args)
285
286     @unittest.skipUnless(_have_iperf3, "'%s' not found, Skipping.")
287     def test_ldp_cut_thru_iperf3(self):
288         """ run LDP cut thru iperf3 test """
289
290         self.timeout = self.client_iperf3_timeout
291         self.cut_thru_test(iperf3, self.server_iperf3_args,
292                            iperf3, self.client_iperf3_args)
293
294     @unittest.skipUnless(running_extended_tests, "part of extended tests")
295     def test_ldp_cut_thru_uni_dir_nsock(self):
296         """ run LDP cut thru uni-directional (multiple sockets) test """
297
298         self.timeout = self.client_uni_dir_nsock_timeout
299         self.cut_thru_test("sock_test_server", self.server_args,
300                            "sock_test_client",
301                            self.client_uni_dir_nsock_test_args)
302
303     @unittest.skipUnless(running_extended_tests, "part of extended tests")
304     @unittest.skip("sock test apps need to be improved")
305     def test_ldp_cut_thru_bi_dir_nsock(self):
306         """ run LDP cut thru bi-directional (multiple sockets) test """
307
308         self.timeout = self.client_bi_dir_nsock_timeout
309         self.cut_thru_test("sock_test_server", self.server_args,
310                            "sock_test_client",
311                            self.client_bi_dir_nsock_test_args)
312
313
314 class VCLCutThruTestCase(VCLTestCase):
315     """ VCL Cut Thru Tests """
316
317     @classmethod
318     def setUpClass(cls):
319         super(VCLCutThruTestCase, cls).setUpClass()
320
321     @classmethod
322     def tearDownClass(cls):
323         super(VCLCutThruTestCase, cls).tearDownClass()
324
325     def setUp(self):
326         super(VCLCutThruTestCase, self).setUp()
327
328         self.cut_thru_setup()
329         self.client_echo_test_args = ["-E", self.echo_phrase, "-X",
330                                       self.server_addr, self.server_port]
331
332         self.client_uni_dir_nsock_timeout = 20
333         self.client_uni_dir_nsock_test_args = ["-N", "1000", "-U", "-X",
334                                                "-I", "2",
335                                                self.server_addr,
336                                                self.server_port]
337         self.client_bi_dir_nsock_timeout = 20
338         self.client_bi_dir_nsock_test_args = ["-N", "1000", "-B", "-X",
339                                               "-I", "2",
340                                               self.server_addr,
341                                               self.server_port]
342
343     def tearDown(self):
344         super(VCLCutThruTestCase, self).tearDown()
345
346     def show_commands_at_teardown(self):
347         self.logger.debug(self.vapi.cli("show session verbose 2"))
348
349     def test_vcl_cut_thru_echo(self):
350         """ run VCL cut thru echo test """
351
352         self.cut_thru_test("vcl_test_server", self.server_args,
353                            "vcl_test_client", self.client_echo_test_args)
354
355     def test_vcl_cut_thru_uni_dir_nsock(self):
356         """ run VCL cut thru uni-directional (multiple sockets) test """
357
358         self.timeout = self.client_uni_dir_nsock_timeout
359         self.cut_thru_test("vcl_test_server", self.server_args,
360                            "vcl_test_client",
361                            self.client_uni_dir_nsock_test_args)
362
363     def test_vcl_cut_thru_bi_dir_nsock(self):
364         """ run VCL cut thru bi-directional (multiple sockets) test """
365
366         self.timeout = self.client_bi_dir_nsock_timeout
367         self.cut_thru_test("vcl_test_server", self.server_args,
368                            "vcl_test_client",
369                            self.client_bi_dir_nsock_test_args)
370
371
372 class VCLThruHostStackEcho(VCLTestCase):
373     """ VCL Thru Host Stack Echo """
374
375     @classmethod
376     def setUpClass(cls):
377         super(VCLThruHostStackEcho, cls).setUpClass()
378
379     @classmethod
380     def tearDownClass(cls):
381         super(VCLThruHostStackEcho, cls).tearDownClass()
382
383     def setUp(self):
384         super(VCLThruHostStackEcho, self).setUp()
385
386         self.thru_host_stack_setup()
387         self.client_bi_dir_nsock_timeout = 20
388         self.client_bi_dir_nsock_test_args = ["-N", "1000", "-B", "-X",
389                                               "-I", "2",
390                                               self.loop0.local_ip4,
391                                               self.server_port]
392         self.client_echo_test_args = ["-E", self.echo_phrase, "-X",
393                                       self.loop0.local_ip4,
394                                       self.server_port]
395
396     def tearDown(self):
397         self.thru_host_stack_tear_down()
398         super(VCLThruHostStackEcho, self).tearDown()
399
400     def show_commands_at_teardown(self):
401         self.logger.debug(self.vapi.cli("show app server"))
402         self.logger.debug(self.vapi.cli("show session verbose"))
403
404
405 class VCLThruHostStackTLS(VCLTestCase):
406     """ VCL Thru Host Stack TLS """
407
408     @classmethod
409     def setUpClass(cls):
410         super(VCLThruHostStackTLS, cls).setUpClass()
411
412     @classmethod
413     def tearDownClass(cls):
414         super(VCLThruHostStackTLS, cls).tearDownClass()
415
416     def setUp(self):
417         super(VCLThruHostStackTLS, self).setUp()
418
419         self.thru_host_stack_setup()
420         self.client_uni_dir_tls_timeout = 20
421         self.server_tls_args = ["-L", self.server_port]
422         self.client_uni_dir_tls_test_args = ["-N", "1000", "-U", "-X", "-L",
423                                              self.loop0.local_ip4,
424                                              self.server_port]
425
426     def test_vcl_thru_host_stack_tls_uni_dir(self):
427         """ run VCL thru host stack uni-directional TLS test """
428
429         self.timeout = self.client_uni_dir_tls_timeout
430         self.thru_host_stack_test("vcl_test_server", self.server_tls_args,
431                                   "vcl_test_client",
432                                   self.client_uni_dir_tls_test_args)
433
434     def tearDown(self):
435         self.thru_host_stack_tear_down()
436         super(VCLThruHostStackTLS, self).tearDown()
437
438     def show_commands_at_teardown(self):
439         self.logger.debug(self.vapi.cli("show app server"))
440         self.logger.debug(self.vapi.cli("show session verbose 2"))
441
442
443 class VCLThruHostStackBidirNsock(VCLTestCase):
444     """ VCL Thru Host Stack Bidir Nsock """
445
446     @classmethod
447     def setUpClass(cls):
448         super(VCLThruHostStackBidirNsock, cls).setUpClass()
449
450     @classmethod
451     def tearDownClass(cls):
452         super(VCLThruHostStackBidirNsock, cls).tearDownClass()
453
454     def setUp(self):
455         super(VCLThruHostStackBidirNsock, self).setUp()
456
457         self.thru_host_stack_setup()
458         self.client_bi_dir_nsock_timeout = 20
459         self.client_bi_dir_nsock_test_args = ["-N", "1000", "-B", "-X",
460                                               "-I", "2",
461                                               self.loop0.local_ip4,
462                                               self.server_port]
463         self.client_echo_test_args = ["-E", self.echo_phrase, "-X",
464                                       self.loop0.local_ip4,
465                                       self.server_port]
466
467     def tearDown(self):
468         self.thru_host_stack_tear_down()
469         super(VCLThruHostStackBidirNsock, self).tearDown()
470
471     def show_commands_at_teardown(self):
472         self.logger.debug(self.vapi.cli("show session verbose 2"))
473
474     def test_vcl_thru_host_stack_bi_dir_nsock(self):
475         """ run VCL thru host stack bi-directional (multiple sockets) test """
476
477         self.timeout = self.client_bi_dir_nsock_timeout
478         self.thru_host_stack_test("vcl_test_server", self.server_args,
479                                   "vcl_test_client",
480                                   self.client_bi_dir_nsock_test_args)
481
482
483 class LDPThruHostStackBidirNsock(VCLTestCase):
484     """ LDP Thru Host Stack Bidir Nsock """
485
486     @classmethod
487     def setUpClass(cls):
488         super(LDPThruHostStackBidirNsock, cls).setUpClass()
489
490     @classmethod
491     def tearDownClass(cls):
492         super(LDPThruHostStackBidirNsock, cls).tearDownClass()
493
494     def setUp(self):
495         super(LDPThruHostStackBidirNsock, self).setUp()
496
497         self.thru_host_stack_setup()
498         if self.vppDebug:
499             self.client_bi_dir_nsock_timeout = 20
500             self.client_bi_dir_nsock_test_args = ["-N", "1000", "-B", "-X",
501                                                   # OUCH! Host Stack Bug?
502                                                   # "-I", "2",
503                                                   self.loop0.local_ip4,
504                                                   self.server_port]
505         else:
506             self.client_bi_dir_nsock_timeout = 20
507             self.client_bi_dir_nsock_test_args = ["-N", "1000", "-B", "-X",
508                                                   # OUCH! Host Stack Bug?
509                                                   # "-I", "2",
510                                                   self.loop0.local_ip4,
511                                                   self.server_port]
512
513     def tearDown(self):
514         self.thru_host_stack_tear_down()
515         super(LDPThruHostStackBidirNsock, self).tearDown()
516
517     def show_commands_at_teardown(self):
518         self.logger.debug(self.vapi.cli("show session verbose 2"))
519
520     def test_ldp_thru_host_stack_bi_dir_nsock(self):
521         """ run LDP thru host stack bi-directional (multiple sockets) test """
522
523         self.timeout = self.client_bi_dir_nsock_timeout
524         self.thru_host_stack_test("sock_test_server", self.server_args,
525                                   "sock_test_client",
526                                   self.client_bi_dir_nsock_test_args)
527
528
529 class LDPThruHostStackNsock(VCLTestCase):
530     """ LDP Thru Host Stack Nsock """
531
532     @classmethod
533     def setUpClass(cls):
534         super(LDPThruHostStackNsock, cls).setUpClass()
535
536     @classmethod
537     def tearDownClass(cls):
538         super(LDPThruHostStackNsock, cls).tearDownClass()
539
540     def setUp(self):
541         super(LDPThruHostStackNsock, self).setUp()
542
543         self.thru_host_stack_setup()
544         if self.vppDebug:
545             self.client_uni_dir_nsock_timeout = 20
546             self.numSockets = "2"
547         else:
548             self.client_uni_dir_nsock_timeout = 20
549             self.numSockets = "5"
550
551         self.client_uni_dir_nsock_test_args = ["-N", "1000", "-U", "-X",
552                                                "-I", self.numSockets,
553                                                self.loop0.local_ip4,
554                                                self.server_port]
555
556     def tearDown(self):
557         self.thru_host_stack_tear_down()
558         super(LDPThruHostStackNsock, self).tearDown()
559
560     def test_ldp_thru_host_stack_uni_dir_nsock(self):
561         """ run LDP thru host stack uni-directional (multiple sockets) test """
562
563         self.timeout = self.client_uni_dir_nsock_timeout
564         self.thru_host_stack_test("sock_test_server", self.server_args,
565                                   "sock_test_client",
566                                   self.client_uni_dir_nsock_test_args)
567
568
569 class VCLThruHostStackNsock(VCLTestCase):
570     """ VCL Thru Host Stack Nsock """
571
572     @classmethod
573     def setUpClass(cls):
574         super(VCLThruHostStackNsock, cls).setUpClass()
575
576     @classmethod
577     def tearDownClass(cls):
578         super(VCLThruHostStackNsock, cls).tearDownClass()
579
580     def setUp(self):
581         super(VCLThruHostStackNsock, self).setUp()
582
583         self.thru_host_stack_setup()
584         if self.vppDebug:
585             self.client_uni_dir_nsock_timeout = 20
586             self.numSockets = "2"
587         else:
588             self.client_uni_dir_nsock_timeout = 20
589             self.numSockets = "5"
590
591         self.client_uni_dir_nsock_test_args = ["-N", "1000", "-U", "-X",
592                                                "-I", self.numSockets,
593                                                self.loop0.local_ip4,
594                                                self.server_port]
595
596     def tearDown(self):
597         self.thru_host_stack_tear_down()
598         super(VCLThruHostStackNsock, self).tearDown()
599
600     def test_vcl_thru_host_stack_uni_dir_nsock(self):
601         """ run VCL thru host stack uni-directional (multiple sockets) test """
602
603         self.timeout = self.client_uni_dir_nsock_timeout
604         self.thru_host_stack_test("vcl_test_server", self.server_args,
605                                   "vcl_test_client",
606                                   self.client_uni_dir_nsock_test_args)
607
608
609 class LDPThruHostStackIperf(VCLTestCase):
610     """ LDP Thru Host Stack Iperf  """
611
612     @classmethod
613     def setUpClass(cls):
614         super(LDPThruHostStackIperf, cls).setUpClass()
615
616     @classmethod
617     def tearDownClass(cls):
618         super(LDPThruHostStackIperf, cls).tearDownClass()
619
620     def setUp(self):
621         super(LDPThruHostStackIperf, self).setUp()
622
623         self.thru_host_stack_setup()
624         self.client_iperf3_timeout = 20
625         self.client_iperf3_args = ["-V4d", "-t 2", "-c", self.loop0.local_ip4]
626         self.server_iperf3_args = ["-V4d", "-s"]
627
628     def tearDown(self):
629         self.thru_host_stack_tear_down()
630         super(LDPThruHostStackIperf, self).tearDown()
631
632     def show_commands_at_teardown(self):
633         self.logger.debug(self.vapi.cli("show session verbose 2"))
634
635     @unittest.skipUnless(_have_iperf3, "'%s' not found, Skipping.")
636     def test_ldp_thru_host_stack_iperf3(self):
637         """ run LDP thru host stack iperf3 test """
638
639         self.timeout = self.client_iperf3_timeout
640         self.thru_host_stack_test(iperf3, self.server_iperf3_args,
641                                   iperf3, self.client_iperf3_args)
642
643
644 class LDPIpv6CutThruTestCase(VCLTestCase):
645     """ LDP IPv6 Cut Thru Tests """
646
647     @classmethod
648     def setUpClass(cls):
649         super(LDPIpv6CutThruTestCase, cls).setUpClass()
650
651     @classmethod
652     def tearDownClass(cls):
653         super(LDPIpv6CutThruTestCase, cls).tearDownClass()
654
655     def setUp(self):
656         super(LDPIpv6CutThruTestCase, self).setUp()
657
658         self.cut_thru_setup()
659         self.client_iperf3_timeout = 20
660         self.client_uni_dir_nsock_timeout = 20
661         self.client_bi_dir_nsock_timeout = 20
662         self.client_ipv6_echo_test_args = ["-6", "-E", self.echo_phrase, "-X",
663                                            self.server_ipv6_addr,
664                                            self.server_port]
665         self.client_ipv6_iperf3_args = ["-V6d", "-t 2", "-c",
666                                         self.server_ipv6_addr]
667         self.server_ipv6_iperf3_args = ["-V6d", "-s"]
668         self.client_ipv6_uni_dir_nsock_test_args = ["-N", "1000", "-U", "-X",
669                                                     "-6",
670                                                     "-I", "2",
671                                                     self.server_ipv6_addr,
672                                                     self.server_port]
673         self.client_ipv6_bi_dir_nsock_test_args = ["-N", "1000", "-B", "-X",
674                                                    "-6",
675                                                    "-I", "2",
676                                                    self.server_ipv6_addr,
677                                                    self.server_port]
678
679     def tearDown(self):
680         super(LDPIpv6CutThruTestCase, self).tearDown()
681         self.cut_thru_tear_down()
682
683     def test_ldp_ipv6_cut_thru_echo(self):
684         """ run LDP IPv6 cut thru echo test """
685
686         self.cut_thru_test("sock_test_server",
687                            self.server_ipv6_args,
688                            "sock_test_client",
689                            self.client_ipv6_echo_test_args)
690
691     @unittest.skipUnless(_have_iperf3, "'%s' not found, Skipping.")
692     @unittest.skipUnless(running_extended_tests, "part of extended tests")
693     def test_ldp_ipv6_cut_thru_iperf3(self):
694         """ run LDP IPv6 cut thru iperf3 test """
695
696         self.timeout = self.client_iperf3_timeout
697         self.cut_thru_test(iperf3, self.server_ipv6_iperf3_args,
698                            iperf3, self.client_ipv6_iperf3_args)
699
700     @unittest.skipUnless(running_extended_tests, "part of extended tests")
701     def test_ldp_ipv6_cut_thru_uni_dir_nsock(self):
702         """ run LDP IPv6 cut thru uni-directional (multiple sockets) test """
703
704         self.timeout = self.client_uni_dir_nsock_timeout
705         self.cut_thru_test("sock_test_server", self.server_ipv6_args,
706                            "sock_test_client",
707                            self.client_ipv6_uni_dir_nsock_test_args)
708
709     @unittest.skipUnless(running_extended_tests, "part of extended tests")
710     @unittest.skip("sock test apps need to be improved")
711     def test_ldp_ipv6_cut_thru_bi_dir_nsock(self):
712         """ run LDP IPv6 cut thru bi-directional (multiple sockets) test """
713
714         self.timeout = self.client_bi_dir_nsock_timeout
715         self.cut_thru_test("sock_test_server", self.server_ipv6_args,
716                            "sock_test_client",
717                            self.client_ipv6_bi_dir_nsock_test_args)
718
719
720 class VCLIpv6CutThruTestCase(VCLTestCase):
721     """ VCL IPv6 Cut Thru Tests """
722
723     @classmethod
724     def setUpClass(cls):
725         super(VCLIpv6CutThruTestCase, cls).setUpClass()
726
727     @classmethod
728     def tearDownClass(cls):
729         super(VCLIpv6CutThruTestCase, cls).tearDownClass()
730
731     def setUp(self):
732         super(VCLIpv6CutThruTestCase, self).setUp()
733
734         self.cut_thru_setup()
735         self.client_uni_dir_nsock_timeout = 20
736         self.client_bi_dir_nsock_timeout = 20
737         self.client_ipv6_echo_test_args = ["-6", "-E", self.echo_phrase, "-X",
738                                            self.server_ipv6_addr,
739                                            self.server_port]
740         self.client_ipv6_uni_dir_nsock_test_args = ["-N", "1000", "-U", "-X",
741                                                     "-6",
742                                                     "-I", "2",
743                                                     self.server_ipv6_addr,
744                                                     self.server_port]
745         self.client_ipv6_bi_dir_nsock_test_args = ["-N", "1000", "-B", "-X",
746                                                    "-6",
747                                                    "-I", "2",
748                                                    self.server_ipv6_addr,
749                                                    self.server_port]
750
751     def tearDown(self):
752         super(VCLIpv6CutThruTestCase, self).tearDown()
753         self.cut_thru_tear_down()
754
755     def test_vcl_ipv6_cut_thru_echo(self):
756         """ run VCL IPv6 cut thru echo test """
757
758         self.cut_thru_test("vcl_test_server",
759                            self.server_ipv6_args,
760                            "vcl_test_client",
761                            self.client_ipv6_echo_test_args)
762
763     @unittest.skipUnless(running_extended_tests, "part of extended tests")
764     def test_vcl_ipv6_cut_thru_uni_dir_nsock(self):
765         """ run VCL IPv6 cut thru uni-directional (multiple sockets) test """
766
767         self.timeout = self.client_uni_dir_nsock_timeout
768         self.cut_thru_test("vcl_test_server", self.server_ipv6_args,
769                            "vcl_test_client",
770                            self.client_ipv6_uni_dir_nsock_test_args)
771
772     @unittest.skipUnless(running_extended_tests, "part of extended tests")
773     def test_vcl_ipv6_cut_thru_bi_dir_nsock(self):
774         """ run VCL IPv6 cut thru bi-directional (multiple sockets) test """
775
776         self.timeout = self.client_bi_dir_nsock_timeout
777         self.cut_thru_test("vcl_test_server", self.server_ipv6_args,
778                            "vcl_test_client",
779                            self.client_ipv6_bi_dir_nsock_test_args)
780
781
782 class VCLIpv6ThruHostStackEcho(VCLTestCase):
783     """ VCL IPv6 Thru Host Stack Echo """
784
785     @classmethod
786     def setUpClass(cls):
787         super(VCLIpv6ThruHostStackEcho, cls).setUpClass()
788
789     @classmethod
790     def tearDownClass(cls):
791         super(VCLIpv6ThruHostStackEcho, cls).tearDownClass()
792
793     def setUp(self):
794         super(VCLIpv6ThruHostStackEcho, self).setUp()
795
796         self.thru_host_stack_ipv6_setup()
797         self.client_ipv6_echo_test_args = ["-6", "-E", self.echo_phrase, "-X",
798                                            self.loop0.local_ip6,
799                                            self.server_port]
800
801     def tearDown(self):
802         self.thru_host_stack_ipv6_tear_down()
803         super(VCLIpv6ThruHostStackEcho, self).tearDown()
804
805     def test_vcl_ipv6_thru_host_stack_echo(self):
806         """ run VCL IPv6 thru host stack echo test """
807
808         self.thru_host_stack_test("vcl_test_server",
809                                   self.server_ipv6_args,
810                                   "vcl_test_client",
811                                   self.client_ipv6_echo_test_args)
812
813
814 if __name__ == '__main__':
815     unittest.main(testRunner=VppTestRunner)