aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_plugin_cmd_simple_send_dv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_transport_plugin_cmd_simple_send_dv.c')
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send_dv.c431
1 files changed, 0 insertions, 431 deletions
diff --git a/src/transport/test_transport_plugin_cmd_simple_send_dv.c b/src/transport/test_transport_plugin_cmd_simple_send_dv.c
deleted file mode 100644
index 55ab4a48f..000000000
--- a/src/transport/test_transport_plugin_cmd_simple_send_dv.c
+++ /dev/null
@@ -1,431 +0,0 @@
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_broadcast.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 (kind, __VA_ARGS__)
39
40#define BASE_DIR "testdir"
41
42#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
43
44#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
45
46/**
47 * The number of messages received.
48 */
49static unsigned int number_received;
50
51static struct GNUNET_TESTING_Command block_send;
52
53static struct GNUNET_TESTING_Command block_receive;
54
55static struct GNUNET_TESTING_Command connect_peers;
56
57static struct GNUNET_TESTING_Command local_prepared;
58
59static struct GNUNET_TESTING_Command start_peer;
60
61static struct GNUNET_TESTING_Interpreter *is;
62
63/**
64 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
65 * received.
66 *
67 */
68static int
69check_test (void *cls,
70 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
71{
72 GNUNET_assert (NULL != cls);
73 return GNUNET_OK;
74}
75
76
77/**
78 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
79 * being received.
80 *
81 */
82static void
83handle_test (void *cls,
84 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
85{
86 struct GNUNET_PeerIdentity *peer = cls;
87 const struct GNUNET_TESTING_AsyncContext *ac_block;
88 const struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
89 unsigned int connected;
90 struct GNUNET_TESTING_BlockState *bs;
91 struct GNUNET_TRANSPORT_CoreHandle *ch;
92 const struct StartPeerState *sps;
93
94
95 GNUNET_TRANSPORT_get_trait_state (&start_peer,
96 &sps);
97 ch = sps->th;
98 GNUNET_TRANSPORT_get_trait_connected_peers_map (&start_peer,
99 &connected_peers_map);
100
101 if (NULL != connected_peers_map)
102 {
103 connected = GNUNET_CONTAINER_multishortmap_size (
104 connected_peers_map);
105
106 number_received++;
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
108 "Received %u test message(s) from %s, %u connected peer(s)\n",
109 number_received,
110 GNUNET_i2s (peer),
111 connected);
112
113 GNUNET_TESTING_get_trait_async_context (&block_receive,
114 &ac_block);
115
116 if ( connected == number_received)
117 {
118 if (NULL != ac_block->is)
119 {
120 GNUNET_assert (NULL != ac_block);
121 if (NULL == ac_block->cont)
122 GNUNET_TESTING_async_fail ((struct
123 GNUNET_TESTING_AsyncContext *) ac_block);
124 else
125 GNUNET_TESTING_async_finish ((struct
126 GNUNET_TESTING_AsyncContext *) ac_block);
127 }
128 else
129 {
130 GNUNET_TESTING_get_trait_block_state (
131 &block_receive,
132 (const struct GNUNET_TESTING_BlockState **) &bs);
133 bs->asynchronous_finish = GNUNET_YES;
134 }
135
136 }
137 }
138 GNUNET_TRANSPORT_core_receive_continue (ch, peer);
139}
140
141
142struct GNUNET_TESTING_BarrierList *
143get_waiting_for_barriers ()
144{
145 //No Barrier
146 return GNUNET_new (struct GNUNET_TESTING_BarrierList);
147}
148
149
150/**
151 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
152 *
153 */
154static void
155all_peers_started ()
156{
157 const struct GNUNET_TESTING_AsyncContext *ac;
158
159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
160 "Received message\n");
161 GNUNET_TESTING_get_trait_async_context (&block_send,
162 &ac);
163 GNUNET_assert (NULL != ac);
164 if (NULL == ac->cont)
165 GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
166 else
167 GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
168}
169
170
171/**
172 * Function called with the final result of the test.
173 *
174 * @param cls the `struct MainParams`
175 * @param rv #GNUNET_OK if the test passed
176 */
177static void
178handle_result (void *cls,
179 enum GNUNET_GenericReturnValue rv)
180{
181 struct TestState *ts = cls;
182
183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
184 "Local test exits with status %d\n",
185 rv);
186 ts->finished_cb (rv);
187 GNUNET_free (ts->testdir);
188 GNUNET_free (ts->cfgname);
189 GNUNET_TESTING_free_topology (ts->topology);
190 GNUNET_free (ts);
191}
192
193
194/**
195 * Callback from start peer cmd for signaling a peer got connected.
196 *
197 */
198static void *
199notify_connect (struct GNUNET_TESTING_Interpreter *is,
200 const struct GNUNET_PeerIdentity *peer)
201{
202 const struct ConnectPeersState *cps;
203 const struct GNUNET_TESTING_Command *cmd;
204 void *ret = NULL;
205
206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
207 "notify_connect peer %s\n",
208 GNUNET_i2s (peer));
209 cmd = GNUNET_TESTING_interpreter_lookup_command_all (is,
210 "connect-peers");
211 GNUNET_TRANSPORT_get_trait_connect_peer_state (cmd,
212 &cps);
213 cps->notify_connect (is,
214 peer);
215
216 return ret;
217}
218
219
220/**
221 * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api.
222 */
223static void
224all_local_tests_prepared ()
225{
226 const struct GNUNET_TESTING_LocalPreparedState *lfs;
227
228 GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared,
229 &lfs);
230 GNUNET_assert (NULL != &lfs->ac);
231 if (NULL == lfs->ac.cont)
232 GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) &lfs->ac);
233 else
234 GNUNET_TESTING_async_finish ((struct
235 GNUNET_TESTING_AsyncContext *) &lfs->ac);
236}
237
238
239/**
240 * Function to start a local test case.
241 *
242 * @param write_message Callback to send a message to the master loop.
243 * @param router_ip Global address of the network namespace.
244 * @param node_ip The IP address of the node.
245 * @param m The number of the node in a network namespace.
246 * @param n The number of the network namespace.
247 * @param local_m The number of nodes in a network namespace.
248 */
249static struct GNUNET_TESTING_Interpreter *
250start_testcase (GNUNET_TESTING_cmd_helper_write_cb write_message,
251 const char *router_ip,
252 const char *node_ip,
253 const char *m,
254 const char *n,
255 const char *local_m,
256 const char *topology_data,
257 unsigned int *read_file,
258 GNUNET_TESTING_cmd_helper_finish_cb finished_cb)
259{
260 unsigned int n_int;
261 unsigned int m_int;
262 unsigned int local_m_int;
263 unsigned int num;
264 struct TestState *ts = GNUNET_new (struct TestState);
265 struct GNUNET_TESTING_NetjailTopology *topology;
266 struct GNUNET_MQ_MessageHandler handlers[] = {
267 GNUNET_MQ_hd_var_size (test,
268 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
269 struct GNUNET_TRANSPORT_TESTING_TestMessage,
270 ts),
271 GNUNET_MQ_handler_end ()
272 };
273 unsigned int sscanf_ret = 0;
274
275 ts->finished_cb = finished_cb;
276 LOG (GNUNET_ERROR_TYPE_ERROR,
277 "n %s m %s\n",
278 n,
279 m);
280
281 if (GNUNET_YES == *read_file)
282 {
283 LOG (GNUNET_ERROR_TYPE_DEBUG,
284 "read from file\n");
285 topology = GNUNET_TESTING_get_topo_from_file (topology_data);
286 }
287 else
288 topology = GNUNET_TESTING_get_topo_from_string (topology_data);
289
290 ts->topology = topology;
291
292 errno = 0;
293 sscanf_ret = sscanf (m, "%u", &m_int);
294 if (errno != 0)
295 {
296 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
297 }
298 GNUNET_assert (0 < sscanf_ret);
299 errno = 0;
300 sscanf_ret = sscanf (n, "%u", &n_int);
301 if (errno != 0)
302 {
303 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
304 }
305 GNUNET_assert (0 < sscanf_ret);
306 errno = 0;
307 sscanf_ret = sscanf (local_m, "%u", &local_m_int);
308 if (errno != 0)
309 {
310 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
311 }
312 GNUNET_assert (0 < sscanf_ret);
313
314 if (0 == n_int)
315 num = m_int;
316 else
317 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
318
319 block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block");
320 block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
321 "block-receive");
322 connect_peers = GNUNET_TRANSPORT_cmd_connect_peers (
323 "connect-peers",
324 "start-peer",
325 "system-create",
326 num,
327 topology,
328 topology->additional_connects);
329 local_prepared = GNUNET_TESTING_cmd_local_test_prepared (
330 "local-test-prepared",
331 write_message);
332
333
334 GNUNET_asprintf (&ts->cfgname,
335 "test_transport_api2_tcp_node1.conf");
336
337 LOG (GNUNET_ERROR_TYPE_DEBUG,
338 "plugin cfgname: %s\n",
339 ts->cfgname);
340
341 LOG (GNUNET_ERROR_TYPE_DEBUG,
342 "node ip: %s\n",
343 node_ip);
344
345 GNUNET_asprintf (&ts->testdir,
346 "%s%s%s",
347 BASE_DIR,
348 m,
349 n);
350
351 start_peer = GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
352 "system-create",
353 num,
354 node_ip,
355 handlers,
356 ts->cfgname,
357 notify_connect,
358 GNUNET_NO);
359 struct GNUNET_TESTING_Command commands[] = {
360 GNUNET_TESTING_cmd_system_create ("system-create",
361 ts->testdir),
362 start_peer,
363 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
364 write_message),
365 block_send,
366 connect_peers,
367 GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
368 "start-peer",
369 "system-create",
370 num,
371 topology),
372 block_receive,
373 local_prepared,
374 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
375 "start-peer"),
376 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
377 "system-create"),
378 GNUNET_TESTING_cmd_end ()
379 };
380
381 ts->write_message = write_message;
382
383 is = GNUNET_TESTING_run (commands,
384 TIMEOUT,
385 &handle_result,
386 ts);
387 return is;
388}
389
390
391/**
392 * Entry point for the plugin.
393 *
394 * @param cls NULL
395 * @return the exported block API
396 */
397void *
398libgnunet_test_transport_plugin_cmd_simple_send_dv_init (void *cls)
399{
400 struct GNUNET_TESTING_PluginFunctions *api;
401
402 GNUNET_log_setup ("simple-send",
403 "DEBUG",
404 NULL);
405
406 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
407 api->start_testcase = &start_testcase;
408 api->all_peers_started = &all_peers_started;
409 api->all_local_tests_prepared = all_local_tests_prepared;
410 api->get_waiting_for_barriers = get_waiting_for_barriers;
411 return api;
412}
413
414
415/**
416 * Exit point from the plugin.
417 *
418 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
419 * @return NULL
420 */
421void *
422libgnunet_test_transport_plugin_cmd_simple_send_dv_done (void *cls)
423{
424 struct GNUNET_TESTING_PluginFunctions *api = cls;
425
426 GNUNET_free (api);
427 return NULL;
428}
429
430
431/* end of plugin_cmd_simple_send_broadcast.c */