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