REST/NAMESTORE: rework API
[oweals/gnunet.git] / src / transport / gnunet-transport-profiler.c
index f37d2f8a4ed8ff73ffa171e8a725ff7f01837112..89f5b410863bc1eeec8cbca357f99004886ad9cc 100644 (file)
@@ -1,44 +1,60 @@
 /*
  This file is part of GNUnet.
- (C) 2011-2014 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2011-2016 GNUnet e.V.
 
- GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
 
  GNUnet is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- General Public License for more details.
Affero General Public License for more details.
 
- 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.
+ You should have received a copy of the GNU Affero General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+     SPDX-License-Identifier: AGPL3.0-or-later
  */
 
 /**
- * @file src/transport/gnunet-transport.c
- * @brief Tool to help configure, measure and control the transport subsystem.
+ * @file src/transport/gnunet-transport-profiler.c
+ * @brief Tool to help benchmark the transport subsystem.
  * @author Christian Grothoff
  * @author Nathan Evans
  *
- * This utility can be used to test if a transport mechanism for
- * GNUnet is properly configured.
+ * This utility can be used to benchmark a transport mechanism for
+ * GNUnet.
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
-#include "gnunet_resolver_service.h"
 #include "gnunet_protocols.h"
+#include "gnunet_ats_service.h"
 #include "gnunet_transport_service.h"
-#include "gnunet_nat_lib.h"
+
+
+struct Iteration
+{
+  struct Iteration *next;
+  struct Iteration *prev;
+  struct GNUNET_TIME_Absolute start;
+  struct GNUNET_TIME_Absolute end;
+
+  struct GNUNET_TIME_Relative dur;
+
+  /* Transmission rate for this iteration in KB/s */
+  float rate;
+
+  unsigned int msgs_sent;
+};
 
 
 /**
  * Timeout for a connections
  */
-#define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
+#define CONNECT_TIMEOUT \
+  GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
 
 /**
  * Benchmarking block size in bye
  */
 #define DEFAULT_MESSAGE_COUNT 1024
 
+/**
+ * Benchmarking iteration count
+ */
+#define DEFAULT_ITERATION_COUNT 1
+
 /**
  * Option -s.
  */
@@ -65,11 +86,21 @@ static int benchmark_receive;
  */
 static unsigned int benchmark_count;
 
+/**
+ * Option -i.
+ */
+static unsigned int benchmark_iterations;
+
 /**
  * Option -m.
  */
 static unsigned int benchmark_size;
 
+/**
+ * Benchmark running
+ */
+static unsigned int benchmark_running;
+
 /**
  * Which peer should we connect to?
  */
@@ -78,7 +109,12 @@ static char *cpid;
 /**
  * Handle to transport service.
  */
-static struct GNUNET_TRANSPORT_Handle *handle;
+static struct GNUNET_TRANSPORT_CoreHandle *handle;
+
+/**
+ * Handle to ATS service.
+ */
+static struct GNUNET_ATS_ConnectivityHandle *ats;
 
 /**
  * Configuration handle
@@ -88,35 +124,23 @@ static struct GNUNET_CONFIGURATION_Handle *cfg;
 /**
  * Try_connect handle
  */
-struct GNUNET_TRANSPORT_TryConnectHandle *tc_handle;
+static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh;
 
+static struct Iteration *ihead;
 
+static struct Iteration *itail;
 
 /**
  * Global return value (0 success).
  */
 static int ret;
-/**
- * Number of bytes of traffic we received so far.
- */
-static unsigned long long traffic_received;
 
 /**
- * Number of bytes of traffic we sent so far.
+ * Handle for transmissions.
  */
-static unsigned long long traffic_sent;
+static struct GNUNET_MQ_Handle *mq;
 
-/**
- * Starting time of transmitting/receiving data.
- */
-static struct GNUNET_TIME_Absolute start_time;
-
-/**
- * Handle for current transmission request.
- */
-static struct GNUNET_TRANSPORT_TransmitHandle *th;
-
-struct GNUNET_TRANSPORT_Blacklist *bl_handle;
+static struct GNUNET_TRANSPORT_Blacklist *bl_handle;
 
 /**
  * Identity of the peer we transmit to / connect to.
@@ -124,102 +148,150 @@ struct GNUNET_TRANSPORT_Blacklist *bl_handle;
  */
 static struct GNUNET_PeerIdentity pid;
 
-/**
- * Task scheduled for cleanup / termination of the process.
- */
-static GNUNET_SCHEDULER_TaskIdentifier end;
-
-/**
- * Task for operation timeout
- */
-static GNUNET_SCHEDULER_TaskIdentifier op_timeout;
-
 /**
  * Selected level of verbosity.
  */
-static int verbosity;
+static unsigned int verbosity;
+
 
 /**
  * Task run in monitor mode when the user presses CTRL-C to abort.
  * Stops monitoring activity.
  *
  * @param cls NULL
- * @param tc scheduler context
  */
 static void
-shutdown_task (void *cls,
-               const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
 {
-  struct GNUNET_TIME_Relative duration;
+  struct Iteration *icur;
+  struct Iteration *inext;
+
+  unsigned int iterations;
+
+  unsigned long long avg_duration;
+  float avg_rate;
+  float stddev_rate;
+  float stddev_duration;
 
-  end = GNUNET_SCHEDULER_NO_TASK;
-  if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
+  if (NULL != ats_sh)
   {
-    GNUNET_SCHEDULER_cancel (op_timeout);
-    op_timeout = GNUNET_SCHEDULER_NO_TASK;
+    GNUNET_ATS_connectivity_suggest_cancel (ats_sh);
+    ats_sh = NULL;
   }
-
-  if (NULL != tc_handle)
+  if (NULL != bl_handle)
   {
-    GNUNET_TRANSPORT_try_connect_cancel (tc_handle);
-    tc_handle = NULL;
+    GNUNET_TRANSPORT_blacklist_cancel (bl_handle);
+    bl_handle = NULL;
   }
-  if (NULL != th)
+  if (NULL != ats)
   {
-    GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
-    th = NULL;
+    GNUNET_ATS_connectivity_done (ats);
+    ats = NULL;
   }
   if (NULL != handle)
   {
-    GNUNET_TRANSPORT_disconnect (handle);
+    GNUNET_TRANSPORT_core_disconnect (handle);
     handle = NULL;
   }
-  if (NULL != bl_handle )
-  {
-    GNUNET_TRANSPORT_blacklist_cancel (bl_handle);
-    bl_handle = NULL;
-  }
-#if 0
+
+  if (verbosity > 0)
+    FPRINTF (stdout, "\n");
+
+  /* Output format:
+   * All time values in ms
+   * Rate in KB/s
+   * #messages;#messagesize;#avg_dur;#avg_rate;#duration_i0;#duration_i0;... */
+
   if (benchmark_send)
   {
-    duration = GNUNET_TIME_absolute_get_duration (start_time);
+    /* First iteration to calculcate avg and stddev */
+    iterations = 0;
+    avg_duration = 0;
+    avg_rate = 0.0;
+
+    inext = ihead;
+    while (NULL != (icur = inext))
+    {
+      inext = icur->next;
+      icur->rate = ((benchmark_count * benchmark_size) / 1024) /
+                   ((float) icur->dur.rel_value_us / (1000 * 1000));
+      if (verbosity > 0)
+        FPRINTF (stdout,
+                 _ ("%llu B in %llu ms == %.2f KB/s!\n"),
+                 ((long long unsigned int) benchmark_count * benchmark_size),
+                 ((long long unsigned int) icur->dur.rel_value_us / 1000),
+                 (float) icur->rate);
+
+      avg_duration += icur->dur.rel_value_us / (1000);
+      avg_rate += icur->rate;
+      iterations++;
+    }
+    if (0 == iterations)
+      iterations = 1; /* avoid division by zero */
+    /* Calculate average rate */
+    avg_rate /= iterations;
+    /* Calculate average duration */
+    avg_duration /= iterations;
+
+    stddev_rate = 0;
+    stddev_duration = 0;
+    inext = ihead;
+    while (NULL != (icur = inext))
+    {
+      inext = icur->next;
+      stddev_rate += ((icur->rate - avg_rate) * (icur->rate - avg_rate));
+      stddev_duration += (((icur->dur.rel_value_us / 1000) - avg_duration) *
+                          ((icur->dur.rel_value_us / 1000) - avg_duration));
+    }
+    /* Calculate standard deviation rate */
+    stddev_rate = stddev_rate / iterations;
+    stddev_rate = sqrtf (stddev_rate);
+
+    /* Calculate standard deviation duration */
+    stddev_duration = stddev_duration / iterations;
+    stddev_duration = sqrtf (stddev_duration);
+
+    /* Output */
     FPRINTF (stdout,
-             _("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
-             1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us),
-             traffic_sent,
-             GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
+             "%u;%u;%llu;%llu;%.2f;%.2f",
+             benchmark_count,
+             benchmark_size,
+             avg_duration,
+             (unsigned long long) stddev_duration,
+             avg_rate,
+             stddev_rate);
+
+    inext = ihead;
+    while (NULL != (icur = inext))
+    {
+      inext = icur->next;
+      GNUNET_CONTAINER_DLL_remove (ihead, itail, icur);
+
+      FPRINTF (stdout,
+               ";%llu;%.2f",
+               (long long unsigned int) (icur->dur.rel_value_us / 1000),
+               icur->rate);
+
+      GNUNET_free (icur);
+    }
   }
+#if 0
   if (benchmark_receive)
   {
     duration = GNUNET_TIME_absolute_get_duration (start_time);
     FPRINTF (stdout,
-             _("Received %llu bytes/s (%llu bytes in %s)\n"),
+             "Received %llu bytes/s (%llu bytes in %s)\n",
              1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
              traffic_received,
              GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
   }
 #endif
+  FPRINTF (stdout, "\n");
 }
 
 
 static void
-operation_timeout (void *cls,
-                   const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-
-  op_timeout = GNUNET_SCHEDULER_NO_TASK;
-  if ((benchmark_send) || (benchmark_receive))
-  {
-    FPRINTF (stdout,
-             _("Failed to connect to `%s'\n"),
-             GNUNET_i2s_full (&pid));
-    if (GNUNET_SCHEDULER_NO_TASK != end)
-      GNUNET_SCHEDULER_cancel (end);
-    end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
-    ret = 1;
-    return;
-  }
-}
+iteration_done ();
 
 
 /**
@@ -233,72 +305,67 @@ operation_timeout (void *cls,
  * @param buf where the callee should write the message
  * @return number of bytes written to @a buf
  */
-static size_t
-transmit_data (void *cls,
-               size_t size,
-               void *buf)
+static void
+send_msg (void *cls)
 {
-  static  msgs_sent = 0;
-  struct GNUNET_MessageHeader *m = buf;
-
-
-  if ((NULL == buf) || (0 == size))
-  {
-    th = NULL;
-    return 0;
-  }
+  struct GNUNET_MQ_Envelope *env;
+  struct GNUNET_MessageHeader *m;
 
-  msgs_sent ++;
-
-  GNUNET_assert(size >= sizeof(struct GNUNET_MessageHeader));
-  GNUNET_assert(size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
-  m->size = ntohs (size);
-  m->type = ntohs (GNUNET_MESSAGE_TYPE_DUMMY);
-  memset (&m[1], 52, size - sizeof(struct GNUNET_MessageHeader));
-  traffic_sent += size;
+  if (NULL == mq)
+    return;
+  env = GNUNET_MQ_msg_extra (m, benchmark_size, GNUNET_MESSAGE_TYPE_DUMMY);
+  memset (&m[1], 52, benchmark_size - sizeof (struct GNUNET_MessageHeader));
 
-  if (msgs_sent <benchmark_count)
+  if (itail->msgs_sent < benchmark_count)
   {
-  th = GNUNET_TRANSPORT_notify_transmit_ready (handle, &pid,
-                                               benchmark_size,
-                                               GNUNET_TIME_UNIT_FOREVER_REL,
-                                               &transmit_data, NULL);
+    GNUNET_MQ_notify_sent (env, &send_msg, NULL);
   }
   else
   {
-    if (verbosity > 0)
-      FPRINTF (stdout, _("DONE!\n"));
-    return size;
+    iteration_done ();
   }
-  if (verbosity > 0)
-    FPRINTF (stdout, _("Transmitting %u bytes to %s\n"), (unsigned int) size,
-        GNUNET_i2s (&pid));
-  return size;
+  GNUNET_MQ_send (mq, env);
+  if ((verbosity > 0) && (0 == itail->msgs_sent % 10))
+    FPRINTF (stdout, ".");
 }
 
+
 static void
-start_benchmark ()
+iteration_start ()
 {
+  struct Iteration *icur;
+
   ret = 0;
-  if (benchmark_send)
+  if (! benchmark_send)
+    return;
+  benchmark_running = GNUNET_YES;
+  icur = GNUNET_new (struct Iteration);
+  GNUNET_CONTAINER_DLL_insert_tail (ihead, itail, icur);
+  icur->start = GNUNET_TIME_absolute_get ();
+  if (verbosity > 0)
+    FPRINTF (
+      stdout,
+      "\nStarting benchmark, starting to send %u messages in %u byte blocks\n",
+      benchmark_count,
+      benchmark_size);
+  send_msg (NULL);
+}
+
+
+static void
+iteration_done ()
+{
+  static int it_count = 0;
+
+  it_count++;
+  itail->dur = GNUNET_TIME_absolute_get_duration (itail->start);
+  if (it_count == benchmark_iterations)
   {
-    if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
-    {
-      GNUNET_SCHEDULER_cancel (op_timeout);
-      op_timeout = GNUNET_SCHEDULER_NO_TASK;
-    }
-    if (verbosity > 0)
-      FPRINTF (stdout,
-          _("Successfully connected to `%s', starting to send %u messages in %u byte blocks\n"),
-          GNUNET_i2s (&pid), benchmark_count, benchmark_size);
-    start_time = GNUNET_TIME_absolute_get ();
-    if (NULL == th)
-      th = GNUNET_TRANSPORT_notify_transmit_ready (handle, &pid, benchmark_size,
-          GNUNET_TIME_UNIT_FOREVER_REL, &transmit_data, NULL );
-    else
-      GNUNET_break(0);
+    benchmark_running = GNUNET_NO;
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
+  iteration_start ();
 }
 
 
@@ -308,30 +375,25 @@ start_benchmark ()
  *
  * @param cls closure
  * @param peer the peer that connected
+ * @param m message queue for transmissions
+ * @return NULL
  */
-static void
+static void *
 notify_connect (void *cls,
-                const struct GNUNET_PeerIdentity *peer)
+                const struct GNUNET_PeerIdentity *peer,
+                struct GNUNET_MQ_Handle *m)
 {
-  if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
+  if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity)))
   {
-    FPRINTF (stdout,
-        _("Connected to different peer `%s'\n"), GNUNET_i2s (&pid));
-    return;
+    FPRINTF (stdout, "Connected to different peer `%s'\n", GNUNET_i2s (&pid));
+    return NULL;
   }
 
   if (verbosity > 0)
-    FPRINTF (stdout,
-        _("Successfully connected to `%s'\n"),
-        GNUNET_i2s (&pid));
-
-  if (NULL != tc_handle)
-  {
-    GNUNET_TRANSPORT_try_connect_cancel (tc_handle);
-    tc_handle = NULL;
-  }
-
-  start_benchmark ();
+    FPRINTF (stdout, "Successfully connected to `%s'\n", GNUNET_i2s (&pid));
+  mq = m;
+  iteration_start ();
+  return NULL;
 }
 
 
@@ -341,237 +403,221 @@ notify_connect (void *cls,
  *
  * @param cls closure
  * @param peer the peer that disconnected
+ * @param internal_cls NULL
  */
 static void
 notify_disconnect (void *cls,
-                   const struct GNUNET_PeerIdentity *peer)
+                   const struct GNUNET_PeerIdentity *peer,
+                   void *internal_cls)
 {
-  if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
+  if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity)))
     return;
-  if (benchmark_send)
+  mq = NULL;
+  if (GNUNET_YES == benchmark_running)
   {
-    FPRINTF (stdout, _("Disconnected from peer `%s' while benchmarking\n"),
-        GNUNET_i2s (&pid));
-    if (GNUNET_SCHEDULER_NO_TASK != end)
-      GNUNET_SCHEDULER_cancel (end);
+    FPRINTF (stdout,
+             "Disconnected from peer `%s' while benchmarking\n",
+             GNUNET_i2s (&pid));
     return;
   }
 }
 
+
 /**
  * Function called by the transport for each received message.
  *
  * @param cls closure
- * @param peer (claimed) identity of the other peer
  * @param message the message
+ * @return #GNUNET_OK
  */
-static void
-notify_receive (void *cls,
-                const struct GNUNET_PeerIdentity *peer,
-                const struct GNUNET_MessageHeader *message)
+static int
+check_dummy (void *cls, const struct GNUNET_MessageHeader *message)
 {
-  if (benchmark_receive)
-  {
-    if (GNUNET_MESSAGE_TYPE_DUMMY != ntohs (message->type))
-      return;
-    if (verbosity > 0)
-      FPRINTF (stdout,
-               _("Received %u bytes from %s\n"),
-               (unsigned int) ntohs (message->size),
-               GNUNET_i2s (peer));
-
-    if (traffic_received == 0)
-      start_time = GNUNET_TIME_absolute_get ();
-    traffic_received += ntohs (message->size);
-    return;
-  }
+  return GNUNET_OK; /* all messages are fine */
 }
 
 
-
+/**
+ * Function called by the transport for each received message.
+ *
+ * @param cls closure
+ * @param message the message
+ */
 static void
-try_connect_cb (void *cls,
-                const int result)
+handle_dummy (void *cls, const struct GNUNET_MessageHeader *message)
 {
-  static int retries = 0;
-
-  if (GNUNET_OK == result)
-  {
-    tc_handle = NULL;
+  if (! benchmark_receive)
     return;
-  }
-
-  retries++;
-  if (retries < 10)
-  {
-    if (verbosity > 0)
-      FPRINTF (stdout, _("Retrying to connect to `%s'\n"), GNUNET_i2s (&pid));
-
-    tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb,
-        NULL);
-  }
-  else
-  {
-    FPRINTF (stderr,
-             "%s",
-             _("Failed to send connect request to transport service\n"));
-    if (GNUNET_SCHEDULER_NO_TASK != end)
-      GNUNET_SCHEDULER_cancel (end);
-    ret = 1;
-    end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
-    return;
-  }
+  if (verbosity > 0)
+    FPRINTF (stdout,
+             "Received %u bytes\n",
+             (unsigned int) ntohs (message->size));
 }
 
+
 static int
 blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
 {
-  if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
+  if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity)))
   {
     if (verbosity > 0)
-      FPRINTF (stdout,
-          _("Denying connection to `%s'\n"),
-          GNUNET_i2s (&peer));
+      FPRINTF (stdout, "Denying connection to `%s'\n", GNUNET_i2s (peer));
     return GNUNET_SYSERR;
   }
-
-  if (verbosity > 0)
-    FPRINTF (stdout,
-        _("Permitting connection to `%s'\n"),
-        GNUNET_i2s (&pid));
   return GNUNET_OK;
 }
 
 
-
 /**
- * Function called with the result of the check if the 'transport'
- * service is running.
+ * Main function that will be run by the scheduler.
  *
- * @param cls closure with our configuration
- * @param result #GNUNET_YES if transport is running
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be NULL!)
+ * @param mycfg configuration
  */
 static void
-testservice_task (void *cls, int result)
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *mycfg)
 {
+  struct GNUNET_MQ_MessageHandler handlers[] =
+    {GNUNET_MQ_hd_var_size (dummy,
+                            GNUNET_MESSAGE_TYPE_DUMMY,
+                            struct GNUNET_MessageHeader,
+                            NULL),
+     GNUNET_MQ_handler_end ()};
+
+  cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
+
   ret = 1;
-#if 0
-  if (GNUNET_YES != result)
+  if (GNUNET_MAX_MESSAGE_SIZE <= benchmark_size)
   {
-    FPRINTF (stderr, _("Service `%s' is not running\n"), "transport");
+    FPRINTF (stderr, "Message size too big!\n");
     return;
   }
-#endif
 
   if (NULL == cpid)
   {
-    FPRINTF (stderr, _("No peer identity given\n"));
+    FPRINTF (stderr, "No peer identity given\n");
     return;
   }
-  if ((GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (cpid, strlen (cpid),
-              &pid.public_key)))
+  if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (cpid,
+                                                               strlen (cpid),
+                                                               &pid.public_key))
   {
-    FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), cpid);
+    FPRINTF (stderr, "Failed to parse peer identity `%s'\n", cpid);
     return;
   }
-
-
   if (1 == benchmark_send)
   {
-    FPRINTF (stderr,
-        _("Trying to send %u messages with size %u to peer `%s'\n"),
-          benchmark_count, benchmark_size, GNUNET_i2s (&pid));
+    if (verbosity > 0)
+      FPRINTF (stderr,
+               "Trying to send %u messages with size %u to peer `%s'\n",
+               benchmark_count,
+               benchmark_size,
+               GNUNET_i2s (&pid));
   }
   else if (1 == benchmark_receive)
   {
     FPRINTF (stderr,
-        _("Trying to receive messages from peer `%s'\n"),
-        GNUNET_i2s (&pid));
+             "Trying to receive messages from peer `%s'\n",
+             GNUNET_i2s (&pid));
   }
   else
   {
-    FPRINTF (stderr, _("No operation given\n"));
+    FPRINTF (stderr, "No operation given\n");
     return;
   }
 
-  handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive,
-      &notify_connect, &notify_disconnect);
+  ats = GNUNET_ATS_connectivity_init (cfg);
+  if (NULL == ats)
+  {
+    FPRINTF (stderr, "Failed to connect to ATS service\n");
+    ret = 1;
+    return;
+  }
 
+  handle = GNUNET_TRANSPORT_core_connect (cfg,
+                                          NULL,
+                                          handlers,
+                                          NULL,
+                                          &notify_connect,
+                                          &notify_disconnect,
+                                          NULL);
   if (NULL == handle)
   {
-    FPRINTF (stderr, "%s", _("Failed to connect to transport service\n"));
+    FPRINTF (stderr, "Failed to connect to transport service\n");
+    GNUNET_ATS_connectivity_done (ats);
+    ats = NULL;
     ret = 1;
     return;
   }
 
-  bl_handle = GNUNET_TRANSPORT_blacklist (cfg, blacklist_cb, NULL);
-  tc_handle = GNUNET_TRANSPORT_try_connect(handle, &pid, try_connect_cb, NULL);
-
-  end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                      &shutdown_task,
-                                      NULL);
+  bl_handle = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL);
+  ats_sh = GNUNET_ATS_connectivity_suggest (ats, &pid, 1);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
 }
 
 
-/**
- * Main function that will be run by the scheduler.
- *
- * @param cls closure
- * @param args remaining command-line arguments
- * @param cfgfile name of the configuration file used (for saving, can be NULL!)
- * @param mycfg configuration
- */
-static void
-run (void *cls,
-     char * const *args,
-     const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *mycfg)
-{
-  cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
-  GNUNET_CLIENT_service_test ("transport", cfg, GNUNET_TIME_UNIT_SECONDS,
-      &testservice_task, (void *) cfg);
-}
-
 int
-main (int argc, char * const *argv)
+main (int argc, char *const *argv)
 {
   int res;
   benchmark_count = DEFAULT_MESSAGE_COUNT;
   benchmark_size = DEFAULT_MESSAGE_SIZE;
-
-  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
-
-    { 's', "send", NULL,
-      gettext_noop ("send data to peer"),
-      0, &GNUNET_GETOPT_set_one, &benchmark_send},
-    { 'r', "receive", NULL, gettext_noop
-      ("receive data from peer"), 0,
-      &GNUNET_GETOPT_set_one, &benchmark_receive},
-    { 'n', "number", NULL, gettext_noop
-      ("number of messages to send"), 1,
-      &GNUNET_GETOPT_set_uint, &benchmark_count},
-    { 'm', "messagesize", NULL, gettext_noop
-      ("message size to use"), 1,
-      &GNUNET_GETOPT_set_uint, &benchmark_size},
-    { 'p', "peer", "PEER",
-      gettext_noop ("peer identity"), 1, &GNUNET_GETOPT_set_string,
-      &cpid },
-    GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
-    GNUNET_GETOPT_OPTION_END
-  };
+  benchmark_iterations = DEFAULT_ITERATION_COUNT;
+  benchmark_running = GNUNET_NO;
+
+  struct GNUNET_GETOPT_CommandLineOption options[] = {
+
+    GNUNET_GETOPT_option_flag ('s',
+                               "send",
+                               gettext_noop ("send data to peer"),
+                               &benchmark_send),
+    GNUNET_GETOPT_option_flag ('r',
+                               "receive",
+                               gettext_noop ("receive data from peer"),
+                               &benchmark_receive),
+    GNUNET_GETOPT_option_uint ('i',
+                               "iterations",
+                               NULL,
+                               gettext_noop ("iterations"),
+                               &benchmark_iterations),
+    GNUNET_GETOPT_option_uint ('n',
+                               "number",
+                               NULL,
+                               gettext_noop ("number of messages to send"),
+                               &benchmark_count),
+    GNUNET_GETOPT_option_uint ('m',
+                               "messagesize",
+                               NULL,
+                               gettext_noop ("message size to use"),
+                               &benchmark_size),
+    GNUNET_GETOPT_option_string ('p',
+                                 "peer",
+                                 "PEER",
+                                 gettext_noop ("peer identity"),
+                                 &cpid),
+    GNUNET_GETOPT_option_verbose (&verbosity),
+    GNUNET_GETOPT_OPTION_END};
 
   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
     return 2;
 
-  res = GNUNET_PROGRAM_run (argc, argv,
-                            "gnunet-transport",
-                            gettext_noop ("Direct access to transport service."),
-                            options,
-                            &run, NULL);
-  GNUNET_free((void *) argv);
+  res =
+    GNUNET_PROGRAM_run (argc,
+                        argv,
+                        "gnunet-transport",
+                        gettext_noop ("Direct access to transport service."),
+                        options,
+                        &run,
+                        NULL);
+  GNUNET_free ((void *) argv);
   if (GNUNET_OK == res)
     return ret;
   return 1;
 }
 
-/* end of gnunet-transport.c */
+/* end of gnunet-transport-profiler.c */