aboutsummaryrefslogtreecommitdiff
path: root/src/rps/test_rps.c
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2018-03-05 18:33:28 +0100
committerJulius Bünger <buenger@mytum.de>2018-03-05 18:34:36 +0100
commit31c1856767dbf20d04520f9091e0ae80780de7c7 (patch)
treede1e3474f3471ff812009c771a1400953b1f4faa /src/rps/test_rps.c
parente1534af8705146a702e69f836969b6e8a9e6d495 (diff)
downloadgnunet-31c1856767dbf20d04520f9091e0ae80780de7c7.tar.gz
gnunet-31c1856767dbf20d04520f9091e0ae80780de7c7.zip
rps profiler: get views from peers
Diffstat (limited to 'src/rps/test_rps.c')
-rw-r--r--src/rps/test_rps.c132
1 files changed, 131 insertions, 1 deletions
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c
index 4ef97ad92..e0f87652b 100644
--- a/src/rps/test_rps.c
+++ b/src/rps/test_rps.c
@@ -258,6 +258,16 @@ struct RPSPeer
258 * @brief File name of the file the stats are finally written to 258 * @brief File name of the file the stats are finally written to
259 */ 259 */
260 char *file_name_stats; 260 char *file_name_stats;
261
262 /**
263 * @brief The current view
264 */
265 struct GNUNET_PeerIdentity *cur_view;
266
267 /**
268 * @brief Number of peers in the #cur_view.
269 */
270 uint32_t cur_view_count;
261}; 271};
262 272
263enum STAT_TYPE 273enum STAT_TYPE
@@ -419,6 +429,21 @@ enum OPTION_COLLECT_STATISTICS {
419}; 429};
420 430
421/** 431/**
432 * @brief Do we collect views during run?
433 */
434enum OPTION_COLLECT_VIEW {
435 /**
436 * @brief We collect view during run
437 */
438 COLLECT_VIEW,
439
440 /**
441 * @brief We do not collect the view during run
442 */
443 NO_COLLECT_VIEW,
444};
445
446/**
422 * Structure to define a single test 447 * Structure to define a single test
423 */ 448 */
424struct SingleTestRun 449struct SingleTestRun
@@ -484,6 +509,11 @@ struct SingleTestRun
484 enum OPTION_COLLECT_STATISTICS have_collect_statistics; 509 enum OPTION_COLLECT_STATISTICS have_collect_statistics;
485 510
486 /** 511 /**
512 * Collect view during run?
513 */
514 enum OPTION_COLLECT_VIEW have_collect_view;
515
516 /**
487 * @brief Mark which values from the statistics service to collect at the end 517 * @brief Mark which values from the statistics service to collect at the end
488 * of the run 518 * of the run
489 */ 519 */
@@ -1788,6 +1818,91 @@ store_stats_file_name (struct RPSPeer *rps_peer)
1788 rps_peer->file_name_stats = file_name; 1818 rps_peer->file_name_stats = file_name;
1789} 1819}
1790 1820
1821void compute_diversity ()
1822{
1823 uint32_t i, j, k;
1824 /* ith entry represents the numer of occurrences in other peer's views */
1825 uint32_t *count_peers = GNUNET_new_array (num_peers, uint32_t);
1826 uint32_t views_total_size;
1827 double expected;
1828 /* deviation from expected number of peers */
1829 double *deviation = GNUNET_new_array (num_peers, double);
1830
1831 views_total_size = 0;
1832 expected = 0;
1833
1834 /* For each peer count its representation in other peer's views*/
1835 for (i = 0; i < num_peers; i++) /* Peer to count */
1836 {
1837 views_total_size += rps_peers[i].cur_view_count;
1838 for (j = 0; j < num_peers; j++) /* Peer in which view is counted */
1839 {
1840 for (k = 0; k < rps_peers[j].cur_view_count; k++) /* entry in view */
1841 {
1842 if (0 == memcmp (rps_peers[i].peer_id,
1843 &rps_peers[j].cur_view[k],
1844 sizeof (struct GNUNET_PeerIdentity)))
1845 {
1846 count_peers[i]++;
1847 }
1848 }
1849 }
1850 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1851 "Counted representation of %" PRIu32 "th peer: %" PRIu32"\n",
1852 i,
1853 count_peers[i]);
1854 }
1855
1856 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1857 "size of all views combined: %" PRIu32 "\n",
1858 views_total_size);
1859 expected = ((double) 1/num_peers) * views_total_size;
1860 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1861 "Expected number of occurrences of each peer in all views: %f\n",
1862 expected);
1863 for (i = 0; i < num_peers; i++) /* Peer to count */
1864 {
1865 deviation[i] = expected - count_peers[i];
1866 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1867 "Deviation from expectation: %f\n", deviation[i]);
1868 }
1869 GNUNET_free (count_peers);
1870 GNUNET_free (deviation);
1871}
1872
1873void all_views_updated_cb ()
1874{
1875 compute_diversity ();
1876}
1877
1878void view_update_cb (void *cls,
1879 uint64_t num_peers,
1880 const struct GNUNET_PeerIdentity *peers)
1881{
1882 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1883 "View was updated (%" PRIu64 ")\n", num_peers);
1884 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
1885 for (int i = 0; i < num_peers; i++)
1886 {
1887 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1888 "\t%s\n", GNUNET_i2s (&peers[i]));
1889 }
1890 GNUNET_array_grow (rps_peer->cur_view,
1891 rps_peer->cur_view_count,
1892 num_peers);
1893 //*rps_peer->cur_view = *peers;
1894 memcpy (rps_peer->cur_view,
1895 peers,
1896 num_peers * sizeof (struct GNUNET_PeerIdentity));
1897 all_views_updated_cb();
1898}
1899
1900static void
1901pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
1902{
1903 GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer);
1904}
1905
1791/** 1906/**
1792 * Continuation called by #GNUNET_STATISTICS_get() functions. 1907 * Continuation called by #GNUNET_STATISTICS_get() functions.
1793 * 1908 *
@@ -2009,6 +2124,11 @@ run (void *cls,
2009 rps_peers[i].index = i; 2124 rps_peers[i].index = i;
2010 if (NULL != cur_test_run.init_peer) 2125 if (NULL != cur_test_run.init_peer)
2011 cur_test_run.init_peer (&rps_peers[i]); 2126 cur_test_run.init_peer (&rps_peers[i]);
2127 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view)
2128 {
2129 rps_peers->cur_view_count = 0;
2130 rps_peers->cur_view = NULL;
2131 }
2012 entry->op = GNUNET_TESTBED_peer_get_information (peers[i], 2132 entry->op = GNUNET_TESTBED_peer_get_information (peers[i],
2013 GNUNET_TESTBED_PIT_IDENTITY, 2133 GNUNET_TESTBED_PIT_IDENTITY,
2014 &info_cb, 2134 &info_cb,
@@ -2067,6 +2187,7 @@ main (int argc, char *argv[])
2067{ 2187{
2068 int ret_value; 2188 int ret_value;
2069 2189
2190 /* Defaults for tests */
2070 num_peers = 5; 2191 num_peers = 5;
2071 cur_test_run.name = "test-rps-default"; 2192 cur_test_run.name = "test-rps-default";
2072 cur_test_run.init_peer = default_init_peer; 2193 cur_test_run.init_peer = default_init_peer;
@@ -2077,6 +2198,7 @@ main (int argc, char *argv[])
2077 cur_test_run.have_churn = HAVE_CHURN; 2198 cur_test_run.have_churn = HAVE_CHURN;
2078 cur_test_run.have_collect_statistics = NO_COLLECT_STATISTICS; 2199 cur_test_run.have_collect_statistics = NO_COLLECT_STATISTICS;
2079 cur_test_run.stat_collect_flags = 0; 2200 cur_test_run.stat_collect_flags = 0;
2201 cur_test_run.have_collect_view = NO_COLLECT_VIEW;
2080 churn_task = NULL; 2202 churn_task = NULL;
2081 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); 2203 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30);
2082 2204
@@ -2190,7 +2312,8 @@ main (int argc, char *argv[])
2190 num_peers = 10; 2312 num_peers = 10;
2191 mal_type = 3; 2313 mal_type = 3;
2192 cur_test_run.init_peer = profiler_init_peer; 2314 cur_test_run.init_peer = profiler_init_peer;
2193 cur_test_run.pre_test = mal_pre; 2315 //cur_test_run.pre_test = mal_pre;
2316 cur_test_run.pre_test = pre_profiler;
2194 cur_test_run.main_test = profiler_cb; 2317 cur_test_run.main_test = profiler_cb;
2195 cur_test_run.reply_handle = profiler_reply_handle; 2318 cur_test_run.reply_handle = profiler_reply_handle;
2196 cur_test_run.eval_cb = profiler_eval; 2319 cur_test_run.eval_cb = profiler_eval;
@@ -2216,6 +2339,7 @@ main (int argc, char *argv[])
2216 STAT_TYPE_RECV_PUSH_SEND | 2339 STAT_TYPE_RECV_PUSH_SEND |
2217 STAT_TYPE_RECV_PULL_REQ | 2340 STAT_TYPE_RECV_PULL_REQ |
2218 STAT_TYPE_RECV_PULL_REP; 2341 STAT_TYPE_RECV_PULL_REP;
2342 cur_test_run.have_collect_view = COLLECT_VIEW;
2219 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300); 2343 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300);
2220 2344
2221 /* 'Clean' directory */ 2345 /* 'Clean' directory */
@@ -2249,6 +2373,12 @@ main (int argc, char *argv[])
2249 } 2373 }
2250 2374
2251 ret_value = cur_test_run.eval_cb(); 2375 ret_value = cur_test_run.eval_cb();
2376 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view)
2377 {
2378 GNUNET_array_grow (rps_peers->cur_view,
2379 rps_peers->cur_view_count,
2380 0);
2381 }
2252 GNUNET_free (rps_peers); 2382 GNUNET_free (rps_peers);
2253 GNUNET_free (rps_peer_ids); 2383 GNUNET_free (rps_peer_ids);
2254 GNUNET_CONTAINER_multipeermap_destroy (peer_map); 2384 GNUNET_CONTAINER_multipeermap_destroy (peer_map);