- begin work on enhanced multipart receiving
[oweals/gnunet.git] / src / ats-tests / perf_ats.c
index a50de992f0f326976b537984ed7fe616312ee7a7..f52bcfb25c578013a791ae753bb15f4ea8e478a0 100644 (file)
 #include "gnunet_testbed_service.h"
 #include "gnunet_ats_service.h"
 #include "gnunet_core_service.h"
+#include "perf_ats.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_MESSAGE_SIZE 1000
 #define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
 
-/**
- * Information about a benchmarking partner
- */
-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;
-};
-
 /**
  * Connect peers with testbed
  */
@@ -107,138 +62,37 @@ struct TestbedConnectOperation
 };
 
 /**
- * Information we track for a peer in the testbed.
+ * Overall state of the performance benchmark
  */
-struct BenchmarkPeer
+struct BenchmarkState
 {
   /**
-   * 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
+   * Are we connected to ATS service of all peers: GNUNET_YES/NO
    */
-  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;
+  int connected_ATS_service;
 
   /**
-   * Total number of messages this peer has sent
+   * Are we connected to CORE service of all peers: GNUNET_YES/NO
    */
-  unsigned int total_messages_sent;
+  int connected_COMM_service;
 
   /**
-   * Total number of bytes this peer has sent
+   * Are we connected to all peers: GNUNET_YES/NO
    */
-  unsigned int total_bytes_sent;
+  int connected_PEERS;
 
   /**
-   * Total number of messages this peer has received
+   * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
    */
-  unsigned int total_messages_received;
+  int connected_CORE;
 
   /**
-   * Total number of bytes this peer has received
+   * Are we connected to CORE service of all peers: GNUNET_YES/NO
    */
-  unsigned int total_bytes_received;
-};
-
-/**
- * Overall state of the performance benchmark
- */
-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;
-
-  /* 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;
 };
 
+
 /**
  * Shutdown task
  */
@@ -254,11 +108,25 @@ static GNUNET_SCHEDULER_TaskIdentifier progress_task;
  */
 static int result;
 
+/**
+ * Test result logging
+ */
+static int logging;
+
+/**Test core (GNUNET_YES) or transport (GNUNET_NO)
+ */
+static int test_core;
+
 /**
  * Solver string
  */
 static char *solver;
 
+/**
+ * Preference string
+ */
+static char *testname;
+
 /**
  * Preference string
  */
@@ -272,21 +140,32 @@ static int pref_val;
 /**
  * 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;
+static unsigned int num_slaves;
+
 /**
  * Array of slave peers
  */
-struct BenchmarkPeer *sps;
+static struct BenchmarkPeer *sps;
+
+/**
+ * Benchmark duration
+ */
+static struct GNUNET_TIME_Relative perf_duration;
+
+/**
+ * Logging frequency
+ */
+static struct GNUNET_TIME_Relative log_frequency;
 
 /**
  * Benchmark state
@@ -300,8 +179,9 @@ evaluate ()
   int c_s;
   unsigned int duration;
   struct BenchmarkPeer *mp;
+  struct BenchmarkPartner *p;
 
-  duration = (BENCHMARK_DURATION.rel_value_us / (1000 * 1000));
+  duration = (perf_duration.rel_value_us / (1000 * 1000));
   for (c_m = 0; c_m < num_masters; c_m++)
   {
     mp = &mps[c_m];
@@ -314,14 +194,20 @@ evaluate ()
 
     for (c_s = 0; c_s < num_slaves; c_s++)
     {
+      p = &mp->partners[c_s];
+      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,
+          (p->bytes_sent / 1024) / duration,
+          ((double) p->bytes_sent * 100) / mp->total_bytes_sent,
+          (p->bytes_received / 1024) / duration,
+          ((double) p->bytes_received * 100) / mp->total_bytes_received );
       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,
+          p->total_app_rtt / (1000 * p->messages_sent));
     }
   }
 }
@@ -338,6 +224,10 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   int c_m;
   int c_s;
   int c_op;
+  struct BenchmarkPeer *p;
+
+  if (GNUNET_YES == logging)
+    perf_logging_stop();
 
   shutdown_task = GNUNET_SCHEDULER_NO_TASK;
   if (GNUNET_SCHEDULER_NO_TASK != progress_task)
@@ -353,82 +243,90 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   for (c_m = 0; c_m < num_masters; c_m++)
   {
+    p = &mps[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;
+      GNUNET_TESTBED_operation_done (p->peer_id_op);
+      p->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;
+    if (GNUNET_SCHEDULER_NO_TASK != p->ats_task)
+      GNUNET_SCHEDULER_cancel (p->ats_task);
+    p->ats_task = GNUNET_SCHEDULER_NO_TASK;
 
-    for (c_op = 0; c_op < num_slaves; c_op++)
+    for (c_op = 0; c_op < p->num_partners; c_op++)
     {
-
-      if (NULL != mps[c_m].partners[c_op].cth)
+      if (NULL != p->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;
+        GNUNET_CORE_notify_transmit_ready_cancel (p->partners[c_op].cth);
+        p->partners[c_op].cth = NULL;
       }
-
-      if (NULL != mps[c_m].core_connect_ops[c_op].connect_op)
+      if (NULL != p->partners[c_op].tth)
+      {
+        GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->partners[c_op].tth);
+        p->partners[c_op].tth = NULL;
+      }
+      if (NULL != p->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;
+            p->core_connect_ops[c_op].connect_op);
+        p->core_connect_ops[c_op].connect_op = NULL;
         result = 1;
       }
     }
 
-    if (NULL != mps[c_m].ats_perf_op)
+    if (NULL != p->ats_perf_op)
     {
-      GNUNET_TESTBED_operation_done (mps[c_m].ats_perf_op);
-      mps[c_m].ats_perf_op = NULL;
+      GNUNET_TESTBED_operation_done (p->ats_perf_op);
+      p->ats_perf_op = NULL;
     }
 
-    if (NULL != mps[c_m].core_op)
+    if (NULL != p->comm_op)
     {
-      GNUNET_TESTBED_operation_done (mps[c_m].core_op);
-      mps[c_m].core_op = NULL;
+      GNUNET_TESTBED_operation_done (p->comm_op);
+      p->comm_op = NULL;
     }
-    GNUNET_free(mps[c_m].core_connect_ops);
-    GNUNET_free(mps[c_m].partners);
-    mps[c_m].partners = NULL;
+    GNUNET_free(p->core_connect_ops);
+    GNUNET_free(p->partners);
+    p->partners = NULL;
   }
 
   for (c_s = 0; c_s < num_slaves; c_s++)
   {
-    if (NULL != sps[c_s].peer_id_op)
+    p = &sps[c_s];
+    if (NULL != p->peer_id_op)
     {
-      GNUNET_TESTBED_operation_done (sps[c_s].peer_id_op);
-      sps[c_s].peer_id_op = NULL;
+      GNUNET_TESTBED_operation_done (p->peer_id_op);
+      p->peer_id_op = NULL;
     }
 
-    for (c_op = 0; c_op < num_slaves; c_op++)
+    for (c_op = 0; c_op < p->num_partners; c_op++)
     {
-      if (NULL != sps[c_s].partners[c_op].cth)
+      if (NULL != p->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;
+        GNUNET_CORE_notify_transmit_ready_cancel (p->partners[c_op].cth);
+        p->partners[c_op].cth = NULL;
+      }
+      if (NULL != p->partners[c_op].tth)
+      {
+        GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->partners[c_op].tth);
+        p->partners[c_op].tth = NULL;
       }
     }
-
-    if (NULL != sps[c_s].ats_perf_op)
+    if (NULL != p->ats_perf_op)
     {
-      GNUNET_TESTBED_operation_done (sps[c_s].ats_perf_op);
-      sps[c_s].ats_perf_op = NULL;
+      GNUNET_TESTBED_operation_done (p->ats_perf_op);
+      p->ats_perf_op = NULL;
     }
-    if (NULL != sps[c_s].core_op)
+    if (NULL != p->comm_op)
     {
-      GNUNET_TESTBED_operation_done (sps[c_s].core_op);
-      sps[c_s].core_op = NULL;
+      GNUNET_TESTBED_operation_done (p->comm_op);
+      p->comm_op = NULL;
     }
-
-    GNUNET_free(sps[c_s].partners);
-    sps[c_s].partners = NULL;
+    GNUNET_free(p->partners);
+    p->partners = NULL;
   }
 
   GNUNET_SCHEDULER_shutdown ();
@@ -479,20 +377,35 @@ controller_event_cb (void *cls,
 }
 
 static size_t
-core_send_ready (void *cls, size_t size, void *buf)
+comm_send_ready (void *cls, size_t size, void *buf)
 {
   static char msgbuf[TEST_MESSAGE_SIZE];
-  struct BenchmarkPartner *partner = cls;
+  struct BenchmarkPartner *p = cls;
   struct GNUNET_MessageHeader *msg;
 
-  partner->cth = NULL;
+  if (GNUNET_YES == test_core)
+    p->cth = NULL;
+  else
+    p->tth = NULL;
+
+  if (NULL == buf)
+  {
+    GNUNET_break (0);
+    return 0;
+  }
+  if (size < TEST_MESSAGE_SIZE)
+  {
+    GNUNET_break (0);
+    return 0;
+  }
+
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Master [%u]: Sending PING to [%u]\n",
-      partner->me->no, partner->dest->no);
+      p->me->no, p->dest->no);
 
-  partner->messages_sent++;
-  partner->bytes_sent += TEST_MESSAGE_SIZE;
-  partner->me->total_messages_sent++;
-  partner->me->total_bytes_sent += TEST_MESSAGE_SIZE;
+  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);
@@ -502,6 +415,25 @@ core_send_ready (void *cls, size_t size, void *buf)
   return TEST_MESSAGE_SIZE;
 }
 
+static void
+comm_schedule_send (struct BenchmarkPartner *p)
+{
+  p->last_message_sent = GNUNET_TIME_absolute_get();
+  if (GNUNET_YES == test_core)
+  {
+    p->cth = GNUNET_CORE_notify_transmit_ready (
+      p->me->ch, GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, &p->dest->id,
+      TEST_MESSAGE_SIZE, &comm_send_ready, p);
+  }
+  else
+  {
+    p->tth = GNUNET_TRANSPORT_notify_transmit_ready (
+      p->me->th, &p->dest->id, TEST_MESSAGE_SIZE, 0,GNUNET_TIME_UNIT_MINUTES,
+      &comm_send_ready, p);
+  }
+
+}
+
 static void
 print_progress ()
 {
@@ -509,7 +441,7 @@ print_progress ()
   progress_task = GNUNET_SCHEDULER_NO_TASK;
 
   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,
@@ -540,7 +472,7 @@ do_benchmark ()
   int c_s;
 
   if ((state.connected_ATS_service == GNUNET_NO)
-      || (state.connected_CORE_service == GNUNET_NO)
+      || (state.connected_COMM_service == GNUNET_NO)
       || (state.connected_PEERS == GNUNET_NO)
       || (state.connected_CORE == GNUNET_NO))
     return;
@@ -550,7 +482,7 @@ do_benchmark ()
 
   if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
     GNUNET_SCHEDULER_cancel (shutdown_task);
-  shutdown_task = GNUNET_SCHEDULER_add_delayed (BENCHMARK_DURATION,
+  shutdown_task = GNUNET_SCHEDULER_add_delayed (perf_duration,
       &do_shutdown, NULL );
 
   progress_task = GNUNET_SCHEDULER_add_now (&print_progress, NULL );
@@ -559,14 +491,13 @@ do_benchmark ()
   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]);
-    }
+      comm_schedule_send (&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]);
   }
+  if (GNUNET_YES == logging)
+    perf_logging_start (log_frequency, testname, mps, num_masters);
+
 }
 
 static void
@@ -614,7 +545,7 @@ do_connect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   struct BenchmarkPeer *p;
 
   if ((state.connected_ATS_service == GNUNET_NO)
-      || (state.connected_CORE_service == GNUNET_NO))
+      || (state.connected_COMM_service == GNUNET_NO))
     return;
 
   GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Connecting peers on CORE level\n"));
@@ -656,7 +587,7 @@ do_connect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * @param peer peer identity this notification is about
  */
 static void
-core_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
+comm_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
 {
   struct BenchmarkPeer *me = cls;
   struct BenchmarkPeer *remote;
@@ -706,19 +637,35 @@ core_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
   GNUNET_free(id);
 }
 
+static struct BenchmarkPartner *
+find_partner (struct BenchmarkPeer *me, const struct GNUNET_PeerIdentity * peer)
+{
+  int c_m;
+  GNUNET_assert (NULL != me);
+  GNUNET_assert (NULL != peer);
+
+  for (c_m = 0; c_m < me->num_partners; c_m++)
+  {
+    /* Find a partner with other as destination */
+    if (0 == memcmp (peer, &me->partners[c_m].dest->id,
+            sizeof(struct GNUNET_PeerIdentity)))
+    {
+      return &me->partners[c_m];
+    }
+  }
+
+  return NULL;
+}
+
 static void
-core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
+comm_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
 {
   struct BenchmarkPeer *me = cls;
-  struct BenchmarkPeer *remote;
+  struct BenchmarkPartner *p;
   char *id;
 
-  remote = find_peer (peer);
-  if (NULL == remote)
-  {
-    GNUNET_break(0);
+  if (NULL == (p = find_partner (me, peer)))
     return;
-  }
 
   id = GNUNET_strdup (GNUNET_i2s (&me->id));
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s disconnected from %s \n", id,
@@ -727,22 +674,35 @@ core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
   me->core_connections--;
 
   if ((GNUNET_YES == state.benchmarking)
-      && ((GNUNET_YES == me->master) || (GNUNET_YES == remote->master)))
+      && ((GNUNET_YES == me->master) || (GNUNET_YES == p->dest->master)))
   {
     GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
         "%s disconnected from %s while benchmarking \n", id, GNUNET_i2s (peer));
+    if (NULL != p->tth)
+    {
+      GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->tth);
+      p->tth = NULL;
+    }
+    if (NULL != p->cth)
+    {
+      GNUNET_CORE_notify_transmit_ready_cancel (p->cth);
+      p->cth = NULL;
+    }
   }
   GNUNET_free(id);
 }
 
 static size_t
-core_send_echo_ready (void *cls, size_t size, void *buf)
+comm_send_pong_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;
+  if (GNUNET_YES == test_core)
+    p->cth = NULL;
+  else
+    p->tth = NULL;
 
   p->messages_sent++;
   p->bytes_sent += TEST_MESSAGE_SIZE;
@@ -759,28 +719,18 @@ core_send_echo_ready (void *cls, size_t size, void *buf)
 }
 
 static int
-core_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
+comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
     const struct GNUNET_MessageHeader *message)
 {
-  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)
+
+  if (NULL == (p = find_partner(me, other)))
   {
     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,
@@ -791,36 +741,35 @@ core_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
   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);
+  if (GNUNET_YES == test_core)
+  {
+    GNUNET_assert (NULL == p->cth);
+    p->cth = GNUNET_CORE_notify_transmit_ready (me->ch, GNUNET_NO, 0,
+        GNUNET_TIME_UNIT_MINUTES, &p->dest->id, TEST_MESSAGE_SIZE,
+        &comm_send_pong_ready, p);
+  }
+  else
+  {
+    GNUNET_assert (NULL == p->tth);
+    p->tth = GNUNET_TRANSPORT_notify_transmit_ready (me->th, &p->dest->id,
+        TEST_MESSAGE_SIZE, 0, GNUNET_TIME_UNIT_MINUTES, &comm_send_pong_ready,
+        p);
+  }
   return GNUNET_OK;
 }
 
 static int
-core_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
+comm_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++)
-  {
-    if (0
-        == memcmp (other, &me->partners[c_s].dest->id,
-            sizeof(struct GNUNET_PeerIdentity)))
-    {
-      p = &me->partners[c_s];
-      break;
-    }
-  }
-  if (NULL == p)
+  if (NULL == (p = find_partner (me, other)))
   {
     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,
@@ -830,11 +779,10 @@ core_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
   p->bytes_received += TEST_MESSAGE_SIZE;
   p->me->total_messages_received++;
   p->me->total_bytes_received += TEST_MESSAGE_SIZE;
+  p->total_app_rtt += GNUNET_TIME_absolute_get_difference(p->last_message_sent,
+      GNUNET_TIME_absolute_get()).rel_value_us;
 
-  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);
-
+  comm_schedule_send (p);
   return GNUNET_OK;
 }
 
@@ -844,11 +792,11 @@ 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,
+      &comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 }, { &comm_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);
+  me->ch = GNUNET_CORE_connect (cfg, me, NULL, comm_connect_cb,
+      comm_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;
@@ -864,10 +812,10 @@ core_disconnect_adapter (void *cls, void *op_result)
 }
 
 static void
-core_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
+comm_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
     void *ca_result, const char *emsg)
 {
-  static int core_done = 0;
+  static int comm_done = 0;
   if ((NULL != emsg) || (NULL == ca_result))
   {
     GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
@@ -877,34 +825,90 @@ core_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
     shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
     return;
   }
-  core_done++;
+  comm_done++;
 
-  if (core_done == num_slaves + num_masters)
+  if (comm_done == num_slaves + num_masters)
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all CORE services\n");
-    state.connected_CORE_service = GNUNET_YES;
+    GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all %s services\n",
+        (GNUNET_YES == test_core) ? "CORE" : "TRANSPORT");
+    state.connected_COMM_service = GNUNET_YES;
     GNUNET_SCHEDULER_add_now (&do_connect_peers, NULL );
   }
 }
 
 static void
-do_connect_core (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+transport_recv_cb (void *cls,
+                   const struct GNUNET_PeerIdentity * peer,
+                   const struct GNUNET_MessageHeader * message)
+{
+  if (TEST_MESSAGE_SIZE != ntohs (message->size) ||
+      (TEST_MESSAGE_TYPE_PING != ntohs (message->type) &&
+      TEST_MESSAGE_TYPE_PONG != ntohs (message->type)))
+  {
+    return;
+  }
+  if (TEST_MESSAGE_TYPE_PING == ntohs (message->type))
+    comm_handle_ping (cls, peer, message);
+
+  if (TEST_MESSAGE_TYPE_PONG == ntohs (message->type))
+    comm_handle_pong (cls, peer, message);
+}
+
+
+static void *
+transport_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  struct BenchmarkPeer *me = cls;
+
+  me->th = GNUNET_TRANSPORT_connect (cfg, &me->id, me,  &transport_recv_cb,
+      &comm_connect_cb, &comm_disconnect_cb);
+  if (NULL == me->th)
+    GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create transport connection \n");
+  return me->th;
+}
+
+static void
+transport_disconnect_adapter (void *cls, void *op_result)
+{
+  struct BenchmarkPeer *me = cls;
+
+  GNUNET_TRANSPORT_disconnect (me->th);
+  me->th = NULL;
+}
+
+static void
+do_comm_connect (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");
+  GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all %s services\n",
+      (GNUNET_YES == test_core) ? "CORE" : "TRANSPORT");
   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,
+    if (GNUNET_YES == test_core)
+      mps[c_m].comm_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer,
+        "core", &comm_connect_completion_cb, NULL, &core_connect_adapter,
         &core_disconnect_adapter, &mps[c_m]);
+    else
+    {
+      mps[c_m].comm_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer,
+        "transport", &comm_connect_completion_cb, NULL, &transport_connect_adapter,
+        &transport_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,
+    if (GNUNET_YES == test_core)
+      sps[c_s].comm_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer,
+        "core", &comm_connect_completion_cb, NULL, &core_connect_adapter,
         &core_disconnect_adapter, &sps[c_s]);
+    else
+    {
+      sps[c_s].comm_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer,
+        "transport", &comm_connect_completion_cb, NULL, &transport_connect_adapter,
+        &transport_disconnect_adapter, &sps[c_s]);
+    }
   }
 }
 
@@ -915,32 +919,88 @@ ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
     const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
 {
   struct BenchmarkPeer *me = cls;
+  struct BenchmarkPartner *p;
   int c_a;
+  int log;
   char *peer_id;
 
-  peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
-  for (c_a = 0; c_a < ats_count; c_a++)
+  p = find_partner (me, &address->peer);
+  if (NULL == p)
   {
-    /*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));*/
+    /* This is not one of my partners
+     * Will happen since the peers will connect to each other due to gossiping
+     */
+    return;
   }
-#if 0
-  if ((GNUNET_YES == me->master)
-      && (0 == memcmp (&address->peer, &me->destination->id,
-              sizeof(struct GNUNET_PeerIdentity))))
+  peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
+
+  log = GNUNET_NO;
+  if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) ||
+      (p->bandwidth_out != ntohl (bandwidth_out.value__)))
+      log = GNUNET_YES;
+  p->bandwidth_in = ntohl (bandwidth_in.value__);
+  p->bandwidth_out = ntohl (bandwidth_out.value__);
+
+  for (c_a = 0; c_a < ats_count; c_a++)
   {
-    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__));
-  }
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s [%u] received ATS information: %s %s %u\n",
+        (GNUNET_YES == p->me->master) ? "Master" : "Slave",
+        p->me->no,
+        GNUNET_i2s (&p->dest->id),
+        GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)),
+        ntohl(ats[c_a].value));
+    switch (ntohl (ats[c_a].type ))
+    {
+      case GNUNET_ATS_ARRAY_TERMINATOR:
+        break;
+      case GNUNET_ATS_UTILIZATION_OUT:
+        if (p->ats_utilization_up != ntohl (ats[c_a].value))
+            log = GNUNET_YES;
+        p->ats_utilization_up = ntohl (ats[c_a].value);
 
-  store_information (&bp->id, address, address_active, bandwidth_in,
-      bandwidth_out, ats, ats_count);
-#endif
+        break;
+      case GNUNET_ATS_UTILIZATION_IN:
+        if (p->ats_utilization_down != ntohl (ats[c_a].value))
+            log = GNUNET_YES;
+        p->ats_utilization_down = ntohl (ats[c_a].value);
+        break;
+      case GNUNET_ATS_NETWORK_TYPE:
+        if (p->ats_network_type != ntohl (ats[c_a].value))
+            log = GNUNET_YES;
+        p->ats_network_type = ntohl (ats[c_a].value);
+        break;
+      case GNUNET_ATS_QUALITY_NET_DELAY:
+        if (p->ats_delay != ntohl (ats[c_a].value))
+            log = GNUNET_YES;
+        p->ats_delay = ntohl (ats[c_a].value);
+        break;
+      case GNUNET_ATS_QUALITY_NET_DISTANCE:
+        if (p->ats_distance != ntohl (ats[c_a].value))
+            log = GNUNET_YES;
+        p->ats_distance = ntohl (ats[c_a].value);
+        GNUNET_break (0);
+        break;
+      case GNUNET_ATS_COST_WAN:
+        if (p->ats_cost_wan != ntohl (ats[c_a].value))
+            log = GNUNET_YES;
+        p->ats_cost_wan = ntohl (ats[c_a].value);
+        break;
+      case GNUNET_ATS_COST_LAN:
+        if (p->ats_cost_lan != ntohl (ats[c_a].value))
+            log = GNUNET_YES;
+        p->ats_cost_lan = ntohl (ats[c_a].value);
+        break;
+      case GNUNET_ATS_COST_WLAN:
+        if (p->ats_cost_wlan != ntohl (ats[c_a].value))
+            log = GNUNET_YES;
+        p->ats_cost_wlan = ntohl (ats[c_a].value);
+        break;
+      default:
+        break;
+    }
+  }
+  if ((GNUNET_YES == logging) && (GNUNET_YES == log))
+    collect_log_now();
   GNUNET_free(peer_id);
 }
 
@@ -987,7 +1047,7 @@ ats_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
   {
     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 );
+    GNUNET_SCHEDULER_add_now (&do_comm_connect, NULL );
   }
 }
 
@@ -1053,9 +1113,11 @@ peerinformation_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op,
  *          failed
  */
 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)
+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;
@@ -1081,7 +1143,8 @@ main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers,
     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));
+        GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPartner));
+    mps[c_m].num_partners = num_slaves;
     /* Initialize partners */
     for (c_s = 0; c_s < num_slaves; c_s++)
     {
@@ -1100,7 +1163,8 @@ main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers,
     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));
+        GNUNET_malloc (num_masters * sizeof (struct BenchmarkPartner));
+    sps[c_s].num_partners = num_masters;
     /* Initialize partners */
     for (c_m = 0; c_m < num_masters; c_m++)
     {
@@ -1119,6 +1183,7 @@ 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;
   int c;
@@ -1144,6 +1209,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,
@@ -1175,9 +1262,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,17 +1314,47 @@ 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_COMM_service = GNUNET_NO;
   state.connected_PEERS = GNUNET_NO;
   state.benchmarking = GNUNET_NO;
   state.connected_PEERS = GNUNET_NO;
@@ -1233,7 +1367,7 @@ main (int argc, char *argv[])
   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,
+  (void) GNUNET_TESTBED_test_run ("perf-ats", conf_name,
       num_slaves + num_masters, event_mask, &controller_event_cb, NULL,
       &main_run, NULL );
 
@@ -1241,6 +1375,8 @@ main (int argc, char *argv[])
   GNUNET_free(pref_str);
   GNUNET_free(conf_name);
   GNUNET_free(test_name);
+  GNUNET_free(testname);
+  GNUNET_free (comm_name);
   GNUNET_free(mps);
   GNUNET_free(sps);