aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_netjail_start_testsystem.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_netjail_start_testsystem.c')
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c327
1 files changed, 203 insertions, 124 deletions
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c
index 4224a5736..a1d71c436 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -67,6 +67,11 @@ struct NetJailState
67 struct GNUNET_TESTING_AsyncContext ac; 67 struct GNUNET_TESTING_AsyncContext ac;
68 68
69 /** 69 /**
70 * The complete topology information.
71 */
72 struct GNUNET_TESTING_NetjailTopology *topology;
73
74 /**
70 * Pointer to the return value of the test. 75 * Pointer to the return value of the test.
71 * 76 *
72 */ 77 */
@@ -96,16 +101,22 @@ struct NetJailState
96 unsigned int n_helper; 101 unsigned int n_helper;
97 102
98 /** 103 /**
99 * Number of nodes in a network namespace. //TODO make this a unsigned int 104 * Number of nodes in a natted subnet.
105 *
106 */
107 unsigned int local_m;
108
109 /**
110 * Number of natted subnets.
100 * 111 *
101 */ 112 */
102 char *local_m; 113 unsigned int global_n;
103 114
104 /** 115 /**
105 * Number of network namespaces. //TODO make this a unsigned int 116 * Number of global known nodes.
106 * 117 *
107 */ 118 */
108 char *global_n; 119 unsigned int known;
109 120
110 /** 121 /**
111 * The send handle for the helper 122 * The send handle for the helper
@@ -271,7 +282,8 @@ netjail_exec_traits (void *cls,
271int 282int
272GNUNET_TESTING_get_trait_helper_handles (const struct 283GNUNET_TESTING_get_trait_helper_handles (const struct
273 GNUNET_TESTING_Command *cmd, 284 GNUNET_TESTING_Command *cmd,
274 struct GNUNET_HELPER_Handle ***helper) 285 struct GNUNET_HELPER_Handle ***
286 helper)
275{ 287{
276 return cmd->traits (cmd->cls, 288 return cmd->traits (cmd->cls,
277 (const void **) helper, 289 (const void **) helper,
@@ -301,6 +313,43 @@ clear_msg (void *cls, int result)
301} 313}
302 314
303 315
316static void
317send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
318{
319 unsigned int total_number = ns->local_m * ns->global_n + ns->known;
320 struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
321 size_t msg_length;
322 struct GNUNET_HELPER_Handle *helper;
323 struct TestingSystemCount *tbc;
324
325 tbc = GNUNET_new (struct TestingSystemCount);
326 tbc->ns = ns;
327 // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone.
328 if (0 == i)
329 tbc->count = j + total_number;
330 else
331 tbc->count = (i - 1) * ns->local_m + j + total_number + ns->known;
332
333 helper = ns->helper[tbc->count - 1 - total_number];
334 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
335 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
336 reply->header.type = htons (
337 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
338 reply->header.size = htons ((uint16_t) msg_length);
339
340 GNUNET_array_append (ns->msg, ns->n_msg, &reply->header);
341
342 struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
343 helper,
344 &reply->header,
345 GNUNET_NO,
346 &clear_msg,
347 tbc);
348
349 GNUNET_array_append (ns->shandle, ns->n_shandle, sh);
350}
351
352
304/** 353/**
305 * Functions with this signature are called whenever a 354 * Functions with this signature are called whenever a
306 * complete message is received by the tokenizer. 355 * complete message is received by the tokenizer.
@@ -319,6 +368,7 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
319 struct TestingSystemCount *tbc = cls; 368 struct TestingSystemCount *tbc = cls;
320 struct NetJailState *ns = tbc->ns; 369 struct NetJailState *ns = tbc->ns;
321 struct HelperMessage *hp_msg; 370 struct HelperMessage *hp_msg;
371 unsigned int total_number = ns->local_m * ns->global_n + ns->known;
322 372
323 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type)) 373 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
324 { 374 {
@@ -328,11 +378,31 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
328 message->type)) 378 message->type))
329 { 379 {
330 ns->number_of_peers_started++; 380 ns->number_of_peers_started++;
381 if (ns->number_of_peers_started == total_number)
382 {
383 for (int i = 1; i <= ns->known; i++)
384 {
385 send_all_peers_started (0,i, ns);
386 }
387
388 for (int i = 1; i <= ns->global_n; i++)
389 {
390 for (int j = 1; j <= ns->local_m; j++)
391 {
392 send_all_peers_started (i,j, ns);
393 }
394 }
395 ns->number_of_peers_started = 0;
396 }
331 } 397 }
332 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs ( 398 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
333 message->type)) 399 message->type))
334 { 400 {
335 ns->number_of_local_test_finished++; 401 ns->number_of_local_test_finished++;
402 if (ns->number_of_local_test_finished == total_number)
403 {
404 GNUNET_TESTING_async_finish (&ns->ac);
405 }
336 } 406 }
337 else 407 else
338 { 408 {
@@ -343,6 +413,12 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
343 hp_msg); 413 hp_msg);
344 } 414 }
345 415
416
417
418
419
420
421
346 return GNUNET_OK; 422 return GNUNET_OK;
347} 423}
348 424
@@ -354,24 +430,21 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
354static void 430static void
355exp_cb (void *cls) 431exp_cb (void *cls)
356{ 432{
357 struct NetJailState *ns = cls; 433 struct TestingSystemCount *tbc = cls;
434
358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n"); 435 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n");
359 *ns->rv = 1; 436 GNUNET_TESTING_interpreter_fail (tbc->ns->ac.is);
360} 437}
361 438
362 439
363/** 440/**
364 * Function to initialize a init message for the helper. 441 * Function to initialize a init message for the helper.
365 * 442 *
366 * @param m_char The actual node in a namespace. //TODO Change this to unsigned int
367 * @param n_char The actual namespace. //TODO Change this to unsigned int
368 * @param plugin_name Name of the test case plugin the helper will load. 443 * @param plugin_name Name of the test case plugin the helper will load.
369 * 444 *
370 */ 445 */
371static struct GNUNET_CMDS_HelperInit * 446static struct GNUNET_CMDS_HelperInit *
372create_helper_init_msg_ (char *m_char, 447create_helper_init_msg_ (const char *plugin_name)
373 char *n_char,
374 const char *plugin_name)
375{ 448{
376 struct GNUNET_CMDS_HelperInit *msg; 449 struct GNUNET_CMDS_HelperInit *msg;
377 uint16_t plugin_name_len; 450 uint16_t plugin_name_len;
@@ -398,24 +471,49 @@ create_helper_init_msg_ (char *m_char,
398static void 471static void
399start_helper (struct NetJailState *ns, struct 472start_helper (struct NetJailState *ns, struct
400 GNUNET_CONFIGURATION_Handle *config, 473 GNUNET_CONFIGURATION_Handle *config,
401 char *m_char, 474 unsigned int m,
402 char *n_char) 475 unsigned int n)
403{ 476{
404 struct GNUNET_HELPER_Handle *helper; 477 struct GNUNET_HELPER_Handle *helper;
405 struct GNUNET_CMDS_HelperInit *msg; 478 struct GNUNET_CMDS_HelperInit *msg;
406 struct TestingSystemCount *tbc; 479 struct TestingSystemCount *tbc;
407 char *const script_argv[] = { 480 char *m_char, *n_char, *global_n_char, *local_m_char, *known_char, *node_id,
408 NETJAIL_EXEC_SCRIPT, 481 *plugin;
409 m_char, 482 pid_t pid;
410 n_char, 483 unsigned int script_num;
411 GNUNET_OS_get_libexec_binary_path ( 484 struct GNUNET_ShortHashCode *hkey;
412 HELPER_CMDS_BINARY), 485 struct GNUNET_HashCode hc;
413 ns->global_n, 486 struct GNUNET_TESTING_NetjailTopology *topology = ns->topology;
414 ns->local_m, 487 struct GNUNET_TESTING_NetjailNode *node;
415 NULL 488 struct GNUNET_TESTING_NetjailNamespace *namespace;
416 }; 489
417 unsigned int m = atoi (m_char); 490
418 unsigned int n = atoi (n_char); 491 if (0 == n)
492 script_num = m - 1;
493 else
494 script_num = n - 1 + (n - 1) * ns->local_m + m + ns->known;
495 pid = getpid ();
496
497 GNUNET_asprintf (&m_char, "%u", m);
498 GNUNET_asprintf (&n_char, "%u", n);
499 GNUNET_asprintf (&local_m_char, "%u", ns->local_m);
500 GNUNET_asprintf (&global_n_char, "%u",ns->global_n);
501 GNUNET_asprintf (&known_char, "%u",ns->known);
502 GNUNET_asprintf (&node_id, "%06x-%08x\n",
503 pid,
504 script_num);
505
506
507 char *const script_argv[] = {NETJAIL_EXEC_SCRIPT,
508 m_char,
509 n_char,
510 GNUNET_OS_get_libexec_binary_path (
511 HELPER_CMDS_BINARY),
512 global_n_char,
513 local_m_char,
514 node_id,
515 NULL};
516
419 unsigned int helper_check = GNUNET_OS_check_helper_binary ( 517 unsigned int helper_check = GNUNET_OS_check_helper_binary (
420 NETJAIL_EXEC_SCRIPT, 518 NETJAIL_EXEC_SCRIPT,
421 GNUNET_YES, 519 GNUNET_YES,
@@ -423,7 +521,10 @@ start_helper (struct NetJailState *ns, struct
423 521
424 tbc = GNUNET_new (struct TestingSystemCount); 522 tbc = GNUNET_new (struct TestingSystemCount);
425 tbc->ns = ns; 523 tbc->ns = ns;
426 tbc->count = (n - 1) * atoi (ns->local_m) + m; 524 if (0 == n)
525 tbc->count = m;
526 else
527 tbc->count = (n - 1) * ns->local_m + m + ns->known;
427 528
428 GNUNET_CONTAINER_DLL_insert (ns->tbcs_head, ns->tbcs_tail, 529 GNUNET_CONTAINER_DLL_insert (ns->tbcs_head, ns->tbcs_tail,
429 tbc); 530 tbc);
@@ -434,18 +535,17 @@ start_helper (struct NetJailState *ns, struct
434 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 535 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
435 "No SUID for %s!\n", 536 "No SUID for %s!\n",
436 NETJAIL_EXEC_SCRIPT); 537 NETJAIL_EXEC_SCRIPT);
437 *ns->rv = 1; 538 GNUNET_TESTING_interpreter_fail (ns->ac.is);
438 } 539 }
439 else if (GNUNET_NO == helper_check) 540 else if (GNUNET_NO == helper_check)
440 { 541 {
441 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 542 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
442 "%s not found!\n", 543 "%s not found!\n",
443 NETJAIL_EXEC_SCRIPT); 544 NETJAIL_EXEC_SCRIPT);
444 *ns->rv = 1; 545 GNUNET_TESTING_interpreter_fail (ns->ac.is);
445 } 546 }
446 GNUNET_array_append (ns->helper, 547
447 ns->n_helper, 548 GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start (
448 GNUNET_HELPER_start (
449 GNUNET_YES, 549 GNUNET_YES,
450 NETJAIL_EXEC_SCRIPT, 550 NETJAIL_EXEC_SCRIPT,
451 script_argv, 551 script_argv,
@@ -455,9 +555,57 @@ start_helper (struct NetJailState *ns, struct
455 555
456 helper = ns->helper[tbc->count - 1]; 556 helper = ns->helper[tbc->count - 1];
457 557
458 msg = create_helper_init_msg_ (m_char, 558 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
459 n_char, 559
460 ns->plugin_name); 560 plugin = topology->plugin;
561
562 if (0 == m)
563 {
564
565 GNUNET_CRYPTO_hash (&n, sizeof(n), &hc);
566 memcpy (hkey,
567 &hc,
568 sizeof (*hkey));
569 if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_globals,
570 hkey))
571 {
572 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
573 hkey);
574 if (NULL != node->plugin)
575 plugin = node->plugin;
576 }
577
578 }
579 else
580 {
581 GNUNET_CRYPTO_hash (&m, sizeof(m), &hc);
582 memcpy (hkey,
583 &hc,
584 sizeof (*hkey));
585 if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_namespaces,
586 hkey))
587 {
588 namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
589 hkey);
590 GNUNET_CRYPTO_hash (&n, sizeof(n), &hc);
591 memcpy (hkey,
592 &hc,
593 sizeof (*hkey));
594 if (1 == GNUNET_CONTAINER_multishortmap_contains (namespace->nodes,
595 hkey))
596 {
597 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
598 hkey);
599 if (NULL != node->plugin)
600 plugin = node->plugin;
601 }
602 }
603
604
605 }
606
607 msg = create_helper_init_msg_ (plugin);
608
461 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header); 609 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
462 610
463 GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send ( 611 GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send (
@@ -472,7 +620,7 @@ start_helper (struct NetJailState *ns, struct
472 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 620 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
473 "Send handle is NULL!\n"); 621 "Send handle is NULL!\n");
474 GNUNET_free (msg); 622 GNUNET_free (msg);
475 *ns->rv = 1; 623 GNUNET_TESTING_interpreter_fail (ns->ac.is);
476 } 624 }
477} 625}
478 626
@@ -488,93 +636,26 @@ static void
488netjail_exec_run (void *cls, 636netjail_exec_run (void *cls,
489 struct GNUNET_TESTING_Interpreter *is) 637 struct GNUNET_TESTING_Interpreter *is)
490{ 638{
491 char str_m[12];
492 char str_n[12];
493 struct NetJailState *ns = cls; 639 struct NetJailState *ns = cls;
494 struct GNUNET_CONFIGURATION_Handle *config = 640 struct GNUNET_CONFIGURATION_Handle *config =
495 GNUNET_CONFIGURATION_create (); 641 GNUNET_CONFIGURATION_create ();
496 642
497 for (int i = 1; i <= atoi (ns->global_n); i++) 643 for (int i = 1; i <= ns->known; i++)
498 { 644 {
499 for (int j = 1; j <= atoi (ns->local_m); j++) 645 start_helper (ns, config,
500 { 646 i,
501 sprintf (str_n, "%d", i); 647 0);
502 sprintf (str_m, "%d", j);
503 start_helper (ns, config,
504 str_m,
505 str_n);
506 }
507 } 648 }
508}
509
510 649
511/** 650 for (int i = 1; i <= ns->global_n; i++)
512 * This function checks on three different information.
513 *
514 * 1. Did all helpers start. This is only logged.
515 * 2. Did all peer start.
516 * In this case a GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED is send to all peers.
517 * 3. Did all peers finished the test case. In this case interpreter_next will be called.
518 *
519 * => FIXME: must change _completely_.
520 */
521static int
522netjail_start_finish (void *cls,
523 GNUNET_SCHEDULER_TaskCallback cont,
524 void *cont_cls)
525{
526 unsigned int ret = GNUNET_NO;
527 struct NetJailState *ns = cls;
528 unsigned int total_number = atoi (ns->local_m) * atoi (ns->global_n);
529 struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
530 size_t msg_length;
531 struct GNUNET_HELPER_Handle *helper;
532 struct TestingSystemCount *tbc;
533
534 if (ns->number_of_local_test_finished == total_number)
535 { 651 {
536 ret = GNUNET_YES; 652 for (int j = 1; j <= ns->local_m; j++)
537 cont (cont_cls);
538 }
539
540 if (ns->number_of_testsystems_started == total_number)
541 {
542 ns->number_of_testsystems_started = 0;
543 }
544
545 if (ns->number_of_peers_started == total_number)
546 {
547 for (int i = 1; i <= atoi (ns->global_n); i++)
548 { 653 {
549 for (int j = 1; j <= atoi (ns->local_m); j++) 654 start_helper (ns, config,
550 { 655 j,
551 tbc = GNUNET_new (struct TestingSystemCount); 656 i);
552 tbc->ns = ns;
553 // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone.
554 tbc->count = (i - 1) * atoi (ns->local_m) + j + total_number;
555
556 helper = ns->helper[tbc->count - 1 - total_number];
557 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
558 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
559 reply->header.type = htons (
560 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
561 reply->header.size = htons ((uint16_t) msg_length);
562
563 GNUNET_array_append (ns->msg, ns->n_msg, &reply->header);
564
565 struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
566 helper,
567 &reply->header,
568 GNUNET_NO,
569 &clear_msg,
570 tbc);
571
572 GNUNET_array_append (ns->shandle, ns->n_shandle, sh);
573 }
574 } 657 }
575 ns->number_of_peers_started = 0;
576 } 658 }
577 return ret;
578} 659}
579 660
580 661
@@ -582,26 +663,24 @@ netjail_start_finish (void *cls,
582 * Create command. 663 * Create command.
583 * 664 *
584 * @param label Name for the command. 665 * @param label Name for the command.
585 * @param local_m Number of nodes in a network namespace. //TODO make this a unsigned int 666 * @param topology_config Configuration file for the test topology.
586 * @param global_n Number of network namespaces. //TODO make this a unsigned int
587 * @param plugin_name Name of the test case plugin the helper will load.
588 * @param rv Pointer to the return value of the test.
589 * @return command. 667 * @return command.
590 */ 668 */
591struct GNUNET_TESTING_Command 669struct GNUNET_TESTING_Command
592GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label, 670GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label,
593 char *local_m, 671 const char *topology_config)
594 char *global_n,
595 char *plugin_name,
596 unsigned int *rv)
597{ 672{
598 struct NetJailState *ns; 673 struct NetJailState *ns;
599 674
675 struct GNUNET_TESTING_NetjailTopology *topology =
676 GNUNET_TESTING_get_topo_from_file (topology_config);
677
600 ns = GNUNET_new (struct NetJailState); 678 ns = GNUNET_new (struct NetJailState);
601 ns->local_m = local_m; 679 ns->local_m = topology->nodes_m;
602 ns->global_n = global_n; 680 ns->global_n = topology->namespaces_n;
603 ns->plugin_name = plugin_name; 681 ns->known = topology->nodes_x;
604 ns->rv = rv; 682 ns->plugin_name = topology->plugin;
683 ns->topology = topology;
605 684
606 struct GNUNET_TESTING_Command cmd = { 685 struct GNUNET_TESTING_Command cmd = {
607 .cls = ns, 686 .cls = ns,