blob: 2f8edd4e0e2721b841e5f863162c09d896437a18 [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"
26 p = subprocess.Popen(ssl, stdin=subprocess.PIPE,
27 stdout=subprocess.PIPE, shell=True)
28 p.wait()
29 output = p.stdout.read()
30 status = p.returncode
31
32 if status:
Paul Vinciguerra3f7b0f42019-12-26 19:13:02 -050033 pass
34 # print("openssl version error!")
haiyanx1.zhang419d31f2019-10-12 08:44:44 +000035 else:
36 ssl_ver_src = re.findall(r"(\d+)\.+\d+.+\d+", output)
37 ssl_ver = int(ssl_ver_src[0])
38 if ssl_ver < 3:
39 ret = False
40 else:
41 ret = True
42 else:
Paul Vinciguerra3f7b0f42019-12-26 19:13:02 -050043 # print("NO OPENSSL_ROOT_DIR!")
44 pass
haiyanx1.zhang419d31f2019-10-12 08:44:44 +000045
46 return ret
47
48
49def checkAll():
50 ret = checkQat() & checkOpenSSLVersion()
51 return ret
52
53
54class TestTLS(VppTestCase):
55 """ TLS Qat Test Case. """
56
57 @classmethod
58 def setUpClass(cls):
59 super(TestTLS, cls).setUpClass()
60
61 @classmethod
62 def tearDownClass(cls):
63 super(TestTLS, cls).tearDownClass()
64
65 def setUp(self):
66 super(TestTLS, self).setUp()
67
Jakub Grajciar6a2794e2020-11-24 11:22:01 +010068 self.vapi.session_enable_disable(is_enable=1)
haiyanx1.zhang419d31f2019-10-12 08:44:44 +000069 self.create_loopback_interfaces(2)
70
71 table_id = 0
72
73 for i in self.lo_interfaces:
74 i.admin_up()
75
76 if table_id != 0:
77 tbl = VppIpTable(self, table_id)
78 tbl.add_vpp_config()
79
80 i.set_table_ip4(table_id)
81 i.config_ip4()
82 table_id += 1
83
84 # Configure namespaces
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010085 self.vapi.app_namespace_add_del(namespace_id="0",
haiyanx1.zhang419d31f2019-10-12 08:44:44 +000086 sw_if_index=self.loop0.sw_if_index)
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010087 self.vapi.app_namespace_add_del(namespace_id="1",
haiyanx1.zhang419d31f2019-10-12 08:44:44 +000088 sw_if_index=self.loop1.sw_if_index)
89
90 def tearDown(self):
91 for i in self.lo_interfaces:
92 i.unconfig_ip4()
93 i.set_table_ip4(0)
94 i.admin_down()
Jakub Grajciar6a2794e2020-11-24 11:22:01 +010095 self.vapi.session_enable_disable(is_enable=0)
haiyanx1.zhang419d31f2019-10-12 08:44:44 +000096 super(TestTLS, self).tearDown()
97
98 @unittest.skipUnless(checkAll(),
99 "QAT or OpenSSL not satisfied,skip.")
100 def test_tls_transfer(self):
101 """ TLS qat echo client/server transfer """
102
103 # Add inter-table routes
104 ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32,
105 [VppRoutePath("0.0.0.0",
106 0xffffffff,
107 nh_table_id=1)])
108
109 ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32,
110 [VppRoutePath("0.0.0.0",
111 0xffffffff,
112 nh_table_id=0)], table_id=1)
113 ip_t01.add_vpp_config()
114 ip_t10.add_vpp_config()
115
116 # Enable QAT engine and TLS async
117 r = self.vapi.tls_openssl_set_engine(
118 async_enable=1,
119 engine="qat",
120 algorithm="RSA,PKEY_CRYPTO",
121 ciphers="RSA")
122 self.assertIsNotNone(r,
123 'No response msg ')
124
125 # Start builtin server and client
126 uri = "tls://" + self.loop0.local_ip4 + "/1234"
127 error = self.vapi.cli("test echo server appns 0 fifo-size 4 "
128 "tls-engine 1 uri " +
129 uri)
130 if error:
131 self.logger.critical(error)
132 self.assertNotIn("failed", error)
133
134 error = self.vapi.cli("test echo client mbytes 10 appns 1 "
135 "fifo-size 4 no-output test-bytes "
136 "tls-engine 1 "
137 "syn-timeout 2 uri " + uri)
138 if error:
139 self.logger.critical(error)
140 self.assertNotIn("failed", error)
141
142 # Delete inter-table routes
143 ip_t01.remove_vpp_config()
144 ip_t10.remove_vpp_config()
145
Paul Vinciguerra3f7b0f42019-12-26 19:13:02 -0500146
haiyanx1.zhang419d31f2019-10-12 08:44:44 +0000147if __name__ == '__main__':
148 unittest.main(testRunner=VppTestRunner)