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