aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2015-01-09 18:04:37 +0000
committerBart Polot <bart@net.in.tum.de>2015-01-09 18:04:37 +0000
commit4877f43f09856435d99b8f34dcf9d965c3fca347 (patch)
tree7d11db0450f5ce9e39536cb5f8f324106a8141a6 /src/cadet
parent1aef5fe5b9b7a139ad5e56c228219623c055b4b5 (diff)
downloadgnunet-4877f43f09856435d99b8f34dcf9d965c3fca347.tar.gz
gnunet-4877f43f09856435d99b8f34dcf9d965c3fca347.zip
- refactor test, always gather stats
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/test_cadet.c206
1 files changed, 98 insertions, 108 deletions
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c
index 9b1e20b6c..e64b6c45b 100644
--- a/src/cadet/test_cadet.c
+++ b/src/cadet/test_cadet.c
@@ -33,7 +33,7 @@
33/** 33/**
34 * How namy messages to send 34 * How namy messages to send
35 */ 35 */
36#define TOTAL_PACKETS 40000 36#define TOTAL_PACKETS 20
37 37
38/** 38/**
39 * How long until we give up on connecting the peers? 39 * How long until we give up on connecting the peers?
@@ -43,7 +43,7 @@
43/** 43/**
44 * Time to wait for stuff that should be rather fast 44 * Time to wait for stuff that should be rather fast
45 */ 45 */
46#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) 46#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
47 47
48/** 48/**
49 * DIFFERENT TESTS TO RUN 49 * DIFFERENT TESTS TO RUN
@@ -261,7 +261,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
261/** 261/**
262 * Disconnect from cadet services af all peers, call shutdown. 262 * Disconnect from cadet services af all peers, call shutdown.
263 * 263 *
264 * @param cls Closure (unused). 264 * @param cls Closure (line number from which termination was requested).
265 * @param tc Task Context. 265 * @param tc Task Context.
266 */ 266 */
267static void 267static void
@@ -302,6 +302,92 @@ disconnect_cadet_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
302} 302}
303 303
304 304
305
306/**
307 * Stats callback. Finish the stats testbed operation and when all stats have
308 * been iterated, shutdown the test.
309 *
310 * @param cls Closure (line number from which termination was requested).
311 * @param op the operation that has been finished
312 * @param emsg error message in case the operation has failed; will be NULL if
313 * operation has executed successfully.
314 */
315static void
316stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
317{
318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "stats_cont for peer %u\n", cls);
319 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " KA sent: %u, KA received: %u\n",
320 ka_sent, ka_received);
321 if (KEEPALIVE == test && (ka_sent < 2 || ka_sent > ka_received + 1))
322 ok--;
323 GNUNET_TESTBED_operation_done (stats_op);
324
325 if (NULL != disconnect_task)
326 GNUNET_SCHEDULER_cancel (disconnect_task);
327 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, cls);
328
329}
330
331
332/**
333 * Process statistic values.
334 *
335 * @param cls closure (line number, unused)
336 * @param peer the peer the statistic belong to
337 * @param subsystem name of subsystem that created the statistic
338 * @param name the name of the datum
339 * @param value the current value
340 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
341 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
342 */
343static int
344stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer,
345 const char *subsystem, const char *name,
346 uint64_t value, int is_persistent)
347{
348 static const char *s_sent = "# keepalives sent";
349 static const char *s_recv = "# keepalives received";
350 uint32_t i;
351
352 i = GNUNET_TESTBED_get_index (peer);
353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u - %s [%s]: %llu\n",
354 i, subsystem, name, value);
355 if (0 == strncmp (s_sent, name, strlen (s_sent)) && 0 == i)
356 ka_sent = value;
357
358 if (0 == strncmp(s_recv, name, strlen (s_recv)) && peers_requested - 1 == i)
359 ka_received = value;
360
361 return GNUNET_OK;
362}
363
364
365/**
366 * Task to gather all statistics.
367 *
368 * @param cls Closure (NULL).
369 * @param tc Task Context.
370 */
371static void
372gather_stats_and_exit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
373{
374 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
375 return;
376
377 disconnect_task = NULL;
378 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "gathering statistics\n");
379 if (NULL != ch)
380 {
381 GNUNET_CADET_channel_destroy (ch);
382 ch = NULL;
383 }
384 stats_op = GNUNET_TESTBED_get_statistics (peers_running, testbed_peers,
385 "cadet", NULL,
386 stats_iterator, stats_cont, cls);
387}
388
389
390
305/** 391/**
306 * Abort test: schedule disconnect and shutdown immediately 392 * Abort test: schedule disconnect and shutdown immediately
307 * 393 *
@@ -313,6 +399,7 @@ abort_test (long line)
313 if (disconnect_task != NULL) 399 if (disconnect_task != NULL)
314 { 400 {
315 GNUNET_SCHEDULER_cancel (disconnect_task); 401 GNUNET_SCHEDULER_cancel (disconnect_task);
402 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Aborting test from %ld\n", line);
316 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, 403 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
317 (void *) line); 404 (void *) line);
318 } 405 }
@@ -473,14 +560,14 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel,
473 560
474 GNUNET_CADET_receive_done (channel); 561 GNUNET_CADET_receive_done (channel);
475 562
476 if ((ok % 20) == 0) 563 if ((ok % 10) == 0)
477 { 564 {
478 if (NULL != disconnect_task) 565 if (NULL != disconnect_task)
479 { 566 {
480 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " reschedule timeout\n"); 567 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " reschedule timeout\n");
481 GNUNET_SCHEDULER_cancel (disconnect_task); 568 GNUNET_SCHEDULER_cancel (disconnect_task);
482 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, 569 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
483 &disconnect_cadet_peers, 570 &gather_stats_and_exit,
484 (void *) __LINE__); 571 (void *) __LINE__);
485 } 572 }
486 } 573 }
@@ -574,100 +661,11 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel,
574 } 661 }
575 } 662 }
576 663
577 if (NULL != disconnect_task)
578 {
579 GNUNET_SCHEDULER_cancel (disconnect_task);
580 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
581 &disconnect_cadet_peers,
582 (void *) __LINE__);
583 }
584
585 return GNUNET_OK; 664 return GNUNET_OK;
586} 665}
587 666
588 667
589/** 668/**
590 * Stats callback. Finish the stats testbed operation and when all stats have
591 * been iterated, shutdown the test.
592 *
593 * @param cls closure
594 * @param op the operation that has been finished
595 * @param emsg error message in case the operation has failed; will be NULL if
596 * operation has executed successfully.
597 */
598static void
599stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
600{
601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "stats_cont for peer %u\n", cls);
602 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " KA sent: %u, KA received: %u\n",
603 ka_sent, ka_received);
604 if (ka_sent < 2 || ka_sent > ka_received + 1)
605 ok--;
606 GNUNET_TESTBED_operation_done (stats_op);
607
608 if (NULL != disconnect_task)
609 GNUNET_SCHEDULER_cancel (disconnect_task);
610 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
611 (void *) __LINE__);
612
613}
614
615
616/**
617 * Process statistic values.
618 *
619 * @param cls closure
620 * @param peer the peer the statistic belong to
621 * @param subsystem name of subsystem that created the statistic
622 * @param name the name of the datum
623 * @param value the current value
624 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
625 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
626 */
627static int
628stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer,
629 const char *subsystem, const char *name,
630 uint64_t value, int is_persistent)
631{
632 static const char *s_sent = "# keepalives sent";
633 static const char *s_recv = "# keepalives received";
634 uint32_t i;
635
636 i = GNUNET_TESTBED_get_index (peer);
637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u - %s [%s]: %llu\n",
638 i, subsystem, name, value);
639 if (0 == strncmp (s_sent, name, strlen (s_sent)) && 0 == i)
640 ka_sent = value;
641
642 if (0 == strncmp(s_recv, name, strlen (s_recv)) && peers_requested - 1 == i)
643 ka_received = value;
644
645 return GNUNET_OK;
646}
647
648
649/**
650 * Task check that keepalives were sent and received.
651 *
652 * @param cls Closure (NULL).
653 * @param tc Task Context.
654 */
655static void
656check_keepalives (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
657{
658 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
659 return;
660
661 disconnect_task = NULL;
662 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "check keepalives\n");
663 GNUNET_CADET_channel_destroy (ch);
664 stats_op = GNUNET_TESTBED_get_statistics (peers_running, testbed_peers,
665 "cadet", NULL,
666 stats_iterator, stats_cont, NULL);
667}
668
669
670/**
671 * Handlers, for diverse services 669 * Handlers, for diverse services
672 */ 670 */
673static struct GNUNET_CADET_MessageHandler handlers[] = { 671static struct GNUNET_CADET_MessageHandler handlers[] = {
@@ -709,17 +707,9 @@ incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
709 if (NULL != disconnect_task) 707 if (NULL != disconnect_task)
710 { 708 {
711 GNUNET_SCHEDULER_cancel (disconnect_task); 709 GNUNET_SCHEDULER_cancel (disconnect_task);
712 if (KEEPALIVE == test) 710 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
713 { 711 &gather_stats_and_exit,
714 struct GNUNET_TIME_Relative delay; 712 (void *) __LINE__);
715 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS , 5);
716 disconnect_task =
717 GNUNET_SCHEDULER_add_delayed (delay, &check_keepalives, NULL);
718 }
719 else
720 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
721 &disconnect_cadet_peers,
722 (void *) __LINE__);
723 } 713 }
724 714
725 return NULL; 715 return NULL;
@@ -765,7 +755,7 @@ channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel,
765 if (NULL != disconnect_task) 755 if (NULL != disconnect_task)
766 { 756 {
767 GNUNET_SCHEDULER_cancel (disconnect_task); 757 GNUNET_SCHEDULER_cancel (disconnect_task);
768 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, 758 disconnect_task = GNUNET_SCHEDULER_add_now (&gather_stats_and_exit,
769 (void *) __LINE__); 759 (void *) __LINE__);
770 } 760 }
771 761
@@ -779,7 +769,7 @@ channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel,
779 * Testcase continues when the root receives confirmation of connected peers, 769 * Testcase continues when the root receives confirmation of connected peers,
780 * on callback funtion ch. 770 * on callback funtion ch.
781 * 771 *
782 * @param cls Closure (unsued). 772 * @param cls Closure (unused).
783 * @param tc Task Context. 773 * @param tc Task Context.
784 */ 774 */
785static void 775static void
@@ -806,7 +796,7 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
806 ch = GNUNET_CADET_channel_create (h1, NULL, p_id[1], 1, flags); 796 ch = GNUNET_CADET_channel_create (h1, NULL, p_id[1], 1, flags);
807 797
808 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, 798 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
809 &disconnect_cadet_peers, 799 &gather_stats_and_exit,
810 (void *) __LINE__); 800 (void *) __LINE__);
811 if (KEEPALIVE == test) 801 if (KEEPALIVE == test)
812 return; /* Don't send any data. */ 802 return; /* Don't send any data. */