blob: 678d2cca8b8235c10a92e6a29a1383e77b39a12b [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
Pratikshya Prasai657bdf72022-08-18 11:09:38 -04005from asfframework import VppTestCase, VppTestRunner
Florin Corasb795bd02017-12-14 11:30:48 -08006from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
Florin Coras3ea6ce22017-12-11 09:09:05 -08007
8
9class TestTCP(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020010 """TCP Test Case"""
Florin Coras3ea6ce22017-12-11 09:09:05 -080011
12 @classmethod
13 def setUpClass(cls):
14 super(TestTCP, cls).setUpClass()
15
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070016 @classmethod
17 def tearDownClass(cls):
18 super(TestTCP, cls).tearDownClass()
19
Florin Coras3ea6ce22017-12-11 09:09:05 -080020 def setUp(self):
21 super(TestTCP, self).setUp()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +010022 self.vapi.session_enable_disable(is_enable=1)
Klement Sekerab9ef2732018-06-24 22:49:33 +020023 self.create_loopback_interfaces(2)
Florin Corasb795bd02017-12-14 11:30:48 -080024
25 table_id = 0
26
27 for i in self.lo_interfaces:
28 i.admin_up()
29
30 if table_id != 0:
31 tbl = VppIpTable(self, table_id)
32 tbl.add_vpp_config()
33
34 i.set_table_ip4(table_id)
35 i.config_ip4()
36 table_id += 1
37
38 # Configure namespaces
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020039 self.vapi.app_namespace_add_del(
40 namespace_id="0", sw_if_index=self.loop0.sw_if_index
41 )
42 self.vapi.app_namespace_add_del(
43 namespace_id="1", sw_if_index=self.loop1.sw_if_index
44 )
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):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020055 """TCP echo client/server transfer"""
Florin Corasb795bd02017-12-14 11:30:48 -080056
57 # Add inter-table routes
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020058 ip_t01 = VppIpRoute(
59 self,
60 self.loop1.local_ip4,
61 32,
62 [VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=1)],
63 )
64 ip_t10 = VppIpRoute(
65 self,
66 self.loop0.local_ip4,
67 32,
68 [VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=0)],
69 table_id=1,
70 )
Florin Corasb795bd02017-12-14 11:30:48 -080071 ip_t01.add_vpp_config()
72 ip_t10.add_vpp_config()
73
74 # Start builtin server and client
75 uri = "tcp://" + self.loop0.local_ip4 + "/1234"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020076 error = self.vapi.cli("test echo server appns 0 fifo-size 4 uri " + uri)
Florin Corasb795bd02017-12-14 11:30:48 -080077 if error:
78 self.logger.critical(error)
Paul Vinciguerra9a6dafd2019-03-06 15:11:28 -080079 self.assertNotIn("failed", error)
Florin Corasb795bd02017-12-14 11:30:48 -080080
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020081 error = self.vapi.cli(
82 "test echo client mbytes 10 appns 1 "
83 + "fifo-size 4 no-output test-bytes "
84 + "syn-timeout 2 uri "
85 + uri
86 )
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
91 # Delete inter-table routes
92 ip_t01.remove_vpp_config()
93 ip_t10.remove_vpp_config()
Florin Coras3ea6ce22017-12-11 09:09:05 -080094
Florin Corasa8f53812018-11-08 13:58:19 -080095
96class TestTCPUnitTests(VppTestCase):
97 "TCP Unit Tests"
98
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070099 @classmethod
100 def setUpClass(cls):
101 super(TestTCPUnitTests, cls).setUpClass()
102
103 @classmethod
104 def tearDownClass(cls):
105 super(TestTCPUnitTests, cls).tearDownClass()
106
Florin Corasa8f53812018-11-08 13:58:19 -0800107 def setUp(self):
108 super(TestTCPUnitTests, self).setUp()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +0100109 self.vapi.session_enable_disable(is_enable=1)
Florin Corasa8f53812018-11-08 13:58:19 -0800110
111 def tearDown(self):
112 super(TestTCPUnitTests, self).tearDown()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +0100113 self.vapi.session_enable_disable(is_enable=0)
Florin Corasa8f53812018-11-08 13:58:19 -0800114
115 def test_tcp_unittest(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200116 """TCP Unit Tests"""
Florin Corasa8f53812018-11-08 13:58:19 -0800117 error = self.vapi.cli("test tcp all")
118
119 if error:
120 self.logger.critical(error)
Paul Vinciguerra9a6dafd2019-03-06 15:11:28 -0800121 self.assertNotIn("failed", error)
Florin Corasa8f53812018-11-08 13:58:19 -0800122
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200123
124if __name__ == "__main__":
Florin Coras3ea6ce22017-12-11 09:09:05 -0800125 unittest.main(testRunner=VppTestRunner)