diff options
-rw-r--r-- | src/testbed/Makefile.am | 14 | ||||
-rw-r--r-- | src/testbed/overlay_topology.txt | 5 | ||||
-rw-r--r-- | src/testbed/test_testbed_api_3peers_3controllers.c | 23 | ||||
-rw-r--r-- | src/testbed/test_testbed_api_testbed_run_topologyfromfile.conf | 81 | ||||
-rw-r--r-- | src/testbed/testbed_api_testbed.c | 32 | ||||
-rw-r--r-- | src/testbed/testbed_api_topology.c | 167 |
6 files changed, 311 insertions, 11 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index 7230888dc0..93ea4cf452 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am @@ -97,7 +97,8 @@ check_PROGRAMS = \ test_testbed_api_testbed_run_topologyring \ test_testbed_api_testbed_run_topologysmallworldring \ test_testbed_api_testbed_run_topology2dtorus \ - test_testbed_api_testbed_run_topologysmallworld + test_testbed_api_testbed_run_topologysmallworld \ + test_testbed_api_testbed_run_topologyfromfile if ENABLE_TEST_RUN TESTS = \ @@ -118,7 +119,8 @@ if ENABLE_TEST_RUN test_testbed_api_testbed_run_topologyring \ test_testbed_api_testbed_run_topologysmallworldring \ test_testbed_api_testbed_run_topology2dtorus \ - test_testbed_api_testbed_run_topologysmallworld + test_testbed_api_testbed_run_topologysmallworld \ + test_testbed_api_testbed_run_topologyfromfile endif test_testbed_api_hosts_SOURCES = \ @@ -234,6 +236,12 @@ test_testbed_api_testbed_run_topologysmallworld_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ libgnunettestbed.la +test_testbed_api_testbed_run_topologyfromfile_SOURCES = \ + test_testbed_api_testbed_run.c +test_testbed_api_testbed_run_topologyfromfile_LDADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + libgnunettestbed.la + EXTRA_DIST = \ test_testbed_api.conf \ test_testbed_api_testbed_run_topologyring.conf \ @@ -243,4 +251,6 @@ EXTRA_DIST = \ test_testbed_api_testbed_run_topologysmallworldring.conf \ test_testbed_api_testbed_run_topology2dtorus.conf \ test_testbed_api_testbed_run_topologysmallworld.conf \ + test_testbed_api_testbed_run_topologyfromfile.conf \ + overlay_topology.txt \ sample_hosts.txt
\ No newline at end of file diff --git a/src/testbed/overlay_topology.txt b/src/testbed/overlay_topology.txt new file mode 100644 index 0000000000..420dbb6a6d --- /dev/null +++ b/src/testbed/overlay_topology.txt @@ -0,0 +1,5 @@ + +1:2|3 +3:4| 0| 1 +2: 3|1|0 +0: 2 diff --git a/src/testbed/test_testbed_api_3peers_3controllers.c b/src/testbed/test_testbed_api_3peers_3controllers.c index 48c212401b..3e75469ffd 100644 --- a/src/testbed/test_testbed_api_3peers_3controllers.c +++ b/src/testbed/test_testbed_api_3peers_3controllers.c @@ -232,7 +232,12 @@ enum Stage /** * Final success stage */ - SUCCESS + SUCCESS, + + /** + * Optional stage for marking test to be skipped + */ + SKIP }; /** @@ -874,8 +879,8 @@ run (void *cls, char *const *args, const char *cfgfile, (void) PRINTF ("%s", "Unable to run the test as this system is not configured " "to use password less SSH logins to localhost.\n" - "Marking test as successful\n"); - result = SUCCESS; + "Skipping test\n"); + result = SKIP; return; } cfg = GNUNET_CONFIGURATION_dup (config); @@ -908,9 +913,17 @@ main (int argc, char **argv) GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, "test_testbed_api_3peers_3controllers", "nohelp", options, &run, NULL); - if ((GNUNET_OK != ret) || (SUCCESS != result)) + if (GNUNET_OK != ret) + return 1; + switch (result) + { + case SUCCESS: + return 0; + case SKIP: + return 77; /* Mark test as skipped */ + default: return 1; - return 0; + } } /* end of test_testbed_api_3peers_3controllers.c */ diff --git a/src/testbed/test_testbed_api_testbed_run_topologyfromfile.conf b/src/testbed/test_testbed_api_testbed_run_topologyfromfile.conf new file mode 100644 index 0000000000..9d91b7193e --- /dev/null +++ b/src/testbed/test_testbed_api_testbed_run_topologyfromfile.conf @@ -0,0 +1,81 @@ +[testbed] +AUTOSTART = NO +PORT = 12113 +ACCEPT_FROM = 127.0.0.1; +HOSTNAME = localhost +NEIGHBOUR_LIMIT = 100 +OVERLAY_TOPOLOGY = FROM_FILE +TOPOLOGY_FILE = overlay_topology.txt +PARALLEL_OVERLAY_CONNECT_THRESHOLD = 2 +#PREFIX = xterm -geometry 100x85 -T peer1 -e libtool --mode=execute gdb --args + +[fs] +AUTOSTART = NO + +[resolver] +AUTOSTART = NO + +[mesh] +AUTOSTART = NO + +[dht] +AUTOSTART = NO + +[block] +plugins = dht test + +[dhtcache] +QUOTA = 1 MB +DATABASE = sqlite + +[transport] +PLUGINS = tcp +ACCEPT_FROM6 = ::1; +ACCEPT_FROM = 127.0.0.1; +NEIGHBOUR_LIMIT = 50 +PORT = 12365 + +[ats] +WAN_QUOTA_OUT = 3932160 +WAN_QUOTA_IN = 3932160 + +[core] +PORT = 12092 +AUTOSTART = YES + +[arm] +DEFAULTSERVICES = core transport +PORT = 12366 + +[transport-tcp] +TIMEOUT = 300 s +PORT = 12368 + +[TESTING] +NUM_PEERS = 5 +WEAKRANDOM = YES +HOSTKEYSFILE = ../../contrib/testing_hostkeys.dat +MAX_CONCURRENT_SSH = 10 +USE_PROGRESSBARS = YES +PEERGROUP_TIMEOUT = 2400 s + +[gnunetd] +HOSTKEY = $SERVICEHOME/.hostkey + +[PATHS] +SERVICEHOME = /tmp/test-testbed/ + +[dns] +AUTOSTART = NO + +[nse] +AUTOSTART = NO + +[vpn] +AUTOSTART = NO + +[nat] +RETURN_LOCAL_ADDRESSES = YES + +[gns-helper-service-w32] +AUTOSTART = NO diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c index f99f72f844..f253cf7991 100644 --- a/src/testbed/testbed_api_testbed.c +++ b/src/testbed/testbed_api_testbed.c @@ -182,6 +182,11 @@ struct RunContext struct GNUNET_TESTBED_Operation *topology_operation; /** + * The file containing topology data. Only used if the topology is set to 'FROM_FILE' + */ + char *topo_file; + + /** * The event mask for the controller */ uint64_t event_mask; @@ -320,6 +325,7 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_free (dll_op); } } + GNUNET_free_non_null (rc->topo_file); GNUNET_free (rc); } @@ -458,6 +464,18 @@ call_cc: rc->random_links, GNUNET_TESTBED_TOPOLOGY_OPTION_END); } + else if (GNUNET_TESTBED_TOPOLOGY_FROM_FILE == rc->topology) + { + GNUNET_assert (NULL != rc->topo_file); + rc->topology_operation = + GNUNET_TESTBED_overlay_configure_topology (NULL, + rc->num_peers, + rc->peers, + &rc->num_oc, + rc->topology, + rc->topo_file, + GNUNET_TESTBED_TOPOLOGY_OPTION_END); + } else rc->topology_operation = GNUNET_TESTBED_overlay_configure_topology (NULL, @@ -666,7 +684,7 @@ GNUNET_TESTBED_run (const char *host_filename, if ( (GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI == rc->topology) || (GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING == rc->topology) || (GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD == rc->topology)) - { + { if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testbed", "OVERLAY_RANDOM_LINKS", &random_links)) @@ -685,6 +703,18 @@ GNUNET_TESTBED_run (const char *host_filename, } rc->random_links = (unsigned int) random_links; } + else if (GNUNET_TESTBED_TOPOLOGY_FROM_FILE == rc->topology) + { + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "testbed", + "TOPOLOGY_FILE", + &rc->topo_file)) + { + /* You need to set TOPOLOGY_FILE option to a topolog file */ + GNUNET_break (0); + GNUNET_free (rc); + return; + } + } GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_run_task, rc); } diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c index a49cabd46f..d2ecdf4de6 100644 --- a/src/testbed/testbed_api_topology.c +++ b/src/testbed/testbed_api_topology.c @@ -502,9 +502,6 @@ gen_topo_random (struct TopologyContext *tc, unsigned int links, int append) * "Emergence of Scaling in Random Networks." Science 286, 509-512, 1999. * * @param tc the topology context - * @param links the number of random links to establish - * @param append GNUNET_YES to add links to existing link array; GNUNET_NO to - * create a new link array */ static void gen_scale_free (struct TopologyContext *tc) @@ -547,6 +544,159 @@ gen_scale_free (struct TopologyContext *tc) /** + * Generates topology from the given file + * + * @param tc the topology context + * @param filename the filename of the file containing topology data + */ +static void +gen_topo_from_file (struct TopologyContext *tc, const char *filename) +{ + char *data; + char *end; + char *buf; + uint64_t fs; + uint64_t offset; + unsigned long int peer_id; + unsigned long int other_peer_id; + enum ParseState { + + /** + * We read the peer index + */ + PEER_INDEX, + + /** + * We read the other peer indices + */ + OTHER_PEER_INDEX, + + } state; + int status; + + status = GNUNET_SYSERR; + if (GNUNET_YES != GNUNET_DISK_file_test (filename)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s not found\n"), filename); + return; + } + if (GNUNET_OK != + GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s has no data\n"), filename); + return; + } + data = GNUNET_malloc (fs); + if (fs != GNUNET_DISK_fn_read (filename, data, fs)) + { + LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s cannot be read\n"), + filename); + goto _exit; + } + + offset = 0; + state = PEER_INDEX; + buf = data; + while (offset < fs) + { + if (0 != isspace (data[offset])) + { + offset++; + continue; + } + switch (state) + { + case PEER_INDEX: + buf = strchr (&data[offset], ':'); + if (NULL == buf) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Failed to read peer index from toology file: %s"), filename); + goto _exit; + } + *buf = '\0'; + errno = 0; + peer_id = (unsigned int) strtoul (&data[offset], &end, 10); + if (0 != errno) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Value in given topology file: %s out of range\n"), filename); + goto _exit; + } + if (&data[offset] == end) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Failed to read peer index from topology file: %s"), filename); + goto _exit; + } + if (tc->num_peers <= peer_id) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Topology file need more peers than the given ones\n"), + filename); + goto _exit; + } + state = OTHER_PEER_INDEX; + offset += ((unsigned int) (buf - &data[offset])) + 1; + break; + case OTHER_PEER_INDEX: + errno = 0; + other_peer_id = (unsigned int) strtoul (&data[offset], &end, 10); + if (0 != errno) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Value in given topology file: %s out of range\n"), filename); + goto _exit; + } + if (&data[offset] == end) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Failed to read peer index from topology file: %s"), filename); + goto _exit; + } + if (tc->num_peers <= other_peer_id) + { + LOG (GNUNET_ERROR_TYPE_ERROR, + _("Topology file need more peers than the given ones\n"), + filename); + goto _exit; + } + tc->link_array_size++; + tc->link_array = GNUNET_realloc (tc->link_array, + sizeof (struct OverlayLink) * + tc->link_array_size); + offset += end - &data[offset]; + make_link (&tc->link_array[tc->link_array_size - 1], peer_id, + other_peer_id, tc); + while (('\n' != data[offset]) && ('|' != data[offset]) + && (offset < fs)) + offset++; + if ('\n' == data[offset]) + state = PEER_INDEX; + else if ('|' == data[offset]) + { + state = OTHER_PEER_INDEX; + offset++; + } + break; + } + } + status = GNUNET_OK; + + _exit: + GNUNET_free (data); + if (GNUNET_OK != status) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Removing and link data read from the file\n"); + tc->link_array_size = 0; + GNUNET_free_non_null (tc->link_array); + tc->link_array = NULL; + } +} + + +/** * Configure overall network topology to have a particular shape. * * @param op_cls closure argument to give with the operation event @@ -686,6 +836,15 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: gen_scale_free (tc); break; + case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: + { + const char *filename; + + filename = va_arg (va, const char *); + GNUNET_assert (NULL != filename); + gen_topo_from_file (tc, filename); + } + break; default: GNUNET_break (0); GNUNET_free (tc); @@ -715,6 +874,8 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, GNUNET_TESTBED_operation_queue_insert_ (c->opq_parallel_topology_config_operations, op); GNUNET_TESTBED_operation_begin_wait_ (op); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Generated %u connections\n", tc->link_array_size); if (NULL != max_connections) *max_connections = tc->link_array_size; return op; |