Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 2 | |
| 3 | import unittest |
| 4 | |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 5 | from asfframework import VppAsfTestCase, VppTestRunner |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 6 | from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame] | 7 | from config import config |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 8 | |
| 9 | |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame] | 10 | @unittest.skipIf( |
| 11 | "hs_apps" in config.excluded_plugins, "Exclude tests requiring hs_apps plugin" |
| 12 | ) |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 13 | class TestTCP(VppAsfTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 14 | """TCP Test Case""" |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 15 | |
| 16 | @classmethod |
| 17 | def setUpClass(cls): |
| 18 | super(TestTCP, cls).setUpClass() |
| 19 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 20 | @classmethod |
| 21 | def tearDownClass(cls): |
| 22 | super(TestTCP, cls).tearDownClass() |
| 23 | |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 24 | def setUp(self): |
| 25 | super(TestTCP, self).setUp() |
Jakub Grajciar | 6a2794e | 2020-11-24 11:22:01 +0100 | [diff] [blame] | 26 | self.vapi.session_enable_disable(is_enable=1) |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 27 | self.create_loopback_interfaces(2) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 28 | |
| 29 | table_id = 0 |
| 30 | |
| 31 | for i in self.lo_interfaces: |
| 32 | i.admin_up() |
| 33 | |
| 34 | if table_id != 0: |
| 35 | tbl = VppIpTable(self, table_id) |
| 36 | tbl.add_vpp_config() |
| 37 | |
| 38 | i.set_table_ip4(table_id) |
| 39 | i.config_ip4() |
| 40 | table_id += 1 |
| 41 | |
| 42 | # Configure namespaces |
Nathan Skrzypczak | 51f1b26 | 2023-04-27 12:43:46 +0200 | [diff] [blame] | 43 | self.vapi.app_namespace_add_del_v4( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 44 | namespace_id="0", sw_if_index=self.loop0.sw_if_index |
| 45 | ) |
Nathan Skrzypczak | 51f1b26 | 2023-04-27 12:43:46 +0200 | [diff] [blame] | 46 | self.vapi.app_namespace_add_del_v4( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 47 | namespace_id="1", sw_if_index=self.loop1.sw_if_index |
| 48 | ) |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 49 | |
| 50 | def tearDown(self): |
Steven Luong | 67bae20 | 2024-07-08 11:21:23 -0700 | [diff] [blame] | 51 | self.vapi.app_namespace_add_del_v4( |
| 52 | is_add=0, namespace_id="0", sw_if_index=self.loop0.sw_if_index |
| 53 | ) |
| 54 | self.vapi.app_namespace_add_del_v4( |
| 55 | is_add=0, namespace_id="1", sw_if_index=self.loop1.sw_if_index |
| 56 | ) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 57 | for i in self.lo_interfaces: |
| 58 | i.unconfig_ip4() |
| 59 | i.set_table_ip4(0) |
| 60 | i.admin_down() |
Jakub Grajciar | 6a2794e | 2020-11-24 11:22:01 +0100 | [diff] [blame] | 61 | self.vapi.session_enable_disable(is_enable=0) |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 62 | super(TestTCP, self).tearDown() |
| 63 | |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 64 | def test_tcp_transfer(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 65 | """TCP echo client/server transfer""" |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 66 | |
| 67 | # Add inter-table routes |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 68 | ip_t01 = VppIpRoute( |
| 69 | self, |
| 70 | self.loop1.local_ip4, |
| 71 | 32, |
| 72 | [VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=1)], |
| 73 | ) |
| 74 | ip_t10 = VppIpRoute( |
| 75 | self, |
| 76 | self.loop0.local_ip4, |
| 77 | 32, |
| 78 | [VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=0)], |
| 79 | table_id=1, |
| 80 | ) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 81 | ip_t01.add_vpp_config() |
| 82 | ip_t10.add_vpp_config() |
| 83 | |
| 84 | # Start builtin server and client |
| 85 | uri = "tcp://" + self.loop0.local_ip4 + "/1234" |
Filip Tehlar | efe875e | 2023-09-04 14:17:52 +0200 | [diff] [blame] | 86 | error = self.vapi.cli("test echo server appns 0 fifo-size 4k uri " + uri) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 87 | if error: |
| 88 | self.logger.critical(error) |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame] | 89 | self.assertNotIn("failed", error) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 90 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 91 | error = self.vapi.cli( |
| 92 | "test echo client mbytes 10 appns 1 " |
Filip Tehlar | efe875e | 2023-09-04 14:17:52 +0200 | [diff] [blame] | 93 | + "fifo-size 4k test-bytes " |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 94 | + "syn-timeout 2 uri " |
| 95 | + uri |
| 96 | ) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 97 | if error: |
| 98 | self.logger.critical(error) |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame] | 99 | self.assertNotIn("failed", error) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 100 | |
| 101 | # Delete inter-table routes |
| 102 | ip_t01.remove_vpp_config() |
| 103 | ip_t10.remove_vpp_config() |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 104 | |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 105 | |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 106 | class TestTCPUnitTests(VppAsfTestCase): |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 107 | "TCP Unit Tests" |
| 108 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 109 | @classmethod |
| 110 | def setUpClass(cls): |
| 111 | super(TestTCPUnitTests, cls).setUpClass() |
| 112 | |
| 113 | @classmethod |
| 114 | def tearDownClass(cls): |
| 115 | super(TestTCPUnitTests, cls).tearDownClass() |
| 116 | |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 117 | def setUp(self): |
| 118 | super(TestTCPUnitTests, self).setUp() |
Jakub Grajciar | 6a2794e | 2020-11-24 11:22:01 +0100 | [diff] [blame] | 119 | self.vapi.session_enable_disable(is_enable=1) |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 120 | |
| 121 | def tearDown(self): |
| 122 | super(TestTCPUnitTests, self).tearDown() |
Jakub Grajciar | 6a2794e | 2020-11-24 11:22:01 +0100 | [diff] [blame] | 123 | self.vapi.session_enable_disable(is_enable=0) |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 124 | |
| 125 | def test_tcp_unittest(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 126 | """TCP Unit Tests""" |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 127 | error = self.vapi.cli("test tcp all") |
| 128 | |
| 129 | if error: |
| 130 | self.logger.critical(error) |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame] | 131 | self.assertNotIn("failed", error) |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 132 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 133 | |
| 134 | if __name__ == "__main__": |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 135 | unittest.main(testRunner=VppTestRunner) |