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