diff options
author | Julius Bünger <buenger@mytum.de> | 2015-04-07 13:13:48 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-04-07 13:13:48 +0000 |
commit | df42828651e3f814a9b4a51dde916db10144cf23 (patch) | |
tree | da348130e4c6d777d7435dd7d1d6b35e2e1e8a69 | |
parent | d780cfa0eca9d603d59f7fb0380088fe096a7e57 (diff) | |
download | gnunet-df42828651e3f814a9b4a51dde916db10144cf23.tar.gz gnunet-df42828651e3f814a9b4a51dde916db10144cf23.zip |
compile test to profiler
-rw-r--r-- | src/rps/Makefile.am | 15 | ||||
-rw-r--r-- | src/rps/test_rps.c | 237 |
2 files changed, 252 insertions, 0 deletions
diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am index 76f935723..844677ab9 100644 --- a/src/rps/Makefile.am +++ b/src/rps/Makefile.am | |||
@@ -40,6 +40,11 @@ libgnunetrps_la_LDFLAGS = \ | |||
40 | libexec_PROGRAMS = \ | 40 | libexec_PROGRAMS = \ |
41 | gnunet-service-rps | 41 | gnunet-service-rps |
42 | 42 | ||
43 | if HAVE_TESTING | ||
44 | check_PROGRAMS = \ | ||
45 | gnunet-nse-profiler | ||
46 | endif | ||
47 | |||
43 | 48 | ||
44 | gnunet_service_rps_SOURCES = \ | 49 | gnunet_service_rps_SOURCES = \ |
45 | gnunet-service-rps_sampler.h gnunet-service-rps_sampler.c \ | 50 | gnunet-service-rps_sampler.h gnunet-service-rps_sampler.c \ |
@@ -56,10 +61,12 @@ gnunet_service_rps_LDADD = \ | |||
56 | -lm -lgcrypt \ | 61 | -lm -lgcrypt \ |
57 | $(GN_LIBINTL) | 62 | $(GN_LIBINTL) |
58 | 63 | ||
64 | |||
59 | if HAVE_TESTING | 65 | if HAVE_TESTING |
60 | check_PROGRAMS = \ | 66 | check_PROGRAMS = \ |
61 | test_rps_malicious_1 \ | 67 | test_rps_malicious_1 \ |
62 | test_rps_malicious_2 \ | 68 | test_rps_malicious_2 \ |
69 | test_rps_malicious_3 \ | ||
63 | test_rps_seed_request \ | 70 | test_rps_seed_request \ |
64 | test_rps_single_req | 71 | test_rps_single_req |
65 | endif | 72 | endif |
@@ -84,6 +91,10 @@ test_rps_malicious_2_SOURCES = \ | |||
84 | test_rps.c | 91 | test_rps.c |
85 | test_rps_malicious_2_LDADD = $(ld_rps_test_lib) | 92 | test_rps_malicious_2_LDADD = $(ld_rps_test_lib) |
86 | 93 | ||
94 | test_rps_malicious_3_SOURCES = \ | ||
95 | test_rps.c | ||
96 | test_rps_malicious_3_LDADD = $(ld_rps_test_lib) | ||
97 | |||
87 | test_rps_single_req_SOURCES = \ | 98 | test_rps_single_req_SOURCES = \ |
88 | test_rps.c | 99 | test_rps.c |
89 | test_rps_single_req_LDADD = $(ld_rps_test_lib) | 100 | test_rps_single_req_LDADD = $(ld_rps_test_lib) |
@@ -92,6 +103,10 @@ test_rps_seed_request_SOURCES = \ | |||
92 | test_rps.c | 103 | test_rps.c |
93 | test_rps_seed_request_LDADD = $(ld_rps_test_lib) | 104 | test_rps_seed_request_LDADD = $(ld_rps_test_lib) |
94 | 105 | ||
106 | gnunet_nse_profiler_SOURCES = \ | ||
107 | test_rps.c | ||
108 | gnunet_nse_profiler_LDADD = $(ld_rps_test_lib) | ||
109 | |||
95 | EXTRA_DIST = \ | 110 | EXTRA_DIST = \ |
96 | test_rps.conf | 111 | test_rps.conf |
97 | 112 | ||
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index d1b7f9eaa..eb2d9d264 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c | |||
@@ -53,6 +53,54 @@ static double portion = .1; | |||
53 | */ | 53 | */ |
54 | static unsigned int mal_type = 0; | 54 | static unsigned int mal_type = 0; |
55 | 55 | ||
56 | /** | ||
57 | * Handles to all of the running peers | ||
58 | */ | ||
59 | static struct GNUNET_TESTBED_Peer **testbed_peers; | ||
60 | |||
61 | |||
62 | /** | ||
63 | * Operation map entry | ||
64 | */ | ||
65 | struct OpListEntry | ||
66 | { | ||
67 | /** | ||
68 | * DLL next ptr | ||
69 | */ | ||
70 | struct OpListEntry *next; | ||
71 | |||
72 | /** | ||
73 | * DLL prev ptr | ||
74 | */ | ||
75 | struct OpListEntry *prev; | ||
76 | |||
77 | /** | ||
78 | * The testbed operation | ||
79 | */ | ||
80 | struct GNUNET_TESTBED_Operation *op; | ||
81 | |||
82 | /** | ||
83 | * Depending on whether we start or stop NSE service at the peer set this to 1 | ||
84 | * or -1 | ||
85 | */ | ||
86 | int delta; | ||
87 | |||
88 | /** | ||
89 | * Index of the regarding peer | ||
90 | */ | ||
91 | unsigned int index; | ||
92 | }; | ||
93 | |||
94 | /** | ||
95 | * OpList DLL head | ||
96 | */ | ||
97 | static struct OpListEntry *oplist_head; | ||
98 | |||
99 | /** | ||
100 | * OpList DLL tail | ||
101 | */ | ||
102 | static struct OpListEntry *oplist_tail; | ||
103 | |||
56 | 104 | ||
57 | /** | 105 | /** |
58 | * Information we track for each peer. | 106 | * Information we track for each peer. |
@@ -85,6 +133,11 @@ struct RPSPeer | |||
85 | //struct GNUNET_RPS_Request_Handle *req_handle; | 133 | //struct GNUNET_RPS_Request_Handle *req_handle; |
86 | 134 | ||
87 | /** | 135 | /** |
136 | * Peer on- or offline? | ||
137 | */ | ||
138 | int online; | ||
139 | |||
140 | /** | ||
88 | * Received PeerIDs | 141 | * Received PeerIDs |
89 | */ | 142 | */ |
90 | struct GNUNET_PeerIdentity *rec_ids; | 143 | struct GNUNET_PeerIdentity *rec_ids; |
@@ -107,12 +160,23 @@ static struct RPSPeer rps_peers[NUM_PEERS]; | |||
107 | static struct GNUNET_PeerIdentity rps_peer_ids[NUM_PEERS]; | 160 | static struct GNUNET_PeerIdentity rps_peer_ids[NUM_PEERS]; |
108 | 161 | ||
109 | /** | 162 | /** |
163 | * Number of online peers. | ||
164 | */ | ||
165 | static unsigned int num_peers_online; | ||
166 | |||
167 | /** | ||
110 | * Return value from 'main'. | 168 | * Return value from 'main'. |
111 | */ | 169 | */ |
112 | static int ok; | 170 | static int ok; |
113 | 171 | ||
114 | 172 | ||
115 | /** | 173 | /** |
174 | * Identifier for the churn task that runs periodically | ||
175 | */ | ||
176 | static struct GNUNET_SCHEDULER_Task *churn_task; | ||
177 | |||
178 | |||
179 | /** | ||
116 | * Called directly after connecting to the service | 180 | * Called directly after connecting to the service |
117 | */ | 181 | */ |
118 | typedef void (*PreTest) (void *cls, struct GNUNET_RPS_Handle *h); | 182 | typedef void (*PreTest) (void *cls, struct GNUNET_RPS_Handle *h); |
@@ -124,6 +188,11 @@ typedef void (*PreTest) (void *cls, struct GNUNET_RPS_Handle *h); | |||
124 | typedef void (*MainTest) (struct RPSPeer *rps_peer); | 188 | typedef void (*MainTest) (struct RPSPeer *rps_peer); |
125 | 189 | ||
126 | /** | 190 | /** |
191 | * Called directly before disconnecting from the service | ||
192 | */ | ||
193 | typedef void (*PostTest) (void *cls, struct GNUNET_RPS_Handle *h); | ||
194 | |||
195 | /** | ||
127 | * Function called after disconnect to evaluate test success | 196 | * Function called after disconnect to evaluate test success |
128 | */ | 197 | */ |
129 | typedef int (*EvaluationCallback) (void); | 198 | typedef int (*EvaluationCallback) (void); |
@@ -145,6 +214,11 @@ struct SingleTestRun | |||
145 | MainTest main_test; | 214 | MainTest main_test; |
146 | 215 | ||
147 | /** | 216 | /** |
217 | * Called directly before disconnecting from the service | ||
218 | */ | ||
219 | PostTest post_test; | ||
220 | |||
221 | /** | ||
148 | * Function to evaluate the test results | 222 | * Function to evaluate the test results |
149 | */ | 223 | */ |
150 | EvaluationCallback eval_cb; | 224 | EvaluationCallback eval_cb; |
@@ -180,6 +254,63 @@ evaluate (struct RPSPeer *loc_rps_peers, | |||
180 | 254 | ||
181 | 255 | ||
182 | /** | 256 | /** |
257 | * Creates an oplist entry and adds it to the oplist DLL | ||
258 | */ | ||
259 | static struct OpListEntry * | ||
260 | make_oplist_entry () | ||
261 | { | ||
262 | struct OpListEntry *entry; | ||
263 | |||
264 | entry = GNUNET_new (struct OpListEntry); | ||
265 | GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry); | ||
266 | return entry; | ||
267 | } | ||
268 | |||
269 | |||
270 | /** | ||
271 | * Callback to be called when NSE service is started or stopped at peers | ||
272 | * | ||
273 | * @param cls NULL | ||
274 | * @param op the operation handle | ||
275 | * @param emsg NULL on success; otherwise an error description | ||
276 | */ | ||
277 | static void | ||
278 | churn_cb (void *cls, | ||
279 | struct GNUNET_TESTBED_Operation *op, | ||
280 | const char *emsg) | ||
281 | { | ||
282 | struct OpListEntry *entry = cls; | ||
283 | |||
284 | GNUNET_TESTBED_operation_done (entry->op); | ||
285 | if (NULL != emsg) | ||
286 | { | ||
287 | //LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop NSE at a peer\n"); | ||
288 | GNUNET_SCHEDULER_shutdown (); | ||
289 | return; | ||
290 | } | ||
291 | GNUNET_assert (0 != entry->delta); | ||
292 | |||
293 | num_peers_online += entry->delta; | ||
294 | |||
295 | if (0 < entry->delta) | ||
296 | { /* Peer hopefully just went online */ | ||
297 | GNUNET_break (GNUNET_NO == rps_peers[entry->index].online); | ||
298 | rps_peers[entry->index].online = GNUNET_YES; | ||
299 | } | ||
300 | else if (0 > entry->delta) | ||
301 | { /* Peer hopefully just went offline */ | ||
302 | GNUNET_break (GNUNET_YES == rps_peers[entry->index].online); | ||
303 | rps_peers[entry->index].online = GNUNET_NO; | ||
304 | } | ||
305 | |||
306 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); | ||
307 | GNUNET_free (entry); | ||
308 | //if (num_peers_in_round[current_round] == peers_running) | ||
309 | // run_round (); | ||
310 | } | ||
311 | |||
312 | |||
313 | /** | ||
183 | * Task run on timeout to shut everything down. | 314 | * Task run on timeout to shut everything down. |
184 | */ | 315 | */ |
185 | static void | 316 | static void |
@@ -309,6 +440,8 @@ rps_connect_complete_cb (void *cls, | |||
309 | struct GNUNET_RPS_Handle *rps = ca_result; | 440 | struct GNUNET_RPS_Handle *rps = ca_result; |
310 | 441 | ||
311 | rps_peer->rps_handle = rps; | 442 | rps_peer->rps_handle = rps; |
443 | rps_peer->online = GNUNET_YES; | ||
444 | num_peers_online++; | ||
312 | 445 | ||
313 | GNUNET_assert (op == rps_peer->op); | 446 | GNUNET_assert (op == rps_peer->op); |
314 | if (NULL != emsg) | 447 | if (NULL != emsg) |
@@ -516,6 +649,93 @@ req_cancel_cb (struct RPSPeer *rps_peer) | |||
516 | // TODO | 649 | // TODO |
517 | } | 650 | } |
518 | 651 | ||
652 | /*********************************** | ||
653 | * PROFILER | ||
654 | ***********************************/ | ||
655 | static void | ||
656 | churn (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
657 | { | ||
658 | struct OpListEntry *entry; | ||
659 | unsigned int i; | ||
660 | unsigned int j; | ||
661 | double portion_online; | ||
662 | unsigned int *permut; | ||
663 | double prob_go_offline; | ||
664 | double portion_go_online; | ||
665 | double portion_go_offline; | ||
666 | uint32_t prob; | ||
667 | |||
668 | portion_online = num_peers_online / NUM_PEERS; | ||
669 | portion_go_online = ((1 - portion_online) * .5 * .66); | ||
670 | portion_go_offline = (portion_online + portion_go_online) - .75; | ||
671 | prob_go_offline = portion_go_offline / (portion_online * .5); | ||
672 | |||
673 | permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, | ||
674 | (unsigned int) NUM_PEERS); | ||
675 | |||
676 | for (i = 0 ; i < .5 * NUM_PEERS ; i++) | ||
677 | { | ||
678 | j = permut[i]; | ||
679 | |||
680 | if (GNUNET_YES == rps_peers[j].online) | ||
681 | { | ||
682 | prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
683 | UINT32_MAX); | ||
684 | if (prob < prob_go_offline * UINT32_MAX) | ||
685 | { | ||
686 | entry = make_oplist_entry (); | ||
687 | entry->delta = 1; | ||
688 | entry->index = j; | ||
689 | entry->op = GNUNET_TESTBED_peer_manage_service (NULL, | ||
690 | testbed_peers[j], | ||
691 | "rps", | ||
692 | &churn_cb, | ||
693 | entry, | ||
694 | 1); | ||
695 | } | ||
696 | } | ||
697 | |||
698 | else if (GNUNET_NO == rps_peers[j].online) | ||
699 | { | ||
700 | prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
701 | UINT32_MAX); | ||
702 | if (prob < .66 * UINT32_MAX) | ||
703 | { | ||
704 | entry = make_oplist_entry (); | ||
705 | entry->delta = -1; | ||
706 | entry->index = j; | ||
707 | entry->op = GNUNET_TESTBED_peer_manage_service (NULL, | ||
708 | testbed_peers[j], | ||
709 | "rps", | ||
710 | &churn_cb, | ||
711 | entry, | ||
712 | 0); | ||
713 | } | ||
714 | } | ||
715 | } | ||
716 | |||
717 | churn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
718 | 10), | ||
719 | churn, NULL); | ||
720 | } | ||
721 | |||
722 | static void | ||
723 | profiler_pre (void *cls, struct GNUNET_RPS_Handle *h) | ||
724 | { | ||
725 | churn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
726 | 10), | ||
727 | churn, NULL); | ||
728 | mal_pre (cls, h); | ||
729 | } | ||
730 | |||
731 | static void | ||
732 | profiler_cb (struct RPSPeer *rps_peer) | ||
733 | { | ||
734 | // We're not requesting peers | ||
735 | // TODO maybe seed | ||
736 | } | ||
737 | |||
738 | |||
519 | /*********************************************************************** | 739 | /*********************************************************************** |
520 | * /Definition of tests | 740 | * /Definition of tests |
521 | ***********************************************************************/ | 741 | ***********************************************************************/ |
@@ -544,6 +764,9 @@ run (void *cls, | |||
544 | unsigned int i; | 764 | unsigned int i; |
545 | unsigned int *tmp_i; | 765 | unsigned int *tmp_i; |
546 | 766 | ||
767 | testbed_peers = peers; | ||
768 | num_peers_online = 0; | ||
769 | |||
547 | for (i = 0 ; i < NUM_PEERS ; i++) | 770 | for (i = 0 ; i < NUM_PEERS ; i++) |
548 | { | 771 | { |
549 | tmp_i = GNUNET_new (unsigned int); | 772 | tmp_i = GNUNET_new (unsigned int); |
@@ -585,6 +808,7 @@ main (int argc, char *argv[]) | |||
585 | { | 808 | { |
586 | cur_test_run.pre_test = NULL; | 809 | cur_test_run.pre_test = NULL; |
587 | cur_test_run.eval_cb = default_eval_cb; | 810 | cur_test_run.eval_cb = default_eval_cb; |
811 | churn_task = NULL; | ||
588 | 812 | ||
589 | if (strstr (argv[0], "malicious") != NULL) | 813 | if (strstr (argv[0], "malicious") != NULL) |
590 | { | 814 | { |
@@ -645,6 +869,16 @@ main (int argc, char *argv[]) | |||
645 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test cancelling a request\n"); | 869 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test cancelling a request\n"); |
646 | cur_test_run.main_test = req_cancel_cb; | 870 | cur_test_run.main_test = req_cancel_cb; |
647 | } | 871 | } |
872 | else if (strstr (argv[0], "profiler") != NULL) | ||
873 | { | ||
874 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n"); | ||
875 | mal_type = 3; | ||
876 | cur_test_run.pre_test = profiler_pre; | ||
877 | cur_test_run.main_test = profiler_cb; | ||
878 | churn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
879 | 10), | ||
880 | churn, NULL); | ||
881 | } | ||
648 | 882 | ||
649 | ok = 1; | 883 | ok = 1; |
650 | (void) GNUNET_TESTBED_test_run ("test-rps-multipeer", | 884 | (void) GNUNET_TESTBED_test_run ("test-rps-multipeer", |
@@ -653,6 +887,9 @@ main (int argc, char *argv[]) | |||
653 | 0, NULL, NULL, | 887 | 0, NULL, NULL, |
654 | &run, NULL); | 888 | &run, NULL); |
655 | 889 | ||
890 | if (NULL != churn_task) | ||
891 | GNUNET_SCHEDULER_cancel (churn_task); | ||
892 | |||
656 | return cur_test_run.eval_cb(); | 893 | return cur_test_run.eval_cb(); |
657 | } | 894 | } |
658 | 895 | ||