diff options
author | Bart Polot <bart@net.in.tum.de> | 2012-02-07 17:14:09 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2012-02-07 17:14:09 +0000 |
commit | 84911487a06ec47e58c8b02e1b617805e20613e9 (patch) | |
tree | 701eecc098df7e1f2a6fb989e89146a10abe90df /src/dht/test_dht_topo.c | |
parent | 7d974214075599fdf8b48940b764e8f9b41f9ae4 (diff) | |
download | gnunet-84911487a06ec47e58c8b02e1b617805e20613e9.tar.gz gnunet-84911487a06ec47e58c8b02e1b617805e20613e9.zip |
- Updated testcase to test for line as well as 2d torus with common code
Diffstat (limited to 'src/dht/test_dht_topo.c')
-rw-r--r-- | src/dht/test_dht_topo.c | 178 |
1 files changed, 120 insertions, 58 deletions
diff --git a/src/dht/test_dht_topo.c b/src/dht/test_dht_topo.c index 1db351841..5fc2a9887 100644 --- a/src/dht/test_dht_topo.c +++ b/src/dht/test_dht_topo.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2011 Christian Grothoff (and other contributing authors) | 3 | (C) 2012 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -18,9 +18,9 @@ | |||
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file dht/test_dht_2dtorus.c | 21 | * @file dht/test_dht_topo.c |
22 | * | 22 | * |
23 | * @brief Test for the dht service: store and retrieve in a 2d_torus. | 23 | * @brief Test for the dht service: store and retrieve in various topologies. |
24 | * Each peer stores it own ID in the DHT and then a different peer tries to | 24 | * Each peer stores it own ID in the DHT and then a different peer tries to |
25 | * retrieve that key from it. The GET starts after a first round of PUTS has | 25 | * retrieve that key from it. The GET starts after a first round of PUTS has |
26 | * been made. Periodically, each peer stores its ID into the DHT. If after | 26 | * been made. Periodically, each peer stores its ID into the DHT. If after |
@@ -34,6 +34,11 @@ | |||
34 | 34 | ||
35 | #define REMOVE_DIR GNUNET_YES | 35 | #define REMOVE_DIR GNUNET_YES |
36 | 36 | ||
37 | /** | ||
38 | * DIFFERENT TESTS TO RUN | ||
39 | */ | ||
40 | #define LINE 0 | ||
41 | #define TORUS 1 | ||
37 | 42 | ||
38 | /** | 43 | /** |
39 | * How long until we give up on connecting the peers? | 44 | * How long until we give up on connecting the peers? |
@@ -44,6 +49,9 @@ | |||
44 | 49 | ||
45 | #define PUT_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 50 | #define PUT_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
46 | 51 | ||
52 | /** | ||
53 | * Result of the test. | ||
54 | */ | ||
47 | static int ok; | 55 | static int ok; |
48 | 56 | ||
49 | /** | 57 | /** |
@@ -123,6 +131,11 @@ struct GNUNET_DHT_GetHandle *get_h_far; | |||
123 | unsigned int found; | 131 | unsigned int found; |
124 | 132 | ||
125 | /** | 133 | /** |
134 | * Which topology are we to run | ||
135 | */ | ||
136 | static int test_topology; | ||
137 | |||
138 | /** | ||
126 | * Check whether peers successfully shut down. | 139 | * Check whether peers successfully shut down. |
127 | */ | 140 | */ |
128 | static void | 141 | static void |
@@ -222,7 +235,7 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
222 | GNUNET_i2s (&put_path[i])); | 235 | GNUNET_i2s (&put_path[i])); |
223 | } | 236 | } |
224 | found++; | 237 | found++; |
225 | if (found < 3) | 238 | if (TORUS == test_topology && found < 3) |
226 | return; | 239 | return; |
227 | ok = 0; | 240 | ok = 0; |
228 | GNUNET_SCHEDULER_cancel (disconnect_task); | 241 | GNUNET_SCHEDULER_cancel (disconnect_task); |
@@ -245,36 +258,43 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
245 | unsigned int i; | 258 | unsigned int i; |
246 | 259 | ||
247 | d = d2 = d_far = o = NULL; | 260 | d = d2 = d_far = o = NULL; |
248 | for (i = 0; i < num_peers; i++) | 261 | if (LINE == test_topology) |
249 | { | 262 | { |
250 | aux = GNUNET_TESTING_daemon_get (pg, i); | 263 | o = GNUNET_TESTING_daemon_get (pg, 0); |
251 | id_aux = GNUNET_i2s (&aux->id); | 264 | d = GNUNET_TESTING_daemon_get (pg, 4); |
252 | if (strcmp (id_aux, id_origin) == 0) | ||
253 | o = aux; | ||
254 | if (strcmp (id_aux, id_far) == 0) | ||
255 | d_far = aux; | ||
256 | if (strcmp (id_aux, id_near) == 0) | ||
257 | d = aux; | ||
258 | if (strcmp (id_aux, id_near2) == 0) | ||
259 | d2 = aux; | ||
260 | } | 265 | } |
261 | if ((NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far)) | 266 | else if (TORUS == test_topology) |
262 | { | 267 | { |
263 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 268 | for (i = 0; i < num_peers; i++) |
264 | "test: Peers not found (hostkey file changed?)\n"); | 269 | { |
265 | GNUNET_SCHEDULER_cancel (disconnect_task); | 270 | aux = GNUNET_TESTING_daemon_get (pg, i); |
266 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); | 271 | id_aux = GNUNET_i2s (&aux->id); |
267 | return; | 272 | if (strcmp (id_aux, id_origin) == 0) |
273 | o = aux; | ||
274 | if (strcmp (id_aux, id_far) == 0) | ||
275 | d_far = aux; | ||
276 | if (strcmp (id_aux, id_near) == 0) | ||
277 | d = aux; | ||
278 | if (strcmp (id_aux, id_near2) == 0) | ||
279 | d2 = aux; | ||
280 | } | ||
281 | if ((NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far)) | ||
282 | { | ||
283 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
284 | "test: Peers not found (hostkey file changed?)\n"); | ||
285 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
286 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); | ||
287 | return; | ||
288 | } | ||
268 | } | 289 | } |
269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); | 290 | else |
270 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", | 291 | { |
271 | GNUNET_h2s_full (&d->id.hashPubKey)); | 292 | GNUNET_assert (0); |
272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", | 293 | } |
273 | GNUNET_h2s_full (&d2->id.hashPubKey)); | 294 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\ntest: from %s\n", |
274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", | ||
275 | GNUNET_h2s_full (&d_far->id.hashPubKey)); | ||
276 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: from %s\n", | ||
277 | GNUNET_h2s_full (&o->id.hashPubKey)); | 295 | GNUNET_h2s_full (&o->id.hashPubKey)); |
296 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", | ||
297 | GNUNET_h2s_full (&d->id.hashPubKey)); | ||
278 | found = 0; | 298 | found = 0; |
279 | get_h = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | 299 | get_h = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ |
280 | GNUNET_BLOCK_TYPE_TEST, /* type */ | 300 | GNUNET_BLOCK_TYPE_TEST, /* type */ |
@@ -283,26 +303,39 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
283 | GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ | 303 | GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ |
284 | 0, /* xquery bits */ | 304 | 0, /* xquery bits */ |
285 | &dht_get_id_handler, NULL); | 305 | &dht_get_id_handler, NULL); |
286 | get_h_2 = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | 306 | if (TORUS == test_topology) |
287 | GNUNET_BLOCK_TYPE_TEST, /* type */ | 307 | { |
288 | &d2->id.hashPubKey, /*key to search */ | 308 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", |
289 | 4U, /* replication level */ | 309 | GNUNET_h2s_full (&d2->id.hashPubKey)); |
290 | GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ | 310 | get_h_2 = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ |
291 | 0, /* xquery bits */ | 311 | GNUNET_BLOCK_TYPE_TEST, /* type */ |
292 | &dht_get_id_handler, NULL); | 312 | &d2->id.hashPubKey, /*key to search */ |
293 | get_h_far = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | 313 | 4U, /* replication level */ |
294 | GNUNET_BLOCK_TYPE_TEST, /* type */ | 314 | GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ |
295 | &d_far->id.hashPubKey, /*key to search */ | 315 | 0, /* xquery bits */ |
296 | 4U, /* replication level */ | ||
297 | GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ | ||
298 | 0, /* xquery bits */ | ||
299 | &dht_get_id_handler, NULL); | 316 | &dht_get_id_handler, NULL); |
317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", | ||
318 | GNUNET_h2s_full (&d_far->id.hashPubKey)); | ||
319 | get_h_far = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | ||
320 | GNUNET_BLOCK_TYPE_TEST, /* type */ | ||
321 | &d_far->id.hashPubKey, /*key to search */ | ||
322 | 4U, /* replication level */ | ||
323 | GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ | ||
324 | 0, /* xquery bits */ | ||
325 | &dht_get_id_handler, NULL); | ||
326 | } | ||
300 | GNUNET_SCHEDULER_cancel (disconnect_task); | 327 | GNUNET_SCHEDULER_cancel (disconnect_task); |
301 | disconnect_task = | 328 | disconnect_task = |
302 | GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); | 329 | GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); |
303 | } | 330 | } |
304 | 331 | ||
305 | 332 | /** | |
333 | * Task to put the id of each peer into teh DHT. | ||
334 | * | ||
335 | * @param cls Closure (unused) | ||
336 | * @param tc Task context | ||
337 | * | ||
338 | */ | ||
306 | static void | 339 | static void |
307 | put_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 340 | put_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
308 | { | 341 | { |
@@ -324,13 +357,17 @@ put_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
324 | 357 | ||
325 | } | 358 | } |
326 | put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, &put_id, NULL); | 359 | put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, &put_id, NULL); |
360 | if (GNUNET_SCHEDULER_NO_TASK == test_task) | ||
361 | test_task = GNUNET_SCHEDULER_add_now (&do_test, NULL); | ||
327 | } | 362 | } |
328 | 363 | ||
329 | 364 | ||
330 | /** | 365 | /** |
331 | * peergroup_ready: start test when all peers are connected | 366 | * peergroup_ready: start test when all peers are connected |
367 | * | ||
332 | * @param cls closure | 368 | * @param cls closure |
333 | * @param emsg error message | 369 | * @param emsg error message |
370 | * | ||
334 | */ | 371 | */ |
335 | static void | 372 | static void |
336 | peergroup_ready (void *cls, const char *emsg) | 373 | peergroup_ready (void *cls, const char *emsg) |
@@ -377,11 +414,8 @@ peergroup_ready (void *cls, const char *emsg) | |||
377 | hs[i] = GNUNET_DHT_connect (d->cfg, 32); | 414 | hs[i] = GNUNET_DHT_connect (d->cfg, 32); |
378 | } | 415 | } |
379 | 416 | ||
417 | test_task = GNUNET_SCHEDULER_NO_TASK; | ||
380 | put_task = GNUNET_SCHEDULER_add_now (&put_id, NULL); | 418 | put_task = GNUNET_SCHEDULER_add_now (&put_id, NULL); |
381 | test_task = | ||
382 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
383 | (GNUNET_TIME_UNIT_SECONDS, 2), &do_test, | ||
384 | NULL); | ||
385 | disconnect_task = | 419 | disconnect_task = |
386 | GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); | 420 | GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); |
387 | 421 | ||
@@ -444,7 +478,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
444 | ok = 1; | 478 | ok = 1; |
445 | testing_cfg = GNUNET_CONFIGURATION_dup (cfg); | 479 | testing_cfg = GNUNET_CONFIGURATION_dup (cfg); |
446 | 480 | ||
447 | GNUNET_log_setup ("test_dht_2dtorus", | 481 | GNUNET_log_setup ("test_dht_topo", |
448 | #if VERBOSE | 482 | #if VERBOSE |
449 | "DEBUG", | 483 | "DEBUG", |
450 | #else | 484 | #else |
@@ -473,12 +507,12 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
473 | &topology_file)) | 507 | &topology_file)) |
474 | { | 508 | { |
475 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 509 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
476 | "Option test_dht_2d:topology_output_file is required!\n"); | 510 | "Option test_dht_topo:topology_output_file is required!\n"); |
477 | return; | 511 | return; |
478 | } | 512 | } |
479 | 513 | ||
480 | if (GNUNET_OK == | 514 | if (GNUNET_OK == |
481 | GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_dht_2dtorus", | 515 | GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_dht_topo", |
482 | "data_output_file", | 516 | "data_output_file", |
483 | &data_filename)) | 517 | &data_filename)) |
484 | { | 518 | { |
@@ -497,7 +531,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
497 | } | 531 | } |
498 | 532 | ||
499 | if (GNUNET_YES == | 533 | if (GNUNET_YES == |
500 | GNUNET_CONFIGURATION_get_value_string (cfg, "test_dht_2dtorus", | 534 | GNUNET_CONFIGURATION_get_value_string (cfg, "test_dht_topo", |
501 | "output_file", &temp_str)) | 535 | "output_file", &temp_str)) |
502 | { | 536 | { |
503 | output_file = | 537 | output_file = |
@@ -542,7 +576,7 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = { | |||
542 | int | 576 | int |
543 | main (int xargc, char *xargv[]) | 577 | main (int xargc, char *xargv[]) |
544 | { | 578 | { |
545 | char *const argv[] = { "test-dht-2dtorus", | 579 | char *const argv_torus[] = { "test-dht-2dtorus", |
546 | "-c", | 580 | "-c", |
547 | "test_dht_2dtorus.conf", | 581 | "test_dht_2dtorus.conf", |
548 | #if VERBOSE | 582 | #if VERBOSE |
@@ -550,13 +584,41 @@ main (int xargc, char *xargv[]) | |||
550 | #endif | 584 | #endif |
551 | NULL | 585 | NULL |
552 | }; | 586 | }; |
553 | 587 | char *const argv_line[] = { "test-dht-line", | |
554 | GNUNET_PROGRAM_run (sizeof (argv) / sizeof (char *) - 1, argv, | 588 | "-c", |
555 | "test_dht_2dtorus", | 589 | "test_dht_line.conf", |
556 | gettext_noop ("Test dht in a small 2D torus."), options, | 590 | #if VERBOSE |
591 | "-L", "DEBUG", | ||
592 | #endif | ||
593 | NULL | ||
594 | }; | ||
595 | char *const *argv; | ||
596 | int argc; | ||
597 | |||
598 | if (strstr (xargv[0], "test_dht_2dtorus") != NULL) | ||
599 | { | ||
600 | argv = argv_torus; | ||
601 | argc = sizeof (argv_torus) / sizeof (char *); | ||
602 | test_topology = TORUS; | ||
603 | } | ||
604 | else if (strstr (xargv[0], "test_dht_line") != NULL) | ||
605 | { | ||
606 | argv = argv_line; | ||
607 | argc = sizeof (argv_line) / sizeof (char *); | ||
608 | test_topology = LINE; | ||
609 | } | ||
610 | else | ||
611 | { | ||
612 | GNUNET_break (0); | ||
613 | return 1; | ||
614 | } | ||
615 | GNUNET_PROGRAM_run (argc - 1, argv, | ||
616 | xargv[0], | ||
617 | gettext_noop ("Test dht in different topologies."), | ||
618 | options, | ||
557 | &run, NULL); | 619 | &run, NULL); |
558 | #if REMOVE_DIR | 620 | #if REMOVE_DIR |
559 | GNUNET_DISK_directory_remove ("/tmp/test_dht_2dtorus"); | 621 | GNUNET_DISK_directory_remove ("/tmp/test_dht_topo"); |
560 | #endif | 622 | #endif |
561 | if (0 != ok) | 623 | if (0 != ok) |
562 | { | 624 | { |
@@ -565,4 +627,4 @@ main (int xargc, char *xargv[]) | |||
565 | return ok; | 627 | return ok; |
566 | } | 628 | } |
567 | 629 | ||
568 | /* end of test_dht_2dtorus.c */ | 630 | /* end of test_dht_topo.c */ |