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