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)
61 self.validateResults(worker_client, worker_server, self.timeout)
63 def thru_host_stack_setup(self):
64 self.vapi.session_enable_disable(is_enabled=1)
65 self.create_loopback_interfaces(range(2))
69 for i in self.lo_interfaces:
73 tbl = VppIpTable(self, table_id)
76 i.set_table_ip4(table_id)
80 # Configure namespaces
81 self.vapi.app_namespace_add(namespace_id="0", secret=1234,
82 sw_if_index=self.loop0.sw_if_index)
83 self.vapi.app_namespace_add(namespace_id="1", secret=5678,
84 sw_if_index=self.loop1.sw_if_index)
86 # Add inter-table routes
87 ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32,
88 [VppRoutePath("0.0.0.0",
91 ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32,
92 [VppRoutePath("0.0.0.0",
94 nh_table_id=0)], table_id=1)
95 ip_t01.add_vpp_config()
96 ip_t10.add_vpp_config()
98 def thru_host_stack_tear_down(self):
99 for i in self.lo_interfaces:
104 self.vapi.session_enable_disable(is_enabled=0)
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"}
112 worker_server = VclAppWorker(self.build_dir, server_app,
114 self.logger, self.env)
115 worker_server.start()
118 self.env.update({'VCL_APP_NAMESPACE_ID': "1",
119 'VCL_APP_NAMESPACE_SECRET': "5678"})
120 worker_client = VclAppWorker(self.build_dir, client_app, client_args,
121 self.logger, self.env)
122 worker_client.start()
123 worker_client.join(self.timeout)
125 self.validateResults(worker_client, worker_server, self.timeout)
127 def validateResults(self, worker_client, worker_server, timeout):
128 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)
133 self.logger.info("Client worker result is `%s'" % worker_client.result)
135 if worker_client.result is None:
139 "Timeout: %ss! Killing client worker process (pid %d)" %
140 (timeout, worker_client.process.pid))
141 os.killpg(os.getpgid(worker_client.process.pid),
146 "Couldn't kill client worker process")
150 "Timeout! Client worker did not finish in %ss" % timeout)
151 self.assert_equal(worker_client.result, 0, "Binary test return code")
154 class VCLCutThruTestCase(VclTestCase):
155 """ VCL Cut Thru Tests """
158 super(VCLCutThruTestCase, self).setUp()
160 self.cut_thru_setup()
161 self.client_echo_test_args = [self.server_addr, self.server_port,
162 "-E", self.echo_phrase, "-X"]
163 self.client_uni_dir_nsock_timeout = 60
164 self.client_uni_dir_nsock_test_args = [self.server_addr,
166 "-I", "5", "-U", "-X"]
167 self.client_bi_dir_nsock_timeout = 120
168 self.client_bi_dir_nsock_test_args = [self.server_addr,
170 "-I", "2", "-B", "-X"]
173 self.cut_thru_tear_down()
175 super(VCLCutThruTestCase, self).tearDown()
177 def test_ldp_cut_thru_echo(self):
178 """ run LDP cut thru echo test """
180 self.cut_thru_test("sock_test_server", "sock_test_client",
181 self.client_echo_test_args)
183 @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 """
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)
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 """
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)
199 def test_vcl_cut_thru_echo(self):
200 """ run VCL cut thru echo test """
202 self.cut_thru_test("vcl_test_server", "vcl_test_client",
203 self.client_echo_test_args)
205 @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 """
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)
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 """
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)
222 class VCLThruHostStackTestCase(VclTestCase):
223 """ VCL Thru Host Stack Tests """
226 super(VCLThruHostStackTestCase, self).setUp()
228 self.thru_host_stack_setup()
229 self.client_echo_test_args = [self.loop0.local_ip4,
231 "-E", self.echo_phrase, "-X"]
234 self.thru_host_stack_tear_down()
236 super(VCLThruHostStackTestCase, self).tearDown()
238 def test_ldp_thru_host_stack_echo(self):
239 """ run LDP thru host stack echo test """
241 self.thru_host_stack_test("sock_test_server", "sock_test_client",
242 self.client_echo_test_args)
243 # TBD: Remove these when VPP thru host teardown config bug is fixed.
244 self.thru_host_stack_test("vcl_test_server", "vcl_test_client",
245 self.client_echo_test_args)
247 def test_vcl_thru_host_stack_echo(self):
248 """ run VCL thru host stack echo test """
250 # TBD: Enable this when VPP thru host teardown config bug is fixed.
251 # self.thru_host_stack_test("vcl_test_server", "vcl_test_client",
252 # self.client_echo_test_args)
254 # TBD: Remove VCLThruHostStackExtended*TestCase classes and move
255 # tests here when VPP thru host teardown/setup config bug
259 class VCLThruHostStackExtendedATestCase(VclTestCase):
260 """ VCL Thru Host Stack Extended Tests """
263 super(VCLThruHostStackExtendedATestCase, self).setUp()
265 self.thru_host_stack_setup()
267 self.client_bi_dir_nsock_timeout = 120
269 self.client_bi_dir_nsock_timeout = 60
270 self.client_bi_dir_nsock_test_args = [self.loop0.local_ip4,
272 "-I", "2", "-B", "-X"]
275 self.thru_host_stack_tear_down()
277 super(VCLThruHostStackExtendedATestCase, self).tearDown()
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 """
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)
288 class VCLThruHostStackExtendedBTestCase(VclTestCase):
289 """ VCL Thru Host Stack Extended Tests """
292 super(VCLThruHostStackExtendedBTestCase, self).setUp()
294 self.thru_host_stack_setup()
296 self.client_bi_dir_nsock_timeout = 120
298 self.client_bi_dir_nsock_timeout = 60
299 self.client_bi_dir_nsock_test_args = [self.loop0.local_ip4,
301 "-I", "2", "-B", "-X"]
304 self.thru_host_stack_tear_down()
306 super(VCLThruHostStackExtendedBTestCase, self).tearDown()
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 """
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)
317 class VCLThruHostStackExtendedCTestCase(VclTestCase):
318 """ VCL Thru Host Stack Extended Tests """
321 super(VCLThruHostStackExtendedCTestCase, self).setUp()
323 self.thru_host_stack_setup()
325 self.client_uni_dir_nsock_timeout = 120
326 self.numSockets = "2"
328 self.client_uni_dir_nsock_timeout = 120
329 self.numSockets = "5"
331 self.client_uni_dir_nsock_test_args = [self.loop0.local_ip4,
333 "-I", self.numSockets,
337 self.thru_host_stack_tear_down()
339 super(VCLThruHostStackExtendedCTestCase, self).tearDown()
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 """
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)
350 class VCLThruHostStackExtendedDTestCase(VclTestCase):
351 """ VCL Thru Host Stack Extended Tests """
354 super(VCLThruHostStackExtendedDTestCase, self).setUp()
356 self.thru_host_stack_setup()
358 self.client_uni_dir_nsock_timeout = 120
359 self.numSockets = "2"
361 self.client_uni_dir_nsock_timeout = 120
362 self.numSockets = "5"
364 self.client_uni_dir_nsock_test_args = [self.loop0.local_ip4,
366 "-I", self.numSockets,
370 self.thru_host_stack_tear_down()
372 super(VCLThruHostStackExtendedDTestCase, self).tearDown()
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 """
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)
383 if __name__ == '__main__':
384 unittest.main(testRunner=VppTestRunner)