7 from framework import VppTestCase, VppTestRunner, running_extended_tests, \
9 from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
12 class VclAppWorker(Worker):
13 """ VCL Test Application Worker """
15 def __init__(self, build_dir, appname, args, logger, env={}):
16 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
23 super(VclAppWorker, self).__init__(self.args, logger, env)
26 class VclTestCase(VppTestCase):
27 """ VCL Test Class """
29 def __init__(self, methodName):
30 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
35 self.server_addr = "127.0.0.1"
36 self.server_port = "22000"
38 self.echo_phrase = "Hello, world! Jenny is a friend of mine."
40 super(VclTestCase, self).__init__(methodName)
42 def cut_thru_setup(self):
43 self.vapi.session_enable_disable(is_enabled=1)
45 def cut_thru_tear_down(self):
46 self.vapi.session_enable_disable(is_enabled=0)
48 def cut_thru_test(self, server_app, client_app, client_args):
49 self.env = {'VCL_API_PREFIX': self.shm_prefix,
50 'VCL_APP_SCOPE_LOCAL': "true"}
52 worker_server = VclAppWorker(self.build_dir, server_app,
54 self.logger, self.env)
57 worker_client = VclAppWorker(self.build_dir, client_app, client_args,
58 self.logger, self.env)
60 worker_client.join(self.timeout)
62 self.validateResults(worker_client, worker_server, self.timeout)
63 except Exception, error:
64 self.fail("Failed with %s" % error)
66 def thru_host_stack_setup(self):
67 self.vapi.session_enable_disable(is_enabled=1)
68 self.create_loopback_interfaces(range(2))
72 for i in self.lo_interfaces:
76 tbl = VppIpTable(self, table_id)
79 i.set_table_ip4(table_id)
83 # Configure namespaces
84 self.vapi.app_namespace_add(namespace_id="0", secret=1234,
85 sw_if_index=self.loop0.sw_if_index)
86 self.vapi.app_namespace_add(namespace_id="1", secret=5678,
87 sw_if_index=self.loop1.sw_if_index)
89 # Add inter-table routes
90 ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32,
91 [VppRoutePath("0.0.0.0",
94 ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32,
95 [VppRoutePath("0.0.0.0",
97 nh_table_id=0)], table_id=1)
98 ip_t01.add_vpp_config()
99 ip_t10.add_vpp_config()
101 def thru_host_stack_tear_down(self):
102 for i in self.lo_interfaces:
107 self.vapi.session_enable_disable(is_enabled=0)
109 def thru_host_stack_test(self, server_app, client_app, client_args):
110 self.env = {'VCL_API_PREFIX': self.shm_prefix,
111 'VCL_APP_SCOPE_GLOBAL': "true",
112 'VCL_APP_NAMESPACE_ID': "0",
113 'VCL_APP_NAMESPACE_SECRET': "1234"}
115 worker_server = VclAppWorker(self.build_dir, server_app,
117 self.logger, self.env)
118 worker_server.start()
121 self.env.update({'VCL_APP_NAMESPACE_ID': "1",
122 'VCL_APP_NAMESPACE_SECRET': "5678"})
123 worker_client = VclAppWorker(self.build_dir, client_app, client_args,
124 self.logger, self.env)
125 worker_client.start()
126 worker_client.join(self.timeout)
129 self.validateResults(worker_client, worker_server, self.timeout)
130 except Exception, error:
131 self.fail("Failed with %s" % error)
133 def validateResults(self, worker_client, worker_server, timeout):
134 if os.path.isdir('/proc/{}'.format(worker_server.process.pid)):
135 self.logger.info("Killing server worker process (pid %d)" %
136 worker_server.process.pid)
137 os.killpg(os.getpgid(worker_server.process.pid), signal.SIGTERM)
139 self.logger.info("Client worker result is `%s'" % worker_client.result)
141 if worker_client.result is None:
145 "Timeout: %ss! Killing client worker process (pid %d)" %
146 (timeout, worker_client.process.pid))
147 os.killpg(os.getpgid(worker_client.process.pid),
152 "Couldn't kill client worker process")
156 "Timeout! Client worker did not finish in %ss" % timeout)
157 self.assert_equal(worker_client.result, 0, "Binary test return code")
160 class VCLCutThruTestCase(VclTestCase):
161 """ VCL Cut Thru Tests """
164 super(VCLCutThruTestCase, self).setUp()
166 self.cut_thru_setup()
167 self.client_echo_test_args = [self.server_addr, self.server_port,
168 "-E", self.echo_phrase, "-X"]
169 self.client_uni_dir_nsock_timeout = 60
170 self.client_uni_dir_nsock_test_args = [self.server_addr,
172 "-I", "5", "-U", "-X"]
173 self.client_bi_dir_nsock_timeout = 120
174 self.client_bi_dir_nsock_test_args = [self.server_addr,
176 "-I", "2", "-B", "-X"]
179 self.cut_thru_tear_down()
181 super(VCLCutThruTestCase, self).tearDown()
183 def test_ldp_cut_thru_echo(self):
184 """ run LDP cut thru echo test """
186 self.cut_thru_test("sock_test_server", "sock_test_client",
187 self.client_echo_test_args)
189 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
190 def test_ldp_cut_thru_uni_dir_nsock(self):
191 """ run LDP cut thru uni-directional (multiple sockets) test """
193 self.timeout = self.client_uni_dir_nsock_timeout
194 self.cut_thru_test("sock_test_server", "sock_test_client",
195 self.client_uni_dir_nsock_test_args)
197 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
198 def test_ldp_cut_thru_bi_dir_nsock(self):
199 """ run LDP cut thru bi-directional (multiple sockets) test """
201 self.timeout = self.client_bi_dir_nsock_timeout
202 self.cut_thru_test("sock_test_server", "sock_test_client",
203 self.client_bi_dir_nsock_test_args)
205 def test_vcl_cut_thru_echo(self):
206 """ run VCL cut thru echo test """
208 self.cut_thru_test("vcl_test_server", "vcl_test_client",
209 self.client_echo_test_args)
211 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
212 def test_vcl_cut_thru_uni_dir_nsock(self):
213 """ run VCL cut thru uni-directional (multiple sockets) test """
215 self.timeout = self.client_uni_dir_nsock_timeout
216 self.cut_thru_test("vcl_test_server", "vcl_test_client",
217 self.client_uni_dir_nsock_test_args)
219 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
220 def test_vcl_cut_thru_bi_dir_nsock(self):
221 """ run VCL cut thru bi-directional (multiple sockets) test """
223 self.timeout = self.client_bi_dir_nsock_timeout
224 self.cut_thru_test("vcl_test_server", "vcl_test_client",
225 self.client_bi_dir_nsock_test_args)
228 class VCLThruHostStackTestCase(VclTestCase):
229 """ VCL Thru Host Stack Tests """
232 super(VCLThruHostStackTestCase, self).setUp()
234 self.thru_host_stack_setup()
235 self.client_echo_test_args = [self.loop0.local_ip4,
237 "-E", self.echo_phrase, "-X"]
240 self.thru_host_stack_tear_down()
242 super(VCLThruHostStackTestCase, self).tearDown()
244 def test_ldp_thru_host_stack_echo(self):
245 """ run LDP thru host stack echo test """
247 self.thru_host_stack_test("sock_test_server", "sock_test_client",
248 self.client_echo_test_args)
249 # TBD: Remove these when VPP thru host teardown config bug is fixed.
250 self.thru_host_stack_test("vcl_test_server", "vcl_test_client",
251 self.client_echo_test_args)
253 def test_vcl_thru_host_stack_echo(self):
254 """ run VCL thru host stack echo test """
256 # TBD: Enable this when VPP thru host teardown config bug is fixed.
257 # self.thru_host_stack_test("vcl_test_server", "vcl_test_client",
258 # self.client_echo_test_args)
260 # TBD: Remove VCLThruHostStackExtended*TestCase classes and move
261 # tests here when VPP thru host teardown/setup config bug
265 class VCLThruHostStackExtendedATestCase(VclTestCase):
266 """ VCL Thru Host Stack Extended Tests """
269 super(VCLThruHostStackExtendedATestCase, self).setUp()
271 self.thru_host_stack_setup()
273 self.client_bi_dir_nsock_timeout = 120
275 self.client_bi_dir_nsock_timeout = 60
276 self.client_bi_dir_nsock_test_args = [self.loop0.local_ip4,
278 "-I", "2", "-B", "-X"]
281 self.thru_host_stack_tear_down()
283 super(VCLThruHostStackExtendedATestCase, self).tearDown()
285 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
286 def test_vcl_thru_host_stack_bi_dir_nsock(self):
287 """ run VCL thru host stack bi-directional (multiple sockets) test """
289 self.timeout = self.client_bi_dir_nsock_timeout
290 self.thru_host_stack_test("vcl_test_server", "vcl_test_client",
291 self.client_bi_dir_nsock_test_args)
294 class VCLThruHostStackExtendedBTestCase(VclTestCase):
295 """ VCL Thru Host Stack Extended Tests """
298 super(VCLThruHostStackExtendedBTestCase, self).setUp()
300 self.thru_host_stack_setup()
302 self.client_bi_dir_nsock_timeout = 120
304 self.client_bi_dir_nsock_timeout = 60
305 self.client_bi_dir_nsock_test_args = [self.loop0.local_ip4,
307 "-I", "2", "-B", "-X"]
310 self.thru_host_stack_tear_down()
312 super(VCLThruHostStackExtendedBTestCase, self).tearDown()
314 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
315 def test_ldp_thru_host_stack_bi_dir_nsock(self):
316 """ run LDP thru host stack bi-directional (multiple sockets) test """
318 self.timeout = self.client_bi_dir_nsock_timeout
319 self.thru_host_stack_test("sock_test_server", "sock_test_client",
320 self.client_bi_dir_nsock_test_args)
323 class VCLThruHostStackExtendedCTestCase(VclTestCase):
324 """ VCL Thru Host Stack Extended Tests """
327 super(VCLThruHostStackExtendedCTestCase, self).setUp()
329 self.thru_host_stack_setup()
331 self.client_uni_dir_nsock_timeout = 120
332 self.numSockets = "2"
334 self.client_uni_dir_nsock_timeout = 120
335 self.numSockets = "5"
337 self.client_uni_dir_nsock_test_args = [self.loop0.local_ip4,
339 "-I", self.numSockets,
343 self.thru_host_stack_tear_down()
345 super(VCLThruHostStackExtendedCTestCase, self).tearDown()
347 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
348 def test_ldp_thru_host_stack_uni_dir_nsock(self):
349 """ run LDP thru host stack uni-directional (multiple sockets) test """
351 self.timeout = self.client_uni_dir_nsock_timeout
352 self.thru_host_stack_test("sock_test_server", "sock_test_client",
353 self.client_uni_dir_nsock_test_args)
356 class VCLThruHostStackExtendedDTestCase(VclTestCase):
357 """ VCL Thru Host Stack Extended Tests """
360 super(VCLThruHostStackExtendedDTestCase, self).setUp()
362 self.thru_host_stack_setup()
364 self.client_uni_dir_nsock_timeout = 120
365 self.numSockets = "2"
367 self.client_uni_dir_nsock_timeout = 120
368 self.numSockets = "5"
370 self.client_uni_dir_nsock_test_args = [self.loop0.local_ip4,
372 "-I", self.numSockets,
376 self.thru_host_stack_tear_down()
378 super(VCLThruHostStackExtendedDTestCase, self).tearDown()
380 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
381 def test_vcl_thru_host_stack_uni_dir_nsock(self):
382 """ run VCL thru host stack uni-directional (multiple sockets) test """
384 self.timeout = self.client_uni_dir_nsock_timeout
385 self.thru_host_stack_test("vcl_test_server", "vcl_test_client",
386 self.client_uni_dir_nsock_test_args)
389 if __name__ == '__main__':
390 unittest.main(testRunner=VppTestRunner)