aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_communicator_basic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_communicator_basic.c')
-rw-r--r--src/transport/test_communicator_basic.c504
1 files changed, 258 insertions, 246 deletions
diff --git a/src/transport/test_communicator_basic.c b/src/transport/test_communicator_basic.c
index ffc21e47a..98b49012a 100644
--- a/src/transport/test_communicator_basic.c
+++ b/src/transport/test_communicator_basic.c
@@ -326,46 +326,128 @@ get_peer_nr (void *cls, unsigned int get_the_other_one)
326} 326}
327 327
328static void 328static void
329latency_timeout (void *cls) 329process_statistics_box_done (void *cls, int success)
330{ 330{
331 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
332 unsigned int peer_nr;
333
334 peer_nr = get_peer_nr_from_tc (tc_h);
331 335
336 if (NULL != box_stats[peer_nr])
337 box_stats[peer_nr] = NULL;
338 if (NULL == rekey_stats[peer_nr])
339 {
340 LOG (GNUNET_ERROR_TYPE_DEBUG,
341 "Finished\n");
342 GNUNET_SCHEDULER_shutdown ();
343 }
344}
345
346
347static void
348process_statistics_rekey_done (void *cls, int success)
349{
332 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 350 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
333 unsigned int peer_nr; 351 unsigned int peer_nr;
334 size_t num_sent = 0;
335 size_t num_received = 0;
336 352
337 peer_nr = get_peer_nr_from_tc (tc_h); 353 peer_nr = get_peer_nr_from_tc (tc_h);
338 to_task[peer_nr] = NULL; 354
339 if (GNUNET_TIME_absolute_get_remaining (timeout[peer_nr]).rel_value_us > 0) 355 if (NULL != rekey_stats[peer_nr])
356 rekey_stats[peer_nr] = NULL;
357 if (NULL == box_stats[peer_nr])
340 { 358 {
341 to_task[peer_nr] = GNUNET_SCHEDULER_add_at (timeout[peer_nr], 359 LOG (GNUNET_ERROR_TYPE_DEBUG,
342 &latency_timeout, 360 "Finished\n");
343 cls); 361 GNUNET_SCHEDULER_shutdown ();
344 return;
345 } 362 }
346 switch (phase[peer_nr]) 363}
364
365static int
366process_statistics (void *cls,
367 const char *subsystem,
368 const char *name,
369 uint64_t value,
370 int is_persistent)
371{
372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
373 "Statistic: Name %s and value %lu\n",
374 name,
375 value);
376 if ((0 == strcmp ("rekey", test_name)) && (0 == strcmp (
377 "# rekeying successful",
378 name)) && (0 == value))
347 { 379 {
348 case TP_INIT: 380 ret = 2;
349 GNUNET_assert (0); 381 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
350 break; 382 "No successful rekeying!\n");
351 case TP_BURST_SHORT: 383 GNUNET_SCHEDULER_shutdown ();
352 num_sent = num_sent_short[peer_nr];
353 num_received = num_received_short[peer_nr];
354 break;
355 case TP_BURST_LONG:
356 num_sent = num_sent_long[peer_nr];
357 num_received = num_received_long[peer_nr];
358 break;
359 case TP_SIZE_CHECK:
360 num_sent = num_sent_size[peer_nr];
361 num_received = num_received_size[peer_nr];
362 break;
363 } 384 }
364 LOG (GNUNET_ERROR_TYPE_ERROR, 385 if ((0 == strcmp ("backchannel", test_name)) &&
365 "Latency too high. Test failed. (Phase: %d. Sent: %lu, Received: %lu)\n", 386 (0 == strcmp (
366 phase[peer_nr], num_sent, num_received); 387 "# messages decrypted with BOX",
367 ret = 2; 388 name))
368 GNUNET_SCHEDULER_shutdown (); 389 && (9000 > value))
390 {
391 ret = 2;
392 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
393 "Not enough BOX messages!\n");
394 GNUNET_SCHEDULER_shutdown ();
395 }
396 if ((0 == strcmp ("rekey", test_name)) &&
397 (0 == strcmp (
398 "# messages decrypted with BOX",
399 name))
400 && (6000 > value))
401 {
402 ret = 2;
403 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
404 "Not enough BOX messages!\n");
405 GNUNET_SCHEDULER_shutdown ();
406 }
407 return GNUNET_OK;
408}
409
410static void
411short_test (void *cls);
412
413static void
414short_test_cb (void *cls)
415{
416 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
417 unsigned int peer_nr;
418 char *payload;
419
420 peer_nr = get_peer_nr_from_tc (tc_h);
421
422 LOG (GNUNET_ERROR_TYPE_DEBUG,
423 "short_test_cb %u/%u for peer %u and handle %p\n",
424 (unsigned int) num_sent_short[peer_nr],
425 (unsigned int) num_received_short[peer_nr],
426 peer_nr,
427 tc_h);
428 payload = make_payload (SHORT_MESSAGE_SIZE);
429 num_sent_short[peer_nr]++;
430 GNUNET_TRANSPORT_TESTING_transport_communicator_send (tc_h,
431 (burst_packets_short ==
432 num_sent_short[peer_nr])
433 ? NULL
434 : &short_test,
435 cls,
436 payload,
437 SHORT_MESSAGE_SIZE);
438 GNUNET_free (payload);
439 timeout[peer_nr] = GNUNET_TIME_relative_to_absolute (
440 GNUNET_TIME_relative_multiply (
441 GNUNET_TIME_UNIT_SECONDS,
442 TIMEOUT_MULTIPLIER));
443}
444
445static void
446short_test (void *cls)
447{
448 GNUNET_SCHEDULER_add_delayed (delay_short,
449 &short_test_cb,
450 cls);
369} 451}
370 452
371static void 453static void
@@ -403,7 +485,6 @@ size_test (void *cls)
403 TIMEOUT_MULTIPLIER)); 485 TIMEOUT_MULTIPLIER));
404} 486}
405 487
406
407static void 488static void
408long_test (void *cls); 489long_test (void *cls);
409 490
@@ -446,161 +527,6 @@ long_test (void *cls)
446 cls); 527 cls);
447} 528}
448 529
449
450static void
451short_test (void *cls);
452
453
454static void
455short_test_cb (void *cls)
456{
457 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
458 unsigned int peer_nr;
459 char *payload;
460
461 peer_nr = get_peer_nr_from_tc (tc_h);
462
463 LOG (GNUNET_ERROR_TYPE_DEBUG,
464 "short_test_cb %u/%u for peer %u and handle %p\n",
465 (unsigned int) num_sent_short[peer_nr],
466 (unsigned int) num_received_short[peer_nr],
467 peer_nr,
468 tc_h);
469 payload = make_payload (SHORT_MESSAGE_SIZE);
470 num_sent_short[peer_nr]++;
471 GNUNET_TRANSPORT_TESTING_transport_communicator_send (tc_h,
472 (burst_packets_short ==
473 num_sent_short[peer_nr])
474 ? NULL
475 : &short_test,
476 cls,
477 payload,
478 SHORT_MESSAGE_SIZE);
479 GNUNET_free (payload);
480 timeout[peer_nr] = GNUNET_TIME_relative_to_absolute (
481 GNUNET_TIME_relative_multiply (
482 GNUNET_TIME_UNIT_SECONDS,
483 TIMEOUT_MULTIPLIER));
484}
485
486
487static void
488short_test (void *cls)
489{
490 GNUNET_SCHEDULER_add_delayed (delay_short,
491 &short_test_cb,
492 cls);
493}
494
495
496/* static int test_prepared = GNUNET_NO; */
497
498/* This helps establishing the backchannel */
499/* static void */
500/* prepare_test (void *cls) */
501/* { */
502/* char *payload; */
503
504/* if (GNUNET_YES == test_prepared) */
505/* { */
506/* GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, */
507/* &short_test, */
508/* NULL); */
509/* return; */
510/* } */
511/* test_prepared = GNUNET_YES; */
512/* payload = make_payload (SHORT_MESSAGE_SIZE); */
513/* GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, */
514/* &prepare_test, */
515/* NULL, */
516/* payload, */
517/* SHORT_MESSAGE_SIZE); */
518/* GNUNET_free (payload); */
519/* } */
520
521static void
522process_statistics_box_done (void *cls, int success)
523{
524 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
525 unsigned int peer_nr;
526
527 peer_nr = get_peer_nr_from_tc (tc_h);
528
529 if (NULL != box_stats[peer_nr])
530 box_stats[peer_nr] = NULL;
531 if (NULL == rekey_stats[peer_nr])
532 {
533 LOG (GNUNET_ERROR_TYPE_DEBUG,
534 "Finished\n");
535 GNUNET_SCHEDULER_shutdown ();
536 }
537}
538
539
540static void
541process_statistics_rekey_done (void *cls, int success)
542{
543 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
544 unsigned int peer_nr;
545
546 peer_nr = get_peer_nr_from_tc (tc_h);
547
548 if (NULL != rekey_stats[peer_nr])
549 rekey_stats[peer_nr] = NULL;
550 if (NULL == box_stats[peer_nr])
551 {
552 LOG (GNUNET_ERROR_TYPE_DEBUG,
553 "Finished\n");
554 GNUNET_SCHEDULER_shutdown ();
555 }
556}
557
558
559static int
560process_statistics (void *cls,
561 const char *subsystem,
562 const char *name,
563 uint64_t value,
564 int is_persistent)
565{
566 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
567 "Statistic: Name %s and value %lu\n",
568 name,
569 value);
570 if ((0 == strcmp ("rekey", test_name)) && (0 == strcmp (
571 "# rekeying successful",
572 name)) && (0 == value))
573 {
574 ret = 2;
575 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
576 "No successful rekeying!\n");
577 GNUNET_SCHEDULER_shutdown ();
578 }
579 if ((0 == strcmp ("backchannel", test_name)) &&
580 (0 == strcmp (
581 "# messages decrypted with BOX",
582 name))
583 && (9000 > value))
584 {
585 ret = 2;
586 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
587 "Not enough BOX messages!\n");
588 GNUNET_SCHEDULER_shutdown ();
589 }
590 if ((0 == strcmp ("rekey", test_name)) &&
591 (0 == strcmp (
592 "# messages decrypted with BOX",
593 name))
594 && (6000 > value))
595 {
596 ret = 2;
597 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
598 "Not enough BOX messages!\n");
599 GNUNET_SCHEDULER_shutdown ();
600 }
601 return GNUNET_OK;
602}
603
604static void 530static void
605choose_phase (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) 531choose_phase (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
606{ 532{
@@ -661,8 +587,11 @@ choose_phase (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
661 } 587 }
662 else 588 else
663 { 589 {
664 if (((PEER_A == peer_nr) && finished[PEER_B]) || ((PEER_B == peer_nr) && 590 if ((GNUNET_NO == bidirect)|| (((PEER_A == peer_nr) &&
665 finished[PEER_A])) 591 finished[PEER_B]) || ((PEER_B ==
592 peer_nr) &&
593 finished
594 [PEER_A])))
666 { 595 {
667 LOG (GNUNET_ERROR_TYPE_DEBUG, 596 LOG (GNUNET_ERROR_TYPE_DEBUG,
668 "Finished\n"); 597 "Finished\n");
@@ -673,6 +602,137 @@ choose_phase (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
673 } 602 }
674} 603}
675 604
605static void finish_phase_long (unsigned int peer_nr)
606{
607 static struct GNUNET_TIME_Relative duration;
608
609 duration = GNUNET_TIME_absolute_get_duration (start_long[peer_nr]);
610 LOG (GNUNET_ERROR_TYPE_MESSAGE,
611 "Long size packet test for peer %u done.\n",
612 peer_nr);
613 char *goodput = GNUNET_STRINGS_byte_size_fancy (
614 (long_message_size * num_received_long[peer_nr] * 1000 * 1000)
615 / duration.
616 rel_value_us);
617
618 LOG (GNUNET_ERROR_TYPE_MESSAGE,
619 "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n",
620 (unsigned long) num_received_long[peer_nr],
621 (unsigned long) num_sent_long[peer_nr],
622 (unsigned long long) duration.rel_value_us,
623 goodput,
624 (unsigned long long) avg_latency[peer_nr]);
625 GNUNET_free (goodput);
626 ack[peer_nr] = 0;
627 // phase = TP_SIZE_CHECK;
628 // num_received = 0;
629 // num_sent_long = 0;
630 avg_latency[peer_nr] = 0;
631 // size_test (NULL);
632 phase_long[peer_nr] = GNUNET_NO;
633 choose_phase (get_tc_h (peer_nr));
634}
635
636static void
637finish_phase_short (unsigned int peer_nr)
638{
639 static struct GNUNET_TIME_Relative duration;
640
641 duration = GNUNET_TIME_absolute_get_duration (start_short[peer_nr]);
642 LOG (GNUNET_ERROR_TYPE_MESSAGE,
643 "Short size packet test for peer %u done.\n",
644 peer_nr);
645 char *goodput = GNUNET_STRINGS_byte_size_fancy (
646 (SHORT_MESSAGE_SIZE * num_received_short[peer_nr] * 1000 * 1000)
647 / duration.rel_value_us);
648 LOG (GNUNET_ERROR_TYPE_MESSAGE,
649 "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n",
650 (unsigned long) num_received_short[peer_nr],
651 (unsigned long) num_sent_short[peer_nr],
652 (unsigned long long) duration.rel_value_us,
653 goodput,
654 (unsigned long long) avg_latency[peer_nr]);
655 GNUNET_free (goodput);
656 // start_long = GNUNET_TIME_absolute_get ();
657 // phase = TP_BURST_LONG;
658 // num_sent_short = 0;
659 avg_latency[peer_nr] = 0;
660 // num_received = 0;
661 phase_short[peer_nr] = GNUNET_NO;
662 choose_phase (get_tc_h (peer_nr));
663 // long_test (NULL);
664}
665
666static void
667latency_timeout (void *cls)
668{
669
670 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
671 unsigned int peer_nr;
672 size_t num_sent = 0;
673 size_t num_received = 0;
674
675 peer_nr = get_peer_nr_from_tc (tc_h);
676 to_task[peer_nr] = NULL;
677
678 switch (phase[peer_nr])
679 {
680 case TP_INIT:
681 GNUNET_assert (0);
682 break;
683 case TP_BURST_SHORT:
684 num_sent = num_sent_short[peer_nr];
685 num_received = num_received_short[peer_nr];
686 if ((num_sent_short[peer_nr] == burst_packets_short) &&
687 (num_received_short[peer_nr] >
688 burst_packets_short
689 / 100
690 *
691 allowed_packet_loss_short) )
692 {
693 finish_phase_short (peer_nr);
694 to_task[peer_nr] = GNUNET_SCHEDULER_add_at (timeout[peer_nr],
695 &latency_timeout,
696 cls);
697 return;
698 }
699 break;
700 case TP_BURST_LONG:
701 num_sent = num_sent_long[peer_nr];
702 num_received = num_received_long[peer_nr];
703 if ((num_sent_long[peer_nr] == burst_packets_long) &&
704 (num_received_long[peer_nr] >
705 burst_packets_long
706 / 100
707 *
708 allowed_packet_loss_long) )
709 {
710 finish_phase_long (peer_nr);
711 to_task[peer_nr] = GNUNET_SCHEDULER_add_at (timeout[peer_nr],
712 &latency_timeout,
713 cls);
714 return;
715 }
716 break;
717 case TP_SIZE_CHECK:
718 num_sent = num_sent_size[peer_nr];
719 num_received = num_received_size[peer_nr];
720 break;
721 }
722 if (GNUNET_TIME_absolute_get_remaining (timeout[peer_nr]).rel_value_us > 0)
723 {
724 to_task[peer_nr] = GNUNET_SCHEDULER_add_at (timeout[peer_nr],
725 &latency_timeout,
726 cls);
727 return;
728 }
729 LOG (GNUNET_ERROR_TYPE_ERROR,
730 "Latency too high. Test failed. (Phase: %d. Sent: %lu, Received: %lu)\n",
731 phase[peer_nr], num_sent, num_received);
732 ret = 2;
733 GNUNET_SCHEDULER_shutdown ();
734}
735
676/** 736/**
677 * @brief Handle opening of queue 737 * @brief Handle opening of queue
678 * 738 *
@@ -812,6 +872,8 @@ load_phase_config ()
812 phase_size[1] = phase_size[0]; 872 phase_size[1] = phase_size[0];
813} 873}
814 874
875
876
815/** 877/**
816 * @brief Handle an incoming message 878 * @brief Handle an incoming message
817 * 879 *
@@ -829,7 +891,7 @@ incoming_message_cb (
829 size_t payload_len) 891 size_t payload_len)
830{ 892{
831 unsigned int peer_nr; 893 unsigned int peer_nr;
832 static struct GNUNET_TIME_Relative duration; 894
833 895
834 peer_nr = get_peer_nr (cls, GNUNET_YES); 896 peer_nr = get_peer_nr (cls, GNUNET_YES);
835 897
@@ -854,37 +916,13 @@ incoming_message_cb (
854 { 916 {
855 GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len); 917 GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len);
856 num_received_short[peer_nr]++; 918 num_received_short[peer_nr]++;
857 duration = GNUNET_TIME_absolute_get_duration (start_short[peer_nr]); 919
858 update_avg_latency (payload, peer_nr); 920 update_avg_latency (payload, peer_nr);
859 if ((num_sent_short[peer_nr] == burst_packets_short) && 921 if ((num_sent_short[peer_nr] == burst_packets_short) &&
860 (num_received_short[peer_nr] > 922 (num_received_short[peer_nr] ==
861 burst_packets_short 923 burst_packets_short))
862 / 100
863 *
864 allowed_packet_loss_short) )
865 { 924 {
866 LOG (GNUNET_ERROR_TYPE_MESSAGE, 925 finish_phase_short (peer_nr);
867 "Short size packet test for peer %u done.\n",
868 peer_nr);
869 char *goodput = GNUNET_STRINGS_byte_size_fancy (
870 (SHORT_MESSAGE_SIZE * num_received_short[peer_nr] * 1000 * 1000)
871 / duration.rel_value_us);
872 LOG (GNUNET_ERROR_TYPE_MESSAGE,
873 "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n",
874 (unsigned long) num_received_short[peer_nr],
875 (unsigned long) num_sent_short[peer_nr],
876 (unsigned long long) duration.rel_value_us,
877 goodput,
878 (unsigned long long) avg_latency[peer_nr]);
879 GNUNET_free (goodput);
880 // start_long = GNUNET_TIME_absolute_get ();
881 // phase = TP_BURST_LONG;
882 // num_sent_short = 0;
883 avg_latency[peer_nr] = 0;
884 // num_received = 0;
885 phase_short[peer_nr] = GNUNET_NO;
886 choose_phase (get_tc_h (peer_nr));
887 // long_test (NULL);
888 } 926 }
889 break; 927 break;
890 } 928 }
@@ -897,39 +935,13 @@ incoming_message_cb (
897 return; // Ignore 935 return; // Ignore
898 } 936 }
899 num_received_long[peer_nr]++; 937 num_received_long[peer_nr]++;
900 duration = GNUNET_TIME_absolute_get_duration (start_long[peer_nr]); 938
901 update_avg_latency (payload, peer_nr); 939 update_avg_latency (payload, peer_nr);
902 if ((num_sent_long[peer_nr] == burst_packets_long) && 940 if ((num_sent_long[peer_nr] == burst_packets_long) &&
903 (num_received_long[peer_nr] > 941 (num_received_long[peer_nr] >
904 burst_packets_long 942 burst_packets_long))
905 / 100
906 *
907 allowed_packet_loss_short) )
908 { 943 {
909 LOG (GNUNET_ERROR_TYPE_MESSAGE, 944 finish_phase_long (peer_nr);
910 "Long size packet test for peer %u done.\n",
911 peer_nr);
912 char *goodput = GNUNET_STRINGS_byte_size_fancy (
913 (long_message_size * num_received_long[peer_nr] * 1000 * 1000)
914 / duration.
915 rel_value_us);
916
917 LOG (GNUNET_ERROR_TYPE_MESSAGE,
918 "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n",
919 (unsigned long) num_received_long[peer_nr],
920 (unsigned long) num_sent_long[peer_nr],
921 (unsigned long long) duration.rel_value_us,
922 goodput,
923 (unsigned long long) avg_latency[peer_nr]);
924 GNUNET_free (goodput);
925 ack[peer_nr] = 0;
926 // phase = TP_SIZE_CHECK;
927 // num_received = 0;
928 // num_sent_long = 0;
929 avg_latency[peer_nr] = 0;
930 // size_test (NULL);
931 phase_long[peer_nr] = GNUNET_NO;
932 choose_phase (get_tc_h (peer_nr));
933 } 945 }
934 break; 946 break;
935 } 947 }