7 from framework import VppTestCase, VppTestRunner, Worker
8 from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
11 class VclAppWorker(Worker):
12 """ VCL Test Application Worker """
14 def __init__(self, appname, args, logger, env={}):
15 var = "VPP_TEST_BUILD_DIR"
16 build_dir = os.getenv(var, 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)
24 class VclTestCase(VppTestCase):
25 """ VCL Test Class """
27 def validateResults(self, worker_client, worker_server, timeout):
28 self.logger.info("Client worker result is `%s'" % worker_client.result)
30 if worker_client.result is None:
34 "Timeout! Client worker did not finish in %ss" % timeout)
35 os.killpg(os.getpgid(worker_client.process.pid),
40 "Couldn't kill client worker-spawned process")
43 os.killpg(os.getpgid(worker_server.process.pid), signal.SIGTERM)
46 "Timeout! Client worker did not finish in %ss" % timeout)
47 self.assert_equal(worker_client.result, 0, "Binary test return code")
50 class VCLCUTTHRUTestCase(VclTestCase):
51 """ VPP Communications Library Test """
53 server_addr = "127.0.0.1"
56 echo_phrase = "Hello, world! Jenny is a friend of mine"
59 super(VCLCUTTHRUTestCase, self).setUp()
61 self.vapi.session_enable_disable(is_enabled=1)
64 self.vapi.session_enable_disable(is_enabled=0)
66 super(VCLCUTTHRUTestCase, self).tearDown()
68 def test_vcl_cutthru(self):
69 """ run VCL cut-thru test """
70 self.env = {'VCL_API_PREFIX': self.shm_prefix,
71 'VCL_APP_SCOPE_LOCAL': "true"}
73 worker_server = VclAppWorker("vcl_test_server",
75 self.logger, self.env)
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)
83 worker_client.join(self.timeout)
84 self.validateResults(worker_client, worker_server, self.timeout)
87 class VCLTHRUHSTestcase(VclTestCase):
88 """ VCL Thru Hoststack Test """
92 echo_phrase = "Hello, world! Jenny is a friend of mine"
95 super(VCLTHRUHSTestcase, self).setUp()
97 self.vapi.session_enable_disable(is_enabled=1)
98 self.create_loopback_interfaces(range(2))
102 for i in self.lo_interfaces:
106 tbl = VppIpTable(self, table_id)
109 i.set_table_ip4(table_id)
113 # Configure namespaces
114 self.vapi.app_namespace_add(namespace_id="0", secret=1234,
115 sw_if_index=self.loop0.sw_if_index)
116 self.vapi.app_namespace_add(namespace_id="1", secret=5678,
117 sw_if_index=self.loop1.sw_if_index)
120 for i in self.lo_interfaces:
125 self.vapi.session_enable_disable(is_enabled=0)
126 super(VCLTHRUHSTestcase, self).tearDown()
128 def test_vcl_thru_hoststack(self):
129 """ run VCL thru hoststack test """
130 self.env = {'VCL_API_PREFIX': self.shm_prefix,
131 'VCL_APP_SCOPE_GLOBAL': "true"}
133 # Add inter-table routes
134 ip_t01 = VppIpRoute(self, self.loop1.local_ip4, 32,
135 [VppRoutePath("0.0.0.0",
138 ip_t10 = VppIpRoute(self, self.loop0.local_ip4, 32,
139 [VppRoutePath("0.0.0.0",
141 nh_table_id=0)], table_id=1)
142 ip_t01.add_vpp_config()
143 ip_t10.add_vpp_config()
145 self.env.update({'VCL_APP_NAMESPACE_ID': "0",
146 'VCL_APP_NAMESPACE_SECRET': "1234"})
147 worker_server = VclAppWorker("vcl_test_server",
149 self.logger, self.env)
150 worker_server.start()
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)
159 worker_client.start()
160 worker_client.join(self.timeout)
162 self.validateResults(worker_client, worker_server, self.timeout)
164 if __name__ == '__main__':
165 unittest.main(testRunner=VppTestRunner)