aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_plugin_cmd_udp_backchannel.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_transport_plugin_cmd_udp_backchannel.c')
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel.c356
1 files changed, 0 insertions, 356 deletions
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
deleted file mode 100644
index 537832e61..000000000
--- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c
+++ /dev/null
@@ -1,356 +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.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_ng_lib.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
34/**
35 * Generic logging shortcut
36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38
39#define BASE_DIR "testdir"
40
41#define TOPOLOGY_CONFIG "test_transport_udp_backchannel_topo.conf"
42
43struct TestState
44{
45 /**
46 * Callback to write messages to the master loop.
47 *
48 */
49 TESTING_CMD_HELPER_write_cb write_message;
50
51 /**
52 * The name for a specific test environment directory.
53 *
54 */
55 char *testdir;
56
57 /**
58 * The name for the configuration file of the specific node.
59 *
60 */
61 char *cfgname;
62
63 /**
64 * The complete topology information.
65 */
66 struct GNUNET_TESTING_NetjailTopology *topology;
67};
68
69static struct GNUNET_TESTING_Command block_send;
70
71static struct GNUNET_TESTING_Command connect_peers;
72
73static struct GNUNET_TESTING_Command local_prepared;
74
75
76/**
77 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
78 * received.
79 *
80 */
81static int
82check_test (void *cls,
83 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
84{
85 return GNUNET_OK;
86}
87
88
89/**
90 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
91 * being received.
92 *
93 */
94static void
95handle_test (void *cls,
96 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
97{
98 // struct GNUNET_TESTING_AsyncContext *ac;
99
100 /*GNUNET_TESTING_get_trait_async_context (&block_receive,
101 &ac);
102 if ((NULL == ac) || (NULL == ac->cont))
103 GNUNET_TESTING_async_fail (ac);
104 else
105 GNUNET_TESTING_async_finish (ac);*/
106}
107
108
109/**
110 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
111 *
112 */
113static void
114all_peers_started ()
115{
116 const struct GNUNET_TESTING_AsyncContext *ac;
117
118 GNUNET_TESTING_get_trait_async_context (&block_send,
119 &ac);
120 GNUNET_assert (NULL != ac);
121 if ((NULL == ac->cont))
122 GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
123 else
124 GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
125}
126
127
128/**
129* Function called with the final result of the test.
130*
131* @param cls the `struct MainParams`
132* @param rv #GNUNET_OK if the test passed
133*/
134static void
135handle_result (void *cls,
136 enum GNUNET_GenericReturnValue rv)
137{
138 struct TestState *ts = cls;
139 struct GNUNET_MessageHeader *reply;
140
141 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
142 "Local test exits with status %d\n",
143 rv);
144 reply = GNUNET_TESTING_send_local_test_finished_msg (rv);
145
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
147 "message prepared\n");
148 ts->write_message (reply,
149 ntohs (reply->size));
150
151 GNUNET_free (ts->testdir);
152 GNUNET_free (ts->cfgname);
153 GNUNET_TESTING_free_topology (ts->topology);
154 GNUNET_free (ts);
155}
156
157
158/**
159 * Callback from start peer cmd for signaling a peer got connected.
160 *
161 */
162static void *
163notify_connect (struct GNUNET_TESTING_Interpreter *is,
164 const struct GNUNET_PeerIdentity *peer)
165{
166 const struct ConnectPeersState *cps;
167
168 GNUNET_TRANSPORT_get_trait_connect_peer_state (&connect_peers,
169 &cps);
170 void *ret = NULL;
171
172 cps->notify_connect (is,
173 peer);
174 return ret;
175}
176
177/**
178 * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api.
179 */
180static void
181all_local_tests_prepared ()
182{
183 const struct LocalPreparedState *lfs;
184
185 GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared,
186 &lfs);
187 GNUNET_assert (NULL != &lfs->ac);
188 if (NULL == lfs->ac.cont)
189 GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) &lfs->ac);
190 else
191 GNUNET_TESTING_async_finish ((struct
192 GNUNET_TESTING_AsyncContext *) &lfs->ac);
193}
194
195/**
196 * Function to start a local test case.
197 *
198 * @param write_message Callback to send a message to the master loop.
199 * @param router_ip Global address of the network namespace.
200 * @param node_ip Local address of a node i a network namespace.
201 * @param m The number of the node in a network namespace.
202 * @param n The number of the network namespace.
203 * @param local_m The number of nodes in a network namespace.
204 */
205static void
206start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
207 char *node_ip,
208 char *m,
209 char *n,
210 char *local_m,
211 char *topology_data,
212 unsigned int *read_file)
213{
214
215 unsigned int n_int;
216 unsigned int m_int;
217 unsigned int local_m_int;
218 unsigned int num;
219 struct TestState *ts = GNUNET_new (struct TestState);
220
221 struct GNUNET_TESTING_NetjailTopology *topology;
222
223 if (GNUNET_YES == *read_file)
224 topology = GNUNET_TESTING_get_topo_from_file (topology_data);
225 else
226 topology = GNUNET_TESTING_get_topo_from_string (topology_data);
227
228 ts->topology = topology;
229
230 sscanf (m, "%u", &m_int);
231 sscanf (n, "%u", &n_int);
232 sscanf (local_m, "%u", &local_m_int);
233
234
235 if (0 == n_int)
236 num = m_int;
237 else
238 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
239
240 block_send = GNUNET_TESTING_cmd_block_until_external_trigger (
241 "block");
242 connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
243 "start-peer",
244 "system-create",
245 num,
246 topology,
247 0);
248 local_prepared = GNUNET_TESTING_cmd_local_test_prepared (
249 "local-test-prepared",
250 write_message);
251
252 GNUNET_asprintf (&ts->cfgname,
253 "test_transport_api2_tcp_node1.conf");
254
255 LOG (GNUNET_ERROR_TYPE_DEBUG,
256 "plugin cfgname: %s\n",
257 ts->cfgname);
258
259 LOG (GNUNET_ERROR_TYPE_DEBUG,
260 "node ip: %s\n",
261 node_ip);
262
263 GNUNET_asprintf (&ts->testdir,
264 "%s%s%s",
265 BASE_DIR,
266 m,
267 n);
268
269 struct GNUNET_MQ_MessageHandler handlers[] = {
270 GNUNET_MQ_hd_var_size (test,
271 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
272 struct GNUNET_TRANSPORT_TESTING_TestMessage,
273 NULL),
274 GNUNET_MQ_handler_end ()
275 };
276
277 struct GNUNET_TESTING_Command commands[] = {
278 GNUNET_TESTING_cmd_system_create ("system-create",
279 ts->testdir),
280 GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
281 "system-create",
282 num,
283 node_ip,
284 handlers,
285 ts->cfgname,
286 notify_connect,
287 GNUNET_NO),
288 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
289 write_message),
290 block_send,
291 connect_peers,
292 GNUNET_TRANSPORT_cmd_backchannel_check ("backchannel-check",
293 "start-peer",
294 "system-create",
295 num,
296 m_int,
297 n_int,
298 topology),
299 local_prepared,
300 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
301 "start-peer"),
302 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
303 "system-create"),
304 GNUNET_TESTING_cmd_end ()
305 };
306
307 ts->write_message = write_message;
308
309 GNUNET_TESTING_run (commands,
310 GNUNET_TIME_UNIT_FOREVER_REL,
311 &handle_result,
312 ts);
313
314}
315
316
317/**
318 * Entry point for the plugin.
319 *
320 * @param cls NULL
321 * @return the exported block API
322 */
323void *
324libgnunet_test_transport_plugin_cmd_udp_backchannel_init (void *cls)
325{
326 struct GNUNET_TESTING_PluginFunctions *api;
327
328 GNUNET_log_setup ("udp-backchannel",
329 "DEBUG",
330 NULL);
331
332 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
333 api->start_testcase = &start_testcase;
334 api->all_peers_started = &all_peers_started;
335 api->all_local_tests_prepared = all_local_tests_prepared;
336 return api;
337}
338
339
340/**
341 * Exit point from the plugin.
342 *
343 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
344 * @return NULL
345 */
346void *
347libgnunet_test_transport_plugin_cmd_udp_backchannel_done (void *cls)
348{
349 struct GNUNET_TESTING_PluginFunctions *api = cls;
350
351 GNUNET_free (api);
352 return NULL;
353}
354
355
356/* end of plugin_cmd_simple_send.c */