diff options
author | xrs <xrs@mail36.net> | 2017-03-03 19:08:01 +0100 |
---|---|---|
committer | xrs <xrs@mail36.net> | 2017-03-03 19:08:01 +0100 |
commit | 4e5dcb2ae364c0def3c37eb5d960ab5a73f0679c (patch) | |
tree | 8f3bd73bc2ecf93f2fa472a71f5dc473b770a972 /src | |
parent | 9528dcc4b739041f51ed0c8791fe34902525fac2 (diff) | |
parent | 3f9a2615b3bd0a55e0c69dba494b4fbfce7b80e9 (diff) | |
download | gnunet-4e5dcb2ae364c0def3c37eb5d960ab5a73f0679c.tar.gz gnunet-4e5dcb2ae364c0def3c37eb5d960ab5a73f0679c.zip |
Merge branch 'master' of ssh://gnunet.org/gnunet
Diffstat (limited to 'src')
-rw-r--r-- | src/cadet/test_cadet_new.c | 127 |
1 files changed, 92 insertions, 35 deletions
diff --git a/src/cadet/test_cadet_new.c b/src/cadet/test_cadet_new.c index d32404815..374e86bf3 100644 --- a/src/cadet/test_cadet_new.c +++ b/src/cadet/test_cadet_new.c | |||
@@ -43,7 +43,7 @@ struct CadetTestChannelWrapper | |||
43 | }; | 43 | }; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * How many messages to send | 46 | * How many messages to send by default. |
47 | */ | 47 | */ |
48 | #define TOTAL_PACKETS 500 /* Cannot exceed 64k! */ | 48 | #define TOTAL_PACKETS 500 /* Cannot exceed 64k! */ |
49 | 49 | ||
@@ -53,7 +53,7 @@ struct CadetTestChannelWrapper | |||
53 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | 53 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * Time to wait for stuff that should be rather fast | 56 | * Time to wait by default for stuff that should be rather fast. |
57 | */ | 57 | */ |
58 | #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) | 58 | #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) |
59 | 59 | ||
@@ -84,6 +84,16 @@ static char *test_name; | |||
84 | static int test_backwards = GNUNET_NO; | 84 | static int test_backwards = GNUNET_NO; |
85 | 85 | ||
86 | /** | 86 | /** |
87 | * How many packets to send. | ||
88 | */ | ||
89 | static unsigned int total_packets; | ||
90 | |||
91 | /** | ||
92 | * Time to wait for fast operations. | ||
93 | */ | ||
94 | static struct GNUNET_TIME_Relative short_time; | ||
95 | |||
96 | /** | ||
87 | * How many events have happened | 97 | * How many events have happened |
88 | */ | 98 | */ |
89 | static int ok; | 99 | static int ok; |
@@ -262,10 +272,10 @@ show_end_data (void) | |||
262 | FPRINTF (stderr, "\nResults of test \"%s\"\n", test_name); | 272 | FPRINTF (stderr, "\nResults of test \"%s\"\n", test_name); |
263 | FPRINTF (stderr, "Test time %s\n", | 273 | FPRINTF (stderr, "Test time %s\n", |
264 | GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES)); | 274 | GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES)); |
265 | FPRINTF (stderr, "Test bandwidth: %f kb/s\n", 4 * TOTAL_PACKETS * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms | 275 | FPRINTF (stderr, "Test bandwidth: %f kb/s\n", 4 * total_packets * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms |
266 | FPRINTF (stderr, "Test throughput: %f packets/s\n\n", TOTAL_PACKETS * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms | 276 | FPRINTF (stderr, "Test throughput: %f packets/s\n\n", total_packets * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms |
267 | GAUGER ("CADET", test_name, | 277 | GAUGER ("CADET", test_name, |
268 | TOTAL_PACKETS * 1000.0 / (total_time.rel_value_us / 1000), | 278 | total_packets * 1000.0 / (total_time.rel_value_us / 1000), |
269 | "packets/s"); | 279 | "packets/s"); |
270 | } | 280 | } |
271 | 281 | ||
@@ -460,7 +470,7 @@ send_test_message (struct GNUNET_CADET_Channel *channel) | |||
460 | struct GNUNET_MQ_Envelope *env; | 470 | struct GNUNET_MQ_Envelope *env; |
461 | struct GNUNET_MessageHeader *msg; | 471 | struct GNUNET_MessageHeader *msg; |
462 | uint32_t *data; | 472 | uint32_t *data; |
463 | int *counter; | 473 | int payload; |
464 | int size; | 474 | int size; |
465 | 475 | ||
466 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 476 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -471,25 +481,47 @@ send_test_message (struct GNUNET_CADET_Channel *channel) | |||
471 | { | 481 | { |
472 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending INITIALIZER\n"); | 482 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending INITIALIZER\n"); |
473 | size += 1000; | 483 | size += 1000; |
474 | counter = &data_sent; | 484 | payload = data_sent; |
475 | if (SPEED_ACK == test) // FIXME unify SPEED_ACK with an initializer | 485 | if (SPEED_ACK == test) // FIXME unify SPEED_ACK with an initializer |
476 | data_sent++; | 486 | data_sent++; |
477 | } | 487 | } |
478 | else if (SPEED == test || SPEED_ACK == test) | 488 | else if (SPEED == test || SPEED_ACK == test) |
479 | { | 489 | { |
480 | counter = get_target_channel() == channel ? &ack_sent : &data_sent; | 490 | if (get_target_channel() == channel) |
481 | size += *counter; | 491 | { |
482 | *counter = *counter + 1; | 492 | payload = ack_sent; |
483 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Sending message %u\n", *counter); | 493 | size += ack_sent; |
494 | ack_sent++; | ||
495 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
496 | "Sending ACK %u [%d bytes]\n", | ||
497 | payload, size); | ||
498 | } | ||
499 | else | ||
500 | { | ||
501 | payload = data_sent; | ||
502 | size += data_sent; | ||
503 | data_sent++; | ||
504 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
505 | "Sending DATA %u [%d bytes]\n", | ||
506 | data_sent, size); | ||
507 | } | ||
508 | } | ||
509 | else if (FORWARD == test) | ||
510 | { | ||
511 | payload = ack_sent; | ||
512 | } | ||
513 | else if (P2P_SIGNAL == test) | ||
514 | { | ||
515 | payload = data_sent; | ||
484 | } | 516 | } |
485 | else | 517 | else |
486 | { | 518 | { |
487 | counter = &ack_sent; | 519 | GNUNET_assert (0); |
488 | } | 520 | } |
489 | env = GNUNET_MQ_msg_extra (msg, size, GNUNET_MESSAGE_TYPE_DUMMY); | 521 | env = GNUNET_MQ_msg_extra (msg, size, GNUNET_MESSAGE_TYPE_DUMMY); |
490 | 522 | ||
491 | data = (uint32_t *) &msg[1]; | 523 | data = (uint32_t *) &msg[1]; |
492 | *data = htonl (*counter); | 524 | *data = htonl (payload); |
493 | GNUNET_MQ_send (GNUNET_CADET_get_mq (channel), env); | 525 | GNUNET_MQ_send (GNUNET_CADET_get_mq (channel), env); |
494 | } | 526 | } |
495 | 527 | ||
@@ -511,13 +543,16 @@ send_next_msg (void *cls) | |||
511 | GNUNET_assert (NULL != channel); | 543 | GNUNET_assert (NULL != channel); |
512 | GNUNET_assert (SPEED == test); | 544 | GNUNET_assert (SPEED == test); |
513 | send_test_message (channel); | 545 | send_test_message (channel); |
514 | if (data_sent < TOTAL_PACKETS) | 546 | if (data_sent < total_packets) |
515 | { | 547 | { |
516 | /* SPEED test: Send all messages as soon as possible */ | 548 | /* SPEED test: Send all messages as soon as possible */ |
517 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 549 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
518 | "Scheduling message %d\n", | 550 | "Scheduling message %d\n", |
519 | data_sent + 1); | 551 | data_sent + 1); |
520 | send_next_msg_task = GNUNET_SCHEDULER_add_now (&send_next_msg, NULL); | 552 | send_next_msg_task = |
553 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, | ||
554 | &send_next_msg, | ||
555 | NULL); | ||
521 | } | 556 | } |
522 | } | 557 | } |
523 | 558 | ||
@@ -538,7 +573,7 @@ reschedule_timeout_task (long line) | |||
538 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 573 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
539 | " reschedule timeout every 10 messages\n"); | 574 | " reschedule timeout every 10 messages\n"); |
540 | GNUNET_SCHEDULER_cancel (disconnect_task); | 575 | GNUNET_SCHEDULER_cancel (disconnect_task); |
541 | disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, | 576 | disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, |
542 | &gather_stats_and_exit, | 577 | &gather_stats_and_exit, |
543 | (void *) line); | 578 | (void *) line); |
544 | } | 579 | } |
@@ -579,13 +614,14 @@ handle_data (void *cls, const struct GNUNET_MessageHeader *message) | |||
579 | int *counter; | 614 | int *counter; |
580 | 615 | ||
581 | ok++; | 616 | ok++; |
617 | GNUNET_CADET_receive_done (channel); | ||
582 | counter = get_target_channel () == channel ? &data_received : &ack_received; | 618 | counter = get_target_channel () == channel ? &data_received : &ack_received; |
583 | 619 | ||
584 | reschedule_timeout_task ((long) __LINE__); | 620 | reschedule_timeout_task ((long) __LINE__); |
585 | 621 | ||
586 | if (channel == outgoing_ch) | 622 | if (channel == outgoing_ch) |
587 | { | 623 | { |
588 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Root client got a message!\n"); | 624 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Root client got a message.\n"); |
589 | } | 625 | } |
590 | else if (channel == incoming_ch) | 626 | else if (channel == incoming_ch) |
591 | { | 627 | { |
@@ -635,7 +671,7 @@ handle_data (void *cls, const struct GNUNET_MessageHeader *message) | |||
635 | } | 671 | } |
636 | else | 672 | else |
637 | { | 673 | { |
638 | if (data_received < TOTAL_PACKETS) | 674 | if (data_received < total_packets) |
639 | return; | 675 | return; |
640 | } | 676 | } |
641 | } | 677 | } |
@@ -646,7 +682,7 @@ handle_data (void *cls, const struct GNUNET_MessageHeader *message) | |||
646 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received); | 682 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received ack %u\n", ack_received); |
647 | /* Send more data */ | 683 | /* Send more data */ |
648 | send_test_message (channel); | 684 | send_test_message (channel); |
649 | if (ack_received < TOTAL_PACKETS && SPEED != test) | 685 | if (ack_received < total_packets && SPEED != test) |
650 | return; | 686 | return; |
651 | if (ok == 2 && SPEED == test) | 687 | if (ok == 2 && SPEED == test) |
652 | return; | 688 | return; |
@@ -685,8 +721,9 @@ connect_handler (void *cls, struct GNUNET_CADET_Channel *channel, | |||
685 | struct CadetTestChannelWrapper *ch; | 721 | struct CadetTestChannelWrapper *ch; |
686 | long peer = (long) cls; | 722 | long peer = (long) cls; |
687 | 723 | ||
688 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Incoming channel from %s to peer %ld\n", | 724 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
689 | GNUNET_i2s (source), peer); | 725 | "Incoming channel from %s to %ld: %p\n", |
726 | GNUNET_i2s (source), peer, channel); | ||
690 | ok++; | 727 | ok++; |
691 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); | 728 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); |
692 | if (peer == peers_requested - 1) | 729 | if (peer == peers_requested - 1) |
@@ -708,9 +745,9 @@ connect_handler (void *cls, struct GNUNET_CADET_Channel *channel, | |||
708 | if (NULL != disconnect_task) | 745 | if (NULL != disconnect_task) |
709 | { | 746 | { |
710 | GNUNET_SCHEDULER_cancel (disconnect_task); | 747 | GNUNET_SCHEDULER_cancel (disconnect_task); |
711 | disconnect_task = | 748 | disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, |
712 | GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &gather_stats_and_exit, | 749 | &gather_stats_and_exit, |
713 | (void *) __LINE__); | 750 | (void *) __LINE__); |
714 | } | 751 | } |
715 | 752 | ||
716 | /* TODO: cannot return channel as-is, in order to unify the data handlers */ | 753 | /* TODO: cannot return channel as-is, in order to unify the data handlers */ |
@@ -811,9 +848,10 @@ start_test (void *cls) | |||
811 | NULL, | 848 | NULL, |
812 | &disconnect_handler, | 849 | &disconnect_handler, |
813 | handlers); | 850 | handlers); |
851 | |||
814 | ch->ch = outgoing_ch; | 852 | ch->ch = outgoing_ch; |
815 | 853 | ||
816 | disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, | 854 | disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, |
817 | &gather_stats_and_exit, | 855 | &gather_stats_and_exit, |
818 | (void *) __LINE__); | 856 | (void *) __LINE__); |
819 | if (KEEPALIVE == test) | 857 | if (KEEPALIVE == test) |
@@ -824,7 +862,9 @@ start_test (void *cls) | |||
824 | data_sent = 0; | 862 | data_sent = 0; |
825 | ack_received = 0; | 863 | ack_received = 0; |
826 | ack_sent = 0; | 864 | ack_sent = 0; |
827 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending data initializer...\n"); | 865 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
866 | "Sending data initializer on channel %p...\n", | ||
867 | outgoing_ch); | ||
828 | send_test_message (outgoing_ch); | 868 | send_test_message (outgoing_ch); |
829 | } | 869 | } |
830 | 870 | ||
@@ -886,7 +926,7 @@ tmain (void *cls, | |||
886 | testbed_peers = peers; | 926 | testbed_peers = peers; |
887 | h1 = cadets[0]; | 927 | h1 = cadets[0]; |
888 | h2 = cadets[num_peers - 1]; | 928 | h2 = cadets[num_peers - 1]; |
889 | disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, | 929 | disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, |
890 | &disconnect_cadet_peers, | 930 | &disconnect_cadet_peers, |
891 | (void *) __LINE__); | 931 | (void *) __LINE__); |
892 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 932 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
@@ -921,12 +961,29 @@ main (int argc, char *argv[]) | |||
921 | const char *config_file; | 961 | const char *config_file; |
922 | char port_id[] = "test port"; | 962 | char port_id[] = "test port"; |
923 | 963 | ||
924 | GNUNET_CRYPTO_hash (port_id, sizeof (port_id), &port); | 964 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
965 | {'t', "time", "short_time", | ||
966 | gettext_noop ("set short timeout"), | ||
967 | GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &short_time}, | ||
968 | {'m', "messages", "NUM_MESSAGES", | ||
969 | gettext_noop ("set number of messages to send"), | ||
970 | GNUNET_YES, &GNUNET_GETOPT_set_uint, &total_packets}, | ||
971 | |||
972 | GNUNET_GETOPT_OPTION_END | ||
973 | }; | ||
925 | 974 | ||
926 | GNUNET_log_setup ("test", "DEBUG", NULL); | 975 | GNUNET_log_setup ("test", "DEBUG", NULL); |
927 | config_file = "test_cadet.conf"; | ||
928 | 976 | ||
929 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start\n"); | 977 | total_packets = TOTAL_PACKETS; |
978 | short_time = SHORT_TIME; | ||
979 | if (-1 == GNUNET_GETOPT_run (argv[0], options, argc, argv)) | ||
980 | { | ||
981 | FPRINTF (stderr, "test failed: problem with CLI parameters\n"); | ||
982 | exit (1); | ||
983 | } | ||
984 | |||
985 | config_file = "test_cadet.conf"; | ||
986 | GNUNET_CRYPTO_hash (port_id, sizeof (port_id), &port); | ||
930 | 987 | ||
931 | /* Find out requested size */ | 988 | /* Find out requested size */ |
932 | if (strstr (argv[0], "_2_") != NULL) | 989 | if (strstr (argv[0], "_2_") != NULL) |
@@ -964,11 +1021,11 @@ main (int argc, char *argv[]) | |||
964 | { | 1021 | { |
965 | /* Test is supposed to generate the following callbacks: | 1022 | /* Test is supposed to generate the following callbacks: |
966 | * 1 incoming channel (@dest) | 1023 | * 1 incoming channel (@dest) |
967 | * TOTAL_PACKETS received data packet (@dest) | 1024 | * total_packets received data packet (@dest) |
968 | * TOTAL_PACKETS received data packet (@orig) | 1025 | * total_packets received data packet (@orig) |
969 | * 1 received channel destroy (@dest) | 1026 | * 1 received channel destroy (@dest) |
970 | */ | 1027 | */ |
971 | ok_goal = TOTAL_PACKETS * 2 + 2; | 1028 | ok_goal = total_packets * 2 + 2; |
972 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n"); | 1029 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n"); |
973 | test = SPEED_ACK; | 1030 | test = SPEED_ACK; |
974 | test_name = "speed ack"; | 1031 | test_name = "speed ack"; |
@@ -978,11 +1035,11 @@ main (int argc, char *argv[]) | |||
978 | /* Test is supposed to generate the following callbacks: | 1035 | /* Test is supposed to generate the following callbacks: |
979 | * 1 incoming channel (@dest) | 1036 | * 1 incoming channel (@dest) |
980 | * 1 initial packet (@dest) | 1037 | * 1 initial packet (@dest) |
981 | * TOTAL_PACKETS received data packet (@dest) | 1038 | * total_packets received data packet (@dest) |
982 | * 1 received data packet (@orig) | 1039 | * 1 received data packet (@orig) |
983 | * 1 received channel destroy (@dest) | 1040 | * 1 received channel destroy (@dest) |
984 | */ | 1041 | */ |
985 | ok_goal = TOTAL_PACKETS + 4; | 1042 | ok_goal = total_packets + 4; |
986 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n"); | 1043 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n"); |
987 | if (strstr (argv[0], "_reliable") != NULL) | 1044 | if (strstr (argv[0], "_reliable") != NULL) |
988 | { | 1045 | { |