diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-10-05 20:25:41 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-10-05 20:25:41 +0000 |
commit | a9517169f685a7f67fe251b45bb2bbb23a614240 (patch) | |
tree | a5f04c8de8f3ab90db0b17fb1a2f0d9024b5b985 /src/mesh/test_mesh_small.c | |
parent | b89e780adf98391f8429eaa78523f76c30021a02 (diff) | |
download | gnunet-a9517169f685a7f67fe251b45bb2bbb23a614240.tar.gz gnunet-a9517169f685a7f67fe251b45bb2bbb23a614240.zip |
Simplfied base multipeer testcase, removed tests from experimental
Diffstat (limited to 'src/mesh/test_mesh_small.c')
-rw-r--r-- | src/mesh/test_mesh_small.c | 263 |
1 files changed, 18 insertions, 245 deletions
diff --git a/src/mesh/test_mesh_small.c b/src/mesh/test_mesh_small.c index 97edbf731..0fd0b9766 100644 --- a/src/mesh/test_mesh_small.c +++ b/src/mesh/test_mesh_small.c | |||
@@ -79,16 +79,6 @@ static struct GNUNET_CONFIGURATION_Handle *testing_cfg; | |||
79 | static unsigned long long peers_running; | 79 | static unsigned long long peers_running; |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * Current round we are in. | ||
83 | */ | ||
84 | static unsigned long long current_round; | ||
85 | |||
86 | /** | ||
87 | * Peers desired in the next round. | ||
88 | */ | ||
89 | static unsigned long long peers_next_round; | ||
90 | |||
91 | /** | ||
92 | * Total number of connections in the whole network. | 82 | * Total number of connections in the whole network. |
93 | */ | 83 | */ |
94 | static unsigned int total_connections; | 84 | static unsigned int total_connections; |
@@ -109,11 +99,6 @@ static struct GNUNET_DISK_FileHandle *output_file; | |||
109 | static struct GNUNET_DISK_FileHandle *data_file; | 99 | static struct GNUNET_DISK_FileHandle *data_file; |
110 | 100 | ||
111 | /** | 101 | /** |
112 | * How many data points to capture before triggering next round? | ||
113 | */ | ||
114 | static struct GNUNET_TIME_Relative wait_time; | ||
115 | |||
116 | /** | ||
117 | * Task called to disconnect peers. | 102 | * Task called to disconnect peers. |
118 | */ | 103 | */ |
119 | static GNUNET_SCHEDULER_TaskIdentifier disconnect_task; | 104 | static GNUNET_SCHEDULER_TaskIdentifier disconnect_task; |
@@ -123,15 +108,12 @@ static GNUNET_SCHEDULER_TaskIdentifier disconnect_task; | |||
123 | */ | 108 | */ |
124 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle; | 109 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle; |
125 | 110 | ||
126 | /** | ||
127 | * Task used to churn the network. | ||
128 | */ | ||
129 | static GNUNET_SCHEDULER_TaskIdentifier churn_task; | ||
130 | |||
131 | static char *topology_file; | 111 | static char *topology_file; |
132 | 112 | ||
133 | static char *data_filename; | 113 | static char *data_filename; |
134 | 114 | ||
115 | static struct GNUNET_TIME_Relative time_out; | ||
116 | |||
135 | /** | 117 | /** |
136 | * Check whether peers successfully shut down. | 118 | * Check whether peers successfully shut down. |
137 | */ | 119 | */ |
@@ -159,7 +141,6 @@ shutdown_callback (void *cls, const char *emsg) | |||
159 | static void | 141 | static void |
160 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 142 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
161 | { | 143 | { |
162 | // struct NSEPeer *pos; | ||
163 | #if VERBOSE | 144 | #if VERBOSE |
164 | fprintf (stderr, "Ending test.\n"); | 145 | fprintf (stderr, "Ending test.\n"); |
165 | #endif | 146 | #endif |
@@ -169,14 +150,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
169 | GNUNET_SCHEDULER_cancel (disconnect_task); | 150 | GNUNET_SCHEDULER_cancel (disconnect_task); |
170 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 151 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; |
171 | } | 152 | } |
172 | // while (NULL != (pos = peer_head)) | ||
173 | // { | ||
174 | // if (pos->nse_handle != NULL) | ||
175 | // GNUNET_NSE_disconnect(pos->nse_handle); | ||
176 | // GNUNET_CONTAINER_DLL_remove(peer_head, peer_tail, pos); | ||
177 | // GNUNET_free(pos); | ||
178 | // } | ||
179 | |||
180 | if (data_file != NULL) | 153 | if (data_file != NULL) |
181 | GNUNET_DISK_file_close (data_file); | 154 | GNUNET_DISK_file_close (data_file); |
182 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 155 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
@@ -193,6 +166,17 @@ static struct GNUNET_MESH_MessageHandler handlers[] = { | |||
193 | }; | 166 | }; |
194 | 167 | ||
195 | 168 | ||
169 | static void | ||
170 | disconnect_mesh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
171 | { | ||
172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
173 | "test: disconnecting mesh service of peers\n"); | ||
174 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
175 | GNUNET_SCHEDULER_cancel (shutdown_handle); | ||
176 | shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); | ||
177 | } | ||
178 | |||
179 | |||
196 | /** | 180 | /** |
197 | * Function called whenever an inbound tunnel is destroyed. Should clean up | 181 | * Function called whenever an inbound tunnel is destroyed. Should clean up |
198 | * any associated state. | 182 | * any associated state. |
@@ -247,7 +231,7 @@ ch (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
247 | * | 231 | * |
248 | */ | 232 | */ |
249 | static void | 233 | static void |
250 | connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 234 | connect_mesh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
251 | { | 235 | { |
252 | struct GNUNET_TESTING_Daemon *d; | 236 | struct GNUNET_TESTING_Daemon *d; |
253 | struct GNUNET_MESH_Handle *h; | 237 | struct GNUNET_MESH_Handle *h; |
@@ -275,206 +259,6 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
275 | } | 259 | } |
276 | 260 | ||
277 | 261 | ||
278 | static void | ||
279 | churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
280 | |||
281 | |||
282 | /** | ||
283 | * Continuation called by the "get_all" and "get" functions. | ||
284 | * | ||
285 | * @param cls struct StatsContext | ||
286 | * @param success GNUNET_OK if statistics were | ||
287 | * successfully obtained, GNUNET_SYSERR if not. | ||
288 | */ | ||
289 | static void | ||
290 | stats_finished_callback (void *cls, int success) | ||
291 | { | ||
292 | struct StatsContext *stats_context = cls; | ||
293 | char *buf; | ||
294 | int buf_len; | ||
295 | |||
296 | if ((GNUNET_OK == success) && (data_file != NULL)) | ||
297 | { | ||
298 | /* Stats lookup successful, write out data */ | ||
299 | buf = NULL; | ||
300 | buf_len = | ||
301 | GNUNET_asprintf (&buf, "TOTAL_MESH_BYTES: %u\n", | ||
302 | stats_context->total_mesh_bytes); | ||
303 | if (buf_len > 0) | ||
304 | { | ||
305 | GNUNET_DISK_file_write (data_file, buf, buf_len); | ||
306 | } | ||
307 | GNUNET_free_non_null (buf); | ||
308 | } | ||
309 | |||
310 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == shutdown_handle); | ||
311 | shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | ||
312 | GNUNET_free (stats_context); | ||
313 | } | ||
314 | |||
315 | |||
316 | /** | ||
317 | * Callback function to process statistic values. | ||
318 | * | ||
319 | * @param cls struct StatsContext | ||
320 | * @param peer the peer the statistics belong to | ||
321 | * @param subsystem name of subsystem that created the statistic | ||
322 | * @param name the name of the datum | ||
323 | * @param value the current value | ||
324 | * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not | ||
325 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | ||
326 | */ | ||
327 | static int | ||
328 | statistics_iterator (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
329 | const char *subsystem, const char *name, uint64_t value, | ||
330 | int is_persistent) | ||
331 | { | ||
332 | struct StatsContext *stats_context = cls; | ||
333 | |||
334 | // | ||
335 | // if ( (0 == strstr(subsystem, "nse")) && | ||
336 | // (0 == strstr(name, "# flood messages received")) ) | ||
337 | stats_context->total_mesh_bytes += 1; //value; | ||
338 | return GNUNET_OK; | ||
339 | } | ||
340 | |||
341 | |||
342 | static void | ||
343 | disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
344 | { | ||
345 | // struct NSEPeer *pos; | ||
346 | char *buf; | ||
347 | struct StatsContext *stats_context; | ||
348 | |||
349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnecting mesh service of peers\n"); | ||
350 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
351 | // pos = peer_head; | ||
352 | // while (NULL != (pos = peer_head)) | ||
353 | // { | ||
354 | // if (pos->nse_handle != NULL) | ||
355 | // { | ||
356 | // GNUNET_NSE_disconnect(pos->nse_handle); | ||
357 | // pos->nse_handle = NULL; | ||
358 | // } | ||
359 | // GNUNET_CONTAINER_DLL_remove(peer_head, peer_tail, pos); | ||
360 | // GNUNET_free(pos); | ||
361 | // } | ||
362 | |||
363 | GNUNET_asprintf (&buf, "round%llu", current_round); | ||
364 | if (GNUNET_OK == | ||
365 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small", | ||
366 | buf, &peers_next_round)) | ||
367 | { | ||
368 | current_round++; | ||
369 | GNUNET_assert (churn_task == GNUNET_SCHEDULER_NO_TASK); | ||
370 | churn_task = GNUNET_SCHEDULER_add_now (&churn_peers, NULL); | ||
371 | } | ||
372 | else | ||
373 | { /* No more rounds, let's shut it down! */ | ||
374 | |||
375 | stats_context = GNUNET_malloc (sizeof (struct StatsContext)); | ||
376 | GNUNET_SCHEDULER_cancel (shutdown_handle); | ||
377 | shutdown_handle = GNUNET_SCHEDULER_NO_TASK; | ||
378 | GNUNET_TESTING_get_statistics (pg, &stats_finished_callback, | ||
379 | &statistics_iterator, stats_context); | ||
380 | } | ||
381 | GNUNET_free (buf); | ||
382 | } | ||
383 | |||
384 | |||
385 | /** | ||
386 | * FIXME. | ||
387 | * | ||
388 | * @param cls unused | ||
389 | * @param emsg NULL on success | ||
390 | */ | ||
391 | static void | ||
392 | topology_output_callback (void *cls, const char *emsg) | ||
393 | { | ||
394 | disconnect_task = | ||
395 | GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL); | ||
396 | GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL); | ||
397 | } | ||
398 | |||
399 | |||
400 | /** | ||
401 | * FIXME. | ||
402 | * | ||
403 | * @param cls closure | ||
404 | * @param emsg NULL on success | ||
405 | */ | ||
406 | static void | ||
407 | churn_callback (void *cls, const char *emsg) | ||
408 | { | ||
409 | char *temp_output_file; | ||
410 | |||
411 | if (emsg == NULL) | ||
412 | { /* Everything is okay! */ | ||
413 | peers_running = peers_next_round; | ||
414 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
415 | "Round %llu, churn finished successfully.\n", current_round); | ||
416 | GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK); | ||
417 | GNUNET_asprintf (&temp_output_file, "%s_%llu.dot", topology_file, | ||
418 | current_round); | ||
419 | GNUNET_TESTING_peergroup_topology_to_file (pg, temp_output_file, | ||
420 | &topology_output_callback, NULL); | ||
421 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Writing topology to file %s\n", | ||
422 | temp_output_file); | ||
423 | GNUNET_free (temp_output_file); | ||
424 | } | ||
425 | else | ||
426 | { | ||
427 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %llu, churn FAILED!!\n", | ||
428 | current_round); | ||
429 | GNUNET_SCHEDULER_cancel (shutdown_handle); | ||
430 | shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | ||
431 | } | ||
432 | } | ||
433 | |||
434 | |||
435 | static void | ||
436 | churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
437 | { | ||
438 | /* peers_running = GNUNET_TESTING_daemons_running(pg); */ | ||
439 | churn_task = GNUNET_SCHEDULER_NO_TASK; | ||
440 | if (peers_next_round == peers_running) | ||
441 | { | ||
442 | /* Nothing to do... */ | ||
443 | GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL); | ||
444 | GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK); | ||
445 | disconnect_task = | ||
446 | GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL); | ||
447 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %lu, doing nothing!\n", | ||
448 | current_round); | ||
449 | } | ||
450 | else | ||
451 | { | ||
452 | if (peers_next_round > num_peers) | ||
453 | { | ||
454 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
455 | "Asked to turn on more peers than we have!!\n"); | ||
456 | GNUNET_SCHEDULER_cancel (shutdown_handle); | ||
457 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | ||
458 | } | ||
459 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
460 | "Round %llu, turning off %llu peers, turning on %llu peers!\n", | ||
461 | current_round, | ||
462 | (peers_running > | ||
463 | peers_next_round) ? peers_running - peers_next_round : 0, | ||
464 | (peers_next_round > | ||
465 | peers_running) ? peers_next_round - peers_running : 0); | ||
466 | GNUNET_TESTING_daemons_churn (pg, "nse", | ||
467 | (peers_running > | ||
468 | peers_next_round) ? peers_running - | ||
469 | peers_next_round : 0, | ||
470 | (peers_next_round > | ||
471 | peers_running) ? peers_next_round - | ||
472 | peers_running : 0, wait_time, &churn_callback, | ||
473 | NULL); | ||
474 | } | ||
475 | } | ||
476 | |||
477 | |||
478 | /** | 262 | /** |
479 | * peergroup_ready: start test when all peers are connected | 263 | * peergroup_ready: start test when all peers are connected |
480 | * @param cls closure | 264 | * @param cls closure |
@@ -511,9 +295,9 @@ peergroup_ready (void *cls, const char *emsg) | |||
511 | } | 295 | } |
512 | peers_running = GNUNET_TESTING_daemons_running (pg); | 296 | peers_running = GNUNET_TESTING_daemons_running (pg); |
513 | 297 | ||
514 | GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL); | 298 | GNUNET_SCHEDULER_add_now (&connect_mesh, NULL); |
515 | disconnect_task = | 299 | disconnect_task = |
516 | GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL); | 300 | GNUNET_SCHEDULER_add_delayed (time_out, &disconnect_mesh, NULL); |
517 | 301 | ||
518 | } | 302 | } |
519 | 303 | ||
@@ -557,7 +341,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
557 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 341 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
558 | { | 342 | { |
559 | char *temp_str; | 343 | char *temp_str; |
560 | unsigned long long temp_wait; | ||
561 | struct GNUNET_TESTING_Host *hosts; | 344 | struct GNUNET_TESTING_Host *hosts; |
562 | 345 | ||
563 | ok = 1; | 346 | ok = 1; |
@@ -577,6 +360,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
577 | "use_progressbars", "YES"); | 360 | "use_progressbars", "YES"); |
578 | #endif | 361 | #endif |
579 | 362 | ||
363 | time_out = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); | ||
364 | |||
580 | if (GNUNET_OK != | 365 | if (GNUNET_OK != |
581 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing", | 366 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing", |
582 | "num_peers", &num_peers)) | 367 | "num_peers", &num_peers)) |
@@ -595,15 +380,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
595 | } | 380 | } |
596 | 381 | ||
597 | if (GNUNET_OK != | 382 | if (GNUNET_OK != |
598 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small", | ||
599 | "wait_time", &temp_wait)) | ||
600 | { | ||
601 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
602 | "Option nsetest_mesh_small:wait_time is required!\n"); | ||
603 | return; | ||
604 | } | ||
605 | |||
606 | if (GNUNET_OK != | ||
607 | GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing", | 383 | GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing", |
608 | "topology_output_file", | 384 | "topology_output_file", |
609 | &topology_file)) | 385 | &topology_file)) |
@@ -636,9 +412,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
636 | GNUNET_free (data_filename); | 412 | GNUNET_free (data_filename); |
637 | } | 413 | } |
638 | 414 | ||
639 | wait_time = | ||
640 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait); | ||
641 | |||
642 | if (GNUNET_YES == | 415 | if (GNUNET_YES == |
643 | GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small", | 416 | GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small", |
644 | "output_file", &temp_str)) | 417 | "output_file", &temp_str)) |