diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2014-01-13 15:59:59 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2014-01-13 15:59:59 +0000 |
commit | dd610f2588f8c53cb677722377301fb641da5c23 (patch) | |
tree | d73d9dd18a7ebc5b8070402228725d95dc444eb6 /src/testbed | |
parent | dee8fa8573a64e884ed1b3889690caf45d266a59 (diff) | |
download | gnunet-dd610f2588f8c53cb677722377301fb641da5c23.tar.gz gnunet-dd610f2588f8c53cb677722377301fb641da5c23.zip |
- latency logging daemon
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/Makefile.am | 13 | ||||
-rw-r--r-- | src/testbed/generate-underlay-topology.c | 4 | ||||
-rw-r--r-- | src/testbed/gnunet-daemon-latency-logger.c | 254 | ||||
-rw-r--r-- | src/testbed/testbed.conf.in | 6 |
4 files changed, 275 insertions, 2 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index 0ec17fa44..532f4ea08 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am | |||
@@ -18,6 +18,7 @@ pkgcfg_DATA = \ | |||
18 | 18 | ||
19 | if HAVE_SQLITE | 19 | if HAVE_SQLITE |
20 | underlay_daemon = gnunet-daemon-testbed-underlay | 20 | underlay_daemon = gnunet-daemon-testbed-underlay |
21 | latency_logger = gnunet-daemon-latency-logger | ||
21 | generate_underlay = generate-underlay-topology | 22 | generate_underlay = generate-underlay-topology |
22 | underlay_testcases = test_testbed_underlay | 23 | underlay_testcases = test_testbed_underlay |
23 | endif | 24 | endif |
@@ -27,7 +28,8 @@ libexec_PROGRAMS = \ | |||
27 | gnunet-helper-testbed \ | 28 | gnunet-helper-testbed \ |
28 | gnunet-service-testbed-logger \ | 29 | gnunet-service-testbed-logger \ |
29 | gnunet-daemon-testbed-blacklist \ | 30 | gnunet-daemon-testbed-blacklist \ |
30 | $(underlay_daemon) | 31 | $(underlay_daemon) \ |
32 | $(latency_logger) | ||
31 | 33 | ||
32 | bin_PROGRAMS = \ | 34 | bin_PROGRAMS = \ |
33 | gnunet-testbed-profiler | 35 | gnunet-testbed-profiler |
@@ -102,6 +104,15 @@ gnunet_daemon_testbed_underlay_DEPENDENCIES = \ | |||
102 | $(top_builddir)/src/transport/libgnunettransport.la \ | 104 | $(top_builddir)/src/transport/libgnunettransport.la \ |
103 | $(top_builddir)/src/util/libgnunetutil.la | 105 | $(top_builddir)/src/util/libgnunetutil.la |
104 | 106 | ||
107 | gnunet_daemon_latency_logger_SOURCES = gnunet-daemon-latency-logger.c | ||
108 | gnunet_daemon_latency_logger_LDADD = $(XLIB) \ | ||
109 | $(top_builddir)/src/ats/libgnunetats.la \ | ||
110 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
111 | $(LTLIBINTL) -lsqlite3 | ||
112 | gnunet_daemon_latency_logger_DEPENDENCIES = \ | ||
113 | $(top_builddir)/src/ats/libgnunetats.la \ | ||
114 | $(top_builddir)/src/util/libgnunetutil.la | ||
115 | |||
105 | lib_LTLIBRARIES = \ | 116 | lib_LTLIBRARIES = \ |
106 | libgnunettestbed.la \ | 117 | libgnunettestbed.la \ |
107 | libgnunettestbedlogger.la | 118 | libgnunettestbedlogger.la |
diff --git a/src/testbed/generate-underlay-topology.c b/src/testbed/generate-underlay-topology.c index 98d7dfc6f..33d434b26 100644 --- a/src/testbed/generate-underlay-topology.c +++ b/src/testbed/generate-underlay-topology.c | |||
@@ -178,7 +178,9 @@ setup_db (const char *dbfile) | |||
178 | if (0 != sqlite3_exec (db, query_create, NULL, NULL, NULL)) | 178 | if (0 != sqlite3_exec (db, query_create, NULL, NULL, NULL)) |
179 | { | 179 | { |
180 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec"); | 180 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_exec"); |
181 | FPRINTF (stderr, "Perhaps the database `%s' already exits.\n", dbfile); | 181 | FPRINTF (stderr, "Error: %d. Perhaps the database `%s' already exits.\n", |
182 | sqlite3_errcode (db), | ||
183 | dbfile); | ||
182 | goto err_ret; | 184 | goto err_ret; |
183 | } | 185 | } |
184 | GNUNET_break (0 == sqlite3_exec (db, "PRAGMA synchronous = 0;", NULL, NULL, NULL)); | 186 | GNUNET_break (0 == sqlite3_exec (db, "PRAGMA synchronous = 0;", NULL, NULL, NULL)); |
diff --git a/src/testbed/gnunet-daemon-latency-logger.c b/src/testbed/gnunet-daemon-latency-logger.c new file mode 100644 index 000000000..e4faa8c98 --- /dev/null +++ b/src/testbed/gnunet-daemon-latency-logger.c | |||
@@ -0,0 +1,254 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2008--2014 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testbed/gnunet-daemon-latency-logger.c | ||
23 | * @brief log latency values from neighbour connections into an SQLite database | ||
24 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_ats_service.h" | ||
30 | #include <sqlite3.h> | ||
31 | |||
32 | |||
33 | /** | ||
34 | * Logging shorthand | ||
35 | */ | ||
36 | #define LOG(type,...) \ | ||
37 | GNUNET_log (type, __VA_ARGS__) | ||
38 | |||
39 | /** | ||
40 | * Debug logging shorthand | ||
41 | */ | ||
42 | #define DEBUG(...) \ | ||
43 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | ||
44 | |||
45 | /** | ||
46 | * Log an error message at log-level 'level' that indicates | ||
47 | * a failure of the command 'cmd' on file 'filename' | ||
48 | * with the message given by strerror(errno). | ||
49 | */ | ||
50 | #define LOG_SQLITE(db, msg, level, cmd) \ | ||
51 | do { \ | ||
52 | GNUNET_log_from (level, "sqlite", _("`%s' failed at %s:%d with error: %s\n"), \ | ||
53 | cmd, __FILE__,__LINE__, sqlite3_errmsg(db)); \ | ||
54 | if (msg != NULL) \ | ||
55 | GNUNET_asprintf(msg, _("`%s' failed at %s:%u with error: %s"), cmd, \ | ||
56 | __FILE__, __LINE__, sqlite3_errmsg(db)); \ | ||
57 | } while(0) | ||
58 | |||
59 | |||
60 | /** | ||
61 | * The SQLite database handle | ||
62 | */ | ||
63 | static struct sqlite3 *db; | ||
64 | |||
65 | /** | ||
66 | * Handle to the ATS performance subsystem | ||
67 | */ | ||
68 | struct GNUNET_ATS_PerformanceHandle *ats; | ||
69 | |||
70 | /** | ||
71 | * Prepared statement for inserting values into the database table | ||
72 | */ | ||
73 | struct sqlite3_stmt *stmt_insert; | ||
74 | |||
75 | /** | ||
76 | * Shutdown task identifier | ||
77 | */ | ||
78 | GNUNET_SCHEDULER_TaskIdentifier shutdown_task; | ||
79 | |||
80 | |||
81 | /** | ||
82 | * Shutdown | ||
83 | * | ||
84 | * @param cls NULL | ||
85 | * @param tc task context from scheduler | ||
86 | * @return | ||
87 | */ | ||
88 | static void | ||
89 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
90 | { | ||
91 | shutdown_task = GNUNET_SCHEDULER_NO_TASK; | ||
92 | GNUNET_ATS_performance_done (ats); | ||
93 | ats = NULL; | ||
94 | if (NULL != stmt_insert) | ||
95 | { | ||
96 | sqlite3_finalize (stmt_insert); | ||
97 | stmt_insert = NULL; | ||
98 | } | ||
99 | GNUNET_break (SQLITE_OK == sqlite3_close (db)); | ||
100 | db = NULL; | ||
101 | } | ||
102 | |||
103 | /** | ||
104 | * Signature of a function that is called with QoS information about an address. | ||
105 | * | ||
106 | * @param cls closure | ||
107 | * @param address the address | ||
108 | * @param address_active is this address actively used to maintain a connection | ||
109 | * to a peer | ||
110 | * @param bandwidth_out assigned outbound bandwidth for the connection | ||
111 | * @param bandwidth_in assigned inbound bandwidth for the connection | ||
112 | * @param ats performance data for the address (as far as known) | ||
113 | * @param ats_count number of performance records in 'ats' | ||
114 | */ | ||
115 | static void | ||
116 | addr_info_cb (void *cls, | ||
117 | const struct GNUNET_HELLO_Address *address, | ||
118 | int address_active, | ||
119 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
120 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
121 | const struct GNUNET_ATS_Information *ats, | ||
122 | uint32_t ats_count) | ||
123 | { | ||
124 | static const char *query_insert = | ||
125 | "INSERT INTO ats_info(" | ||
126 | " id," | ||
127 | " val," | ||
128 | " timestamp" | ||
129 | ") VALUES (" | ||
130 | " ?1," | ||
131 | " ?2," | ||
132 | " datetime('now')" | ||
133 | ");"; | ||
134 | int latency; | ||
135 | unsigned int cnt; | ||
136 | |||
137 | GNUNET_assert (NULL != db); | ||
138 | if (GNUNET_NO == address_active) | ||
139 | return; | ||
140 | for (cnt = 0; cnt < ats_count; cnt++) | ||
141 | { | ||
142 | if (GNUNET_ATS_QUALITY_NET_DELAY == ntohl (ats[cnt].type)) | ||
143 | goto insert; | ||
144 | } | ||
145 | return; | ||
146 | |||
147 | insert: | ||
148 | latency = (int) ntohl (ats[cnt].value); | ||
149 | if (NULL == stmt_insert) | ||
150 | { | ||
151 | if (SQLITE_OK != sqlite3_prepare_v2 (db, query_insert, -1, &stmt_insert, | ||
152 | NULL)) | ||
153 | { | ||
154 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_prepare_v2"); | ||
155 | goto err_shutdown; | ||
156 | } | ||
157 | } | ||
158 | if ( (SQLITE_OK != sqlite3_bind_text (stmt_insert, 1, | ||
159 | GNUNET_i2s (&address->peer), -1, | ||
160 | SQLITE_STATIC)) || | ||
161 | (SQLITE_OK != sqlite3_bind_int (stmt_insert, 2, latency)) ) | ||
162 | { | ||
163 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_bind_text"); | ||
164 | goto err_shutdown; | ||
165 | } | ||
166 | if (SQLITE_DONE != sqlite3_step (stmt_insert)) | ||
167 | { | ||
168 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_step"); | ||
169 | goto err_shutdown; | ||
170 | } | ||
171 | if (SQLITE_OK != sqlite3_reset (stmt_insert)) | ||
172 | { | ||
173 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_insert"); | ||
174 | goto err_shutdown; | ||
175 | } | ||
176 | return; | ||
177 | |||
178 | err_shutdown: | ||
179 | GNUNET_SCHEDULER_shutdown (); | ||
180 | } | ||
181 | |||
182 | |||
183 | /** | ||
184 | * Main function that will be run. | ||
185 | * | ||
186 | * @param cls closure | ||
187 | * @param args remaining command-line arguments | ||
188 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
189 | * @param c configuration | ||
190 | */ | ||
191 | static void | ||
192 | run (void *cls, char *const *args, const char *cfgfile, | ||
193 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
194 | { | ||
195 | const char *query_create = | ||
196 | "CREATE TABLE ats_info (" | ||
197 | "id TEXT," | ||
198 | "val INTEGER," | ||
199 | "timestamp NUMERIC" | ||
200 | ");"; | ||
201 | char *dbfile; | ||
202 | |||
203 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "LATENCY-LOGGER", | ||
204 | "DBFILE", | ||
205 | &dbfile)) | ||
206 | { | ||
207 | GNUNET_break (0); | ||
208 | return; | ||
209 | } | ||
210 | if (SQLITE_OK != sqlite3_open (dbfile, &db)) | ||
211 | { | ||
212 | if (NULL != db) | ||
213 | { | ||
214 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite_open_v2"); | ||
215 | sqlite3_close (db); | ||
216 | } | ||
217 | else | ||
218 | LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot open sqlite file %s\n", dbfile); | ||
219 | GNUNET_free (dbfile); | ||
220 | return; | ||
221 | } | ||
222 | if (0 != sqlite3_exec (db, query_create, NULL, NULL, NULL)) | ||
223 | DEBUG ("SQLite Error: %d. Perhaps the database `%s' already exits.\n", | ||
224 | sqlite3_errcode (db), dbfile); | ||
225 | DEBUG ("Opened database %s\n", dbfile); | ||
226 | GNUNET_free (dbfile); | ||
227 | dbfile = NULL; | ||
228 | ats = GNUNET_ATS_performance_init (c, addr_info_cb, NULL); | ||
229 | shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
230 | &do_shutdown, NULL); | ||
231 | } | ||
232 | |||
233 | |||
234 | /** | ||
235 | * Execution entry point | ||
236 | */ | ||
237 | int | ||
238 | main (int argc, char * const *argv) | ||
239 | { | ||
240 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
241 | GNUNET_GETOPT_OPTION_END | ||
242 | }; | ||
243 | int ret; | ||
244 | |||
245 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | ||
246 | return 2; | ||
247 | ret = | ||
248 | (GNUNET_OK == | ||
249 | GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-latency-logger", | ||
250 | _("Daemon to log latency values of connections to neighbours"), | ||
251 | options, &run, NULL)) ? 0 : 1; | ||
252 | GNUNET_free ((void*) argv); | ||
253 | return ret; | ||
254 | } | ||
diff --git a/src/testbed/testbed.conf.in b/src/testbed/testbed.conf.in index 132480af0..7d22660f8 100644 --- a/src/testbed/testbed.conf.in +++ b/src/testbed/testbed.conf.in | |||
@@ -109,4 +109,10 @@ AUTOSTART = NO | |||
109 | BINARY = gnunet-daemon-testbed-underlay | 109 | BINARY = gnunet-daemon-testbed-underlay |
110 | # The sqlite3 database file containing information about what underlay | 110 | # The sqlite3 database file containing information about what underlay |
111 | # restrictions to apply | 111 | # restrictions to apply |
112 | # DBFILE = | ||
113 | |||
114 | [latency-logger] | ||
115 | AUTOSTART = NO | ||
116 | BINARY = gnunet-daemon-latency-logger | ||
117 | # The sqlite3 database file where the latency values are to be stored | ||
112 | # DBFILE = \ No newline at end of file | 118 | # DBFILE = \ No newline at end of file |