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