diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-08-12 13:40:13 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-08-12 13:40:13 +0000 |
commit | 47d4bf2182b2142272cb2a5283ae929a80e1292c (patch) | |
tree | 824aee8c0169681b7b0167e37d88af25479a6c0e /src/ats/perf_ats.c | |
parent | ec42b7133b9b7816a52a15202dba092114d45694 (diff) | |
download | gnunet-47d4bf2182b2142272cb2a5283ae929a80e1292c.tar.gz gnunet-47d4bf2182b2142272cb2a5283ae929a80e1292c.zip |
-indentation
Diffstat (limited to 'src/ats/perf_ats.c')
-rw-r--r-- | src/ats/perf_ats.c | 186 |
1 files changed, 102 insertions, 84 deletions
diff --git a/src/ats/perf_ats.c b/src/ats/perf_ats.c index c386135ba..41a4f6a89 100644 --- a/src/ats/perf_ats.c +++ b/src/ats/perf_ats.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010,2011 Christian Grothoff (and other contributing authors) | 3 | (C) 2010-2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -18,7 +18,7 @@ | |||
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/test_ats.c | 21 | * @file ats/perf_ats.c |
22 | * @brief ats benchmark: start peers and modify preferences, monitor change over time | 22 | * @brief ats benchmark: start peers and modify preferences, monitor change over time |
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
@@ -104,9 +104,9 @@ static int peers; | |||
104 | 104 | ||
105 | static void | 105 | static void |
106 | core_connect_completion_cb (void *cls, | 106 | core_connect_completion_cb (void *cls, |
107 | struct GNUNET_TESTBED_Operation *op, | 107 | struct GNUNET_TESTBED_Operation *op, |
108 | void *ca_result, | 108 | void *ca_result, |
109 | const char *emsg ); | 109 | const char *emsg ); |
110 | 110 | ||
111 | /** | 111 | /** |
112 | * Shutdown nicely | 112 | * Shutdown nicely |
@@ -117,11 +117,10 @@ core_connect_completion_cb (void *cls, | |||
117 | static void | 117 | static void |
118 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 118 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
119 | { | 119 | { |
120 | int c_p; | 120 | int c_p; |
121 | shutdown_task = GNUNET_SCHEDULER_NO_TASK; | 121 | shutdown_task = GNUNET_SCHEDULER_NO_TASK; |
122 | |||
123 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n")); | ||
124 | 122 | ||
123 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n")); | ||
125 | for (c_p = 0; c_p < peers; c_p++) | 124 | for (c_p = 0; c_p < peers; c_p++) |
126 | { | 125 | { |
127 | if (NULL != ph[c_p].ats_perf_op) | 126 | if (NULL != ph[c_p].ats_perf_op) |
@@ -158,12 +157,12 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
158 | 157 | ||
159 | static void | 158 | static void |
160 | ats_performance_info_cb (void *cls, | 159 | ats_performance_info_cb (void *cls, |
161 | const struct GNUNET_HELLO_Address *address, | 160 | const struct GNUNET_HELLO_Address *address, |
162 | int address_active, | 161 | int address_active, |
163 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 162 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
164 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 163 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
165 | const struct GNUNET_ATS_Information *ats, | 164 | const struct GNUNET_ATS_Information *ats, |
166 | uint32_t ats_count) | 165 | uint32_t ats_count) |
167 | { | 166 | { |
168 | struct BenchmarkPeer *p = cls; | 167 | struct BenchmarkPeer *p = cls; |
169 | int c_a; | 168 | int c_a; |
@@ -173,15 +172,18 @@ ats_performance_info_cb (void *cls, | |||
173 | peer_id = GNUNET_strdup (GNUNET_i2s (&p->id)); | 172 | peer_id = GNUNET_strdup (GNUNET_i2s (&p->id)); |
174 | for (c_a = 0; c_a < ats_count; c_a++) | 173 | for (c_a = 0; c_a < ats_count; c_a++) |
175 | { | 174 | { |
176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("%s: %s %s %u\n"), peer_id, GNUNET_i2s (&address->peer), | 175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("%s: %s %s %u\n"), |
177 | GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)), | 176 | peer_id, |
178 | ntohl(ats[c_a].value)); | 177 | GNUNET_i2s (&address->peer), |
178 | GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)), | ||
179 | ntohl(ats[c_a].value)); | ||
179 | } | 180 | } |
180 | GNUNET_free (peer_id); | 181 | GNUNET_free (peer_id); |
181 | } | 182 | } |
182 | 183 | ||
183 | 184 | ||
184 | static void do_benchmark () | 185 | static void |
186 | do_benchmark () | ||
185 | { | 187 | { |
186 | if ((state.connected_ATS_SRV == GNUNET_NO) || | 188 | if ((state.connected_ATS_SRV == GNUNET_NO) || |
187 | (state.connected_CORE_SRV == GNUNET_NO) || | 189 | (state.connected_CORE_SRV == GNUNET_NO) || |
@@ -194,12 +196,14 @@ static void do_benchmark () | |||
194 | } | 196 | } |
195 | 197 | ||
196 | 198 | ||
197 | static void connect_completion_callback (void *cls, | 199 | static void |
198 | struct GNUNET_TESTBED_Operation *op, | 200 | connect_completion_callback (void *cls, |
199 | const char *emsg) | 201 | struct GNUNET_TESTBED_Operation *op, |
202 | const char *emsg) | ||
200 | { | 203 | { |
201 | static int connections = 0; | 204 | static int connections = 0; |
202 | struct BenchmarkPeer *p = cls; | 205 | struct BenchmarkPeer *p = cls; |
206 | |||
203 | if (NULL == emsg) | 207 | if (NULL == emsg) |
204 | { | 208 | { |
205 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 209 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -226,6 +230,7 @@ static void connect_completion_callback (void *cls, | |||
226 | } | 230 | } |
227 | } | 231 | } |
228 | 232 | ||
233 | |||
229 | static void | 234 | static void |
230 | do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 235 | do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
231 | { | 236 | { |
@@ -278,6 +283,7 @@ controller_event_cb (void *cls, | |||
278 | } | 283 | } |
279 | } | 284 | } |
280 | 285 | ||
286 | |||
281 | /** | 287 | /** |
282 | * Called to open a connection to the peer's ATS performance | 288 | * Called to open a connection to the peer's ATS performance |
283 | * | 289 | * |
@@ -292,6 +298,7 @@ ats_perf_connect_adapter (void *cls, | |||
292 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 298 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
293 | { | 299 | { |
294 | struct BenchmarkPeer *peer = cls; | 300 | struct BenchmarkPeer *peer = cls; |
301 | |||
295 | peer->p_handle = GNUNET_ATS_performance_init (cfg, &ats_performance_info_cb, peer); | 302 | peer->p_handle = GNUNET_ATS_performance_init (cfg, &ats_performance_info_cb, peer); |
296 | if (NULL == peer->p_handle) | 303 | if (NULL == peer->p_handle) |
297 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create ATS performance handle \n"); | 304 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create ATS performance handle \n"); |
@@ -324,10 +331,11 @@ ats_perf_disconnect_adapter (void *cls, void *op_result) | |||
324 | * @param emsg error message in case the operation has failed; will be NULL if | 331 | * @param emsg error message in case the operation has failed; will be NULL if |
325 | * operation has executed successfully. | 332 | * operation has executed successfully. |
326 | */ | 333 | */ |
327 | void ats_connect_completion_cb (void *cls, | 334 | static void |
328 | struct GNUNET_TESTBED_Operation *op, | 335 | ats_connect_completion_cb (void *cls, |
329 | void *ca_result, | 336 | struct GNUNET_TESTBED_Operation *op, |
330 | const char *emsg ) | 337 | void *ca_result, |
338 | const char *emsg ) | ||
331 | { | 339 | { |
332 | static int op_done = 0; | 340 | static int op_done = 0; |
333 | if ((NULL != emsg) || (NULL == ca_result)) | 341 | if ((NULL != emsg) || (NULL == ca_result)) |
@@ -361,27 +369,31 @@ void ats_connect_completion_cb (void *cls, | |||
361 | static void | 369 | static void |
362 | core_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer) | 370 | core_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer) |
363 | { | 371 | { |
364 | struct BenchmarkPeer *p = cls; | 372 | struct BenchmarkPeer *p = cls; |
365 | char *id; | 373 | char *id; |
366 | 374 | ||
367 | p->core_connections ++; | 375 | p->core_connections ++; |
368 | id = GNUNET_strdup (GNUNET_i2s (&p->id)); | 376 | id = GNUNET_strdup (GNUNET_i2s (&p->id)); |
369 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s connected to %s \n", id, GNUNET_i2s (peer)); | 377 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
378 | "%s connected to %s \n", | ||
379 | id, GNUNET_i2s (peer)); | ||
370 | if (p->core_connections == peers) | 380 | if (p->core_connections == peers) |
371 | { | 381 | { |
372 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s connected all peers \n", id, GNUNET_i2s (peer)); | 382 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
383 | "%s connected all peers\n", | ||
384 | id); | ||
373 | } | 385 | } |
374 | if ((p->core_connections == peers) && (p == &ph[0])) | 386 | if ((p->core_connections == peers) && (p == &ph[0])) |
375 | { | 387 | { |
376 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Master peer %s connected all peers on CORE level\n", id, GNUNET_i2s (peer)); | 388 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
377 | state.connected_CORE = GNUNET_YES; | 389 | "Master peer %s connected all peers on CORE level\n", id, GNUNET_i2s (peer)); |
378 | GNUNET_SCHEDULER_add_now (&do_benchmark, NULL); | 390 | state.connected_CORE = GNUNET_YES; |
391 | GNUNET_SCHEDULER_add_now (&do_benchmark, NULL); | ||
379 | } | 392 | } |
380 | GNUNET_free (id); | 393 | GNUNET_free (id); |
381 | } | 394 | } |
382 | 395 | ||
383 | 396 | ||
384 | |||
385 | /** | 397 | /** |
386 | * Method called whenever a peer disconnects. | 398 | * Method called whenever a peer disconnects. |
387 | * | 399 | * |
@@ -391,10 +403,12 @@ core_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer) | |||
391 | static void | 403 | static void |
392 | core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer) | 404 | core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer) |
393 | { | 405 | { |
394 | struct BenchmarkPeer *p = cls; | 406 | struct BenchmarkPeer *p = cls; |
395 | char *id; | 407 | char *id; |
396 | id = GNUNET_strdup (GNUNET_i2s (&p->id)); | 408 | |
397 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s disconnected from %s \n", id, GNUNET_i2s (peer)); | 409 | id = GNUNET_strdup (GNUNET_i2s (&p->id)); |
410 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
411 | "%s disconnected from %s \n", id, GNUNET_i2s (peer)); | ||
398 | GNUNET_free (id); | 412 | GNUNET_free (id); |
399 | } | 413 | } |
400 | 414 | ||
@@ -413,12 +427,14 @@ core_connect_adapter (void *cls, | |||
413 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 427 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
414 | { | 428 | { |
415 | struct BenchmarkPeer *peer = cls; | 429 | struct BenchmarkPeer *peer = cls; |
430 | |||
416 | peer->ch = GNUNET_CORE_connect(cfg, peer, NULL, | 431 | peer->ch = GNUNET_CORE_connect(cfg, peer, NULL, |
417 | core_connect_cb, | 432 | core_connect_cb, |
418 | core_disconnect_cb, | 433 | core_disconnect_cb, |
419 | NULL, GNUNET_NO, NULL, GNUNET_NO, NULL); | 434 | NULL, GNUNET_NO, NULL, GNUNET_NO, NULL); |
420 | if (NULL == peer->ch) | 435 | if (NULL == peer->ch) |
421 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create core connection \n"); | 436 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
437 | "Failed to create core connection \n"); | ||
422 | return peer->ch; | 438 | return peer->ch; |
423 | } | 439 | } |
424 | 440 | ||
@@ -434,9 +450,9 @@ core_connect_adapter (void *cls, | |||
434 | */ | 450 | */ |
435 | static void | 451 | static void |
436 | core_connect_completion_cb (void *cls, | 452 | core_connect_completion_cb (void *cls, |
437 | struct GNUNET_TESTBED_Operation *op, | 453 | struct GNUNET_TESTBED_Operation *op, |
438 | void *ca_result, | 454 | void *ca_result, |
439 | const char *emsg ) | 455 | const char *emsg ) |
440 | { | 456 | { |
441 | static int core_done = 0; | 457 | static int core_done = 0; |
442 | if ((NULL != emsg) || (NULL == ca_result)) | 458 | if ((NULL != emsg) || (NULL == ca_result)) |
@@ -476,8 +492,6 @@ core_disconnect_adapter (void *cls, void *op_result) | |||
476 | } | 492 | } |
477 | 493 | ||
478 | 494 | ||
479 | |||
480 | |||
481 | /** | 495 | /** |
482 | * Callback to be called when the requested peer information is available | 496 | * Callback to be called when the requested peer information is available |
483 | * | 497 | * |
@@ -489,16 +503,18 @@ core_disconnect_adapter (void *cls, void *op_result) | |||
489 | */ | 503 | */ |
490 | static void | 504 | static void |
491 | peerinformation_cb (void *cb_cls, | 505 | peerinformation_cb (void *cb_cls, |
492 | struct GNUNET_TESTBED_Operation *op, | 506 | struct GNUNET_TESTBED_Operation *op, |
493 | const struct GNUNET_TESTBED_PeerInformation*pinfo, | 507 | const struct GNUNET_TESTBED_PeerInformation*pinfo, |
494 | const char *emsg) | 508 | const char *emsg) |
495 | { | 509 | { |
496 | struct BenchmarkPeer *p = cb_cls; | 510 | struct BenchmarkPeer *p = cb_cls; |
511 | |||
497 | if (pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY) | 512 | if (pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY) |
498 | { | 513 | { |
499 | p->id = *pinfo->result.id; | 514 | p->id = *pinfo->result.id; |
500 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 515 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
501 | _("[%3u] Peers %s\n"), p->no, GNUNET_i2s (&p->id)); | 516 | "[%3u] Peers %s\n", |
517 | p->no, GNUNET_i2s (&p->id)); | ||
502 | } | 518 | } |
503 | else | 519 | else |
504 | { | 520 | { |
@@ -522,14 +538,15 @@ peerinformation_cb (void *cb_cls, | |||
522 | */ | 538 | */ |
523 | static void | 539 | static void |
524 | test_main (void *cls, unsigned int num_peers, | 540 | test_main (void *cls, unsigned int num_peers, |
525 | struct GNUNET_TESTBED_Peer **peers_, | 541 | struct GNUNET_TESTBED_Peer **peers_, |
526 | unsigned int links_succeeded, | 542 | unsigned int links_succeeded, |
527 | unsigned int links_failed) | 543 | unsigned int links_failed) |
528 | { | 544 | { |
529 | int c_p; | 545 | int c_p; |
530 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 546 | |
531 | _("Benchmarking solver `%s' on preference `%s' with %u peers\n"), | 547 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
532 | solver, preference, peers); | 548 | _("Benchmarking solver `%s' on preference `%s' with %u peers\n"), |
549 | solver, preference, peers); | ||
533 | 550 | ||
534 | shutdown_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &do_shutdown, NULL); | 551 | shutdown_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &do_shutdown, NULL); |
535 | 552 | ||
@@ -537,8 +554,8 @@ test_main (void *cls, unsigned int num_peers, | |||
537 | GNUNET_assert (peers == num_peers); | 554 | GNUNET_assert (peers == num_peers); |
538 | GNUNET_assert (NULL != peers_); | 555 | GNUNET_assert (NULL != peers_); |
539 | 556 | ||
540 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 557 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
541 | _("Initializing... \n")); | 558 | _("Initializing... \n")); |
542 | 559 | ||
543 | for (c_p = 0; c_p < num_peers; c_p++) | 560 | for (c_p = 0; c_p < num_peers; c_p++) |
544 | { | 561 | { |
@@ -548,21 +565,22 @@ test_main (void *cls, unsigned int num_peers, | |||
548 | ph[c_p].peer = peers_[c_p]; | 565 | ph[c_p].peer = peers_[c_p]; |
549 | 566 | ||
550 | ph[c_p].info_op = GNUNET_TESTBED_peer_get_information (ph[c_p].peer, | 567 | ph[c_p].info_op = GNUNET_TESTBED_peer_get_information (ph[c_p].peer, |
551 | GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &ph[c_p]); | 568 | GNUNET_TESTBED_PIT_IDENTITY, |
569 | &peerinformation_cb, &ph[c_p]); | ||
552 | 570 | ||
553 | ph[c_p].core_op = GNUNET_TESTBED_service_connect (NULL, | 571 | ph[c_p].core_op = GNUNET_TESTBED_service_connect (NULL, |
554 | peers_[c_p], "ats", | 572 | peers_[c_p], "ats", |
555 | core_connect_completion_cb, NULL, | 573 | core_connect_completion_cb, NULL, |
556 | &core_connect_adapter, | 574 | &core_connect_adapter, |
557 | &core_disconnect_adapter, | 575 | &core_disconnect_adapter, |
558 | &ph[c_p]); | 576 | &ph[c_p]); |
559 | 577 | ||
560 | ph[c_p].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, | 578 | ph[c_p].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, |
561 | peers_[c_p], "ats", | 579 | peers_[c_p], "ats", |
562 | ats_connect_completion_cb, NULL, | 580 | ats_connect_completion_cb, NULL, |
563 | &ats_perf_connect_adapter, | 581 | &ats_perf_connect_adapter, |
564 | &ats_perf_disconnect_adapter, | 582 | &ats_perf_disconnect_adapter, |
565 | &ph[c_p]); | 583 | &ph[c_p]); |
566 | } | 584 | } |
567 | } | 585 | } |
568 | 586 | ||
@@ -570,13 +588,13 @@ test_main (void *cls, unsigned int num_peers, | |||
570 | int | 588 | int |
571 | main (int argc, char *argv[]) | 589 | main (int argc, char *argv[]) |
572 | { | 590 | { |
573 | char *tmp; | 591 | char *tmp; |
574 | char *tmp_sep; | 592 | char *tmp_sep; |
575 | char *test_name; | 593 | char *test_name; |
576 | char *conf_name; | 594 | char *conf_name; |
577 | int c; | 595 | int c; |
578 | 596 | ||
579 | peers = 0; | 597 | peers = 0; |
580 | result = 1; | 598 | result = 1; |
581 | 599 | ||
582 | /* figure out testname */ | 600 | /* figure out testname */ |
@@ -608,8 +626,8 @@ main (int argc, char *argv[]) | |||
608 | } | 626 | } |
609 | if (c < argc-1) | 627 | if (c < argc-1) |
610 | { | 628 | { |
611 | if ((0L != (peers = strtol (argv[c + 1], NULL, 10))) && (peers >= 2)) | 629 | if ((0L != (peers = strtol (argv[c + 1], NULL, 10))) && (peers >= 2)) |
612 | fprintf (stderr, "Starting %u peers\n", peers); | 630 | fprintf (stderr, "Starting %u peers\n", peers); |
613 | else | 631 | else |
614 | peers = DEFAULT_NUM; | 632 | peers = DEFAULT_NUM; |
615 | } | 633 | } |