blob: 4ceb46e666cdc8b6fe8e44fbfdf9c1028b65d612 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Florin Coras3ea6ce22017-12-11 09:09:05 -08002
3import unittest
4
Andrew Yourtchenko8dc0d482021-01-29 13:17:19 +00005from framework import tag_fixme_vpp_workers
Florin Coras3ea6ce22017-12-11 09:09:05 -08006from framework import VppTestCase, VppTestRunner
Florin Corasb795bd02017-12-14 11:30:48 -08007from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
Florin Coras3ea6ce22017-12-11 09:09:05 -08008
9
Andrew Yourtchenko8dc0d482021-01-29 13:17:19 +000010@tag_fixme_vpp_workers
Florin Coras3ea6ce22017-12-11 09:09:05 -080011class TestTCP(VppTestCase):
12 """ TCP Test Case """
13
14 @classmethod
15 def setUpClass(cls):
16 super(TestTCP, cls).setUpClass()
17
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070018 @classmethod
19 def tearDownClass(cls):
20 super(TestTCP, cls).tearDownClass()
21
Florin Coras3ea6ce22017-12-11 09:09:05 -080022 def setUp(self):
23 super(TestTCP, self).setUp()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +010024 self.vapi.session_enable_disable(is_enable=1)
Klement Sekerab9ef2732018-06-24 22:49:33 +020025 self.create_loopback_interfaces(2)
Florin Corasb795bd02017-12-14 11:30:48 -080026
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
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010041 self.vapi.app_namespace_add_del(namespace_id="0",
Ole Troane1ade682019-03-04 23:55:43 +010042 sw_if_index=self.loop0.sw_if_index)
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010043 self.vapi.app_namespace_add_del(namespace_id="1",
Ole Troane1ade682019-03-04 23:55:43 +010044 sw_if_index=self.loop1.sw_if_index)
Florin Coras3ea6ce22017-12-11 09:09:05 -080045
46 def tearDown(self):
Florin Corasb795bd02017-12-14 11:30:48 -080047 for i in self.lo_interfaces:
48 i.unconfig_ip4()
49 i.set_table_ip4(0)
50 i.admin_down()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +010051 self.vapi.session_enable_disable(is_enable=0)
Florin Coras3ea6ce22017-12-11 09:09:05 -080052 super(TestTCP, self).tearDown()
53
Florin Corasb795bd02017-12-14 11:30:48 -080054 def test_tcp_transfer(self):
Florin Coras4399c2e2018-01-25 06:34:42 -080055 """ TCP echo client/server transfer """
Florin Corasb795bd02017-12-14 11:30:48 -080056
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"
Florin Coras4399c2e2018-01-25 06:34:42 -080071 error = self.vapi.cli("test echo server appns 0 fifo-size 4 uri " +
Florin Corasb795bd02017-12-14 11:30:48 -080072 uri)
73 if error:
74 self.logger.critical(error)
Paul Vinciguerra9a6dafd2019-03-06 15:11:28 -080075 self.assertNotIn("failed", error)
Florin Corasb795bd02017-12-14 11:30:48 -080076
Florin Coras4399c2e2018-01-25 06:34:42 -080077 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)
Florin Corasb795bd02017-12-14 11:30:48 -080080 if error:
81 self.logger.critical(error)
Paul Vinciguerra9a6dafd2019-03-06 15:11:28 -080082 self.assertNotIn("failed", error)
Florin Corasb795bd02017-12-14 11:30:48 -080083
84 # Delete inter-table routes
85 ip_t01.remove_vpp_config()
86 ip_t10.remove_vpp_config()
Florin Coras3ea6ce22017-12-11 09:09:05 -080087
Florin Corasa8f53812018-11-08 13:58:19 -080088
89class TestTCPUnitTests(VppTestCase):
90 "TCP Unit Tests"
91
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070092 @classmethod
93 def setUpClass(cls):
94 super(TestTCPUnitTests, cls).setUpClass()
95
96 @classmethod
97 def tearDownClass(cls):
98 super(TestTCPUnitTests, cls).tearDownClass()
99
Florin Corasa8f53812018-11-08 13:58:19 -0800100 def setUp(self):
101 super(TestTCPUnitTests, self).setUp()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +0100102 self.vapi.session_enable_disable(is_enable=1)
Florin Corasa8f53812018-11-08 13:58:19 -0800103
104 def tearDown(self):
105 super(TestTCPUnitTests, self).tearDown()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +0100106 self.vapi.session_enable_disable(is_enable=0)
Florin Corasa8f53812018-11-08 13:58:19 -0800107
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)
Paul Vinciguerra9a6dafd2019-03-06 15:11:28 -0800114 self.assertNotIn("failed", error)
Florin Corasa8f53812018-11-08 13:58:19 -0800115
Florin Coras3ea6ce22017-12-11 09:09:05 -0800116if __name__ == '__main__':
117 unittest.main(testRunner=VppTestRunner)