aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-11-29 11:51:56 +0100
committert3sserakt <t3ss@posteo.de>2021-11-29 11:51:56 +0100
commitfdb9fc3b6f1333a05e093ed1a8aee63d6308ced1 (patch)
tree0266f9cc6d245410e29d074c62c563c67321e651 /src
parent8befb3cbc19a5de6895e31efde1783c2eb6d76ce (diff)
downloadgnunet-fdb9fc3b6f1333a05e093ed1a8aee63d6308ced1.tar.gz
gnunet-fdb9fc3b6f1333a05e093ed1a8aee63d6308ced1.zip
- added distance vector testcase
Diffstat (limited to 'src')
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send_dv.c374
1 files changed, 374 insertions, 0 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
new file mode 100644
index 000000000..6a3492705
--- /dev/null
+++ b/src/transport/test_transport_plugin_cmd_simple_send_dv.c
@@ -0,0 +1,374 @@
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_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_simple_send_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 block_receive;
72
73static struct GNUNET_TESTING_Command connect_peers;
74
75static struct GNUNET_TESTING_Command local_prepared;
76
77/**
78 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
79 * received.
80 *
81 */
82static int
83check_test (void *cls,
84 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
85{
86 return GNUNET_OK;
87}
88
89
90/**
91 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
92 * being received.
93 *
94 */
95static void
96handle_test (void *cls,
97 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
98{
99 struct GNUNET_TESTING_AsyncContext *ac;
100
101 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
102 "Received test message\n");
103 GNUNET_TESTING_get_trait_async_context (&block_receive,
104 &ac);
105 GNUNET_assert (NULL != ac);
106 if (NULL == ac->cont)
107 GNUNET_TESTING_async_fail (ac);
108 else
109 GNUNET_TESTING_async_finish (ac);
110}
111
112
113/**
114 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
115 *
116 */
117static void
118all_peers_started ()
119{
120 struct GNUNET_TESTING_AsyncContext *ac;
121
122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
123 "Received message\n");
124 GNUNET_TESTING_get_trait_async_context (&block_send,
125 &ac);
126 GNUNET_assert (NULL != ac);
127 if (NULL == ac->cont)
128 GNUNET_TESTING_async_fail (ac);
129 else
130 GNUNET_TESTING_async_finish (ac);
131}
132
133
134/**
135 * Function called with the final result of the test.
136 *
137 * @param cls the `struct MainParams`
138 * @param rv #GNUNET_OK if the test passed
139 */
140static void
141handle_result (void *cls,
142 enum GNUNET_GenericReturnValue rv)
143{
144 struct TestState *ts = cls;
145 struct GNUNET_MessageHeader *reply;
146
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
148 "Local test exits with status %d\n",
149 rv);
150 reply = GNUNET_TESTING_send_local_test_finished_msg (rv);
151
152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
153 "message prepared\n");
154 ts->write_message (reply,
155 ntohs (reply->size));
156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
157 "message send\n");
158 GNUNET_free (ts->testdir);
159 GNUNET_free (ts->cfgname);
160 GNUNET_TESTING_free_topology (ts->topology);
161 GNUNET_free (ts);
162}
163
164
165/**
166 * Callback from start peer cmd for signaling a peer got connected.
167 *
168 */
169static void *
170notify_connect (struct GNUNET_TESTING_Interpreter *is,
171 const struct GNUNET_PeerIdentity *peer)
172{
173 struct ConnectPeersState *cps;
174 const struct GNUNET_TESTING_Command *cmd;
175 void *ret = NULL;
176
177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
178 "notify_connect peer %s\n",
179 GNUNET_i2s (peer));
180 cmd = GNUNET_TESTING_interpreter_lookup_command_all (is,
181 "connect-peers");
182 GNUNET_TRANSPORT_get_trait_connect_peer_state (cmd,
183 &cps);
184 cps->notify_connect (is,
185 peer);
186
187 return ret;
188}
189
190
191/**
192 * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api.
193 */
194static void
195all_local_tests_prepared ()
196{
197 struct LocalPreparedState *lfs;
198
199 GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared,
200 &lfs);
201 GNUNET_assert (NULL != &lfs->ac);
202 if (NULL == lfs->ac.cont)
203 GNUNET_TESTING_async_fail (&lfs->ac);
204 else
205 GNUNET_TESTING_async_finish (&lfs->ac);
206}
207
208
209/**
210 * Function to start a local test case.
211 *
212 * @param write_message Callback to send a message to the master loop.
213 * @param router_ip Global address of the network namespace.
214 * @param node_ip Local address of a node i a network namespace.
215 * @param m The number of the node in a network namespace.
216 * @param n The number of the network namespace.
217 * @param local_m The number of nodes in a network namespace.
218 */
219static void
220start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
221 char *node_ip,
222 char *m,
223 char *n,
224 char *local_m,
225 char *topology_data,
226 unsigned int *read_file)
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
235
236
237 if (GNUNET_YES == *read_file)
238 {
239 LOG (GNUNET_ERROR_TYPE_DEBUG,
240 "read from file\n");
241 topology = GNUNET_TESTING_get_topo_from_file (topology_data);
242 }
243 else
244 topology = GNUNET_TESTING_get_topo_from_string (topology_data);
245
246 ts->topology = topology;
247
248 sscanf (m, "%u", &m_int);
249 sscanf (n, "%u", &n_int);
250 sscanf (local_m, "%u", &local_m_int);
251
252 if (0 == n_int)
253 num = m_int;
254 else
255 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
256
257 block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block");
258 block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
259 "block-receive");
260 connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
261 "start-peer",
262 "system-create",
263 num,
264 topology,
265 8);
266 local_prepared = GNUNET_TESTING_cmd_local_test_prepared (
267 "local-test-prepared",
268 write_message);
269
270
271 GNUNET_asprintf (&ts->cfgname,
272 "test_transport_api2_tcp_node1.conf");
273
274 LOG (GNUNET_ERROR_TYPE_DEBUG,
275 "plugin cfgname: %s\n",
276 ts->cfgname);
277
278 LOG (GNUNET_ERROR_TYPE_DEBUG,
279 "node ip: %s\n",
280 node_ip);
281
282 GNUNET_asprintf (&ts->testdir,
283 "%s%s%s",
284 BASE_DIR,
285 m,
286 n);
287
288 struct GNUNET_MQ_MessageHandler handlers[] = {
289 GNUNET_MQ_hd_var_size (test,
290 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
291 struct GNUNET_TRANSPORT_TESTING_TestMessage,
292 ts),
293 GNUNET_MQ_handler_end ()
294 };
295
296 struct GNUNET_TESTING_Command commands[] = {
297 GNUNET_TESTING_cmd_system_create ("system-create",
298 ts->testdir),
299 GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
300 "system-create",
301 num,
302 node_ip,
303 handlers,
304 ts->cfgname,
305 notify_connect,
306 GNUNET_YES),
307 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
308 write_message),
309 block_send,
310 connect_peers,
311 GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
312 "start-peer",
313 "system-create",
314 num,
315 topology),
316 block_receive,
317 local_prepared,
318 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
319 "start-peer"),
320 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
321 "system-create"),
322 GNUNET_TESTING_cmd_end ()
323 };
324
325 ts->write_message = write_message;
326
327 GNUNET_TESTING_run (commands,
328 GNUNET_TIME_UNIT_FOREVER_REL,
329 &handle_result,
330 ts);
331
332}
333
334
335/**
336 * Entry point for the plugin.
337 *
338 * @param cls NULL
339 * @return the exported block API
340 */
341void *
342libgnunet_test_transport_plugin_cmd_simple_send_dv_init (void *cls)
343{
344 struct GNUNET_TESTING_PluginFunctions *api;
345
346 GNUNET_log_setup ("simple-send",
347 "DEBUG",
348 NULL);
349
350 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
351 api->start_testcase = &start_testcase;
352 api->all_peers_started = &all_peers_started;
353 api->all_local_tests_prepared = all_local_tests_prepared;
354 return api;
355}
356
357
358/**
359 * Exit point from the plugin.
360 *
361 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
362 * @return NULL
363 */
364void *
365libgnunet_test_transport_plugin_cmd_simple_send_dv_done (void *cls)
366{
367 struct GNUNET_TESTING_PluginFunctions *api = cls;
368
369 GNUNET_free (api);
370 return NULL;
371}
372
373
374/* end of plugin_cmd_simple_send_broadcast.c */