wip
[oweals/gnunet.git] / src / transport / test_transport_ats.c
index 2d3321a9e59a72be8e5ecad2f5e203d68f845d99..55bc7e78030331579ffcbae8b1bc5411d84a22c4 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2009, 2010 Christian Grothoff (and other contributing authors)
+     (C) 2009 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
      Boston, MA 02111-1307, USA.
 */
 /**
- * @file transport/test_transport_ats.c
- * @brief base test case for transport implementations
- *
- * This test case serves as a base for tcp, udp, and udp-nat
- * transport test cases.  Based on the executable being run
- * the correct test case will be performed.  Conservation of
- * C code apparently.
+ * @file testing/test_transport_ats.c
+ * @brief testcase for ats functionality
  */
 #include "platform.h"
-#include "gnunet_common.h"
-#include "gnunet_hello_lib.h"
-#include "gnunet_getopt_lib.h"
-#include "gnunet_os_lib.h"
-#include "gnunet_program_lib.h"
-#include "gnunet_scheduler_lib.h"
+#include "gnunet_testing_lib.h"
 #include "gnunet_transport_service.h"
-#include "transport.h"
+#include "gnunet_scheduler_lib.h"
+#include "gauger.h"
 
 #define VERBOSE GNUNET_NO
 
-#define VERBOSE_ARM GNUNET_NO
-
-#define START_ARM GNUNET_YES
-
-/**
- * How long until we give up on transmitting the message?
- */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90)
-
-/**
- * How long until we give up on transmitting the message?
- */
-#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+#define NUM_PEERS 11
+#define MEASUREMENTS 5
 
-#define MTYPE 12345
+#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)
 
-struct PeerContext
-{
-  struct GNUNET_CONFIGURATION_Handle *cfg;
-  struct GNUNET_TRANSPORT_Handle *th;
-  struct GNUNET_PeerIdentity id;
-#if START_ARM
-  struct GNUNET_OS_Process *arm_proc;
-#endif
-};
+#define ATS_NEW 0
+#define ATS_Q_UPDATED 1
+#define ATS_C_UPDATED 2
+#define ATS_QC_UPDATED 3
+#define ATS_UNMODIFIED 4
 
-static struct PeerContext p1;
+static int ok;
 
-static struct PeerContext p2;
+static int peers_left;
 
-static int ok;
+static int failed_peers;
 
-static int is_tcp;
+static int measurement_started = GNUNET_NO;
+static char * config_file;
 
-static int is_tcp_nat;
+static struct GNUNET_TESTING_PeerGroup *pg;
 
-static int is_udp;
+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;
 
-static int is_unix;
+struct GNUNET_STATISTICS_Handle * stats;
 
-static int is_udp_nat;
+struct TEST_result
+{
+       uint64_t timestamp;
+       uint64_t duration;
+       uint64_t mechs;
+       uint64_t peers;
+       uint64_t solution;
+       uint64_t state;
+};
 
-static int is_http;
+struct TestMessage
+{
+  struct GNUNET_MessageHeader header;
+  uint32_t num;
+};
 
-static int is_https;
 
-static int is_multi_protocol;
+static int count;
+static int c_new;
+static int c_unmodified;
+static int c_modified;
+static int connected;
+static int peers;
 
-static int is_wlan;
+static int force_q_updates;
+static int force_rebuild;
+static int send_msg;
+static int machine_parsable;
 
-static  GNUNET_SCHEDULER_TaskIdentifier die_task;
+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;
 
-static char * key_file_p1;
-static char * cert_file_p1;
+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;
 
-static char * key_file_p2;
-static char * cert_file_p2;
+struct GNUNET_TRANSPORT_TransmitHandle * t;
+struct GNUNET_TRANSPORT_Handle * th;
 
+/**
+ * Check whether peers successfully shut down.
+ */
+void
+shutdown_callback (void *cls, const char *emsg)
+{
+  if (emsg != NULL)
+    {
 #if VERBOSE
-#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
-#else
-#define OKPP do { ok++; } while (0)
+      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");
+       if (stats != NULL)
+               GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
+       stats = NULL;
+#endif
+    }
+}
 
+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
-end ()
+static void evaluate_measurements()
 {
-  /* do work here */
-  GNUNET_assert (ok == 6);
-  GNUNET_SCHEDULER_cancel (die_task);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
-  GNUNET_TRANSPORT_disconnect (p1.th);
-  GNUNET_TRANSPORT_disconnect (p2.th);
-
-  die_task = GNUNET_SCHEDULER_NO_TASK;
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transports disconnected, returning success!\n");
-  ok = 0;
+       int c;
+       //int mechs = 0;
+       double average[3];
+       double stddev[3];
+       //char * output;
+       c = 1;
+
+       //GNUNET_asprintf(&output, "p,%i,m,%i,",peers, MEASUREMENTS, results_modified[0].mechs,
+
+       average[0] = 0.0;
+       for (c=0; c<c_new;c++)
+       {
+               average[0] += (double) results_new[c].duration;
+       }
+       average[0] /= c_new;
+
+       stddev[0] = 0.0;
+       for (c=0; c<c_new;c++)
+       {
+               stddev[0] += (results_new[c].duration - average[0]) * (results_new[c].duration - average[0]);
+       }
+       stddev[0] /= c_new;
+       stddev[0] = sqrt (stddev[0]);
+       if (!machine_parsable) GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"new, %i measurements, average: %f stddev: %f\n",
+                       c_new, average[0], stddev[0]);
+
+       average[1] = 0.0;
+       for (c=0; c<c_modified;c++)
+       {
+               average[1] += (double) results_modified[c].duration;
+       }
+       average[1] /= c_modified;
+
+       stddev[1] = 0.0;
+       for (c=0; c<c_modified;c++)
+       {
+               stddev[1] += (results_modified[c].duration - average[1]) * (results_modified[c].duration - average[1]);
+       }
+       stddev[1] /= c_modified;
+       stddev[1] = sqrt (stddev[1]);
+       if (!machine_parsable) GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"modified, %i measurements, average: %f stddev: %f\n",
+                       c_modified, average[1], stddev[1]);
+
+       average[2] = 0.0;
+       for (c=0; c<c_unmodified;c++)
+       {
+               average[2] += (double) results_unmodified[c].duration;
+       }
+       average[2] /= c_unmodified;
+       stddev[2] = 0.0;
+       for (c=0; c<c_unmodified;c++)
+       {
+               stddev[2] += (results_unmodified[c].duration - average[2]) * (results_unmodified[c].duration - average[2]);
+       }
+       stddev[2] /= c_unmodified;
+       stddev[2] = sqrt (stddev[2]);
+
+       if (!machine_parsable) GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"unmodified, %i measurements, average: %f stddev: %f\n",
+                       c_unmodified, average[2], stddev[2]);
+
+       if (machine_parsable)
+               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,",peers,%i,mechs,%i,"
+                                       "new,%i,%f,%f,"
+                                       "mod,%i,%f,%f,"
+                                       "unmod,%i,%f,%f\n",
+                                       peers-1, results_unmodified[0].mechs,
+                                       c_new, average[0], stddev[0],
+                                       c_modified, average[1], stddev[1],
+                                       c_unmodified, average[2], stddev[2]);
+       shutdown_peers();
 }
 
-static void
-stop_arm (struct PeerContext *p)
+int stats_cb (void *cls,
+                          const char *subsystem,
+                          const char *name,
+                          uint64_t value,
+                          int is_persistent)
 {
-#if START_ARM
-  if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
-    GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
-  GNUNET_OS_process_wait (p->arm_proc);
-  GNUNET_OS_process_close (p->arm_proc);
-  p->arm_proc = NULL;
+       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 !VERBOSE
+               if (!machine_parsable)  fprintf(stderr, "%i", count);
+#endif
+    }
+
+    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 ((c_modified >= MEASUREMENTS) && (c_new >= MEASUREMENTS) && (c_unmodified >= MEASUREMENTS))
+                               {
+#if !VERBOSE
+                                       if (!machine_parsable) fprintf(stdout, "\n");
+#endif
+                                       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;
+#if !VERBOSE
+                               if (!machine_parsable) fprintf(stderr, "..%i", count);
 #endif
-  GNUNET_CONFIGURATION_destroy (p->cfg);
+                               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;
 }
 
 
-static void
-end_badly ()
+void
+stats_get_task (void *cls,
+                         const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
-  GNUNET_break (0);
-  GNUNET_TRANSPORT_disconnect (p1.th);
-  GNUNET_TRANSPORT_disconnect (p2.th);
-  ok = 1;
+       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, 100), &stats_get_task, NULL);
 }
 
-static void
-notify_receive (void *cls,
-                const struct GNUNET_PeerIdentity *peer,
-                const struct GNUNET_MessageHeader *message,
-                const struct GNUNET_TRANSPORT_ATS_Information *ats,
-                uint32_t ats_count)
+void
+delay (void *cls,
+                         const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ok is (%d)!\n",
-              ok);
+       shutdown_task = GNUNET_SCHEDULER_NO_TASK;
+       if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
+           return;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %d from peer (%p)!\n",
-                ntohs(message->type), cls);
+#if VERBOSE
+       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Delay over\n");
+#endif
+       shutdown_peers ();
+}
 
-  GNUNET_assert (ok == 5);
-  OKPP;
+static void connect_peers()
+{
+    shutdown_task = GNUNET_SCHEDULER_add_delayed(DELAY, &delay, NULL);
 
-  GNUNET_assert (MTYPE == ntohs (message->type));
-  GNUNET_assert (sizeof (struct GNUNET_MessageHeader) ==
-                 ntohs (message->size));
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message from peer (%p)!\n",
-              cls);
-  end ();
 }
 
-
-static size_t
-notify_ready (void *cls, size_t size, void *buf)
+size_t send_dummy_data_task (void *cls, size_t size, void *buf)
 {
-  struct GNUNET_MessageHeader *hdr;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Transmitting message to peer (%p) - %u!\n", cls, sizeof (struct GNUNET_MessageHeader));
-  GNUNET_assert (size >= 256);
-  GNUNET_assert (ok == 4);
-  OKPP;
+       int s = sizeof (struct TestMessage);
+       struct TestMessage hdr;
 
-  if (buf != NULL)
-  {
-    hdr = buf;
-    hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
-    hdr->type = htons (MTYPE);
-  }
+       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);
 
-  return sizeof (struct GNUNET_MessageHeader);
+
+       memcpy (buf,&hdr, s);
+       // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sent bytes: %i of %i\n", s, s);
+       t  = NULL;
+       return s;
 }
 
-static size_t
-notify_ready_connect (void *cls, size_t size, void *buf)
+void send_task_f (void *cls,
+                         const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  return 0;
+       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);
 }
 
 
-static void
-notify_connect (void *cls,
-                const struct GNUNET_PeerIdentity *peer,
-                const struct GNUNET_TRANSPORT_ATS_Information *ats,
-                uint32_t ats_count)
+
+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)
 {
-  if (cls == &p1)
-    {
-      GNUNET_SCHEDULER_cancel (die_task);
-      die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT,
-                                              &end_badly, NULL);
-
-      GNUNET_TRANSPORT_notify_transmit_ready (p1.th,
-                                             &p2.id,
-                                             256, 0, TIMEOUT, &notify_ready,
-                                             &p1);
-    }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
+       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);
+       }
 }
 
-
-static void
-notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
+void cont_cb (void *cls, int success)
 {
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Peer `%4s' disconnected (%p)!\n",
-             GNUNET_i2s (peer), cls);
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "STATS cont_cb: %i\n", success);
 }
 
-
 static void
-setup_peer (struct PeerContext *p, const char *cfgname)
+daemon_start_cb (void *cls,
+       const struct GNUNET_PeerIdentity *id,
+       const struct GNUNET_CONFIGURATION_Handle *cfg,
+       struct GNUNET_TESTING_Daemon *d, const char *emsg)
 {
-  p->cfg = GNUNET_CONFIGURATION_create ();
-#if START_ARM
-  p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
-                                        "gnunet-service-arm",
-#if VERBOSE_ARM
-                                        "-L", "DEBUG",
-#endif
-                                        "-c", cfgname, NULL);
-#endif
-  GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
+  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;
+       shutdown_peers ();
+        }
+      return;
+    }
+  peers_left--;
 
-  if (is_https)
+  if (master_deamon == NULL)
   {
-         struct stat sbuf;
-         if (p==&p1)
-         {
-                 if (GNUNET_CONFIGURATION_have_value (p->cfg,
-                                                                                          "transport-https", "KEY_FILE"))
-                               GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p1);
-                 if (key_file_p1==NULL)
-                         GNUNET_asprintf(&key_file_p1,"https.key");
-                 if (0 == stat (key_file_p1, &sbuf ))
-                 {
-                         if (0 == remove(key_file_p1))
-                             GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing private key file `%s'\n",key_file_p1);
-                         else
-                                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove private key file `%s'\n",key_file_p1);
-                 }
-                 if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE"))
-                         GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p1);
-                 if (cert_file_p1==NULL)
-                         GNUNET_asprintf(&cert_file_p1,"https.cert");
-                 if (0 == stat (cert_file_p1, &sbuf ))
-                 {
-                         if (0 == remove(cert_file_p1))
-                             GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing certificate file `%s'\n",cert_file_p1);
-                         else
-                                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove existing certificate file `%s'\n",cert_file_p1);
-                 }
-         }
-         else if (p==&p2)
-         {
-                 if (GNUNET_CONFIGURATION_have_value (p->cfg,
-                                                                                          "transport-https", "KEY_FILE"))
-                               GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p2);
-                 if (key_file_p2==NULL)
-                         GNUNET_asprintf(&key_file_p2,"https.key");
-                 if (0 == stat (key_file_p2, &sbuf ))
-                 {
-                         if (0 == remove(key_file_p2))
-                             GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing private key file `%s'\n",key_file_p2);
-                         else
-                                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove private key file `%s'\n",key_file_p2);
-                 }
-                 if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE"))
-                         GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p2);
-                 if (cert_file_p2==NULL)
-                         GNUNET_asprintf(&cert_file_p2,"https.cert");
-                 if (0 == stat (cert_file_p2, &sbuf ))
-                 {
-                         if (0 == remove(cert_file_p2))
-                             GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing certificate file `%s'\n",cert_file_p2);
-                         else
-                                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove existing certificate file `%s'\n",cert_file_p2);
-                 }
-         }
-  }
-
-  p->th = GNUNET_TRANSPORT_connect (p->cfg,
-                                    NULL, p,
-                                    &notify_receive,
-                                    &notify_connect, &notify_disconnect);
-  GNUNET_assert (p->th != 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);
+  }
 
-static void
-exchange_hello_last (void *cls,
-                     const struct GNUNET_MessageHeader *message)
-{
-  struct PeerContext *me = cls;
-
-  GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, me);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Exchanging HELLO with peer (%p)!\n", cls);
-  GNUNET_assert (ok >= 3);
-  OKPP;
-  GNUNET_assert (message != NULL);
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
-                                      message, &me->id));
-
-  GNUNET_assert(NULL != GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
-                                          &p1.id,
-                                          sizeof (struct GNUNET_MessageHeader), 0,
-                                          TIMEOUT,
-                                          &notify_ready_connect,
-                                          NULL));
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Finished exchanging HELLOs, now waiting for transmission!\n");
-}
+  if (peers_left == 0)
+    {
+         if (ping_deamon == NULL)
+         {
+                 ping_deamon = d;
+                 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ping peer `%s' '%s'\n", GNUNET_i2s(id), d->cfgfile);
+         }
 
-static void
-exchange_hello (void *cls,
-                const struct GNUNET_MessageHeader *message)
-{
-  struct PeerContext *me = cls;
-
-  GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, me);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Exchanging HELLO with peer (%p)!\n", cls);
-  GNUNET_assert (ok >= 2);
-  OKPP;
-  GNUNET_assert (message != NULL);
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
-                                      message, &me->id));
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received HELLO size %d\n", GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message));
-
-  GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
-  GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
+         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;
+    }
 }
 
 
@@ -361,280 +629,104 @@ run (void *cls,
      char *const *args,
      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
-  GNUNET_assert (ok == 1);
-  OKPP;
-  die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                          &end_badly, NULL);
-
-  setup_peer (&p1, "test_transport_ats_peer1.conf");
-  setup_peer (&p2, "test_transport_ats_peer2.conf");
-
-  GNUNET_assert(p1.th != NULL);
-  GNUNET_assert(p2.th != NULL);
-
-  GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
+  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);
 }
 
 static int
 check ()
 {
-  static char *const argv[] = { "test-transport-api",
+  char *const argv[] = { "test-testing",
     "-c",
-    "test_transport_api_data.conf",
+    config_file,
 #if VERBOSE
     "-L", "DEBUG",
 #endif
     NULL
   };
-  static struct GNUNET_GETOPT_CommandLineOption options[] = {
+  struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_OPTION_END
   };
-
-#if WRITECONFIG
-  setTransportOptions("test_transport_api_data.conf");
-#endif
-  ok = 1;
   GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
-                      argv, "test-transport-api", "nohelp",
+                      argv, "test-transport-ats", "nohelp",
                       options, &run, &ok);
-  stop_arm (&p1);
-  stop_arm (&p2);
-
-  if (is_https)
-  {
-         struct stat sbuf;
-         if (0 == stat (cert_file_p1, &sbuf ))
-         {
-                 if (0 == remove(cert_file_p1))
-                         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed existing certificate file `%s'\n",cert_file_p1);
-                 else
-                         GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",cert_file_p1);
-         }
-
-         if (0 == stat (key_file_p1, &sbuf ))
-         {
-                 if (0 == remove(key_file_p1))
-                         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed private key file `%s'\n",key_file_p1);
-                 else
-                         GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file `%s'\n",key_file_p1);
-         }
-
-         if (0 == stat (cert_file_p2, &sbuf ))
-         {
-                 if (0 == remove(cert_file_p2))
-                         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed existing certificate file `%s'\n",cert_file_p2);
-                 else
-                         GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",cert_file_p2);
-         }
-
-         if (0 == stat (key_file_p2, &sbuf ))
-         {
-                 if (0 == remove(key_file_p2))
-                         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed private key file `%s'\n",key_file_p2);
-                 else
-                         GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file `%s'\n",key_file_p2);
-         }
-         GNUNET_free(key_file_p1);
-         GNUNET_free(key_file_p2);
-         GNUNET_free(cert_file_p1);
-         GNUNET_free(cert_file_p2);
-  }
   return ok;
 }
 
-/**
- * Return the actual path to a file found in the current
- * PATH environment variable.
- *
- * @param binary the name of the file to find
- */
-static char *
-get_path_from_PATH (char *binary)
-{
-  char *path;
-  char *pos;
-  char *end;
-  char *buf;
-  const char *p;
-
-  p = getenv ("PATH");
-  if (p == NULL)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  _("PATH environment variable is unset.\n"));
-      return NULL;
-    }
-  path = GNUNET_strdup (p);     /* because we write on it */
-  buf = GNUNET_malloc (strlen (path) + 20);
-  pos = path;
-
-  while (NULL != (end = strchr (pos, PATH_SEPARATOR)))
-    {
-      *end = '\0';
-      sprintf (buf, "%s/%s", pos, binary);
-      if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
-        {
-          GNUNET_free (path);
-          return buf;
-        }
-      pos = end + 1;
-    }
-  sprintf (buf, "%s/%s", pos, binary);
-  if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
-    {
-      GNUNET_free (path);
-      return buf;
-    }
-  GNUNET_free (buf);
-  GNUNET_free (path);
-  return NULL;
-}
-
-/**
- * Check whether the suid bit is set on a file.
- * Attempts to find the file using the current
- * PATH environment variable as a search path.
- *
- * @param binary the name of the file to check
- *
- * @return GNUNET_YES if the binary is found and
- *         can be run properly, GNUNET_NO otherwise
- */
-static int
-check_gnunet_nat_binary(char *binary)
-{
-  struct stat statbuf;
-  char *p;
-#ifdef MINGW
-  SOCKET rawsock;
-#endif
-
-#ifdef MINGW
-  char *binaryexe;
-  GNUNET_asprintf (&binaryexe, "%s.exe", binary);
-  p = get_path_from_PATH (binaryexe);
-  free (binaryexe);
-#else
-  p = get_path_from_PATH (binary);
-#endif
-  if (p == NULL)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  _("Could not find binary `%s' in PATH!\n"),
-                  binary);
-      return GNUNET_NO;
-    }
-  if (0 != STAT (p, &statbuf))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  _("stat (%s) failed: %s\n"),
-                  p,
-                  STRERROR (errno));
-      GNUNET_free (p);
-      return GNUNET_SYSERR;
-    }
-  GNUNET_free (p);
-#ifndef MINGW
-  if ( (0 != (statbuf.st_mode & S_ISUID)) &&
-       (statbuf.st_uid == 0) )
-    return GNUNET_YES;
-  return GNUNET_NO;
-#else
-  rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
-  if (INVALID_SOCKET == rawsock)
-    {
-      DWORD err = GetLastError ();
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n", err);
-      return GNUNET_NO; /* not running as administrator */
-    }
-  closesocket (rawsock);
-  return GNUNET_YES;
-#endif
-}
-
 int
 main (int argc, char *argv[])
 {
+
   int ret;
-#ifdef MINGW
-  return GNUNET_SYSERR;
-#endif
 
   GNUNET_log_setup ("test-transport-ats",
 #if VERBOSE
                     "DEBUG",
 #else
-                    "WARNING",
+                    "INFO",
 #endif
                     NULL);
 
-  if (strstr(argv[0], "tcp_nat") != NULL)
-    {
-      is_tcp_nat = GNUNET_YES;
-      if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server"))
-        {
-          GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                      "`%s' not properly installed, cannot run NAT test!\n",
-                      "gnunet-nat-server");
-          return 0;
-        }
-    }
-  else if (strstr(argv[0], "tcp") != NULL)
-    {
-      is_tcp = GNUNET_YES;
-    }
-  else if (strstr(argv[0], "udp_nat") != NULL)
-    {
-      is_udp_nat = GNUNET_YES;
-      if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server"))
-        {
-          GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                      "`%s' not properly installed, cannot run NAT test!\n",
-                     "gnunet-nat-server");
-          return 0;
-        }
-    }
-  else if (strstr(argv[0], "udp") != NULL)
-    {
-      is_udp = GNUNET_YES;
-    }
-  else if (strstr(argv[0], "unix") != NULL)
-    {
-      is_unix = GNUNET_YES;
-    }
-  else if (strstr(argv[0], "https") != NULL)
-    {
-      is_https = GNUNET_YES;
-    }
-  else if (strstr(argv[0], "http") != NULL)
-    {
-      is_http = GNUNET_YES;
-    }
-  else if (strstr(argv[0], "wlan") != NULL)
-    {
-       is_wlan = GNUNET_YES;
-    }
-  else if (strstr(argv[0], "multi") != NULL)
-    {
-       is_multi_protocol = GNUNET_YES;
-    }
+#if !HAVE_LIBGLPK
+       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed, exiting testcase\n");
+       return 0;
+#endif
 
-  ret = check ();
-  if (is_multi_protocol)
-  {
-         GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-multi-peer-1/");
-         GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-multi-peer-2/");
-  }
-  else
+  GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing");
+
+
+  machine_parsable = GNUNET_NO;
+  peers = NUM_PEERS;
+  config_file = "test_transport_ats_4addr.conf";
+
+  int c = 0;
+  if (argc >= 2)
   {
-         GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1");
-         GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2");
+        for (c=0; c<argc; c++)
+        {
+                /* set peers */
+                if ((strcmp(argv[c], "-p") == 0) && c < (argc-1))
+                {
+                         peers = atoi(argv[c+1]);
+                         peers++;
+                }
+                /* set machine parsable */
+                if (strcmp(argv[c], "-m") == 0)
+                {
+                        machine_parsable = GNUNET_YES;
+                }
+                /* set config file */
+                if ((strcmp(argv[c], "-c") == 0) && c < (argc-1))
+                {
+                        config_file = argv[c+1];
+                }
+        }
   }
 
-  //return ret;
-  /* GGG */
-  return 0;
+
+
+  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");
+  return ret;
 }
 
-/* end of test_transport_ats.c */
+/* end of test_transport_ats.c*/