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 | |
Pratikshya Prasai | 657bdf7 | 2022-08-18 11:09:38 -0400 | [diff] [blame^] | 5 | from asfframework import VppTestCase, VppTestRunner |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 6 | from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 7 | |
| 8 | |
| 9 | class TestTCP(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 10 | """TCP Test Case""" |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 11 | |
| 12 | @classmethod |
| 13 | def setUpClass(cls): |
| 14 | super(TestTCP, cls).setUpClass() |
| 15 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 16 | @classmethod |
| 17 | def tearDownClass(cls): |
| 18 | super(TestTCP, cls).tearDownClass() |
| 19 | |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 20 | def setUp(self): |
| 21 | super(TestTCP, self).setUp() |
Jakub Grajciar | 6a2794e | 2020-11-24 11:22:01 +0100 | [diff] [blame] | 22 | self.vapi.session_enable_disable(is_enable=1) |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 23 | self.create_loopback_interfaces(2) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 24 | |
| 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 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 39 | self.vapi.app_namespace_add_del( |
| 40 | namespace_id="0", sw_if_index=self.loop0.sw_if_index |
| 41 | ) |
| 42 | self.vapi.app_namespace_add_del( |
| 43 | namespace_id="1", sw_if_index=self.loop1.sw_if_index |
| 44 | ) |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 45 | |
| 46 | def tearDown(self): |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 47 | for i in self.lo_interfaces: |
| 48 | i.unconfig_ip4() |
| 49 | i.set_table_ip4(0) |
| 50 | i.admin_down() |
Jakub Grajciar | 6a2794e | 2020-11-24 11:22:01 +0100 | [diff] [blame] | 51 | self.vapi.session_enable_disable(is_enable=0) |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 52 | super(TestTCP, self).tearDown() |
| 53 | |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 54 | def test_tcp_transfer(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 55 | """TCP echo client/server transfer""" |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 56 | |
| 57 | # Add inter-table routes |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 58 | 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 Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 71 | 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" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 76 | error = self.vapi.cli("test echo server appns 0 fifo-size 4 uri " + uri) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 77 | if error: |
| 78 | self.logger.critical(error) |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame] | 79 | self.assertNotIn("failed", error) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 80 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 81 | error = self.vapi.cli( |
| 82 | "test echo client mbytes 10 appns 1 " |
| 83 | + "fifo-size 4 no-output test-bytes " |
| 84 | + "syn-timeout 2 uri " |
| 85 | + uri |
| 86 | ) |
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 | |
| 91 | # Delete inter-table routes |
| 92 | ip_t01.remove_vpp_config() |
| 93 | ip_t10.remove_vpp_config() |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 94 | |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 95 | |
| 96 | class TestTCPUnitTests(VppTestCase): |
| 97 | "TCP Unit Tests" |
| 98 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 99 | @classmethod |
| 100 | def setUpClass(cls): |
| 101 | super(TestTCPUnitTests, cls).setUpClass() |
| 102 | |
| 103 | @classmethod |
| 104 | def tearDownClass(cls): |
| 105 | super(TestTCPUnitTests, cls).tearDownClass() |
| 106 | |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 107 | def setUp(self): |
| 108 | super(TestTCPUnitTests, self).setUp() |
Jakub Grajciar | 6a2794e | 2020-11-24 11:22:01 +0100 | [diff] [blame] | 109 | self.vapi.session_enable_disable(is_enable=1) |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 110 | |
| 111 | def tearDown(self): |
| 112 | super(TestTCPUnitTests, self).tearDown() |
Jakub Grajciar | 6a2794e | 2020-11-24 11:22:01 +0100 | [diff] [blame] | 113 | self.vapi.session_enable_disable(is_enable=0) |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 114 | |
| 115 | def test_tcp_unittest(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 116 | """TCP Unit Tests""" |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 117 | error = self.vapi.cli("test tcp all") |
| 118 | |
| 119 | if error: |
| 120 | self.logger.critical(error) |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame] | 121 | self.assertNotIn("failed", error) |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 122 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 123 | |
| 124 | if __name__ == "__main__": |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 125 | unittest.main(testRunner=VppTestRunner) |