From 5affc9ad078e8d90c47a2972d67cd9d65529792d Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Tue, 5 Jan 2021 13:19:57 +0100 Subject: - started making tng communicator test code more resilient --- src/transport/gnunet-communicator-tcp.c | 111 +++++++++++++++------ src/transport/test_communicator_basic.c | 46 +++++---- .../test_communicator_tcp_basic_peer1.conf | 2 +- .../test_communicator_tcp_basic_peer2.conf | 2 +- .../test_communicator_tcp_rekey_peer2.conf | 2 +- src/transport/transport-testing-communicator.c | 1 + 6 files changed, 116 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c index 59f42496a..0c79fc1b4 100644 --- a/src/transport/gnunet-communicator-tcp.c +++ b/src/transport/gnunet-communicator-tcp.c @@ -540,6 +540,11 @@ struct Queue */ enum GNUNET_NetworkType nt; + /** + * The connection status of this queue. + */ + enum GNUNET_TRANSPORT_ConnectionStatus cs; + /** * Is MQ awaiting a #GNUNET_MQ_impl_send_continue() call? */ @@ -828,7 +833,8 @@ int addrs_lens; /** * Size of data received without KX challenge played back. */ -size_t unverified_size; +// TODO remove? +// size_t unverified_size; /** * Database for peer's HELLOs. @@ -1434,6 +1440,9 @@ try_handle_plaintext (struct Queue *queue) struct TcpHandshakeAckSignature thas; const struct ChallengeNonceP challenge = queue->challenge; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "try handle plaintext!\n"); + if ((sizeof(*hdr) > queue->pread_off)) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -1441,16 +1450,16 @@ try_handle_plaintext (struct Queue *queue) return 0; /* not even a header */ } - if ((-1 != unverified_size) && (unverified_size > INITIAL_CORE_KX_SIZE)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Already received data of size %lu bigger than KX size %lu!\n", - unverified_size, - INITIAL_CORE_KX_SIZE); - GNUNET_break_op (0); - queue_finish (queue); - return 0; - } + /* if ((-1 != unverified_size) && (unverified_size > INITIAL_CORE_KX_SIZE)) */ + /* { */ + /* GNUNET_log (GNUNET_ERROR_TYPE_ERROR, */ + /* "Already received data of size %lu bigger than KX size %lu!\n", */ + /* unverified_size, */ + /* INITIAL_CORE_KX_SIZE); */ + /* GNUNET_break_op (0); */ + /* queue_finish (queue); */ + /* return 0; */ + /* } */ type = ntohs (hdr->type); switch (type) @@ -1513,7 +1522,41 @@ try_handle_plaintext (struct Queue *queue) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Handling plaintext, ack processed!"); - unverified_size = -1; + // unverified_size = -1; + + /* char *foreign_addr; */ + + /* switch (queue->address->sa_family) */ + /* { */ + /* case AF_INET: */ + /* GNUNET_asprintf (&foreign_addr, */ + /* "%s-%s", */ + /* COMMUNICATOR_ADDRESS_PREFIX, */ + /* GNUNET_a2s (queue->address, queue->address_len)); */ + /* break; */ + + /* case AF_INET6: */ + /* GNUNET_asprintf (&foreign_addr, */ + /* "%s-%s", */ + /* COMMUNICATOR_ADDRESS_PREFIX, */ + /* GNUNET_a2s (queue->address, queue->address_len)); */ + /* break; */ + + /* default: */ + /* GNUNET_assert (0); */ + /* } */ + + /* queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, */ + /* &queue->target, */ + /* foreign_addr, */ + /* 0 /\* no MTU *\/, */ + /* GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, */ + /* 0, /\* Priority *\/ */ + /* queue->nt, */ + /* queue->cs, */ + /* queue->mq); */ + + /* GNUNET_free (foreign_addr); */ size = ntohs (hdr->size); break; @@ -1590,8 +1633,8 @@ try_handle_plaintext (struct Queue *queue) return 0; } GNUNET_assert (0 != size); - if (-1 != unverified_size) - unverified_size += size; + /* if (-1 != unverified_size) */ + /* unverified_size += size; */ return size; } @@ -2139,11 +2182,12 @@ queue_write (void *cls) queue->cwrite_off += queue->pwrite_off; queue->pwrite_off = 0; } - if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) && - ((0 == queue->rekey_left_bytes) || - (0 == - GNUNET_TIME_absolute_get_remaining ( - queue->rekey_time).rel_value_us)))) + // if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) && + if (((0 == queue->pwrite_off) && + ((0 == queue->rekey_left_bytes) || + (0 == + GNUNET_TIME_absolute_get_remaining ( + queue->rekey_time).rel_value_us)))) { inject_rekey (queue); } @@ -2282,7 +2326,7 @@ mq_error (void *cls, enum GNUNET_MQ_Error error) * @param queue queue to boot */ static void -boot_queue (struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs) +boot_queue (struct Queue *queue) { queue->nt = GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len); @@ -2333,7 +2377,7 @@ boot_queue (struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs) GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, 0, /* Priority */ queue->nt, - cs, + queue->cs, queue->mq); GNUNET_free (foreign_addr); } @@ -2557,7 +2601,7 @@ free_proto_queue (struct ProtoQueue *pq) * @param queue The queue context. */ static void -send_challenge (struct TCPConfirmation tc, struct Queue *queue) +send_challenge (struct ChallengeNonceP challenge, struct Queue *queue) { struct TCPConfirmationAck tca; struct TcpHandshakeAckSignature thas; @@ -2569,7 +2613,7 @@ send_challenge (struct TCPConfirmation tc, struct Queue *queue) tca.header.type = ntohs ( GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK); tca.header.size = ntohs (sizeof(tca)); - tca.challenge = tc.challenge; + tca.challenge = challenge; tca.sender = my_identity; tca.monotonic_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); @@ -2665,7 +2709,8 @@ proto_read_kx (void *cls) "start kx proto\n"); start_initial_kx_out (queue); - boot_queue (queue, GNUNET_TRANSPORT_CS_INBOUND); + queue->cs = GNUNET_TRANSPORT_CS_INBOUND; + boot_queue (queue); queue->read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, queue->sock, @@ -2676,7 +2721,8 @@ proto_read_kx (void *cls) queue->sock, &queue_write, queue); - send_challenge (tc, queue); + // TODO To early! Move it somewhere else. + // send_challenge (tc, queue); GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq); GNUNET_free (pq); @@ -2762,7 +2808,9 @@ queue_read_kx (void *cls) rcvd = GNUNET_NETWORK_socket_recv (queue->sock, &queue->cread_buf[queue->cread_off], BUF_SIZE - queue->cread_off); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %lu bytes for KX\n", rcvd); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received %lu bytes for KX\n", + rcvd); if (-1 == rcvd) { if ((EAGAIN != errno) && (EINTR != errno)) @@ -2804,14 +2852,20 @@ queue_read_kx (void *cls) queue_destroy (queue); return; } - send_challenge (tc, queue); + send_challenge (tc.challenge, queue); /* update queue timeout */ reschedule_queue_timeout (queue); /* prepare to continue with regular read task immediately */ memmove (queue->cread_buf, &queue->cread_buf[INITIAL_KX_SIZE], queue->cread_off - (INITIAL_KX_SIZE)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "cread_off is %lu bytes before adjusting\n", + queue->cread_off); queue->cread_off -= INITIAL_KX_SIZE; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "cread_off set to %lu bytes\n", + queue->cread_off); if (0 < queue->cread_off) queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue); } @@ -2893,7 +2947,8 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) queue->address = in; queue->address_len = in_len; queue->sock = sock; - boot_queue (queue, GNUNET_TRANSPORT_CS_OUTBOUND); + queue->cs = GNUNET_TRANSPORT_CS_OUTBOUND; + boot_queue (queue); // queue->mq_awaits_continue = GNUNET_YES; queue->read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, diff --git a/src/transport/test_communicator_basic.c b/src/transport/test_communicator_basic.c index 10c942daa..0eeaecb6c 100644 --- a/src/transport/test_communicator_basic.c +++ b/src/transport/test_communicator_basic.c @@ -61,6 +61,8 @@ static char *cfg_peers_name[NUM_PEERS]; static int ret; +static int bidirect = GNUNET_NO; + static size_t long_message_size; static struct GNUNET_TIME_Absolute start_short; @@ -71,6 +73,8 @@ static struct GNUNET_TIME_Absolute timeout; static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *my_tc; +static char *communicator_name; + static char *test_name; static struct GNUNET_STATISTICS_GetHandle *box_stats; @@ -343,11 +347,8 @@ long_test_cb (void *cls) payload = make_payload (long_message_size); num_sent_long++; GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, - ((BURST_PACKETS - * 0.91 == - num_received_long) || - (BURST_PACKETS == - num_sent_long)) + (BURST_PACKETS == + num_sent_long) ? NULL : &long_test, NULL, @@ -385,11 +386,8 @@ short_test_cb (void *cls) payload = make_payload (SHORT_MESSAGE_SIZE); num_sent_short++; GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, - ((BURST_PACKETS - * 0.91 == - num_received_short) || - (BURST_PACKETS == - num_sent_short)) + (BURST_PACKETS == + num_sent_short) ? NULL : &short_test, NULL, @@ -625,7 +623,8 @@ incoming_message_cb (void *cls, num_received_short++; duration = GNUNET_TIME_absolute_get_duration (start_short); update_avg_latency (payload); - if (num_received_short == BURST_PACKETS * 0.91) + if ((num_sent_short == BURST_PACKETS) && (num_received_short > + BURST_PACKETS * 0.91) ) { LOG (GNUNET_ERROR_TYPE_MESSAGE, "Short size packet test done.\n"); @@ -647,6 +646,9 @@ incoming_message_cb (void *cls, // num_sent_short = 0; avg_latency = 0; // num_received = 0; + /*LOG (GNUNET_ERROR_TYPE_DEBUG, + "Finished\n"); + GNUNET_SCHEDULER_shutdown ();*/ long_test (NULL); } break; @@ -662,7 +664,8 @@ incoming_message_cb (void *cls, num_received_long++; duration = GNUNET_TIME_absolute_get_duration (start_long); update_avg_latency (payload); - if (num_received_long == BURST_PACKETS * 0.91) + if ((num_sent_long == BURST_PACKETS) && (num_received_long > BURST_PACKETS + * 0.91) ) { LOG (GNUNET_ERROR_TYPE_MESSAGE, "Long size packet test done.\n"); @@ -723,8 +726,11 @@ incoming_message_cb (void *cls, short_test (NULL); break; } - if ((0 == strcmp ("rekey", test_name))||(0 == strcmp ("backchannel", - test_name)) ) + if ((0 == strcmp ("udp", communicator_name)) && ((0 == strcmp ("rekey", + test_name)) + ||(0 == strcmp ( + "backchannel", + test_name))) ) { if (NULL != box_stats) GNUNET_STATISTICS_get_cancel (box_stats); @@ -810,12 +816,19 @@ run (void *cls) &handle_backchannel_cb, cfg_peers_name[i]); /* cls */ - if ((0 == strcmp ("rekey", test_name))||(0 == strcmp ("backchannel", - test_name)) ) + if ((0 == strcmp ("udp", communicator_name)) && ((0 == strcmp ("rekey", + test_name))|| + (0 == strcmp ( + "backchannel", + test_name))) ) { stats[i] = GNUNET_STATISTICS_create ("C-UDP", cfg_peers[i]); } + else if ((0 == strcmp ("bidirect", test_name))) + { + bidirect = GNUNET_YES; + } } GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); @@ -827,7 +840,6 @@ main (int argc, char *const *argv) { struct GNUNET_CRYPTO_EddsaPrivateKey *private_key; - char *communicator_name; char *test_mode; char *cfg_peer; diff --git a/src/transport/test_communicator_tcp_basic_peer1.conf b/src/transport/test_communicator_tcp_basic_peer1.conf index 2411f485b..b32aa1c17 100644 --- a/src/transport/test_communicator_tcp_basic_peer1.conf +++ b/src/transport/test_communicator_tcp_basic_peer1.conf @@ -33,7 +33,7 @@ UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_1.sock #PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args #PREFIX = valgrind --leak-check=full --track-origins=yes BINDTO = 60002 -DISABLE_V6 = NO +DISABLE_V6 = YES [communicator-udp] BINDTO = 60002 diff --git a/src/transport/test_communicator_tcp_basic_peer2.conf b/src/transport/test_communicator_tcp_basic_peer2.conf index 8005718bf..b73157f0d 100644 --- a/src/transport/test_communicator_tcp_basic_peer2.conf +++ b/src/transport/test_communicator_tcp_basic_peer2.conf @@ -34,7 +34,7 @@ UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_2.sock #PREFIX = xterm -geometry 100x85 -T peer2 -e gdb --args #PREFIX = valgrind --leak-check=full --track-origins=yes BINDTO = 60003 -DISABLE_V6 = NO +DISABLE_V6 = YES [communicator-udp] BINDTO = 60003 diff --git a/src/transport/test_communicator_tcp_rekey_peer2.conf b/src/transport/test_communicator_tcp_rekey_peer2.conf index 1036039c4..086a996ae 100644 --- a/src/transport/test_communicator_tcp_rekey_peer2.conf +++ b/src/transport/test_communicator_tcp_rekey_peer2.conf @@ -38,7 +38,7 @@ UNIXPATH = $GNUNET_RUNTIME_DIR/test_gnunet-communicator-unix_2.sock #PREFIX = xterm -geometry 100x85 -T peer2 -e gdb --args #PREFIX = valgrind --leak-check=full --track-origins=yes BINDTO = 60003 -DISABLE_V6 = NO +DISABLE_V6 = YES REKEY_INTERVAL = 100ms [communicator-udp] diff --git a/src/transport/transport-testing-communicator.c b/src/transport/transport-testing-communicator.c index 56240864c..de356fb9c 100644 --- a/src/transport/transport-testing-communicator.c +++ b/src/transport/transport-testing-communicator.c @@ -317,6 +317,7 @@ handle_add_address (void *cls, client->tc; uint16_t size; size = ntohs (msg->header.size) - sizeof(*msg); + LOG (GNUNET_ERROR_TYPE_DEBUG, "received add address cb %u\n", size); if (0 == size) return; /* receive-only communicator */ LOG (GNUNET_ERROR_TYPE_DEBUG, "received add address cb %u\n", size); -- cgit v1.2.3 From 6bf35601f3eb93a7fcd3401b42be8d53f79c47d8 Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Tue, 5 Jan 2021 17:39:22 +0100 Subject: - added configuration to the tng communicator test code --- src/transport/test_communicator_basic.c | 415 +++++++++++++-------- .../test_communicator_tcp_basic_peer1.conf | 5 + 2 files changed, 274 insertions(+), 146 deletions(-) (limited to 'src') diff --git a/src/transport/test_communicator_basic.c b/src/transport/test_communicator_basic.c index 1f85a9895..0250de474 100644 --- a/src/transport/test_communicator_basic.c +++ b/src/transport/test_communicator_basic.c @@ -81,10 +81,14 @@ static struct GNUNET_STATISTICS_GetHandle *box_stats; static struct GNUNET_STATISTICS_GetHandle *rekey_stats; +#define TEST_SECTION "test-setup" + #define SHORT_MESSAGE_SIZE 128 #define LONG_MESSAGE_SIZE 32000 /* FIXME */ +#define ALLOWED_PACKET_LOSS 91 + #define BURST_PACKETS 5000 #define TOTAL_ITERATIONS 1 @@ -114,6 +118,27 @@ enum TestPhase TP_SIZE_CHECK }; +static unsigned int phase_short; + +static unsigned int phase_long; + +static unsigned int phase_size; + +static long long unsigned int allowed_packet_loss_short; + +static long long unsigned int allowed_packet_loss_long; + +static long long unsigned int burst_packets_short; + +static long long unsigned int burst_packets_long; + +static long long unsigned int delay_long_value; + +static long long unsigned int delay_short_value; + +static struct GNUNET_TIME_Relative delay_short; + +static struct GNUNET_TIME_Relative delay_long; static size_t num_sent_short = 0; @@ -300,10 +325,6 @@ latency_timeout (void *cls) GNUNET_SCHEDULER_shutdown (); } - -/*static void - size_test (void *cls);*/ - static void size_test (void *cls) { @@ -350,7 +371,7 @@ long_test_cb (void *cls) payload = make_payload (long_message_size); num_sent_long++; GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, - (BURST_PACKETS == + (burst_packets_long == num_sent_long) ? NULL : &long_test, @@ -368,10 +389,7 @@ long_test_cb (void *cls) static void long_test (void *cls) { - /*LOG (GNUNET_ERROR_TYPE_DEBUG, - "long_test %u\n", - num_sent_long);*/ - GNUNET_SCHEDULER_add_delayed (DELAY, + GNUNET_SCHEDULER_add_delayed (delay_long, &long_test_cb, NULL); } @@ -393,7 +411,7 @@ short_test_cb (void *cls) payload = make_payload (SHORT_MESSAGE_SIZE); num_sent_short++; GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, - (BURST_PACKETS == + (burst_packets_short == num_sent_short) ? NULL : &short_test, @@ -410,40 +428,164 @@ short_test_cb (void *cls) static void short_test (void *cls) { - GNUNET_SCHEDULER_add_delayed (DELAY, + GNUNET_SCHEDULER_add_delayed (delay_short, &short_test_cb, NULL); } -static int test_prepared = GNUNET_NO; +/* static int test_prepared = GNUNET_NO; */ + +/* This helps establishing the backchannel */ +/* static void */ +/* prepare_test (void *cls) */ +/* { */ +/* char *payload; */ + +/* if (GNUNET_YES == test_prepared) */ +/* { */ +/* GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, */ +/* &short_test, */ +/* NULL); */ +/* return; */ +/* } */ +/* test_prepared = GNUNET_YES; */ +/* payload = make_payload (SHORT_MESSAGE_SIZE); */ +/* GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, */ +/* &prepare_test, */ +/* NULL, */ +/* payload, */ +/* SHORT_MESSAGE_SIZE); */ +/* GNUNET_free (payload); */ +/* } */ -/** - * This helps establishing the backchannel - */ static void -prepare_test (void *cls) +process_statistics_box_done (void *cls, int success) { - char *payload; + if (NULL != box_stats) + box_stats = NULL; + if (NULL == rekey_stats) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Finished\n"); + GNUNET_SCHEDULER_shutdown (); + } +} - if (GNUNET_YES == test_prepared) + +static void +process_statistics_rekey_done (void *cls, int success) +{ + if (NULL != rekey_stats) + rekey_stats = NULL; + if (NULL == box_stats) { - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, - &short_test, - NULL); - return; + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Finished\n"); + GNUNET_SCHEDULER_shutdown (); } - test_prepared = GNUNET_YES; - payload = make_payload (SHORT_MESSAGE_SIZE); - GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, - &prepare_test, - NULL, - payload, - SHORT_MESSAGE_SIZE); - GNUNET_free (payload); } +static int +process_statistics (void *cls, + const char *subsystem, + const char *name, + uint64_t value, + int is_persistent) +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Statistic: Name %s and value %lu\n", + name, + value); + if ((0 == strcmp ("rekey", test_name)) && (0 == strcmp ( + "# rekeying successful", + name)) && (0 == value)) + { + ret = 2; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "No successful rekeying!\n"); + GNUNET_SCHEDULER_shutdown (); + } + if ((0 == strcmp ("backchannel", test_name)) && + (0 == strcmp ( + "# messages decrypted with BOX", + name)) + && (9000 > value)) + { + ret = 2; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Not enough BOX messages!\n"); + GNUNET_SCHEDULER_shutdown (); + } + if ((0 == strcmp ("rekey", test_name)) && + (0 == strcmp ( + "# messages decrypted with BOX", + name)) + && (6000 > value)) + { + ret = 2; + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Not enough BOX messages!\n"); + GNUNET_SCHEDULER_shutdown (); + } + return GNUNET_OK; +} + +static void +choose_phase () +{ + if (GNUNET_YES == phase_short) + { + phase = TP_BURST_SHORT; + start_short = GNUNET_TIME_absolute_get (); + short_test (NULL); + } + else if (GNUNET_YES == phase_long) + { + phase = TP_BURST_LONG; + start_long = GNUNET_TIME_absolute_get (); + long_test (NULL); + } + else if (GNUNET_YES == phase_size) + { + phase = TP_SIZE_CHECK; + size_test (NULL); + } + else + { + if ((0 == strcmp ("udp", communicator_name)) && ((0 == strcmp ("rekey", + test_name)) + ||(0 == strcmp ( + "backchannel", + test_name))) ) + { + if (NULL != box_stats) + GNUNET_STATISTICS_get_cancel (box_stats); + box_stats = GNUNET_STATISTICS_get (stats[1], + "C-UDP", + "# messages decrypted with BOX", + process_statistics_box_done, + &process_statistics, + NULL); + if (NULL != rekey_stats) + GNUNET_STATISTICS_get_cancel (rekey_stats); + rekey_stats = GNUNET_STATISTICS_get (stats[0], + "C-UDP", + "# rekeying successful", + process_statistics_rekey_done, + &process_statistics, + NULL); + } + else + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Finished\n"); + GNUNET_SCHEDULER_shutdown (); + } + } +} + /** * @brief Handle opening of queue * @@ -468,14 +610,14 @@ add_queue_cb (void *cls, return; // TODO? LOG (GNUNET_ERROR_TYPE_DEBUG, "Queue established, starting test...\n"); - start_short = GNUNET_TIME_absolute_get (); + // start_short = GNUNET_TIME_absolute_get (); my_tc = tc_h; if (0 != mtu) /* Message header overhead */ long_message_size = mtu - sizeof(struct GNUNET_TRANSPORT_SendMessageTo) - sizeof(struct GNUNET_MessageHeader); else long_message_size = LONG_MESSAGE_SIZE; - phase = TP_BURST_SHORT; + // phase = TP_BURST_SHORT; timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply ( GNUNET_TIME_UNIT_SECONDS, TIMEOUT_MULTIPLIER)); @@ -486,7 +628,8 @@ add_queue_cb (void *cls, &latency_timeout, NULL); // prepare_test (NULL); - short_test (NULL); + // short_test (NULL); + choose_phase (); } @@ -501,10 +644,7 @@ update_avg_latency (const char*payload) ts_n = (struct GNUNET_TIME_AbsoluteNBO *) payload; ts = GNUNET_TIME_absolute_ntoh (*ts_n); latency = GNUNET_TIME_absolute_get_duration (ts); - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Latency of received packet: %s\n", - GNUNET_STRINGS_relative_time_to_string (latency, - GNUNET_YES)); + switch (phase) { case TP_INIT: @@ -525,83 +665,40 @@ update_avg_latency (const char*payload) else avg_latency = ((avg_latency * (num_received - 1)) + latency.rel_value_us) / num_received; - + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Latency of received packet: %s with avg latency %lu\n", + GNUNET_STRINGS_relative_time_to_string (latency, + GNUNET_YES), + avg_latency); } -static void -process_statistics_box_done (void *cls, int success) -{ - if (NULL != box_stats) - box_stats = NULL; - if (NULL == rekey_stats) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Finished\n"); - GNUNET_SCHEDULER_shutdown (); - } -} static void -process_statistics_rekey_done (void *cls, int success) +load_phase_config () { - if (NULL != rekey_stats) - rekey_stats = NULL; - if (NULL == box_stats) - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Finished\n"); - GNUNET_SCHEDULER_shutdown (); - } -} + phase_short = GNUNET_CONFIGURATION_get_value_yesno (cfg_peers[0], + TEST_SECTION, + "PHASE_SHORT"); + if (GNUNET_SYSERR == phase_short) + phase_short = GNUNET_YES; -static int -process_statistics (void *cls, - const char *subsystem, - const char *name, - uint64_t value, - int is_persistent) -{ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Statistic: Name %s and value %lu\n", - name, - value); - if ((0 == strcmp ("rekey", test_name)) && (0 == strcmp ( - "# rekeying successful", - name)) && (0 == value)) - { - ret = 2; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "No successful rekeying!\n"); - GNUNET_SCHEDULER_shutdown (); - } - if ((0 == strcmp ("backchannel", test_name)) && - (0 == strcmp ( - "# messages decrypted with BOX", - name)) - && (9000 > value)) - { - ret = 2; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Not enough BOX messages!\n"); - GNUNET_SCHEDULER_shutdown (); - } - if ((0 == strcmp ("rekey", test_name)) && - (0 == strcmp ( - "# messages decrypted with BOX", - name)) - && (6000 > value)) - { - ret = 2; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Not enough BOX messages!\n"); - GNUNET_SCHEDULER_shutdown (); - } - return GNUNET_OK; -} + phase_long = GNUNET_CONFIGURATION_get_value_yesno (cfg_peers[0], + TEST_SECTION, + "PHASE_LONG"); + if (GNUNET_SYSERR == phase_long) + phase_long = GNUNET_YES; + + phase_size = GNUNET_CONFIGURATION_get_value_yesno (cfg_peers[0], + TEST_SECTION, + "PHASE_SIZE"); + + if (GNUNET_SYSERR == phase_size) + phase_size = GNUNET_YES; +} /** * @brief Handle an incoming message @@ -641,8 +738,10 @@ incoming_message_cb ( num_received_short++; duration = GNUNET_TIME_absolute_get_duration (start_short); update_avg_latency (payload); - if ((num_sent_short == BURST_PACKETS) && (num_received_short > - BURST_PACKETS * 0.91) ) + if ((num_sent_short == burst_packets_short) && (num_received_short > + burst_packets_short / 100 + * + allowed_packet_loss_short) ) { LOG (GNUNET_ERROR_TYPE_MESSAGE, "Short size packet test done.\n"); @@ -657,12 +756,14 @@ incoming_message_cb ( goodput, (unsigned long long) avg_latency); GNUNET_free (goodput); - start_long = GNUNET_TIME_absolute_get (); - phase = TP_BURST_LONG; + // start_long = GNUNET_TIME_absolute_get (); + // phase = TP_BURST_LONG; // num_sent_short = 0; avg_latency = 0; // num_received = 0; - long_test (NULL); + phase_short = GNUNET_NO; + choose_phase (); + // long_test (NULL); } break; } @@ -677,8 +778,10 @@ incoming_message_cb ( num_received_long++; duration = GNUNET_TIME_absolute_get_duration (start_long); update_avg_latency (payload); - if ((num_sent_long == BURST_PACKETS) && (num_received_long > BURST_PACKETS - * 0.91) ) + if ((num_sent_long == burst_packets_long) && (num_received_long > + burst_packets_long + / 100 + * allowed_packet_loss_short) ) { LOG (GNUNET_ERROR_TYPE_MESSAGE, "Long size packet test done.\n"); @@ -696,11 +799,13 @@ incoming_message_cb ( (unsigned long long) avg_latency); GNUNET_free (goodput); ack = 0; - phase = TP_SIZE_CHECK; + // phase = TP_SIZE_CHECK; // num_received = 0; // num_sent_long = 0; avg_latency = 0; - size_test (NULL); + // size_test (NULL); + phase_long = GNUNET_NO; + choose_phase (); } break; } @@ -728,44 +833,19 @@ incoming_message_cb ( iterations_left--; if (0 != iterations_left) { - start_short = GNUNET_TIME_absolute_get (); - phase = TP_BURST_SHORT; + // start_short = GNUNET_TIME_absolute_get (); + // phase = TP_BURST_SHORT; num_sent_short = 0; num_sent_long = 0; num_received_short = 0; num_received_long = 0; - short_test (NULL); + // short_test (NULL); + load_phase_config (); + choose_phase (); break; } - if ((0 == strcmp ("udp", communicator_name)) && ((0 == strcmp ("rekey", - test_name)) - ||(0 == strcmp ( - "backchannel", - test_name))) ) - { - if (NULL != box_stats) - GNUNET_STATISTICS_get_cancel (box_stats); - box_stats = GNUNET_STATISTICS_get (stats[1], - "C-UDP", - "# messages decrypted with BOX", - process_statistics_box_done, - &process_statistics, - NULL); - if (NULL != rekey_stats) - GNUNET_STATISTICS_get_cancel (rekey_stats); - rekey_stats = GNUNET_STATISTICS_get (stats[0], - "C-UDP", - "# rekeying successful", - process_statistics_rekey_done, - &process_statistics, - NULL); - } - else - { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Finished\n"); - GNUNET_SCHEDULER_shutdown (); - } + phase_size = GNUNET_NO; + choose_phase (); } break; } @@ -802,6 +882,7 @@ do_shutdown (void *cls) } + /** * @brief Main function called by the scheduler * @@ -846,7 +927,6 @@ run (void *cls) NULL); } - int main (int argc, char *const *argv) @@ -924,6 +1004,49 @@ main (int argc, i, GNUNET_i2s_full (&peer_id[i])); } + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number (cfg_peers[0], + TEST_SECTION, + "ALLOWED_PACKET_LOSS_SHORT", + &allowed_packet_loss_short)) + allowed_packet_loss_short = ALLOWED_PACKET_LOSS; + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number (cfg_peers[0], + TEST_SECTION, + "ALLOWED_PACKET_LOSS_LONG", + &allowed_packet_loss_long)) + allowed_packet_loss_long = ALLOWED_PACKET_LOSS; + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number (cfg_peers[0], + TEST_SECTION, + "BURST_PACKETS_SHORT", + &burst_packets_short)) + burst_packets_short = BURST_PACKETS; + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number (cfg_peers[0], + TEST_SECTION, + "BURST_ÜACKETS_LONG", + &burst_packets_long)) + burst_packets_long = BURST_PACKETS; + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number (cfg_peers[0], + TEST_SECTION, + "DELAY_SHORT", + &delay_short_value)) + delay_short = DELAY; + else + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, + delay_short_value); + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_number (cfg_peers[0], + TEST_SECTION, + "DELAY_SHORT", + &delay_long_value)) + delay_long = DELAY; + else + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, + delay_long_value); + load_phase_config (); LOG (GNUNET_ERROR_TYPE_MESSAGE, "Starting test...\n"); LOG (GNUNET_ERROR_TYPE_DEBUG, "argv[0]: %s\n", diff --git a/src/transport/test_communicator_tcp_basic_peer1.conf b/src/transport/test_communicator_tcp_basic_peer1.conf index b32aa1c17..dbc227ac6 100644 --- a/src/transport/test_communicator_tcp_basic_peer1.conf +++ b/src/transport/test_communicator_tcp_basic_peer1.conf @@ -1,5 +1,10 @@ @INLINE@ test_transport_defaults.conf +[test-setup] +#PHASE_LONG=NO +#PHASE_SIZE=NO +#BURST_PACKETS_SHORT=1 + [PATHS] GNUNET_TEST_HOME = $GNUNET_TMP/test-communicator-unix-1/ -- cgit v1.2.3