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