blob: 69fc5c472a5028d3eb210b83103e0acf203c8244 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Florin Coras3ea6ce22017-12-11 09:09:05 -08002
3import unittest
4
Dave Wallace8800f732023-08-31 00:47:44 -04005from asfframework import VppAsfTestCase, VppTestRunner
Florin Corasb795bd02017-12-14 11:30:48 -08006from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
Florin Coras3ea6ce22017-12-11 09:09:05 -08007
8
Dave Wallace8800f732023-08-31 00:47:44 -04009class TestTCP(VppAsfTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020010 """TCP Test Case"""
Florin Coras3ea6ce22017-12-11 09:09:05 -080011
12 @classmethod
13 def setUpClass(cls):
14 super(TestTCP, cls).setUpClass()
15
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070016 @classmethod
17 def tearDownClass(cls):
18 super(TestTCP, cls).tearDownClass()
19
Florin Coras3ea6ce22017-12-11 09:09:05 -080020 def setUp(self):
21 super(TestTCP, self).setUp()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +010022 self.vapi.session_enable_disable(is_enable=1)
Klement Sekerab9ef2732018-06-24 22:49:33 +020023 self.create_loopback_interfaces(2)
Florin Corasb795bd02017-12-14 11:30:48 -080024
25 table_id = 0
26
27 for i in self.lo_interfaces:
28 i.admin_up()
29
30 if table_id != 0:
31 tbl = VppIpTable(self, table_id)
32 tbl.add_vpp_config()
33
34 i.set_table_ip4(table_id)
35 i.config_ip4()
36 table_id += 1
37
38 # Configure namespaces
Nathan Skrzypczak51f1b262023-04-27 12:43:46 +020039 self.vapi.app_namespace_add_del_v4(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020040 namespace_id="0", sw_if_index=self.loop0.sw_if_index
41 )
Nathan Skrzypczak51f1b262023-04-27 12:43:46 +020042 self.vapi.app_namespace_add_del_v4(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020043 namespace_id="1", sw_if_index=self.loop1.sw_if_index
44 )
Florin Coras3ea6ce22017-12-11 09:09:05 -080045
46 def tearDown(self):
Florin Corasb795bd02017-12-14 11:30:48 -080047 for i in self.lo_interfaces:
48 i.unconfig_ip4()
49 i.set_table_ip4(0)
50 i.admin_down()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +010051 self.vapi.session_enable_disable(is_enable=0)
Florin Coras3ea6ce22017-12-11 09:09:05 -080052 super(TestTCP, self).tearDown()
53
Florin Corasb795bd02017-12-14 11:30:48 -080054 def test_tcp_transfer(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020055 """TCP echo client/server transfer"""
Florin Corasb795bd02017-12-14 11:30:48 -080056
57 # Add inter-table routes
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020058 ip_t01 = VppIpRoute(
59 self,
60 self.loop1.local_ip4,
61 32,
62 [VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=1)],
63 )
64 ip_t10 = VppIpRoute(
65 self,
66 self.loop0.local_ip4,
67 32,
68 [VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=0)],
69 table_id=1,
70 )
Florin Corasb795bd02017-12-14 11:30:48 -080071 ip_t01.add_vpp_config()
72 ip_t10.add_vpp_config()
73
74 # Start builtin server and client
75 uri = "tcp://" + self.loop0.local_ip4 + "/1234"
Filip Tehlarefe875e2023-09-04 14:17:52 +020076 error = self.vapi.cli("test echo server appns 0 fifo-size 4k uri " + uri)
Florin Corasb795bd02017-12-14 11:30:48 -080077 if error:
78 self.logger.critical(error)
Paul Vinciguerra9a6dafd2019-03-06 15:11:28 -080079 self.assertNotIn("failed", error)
Florin Corasb795bd02017-12-14 11:30:48 -080080
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020081 error = self.vapi.cli(
82 "test echo client mbytes 10 appns 1 "
Filip Tehlarefe875e2023-09-04 14:17:52 +020083 + "fifo-size 4k test-bytes "
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020084 + "syn-timeout 2 uri "
85 + uri
86 )
Florin Corasb795bd02017-12-14 11:30:48 -080087 if error:
88 self.logger.critical(error)
Paul Vinciguerra9a6dafd2019-03-06 15:11:28 -080089 self.assertNotIn("failed", error)
Florin Corasb795bd02017-12-14 11:30:48 -080090
91 # Delete inter-table routes
92 ip_t01.remove_vpp_config()
93 ip_t10.remove_vpp_config()
Florin Coras3ea6ce22017-12-11 09:09:05 -080094
Florin Corasa8f53812018-11-08 13:58:19 -080095
Dave Wallace8800f732023-08-31 00:47:44 -040096class TestTCPUnitTests(VppAsfTestCase):
Florin Corasa8f53812018-11-08 13:58:19 -080097 "TCP Unit Tests"
98
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070099 @classmethod
100 def setUpClass(cls):
101 super(TestTCPUnitTests, cls).setUpClass()
102
103 @classmethod
104 def tearDownClass(cls):
105 super(TestTCPUnitTests, cls).tearDownClass()
106
Florin Corasa8f53812018-11-08 13:58:19 -0800107 def setUp(self):
108 super(TestTCPUnitTests, self).setUp()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +0100109 self.vapi.session_enable_disable(is_enable=1)
Florin Corasa8f53812018-11-08 13:58:19 -0800110
111 def tearDown(self):
112 super(TestTCPUnitTests, self).tearDown()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +0100113 self.vapi.session_enable_disable(is_enable=0)
Florin Corasa8f53812018-11-08 13:58:19 -0800114
115 def test_tcp_unittest(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200116 """TCP Unit Tests"""
Florin Corasa8f53812018-11-08 13:58:19 -0800117 error = self.vapi.cli("test tcp all")
118
119 if error:
120 self.logger.critical(error)
Paul Vinciguerra9a6dafd2019-03-06 15:11:28 -0800121 self.assertNotIn("failed", error)
Florin Corasa8f53812018-11-08 13:58:19 -0800122
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200123
124if __name__ == "__main__":
Florin Coras3ea6ce22017-12-11 09:09:05 -0800125 unittest.main(testRunner=VppTestRunner)