Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import unittest |
| 4 | |
| 5 | from framework 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): |
| 10 | """ TCP Test Case """ |
| 11 | |
| 12 | @classmethod |
| 13 | def setUpClass(cls): |
| 14 | super(TestTCP, cls).setUpClass() |
| 15 | |
| 16 | def setUp(self): |
| 17 | super(TestTCP, self).setUp() |
| 18 | self.vapi.session_enable_disable(is_enabled=1) |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 19 | self.create_loopback_interfaces(2) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 20 | |
| 21 | table_id = 0 |
| 22 | |
| 23 | for i in self.lo_interfaces: |
| 24 | i.admin_up() |
| 25 | |
| 26 | if table_id != 0: |
| 27 | tbl = VppIpTable(self, table_id) |
| 28 | tbl.add_vpp_config() |
| 29 | |
| 30 | i.set_table_ip4(table_id) |
| 31 | i.config_ip4() |
| 32 | table_id += 1 |
| 33 | |
| 34 | # Configure namespaces |
| 35 | self.vapi.app_namespace_add(namespace_id="0", |
| 36 | sw_if_index=self.loop0.sw_if_index) |
| 37 | self.vapi.app_namespace_add(namespace_id="1", |
| 38 | sw_if_index=self.loop1.sw_if_index) |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 39 | |
| 40 | def tearDown(self): |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 41 | for i in self.lo_interfaces: |
| 42 | i.unconfig_ip4() |
| 43 | i.set_table_ip4(0) |
| 44 | i.admin_down() |
| 45 | self.vapi.session_enable_disable(is_enabled=0) |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 46 | super(TestTCP, self).tearDown() |
| 47 | |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 48 | def test_tcp_transfer(self): |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 49 | """ TCP echo client/server transfer """ |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 50 | |
| 51 | # Add inter-table routes |
| 52 | ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32, |
| 53 | [VppRoutePath("0.0.0.0", |
| 54 | 0xffffffff, |
| 55 | nh_table_id=1)]) |
| 56 | ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32, |
| 57 | [VppRoutePath("0.0.0.0", |
| 58 | 0xffffffff, |
| 59 | nh_table_id=0)], table_id=1) |
| 60 | ip_t01.add_vpp_config() |
| 61 | ip_t10.add_vpp_config() |
| 62 | |
| 63 | # Start builtin server and client |
| 64 | uri = "tcp://" + self.loop0.local_ip4 + "/1234" |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 65 | 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] | 66 | uri) |
| 67 | if error: |
| 68 | self.logger.critical(error) |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 69 | self.assertEqual(error.find("failed"), -1) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 70 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 71 | error = self.vapi.cli("test echo client mbytes 10 appns 1 " + |
| 72 | "fifo-size 4 no-output test-bytes " + |
| 73 | "syn-timeout 2 uri " + uri) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 74 | if error: |
| 75 | self.logger.critical(error) |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 76 | self.assertEqual(error.find("failed"), -1) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 77 | |
| 78 | # Delete inter-table routes |
| 79 | ip_t01.remove_vpp_config() |
| 80 | ip_t10.remove_vpp_config() |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 81 | |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 82 | |
| 83 | class TestTCPUnitTests(VppTestCase): |
| 84 | "TCP Unit Tests" |
| 85 | |
| 86 | def setUp(self): |
| 87 | super(TestTCPUnitTests, self).setUp() |
| 88 | self.vapi.session_enable_disable(is_enabled=1) |
| 89 | |
| 90 | def tearDown(self): |
| 91 | super(TestTCPUnitTests, self).tearDown() |
| 92 | self.vapi.session_enable_disable(is_enabled=0) |
| 93 | |
| 94 | def test_tcp_unittest(self): |
| 95 | """ TCP Unit Tests """ |
| 96 | error = self.vapi.cli("test tcp all") |
| 97 | |
| 98 | if error: |
| 99 | self.logger.critical(error) |
| 100 | self.assertEqual(error.find("failed"), -1) |
| 101 | |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 102 | if __name__ == '__main__': |
| 103 | unittest.main(testRunner=VppTestRunner) |