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 | |
| 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 | |
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() |
| 22 | self.vapi.session_enable_disable(is_enabled=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 |
Paul Vinciguerra | 22ab6f7 | 2019-03-07 17:55:33 -0800 | [diff] [blame] | 39 | self.vapi.app_namespace_add_del(namespace_id=b"0", |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 40 | sw_if_index=self.loop0.sw_if_index) |
Paul Vinciguerra | 22ab6f7 | 2019-03-07 17:55:33 -0800 | [diff] [blame] | 41 | self.vapi.app_namespace_add_del(namespace_id=b"1", |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 42 | sw_if_index=self.loop1.sw_if_index) |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 43 | |
| 44 | def tearDown(self): |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 45 | for i in self.lo_interfaces: |
| 46 | i.unconfig_ip4() |
| 47 | i.set_table_ip4(0) |
| 48 | i.admin_down() |
| 49 | self.vapi.session_enable_disable(is_enabled=0) |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 50 | super(TestTCP, self).tearDown() |
| 51 | |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 52 | def test_tcp_transfer(self): |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 53 | """ TCP echo client/server transfer """ |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 54 | |
| 55 | # Add inter-table routes |
| 56 | ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32, |
| 57 | [VppRoutePath("0.0.0.0", |
| 58 | 0xffffffff, |
| 59 | nh_table_id=1)]) |
| 60 | ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32, |
| 61 | [VppRoutePath("0.0.0.0", |
| 62 | 0xffffffff, |
| 63 | nh_table_id=0)], table_id=1) |
| 64 | ip_t01.add_vpp_config() |
| 65 | ip_t10.add_vpp_config() |
| 66 | |
| 67 | # Start builtin server and client |
| 68 | uri = "tcp://" + self.loop0.local_ip4 + "/1234" |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 69 | 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] | 70 | uri) |
| 71 | if error: |
| 72 | self.logger.critical(error) |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame] | 73 | self.assertNotIn("failed", error) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 74 | |
Florin Coras | 4399c2e | 2018-01-25 06:34:42 -0800 | [diff] [blame] | 75 | error = self.vapi.cli("test echo client mbytes 10 appns 1 " + |
| 76 | "fifo-size 4 no-output test-bytes " + |
| 77 | "syn-timeout 2 uri " + uri) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 78 | if error: |
| 79 | self.logger.critical(error) |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame] | 80 | self.assertNotIn("failed", error) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 81 | |
| 82 | # Delete inter-table routes |
| 83 | ip_t01.remove_vpp_config() |
| 84 | ip_t10.remove_vpp_config() |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 85 | |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 86 | |
| 87 | class TestTCPUnitTests(VppTestCase): |
| 88 | "TCP Unit Tests" |
| 89 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 90 | @classmethod |
| 91 | def setUpClass(cls): |
| 92 | super(TestTCPUnitTests, cls).setUpClass() |
| 93 | |
| 94 | @classmethod |
| 95 | def tearDownClass(cls): |
| 96 | super(TestTCPUnitTests, cls).tearDownClass() |
| 97 | |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 98 | def setUp(self): |
| 99 | super(TestTCPUnitTests, self).setUp() |
| 100 | self.vapi.session_enable_disable(is_enabled=1) |
| 101 | |
| 102 | def tearDown(self): |
| 103 | super(TestTCPUnitTests, self).tearDown() |
| 104 | self.vapi.session_enable_disable(is_enabled=0) |
| 105 | |
| 106 | def test_tcp_unittest(self): |
| 107 | """ TCP Unit Tests """ |
| 108 | error = self.vapi.cli("test tcp all") |
| 109 | |
| 110 | if error: |
| 111 | self.logger.critical(error) |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame] | 112 | self.assertNotIn("failed", error) |
Florin Coras | a8f5381 | 2018-11-08 13:58:19 -0800 | [diff] [blame] | 113 | |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 114 | if __name__ == '__main__': |
| 115 | unittest.main(testRunner=VppTestRunner) |