diff options
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/test_communicator_basic.c | 51 | ||||
-rw-r--r-- | src/transport/transport-testing2.c | 65 |
2 files changed, 94 insertions, 22 deletions
diff --git a/src/transport/test_communicator_basic.c b/src/transport/test_communicator_basic.c index d7622a2cc..ef91e133d 100644 --- a/src/transport/test_communicator_basic.c +++ b/src/transport/test_communicator_basic.c | |||
@@ -69,7 +69,7 @@ static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *my_tc; | |||
69 | #define BURST_RUNS 1 | 69 | #define BURST_RUNS 1 |
70 | 70 | ||
71 | #define SHORT_BURST_WINDOW \ | 71 | #define SHORT_BURST_WINDOW \ |
72 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,5) | 72 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,2) |
73 | 73 | ||
74 | #define LONG_BURST_WINDOW \ | 74 | #define LONG_BURST_WINDOW \ |
75 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,2) | 75 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,2) |
@@ -81,7 +81,7 @@ static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *my_tc; | |||
81 | #define SIZE_CHECK 2 | 81 | #define SIZE_CHECK 2 |
82 | 82 | ||
83 | 83 | ||
84 | static int num_sent = 0; | 84 | static size_t num_sent = 0; |
85 | 85 | ||
86 | static uint32_t ack = 0; | 86 | static uint32_t ack = 0; |
87 | 87 | ||
@@ -91,6 +91,8 @@ static size_t num_received = 0; | |||
91 | 91 | ||
92 | static uint64_t avg_latency = 0; | 92 | static uint64_t avg_latency = 0; |
93 | 93 | ||
94 | static struct GNUNET_TIME_Relative duration; | ||
95 | |||
94 | static void | 96 | static void |
95 | communicator_available_cb (void *cls, | 97 | communicator_available_cb (void *cls, |
96 | struct | 98 | struct |
@@ -187,18 +189,20 @@ size_test (void *cls) | |||
187 | ack); | 189 | ack); |
188 | GNUNET_free (payload); | 190 | GNUNET_free (payload); |
189 | ack += 5; | 191 | ack += 5; |
192 | num_sent++; | ||
190 | if (ack < 64000) | 193 | if (ack < 64000) |
191 | GNUNET_SCHEDULER_add_now (&size_test, NULL); | 194 | GNUNET_SCHEDULER_add_now (&size_test, NULL); |
192 | else | 195 | else |
193 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 196 | GNUNET_SCHEDULER_add_delayed (SHORT_BURST_WINDOW, |
194 | &size_test, NULL); | 197 | &size_test, NULL); |
195 | return; | 198 | return; |
196 | } | 199 | } |
197 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 200 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
198 | "Size packet test done.\n"); | 201 | "Size packet test done.\n"); |
199 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 202 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
200 | "#packets: %lu -- latency: %lu microseconds\n", | 203 | "%lu/%lu packets -- avg latency: %lu us\n", |
201 | num_received, | 204 | num_received, |
205 | num_sent, | ||
202 | avg_latency); | 206 | avg_latency); |
203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
204 | "Finished\n"); | 208 | "Finished\n"); |
@@ -210,8 +214,6 @@ size_test (void *cls) | |||
210 | static void | 214 | static void |
211 | long_test (void *cls) | 215 | long_test (void *cls) |
212 | { | 216 | { |
213 | struct GNUNET_TIME_Relative duration = GNUNET_TIME_absolute_get_duration ( | ||
214 | start_long); | ||
215 | char *payload; | 217 | char *payload; |
216 | if (num_sent < BURST_PACKETS) | 218 | if (num_sent < BURST_PACKETS) |
217 | { | 219 | { |
@@ -228,13 +230,14 @@ long_test (void *cls) | |||
228 | &long_test, NULL); | 230 | &long_test, NULL); |
229 | return; | 231 | return; |
230 | } | 232 | } |
231 | duration = GNUNET_TIME_absolute_get_duration (start_long); | ||
232 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 233 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
233 | "Long size packet test done.\n"); | 234 | "Long size packet test done.\n"); |
234 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 235 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
235 | "goodput: %lu kb/s -- #packets: %lu -- latency: %lu microseconds\n", | 236 | "%lu/%lu packets in %lu us (%lu kb/s) -- avg latency: %lu us\n", |
236 | (LONG_MESSAGE_SIZE * num_received) / (duration.rel_value_us / 1000), | ||
237 | num_received, | 237 | num_received, |
238 | num_sent, | ||
239 | duration.rel_value_us, | ||
240 | (LONG_MESSAGE_SIZE * num_received) / (duration.rel_value_us / 1000), | ||
238 | avg_latency); | 241 | avg_latency); |
239 | ack = 10; | 242 | ack = 10; |
240 | num_received = 0; | 243 | num_received = 0; |
@@ -247,9 +250,8 @@ long_test (void *cls) | |||
247 | static void | 250 | static void |
248 | short_test (void *cls) | 251 | short_test (void *cls) |
249 | { | 252 | { |
250 | struct GNUNET_TIME_Relative duration; | ||
251 | char *payload; | 253 | char *payload; |
252 | if (num_sent < BURST_PACKETS) | 254 | while (num_sent < BURST_PACKETS) |
253 | { | 255 | { |
254 | payload = make_payload (SHORT_MESSAGE_SIZE); | 256 | payload = make_payload (SHORT_MESSAGE_SIZE); |
255 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, | 257 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, |
@@ -257,20 +259,23 @@ short_test (void *cls) | |||
257 | SHORT_MESSAGE_SIZE); | 259 | SHORT_MESSAGE_SIZE); |
258 | num_sent++; | 260 | num_sent++; |
259 | GNUNET_free (payload); | 261 | GNUNET_free (payload); |
260 | if (num_sent < BURST_PACKETS) | 262 | //if (num_sent < BURST_PACKETS) |
261 | GNUNET_SCHEDULER_add_now (&short_test, NULL); | 263 | // GNUNET_SCHEDULER_add_now (&short_test, NULL); |
262 | if (num_sent == BURST_PACKETS) | 264 | if (num_sent == BURST_PACKETS) |
265 | { | ||
263 | GNUNET_SCHEDULER_add_delayed (SHORT_BURST_WINDOW, | 266 | GNUNET_SCHEDULER_add_delayed (SHORT_BURST_WINDOW, |
264 | &short_test, NULL); | 267 | &short_test, NULL); |
265 | return; | 268 | return; |
269 | } | ||
266 | } | 270 | } |
267 | duration = GNUNET_TIME_absolute_get_duration (start_short); | ||
268 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 271 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
269 | "Short size packet test done.\n"); | 272 | "Short size packet test done.\n"); |
270 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 273 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
271 | "goodput: %lu kb/s -- #packets: %lu -- latency: %lu microseconds\n", | 274 | "%lu/%lu packets in %lu us (%lu kb/s) -- avg latency: %lu us\n", |
272 | (SHORT_MESSAGE_SIZE * num_received) / (duration.rel_value_us / 1000), | ||
273 | num_received, | 275 | num_received, |
276 | num_sent, | ||
277 | duration.rel_value_us, | ||
278 | (SHORT_MESSAGE_SIZE * num_received) / (duration.rel_value_us / 1000), | ||
274 | avg_latency); | 279 | avg_latency); |
275 | start_long = GNUNET_TIME_absolute_get (); | 280 | start_long = GNUNET_TIME_absolute_get (); |
276 | phase = BURST_LONG; | 281 | phase = BURST_LONG; |
@@ -345,18 +350,28 @@ incoming_message_cb (void *cls, | |||
345 | size_t payload_len) | 350 | size_t payload_len) |
346 | { | 351 | { |
347 | if (0 != strcmp ((char*) cls, cfg_peers_name[NUM_PEERS - 1])) | 352 | if (0 != strcmp ((char*) cls, cfg_peers_name[NUM_PEERS - 1])) |
348 | return; // TODO? | 353 | { |
354 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
355 | "unexpected receiver...\n"); | ||
356 | return; | ||
357 | } | ||
349 | if (phase == BURST_SHORT) | 358 | if (phase == BURST_SHORT) |
350 | { | 359 | { |
351 | GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len); | 360 | GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len); |
352 | num_received++; | 361 | num_received++; |
362 | duration = GNUNET_TIME_absolute_get_duration (start_short); | ||
353 | update_avg_latency (payload); | 363 | update_avg_latency (payload); |
354 | } | 364 | } |
355 | else if (phase == BURST_LONG) | 365 | else if (phase == BURST_LONG) |
356 | { | 366 | { |
357 | if (LONG_MESSAGE_SIZE != payload_len) | 367 | if (LONG_MESSAGE_SIZE != payload_len) |
368 | { | ||
369 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
370 | "Ignoring packet with wrong length\n"); | ||
358 | return; // Ignore | 371 | return; // Ignore |
372 | } | ||
359 | num_received++; | 373 | num_received++; |
374 | duration = GNUNET_TIME_absolute_get_duration (start_long); | ||
360 | update_avg_latency (payload); | 375 | update_avg_latency (payload); |
361 | } | 376 | } |
362 | else // if (phase == SIZE_CHECK) { | 377 | else // if (phase == SIZE_CHECK) { |
diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c index ba58776fb..558bf007f 100644 --- a/src/transport/transport-testing2.c +++ b/src/transport/transport-testing2.c | |||
@@ -80,6 +80,11 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle | |||
80 | struct GNUNET_OS_Process *c_proc; | 80 | struct GNUNET_OS_Process *c_proc; |
81 | 81 | ||
82 | /** | 82 | /** |
83 | * NAT process | ||
84 | */ | ||
85 | struct GNUNET_OS_Process *nat_proc; | ||
86 | |||
87 | /** | ||
83 | * @brief Task that will be run on shutdown to stop and clean communicator | 88 | * @brief Task that will be run on shutdown to stop and clean communicator |
84 | */ | 89 | */ |
85 | struct GNUNET_SCHEDULER_Task *c_shutdown_task; | 90 | struct GNUNET_SCHEDULER_Task *c_shutdown_task; |
@@ -660,10 +665,8 @@ transport_communicator_start ( | |||
660 | * @param cls Closure - Process of communicator | 665 | * @param cls Closure - Process of communicator |
661 | */ | 666 | */ |
662 | static void | 667 | static void |
663 | shutdown_communicator (void *cls) | 668 | shutdown_process (struct GNUNET_OS_Process *proc) |
664 | { | 669 | { |
665 | struct GNUNET_OS_Process *proc = cls; | ||
666 | |||
667 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 670 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
668 | { | 671 | { |
669 | LOG (GNUNET_ERROR_TYPE_WARNING, | 672 | LOG (GNUNET_ERROR_TYPE_WARNING, |
@@ -677,6 +680,13 @@ shutdown_communicator (void *cls) | |||
677 | GNUNET_OS_process_destroy (proc); | 680 | GNUNET_OS_process_destroy (proc); |
678 | } | 681 | } |
679 | 682 | ||
683 | static void | ||
684 | shutdown_communicator (void *cls) | ||
685 | { | ||
686 | struct GNUNET_OS_Process *proc = cls; | ||
687 | shutdown_process(proc); | ||
688 | } | ||
689 | |||
680 | 690 | ||
681 | /** | 691 | /** |
682 | * @brief Start the communicator | 692 | * @brief Start the communicator |
@@ -711,6 +721,51 @@ communicator_start ( | |||
711 | GNUNET_free (binary); | 721 | GNUNET_free (binary); |
712 | } | 722 | } |
713 | 723 | ||
724 | /** | ||
725 | * @brief Task run at shutdown to kill communicator and clean up | ||
726 | * | ||
727 | * @param cls Closure - Process of communicator | ||
728 | */ | ||
729 | static void | ||
730 | shutdown_nat (void *cls) | ||
731 | { | ||
732 | struct GNUNET_OS_Process *proc = cls; | ||
733 | shutdown_process (proc); | ||
734 | } | ||
735 | |||
736 | |||
737 | /** | ||
738 | * @brief Start NAT | ||
739 | * | ||
740 | */ | ||
741 | static void | ||
742 | nat_start ( | ||
743 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) | ||
744 | { | ||
745 | char *binary; | ||
746 | |||
747 | LOG (GNUNET_ERROR_TYPE_DEBUG, "nat_start\n"); | ||
748 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-nat"); | ||
749 | tc_h->nat_proc = GNUNET_OS_start_process (GNUNET_YES, | ||
750 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | ||
751 | NULL, | ||
752 | NULL, | ||
753 | NULL, | ||
754 | binary, | ||
755 | "gnunet-service-nat", | ||
756 | "-c", | ||
757 | tc_h->cfg_filename, | ||
758 | NULL); | ||
759 | if (NULL == tc_h->nat_proc) | ||
760 | { | ||
761 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start NAT!"); | ||
762 | return; | ||
763 | } | ||
764 | LOG (GNUNET_ERROR_TYPE_INFO, "started NAT\n"); | ||
765 | GNUNET_free (binary); | ||
766 | } | ||
767 | |||
768 | |||
714 | 769 | ||
715 | static void | 770 | static void |
716 | do_shutdown (void *cls) | 771 | do_shutdown (void *cls) |
@@ -718,6 +773,7 @@ do_shutdown (void *cls) | |||
718 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | 773 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; |
719 | shutdown_communicator(tc_h->c_proc); | 774 | shutdown_communicator(tc_h->c_proc); |
720 | shutdown_service(tc_h->sh); | 775 | shutdown_service(tc_h->sh); |
776 | shutdown_nat(tc_h->nat_proc); | ||
721 | } | 777 | } |
722 | 778 | ||
723 | 779 | ||
@@ -771,7 +827,8 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( | |||
771 | 827 | ||
772 | /* Start communicator part of service */ | 828 | /* Start communicator part of service */ |
773 | transport_communicator_start (tc_h); | 829 | transport_communicator_start (tc_h); |
774 | 830 | /* Start NAT */ | |
831 | nat_start (tc_h); | ||
775 | /* Schedule start communicator */ | 832 | /* Schedule start communicator */ |
776 | communicator_start (tc_h, | 833 | communicator_start (tc_h, |
777 | binary_name); | 834 | binary_name); |