gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r24270 - gnunet/src/testbed


From: gnunet
Subject: [GNUnet-SVN] r24270 - gnunet/src/testbed
Date: Thu, 11 Oct 2012 17:43:18 +0200

Author: harsha
Date: 2012-10-11 17:43:18 +0200 (Thu, 11 Oct 2012)
New Revision: 24270

Added:
   gnunet/src/testbed/gnunet-testbed-profiler.c
Modified:
   gnunet/src/testbed/
   gnunet/src/testbed/Makefile.am
Log:
testbed profiler

Index: gnunet/src/testbed
===================================================================
--- gnunet/src/testbed  2012-10-11 14:45:30 UTC (rev 24269)
+++ gnunet/src/testbed  2012-10-11 15:43:18 UTC (rev 24270)

Property changes on: gnunet/src/testbed
___________________________________________________________________
Modified: svn:ignore
## -1,7 +1,7 ##
 test_testbed_api_2peers_2controllers
 test_testbed_api_2peers
 test_gnunet_testbed_helper
-gnunet-testbed-helper
+gnunet-testbed-profiler
 Makefile.in
 Makefile
 .deps
Modified: gnunet/src/testbed/Makefile.am
===================================================================
--- gnunet/src/testbed/Makefile.am      2012-10-11 14:45:30 UTC (rev 24269)
+++ gnunet/src/testbed/Makefile.am      2012-10-11 15:43:18 UTC (rev 24270)
@@ -18,6 +18,9 @@
   gnunet-service-testbed \
   gnunet-helper-testbed
 
+noinst_PROGRAMS = \
+  gnunet-testbed-profiler
+
 gnunet_service_testbed_SOURCES = \
   gnunet-service-testbed.c
 gnunet_service_testbed_LDADD = $(XLIB) \
@@ -31,6 +34,12 @@
 gnunet_service_testbed_DEPENDENCIES = \
   libgnunettestbed.la
 
+gnunet_testbed_profiler_SOURCES = \
+  gnunet-testbed-profiler.c
+gnunet_testbed_profiler_LDADD = $(XLIB) \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ libgnunettestbed.la
+
 gnunet_helper_testbed_SOURCES = \
   gnunet-helper-testbed.c
 gnunet_helper_testbed_LDADD = $(XLIB) \

Added: gnunet/src/testbed/gnunet-testbed-profiler.c
===================================================================
--- gnunet/src/testbed/gnunet-testbed-profiler.c                                
(rev 0)
+++ gnunet/src/testbed/gnunet-testbed-profiler.c        2012-10-11 15:43:18 UTC 
(rev 24270)
@@ -0,0 +1,203 @@
+/*
+     This file is part of GNUnet.
+     (C) 2011, 2012 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
+     by the Free Software Foundation; either version 3, 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.
+
+     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.
+*/
+
+/**
+ * @file testbed/gnunet-testbed-profiler.c
+ * @brief Profiling driver for the testbed.
+ * @author Sree Harsha Totakura <address@hidden> 
+ */
+
+#include "platform.h"
+#include "gnunet_common.h"
+#include "gnunet_testbed_service.h"
+
+
+/**
+ * The array of peers; we fill this as the peers are given to us by the testbed
+ */
+static struct GNUNET_TESTBED_Peer **peers;
+
+/**
+ * Operation handle
+ */
+static struct GNUNET_TESTBED_Operation *op;
+
+/**
+ * Abort task identifier
+ */
+static GNUNET_SCHEDULER_TaskIdentifier abort_task;
+
+/**
+ * Current peer id
+ */
+unsigned int peer_id;
+
+/**
+ * Number of peers to be started by the profiler
+ */
+static unsigned int num_peers;
+
+/**
+ * Global testing status
+ */
+static int result;
+
+
+/**
+ * Shutdown nicely
+ *
+ * @param cls NULL
+ * @param tc the task context
+ */
+static void
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  if (GNUNET_SCHEDULER_NO_TASK != abort_task)
+    GNUNET_SCHEDULER_cancel (abort_task);
+  GNUNET_free_non_null (peers);
+  GNUNET_SCHEDULER_shutdown ();        /* Stop scheduler to shutdown testbed 
run */
+}
+
+
+/**
+ * abort task to run on test timed out
+ *
+ * @param cls NULL
+ * @param tc the task context
+ */
+static void
+do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
+  abort_task = GNUNET_SCHEDULER_NO_TASK;
+  GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+}
+
+
+/**
+ * Task to be executed when peers are ready
+ *
+ * @param cls NULL
+ * @param tc the task context
+ */
+static void
+master_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  result = GNUNET_OK;
+  GNUNET_assert (NULL != peers[0]);
+  op = GNUNET_TESTBED_peer_stop (peers[0], NULL, NULL);
+  GNUNET_assert (NULL != op);
+}
+
+
+/**
+ * Controller event callback
+ *
+ * @param cls NULL
+ * @param event the controller event
+ */
+static void
+controller_event_cb (void *cls,
+                     const struct GNUNET_TESTBED_EventInformation *event)
+{
+
+  switch (event->type)
+  {
+  case GNUNET_TESTBED_ET_PEER_START:
+    GNUNET_assert (NULL == peers[peer_id]);
+    GNUNET_assert (NULL != event->details.peer_start.peer);
+    peers[peer_id++] = event->details.peer_start.peer;
+    break;
+  case GNUNET_TESTBED_ET_PEER_STOP:
+    GNUNET_assert (NULL != op);
+    GNUNET_TESTBED_operation_done (op);
+    GNUNET_assert (peers[0] == event->details.peer_stop.peer);
+    GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+    break;
+  default:
+    GNUNET_assert (0);
+  }
+}
+
+
+/**
+ * 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 cfg configuration
+ */
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *config)
+{
+  uint64_t event_mask;
+
+  if (0 == num_peers)
+  {
+    result = GNUNET_OK;
+    return;
+  }
+  peers = GNUNET_malloc (num_peers * sizeof (struct GNUNET_TESTBED_Peer *));
+  event_mask = 0;
+  event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
+  event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
+  event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
+  event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
+  GNUNET_TESTBED_run (NULL, config, num_peers, event_mask, 
&controller_event_cb,
+                      NULL, &master_task, NULL);
+  abort_task =
+      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+                                    (GNUNET_TIME_UNIT_SECONDS, 5), &do_abort,
+                                    NULL);
+}
+
+
+/**
+ * Main function.
+ *
+ * @return 0 on success
+ */
+int
+main (int argc, char *const *argv)
+{
+  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+    { 'n', "num-peers", "COUNT",
+      gettext_noop ("create COUNT number of peers"),
+      GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_peers },
+    GNUNET_GETOPT_OPTION_END
+  };
+  int ret;
+
+  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+    return 2;
+  
+  result = GNUNET_SYSERR;
+  ret =
+      GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-profiler [OPTIONS]",
+                          _("Profiler for testbed"),
+                          options, &run, NULL);
+  if (GNUNET_OK != ret)
+    return ret;
+  if (GNUNET_OK != result)
+    return 1;
+  return 0;
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]