Tests Cleanup: Fix missing calls to setUpClass/tearDownClass.
[vpp.git] / test / test_session.py
1 #!/usr/bin/env python
2
3 import unittest
4
5 from framework import VppTestCase, VppTestRunner
6 from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
7
8
9 class TestSession(VppTestCase):
10     """ Session Test Case """
11
12     @classmethod
13     def setUpClass(cls):
14         super(TestSession, cls).setUpClass()
15
16     @classmethod
17     def tearDownClass(cls):
18         super(TestSession, cls).tearDownClass()
19
20     def setUp(self):
21         super(TestSession, self).setUp()
22
23         self.vapi.session_enable_disable(is_enabled=1)
24         self.create_loopback_interfaces(2)
25
26         table_id = 0
27
28         for i in self.lo_interfaces:
29             i.admin_up()
30
31             if table_id != 0:
32                 tbl = VppIpTable(self, table_id)
33                 tbl.add_vpp_config()
34
35             i.set_table_ip4(table_id)
36             i.config_ip4()
37             table_id += 1
38
39         # Configure namespaces
40         self.vapi.app_namespace_add_del(namespace_id=b"0",
41                                         sw_if_index=self.loop0.sw_if_index)
42         self.vapi.app_namespace_add_del(namespace_id=b"1",
43                                         sw_if_index=self.loop1.sw_if_index)
44
45     def tearDown(self):
46         for i in self.lo_interfaces:
47             i.unconfig_ip4()
48             i.set_table_ip4(0)
49             i.admin_down()
50
51         super(TestSession, self).tearDown()
52         self.vapi.session_enable_disable(is_enabled=1)
53
54     def test_segment_manager_alloc(self):
55         """ Session Segment Manager Multiple Segment Allocation """
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 with small private segments
70         uri = "tcp://" + self.loop0.local_ip4 + "/1234"
71         error = self.vapi.cli("test echo server appns 0 fifo-size 64 " +
72                               "private-segment-size 1m uri " + uri)
73         if error:
74             self.logger.critical(error)
75             self.assertNotIn("failed", error)
76
77         error = self.vapi.cli("test echo client nclients 100 appns 1 " +
78                               "no-output fifo-size 64 syn-timeout 2 " +
79                               "private-segment-size 1m uri " + uri)
80         if error:
81             self.logger.critical(error)
82             self.assertNotIn("failed", error)
83
84         if self.vpp_dead:
85             self.assert_equal(0)
86
87         # Delete inter-table routes
88         ip_t01.remove_vpp_config()
89         ip_t10.remove_vpp_config()
90
91
92 class TestSessionUnitTests(VppTestCase):
93     """ Session Unit Tests Case """
94
95     @classmethod
96     def setUpClass(cls):
97         super(TestSessionUnitTests, cls).setUpClass()
98
99     @classmethod
100     def tearDownClass(cls):
101         super(TestSessionUnitTests, cls).tearDownClass()
102
103     def setUp(self):
104         super(TestSessionUnitTests, self).setUp()
105         self.vapi.session_enable_disable(is_enabled=1)
106
107     def test_session(self):
108         """ Session Unit Tests """
109         error = self.vapi.cli("test session all")
110
111         if error:
112             self.logger.critical(error)
113         self.assertNotIn("failed", error)
114
115     def tearDown(self):
116         super(TestSessionUnitTests, self).tearDown()
117         self.vapi.session_enable_disable(is_enabled=0)
118
119 if __name__ == '__main__':
120     unittest.main(testRunner=VppTestRunner)