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 | |
Andrew Yourtchenko | 8dc0d48 | 2021-01-29 13:17:19 +0000 | [diff] [blame] | 5 | from framework import tag_fixme_vpp_workers |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 6 | from framework import VppTestCase, VppTestRunner |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 7 | from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 8 | |
| 9 | |
Andrew Yourtchenko | 8dc0d48 | 2021-01-29 13:17:19 +0000 | [diff] [blame] | 10 | @tag_fixme_vpp_workers |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 11 | class TestTCP(VppTestCase): |
| 12 | """ TCP Test Case """ |
| 13 | |
| 14 | @classmethod |
| 15 | def setUpClass(cls): |
| 16 | super(TestTCP, cls).setUpClass() |
| 17 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 18 | @classmethod |
| 19 | def tearDownClass(cls): |
| 20 | super(TestTCP, cls).tearDownClass() |
| 21 | |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 22 | def setUp(self): |
| 23 | super(TestTCP, self).setUp() |
Jakub Grajciar | 6a2794e | 2020-11-24 11:22:01 +0100 | [diff] [blame] | 24 | self.vapi.session_enable_disable(is_enable=1) |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 25 | self.create_loopback_interfaces(2) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 26 | |
| 27 | table_id = 0 |
| 28 | |
| 29 | for i in self.lo_interfaces: |
| 30 | i.admin_up() |
| 31 | |
| 32 | if table_id != 0: |
| 33 | tbl = VppIpTable(self, table_id) |
| 34 | tbl.add_vpp_config() |
| 35 | |
| 36 | i.set_table_ip4(table_id) |
| 37 | i.config_ip4() |
| 38 | table_id += 1 |
| 39 | |
| 40 | # Configure namespaces |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 41 | self.vapi.app_namespace_add_del(namespace_id="0", |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 42 | sw_if_index=self.loop0.sw_if_index) |
Jakub Grajciar | b4e5e50 | 2020-01-31 09:35:29 +0100 | [diff] [blame] | 43 | self.vapi.app_namespace_add_del(namespace_id="1", |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 44 | sw_if_index=self.loop1.sw_if_index) |
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): |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [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 |
| 58 | ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32, |
| 59 | [VppRoutePath("0.0.0.0", |
| 60 | 0xffffffff, |
| 61 | nh_table_id=1)]) |
| 62 | ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32, |
| 63 | [VppRoutePath("0.0.0.0", |
| 64 | 0xffffffff, |
| 65 | nh_table_id=0)], table_id=1) |
| 66 | ip_t01.add_vpp_config() |
| 67 | ip_t10.add_vpp_config() |
| 68 | |
| 69 | # Start builtin server and client |
| 70 | uri = "tcp://" + self.loop0.local_ip4 + "/1234" |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 71 | error = self.vapi.cli("test echo server appns 0 fifo-size 4 uri " + |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 72 | uri) |
| 73 | if error: |
| 74 | self.logger.critical(error) |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame] | 75 | self.assertNotIn("failed", error) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 76 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 77 | error = self.vapi.cli("test echo client mbytes 10 appns 1 " + |
| 78 | "fifo-size 4 no-output test-bytes " + |
| 79 | "syn-timeout 2 uri " + uri) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 80 | if error: |
| 81 | self.logger.critical(error) |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame] | 82 | self.assertNotIn("failed", error) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 83 | |
| 84 | # Delete inter-table routes |
| 85 | ip_t01.remove_vpp_config() |
| 86 | ip_t10.remove_vpp_config() |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 87 | |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 88 | |
| 89 | class TestTCPUnitTests(VppTestCase): |
| 90 | "TCP Unit Tests" |
| 91 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 92 | @classmethod |
| 93 | def setUpClass(cls): |
| 94 | super(TestTCPUnitTests, cls).setUpClass() |
| 95 | |
| 96 | @classmethod |
| 97 | def tearDownClass(cls): |
| 98 | super(TestTCPUnitTests, cls).tearDownClass() |
| 99 | |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 100 | def setUp(self): |
| 101 | super(TestTCPUnitTests, self).setUp() |
Jakub Grajciar | 6a2794e | 2020-11-24 11:22:01 +0100 | [diff] [blame] | 102 | self.vapi.session_enable_disable(is_enable=1) |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 103 | |
| 104 | def tearDown(self): |
| 105 | super(TestTCPUnitTests, self).tearDown() |
Jakub Grajciar | 6a2794e | 2020-11-24 11:22:01 +0100 | [diff] [blame] | 106 | self.vapi.session_enable_disable(is_enable=0) |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 107 | |
| 108 | def test_tcp_unittest(self): |
| 109 | """ TCP Unit Tests """ |
| 110 | error = self.vapi.cli("test tcp all") |
| 111 | |
| 112 | if error: |
| 113 | self.logger.critical(error) |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame] | 114 | self.assertNotIn("failed", error) |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 115 | |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 116 | if __name__ == '__main__': |
| 117 | unittest.main(testRunner=VppTestRunner) |