2 This file is part of GNUnet.
3 Copyright (C) 2009, 2012 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @file rps/test_rps.c
20 * @brief Testcase for the random peer sampling service. Starts
21 * a peergroup with a given number of peers, then waits to
22 * receive size pushes/pulls from each peer. Expects to wait
23 * for one message from each peer.
26 //#include "rps_test_lib.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_testbed_service.h"
30 #include "gnunet_rps_service.h"
31 #include "rps-test_util.h"
32 #include "gnunet-service-rps_sampler_elem.h"
37 #define BIT(n) (1 << (n))
40 * How many peers do we start?
42 static uint32_t num_peers;
45 * @brief numer of bits required to represent the largest peer id
47 static unsigned bits_needed;
50 * How long do we run the test?
52 static struct GNUNET_TIME_Relative duration;
55 * When do we do a hard shutdown?
57 static struct GNUNET_TIME_Relative timeout;
61 * Portion of malicious peers
63 static double portion = .1;
66 * Type of malicious peer to test
68 static unsigned int mal_type = 0;
71 * Handles to all of the running peers
73 static struct GNUNET_TESTBED_Peer **testbed_peers;
77 STAT_TYPE_ROUNDS, /* 0 */
78 STAT_TYPE_BLOCKS, /* 1 */
79 STAT_TYPE_BLOCKS_MANY_PUSH, /* 2 */
80 STAT_TYPE_BLOCKS_NO_PUSH, /* 3 */
81 STAT_TYPE_BLOCKS_NO_PULL, /* 4 */
82 STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL, /* 5 */
83 STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL, /* 6 */
84 STAT_TYPE_ISSUED_PUSH_SEND, /* 7 */
85 STAT_TYPE_ISSUED_PULL_REQ, /* 8 */
86 STAT_TYPE_ISSUED_PULL_REP, /* 9 */
87 STAT_TYPE_SENT_PUSH_SEND, /* 10 */
88 STAT_TYPE_SENT_PULL_REQ, /* 11 */
89 STAT_TYPE_SENT_PULL_REP, /* 12 */
90 STAT_TYPE_RECV_PUSH_SEND, /* 13 */
91 STAT_TYPE_RECV_PULL_REQ, /* 14 */
92 STAT_TYPE_RECV_PULL_REP, /* 15 */
93 STAT_TYPE_MAX, /* 16 */
96 static char* stat_type_strings[] = {
99 "# rounds blocked - too many pushes",
100 "# rounds blocked - no pushes",
101 "# rounds blocked - no pull replies",
102 "# rounds blocked - too many pushes, no pull replies",
103 "# rounds blocked - no pushes, no pull replies",
104 "# push send issued",
105 "# pull request send issued",
106 "# pull reply send issued",
108 "# pull requests sent",
109 "# pull replys sent",
110 "# push message received",
111 "# pull request message received",
112 "# pull reply messages received",
117 struct RPSPeer *rps_peer;
118 enum STAT_TYPE stat_type;
123 * @brief Converts string representation to the corresponding #STAT_TYPE enum.
125 * @param stat_str string representation of statistics specifier
127 * @return corresponding enum
129 enum STAT_TYPE stat_str_2_type (const char *stat_str)
131 if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL],
133 strlen (stat_type_strings[STAT_TYPE_BLOCKS_NO_PULL])))
135 return STAT_TYPE_BLOCKS_NO_PULL;
137 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL],
139 strlen (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL])))
141 return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL;
143 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH],
145 strlen (stat_type_strings[STAT_TYPE_BLOCKS_MANY_PUSH])))
147 return STAT_TYPE_BLOCKS_MANY_PUSH;
149 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL],
151 strlen (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL])))
153 return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL;
155 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH],
157 strlen (stat_type_strings[STAT_TYPE_BLOCKS_NO_PUSH])))
159 return STAT_TYPE_BLOCKS_NO_PUSH;
161 else if (0 == strncmp (stat_type_strings[STAT_TYPE_BLOCKS],
163 strlen (stat_type_strings[STAT_TYPE_BLOCKS])))
165 return STAT_TYPE_BLOCKS;
167 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ROUNDS],
169 strlen (stat_type_strings[STAT_TYPE_ROUNDS])))
171 return STAT_TYPE_ROUNDS;
173 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND],
175 strlen (stat_type_strings[STAT_TYPE_ISSUED_PUSH_SEND])))
177 return STAT_TYPE_ISSUED_PUSH_SEND;
179 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ],
181 strlen (stat_type_strings[STAT_TYPE_ISSUED_PULL_REQ])))
183 return STAT_TYPE_ISSUED_PULL_REQ;
185 else if (0 == strncmp (stat_type_strings[STAT_TYPE_ISSUED_PULL_REP],
187 strlen (stat_type_strings[STAT_TYPE_ISSUED_PULL_REP])))
189 return STAT_TYPE_ISSUED_PULL_REP;
191 else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PUSH_SEND],
193 strlen (stat_type_strings[STAT_TYPE_SENT_PUSH_SEND])))
195 return STAT_TYPE_SENT_PUSH_SEND;
197 else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PULL_REQ],
199 strlen (stat_type_strings[STAT_TYPE_SENT_PULL_REQ])))
201 return STAT_TYPE_SENT_PULL_REQ;
203 else if (0 == strncmp (stat_type_strings[STAT_TYPE_SENT_PULL_REP],
205 strlen (stat_type_strings[STAT_TYPE_SENT_PULL_REP])))
207 return STAT_TYPE_SENT_PULL_REP;
209 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND],
211 strlen (stat_type_strings[STAT_TYPE_RECV_PUSH_SEND])))
213 return STAT_TYPE_RECV_PUSH_SEND;
215 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REQ],
217 strlen (stat_type_strings[STAT_TYPE_RECV_PULL_REQ])))
219 return STAT_TYPE_RECV_PULL_REQ;
221 else if (0 == strncmp (stat_type_strings[STAT_TYPE_RECV_PULL_REP],
223 strlen (stat_type_strings[STAT_TYPE_RECV_PULL_REP])))
225 return STAT_TYPE_RECV_PULL_REP;
227 return STAT_TYPE_MAX;
232 * @brief Indicates whether peer should go off- or online
234 enum PEER_ONLINE_DELTA {
236 * @brief Indicates peer going online
240 * @brief Indicates peer going offline
242 PEER_GO_OFFLINE = -1,
246 * Operation map entry
253 struct OpListEntry *next;
258 struct OpListEntry *prev;
261 * The testbed operation
263 struct GNUNET_TESTBED_Operation *op;
266 * Depending on whether we start or stop RPS service at the peer, set this to
267 * #PEER_GO_ONLINE (1) or #PEER_GO_OFFLINE (-1)
269 enum PEER_ONLINE_DELTA delta;
272 * Index of the regarding peer
280 static struct OpListEntry *oplist_head;
285 static struct OpListEntry *oplist_tail;
289 * A pending reply: A request was sent and the reply is pending.
296 struct PendingReply *next;
297 struct PendingReply *prev;
300 * Handle to the request we are waiting for
302 struct GNUNET_RPS_Request_Handle *req_handle;
305 * The peer that requested
307 struct RPSPeer *rps_peer;
312 * A pending request: A request was not made yet but is scheduled for later.
314 struct PendingRequest
319 struct PendingRequest *next;
320 struct PendingRequest *prev;
323 * Handle to the request we are waiting for
325 struct GNUNET_SCHEDULER_Task *request_task;
328 * The peer that requested
330 struct RPSPeer *rps_peer;
335 * Information we track for each peer.
345 * Handle for RPS connect operation.
347 struct GNUNET_TESTBED_Operation *op;
350 * Handle to RPS service.
352 struct GNUNET_RPS_Handle *rps_handle;
357 struct GNUNET_PeerIdentity *peer_id;
360 * A request handle to check for an request
362 //struct GNUNET_RPS_Request_Handle *req_handle;
365 * Peer on- or offline?
370 * Number of Peer IDs to request during the whole test
372 unsigned int num_ids_to_request;
375 * Pending requests DLL
377 struct PendingRequest *pending_req_head;
378 struct PendingRequest *pending_req_tail;
381 * Number of pending requests
383 unsigned int num_pending_reqs;
386 * Pending replies DLL
388 struct PendingReply *pending_rep_head;
389 struct PendingReply *pending_rep_tail;
392 * Number of pending replies
394 unsigned int num_pending_reps;
397 * Number of received PeerIDs
399 unsigned int num_recv_ids;
402 * Pending operation on that peer
404 const struct OpListEntry *entry_op_manage;
407 * Testbed operation to connect to statistics service
409 struct GNUNET_TESTBED_Operation *stat_op;
412 * Handle to the statistics service
414 struct GNUNET_STATISTICS_Handle *stats_h;
417 * @brief flags to indicate which statistics values have been already
418 * collected from the statistics service.
419 * Used to check whether we are able to shutdown.
421 uint32_t stat_collected_flags;
424 * @brief File name of the file the stats are finally written to
426 const char *file_name_stats;
429 * @brief File name of the file the stats are finally written to
431 const char *file_name_probs;
434 * @brief The current view
436 struct GNUNET_PeerIdentity *cur_view;
439 * @brief Number of peers in the #cur_view.
441 uint32_t cur_view_count;
444 * @brief Number of occurrences in other peer's view
446 uint32_t count_in_views;
449 * @brief statistics values
451 uint64_t stats[STAT_TYPE_MAX];
453 * @brief Handle for the statistics get request
455 struct GNUNET_STATISTICS_GetHandle *h_stat_get[STAT_TYPE_MAX];
459 * Information for all the peers.
461 static struct RPSPeer *rps_peers;
464 * Peermap to get the index of a given peer ID quick.
466 static struct GNUNET_CONTAINER_MultiPeerMap *peer_map;
471 static struct GNUNET_PeerIdentity *rps_peer_ids;
474 * ID of the targeted peer.
476 static struct GNUNET_PeerIdentity *target_peer;
479 * Number of online peers.
481 static unsigned int num_peers_online;
484 * @brief The added sizes of the peer's views
486 static unsigned int view_sizes;
489 * Return value from 'main'.
494 * Identifier for the task that runs after the test to collect results
496 static struct GNUNET_SCHEDULER_Task *post_test_task;
499 * Identifier for the shutdown task
501 static struct GNUNET_SCHEDULER_Task *shutdown_task;
505 * Identifier for the churn task that runs periodically
507 static struct GNUNET_SCHEDULER_Task *churn_task;
510 * Called to initialise the given RPSPeer
512 typedef void (*InitPeer) (struct RPSPeer *rps_peer);
515 * @brief Called directly after connecting to the service
517 * @param rps_peer Specific peer the function is called on
518 * @param h the handle to the rps service
520 typedef void (*PreTest) (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h);
523 * @brief Executes functions to test the api/service for a given peer
525 * Called from within #rps_connect_complete_cb ()
526 * Implemented by #churn_test_cb, #profiler_cb, #mal_cb, #single_req_cb,
527 * #delay_req_cb, #seed_big_cb, #single_peer_seed_cb, #seed_cb, #req_cancel_cb
529 * @param rps_peer the peer the task runs on
531 typedef void (*MainTest) (struct RPSPeer *rps_peer);
534 * Callback called once the requested random peers are available
536 typedef void (*ReplyHandle) (void *cls,
538 const struct GNUNET_PeerIdentity *recv_peers);
541 * Called directly before disconnecting from the service
543 typedef void (*PostTest) (struct RPSPeer *peer);
546 * Function called after disconnect to evaluate test success
548 typedef int (*EvaluationCallback) (void);
551 * @brief Do we have Churn?
555 * @brief If we have churn this is set
559 * @brief If we have no churn this is set
565 * @brief Is it ok to quit the test before the timeout?
567 enum OPTION_QUICK_QUIT {
569 * @brief It is ok for the test to quit before the timeout triggers
574 * @brief It is NOT ok for the test to quit before the timeout triggers
580 * @brief Do we collect statistics at the end?
582 enum OPTION_COLLECT_STATISTICS {
584 * @brief We collect statistics at the end
589 * @brief We do not collect statistics at the end
591 NO_COLLECT_STATISTICS,
595 * @brief Do we collect views during run?
597 enum OPTION_COLLECT_VIEW {
599 * @brief We collect view during run
604 * @brief We do not collect the view during run
610 * Structure to define a single test
620 * Called with a single peer in order to initialise that peer
625 * Called directly after connecting to the service
630 * Main function for each peer
635 * Callback called once the requested peers are available
637 ReplyHandle reply_handle;
640 * Called directly before disconnecting from the service
645 * Function to evaluate the test results
647 EvaluationCallback eval_cb;
652 uint32_t request_interval;
655 * Number of Requests to make.
657 uint32_t num_requests;
660 * Run with (-out) churn
662 enum OPTION_CHURN have_churn;
665 * Quit test before timeout?
667 enum OPTION_QUICK_QUIT have_quick_quit;
670 * Collect statistics at the end?
672 enum OPTION_COLLECT_STATISTICS have_collect_statistics;
675 * Collect view during run?
677 enum OPTION_COLLECT_VIEW have_collect_view;
680 * @brief Mark which values from the statistics service to collect at the end
683 uint32_t stat_collect_flags;
687 * Did we finish the test?
689 static int post_test;
692 * Are we shutting down?
694 static int in_shutdown;
697 * Append arguments to file
700 tofile_ (const char *file_name, const char *line)
702 struct GNUNET_DISK_FileHandle *f;
703 /* char output_buffer[512]; */
708 if (NULL == (f = GNUNET_DISK_file_open (file_name,
709 GNUNET_DISK_OPEN_APPEND |
710 GNUNET_DISK_OPEN_WRITE |
711 GNUNET_DISK_OPEN_CREATE,
712 GNUNET_DISK_PERM_USER_READ |
713 GNUNET_DISK_PERM_USER_WRITE |
714 GNUNET_DISK_PERM_GROUP_READ |
715 GNUNET_DISK_PERM_OTHER_READ)))
717 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
718 "Not able to open file %s\n",
722 /* size = GNUNET_snprintf (output_buffer,
723 sizeof (output_buffer),
725 GNUNET_TIME_absolute_get ().abs_value_us,
729 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
730 "Failed to write string to buffer (size: %i)\n",
735 size = strlen (line) * sizeof (char);
737 size2 = GNUNET_DISK_file_write (f, line, size);
740 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
741 "Unable to write to file! (Size: %lu, size2: %lu)\n",
744 if (GNUNET_YES != GNUNET_DISK_file_close (f))
746 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
747 "Unable to close file\n");
752 if (GNUNET_YES != GNUNET_DISK_file_close (f))
754 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
755 "Unable to close file\n");
760 * This function is used to facilitate writing important information to disk
762 #define tofile(file_name, ...) do {\
765 size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\
767 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\
768 "Failed to create tmp_buf\n");\
770 tofile_(file_name,tmp_buf);\
775 * Write the ids and their according index in the given array to a file
779 ids_to_file (char *file_name,
780 struct GNUNET_PeerIdentity *peer_ids,
781 unsigned int num_peer_ids)
785 for (i=0 ; i < num_peer_ids ; i++)
790 GNUNET_i2s_full (&peer_ids[i]));
795 * Test the success of a single test
805 for (i = 0; i < num_peers; i++)
807 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
808 "%u. peer [%s] received %u of %u expected peer_ids: %i\n",
810 GNUNET_i2s (rps_peers[i].peer_id),
811 rps_peers[i].num_recv_ids,
812 rps_peers[i].num_ids_to_request,
813 (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids));
814 tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids);
816 return tmp_ok? 0 : 1;
821 * Creates an oplist entry and adds it to the oplist DLL
823 static struct OpListEntry *
826 struct OpListEntry *entry;
828 entry = GNUNET_new (struct OpListEntry);
829 GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
835 * @brief Checks if given peer already received its statistics value from the
836 * statistics service.
838 * @param rps_peer the peer to check for
840 * @return #GNUNET_YES if so
841 * #GNUNET_NO otherwise
843 static int check_statistics_collect_completed_single_peer (
844 const struct RPSPeer *rps_peer)
846 if (cur_test_run.stat_collect_flags !=
847 (cur_test_run.stat_collect_flags &
848 rps_peer->stat_collected_flags))
855 * @brief Checks if all peers already received their statistics value from the
856 * statistics service.
858 * @return #GNUNET_YES if so
859 * #GNUNET_NO otherwise
861 static int check_statistics_collect_completed ()
865 for (i = 0; i < num_peers; i++)
867 if (GNUNET_NO == check_statistics_collect_completed_single_peer (&rps_peers[i]))
869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
870 "At least Peer %" PRIu32 " did not yet receive all statistics values\n",
875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
876 "All peers received their statistics values\n");
881 rps_disconnect_adapter (void *cls,
885 cancel_pending_req (struct PendingRequest *pending_req)
887 struct RPSPeer *rps_peer;
889 rps_peer = pending_req->rps_peer;
890 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
891 rps_peer->pending_req_tail,
893 rps_peer->num_pending_reqs--;
894 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
895 "Cancelling pending rps get request\n");
896 GNUNET_SCHEDULER_cancel (pending_req->request_task);
897 GNUNET_free (pending_req);
901 cancel_request (struct PendingReply *pending_rep)
903 struct RPSPeer *rps_peer;
905 rps_peer = pending_rep->rps_peer;
906 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
907 rps_peer->pending_rep_tail,
909 rps_peer->num_pending_reps--;
910 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
911 "Cancelling rps get reply\n");
912 GNUNET_RPS_request_cancel (pending_rep->req_handle);
913 GNUNET_free (pending_rep);
917 clean_peer (unsigned peer_index)
919 struct PendingRequest *pending_req;
921 while (NULL != (pending_req = rps_peers[peer_index].pending_req_head))
923 cancel_pending_req (pending_req);
925 pending_req = rps_peers[peer_index].pending_req_head;
926 rps_disconnect_adapter (&rps_peers[peer_index],
927 &rps_peers[peer_index].rps_handle);
928 for (unsigned stat_type = STAT_TYPE_ROUNDS;
929 stat_type < STAT_TYPE_MAX;
932 if (NULL != rps_peers[peer_index].h_stat_get[stat_type])
934 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
935 "(%u) did not yet receive stat value for `%s'\n",
936 rps_peers[peer_index].index,
937 stat_type_strings[stat_type]);
938 GNUNET_STATISTICS_get_cancel (
939 rps_peers[peer_index].h_stat_get[stat_type]);
942 if (NULL != rps_peers[peer_index].op)
944 GNUNET_TESTBED_operation_done (rps_peers[peer_index].op);
945 rps_peers[peer_index].op = NULL;
950 * Task run on timeout to shut everything down.
953 shutdown_op (void *cls)
956 struct OpListEntry *entry;
959 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
960 "Shutdown task scheduled, going down.\n");
961 in_shutdown = GNUNET_YES;
963 if (NULL != shutdown_task)
965 GNUNET_SCHEDULER_cancel (shutdown_task);
966 shutdown_task = NULL;
968 if (NULL != post_test_task)
970 GNUNET_SCHEDULER_cancel (post_test_task);
971 post_test_task = NULL;
973 if (NULL != churn_task)
975 GNUNET_SCHEDULER_cancel (churn_task);
979 while (NULL != (entry = oplist_head))
981 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
982 "Operation still pending on shutdown (%u)\n",
984 GNUNET_TESTBED_operation_done (entry->op);
985 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
988 for (i = 0; i < num_peers; i++)
995 trigger_shutdown (void *cls)
999 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1000 "Shutdown was triggerd by timeout, going down.\n");
1001 shutdown_task = NULL;
1002 GNUNET_SCHEDULER_shutdown ();
1007 * Task run after #duration to collect statistics and potentially shut down.
1010 post_test_op (void *cls)
1015 post_test_task = NULL;
1016 post_test = GNUNET_YES;
1017 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1018 "Post test task scheduled.\n");
1019 if (NULL != churn_task)
1021 GNUNET_SCHEDULER_cancel (churn_task);
1024 for (i = 0; i < num_peers; i++)
1026 if (NULL != rps_peers[i].op)
1028 GNUNET_TESTBED_operation_done (rps_peers[i].op);
1029 rps_peers[i].op = NULL;
1031 if (NULL != cur_test_run.post_test)
1033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i);
1034 cur_test_run.post_test (&rps_peers[i]);
1037 /* If we do not collect statistics, shut down directly */
1038 if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics ||
1039 GNUNET_YES == check_statistics_collect_completed())
1041 GNUNET_SCHEDULER_cancel (shutdown_task);
1042 shutdown_task = NULL;
1043 GNUNET_SCHEDULER_shutdown ();
1052 seed_peers (void *cls)
1054 struct RPSPeer *peer = cls;
1055 unsigned int amount;
1058 // TODO if malicious don't seed mal peers
1059 amount = round (.5 * num_peers);
1061 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n");
1062 for (i = 0 ; i < amount ; i++)
1063 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
1065 GNUNET_i2s (&rps_peer_ids[i]));
1067 GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids);
1072 * Get the id of peer i.
1075 info_cb (void *cb_cls,
1076 struct GNUNET_TESTBED_Operation *op,
1077 const struct GNUNET_TESTBED_PeerInformation *pinfo,
1080 struct OpListEntry *entry = (struct OpListEntry *) cb_cls;
1083 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1088 if (NULL == pinfo || NULL != emsg)
1090 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
1091 GNUNET_TESTBED_operation_done (entry->op);
1095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1098 GNUNET_i2s (pinfo->result.id));
1100 rps_peer_ids[entry->index] = *(pinfo->result.id);
1101 rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index];
1103 GNUNET_assert (GNUNET_OK ==
1104 GNUNET_CONTAINER_multipeermap_put (peer_map,
1105 &rps_peer_ids[entry->index],
1106 &rps_peers[entry->index],
1107 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1108 tofile ("/tmp/rps/peer_ids",
1111 GNUNET_i2s_full (&rps_peer_ids[entry->index]));
1113 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
1114 GNUNET_TESTBED_operation_done (entry->op);
1115 GNUNET_free (entry);
1120 * Callback to be called when RPS service connect operation is completed
1122 * @param cls the callback closure from functions generating an operation
1123 * @param op the operation that has been finished
1124 * @param ca_result the RPS service handle returned from rps_connect_adapter
1125 * @param emsg error message in case the operation has failed; will be NULL if
1126 * operation has executed successfully.
1129 rps_connect_complete_cb (void *cls,
1130 struct GNUNET_TESTBED_Operation *op,
1134 struct RPSPeer *rps_peer = cls;
1135 struct GNUNET_RPS_Handle *rps = ca_result;
1137 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1142 rps_peer->rps_handle = rps;
1143 rps_peer->online = GNUNET_YES;
1146 GNUNET_assert (op == rps_peer->op);
1149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1150 "Failed to connect to RPS service: %s\n",
1153 GNUNET_SCHEDULER_shutdown ();
1157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1158 "Started client successfully (%u)\n",
1161 cur_test_run.main_test (rps_peer);
1166 * Adapter function called to establish a connection to
1169 * @param cls closure
1170 * @param cfg configuration of the peer to connect to; will be available until
1171 * GNUNET_TESTBED_operation_done() is called on the operation returned
1172 * from GNUNET_TESTBED_service_connect()
1173 * @return service handle to return in 'op_result', NULL on error
1176 rps_connect_adapter (void *cls,
1177 const struct GNUNET_CONFIGURATION_Handle *cfg)
1179 struct GNUNET_RPS_Handle *h;
1181 h = GNUNET_RPS_connect (cfg);
1183 if (NULL != cur_test_run.pre_test)
1184 cur_test_run.pre_test (cls, h);
1190 * Called to open a connection to the peer's statistics
1192 * @param cls peer context
1193 * @param cfg configuration of the peer to connect to; will be available until
1194 * GNUNET_TESTBED_operation_done() is called on the operation returned
1195 * from GNUNET_TESTBED_service_connect()
1196 * @return service handle to return in 'op_result', NULL on error
1199 stat_connect_adapter (void *cls,
1200 const struct GNUNET_CONFIGURATION_Handle *cfg)
1202 struct RPSPeer *peer = cls;
1204 peer->stats_h = GNUNET_STATISTICS_create ("rps-profiler", cfg);
1205 return peer->stats_h;
1209 * Called to disconnect from peer's statistics service
1211 * @param cls peer context
1212 * @param op_result service handle returned from the connect adapter
1215 stat_disconnect_adapter (void *cls, void *op_result)
1217 struct RPSPeer *peer = cls;
1219 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
1220 // (peer->stats_h, "core", "# peers connected",
1221 // stat_iterator, peer));
1222 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
1223 // (peer->stats_h, "nse", "# peers connected",
1224 // stat_iterator, peer));
1225 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
1226 peer->stats_h = NULL;
1230 * Called after successfully opening a connection to a peer's statistics
1231 * service; we register statistics monitoring for CORE and NSE here.
1233 * @param cls the callback closure from functions generating an operation
1234 * @param op the operation that has been finished
1235 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
1236 * @param emsg error message in case the operation has failed; will be NULL if
1237 * operation has executed successfully.
1240 stat_complete_cb (void *cls,
1241 struct GNUNET_TESTBED_Operation *op,
1245 //struct GNUNET_STATISTICS_Handle *sh = ca_result;
1246 //struct RPSPeer *peer = (struct RPSPeer *) cls;
1256 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
1257 // (sh, "core", "# peers connected",
1258 // stat_iterator, peer));
1259 //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
1260 // (sh, "nse", "# peers connected",
1261 // stat_iterator, peer));
1266 * Adapter function called to destroy connection to
1269 * @param cls closure
1270 * @param op_result service handle returned from the connect adapter
1273 rps_disconnect_adapter (void *cls,
1276 struct RPSPeer *peer = cls;
1277 struct GNUNET_RPS_Handle *h = op_result;
1278 struct PendingReply *pending_rep;
1280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1281 "disconnect_adapter (%u)\n",
1283 GNUNET_assert (NULL != peer);
1284 if (NULL != peer->rps_handle)
1286 while (NULL != (pending_rep = peer->pending_rep_head))
1288 cancel_request (pending_rep);
1290 GNUNET_assert (h == peer->rps_handle);
1291 GNUNET_RPS_disconnect (h);
1292 peer->rps_handle = NULL;
1297 /***********************************************************************
1298 * Definition of tests
1299 ***********************************************************************/
1302 * Callback to call on receipt of a reply
1304 * @param cls closure
1305 * @param n number of peers
1306 * @param recv_peers the received peers
1309 default_reply_handle (void *cls,
1311 const struct GNUNET_PeerIdentity *recv_peers)
1313 struct RPSPeer *rps_peer;
1314 struct PendingReply *pending_rep = (struct PendingReply *) cls;
1317 rps_peer = pending_rep->rps_peer;
1318 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
1319 rps_peer->pending_rep_tail,
1321 rps_peer->num_pending_reps--;
1322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1323 "[%s] got %" PRIu64 " peers:\n",
1324 GNUNET_i2s (rps_peer->peer_id),
1327 for (i = 0; i < n; i++)
1329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1332 GNUNET_i2s (&recv_peers[i]));
1334 rps_peer->num_recv_ids++;
1337 if (GNUNET_YES != post_test) return;
1338 if (HAVE_QUICK_QUIT != cur_test_run.have_quick_quit) return;
1339 if (0 == evaluate())
1341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1342 "Test succeeded before end of duration\n");
1343 if (NULL != post_test_task) GNUNET_SCHEDULER_cancel (post_test_task);
1344 post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL);
1345 GNUNET_assert (NULL != post_test_task);
1350 * Request random peers.
1353 request_peers (void *cls)
1355 struct PendingRequest *pending_req = cls;
1356 struct RPSPeer *rps_peer;
1357 struct PendingReply *pending_rep;
1359 rps_peer = pending_req->rps_peer;
1360 GNUNET_assert (1 <= rps_peer->num_pending_reqs);
1361 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
1362 rps_peer->pending_req_tail,
1364 rps_peer->num_pending_reqs--;
1365 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) return;
1366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1367 "Requesting one peer\n");
1368 pending_rep = GNUNET_new (struct PendingReply);
1369 pending_rep->rps_peer = rps_peer;
1370 pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle,
1372 cur_test_run.reply_handle,
1374 GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_rep_head,
1375 rps_peer->pending_rep_tail,
1377 rps_peer->num_pending_reps++;
1382 * Schedule requests for peer @a rps_peer that have neither been scheduled, nor
1383 * issued, nor replied
1386 schedule_missing_requests (struct RPSPeer *rps_peer)
1389 struct PendingRequest *pending_req;
1391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1392 "Scheduling %u - %u missing requests\n",
1393 rps_peer->num_ids_to_request,
1394 rps_peer->num_pending_reqs + rps_peer->num_pending_reps);
1395 GNUNET_assert (rps_peer->num_pending_reqs + rps_peer->num_pending_reps <=
1396 rps_peer->num_ids_to_request);
1397 for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps;
1398 i < rps_peer->num_ids_to_request; i++)
1400 pending_req = GNUNET_new (struct PendingRequest);
1401 pending_req->rps_peer = rps_peer;
1402 pending_req->request_task = GNUNET_SCHEDULER_add_delayed (
1403 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
1404 cur_test_run.request_interval * i),
1407 GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_req_head,
1408 rps_peer->pending_req_tail,
1410 rps_peer->num_pending_reqs++;
1415 cancel_pending_req_rep (struct RPSPeer *rps_peer)
1417 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1418 "Cancelling all (pending) requests.\n");
1419 while (NULL != rps_peer->pending_req_head)
1420 cancel_pending_req (rps_peer->pending_req_head);
1421 GNUNET_assert (0 == rps_peer->num_pending_reqs);
1422 while (NULL != rps_peer->pending_rep_head)
1423 cancel_request (rps_peer->pending_rep_head);
1424 GNUNET_assert (0 == rps_peer->num_pending_reps);
1427 /***********************************
1429 ***********************************/
1432 * Initialise only non-mal RPSPeers
1434 static void mal_init_peer (struct RPSPeer *rps_peer)
1436 if (rps_peer->index >= round (portion * num_peers))
1437 rps_peer->num_ids_to_request = 1;
1442 * @brief Set peers to (non-)malicious before execution
1444 * Of signature #PreTest
1446 * @param rps_peer the peer to set (non-) malicious
1447 * @param h the handle to the service
1450 mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
1452 #ifdef ENABLE_MALICIOUS
1453 uint32_t num_mal_peers;
1455 GNUNET_assert ( (1 >= portion) &&
1457 num_mal_peers = round (portion * num_peers);
1459 if (rps_peer->index < num_mal_peers)
1461 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1462 "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n",
1464 GNUNET_i2s (rps_peer->peer_id),
1467 GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers,
1468 rps_peer_ids, target_peer);
1470 #endif /* ENABLE_MALICIOUS */
1474 mal_cb (struct RPSPeer *rps_peer)
1476 uint32_t num_mal_peers;
1478 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1483 #ifdef ENABLE_MALICIOUS
1484 GNUNET_assert ( (1 >= portion) &&
1486 num_mal_peers = round (portion * num_peers);
1488 if (rps_peer->index >= num_mal_peers)
1489 { /* It's useless to ask a malicious peer about a random sample -
1490 it's not sampling */
1491 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
1492 seed_peers, rps_peer);
1493 schedule_missing_requests (rps_peer);
1495 #endif /* ENABLE_MALICIOUS */
1498 /***********************************
1500 ***********************************/
1506 * @brief Starts churn
1508 * Has signature of #MainTest
1510 * This is not implemented too nicely as this is called for each peer, but we
1511 * only need to call it once. (Yes we check that we only schedule the task
1514 * @param rps_peer The peer it's called for
1517 churn_test_cb (struct RPSPeer *rps_peer)
1519 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1525 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task)
1527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1528 "Starting churn task\n");
1529 churn_task = GNUNET_SCHEDULER_add_delayed (
1530 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
1534 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1535 "Not starting churn task\n");
1538 schedule_missing_requests (rps_peer);
1541 /***********************************
1543 ***********************************/
1546 * Callback to be called when RPS service is started or stopped at peers
1549 * @param op the operation handle
1550 * @param emsg NULL on success; otherwise an error description
1553 churn_cb (void *cls,
1554 struct GNUNET_TESTBED_Operation *op,
1558 struct OpListEntry *entry = cls;
1561 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1566 GNUNET_TESTBED_operation_done (entry->op);
1569 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n");
1570 GNUNET_SCHEDULER_shutdown ();
1573 GNUNET_assert (0 != entry->delta);
1575 num_peers_online += entry->delta;
1577 if (PEER_GO_OFFLINE == entry->delta)
1578 { /* Peer hopefully just went offline */
1579 if (GNUNET_YES != rps_peers[entry->index].online)
1581 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1582 "peer %s was expected to go offline but is still marked as online\n",
1583 GNUNET_i2s (rps_peers[entry->index].peer_id));
1588 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1589 "peer %s probably went offline as expected\n",
1590 GNUNET_i2s (rps_peers[entry->index].peer_id));
1592 rps_peers[entry->index].online = GNUNET_NO;
1595 else if (PEER_GO_ONLINE < entry->delta)
1596 { /* Peer hopefully just went online */
1597 if (GNUNET_NO != rps_peers[entry->index].online)
1599 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1600 "peer %s was expected to go online but is still marked as offline\n",
1601 GNUNET_i2s (rps_peers[entry->index].peer_id));
1606 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1607 "peer %s probably went online as expected\n",
1608 GNUNET_i2s (rps_peers[entry->index].peer_id));
1609 if (NULL != cur_test_run.pre_test)
1611 cur_test_run.pre_test (&rps_peers[entry->index],
1612 rps_peers[entry->index].rps_handle);
1613 schedule_missing_requests (&rps_peers[entry->index]);
1616 rps_peers[entry->index].online = GNUNET_YES;
1620 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1621 "Invalid value for delta: %i\n", entry->delta);
1625 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
1626 rps_peers[entry->index].entry_op_manage = NULL;
1627 GNUNET_free (entry);
1628 //if (num_peers_in_round[current_round] == peers_running)
1633 * @brief Set the rps-service up or down for a specific peer
1635 * @param i index of action
1636 * @param j index of peer
1637 * @param delta (#PEER_ONLINE_DELTA) down (-1) or up (1)
1638 * @param prob_go_on_off the probability of the action
1641 manage_service_wrapper (unsigned int i, unsigned int j,
1642 enum PEER_ONLINE_DELTA delta,
1643 double prob_go_on_off)
1645 struct OpListEntry *entry = NULL;
1648 /* make sure that management operation is not already scheduled */
1649 if (NULL != rps_peers[j].entry_op_manage)
1654 prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1657 "%u. selected peer (%u: %s) is %s.\n",
1660 GNUNET_i2s (rps_peers[j].peer_id),
1661 (PEER_GO_ONLINE == delta) ? "online" : "offline");
1662 if (prob < prob_go_on_off * UINT32_MAX)
1664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1666 GNUNET_i2s (rps_peers[j].peer_id),
1667 (PEER_GO_OFFLINE == delta) ? "offline" : "online");
1669 if (PEER_GO_OFFLINE == delta)
1670 cancel_pending_req_rep (&rps_peers[j]);
1671 entry = make_oplist_entry ();
1672 entry->delta = delta;
1674 entry->op = GNUNET_TESTBED_peer_manage_service (NULL,
1679 (PEER_GO_OFFLINE == delta) ? 0 : 1);
1680 rps_peers[j].entry_op_manage = entry;
1690 double portion_online;
1691 unsigned int *permut;
1692 double prob_go_offline;
1693 double portion_go_online;
1694 double portion_go_offline;
1697 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1702 "Churn function executing\n");
1704 churn_task = NULL; /* Should be invalid by now */
1706 /* Compute the probability for an online peer to go offline
1708 portion_online = num_peers_online * 1.0 / num_peers;
1709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1710 "Portion online: %f\n",
1712 portion_go_online = ((1 - portion_online) * .5 * .66);
1713 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1714 "Portion that should go online: %f\n",
1716 portion_go_offline = (portion_online + portion_go_online) - .75;
1717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1718 "Portion that probably goes offline: %f\n",
1719 portion_go_offline);
1720 prob_go_offline = portion_go_offline / (portion_online * .5);
1721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1722 "Probability of a selected online peer to go offline: %f\n",
1725 permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
1726 (unsigned int) num_peers);
1728 /* Go over 50% randomly chosen peers */
1729 for (i = 0; i < .5 * num_peers; i++)
1733 /* If online, shut down with certain probability */
1734 if (GNUNET_YES == rps_peers[j].online)
1736 manage_service_wrapper (i, j, -1, prob_go_offline);
1739 /* If offline, restart with certain probability */
1740 else if (GNUNET_NO == rps_peers[j].online)
1742 manage_service_wrapper (i, j, 1, 0.66);
1746 GNUNET_free (permut);
1748 churn_task = GNUNET_SCHEDULER_add_delayed (
1749 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2),
1756 * Initialise given RPSPeer
1758 static void profiler_init_peer (struct RPSPeer *rps_peer)
1760 rps_peer->num_ids_to_request = cur_test_run.num_requests;
1761 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer shall request %i peers\n",
1762 rps_peer->num_ids_to_request);
1767 * Callback to call on receipt of a reply
1769 * @param cls closure
1770 * @param n number of peers
1771 * @param recv_peers the received peers
1774 profiler_reply_handle (void *cls,
1776 const struct GNUNET_PeerIdentity *recv_peers)
1778 struct RPSPeer *rps_peer;
1779 struct RPSPeer *rcv_rps_peer;
1780 char file_name_buf[128];
1781 char file_name_dh_buf[128];
1782 char file_name_dhr_buf[128];
1783 char file_name_dhru_buf[128];
1784 char *file_name = file_name_buf;
1785 char *file_name_dh = file_name_dh_buf;
1786 char *file_name_dhr = file_name_dhr_buf;
1787 char *file_name_dhru = file_name_dhru_buf;
1789 struct PendingReply *pending_rep = (struct PendingReply *) cls;
1791 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n");
1792 rps_peer = pending_rep->rps_peer;
1793 (void) GNUNET_asprintf (&file_name,
1794 "/tmp/rps/received_ids-%u",
1797 (void) GNUNET_asprintf (&file_name_dh,
1798 "/tmp/rps/diehard_input-%u",
1800 (void) GNUNET_asprintf (&file_name_dhr,
1801 "/tmp/rps/diehard_input_raw-%u",
1803 (void) GNUNET_asprintf (&file_name_dhru,
1804 "/tmp/rps/diehard_input_raw_aligned-%u",
1806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1807 "[%s] got %" PRIu64 " peers:\n",
1808 GNUNET_i2s (rps_peer->peer_id),
1810 for (i = 0; i < n; i++)
1812 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1815 GNUNET_i2s (&recv_peers[i]));
1818 GNUNET_i2s_full (&recv_peers[i]));
1819 rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, &recv_peers[i]);
1820 GNUNET_assert (NULL != rcv_rps_peer);
1821 tofile (file_name_dh,
1823 (uint32_t) rcv_rps_peer->index);
1825 to_file_raw (file_name_dhr,
1826 (char *) &rcv_rps_peer->index,
1828 to_file_raw_unaligned (file_name_dhru,
1829 (char *) &rcv_rps_peer->index,
1832 #endif /* TO_FILE */
1834 default_reply_handle (cls, n, recv_peers);
1839 profiler_cb (struct RPSPeer *rps_peer)
1841 if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test)
1847 if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task)
1849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1850 "Starting churn task\n");
1851 churn_task = GNUNET_SCHEDULER_add_delayed (
1852 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
1856 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1857 "Not starting churn task\n");
1860 /* Only request peer ids at one peer.
1861 * (It's the before-last because last one is target of the focussed attack.)
1863 if (0 < rps_peer->num_ids_to_request)
1864 schedule_missing_requests (rps_peer);
1868 * Function called from #profiler_eval with a filename.
1870 * @param cls closure
1871 * @param filename complete filename (absolute path)
1872 * @return #GNUNET_OK to continue to iterate,
1873 * #GNUNET_NO to stop iteration with no error,
1874 * #GNUNET_SYSERR to abort iteration with error!
1877 file_name_cb (void *cls, const char *filename)
1879 if (NULL != strstr (filename, "sampler_el"))
1881 struct RPS_SamplerElement *s_elem;
1882 struct GNUNET_CRYPTO_AuthKey auth_key;
1883 const char *key_char;
1887 key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */
1888 tofile (filename, "--------------------------\n");
1890 auth_key = string_to_auth_key (key_char);
1891 s_elem = RPS_sampler_elem_create ();
1892 RPS_sampler_elem_set (s_elem, auth_key);
1894 for (i = 0; i < num_peers; i++)
1896 RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]);
1898 RPS_sampler_elem_destroy (s_elem);
1904 * This is run after the test finished.
1906 * Compute all perfect samples.
1909 profiler_eval (void)
1912 /* Compute perfect sample for each sampler element */
1913 if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL))
1915 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n");
1917 #endif /* TO_FILE */
1922 static uint32_t fac (uint32_t x)
1928 return x * fac (x - 1);
1931 static uint32_t binom (uint32_t n, uint32_t k)
1933 //GNUNET_assert (n >= k);
1934 if (k > n) return 0;
1935 /* if (0 > n) return 0; - always false */
1936 /* if (0 > k) return 0; - always false */
1937 if (0 == k) return 1;
1940 fac(k) * fac(n - k);
1944 * @brief is b in view of a?
1951 static int is_in_view (uint32_t a, uint32_t b)
1954 for (i = 0; i < rps_peers[a].cur_view_count; i++)
1956 if (0 == memcmp (rps_peers[b].peer_id,
1957 &rps_peers[a].cur_view[i],
1958 sizeof (struct GNUNET_PeerIdentity)))
1966 static uint32_t get_idx_of_pid (const struct GNUNET_PeerIdentity *pid)
1970 for (i = 0; i < num_peers; i++)
1972 if (0 == memcmp (pid,
1973 rps_peers[i].peer_id,
1974 sizeof (struct GNUNET_PeerIdentity)))
1979 //return 0; /* Should not happen - make compiler happy */
1980 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1981 "No known _PeerIdentity %s!\n",
1982 GNUNET_i2s_full (pid));
1987 * @brief Counts number of peers in view of a that have b in their view
1994 static uint32_t count_containing_views (uint32_t a, uint32_t b)
2000 for (i = 0; i < rps_peers[a].cur_view_count; i++)
2002 peer_idx = get_idx_of_pid (&rps_peers[a].cur_view[i]);
2003 if (GNUNET_YES == is_in_view (peer_idx, b))
2012 * @brief Computes the probability for each other peer to be selected by the
2013 * sampling process based on the views of all peers
2015 * @param peer_idx index of the peer that is about to sample
2017 static void compute_probabilities (uint32_t peer_idx)
2019 //double probs[num_peers] = { 0 };
2020 double probs[num_peers];
2021 size_t probs_as_str_size = (num_peers * 10 + 1) * sizeof (char);
2022 char *probs_as_str = GNUNET_malloc (probs_as_str_size);
2023 char *probs_as_str_cpy;
2028 uint32_t cont_views;
2029 uint32_t number_of_being_in_pull_events;
2031 uint32_t count_non_zero_prob = 0;
2033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2034 "Computing probabilities for peer %" PRIu32 "\n", peer_idx);
2035 /* Firstly without knowledge of old views */
2036 for (i = 0; i < num_peers; i++)
2038 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2039 "\tfor peer %" PRIu32 ":\n", i);
2040 view_size = rps_peers[i].cur_view_count;
2041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2042 "\t\tview_size: %" PRIu32 "\n", view_size);
2043 /* For peer i the probability of being sampled is
2044 * evenly distributed among all possibly observed peers. */
2045 /* We could have observed a peer in three cases:
2046 * 1. peer sent a push
2047 * 2. peer was contained in a pull reply
2048 * 3. peer was in history (sampler) - ignored for now */
2049 /* 1. Probability of having received a push from peer i */
2050 if ((GNUNET_YES == is_in_view (i, peer_idx)) &&
2051 (1 <= (0.45 * view_size)))
2053 if (0 == binom (view_size, 0.45 * view_size)) prob_push = 0;
2056 prob_push = 1.0 * binom (0.45 * view_size, 1)
2058 binom (view_size, 0.45 * view_size);
2060 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2061 "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n",
2065 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2066 "\t\tposs choices from view: %" PRIu32 ", containing i: %" PRIu32 "\n",
2067 binom (view_size, 0.45 * view_size),
2068 binom (0.45 * view_size, 1));
2071 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2072 "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n",
2076 /* 2. Probability of peer i being contained in pulls */
2077 view_size = rps_peers[peer_idx].cur_view_count;
2078 cont_views = count_containing_views (peer_idx, i);
2079 number_of_being_in_pull_events =
2080 (binom (view_size, 0.45 * view_size) -
2081 binom (view_size - cont_views, 0.45 * view_size));
2082 if (0 != number_of_being_in_pull_events)
2084 prob_pull = number_of_being_in_pull_events
2086 (1.0 * binom (view_size, 0.45 * view_size));
2091 probs[i] = prob_push + prob_pull - (prob_push * prob_pull);
2092 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2093 "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32
2094 " peers in its view who know %" PRIu32 " prob: %f\n",
2100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2101 "\t\tnumber of possible pull combinations: %" PRIu32 "\n",
2102 binom (view_size, 0.45 * view_size));
2103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2104 "\t\tnumber of possible pull combinations without %" PRIu32
2107 binom (view_size - cont_views, 0.45 * view_size));
2108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2109 "\t\tnumber of possible pull combinations with %" PRIu32
2112 number_of_being_in_pull_events);
2114 if (0 != probs[i]) count_non_zero_prob++;
2117 if (0 != count_non_zero_prob)
2119 for (i = 0; i < num_peers; i++)
2121 probs[i] = probs[i] * (1.0 / count_non_zero_prob);
2124 for (i = 0; i < num_peers; i++)
2130 for (i = 0; i < num_peers; i++)
2132 probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size);
2133 tmp = GNUNET_snprintf (probs_as_str,
2135 "%s %7.6f", probs_as_str_cpy, probs[i]);
2136 GNUNET_free (probs_as_str_cpy);
2137 GNUNET_assert (0 <= tmp);
2140 to_file_w_len (rps_peers[peer_idx].file_name_probs,
2143 GNUNET_free (probs_as_str);
2147 * @brief This counts the number of peers in which views a given peer occurs.
2149 * It also stores this value in the rps peer.
2151 * @param peer_idx the index of the peer to count the representation
2153 * @return the number of occurrences
2155 static uint32_t count_peer_in_views_2 (uint32_t peer_idx)
2160 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2162 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */
2164 if (0 == memcmp (rps_peers[peer_idx].peer_id,
2165 &rps_peers[i].cur_view[j],
2166 sizeof (struct GNUNET_PeerIdentity)))
2173 rps_peers[peer_idx].count_in_views = count;
2177 static uint32_t cumulated_view_sizes ()
2182 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2184 view_sizes += rps_peers[i].cur_view_count;
2189 static void count_peer_in_views (uint32_t *count_peers)
2193 for (i = 0; i < num_peers; i++) /* Peer in which view is counted */
2195 for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */
2197 if (0 == memcmp (rps_peers[i].peer_id,
2198 &rps_peers[i].cur_view[j],
2199 sizeof (struct GNUNET_PeerIdentity)))
2207 void compute_diversity ()
2210 /* ith entry represents the numer of occurrences in other peer's views */
2211 uint32_t *count_peers = GNUNET_new_array (num_peers, uint32_t);
2212 uint32_t views_total_size;
2214 /* deviation from expected number of peers */
2215 double *deviation = GNUNET_new_array (num_peers, double);
2217 views_total_size = 0;
2220 /* For each peer count its representation in other peer's views*/
2221 for (i = 0; i < num_peers; i++) /* Peer to count */
2223 views_total_size += rps_peers[i].cur_view_count;
2224 count_peer_in_views (count_peers);
2225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2226 "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32"\n",
2228 GNUNET_i2s (rps_peers[i].peer_id),
2232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2233 "size of all views combined: %" PRIu32 "\n",
2235 expected = ((double) 1/num_peers) * views_total_size;
2236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2237 "Expected number of occurrences of each peer in all views: %f\n",
2239 for (i = 0; i < num_peers; i++) /* Peer to count */
2241 deviation[i] = expected - count_peers[i];
2242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2243 "Deviation from expectation: %f\n", deviation[i]);
2245 GNUNET_free (count_peers);
2246 GNUNET_free (deviation);
2249 void print_view_sizes()
2253 for (i = 0; i < num_peers; i++) /* Peer to count */
2255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2256 "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n",
2258 GNUNET_i2s (rps_peers[i].peer_id),
2259 rps_peers[i].cur_view_count);
2263 void all_views_updated_cb()
2265 compute_diversity();
2269 void view_update_cb (void *cls,
2271 const struct GNUNET_PeerIdentity *peers)
2273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2274 "View was updated (%" PRIu64 ")\n", view_size);
2275 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
2276 to_file ("/tmp/rps/view_sizes.txt",
2277 "%" PRIu64 " %" PRIu32 "",
2280 for (uint64_t i = 0; i < view_size; i++)
2282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2283 "\t%s\n", GNUNET_i2s (&peers[i]));
2285 GNUNET_array_grow (rps_peer->cur_view,
2286 rps_peer->cur_view_count,
2288 //*rps_peer->cur_view = *peers;
2289 GNUNET_memcpy (rps_peer->cur_view,
2291 view_size * sizeof (struct GNUNET_PeerIdentity));
2292 to_file ("/tmp/rps/count_in_views.txt",
2293 "%" PRIu64 " %" PRIu32 "",
2295 count_peer_in_views_2 (rps_peer->index));
2296 cumulated_view_sizes();
2299 to_file ("/tmp/rps/repr.txt",
2300 "%" PRIu64 /* index */
2301 " %" PRIu32 /* occurrence in views */
2302 " %" PRIu32 /* view sizes */
2303 " %f" /* fraction of repr in views */
2304 " %f" /* average view size */
2305 " %f" /* prob of occurrence in view slot */
2306 " %f" "", /* exp frac of repr in views */
2308 count_peer_in_views_2 (rps_peer->index),
2310 count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */
2311 view_sizes / (view_size * 1.0), /* average view size */
2312 1.0 /view_size, /* prob of occurrence in view slot */
2313 (1.0/view_size) * (view_sizes/view_size) /* expected fraction of repr in views */
2316 compute_probabilities (rps_peer->index);
2317 all_views_updated_cb();
2321 pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
2323 rps_peer->file_name_probs =
2324 store_prefix_file_name (rps_peer->peer_id, "probs");
2325 GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer);
2328 void write_final_stats (void){
2329 uint64_t sums[STAT_TYPE_MAX] = { 0 };
2331 for (uint32_t i = 0; i < num_peers; i++)
2333 to_file ("/tmp/rps/final_stats.csv",
2334 ", %" PRIu32 ", " /* index */
2336 PRIu64 ", %" /* rounds */
2337 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* blocking */
2338 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */
2339 PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */
2340 PRIu64 ", %" PRIu64 ", %" PRIu64 /* recv */,
2342 GNUNET_i2s (rps_peers[i].peer_id),
2343 rps_peers[i].stats[STAT_TYPE_ROUNDS],
2344 rps_peers[i].stats[STAT_TYPE_BLOCKS],
2345 rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH],
2346 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH],
2347 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PULL],
2348 rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL],
2349 rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL],
2350 rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND],
2351 rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ],
2352 rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REP],
2353 rps_peers[i].stats[STAT_TYPE_SENT_PUSH_SEND],
2354 rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ],
2355 rps_peers[i].stats[STAT_TYPE_SENT_PULL_REP],
2356 rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND],
2357 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ],
2358 rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP]);
2359 for (enum STAT_TYPE stat_type = STAT_TYPE_ROUNDS;
2360 stat_type < STAT_TYPE_MAX;
2363 sums[stat_type] += rps_peers[i].stats[stat_type];
2366 to_file ("/tmp/rps/final_stats.dat",
2368 PRIu64 " %" /* rounds */
2369 PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" /* blocking */
2370 PRIu64 " %" PRIu64 " %" PRIu64 " %" /* issued */
2371 PRIu64 " %" PRIu64 " %" PRIu64 " %" /* sent */
2372 PRIu64 " %" PRIu64 " %" PRIu64 /* recv */,
2373 sums[STAT_TYPE_ROUNDS],
2374 sums[STAT_TYPE_BLOCKS],
2375 sums[STAT_TYPE_BLOCKS_MANY_PUSH],
2376 sums[STAT_TYPE_BLOCKS_NO_PUSH],
2377 sums[STAT_TYPE_BLOCKS_NO_PULL],
2378 sums[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL],
2379 sums[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL],
2380 sums[STAT_TYPE_ISSUED_PUSH_SEND],
2381 sums[STAT_TYPE_ISSUED_PULL_REQ],
2382 sums[STAT_TYPE_ISSUED_PULL_REP],
2383 sums[STAT_TYPE_SENT_PUSH_SEND],
2384 sums[STAT_TYPE_SENT_PULL_REQ],
2385 sums[STAT_TYPE_SENT_PULL_REP],
2386 sums[STAT_TYPE_RECV_PUSH_SEND],
2387 sums[STAT_TYPE_RECV_PULL_REQ],
2388 sums[STAT_TYPE_RECV_PULL_REP]);
2392 * Continuation called by #GNUNET_STATISTICS_get() functions.
2394 * Remembers that this specific statistics value was received for this peer.
2395 * Checks whether all peers received their statistics yet.
2396 * Issues the shutdown.
2398 * @param cls closure
2399 * @param success #GNUNET_OK if statistics were
2400 * successfully obtained, #GNUNET_SYSERR if not.
2403 post_test_shutdown_ready_cb (void *cls,
2406 struct STATcls *stat_cls = (struct STATcls *) cls;
2407 struct RPSPeer *rps_peer = stat_cls->rps_peer;
2409 rps_peer->h_stat_get[stat_cls->stat_type] = NULL;
2410 if (GNUNET_OK == success)
2412 /* set flag that we we got the value */
2413 rps_peer->stat_collected_flags |= BIT(stat_cls->stat_type);
2415 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2416 "Peer %u did not receive statistics value\n",
2418 GNUNET_free (stat_cls);
2423 if (NULL != rps_peer->stat_op &&
2424 GNUNET_YES == check_statistics_collect_completed_single_peer (rps_peer))
2426 GNUNET_TESTBED_operation_done (rps_peer->stat_op);
2429 //write_final_stats ();
2430 if (GNUNET_YES == check_statistics_collect_completed())
2432 write_final_stats ();
2433 GNUNET_free (stat_cls);
2434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2436 GNUNET_SCHEDULER_shutdown ();
2438 GNUNET_free (stat_cls);
2443 * Callback function to process statistic values.
2445 * @param cls closure
2446 * @param subsystem name of subsystem that created the statistic
2447 * @param name the name of the datum
2448 * @param value the current value
2449 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
2450 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
2453 stat_iterator (void *cls,
2454 const char *subsystem,
2459 const struct STATcls *stat_cls = (const struct STATcls *) cls;
2460 struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer;
2461 enum STAT_TYPE stat_type;
2463 (void) is_persistent;
2465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n",
2468 to_file (rps_peer->file_name_stats,
2469 "%s: %" PRIu64 "\n",
2472 stat_type = stat_str_2_type (name);
2473 GNUNET_assert (STAT_TYPE_ROUNDS <= stat_type &&
2474 STAT_TYPE_MAX > stat_type);
2475 rps_peer->stats[stat_type] = value;
2479 void post_profiler (struct RPSPeer *rps_peer)
2481 if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics)
2486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2487 "Going to request statistic values with mask 0x%" PRIx32 "\n",
2488 cur_test_run.stat_collect_flags);
2490 struct STATcls *stat_cls;
2492 for (stat_type = STAT_TYPE_ROUNDS;
2493 stat_type < STAT_TYPE_MAX;
2496 if (BIT(stat_type) & cur_test_run.stat_collect_flags)
2498 stat_cls = GNUNET_malloc (sizeof (struct STATcls));
2499 stat_cls->rps_peer = rps_peer;
2500 stat_cls->stat_type = stat_type;
2501 rps_peer->file_name_stats =
2502 store_prefix_file_name (rps_peer->peer_id, "stats");
2503 rps_peer->h_stat_get[stat_type] =
2504 GNUNET_STATISTICS_get (rps_peer->stats_h,
2506 stat_type_strings [stat_type],
2507 post_test_shutdown_ready_cb,
2509 (struct STATcls *) stat_cls);
2510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2511 "Requested statistics for %s (peer %" PRIu32 ")\n",
2512 stat_type_strings [stat_type],
2519 /***********************************************************************
2520 * /Definition of tests
2521 ***********************************************************************/
2525 * Actual "main" function for the testcase.
2527 * @param cls closure
2528 * @param h the run handle
2529 * @param n_peers number of peers in 'peers'
2530 * @param peers handle to peers run in the testbed
2531 * @param links_succeeded the number of overlay link connection attempts that
2533 * @param links_failed the number of overlay link connection attempts that
2537 test_run (void *cls,
2538 struct GNUNET_TESTBED_RunHandle *h,
2539 unsigned int n_peers,
2540 struct GNUNET_TESTBED_Peer **peers,
2541 unsigned int links_succeeded,
2542 unsigned int links_failed)
2545 struct OpListEntry *entry;
2548 (void) links_failed;
2550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n");
2552 /* Check whether we timed out */
2553 if (n_peers != num_peers ||
2555 0 == links_succeeded)
2557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Going down due to args (eg. timeout)\n");
2558 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers);
2559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", num_peers);
2560 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers);
2561 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", links_succeeded);
2562 GNUNET_SCHEDULER_shutdown ();
2567 /* Initialize peers */
2568 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "going to initialise peers\n");
2569 testbed_peers = peers;
2570 num_peers_online = 0;
2571 for (i = 0; i < num_peers; i++)
2573 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "initialising %u\n", i);
2574 entry = make_oplist_entry ();
2576 rps_peers[i].index = i;
2577 if (NULL != cur_test_run.init_peer)
2578 cur_test_run.init_peer (&rps_peers[i]);
2579 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view)
2581 rps_peers->cur_view_count = 0;
2582 rps_peers->cur_view = NULL;
2584 entry->op = GNUNET_TESTBED_peer_get_information (peers[i],
2585 GNUNET_TESTBED_PIT_IDENTITY,
2590 /* Bring peers up */
2591 GNUNET_assert (num_peers == n_peers);
2592 for (i = 0; i < n_peers; i++)
2594 rps_peers[i].index = i;
2596 GNUNET_TESTBED_service_connect (&rps_peers[i],
2599 &rps_connect_complete_cb,
2601 &rps_connect_adapter,
2602 &rps_disconnect_adapter,
2604 /* Connect all peers to statistics service */
2605 if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics)
2607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2608 "Connecting to statistics service\n");
2609 rps_peers[i].stat_op =
2610 GNUNET_TESTBED_service_connect (NULL,
2615 &stat_connect_adapter,
2616 &stat_disconnect_adapter,
2621 if (NULL != churn_task)
2622 GNUNET_SCHEDULER_cancel (churn_task);
2623 post_test_task = GNUNET_SCHEDULER_add_delayed (duration, &post_test_op, NULL);
2624 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "timeout for shutdown is %lu\n", timeout.rel_value_us/1000000);
2625 shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout,
2628 GNUNET_SCHEDULER_add_shutdown (shutdown_op, NULL);
2633 * Entry point for the testcase, sets up the testbed.
2635 * @param argc unused
2636 * @param argv unused
2641 const char *cfgfile,
2642 const struct GNUNET_CONFIGURATION_Handle *cfg)
2649 /* Defaults for tests */
2652 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n");
2653 cur_test_run.name = "test-rps-profiler";
2654 if (0 == num_peers) num_peers = 10;
2656 cur_test_run.init_peer = profiler_init_peer;
2657 //cur_test_run.pre_test = mal_pre;
2658 cur_test_run.pre_test = pre_profiler;
2659 cur_test_run.main_test = profiler_cb;
2660 cur_test_run.reply_handle = profiler_reply_handle;
2661 cur_test_run.eval_cb = profiler_eval;
2662 cur_test_run.post_test = post_profiler;
2663 cur_test_run.request_interval = 2;
2664 if (0 == cur_test_run.num_requests) cur_test_run.num_requests = 5;
2665 //cur_test_run.have_churn = HAVE_CHURN;
2666 cur_test_run.have_churn = HAVE_NO_CHURN;
2667 cur_test_run.have_quick_quit = HAVE_QUICK_QUIT;
2668 cur_test_run.have_collect_statistics = COLLECT_STATISTICS;
2669 cur_test_run.stat_collect_flags = BIT(STAT_TYPE_ROUNDS) |
2670 BIT(STAT_TYPE_BLOCKS) |
2671 BIT(STAT_TYPE_BLOCKS_MANY_PUSH) |
2672 BIT(STAT_TYPE_BLOCKS_NO_PUSH) |
2673 BIT(STAT_TYPE_BLOCKS_NO_PULL) |
2674 BIT(STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL) |
2675 BIT(STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL) |
2676 BIT(STAT_TYPE_ISSUED_PUSH_SEND) |
2677 BIT(STAT_TYPE_ISSUED_PULL_REQ) |
2678 BIT(STAT_TYPE_ISSUED_PULL_REP) |
2679 BIT(STAT_TYPE_SENT_PUSH_SEND) |
2680 BIT(STAT_TYPE_SENT_PULL_REQ) |
2681 BIT(STAT_TYPE_SENT_PULL_REP) |
2682 BIT(STAT_TYPE_RECV_PUSH_SEND) |
2683 BIT(STAT_TYPE_RECV_PULL_REQ) |
2684 BIT(STAT_TYPE_RECV_PULL_REP);
2685 cur_test_run.have_collect_view = COLLECT_VIEW;
2687 /* 'Clean' directory */
2688 (void) GNUNET_DISK_directory_remove ("/tmp/rps/");
2689 GNUNET_DISK_directory_create ("/tmp/rps/");
2690 if (0 == duration.rel_value_us)
2692 if (0 == timeout.rel_value_us)
2694 duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90);
2695 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
2697 (0.01 * num_peers));
2701 duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
2702 (timeout.rel_value_us/1000000)
2708 if (0 == timeout.rel_value_us)
2710 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
2711 ((duration.rel_value_us/1000000)
2712 * 1.2) + (0.01 * num_peers));
2715 GNUNET_assert (duration.rel_value_us < timeout.rel_value_us);
2716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2717 "duration is %lus\n",
2718 duration.rel_value_us/1000000);
2719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2720 "timeout is %lus\n",
2721 timeout.rel_value_us/1000000);
2723 /* Compute number of bits for representing largest peer id */
2724 for (bits_needed = 1; (1 << bits_needed) < num_peers; bits_needed++)
2726 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2727 "Need %u bits to represent %" PRIu32 " peers\n",
2731 rps_peers = GNUNET_new_array (num_peers, struct RPSPeer);
2732 peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO);
2733 rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
2734 if ( (2 == mal_type) ||
2736 target_peer = &rps_peer_ids[num_peers - 2];
2739 GNUNET_TESTBED_run (NULL,
2750 * Entry point for the testcase, sets up the testbed.
2752 * @param argc unused
2753 * @param argv unused
2754 * @return 0 on success
2757 main (int argc, char *argv[])
2760 struct GNUNET_GETOPT_CommandLineOption options[] = {
2761 GNUNET_GETOPT_option_uint ('n',
2764 gettext_noop ("number of peers to start"),
2767 GNUNET_GETOPT_option_relative_time ('d',
2770 gettext_noop ("duration of the profiling"),
2773 GNUNET_GETOPT_option_relative_time ('t',
2776 gettext_noop ("timeout for the profiling"),
2779 GNUNET_GETOPT_option_uint ('r',
2782 gettext_noop ("number of PeerIDs to request"),
2783 &cur_test_run.num_requests),
2785 GNUNET_GETOPT_OPTION_END
2789 // GNUNET_STRINGS_get_utf8_args (argc, argv,
2794 GNUNET_PROGRAM_run (argc,
2796 "gnunet-rps-profiler",
2797 gettext_noop ("Measure quality and performance of the RPS service."),
2804 if (GNUNET_OK != ret_value)
2806 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2807 "Test did not run successfully!\n");
2810 ret_value = cur_test_run.eval_cb();
2811 if (NO_COLLECT_VIEW == cur_test_run.have_collect_view)
2813 GNUNET_array_grow (rps_peers->cur_view,
2814 rps_peers->cur_view_count,
2817 GNUNET_free (rps_peers);
2818 GNUNET_free (rps_peer_ids);
2819 GNUNET_CONTAINER_multipeermap_destroy (peer_map);
2823 /* end of test_rps.c */