diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-08-06 14:38:08 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-08-06 14:38:08 +0000 |
commit | 99302fc71c669b489e543f88f9db79a402524973 (patch) | |
tree | 2296f9544889f9816d6d0bdac5ae508662a8fafa /src/ats/perf_ats.c | |
parent | 4bbe92a1d2329405ddc70196bd023b5c070cfbf2 (diff) | |
download | gnunet-99302fc71c669b489e543f88f9db79a402524973.tar.gz gnunet-99302fc71c669b489e543f88f9db79a402524973.zip |
core connections
Diffstat (limited to 'src/ats/perf_ats.c')
-rw-r--r-- | src/ats/perf_ats.c | 174 |
1 files changed, 169 insertions, 5 deletions
diff --git a/src/ats/perf_ats.c b/src/ats/perf_ats.c index b7c7f5ab4..22dbb90c1 100644 --- a/src/ats/perf_ats.c +++ b/src/ats/perf_ats.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_testbed_service.h" | 28 | #include "gnunet_testbed_service.h" |
29 | #include "gnunet_ats_service.h" | 29 | #include "gnunet_ats_service.h" |
30 | #include "gnunet_core_service.h" | ||
30 | 31 | ||
31 | #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 32 | #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
32 | #define TESTNAME_PREFIX "perf_ats_" | 33 | #define TESTNAME_PREFIX "perf_ats_" |
@@ -44,6 +45,8 @@ struct BenchmarkPeer | |||
44 | 45 | ||
45 | struct GNUNET_PeerIdentity id; | 46 | struct GNUNET_PeerIdentity id; |
46 | 47 | ||
48 | struct GNUNET_CORE_Handle *ch; | ||
49 | |||
47 | /** | 50 | /** |
48 | * Testbed operation to connect to ATS performance service | 51 | * Testbed operation to connect to ATS performance service |
49 | */ | 52 | */ |
@@ -60,14 +63,30 @@ struct BenchmarkPeer | |||
60 | struct GNUNET_TESTBED_Operation *connect_op; | 63 | struct GNUNET_TESTBED_Operation *connect_op; |
61 | 64 | ||
62 | /** | 65 | /** |
66 | * Testbed operation to connect to core | ||
67 | */ | ||
68 | struct GNUNET_TESTBED_Operation *core_op; | ||
69 | |||
70 | /** | ||
63 | * ATS performance handle | 71 | * ATS performance handle |
64 | */ | 72 | */ |
65 | struct GNUNET_ATS_PerformanceHandle *p_handle; | 73 | struct GNUNET_ATS_PerformanceHandle *p_handle; |
74 | |||
75 | int core_connections; | ||
66 | }; | 76 | }; |
67 | 77 | ||
68 | struct BenchmarkPeer *ph; | 78 | struct BenchmarkPeer *ph; |
69 | 79 | ||
80 | struct BenchmarkState | ||
81 | { | ||
82 | int connected_ATS; | ||
83 | int connected_CORE; | ||
84 | int connected_PEERS; | ||
70 | 85 | ||
86 | int *core_connections; | ||
87 | }; | ||
88 | |||
89 | static struct BenchmarkState state; | ||
71 | 90 | ||
72 | /** | 91 | /** |
73 | * Shutdown task | 92 | * Shutdown task |
@@ -102,6 +121,11 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
102 | ph[c_p].ats_perf_op = NULL; | 121 | ph[c_p].ats_perf_op = NULL; |
103 | } | 122 | } |
104 | 123 | ||
124 | if (NULL != ph[c_p].core_op) | ||
125 | { | ||
126 | GNUNET_TESTBED_operation_done (ph[c_p].core_op); | ||
127 | ph[c_p].core_op = NULL; | ||
128 | } | ||
105 | 129 | ||
106 | if (NULL != ph[c_p].info_op) | 130 | if (NULL != ph[c_p].info_op) |
107 | { | 131 | { |
@@ -132,7 +156,19 @@ ats_performance_info_cb (void *cls, | |||
132 | const struct GNUNET_ATS_Information *ats, | 156 | const struct GNUNET_ATS_Information *ats, |
133 | uint32_t ats_count) | 157 | uint32_t ats_count) |
134 | { | 158 | { |
135 | //GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("[P] %s\n"), GNUNET_i2s (&address->peer)); | 159 | struct BenchmarkPeer *p = cls; |
160 | int c_a; | ||
161 | char *peer_id; | ||
162 | if (p != &ph[0]) | ||
163 | return; /* print only master peer */ | ||
164 | peer_id = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
165 | for (c_a = 0; c_a < ats_count; c_a++) | ||
166 | { | ||
167 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("%s: %s %s %u\n"), peer_id, GNUNET_i2s (&address->peer), | ||
168 | GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)), | ||
169 | ntohl(ats[c_a].value)); | ||
170 | } | ||
171 | GNUNET_free (peer_id); | ||
136 | } | 172 | } |
137 | 173 | ||
138 | /** | 174 | /** |
@@ -196,7 +232,123 @@ ats_perf_disconnect_adapter (void *cls, void *op_result) | |||
196 | peer->p_handle = NULL; | 232 | peer->p_handle = NULL; |
197 | } | 233 | } |
198 | 234 | ||
199 | void connect_completion_callback (void *cls, | 235 | /** |
236 | * Method called whenever a given peer connects. | ||
237 | * | ||
238 | * @param cls closure | ||
239 | * @param peer peer identity this notification is about | ||
240 | */ | ||
241 | static void | ||
242 | core_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer) | ||
243 | { | ||
244 | struct BenchmarkPeer *p = cls; | ||
245 | char *id; | ||
246 | id = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
247 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s connected to %s \n", id, GNUNET_i2s (peer)); | ||
248 | GNUNET_free (id); | ||
249 | } | ||
250 | |||
251 | |||
252 | |||
253 | /** | ||
254 | * Method called whenever a peer disconnects. | ||
255 | * | ||
256 | * @param cls closure | ||
257 | * @param peer peer identity this notification is about | ||
258 | */ | ||
259 | static void | ||
260 | core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer) | ||
261 | { | ||
262 | struct BenchmarkPeer *p = cls; | ||
263 | char *id; | ||
264 | id = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
265 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s disconnected from %s \n", id, GNUNET_i2s (peer)); | ||
266 | GNUNET_free (id); | ||
267 | } | ||
268 | |||
269 | |||
270 | /** | ||
271 | * Called to open a connection to the peer's ATS performance | ||
272 | * | ||
273 | * @param cls peer context | ||
274 | * @param cfg configuration of the peer to connect to; will be available until | ||
275 | * GNUNET_TESTBED_operation_done() is called on the operation returned | ||
276 | * from GNUNET_TESTBED_service_connect() | ||
277 | * @return service handle to return in 'op_result', NULL on error | ||
278 | */ | ||
279 | static void * | ||
280 | core_connect_adapter (void *cls, | ||
281 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
282 | { | ||
283 | struct BenchmarkPeer *peer = cls; | ||
284 | peer->ch = GNUNET_CORE_connect(cfg, peer, NULL, | ||
285 | core_connect_cb, | ||
286 | core_disconnect_cb, | ||
287 | NULL, GNUNET_NO, NULL, GNUNET_NO, NULL); | ||
288 | if (NULL == peer->ch) | ||
289 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create core connection \n"); | ||
290 | return peer->ch; | ||
291 | } | ||
292 | |||
293 | |||
294 | /** | ||
295 | * Callback to be called when a service connect operation is completed | ||
296 | * | ||
297 | * @param cls the callback closure from functions generating an operation | ||
298 | * @param op the operation that has been finished | ||
299 | * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter() | ||
300 | * @param emsg error message in case the operation has failed; will be NULL if | ||
301 | * operation has executed successfully. | ||
302 | */ | ||
303 | static void | ||
304 | core_connect_completion_cb (void *cls, | ||
305 | struct GNUNET_TESTBED_Operation *op, | ||
306 | void *ca_result, | ||
307 | const char *emsg ) | ||
308 | { | ||
309 | static int core_done = 0; | ||
310 | if ((NULL != emsg) || (NULL == ca_result)) | ||
311 | { | ||
312 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
313 | _("Initialization failed, shutdown\n")); | ||
314 | GNUNET_break (0); | ||
315 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | ||
316 | GNUNET_SCHEDULER_cancel(shutdown_task); | ||
317 | shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL); | ||
318 | return; | ||
319 | } | ||
320 | core_done ++; | ||
321 | if (core_done == peers) | ||
322 | { | ||
323 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
324 | "Connected to all CORE services\n"); | ||
325 | state.connected_CORE = GNUNET_YES; | ||
326 | } | ||
327 | } | ||
328 | |||
329 | |||
330 | /** | ||
331 | * Called to disconnect from peer's statistics service | ||
332 | * | ||
333 | * @param cls peer context | ||
334 | * @param op_result service handle returned from the connect adapter | ||
335 | */ | ||
336 | static void | ||
337 | core_disconnect_adapter (void *cls, void *op_result) | ||
338 | { | ||
339 | struct BenchmarkPeer *peer = cls; | ||
340 | |||
341 | GNUNET_CORE_disconnect (peer->ch); | ||
342 | peer->ch = NULL; | ||
343 | } | ||
344 | |||
345 | |||
346 | static void do_benchmark () | ||
347 | { | ||
348 | |||
349 | } | ||
350 | |||
351 | static void connect_completion_callback (void *cls, | ||
200 | struct GNUNET_TESTBED_Operation *op, | 352 | struct GNUNET_TESTBED_Operation *op, |
201 | const char *emsg) | 353 | const char *emsg) |
202 | { | 354 | { |
@@ -224,7 +376,9 @@ void connect_completion_callback (void *cls, | |||
224 | if (connections == peers -1) | 376 | if (connections == peers -1) |
225 | { | 377 | { |
226 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 378 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
227 | "All peers connected\n"); | 379 | "All peers connected, start benchmarking \n"); |
380 | GNUNET_SCHEDULER_add_now (&do_benchmark, NULL); | ||
381 | state.connected_PEERS = GNUNET_YES; | ||
228 | } | 382 | } |
229 | 383 | ||
230 | } | 384 | } |
@@ -280,8 +434,8 @@ void ats_connect_completion_cb (void *cls, | |||
280 | { | 434 | { |
281 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 435 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
282 | _("Initialization done, connecting peers\n")); | 436 | _("Initialization done, connecting peers\n")); |
283 | 437 | state.connected_ATS = GNUNET_YES; | |
284 | GNUNET_SCHEDULER_add_now (&do_connect, NULL); | 438 | GNUNET_SCHEDULER_add_now (&do_connect, NULL); |
285 | } | 439 | } |
286 | } | 440 | } |
287 | 441 | ||
@@ -356,6 +510,13 @@ test_main (void *cls, unsigned int num_peers, | |||
356 | ph[c_p].info_op = GNUNET_TESTBED_peer_get_information (ph[c_p].peer, | 510 | ph[c_p].info_op = GNUNET_TESTBED_peer_get_information (ph[c_p].peer, |
357 | GNUNET_TESTBED_PIT_IDENTITY, &pid_cb, &ph[c_p]); | 511 | GNUNET_TESTBED_PIT_IDENTITY, &pid_cb, &ph[c_p]); |
358 | 512 | ||
513 | ph[c_p].core_op = GNUNET_TESTBED_service_connect (NULL, | ||
514 | peers_[c_p], "ats", | ||
515 | core_connect_completion_cb, NULL, | ||
516 | &core_connect_adapter, | ||
517 | &core_disconnect_adapter, | ||
518 | &ph[c_p]); | ||
519 | |||
359 | ph[c_p].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, | 520 | ph[c_p].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, |
360 | peers_[c_p], "ats", | 521 | peers_[c_p], "ats", |
361 | ats_connect_completion_cb, NULL, | 522 | ats_connect_completion_cb, NULL, |
@@ -416,6 +577,9 @@ main (int argc, char *argv[]) | |||
416 | peers = DEFAULT_NUM; | 577 | peers = DEFAULT_NUM; |
417 | 578 | ||
418 | ph = GNUNET_malloc (peers * sizeof (struct BenchmarkPeer)); | 579 | ph = GNUNET_malloc (peers * sizeof (struct BenchmarkPeer)); |
580 | state.connected_ATS = GNUNET_NO; | ||
581 | state.connected_CORE = GNUNET_NO; | ||
582 | state.connected_PEERS = GNUNET_NO; | ||
419 | /* Start topology */ | 583 | /* Start topology */ |
420 | uint64_t event_mask; | 584 | uint64_t event_mask; |
421 | result = GNUNET_SYSERR; | 585 | result = GNUNET_SYSERR; |