gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r31883 - gnunet/src/testbed
Date: Mon, 13 Jan 2014 16:59:59 +0100

Author: harsha
Date: 2014-01-13 16:59:59 +0100 (Mon, 13 Jan 2014)
New Revision: 31883

Added:
   gnunet/src/testbed/gnunet-daemon-latency-logger.c
Modified:
   gnunet/src/testbed/
   gnunet/src/testbed/Makefile.am
   gnunet/src/testbed/generate-underlay-topology.c
   gnunet/src/testbed/testbed.conf.in
Log:
- latency logging daemon


Index: gnunet/src/testbed
===================================================================
--- gnunet/src/testbed  2014-01-13 15:15:18 UTC (rev 31882)
+++ gnunet/src/testbed  2014-01-13 15:59:59 UTC (rev 31883)

Property changes on: gnunet/src/testbed
___________________________________________________________________
Modified: svn:ignore
## -52,3 +52,4 ##
 gnunet-daemon-testbed-underlay
 generate-underlay-topology
 test_testbed_underlay
+gnunet-daemon-latency-logger
Modified: gnunet/src/testbed/Makefile.am
===================================================================
--- gnunet/src/testbed/Makefile.am      2014-01-13 15:15:18 UTC (rev 31882)
+++ gnunet/src/testbed/Makefile.am      2014-01-13 15:59:59 UTC (rev 31883)
@@ -18,6 +18,7 @@
 
 if HAVE_SQLITE
   underlay_daemon = gnunet-daemon-testbed-underlay
+  latency_logger = gnunet-daemon-latency-logger
   generate_underlay = generate-underlay-topology
   underlay_testcases = test_testbed_underlay
 endif
@@ -27,7 +28,8 @@
   gnunet-helper-testbed \
   gnunet-service-testbed-logger \
   gnunet-daemon-testbed-blacklist \
-  $(underlay_daemon)
+  $(underlay_daemon) \
+  $(latency_logger)
 
 bin_PROGRAMS = \
   gnunet-testbed-profiler
@@ -102,6 +104,15 @@
  $(top_builddir)/src/transport/libgnunettransport.la \
  $(top_builddir)/src/util/libgnunetutil.la
 
+gnunet_daemon_latency_logger_SOURCES = gnunet-daemon-latency-logger.c
+gnunet_daemon_latency_logger_LDADD = $(XLIB) \
+ $(top_builddir)/src/ats/libgnunetats.la \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(LTLIBINTL) -lsqlite3
+gnunet_daemon_latency_logger_DEPENDENCIES = \
+ $(top_builddir)/src/ats/libgnunetats.la \
+ $(top_builddir)/src/util/libgnunetutil.la
+
 lib_LTLIBRARIES = \
   libgnunettestbed.la \
   libgnunettestbedlogger.la

Modified: gnunet/src/testbed/generate-underlay-topology.c
===================================================================
--- gnunet/src/testbed/generate-underlay-topology.c     2014-01-13 15:15:18 UTC 
(rev 31882)
+++ gnunet/src/testbed/generate-underlay-topology.c     2014-01-13 15:59:59 UTC 
(rev 31883)
@@ -178,7 +178,9 @@
   if (0 != sqlite3_exec (db, query_create, NULL, NULL, NULL))
   {
     LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec");
-    FPRINTF (stderr, "Perhaps the database `%s' already exits.\n", dbfile);
+    FPRINTF (stderr, "Error: %d.  Perhaps the database `%s' already exits.\n",
+             sqlite3_errcode (db),
+             dbfile);
     goto err_ret;
   }
   GNUNET_break (0 == sqlite3_exec (db, "PRAGMA synchronous = 0;", NULL, NULL, 
NULL));

Added: gnunet/src/testbed/gnunet-daemon-latency-logger.c
===================================================================
--- gnunet/src/testbed/gnunet-daemon-latency-logger.c                           
(rev 0)
+++ gnunet/src/testbed/gnunet-daemon-latency-logger.c   2014-01-13 15:59:59 UTC 
(rev 31883)
@@ -0,0 +1,254 @@
+/*
+      This file is part of GNUnet
+      (C) 2008--2014 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-daemon-latency-logger.c
+ * @brief log latency values from neighbour connections into an SQLite database
+ * @author Sree Harsha Totakura <address@hidden> 
+ */
+
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_ats_service.h"
+#include <sqlite3.h>
+
+
+/**
+ * Logging shorthand
+ */
+#define LOG(type,...)                           \
+  GNUNET_log (type, __VA_ARGS__)
+
+/**
+ * Debug logging shorthand
+ */
+#define DEBUG(...)                              \
+  LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+
+/**
+ * Log an error message at log-level 'level' that indicates
+ * a failure of the command 'cmd' on file 'filename'
+ * with the message given by strerror(errno).
+ */
+#define LOG_SQLITE(db, msg, level, cmd)                                 \
+  do {                                                                  \
+    GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: 
%s\n"), \
+                     cmd, __FILE__,__LINE__, sqlite3_errmsg(db));  \
+    if (msg != NULL)                                                    \
+      GNUNET_asprintf(msg, _("`%s' failed at %s:%u with error: %s"), cmd, \
+                      __FILE__, __LINE__, sqlite3_errmsg(db));     \
+  } while(0)
+
+
+/**
+ * The SQLite database handle
+ */
+static struct sqlite3 *db;
+
+/**
+ * Handle to the ATS performance subsystem
+ */
+struct GNUNET_ATS_PerformanceHandle *ats;
+
+/**
+ * Prepared statement for inserting values into the database table
+ */
+struct sqlite3_stmt *stmt_insert;
+
+/**
+ * Shutdown task identifier
+ */
+GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
+
+
+/**
+ * Shutdown
+ *
+ * @param cls NULL
+ * @param tc task context from scheduler
+ * @return 
+ */
+static void
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  shutdown_task = GNUNET_SCHEDULER_NO_TASK;
+  GNUNET_ATS_performance_done (ats);
+  ats = NULL;
+  if (NULL != stmt_insert)
+  {
+    sqlite3_finalize (stmt_insert);
+    stmt_insert = NULL;
+  }
+  GNUNET_break (SQLITE_OK == sqlite3_close (db));
+  db = NULL;
+}
+
+/**
+ * Signature of a function that is called with QoS information about an 
address.
+ *
+ * @param cls closure
+ * @param address the address
+ * @param address_active is this address actively used to maintain a connection
+ *                             to a peer
+ * @param bandwidth_out assigned outbound bandwidth for the connection
+ * @param bandwidth_in assigned inbound bandwidth for the connection
+ * @param ats performance data for the address (as far as known)
+ * @param ats_count number of performance records in 'ats'
+ */
+static void
+addr_info_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)
+{
+  static const char *query_insert =
+      "INSERT INTO ats_info("
+      " id,"
+      " val,"
+      " timestamp"
+      ") VALUES ("
+      " ?1,"
+      " ?2,"
+      " datetime('now')"
+      ");";
+  int latency;
+  unsigned int cnt;
+
+  GNUNET_assert (NULL != db);
+  if (GNUNET_NO == address_active)
+    return;
+  for (cnt = 0; cnt < ats_count; cnt++)
+  {
+    if (GNUNET_ATS_QUALITY_NET_DELAY == ntohl (ats[cnt].type))
+      goto insert;
+  }
+  return;
+
+ insert:
+  latency = (int) ntohl (ats[cnt].value);
+  if (NULL == stmt_insert)
+  {
+    if (SQLITE_OK != sqlite3_prepare_v2 (db, query_insert, -1, &stmt_insert,
+                                         NULL))
+    {
+      LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2");
+      goto err_shutdown;
+    }
+  }
+  if ( (SQLITE_OK != sqlite3_bind_text (stmt_insert, 1,
+                                        GNUNET_i2s (&address->peer), -1,
+                                        SQLITE_STATIC)) ||
+        (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, latency)) )
+  {
+     LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_text");
+     goto err_shutdown;
+  }
+  if (SQLITE_DONE != sqlite3_step (stmt_insert))
+  {
+    LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step");
+    goto err_shutdown;
+  }
+  if (SQLITE_OK != sqlite3_reset (stmt_insert))
+  {
+    LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_insert");
+    goto err_shutdown;
+  }
+  return;
+  
+ err_shutdown:
+      GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Main function that will be run.
+ *
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be 
NULL!)
+ * @param c configuration
+ */
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *c)
+{
+  const char *query_create = 
+      "CREATE TABLE ats_info ("
+      "id TEXT,"
+      "val INTEGER,"
+      "timestamp NUMERIC"
+      ");";
+  char *dbfile;
+
+  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, 
"LATENCY-LOGGER",
+                                                            "DBFILE",
+                                                            &dbfile))
+  {
+    GNUNET_break (0);
+    return;
+  }
+  if (SQLITE_OK != sqlite3_open (dbfile, &db))
+  {
+    if (NULL != db)
+    {
+      LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite_open_v2");
+      sqlite3_close (db);
+    }
+    else
+      LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot open sqlite file %s\n", dbfile);
+    GNUNET_free (dbfile);
+    return;
+  }
+  if (0 != sqlite3_exec (db, query_create, NULL, NULL, NULL))
+    DEBUG ("SQLite Error: %d.  Perhaps the database `%s' already exits.\n",
+           sqlite3_errcode (db), dbfile);
+  DEBUG ("Opened database %s\n", dbfile);
+  GNUNET_free (dbfile);  
+  dbfile = NULL;
+  ats = GNUNET_ATS_performance_init (c, addr_info_cb, NULL);
+  shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+                                                &do_shutdown, NULL);
+}
+
+
+/**
+ * Execution entry point
+ */
+int
+main (int argc, char * const *argv)
+{
+  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+    GNUNET_GETOPT_OPTION_END
+  };
+  int ret;
+
+  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+    return 2;
+  ret =
+      (GNUNET_OK ==
+       GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-latency-logger",
+                           _("Daemon to log latency values of connections to 
neighbours"),
+                           options, &run, NULL)) ? 0 : 1;
+  GNUNET_free ((void*) argv);
+  return ret;
+}

Modified: gnunet/src/testbed/testbed.conf.in
===================================================================
--- gnunet/src/testbed/testbed.conf.in  2014-01-13 15:15:18 UTC (rev 31882)
+++ gnunet/src/testbed/testbed.conf.in  2014-01-13 15:59:59 UTC (rev 31883)
@@ -109,4 +109,10 @@
 BINARY = gnunet-daemon-testbed-underlay
 # The sqlite3 database file containing information about what underlay
 # restrictions to apply
+# DBFILE = 
+
+[latency-logger]
+AUTOSTART = NO
+BINARY = gnunet-daemon-latency-logger
+# The sqlite3 database file where the latency values are to be stored
 # DBFILE = 
\ No newline at end of file




reply via email to

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