*/
/**
* @file testing/test_transport_ats.c
- * @brief testcase for ats functionality
+ * @brief testcase for ats functionality without starting peers
*/
#include "platform.h"
-#include "gnunet_testing_lib.h"
-#include "gnunet_transport_service.h"
-#include "gnunet_scheduler_lib.h"
-#include "gauger.h"
+#include "gnunet-service-transport_ats.h"
+#include "gnunet_configuration_lib.h"
+#include "gnunet_crypto_lib.h"
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_YES
-#define NUM_PEERS 11
-#define MEASUREMENTS 5
+static struct ATS_Handle * ats;
+static struct GNUNET_CONFIGURATION_Handle * cfg;
-#define DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
-#define SEND_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
-
-#define ATS_NEW 0
-#define ATS_Q_UPDATED 1
-#define ATS_C_UPDATED 2
-#define ATS_QC_UPDATED 3
-#define ATS_UNMODIFIED 4
-
-static int ok;
-
-static int peers_left;
-
-static int failed_peers;
-
-static int measurement_started = GNUNET_NO;
-
-static struct GNUNET_TESTING_PeerGroup *pg;
-
-static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
-static GNUNET_SCHEDULER_TaskIdentifier stats_task;
-static GNUNET_SCHEDULER_TaskIdentifier send_task;
-struct GNUNET_TESTING_Daemon * master_deamon;
-struct GNUNET_TESTING_Daemon * ping_deamon;
-
-struct GNUNET_STATISTICS_Handle * stats;
-
-struct TEST_result
+void ats_result_cb ()
{
- uint64_t timestamp;
- uint64_t duration;
- uint64_t mechs;
- uint64_t peers;
- uint64_t solution;
- uint64_t state;
-};
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ATS Result callback\n");
+}
-struct TestMessage
+struct TransportConfiguration
{
- struct GNUNET_MessageHeader header;
- uint32_t num;
-};
-
-
-static int count;
-static int c_new;
-static int c_unmodified;
-static int c_modified;
-static int connected;
-static int peers;
-
-static int force_q_updates;
-static int force_rebuild;
-static int send_msg;
+ int peers;
+ int mechanisms;
-static struct TEST_result results_new [MEASUREMENTS+1];
-static struct TEST_result results_modified [MEASUREMENTS+1];
-static struct TEST_result results_unmodified[MEASUREMENTS+1];
-static struct TEST_result current;
+ struct ATS_peer * p_head;
+ struct ATS_peer * p_tail;
-static struct GNUNET_STATISTICS_GetHandle * s_solution;
-static struct GNUNET_STATISTICS_GetHandle * s_time;
-static struct GNUNET_STATISTICS_GetHandle * s_peers;
-static struct GNUNET_STATISTICS_GetHandle * s_mechs;
-static struct GNUNET_STATISTICS_GetHandle * s_duration;
-static struct GNUNET_STATISTICS_GetHandle * s_invalid;
-static struct GNUNET_STATISTICS_GetHandle * s_state;
+ struct ATS_mechanism * m_head;
+ struct ATS_mechanism * m_tail;
+};
-struct GNUNET_TRANSPORT_TransmitHandle * t;
-struct GNUNET_TRANSPORT_Handle * th;
+struct TransportConfiguration *tc;
-/**
- * Check whether peers successfully shut down.
- */
-void
-shutdown_callback (void *cls, const char *emsg)
+/*
+void create_topology (int c_peers, int c_mechanisms)
{
- if (emsg != NULL)
+ int c;
+ peers = GNUNET_malloc ( c_peers * sizeof (struct ATS_peer));
+ for (c=0 ; c<c_peers; c++)
{
-#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
-#endif
- if (ok == 0)
- ok = 666;
+ peers[c].f = 1.0 / c_peers;
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &peers[c].peer.hashPubKey);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer %s \n", GNUNET_i2s (&peers[c].peer));
+ peers[c].m_head = NULL;
+ peers[c].m_tail = NULL;
}
- else
+ mechanisms = GNUNET_malloc ( c_mechanisms * sizeof (struct ATS_mechanism));
+ for (c=0 ; c<c_mechanisms; c++)
{
-#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers successfully shut down!\n");
- if (stats != NULL)
- GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
- stats = NULL;
-#endif
+ mechanisms[c].peer = &peers[c];
}
}
-static void shutdown_peers()
-{
- if (shutdown_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_NO_TASK;
- }
- if (stats_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(stats_task);
- stats_task = GNUNET_SCHEDULER_NO_TASK;
- }
- if (send_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(send_task);
- send_task = GNUNET_SCHEDULER_NO_TASK;
- }
-
- if (t!=NULL)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel(t);
- t = NULL;
- }
-
- GNUNET_TRANSPORT_disconnect(th);
-
- if (s_time != NULL)
- {
- GNUNET_STATISTICS_get_cancel(s_time);
- s_time = NULL;
- }
- if (s_peers != NULL)
- {
- GNUNET_STATISTICS_get_cancel(s_peers);
- s_peers = NULL;
- }
- if (s_mechs != NULL)
- {
- GNUNET_STATISTICS_get_cancel(s_mechs);
- s_mechs = NULL;
- }
- if (s_solution != NULL)
- {
- GNUNET_STATISTICS_get_cancel(s_solution);
- s_solution = NULL;
- }
- if (s_duration != NULL)
- {
- GNUNET_STATISTICS_get_cancel(s_duration);
- s_duration = NULL;
- }
- if (s_invalid != NULL)
- {
- GNUNET_STATISTICS_get_cancel(s_invalid);
- s_invalid = NULL;
- }
- if (s_state != NULL)
- {
- GNUNET_STATISTICS_get_cancel(s_state);
- s_state = NULL;
- }
-
- GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
-}
-static void evaluate_measurements()
+void delete_topology (void)
{
- int c;
- double average ;
- double stddev;
-
- c = 1;
-
- average = 0.0;
- for (c=0; c<c_new;c++)
- {
- average += (double) results_new[c].duration;
- }
- average /= c_new;
-
- stddev = 0.0;
- for (c=0; c<c_new;c++)
- {
- stddev += (results_new[c].duration - average) * (results_new[c].duration - average);
- }
- stddev /= c_new;
- stddev = sqrt (stddev);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"new average: %f stddev: %f\n", average, stddev);
-
- average = 0.0;
- for (c=0; c<c_modified;c++)
- {
- average += (double) results_modified[c].duration;
- }
- average /= c_modified;
-
- stddev = 0.0;
- for (c=0; c<c_modified;c++)
- {
- stddev += (results_modified[c].duration - average) * (results_modified[c].duration - average);
- }
- stddev /= c_modified;
- stddev = sqrt (stddev);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"modified average: %f stddev: %f\n", average, stddev);
-
- average = 0.0;
- for (c=0; c<c_unmodified;c++)
- {
- average += (double) results_unmodified[c].duration;
- }
- average /= c_unmodified;
- stddev = 0.0;
- for (c=0; c<c_unmodified;c++)
- {
- stddev += (results_unmodified[c].duration - average) * (results_unmodified[c].duration - average);
- }
- stddev /= c_unmodified;
- stddev = sqrt (stddev);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"unmodified average: %f stddev: %f\n", average, stddev);
-
-
-
-
-
- shutdown_peers();
-}
+ GNUNET_free (peers);
+ GNUNET_free (mechanisms);
+}*/
-int stats_cb (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
+
+void create_ats_information (struct ATS_peer **p, int * c_p,
+ struct ATS_mechanism ** m, int * c_m)
{
- static int printed = GNUNET_NO;
- //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s = %llu\n", name ,value);
- if (0 == strcmp (name,"ATS invalid solutions"))
- {
- if (stats_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(stats_task);
- stats_task = GNUNET_SCHEDULER_NO_TASK;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"MLP produced invalid %llu result(s)!\n", value);
- shutdown_peers();
- return GNUNET_SYSERR;
- }
-
- if (0 == strcmp (name,"ATS solution"))
- {
- s_solution = NULL;
- }
-
- if (0 == strcmp (name,"ATS peers"))
- {
- s_peers = NULL;
- }
-
- if (0 == strcmp (name,"ATS mechanisms"))
- {
- s_mechs = NULL;
- }
-
- if (0 == strcmp (name,"ATS duration"))
- {
- s_duration = NULL;
- }
- if (0 == strcmp (name,"ATS timestamp"))
- {
- s_time = NULL;
- }
- if (0 == strcmp (name,"ATS state"))
- {
- s_state = NULL;
- }
-
- if ((measurement_started == GNUNET_NO) && (0 == strcmp (name, "ATS peers")) && (value == peers-1))
- {
- measurement_started = GNUNET_YES;
- count = 1;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All %llu peers connected\n", value);
- }
- if (measurement_started == GNUNET_YES)
- {
- // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s == %llu\n", name ,value);
- if (0 == strcmp (name,"ATS timestamp"))
- {
- if (current.timestamp == 0)
- {
- printed = GNUNET_NO;
- current.timestamp = value;
- }
- if (current.timestamp == value)
- {
- printed = GNUNET_YES;
- }
- if (current.timestamp != value)
- {
- if (current.state == ATS_NEW)
- {
- if (c_new < MEASUREMENTS)
- {
- results_new[c_new] = current;
- c_new++;
- }
- else
- {
- force_rebuild = GNUNET_NO;
- force_q_updates = GNUNET_NO;
- send_msg = GNUNET_NO;
- }
- }
- if (current.state == ATS_UNMODIFIED)
- {
- if (c_unmodified < MEASUREMENTS)
- {
- results_unmodified[c_unmodified] = current;
- c_unmodified++;
- }
-
- }
- if (current.state == ATS_Q_UPDATED)
- {
- if (c_modified < MEASUREMENTS)
- {
- results_modified[c_modified] = current;
- c_modified++;
- }
- else
- {
- force_q_updates = GNUNET_NO;
- force_rebuild = GNUNET_YES;
- }
- }
- count ++;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(new: %i / modified: %i / unmodified: %i) of %i \n", c_new, c_modified, c_unmodified , MEASUREMENTS);
- if ((count > MEASUREMENTS * 4) || ((c_modified >= MEASUREMENTS) && (c_new >= MEASUREMENTS) && (c_unmodified >= MEASUREMENTS)))
- {
- fprintf(stdout, "\n");
- if (stats_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel(stats_task);
- stats_task = GNUNET_SCHEDULER_NO_TASK;
- }
- evaluate_measurements();
- return GNUNET_SYSERR;
- }
-
- printed = GNUNET_NO;
- current.timestamp = value;
- return GNUNET_OK;
- }
- }
-
- if (0 == strcmp (name,"ATS solution"))
- {
- current.solution = value;
- if (printed == GNUNET_NO) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n", count, name, value);
- }
-
- if (0 == strcmp (name,"ATS peers"))
- {
- current.peers = value;
- if (printed == GNUNET_NO) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n", count, name, value);
- }
-
- if (0 == strcmp (name,"ATS mechanisms"))
- {
- current.mechs = value;
- if (printed == GNUNET_NO) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n", count, name, value);
- }
-
- if (0 == strcmp (name,"ATS duration"))
- {
- current.duration = value;
- if (printed == GNUNET_NO) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n", count, name, value);
- }
- if (0 == strcmp (name,"ATS state"))
- {
- current.state = value;
- char * cont;
- if (value == ATS_NEW)
- cont = "NEW";
- if (value == ATS_C_UPDATED)
- cont = "C_UPDATED";
- if (value == ATS_Q_UPDATED)
- cont = "Q_UPDATED";
- if (value == ATS_QC_UPDATED)
- cont = "QC_UPDATED";
- if (value == ATS_UNMODIFIED)
- cont = "UNMODIFIED";
- if (printed == GNUNET_NO) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] ATS state: %s\n", count, cont);
- }
- }
- return GNUNET_OK;
-}
+ 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;
-void
-stats_get_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- stats_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
-
- s_time = GNUNET_STATISTICS_get (stats, "transport", "ATS timestamp", TIMEOUT, NULL, &stats_cb, NULL);
- s_solution = GNUNET_STATISTICS_get (stats, "transport", "ATS solution", TIMEOUT, NULL, &stats_cb, NULL);
- s_duration = GNUNET_STATISTICS_get (stats, "transport","ATS duration", TIMEOUT, NULL, &stats_cb, NULL);
- s_peers = GNUNET_STATISTICS_get (stats, "transport", "ATS peers", TIMEOUT, NULL, &stats_cb, NULL);
- s_mechs = GNUNET_STATISTICS_get (stats, "transport", "ATS mechanisms", TIMEOUT, NULL, &stats_cb, NULL);
- s_invalid = GNUNET_STATISTICS_get (stats, "transport", "ATS invalid solutions", TIMEOUT, NULL, &stats_cb, NULL);
- s_state = GNUNET_STATISTICS_get (stats, "transport", "ATS state", TIMEOUT, NULL, &stats_cb, NULL);
-
- stats_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250), &stats_get_task, NULL);
}
-void
-delay (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+int run_ats (void)
{
- shutdown_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");
+ int ret = 0;
+#if HAVE_LIBGLPK
+ ats_calculate_bandwidth_distribution (ats);
#endif
- shutdown_peers ();
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Running ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
+ return ret;
}
-static void connect_peers()
+int init_ats (void)
{
- shutdown_task = GNUNET_SCHEDULER_add_delayed(DELAY, &delay, NULL);
+ int ret = 0;
+#if HAVE_LIBGLPK
+ ats = ats_init(1.0, 1.0, 1.0, 50000, 5, 10, ATS_MAX_EXEC_DURATION,
+ create_ats_information,
+ ats_result_cb);
+#endif
+ //GNUNET_assert (ats != NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Initializing ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
+ return ret;
}
-size_t send_dummy_data_task (void *cls, size_t size, void *buf)
-{
-
- int s = sizeof (struct TestMessage);
- struct TestMessage hdr;
-
- hdr.header.size = htons (s);
- hdr.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ATS);
- if (force_rebuild)
- hdr.num = htonl (1);
- if (force_q_updates)
- hdr.num = htonl (2);
-
- memcpy (buf,&hdr, s);
- // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sent bytes: %i of %i\n", s, s);
- t = NULL;
- return s;
+int shutdown_ats (void)
+{
+ int ret = 0;
+#if HAVE_LIBGLPK
+ ats_delete_problem (ats);
+ ats_shutdown (ats);
+#endif
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Shutdown ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
+ return ret;
}
-void send_task_f (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+/* To make compiler happy */
+void dummy(void)
{
- send_task = GNUNET_SCHEDULER_NO_TASK;
- if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
-
- if (t!=NULL)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel(t);
- t = NULL;
- }
- // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sent bytes: %i to %s\n", size, GNUNET_i2s(&master_deamon->id));
- if (send_msg == GNUNET_YES)
- t = GNUNET_TRANSPORT_notify_transmit_ready(th, &master_deamon->id, sizeof (struct TestMessage), 0, SEND_TIMEOUT, &send_dummy_data_task, NULL);
- send_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,1000), &send_task_f, NULL);
+ struct ATS_quality_metric * q = qm;
+ q = NULL;
+ struct ATS_ressource * r = ressources;
+ r = NULL;
}
-
-
-void daemon_connect_cb(void *cls,
- const struct GNUNET_PeerIdentity *first,
- const struct GNUNET_PeerIdentity *second,
- uint32_t distance,
- const struct GNUNET_CONFIGURATION_Handle *first_cfg,
- const struct GNUNET_CONFIGURATION_Handle *second_cfg,
- struct GNUNET_TESTING_Daemon *first_daemon,
- struct GNUNET_TESTING_Daemon *second_daemon,
- const char *emsg)
+void iterate_peer_values (void *cls,
+ const char *section,
+ const char *option,
+ const char *value)
{
- char * firstc = strdup(GNUNET_i2s(first));
- char * secondc = strdup(GNUNET_i2s(second));
- connected++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected peers `%s'<->`%s' (%i/%i)\n", firstc, secondc, connected, peers-1);
- GNUNET_free(firstc);
- GNUNET_free(secondc);
-
- if (((first_daemon == ping_deamon) || (second_daemon == ping_deamon)) && (master_deamon != NULL) && (ping_deamon != NULL))
- {
- th = GNUNET_TRANSPORT_connect (ping_deamon->cfg,&ping_deamon->id, NULL, NULL,NULL, NULL);
- t = NULL;
- force_q_updates = GNUNET_YES;
- send_msg = GNUNET_YES;
- send_task = GNUNET_SCHEDULER_add_now(&send_task_f, NULL);
- }
+ if (strcmp (option, "f") == 0)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "\t %s %s\n", option, value);
}
-void cont_cb (void *cls, int success)
+void iterate_mech_values (void *cls,
+ const char *section,
+ const char *option,
+ const char *value)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "STATS cont_cb: %i\n", success);
+ if (strcmp (option, "f") == 0)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "\t %s %s\n", option, value);
}
-static void
-daemon_start_cb (void *cls,
- const struct GNUNET_PeerIdentity *id,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Daemon *d, const char *emsg)
+void iterate_sections (void *cls,
+ const char *section)
{
- if (id == NULL)
+ struct TransportConfiguration * tc = cls;
+ /* Peer definition */
+ if (99 == strlen(section))
{
- 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;
- shutdown_peers ();
- }
- return;
+ 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++;
}
- peers_left--;
-
- if (master_deamon == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Master peer `%s' '%s'\n", GNUNET_i2s(id), d->cfgfile);
-
- master_deamon = d;
- stats = GNUNET_STATISTICS_create("transport", master_deamon->cfg);
- GNUNET_assert (stats != NULL);
- stats_task = GNUNET_SCHEDULER_add_now(&stats_get_task, NULL);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer `%s'\n", GNUNET_i2s(id), GNUNET_i2s(&master_deamon->id));
- GNUNET_TESTING_daemons_connect(d, master_deamon, TIMEOUT, 0, GNUNET_YES,&daemon_connect_cb, NULL);
- }
-
- if (peers_left == 0)
+ if (10 == strlen(section))
{
- if (ping_deamon == NULL)
- {
- ping_deamon = d;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ping peer `%s' '%s'\n", GNUNET_i2s(id), d->cfgfile);
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers started successfully!\n");
- connect_peers();
- ok = 0;
- }
- else if (failed_peers == peers_left)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Too many peers failed, ending test!\n");
- shutdown_peers();
- 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)
+void destroy_transport_configuration (char * filename)
{
- ok = 1;
- measurement_started = GNUNET_NO;
-#if VERBOSE
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting %i peers.\n", peers);
-#endif
- peers_left = 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,
- &daemon_start_cb, NULL, NULL, NULL, NULL);
- GNUNET_assert (pg != NULL);
+ GNUNET_CONFIGURATION_destroy (cfg);
+
}
-static int
-check ()
+struct TransportConfiguration * load_transport_configuration (char * filename)
{
- char *const argv[] = { "test-testing",
- "-c",
- "test_transport_ats.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-transport-ats", "nohelp",
- options, &run, &ok);
- return ok;
+ struct TransportConfiguration * ret = GNUNET_malloc(sizeof (struct TransportConfiguration));
+ cfg = GNUNET_CONFIGURATION_create();
+ GNUNET_CONFIGURATION_load(cfg, filename);
+ GNUNET_CONFIGURATION_iterate_sections(cfg, iterate_sections, ret);
+
+ return ret;
}
int
main (int argc, char *argv[])
{
-#if !HAVE_LIBGLPK
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed, exiting testcase\n");
- return 0;
-#endif
-
- int ret;
+ int ret = 0;
GNUNET_log_setup ("test-transport-ats",
#if VERBOSE
"INFO",
#endif
NULL);
- GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing");
-
- peers = NUM_PEERS;
- if (argc == 2)
- {
- peers = atoi(argv[1]);
- peers++;
- }
-
- 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");
+#if !HAVE_LIBGLPK
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "HAVE_LIBGLPK not set, exiting testcase\n");
+#endif
+
+#if !HAVE_LIBGLPK
+ return ret;
+#endif
+
+ return 0;
+
+ tc = load_transport_configuration ("test.ats");
+
return ret;
+
+ /* Testing */
+ ats = NULL;
+
+ ret += init_ats ();
+ ret += run_ats ();
+ ret += shutdown_ats ();
+
+ /* Shutdown */
+ return ret;
+
}
/* end of test_transport_ats.c*/