From 84911487a06ec47e58c8b02e1b617805e20613e9 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Tue, 7 Feb 2012 17:14:09 +0000 Subject: [PATCH] - Updated testcase to test for line as well as 2d torus with common code --- src/dht/Makefile.am | 11 +++ src/dht/test_dht_2dtorus.conf | 9 +- src/dht/test_dht_line.conf | 87 +++++++++++++++++ src/dht/test_dht_monitor.c | 4 +- src/dht/test_dht_topo.c | 178 +++++++++++++++++++++++----------- 5 files changed, 225 insertions(+), 64 deletions(-) create mode 100644 src/dht/test_dht_line.conf diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am index 0917297cb..acc81e2b5 100644 --- a/src/dht/Makefile.am +++ b/src/dht/Makefile.am @@ -99,6 +99,7 @@ check_PROGRAMS = \ test_dht_twopeer_get_put \ test_dht_twopeer_path_tracking \ test_dht_multipeer \ + test_dht_line \ test_dht_2dtorus \ test_dht_monitor @@ -109,6 +110,7 @@ TESTS = test_dht_api $(check_SCRIPTS) \ test_dht_twopeer_get_put \ test_dht_twopeer_path_tracking \ test_dht_multipeer \ + test_dht_line \ test_dht_2dtorus \ test_dht_monitor endif @@ -171,6 +173,15 @@ test_dht_2dtorus_LDADD = \ test_dht_2dtorus_DEPENDENCIES = \ libgnunetdht.la +test_dht_line_SOURCES = \ + test_dht_topo.c +test_dht_line_LDADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(top_builddir)/src/testing/libgnunettesting.la \ + $(top_builddir)/src/dht/libgnunetdht.la +test_dht_line_DEPENDENCIES = \ + libgnunetdht.la + test_dht_monitor_SOURCES = test_dht_monitor.c test_dht_monitor_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ diff --git a/src/dht/test_dht_2dtorus.conf b/src/dht/test_dht_2dtorus.conf index 2d0deddbd..d420b29fa 100644 --- a/src/dht/test_dht_2dtorus.conf +++ b/src/dht/test_dht_2dtorus.conf @@ -1,5 +1,5 @@ [PATHS] -SERVICEHOME = /tmp/test_dht_2dtours/ +SERVICEHOME = /tmp/test_dht_topo/ DEFAULTCONFIG = test_dht_2dtours.conf [arm] @@ -51,8 +51,9 @@ PORT = 10004 [testing] NUM_PEERS = 16 WEAKRANDOM = YES -TOPOLOGY = 2D_TORUS -CONNECT_TOPOLOGY = NONE +TOPOLOGY = NONE +CONNECT_TOPOLOGY = 2D_TORUS +BLACKLIST_TOPOLOGY = 2D_TORUS #TOPOLOGY_FILE = small.dat #CONNECT_TOPOLOGY = ERDOS_RENYI #CONNECT_TOPOLOGY_OPTION = CONNECT_MINIMUM @@ -75,7 +76,7 @@ MAX_OUTSTANDING_CONNECTIONS = 75 #NUM_STATISTICS_PER_HOST = 10 DELETE_FILES = YES -[test_dht_2dtorus] +[test_dht_topo] CONNECTION_LIMIT = 16 #DATA_OUTPUT_FILE=data_output diff --git a/src/dht/test_dht_line.conf b/src/dht/test_dht_line.conf new file mode 100644 index 000000000..8bcb12c73 --- /dev/null +++ b/src/dht/test_dht_line.conf @@ -0,0 +1,87 @@ +[PATHS] +SERVICEHOME = /tmp/test_dht_topo/ +DEFAULTCONFIG = test_dht_line.conf + +[arm] +PORT = 10010 +DEFAULTSERVICES = core dht +#DEBUG = YES + +[statistics] +AUTOSTART = YES +PORT = 10000 + +[dht] +DEBUG = NO +AUTOSTART = YES +ACCEPT_FROM6 = ::1; +ACCEPT_FROM = 127.0.0.1; +HOSTNAME = localhost +PORT = 10001 + +[dns] +AUTOSTART = NO +PORT = 10011 + +[transport] +PORT = 10002 +AUTOSTART = YES + +[nat] +DISABLEV6 = YES +BINDTO = 127.0.0.1 +ENABLE_UPNP = NO +BEHIND_NAT = NO +ALLOW_NAT = NO +INTERNAL_ADDRESS = 127.0.0.1 +EXTERNAL_ADDRESS = 127.0.0.1 + +[ats] +WAN_QUOTA_IN = 1 GB +WAN_QUOTA_OUT = 1 GB + +[core] +AUTOSTART = YES +PORT = 10003 + +[peerinfo] +AUTOSTART = YES +PORT = 10004 + +[testing] +NUM_PEERS = 5 +WEAKRANDOM = YES +TOPOLOGY = NONE +CONNECT_TOPOLOGY = LINE +BLACKLIST_TOPOLOGY = LINE +#TOPOLOGY_FILE = small.dat +#CONNECT_TOPOLOGY = ERDOS_RENYI +#CONNECT_TOPOLOGY_OPTION = CONNECT_MINIMUM +#CONNECT_TOPOLOGY_OPTION_MODIFIER = 25 +#PERCENTAGE = 3 +#PROBABILITY = .1 +F2F = NO +CONNECT_TIMEOUT = 60 s +CONNECT_ATTEMPTS = 3 +DEBUG = YES +HOSTKEYSFILE = ../../contrib/testing_hostkeys.dat +MAX_CONCURRENT_SSH = 10 +USE_PROGRESSBARS = YES +PEERGROUP_TIMEOUT = 2400 s +TOPOLOGY_OUTPUT_FILE = line_topo_initial +MAX_OUTSTANDING_CONNECTIONS = 75 +#SINGLE_PEERINFO_PER_HOST = YES +#NUM_PEERINFO_PER_HOST = 10 +#SINGLE_STATISTICS_PER_HOST = YES +#NUM_STATISTICS_PER_HOST = 10 +DELETE_FILES = YES + +[test_dht_topo] +CONNECTION_LIMIT = 5 +#DATA_OUTPUT_FILE=data_output + + +[nse] +WORKDELAY = 500 ms +INTERVAL = 60 s +WORKBITS = 0 diff --git a/src/dht/test_dht_monitor.c b/src/dht/test_dht_monitor.c index 1c91f7ad5..e456ede87 100644 --- a/src/dht/test_dht_monitor.c +++ b/src/dht/test_dht_monitor.c @@ -31,7 +31,7 @@ #include "gnunet_testing_lib.h" #include "gnunet_dht_service.h" -#define VERBOSE 1 +#define VERBOSE GNUNET_YES #define REMOVE_DIR GNUNET_YES @@ -314,7 +314,7 @@ monitor_dht_cb (void *cls, const char *s_key; s_key = GNUNET_h2s(key); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u got a message of type %u for key %s\n", cls, mtype, s_key); 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 @@ /* This file is part of GNUnet. - (C) 2011 Christian Grothoff (and other contributing authors) + (C) 2012 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -18,9 +18,9 @@ Boston, MA 02111-1307, USA. */ /** - * @file dht/test_dht_2dtorus.c + * @file dht/test_dht_topo.c * - * @brief Test for the dht service: store and retrieve in a 2d_torus. + * @brief Test for the dht service: store and retrieve in various topologies. * Each peer stores it own ID in the DHT and then a different peer tries to * retrieve that key from it. The GET starts after a first round of PUTS has * been made. Periodically, each peer stores its ID into the DHT. If after @@ -34,6 +34,11 @@ #define REMOVE_DIR GNUNET_YES +/** + * DIFFERENT TESTS TO RUN + */ +#define LINE 0 +#define TORUS 1 /** * How long until we give up on connecting the peers? @@ -44,6 +49,9 @@ #define PUT_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) +/** + * Result of the test. + */ static int ok; /** @@ -122,6 +130,11 @@ struct GNUNET_DHT_GetHandle *get_h_far; unsigned int found; +/** + * Which topology are we to run + */ +static int test_topology; + /** * Check whether peers successfully shut down. */ @@ -222,7 +235,7 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, GNUNET_i2s (&put_path[i])); } found++; - if (found < 3) + if (TORUS == test_topology && found < 3) return; ok = 0; GNUNET_SCHEDULER_cancel (disconnect_task); @@ -245,36 +258,43 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) unsigned int i; d = d2 = d_far = o = NULL; - for (i = 0; i < num_peers; i++) + if (LINE == test_topology) { - aux = GNUNET_TESTING_daemon_get (pg, i); - id_aux = GNUNET_i2s (&aux->id); - if (strcmp (id_aux, id_origin) == 0) - o = aux; - if (strcmp (id_aux, id_far) == 0) - d_far = aux; - if (strcmp (id_aux, id_near) == 0) - d = aux; - if (strcmp (id_aux, id_near2) == 0) - d2 = aux; + o = GNUNET_TESTING_daemon_get (pg, 0); + d = GNUNET_TESTING_daemon_get (pg, 4); } - if ((NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far)) + else if (TORUS == test_topology) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "test: Peers not found (hostkey file changed?)\n"); - GNUNET_SCHEDULER_cancel (disconnect_task); - disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); - return; + for (i = 0; i < num_peers; i++) + { + aux = GNUNET_TESTING_daemon_get (pg, i); + id_aux = GNUNET_i2s (&aux->id); + if (strcmp (id_aux, id_origin) == 0) + o = aux; + if (strcmp (id_aux, id_far) == 0) + d_far = aux; + if (strcmp (id_aux, id_near) == 0) + d = aux; + if (strcmp (id_aux, id_near2) == 0) + d2 = aux; + } + if ((NULL == o) || (NULL == d) || (NULL == d2) || (NULL == d_far)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "test: Peers not found (hostkey file changed?)\n"); + GNUNET_SCHEDULER_cancel (disconnect_task); + disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); + return; + } } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", - GNUNET_h2s_full (&d->id.hashPubKey)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", - GNUNET_h2s_full (&d2->id.hashPubKey)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", - GNUNET_h2s_full (&d_far->id.hashPubKey)); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: from %s\n", + else + { + GNUNET_assert (0); + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\ntest: from %s\n", GNUNET_h2s_full (&o->id.hashPubKey)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", + GNUNET_h2s_full (&d->id.hashPubKey)); found = 0; get_h = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ GNUNET_BLOCK_TYPE_TEST, /* type */ @@ -283,26 +303,39 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ 0, /* xquery bits */ &dht_get_id_handler, NULL); - get_h_2 = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ - GNUNET_BLOCK_TYPE_TEST, /* type */ - &d2->id.hashPubKey, /*key to search */ - 4U, /* replication level */ - GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ - 0, /* xquery bits */ - &dht_get_id_handler, NULL); - get_h_far = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ - GNUNET_BLOCK_TYPE_TEST, /* type */ - &d_far->id.hashPubKey, /*key to search */ - 4U, /* replication level */ - GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ - 0, /* xquery bits */ + if (TORUS == test_topology) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", + GNUNET_h2s_full (&d2->id.hashPubKey)); + get_h_2 = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ + GNUNET_BLOCK_TYPE_TEST, /* type */ + &d2->id.hashPubKey, /*key to search */ + 4U, /* replication level */ + GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ + 0, /* xquery bits */ &dht_get_id_handler, NULL); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: looking for %s\n", + GNUNET_h2s_full (&d_far->id.hashPubKey)); + get_h_far = GNUNET_DHT_get_start (hs[0], GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ + GNUNET_BLOCK_TYPE_TEST, /* type */ + &d_far->id.hashPubKey, /*key to search */ + 4U, /* replication level */ + GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, NULL, /* xquery */ + 0, /* xquery bits */ + &dht_get_id_handler, NULL); + } GNUNET_SCHEDULER_cancel (disconnect_task); disconnect_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); } - +/** + * Task to put the id of each peer into teh DHT. + * + * @param cls Closure (unused) + * @param tc Task context + * + */ static void put_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { @@ -324,13 +357,17 @@ put_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, &put_id, NULL); + if (GNUNET_SCHEDULER_NO_TASK == test_task) + test_task = GNUNET_SCHEDULER_add_now (&do_test, NULL); } /** * peergroup_ready: start test when all peers are connected + * * @param cls closure * @param emsg error message + * */ static void peergroup_ready (void *cls, const char *emsg) @@ -377,11 +414,8 @@ peergroup_ready (void *cls, const char *emsg) hs[i] = GNUNET_DHT_connect (d->cfg, 32); } + test_task = GNUNET_SCHEDULER_NO_TASK; put_task = GNUNET_SCHEDULER_add_now (&put_id, NULL); - test_task = - GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_SECONDS, 2), &do_test, - NULL); disconnect_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, &disconnect_peers, NULL); @@ -444,7 +478,7 @@ run (void *cls, char *const *args, const char *cfgfile, ok = 1; testing_cfg = GNUNET_CONFIGURATION_dup (cfg); - GNUNET_log_setup ("test_dht_2dtorus", + GNUNET_log_setup ("test_dht_topo", #if VERBOSE "DEBUG", #else @@ -473,12 +507,12 @@ run (void *cls, char *const *args, const char *cfgfile, &topology_file)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Option test_dht_2d:topology_output_file is required!\n"); + "Option test_dht_topo:topology_output_file is required!\n"); return; } if (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_dht_2dtorus", + GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_dht_topo", "data_output_file", &data_filename)) { @@ -497,7 +531,7 @@ run (void *cls, char *const *args, const char *cfgfile, } if (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_string (cfg, "test_dht_2dtorus", + GNUNET_CONFIGURATION_get_value_string (cfg, "test_dht_topo", "output_file", &temp_str)) { output_file = @@ -542,7 +576,7 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = { int main (int xargc, char *xargv[]) { - char *const argv[] = { "test-dht-2dtorus", + char *const argv_torus[] = { "test-dht-2dtorus", "-c", "test_dht_2dtorus.conf", #if VERBOSE @@ -550,13 +584,41 @@ main (int xargc, char *xargv[]) #endif NULL }; - - GNUNET_PROGRAM_run (sizeof (argv) / sizeof (char *) - 1, argv, - "test_dht_2dtorus", - gettext_noop ("Test dht in a small 2D torus."), options, + char *const argv_line[] = { "test-dht-line", + "-c", + "test_dht_line.conf", +#if VERBOSE + "-L", "DEBUG", +#endif + NULL + }; + char *const *argv; + int argc; + + if (strstr (xargv[0], "test_dht_2dtorus") != NULL) + { + argv = argv_torus; + argc = sizeof (argv_torus) / sizeof (char *); + test_topology = TORUS; + } + else if (strstr (xargv[0], "test_dht_line") != NULL) + { + argv = argv_line; + argc = sizeof (argv_line) / sizeof (char *); + test_topology = LINE; + } + else + { + GNUNET_break (0); + return 1; + } + GNUNET_PROGRAM_run (argc - 1, argv, + xargv[0], + gettext_noop ("Test dht in different topologies."), + options, &run, NULL); #if REMOVE_DIR - GNUNET_DISK_directory_remove ("/tmp/test_dht_2dtorus"); + GNUNET_DISK_directory_remove ("/tmp/test_dht_topo"); #endif if (0 != ok) { @@ -565,4 +627,4 @@ main (int xargc, char *xargv[]) return ok; } -/* end of test_dht_2dtorus.c */ +/* end of test_dht_topo.c */ -- 2.25.1