aboutsummaryrefslogtreecommitdiff
path: root/src/service/transport/test_transport_plugin_cmd_udp_backchannel.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/transport/test_transport_plugin_cmd_udp_backchannel.c')
-rw-r--r--src/service/transport/test_transport_plugin_cmd_udp_backchannel.c371
1 files changed, 371 insertions, 0 deletions
diff --git a/src/service/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/service/transport/test_transport_plugin_cmd_udp_backchannel.c
new file mode 100644
index 000000000..75fb85e66
--- /dev/null
+++ b/src/service/transport/test_transport_plugin_cmd_udp_backchannel.c
@@ -0,0 +1,371 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testbed/plugin_cmd_simple_send.c
23 * @brief a plugin to provide the API for running test cases.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_barrier.h"
28#include "gnunet_testing_netjail_lib.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_transport_application_service.h"
31#include "transport-testing2.h"
32#include "transport-testing-cmds.h"
33#include "gnunet_testing_barrier.h"
34
35/**
36 * Generic logging shortcut
37 */
38#define LOG(kind, ...) GNUNET_log_from (kind, "udp-backchannel", __VA_ARGS__)
39
40#define BASE_DIR "testdir"
41
42#define TOPOLOGY_CONFIG "test_transport_udp_backchannel_topo.conf"
43
44#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
45
46static struct GNUNET_TESTING_Command block_send;
47
48static struct GNUNET_TESTING_Command connect_peers;
49
50static struct GNUNET_TESTING_Command local_prepared;
51
52static struct GNUNET_TESTING_Interpreter *is;
53
54
55/**
56 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
57 * received.
58 *
59 */
60static int
61check_test (void *cls,
62 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
63{
64 return GNUNET_OK;
65}
66
67
68/**
69 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
70 * being received.
71 *
72 */
73static void
74handle_test (void *cls,
75 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
76{
77 // struct GNUNET_TESTING_AsyncContext *ac;
78
79 /*GNUNET_TESTING_get_trait_async_context (&block_receive,
80 &ac);
81 if ((NULL == ac) || (NULL == ac->cont))
82 GNUNET_TESTING_async_fail (ac);
83 else
84 GNUNET_TESTING_async_finish (ac);*/
85}
86
87
88struct GNUNET_TESTING_BarrierList *
89get_waiting_for_barriers ()
90{
91 // No Barrier
92 return GNUNET_new (struct GNUNET_TESTING_BarrierList);
93}
94
95
96/**
97 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
98 *
99 */
100static void
101all_peers_started ()
102{
103 struct GNUNET_TESTING_AsyncContext *ac;
104
105 GNUNET_TESTING_get_trait_async_context (&block_send,
106 &ac);
107 GNUNET_assert (NULL != ac);
108 if ((NULL == ac->cont))
109 GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
110 else
111 GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
112}
113
114
115/**
116* Function called with the final result of the test.
117*
118* @param cls the `struct MainParams`
119* @param rv #GNUNET_OK if the test passed
120*/
121static void
122handle_result (void *cls,
123 enum GNUNET_GenericReturnValue rv)
124{
125 struct TestState *ts = cls;
126
127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
128 "Local test exits with status %d\n",
129 rv);
130
131 ts->finished_cb (rv);
132 GNUNET_free (ts->testdir);
133 GNUNET_free (ts->cfgname);
134 GNUNET_TESTING_free_topology (ts->topology);
135 GNUNET_free (ts);
136}
137
138
139/**
140 * Callback from start peer cmd for signaling a peer got connected.
141 *
142 */
143static void *
144notify_connect (struct GNUNET_TESTING_Interpreter *is,
145 const struct GNUNET_PeerIdentity *peer)
146{
147 const struct ConnectPeersState *cps;
148
149 GNUNET_TRANSPORT_TESTING_get_trait_connect_peer_state (&connect_peers,
150 &cps);
151 void *ret = NULL;
152
153 cps->notify_connect (is,
154 peer);
155 return ret;
156}
157
158
159/**
160 * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api.
161 */
162static void
163all_local_tests_prepared ()
164{
165 const struct GNUNET_TESTING_LocalPreparedState *lfs;
166
167 GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared,
168 &lfs);
169 GNUNET_assert (NULL != &lfs->ac);
170 if (NULL == lfs->ac.cont)
171 GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) &lfs->ac);
172 else
173 GNUNET_TESTING_async_finish ((struct
174 GNUNET_TESTING_AsyncContext *) &lfs->ac);
175}
176
177
178/**
179 * Function to start a local test case.
180 *
181 * @param write_message Callback to send a message to the master loop.
182 * @param router_ip Global address of the network namespace.
183 * @param node_ip The IP address of the node.
184 * @param m The number of the node in a network namespace.
185 * @param n The number of the network namespace.
186 * @param local_m The number of nodes in a network namespace.
187 */
188static struct GNUNET_TESTING_Interpreter *
189start_testcase (GNUNET_TESTING_cmd_helper_write_cb write_message,
190 const char *router_ip,
191 const char *node_ip,
192 const char *m,
193 const char *n,
194 const char *local_m,
195 const char *topology_data,
196 unsigned int *read_file,
197 GNUNET_TESTING_cmd_helper_finish_cb finished_cb)
198{
199
200 unsigned int n_int;
201 unsigned int m_int;
202 unsigned int local_m_int;
203 unsigned int num;
204 struct TestState *ts = GNUNET_new (struct TestState);
205 struct GNUNET_TESTING_NetjailTopology *topology;
206 unsigned int sscanf_ret = 0;
207
208 ts->finished_cb = finished_cb;
209 LOG (GNUNET_ERROR_TYPE_ERROR,
210 "n %s m %s\n",
211 n,
212 m);
213
214 if (GNUNET_YES == *read_file)
215 {
216 LOG (GNUNET_ERROR_TYPE_DEBUG,
217 "read from file\n");
218 topology = GNUNET_TESTING_get_topo_from_file (topology_data);
219 }
220 else
221 topology = GNUNET_TESTING_get_topo_from_string (topology_data);
222
223 ts->topology = topology;
224
225 errno = 0;
226 sscanf_ret = sscanf (m, "%u", &m_int);
227 if (errno != 0)
228 {
229 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
230 }
231 GNUNET_assert (0 < sscanf_ret);
232 errno = 0;
233 sscanf_ret = sscanf (n, "%u", &n_int);
234 if (errno != 0)
235 {
236 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
237 }
238 GNUNET_assert (0 < sscanf_ret);
239 errno = 0;
240 sscanf_ret = sscanf (local_m, "%u", &local_m_int);
241 if (errno != 0)
242 {
243 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
244 }
245 GNUNET_assert (0 < sscanf_ret);
246
247
248 if (0 == n_int)
249 num = m_int;
250 else
251 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
252
253 block_send = GNUNET_TESTING_cmd_block_until_external_trigger (
254 "block");
255 connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
256 "start-peer",
257 "system-create",
258 num,
259 topology,
260 0,
261 GNUNET_YES);
262 local_prepared = GNUNET_TESTING_cmd_local_test_prepared (
263 "local-test-prepared",
264 write_message);
265
266 GNUNET_asprintf (&ts->cfgname,
267 "test_transport_api2_tcp_node1.conf");
268
269 LOG (GNUNET_ERROR_TYPE_DEBUG,
270 "plugin cfgname: %s\n",
271 ts->cfgname);
272
273 LOG (GNUNET_ERROR_TYPE_DEBUG,
274 "node ip: %s\n",
275 node_ip);
276
277 GNUNET_asprintf (&ts->testdir,
278 "%s%s%s",
279 BASE_DIR,
280 m,
281 n);
282
283 struct GNUNET_MQ_MessageHandler handlers[] = {
284 GNUNET_MQ_hd_var_size (test,
285 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
286 struct GNUNET_TRANSPORT_TESTING_TestMessage,
287 NULL),
288 GNUNET_MQ_handler_end ()
289 };
290
291 struct GNUNET_TESTING_Command commands[] = {
292 GNUNET_TESTING_cmd_system_create ("system-create",
293 ts->testdir),
294 GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
295 "system-create",
296 num,
297 node_ip,
298 handlers,
299 ts->cfgname,
300 notify_connect,
301 GNUNET_NO),
302 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
303 write_message),
304 block_send,
305 connect_peers,
306 GNUNET_TRANSPORT_cmd_backchannel_check ("backchannel-check",
307 "start-peer",
308 "system-create",
309 num,
310 m_int,
311 n_int,
312 topology),
313 local_prepared,
314 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
315 "start-peer"),
316 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
317 "system-create"),
318 GNUNET_TESTING_cmd_end ()
319 };
320
321 ts->write_message = write_message;
322
323 is = GNUNET_TESTING_run (commands,
324 TIMEOUT,
325 &handle_result,
326 ts);
327 return is;
328}
329
330
331/**
332 * Entry point for the plugin.
333 *
334 * @param cls NULL
335 * @return the exported block API
336 */
337void *
338libgnunet_test_transport_plugin_cmd_udp_backchannel_init (void *cls)
339{
340 struct GNUNET_TESTING_PluginFunctions *api;
341
342 GNUNET_log_setup ("udp-backchannel",
343 "DEBUG",
344 "plugin.out");
345
346 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
347 api->start_testcase = &start_testcase;
348 api->all_peers_started = &all_peers_started;
349 api->all_local_tests_prepared = all_local_tests_prepared;
350 api->get_waiting_for_barriers = get_waiting_for_barriers;
351 return api;
352}
353
354
355/**
356 * Exit point from the plugin.
357 *
358 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
359 * @return NULL
360 */
361void *
362libgnunet_test_transport_plugin_cmd_udp_backchannel_done (void *cls)
363{
364 struct GNUNET_TESTING_PluginFunctions *api = cls;
365
366 GNUNET_free (api);
367 return NULL;
368}
369
370
371/* end of plugin_cmd_simple_send.c */