Boston, MA 02111-1307, USA.
*/
/**
- * @file testing/test_testing_group.c
- * @brief testcase for functions to connect peers in testing.c
+ * @file testing/test_transport_ats.c
+ * @brief testcase for ats functionality without starting peers
*/
#include "platform.h"
-#include "gnunet_testing_lib.h"
-#include "gnunet_scheduler_lib.h"
+#include "gnunet-service-transport_ats.h"
+#include "gnunet_configuration_lib.h"
+#include "gnunet_crypto_lib.h"
#define VERBOSE GNUNET_YES
-#define NUM_PEERS 4
+static struct ATS_Handle * ats;
-#define DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
+static struct GNUNET_CONFIGURATION_Handle * cfg;
-/**
- * How long until we give up on connecting the peers?
- */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
+static struct TransportConfiguration *tc;
-static int ok;
-static int peers_left;
+static void
+ats_result_cb ()
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ATS Result callback\n");
+}
-static int failed_peers;
+struct TransportConfiguration
+{
+ int peers;
+ int mechanisms;
-static struct GNUNET_TESTING_PeerGroup *pg;
+ struct ATS_peer * p_head;
+ struct ATS_peer * p_tail;
-static GNUNET_SCHEDULER_TaskIdentifier task;
+ struct ATS_mechanism * m_head;
+ struct ATS_mechanism * m_tail;
+};
-/**
- * Check whether peers successfully shut down.
- */
-void
-shutdown_callback (void *cls, const char *emsg)
-{
- if (emsg != NULL)
- {
-#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
-#endif
- if (ok == 0)
- ok = 666;
- }
- else
- {
-#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers successfully shut down!\n");
-#endif
- }
+static void
+create_ats_information (struct ATS_peer **p, int * c_p,
+ struct ATS_mechanism ** m, int * c_m)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ATS needs addresses\n");
+
+ (*p) = tc->p_head;
+ (*c_p) = tc->mechanisms;
+ (*m) = tc->m_head;
+ (*c_m) = tc->mechanisms;
}
-static void shutdown_peers()
+
+static
+int run_ats ()
{
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ int ret = 0;
+ ats_calculate_bandwidth_distribution (ats);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Running ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
+ return ret;
}
-void
-delay_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- task = GNUNET_SCHEDULER_NO_TASK;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
-#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Delay over\n");
-#endif
- shutdown_peers ();
+static int
+init_ats ()
+{
+ int ret = 0;
+ ats = ats_init(1.0, 1.0, 1.0, 50000, 5, 10, ATS_MAX_EXEC_DURATION,
+ create_ats_information,
+ ats_result_cb);
+ //GNUNET_assert (ats != NULL);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Initializing ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
+ return ret;
}
-static void connect_peers()
+
+static int
+shutdown_ats ()
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peers!\n");
+ int ret = 0;
+ ats_delete_problem (ats);
+ ats_shutdown (ats);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Shutdown ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
+ return ret;
+}
- task = GNUNET_SCHEDULER_add_delayed(DELAY, &delay_task, NULL);
+/* To make compiler happy */
+void
+dummy()
+{
+ struct ATS_quality_metric * q = qm;
+ q = NULL;
+ struct ATS_ressource * r = ressources;
+ r = NULL;
+ q++;
+ r++;
+}
- //GNUNET_TESTING_daemons_connect();
- //shutdown_peers();
+static void
+iterate_peer_values (void *cls,
+ const char *section,
+ const char *option,
+ const char *value)
+{
+ if (strcmp (option, "f") == 0)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "\t %s %s\n", option, value);
}
static void
-my_cb (void *cls,
- const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d, const char *emsg)
+iterate_mech_values (void *cls,
+ const char *section,
+ const char *option,
+ const char *value)
{
- if (id == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Start callback called with error (too long starting peers), aborting test!\n");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
- failed_peers++;
- if (failed_peers == peers_left)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Too many peers failed, ending test!\n");
- ok = 1;
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
- }
- return;
- }
+ if (strcmp (option, "f") == 0)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "\t %s %s\n", option, value);
+}
- peers_left--;
- if (peers_left == 0)
+static void
+iterate_sections (void *cls,
+ const char *section)
+{
+ struct TransportConfiguration * tc = cls;
+ /* Peer definition */
+ if (99 == strlen(section))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers started successfully!\n");
- connect_peers();
- ok = 0;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer '%s`\n", section);
+ GNUNET_HashCode h;
+ int res =GNUNET_CRYPTO_hash_from_string(section, &h);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "HASH '%s` %i\n", GNUNET_h2s (&h), res);
+ GNUNET_CONFIGURATION_iterate_section_values(cfg, section, iterate_peer_values, NULL);
+ tc->peers++;
}
- else if (failed_peers == peers_left)
+ if (10 == strlen(section))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Too many peers failed, ending test!\n");
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
- ok = 1;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Mechanism '%s`\n",section);
+ GNUNET_CONFIGURATION_iterate_section_values(cfg, section, iterate_mech_values, NULL);
+ tc->peers++;
}
}
-static void
-run (void *cls,
- char *const *args,
- const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
+static struct TransportConfiguration *
+load_transport_configuration (char * filename)
{
- ok = 1;
-#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting %i peers.\n", NUM_PEERS);
-#endif
- peers_left = NUM_PEERS;
- pg = GNUNET_TESTING_daemons_start (cfg,
- peers_left, /* Total number of peers */
- peers_left, /* Number of outstanding connections */
- peers_left, /* Number of parallel ssh connections, or peers being started at once */
- TIMEOUT,
- NULL, NULL,
- &my_cb, NULL, NULL, NULL, NULL);
- GNUNET_assert (pg != NULL);
+ struct TransportConfiguration * ret = GNUNET_malloc(sizeof (struct TransportConfiguration));
+
+ cfg = GNUNET_CONFIGURATION_create();
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_load(cfg, filename));
+ GNUNET_CONFIGURATION_iterate_sections (cfg, iterate_sections, ret);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ cfg = NULL;
+ return ret;
}
-static int
-check ()
-{
- char *const argv[] = { "test-testing",
- "-c",
- "test_testing_data.conf",
-#if VERBOSE
- "-L", "DEBUG",
-#endif
- NULL
- };
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
- GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-testing-group", "nohelp",
- options, &run, &ok);
- return ok;
-}
int
main (int argc, char *argv[])
{
- int ret;
+ int ret = 0;
- GNUNET_log_setup ("test-testing-group",
+ GNUNET_log_setup ("test-transport-ats",
#if VERBOSE
"DEBUG",
#else
- "WARNING",
+ "INFO",
#endif
NULL);
- ret = check ();
- /**
- * Still need to remove the base testing directory here,
- * because group starts will create subdirectories under this
- * main dir. However, we no longer need to sleep, as the
- * shutdown sequence won't return until everything is cleaned
- * up.
- */
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing");
+ tc = load_transport_configuration ("test_transport_ats.data");
+ ats = NULL;
+ ret += init_ats ();
+ ret += run_ats ();
+ ret += shutdown_ats ();
return ret;
+
}
-/* end of test_testing_group.c */
+/* end of test_transport_ats.c*/