blob: 301cddf50822bb4c58ea918e3fb32cc6ce2075b5 [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
8from framework import VppTestCase, VppTestRunner
9from 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
55class TestTLS(VppTestCase):
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
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020086 self.vapi.app_namespace_add_del(
87 namespace_id="0", sw_if_index=self.loop0.sw_if_index
88 )
89 self.vapi.app_namespace_add_del(
90 namespace_id="1", sw_if_index=self.loop1.sw_if_index
91 )
haiyanx1.zhang419d31f2019-10-12 08:44:44 +000092
93 def tearDown(self):
94 for i in self.lo_interfaces:
95 i.unconfig_ip4()
96 i.set_table_ip4(0)
97 i.admin_down()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +010098 self.vapi.session_enable_disable(is_enable=0)
haiyanx1.zhang419d31f2019-10-12 08:44:44 +000099 super(TestTLS, self).tearDown()
100
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200101 @unittest.skipUnless(checkAll(), "QAT or OpenSSL not satisfied,skip.")
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000102 def test_tls_transfer(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200103 """TLS qat echo client/server transfer"""
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000104
105 # Add inter-table routes
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200106 ip_t01 = VppIpRoute(
107 self,
108 self.loop1.local_ip4,
109 32,
110 [VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=1)],
111 )
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000112
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200113 ip_t10 = VppIpRoute(
114 self,
115 self.loop0.local_ip4,
116 32,
117 [VppRoutePath("0.0.0.0", 0xFFFFFFFF, nh_table_id=0)],
118 table_id=1,
119 )
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000120 ip_t01.add_vpp_config()
121 ip_t10.add_vpp_config()
122
123 # Enable QAT engine and TLS async
124 r = self.vapi.tls_openssl_set_engine(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200125 async_enable=1, engine="qat", algorithm="RSA,PKEY_CRYPTO", ciphers="RSA"
126 )
127 self.assertIsNotNone(r, "No response msg ")
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000128
129 # Start builtin server and client
130 uri = "tls://" + self.loop0.local_ip4 + "/1234"
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200131 error = self.vapi.cli(
132 "test echo server appns 0 fifo-size 4 tls-engine 1 uri " + uri
133 )
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000134 if error:
135 self.logger.critical(error)
136 self.assertNotIn("failed", error)
137
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200138 error = self.vapi.cli(
139 "test echo client mbytes 10 appns 1 "
140 "fifo-size 4 no-output test-bytes "
141 "tls-engine 1 "
142 "syn-timeout 2 uri " + uri
143 )
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000144 if error:
145 self.logger.critical(error)
146 self.assertNotIn("failed", error)
147
148 # Delete inter-table routes
149 ip_t01.remove_vpp_config()
150 ip_t10.remove_vpp_config()
151
Paul Vinciguerra3f7b0f42019-12-26 19:13:02 -0500152
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200153if __name__ == "__main__":
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000154 unittest.main(testRunner=VppTestRunner)