diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-12-25 13:42:20 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-12-25 13:42:20 +0100 |
commit | 7a70077cde3966250c4c7323e67d41113255bb82 (patch) | |
tree | 81880e33cc7216b43663c18db6ce3f463ba8463c /src/transport/test_communicator_basic.c | |
parent | 817ec33a8844965269f99950b4f198c8f237c130 (diff) | |
download | gnunet-7a70077cde3966250c4c7323e67d41113255bb82.tar.gz gnunet-7a70077cde3966250c4c7323e67d41113255bb82.zip |
clean up code a bit
Diffstat (limited to 'src/transport/test_communicator_basic.c')
-rw-r--r-- | src/transport/test_communicator_basic.c | 187 |
1 files changed, 98 insertions, 89 deletions
diff --git a/src/transport/test_communicator_basic.c b/src/transport/test_communicator_basic.c index f697f17b3..74bd831b4 100644 --- a/src/transport/test_communicator_basic.c +++ b/src/transport/test_communicator_basic.c | |||
@@ -78,18 +78,19 @@ static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *my_tc; | |||
78 | #define LONG_BURST_WINDOW \ | 78 | #define LONG_BURST_WINDOW \ |
79 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,2) | 79 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,2) |
80 | 80 | ||
81 | #define BURST_SHORT 0 | 81 | enum TestPhase |
82 | 82 | { | |
83 | #define BURST_LONG 1 | 83 | TP_BURST_SHORT, |
84 | 84 | TP_BURST_LONG, | |
85 | #define SIZE_CHECK 2 | 85 | TP_SIZE_CHECK |
86 | }; | ||
86 | 87 | ||
87 | 88 | ||
88 | static size_t num_sent = 0; | 89 | static size_t num_sent = 0; |
89 | 90 | ||
90 | static uint32_t ack = 0; | 91 | static uint32_t ack = 0; |
91 | 92 | ||
92 | static int phase; | 93 | static enum TestPhase phase; |
93 | 94 | ||
94 | static size_t num_received = 0; | 95 | static size_t num_received = 0; |
95 | 96 | ||
@@ -199,8 +200,8 @@ static void | |||
199 | size_test (void *cls) | 200 | size_test (void *cls) |
200 | { | 201 | { |
201 | char *payload; | 202 | char *payload; |
202 | phase = SIZE_CHECK; | ||
203 | 203 | ||
204 | phase = TP_SIZE_CHECK; | ||
204 | if (ack < 64000) // Leave some room for our protocol. | 205 | if (ack < 64000) // Leave some room for our protocol. |
205 | { | 206 | { |
206 | payload = make_payload (ack); | 207 | payload = make_payload (ack); |
@@ -296,7 +297,7 @@ add_queue_cb (void *cls, | |||
296 | "Queue established, starting test...\n"); | 297 | "Queue established, starting test...\n"); |
297 | start_short = GNUNET_TIME_absolute_get (); | 298 | start_short = GNUNET_TIME_absolute_get (); |
298 | my_tc = tc_queue; | 299 | my_tc = tc_queue; |
299 | phase = BURST_SHORT; | 300 | phase = TP_BURST_SHORT; |
300 | GNUNET_SCHEDULER_add_now (&short_test, tc_queue); | 301 | GNUNET_SCHEDULER_add_now (&short_test, tc_queue); |
301 | } | 302 | } |
302 | 303 | ||
@@ -329,7 +330,7 @@ update_avg_latency (const char*payload) | |||
329 | * @param tc_h Handle to the receiving communicator | 330 | * @param tc_h Handle to the receiving communicator |
330 | * @param msg Received message | 331 | * @param msg Received message |
331 | */ | 332 | */ |
332 | void | 333 | static void |
333 | incoming_message_cb (void *cls, | 334 | incoming_message_cb (void *cls, |
334 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle | 335 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle |
335 | *tc_h, | 336 | *tc_h, |
@@ -342,97 +343,105 @@ incoming_message_cb (void *cls, | |||
342 | "unexpected receiver...\n"); | 343 | "unexpected receiver...\n"); |
343 | return; | 344 | return; |
344 | } | 345 | } |
345 | if (phase == BURST_SHORT) | 346 | switch (phase) |
346 | { | 347 | { |
347 | GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len); | 348 | case TP_BURST_SHORT: |
348 | num_received++; | ||
349 | duration = GNUNET_TIME_absolute_get_duration (start_short); | ||
350 | update_avg_latency (payload); | ||
351 | if (num_received == BURST_PACKETS) | ||
352 | { | 349 | { |
353 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 350 | GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len); |
354 | "Short size packet test done.\n"); | 351 | num_received++; |
355 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 352 | duration = GNUNET_TIME_absolute_get_duration (start_short); |
356 | "%lu/%lu packets in %llu us (%llu kb/s) -- avg latency: %llu us\n", | 353 | update_avg_latency (payload); |
357 | (unsigned long) num_received, | 354 | if (num_received == BURST_PACKETS) |
358 | (unsigned long) num_sent, | 355 | { |
359 | (unsigned long long) duration.rel_value_us, | 356 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
360 | (unsigned long long) ((SHORT_MESSAGE_SIZE * num_received) | 357 | "Short size packet test done.\n"); |
361 | / (duration.rel_value_us | 358 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
362 | / | 359 | "%lu/%lu packets in %llu us (%llu kb/s) -- avg latency: %llu us\n", |
363 | 1000)), | 360 | (unsigned long) num_received, |
364 | (unsigned long long) avg_latency); | 361 | (unsigned long) num_sent, |
365 | start_long = GNUNET_TIME_absolute_get (); | 362 | (unsigned long long) duration.rel_value_us, |
366 | phase = BURST_LONG; | 363 | (unsigned long long) ((SHORT_MESSAGE_SIZE * num_received) |
367 | num_sent = 0; | 364 | / (duration.rel_value_us |
368 | avg_latency = 0; | 365 | / |
369 | num_received = 0; | 366 | 1000)), |
370 | GNUNET_SCHEDULER_cancel (to_task); | 367 | (unsigned long long) avg_latency); |
371 | to_task = NULL; | 368 | start_long = GNUNET_TIME_absolute_get (); |
372 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &long_test, NULL); | 369 | phase = TP_BURST_LONG; |
373 | } | 370 | num_sent = 0; |
371 | avg_latency = 0; | ||
372 | num_received = 0; | ||
373 | GNUNET_SCHEDULER_cancel (to_task); | ||
374 | to_task = NULL; | ||
375 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &long_test, | ||
376 | NULL); | ||
377 | } | ||
374 | 378 | ||
375 | } | 379 | break; |
376 | else if (phase == BURST_LONG) | ||
377 | { | ||
378 | if (LONG_MESSAGE_SIZE != payload_len) | ||
379 | { | ||
380 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
381 | "Ignoring packet with wrong length\n"); | ||
382 | return; // Ignore | ||
383 | } | 380 | } |
384 | num_received++; | 381 | case TP_BURST_LONG: |
385 | duration = GNUNET_TIME_absolute_get_duration (start_long); | ||
386 | update_avg_latency (payload); | ||
387 | if (num_received == BURST_PACKETS) | ||
388 | { | 382 | { |
389 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 383 | if (LONG_MESSAGE_SIZE != payload_len) |
390 | "Long size packet test done.\n"); | 384 | { |
391 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 385 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
392 | "%lu/%lu packets in %llu us (%llu kb/s) -- avg latency: %llu us\n", | 386 | "Ignoring packet with wrong length\n"); |
393 | (unsigned long) num_received, | 387 | return; // Ignore |
394 | (unsigned long) num_sent, | 388 | } |
395 | (unsigned long long) duration.rel_value_us, | 389 | num_received++; |
396 | (unsigned long long) ((LONG_MESSAGE_SIZE * num_received) | 390 | duration = GNUNET_TIME_absolute_get_duration (start_long); |
397 | / (duration.rel_value_us | 391 | update_avg_latency (payload); |
398 | / | 392 | if (num_received == BURST_PACKETS) |
399 | 1000)), | 393 | { |
400 | (unsigned long long) avg_latency); | 394 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
401 | ack = 10; | 395 | "Long size packet test done.\n"); |
402 | phase = SIZE_CHECK; | 396 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
403 | num_received = 0; | 397 | "%lu/%lu packets in %llu us (%llu kb/s) -- avg latency: %llu us\n", |
404 | num_sent = 0; | 398 | (unsigned long) num_received, |
405 | avg_latency = 0; | 399 | (unsigned long) num_sent, |
406 | GNUNET_SCHEDULER_cancel (to_task); | 400 | (unsigned long long) duration.rel_value_us, |
407 | to_task = NULL; | 401 | (unsigned long long) ((LONG_MESSAGE_SIZE * num_received) |
408 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &size_test, NULL); | 402 | / (duration.rel_value_us |
403 | / | ||
404 | 1000)), | ||
405 | (unsigned long long) avg_latency); | ||
406 | ack = 10; | ||
407 | phase = TP_SIZE_CHECK; | ||
408 | num_received = 0; | ||
409 | num_sent = 0; | ||
410 | avg_latency = 0; | ||
411 | GNUNET_SCHEDULER_cancel (to_task); | ||
412 | to_task = NULL; | ||
413 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &size_test, | ||
414 | NULL); | ||
409 | 415 | ||
416 | } | ||
417 | break; | ||
410 | } | 418 | } |
411 | } | 419 | case TP_SIZE_CHECK: |
412 | else // if (phase == SIZE_CHECK) { | ||
413 | { | ||
414 | num_received++; | ||
415 | update_avg_latency (payload); | ||
416 | if (num_received >= (64000 - 10) / 5) | ||
417 | { | 420 | { |
418 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 421 | num_received++; |
419 | "Size packet test done.\n"); | 422 | update_avg_latency (payload); |
420 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 423 | if (num_received >= (64000 - 10) / 5) |
421 | "%lu/%lu packets -- avg latency: %llu us\n", | 424 | { |
422 | (unsigned long) num_received, | 425 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
423 | (unsigned long) num_sent, | 426 | "Size packet test done.\n"); |
424 | (unsigned long long) avg_latency); | 427 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
425 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 428 | "%lu/%lu packets -- avg latency: %llu us\n", |
426 | "Finished\n"); | 429 | (unsigned long) num_received, |
427 | GNUNET_SCHEDULER_cancel (to_task); | 430 | (unsigned long) num_sent, |
428 | to_task = NULL; | 431 | (unsigned long long) avg_latency); |
429 | GNUNET_SCHEDULER_shutdown (); | 432 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
430 | // Finished! | 433 | "Finished\n"); |
431 | // } | 434 | GNUNET_SCHEDULER_cancel (to_task); |
435 | to_task = NULL; | ||
436 | GNUNET_SCHEDULER_shutdown (); | ||
437 | // Finished! | ||
438 | // } | ||
439 | } | ||
440 | break; | ||
432 | } | 441 | } |
433 | } | 442 | } |
434 | // Reset timeout | 443 | // Reset timeout |
435 | if (to_task != NULL) | 444 | if (NULL != to_task) |
436 | { | 445 | { |
437 | GNUNET_SCHEDULER_cancel (to_task); | 446 | GNUNET_SCHEDULER_cancel (to_task); |
438 | to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 447 | to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |