aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_testing_netjail_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_testing_netjail_lib.h')
-rw-r--r--src/include/gnunet_testing_netjail_lib.h224
1 files changed, 121 insertions, 103 deletions
diff --git a/src/include/gnunet_testing_netjail_lib.h b/src/include/gnunet_testing_netjail_lib.h
index 334f43c88..843fce0d5 100644
--- a/src/include/gnunet_testing_netjail_lib.h
+++ b/src/include/gnunet_testing_netjail_lib.h
@@ -27,9 +27,8 @@
27#ifndef GNUNET_TESTING_NETJAIL_LIB_H 27#ifndef GNUNET_TESTING_NETJAIL_LIB_H
28#define GNUNET_TESTING_NETJAIL_LIB_H 28#define GNUNET_TESTING_NETJAIL_LIB_H
29 29
30#include "gnunet_util_lib.h"
31#include "gnunet_testing_plugin.h"
32#include "gnunet_testing_ng_lib.h" 30#include "gnunet_testing_ng_lib.h"
31#include "gnunet_testing_plugin.h"
33 32
34 33
35/** 34/**
@@ -52,7 +51,7 @@ struct GNUNET_TESTING_NetjailRouter
52/** 51/**
53 * Enum for the different types of nodes. 52 * Enum for the different types of nodes.
54 */ 53 */
55enum GNUNET_TESTING_NODE_TYPE 54enum GNUNET_TESTING_NodeType
56{ 55{
57 /** 56 /**
58 * Node in a subnet. 57 * Node in a subnet.
@@ -121,7 +120,7 @@ struct GNUNET_TESTING_NodeConnection
121 /** 120 /**
122 * The type of the node this connection points to. 121 * The type of the node this connection points to.
123 */ 122 */
124 enum GNUNET_TESTING_NODE_TYPE node_type; 123 enum GNUNET_TESTING_NodeType node_type;
125 124
126 /** 125 /**
127 * The node which establish the connection 126 * The node which establish the connection
@@ -145,6 +144,16 @@ struct GNUNET_TESTING_NodeConnection
145struct GNUNET_TESTING_NetjailNode 144struct GNUNET_TESTING_NetjailNode
146{ 145{
147 /** 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 /**
148 * Plugin for the test case to be run on this node. 157 * Plugin for the test case to be run on this node.
149 */ 158 */
150 char *plugin; 159 char *plugin;
@@ -165,14 +174,19 @@ struct GNUNET_TESTING_NetjailNode
165 unsigned int node_n; 174 unsigned int node_n;
166 175
167 /** 176 /**
168 * Head of the DLL with the connections which shall be established to other nodes. 177 * The overall number of the node in the whole test system.
169 */ 178 */
170 struct GNUNET_TESTING_NodeConnection *node_connections_head; 179 unsigned int node_number;
171 180
172 /** 181 /**
173 * Tail of the DLL with the connections which shall be established to other nodes. 182 * The number of unintentional additional connections this node waits for. This overwrites the global additional_connects value.
174 */ 183 */
175 struct GNUNET_TESTING_NodeConnection *node_connections_tail; 184 unsigned int additional_connects;
185
186 /**
187 * The number of cmds waiting for a specific barrier.
188 */
189 unsigned int expected_reaches;
176}; 190};
177 191
178 192
@@ -232,6 +246,11 @@ struct GNUNET_TESTING_NetjailTopology
232 * Hash map containing the global known nodes which are not natted. 246 * Hash map containing the global known nodes which are not natted.
233 */ 247 */
234 struct GNUNET_CONTAINER_MultiShortmap *map_globals; 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;
235}; 254};
236 255
237/** 256/**
@@ -245,13 +264,37 @@ GNUNET_TESTING_get_topo_from_file (const char *filename);
245 264
246 265
247/** 266/**
267 * FIXME: this could use a "to_string".
248 * Parse the topology data. 268 * Parse the topology data.
249 * 269 *
250 * @param data The topology data. 270 * @param data The topology data.
251 * @return The GNUNET_TESTING_NetjailTopology 271 * @return The GNUNET_TESTING_NetjailTopology
252 */ 272 */
253struct GNUNET_TESTING_NetjailTopology * 273struct GNUNET_TESTING_NetjailTopology *
254GNUNET_TESTING_get_topo_from_string (char *data); 274GNUNET_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 */
283unsigned int
284GNUNET_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 */
295struct GNUNET_TESTING_NetjailNode *
296GNUNET_TESTING_get_node (unsigned int num,
297 struct GNUNET_TESTING_NetjailTopology *topology);
255 298
256 299
257/** 300/**
@@ -262,8 +305,8 @@ GNUNET_TESTING_get_topo_from_string (char *data);
262 * @return The connections of the node. 305 * @return The connections of the node.
263 */ 306 */
264struct GNUNET_TESTING_NodeConnection * 307struct GNUNET_TESTING_NodeConnection *
265GNUNET_TESTING_get_connections (unsigned int num, struct 308GNUNET_TESTING_get_connections (unsigned int num,
266 GNUNET_TESTING_NetjailTopology *topology); 309 const struct GNUNET_TESTING_NetjailTopology *topology);
267 310
268 311
269/** 312/**
@@ -275,7 +318,7 @@ GNUNET_TESTING_get_connections (unsigned int num, struct
275 */ 318 */
276char * 319char *
277GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection, 320GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection,
278 char *prefix); 321 const char *prefix);
279 322
280 323
281/** 324/**
@@ -288,7 +331,7 @@ GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology);
288 331
289 332
290/** 333/**
291 * Calculate the unique id identifying a node from a given connction. 334 * Calculate the unique id identifying a node from a given connection.
292 * 335 *
293 * @param node_connection The connection we calculate the id from. 336 * @param node_connection The connection we calculate the id from.
294 * @param topology The topology we get all needed information from. 337 * @param topology The topology we get all needed information from.
@@ -304,7 +347,7 @@ GNUNET_TESTING_calculate_num (struct
304 * Struct with information for callbacks. 347 * Struct with information for callbacks.
305 * 348 *
306 */ 349 */
307struct BlockState 350struct GNUNET_TESTING_BlockState
308{ 351{
309 /** 352 /**
310 * Context for our asynchronous completion. 353 * Context for our asynchronous completion.
@@ -326,7 +369,7 @@ struct BlockState
326 * Struct to hold information for callbacks. 369 * Struct to hold information for callbacks.
327 * 370 *
328 */ 371 */
329struct LocalPreparedState 372struct GNUNET_TESTING_LocalPreparedState
330{ 373{
331 /** 374 /**
332 * Context for our asynchronous completion. 375 * Context for our asynchronous completion.
@@ -337,28 +380,35 @@ struct LocalPreparedState
337 * Callback to write messages to the master loop. 380 * Callback to write messages to the master loop.
338 * 381 *
339 */ 382 */
340 TESTING_CMD_HELPER_write_cb write_message; 383 GNUNET_TESTING_cmd_helper_write_cb write_message;
341}; 384};
342 385
343 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 */
344struct GNUNET_TESTING_Command 394struct GNUNET_TESTING_Command
345GNUNET_TESTING_cmd_system_destroy (const char *label, 395GNUNET_TESTING_cmd_system_destroy (const char *label,
346 const char *create_label); 396 const char *create_label);
347 397
348 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 */
349struct GNUNET_TESTING_Command 405struct GNUNET_TESTING_Command
350GNUNET_TESTING_cmd_system_create (const char *label, 406GNUNET_TESTING_cmd_system_create (const char *label,
351 const char *testdir); 407 const char *testdir);
352 408
353 409
354int
355GNUNET_TESTING_get_trait_test_system (const struct
356 GNUNET_TESTING_Command *cmd,
357 struct GNUNET_TESTING_System **test_system);
358
359
360/** 410/**
361 * Create command. 411 * This command executes a shell script to setup the netjail environment.
362 * 412 *
363 * @param label name for command. 413 * @param label name for command.
364 * @param topology_config Configuration file for the test topology. 414 * @param topology_config Configuration file for the test topology.
@@ -372,7 +422,7 @@ GNUNET_TESTING_cmd_netjail_start (const char *label,
372 422
373 423
374/** 424/**
375 * Create command. 425 * This command executes a shell script to remove the netjail environment.
376 * 426 *
377 * @param label name for command. 427 * @param label name for command.
378 * @param topology_config Configuration file for the test topology. 428 * @param topology_config Configuration file for the test topology.
@@ -386,20 +436,23 @@ GNUNET_TESTING_cmd_netjail_stop (const char *label,
386 436
387 437
388/** 438/**
389 * Create command. 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.
390 * 441 *
391 * @param label Name for the command. 442 * @param label Name for the command.
392 * @param topology The complete topology information. 443 * @param topology The complete topology information.
393 * @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. 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.
394 * @param topology_data If read_file is GNUNET_NO, topology_data holds the string with the topology. 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.
395 * @return command. 447 * @return command.
396 */ 448 */
397struct GNUNET_TESTING_Command 449struct GNUNET_TESTING_Command
398GNUNET_TESTING_cmd_netjail_start_testing_system ( 450GNUNET_TESTING_cmd_netjail_start_cmds_helper (
399 const char *label, 451 const char *label,
400 struct GNUNET_TESTING_NetjailTopology *topology, 452 struct GNUNET_TESTING_NetjailTopology *topology,
401 unsigned int *read_file, 453 unsigned int *read_file,
402 char *topology_data); 454 char *topology_data,
455 struct GNUNET_TIME_Relative timeout);
403 456
404 457
405/** 458/**
@@ -411,118 +464,83 @@ GNUNET_TESTING_cmd_netjail_start_testing_system (
411 * @return command. 464 * @return command.
412 */ 465 */
413struct GNUNET_TESTING_Command 466struct GNUNET_TESTING_Command
414GNUNET_TESTING_cmd_stop_testing_system ( 467GNUNET_TESTING_cmd_stop_cmds_helper (
415 const char *label, 468 const char *label,
416 const char *helper_start_label, 469 const char *helper_start_label,
417 struct GNUNET_TESTING_NetjailTopology *topology); 470 struct GNUNET_TESTING_NetjailTopology *topology);
418 471
419 472
420/** 473/**
421 * Create a GNUNET_CMDS_LOCAL_FINISHED message. 474 * This command is used to block the loop, until the command is finished by other commands,
422 * 475 * using a trait to get this commands struct GNUNET_TESTING_AsyncContext.
423 * @param rv The result of the local test as GNUNET_GenericReturnValue.
424 * @return The GNUNET_CMDS_LOCAL_FINISHED message.
425*/
426struct GNUNET_MessageHeader *
427GNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv);
428
429
430/**
431 * Function to get the trait with the async context.
432 *
433 * @param[out] ac GNUNET_TESTING_AsyncContext.
434 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
435 */
436int
437GNUNET_TESTING_get_trait_async_context (
438 const struct GNUNET_TESTING_Command *cmd,
439 struct GNUNET_TESTING_AsyncContext **ac);
440
441
442/**
443 * Offer handles to testing cmd helper from trait
444 *
445 * @param cmd command to extract the message from.
446 * @param pt pointer to message.
447 * @return #GNUNET_OK on success.
448 */
449enum GNUNET_GenericReturnValue
450GNUNET_TESTING_get_trait_helper_handles (
451 const struct GNUNET_TESTING_Command *cmd,
452 struct GNUNET_HELPER_Handle ***helper);
453
454
455struct GNUNET_TESTING_Command
456GNUNET_TESTING_cmd_block_until_all_peers_started (
457 const char *label,
458 unsigned int *all_peers_started);
459
460
461/**
462 * Create command.
463 * 476 *
464 * @param label name for command. 477 * @param label name for command.
465 * @param all_peers_started Flag which will be set from outside.
466 * @param asynchronous_finish If GNUNET_YES this command will not block.
467 * @return command. 478 * @return command.
468 */ 479 */
469struct GNUNET_TESTING_Command 480struct GNUNET_TESTING_Command
470GNUNET_TESTING_cmd_block_until_external_trigger ( 481GNUNET_TESTING_cmd_block_until_external_trigger (
471 const char *label); 482 const char *label);
472 483
473
474struct GNUNET_TESTING_Command
475GNUNET_TESTING_cmd_send_peer_ready (const char *label,
476 TESTING_CMD_HELPER_write_cb write_message);
477
478
479/** 484/**
480 * Create command. 485 * DEPRECATED
486 * This command sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED message to the master loop.
481 * 487 *
482 * @param label name for command. 488 * @param label name for command.
483 * @param write_message Callback to write messages to the master loop. 489 * @param write_message Callback to write messages to the master loop.
484 * @return command. 490 * @return command.
485 */ 491 */
486struct GNUNET_TESTING_Command 492struct GNUNET_TESTING_Command
487GNUNET_TESTING_cmd_local_test_finished ( 493GNUNET_TESTING_cmd_send_peer_ready (const char *label,
488 const char *label, 494 GNUNET_TESTING_cmd_helper_write_cb write_message);
489 TESTING_CMD_HELPER_write_cb write_message); 495
490 496
491/** 497/**
492 * Create command. 498 * This command sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_TESTS_PREPARED message to the master loop.
493 * 499 *
494 * @param label name for command. 500 * @param label name for command.
495 * @param write_message Callback to write messages to the master loop. 501 * @param write_message Callback to write messages to the master loop.
496 * @param all_local_tests_prepared Flag which will be set from outside.
497 * @return command. 502 * @return command.
498 */ 503 */
499struct GNUNET_TESTING_Command 504struct GNUNET_TESTING_Command
500GNUNET_TESTING_cmd_local_test_prepared (const char *label, 505GNUNET_TESTING_cmd_local_test_prepared (const char *label,
501 TESTING_CMD_HELPER_write_cb 506 GNUNET_TESTING_cmd_helper_write_cb
502 write_message); 507 write_message);
503 508
509
504/** 510/**
505 * Function to get the trait with the struct LocalPreparedState. 511 * Create command.
506 *
507 * @param[out] lfs struct LocalPreparedState.
508 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
509 * 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.
510 */ 520 */
511enum GNUNET_GenericReturnValue 521struct GNUNET_TESTING_Command
512GNUNET_TESTING_get_trait_local_prepared_state ( 522GNUNET_TESTING_cmd_start_peer (const char *label,
513 const struct GNUNET_TESTING_Command *cmd, 523 const char *system_label,
514 struct LocalPreparedState **lfs); 524 uint32_t no,
525 const char *node_ip,
526 const char *cfgname,
527 unsigned int broadcast);
528
529
530/* ***** Netjail trait support ***** */
515 531
516 532
517/** 533/**
518 * Function to get the trait with the internal command state BlockState. 534 * Call #op on all simple traits.
519 *
520 * * @param[out] ac struct BlockState.
521* @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
522 */ 535 */
523int 536#define GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS(op, prefix) \
524GNUNET_TESTING_get_trait_block_state ( 537 op (prefix, test_system, const struct GNUNET_TESTING_System) \
525 const struct GNUNET_TESTING_Command *cmd, 538 op (prefix, async_context, struct GNUNET_TESTING_AsyncContext) \
526 struct BlockState **bs); 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
543GNUNET_TESTING_SIMPLE_NETJAIL_TRAITS (GNUNET_TESTING_MAKE_DECL_SIMPLE_TRAIT, GNUNET_TESTING)
544
527 545
528#endif 546#endif