aboutsummaryrefslogtreecommitdiff
path: root/src/rps
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2018-01-15 18:13:39 +0100
committerJulius Bünger <buenger@mytum.de>2018-01-16 13:18:02 +0100
commit5441f24ab5327f576b941e8e1e14a00270690759 (patch)
tree19d0bc74f3ec43be5e8ea7683b47549143533826 /src/rps
parent7141b7243358344e865c4ce2c9692872fc9006cb (diff)
downloadgnunet-5441f24ab5327f576b941e8e1e14a00270690759.tar.gz
gnunet-5441f24ab5327f576b941e8e1e14a00270690759.zip
rps: start using statistics service
Diffstat (limited to 'src/rps')
-rw-r--r--src/rps/gnunet-service-rps.c21
-rw-r--r--src/rps/test_rps.c204
2 files changed, 223 insertions, 2 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index ec70075cf..877893ee8 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -29,6 +29,7 @@
29#include "gnunet_cadet_service.h" 29#include "gnunet_cadet_service.h"
30#include "gnunet_peerinfo_service.h" 30#include "gnunet_peerinfo_service.h"
31#include "gnunet_nse_service.h" 31#include "gnunet_nse_service.h"
32#include "gnunet_statistics_service.h"
32#include "rps.h" 33#include "rps.h"
33#include "rps-test_util.h" 34#include "rps-test_util.h"
34#include "gnunet-service-rps_sampler.h" 35#include "gnunet-service-rps_sampler.h"
@@ -60,6 +61,11 @@
60static const struct GNUNET_CONFIGURATION_Handle *cfg; 61static const struct GNUNET_CONFIGURATION_Handle *cfg;
61 62
62/** 63/**
64 * Handle to the statistics service.
65 */
66static struct GNUNET_STATISTICS_Handle *stats;
67
68/**
63 * Our own identity. 69 * Our own identity.
64 */ 70 */
65static struct GNUNET_PeerIdentity own_identity; 71static struct GNUNET_PeerIdentity own_identity;
@@ -2390,6 +2396,7 @@ send_pull_reply (const struct GNUNET_PeerIdentity *peer_id,
2390 send_size * sizeof (struct GNUNET_PeerIdentity)); 2396 send_size * sizeof (struct GNUNET_PeerIdentity));
2391 2397
2392 Peers_send_message (peer_id, ev, "PULL REPLY"); 2398 Peers_send_message (peer_id, ev, "PULL REPLY");
2399 GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO);
2393} 2400}
2394 2401
2395 2402
@@ -2961,6 +2968,7 @@ handle_peer_push (void *cls,
2961 LOG (GNUNET_ERROR_TYPE_DEBUG, 2968 LOG (GNUNET_ERROR_TYPE_DEBUG,
2962 "Received PUSH (%s)\n", 2969 "Received PUSH (%s)\n",
2963 GNUNET_i2s (peer)); 2970 GNUNET_i2s (peer));
2971 GNUNET_STATISTICS_update(stats, "# push messages received", 1, GNUNET_NO);
2964 2972
2965 #ifdef ENABLE_MALICIOUS 2973 #ifdef ENABLE_MALICIOUS
2966 struct AttackedPeer *tmp_att_peer; 2974 struct AttackedPeer *tmp_att_peer;
@@ -3013,6 +3021,7 @@ handle_peer_pull_request (void *cls,
3013 const struct GNUNET_PeerIdentity *view_array; 3021 const struct GNUNET_PeerIdentity *view_array;
3014 3022
3015 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer)); 3023 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer));
3024 GNUNET_STATISTICS_update(stats, "# pull request messages received", 1, GNUNET_NO);
3016 3025
3017 #ifdef ENABLE_MALICIOUS 3026 #ifdef ENABLE_MALICIOUS
3018 if (1 == mal_type 3027 if (1 == mal_type
@@ -3096,6 +3105,7 @@ handle_peer_pull_reply (void *cls,
3096#endif /* ENABLE_MALICIOUS */ 3105#endif /* ENABLE_MALICIOUS */
3097 3106
3098 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REPLY (%s)\n", GNUNET_i2s (sender)); 3107 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REPLY (%s)\n", GNUNET_i2s (sender));
3108 GNUNET_STATISTICS_update(stats, "# pull reply messages received", 1, GNUNET_NO);
3099 3109
3100 #ifdef ENABLE_MALICIOUS 3110 #ifdef ENABLE_MALICIOUS
3101 // We shouldn't even receive pull replies as we're not sending 3111 // We shouldn't even receive pull replies as we're not sending
@@ -3234,6 +3244,7 @@ send_pull_request (const struct GNUNET_PeerIdentity *peer)
3234 3244
3235 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); 3245 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST);
3236 Peers_send_message (peer, ev, "PULL REQUEST"); 3246 Peers_send_message (peer, ev, "PULL REQUEST");
3247 GNUNET_STATISTICS_update(stats, "# pull request send issued", 1, GNUNET_NO);
3237} 3248}
3238 3249
3239 3250
@@ -3253,6 +3264,7 @@ send_push (const struct GNUNET_PeerIdentity *peer_id)
3253 3264
3254 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); 3265 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH);
3255 Peers_send_message (peer_id, ev, "PUSH"); 3266 Peers_send_message (peer_id, ev, "PUSH");
3267 GNUNET_STATISTICS_update(stats, "# push send issued", 1, GNUNET_NO);
3256} 3268}
3257 3269
3258 3270
@@ -3554,6 +3566,7 @@ do_round (void *cls)
3554 3566
3555 LOG (GNUNET_ERROR_TYPE_DEBUG, 3567 LOG (GNUNET_ERROR_TYPE_DEBUG,
3556 "Going to execute next round.\n"); 3568 "Going to execute next round.\n");
3569 GNUNET_STATISTICS_update(stats, "# rounds", 1, GNUNET_NO);
3557 do_round_task = NULL; 3570 do_round_task = NULL;
3558 LOG (GNUNET_ERROR_TYPE_DEBUG, 3571 LOG (GNUNET_ERROR_TYPE_DEBUG,
3559 "Printing view:\n"); 3572 "Printing view:\n");
@@ -3706,6 +3719,7 @@ do_round (void *cls)
3706 else 3719 else
3707 { 3720 {
3708 LOG (GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n"); 3721 LOG (GNUNET_ERROR_TYPE_DEBUG, "No update of the view.\n");
3722 GNUNET_STATISTICS_update(stats, "# rounds blocked", 1, GNUNET_NO);
3709 } 3723 }
3710 // TODO independent of that also get some peers from CADET_get_peers()? 3724 // TODO independent of that also get some peers from CADET_get_peers()?
3711 3725
@@ -3881,6 +3895,11 @@ shutdown_task (void *cls)
3881 View_destroy (); 3895 View_destroy ();
3882 CustomPeerMap_destroy (push_map); 3896 CustomPeerMap_destroy (push_map);
3883 CustomPeerMap_destroy (pull_map); 3897 CustomPeerMap_destroy (pull_map);
3898 if (NULL != stats)
3899 {
3900 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
3901 stats = NULL;
3902 }
3884 #ifdef ENABLE_MALICIOUS 3903 #ifdef ENABLE_MALICIOUS
3885 struct AttackedPeer *tmp_att_peer; 3904 struct AttackedPeer *tmp_att_peer;
3886 GNUNET_free (file_name_view_log); 3905 GNUNET_free (file_name_view_log);
@@ -4129,6 +4148,8 @@ run (void *cls,
4129 LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduled first round\n"); 4148 LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduled first round\n");
4130 4149
4131 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 4150 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
4151 stats = GNUNET_STATISTICS_create ("rps", cfg);
4152
4132} 4153}
4133 4154
4134 4155
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c
index 7d61ae6a1..c958194a8 100644
--- a/src/rps/test_rps.c
+++ b/src/rps/test_rps.c
@@ -41,6 +41,11 @@
41static uint32_t num_peers; 41static uint32_t num_peers;
42 42
43/** 43/**
44 * How many peers are ready to shutdown?
45 */
46static uint32_t num_shutdown_ready;
47
48/**
44 * How long do we run the test? 49 * How long do we run the test?
45 */ 50 */
46//#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 51//#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
@@ -236,6 +241,16 @@ struct RPSPeer
236 * Pending operation on that peer 241 * Pending operation on that peer
237 */ 242 */
238 const struct OpListEntry *entry_op_manage; 243 const struct OpListEntry *entry_op_manage;
244
245 /**
246 * Testbed operation to connect to statistics service
247 */
248 struct GNUNET_TESTBED_Operation *stat_op;
249
250 /**
251 * Handle to the statistics service
252 */
253 struct GNUNET_STATISTICS_Handle *stats_h;
239}; 254};
240 255
241 256
@@ -318,7 +333,7 @@ typedef void (*ReplyHandle) (void *cls,
318/** 333/**
319 * Called directly before disconnecting from the service 334 * Called directly before disconnecting from the service
320 */ 335 */
321typedef void (*PostTest) (void *cls, struct GNUNET_RPS_Handle *h); 336typedef void (*PostTest) (const struct RPSPeer *peer);
322 337
323/** 338/**
324 * Function called after disconnect to evaluate test success 339 * Function called after disconnect to evaluate test success
@@ -355,6 +370,21 @@ enum OPTION_QUICK_QUIT {
355}; 370};
356 371
357/** 372/**
373 * @brief Do we collect statistics at the end?
374 */
375enum OPTION_COLLECT_STATISTICS {
376 /**
377 * @brief We collect statistics at the end
378 */
379 COLLECT_STATISTICS,
380
381 /**
382 * @brief We do not collect statistics at the end
383 */
384 NO_COLLECT_STATISTICS,
385};
386
387/**
358 * Structure to define a single test 388 * Structure to define a single test
359 */ 389 */
360struct SingleTestRun 390struct SingleTestRun
@@ -413,6 +443,11 @@ struct SingleTestRun
413 * Quit test before timeout? 443 * Quit test before timeout?
414 */ 444 */
415 enum OPTION_QUICK_QUIT have_quick_quit; 445 enum OPTION_QUICK_QUIT have_quick_quit;
446
447 /**
448 * Collect statistics at the end?
449 */
450 enum OPTION_COLLECT_STATISTICS have_collect_statistics;
416} cur_test_run; 451} cur_test_run;
417 452
418/** 453/**
@@ -575,9 +610,21 @@ shutdown_op (void *cls)
575 churn_task = NULL; 610 churn_task = NULL;
576 } 611 }
577 for (i = 0; i < num_peers; i++) 612 for (i = 0; i < num_peers; i++)
613 {
578 if (NULL != rps_peers[i].op) 614 if (NULL != rps_peers[i].op)
579 GNUNET_TESTBED_operation_done (rps_peers[i].op); 615 GNUNET_TESTBED_operation_done (rps_peers[i].op);
580 GNUNET_SCHEDULER_shutdown (); 616 if (NULL != cur_test_run.post_test)
617 {
618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i);
619 cur_test_run.post_test (&rps_peers[i]);
620 }
621 }
622 /* If we do not collect statistics, shut down directly */
623 if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics ||
624 num_peers <= num_shutdown_ready)
625 {
626 GNUNET_SCHEDULER_shutdown ();
627 }
581} 628}
582 629
583 630
@@ -753,6 +800,76 @@ rps_connect_adapter (void *cls,
753 return h; 800 return h;
754} 801}
755 802
803/**
804 * Called to open a connection to the peer's statistics
805 *
806 * @param cls peer context
807 * @param cfg configuration of the peer to connect to; will be available until
808 * GNUNET_TESTBED_operation_done() is called on the operation returned
809 * from GNUNET_TESTBED_service_connect()
810 * @return service handle to return in 'op_result', NULL on error
811 */
812static void *
813stat_connect_adapter (void *cls,
814 const struct GNUNET_CONFIGURATION_Handle *cfg)
815{
816 struct RPSPeer *peer = cls;
817
818 peer->stats_h = GNUNET_STATISTICS_create ("rps-profiler", cfg);
819 return peer->stats_h;
820}
821
822/**
823 * Called to disconnect from peer's statistics service
824 *
825 * @param cls peer context
826 * @param op_result service handle returned from the connect adapter
827 */
828static void
829stat_disconnect_adapter (void *cls, void *op_result)
830{
831 struct RPSPeer *peer = cls;
832
833 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
834 // (peer->stats_h, "core", "# peers connected",
835 // stat_iterator, peer));
836 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
837 // (peer->stats_h, "nse", "# peers connected",
838 // stat_iterator, peer));
839 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
840 peer->stats_h = NULL;
841}
842
843/**
844 * Called after successfully opening a connection to a peer's statistics
845 * service; we register statistics monitoring for CORE and NSE here.
846 *
847 * @param cls the callback closure from functions generating an operation
848 * @param op the operation that has been finished
849 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
850 * @param emsg error message in case the operation has failed; will be NULL if
851 * operation has executed successfully.
852 */
853static void
854stat_complete_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
855 void *ca_result, const char *emsg )
856{
857 //struct GNUNET_STATISTICS_Handle *sh = ca_result;
858 //struct RPSPeer *peer = (struct RPSPeer *) cls;
859
860 if (NULL != emsg)
861 {
862 GNUNET_break (0);
863 return;
864 }
865 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
866 // (sh, "core", "# peers connected",
867 // stat_iterator, peer));
868 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
869 // (sh, "nse", "# peers connected",
870 // stat_iterator, peer));
871}
872
756 873
757/** 874/**
758 * Adapter function called to destroy connection to 875 * Adapter function called to destroy connection to
@@ -1541,6 +1658,71 @@ profiler_eval (void)
1541 return evaluate (); 1658 return evaluate ();
1542} 1659}
1543 1660
1661/**
1662 * Continuation called by #GNUNET_STATISTICS_get() functions.
1663 *
1664 * Checks whether all peers received their statistics yet.
1665 * Issues the shutdown.
1666 *
1667 * @param cls closure
1668 * @param success #GNUNET_OK if statistics were
1669 * successfully obtained, #GNUNET_SYSERR if not.
1670 */
1671void
1672post_test_shutdown_ready_cb (void *cls,
1673 int success)
1674{
1675 const struct RPSPeer *rps_peer = (const struct RPSPeer *) cls;
1676 if (NULL != rps_peer->stat_op)
1677 {
1678 GNUNET_TESTBED_operation_done (rps_peer->stat_op);
1679 }
1680 num_shutdown_ready++;
1681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1682 "%" PRIu32 " of %" PRIu32 " Peers are ready to shut down\n",
1683 num_shutdown_ready,
1684 num_peers);
1685 if (num_peers <= num_shutdown_ready)
1686 {
1687 GNUNET_SCHEDULER_shutdown ();
1688 }
1689}
1690
1691/**
1692 * Callback function to process statistic values.
1693 *
1694 * @param cls closure
1695 * @param subsystem name of subsystem that created the statistic
1696 * @param name the name of the datum
1697 * @param value the current value
1698 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
1699 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
1700 */
1701int
1702stat_iterator (void *cls,
1703 const char *subsystem,
1704 const char *name,
1705 uint64_t value,
1706 int is_persistent)
1707{
1708 //const struct RPSPeer *rps_peer = (const struct RPSPeer *) cls;
1709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %" PRIu64 "\n", value);
1710 return GNUNET_OK;
1711}
1712
1713void post_profiler (const struct RPSPeer *rps_peer)
1714{
1715 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics)
1716 {
1717 GNUNET_STATISTICS_get (rps_peer->stats_h,
1718 "rps",
1719 "# rounds",
1720 post_test_shutdown_ready_cb,
1721 stat_iterator,
1722 (struct RPSPeer *) rps_peer);
1723 }
1724}
1725
1544 1726
1545/*********************************************************************** 1727/***********************************************************************
1546 * /Definition of tests 1728 * /Definition of tests
@@ -1623,6 +1805,19 @@ run (void *cls,
1623 &rps_disconnect_adapter, 1805 &rps_disconnect_adapter,
1624 &rps_peers[i]); 1806 &rps_peers[i]);
1625 } 1807 }
1808 /* Connect all peers to statistics service */
1809 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics)
1810 {
1811 rps_peers[i].stat_op =
1812 GNUNET_TESTBED_service_connect (NULL,
1813 peers[i],
1814 "statistics",
1815 stat_complete_cb,
1816 &rps_peers[i],
1817 &stat_connect_adapter,
1818 &stat_disconnect_adapter,
1819 &rps_peers[i]);
1820 }
1626 } 1821 }
1627 1822
1628 if (NULL != churn_task) 1823 if (NULL != churn_task)
@@ -1644,12 +1839,15 @@ main (int argc, char *argv[])
1644 int ret_value; 1839 int ret_value;
1645 1840
1646 num_peers = 5; 1841 num_peers = 5;
1842 num_shutdown_ready = 0;
1647 cur_test_run.name = "test-rps-default"; 1843 cur_test_run.name = "test-rps-default";
1648 cur_test_run.init_peer = default_init_peer; 1844 cur_test_run.init_peer = default_init_peer;
1649 cur_test_run.pre_test = NULL; 1845 cur_test_run.pre_test = NULL;
1650 cur_test_run.reply_handle = default_reply_handle; 1846 cur_test_run.reply_handle = default_reply_handle;
1651 cur_test_run.eval_cb = default_eval_cb; 1847 cur_test_run.eval_cb = default_eval_cb;
1848 cur_test_run.post_test = NULL;
1652 cur_test_run.have_churn = HAVE_CHURN; 1849 cur_test_run.have_churn = HAVE_CHURN;
1850 cur_test_run.have_collect_statistics = NO_COLLECT_STATISTICS;
1653 churn_task = NULL; 1851 churn_task = NULL;
1654 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); 1852 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
1655 1853
@@ -1767,10 +1965,12 @@ main (int argc, char *argv[])
1767 cur_test_run.main_test = profiler_cb; 1965 cur_test_run.main_test = profiler_cb;
1768 cur_test_run.reply_handle = profiler_reply_handle; 1966 cur_test_run.reply_handle = profiler_reply_handle;
1769 cur_test_run.eval_cb = profiler_eval; 1967 cur_test_run.eval_cb = profiler_eval;
1968 cur_test_run.post_test = post_profiler;
1770 cur_test_run.request_interval = 2; 1969 cur_test_run.request_interval = 2;
1771 cur_test_run.num_requests = 5; 1970 cur_test_run.num_requests = 5;
1772 cur_test_run.have_churn = HAVE_CHURN; 1971 cur_test_run.have_churn = HAVE_CHURN;
1773 cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; 1972 cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT;
1973 cur_test_run.have_collect_statistics = COLLECT_STATISTICS;
1774 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300); 1974 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300);
1775 1975
1776 /* 'Clean' directory */ 1976 /* 'Clean' directory */