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