diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-08-06 14:56:50 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-08-06 14:56:50 +0000 |
commit | 1360f8a1e5877a8796dc8e7d0c55d78481382e80 (patch) | |
tree | d647e4d0274833cb5733b967ead399690fead5d2 | |
parent | 99302fc71c669b489e543f88f9db79a402524973 (diff) | |
download | gnunet-1360f8a1e5877a8796dc8e7d0c55d78481382e80.tar.gz gnunet-1360f8a1e5877a8796dc8e7d0c55d78481382e80.zip |
ready to start with benchmarkign implementation
-rw-r--r-- | src/ats/perf_ats.c | 241 |
1 files changed, 140 insertions, 101 deletions
diff --git a/src/ats/perf_ats.c b/src/ats/perf_ats.c index 22dbb90c1..e7a198f9d 100644 --- a/src/ats/perf_ats.c +++ b/src/ats/perf_ats.c | |||
@@ -79,9 +79,10 @@ struct BenchmarkPeer *ph; | |||
79 | 79 | ||
80 | struct BenchmarkState | 80 | struct BenchmarkState |
81 | { | 81 | { |
82 | int connected_ATS; | 82 | int connected_ATS_SRV; |
83 | int connected_CORE; | 83 | int connected_CORE_SRV; |
84 | int connected_PEERS; | 84 | int connected_PEERS; |
85 | int connected_CORE; | ||
85 | 86 | ||
86 | int *core_connections; | 87 | int *core_connections; |
87 | }; | 88 | }; |
@@ -99,6 +100,12 @@ static char *preference; | |||
99 | 100 | ||
100 | static int peers; | 101 | static int peers; |
101 | 102 | ||
103 | static void | ||
104 | core_connect_completion_cb (void *cls, | ||
105 | struct GNUNET_TESTBED_Operation *op, | ||
106 | void *ca_result, | ||
107 | const char *emsg ); | ||
108 | |||
102 | /** | 109 | /** |
103 | * Shutdown nicely | 110 | * Shutdown nicely |
104 | * | 111 | * |
@@ -171,6 +178,81 @@ ats_performance_info_cb (void *cls, | |||
171 | GNUNET_free (peer_id); | 178 | GNUNET_free (peer_id); |
172 | } | 179 | } |
173 | 180 | ||
181 | |||
182 | static void do_benchmark () | ||
183 | { | ||
184 | if ((state.connected_ATS_SRV == GNUNET_NO) || | ||
185 | (state.connected_CORE_SRV == GNUNET_NO) || | ||
186 | (state.connected_PEERS == GNUNET_NO) || | ||
187 | (state.connected_CORE == GNUNET_NO)) | ||
188 | return; | ||
189 | |||
190 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
191 | _("BENCHMARKING\n")); | ||
192 | } | ||
193 | |||
194 | |||
195 | static void connect_completion_callback (void *cls, | ||
196 | struct GNUNET_TESTBED_Operation *op, | ||
197 | const char *emsg) | ||
198 | { | ||
199 | static int connections = 0; | ||
200 | struct BenchmarkPeer *p = cls; | ||
201 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
202 | _("Connected peer 0 with peer %p\n"), p->peer); | ||
203 | if (NULL == emsg) | ||
204 | { | ||
205 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
206 | _("Connected peer 0 with peer %p\n"), p->peer); | ||
207 | } | ||
208 | else | ||
209 | { | ||
210 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
211 | _("Failed to connect peer 0 with peer %p\n"), p->peer); | ||
212 | GNUNET_break (0); | ||
213 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | ||
214 | GNUNET_SCHEDULER_cancel(shutdown_task); | ||
215 | shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL); | ||
216 | } | ||
217 | GNUNET_TESTBED_operation_done(op); | ||
218 | p->connect_op = NULL; | ||
219 | connections++; | ||
220 | if (connections == peers -1) | ||
221 | { | ||
222 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
223 | "All peers connected, start benchmarking \n"); | ||
224 | GNUNET_SCHEDULER_add_now (&do_benchmark, NULL); | ||
225 | state.connected_PEERS = GNUNET_YES; | ||
226 | } | ||
227 | } | ||
228 | |||
229 | static void | ||
230 | do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
231 | { | ||
232 | int c_p; | ||
233 | |||
234 | if ((state.connected_ATS_SRV == GNUNET_NO) || | ||
235 | (state.connected_CORE_SRV == GNUNET_NO)) | ||
236 | return; | ||
237 | |||
238 | for (c_p = 1; c_p < peers; c_p ++) | ||
239 | { | ||
240 | ph[c_p].connect_op = GNUNET_TESTBED_overlay_connect( NULL, | ||
241 | &connect_completion_callback, &ph[c_p], ph[0].peer, ph[c_p].peer); | ||
242 | if (NULL == ph[c_p].connect_op) | ||
243 | { | ||
244 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
245 | _("Could not connect peer 0 and peer %u\n"), c_p); | ||
246 | GNUNET_break (0); | ||
247 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | ||
248 | GNUNET_SCHEDULER_cancel(shutdown_task); | ||
249 | shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL); | ||
250 | return; | ||
251 | } | ||
252 | } | ||
253 | } | ||
254 | |||
255 | |||
174 | /** | 256 | /** |
175 | * Controller event callback | 257 | * Controller event callback |
176 | * | 258 | * |
@@ -232,6 +314,44 @@ ats_perf_disconnect_adapter (void *cls, void *op_result) | |||
232 | peer->p_handle = NULL; | 314 | peer->p_handle = NULL; |
233 | } | 315 | } |
234 | 316 | ||
317 | |||
318 | /** | ||
319 | * Callback to be called when a service connect operation is completed | ||
320 | * | ||
321 | * @param cls the callback closure from functions generating an operation | ||
322 | * @param op the operation that has been finished | ||
323 | * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter() | ||
324 | * @param emsg error message in case the operation has failed; will be NULL if | ||
325 | * operation has executed successfully. | ||
326 | */ | ||
327 | void ats_connect_completion_cb (void *cls, | ||
328 | struct GNUNET_TESTBED_Operation *op, | ||
329 | void *ca_result, | ||
330 | const char *emsg ) | ||
331 | { | ||
332 | static int op_done = 0; | ||
333 | if ((NULL != emsg) || (NULL == ca_result)) | ||
334 | { | ||
335 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
336 | _("Initialization failed, shutdown\n")); | ||
337 | GNUNET_break (0); | ||
338 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | ||
339 | GNUNET_SCHEDULER_cancel(shutdown_task); | ||
340 | shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL); | ||
341 | return; | ||
342 | } | ||
343 | |||
344 | op_done ++; | ||
345 | if (op_done == peers) | ||
346 | { | ||
347 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
348 | _("Initialization done, connecting peers\n")); | ||
349 | state.connected_ATS_SRV = GNUNET_YES; | ||
350 | GNUNET_SCHEDULER_add_now (&do_connect, NULL); | ||
351 | } | ||
352 | } | ||
353 | |||
354 | |||
235 | /** | 355 | /** |
236 | * Method called whenever a given peer connects. | 356 | * Method called whenever a given peer connects. |
237 | * | 357 | * |
@@ -243,8 +363,20 @@ core_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer) | |||
243 | { | 363 | { |
244 | struct BenchmarkPeer *p = cls; | 364 | struct BenchmarkPeer *p = cls; |
245 | char *id; | 365 | char *id; |
366 | |||
367 | p->core_connections ++; | ||
246 | id = GNUNET_strdup (GNUNET_i2s (&p->id)); | 368 | id = GNUNET_strdup (GNUNET_i2s (&p->id)); |
247 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s connected to %s \n", id, GNUNET_i2s (peer)); | 369 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s connected to %s \n", id, GNUNET_i2s (peer)); |
370 | if (p->core_connections == peers) | ||
371 | { | ||
372 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s connected all peers \n", id, GNUNET_i2s (peer)); | ||
373 | } | ||
374 | if ((p->core_connections == peers) && (p == &ph[0])) | ||
375 | { | ||
376 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Master peer %s connected all peers on CORE level\n", id, GNUNET_i2s (peer)); | ||
377 | state.connected_CORE = GNUNET_YES; | ||
378 | GNUNET_SCHEDULER_add_now (&do_benchmark, NULL); | ||
379 | } | ||
248 | GNUNET_free (id); | 380 | GNUNET_free (id); |
249 | } | 381 | } |
250 | 382 | ||
@@ -322,7 +454,8 @@ core_connect_completion_cb (void *cls, | |||
322 | { | 454 | { |
323 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 455 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
324 | "Connected to all CORE services\n"); | 456 | "Connected to all CORE services\n"); |
325 | state.connected_CORE = GNUNET_YES; | 457 | state.connected_CORE_SRV = GNUNET_YES; |
458 | GNUNET_SCHEDULER_add_now (&do_connect, NULL); | ||
326 | } | 459 | } |
327 | } | 460 | } |
328 | 461 | ||
@@ -343,101 +476,7 @@ core_disconnect_adapter (void *cls, void *op_result) | |||
343 | } | 476 | } |
344 | 477 | ||
345 | 478 | ||
346 | static void do_benchmark () | ||
347 | { | ||
348 | 479 | ||
349 | } | ||
350 | |||
351 | static void connect_completion_callback (void *cls, | ||
352 | struct GNUNET_TESTBED_Operation *op, | ||
353 | const char *emsg) | ||
354 | { | ||
355 | static int connections = 0; | ||
356 | struct BenchmarkPeer *p = cls; | ||
357 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
358 | _("Connected peer 0 with peer %p\n"), p->peer); | ||
359 | if (NULL == emsg) | ||
360 | { | ||
361 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
362 | _("Connected peer 0 with peer %p\n"), p->peer); | ||
363 | } | ||
364 | else | ||
365 | { | ||
366 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
367 | _("Failed to connect peer 0 with peer %p\n"), p->peer); | ||
368 | GNUNET_break (0); | ||
369 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | ||
370 | GNUNET_SCHEDULER_cancel(shutdown_task); | ||
371 | shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL); | ||
372 | } | ||
373 | GNUNET_TESTBED_operation_done(op); | ||
374 | p->connect_op = NULL; | ||
375 | connections++; | ||
376 | if (connections == peers -1) | ||
377 | { | ||
378 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
379 | "All peers connected, start benchmarking \n"); | ||
380 | GNUNET_SCHEDULER_add_now (&do_benchmark, NULL); | ||
381 | state.connected_PEERS = GNUNET_YES; | ||
382 | } | ||
383 | |||
384 | } | ||
385 | static void | ||
386 | do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
387 | { | ||
388 | int c_p; | ||
389 | for (c_p = 1; c_p < peers; c_p ++) | ||
390 | { | ||
391 | ph[c_p].connect_op = GNUNET_TESTBED_overlay_connect( NULL, | ||
392 | &connect_completion_callback, &ph[c_p], ph[0].peer, ph[c_p].peer); | ||
393 | if (NULL == ph[c_p].connect_op) | ||
394 | { | ||
395 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
396 | _("Could not connect peer 0 and peer %u\n"), c_p); | ||
397 | GNUNET_break (0); | ||
398 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | ||
399 | GNUNET_SCHEDULER_cancel(shutdown_task); | ||
400 | shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL); | ||
401 | return; | ||
402 | } | ||
403 | } | ||
404 | } | ||
405 | |||
406 | /** | ||
407 | * Callback to be called when a service connect operation is completed | ||
408 | * | ||
409 | * @param cls the callback closure from functions generating an operation | ||
410 | * @param op the operation that has been finished | ||
411 | * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter() | ||
412 | * @param emsg error message in case the operation has failed; will be NULL if | ||
413 | * operation has executed successfully. | ||
414 | */ | ||
415 | void ats_connect_completion_cb (void *cls, | ||
416 | struct GNUNET_TESTBED_Operation *op, | ||
417 | void *ca_result, | ||
418 | const char *emsg ) | ||
419 | { | ||
420 | static int op_done = 0; | ||
421 | if ((NULL != emsg) || (NULL == ca_result)) | ||
422 | { | ||
423 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
424 | _("Initialization failed, shutdown\n")); | ||
425 | GNUNET_break (0); | ||
426 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | ||
427 | GNUNET_SCHEDULER_cancel(shutdown_task); | ||
428 | shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL); | ||
429 | return; | ||
430 | } | ||
431 | |||
432 | op_done ++; | ||
433 | if (op_done == peers) | ||
434 | { | ||
435 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
436 | _("Initialization done, connecting peers\n")); | ||
437 | state.connected_ATS = GNUNET_YES; | ||
438 | GNUNET_SCHEDULER_add_now (&do_connect, NULL); | ||
439 | } | ||
440 | } | ||
441 | 480 | ||
442 | /** | 481 | /** |
443 | * Callback to be called when the requested peer information is available | 482 | * Callback to be called when the requested peer information is available |
@@ -449,7 +488,7 @@ void ats_connect_completion_cb (void *cls, | |||
449 | * operation is successfull | 488 | * operation is successfull |
450 | */ | 489 | */ |
451 | static void | 490 | static void |
452 | pid_cb (void *cb_cls, | 491 | peerinformation_cb (void *cb_cls, |
453 | struct GNUNET_TESTBED_Operation *op, | 492 | struct GNUNET_TESTBED_Operation *op, |
454 | const struct GNUNET_TESTBED_PeerInformation*pinfo, | 493 | const struct GNUNET_TESTBED_PeerInformation*pinfo, |
455 | const char *emsg) | 494 | const char *emsg) |
@@ -508,7 +547,7 @@ test_main (void *cls, unsigned int num_peers, | |||
508 | ph[c_p].peer = peers_[c_p]; | 547 | ph[c_p].peer = peers_[c_p]; |
509 | 548 | ||
510 | ph[c_p].info_op = GNUNET_TESTBED_peer_get_information (ph[c_p].peer, | 549 | ph[c_p].info_op = GNUNET_TESTBED_peer_get_information (ph[c_p].peer, |
511 | GNUNET_TESTBED_PIT_IDENTITY, &pid_cb, &ph[c_p]); | 550 | GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &ph[c_p]); |
512 | 551 | ||
513 | ph[c_p].core_op = GNUNET_TESTBED_service_connect (NULL, | 552 | ph[c_p].core_op = GNUNET_TESTBED_service_connect (NULL, |
514 | peers_[c_p], "ats", | 553 | peers_[c_p], "ats", |
@@ -577,8 +616,8 @@ main (int argc, char *argv[]) | |||
577 | peers = DEFAULT_NUM; | 616 | peers = DEFAULT_NUM; |
578 | 617 | ||
579 | ph = GNUNET_malloc (peers * sizeof (struct BenchmarkPeer)); | 618 | ph = GNUNET_malloc (peers * sizeof (struct BenchmarkPeer)); |
580 | state.connected_ATS = GNUNET_NO; | 619 | state.connected_ATS_SRV = GNUNET_NO; |
581 | state.connected_CORE = GNUNET_NO; | 620 | state.connected_CORE_SRV = GNUNET_NO; |
582 | state.connected_PEERS = GNUNET_NO; | 621 | state.connected_PEERS = GNUNET_NO; |
583 | /* Start topology */ | 622 | /* Start topology */ |
584 | uint64_t event_mask; | 623 | uint64_t event_mask; |