adding DEBUG logic for #3863
[oweals/gnunet.git] / src / ats-tests / perf_ats.c
index a50de992f0f326976b537984ed7fe616312ee7a7..e0affb4f91a059c589c0bf7213a815e3645f1359 100644 (file)
@@ -1,6 +1,6 @@
 /*
  This file is part of GNUnet.
- (C) 2010-2013 Christian Grothoff (and other contributing authors)
Copyright (C) 2010-2013 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
@@ -14,8 +14,8 @@
 
  You should have received a copy of the GNU General Public License
  along with GNUnet; see the file COPYING.  If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
  */
 /**
  * @file ats/perf_ats.c
 #include "gnunet_testbed_service.h"
 #include "gnunet_ats_service.h"
 #include "gnunet_core_service.h"
+#include "ats-testing.h"
 
-#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
-#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
-#define TESTNAME_PREFIX "perf_ats_"
-#define DEFAULT_SLAVES_NUM 3
-#define DEFAULT_MASTERS_NUM 1
 
 #define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
 #define TEST_ATS_PREFRENCE_START 1.0
 #define TEST_ATS_PREFRENCE_DELTA 1.0
 
-#define TEST_MESSAGE_TYPE_PING 12345
-#define TEST_MESSAGE_TYPE_PONG 12346
-#define TEST_MESSAGE_SIZE 1000
 #define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
 
+#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
+#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
+#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500)
+#define TESTNAME_PREFIX "perf_ats_"
+#define DEFAULT_SLAVES_NUM 2
+#define DEFAULT_MASTERS_NUM 1
 /**
- * Information about a benchmarking partner
+ * Shutdown task
  */
-struct BenchmarkPartner
-{
-  /**
-   * The peer itself this partner belongs to
-   */
-  struct BenchmarkPeer *me;
-
-  /**
-   * The partner peer
-   */
-  struct BenchmarkPeer *dest;
-
-  /**
-   * Core transmit handles
-   */
-  void *cth;
-
-  /**
-   * Number of messages sent to this partner
-   */
-  unsigned int messages_sent;
-
-  /**
-   * Number of bytes sent to this partner
-   */
-  unsigned int bytes_sent;
-
-  /**
-   * Number of messages received from this partner
-   */
-  unsigned int messages_received;
-
-  /**
-   * Number of bytes received from this partner
-   */
-  unsigned int bytes_received;
-};
+static struct GNUNET_SCHEDULER_Task * shutdown_task;
 
 /**
- * Connect peers with testbed
+ * Progress task
  */
-struct TestbedConnectOperation
-{
-  /**
-   * The benchmarking master initiating this connection
-   */
-  struct BenchmarkPeer *master;
-
-  /**
-   * The benchmarking slave to connect to
-   */
-  struct BenchmarkPeer *slave;
-
-  /**
-   * Testbed operation to connect peers
-   */
-  struct GNUNET_TESTBED_Operation *connect_op;
-};
+static struct GNUNET_SCHEDULER_Task * progress_task;
 
 /**
- * Information we track for a peer in the testbed.
+ * Test result
  */
-struct BenchmarkPeer
-{
-  /**
-   * Handle with testbed.
-   */
-  struct GNUNET_TESTBED_Peer *peer;
-
-  /**
-   * Unique identifier
-   */
-  int no;
-
-  /**
-   * Is this peer a measter: GNUNET_YES/GNUNET_NO
-   */
-  int master;
-
-  /**
-   *  Peer ID
-   */
-  struct GNUNET_PeerIdentity id;
-
-  /**
-   * Testbed operation to get peer information
-   */
-  struct GNUNET_TESTBED_Operation *peer_id_op;
-
-  /**
-   * Testbed operation to connect to ATS performance service
-   */
-  struct GNUNET_TESTBED_Operation *ats_perf_op;
-
-  /**
-   * Testbed operation to connect to core
-   */
-  struct GNUNET_TESTBED_Operation *core_op;
-
-  /**
-   * ATS performance handle
-   */
-  struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
-
-  /**
-   * Masters only:
-   * Testbed connect operations to connect masters to slaves
-   */
-  struct TestbedConnectOperation *core_connect_ops;
-
-  /**
-   *  Core handle
-   */
-  struct GNUNET_CORE_Handle *ch;
-
-  /**
-   * Masters only:
-   * Peer to set ATS preferences for
-   */
-  struct BenchmarkPeer *pref_partner;
-
-  /**
-   * Masters only
-   * Progress task
-   */
-  GNUNET_SCHEDULER_TaskIdentifier ats_task;
-
-  /**
-   * Masters only
-   * Progress task
-   */
-  double pref_value;
-
-  /**
-   * Array of partners with num_slaves entries (if master) or
-   * num_master entries (if slave)
-   */
-  struct BenchmarkPartner *partners;
-
-  /**
-   * Number of core connections
-   */
-  int core_connections;
-
-  /**
-   * Masters only:
-   * Number of connections to slave peers
-   */
-  int core_slave_connections;
-
-  /**
-   * Total number of messages this peer has sent
-   */
-  unsigned int total_messages_sent;
-
-  /**
-   * Total number of bytes this peer has sent
-   */
-  unsigned int total_bytes_sent;
-
-  /**
-   * Total number of messages this peer has received
-   */
-  unsigned int total_messages_received;
-
-  /**
-   * Total number of bytes this peer has received
-   */
-  unsigned int total_bytes_received;
-};
+static int result;
 
 /**
- * Overall state of the performance benchmark
+ * Test result logging
  */
-struct BenchmarkState
-{
-  /* Are we connected to ATS service of all peers: GNUNET_YES/NO */
-  int connected_ATS_service;
-
-  /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
-  int connected_CORE_service;
-
-  /* Are we connected to all peers: GNUNET_YES/NO */
-  int connected_PEERS;
+static int logging;
 
-  /* Are we connected to all slave peers on CORE level: GNUNET_YES/NO */
-  int connected_CORE;
-
-  /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
-  int benchmarking;
-};
+/**Test core (GNUNET_YES) or transport (GNUNET_NO)
+ */
+static int test_core;
 
 /**
- * Shutdown task
+ * Solver string
  */
-static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
+static char *solver;
 
 /**
- * Progress task
+ * Preference string
  */
-static GNUNET_SCHEDULER_TaskIdentifier progress_task;
+static char *testname;
 
 /**
- * Test result
+ * Preference string
  */
-static int result;
+static char *pref_str;
 
 /**
- * Solver string
+ * ATS preference value
  */
-static char *solver;
+static int pref_val;
 
 /**
- * Preference string
+ * Benchmark duration
  */
-static char *pref_str;
+static struct GNUNET_TIME_Relative perf_duration;
 
 /**
- * ATS preference value
+ * Logging frequency
  */
-static int pref_val;
+static struct GNUNET_TIME_Relative log_frequency;
 
 /**
  * Number master peers
  */
-static int num_masters;
+static unsigned int num_masters;
 
 /**
  * Array of master peers
  */
-struct BenchmarkPeer *mps;
+static struct BenchmarkPeer *mps;
 
 /**
  * Number slave peers
  */
-static int num_slaves;
-/**
- * Array of slave peers
- */
-struct BenchmarkPeer *sps;
+static unsigned int num_slaves;
 
 /**
- * Benchmark state
+ * Array of master peers
  */
-static struct BenchmarkState state;
+static struct BenchmarkPeer *sps;
+
+static struct LoggingHandle *l;
 
 static void
 evaluate ()
@@ -300,8 +126,15 @@ evaluate ()
   int c_s;
   unsigned int duration;
   struct BenchmarkPeer *mp;
+  struct BenchmarkPartner *p;
 
-  duration = (BENCHMARK_DURATION.rel_value_us / (1000 * 1000));
+  unsigned int kb_sent_sec;
+  double kb_sent_percent;
+  unsigned int kb_recv_sec;
+  double kb_recv_percent;
+  unsigned int rtt;
+
+  duration = (perf_duration.rel_value_us / (1000 * 1000));
   for (c_m = 0; c_m < num_masters; c_m++)
   {
     mp = &mps[c_m];
@@ -314,14 +147,36 @@ evaluate ()
 
     for (c_s = 0; c_s < num_slaves; c_s++)
     {
+      p = &mp->partners[c_s];
+
+      kb_sent_sec = 0;
+      kb_recv_sec = 0;
+      kb_sent_percent = 0.0;
+      kb_recv_percent = 0.0;
+      rtt = 0;
+
+      if (duration > 0)
+      {
+         kb_sent_sec = (p->bytes_sent / 1024) / duration;
+         kb_recv_sec = (p->bytes_received / 1024) / duration;
+      }
+
+      if (mp->total_bytes_sent > 0)
+         kb_sent_percent = ((double) p->bytes_sent * 100) / mp->total_bytes_sent;
+      if (mp->total_bytes_received > 0)
+         kb_recv_percent = ((double) p->bytes_received * 100) / mp->total_bytes_received;
+      if (1000 * p->messages_sent > 0)
+         rtt = p->total_app_rtt / (1000 * p->messages_sent);
+      fprintf (stderr,
+          "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n",
+          (mp->pref_partner == p->dest) ? '*' : ' ',
+          mp->no, p->dest->no,
+          kb_sent_sec, kb_sent_percent,
+                 kb_recv_sec, kb_recv_percent);
       fprintf (stderr,
-          "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f \%), received %u KiB/s (%.2f \%)\n",
-          (mp->pref_partner == mp->partners[c_s].dest) ? '*' : ' ',
-          mp->no, mp->partners[c_s].dest->no,
-          (mp->partners[c_s].bytes_sent / 1024) / duration,
-          ((double) mp->partners[c_s].bytes_sent * 100) / mp->total_bytes_sent,
-          (mp->partners[c_s].bytes_received / 1024) / duration,
-          ((double) mp->partners[c_s].bytes_received * 100) / mp->total_bytes_received );
+          "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
+          (mp->pref_partner == p->dest) ? '*' : ' ',
+          mp->no, p->dest->no, rtt);
     }
   }
 }
@@ -335,181 +190,33 @@ evaluate ()
 static void
 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  int c_m;
-  int c_s;
-  int c_op;
 
-  shutdown_task = GNUNET_SCHEDULER_NO_TASK;
-  if (GNUNET_SCHEDULER_NO_TASK != progress_task)
+  if (GNUNET_YES == logging)
+    GNUNET_ATS_TEST_logging_clean_up(l);
+
+  shutdown_task = NULL;
+  if (NULL != progress_task)
   {
     fprintf (stderr, "0\n");
     GNUNET_SCHEDULER_cancel (progress_task);
   }
-  progress_task = GNUNET_SCHEDULER_NO_TASK;
+  progress_task = NULL;
 
   evaluate ();
-  state.benchmarking = GNUNET_NO;
   GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n"));
 
-  for (c_m = 0; c_m < num_masters; c_m++)
-  {
-    if (NULL != mps[c_m].peer_id_op)
-    {
-      GNUNET_TESTBED_operation_done (mps[c_m].peer_id_op);
-      mps[c_m].peer_id_op = NULL;
-    }
-
-    if (GNUNET_SCHEDULER_NO_TASK != mps[c_m].ats_task)
-      GNUNET_SCHEDULER_cancel (mps[c_m].ats_task);
-    mps[c_m].ats_task = GNUNET_SCHEDULER_NO_TASK;
-
-    for (c_op = 0; c_op < num_slaves; c_op++)
-    {
-
-      if (NULL != mps[c_m].partners[c_op].cth)
-      {
-        GNUNET_CORE_notify_transmit_ready_cancel (mps[c_m].partners[c_op].cth);
-        mps[c_m].partners[c_op].cth = NULL;
-      }
-
-      if (NULL != mps[c_m].core_connect_ops[c_op].connect_op)
-      {
-        GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-            _("Failed to connect peer 0 and %u\n"), c_op);
-        GNUNET_TESTBED_operation_done (
-            mps[c_m].core_connect_ops[c_op].connect_op);
-        mps[c_m].core_connect_ops[c_op].connect_op = NULL;
-        result = 1;
-      }
-    }
-
-    if (NULL != mps[c_m].ats_perf_op)
-    {
-      GNUNET_TESTBED_operation_done (mps[c_m].ats_perf_op);
-      mps[c_m].ats_perf_op = NULL;
-    }
-
-    if (NULL != mps[c_m].core_op)
-    {
-      GNUNET_TESTBED_operation_done (mps[c_m].core_op);
-      mps[c_m].core_op = NULL;
-    }
-    GNUNET_free(mps[c_m].core_connect_ops);
-    GNUNET_free(mps[c_m].partners);
-    mps[c_m].partners = NULL;
-  }
-
-  for (c_s = 0; c_s < num_slaves; c_s++)
-  {
-    if (NULL != sps[c_s].peer_id_op)
-    {
-      GNUNET_TESTBED_operation_done (sps[c_s].peer_id_op);
-      sps[c_s].peer_id_op = NULL;
-    }
-
-    for (c_op = 0; c_op < num_slaves; c_op++)
-    {
-      if (NULL != sps[c_s].partners[c_op].cth)
-      {
-        GNUNET_CORE_notify_transmit_ready_cancel (sps[c_s].partners[c_op].cth);
-        sps[c_s].partners[c_op].cth = NULL;
-      }
-    }
-
-    if (NULL != sps[c_s].ats_perf_op)
-    {
-      GNUNET_TESTBED_operation_done (sps[c_s].ats_perf_op);
-      sps[c_s].ats_perf_op = NULL;
-    }
-    if (NULL != sps[c_s].core_op)
-    {
-      GNUNET_TESTBED_operation_done (sps[c_s].core_op);
-      sps[c_s].core_op = NULL;
-    }
-
-    GNUNET_free(sps[c_s].partners);
-    sps[c_s].partners = NULL;
-  }
-
-  GNUNET_SCHEDULER_shutdown ();
-}
-
-static struct BenchmarkPeer *
-find_peer (const struct GNUNET_PeerIdentity * peer)
-{
-  int c_p;
-
-  for (c_p = 0; c_p < num_masters; c_p++)
-  {
-    if (0 == memcmp (&mps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity)))
-      return &mps[c_p];
-  }
-
-  for (c_p = 0; c_p < num_slaves; c_p++)
-  {
-    if (0 == memcmp (&sps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity)))
-      return &sps[c_p];
-  }
-  return NULL ;
-}
-
-/**
- * Controller event callback
- *
- * @param cls NULL
- * @param event the controller event
- */
-static void
-controller_event_cb (void *cls,
-    const struct GNUNET_TESTBED_EventInformation *event)
-{
-  //struct BenchmarkPeer *p = cls;
-  switch (event->type)
-  {
-  case GNUNET_TESTBED_ET_CONNECT:
-    break;
-  case GNUNET_TESTBED_ET_OPERATION_FINISHED:
-    break;
-  default:
-    GNUNET_break(0);
-    result = 2;
-    GNUNET_SCHEDULER_cancel (shutdown_task);
-    shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL );
-  }
+  GNUNET_ATS_TEST_shutdown_topology();
 }
 
-static size_t
-core_send_ready (void *cls, size_t size, void *buf)
-{
-  static char msgbuf[TEST_MESSAGE_SIZE];
-  struct BenchmarkPartner *partner = cls;
-  struct GNUNET_MessageHeader *msg;
-
-  partner->cth = NULL;
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Master [%u]: Sending PING to [%u]\n",
-      partner->me->no, partner->dest->no);
-
-  partner->messages_sent++;
-  partner->bytes_sent += TEST_MESSAGE_SIZE;
-  partner->me->total_messages_sent++;
-  partner->me->total_bytes_sent += TEST_MESSAGE_SIZE;
-
-  msg = (struct GNUNET_MessageHeader *) &msgbuf;
-  memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
-  msg->type = htons (TEST_MESSAGE_TYPE_PING);
-  msg->size = htons (TEST_MESSAGE_SIZE);
-  memcpy (buf, msg, TEST_MESSAGE_SIZE);
-  return TEST_MESSAGE_SIZE;
-}
 
 static void
 print_progress ()
 {
   static int calls;
-  progress_task = GNUNET_SCHEDULER_NO_TASK;
+  progress_task = NULL;
 
   fprintf (stderr, "%llu..",
-      (long long unsigned) BENCHMARK_DURATION.rel_value_us / (1000 * 1000) - calls);
+      (long long unsigned) perf_duration.rel_value_us / (1000 * 1000) - calls);
   calls++;
 
   progress_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
@@ -521,7 +228,7 @@ ats_pref_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct BenchmarkPeer *me = cls;
 
-  me->ats_task = GNUNET_SCHEDULER_NO_TASK;
+  me->ats_task = NULL;
 
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, " Master [%u] set preference for slave [%u] to %f\n",
       me->no, me->pref_partner->no, me->pref_value);
@@ -534,584 +241,120 @@ ats_pref_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 }
 
 static void
-do_benchmark ()
+start_benchmark()
 {
   int c_m;
   int c_s;
 
-  if ((state.connected_ATS_service == GNUNET_NO)
-      || (state.connected_CORE_service == GNUNET_NO)
-      || (state.connected_PEERS == GNUNET_NO)
-      || (state.connected_CORE == GNUNET_NO))
-    return;
-
-  state.benchmarking = GNUNET_YES;
   GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking start\n"));
 
-  if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
-    GNUNET_SCHEDULER_cancel (shutdown_task);
-  shutdown_task = GNUNET_SCHEDULER_add_delayed (BENCHMARK_DURATION,
-      &do_shutdown, NULL );
-
-  progress_task = GNUNET_SCHEDULER_add_now (&print_progress, NULL );
-
-  /* Start sending test messages */
-  for (c_m = 0; c_m < num_masters; c_m++)
-  {
-    for (c_s = 0; c_s < num_slaves; c_s++)
-    {
-      mps[c_m].partners[c_s].cth = GNUNET_CORE_notify_transmit_ready (
-          mps[c_m].ch, GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, &sps[c_s].id,
-          TEST_MESSAGE_SIZE, &core_send_ready, &mps[c_m].partners[c_s]);
-    }
-    if (pref_val != GNUNET_ATS_PREFERENCE_END)
-      mps[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task, &mps[c_m]);
-  }
-}
-
-static void
-connect_completion_callback (void *cls, struct GNUNET_TESTBED_Operation *op,
-    const char *emsg)
-{
-  struct TestbedConnectOperation *cop = cls;
-  static int ops = 0;
-  int c;
-  if (NULL == emsg)
-  {
-    GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-        _("Connected master [%u] with slave [%u]\n"), cop->master->no,
-        cop->slave->no);
-  }
-  else
-  {
-    GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
-        _("Failed to connect master peer [%u] with slave [%u]\n"),
-        cop->master->no, cop->slave->no);
-    GNUNET_break(0);
-    if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
-      GNUNET_SCHEDULER_cancel (shutdown_task);
-    shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
-  }
-  GNUNET_TESTBED_operation_done (op);
-  ops++;
-  for (c = 0; c < num_slaves; c++)
-  {
-    if (cop == &cop->master->core_connect_ops[c])
-      cop->master->core_connect_ops[c].connect_op = NULL;
-  }
-  if (ops == num_masters * num_slaves)
-  {
-    state.connected_PEERS = GNUNET_YES;
-    GNUNET_SCHEDULER_add_now (&do_benchmark, NULL );
-  }
-}
-
-static void
-do_connect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  int c_m;
-  int c_s;
-  struct BenchmarkPeer *p;
+  if (NULL != shutdown_task)
+    GNUNET_SCHEDULER_cancel(shutdown_task);
+  shutdown_task = GNUNET_SCHEDULER_add_delayed(perf_duration, &do_shutdown,
+      NULL );
 
-  if ((state.connected_ATS_service == GNUNET_NO)
-      || (state.connected_CORE_service == GNUNET_NO))
-    return;
+  progress_task = GNUNET_SCHEDULER_add_now(&print_progress, NULL );
 
-  GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Connecting peers on CORE level\n"));
+  GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+      "Topology connected, start benchmarking...\n");
 
+  /* Start sending test messages */
   for (c_m = 0; c_m < num_masters; c_m++)
-  {
-    p = &mps[c_m];
-    p->core_connect_ops = GNUNET_malloc (num_slaves *
-        sizeof (struct TestbedConnectOperation));
-
-    for (c_s = 0; c_s < num_slaves; c_s++)
     {
-      GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-          _("Connecting master [%u] with slave [%u]\n"), p->no, sps[c_s].no);
-      p->core_connect_ops[c_s].master = p;
-      p->core_connect_ops[c_s].slave = &sps[c_s];
-      p->core_connect_ops[c_s].connect_op = GNUNET_TESTBED_overlay_connect (
-          NULL, &connect_completion_callback, &p->core_connect_ops[c_s],
-          sps[c_s].peer, p->peer);
-      if (NULL == p->core_connect_ops[c_s].connect_op)
+      for (c_s = 0; c_s < num_slaves; c_s++)
       {
-        GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
-            _("Could not connect master [%u] and slave [%u]\n"), p->no,
-            sps[c_s].no);
-        GNUNET_break(0);
-        if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
-          GNUNET_SCHEDULER_cancel (shutdown_task);
-        shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
-        return;
+        GNUNET_ATS_TEST_generate_traffic_start (&mps[c_m], &mps[c_m].partners[c_s],
+            GNUNET_ATS_TEST_TG_LINEAR, UINT32_MAX, UINT32_MAX,
+            GNUNET_TIME_UNIT_MINUTES, GNUNET_TIME_UNIT_FOREVER_REL);
       }
+      if (pref_val != GNUNET_ATS_PREFERENCE_END)
+        mps[c_m].ats_task = GNUNET_SCHEDULER_add_now(&ats_pref_task, &mps[c_m]);
     }
-  }
-}
-
-/**
- * Method called whenever a given peer connects.
- *
- * @param cls closure
- * @param peer peer identity this notification is about
- */
-static void
-core_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
-{
-  struct BenchmarkPeer *me = cls;
-  struct BenchmarkPeer *remote;
-  char *id;
-  int c;
-  int completed;
-
-  remote = find_peer (peer);
-  if (NULL == remote)
-  {
-    GNUNET_break(0);
-    return;
-  }
-
-  id = GNUNET_strdup (GNUNET_i2s (&me->id));
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s [%u] `%s' connected to %s [%u] %s\n",
-      (me->master == GNUNET_YES) ? "Master": "Slave", me->no, id,
-      (remote->master == GNUNET_YES) ? "Master": "Slave", remote->no,
-      GNUNET_i2s (peer));
 
-  me->core_connections++;
-  if ((GNUNET_YES == me->master) && (GNUNET_NO == remote->master)
-      && (GNUNET_NO == state.connected_CORE))
-  {
-    me->core_slave_connections++;
-
-    if (me->core_slave_connections == num_slaves)
-    {
-      GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Master [%u] connected all slaves\n",
-          me->no);
-    }
-    completed = GNUNET_YES;
-    for (c = 0; c < num_masters; c++)
-    {
-      if (mps[c].core_slave_connections != num_slaves)
-        completed = GNUNET_NO;
-    }
-    if (GNUNET_YES == completed)
-    {
-      GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-          "All master peers connected all slave peers\n", id,
-          GNUNET_i2s (peer));
-      state.connected_CORE = GNUNET_YES;
-      GNUNET_SCHEDULER_add_now (&do_benchmark, NULL );
-    }
-  }
-  GNUNET_free(id);
+  if (GNUNET_YES == logging)
+    l = GNUNET_ATS_TEST_logging_start (log_frequency, testname, mps,
+        num_masters, num_slaves, GNUNET_NO);
 }
 
 static void
-core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
+do_benchmark (void *cls, struct BenchmarkPeer *masters, struct BenchmarkPeer *slaves)
 {
-  struct BenchmarkPeer *me = cls;
-  struct BenchmarkPeer *remote;
-  char *id;
+  mps = masters;
+  sps = slaves;
 
-  remote = find_peer (peer);
-  if (NULL == remote)
-  {
-    GNUNET_break(0);
-    return;
-  }
-
-  id = GNUNET_strdup (GNUNET_i2s (&me->id));
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s disconnected from %s \n", id,
-      GNUNET_i2s (peer));
-  GNUNET_assert(me->core_connections > 0);
-  me->core_connections--;
-
-  if ((GNUNET_YES == state.benchmarking)
-      && ((GNUNET_YES == me->master) || (GNUNET_YES == remote->master)))
-  {
-    GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
-        "%s disconnected from %s while benchmarking \n", id, GNUNET_i2s (peer));
-  }
-  GNUNET_free(id);
+  GNUNET_SCHEDULER_add_now(&start_benchmark, NULL);
 }
 
-static size_t
-core_send_echo_ready (void *cls, size_t size, void *buf)
-{
-  static char msgbuf[TEST_MESSAGE_SIZE];
-  struct BenchmarkPartner *p = cls;
-  struct GNUNET_MessageHeader *msg;
-
-  p->cth = NULL;
 
-  p->messages_sent++;
-  p->bytes_sent += TEST_MESSAGE_SIZE;
-  p->me->total_messages_sent++;
-  p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
 
-  msg = (struct GNUNET_MessageHeader *) &msgbuf;
-  memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
-  msg->type = htons (TEST_MESSAGE_TYPE_PONG);
-  msg->size = htons (TEST_MESSAGE_SIZE);
-  memcpy (buf, msg, TEST_MESSAGE_SIZE);
-
-  return TEST_MESSAGE_SIZE;
-}
 
-static int
-core_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
-    const struct GNUNET_MessageHeader *message)
+static struct BenchmarkPartner *
+find_partner (struct BenchmarkPeer *me, const struct GNUNET_PeerIdentity * peer)
 {
   int c_m;
-  struct BenchmarkPeer *me = cls;
-  struct BenchmarkPartner *p = NULL;
-  for (c_m = 0; c_m < num_masters; c_m++)
-  {
-    if (0
-        == memcmp (other, &me->partners[c_m].dest->id,
-            sizeof(struct GNUNET_PeerIdentity)))
-    {
-      p = &me->partners[c_m];
-      break;
-    }
-  }
-  if (NULL == p)
-  {
-    GNUNET_break(0);
-    return GNUNET_SYSERR;
-  }
-  GNUNET_assert(NULL == p->cth);
-
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-      "Slave [%u]: Received PING from [%u], sending PONG\n", me->no,
-      p->dest->no);
-
-  p->messages_received++;
-  p->bytes_received += TEST_MESSAGE_SIZE;
-  p->me->total_messages_received++;
-  p->me->total_bytes_received += TEST_MESSAGE_SIZE;
-
-  p->cth = GNUNET_CORE_notify_transmit_ready (me->ch, GNUNET_NO, 0,
-      GNUNET_TIME_UNIT_MINUTES, &p->dest->id, TEST_MESSAGE_SIZE,
-      &core_send_echo_ready, p);
-  return GNUNET_OK;
-}
+  GNUNET_assert (NULL != me);
+  GNUNET_assert (NULL != peer);
 
-static int
-core_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
-    const struct GNUNET_MessageHeader *message)
-{
-  int c_s;
-  struct BenchmarkPeer *me = cls;
-  struct BenchmarkPartner *p = NULL;
-
-  for (c_s = 0; c_s < num_slaves; c_s++)
+  for (c_m = 0; c_m < me->num_partners; c_m++)
   {
-    if (0
-        == memcmp (other, &me->partners[c_s].dest->id,
+    /* Find a partner with other as destination */
+    if (0 == memcmp (peer, &me->partners[c_m].dest->id,
             sizeof(struct GNUNET_PeerIdentity)))
     {
-      p = &me->partners[c_s];
-      break;
+      return &me->partners[c_m];
     }
   }
-  if (NULL == p)
-  {
-    GNUNET_break(0);
-    return GNUNET_SYSERR;
-  }
-  GNUNET_assert(NULL == p->cth);
-
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-      "Master [%u]: Received PONG from [%u], next message\n", me->no,
-      p->dest->no);
-
-  p->messages_received++;
-  p->bytes_received += TEST_MESSAGE_SIZE;
-  p->me->total_messages_received++;
-  p->me->total_bytes_received += TEST_MESSAGE_SIZE;
-
-  p->cth = GNUNET_CORE_notify_transmit_ready (me->ch, GNUNET_NO, 0,
-      GNUNET_TIME_UNIT_MINUTES, &p->dest->id, TEST_MESSAGE_SIZE,
-      &core_send_ready, p);
-
-  return GNUNET_OK;
-}
-
-static void *
-core_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-  struct BenchmarkPeer *me = cls;
-
-  static const struct GNUNET_CORE_MessageHandler handlers[] = { {
-      &core_handle_ping, TEST_MESSAGE_TYPE_PING, 0 }, { &core_handle_pong,
-      TEST_MESSAGE_TYPE_PONG, 0 }, { NULL, 0, 0 } };
-
-  me->ch = GNUNET_CORE_connect (cfg, me, NULL, core_connect_cb,
-      core_disconnect_cb, NULL, GNUNET_NO, NULL, GNUNET_NO, handlers);
-  if (NULL == me->ch)
-    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create core connection \n");
-  return me->ch;
+  return NULL;
 }
 
 static void
-core_disconnect_adapter (void *cls, void *op_result)
+test_recv_cb (void *cls,
+                     const struct GNUNET_PeerIdentity * peer,
+                     const struct GNUNET_MessageHeader * message)
 {
-  struct BenchmarkPeer *me = cls;
 
-  GNUNET_CORE_disconnect (me->ch);
-  me->ch = NULL;
 }
 
-static void
-core_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
-    void *ca_result, const char *emsg)
-{
-  static int core_done = 0;
-  if ((NULL != emsg) || (NULL == ca_result))
-  {
-    GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
-    GNUNET_break(0);
-    if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
-      GNUNET_SCHEDULER_cancel (shutdown_task);
-    shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
-    return;
-  }
-  core_done++;
-
-  if (core_done == num_slaves + num_masters)
-  {
-    GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all CORE services\n");
-    state.connected_CORE_service = GNUNET_YES;
-    GNUNET_SCHEDULER_add_now (&do_connect_peers, NULL );
-  }
-}
 
 static void
-do_connect_core (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  int c_s;
-  int c_m;
-  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all CORE services\n");
-  for (c_m = 0; c_m < num_masters; c_m++)
-  {
-    mps[c_m].core_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer,
-        "core", core_connect_completion_cb, NULL, &core_connect_adapter,
-        &core_disconnect_adapter, &mps[c_m]);
-  }
-
-  for (c_s = 0; c_s < num_slaves; c_s++)
-  {
-    sps[c_s].core_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer,
-        "core", core_connect_completion_cb, NULL, &core_connect_adapter,
-        &core_disconnect_adapter, &sps[c_s]);
-  }
-}
-
-static void
-ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
+log_request_cb (void *cls, const struct GNUNET_HELLO_Address *address,
     int address_active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
-    const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
+    const struct GNUNET_ATS_Properties *ats)
 {
   struct BenchmarkPeer *me = cls;
-  int c_a;
+  struct BenchmarkPartner *p;
   char *peer_id;
 
-  peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
-  for (c_a = 0; c_a < ats_count; c_a++)
-  {
-    /*GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("%c %03u: %s %s %u\n"),
-     (GNUNET_YES == p->master) ? 'M' : 'S',
-     p->no,
-     GNUNET_i2s (&address->peer),
-     GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)),
-     ntohl(ats[c_a].value));*/
-  }
-#if 0
-  if ((GNUNET_YES == me->master)
-      && (0 == memcmp (&address->peer, &me->destination->id,
-              sizeof(struct GNUNET_PeerIdentity))))
-  {
-    GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Bandwidth for master %u: %lu %lu\n",
-        me->no, (long unsigned int ) ntohl (bandwidth_in.value__),
-        (long unsigned int ) ntohl (bandwidth_in.value__));
-  }
-
-  store_information (&bp->id, address, address_active, bandwidth_in,
-      bandwidth_out, ats, ats_count);
-#endif
-  GNUNET_free(peer_id);
-}
-
-static void *
-ats_perf_connect_adapter (void *cls,
-    const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-  struct BenchmarkPeer *me = cls;
-
-  me->ats_perf_handle = GNUNET_ATS_performance_init (cfg,
-      &ats_performance_info_cb, me);
-  if (NULL == me->ats_perf_handle)
-    GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
-        "Failed to create ATS performance handle \n");
-  return me->ats_perf_handle;
-}
-
-static void
-ats_perf_disconnect_adapter (void *cls, void *op_result)
-{
-  struct BenchmarkPeer *me = cls;
-
-  GNUNET_ATS_performance_done (me->ats_perf_handle);
-  me->ats_perf_handle = NULL;
-}
-
-static void
-ats_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
-    void *ca_result, const char *emsg)
-{
-  static int op_done = 0;
-
-  if ((NULL != emsg) || (NULL == ca_result))
+  p = find_partner (me, &address->peer);
+  if (NULL == p)
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
-    GNUNET_break(0);
-    if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
-      GNUNET_SCHEDULER_cancel (shutdown_task);
-    shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
+    /* This is not one of my partners
+     * Will happen since the peers will connect to each other due to gossiping
+     */
     return;
   }
-  op_done++;
-  if (op_done == (num_masters + num_slaves))
-  {
-    GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all ATS services\n");
-    state.connected_ATS_service = GNUNET_YES;
-    GNUNET_SCHEDULER_add_now (&do_connect_core, NULL );
-  }
-}
-
-static void
-do_connect_ats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  int c_m;
-  int c_s;
-
-  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all ATS services\n");
-  for (c_m = 0; c_m < num_masters; c_m++)
-  {
-    mps[c_m].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer,
-        "ats", ats_connect_completion_cb, NULL, &ats_perf_connect_adapter,
-        &ats_perf_disconnect_adapter, &mps[c_m]);
+  peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
 
-  }
+  if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) ||
+      (p->bandwidth_out != ntohl (bandwidth_out.value__)))
+  p->bandwidth_in = ntohl (bandwidth_in.value__);
+  p->bandwidth_out = ntohl (bandwidth_out.value__);
 
-  for (c_s = 0; c_s < num_slaves; c_s++)
-  {
-    sps[c_s].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer,
-        "ats", ats_connect_completion_cb, NULL, &ats_perf_connect_adapter,
-        &ats_perf_disconnect_adapter, &sps[c_s]);
-  }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s [%u] received ATS information for peers `%s'\n",
+      (GNUNET_YES == p->me->master) ? "Master" : "Slave",
+          p->me->no,
+          GNUNET_i2s (&p->dest->id));
 
+  GNUNET_free(peer_id);
+  if (NULL != l)
+    GNUNET_ATS_TEST_logging_now (l);
 }
 
-static void
-peerinformation_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op,
-    const struct GNUNET_TESTBED_PeerInformation*pinfo, const char *emsg)
-{
-  struct BenchmarkPeer *p = cb_cls;
-  static int done = 0;
-
-  GNUNET_assert(pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY);
-
-  p->id = *pinfo->result.id;
-  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%s [%u] has peer id `%s'\n",
-      (p->master == GNUNET_YES) ? "Master" : "Slave", p->no,
-      GNUNET_i2s (&p->id));
-
-  GNUNET_TESTBED_operation_done (op);
-  p->peer_id_op = NULL;
-  done++;
-
-  if (done == num_slaves + num_masters)
-  {
-    GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-        "Retrieved all peer ID, connect to ATS\n");
-    GNUNET_SCHEDULER_add_now (&do_connect_ats, NULL );
-  }
-}
 
-/**
- * Signature of a main function for a testcase.
- *
- * @param cls closure
- * @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
+/*
+ * Start the performance test case
  */
-static void
-main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers,
-    struct GNUNET_TESTBED_Peer **peers_, unsigned int links_succeeded,
-    unsigned int links_failed)
-{
-  int c_m;
-  int c_s;
-  GNUNET_assert(NULL == cls);
-  GNUNET_assert(num_masters + num_slaves == num_peers);
-  GNUNET_assert(NULL != peers_);
-
-  GNUNET_log(GNUNET_ERROR_TYPE_INFO,
-      _("Benchmarking solver `%s' on preference `%s' with %u master and %u slave peers\n"),
-      solver, pref_str, num_masters, num_slaves);
-
-  shutdown_task = GNUNET_SCHEDULER_add_delayed (
-      GNUNET_TIME_relative_multiply (TEST_TIMEOUT, num_masters + num_slaves),
-      &do_shutdown, NULL );
-
-  /* Setup master peers */
-  for (c_m = 0; c_m < num_masters; c_m++)
-  {
-    GNUNET_assert(NULL != peers_[c_m]);
-    mps[c_m].peer = peers_[c_m];
-    mps[c_m].no = c_m;
-    mps[c_m].master = GNUNET_YES;
-    mps[c_m].pref_partner = &sps[c_m];
-    mps[c_m].pref_value = TEST_ATS_PREFRENCE_START;
-    mps[c_m].partners =
-        GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer));
-    /* Initialize partners */
-    for (c_s = 0; c_s < num_slaves; c_s++)
-    {
-      mps[c_m].partners[c_s].me = &mps[c_m];
-      mps[c_m].partners[c_s].dest = &sps[c_s];
-    }
-    mps[c_m].peer_id_op = GNUNET_TESTBED_peer_get_information (mps[c_m].peer,
-        GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &mps[c_m]);
-  }
-
-  /* Setup slave peers */
-  for (c_s = 0; c_s < num_slaves; c_s++)
-  {
-    GNUNET_assert(NULL != peers_[c_s + num_masters]);
-    sps[c_s].peer = peers_[c_s + num_masters];
-    sps[c_s].no = c_s + num_masters;
-    sps[c_s].master = GNUNET_NO;
-    sps[c_s].partners =
-        GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer));
-    /* Initialize partners */
-    for (c_m = 0; c_m < num_masters; c_m++)
-    {
-      sps[c_s].partners[c_m].me = &sps[c_s];
-      sps[c_s].partners[c_m].dest = &mps[c_m];
-    }
-    sps[c_s].peer_id_op = GNUNET_TESTBED_peer_get_information (sps[c_s].peer,
-        GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &sps[c_s]);
-  }
-}
-
 int
 main (int argc, char *argv[])
 {
@@ -1119,23 +362,34 @@ main (int argc, char *argv[])
   char *tmp_sep;
   char *test_name;
   char *conf_name;
+  char *comm_name;
   char *dotexe;
-  char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
+  char *prefs[] = GNUNET_ATS_PreferenceTypeString;
   int c;
 
   result = 0;
 
-  /* figure out testname */
+  /* Determine testname
+   * perf_ats_<solver>_<transport>_<preference>[.exe]*/
+
+  /* Find test prefix, store in temp */
   tmp = strstr (argv[0], TESTNAME_PREFIX);
   if (NULL == tmp)
   {
     fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
     return GNUNET_SYSERR;
   }
+
+  /* Set tmp to end of test name prefix */
   tmp += strlen (TESTNAME_PREFIX);
+
+  /* Determine solver name */
   solver = GNUNET_strdup (tmp);
+  /* Remove .exe prefix */
   if (NULL != (dotexe = strstr (solver, ".exe")) && dotexe[4] == '\0')
     dotexe[0] = '\0';
+
+  /* Determine first '_' after solver */
   tmp_sep = strchr (solver, '_');
   if (NULL == tmp_sep)
   {
@@ -1144,6 +398,28 @@ main (int argc, char *argv[])
     return GNUNET_SYSERR;
   }
   tmp_sep[0] = '\0';
+  comm_name = GNUNET_strdup (&tmp_sep[1]);
+  tmp_sep = strchr (comm_name, '_');
+  if (NULL == tmp_sep)
+  {
+    fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
+    GNUNET_free(solver);
+    return GNUNET_SYSERR;
+  }
+  tmp_sep[0] = '\0';
+  for (c = 0; c <= strlen (comm_name); c++)
+    comm_name[c] = toupper (comm_name[c]);
+  if (0 == strcmp (comm_name, "CORE"))
+    test_core = GNUNET_YES;
+  else if (0 == strcmp (comm_name, "TRANSPORT"))
+    test_core = GNUNET_NO;
+  else
+  {
+    GNUNET_free (comm_name);
+    GNUNET_free (solver);
+    return GNUNET_SYSERR;
+  }
+
   pref_str = GNUNET_strdup(tmp_sep + 1);
 
   GNUNET_asprintf (&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver,
@@ -1156,7 +432,7 @@ main (int argc, char *argv[])
 
   if (0 != strcmp (pref_str, "NONE"))
   {
-    for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
+    for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++)
     {
       if (0 == strcmp (pref_str, prefs[c]))
       {
@@ -1175,9 +451,26 @@ main (int argc, char *argv[])
     fprintf (stderr, "Unknown preference: `%s'\n", pref_str);
     GNUNET_free(solver);
     GNUNET_free(pref_str);
+    GNUNET_free (comm_name);
     return -1;
   }
 
+  for (c = 0; c < (argc - 1); c++)
+  {
+    if (0 == strcmp (argv[c], "-d"))
+      break;
+  }
+  if (c < argc - 1)
+  {
+    if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], &perf_duration))
+        fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
+  }
+  else
+  {
+    perf_duration = BENCHMARK_DURATION;
+  }
+  fprintf (stderr, "Running benchmark for %llu secs\n", (unsigned long long) (perf_duration.rel_value_us) / (1000 * 1000));
+
   for (c = 0; c < (argc - 1); c++)
   {
     if (0 == strcmp (argv[c], "-s"))
@@ -1210,39 +503,55 @@ main (int argc, char *argv[])
   else
     num_masters = DEFAULT_MASTERS_NUM;
 
+  logging = GNUNET_NO;
+  for (c = 0; c < argc; c++)
+  {
+    if (0 == strcmp (argv[c], "-l"))
+      logging = GNUNET_YES;
+  }
+
+  if (GNUNET_YES == logging)
+  {
+    for (c = 0; c < (argc - 1); c++)
+    {
+      if (0 == strcmp (argv[c], "-f"))
+        break;
+    }
+    if (c < argc - 1)
+    {
+      if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], &log_frequency))
+          fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]);
+    }
+    else
+    {
+      log_frequency = LOGGING_FREQUENCY;
+    }
+    fprintf (stderr, "Using log frequency %llu ms\n",
+        (unsigned long long) (log_frequency.rel_value_us) / (1000));
+  }
+
+  GNUNET_asprintf (&testname, "%s_%s_%s",solver, comm_name, pref_str);
+
   if (num_slaves < num_masters)
   {
     fprintf (stderr, "Number of master peers is lower than slaves! exit...\n");
     GNUNET_free(test_name);
     GNUNET_free(solver);
     GNUNET_free(pref_str);
+    GNUNET_free (comm_name);
     return GNUNET_SYSERR;
   }
 
-  state.connected_ATS_service = GNUNET_NO;
-  state.connected_CORE_service = GNUNET_NO;
-  state.connected_PEERS = GNUNET_NO;
-  state.benchmarking = GNUNET_NO;
-  state.connected_PEERS = GNUNET_NO;
-
-  mps = GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer));
-  sps = GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer));
-
-  /* Start topology */
-  uint64_t event_mask;
-  event_mask = 0;
-  event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
-  event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
-  (void) GNUNET_TESTBED_test_run ("perf_ats", conf_name,
-      num_slaves + num_masters, event_mask, &controller_event_cb, NULL,
-      &main_run, NULL );
-
-  GNUNET_free(solver);
-  GNUNET_free(pref_str);
-  GNUNET_free(conf_name);
-  GNUNET_free(test_name);
-  GNUNET_free(mps);
-  GNUNET_free(sps);
+  /**
+   * Setup the topology
+   */
+  GNUNET_ATS_TEST_create_topology ("perf-ats", conf_name,
+      num_slaves, num_masters,
+      test_core,
+      &do_benchmark,
+      NULL,
+      &test_recv_cb,
+      &log_request_cb);
 
   return result;
 }