2 This file is part of GNUnet.
3 (C) 2010-2013 Christian Grothoff (and other contributing authors)
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.
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.
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.
21 * @file ats/perf_ats.c
22 * @brief ats benchmark: start peers and modify preferences, monitor change over time
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_util_lib.h"
28 #include "gnunet_testbed_service.h"
29 #include "gnunet_ats_service.h"
30 #include "gnunet_core_service.h"
33 #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
34 #define BENCHMARK_DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
35 #define TESTNAME_PREFIX "perf_ats_"
36 #define DEFAULT_SLAVES_NUM 3
37 #define DEFAULT_MASTERS_NUM 1
39 #define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
40 #define TEST_ATS_PREFRENCE_START 1.0
41 #define TEST_ATS_PREFRENCE_DELTA 1.0
43 #define TEST_MESSAGE_TYPE_PING 12345
44 #define TEST_MESSAGE_TYPE_PONG 12346
45 #define TEST_MESSAGE_SIZE 1000
46 #define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
49 * Connect peers with testbed
51 struct TestbedConnectOperation
54 * The benchmarking master initiating this connection
56 struct BenchmarkPeer *master;
59 * The benchmarking slave to connect to
61 struct BenchmarkPeer *slave;
64 * Testbed operation to connect peers
66 struct GNUNET_TESTBED_Operation *connect_op;
70 * Overall state of the performance benchmark
74 /* Are we connected to ATS service of all peers: GNUNET_YES/NO */
75 int connected_ATS_service;
77 /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
78 int connected_COMM_service;
80 /* Are we connected to all peers: GNUNET_YES/NO */
83 /* Are we connected to all slave peers on CORE level: GNUNET_YES/NO */
86 /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
93 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
98 static GNUNET_SCHEDULER_TaskIdentifier progress_task;
106 * Test result logging
110 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
112 static int test_core;
122 static char *testname;
127 static char *pref_str;
130 * ATS preference value
135 * Number master peers
137 static int num_masters;
140 * Array of master peers
142 struct BenchmarkPeer *mps;
147 static int num_slaves;
149 * Array of slave peers
151 struct BenchmarkPeer *sps;
156 static struct BenchmarkState state;
163 unsigned int duration;
164 struct BenchmarkPeer *mp;
166 duration = (BENCHMARK_DURATION.rel_value_us / (1000 * 1000));
167 for (c_m = 0; c_m < num_masters; c_m++)
171 _("Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"),
172 mp->no, mp->total_bytes_sent / 1024, duration,
173 (mp->total_bytes_sent / 1024) / duration,
174 mp->total_bytes_received / 1024, duration,
175 (mp->total_bytes_received / 1024) / duration);
177 for (c_s = 0; c_s < num_slaves; c_s++)
180 "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f \%), received %u KiB/s (%.2f \%)\n",
181 (mp->pref_partner == mp->partners[c_s].dest) ? '*' : ' ',
182 mp->no, mp->partners[c_s].dest->no,
183 (mp->partners[c_s].bytes_sent / 1024) / duration,
184 ((double) mp->partners[c_s].bytes_sent * 100) / mp->total_bytes_sent,
185 (mp->partners[c_s].bytes_received / 1024) / duration,
186 ((double) mp->partners[c_s].bytes_received * 100) / mp->total_bytes_received );
195 * @param tc the task context
198 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
204 if (GNUNET_YES == logging)
207 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
208 if (GNUNET_SCHEDULER_NO_TASK != progress_task)
210 fprintf (stderr, "0\n");
211 GNUNET_SCHEDULER_cancel (progress_task);
213 progress_task = GNUNET_SCHEDULER_NO_TASK;
216 state.benchmarking = GNUNET_NO;
217 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n"));
219 for (c_m = 0; c_m < num_masters; c_m++)
221 if (NULL != mps[c_m].peer_id_op)
223 GNUNET_TESTBED_operation_done (mps[c_m].peer_id_op);
224 mps[c_m].peer_id_op = NULL;
227 if (GNUNET_SCHEDULER_NO_TASK != mps[c_m].ats_task)
228 GNUNET_SCHEDULER_cancel (mps[c_m].ats_task);
229 mps[c_m].ats_task = GNUNET_SCHEDULER_NO_TASK;
231 for (c_op = 0; c_op < num_slaves; c_op++)
234 if (NULL != mps[c_m].partners[c_op].cth)
236 GNUNET_CORE_notify_transmit_ready_cancel (mps[c_m].partners[c_op].cth);
237 mps[c_m].partners[c_op].cth = NULL;
239 if (NULL != mps[c_m].partners[c_op].tth)
241 GNUNET_TRANSPORT_notify_transmit_ready_cancel (mps[c_m].partners[c_op].tth);
242 mps[c_m].partners[c_op].tth = NULL;
246 if (NULL != mps[c_m].core_connect_ops[c_op].connect_op)
248 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
249 _("Failed to connect peer 0 and %u\n"), c_op);
250 GNUNET_TESTBED_operation_done (
251 mps[c_m].core_connect_ops[c_op].connect_op);
252 mps[c_m].core_connect_ops[c_op].connect_op = NULL;
257 if (NULL != mps[c_m].ats_perf_op)
259 GNUNET_TESTBED_operation_done (mps[c_m].ats_perf_op);
260 mps[c_m].ats_perf_op = NULL;
263 if (NULL != mps[c_m].comm_op)
265 GNUNET_TESTBED_operation_done (mps[c_m].comm_op);
266 mps[c_m].comm_op = NULL;
268 GNUNET_free(mps[c_m].core_connect_ops);
269 GNUNET_free(mps[c_m].partners);
270 mps[c_m].partners = NULL;
273 for (c_s = 0; c_s < num_slaves; c_s++)
275 if (NULL != sps[c_s].peer_id_op)
277 GNUNET_TESTBED_operation_done (sps[c_s].peer_id_op);
278 sps[c_s].peer_id_op = NULL;
281 for (c_op = 0; c_op < num_slaves; c_op++)
283 if (NULL != sps[c_s].partners[c_op].cth)
285 GNUNET_CORE_notify_transmit_ready_cancel (sps[c_s].partners[c_op].cth);
286 sps[c_s].partners[c_op].cth = NULL;
289 if (NULL != sps[c_s].partners[c_op].tth)
291 GNUNET_TRANSPORT_notify_transmit_ready_cancel (sps[c_s].partners[c_op].tth);
292 sps[c_s].partners[c_op].tth = NULL;
296 if (NULL != sps[c_s].ats_perf_op)
298 GNUNET_TESTBED_operation_done (sps[c_s].ats_perf_op);
299 sps[c_s].ats_perf_op = NULL;
301 if (NULL != sps[c_s].comm_op)
303 GNUNET_TESTBED_operation_done (sps[c_s].comm_op);
304 sps[c_s].comm_op = NULL;
307 GNUNET_free(sps[c_s].partners);
308 sps[c_s].partners = NULL;
311 GNUNET_SCHEDULER_shutdown ();
314 static struct BenchmarkPeer *
315 find_peer (const struct GNUNET_PeerIdentity * peer)
319 for (c_p = 0; c_p < num_masters; c_p++)
321 if (0 == memcmp (&mps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity)))
325 for (c_p = 0; c_p < num_slaves; c_p++)
327 if (0 == memcmp (&sps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity)))
334 * Controller event callback
337 * @param event the controller event
340 controller_event_cb (void *cls,
341 const struct GNUNET_TESTBED_EventInformation *event)
343 //struct BenchmarkPeer *p = cls;
346 case GNUNET_TESTBED_ET_CONNECT:
348 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
353 GNUNET_SCHEDULER_cancel (shutdown_task);
354 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL );
359 comm_send_ready (void *cls, size_t size, void *buf)
361 static char msgbuf[TEST_MESSAGE_SIZE];
362 struct BenchmarkPartner *partner = cls;
363 struct GNUNET_MessageHeader *msg;
365 if (GNUNET_YES == test_core)
370 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Master [%u]: Sending PING to [%u]\n",
371 partner->me->no, partner->dest->no);
373 partner->messages_sent++;
374 partner->bytes_sent += TEST_MESSAGE_SIZE;
375 partner->me->total_messages_sent++;
376 partner->me->total_bytes_sent += TEST_MESSAGE_SIZE;
378 msg = (struct GNUNET_MessageHeader *) &msgbuf;
379 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
380 msg->type = htons (TEST_MESSAGE_TYPE_PING);
381 msg->size = htons (TEST_MESSAGE_SIZE);
382 memcpy (buf, msg, TEST_MESSAGE_SIZE);
383 return TEST_MESSAGE_SIZE;
390 progress_task = GNUNET_SCHEDULER_NO_TASK;
392 fprintf (stderr, "%llu..",
393 (long long unsigned) BENCHMARK_DURATION.rel_value_us / (1000 * 1000) - calls);
396 progress_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
397 &print_progress, NULL );
401 ats_pref_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
403 struct BenchmarkPeer *me = cls;
405 me->ats_task = GNUNET_SCHEDULER_NO_TASK;
407 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, " Master [%u] set preference for slave [%u] to %f\n",
408 me->no, me->pref_partner->no, me->pref_value);
409 GNUNET_ATS_performance_change_preference (me->ats_perf_handle,
410 &me->pref_partner->id,
411 pref_val, me->pref_value, GNUNET_ATS_PREFERENCE_END);
412 me->pref_value += TEST_ATS_PREFRENCE_DELTA;
413 me->ats_task = GNUNET_SCHEDULER_add_delayed (TEST_ATS_PREFRENCE_FREQUENCY,
414 &ats_pref_task, cls);
423 if ((state.connected_ATS_service == GNUNET_NO)
424 || (state.connected_COMM_service == GNUNET_NO)
425 || (state.connected_PEERS == GNUNET_NO)
426 || (state.connected_CORE == GNUNET_NO))
429 state.benchmarking = GNUNET_YES;
430 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking start\n"));
432 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
433 GNUNET_SCHEDULER_cancel (shutdown_task);
434 shutdown_task = GNUNET_SCHEDULER_add_delayed (BENCHMARK_DURATION,
435 &do_shutdown, NULL );
437 progress_task = GNUNET_SCHEDULER_add_now (&print_progress, NULL );
439 /* Start sending test messages */
440 for (c_m = 0; c_m < num_masters; c_m++)
442 for (c_s = 0; c_s < num_slaves; c_s++)
444 if (GNUNET_YES == test_core)
445 mps[c_m].partners[c_s].cth = GNUNET_CORE_notify_transmit_ready (
446 mps[c_m].ch, GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, &sps[c_s].id,
447 TEST_MESSAGE_SIZE, &comm_send_ready, &mps[c_m].partners[c_s]);
450 mps[c_m].partners[c_s].tth = GNUNET_TRANSPORT_notify_transmit_ready (
451 mps[c_m].th, &sps[c_s].id, TEST_MESSAGE_SIZE, 0,GNUNET_TIME_UNIT_MINUTES,
452 &comm_send_ready, &mps[c_m].partners[c_s]);
455 if (pref_val != GNUNET_ATS_PREFERENCE_END)
456 mps[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task, &mps[c_m]);
458 if (GNUNET_YES == logging)
459 perf_logging_start (testname, mps, num_masters);
463 connect_completion_callback (void *cls, struct GNUNET_TESTBED_Operation *op,
466 struct TestbedConnectOperation *cop = cls;
471 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
472 _("Connected master [%u] with slave [%u]\n"), cop->master->no,
477 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
478 _("Failed to connect master peer [%u] with slave [%u]\n"),
479 cop->master->no, cop->slave->no);
481 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
482 GNUNET_SCHEDULER_cancel (shutdown_task);
483 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
485 GNUNET_TESTBED_operation_done (op);
487 for (c = 0; c < num_slaves; c++)
489 if (cop == &cop->master->core_connect_ops[c])
490 cop->master->core_connect_ops[c].connect_op = NULL;
492 if (ops == num_masters * num_slaves)
494 state.connected_PEERS = GNUNET_YES;
495 GNUNET_SCHEDULER_add_now (&do_benchmark, NULL );
500 do_connect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
504 struct BenchmarkPeer *p;
506 if ((state.connected_ATS_service == GNUNET_NO)
507 || (state.connected_COMM_service == GNUNET_NO))
510 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Connecting peers on CORE level\n"));
512 for (c_m = 0; c_m < num_masters; c_m++)
515 p->core_connect_ops = GNUNET_malloc (num_slaves *
516 sizeof (struct TestbedConnectOperation));
518 for (c_s = 0; c_s < num_slaves; c_s++)
520 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
521 _("Connecting master [%u] with slave [%u]\n"), p->no, sps[c_s].no);
522 p->core_connect_ops[c_s].master = p;
523 p->core_connect_ops[c_s].slave = &sps[c_s];
524 p->core_connect_ops[c_s].connect_op = GNUNET_TESTBED_overlay_connect (
525 NULL, &connect_completion_callback, &p->core_connect_ops[c_s],
526 sps[c_s].peer, p->peer);
527 if (NULL == p->core_connect_ops[c_s].connect_op)
529 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
530 _("Could not connect master [%u] and slave [%u]\n"), p->no,
533 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
534 GNUNET_SCHEDULER_cancel (shutdown_task);
535 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
543 * Method called whenever a given peer connects.
546 * @param peer peer identity this notification is about
549 comm_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
551 struct BenchmarkPeer *me = cls;
552 struct BenchmarkPeer *remote;
557 remote = find_peer (peer);
564 id = GNUNET_strdup (GNUNET_i2s (&me->id));
565 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s [%u] `%s' connected to %s [%u] %s\n",
566 (me->master == GNUNET_YES) ? "Master": "Slave", me->no, id,
567 (remote->master == GNUNET_YES) ? "Master": "Slave", remote->no,
570 me->core_connections++;
571 if ((GNUNET_YES == me->master) && (GNUNET_NO == remote->master)
572 && (GNUNET_NO == state.connected_CORE))
574 me->core_slave_connections++;
576 if (me->core_slave_connections == num_slaves)
578 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Master [%u] connected all slaves\n",
581 completed = GNUNET_YES;
582 for (c = 0; c < num_masters; c++)
584 if (mps[c].core_slave_connections != num_slaves)
585 completed = GNUNET_NO;
587 if (GNUNET_YES == completed)
589 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
590 "All master peers connected all slave peers\n", id,
592 state.connected_CORE = GNUNET_YES;
593 GNUNET_SCHEDULER_add_now (&do_benchmark, NULL );
600 comm_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
602 struct BenchmarkPeer *me = cls;
603 struct BenchmarkPeer *remote;
606 remote = find_peer (peer);
613 id = GNUNET_strdup (GNUNET_i2s (&me->id));
614 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s disconnected from %s \n", id,
616 GNUNET_assert(me->core_connections > 0);
617 me->core_connections--;
619 if ((GNUNET_YES == state.benchmarking)
620 && ((GNUNET_YES == me->master) || (GNUNET_YES == remote->master)))
622 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
623 "%s disconnected from %s while benchmarking \n", id, GNUNET_i2s (peer));
629 comm_send_pong_ready (void *cls, size_t size, void *buf)
631 static char msgbuf[TEST_MESSAGE_SIZE];
632 struct BenchmarkPartner *p = cls;
633 struct GNUNET_MessageHeader *msg;
635 if (GNUNET_YES == test_core)
641 p->bytes_sent += TEST_MESSAGE_SIZE;
642 p->me->total_messages_sent++;
643 p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
645 msg = (struct GNUNET_MessageHeader *) &msgbuf;
646 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
647 msg->type = htons (TEST_MESSAGE_TYPE_PONG);
648 msg->size = htons (TEST_MESSAGE_SIZE);
649 memcpy (buf, msg, TEST_MESSAGE_SIZE);
651 return TEST_MESSAGE_SIZE;
655 comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
656 const struct GNUNET_MessageHeader *message)
659 struct BenchmarkPeer *me = cls;
660 struct BenchmarkPartner *p = NULL;
661 for (c_m = 0; c_m < num_masters; c_m++)
664 == memcmp (other, &me->partners[c_m].dest->id,
665 sizeof(struct GNUNET_PeerIdentity)))
667 p = &me->partners[c_m];
674 return GNUNET_SYSERR;
677 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
678 "Slave [%u]: Received PING from [%u], sending PONG\n", me->no,
681 p->messages_received++;
682 p->bytes_received += TEST_MESSAGE_SIZE;
683 p->me->total_messages_received++;
684 p->me->total_bytes_received += TEST_MESSAGE_SIZE;
686 if (GNUNET_YES == test_core)
688 GNUNET_assert (NULL == p->cth);
689 p->cth = GNUNET_CORE_notify_transmit_ready (me->ch, GNUNET_NO, 0,
690 GNUNET_TIME_UNIT_MINUTES, &p->dest->id, TEST_MESSAGE_SIZE,
691 &comm_send_pong_ready, p);
695 GNUNET_assert (NULL == p->tth);
696 p->tth = GNUNET_TRANSPORT_notify_transmit_ready (me->th, &p->dest->id,
697 TEST_MESSAGE_SIZE, 0, GNUNET_TIME_UNIT_MINUTES, &comm_send_pong_ready,
704 comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
705 const struct GNUNET_MessageHeader *message)
708 struct BenchmarkPeer *me = cls;
709 struct BenchmarkPartner *p = NULL;
711 for (c_s = 0; c_s < num_slaves; c_s++)
714 == memcmp (other, &me->partners[c_s].dest->id,
715 sizeof(struct GNUNET_PeerIdentity)))
717 p = &me->partners[c_s];
724 return GNUNET_SYSERR;
727 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
728 "Master [%u]: Received PONG from [%u], next message\n", me->no,
731 p->messages_received++;
732 p->bytes_received += TEST_MESSAGE_SIZE;
733 p->me->total_messages_received++;
734 p->me->total_bytes_received += TEST_MESSAGE_SIZE;
736 if (GNUNET_YES == test_core)
738 GNUNET_assert (NULL == p->cth);
739 p->cth = GNUNET_CORE_notify_transmit_ready (me->ch, GNUNET_NO, 0,
740 GNUNET_TIME_UNIT_MINUTES, &p->dest->id, TEST_MESSAGE_SIZE,
741 &comm_send_ready, p);
745 GNUNET_assert (NULL == p->tth);
746 p->tth = GNUNET_TRANSPORT_notify_transmit_ready (
747 me->th, &p->dest->id, TEST_MESSAGE_SIZE, 0,GNUNET_TIME_UNIT_MINUTES,
748 &comm_send_ready, p);
755 core_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
757 struct BenchmarkPeer *me = cls;
759 static const struct GNUNET_CORE_MessageHandler handlers[] = { {
760 &comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 }, { &comm_handle_pong,
761 TEST_MESSAGE_TYPE_PONG, 0 }, { NULL, 0, 0 } };
763 me->ch = GNUNET_CORE_connect (cfg, me, NULL, comm_connect_cb,
764 comm_disconnect_cb, NULL, GNUNET_NO, NULL, GNUNET_NO, handlers);
766 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create core connection \n");
771 core_disconnect_adapter (void *cls, void *op_result)
773 struct BenchmarkPeer *me = cls;
775 GNUNET_CORE_disconnect (me->ch);
780 comm_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
781 void *ca_result, const char *emsg)
783 static int comm_done = 0;
784 if ((NULL != emsg) || (NULL == ca_result))
786 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
788 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
789 GNUNET_SCHEDULER_cancel (shutdown_task);
790 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
795 if (comm_done == num_slaves + num_masters)
797 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all %s services\n",
798 (GNUNET_YES == test_core) ? "CORE" : "TRANSPORT");
799 state.connected_COMM_service = GNUNET_YES;
800 GNUNET_SCHEDULER_add_now (&do_connect_peers, NULL );
805 transport_recv_cb (void *cls,
806 const struct GNUNET_PeerIdentity * peer,
807 const struct GNUNET_MessageHeader * message)
809 if (TEST_MESSAGE_SIZE != ntohs (message->size) ||
810 (TEST_MESSAGE_TYPE_PING != ntohs (message->type) &&
811 TEST_MESSAGE_TYPE_PONG != ntohs (message->type)))
815 if (TEST_MESSAGE_TYPE_PING == ntohs (message->type))
816 comm_handle_ping (cls, peer, message);
818 if (TEST_MESSAGE_TYPE_PONG == ntohs (message->type))
819 comm_handle_pong (cls, peer, message);
824 transport_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
826 struct BenchmarkPeer *me = cls;
828 me->th = GNUNET_TRANSPORT_connect (cfg, &me->id, me, &transport_recv_cb,
829 &comm_connect_cb, &comm_disconnect_cb);
831 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create transport connection \n");
836 transport_disconnect_adapter (void *cls, void *op_result)
838 struct BenchmarkPeer *me = cls;
840 GNUNET_TRANSPORT_disconnect (me->th);
845 do_comm_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
849 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all %s services\n",
850 (GNUNET_YES == test_core) ? "CORE" : "TRANSPORT");
851 for (c_m = 0; c_m < num_masters; c_m++)
853 if (GNUNET_YES == test_core)
854 mps[c_m].comm_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer,
855 "core", &comm_connect_completion_cb, NULL, &core_connect_adapter,
856 &core_disconnect_adapter, &mps[c_m]);
859 mps[c_m].comm_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer,
860 "transport", &comm_connect_completion_cb, NULL, &transport_connect_adapter,
861 &transport_disconnect_adapter, &mps[c_m]);
865 for (c_s = 0; c_s < num_slaves; c_s++)
867 if (GNUNET_YES == test_core)
868 sps[c_s].comm_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer,
869 "core", &comm_connect_completion_cb, NULL, &core_connect_adapter,
870 &core_disconnect_adapter, &sps[c_s]);
873 sps[c_s].comm_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer,
874 "transport", &comm_connect_completion_cb, NULL, &transport_connect_adapter,
875 &transport_disconnect_adapter, &sps[c_s]);
881 ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
882 int address_active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
883 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
884 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
886 struct BenchmarkPeer *me = cls;
890 peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
891 for (c_a = 0; c_a < ats_count; c_a++)
893 /*GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("%c %03u: %s %s %u\n"),
894 (GNUNET_YES == p->master) ? 'M' : 'S',
896 GNUNET_i2s (&address->peer),
897 GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)),
898 ntohl(ats[c_a].value));*/
901 if ((GNUNET_YES == me->master)
902 && (0 == memcmp (&address->peer, &me->destination->id,
903 sizeof(struct GNUNET_PeerIdentity))))
905 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Bandwidth for master %u: %lu %lu\n",
906 me->no, (long unsigned int ) ntohl (bandwidth_in.value__),
907 (long unsigned int ) ntohl (bandwidth_in.value__));
910 store_information (&bp->id, address, address_active, bandwidth_in,
911 bandwidth_out, ats, ats_count);
913 GNUNET_free(peer_id);
917 ats_perf_connect_adapter (void *cls,
918 const struct GNUNET_CONFIGURATION_Handle *cfg)
920 struct BenchmarkPeer *me = cls;
922 me->ats_perf_handle = GNUNET_ATS_performance_init (cfg,
923 &ats_performance_info_cb, me);
924 if (NULL == me->ats_perf_handle)
925 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
926 "Failed to create ATS performance handle \n");
927 return me->ats_perf_handle;
931 ats_perf_disconnect_adapter (void *cls, void *op_result)
933 struct BenchmarkPeer *me = cls;
935 GNUNET_ATS_performance_done (me->ats_perf_handle);
936 me->ats_perf_handle = NULL;
940 ats_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
941 void *ca_result, const char *emsg)
943 static int op_done = 0;
945 if ((NULL != emsg) || (NULL == ca_result))
947 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
949 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
950 GNUNET_SCHEDULER_cancel (shutdown_task);
951 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
955 if (op_done == (num_masters + num_slaves))
957 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all ATS services\n");
958 state.connected_ATS_service = GNUNET_YES;
959 GNUNET_SCHEDULER_add_now (&do_comm_connect, NULL );
964 do_connect_ats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
969 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all ATS services\n");
970 for (c_m = 0; c_m < num_masters; c_m++)
972 mps[c_m].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer,
973 "ats", ats_connect_completion_cb, NULL, &ats_perf_connect_adapter,
974 &ats_perf_disconnect_adapter, &mps[c_m]);
978 for (c_s = 0; c_s < num_slaves; c_s++)
980 sps[c_s].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer,
981 "ats", ats_connect_completion_cb, NULL, &ats_perf_connect_adapter,
982 &ats_perf_disconnect_adapter, &sps[c_s]);
988 peerinformation_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op,
989 const struct GNUNET_TESTBED_PeerInformation*pinfo, const char *emsg)
991 struct BenchmarkPeer *p = cb_cls;
994 GNUNET_assert(pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY);
996 p->id = *pinfo->result.id;
997 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%s [%u] has peer id `%s'\n",
998 (p->master == GNUNET_YES) ? "Master" : "Slave", p->no,
999 GNUNET_i2s (&p->id));
1001 GNUNET_TESTBED_operation_done (op);
1002 p->peer_id_op = NULL;
1005 if (done == num_slaves + num_masters)
1007 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1008 "Retrieved all peer ID, connect to ATS\n");
1009 GNUNET_SCHEDULER_add_now (&do_connect_ats, NULL );
1014 * Signature of a main function for a testcase.
1016 * @param cls closure
1017 * @param num_peers number of peers in 'peers'
1018 * @param peers_ handle to peers run in the testbed
1019 * @param links_succeeded the number of overlay link connection attempts that
1021 * @param links_failed the number of overlay link connection attempts that
1025 main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers,
1026 struct GNUNET_TESTBED_Peer **peers_, unsigned int links_succeeded,
1027 unsigned int links_failed)
1031 GNUNET_assert(NULL == cls);
1032 GNUNET_assert(num_masters + num_slaves == num_peers);
1033 GNUNET_assert(NULL != peers_);
1035 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1036 _("Benchmarking solver `%s' on preference `%s' with %u master and %u slave peers\n"),
1037 solver, pref_str, num_masters, num_slaves);
1039 shutdown_task = GNUNET_SCHEDULER_add_delayed (
1040 GNUNET_TIME_relative_multiply (TEST_TIMEOUT, num_masters + num_slaves),
1041 &do_shutdown, NULL );
1043 /* Setup master peers */
1044 for (c_m = 0; c_m < num_masters; c_m++)
1046 GNUNET_assert(NULL != peers_[c_m]);
1047 mps[c_m].peer = peers_[c_m];
1049 mps[c_m].master = GNUNET_YES;
1050 mps[c_m].pref_partner = &sps[c_m];
1051 mps[c_m].pref_value = TEST_ATS_PREFRENCE_START;
1053 GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer));
1054 mps[c_m].num_partners = num_slaves;
1055 /* Initialize partners */
1056 for (c_s = 0; c_s < num_slaves; c_s++)
1058 mps[c_m].partners[c_s].me = &mps[c_m];
1059 mps[c_m].partners[c_s].dest = &sps[c_s];
1061 mps[c_m].peer_id_op = GNUNET_TESTBED_peer_get_information (mps[c_m].peer,
1062 GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &mps[c_m]);
1065 /* Setup slave peers */
1066 for (c_s = 0; c_s < num_slaves; c_s++)
1068 GNUNET_assert(NULL != peers_[c_s + num_masters]);
1069 sps[c_s].peer = peers_[c_s + num_masters];
1070 sps[c_s].no = c_s + num_masters;
1071 sps[c_s].master = GNUNET_NO;
1073 GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer));
1074 sps[c_s].num_partners = num_masters;
1075 /* Initialize partners */
1076 for (c_m = 0; c_m < num_masters; c_m++)
1078 sps[c_s].partners[c_m].me = &sps[c_s];
1079 sps[c_s].partners[c_m].dest = &mps[c_m];
1081 sps[c_s].peer_id_op = GNUNET_TESTBED_peer_get_information (sps[c_s].peer,
1082 GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &sps[c_s]);
1087 main (int argc, char *argv[])
1095 char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
1100 /* figure out testname */
1101 tmp = strstr (argv[0], TESTNAME_PREFIX);
1104 fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
1105 return GNUNET_SYSERR;
1107 tmp += strlen (TESTNAME_PREFIX);
1108 solver = GNUNET_strdup (tmp);
1109 if (NULL != (dotexe = strstr (solver, ".exe")) && dotexe[4] == '\0')
1111 tmp_sep = strchr (solver, '_');
1112 if (NULL == tmp_sep)
1114 fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
1115 GNUNET_free(solver);
1116 return GNUNET_SYSERR;
1119 comm_name = GNUNET_strdup (&tmp_sep[1]);
1120 tmp_sep = strchr (comm_name, '_');
1121 if (NULL == tmp_sep)
1123 fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
1124 GNUNET_free(solver);
1125 return GNUNET_SYSERR;
1128 for (c = 0; c <= strlen (comm_name); c++)
1129 comm_name[c] = toupper (comm_name[c]);
1130 if (0 == strcmp (comm_name, "CORE"))
1131 test_core = GNUNET_YES;
1132 else if (0 == strcmp (comm_name, "TRANSPORT"))
1133 test_core = GNUNET_NO;
1136 GNUNET_free (comm_name);
1137 GNUNET_free (solver);
1138 return GNUNET_SYSERR;
1141 pref_str = GNUNET_strdup(tmp_sep + 1);
1143 GNUNET_asprintf (&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver,
1145 GNUNET_asprintf (&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, pref_str);
1147 for (c = 0; c <= strlen (pref_str); c++)
1148 pref_str[c] = toupper (pref_str[c]);
1151 if (0 != strcmp (pref_str, "NONE"))
1153 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
1155 if (0 == strcmp (pref_str, prefs[c]))
1164 /* abuse terminator to indicate no pref */
1165 pref_val = GNUNET_ATS_PREFERENCE_END;
1169 fprintf (stderr, "Unknown preference: `%s'\n", pref_str);
1170 GNUNET_free(solver);
1171 GNUNET_free(pref_str);
1172 GNUNET_free (comm_name);
1176 for (c = 0; c < (argc - 1); c++)
1178 if (0 == strcmp (argv[c], "-s"))
1183 if ((0L != (num_slaves = strtol (argv[c + 1], NULL, 10)))
1184 && (num_slaves >= 1))
1185 fprintf (stderr, "Starting %u slave peers\n", num_slaves);
1187 num_slaves = DEFAULT_SLAVES_NUM;
1190 num_slaves = DEFAULT_SLAVES_NUM;
1192 for (c = 0; c < (argc - 1); c++)
1194 if (0 == strcmp (argv[c], "-m"))
1199 if ((0L != (num_masters = strtol (argv[c + 1], NULL, 10)))
1200 && (num_masters >= 2))
1201 fprintf (stderr, "Starting %u master peers\n", num_masters);
1203 num_masters = DEFAULT_MASTERS_NUM;
1206 num_masters = DEFAULT_MASTERS_NUM;
1208 logging = GNUNET_NO;
1209 for (c = 0; c < argc; c++)
1211 if (0 == strcmp (argv[c], "-l"))
1212 logging = GNUNET_YES;
1215 GNUNET_asprintf (&testname, "%s_%s_%s",solver, comm_name, pref_str);
1217 if (num_slaves < num_masters)
1219 fprintf (stderr, "Number of master peers is lower than slaves! exit...\n");
1220 GNUNET_free(test_name);
1221 GNUNET_free(solver);
1222 GNUNET_free(pref_str);
1223 GNUNET_free (comm_name);
1224 return GNUNET_SYSERR;
1227 state.connected_ATS_service = GNUNET_NO;
1228 state.connected_COMM_service = GNUNET_NO;
1229 state.connected_PEERS = GNUNET_NO;
1230 state.benchmarking = GNUNET_NO;
1231 state.connected_PEERS = GNUNET_NO;
1233 mps = GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer));
1234 sps = GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer));
1236 /* Start topology */
1237 uint64_t event_mask;
1239 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
1240 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
1241 (void) GNUNET_TESTBED_test_run ("perf-ats", conf_name,
1242 num_slaves + num_masters, event_mask, &controller_event_cb, NULL,
1245 GNUNET_free(solver);
1246 GNUNET_free(pref_str);
1247 GNUNET_free(conf_name);
1248 GNUNET_free(test_name);
1249 GNUNET_free(testname);
1250 GNUNET_free (comm_name);
1257 /* end of file perf_ats.c */