blob: 23772d34c76b7871ca82974263fad2854385cf8a [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
Dave Wallace8800f732023-08-31 00:47:44 -04005from asfframework import VppAsfTestCase, VppTestRunner
Florin Corasb795bd02017-12-14 11:30:48 -08006from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
Dmitry Valter34fa0ce2024-03-11 10:38:46 +00007from config import config
Florin Coras3ea6ce22017-12-11 09:09:05 -08008
9
Dmitry Valter34fa0ce2024-03-11 10:38:46 +000010@unittest.skipIf(
11 "hs_apps" in config.excluded_plugins, "Exclude tests requiring hs_apps plugin"
12)
Dave Wallace8800f732023-08-31 00:47:44 -040013class TestTCP(VppAsfTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020014 """TCP Test Case"""
Florin Coras3ea6ce22017-12-11 09:09:05 -080015
16 @classmethod
17 def setUpClass(cls):
18 super(TestTCP, cls).setUpClass()
19
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070020 @classmethod
21 def tearDownClass(cls):
22 super(TestTCP, cls).tearDownClass()
23
Florin Coras3ea6ce22017-12-11 09:09:05 -080024 def setUp(self):
25 super(TestTCP, self).setUp()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +010026 self.vapi.session_enable_disable(is_enable=1)
Klement Sekerab9ef2732018-06-24 22:49:33 +020027 self.create_loopback_interfaces(2)
Florin Corasb795bd02017-12-14 11:30:48 -080028
29 table_id = 0
30
31 for i in self.lo_interfaces:
32 i.admin_up()
33
34 if table_id != 0:
35 tbl = VppIpTable(self, table_id)
36 tbl.add_vpp_config()
37
38 i.set_table_ip4(table_id)
39 i.config_ip4()
40 table_id += 1
41
42 # Configure namespaces
Nathan Skrzypczak51f1b262023-04-27 12:43:46 +020043 self.vapi.app_namespace_add_del_v4(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020044 namespace_id="0", sw_if_index=self.loop0.sw_if_index
45 )
Nathan Skrzypczak51f1b262023-04-27 12:43:46 +020046 self.vapi.app_namespace_add_del_v4(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020047 namespace_id="1", sw_if_index=self.loop1.sw_if_index
48 )
Florin Coras3ea6ce22017-12-11 09:09:05 -080049
50 def tearDown(self):
Steven Luong67bae202024-07-08 11:21:23 -070051 self.vapi.app_namespace_add_del_v4(
52 is_add=0, namespace_id="0", sw_if_index=self.loop0.sw_if_index
53 )
54 self.vapi.app_namespace_add_del_v4(
55 is_add=0, namespace_id="1", sw_if_index=self.loop1.sw_if_index
56 )
Florin Corasb795bd02017-12-14 11:30:48 -080057 for i in self.lo_interfaces:
58 i.unconfig_ip4()
59 i.set_table_ip4(0)
60 i.admin_down()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +010061 self.vapi.session_enable_disable(is_enable=0)
Florin Coras3ea6ce22017-12-11 09:09:05 -080062 super(TestTCP, self).tearDown()
63
Florin Corasb795bd02017-12-14 11:30:48 -080064 def test_tcp_transfer(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020065 """TCP echo client/server transfer"""
Florin Corasb795bd02017-12-14 11:30:48 -080066
67 # Add inter-table routes
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020068 ip_t01 = VppIpRoute(
69 self,
70 self.loop1.local_ip4,
71 32,
72 [VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=1)],
73 )
74 ip_t10 = VppIpRoute(
75 self,
76 self.loop0.local_ip4,
77 32,
78 [VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=0)],
79 table_id=1,
80 )
Florin Corasb795bd02017-12-14 11:30:48 -080081 ip_t01.add_vpp_config()
82 ip_t10.add_vpp_config()
83
84 # Start builtin server and client
85 uri = "tcp://" + self.loop0.local_ip4 + "/1234"
Filip Tehlarefe875e2023-09-04 14:17:52 +020086 error = self.vapi.cli("test echo server appns 0 fifo-size 4k uri " + uri)
Florin Corasb795bd02017-12-14 11:30:48 -080087 if error:
88 self.logger.critical(error)
Paul Vinciguerra9a6dafd2019-03-06 15:11:28 -080089 self.assertNotIn("failed", error)
Florin Corasb795bd02017-12-14 11:30:48 -080090
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020091 error = self.vapi.cli(
92 "test echo client mbytes 10 appns 1 "
Filip Tehlarefe875e2023-09-04 14:17:52 +020093 + "fifo-size 4k test-bytes "
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020094 + "syn-timeout 2 uri "
95 + uri
96 )
Florin Corasb795bd02017-12-14 11:30:48 -080097 if error:
98 self.logger.critical(error)
Paul Vinciguerra9a6dafd2019-03-06 15:11:28 -080099 self.assertNotIn("failed", error)
Florin Corasb795bd02017-12-14 11:30:48 -0800100
101 # Delete inter-table routes
102 ip_t01.remove_vpp_config()
103 ip_t10.remove_vpp_config()
Florin Coras3ea6ce22017-12-11 09:09:05 -0800104
Florin Corasa8f53812018-11-08 13:58:19 -0800105
Dave Wallace8800f732023-08-31 00:47:44 -0400106class TestTCPUnitTests(VppAsfTestCase):
Florin Corasa8f53812018-11-08 13:58:19 -0800107 "TCP Unit Tests"
108
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700109 @classmethod
110 def setUpClass(cls):
111 super(TestTCPUnitTests, cls).setUpClass()
112
113 @classmethod
114 def tearDownClass(cls):
115 super(TestTCPUnitTests, cls).tearDownClass()
116
Florin Corasa8f53812018-11-08 13:58:19 -0800117 def setUp(self):
118 super(TestTCPUnitTests, self).setUp()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +0100119 self.vapi.session_enable_disable(is_enable=1)
Florin Corasa8f53812018-11-08 13:58:19 -0800120
121 def tearDown(self):
122 super(TestTCPUnitTests, self).tearDown()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +0100123 self.vapi.session_enable_disable(is_enable=0)
Florin Corasa8f53812018-11-08 13:58:19 -0800124
125 def test_tcp_unittest(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200126 """TCP Unit Tests"""
Florin Corasa8f53812018-11-08 13:58:19 -0800127 error = self.vapi.cli("test tcp all")
128
129 if error:
130 self.logger.critical(error)
Paul Vinciguerra9a6dafd2019-03-06 15:11:28 -0800131 self.assertNotIn("failed", error)
Florin Corasa8f53812018-11-08 13:58:19 -0800132
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200133
134if __name__ == "__main__":
Florin Coras3ea6ce22017-12-11 09:09:05 -0800135 unittest.main(testRunner=VppTestRunner)