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