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.c174
1 files changed, 137 insertions, 37 deletions
diff --git a/src/transport/test_communicator_basic.c b/src/transport/test_communicator_basic.c
index e3573ac2c..2d550dc16 100644
--- a/src/transport/test_communicator_basic.c
+++ b/src/transport/test_communicator_basic.c
@@ -82,6 +82,9 @@ static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *my_tc;
82 82
83static unsigned int iterations_left = TOTAL_ITERATIONS; 83static unsigned int iterations_left = TOTAL_ITERATIONS;
84 84
85#define DELAY \
86 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS,1000)
87
85#define SHORT_BURST_WINDOW \ 88#define SHORT_BURST_WINDOW \
86 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,2) 89 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,2)
87 90
@@ -97,13 +100,21 @@ enum TestPhase
97}; 100};
98 101
99 102
100static size_t num_sent = 0; 103static size_t num_sent_short = 0;
104
105static size_t num_sent_long = 0;
106
107static size_t num_sent_size = 0;
101 108
102static uint32_t ack = 0; 109static uint32_t ack = 0;
103 110
104static enum TestPhase phase; 111static enum TestPhase phase;
105 112
106static size_t num_received = 0; 113static size_t num_received_short = 0;
114
115static size_t num_received_long = 0;
116
117static size_t num_received_size = 0;
107 118
108static uint64_t avg_latency = 0; 119static uint64_t avg_latency = 0;
109 120
@@ -230,6 +241,10 @@ make_payload (size_t payload_size)
230static void 241static void
231latency_timeout (void *cls) 242latency_timeout (void *cls)
232{ 243{
244
245 size_t num_sent = 0;
246 size_t num_received = 0;
247
233 to_task = NULL; 248 to_task = NULL;
234 if (GNUNET_TIME_absolute_get_remaining (timeout).rel_value_us > 0) 249 if (GNUNET_TIME_absolute_get_remaining (timeout).rel_value_us > 0)
235 { 250 {
@@ -239,6 +254,21 @@ latency_timeout (void *cls)
239 return; 254 return;
240 } 255 }
241 256
257 switch (phase)
258 {
259 case TP_BURST_SHORT:
260 num_sent = num_sent_short;
261 num_received = num_received_short;
262 break;
263 case TP_BURST_LONG:
264 num_sent = num_sent_long;
265 num_received = num_received_long;
266 break;
267 case TP_SIZE_CHECK:
268 num_sent = num_sent_size;
269 num_received = num_received_size;
270 break;
271 }
242 LOG (GNUNET_ERROR_TYPE_ERROR, 272 LOG (GNUNET_ERROR_TYPE_ERROR,
243 "Latency too high. Test failed. (Phase: %d. Sent: %lu, Received: %lu)\n", 273 "Latency too high. Test failed. (Phase: %d. Sent: %lu, Received: %lu)\n",
244 phase, num_sent, num_received); 274 phase, num_sent, num_received);
@@ -246,6 +276,8 @@ latency_timeout (void *cls)
246 GNUNET_SCHEDULER_shutdown (); 276 GNUNET_SCHEDULER_shutdown ();
247} 277}
248 278
279/*static void
280 size_test (void *cls);*/
249 281
250static void 282static void
251size_test (void *cls) 283size_test (void *cls)
@@ -253,6 +285,9 @@ size_test (void *cls)
253 char *payload; 285 char *payload;
254 size_t max_size = 64000; 286 size_t max_size = 64000;
255 287
288 LOG (GNUNET_ERROR_TYPE_DEBUG,
289 "size_test_cb %u\n",
290 num_sent_size);
256 GNUNET_assert (TP_SIZE_CHECK == phase); 291 GNUNET_assert (TP_SIZE_CHECK == phase);
257 if (LONG_MESSAGE_SIZE != long_message_size) 292 if (LONG_MESSAGE_SIZE != long_message_size)
258 max_size = long_message_size; 293 max_size = long_message_size;
@@ -260,7 +295,7 @@ size_test (void *cls)
260 return; /* Leave some room for our protocol, so not 2^16 exactly */ 295 return; /* Leave some room for our protocol, so not 2^16 exactly */
261 ack += 10; 296 ack += 10;
262 payload = make_payload (ack); 297 payload = make_payload (ack);
263 num_sent++; 298 num_sent_size++;
264 GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, 299 GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc,
265 (ack < max_size) 300 (ack < max_size)
266 ? &size_test 301 ? &size_test
@@ -272,17 +307,34 @@ size_test (void *cls)
272 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS); 307 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
273} 308}
274 309
310/*static void
311size_test (void *cls)
312{
313 GNUNET_SCHEDULER_add_delayed (DELAY,
314 &size_test_cb,
315 NULL);
316 }*/
317
318static void
319long_test (void *cls);
275 320
276static void 321static void
277long_test (void *cls) 322long_test_cb (void *cls)
278{ 323{
279 char *payload; 324 char *payload;
280 325
326 LOG (GNUNET_ERROR_TYPE_DEBUG,
327 "long_test_cb %u/%u\n",
328 num_sent_long,
329 num_received_long);
281 payload = make_payload (long_message_size); 330 payload = make_payload (long_message_size);
282 num_sent++; 331 num_sent_long++;
283 GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, 332 GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc,
284 (BURST_PACKETS == 333 ((BURST_PACKETS
285 num_sent) 334 * 0.91 ==
335 num_received_long) ||
336 (BURST_PACKETS ==
337 num_sent_long))
286 ? NULL 338 ? NULL
287 : &long_test, 339 : &long_test,
288 NULL, 340 NULL,
@@ -292,17 +344,37 @@ long_test (void *cls)
292 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS); 344 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
293} 345}
294 346
347static void
348long_test (void *cls)
349{
350 /*LOG (GNUNET_ERROR_TYPE_DEBUG,
351 "long_test %u\n",
352 num_sent_long);*/
353 GNUNET_SCHEDULER_add_delayed (DELAY,
354 &long_test_cb,
355 NULL);
356}
295 357
296static void 358static void
297short_test (void *cls) 359short_test (void *cls);
360
361static void
362short_test_cb (void *cls)
298{ 363{
299 char *payload; 364 char *payload;
300 365
366 LOG (GNUNET_ERROR_TYPE_DEBUG,
367 "short_test_cb %u/%u\n",
368 num_sent_short,
369 num_received_short);
301 payload = make_payload (SHORT_MESSAGE_SIZE); 370 payload = make_payload (SHORT_MESSAGE_SIZE);
302 num_sent++; 371 num_sent_short++;
303 GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, 372 GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc,
304 (BURST_PACKETS == 373 ((BURST_PACKETS
305 num_sent) 374 * 0.91 ==
375 num_received_short) ||
376 (BURST_PACKETS ==
377 num_sent_short))
306 ? NULL 378 ? NULL
307 : &short_test, 379 : &short_test,
308 NULL, 380 NULL,
@@ -312,6 +384,14 @@ short_test (void *cls)
312 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS); 384 timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS);
313} 385}
314 386
387static void
388short_test (void *cls)
389{
390 GNUNET_SCHEDULER_add_delayed (DELAY,
391 &short_test_cb,
392 NULL);
393}
394
315 395
316static int test_prepared = GNUNET_NO; 396static int test_prepared = GNUNET_NO;
317 397
@@ -388,10 +468,23 @@ update_avg_latency (const char*payload)
388 struct GNUNET_TIME_AbsoluteNBO *ts_n; 468 struct GNUNET_TIME_AbsoluteNBO *ts_n;
389 struct GNUNET_TIME_Absolute ts; 469 struct GNUNET_TIME_Absolute ts;
390 struct GNUNET_TIME_Relative latency; 470 struct GNUNET_TIME_Relative latency;
471 size_t num_received = 0;
391 472
392 ts_n = (struct GNUNET_TIME_AbsoluteNBO *) payload; 473 ts_n = (struct GNUNET_TIME_AbsoluteNBO *) payload;
393 ts = GNUNET_TIME_absolute_ntoh (*ts_n); 474 ts = GNUNET_TIME_absolute_ntoh (*ts_n);
394 latency = GNUNET_TIME_absolute_get_duration (ts); 475 latency = GNUNET_TIME_absolute_get_duration (ts);
476 switch (phase)
477 {
478 case TP_BURST_SHORT:
479 num_received = num_received_short;
480 break;
481 case TP_BURST_LONG:
482 num_received = num_received_long;
483 break;
484 case TP_SIZE_CHECK:
485 num_received = num_received_size;
486 break;
487 }
395 if (1 >= num_received) 488 if (1 >= num_received)
396 avg_latency = latency.rel_value_us; 489 avg_latency = latency.rel_value_us;
397 else 490 else
@@ -400,7 +493,6 @@ update_avg_latency (const char*payload)
400 493
401} 494}
402 495
403
404/** 496/**
405 * @brief Handle an incoming message 497 * @brief Handle an incoming message
406 * 498 *
@@ -412,7 +504,8 @@ update_avg_latency (const char*payload)
412 */ 504 */
413static void 505static void
414incoming_message_cb (void *cls, 506incoming_message_cb (void *cls,
415 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle 507 struct
508 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
416 *tc_h, 509 *tc_h,
417 const char*payload, 510 const char*payload,
418 size_t payload_len) 511 size_t payload_len)
@@ -433,30 +526,31 @@ incoming_message_cb (void *cls,
433 case TP_BURST_SHORT: 526 case TP_BURST_SHORT:
434 { 527 {
435 GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len); 528 GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len);
436 num_received++; 529 num_received_short++;
437 duration = GNUNET_TIME_absolute_get_duration (start_short); 530 duration = GNUNET_TIME_absolute_get_duration (start_short);
438 update_avg_latency (payload); 531 update_avg_latency (payload);
439 if (num_received == BURST_PACKETS) 532 if (num_received_short == BURST_PACKETS * 0.91)
440 { 533 {
441 LOG (GNUNET_ERROR_TYPE_MESSAGE, 534 LOG (GNUNET_ERROR_TYPE_MESSAGE,
442 "Short size packet test done.\n"); 535 "Short size packet test done.\n");
443 char *goodput = GNUNET_STRINGS_byte_size_fancy ((SHORT_MESSAGE_SIZE 536 char *goodput = GNUNET_STRINGS_byte_size_fancy ((SHORT_MESSAGE_SIZE
444 * num_received * 1000 537 * num_received_short
538 * 1000
445 * 1000) 539 * 1000)
446 / duration.rel_value_us); 540 / duration.rel_value_us);
447 LOG (GNUNET_ERROR_TYPE_MESSAGE, 541 LOG (GNUNET_ERROR_TYPE_MESSAGE,
448 "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", 542 "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n",
449 (unsigned long) num_received, 543 (unsigned long) num_received_short,
450 (unsigned long) num_sent, 544 (unsigned long) num_sent_short,
451 (unsigned long long) duration.rel_value_us, 545 (unsigned long long) duration.rel_value_us,
452 goodput, 546 goodput,
453 (unsigned long long) avg_latency); 547 (unsigned long long) avg_latency);
454 GNUNET_free (goodput); 548 GNUNET_free (goodput);
455 start_long = GNUNET_TIME_absolute_get (); 549 start_long = GNUNET_TIME_absolute_get ();
456 phase = TP_BURST_LONG; 550 phase = TP_BURST_LONG;
457 num_sent = 0; 551 // num_sent_short = 0;
458 avg_latency = 0; 552 avg_latency = 0;
459 num_received = 0; 553 // num_received = 0;
460 long_test (NULL); 554 long_test (NULL);
461 } 555 }
462 break; 556 break;
@@ -467,32 +561,34 @@ incoming_message_cb (void *cls,
467 { 561 {
468 LOG (GNUNET_ERROR_TYPE_WARNING, 562 LOG (GNUNET_ERROR_TYPE_WARNING,
469 "Ignoring packet with wrong length\n"); 563 "Ignoring packet with wrong length\n");
470 return; // Ignore 564 return; // Ignore
471 } 565 }
472 num_received++; 566 num_received_long++;
473 duration = GNUNET_TIME_absolute_get_duration (start_long); 567 duration = GNUNET_TIME_absolute_get_duration (start_long);
474 update_avg_latency (payload); 568 update_avg_latency (payload);
475 if (num_received == BURST_PACKETS) 569 if (num_received_long == BURST_PACKETS * 0.91)
476 { 570 {
477 LOG (GNUNET_ERROR_TYPE_MESSAGE, 571 LOG (GNUNET_ERROR_TYPE_MESSAGE,
478 "Long size packet test done.\n"); 572 "Long size packet test done.\n");
479 char *goodput = GNUNET_STRINGS_byte_size_fancy ((long_message_size 573 char *goodput = GNUNET_STRINGS_byte_size_fancy ((long_message_size
480 * num_received * 1000 574 * num_received_long
575 * 1000
481 * 1000) 576 * 1000)
482 / duration.rel_value_us); 577 / duration.
578 rel_value_us);
483 579
484 LOG (GNUNET_ERROR_TYPE_MESSAGE, 580 LOG (GNUNET_ERROR_TYPE_MESSAGE,
485 "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", 581 "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n",
486 (unsigned long) num_received, 582 (unsigned long) num_received_long,
487 (unsigned long) num_sent, 583 (unsigned long) num_sent_long,
488 (unsigned long long) duration.rel_value_us, 584 (unsigned long long) duration.rel_value_us,
489 goodput, 585 goodput,
490 (unsigned long long) avg_latency); 586 (unsigned long long) avg_latency);
491 GNUNET_free (goodput); 587 GNUNET_free (goodput);
492 ack = 0; 588 ack = 0;
493 phase = TP_SIZE_CHECK; 589 phase = TP_SIZE_CHECK;
494 num_received = 0; 590 // num_received = 0;
495 num_sent = 0; 591 // num_sent_long = 0;
496 avg_latency = 0; 592 avg_latency = 0;
497 size_test (NULL); 593 size_test (NULL);
498 } 594 }
@@ -505,25 +601,29 @@ incoming_message_cb (void *cls,
505 GNUNET_assert (TP_SIZE_CHECK == phase); 601 GNUNET_assert (TP_SIZE_CHECK == phase);
506 if (LONG_MESSAGE_SIZE != long_message_size) 602 if (LONG_MESSAGE_SIZE != long_message_size)
507 max_size = long_message_size; 603 max_size = long_message_size;
508 num_received++; 604 num_received_size++;
509 update_avg_latency (payload); 605 update_avg_latency (payload);
510 if (num_received >= (max_size) / 10) 606 if (num_received_size >= (max_size) / 10)
511 { 607 {
512 LOG (GNUNET_ERROR_TYPE_MESSAGE, 608 LOG (GNUNET_ERROR_TYPE_MESSAGE,
513 "Size packet test done.\n"); 609 "Size packet test done.\n");
514 LOG (GNUNET_ERROR_TYPE_MESSAGE, 610 LOG (GNUNET_ERROR_TYPE_MESSAGE,
515 "%lu/%lu packets -- avg latency: %llu us\n", 611 "%lu/%lu packets -- avg latency: %llu us\n",
516 (unsigned long) num_received, 612 (unsigned long) num_received_size,
517 (unsigned long) num_sent, 613 (unsigned long) num_sent_size,
518 (unsigned long long) avg_latency); 614 (unsigned long long) avg_latency);
519 num_received = 0; 615 num_received_size = 0;
520 num_sent = 0; 616 num_sent_size = 0;
521 avg_latency = 0; 617 avg_latency = 0;
522 iterations_left--; 618 iterations_left--;
523 if (0 != iterations_left) 619 if (0 != iterations_left)
524 { 620 {
525 start_short = GNUNET_TIME_absolute_get (); 621 start_short = GNUNET_TIME_absolute_get ();
526 phase = TP_BURST_SHORT; 622 phase = TP_BURST_SHORT;
623 num_sent_short = 0;
624 num_sent_long = 0;
625 num_received_short = 0;
626 num_received_long = 0;
527 short_test (NULL); 627 short_test (NULL);
528 break; 628 break;
529 } 629 }
@@ -561,8 +661,8 @@ static void
561run (void *cls) 661run (void *cls)
562{ 662{
563 ret = 0; 663 ret = 0;
564 num_received = 0; 664 // num_received = 0;
565 num_sent = 0; 665 // num_sent = 0;
566 for (unsigned int i = 0; i < NUM_PEERS; i++) 666 for (unsigned int i = 0; i < NUM_PEERS; i++)
567 { 667 {
568 tc_hs[i] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( 668 tc_hs[i] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (