2019-10-31 13:31:07 -05:00
|
|
|
#!/usr/bin/env python3
|
2017-12-11 09:09:05 -08:00
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
2023-08-31 00:47:44 -04:00
|
|
|
from asfframework import VppAsfTestCase, VppTestRunner
|
2017-12-14 11:30:48 -08:00
|
|
|
from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
|
2024-03-11 10:38:46 +00:00
|
|
|
from config import config
|
2017-12-11 09:09:05 -08:00
|
|
|
|
|
|
|
|
2024-03-11 10:38:46 +00:00
|
|
|
@unittest.skipIf(
|
|
|
|
"hs_apps" in config.excluded_plugins, "Exclude tests requiring hs_apps plugin"
|
|
|
|
)
|
2023-08-31 00:47:44 -04:00
|
|
|
class TestTCP(VppAsfTestCase):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""TCP Test Case"""
|
2017-12-11 09:09:05 -08:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(TestTCP, cls).setUpClass()
|
|
|
|
|
2019-03-12 19:23:27 -07:00
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(TestTCP, cls).tearDownClass()
|
|
|
|
|
2017-12-11 09:09:05 -08:00
|
|
|
def setUp(self):
|
|
|
|
super(TestTCP, self).setUp()
|
2020-11-24 11:22:01 +01:00
|
|
|
self.vapi.session_enable_disable(is_enable=1)
|
2018-06-24 22:49:33 +02:00
|
|
|
self.create_loopback_interfaces(2)
|
2017-12-14 11:30:48 -08:00
|
|
|
|
|
|
|
table_id = 0
|
|
|
|
|
|
|
|
for i in self.lo_interfaces:
|
|
|
|
i.admin_up()
|
|
|
|
|
|
|
|
if table_id != 0:
|
|
|
|
tbl = VppIpTable(self, table_id)
|
|
|
|
tbl.add_vpp_config()
|
|
|
|
|
|
|
|
i.set_table_ip4(table_id)
|
|
|
|
i.config_ip4()
|
|
|
|
table_id += 1
|
|
|
|
|
|
|
|
# Configure namespaces
|
2023-04-27 12:43:46 +02:00
|
|
|
self.vapi.app_namespace_add_del_v4(
|
2022-04-26 19:02:15 +02:00
|
|
|
namespace_id="0", sw_if_index=self.loop0.sw_if_index
|
|
|
|
)
|
2023-04-27 12:43:46 +02:00
|
|
|
self.vapi.app_namespace_add_del_v4(
|
2022-04-26 19:02:15 +02:00
|
|
|
namespace_id="1", sw_if_index=self.loop1.sw_if_index
|
|
|
|
)
|
2017-12-11 09:09:05 -08:00
|
|
|
|
|
|
|
def tearDown(self):
|
2024-07-08 11:21:23 -07:00
|
|
|
self.vapi.app_namespace_add_del_v4(
|
|
|
|
is_add=0, namespace_id="0", sw_if_index=self.loop0.sw_if_index
|
|
|
|
)
|
|
|
|
self.vapi.app_namespace_add_del_v4(
|
|
|
|
is_add=0, namespace_id="1", sw_if_index=self.loop1.sw_if_index
|
|
|
|
)
|
2017-12-14 11:30:48 -08:00
|
|
|
for i in self.lo_interfaces:
|
|
|
|
i.unconfig_ip4()
|
|
|
|
i.set_table_ip4(0)
|
|
|
|
i.admin_down()
|
2020-11-24 11:22:01 +01:00
|
|
|
self.vapi.session_enable_disable(is_enable=0)
|
2017-12-11 09:09:05 -08:00
|
|
|
super(TestTCP, self).tearDown()
|
|
|
|
|
2017-12-14 11:30:48 -08:00
|
|
|
def test_tcp_transfer(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""TCP echo client/server transfer"""
|
2017-12-14 11:30:48 -08:00
|
|
|
|
|
|
|
# Add inter-table routes
|
2022-04-26 19:02:15 +02:00
|
|
|
ip_t01 = VppIpRoute(
|
|
|
|
self,
|
|
|
|
self.loop1.local_ip4,
|
|
|
|
32,
|
|
|
|
[VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=1)],
|
|
|
|
)
|
|
|
|
ip_t10 = VppIpRoute(
|
|
|
|
self,
|
|
|
|
self.loop0.local_ip4,
|
|
|
|
32,
|
|
|
|
[VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=0)],
|
|
|
|
table_id=1,
|
|
|
|
)
|
2017-12-14 11:30:48 -08:00
|
|
|
ip_t01.add_vpp_config()
|
|
|
|
ip_t10.add_vpp_config()
|
|
|
|
|
|
|
|
# Start builtin server and client
|
|
|
|
uri = "tcp://" + self.loop0.local_ip4 + "/1234"
|
2023-09-04 14:17:52 +02:00
|
|
|
error = self.vapi.cli("test echo server appns 0 fifo-size 4k uri " + uri)
|
2017-12-14 11:30:48 -08:00
|
|
|
if error:
|
|
|
|
self.logger.critical(error)
|
2019-03-06 15:11:28 -08:00
|
|
|
self.assertNotIn("failed", error)
|
2017-12-14 11:30:48 -08:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
error = self.vapi.cli(
|
|
|
|
"test echo client mbytes 10 appns 1 "
|
2023-09-04 14:17:52 +02:00
|
|
|
+ "fifo-size 4k test-bytes "
|
2022-04-26 19:02:15 +02:00
|
|
|
+ "syn-timeout 2 uri "
|
|
|
|
+ uri
|
|
|
|
)
|
2017-12-14 11:30:48 -08:00
|
|
|
if error:
|
|
|
|
self.logger.critical(error)
|
2019-03-06 15:11:28 -08:00
|
|
|
self.assertNotIn("failed", error)
|
2017-12-14 11:30:48 -08:00
|
|
|
|
|
|
|
# Delete inter-table routes
|
|
|
|
ip_t01.remove_vpp_config()
|
|
|
|
ip_t10.remove_vpp_config()
|
2017-12-11 09:09:05 -08:00
|
|
|
|
2018-11-08 13:58:19 -08:00
|
|
|
|
2023-08-31 00:47:44 -04:00
|
|
|
class TestTCPUnitTests(VppAsfTestCase):
|
2018-11-08 13:58:19 -08:00
|
|
|
"TCP Unit Tests"
|
|
|
|
|
2019-03-12 19:23:27 -07:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(TestTCPUnitTests, cls).setUpClass()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(TestTCPUnitTests, cls).tearDownClass()
|
|
|
|
|
2018-11-08 13:58:19 -08:00
|
|
|
def setUp(self):
|
|
|
|
super(TestTCPUnitTests, self).setUp()
|
2020-11-24 11:22:01 +01:00
|
|
|
self.vapi.session_enable_disable(is_enable=1)
|
2018-11-08 13:58:19 -08:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
super(TestTCPUnitTests, self).tearDown()
|
2020-11-24 11:22:01 +01:00
|
|
|
self.vapi.session_enable_disable(is_enable=0)
|
2018-11-08 13:58:19 -08:00
|
|
|
|
|
|
|
def test_tcp_unittest(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""TCP Unit Tests"""
|
2018-11-08 13:58:19 -08:00
|
|
|
error = self.vapi.cli("test tcp all")
|
|
|
|
|
|
|
|
if error:
|
|
|
|
self.logger.critical(error)
|
2019-03-06 15:11:28 -08:00
|
|
|
self.assertNotIn("failed", error)
|
2018-11-08 13:58:19 -08:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2017-12-11 09:09:05 -08:00
|
|
|
unittest.main(testRunner=VppTestRunner)
|