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"
32 #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
33 #define BENCHMARK_DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
34 #define TESTNAME_PREFIX "perf_ats_"
35 #define DEFAULT_SLAVES_NUM 3
36 #define DEFAULT_MASTERS_NUM 1
38 #define TEST_MESSAGE_TYPE_PING 12345
39 #define TEST_MESSAGE_TYPE_PONG 12346
40 #define TEST_MESSAGE_SIZE 1000
41 #define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
44 * Information about a benchmarking partner
46 struct BenchmarkPartner
49 * The peer itself this partner belongs to
51 struct BenchmarkPeer *me;
56 struct BenchmarkPeer *dest;
59 * Core transmit handles
64 * Number of messages sent to this partner
66 unsigned int messages_sent;
69 * Number of bytes sent to this partner
71 unsigned int bytes_sent;
74 * Number of messages received from this partner
76 unsigned int messages_received;
79 * Number of bytes received from this partner
81 unsigned int bytes_received;
85 * Connect peers with testbed
87 struct TestbedConnectOperation
90 * The benchmarking master initiating this connection
92 struct BenchmarkPeer *master;
95 * The benchmarking slave to connect to
97 struct BenchmarkPeer *slave;
100 * Testbed operation to connect peers
102 struct GNUNET_TESTBED_Operation *connect_op;
106 * Information we track for a peer in the testbed.
111 * Handle with testbed.
113 struct GNUNET_TESTBED_Peer *peer;
121 * Is this peer a measter: GNUNET_YES/GNUNET_NO
128 struct GNUNET_PeerIdentity id;
131 * Testbed operation to get peer information
133 struct GNUNET_TESTBED_Operation *peer_id_op;
136 * Testbed operation to connect to ATS performance service
138 struct GNUNET_TESTBED_Operation *ats_perf_op;
141 * Testbed operation to connect to core
143 struct GNUNET_TESTBED_Operation *core_op;
146 * ATS performance handle
148 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
152 * Testbed connect operations to connect masters to slaves
154 struct TestbedConnectOperation *core_connect_ops;
159 struct GNUNET_CORE_Handle *ch;
163 * Peer to set ATS preferences for
165 struct BenchmarkPeer *pref_partner;
168 * Array of partners with num_slaves entries (if master) or
169 * num_master entries (if slave)
171 struct BenchmarkPartner *partners;
174 * Number of core connections
176 int core_connections;
180 * Number of connections to slave peers
182 int core_slave_connections;
185 * Total number of messages this peer has sent
187 unsigned int total_messages_sent;
190 * Total number of bytes this peer has sent
192 unsigned int total_bytes_sent;
195 * Total number of messages this peer has received
197 unsigned int total_messages_received;
200 * Total number of bytes this peer has received
202 unsigned int total_bytes_received;
206 * Overall state of the performance benchmark
208 struct BenchmarkState
210 /* Are we connected to ATS service of all peers: GNUNET_YES/NO */
211 int connected_ATS_service;
213 /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
214 int connected_CORE_service;
216 /* Are we connected to all peers: GNUNET_YES/NO */
219 /* Are we connected to all slave peers on CORE level: GNUNET_YES/NO */
222 /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
229 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
234 static GNUNET_SCHEDULER_TaskIdentifier progress_task;
249 static char *pref_str;
252 * ATS preference value
257 * Number master peers
259 static int num_masters;
262 * Array of master peers
264 struct BenchmarkPeer *mps;
269 static int num_slaves;
271 * Array of slave peers
273 struct BenchmarkPeer *sps;
278 static struct BenchmarkState state;
285 unsigned int duration;
286 struct BenchmarkPeer *mp;
288 duration = (BENCHMARK_DURATION.rel_value_us / (1000 * 1000));
289 for (c_m = 0; c_m < num_masters; c_m++)
293 _("Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"),
294 mp->no, mp->total_bytes_sent / 1024, duration,
295 (mp->total_bytes_sent / 1024) / duration,
296 mp->total_bytes_received / 1024, duration,
297 (mp->total_bytes_received / 1024) / duration);
299 for (c_s = 0; c_s < num_slaves; c_s++)
302 "Master [%u] -> Slave [%u]: sent %u KiB/s, received %u KiB/s \n",
303 mp->no, mp->partners[c_s].dest->no,
304 (mp->partners[c_s].bytes_sent / 1024) / duration,
305 (mp->partners[c_s].bytes_received / 1024) / duration);
314 * @param tc the task context
317 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
323 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
324 if (GNUNET_SCHEDULER_NO_TASK != progress_task)
326 fprintf (stderr, "0\n");
327 GNUNET_SCHEDULER_cancel (progress_task);
329 progress_task = GNUNET_SCHEDULER_NO_TASK;
332 state.benchmarking = GNUNET_NO;
333 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n"));
335 for (c_m = 0; c_m < num_masters; c_m++)
337 if (NULL != mps[c_m].peer_id_op)
339 GNUNET_TESTBED_operation_done (mps[c_m].peer_id_op);
340 mps[c_m].peer_id_op = NULL;
343 for (c_op = 0; c_op < num_slaves; c_op++)
346 if (NULL != mps[c_m].partners[c_op].cth)
348 GNUNET_CORE_notify_transmit_ready_cancel (mps[c_m].partners[c_op].cth);
349 mps[c_m].partners[c_op].cth = NULL;
352 if (NULL != mps[c_m].core_connect_ops[c_op].connect_op)
354 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
355 _("Failed to connect peer 0 and %u\n"), c_op);
356 GNUNET_TESTBED_operation_done (
357 mps[c_m].core_connect_ops[c_op].connect_op);
358 mps[c_m].core_connect_ops[c_op].connect_op = NULL;
363 if (NULL != mps[c_m].ats_perf_op)
365 GNUNET_TESTBED_operation_done (mps[c_m].ats_perf_op);
366 mps[c_m].ats_perf_op = NULL;
369 if (NULL != mps[c_m].core_op)
371 GNUNET_TESTBED_operation_done (mps[c_m].core_op);
372 mps[c_m].core_op = NULL;
374 GNUNET_free(mps[c_m].core_connect_ops);
375 GNUNET_free(mps[c_m].partners);
376 mps[c_m].partners = NULL;
379 for (c_s = 0; c_s < num_slaves; c_s++)
381 if (NULL != sps[c_s].peer_id_op)
383 GNUNET_TESTBED_operation_done (sps[c_s].peer_id_op);
384 sps[c_s].peer_id_op = NULL;
387 for (c_op = 0; c_op < num_slaves; c_op++)
389 if (NULL != sps[c_s].partners[c_op].cth)
391 GNUNET_CORE_notify_transmit_ready_cancel (sps[c_s].partners[c_op].cth);
392 sps[c_s].partners[c_op].cth = NULL;
396 if (NULL != sps[c_s].ats_perf_op)
398 GNUNET_TESTBED_operation_done (sps[c_s].ats_perf_op);
399 sps[c_s].ats_perf_op = NULL;
401 if (NULL != sps[c_s].core_op)
403 GNUNET_TESTBED_operation_done (sps[c_s].core_op);
404 sps[c_s].core_op = NULL;
407 GNUNET_free(sps[c_s].partners);
408 sps[c_s].partners = NULL;
411 GNUNET_SCHEDULER_shutdown ();
414 static struct BenchmarkPeer *
415 find_peer (const struct GNUNET_PeerIdentity * peer)
419 for (c_p = 0; c_p < num_masters; c_p++)
421 if (0 == memcmp (&mps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity)))
425 for (c_p = 0; c_p < num_slaves; c_p++)
427 if (0 == memcmp (&sps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity)))
434 * Controller event callback
437 * @param event the controller event
440 controller_event_cb (void *cls,
441 const struct GNUNET_TESTBED_EventInformation *event)
443 //struct BenchmarkPeer *p = cls;
446 case GNUNET_TESTBED_ET_CONNECT:
448 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
453 GNUNET_SCHEDULER_cancel (shutdown_task);
454 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL );
459 core_send_ready (void *cls, size_t size, void *buf)
461 static char msgbuf[TEST_MESSAGE_SIZE];
462 struct BenchmarkPartner *partner = cls;
463 struct GNUNET_MessageHeader *msg;
466 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Master [%u]: Sending PING to [%u]\n",
467 partner->me->no, partner->dest->no);
469 partner->messages_sent++;
470 partner->bytes_sent += TEST_MESSAGE_SIZE;
471 partner->me->total_messages_sent++;
472 partner->me->total_bytes_sent += TEST_MESSAGE_SIZE;
474 msg = (struct GNUNET_MessageHeader *) &msgbuf;
475 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
476 msg->type = htons (TEST_MESSAGE_TYPE_PING);
477 msg->size = htons (TEST_MESSAGE_SIZE);
478 memcpy (buf, msg, TEST_MESSAGE_SIZE);
479 return TEST_MESSAGE_SIZE;
486 progress_task = GNUNET_SCHEDULER_NO_TASK;
488 fprintf (stderr, "%llu..",
489 (long long unsigned) BENCHMARK_DURATION.rel_value_us / (1000 * 1000) - calls);
492 progress_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
493 &print_progress, NULL );
502 if ((state.connected_ATS_service == GNUNET_NO)
503 || (state.connected_CORE_service == GNUNET_NO)
504 || (state.connected_PEERS == GNUNET_NO)
505 || (state.connected_CORE == GNUNET_NO))
508 state.benchmarking = GNUNET_YES;
509 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking start\n"));
511 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
512 GNUNET_SCHEDULER_cancel (shutdown_task);
513 shutdown_task = GNUNET_SCHEDULER_add_delayed (BENCHMARK_DURATION,
514 &do_shutdown, NULL );
516 progress_task = GNUNET_SCHEDULER_add_now (&print_progress, NULL );
518 /* Start sending test messages */
519 for (c_m = 0; c_m < num_masters; c_m++)
521 for (c_s = 0; c_s < num_slaves; c_s++)
523 mps[c_m].partners[c_s].cth = GNUNET_CORE_notify_transmit_ready (
524 mps[c_m].ch, GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, &sps[c_s].id,
525 TEST_MESSAGE_SIZE, &core_send_ready, &mps[c_m].partners[c_s]);
531 connect_completion_callback (void *cls, struct GNUNET_TESTBED_Operation *op,
534 struct TestbedConnectOperation *cop = cls;
539 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
540 _("Connected master [%u] with slave [%u]\n"), cop->master->no,
545 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
546 _("Failed to connect master peer [%u] with slave [%u]\n"),
547 cop->master->no, cop->slave->no);
549 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
550 GNUNET_SCHEDULER_cancel (shutdown_task);
551 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
553 GNUNET_TESTBED_operation_done (op);
555 for (c = 0; c < num_slaves; c++)
557 if (cop == &cop->master->core_connect_ops[c])
558 cop->master->core_connect_ops[c].connect_op = NULL;
560 if (ops == num_masters * num_slaves)
562 state.connected_PEERS = GNUNET_YES;
563 GNUNET_SCHEDULER_add_now (&do_benchmark, NULL );
568 do_connect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
572 struct BenchmarkPeer *p;
574 if ((state.connected_ATS_service == GNUNET_NO)
575 || (state.connected_CORE_service == GNUNET_NO))
578 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Connecting peers on CORE level\n"));
580 for (c_m = 0; c_m < num_masters; c_m++)
583 p->core_connect_ops = GNUNET_malloc (num_slaves *
584 sizeof (struct TestbedConnectOperation));
586 for (c_s = 0; c_s < num_slaves; c_s++)
588 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
589 _("Connecting master [%u] with slave [%u]\n"), p->no, sps[c_s].no);
590 p->core_connect_ops[c_s].master = p;
591 p->core_connect_ops[c_s].slave = &sps[c_s];
592 p->core_connect_ops[c_s].connect_op = GNUNET_TESTBED_overlay_connect (
593 NULL, &connect_completion_callback, &p->core_connect_ops[c_s],
594 sps[c_s].peer, p->peer);
595 if (NULL == p->core_connect_ops[c_s].connect_op)
597 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
598 _("Could not connect master [%u] and slave [%u]\n"), p->no,
601 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
602 GNUNET_SCHEDULER_cancel (shutdown_task);
603 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
611 * Method called whenever a given peer connects.
614 * @param peer peer identity this notification is about
617 core_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
619 struct BenchmarkPeer *me = cls;
620 struct BenchmarkPeer *remote;
625 remote = find_peer (peer);
632 id = GNUNET_strdup (GNUNET_i2s (&me->id));
633 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s [%u] `%s' connected to %s [%u] %s\n",
634 (me->master == GNUNET_YES) ? "Master": "Slave", me->no, id,
635 (remote->master == GNUNET_YES) ? "Master": "Slave", remote->no,
638 me->core_connections++;
639 if ((GNUNET_YES == me->master) && (GNUNET_NO == remote->master)
640 && (GNUNET_NO == state.connected_CORE))
642 me->core_slave_connections++;
644 if (me->core_slave_connections == num_slaves)
646 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Master [%u] connected all slaves\n",
649 completed = GNUNET_YES;
650 for (c = 0; c < num_masters; c++)
652 if (mps[c].core_slave_connections != num_slaves)
653 completed = GNUNET_NO;
655 if (GNUNET_YES == completed)
657 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
658 "All master peers connected all slave peers\n", id,
660 state.connected_CORE = GNUNET_YES;
661 GNUNET_SCHEDULER_add_now (&do_benchmark, NULL );
668 core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
670 struct BenchmarkPeer *me = cls;
671 struct BenchmarkPeer *remote;
674 remote = find_peer (peer);
681 id = GNUNET_strdup (GNUNET_i2s (&me->id));
682 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s disconnected from %s \n", id,
684 GNUNET_assert(me->core_connections > 0);
685 me->core_connections--;
687 if ((GNUNET_YES == state.benchmarking)
688 && ((GNUNET_YES == me->master) || (GNUNET_YES == remote->master)))
690 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
691 "%s disconnected from %s while benchmarking \n", id, GNUNET_i2s (peer));
697 core_send_echo_ready (void *cls, size_t size, void *buf)
699 static char msgbuf[TEST_MESSAGE_SIZE];
700 struct BenchmarkPartner *p = cls;
701 struct GNUNET_MessageHeader *msg;
706 p->bytes_sent += TEST_MESSAGE_SIZE;
707 p->me->total_messages_sent++;
708 p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
710 msg = (struct GNUNET_MessageHeader *) &msgbuf;
711 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
712 msg->type = htons (TEST_MESSAGE_TYPE_PONG);
713 msg->size = htons (TEST_MESSAGE_SIZE);
714 memcpy (buf, msg, TEST_MESSAGE_SIZE);
716 return TEST_MESSAGE_SIZE;
720 core_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
721 const struct GNUNET_MessageHeader *message)
724 struct BenchmarkPeer *me = cls;
725 struct BenchmarkPartner *p = NULL;
726 for (c_m = 0; c_m < num_masters; c_m++)
729 == memcmp (other, &me->partners[c_m].dest->id,
730 sizeof(struct GNUNET_PeerIdentity)))
732 p = &me->partners[c_m];
739 return GNUNET_SYSERR;
741 GNUNET_assert(NULL == p->cth);
743 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
744 "Slave [%u]: Received PING from [%u], sending PONG\n", me->no,
747 p->messages_received++;
748 p->bytes_received += TEST_MESSAGE_SIZE;
749 p->me->total_messages_received++;
750 p->me->total_bytes_received += TEST_MESSAGE_SIZE;
752 p->cth = GNUNET_CORE_notify_transmit_ready (me->ch, GNUNET_NO, 0,
753 GNUNET_TIME_UNIT_MINUTES, &p->dest->id, TEST_MESSAGE_SIZE,
754 &core_send_echo_ready, p);
759 core_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
760 const struct GNUNET_MessageHeader *message)
763 struct BenchmarkPeer *me = cls;
764 struct BenchmarkPartner *p = NULL;
766 for (c_s = 0; c_s < num_slaves; c_s++)
769 == memcmp (other, &me->partners[c_s].dest->id,
770 sizeof(struct GNUNET_PeerIdentity)))
772 p = &me->partners[c_s];
779 return GNUNET_SYSERR;
781 GNUNET_assert(NULL == p->cth);
783 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
784 "Master [%u]: Received PONG from [%u], next message\n", me->no,
787 p->messages_received++;
788 p->bytes_received += TEST_MESSAGE_SIZE;
789 p->me->total_messages_received++;
790 p->me->total_bytes_received += TEST_MESSAGE_SIZE;
792 p->cth = GNUNET_CORE_notify_transmit_ready (me->ch, GNUNET_NO, 0,
793 GNUNET_TIME_UNIT_MINUTES, &p->dest->id, TEST_MESSAGE_SIZE,
794 &core_send_ready, p);
800 core_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
802 struct BenchmarkPeer *me = cls;
804 static const struct GNUNET_CORE_MessageHandler handlers[] = { {
805 &core_handle_ping, TEST_MESSAGE_TYPE_PING, 0 }, { &core_handle_pong,
806 TEST_MESSAGE_TYPE_PONG, 0 }, { NULL, 0, 0 } };
808 me->ch = GNUNET_CORE_connect (cfg, me, NULL, core_connect_cb,
809 core_disconnect_cb, NULL, GNUNET_NO, NULL, GNUNET_NO, handlers);
811 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create core connection \n");
816 core_disconnect_adapter (void *cls, void *op_result)
818 struct BenchmarkPeer *me = cls;
820 GNUNET_CORE_disconnect (me->ch);
825 core_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
826 void *ca_result, const char *emsg)
828 static int core_done = 0;
829 if ((NULL != emsg) || (NULL == ca_result))
831 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
833 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
834 GNUNET_SCHEDULER_cancel (shutdown_task);
835 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
840 if (core_done == num_slaves + num_masters)
842 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all CORE services\n");
843 state.connected_CORE_service = GNUNET_YES;
844 GNUNET_SCHEDULER_add_now (&do_connect_peers, NULL );
849 do_connect_core (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
853 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all CORE services\n");
854 for (c_m = 0; c_m < num_masters; c_m++)
856 mps[c_m].core_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer,
857 "core", core_connect_completion_cb, NULL, &core_connect_adapter,
858 &core_disconnect_adapter, &mps[c_m]);
861 for (c_s = 0; c_s < num_slaves; c_s++)
863 sps[c_s].core_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer,
864 "core", core_connect_completion_cb, NULL, &core_connect_adapter,
865 &core_disconnect_adapter, &sps[c_s]);
870 ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
871 int address_active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
872 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
873 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
875 struct BenchmarkPeer *me = cls;
879 peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
880 for (c_a = 0; c_a < ats_count; c_a++)
882 /*GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("%c %03u: %s %s %u\n"),
883 (GNUNET_YES == p->master) ? 'M' : 'S',
885 GNUNET_i2s (&address->peer),
886 GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)),
887 ntohl(ats[c_a].value));*/
890 if ((GNUNET_YES == me->master)
891 && (0 == memcmp (&address->peer, &me->destination->id,
892 sizeof(struct GNUNET_PeerIdentity))))
894 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Bandwidth for master %u: %lu %lu\n",
895 me->no, (long unsigned int ) ntohl (bandwidth_in.value__),
896 (long unsigned int ) ntohl (bandwidth_in.value__));
899 store_information (&bp->id, address, address_active, bandwidth_in,
900 bandwidth_out, ats, ats_count);
902 GNUNET_free(peer_id);
906 ats_perf_connect_adapter (void *cls,
907 const struct GNUNET_CONFIGURATION_Handle *cfg)
909 struct BenchmarkPeer *me = cls;
911 me->ats_perf_handle = GNUNET_ATS_performance_init (cfg,
912 &ats_performance_info_cb, me);
913 if (NULL == me->ats_perf_handle)
914 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
915 "Failed to create ATS performance handle \n");
916 return me->ats_perf_handle;
920 ats_perf_disconnect_adapter (void *cls, void *op_result)
922 struct BenchmarkPeer *me = cls;
924 GNUNET_ATS_performance_done (me->ats_perf_handle);
925 me->ats_perf_handle = NULL;
929 ats_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
930 void *ca_result, const char *emsg)
932 static int op_done = 0;
934 if ((NULL != emsg) || (NULL == ca_result))
936 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
938 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
939 GNUNET_SCHEDULER_cancel (shutdown_task);
940 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
944 if (op_done == (num_masters + num_slaves))
946 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all ATS services\n");
947 state.connected_ATS_service = GNUNET_YES;
948 GNUNET_SCHEDULER_add_now (&do_connect_core, NULL );
953 do_connect_ats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
958 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all ATS services\n");
959 for (c_m = 0; c_m < num_masters; c_m++)
961 mps[c_m].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, mps[c_m].peer,
962 "ats", ats_connect_completion_cb, NULL, &ats_perf_connect_adapter,
963 &ats_perf_disconnect_adapter, &mps[c_m]);
967 for (c_s = 0; c_s < num_slaves; c_s++)
969 sps[c_s].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, sps[c_s].peer,
970 "ats", ats_connect_completion_cb, NULL, &ats_perf_connect_adapter,
971 &ats_perf_disconnect_adapter, &sps[c_s]);
977 peerinformation_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op,
978 const struct GNUNET_TESTBED_PeerInformation*pinfo, const char *emsg)
980 struct BenchmarkPeer *p = cb_cls;
983 GNUNET_assert(pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY);
985 p->id = *pinfo->result.id;
986 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%s [%u] has peer id `%s'\n",
987 (p->master == GNUNET_YES) ? "Master" : "Slave", p->no,
988 GNUNET_i2s (&p->id));
990 GNUNET_TESTBED_operation_done (op);
991 p->peer_id_op = NULL;
994 if (done == num_slaves + num_masters)
996 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
997 "Retrieved all peer ID, connect to ATS\n");
998 GNUNET_SCHEDULER_add_now (&do_connect_ats, NULL );
1003 * Signature of a main function for a testcase.
1005 * @param cls closure
1006 * @param num_peers number of peers in 'peers'
1007 * @param peers_ handle to peers run in the testbed
1008 * @param links_succeeded the number of overlay link connection attempts that
1010 * @param links_failed the number of overlay link connection attempts that
1014 main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers,
1015 struct GNUNET_TESTBED_Peer **peers_, unsigned int links_succeeded,
1016 unsigned int links_failed)
1020 GNUNET_assert(NULL == cls);
1021 GNUNET_assert(num_masters + num_slaves == num_peers);
1022 GNUNET_assert(NULL != peers_);
1024 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1025 _("Benchmarking solver `%s' on preference `%s' with %u master and %u slave peers\n"),
1026 solver, pref_str, num_masters, num_slaves);
1028 shutdown_task = GNUNET_SCHEDULER_add_delayed (
1029 GNUNET_TIME_relative_multiply (TEST_TIMEOUT, num_masters + num_slaves),
1030 &do_shutdown, NULL );
1032 /* Setup master peers */
1033 for (c_m = 0; c_m < num_masters; c_m++)
1035 GNUNET_assert(NULL != peers_[c_m]);
1036 mps[c_m].peer = peers_[c_m];
1038 mps[c_m].master = GNUNET_YES;
1039 mps[c_m].pref_partner = &sps[c_m];
1041 GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer));
1042 /* Initialize partners */
1043 for (c_s = 0; c_s < num_slaves; c_s++)
1045 mps[c_m].partners[c_s].me = &mps[c_m];
1046 mps[c_m].partners[c_s].dest = &sps[c_s];
1048 mps[c_m].peer_id_op = GNUNET_TESTBED_peer_get_information (mps[c_m].peer,
1049 GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &mps[c_m]);
1052 /* Setup slave peers */
1053 for (c_s = 0; c_s < num_slaves; c_s++)
1055 GNUNET_assert(NULL != peers_[c_s + num_masters]);
1056 sps[c_s].peer = peers_[c_s + num_masters];
1057 sps[c_s].no = c_s + num_masters;
1058 sps[c_s].master = GNUNET_NO;
1060 GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer));
1061 /* Initialize partners */
1062 for (c_m = 0; c_m < num_masters; c_m++)
1064 sps[c_s].partners[c_m].me = &sps[c_s];
1065 sps[c_s].partners[c_m].dest = &mps[c_m];
1067 sps[c_s].peer_id_op = GNUNET_TESTBED_peer_get_information (sps[c_s].peer,
1068 GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &sps[c_s]);
1073 main (int argc, char *argv[])
1080 char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
1085 /* figure out testname */
1086 tmp = strstr (argv[0], TESTNAME_PREFIX);
1089 fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
1090 return GNUNET_SYSERR;
1092 tmp += strlen (TESTNAME_PREFIX);
1093 solver = GNUNET_strdup (tmp);
1094 if (NULL != (dotexe = strstr (solver, ".exe")) && dotexe[4] == '\0')
1096 tmp_sep = strchr (solver, '_');
1097 if (NULL == tmp_sep)
1099 fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
1100 GNUNET_free(solver);
1101 return GNUNET_SYSERR;
1104 pref_str = GNUNET_strdup(tmp_sep + 1);
1106 GNUNET_asprintf (&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver,
1108 GNUNET_asprintf (&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, pref_str);
1110 for (c = 0; c <= strlen (pref_str); c++)
1111 pref_str[c] = toupper (pref_str[c]);
1114 if (0 != strcmp (pref_str, "NONE"))
1116 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
1118 if (0 == strcmp (pref_str, prefs[c]))
1127 /* abuse terminator to indicate no pref */
1128 pref_val = GNUNET_ATS_PREFERENCE_END;
1132 fprintf (stderr, "Unknown preference: `%s'\n", pref_str);
1133 GNUNET_free(solver);
1134 GNUNET_free(pref_str);
1138 for (c = 0; c < (argc - 1); c++)
1140 if (0 == strcmp (argv[c], "-s"))
1145 if ((0L != (num_slaves = strtol (argv[c + 1], NULL, 10)))
1146 && (num_slaves >= 1))
1147 fprintf (stderr, "Starting %u slave peers\n", num_slaves);
1149 num_slaves = DEFAULT_SLAVES_NUM;
1152 num_slaves = DEFAULT_SLAVES_NUM;
1154 for (c = 0; c < (argc - 1); c++)
1156 if (0 == strcmp (argv[c], "-m"))
1161 if ((0L != (num_masters = strtol (argv[c + 1], NULL, 10)))
1162 && (num_masters >= 2))
1163 fprintf (stderr, "Starting %u master peers\n", num_masters);
1165 num_masters = DEFAULT_MASTERS_NUM;
1168 num_masters = DEFAULT_MASTERS_NUM;
1170 if (num_slaves < num_masters)
1172 fprintf (stderr, "Number of master peers is lower than slaves! exit...\n");
1173 GNUNET_free(test_name);
1174 GNUNET_free(solver);
1175 GNUNET_free(pref_str);
1176 return GNUNET_SYSERR;
1179 state.connected_ATS_service = GNUNET_NO;
1180 state.connected_CORE_service = GNUNET_NO;
1181 state.connected_PEERS = GNUNET_NO;
1182 state.benchmarking = GNUNET_NO;
1183 state.connected_PEERS = GNUNET_NO;
1185 mps = GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer));
1186 sps = GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer));
1188 /* Start topology */
1189 uint64_t event_mask;
1191 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
1192 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
1193 (void) GNUNET_TESTBED_test_run ("perf_ats", conf_name,
1194 num_slaves + num_masters, event_mask, &controller_event_cb, NULL,
1197 GNUNET_free(solver);
1198 GNUNET_free(pref_str);
1199 GNUNET_free(conf_name);
1200 GNUNET_free(test_name);
1207 /* end of file perf_ats.c */