blob: 2ce87143339504f456da3d4882b3c614fae88869 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
haiyanx1.zhang419d31f2019-10-12 08:44:44 +00002
3import unittest
4import os
5import re
6import subprocess
7
Dave Wallace8800f732023-08-31 00:47:44 -04008from asfframework import VppAsfTestCase, VppTestRunner
haiyanx1.zhang419d31f2019-10-12 08:44:44 +00009from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
10
11
12def checkQat():
13 r = os.path.exists("/dev/qat_dev_processes")
14 if r:
15 return True
16 else:
Paul Vinciguerra3f7b0f42019-12-26 19:13:02 -050017 # print("NO QAT! EXIT!")
haiyanx1.zhang419d31f2019-10-12 08:44:44 +000018 return False
19
20
21def checkOpenSSLVersion():
22 ret = False
23 r = "OPENSSL_ROOT_DIR" in os.environ
24 if r:
25 ssl = os.environ["OPENSSL_ROOT_DIR"] + "/bin/openssl version"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020026 p = subprocess.Popen(
27 ssl, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True
28 )
haiyanx1.zhang419d31f2019-10-12 08:44:44 +000029 p.wait()
30 output = p.stdout.read()
31 status = p.returncode
32
33 if status:
Paul Vinciguerra3f7b0f42019-12-26 19:13:02 -050034 pass
35 # print("openssl version error!")
haiyanx1.zhang419d31f2019-10-12 08:44:44 +000036 else:
37 ssl_ver_src = re.findall(r"(\d+)\.+\d+.+\d+", output)
38 ssl_ver = int(ssl_ver_src[0])
39 if ssl_ver < 3:
40 ret = False
41 else:
42 ret = True
43 else:
Paul Vinciguerra3f7b0f42019-12-26 19:13:02 -050044 # print("NO OPENSSL_ROOT_DIR!")
45 pass
haiyanx1.zhang419d31f2019-10-12 08:44:44 +000046
47 return ret
48
49
50def checkAll():
51 ret = checkQat() & checkOpenSSLVersion()
52 return ret
53
54
Dave Wallace8800f732023-08-31 00:47:44 -040055class TestTLS(VppAsfTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020056 """TLS Qat Test Case."""
haiyanx1.zhang419d31f2019-10-12 08:44:44 +000057
58 @classmethod
59 def setUpClass(cls):
60 super(TestTLS, cls).setUpClass()
61
62 @classmethod
63 def tearDownClass(cls):
64 super(TestTLS, cls).tearDownClass()
65
66 def setUp(self):
67 super(TestTLS, self).setUp()
68
Jakub Grajciar6a2794e2020-11-24 11:22:01 +010069 self.vapi.session_enable_disable(is_enable=1)
haiyanx1.zhang419d31f2019-10-12 08:44:44 +000070 self.create_loopback_interfaces(2)
71
72 table_id = 0
73
74 for i in self.lo_interfaces:
75 i.admin_up()
76
77 if table_id != 0:
78 tbl = VppIpTable(self, table_id)
79 tbl.add_vpp_config()
80
81 i.set_table_ip4(table_id)
82 i.config_ip4()
83 table_id += 1
84
85 # Configure namespaces
Nathan Skrzypczak51f1b262023-04-27 12:43:46 +020086 self.vapi.app_namespace_add_del_v4(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020087 namespace_id="0", sw_if_index=self.loop0.sw_if_index
88 )
Nathan Skrzypczak51f1b262023-04-27 12:43:46 +020089 self.vapi.app_namespace_add_del_v4(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020090 namespace_id="1", sw_if_index=self.loop1.sw_if_index
91 )
haiyanx1.zhang419d31f2019-10-12 08:44:44 +000092
93 def tearDown(self):
Steven Luong67bae202024-07-08 11:21:23 -070094 self.vapi.app_namespace_add_del_v4(
95 is_add=0, namespace_id="0", sw_if_index=self.loop0.sw_if_index
96 )
97 self.vapi.app_namespace_add_del_v4(
98 is_add=0, namespace_id="1", sw_if_index=self.loop1.sw_if_index
99 )
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000100 for i in self.lo_interfaces:
101 i.unconfig_ip4()
102 i.set_table_ip4(0)
103 i.admin_down()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +0100104 self.vapi.session_enable_disable(is_enable=0)
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000105 super(TestTLS, self).tearDown()
106
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200107 @unittest.skipUnless(checkAll(), "QAT or OpenSSL not satisfied,skip.")
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000108 def test_tls_transfer(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200109 """TLS qat echo client/server transfer"""
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000110
111 # Add inter-table routes
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200112 ip_t01 = VppIpRoute(
113 self,
114 self.loop1.local_ip4,
115 32,
116 [VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=1)],
117 )
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000118
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200119 ip_t10 = VppIpRoute(
120 self,
121 self.loop0.local_ip4,
122 32,
123 [VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=0)],
124 table_id=1,
125 )
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000126 ip_t01.add_vpp_config()
127 ip_t10.add_vpp_config()
128
129 # Enable QAT engine and TLS async
130 r = self.vapi.tls_openssl_set_engine(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200131 async_enable=1, engine="qat", algorithm="RSA,PKEY_CRYPTO", ciphers="RSA"
132 )
133 self.assertIsNotNone(r, "No response msg ")
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000134
135 # Start builtin server and client
136 uri = "tls://" + self.loop0.local_ip4 + "/1234"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200137 error = self.vapi.cli(
Filip Tehlarefe875e2023-09-04 14:17:52 +0200138 "test echo server appns 0 fifo-size 4k tls-engine 1 uri " + uri
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200139 )
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000140 if error:
141 self.logger.critical(error)
142 self.assertNotIn("failed", error)
143
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200144 error = self.vapi.cli(
145 "test echo client mbytes 10 appns 1 "
Filip Tehlarefe875e2023-09-04 14:17:52 +0200146 "fifo-size 4k test-bytes "
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200147 "tls-engine 1 "
148 "syn-timeout 2 uri " + uri
149 )
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000150 if error:
151 self.logger.critical(error)
152 self.assertNotIn("failed", error)
153
154 # Delete inter-table routes
155 ip_t01.remove_vpp_config()
156 ip_t10.remove_vpp_config()
157
Paul Vinciguerra3f7b0f42019-12-26 19:13:02 -0500158
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200159if __name__ == "__main__":
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000160 unittest.main(testRunner=VppTestRunner)