blob: a8a00f40f6157d097218ac21a85c3fa10cf4a2ba [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 Wallace42996c02018-02-26 14:40:13 -05007from framework import VppTestCase, VppTestRunner, Worker
Dave Wallacea67a03e2018-02-20 12:39:37 -05008from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
Dave Wallacecfcf2f42018-02-16 18:31:56 -05009
10
Dave Wallace42996c02018-02-26 14:40:13 -050011class VclAppWorker(Worker):
12 """ VCL Test Application Worker """
13
14 def __init__(self, appname, args, logger, env={}):
15 var = "VPP_TEST_BUILD_DIR"
16 build_dir = os.getenv(var, None)
17 if build_dir is None:
18 raise Exception("Environment variable `%s' not set" % var)
19 vcl_app_dir = "%s/vpp/.libs" % build_dir
20 self.args = ["%s/%s" % (vcl_app_dir, appname)] + args
21 super(VclAppWorker, self).__init__(self.args, logger, env)
22
23
24class VclTestCase(VppTestCase):
25 """ VCL Test Class """
26
27 def validateResults(self, worker_client, worker_server, timeout):
28 self.logger.info("Client worker result is `%s'" % worker_client.result)
29 error = False
30 if worker_client.result is None:
31 try:
32 error = True
33 self.logger.error(
34 "Timeout! Client worker did not finish in %ss" % timeout)
35 os.killpg(os.getpgid(worker_client.process.pid),
36 signal.SIGTERM)
37 worker_client.join()
38 except:
39 self.logger.debug(
40 "Couldn't kill client worker-spawned process")
41 raise
42 if error:
43 os.killpg(os.getpgid(worker_server.process.pid), signal.SIGTERM)
44 worker_server.join()
45 raise Exception(
46 "Timeout! Client worker did not finish in %ss" % timeout)
47 self.assert_equal(worker_client.result, 0, "Binary test return code")
48
49
50class VCLCUTTHRUTestCase(VclTestCase):
51 """ VPP Communications Library Test """
Dave Wallacecfcf2f42018-02-16 18:31:56 -050052
53 server_addr = "127.0.0.1"
54 server_port = "22000"
Dave Wallace42996c02018-02-26 14:40:13 -050055 timeout = 3
56 echo_phrase = "Hello, world! Jenny is a friend of mine"
Dave Wallacecfcf2f42018-02-16 18:31:56 -050057
58 def setUp(self):
Dave Wallacea67a03e2018-02-20 12:39:37 -050059 super(VCLCUTTHRUTestCase, self).setUp()
60
61 self.vapi.session_enable_disable(is_enabled=1)
62
63 def tearDown(self):
64 self.vapi.session_enable_disable(is_enabled=0)
65
66 super(VCLCUTTHRUTestCase, self).tearDown()
Dave Wallacecfcf2f42018-02-16 18:31:56 -050067
68 def test_vcl_cutthru(self):
69 """ run VCL cut-thru test """
Dave Wallace42996c02018-02-26 14:40:13 -050070 self.env = {'VCL_API_PREFIX': self.shm_prefix,
71 'VCL_APP_SCOPE_LOCAL': "true"}
72
73 worker_server = VclAppWorker("vcl_test_server",
74 [self.server_port],
75 self.logger, self.env)
Dave Wallacecfcf2f42018-02-16 18:31:56 -050076 worker_server.start()
Dave Wallace42996c02018-02-26 14:40:13 -050077 self.sleep(0.2)
78 worker_client = VclAppWorker("vcl_test_client",
79 [self.server_addr, self.server_port,
80 "-E", self.echo_phrase, "-X"],
81 self.logger, self.env)
Dave Wallacecfcf2f42018-02-16 18:31:56 -050082 worker_client.start()
Dave Wallace42996c02018-02-26 14:40:13 -050083 worker_client.join(self.timeout)
84 self.validateResults(worker_client, worker_server, self.timeout)
Dave Wallacecfcf2f42018-02-16 18:31:56 -050085
86
Dave Wallace42996c02018-02-26 14:40:13 -050087class VCLTHRUHSTestcase(VclTestCase):
Dave Wallacea67a03e2018-02-20 12:39:37 -050088 """ VCL Thru Hoststack Test """
89
90 server_port = "22000"
Dave Wallace42996c02018-02-26 14:40:13 -050091 timeout = 3
92 echo_phrase = "Hello, world! Jenny is a friend of mine"
Dave Wallacea67a03e2018-02-20 12:39:37 -050093
94 def setUp(self):
95 super(VCLTHRUHSTestcase, self).setUp()
96
97 self.vapi.session_enable_disable(is_enabled=1)
98 self.create_loopback_interfaces(range(2))
99
100 table_id = 0
101
102 for i in self.lo_interfaces:
103 i.admin_up()
104
105 if table_id != 0:
106 tbl = VppIpTable(self, table_id)
107 tbl.add_vpp_config()
108
109 i.set_table_ip4(table_id)
110 i.config_ip4()
111 table_id += 1
112
113 # Configure namespaces
Dave Wallace42996c02018-02-26 14:40:13 -0500114 self.vapi.app_namespace_add(namespace_id="0", secret=1234,
Dave Wallacea67a03e2018-02-20 12:39:37 -0500115 sw_if_index=self.loop0.sw_if_index)
Dave Wallace42996c02018-02-26 14:40:13 -0500116 self.vapi.app_namespace_add(namespace_id="1", secret=5678,
Dave Wallacea67a03e2018-02-20 12:39:37 -0500117 sw_if_index=self.loop1.sw_if_index)
118
119 def tearDown(self):
120 for i in self.lo_interfaces:
121 i.unconfig_ip4()
122 i.set_table_ip4(0)
123 i.admin_down()
124
125 self.vapi.session_enable_disable(is_enabled=0)
126 super(VCLTHRUHSTestcase, self).tearDown()
127
128 def test_vcl_thru_hoststack(self):
129 """ run VCL thru hoststack test """
Dave Wallace42996c02018-02-26 14:40:13 -0500130 self.env = {'VCL_API_PREFIX': self.shm_prefix,
131 'VCL_APP_SCOPE_GLOBAL': "true"}
132
Dave Wallacea67a03e2018-02-20 12:39:37 -0500133 # Add inter-table routes
134 ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32,
135 [VppRoutePath("0.0.0.0",
136 0xffffffff,
137 nh_table_id=1)])
138 ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32,
139 [VppRoutePath("0.0.0.0",
140 0xffffffff,
141 nh_table_id=0)], table_id=1)
142 ip_t01.add_vpp_config()
143 ip_t10.add_vpp_config()
144
Dave Wallace42996c02018-02-26 14:40:13 -0500145 self.env.update({'VCL_APP_NAMESPACE_ID': "0",
146 'VCL_APP_NAMESPACE_SECRET': "1234"})
147 worker_server = VclAppWorker("vcl_test_server",
148 [self.server_port],
149 self.logger, self.env)
Dave Wallacea67a03e2018-02-20 12:39:37 -0500150 worker_server.start()
Dave Wallace42996c02018-02-26 14:40:13 -0500151 self.sleep(0.2)
152
153 self.env.update({'VCL_APP_NAMESPACE_ID': "1",
154 'VCL_APP_NAMESPACE_SECRET': "5678"})
155 worker_client = VclAppWorker("vcl_test_client",
156 [self.loop0.local_ip4, self.server_port,
157 "-E", self.echo_phrase, "-X"],
158 self.logger, self.env)
Dave Wallacea67a03e2018-02-20 12:39:37 -0500159 worker_client.start()
Dave Wallace42996c02018-02-26 14:40:13 -0500160 worker_client.join(self.timeout)
161
162 self.validateResults(worker_client, worker_server, self.timeout)
Dave Wallacea67a03e2018-02-20 12:39:37 -0500163
Dave Wallacecfcf2f42018-02-16 18:31:56 -0500164if __name__ == '__main__':
165 unittest.main(testRunner=VppTestRunner)