From ce8e0739623ee25d2a29a75f393027a42bbe4d4f Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Wed, 8 Jan 2014 15:02:20 +0000 Subject: [PATCH] - testbed underlay testcase --- src/testbed/Makefile.am | 14 ++- src/testbed/test-underlay.sqlite | Bin 0 -> 3072 bytes src/testbed/test_testbed_underlay.c | 141 ++++++++++++++++++++++ src/testbed/test_testbed_underlay.conf.in | 14 +++ src/testbed/testbed.conf.in | 10 ++ 5 files changed, 177 insertions(+), 2 deletions(-) create mode 100644 src/testbed/test-underlay.sqlite create mode 100644 src/testbed/test_testbed_underlay.c create mode 100644 src/testbed/test_testbed_underlay.conf.in diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index b8e00f90c..823ddaa83 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am @@ -19,6 +19,7 @@ pkgcfg_DATA = \ if HAVE_SQLITE underlay_daemon = gnunet-daemon-testbed-underlay generate_underlay = generate-underlay-topology + underlay_testcases = test_testbed_underlay endif libexec_PROGRAMS = \ @@ -177,7 +178,8 @@ check_PROGRAMS = \ test_testbed_api_testbed_run_waitforever \ test_testbed_api_statistics \ gnunet-service-test-barriers \ - test_testbed_api_barriers + test_testbed_api_barriers \ + $(underlay_testcases) if ENABLE_TEST_RUN TESTS = \ @@ -394,6 +396,12 @@ gnunet_service_test_barriers_LDADD = \ $(top_builddir)/src/util/libgnunetutil.la \ libgnunettestbed.la +test_testbed_underlay_SOURCES = \ + test_testbed_underlay.c +test_testbed_underlay_LDADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + libgnunettestbed.la + EXTRA_DIST = \ test_testbed_api.conf \ test_testbed_api_test_timeout.conf \ @@ -411,4 +419,6 @@ EXTRA_DIST = \ test_testbed_api_barriers.conf.in \ overlay_topology.txt \ sample_hosts.txt \ - sample.job + sample.job \ + test_testbed_underlay.conf.in \ + test-underlay.sqlite diff --git a/src/testbed/test-underlay.sqlite b/src/testbed/test-underlay.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..46f48d9dbf539594e2cdd0318b13ff4066b0d5db GIT binary patch literal 3072 zcmeHGze~eF7`3Ofyj5qk%TsY zO1c2$iya7j7zF;%a|a=~BR`nPPLJ@WY+ + */ + +#include "platform.h" +#include "gnunet_util_lib.h" +#include "gnunet_testbed_service.h" + + +/** + * Number of peers we start in this test case + */ +#define NUM_PEERS 3 + +/** + * Result of this test case + */ +static int result; + +static struct GNUNET_TESTBED_Operation *op; + + +/** + * Callback to be called when an operation is completed + * + * @param cls the callback closure from functions generating an operation + * @param op the operation that has been finished + * @param emsg error message in case the operation has failed; will be NULL if + * operation has executed successfully. + */ +static void +overlay_connect_status (void *cls, + struct GNUNET_TESTBED_Operation *op, + const char *emsg) +{ + GNUNET_TESTBED_operation_done (op); + op = NULL; + if (NULL == emsg) + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Peers 0 and 2 should not get connected\n"); + else + result = GNUNET_OK; + GNUNET_SCHEDULER_shutdown (); +} + + + +/** + * Signature of a main function for a testcase. + * + * @param cls closure + * @param h the run handle + * @param num_peers number of peers in 'peers' + * @param peers_ handle to peers run in the testbed + * @param links_succeeded the number of overlay link connection attempts that + * succeeded + * @param links_failed the number of overlay link connection attempts that + * failed + */ +static void +test_master (void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers_, + unsigned int links_succeeded, + unsigned int links_failed) +{ + GNUNET_assert (NULL == cls); + if (NULL == peers_) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n"); + return; + } + GNUNET_assert (NUM_PEERS == num_peers); + getchar(); + op = GNUNET_TESTBED_overlay_connect (NULL, + &overlay_connect_status, + NULL, + peers_[0], + peers_[2]); +} + + +/** + * Main function + */ +int +main (int argc, char **argv) +{ + struct GNUNET_CONFIGURATION_Handle *cfg; + char pwd[PATH_MAX]; + char *dbfile; + uint64_t event_mask; + + result = GNUNET_SYSERR; + event_mask = 0; + cfg = GNUNET_CONFIGURATION_create (); + GNUNET_assert (GNUNET_YES == + GNUNET_CONFIGURATION_parse (cfg, + "test_testbed_underlay.conf.in")); + if (NULL == getcwd (pwd, PATH_MAX)) + return 1; + GNUNET_assert (0 < GNUNET_asprintf (&dbfile, "%s/%s", pwd, + "test-underlay.sqlite")); + GNUNET_CONFIGURATION_set_value_string (cfg, "TESTBED-UNDERLAY","DBFILE", dbfile); + GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write + (cfg, "test_testbed_underlay.conf")); + GNUNET_CONFIGURATION_destroy (cfg); + cfg = NULL; + GNUNET_free (dbfile); + dbfile = NULL; + (void) GNUNET_TESTBED_test_run ("test_testbed_underlay", + "test_testbed_underlay.conf", NUM_PEERS, + event_mask, NULL, NULL, + &test_master, NULL); + (void) unlink ("test_testbed_underlay.conf"); + if (GNUNET_OK != result) + return 1; + return 0; +} diff --git a/src/testbed/test_testbed_underlay.conf.in b/src/testbed/test_testbed_underlay.conf.in new file mode 100644 index 000000000..647360ec1 --- /dev/null +++ b/src/testbed/test_testbed_underlay.conf.in @@ -0,0 +1,14 @@ +@INLINE@ test_testbed_api_template.conf + +[testbed] +OVERLAY_TOPOLOGY = LINE + +[testbed-underlay] +AUTOSTART = NO +DBFILE = /will/be/overwritten/by/testcase + +[dv] +AUTOSTART = NO + +[arm] +DEFAULTSERVICES = core transport testbed-underlay diff --git a/src/testbed/testbed.conf.in b/src/testbed/testbed.conf.in index 79334c4cd..132480af0 100644 --- a/src/testbed/testbed.conf.in +++ b/src/testbed/testbed.conf.in @@ -100,3 +100,13 @@ HOSTNAME = localhost UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-testbed-barrier.sock UNIX_MATCH_UID = YES UNIX_MATCH_GID = YES + + +# This section is related to configuring underlay restrictions to simulate +# connectivity restrictions of NAT boxes +[testbed-underlay] +AUTOSTART = NO +BINARY = gnunet-daemon-testbed-underlay +# The sqlite3 database file containing information about what underlay +# restrictions to apply +# DBFILE = \ No newline at end of file -- 2.25.1