blob: d5bbccd26aaddc523e06eeba6791fb76dd95aef6 [file] [log] [blame]
Dave Wallacecfcf2f42018-02-16 18:31:56 -05001#!/usr/bin/env python
2""" Vpp VCL tests """
3
4import unittest
5import os
6import signal
Dave Wallaced85075e2018-03-02 13:19:30 -05007from framework import VppTestCase, VppTestRunner, running_extended_tests, \
8 Worker
Dave Wallacea67a03e2018-02-20 12:39:37 -05009from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
Dave Wallacecfcf2f42018-02-16 18:31:56 -050010
11
Dave Wallace42996c02018-02-26 14:40:13 -050012class VclAppWorker(Worker):
13 """ VCL Test Application Worker """
14
Dave Wallaced85075e2018-03-02 13:19:30 -050015 def __init__(self, build_dir, appname, args, logger, env={}):
Dave Wallace9f11c012018-02-28 17:55:23 -050016 vcl_lib_dir = "%s/vpp/.libs" % build_dir
17 app = "%s/%s" % (vcl_lib_dir, appname)
18 if not os.path.isfile(app):
19 app = "%s/vpp/%s" % (build_dir, appname)
20 env.update({'LD_PRELOAD':
21 "%s/libvcl_ldpreload.so.0.0.0" % vcl_lib_dir})
22 self.args = [app] + args
Dave Wallace42996c02018-02-26 14:40:13 -050023 super(VclAppWorker, self).__init__(self.args, logger, env)
24
25
26class VclTestCase(VppTestCase):
27 """ VCL Test Class """
28
Dave Wallace9f11c012018-02-28 17:55:23 -050029 def __init__(self, methodName):
Dave Wallaced85075e2018-03-02 13:19:30 -050030 var = "VPP_TEST_BUILD_DIR"
31 self.build_dir = os.getenv(var, None)
32 if self.build_dir is None:
33 raise Exception("Environment variable `%s' not set" % var)
34 self.vppDebug = 'vpp_debug' in self.build_dir
Dave Wallace9f11c012018-02-28 17:55:23 -050035 self.server_addr = "127.0.0.1"
36 self.server_port = "22000"
37 self.timeout = 3
38 self.echo_phrase = "Hello, world! Jenny is a friend of mine."
Dave Wallace42996c02018-02-26 14:40:13 -050039
Dave Wallace9f11c012018-02-28 17:55:23 -050040 super(VclTestCase, self).__init__(methodName)
Dave Wallace42996c02018-02-26 14:40:13 -050041
Dave Wallace9f11c012018-02-28 17:55:23 -050042 def cut_thru_setup(self):
Dave Wallacea67a03e2018-02-20 12:39:37 -050043 self.vapi.session_enable_disable(is_enabled=1)
44
Dave Wallace9f11c012018-02-28 17:55:23 -050045 def cut_thru_tear_down(self):
Dave Wallacea67a03e2018-02-20 12:39:37 -050046 self.vapi.session_enable_disable(is_enabled=0)
47
Dave Wallace9f11c012018-02-28 17:55:23 -050048 def cut_thru_test(self, server_app, client_app, client_args):
Dave Wallace42996c02018-02-26 14:40:13 -050049 self.env = {'VCL_API_PREFIX': self.shm_prefix,
50 'VCL_APP_SCOPE_LOCAL': "true"}
51
Dave Wallaced85075e2018-03-02 13:19:30 -050052 worker_server = VclAppWorker(self.build_dir, server_app,
53 [self.server_port],
Dave Wallace42996c02018-02-26 14:40:13 -050054 self.logger, self.env)
Dave Wallacecfcf2f42018-02-16 18:31:56 -050055 worker_server.start()
Dave Wallace42996c02018-02-26 14:40:13 -050056 self.sleep(0.2)
Dave Wallaced85075e2018-03-02 13:19:30 -050057 worker_client = VclAppWorker(self.build_dir, client_app, client_args,
Dave Wallace42996c02018-02-26 14:40:13 -050058 self.logger, self.env)
Dave Wallacecfcf2f42018-02-16 18:31:56 -050059 worker_client.start()
Dave Wallace42996c02018-02-26 14:40:13 -050060 worker_client.join(self.timeout)
61 self.validateResults(worker_client, worker_server, self.timeout)
Dave Wallacecfcf2f42018-02-16 18:31:56 -050062
Dave Wallace9f11c012018-02-28 17:55:23 -050063 def thru_host_stack_setup(self):
Dave Wallacea67a03e2018-02-20 12:39:37 -050064 self.vapi.session_enable_disable(is_enabled=1)
65 self.create_loopback_interfaces(range(2))
66
67 table_id = 0
68
69 for i in self.lo_interfaces:
70 i.admin_up()
71
72 if table_id != 0:
73 tbl = VppIpTable(self, table_id)
74 tbl.add_vpp_config()
75
76 i.set_table_ip4(table_id)
77 i.config_ip4()
78 table_id += 1
79
80 # Configure namespaces
Dave Wallace42996c02018-02-26 14:40:13 -050081 self.vapi.app_namespace_add(namespace_id="0", secret=1234,
Dave Wallacea67a03e2018-02-20 12:39:37 -050082 sw_if_index=self.loop0.sw_if_index)
Dave Wallace42996c02018-02-26 14:40:13 -050083 self.vapi.app_namespace_add(namespace_id="1", secret=5678,
Dave Wallacea67a03e2018-02-20 12:39:37 -050084 sw_if_index=self.loop1.sw_if_index)
85
Dave Wallacea67a03e2018-02-20 12:39:37 -050086 # Add inter-table routes
87 ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32,
88 [VppRoutePath("0.0.0.0",
89 0xffffffff,
90 nh_table_id=1)])
91 ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32,
92 [VppRoutePath("0.0.0.0",
93 0xffffffff,
94 nh_table_id=0)], table_id=1)
95 ip_t01.add_vpp_config()
96 ip_t10.add_vpp_config()
97
Dave Wallace9f11c012018-02-28 17:55:23 -050098 def thru_host_stack_tear_down(self):
99 for i in self.lo_interfaces:
100 i.unconfig_ip4()
101 i.set_table_ip4(0)
102 i.admin_down()
103
104 self.vapi.session_enable_disable(is_enabled=0)
105
106 def thru_host_stack_test(self, server_app, client_app, client_args):
107 self.env = {'VCL_API_PREFIX': self.shm_prefix,
108 'VCL_APP_SCOPE_GLOBAL': "true",
109 'VCL_APP_NAMESPACE_ID': "0",
110 'VCL_APP_NAMESPACE_SECRET': "1234"}
111
Dave Wallaced85075e2018-03-02 13:19:30 -0500112 worker_server = VclAppWorker(self.build_dir, server_app,
113 [self.server_port],
Dave Wallace42996c02018-02-26 14:40:13 -0500114 self.logger, self.env)
Dave Wallacea67a03e2018-02-20 12:39:37 -0500115 worker_server.start()
Dave Wallace42996c02018-02-26 14:40:13 -0500116 self.sleep(0.2)
117
118 self.env.update({'VCL_APP_NAMESPACE_ID': "1",
119 'VCL_APP_NAMESPACE_SECRET': "5678"})
Dave Wallaced85075e2018-03-02 13:19:30 -0500120 worker_client = VclAppWorker(self.build_dir, client_app, client_args,
Dave Wallace42996c02018-02-26 14:40:13 -0500121 self.logger, self.env)
Dave Wallacea67a03e2018-02-20 12:39:37 -0500122 worker_client.start()
Dave Wallace42996c02018-02-26 14:40:13 -0500123 worker_client.join(self.timeout)
124
125 self.validateResults(worker_client, worker_server, self.timeout)
Dave Wallacea67a03e2018-02-20 12:39:37 -0500126
Dave Wallace9f11c012018-02-28 17:55:23 -0500127 def validateResults(self, worker_client, worker_server, timeout):
Dave Wallaced85075e2018-03-02 13:19:30 -0500128 if os.path.isdir('/proc/{}'.format(worker_server.process.pid)):
129 self.logger.info("Killing server worker process (pid %d)" %
130 worker_server.process.pid)
131 os.killpg(os.getpgid(worker_server.process.pid), signal.SIGTERM)
132 worker_server.join()
Dave Wallace9f11c012018-02-28 17:55:23 -0500133 self.logger.info("Client worker result is `%s'" % worker_client.result)
134 error = False
135 if worker_client.result is None:
136 try:
137 error = True
138 self.logger.error(
Dave Wallaced85075e2018-03-02 13:19:30 -0500139 "Timeout: %ss! Killing client worker process (pid %d)" %
140 (timeout, worker_client.process.pid))
Dave Wallace9f11c012018-02-28 17:55:23 -0500141 os.killpg(os.getpgid(worker_client.process.pid),
142 signal.SIGTERM)
143 worker_client.join()
144 except:
145 self.logger.debug(
146 "Couldn't kill client worker process")
147 raise
148 if error:
Dave Wallace9f11c012018-02-28 17:55:23 -0500149 raise Exception(
150 "Timeout! Client worker did not finish in %ss" % timeout)
151 self.assert_equal(worker_client.result, 0, "Binary test return code")
152
153
154class VCLCutThruTestCase(VclTestCase):
155 """ VCL Cut Thru Tests """
156
157 def setUp(self):
158 super(VCLCutThruTestCase, self).setUp()
159
160 self.cut_thru_setup()
161 self.client_echo_test_args = [self.server_addr, self.server_port,
162 "-E", self.echo_phrase, "-X"]
Dave Wallaced85075e2018-03-02 13:19:30 -0500163 self.client_uni_dir_nsock_timeout = 60
164 self.client_uni_dir_nsock_test_args = [self.server_addr,
165 self.server_port,
166 "-I", "5", "-U", "-X"]
167 self.client_bi_dir_nsock_timeout = 120
168 self.client_bi_dir_nsock_test_args = [self.server_addr,
169 self.server_port,
170 "-I", "2", "-B", "-X"]
Dave Wallace9f11c012018-02-28 17:55:23 -0500171
172 def tearDown(self):
173 self.cut_thru_tear_down()
174
175 super(VCLCutThruTestCase, self).tearDown()
176
177 def test_ldp_cut_thru_echo(self):
178 """ run LDP cut thru echo test """
179
180 self.cut_thru_test("sock_test_server", "sock_test_client",
181 self.client_echo_test_args)
182
Dave Wallaced85075e2018-03-02 13:19:30 -0500183 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
184 def test_ldp_cut_thru_uni_dir_nsock(self):
185 """ run LDP cut thru uni-directional (multiple sockets) test """
186
187 self.timeout = self.client_uni_dir_nsock_timeout
188 self.cut_thru_test("sock_test_server", "sock_test_client",
189 self.client_uni_dir_nsock_test_args)
190
191 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
192 def test_ldp_cut_thru_bi_dir_nsock(self):
193 """ run LDP cut thru bi-directional (multiple sockets) test """
194
195 self.timeout = self.client_bi_dir_nsock_timeout
196 self.cut_thru_test("sock_test_server", "sock_test_client",
197 self.client_bi_dir_nsock_test_args)
198
Dave Wallace9f11c012018-02-28 17:55:23 -0500199 def test_vcl_cut_thru_echo(self):
200 """ run VCL cut thru echo test """
201
202 self.cut_thru_test("vcl_test_server", "vcl_test_client",
203 self.client_echo_test_args)
204
Dave Wallaced85075e2018-03-02 13:19:30 -0500205 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
206 def test_vcl_cut_thru_uni_dir_nsock(self):
207 """ run VCL cut thru uni-directional (multiple sockets) test """
208
209 self.timeout = self.client_uni_dir_nsock_timeout
210 self.cut_thru_test("vcl_test_server", "vcl_test_client",
211 self.client_uni_dir_nsock_test_args)
212
213 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
214 def test_vcl_cut_thru_bi_dir_nsock(self):
215 """ run VCL cut thru bi-directional (multiple sockets) test """
216
217 self.timeout = self.client_bi_dir_nsock_timeout
218 self.cut_thru_test("vcl_test_server", "vcl_test_client",
219 self.client_bi_dir_nsock_test_args)
220
Dave Wallace9f11c012018-02-28 17:55:23 -0500221
222class VCLThruHostStackTestCase(VclTestCase):
223 """ VCL Thru Host Stack Tests """
224
225 def setUp(self):
226 super(VCLThruHostStackTestCase, self).setUp()
227
228 self.thru_host_stack_setup()
Dave Wallaced85075e2018-03-02 13:19:30 -0500229 self.client_echo_test_args = [self.loop0.local_ip4,
230 self.server_port,
Dave Wallace9f11c012018-02-28 17:55:23 -0500231 "-E", self.echo_phrase, "-X"]
232
233 def tearDown(self):
234 self.thru_host_stack_tear_down()
235
236 super(VCLThruHostStackTestCase, self).tearDown()
237
238 def test_ldp_thru_host_stack_echo(self):
239 """ run LDP thru host stack echo test """
240
241 self.thru_host_stack_test("sock_test_server", "sock_test_client",
242 self.client_echo_test_args)
Dave Wallaced85075e2018-03-02 13:19:30 -0500243 # TBD: Remove these when VPP thru host teardown config bug is fixed.
Dave Wallace9f11c012018-02-28 17:55:23 -0500244 self.thru_host_stack_test("vcl_test_server", "vcl_test_client",
245 self.client_echo_test_args)
246
247 def test_vcl_thru_host_stack_echo(self):
248 """ run VCL thru host stack echo test """
249
Dave Wallaced85075e2018-03-02 13:19:30 -0500250 # TBD: Enable this when VPP thru host teardown config bug is fixed.
Dave Wallace9f11c012018-02-28 17:55:23 -0500251 # self.thru_host_stack_test("vcl_test_server", "vcl_test_client",
252 # self.client_echo_test_args)
253
Dave Wallaced85075e2018-03-02 13:19:30 -0500254 # TBD: Remove VCLThruHostStackExtended*TestCase classes and move
255 # tests here when VPP thru host teardown/setup config bug
256 # is fixed.
257
258
259class VCLThruHostStackExtendedATestCase(VclTestCase):
260 """ VCL Thru Host Stack Extended Tests """
261
262 def setUp(self):
263 super(VCLThruHostStackExtendedATestCase, self).setUp()
264
265 self.thru_host_stack_setup()
266 if self.vppDebug:
267 self.client_bi_dir_nsock_timeout = 120
268 else:
269 self.client_bi_dir_nsock_timeout = 60
270 self.client_bi_dir_nsock_test_args = [self.loop0.local_ip4,
271 self.server_port,
272 "-I", "2", "-B", "-X"]
273
274 def tearDown(self):
275 self.thru_host_stack_tear_down()
276
277 super(VCLThruHostStackExtendedATestCase, self).tearDown()
278
279 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
280 def test_vcl_thru_host_stack_bi_dir_nsock(self):
281 """ run VCL thru host stack bi-directional (multiple sockets) test """
282
283 self.timeout = self.client_bi_dir_nsock_timeout
284 self.thru_host_stack_test("vcl_test_server", "vcl_test_client",
285 self.client_bi_dir_nsock_test_args)
286
287
288class VCLThruHostStackExtendedBTestCase(VclTestCase):
289 """ VCL Thru Host Stack Extended Tests """
290
291 def setUp(self):
292 super(VCLThruHostStackExtendedBTestCase, self).setUp()
293
294 self.thru_host_stack_setup()
295 if self.vppDebug:
296 self.client_bi_dir_nsock_timeout = 120
297 else:
298 self.client_bi_dir_nsock_timeout = 60
299 self.client_bi_dir_nsock_test_args = [self.loop0.local_ip4,
300 self.server_port,
301 "-I", "2", "-B", "-X"]
302
303 def tearDown(self):
304 self.thru_host_stack_tear_down()
305
306 super(VCLThruHostStackExtendedBTestCase, self).tearDown()
307
308 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
309 def test_ldp_thru_host_stack_bi_dir_nsock(self):
310 """ run LDP thru host stack bi-directional (multiple sockets) test """
311
312 self.timeout = self.client_bi_dir_nsock_timeout
313 self.thru_host_stack_test("sock_test_server", "sock_test_client",
314 self.client_bi_dir_nsock_test_args)
315
316
317class VCLThruHostStackExtendedCTestCase(VclTestCase):
318 """ VCL Thru Host Stack Extended Tests """
319
320 def setUp(self):
321 super(VCLThruHostStackExtendedCTestCase, self).setUp()
322
323 self.thru_host_stack_setup()
324 if self.vppDebug:
325 self.client_uni_dir_nsock_timeout = 120
326 self.numSockets = "2"
327 else:
328 self.client_uni_dir_nsock_timeout = 120
329 self.numSockets = "5"
330
331 self.client_uni_dir_nsock_test_args = [self.loop0.local_ip4,
332 self.server_port,
333 "-I", self.numSockets,
334 "-U", "-X"]
335
336 def tearDown(self):
337 self.thru_host_stack_tear_down()
338
339 super(VCLThruHostStackExtendedCTestCase, self).tearDown()
340
341 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
342 def test_ldp_thru_host_stack_uni_dir_nsock(self):
343 """ run LDP thru host stack uni-directional (multiple sockets) test """
344
345 self.timeout = self.client_uni_dir_nsock_timeout
346 self.thru_host_stack_test("sock_test_server", "sock_test_client",
347 self.client_uni_dir_nsock_test_args)
348
349
350class VCLThruHostStackExtendedDTestCase(VclTestCase):
351 """ VCL Thru Host Stack Extended Tests """
352
353 def setUp(self):
354 super(VCLThruHostStackExtendedDTestCase, self).setUp()
355
356 self.thru_host_stack_setup()
357 if self.vppDebug:
358 self.client_uni_dir_nsock_timeout = 120
359 self.numSockets = "2"
360 else:
361 self.client_uni_dir_nsock_timeout = 120
362 self.numSockets = "5"
363
364 self.client_uni_dir_nsock_test_args = [self.loop0.local_ip4,
365 self.server_port,
366 "-I", self.numSockets,
367 "-U", "-X"]
368
369 def tearDown(self):
370 self.thru_host_stack_tear_down()
371
372 super(VCLThruHostStackExtendedDTestCase, self).tearDown()
373
374 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
375 def test_vcl_thru_host_stack_uni_dir_nsock(self):
376 """ run VCL thru host stack uni-directional (multiple sockets) test """
377
378 self.timeout = self.client_uni_dir_nsock_timeout
379 self.thru_host_stack_test("vcl_test_server", "vcl_test_client",
380 self.client_uni_dir_nsock_test_args)
381
382
Dave Wallacecfcf2f42018-02-16 18:31:56 -0500383if __name__ == '__main__':
384 unittest.main(testRunner=VppTestRunner)