4ceb46e666cdc8b6fe8e44fbfdf9c1028b65d612
[vpp.git] / test / test_tcp.py
1 #!/usr/bin/env python3
2
3 import unittest
4
5 from framework import tag_fixme_vpp_workers
6 from framework import VppTestCase, VppTestRunner
7 from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
8
9
10 @tag_fixme_vpp_workers
11 class TestTCP(VppTestCase):
12     """ TCP Test Case """
13
14     @classmethod
15     def setUpClass(cls):
16         super(TestTCP, cls).setUpClass()
17
18     @classmethod
19     def tearDownClass(cls):
20         super(TestTCP, cls).tearDownClass()
21
22     def setUp(self):
23         super(TestTCP, self).setUp()
24         self.vapi.session_enable_disable(is_enable=1)
25         self.create_loopback_interfaces(2)
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
41         self.vapi.app_namespace_add_del(namespace_id="0",
42                                         sw_if_index=self.loop0.sw_if_index)
43         self.vapi.app_namespace_add_del(namespace_id="1",
44                                         sw_if_index=self.loop1.sw_if_index)
45
46     def tearDown(self):
47         for i in self.lo_interfaces:
48             i.unconfig_ip4()
49             i.set_table_ip4(0)
50             i.admin_down()
51         self.vapi.session_enable_disable(is_enable=0)
52         super(TestTCP, self).tearDown()
53
54     def test_tcp_transfer(self):
55         """ TCP echo client/server transfer """
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"
71         error = self.vapi.cli("test echo server appns 0 fifo-size 4 uri " +
72                               uri)
73         if error:
74             self.logger.critical(error)
75             self.assertNotIn("failed", error)
76
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)
80         if error:
81             self.logger.critical(error)
82             self.assertNotIn("failed", error)
83
84         # Delete inter-table routes
85         ip_t01.remove_vpp_config()
86         ip_t10.remove_vpp_config()
87
88
89 class TestTCPUnitTests(VppTestCase):
90     "TCP Unit Tests"
91
92     @classmethod
93     def setUpClass(cls):
94         super(TestTCPUnitTests, cls).setUpClass()
95
96     @classmethod
97     def tearDownClass(cls):
98         super(TestTCPUnitTests, cls).tearDownClass()
99
100     def setUp(self):
101         super(TestTCPUnitTests, self).setUp()
102         self.vapi.session_enable_disable(is_enable=1)
103
104     def tearDown(self):
105         super(TestTCPUnitTests, self).tearDown()
106         self.vapi.session_enable_disable(is_enable=0)
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)
114         self.assertNotIn("failed", error)
115
116 if __name__ == '__main__':
117     unittest.main(testRunner=VppTestRunner)