diff options
Diffstat (limited to 'src/include/gnunet_testing_netjail_lib.h')
-rw-r--r-- | src/include/gnunet_testing_netjail_lib.h | 515 |
1 files changed, 0 insertions, 515 deletions
diff --git a/src/include/gnunet_testing_netjail_lib.h b/src/include/gnunet_testing_netjail_lib.h deleted file mode 100644 index b65ae6537..000000000 --- a/src/include/gnunet_testing_netjail_lib.h +++ /dev/null | |||
@@ -1,515 +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 | * @brief API for writing an interpreter to test GNUnet components | ||
23 | * @author Christian Grothoff <christian@grothoff.org> | ||
24 | * @author Marcello Stanisci | ||
25 | * @author t3sserakt | ||
26 | */ | ||
27 | #ifndef GNUNET_TESTING_NETJAIL_LIB_H | ||
28 | #define GNUNET_TESTING_NETJAIL_LIB_H | ||
29 | |||
30 | #include "gnunet_util_lib.h" | ||
31 | #include "gnunet_testing_plugin.h" | ||
32 | #include "gnunet_testing_ng_lib.h" | ||
33 | |||
34 | |||
35 | /** | ||
36 | * Router of a netjail subnet. | ||
37 | */ | ||
38 | struct GNUNET_TESTING_NetjailRouter | ||
39 | { | ||
40 | /** | ||
41 | * Will tcp be forwarded? | ||
42 | */ | ||
43 | unsigned int tcp_port; | ||
44 | |||
45 | /** | ||
46 | * Will udp be forwarded? | ||
47 | */ | ||
48 | unsigned int udp_port; | ||
49 | }; | ||
50 | |||
51 | |||
52 | /** | ||
53 | * Enum for the different types of nodes. | ||
54 | */ | ||
55 | enum GNUNET_TESTING_NODE_TYPE | ||
56 | { | ||
57 | /** | ||
58 | * Node in a subnet. | ||
59 | */ | ||
60 | GNUNET_TESTING_SUBNET_NODE, | ||
61 | |||
62 | /** | ||
63 | * Global known node. | ||
64 | */ | ||
65 | GNUNET_TESTING_GLOBAL_NODE | ||
66 | }; | ||
67 | |||
68 | /** | ||
69 | * Protocol address prefix für a connection between nodes. | ||
70 | */ | ||
71 | struct GNUNET_TESTING_AddressPrefix | ||
72 | { | ||
73 | /** | ||
74 | * Pointer to the previous prefix in the DLL. | ||
75 | */ | ||
76 | struct GNUNET_TESTING_AddressPrefix *prev; | ||
77 | |||
78 | /** | ||
79 | * Pointer to the next prefix in the DLL. | ||
80 | */ | ||
81 | struct GNUNET_TESTING_AddressPrefix *next; | ||
82 | |||
83 | /** | ||
84 | * The address prefix. | ||
85 | */ | ||
86 | char *address_prefix; | ||
87 | }; | ||
88 | |||
89 | |||
90 | /** | ||
91 | * Node in a netjail topology. | ||
92 | */ | ||
93 | struct GNUNET_TESTING_NetjailNode; | ||
94 | |||
95 | /** | ||
96 | * Connection to another node. | ||
97 | */ | ||
98 | struct GNUNET_TESTING_NodeConnection | ||
99 | { | ||
100 | /** | ||
101 | * Pointer to the previous connection in the DLL. | ||
102 | */ | ||
103 | struct GNUNET_TESTING_NodeConnection *prev; | ||
104 | |||
105 | /** | ||
106 | * Pointer to the next connection in the DLL. | ||
107 | */ | ||
108 | struct GNUNET_TESTING_NodeConnection *next; | ||
109 | |||
110 | /** | ||
111 | * The number of the subnet of the node this connection points to. This is 0, | ||
112 | * if the node is a global known node. | ||
113 | */ | ||
114 | unsigned int namespace_n; | ||
115 | |||
116 | /** | ||
117 | * The number of the node this connection points to. | ||
118 | */ | ||
119 | unsigned int node_n; | ||
120 | |||
121 | /** | ||
122 | * The type of the node this connection points to. | ||
123 | */ | ||
124 | enum GNUNET_TESTING_NODE_TYPE node_type; | ||
125 | |||
126 | /** | ||
127 | * The node which establish the connection | ||
128 | */ | ||
129 | struct GNUNET_TESTING_NetjailNode *node; | ||
130 | |||
131 | /** | ||
132 | * Head of the DLL with the address prefixes for the protocolls this node is reachable. | ||
133 | */ | ||
134 | struct GNUNET_TESTING_AddressPrefix *address_prefixes_head; | ||
135 | |||
136 | /** | ||
137 | * Tail of the DLL with the address prefixes for the protocolls this node is reachable. | ||
138 | */ | ||
139 | struct GNUNET_TESTING_AddressPrefix *address_prefixes_tail; | ||
140 | }; | ||
141 | |||
142 | /** | ||
143 | * Node in the netjail topology. | ||
144 | */ | ||
145 | struct GNUNET_TESTING_NetjailNode | ||
146 | { | ||
147 | /** | ||
148 | * Plugin for the test case to be run on this node. | ||
149 | */ | ||
150 | char *plugin; | ||
151 | |||
152 | /** | ||
153 | * Flag indicating if this node is a global known node. | ||
154 | */ | ||
155 | unsigned int is_global; | ||
156 | |||
157 | /** | ||
158 | * The number of the subnet this node is running in. | ||
159 | */ | ||
160 | unsigned int namespace_n; | ||
161 | |||
162 | /** | ||
163 | * The number of this node in the subnet. | ||
164 | */ | ||
165 | unsigned int node_n; | ||
166 | |||
167 | /** | ||
168 | * Head of the DLL with the connections which shall be established to other nodes. | ||
169 | */ | ||
170 | struct GNUNET_TESTING_NodeConnection *node_connections_head; | ||
171 | |||
172 | /** | ||
173 | * Tail of the DLL with the connections which shall be established to other nodes. | ||
174 | */ | ||
175 | struct GNUNET_TESTING_NodeConnection *node_connections_tail; | ||
176 | }; | ||
177 | |||
178 | |||
179 | /** | ||
180 | * Subnet in a topology. | ||
181 | */ | ||
182 | struct GNUNET_TESTING_NetjailNamespace | ||
183 | { | ||
184 | /** | ||
185 | * The number of the subnet. | ||
186 | */ | ||
187 | unsigned int namespace_n; | ||
188 | |||
189 | /** | ||
190 | * Router of the subnet. | ||
191 | */ | ||
192 | struct GNUNET_TESTING_NetjailRouter *router; | ||
193 | |||
194 | /** | ||
195 | * Hash map containing the nodes in this subnet. | ||
196 | */ | ||
197 | struct GNUNET_CONTAINER_MultiShortmap *nodes; | ||
198 | }; | ||
199 | |||
200 | /** | ||
201 | * Toplogy of our netjail setup. | ||
202 | */ | ||
203 | struct GNUNET_TESTING_NetjailTopology | ||
204 | { | ||
205 | |||
206 | /** | ||
207 | * Default plugin for the test case to be run on nodes. | ||
208 | */ | ||
209 | char *plugin; | ||
210 | |||
211 | /** | ||
212 | * Number of subnets. | ||
213 | */ | ||
214 | unsigned int namespaces_n; | ||
215 | |||
216 | /** | ||
217 | * Number of nodes per subnet. | ||
218 | */ | ||
219 | unsigned int nodes_m; | ||
220 | |||
221 | /** | ||
222 | * Number of global known nodes. | ||
223 | */ | ||
224 | unsigned int nodes_x; | ||
225 | |||
226 | /** | ||
227 | * Hash map containing the subnets (for natted nodes) of the topology. | ||
228 | */ | ||
229 | struct GNUNET_CONTAINER_MultiShortmap *map_namespaces; | ||
230 | |||
231 | /** | ||
232 | * Hash map containing the global known nodes which are not natted. | ||
233 | */ | ||
234 | struct GNUNET_CONTAINER_MultiShortmap *map_globals; | ||
235 | |||
236 | /** | ||
237 | * Additional connects we do expect, beside the connects which are configured in the topology. | ||
238 | */ | ||
239 | unsigned int additional_connects; | ||
240 | }; | ||
241 | |||
242 | /** | ||
243 | * Getting the topology from file. | ||
244 | * | ||
245 | * @param filename The name of the topology file. | ||
246 | * @return The GNUNET_TESTING_NetjailTopology | ||
247 | */ | ||
248 | struct GNUNET_TESTING_NetjailTopology * | ||
249 | GNUNET_TESTING_get_topo_from_file (const char *filename); | ||
250 | |||
251 | |||
252 | /** | ||
253 | * Parse the topology data. | ||
254 | * | ||
255 | * @param data The topology data. | ||
256 | * @return The GNUNET_TESTING_NetjailTopology | ||
257 | */ | ||
258 | struct GNUNET_TESTING_NetjailTopology * | ||
259 | GNUNET_TESTING_get_topo_from_string (char *data); | ||
260 | |||
261 | |||
262 | /** | ||
263 | * Get the connections to other nodes for a specific node. | ||
264 | * | ||
265 | * @param num The specific node we want the connections for. | ||
266 | * @param topology The topology we get the connections from. | ||
267 | * @return The connections of the node. | ||
268 | */ | ||
269 | struct GNUNET_TESTING_NodeConnection * | ||
270 | GNUNET_TESTING_get_connections (unsigned int num, struct | ||
271 | GNUNET_TESTING_NetjailTopology *topology); | ||
272 | |||
273 | |||
274 | /** | ||
275 | * Get the address for a specific communicator from a connection. | ||
276 | * | ||
277 | * @param connection The connection we like to have the address from. | ||
278 | * @param prefix The communicator protocol prefix. | ||
279 | * @return The address of the communicator. | ||
280 | */ | ||
281 | char * | ||
282 | GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection, | ||
283 | char *prefix); | ||
284 | |||
285 | |||
286 | /** | ||
287 | * Deallocate memory of the struct GNUNET_TESTING_NetjailTopology. | ||
288 | * | ||
289 | * @param topology The GNUNET_TESTING_NetjailTopology to be deallocated. | ||
290 | */ | ||
291 | void | ||
292 | GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology); | ||
293 | |||
294 | |||
295 | /** | ||
296 | * Calculate the unique id identifying a node from a given connection. | ||
297 | * | ||
298 | * @param node_connection The connection we calculate the id from. | ||
299 | * @param topology The topology we get all needed information from. | ||
300 | * @return The unique id of the node from the connection. | ||
301 | */ | ||
302 | unsigned int | ||
303 | GNUNET_TESTING_calculate_num (struct | ||
304 | GNUNET_TESTING_NodeConnection *node_connection, | ||
305 | struct GNUNET_TESTING_NetjailTopology *topology); | ||
306 | |||
307 | |||
308 | /** | ||
309 | * Struct with information for callbacks. | ||
310 | * | ||
311 | */ | ||
312 | struct BlockState | ||
313 | { | ||
314 | /** | ||
315 | * Context for our asynchronous completion. | ||
316 | */ | ||
317 | struct GNUNET_TESTING_AsyncContext ac; | ||
318 | |||
319 | /** | ||
320 | * The label of this command. | ||
321 | */ | ||
322 | const char *label; | ||
323 | |||
324 | /** | ||
325 | * If this command will block. | ||
326 | */ | ||
327 | unsigned int asynchronous_finish; | ||
328 | }; | ||
329 | |||
330 | /** | ||
331 | * Struct to hold information for callbacks. | ||
332 | * | ||
333 | */ | ||
334 | struct LocalPreparedState | ||
335 | { | ||
336 | /** | ||
337 | * Context for our asynchronous completion. | ||
338 | */ | ||
339 | struct GNUNET_TESTING_AsyncContext ac; | ||
340 | |||
341 | /** | ||
342 | * Callback to write messages to the master loop. | ||
343 | * | ||
344 | */ | ||
345 | TESTING_CMD_HELPER_write_cb write_message; | ||
346 | }; | ||
347 | |||
348 | |||
349 | struct GNUNET_TESTING_Command | ||
350 | GNUNET_TESTING_cmd_system_destroy (const char *label, | ||
351 | const char *create_label); | ||
352 | |||
353 | |||
354 | struct GNUNET_TESTING_Command | ||
355 | GNUNET_TESTING_cmd_system_create (const char *label, | ||
356 | const char *testdir); | ||
357 | |||
358 | |||
359 | /** | ||
360 | * Create command. | ||
361 | * | ||
362 | * @param label name for command. | ||
363 | * @param topology_config Configuration file for the test topology. | ||
364 | * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data. | ||
365 | * @return command. | ||
366 | */ | ||
367 | struct GNUNET_TESTING_Command | ||
368 | GNUNET_TESTING_cmd_netjail_start (const char *label, | ||
369 | char *topology_config, | ||
370 | unsigned int *read_file); | ||
371 | |||
372 | |||
373 | /** | ||
374 | * Create command. | ||
375 | * | ||
376 | * @param label name for command. | ||
377 | * @param topology_config Configuration file for the test topology. | ||
378 | * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data. | ||
379 | * @return command. | ||
380 | */ | ||
381 | struct GNUNET_TESTING_Command | ||
382 | GNUNET_TESTING_cmd_netjail_stop (const char *label, | ||
383 | char *topology_config, | ||
384 | unsigned int *read_file); | ||
385 | |||
386 | |||
387 | /** | ||
388 | * Create command. | ||
389 | * | ||
390 | * @param label Name for the command. | ||
391 | * @param topology The complete topology information. | ||
392 | * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data. | ||
393 | * @param topology_data If read_file is GNUNET_NO, topology_data holds the string with the topology. | ||
394 | * @param timeout Before this timeout is reached this cmd MUST finish. | ||
395 | * @return command. | ||
396 | */ | ||
397 | struct GNUNET_TESTING_Command | ||
398 | GNUNET_TESTING_cmd_netjail_start_testing_system ( | ||
399 | const char *label, | ||
400 | struct GNUNET_TESTING_NetjailTopology *topology, | ||
401 | unsigned int *read_file, | ||
402 | char *topology_data, | ||
403 | struct GNUNET_TIME_Relative timeout); | ||
404 | |||
405 | |||
406 | /** | ||
407 | * Create command. | ||
408 | * | ||
409 | * @param label name for command. | ||
410 | * @param helper_start_label label of the cmd to start the test system. | ||
411 | * @param topology The complete topology information. | ||
412 | * @return command. | ||
413 | */ | ||
414 | struct GNUNET_TESTING_Command | ||
415 | GNUNET_TESTING_cmd_stop_testing_system ( | ||
416 | const char *label, | ||
417 | const char *helper_start_label, | ||
418 | struct GNUNET_TESTING_NetjailTopology *topology); | ||
419 | |||
420 | |||
421 | /** | ||
422 | * Create a GNUNET_CMDS_LOCAL_FINISHED message. | ||
423 | * | ||
424 | * @param rv The result of the local test as GNUNET_GenericReturnValue. | ||
425 | * @return The GNUNET_CMDS_LOCAL_FINISHED message. | ||
426 | */ | ||
427 | struct GNUNET_MessageHeader * | ||
428 | GNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv); | ||
429 | |||
430 | |||
431 | struct GNUNET_TESTING_Command | ||
432 | GNUNET_TESTING_cmd_barrier_create ( | ||
433 | const char *label); | ||
434 | |||
435 | |||
436 | struct GNUNET_TESTING_Command | ||
437 | GNUNET_TESTING_cmd_barrier_setup_finished ( | ||
438 | const char *label); | ||
439 | |||
440 | |||
441 | // Wait for barrier to be reached by all; | ||
442 | // async version implies reached but does not | ||
443 | // wait on other peers to reach it. | ||
444 | struct GNUNET_TESTING_Command | ||
445 | GNUNET_TESTING_cmd_barrier_reached ( | ||
446 | const char *label, | ||
447 | const char *barrier_label); | ||
448 | |||
449 | |||
450 | struct GNUNET_TESTING_Command | ||
451 | GNUNET_TESTING_cmd_block_until_all_peers_started ( | ||
452 | const char *label, | ||
453 | unsigned int *all_peers_started); | ||
454 | |||
455 | |||
456 | /** | ||
457 | * Create command. | ||
458 | * | ||
459 | * @param label name for command. | ||
460 | * @param all_peers_started Flag which will be set from outside. | ||
461 | * @param asynchronous_finish If GNUNET_YES this command will not block. | ||
462 | * @return command. | ||
463 | */ | ||
464 | struct GNUNET_TESTING_Command | ||
465 | GNUNET_TESTING_cmd_block_until_external_trigger ( | ||
466 | const char *label); | ||
467 | |||
468 | |||
469 | struct GNUNET_TESTING_Command | ||
470 | GNUNET_TESTING_cmd_send_peer_ready (const char *label, | ||
471 | TESTING_CMD_HELPER_write_cb write_message); | ||
472 | |||
473 | |||
474 | /** | ||
475 | * Create command. | ||
476 | * | ||
477 | * @param label name for command. | ||
478 | * @param write_message Callback to write messages to the master loop. | ||
479 | * @return command. | ||
480 | */ | ||
481 | struct GNUNET_TESTING_Command | ||
482 | GNUNET_TESTING_cmd_local_test_finished ( | ||
483 | const char *label, | ||
484 | TESTING_CMD_HELPER_write_cb write_message); | ||
485 | |||
486 | /** | ||
487 | * Create command. | ||
488 | * | ||
489 | * @param label name for command. | ||
490 | * @param write_message Callback to write messages to the master loop. | ||
491 | * @param all_local_tests_prepared Flag which will be set from outside. | ||
492 | * @return command. | ||
493 | */ | ||
494 | struct GNUNET_TESTING_Command | ||
495 | GNUNET_TESTING_cmd_local_test_prepared (const char *label, | ||
496 | TESTING_CMD_HELPER_write_cb | ||
497 | write_message); | ||
498 | |||
499 | |||
500 | /* ***** Netjail trait support ***** */ | ||
501 | |||
502 | |||
503 | /** | ||
504 | * Call #op on all simple traits. | ||
505 | */ | ||
506 | #define GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS(op) \ | ||
507 | op (test_system, const struct GNUNET_TESTING_System) \ | ||
508 | op (async_context, const struct GNUNET_TESTING_AsyncContext) \ | ||
509 | op (helper_handles, const struct GNUNET_HELPER_Handle *) \ | ||
510 | op (local_prepared_state, const struct LocalPreparedState) \ | ||
511 | op (block_state, const struct BlockState) | ||
512 | |||
513 | GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT) | ||
514 | |||
515 | #endif | ||