aboutsummaryrefslogtreecommitdiff
path: root/src/ats-tests/perf_ats.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-01-21 16:27:55 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-01-21 16:27:55 +0000
commitf15624031417464fa72c659be7e0be8db55a909b (patch)
tree431a51f38b9516f56dc6d38e347fef0abade1b51 /src/ats-tests/perf_ats.c
parent1f3f45c08b82899a5350633dc6f1030216a1e150 (diff)
downloadgnunet-f15624031417464fa72c659be7e0be8db55a909b.tar.gz
gnunet-f15624031417464fa72c659be7e0be8db55a909b.zip
not yet finished: moving perf_ats to testing
Diffstat (limited to 'src/ats-tests/perf_ats.c')
-rw-r--r--src/ats-tests/perf_ats.c766
1 files changed, 58 insertions, 708 deletions
diff --git a/src/ats-tests/perf_ats.c b/src/ats-tests/perf_ats.c
index f52bcfb25..daffb9f28 100644
--- a/src/ats-tests/perf_ats.c
+++ b/src/ats-tests/perf_ats.c
@@ -28,7 +28,7 @@
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#include "gnunet_core_service.h"
31#include "perf_ats.h" 31#include "ats-testing.h"
32 32
33 33
34#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) 34#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
@@ -40,58 +40,6 @@
40#define TEST_MESSAGE_SIZE 1000 40#define TEST_MESSAGE_SIZE 1000
41#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) 41#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
42 42
43/**
44 * Connect peers with testbed
45 */
46struct TestbedConnectOperation
47{
48 /**
49 * The benchmarking master initiating this connection
50 */
51 struct BenchmarkPeer *master;
52
53 /**
54 * The benchmarking slave to connect to
55 */
56 struct BenchmarkPeer *slave;
57
58 /**
59 * Testbed operation to connect peers
60 */
61 struct GNUNET_TESTBED_Operation *connect_op;
62};
63
64/**
65 * Overall state of the performance benchmark
66 */
67struct BenchmarkState
68{
69 /**
70 * Are we connected to ATS service of all peers: GNUNET_YES/NO
71 */
72 int connected_ATS_service;
73
74 /**
75 * Are we connected to CORE service of all peers: GNUNET_YES/NO
76 */
77 int connected_COMM_service;
78
79 /**
80 * Are we connected to all peers: GNUNET_YES/NO
81 */
82 int connected_PEERS;
83
84 /**
85 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
86 */
87 int connected_CORE;
88
89 /**
90 * Are we connected to CORE service of all peers: GNUNET_YES/NO
91 */
92 int benchmarking;
93};
94
95 43
96/** 44/**
97 * Shutdown task 45 * Shutdown task
@@ -138,6 +86,16 @@ static char *pref_str;
138static int pref_val; 86static int pref_val;
139 87
140/** 88/**
89 * Benchmark duration
90 */
91static struct GNUNET_TIME_Relative perf_duration;
92
93/**
94 * Logging frequency
95 */
96static struct GNUNET_TIME_Relative log_frequency;
97
98/**
141 * Number master peers 99 * Number master peers
142 */ 100 */
143static unsigned int num_masters; 101static unsigned int num_masters;
@@ -153,25 +111,10 @@ static struct BenchmarkPeer *mps;
153static unsigned int num_slaves; 111static unsigned int num_slaves;
154 112
155/** 113/**
156 * Array of slave peers 114 * Array of master peers
157 */ 115 */
158static struct BenchmarkPeer *sps; 116static struct BenchmarkPeer *sps;
159 117
160/**
161 * Benchmark duration
162 */
163static struct GNUNET_TIME_Relative perf_duration;
164
165/**
166 * Logging frequency
167 */
168static struct GNUNET_TIME_Relative log_frequency;
169
170/**
171 * Benchmark state
172 */
173static struct BenchmarkState state;
174
175static void 118static void
176evaluate () 119evaluate ()
177{ 120{
@@ -221,14 +164,10 @@ evaluate ()
221static void 164static void
222do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 165do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
223{ 166{
224 int c_m; 167 /*
225 int c_s;
226 int c_op;
227 struct BenchmarkPeer *p;
228
229 if (GNUNET_YES == logging) 168 if (GNUNET_YES == logging)
230 perf_logging_stop(); 169 perf_logging_stop();
231 170*/
232 shutdown_task = GNUNET_SCHEDULER_NO_TASK; 171 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
233 if (GNUNET_SCHEDULER_NO_TASK != progress_task) 172 if (GNUNET_SCHEDULER_NO_TASK != progress_task)
234 { 173 {
@@ -238,142 +177,9 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
238 progress_task = GNUNET_SCHEDULER_NO_TASK; 177 progress_task = GNUNET_SCHEDULER_NO_TASK;
239 178
240 evaluate (); 179 evaluate ();
241 state.benchmarking = GNUNET_NO;
242 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n")); 180 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n"));
243 181
244 for (c_m = 0; c_m < num_masters; c_m++) 182 GNUNET_ATS_TEST_shutdown_topology();
245 {
246 p = &mps[c_m];
247 if (NULL != mps[c_m].peer_id_op)
248 {
249 GNUNET_TESTBED_operation_done (p->peer_id_op);
250 p->peer_id_op = NULL;
251 }
252
253 if (GNUNET_SCHEDULER_NO_TASK != p->ats_task)
254 GNUNET_SCHEDULER_cancel (p->ats_task);
255 p->ats_task = GNUNET_SCHEDULER_NO_TASK;
256
257 for (c_op = 0; c_op < p->num_partners; c_op++)
258 {
259 if (NULL != p->partners[c_op].cth)
260 {
261 GNUNET_CORE_notify_transmit_ready_cancel (p->partners[c_op].cth);
262 p->partners[c_op].cth = NULL;
263 }
264 if (NULL != p->partners[c_op].tth)
265 {
266 GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->partners[c_op].tth);
267 p->partners[c_op].tth = NULL;
268 }
269 if (NULL != p->core_connect_ops[c_op].connect_op)
270 {
271 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
272 _("Failed to connect peer 0 and %u\n"), c_op);
273 GNUNET_TESTBED_operation_done (
274 p->core_connect_ops[c_op].connect_op);
275 p->core_connect_ops[c_op].connect_op = NULL;
276 result = 1;
277 }
278 }
279
280 if (NULL != p->ats_perf_op)
281 {
282 GNUNET_TESTBED_operation_done (p->ats_perf_op);
283 p->ats_perf_op = NULL;
284 }
285
286 if (NULL != p->comm_op)
287 {
288 GNUNET_TESTBED_operation_done (p->comm_op);
289 p->comm_op = NULL;
290 }
291 GNUNET_free(p->core_connect_ops);
292 GNUNET_free(p->partners);
293 p->partners = NULL;
294 }
295
296 for (c_s = 0; c_s < num_slaves; c_s++)
297 {
298 p = &sps[c_s];
299 if (NULL != p->peer_id_op)
300 {
301 GNUNET_TESTBED_operation_done (p->peer_id_op);
302 p->peer_id_op = NULL;
303 }
304
305 for (c_op = 0; c_op < p->num_partners; c_op++)
306 {
307 if (NULL != p->partners[c_op].cth)
308 {
309 GNUNET_CORE_notify_transmit_ready_cancel (p->partners[c_op].cth);
310 p->partners[c_op].cth = NULL;
311 }
312 if (NULL != p->partners[c_op].tth)
313 {
314 GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->partners[c_op].tth);
315 p->partners[c_op].tth = NULL;
316 }
317 }
318 if (NULL != p->ats_perf_op)
319 {
320 GNUNET_TESTBED_operation_done (p->ats_perf_op);
321 p->ats_perf_op = NULL;
322 }
323 if (NULL != p->comm_op)
324 {
325 GNUNET_TESTBED_operation_done (p->comm_op);
326 p->comm_op = NULL;
327 }
328 GNUNET_free(p->partners);
329 p->partners = NULL;
330 }
331
332 GNUNET_SCHEDULER_shutdown ();
333}
334
335static struct BenchmarkPeer *
336find_peer (const struct GNUNET_PeerIdentity * peer)
337{
338 int c_p;
339
340 for (c_p = 0; c_p < num_masters; c_p++)
341 {
342 if (0 == memcmp (&mps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity)))
343 return &mps[c_p];
344 }
345
346 for (c_p = 0; c_p < num_slaves; c_p++)
347 {
348 if (0 == memcmp (&sps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity)))
349 return &sps[c_p];
350 }
351 return NULL ;
352}
353
354/**
355 * Controller event callback
356 *
357 * @param cls NULL
358 * @param event the controller event
359 */
360static void
361controller_event_cb (void *cls,
362 const struct GNUNET_TESTBED_EventInformation *event)
363{
364 //struct BenchmarkPeer *p = cls;
365 switch (event->type)
366 {
367 case GNUNET_TESTBED_ET_CONNECT:
368 break;
369 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
370 break;
371 default:
372 GNUNET_break(0);
373 result = 2;
374 GNUNET_SCHEDULER_cancel (shutdown_task);
375 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL );
376 }
377} 183}
378 184
379static size_t 185static size_t
@@ -399,7 +205,7 @@ comm_send_ready (void *cls, size_t size, void *buf)
399 return 0; 205 return 0;
400 } 206 }
401 207
402 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Master [%u]: Sending PING to [%u]\n", 208 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Master [%u]: Sending PING to [%u]\n",
403 p->me->no, p->dest->no); 209 p->me->no, p->dest->no);
404 210
405 p->messages_sent++; 211 p->messages_sent++;
@@ -466,18 +272,14 @@ ats_pref_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
466} 272}
467 273
468static void 274static void
469do_benchmark () 275do_benchmark (void *cls, struct BenchmarkPeer *masters, struct BenchmarkPeer *slaves)
470{ 276{
471 int c_m; 277 int c_m;
472 int c_s; 278 int c_s;
473 279
474 if ((state.connected_ATS_service == GNUNET_NO) 280 mps = masters;
475 || (state.connected_COMM_service == GNUNET_NO) 281 sps = slaves;
476 || (state.connected_PEERS == GNUNET_NO)
477 || (state.connected_CORE == GNUNET_NO))
478 return;
479 282
480 state.benchmarking = GNUNET_YES;
481 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking start\n")); 283 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking start\n"));
482 284
483 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) 285 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
@@ -487,154 +289,48 @@ do_benchmark ()
487 289
488 progress_task = GNUNET_SCHEDULER_add_now (&print_progress, NULL ); 290 progress_task = GNUNET_SCHEDULER_add_now (&print_progress, NULL );
489 291
292 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Topology connected, start benchmarking...\n");
293
490 /* Start sending test messages */ 294 /* Start sending test messages */
491 for (c_m = 0; c_m < num_masters; c_m++) 295 for (c_m = 0; c_m < num_masters; c_m++)
492 { 296 {
493 for (c_s = 0; c_s < num_slaves; c_s++) 297 for (c_s = 0; c_s < num_slaves; c_s++)
494 comm_schedule_send (&mps[c_m].partners[c_s]); 298 comm_schedule_send (&masters[c_m].partners[c_s]);
495 if (pref_val != GNUNET_ATS_PREFERENCE_END) 299 if (pref_val != GNUNET_ATS_PREFERENCE_END)
496 mps[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task, &mps[c_m]); 300 masters[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task, &masters[c_m]);
497 } 301 }
302
303 /*
498 if (GNUNET_YES == logging) 304 if (GNUNET_YES == logging)
499 perf_logging_start (log_frequency, testname, mps, num_masters); 305 perf_logging_start (log_frequency, testname, mps, num_masters);
500 306*/
501} 307}
502 308
503static void
504connect_completion_callback (void *cls, struct GNUNET_TESTBED_Operation *op,
505 const char *emsg)
506{
507 struct TestbedConnectOperation *cop = cls;
508 static int ops = 0;
509 int c;
510 if (NULL == emsg)
511 {
512 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
513 _("Connected master [%u] with slave [%u]\n"), cop->master->no,
514 cop->slave->no);
515 }
516 else
517 {
518 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
519 _("Failed to connect master peer [%u] with slave [%u]\n"),
520 cop->master->no, cop->slave->no);
521 GNUNET_break(0);
522 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
523 GNUNET_SCHEDULER_cancel (shutdown_task);
524 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
525 }
526 GNUNET_TESTBED_operation_done (op);
527 ops++;
528 for (c = 0; c < num_slaves; c++)
529 {
530 if (cop == &cop->master->core_connect_ops[c])
531 cop->master->core_connect_ops[c].connect_op = NULL;
532 }
533 if (ops == num_masters * num_slaves)
534 {
535 state.connected_PEERS = GNUNET_YES;
536 GNUNET_SCHEDULER_add_now (&do_benchmark, NULL );
537 }
538}
539
540static void
541do_connect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
542{
543 int c_m;
544 int c_s;
545 struct BenchmarkPeer *p;
546
547 if ((state.connected_ATS_service == GNUNET_NO)
548 || (state.connected_COMM_service == GNUNET_NO))
549 return;
550
551 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Connecting peers on CORE level\n"));
552
553 for (c_m = 0; c_m < num_masters; c_m++)
554 {
555 p = &mps[c_m];
556 p->core_connect_ops = GNUNET_malloc (num_slaves *
557 sizeof (struct TestbedConnectOperation));
558 309
559 for (c_s = 0; c_s < num_slaves; c_s++) 310static size_t
560 { 311comm_send_pong_ready (void *cls, size_t size, void *buf)
561 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
562 _("Connecting master [%u] with slave [%u]\n"), p->no, sps[c_s].no);
563 p->core_connect_ops[c_s].master = p;
564 p->core_connect_ops[c_s].slave = &sps[c_s];
565 p->core_connect_ops[c_s].connect_op = GNUNET_TESTBED_overlay_connect (
566 NULL, &connect_completion_callback, &p->core_connect_ops[c_s],
567 sps[c_s].peer, p->peer);
568 if (NULL == p->core_connect_ops[c_s].connect_op)
569 {
570 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
571 _("Could not connect master [%u] and slave [%u]\n"), p->no,
572 sps[c_s].no);
573 GNUNET_break(0);
574 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
575 GNUNET_SCHEDULER_cancel (shutdown_task);
576 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
577 return;
578 }
579 }
580 }
581}
582
583/**
584 * Method called whenever a given peer connects.
585 *
586 * @param cls closure
587 * @param peer peer identity this notification is about
588 */
589static void
590comm_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
591{ 312{
592 struct BenchmarkPeer *me = cls; 313 static char msgbuf[TEST_MESSAGE_SIZE];
593 struct BenchmarkPeer *remote; 314 struct BenchmarkPartner *p = cls;
594 char *id; 315 struct GNUNET_MessageHeader *msg;
595 int c;
596 int completed;
597 316
598 remote = find_peer (peer); 317 if (GNUNET_YES == test_core)
599 if (NULL == remote) 318 p->cth = NULL;
600 { 319 else
601 GNUNET_break(0); 320 p->tth = NULL;
602 return;
603 }
604 321
605 id = GNUNET_strdup (GNUNET_i2s (&me->id)); 322 p->messages_sent++;
606 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s [%u] `%s' connected to %s [%u] %s\n", 323 p->bytes_sent += TEST_MESSAGE_SIZE;
607 (me->master == GNUNET_YES) ? "Master": "Slave", me->no, id, 324 p->me->total_messages_sent++;
608 (remote->master == GNUNET_YES) ? "Master": "Slave", remote->no, 325 p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
609 GNUNET_i2s (peer));
610 326
611 me->core_connections++; 327 msg = (struct GNUNET_MessageHeader *) &msgbuf;
612 if ((GNUNET_YES == me->master) && (GNUNET_NO == remote->master) 328 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
613 && (GNUNET_NO == state.connected_CORE)) 329 msg->type = htons (TEST_MESSAGE_TYPE_PONG);
614 { 330 msg->size = htons (TEST_MESSAGE_SIZE);
615 me->core_slave_connections++; 331 memcpy (buf, msg, TEST_MESSAGE_SIZE);
616 332
617 if (me->core_slave_connections == num_slaves) 333 return TEST_MESSAGE_SIZE;
618 {
619 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Master [%u] connected all slaves\n",
620 me->no);
621 }
622 completed = GNUNET_YES;
623 for (c = 0; c < num_masters; c++)
624 {
625 if (mps[c].core_slave_connections != num_slaves)
626 completed = GNUNET_NO;
627 }
628 if (GNUNET_YES == completed)
629 {
630 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
631 "All master peers connected all slave peers\n", id,
632 GNUNET_i2s (peer));
633 state.connected_CORE = GNUNET_YES;
634 GNUNET_SCHEDULER_add_now (&do_benchmark, NULL );
635 }
636 }
637 GNUNET_free(id);
638} 334}
639 335
640static struct BenchmarkPartner * 336static struct BenchmarkPartner *
@@ -657,67 +353,6 @@ find_partner (struct BenchmarkPeer *me, const struct GNUNET_PeerIdentity * peer)
657 return NULL; 353 return NULL;
658} 354}
659 355
660static void
661comm_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
662{
663 struct BenchmarkPeer *me = cls;
664 struct BenchmarkPartner *p;
665 char *id;
666
667 if (NULL == (p = find_partner (me, peer)))
668 return;
669
670 id = GNUNET_strdup (GNUNET_i2s (&me->id));
671 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s disconnected from %s \n", id,
672 GNUNET_i2s (peer));
673 GNUNET_assert(me->core_connections > 0);
674 me->core_connections--;
675
676 if ((GNUNET_YES == state.benchmarking)
677 && ((GNUNET_YES == me->master) || (GNUNET_YES == p->dest->master)))
678 {
679 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
680 "%s disconnected from %s while benchmarking \n", id, GNUNET_i2s (peer));
681 if (NULL != p->tth)
682 {
683 GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->tth);
684 p->tth = NULL;
685 }
686 if (NULL != p->cth)
687 {
688 GNUNET_CORE_notify_transmit_ready_cancel (p->cth);
689 p->cth = NULL;
690 }
691 }
692 GNUNET_free(id);
693}
694
695static size_t
696comm_send_pong_ready (void *cls, size_t size, void *buf)
697{
698 static char msgbuf[TEST_MESSAGE_SIZE];
699 struct BenchmarkPartner *p = cls;
700 struct GNUNET_MessageHeader *msg;
701
702 if (GNUNET_YES == test_core)
703 p->cth = NULL;
704 else
705 p->tth = NULL;
706
707 p->messages_sent++;
708 p->bytes_sent += TEST_MESSAGE_SIZE;
709 p->me->total_messages_sent++;
710 p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
711
712 msg = (struct GNUNET_MessageHeader *) &msgbuf;
713 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
714 msg->type = htons (TEST_MESSAGE_TYPE_PONG);
715 msg->size = htons (TEST_MESSAGE_SIZE);
716 memcpy (buf, msg, TEST_MESSAGE_SIZE);
717
718 return TEST_MESSAGE_SIZE;
719}
720
721static int 356static int
722comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other, 357comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
723 const struct GNUNET_MessageHeader *message) 358 const struct GNUNET_MessageHeader *message)
@@ -732,7 +367,7 @@ comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
732 return GNUNET_SYSERR; 367 return GNUNET_SYSERR;
733 } 368 }
734 369
735 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 370 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
736 "Slave [%u]: Received PING from [%u], sending PONG\n", me->no, 371 "Slave [%u]: Received PING from [%u], sending PONG\n", me->no,
737 p->dest->no); 372 p->dest->no);
738 373
@@ -771,7 +406,7 @@ comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
771 return GNUNET_SYSERR; 406 return GNUNET_SYSERR;
772 } 407 }
773 408
774 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 409 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
775 "Master [%u]: Received PONG from [%u], next message\n", me->no, 410 "Master [%u]: Received PONG from [%u], next message\n", me->no,
776 p->dest->no); 411 p->dest->no);
777 412
@@ -786,61 +421,14 @@ comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
786 return GNUNET_OK; 421 return GNUNET_OK;
787} 422}
788 423
789static void *
790core_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
791{
792 struct BenchmarkPeer *me = cls;
793 424
794 static const struct GNUNET_CORE_MessageHandler handlers[] = { {
795 &comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 }, { &comm_handle_pong,
796 TEST_MESSAGE_TYPE_PONG, 0 }, { NULL, 0, 0 } };
797
798 me->ch = GNUNET_CORE_connect (cfg, me, NULL, comm_connect_cb,
799 comm_disconnect_cb, NULL, GNUNET_NO, NULL, GNUNET_NO, handlers);
800 if (NULL == me->ch)
801 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create core connection \n");
802 return me->ch;
803}
804
805static void
806core_disconnect_adapter (void *cls, void *op_result)
807{
808 struct BenchmarkPeer *me = cls;
809
810 GNUNET_CORE_disconnect (me->ch);
811 me->ch = NULL;
812}
813
814static void
815comm_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
816 void *ca_result, const char *emsg)
817{
818 static int comm_done = 0;
819 if ((NULL != emsg) || (NULL == ca_result))
820 {
821 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
822 GNUNET_break(0);
823 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
824 GNUNET_SCHEDULER_cancel (shutdown_task);
825 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
826 return;
827 }
828 comm_done++;
829
830 if (comm_done == num_slaves + num_masters)
831 {
832 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all %s services\n",
833 (GNUNET_YES == test_core) ? "CORE" : "TRANSPORT");
834 state.connected_COMM_service = GNUNET_YES;
835 GNUNET_SCHEDULER_add_now (&do_connect_peers, NULL );
836 }
837}
838 425
839static void 426static void
840transport_recv_cb (void *cls, 427transport_recv_cb (void *cls,
841 const struct GNUNET_PeerIdentity * peer, 428 const struct GNUNET_PeerIdentity * peer,
842 const struct GNUNET_MessageHeader * message) 429 const struct GNUNET_MessageHeader * message)
843{ 430{
431 GNUNET_break (0);
844 if (TEST_MESSAGE_SIZE != ntohs (message->size) || 432 if (TEST_MESSAGE_SIZE != ntohs (message->size) ||
845 (TEST_MESSAGE_TYPE_PING != ntohs (message->type) && 433 (TEST_MESSAGE_TYPE_PING != ntohs (message->type) &&
846 TEST_MESSAGE_TYPE_PONG != ntohs (message->type))) 434 TEST_MESSAGE_TYPE_PONG != ntohs (message->type)))
@@ -855,62 +443,8 @@ transport_recv_cb (void *cls,
855} 443}
856 444
857 445
858static void *
859transport_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
860{
861 struct BenchmarkPeer *me = cls;
862
863 me->th = GNUNET_TRANSPORT_connect (cfg, &me->id, me, &transport_recv_cb,
864 &comm_connect_cb, &comm_disconnect_cb);
865 if (NULL == me->th)
866 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create transport connection \n");
867 return me->th;
868}
869 446
870static void
871transport_disconnect_adapter (void *cls, void *op_result)
872{
873 struct BenchmarkPeer *me = cls;
874 447
875 GNUNET_TRANSPORT_disconnect (me->th);
876 me->th = NULL;
877}
878
879static void
880do_comm_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
881{
882 int c_s;
883 int c_m;
884 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all %s services\n",
885 (GNUNET_YES == test_core) ? "CORE" : "TRANSPORT");
886 for (c_m = 0; c_m < num_masters; c_m++)
887 {
888 if (GNUNET_YES == test_core)
889 mps[c_m].comm_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer,
890 "core", &comm_connect_completion_cb, NULL, &core_connect_adapter,
891 &core_disconnect_adapter, &mps[c_m]);
892 else
893 {
894 mps[c_m].comm_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer,
895 "transport", &comm_connect_completion_cb, NULL, &transport_connect_adapter,
896 &transport_disconnect_adapter, &mps[c_m]);
897 }
898 }
899
900 for (c_s = 0; c_s < num_slaves; c_s++)
901 {
902 if (GNUNET_YES == test_core)
903 sps[c_s].comm_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer,
904 "core", &comm_connect_completion_cb, NULL, &core_connect_adapter,
905 &core_disconnect_adapter, &sps[c_s]);
906 else
907 {
908 sps[c_s].comm_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer,
909 "transport", &comm_connect_completion_cb, NULL, &transport_connect_adapter,
910 &transport_disconnect_adapter, &sps[c_s]);
911 }
912 }
913}
914 448
915static void 449static void
916ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address, 450ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
@@ -999,182 +533,16 @@ ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
999 break; 533 break;
1000 } 534 }
1001 } 535 }
536 /*
1002 if ((GNUNET_YES == logging) && (GNUNET_YES == log)) 537 if ((GNUNET_YES == logging) && (GNUNET_YES == log))
1003 collect_log_now(); 538 collect_log_now();
539 */
1004 GNUNET_free(peer_id); 540 GNUNET_free(peer_id);
1005} 541}
1006 542
1007static void *
1008ats_perf_connect_adapter (void *cls,
1009 const struct GNUNET_CONFIGURATION_Handle *cfg)
1010{
1011 struct BenchmarkPeer *me = cls;
1012
1013 me->ats_perf_handle = GNUNET_ATS_performance_init (cfg,
1014 &ats_performance_info_cb, me);
1015 if (NULL == me->ats_perf_handle)
1016 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1017 "Failed to create ATS performance handle \n");
1018 return me->ats_perf_handle;
1019}
1020
1021static void
1022ats_perf_disconnect_adapter (void *cls, void *op_result)
1023{
1024 struct BenchmarkPeer *me = cls;
1025
1026 GNUNET_ATS_performance_done (me->ats_perf_handle);
1027 me->ats_perf_handle = NULL;
1028}
1029
1030static void
1031ats_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
1032 void *ca_result, const char *emsg)
1033{
1034 static int op_done = 0;
1035
1036 if ((NULL != emsg) || (NULL == ca_result))
1037 {
1038 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
1039 GNUNET_break(0);
1040 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
1041 GNUNET_SCHEDULER_cancel (shutdown_task);
1042 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
1043 return;
1044 }
1045 op_done++;
1046 if (op_done == (num_masters + num_slaves))
1047 {
1048 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all ATS services\n");
1049 state.connected_ATS_service = GNUNET_YES;
1050 GNUNET_SCHEDULER_add_now (&do_comm_connect, NULL );
1051 }
1052}
1053
1054static void
1055do_connect_ats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1056{
1057 int c_m;
1058 int c_s;
1059
1060 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all ATS services\n");
1061 for (c_m = 0; c_m < num_masters; c_m++)
1062 {
1063 mps[c_m].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer,
1064 "ats", ats_connect_completion_cb, NULL, &ats_perf_connect_adapter,
1065 &ats_perf_disconnect_adapter, &mps[c_m]);
1066
1067 }
1068
1069 for (c_s = 0; c_s < num_slaves; c_s++)
1070 {
1071 sps[c_s].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer,
1072 "ats", ats_connect_completion_cb, NULL, &ats_perf_connect_adapter,
1073 &ats_perf_disconnect_adapter, &sps[c_s]);
1074 }
1075
1076}
1077
1078static void
1079peerinformation_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op,
1080 const struct GNUNET_TESTBED_PeerInformation*pinfo, const char *emsg)
1081{
1082 struct BenchmarkPeer *p = cb_cls;
1083 static int done = 0;
1084
1085 GNUNET_assert(pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY);
1086 543
1087 p->id = *pinfo->result.id;
1088 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%s [%u] has peer id `%s'\n",
1089 (p->master == GNUNET_YES) ? "Master" : "Slave", p->no,
1090 GNUNET_i2s (&p->id));
1091 544
1092 GNUNET_TESTBED_operation_done (op);
1093 p->peer_id_op = NULL;
1094 done++;
1095 545
1096 if (done == num_slaves + num_masters)
1097 {
1098 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1099 "Retrieved all peer ID, connect to ATS\n");
1100 GNUNET_SCHEDULER_add_now (&do_connect_ats, NULL );
1101 }
1102}
1103
1104/**
1105 * Signature of a main function for a testcase.
1106 *
1107 * @param cls closure
1108 * @param num_peers number of peers in 'peers'
1109 * @param peers_ handle to peers run in the testbed
1110 * @param links_succeeded the number of overlay link connection attempts that
1111 * succeeded
1112 * @param links_failed the number of overlay link connection attempts that
1113 * failed
1114 */
1115static void
1116main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h,
1117 unsigned int num_peers,
1118 struct GNUNET_TESTBED_Peer **peers_,
1119 unsigned int links_succeeded,
1120 unsigned int links_failed)
1121{
1122 int c_m;
1123 int c_s;
1124 GNUNET_assert(NULL == cls);
1125 GNUNET_assert(num_masters + num_slaves == num_peers);
1126 GNUNET_assert(NULL != peers_);
1127
1128 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1129 _("Benchmarking solver `%s' on preference `%s' with %u master and %u slave peers\n"),
1130 solver, pref_str, num_masters, num_slaves);
1131
1132 shutdown_task = GNUNET_SCHEDULER_add_delayed (
1133 GNUNET_TIME_relative_multiply (TEST_TIMEOUT, num_masters + num_slaves),
1134 &do_shutdown, NULL );
1135
1136 /* Setup master peers */
1137 for (c_m = 0; c_m < num_masters; c_m++)
1138 {
1139 GNUNET_assert(NULL != peers_[c_m]);
1140 mps[c_m].peer = peers_[c_m];
1141 mps[c_m].no = c_m;
1142 mps[c_m].master = GNUNET_YES;
1143 mps[c_m].pref_partner = &sps[c_m];
1144 mps[c_m].pref_value = TEST_ATS_PREFRENCE_START;
1145 mps[c_m].partners =
1146 GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPartner));
1147 mps[c_m].num_partners = num_slaves;
1148 /* Initialize partners */
1149 for (c_s = 0; c_s < num_slaves; c_s++)
1150 {
1151 mps[c_m].partners[c_s].me = &mps[c_m];
1152 mps[c_m].partners[c_s].dest = &sps[c_s];
1153 }
1154 mps[c_m].peer_id_op = GNUNET_TESTBED_peer_get_information (mps[c_m].peer,
1155 GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &mps[c_m]);
1156 }
1157
1158 /* Setup slave peers */
1159 for (c_s = 0; c_s < num_slaves; c_s++)
1160 {
1161 GNUNET_assert(NULL != peers_[c_s + num_masters]);
1162 sps[c_s].peer = peers_[c_s + num_masters];
1163 sps[c_s].no = c_s + num_masters;
1164 sps[c_s].master = GNUNET_NO;
1165 sps[c_s].partners =
1166 GNUNET_malloc (num_masters * sizeof (struct BenchmarkPartner));
1167 sps[c_s].num_partners = num_masters;
1168 /* Initialize partners */
1169 for (c_m = 0; c_m < num_masters; c_m++)
1170 {
1171 sps[c_s].partners[c_m].me = &sps[c_s];
1172 sps[c_s].partners[c_m].dest = &mps[c_m];
1173 }
1174 sps[c_s].peer_id_op = GNUNET_TESTBED_peer_get_information (sps[c_s].peer,
1175 GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &sps[c_s]);
1176 }
1177}
1178 546
1179int 547int
1180main (int argc, char *argv[]) 548main (int argc, char *argv[])
@@ -1353,32 +721,14 @@ main (int argc, char *argv[])
1353 return GNUNET_SYSERR; 721 return GNUNET_SYSERR;
1354 } 722 }
1355 723
1356 state.connected_ATS_service = GNUNET_NO; 724 static struct GNUNET_CORE_MessageHandler handlers[] = {
1357 state.connected_COMM_service = GNUNET_NO; 725 {&comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 },
1358 state.connected_PEERS = GNUNET_NO; 726 {&comm_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 },
1359 state.benchmarking = GNUNET_NO; 727 { NULL, 0, 0 } };
1360 state.connected_PEERS = GNUNET_NO; 728
1361 729 GNUNET_ATS_TEST_create_topology ("perf-ats", conf_name,
1362 mps = GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer)); 730 num_slaves, num_masters, test_core,
1363 sps = GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer)); 731 &do_benchmark, NULL, handlers, &transport_recv_cb);
1364
1365 /* Start topology */
1366 uint64_t event_mask;
1367 event_mask = 0;
1368 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
1369 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
1370 (void) GNUNET_TESTBED_test_run ("perf-ats", conf_name,
1371 num_slaves + num_masters, event_mask, &controller_event_cb, NULL,
1372 &main_run, NULL );
1373
1374 GNUNET_free(solver);
1375 GNUNET_free(pref_str);
1376 GNUNET_free(conf_name);
1377 GNUNET_free(test_name);
1378 GNUNET_free(testname);
1379 GNUNET_free (comm_name);
1380 GNUNET_free(mps);
1381 GNUNET_free(sps);
1382 732
1383 return result; 733 return result;
1384} 734}