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)
45 * Information about a benchmarking partner
47 struct BenchmarkPartner
50 * The peer itself this partner belongs to
52 struct BenchmarkPeer *me;
57 struct BenchmarkPeer *dest;
60 * Core transmit handles
65 * Number of messages sent to this partner
67 unsigned int messages_sent;
70 * Number of bytes sent to this partner
72 unsigned int bytes_sent;
75 * Number of messages received from this partner
77 unsigned int messages_received;
80 * Number of bytes received from this partner
82 unsigned int bytes_received;
86 struct MasterInformation
88 int core_slave_connections;
91 * Testbed connect operation
97 * Connect peers with testbed
99 struct TestbedConnectOperation
102 * The benchmarking master initiating this connection
104 struct BenchmarkPeer *master;
107 * The benchmarking slave to connect to
109 struct BenchmarkPeer *slave;
112 * Testbed operation to connect peers
114 struct GNUNET_TESTBED_Operation *connect_op;
120 * Information we track for a peer in the testbed.
125 * Handle with testbed.
127 struct GNUNET_TESTBED_Peer *peer;
135 * Is this peer a measter: GNUNET_YES/GNUNET_NO
142 struct GNUNET_PeerIdentity id;
145 * Testbed operation to get peer information
147 struct GNUNET_TESTBED_Operation *peer_id_op;
150 * Testbed operation to connect to ATS performance service
152 struct GNUNET_TESTBED_Operation *ats_perf_op;
155 * Testbed operation to connect to core
157 struct GNUNET_TESTBED_Operation *core_op;
160 * ATS performance handle
162 struct GNUNET_ATS_PerformanceHandle *ats_perf_handle;
165 * Testbed connect operations to connect masters to slaves
166 * For masters peers only
168 struct TestbedConnectOperation *core_connect_ops;
173 struct GNUNET_CORE_Handle *ch;
176 * Array of partners with num_slaves entries (if master) or
177 * num_master entries (if slave)
179 struct BenchmarkPartner *partners;
181 int core_connections;
183 struct MasterInformation mi;
186 * Total number of messages this peer has sent
188 unsigned int total_messages_sent;
191 * Total number of bytes this peer has sent
193 unsigned int total_bytes_sent;
196 * Total number of messages this peer has received
198 unsigned int total_messages_received;
201 * Total number of bytes this peer has received
203 unsigned int total_bytes_received;
208 * Overall state of the performance benchmark
210 struct BenchmarkState
212 /* Are we connected to ATS service of all peers: GNUNET_YES/NO */
213 int connected_ATS_service;
215 /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
216 int connected_CORE_service;
218 /* Are we connected to all peers: GNUNET_YES/NO */
221 /* Are we connected to all slave peers on CORE level: GNUNET_YES/NO */
224 /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
232 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
247 static char *pref_str;
250 * ATS preference value
255 * Number master peers
257 static int num_masters;
260 * Array of master peers
262 struct BenchmarkPeer *mps;
267 static int num_slaves;
269 * Array of slave peers
271 struct BenchmarkPeer *sps;
276 static struct BenchmarkState state;
284 unsigned int duration;
285 struct BenchmarkPeer *mp;
287 duration = (BENCHMARK_DURATION.rel_value_us / (1000 * 1000));
288 for (c_m = 0; c_m < num_masters; c_m++)
291 fprintf (stderr, _("Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"),
293 mp->total_bytes_sent / 1024,
295 (mp->total_bytes_sent / 1024) / duration ,
296 mp->total_bytes_received / 1024,
298 (mp->total_bytes_received / 1024) / duration);
300 for (c_s = 0; c_s < num_slaves; c_s ++)
302 fprintf (stderr, "Master [%u] -> Slave [%u]: sent %u KiB/s, received %u KiB/s \n",
304 mp->partners[c_s].dest->no,
305 (mp->partners[c_s].bytes_sent / 1024) / duration,
306 (mp->partners[c_s].bytes_received / 1024) / duration);
316 * @param tc the task context
319 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
325 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
327 state.benchmarking = GNUNET_NO;
328 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n"));
330 for (c_m = 0; c_m < num_masters; c_m++)
332 if (NULL != mps[c_m].peer_id_op)
334 GNUNET_TESTBED_operation_done (mps[c_m].peer_id_op);
335 mps[c_m].peer_id_op = NULL;
338 for (c_op = 0; c_op < num_slaves; c_op++)
341 if (NULL != mps[c_m].partners[c_op].cth)
343 GNUNET_CORE_notify_transmit_ready_cancel (mps[c_m].partners[c_op].cth);
344 mps[c_m].partners[c_op].cth = NULL;
347 if (NULL != mps[c_m].core_connect_ops[c_op].connect_op)
349 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
350 _("Failed to connect peer 0 and %u\n"), c_op);
351 GNUNET_TESTBED_operation_done (
352 mps[c_m].core_connect_ops[c_op].connect_op);
353 mps[c_m].core_connect_ops[c_op].connect_op = NULL;
358 if (NULL != mps[c_m].ats_perf_op)
360 GNUNET_TESTBED_operation_done (mps[c_m].ats_perf_op);
361 mps[c_m].ats_perf_op = NULL;
364 if (NULL != mps[c_m].core_op)
366 GNUNET_TESTBED_operation_done (mps[c_m].core_op);
367 mps[c_m].core_op = NULL;
369 GNUNET_free (mps[c_m].core_connect_ops);
370 GNUNET_free (mps[c_m].partners);
371 mps[c_m].partners = NULL;
375 for (c_s = 0; c_s < num_slaves; c_s++)
377 if (NULL != sps[c_s].peer_id_op)
379 GNUNET_TESTBED_operation_done (sps[c_s].peer_id_op);
380 sps[c_s].peer_id_op = NULL;
383 for (c_op = 0; c_op < num_slaves; c_op++)
385 if (NULL != sps[c_s].partners[c_op].cth)
387 GNUNET_CORE_notify_transmit_ready_cancel (sps[c_s].partners[c_op].cth);
388 sps[c_s].partners[c_op].cth = NULL;
393 if (NULL != sps[c_s].ats_perf_op)
395 GNUNET_TESTBED_operation_done (sps[c_s].ats_perf_op);
396 sps[c_s].ats_perf_op = NULL;
398 if (NULL != sps[c_s].core_op)
400 GNUNET_TESTBED_operation_done (sps[c_s].core_op);
401 sps[c_s].core_op = NULL;
404 GNUNET_free (sps[c_s].partners);
405 sps[c_s].partners = NULL;
408 GNUNET_SCHEDULER_shutdown ();
412 static struct BenchmarkPeer *
413 find_peer (const struct GNUNET_PeerIdentity * peer)
417 for (c_p = 0; c_p < num_masters; c_p++)
420 == memcmp (&mps[c_p].id, peer,
421 sizeof(struct GNUNET_PeerIdentity)))
425 for (c_p = 0; c_p < num_slaves; c_p++)
427 if (0 == memcmp (&sps[c_p].id, peer,
428 sizeof(struct GNUNET_PeerIdentity)))
436 * Controller event callback
439 * @param event the controller event
442 controller_event_cb (void *cls,
443 const struct GNUNET_TESTBED_EventInformation *event)
445 //struct BenchmarkPeer *p = cls;
448 case GNUNET_TESTBED_ET_CONNECT:
450 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
455 GNUNET_SCHEDULER_cancel (shutdown_task);
456 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL );
462 core_send_ready (void *cls, size_t size, void *buf)
464 static char msgbuf[TEST_MESSAGE_SIZE];
465 struct BenchmarkPartner *partner = cls;
466 struct GNUNET_MessageHeader *msg;
469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Master [%u]: Sending PING to [%u]\n",
470 partner->me->no, partner->dest->no);
472 partner->messages_sent ++;
473 partner->bytes_sent += TEST_MESSAGE_SIZE;
474 partner->me->total_messages_sent ++;
475 partner->me->total_bytes_sent += TEST_MESSAGE_SIZE;
477 msg = (struct GNUNET_MessageHeader *) &msgbuf;
478 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
479 msg->type = htons (TEST_MESSAGE_TYPE_PING);
480 msg->size = htons (TEST_MESSAGE_SIZE);
481 memcpy (buf, msg, TEST_MESSAGE_SIZE);
482 return TEST_MESSAGE_SIZE;
492 if ((state.connected_ATS_service == GNUNET_NO)
493 || (state.connected_CORE_service == GNUNET_NO)
494 || (state.connected_PEERS == GNUNET_NO)
495 || (state.connected_CORE == GNUNET_NO))
498 state.benchmarking = GNUNET_YES;
499 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking start\n"));
501 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
502 GNUNET_SCHEDULER_cancel (shutdown_task);
503 shutdown_task = GNUNET_SCHEDULER_add_delayed (BENCHMARK_DURATION,
504 &do_shutdown, NULL );
506 /* Start sending test messages */
507 for (c_m = 0; c_m < num_masters; c_m++)
509 for (c_s = 0; c_s < num_slaves; c_s++)
511 mps[c_m].partners[c_s].cth = GNUNET_CORE_notify_transmit_ready (mps[c_m].ch,
512 GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, &sps[c_s].id,
513 TEST_MESSAGE_SIZE, &core_send_ready, &mps[c_m].partners[c_s]);
520 connect_completion_callback (void *cls, struct GNUNET_TESTBED_Operation *op,
523 struct TestbedConnectOperation *cop = cls;
528 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
529 _("Connected master peer %u with peer %u\n"), cop->master->no,
534 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
535 _("Failed to connect master peer%u with peer %u\n"), cop->master->no,
538 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
539 GNUNET_SCHEDULER_cancel (shutdown_task);
540 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
542 GNUNET_TESTBED_operation_done (op);
544 for (c = 0; c < num_slaves; c++)
546 if (cop == &cop->master->core_connect_ops[c])
547 cop->master->core_connect_ops[c].connect_op = NULL;
549 if (ops == num_masters * num_slaves)
551 state.connected_PEERS = GNUNET_YES;
552 GNUNET_SCHEDULER_add_now (&do_benchmark, NULL );
558 do_connect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
562 struct BenchmarkPeer *p;
564 if ((state.connected_ATS_service == GNUNET_NO)
565 || (state.connected_CORE_service == GNUNET_NO))
570 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Connecting peers on CORE level\n"));
572 for (c_m = 0; c_m < num_masters; c_m++)
575 p->core_connect_ops = GNUNET_malloc (num_slaves *
576 sizeof (struct TestbedConnectOperation));
578 for (c_s = 0; c_s < num_slaves; c_s++)
580 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
581 _("Connecting master peer %u with slave peer %u\n"), p->no,
583 p->core_connect_ops[c_s].master = p;
584 p->core_connect_ops[c_s].slave = &sps[c_s];
585 p->core_connect_ops[c_s].connect_op = GNUNET_TESTBED_overlay_connect (NULL,
586 &connect_completion_callback, &p->core_connect_ops[c_s],
587 sps[c_s].peer, p->peer);
588 if (NULL == p->core_connect_ops[c_s].connect_op)
590 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
591 _("Could not connect master peer %u and slave peer %u\n"), p->no,
594 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
595 GNUNET_SCHEDULER_cancel (shutdown_task);
596 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
605 * Method called whenever a given peer connects.
608 * @param peer peer identity this notification is about
611 core_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
613 struct BenchmarkPeer *p = cls;
614 struct BenchmarkPeer *t;
619 t = find_peer (peer);
626 id = GNUNET_strdup (GNUNET_i2s (&p->id));
627 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s %s connected to %s %s\n",
628 (p->master == GNUNET_YES) ? "Master": "Slave", id,
629 (t->master == GNUNET_YES) ? "Master": "Slave", GNUNET_i2s (peer));
631 p->core_connections++;
632 if ((GNUNET_YES == p->master) && (GNUNET_NO == t->master)
633 && (GNUNET_NO == state.connected_CORE))
635 p->mi.core_slave_connections++;
637 if (p->mi.core_slave_connections == num_slaves)
639 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Master %u connected all slaves\n",
642 completed = GNUNET_YES;
643 for (c = 0; c < num_masters; c++)
645 if (mps[c].mi.core_slave_connections != num_slaves)
646 completed = GNUNET_NO;
648 if (GNUNET_YES == completed)
650 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
651 "All master peers connected all slave peers\n", id,
653 state.connected_CORE = GNUNET_YES;
654 GNUNET_SCHEDULER_add_now (&do_benchmark, NULL );
662 core_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
664 struct BenchmarkPeer *p = cls;
665 struct BenchmarkPeer *t;
668 t = find_peer (peer);
675 id = GNUNET_strdup (GNUNET_i2s (&p->id));
676 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s disconnected from %s \n", id,
678 GNUNET_assert(p->core_connections > 0);
679 p->core_connections--;
681 if ((GNUNET_YES == state.benchmarking)
682 && ((GNUNET_YES == p->master) || (GNUNET_YES == t->master)))
684 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
685 "%s disconnected from %s while benchmarking \n", id, GNUNET_i2s (peer));
691 core_send_echo_ready (void *cls, size_t size, void *buf)
693 static char msgbuf[TEST_MESSAGE_SIZE];
694 struct BenchmarkPartner *p = cls;
695 struct GNUNET_MessageHeader *msg;
700 p->bytes_sent += TEST_MESSAGE_SIZE;
701 p->me->total_messages_sent ++;
702 p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
704 msg = (struct GNUNET_MessageHeader *) &msgbuf;
705 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
706 msg->type = htons (TEST_MESSAGE_TYPE_PONG);
707 msg->size = htons (TEST_MESSAGE_SIZE);
708 memcpy (buf, msg, TEST_MESSAGE_SIZE);
710 return TEST_MESSAGE_SIZE;
715 core_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
716 const struct GNUNET_MessageHeader *message)
719 struct BenchmarkPeer *me = cls;
720 struct BenchmarkPartner *p = NULL;
721 for (c_m = 0; c_m < num_masters; c_m++)
723 if (0 == memcmp (other, &me->partners[c_m].dest->id, sizeof (struct GNUNET_PeerIdentity)))
725 p = &me->partners[c_m];
732 return GNUNET_SYSERR;
734 GNUNET_assert (NULL == p->cth);
736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
737 "Slave [%u]: Received PING from [%u], sending PONG\n",
738 me->no, p->dest->no);
740 p->messages_received ++;
741 p->bytes_received += TEST_MESSAGE_SIZE;
742 p->me->total_messages_received ++;
743 p->me->total_bytes_received += TEST_MESSAGE_SIZE;
745 p->cth = GNUNET_CORE_notify_transmit_ready (me->ch, GNUNET_NO, 0,
746 GNUNET_TIME_UNIT_MINUTES, &p->dest->id, TEST_MESSAGE_SIZE,
747 &core_send_echo_ready, p);
752 core_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
753 const struct GNUNET_MessageHeader *message)
756 struct BenchmarkPeer *me = cls;
757 struct BenchmarkPartner *p = NULL;
759 for (c_s = 0; c_s < num_slaves; c_s++)
761 if (0 == memcmp (other, &me->partners[c_s].dest->id, sizeof (struct GNUNET_PeerIdentity)))
763 p = &me->partners[c_s];
770 return GNUNET_SYSERR;
772 GNUNET_assert (NULL == p->cth);
774 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
775 "Master [%u]: Received PONG from [%u], next message\n",
776 me->no, p->dest->no);
778 p->messages_received ++;
779 p->bytes_received += TEST_MESSAGE_SIZE;
780 p->me->total_messages_received ++;
781 p->me->total_bytes_received += TEST_MESSAGE_SIZE;
783 p->cth = GNUNET_CORE_notify_transmit_ready (me->ch,
784 GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, &p->dest->id,
785 TEST_MESSAGE_SIZE, &core_send_ready, p);
791 core_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
793 struct BenchmarkPeer *peer = cls;
795 static const struct GNUNET_CORE_MessageHandler handlers[] = {
796 {&core_handle_ping, TEST_MESSAGE_TYPE_PING, 0 },
797 {&core_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 },
800 peer->ch = GNUNET_CORE_connect (cfg, peer, NULL, core_connect_cb,
801 core_disconnect_cb, NULL, GNUNET_NO, NULL, GNUNET_NO, handlers);
802 if (NULL == peer->ch)
803 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create core connection \n");
809 core_disconnect_adapter (void *cls, void *op_result)
811 struct BenchmarkPeer *peer = cls;
813 GNUNET_CORE_disconnect (peer->ch);
819 core_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
820 void *ca_result, const char *emsg)
822 static int core_done = 0;
823 if ((NULL != emsg) || (NULL == ca_result))
825 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
827 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
828 GNUNET_SCHEDULER_cancel (shutdown_task);
829 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
834 if (core_done == num_slaves + num_masters)
836 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all CORE services\n");
837 state.connected_CORE_service = GNUNET_YES;
838 GNUNET_SCHEDULER_add_now (&do_connect_peers, NULL );
844 do_connect_core (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
848 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all CORE services\n");
849 for (c_m = 0; c_m < num_masters; c_m++)
851 mps[c_m].core_op = GNUNET_TESTBED_service_connect (NULL,
852 mps[c_m].peer, "core", core_connect_completion_cb, NULL,
853 &core_connect_adapter, &core_disconnect_adapter, &mps[c_m]);
856 for (c_s = 0; c_s < num_slaves; c_s++)
858 sps[c_s].core_op = GNUNET_TESTBED_service_connect (NULL,
859 sps[c_s].peer, "core", core_connect_completion_cb, NULL,
860 &core_connect_adapter, &core_disconnect_adapter, &sps[c_s]);
865 ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
866 int address_active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
867 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
868 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
870 struct BenchmarkPeer *p = cls;
874 peer_id = GNUNET_strdup (GNUNET_i2s (&p->id));
875 for (c_a = 0; c_a < ats_count; c_a++)
877 /*GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("%c %03u: %s %s %u\n"),
878 (GNUNET_YES == p->master) ? 'M' : 'S',
880 GNUNET_i2s (&address->peer),
881 GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)),
882 ntohl(ats[c_a].value));*/
885 if ((GNUNET_YES == p->master)
886 && (0 == memcmp (&address->peer, &p->destination->id,
887 sizeof(struct GNUNET_PeerIdentity))))
889 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Bandwidth for master %u: %lu %lu\n",
890 p->no, (long unsigned int ) ntohl (bandwidth_in.value__),
891 (long unsigned int ) ntohl (bandwidth_in.value__));
894 store_information (&bp->id, address, address_active, bandwidth_in,
895 bandwidth_out, ats, ats_count);
897 GNUNET_free(peer_id);
902 ats_perf_connect_adapter (void *cls,
903 const struct GNUNET_CONFIGURATION_Handle *cfg)
905 struct BenchmarkPeer *peer = cls;
907 peer->ats_perf_handle = GNUNET_ATS_performance_init (cfg, &ats_performance_info_cb,
909 if (NULL == peer->ats_perf_handle)
910 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
911 "Failed to create ATS performance handle \n");
912 return peer->ats_perf_handle;
917 ats_perf_disconnect_adapter (void *cls, void *op_result)
919 struct BenchmarkPeer *peer = cls;
921 GNUNET_ATS_performance_done (peer->ats_perf_handle);
922 peer->ats_perf_handle = NULL;
926 ats_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
927 void *ca_result, const char *emsg)
929 static int op_done = 0;
931 if ((NULL != emsg) || (NULL == ca_result))
933 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
935 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
936 GNUNET_SCHEDULER_cancel (shutdown_task);
937 shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
941 if (op_done == (num_masters+ num_slaves))
943 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all ATS services\n");
944 state.connected_ATS_service = GNUNET_YES;
945 GNUNET_SCHEDULER_add_now (&do_connect_core, NULL );
951 do_connect_ats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
956 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all ATS services\n");
957 for (c_m = 0; c_m < num_masters; c_m++)
959 mps[c_m].ats_perf_op = GNUNET_TESTBED_service_connect (NULL,
960 mps[c_m].peer, "ats", ats_connect_completion_cb, NULL,
961 &ats_perf_connect_adapter, &ats_perf_disconnect_adapter,
966 for (c_s = 0; c_s < num_slaves; c_s++)
968 sps[c_s].ats_perf_op = GNUNET_TESTBED_service_connect (NULL,
969 sps[c_s].peer, "ats", ats_connect_completion_cb, NULL,
970 &ats_perf_connect_adapter, &ats_perf_disconnect_adapter,
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, "[%c %03u] Peers %s\n",
987 (p->master == GNUNET_YES) ? 'M' : 'S', p->no, GNUNET_i2s (&p->id));
989 GNUNET_TESTBED_operation_done (op);
990 p->peer_id_op = NULL;
993 if (done == num_slaves + num_masters)
995 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
996 "Retrieved all peer ID, connect to ATS\n");
997 GNUNET_SCHEDULER_add_now (&do_connect_ats, NULL );
1002 * Signature of a main function for a testcase.
1004 * @param cls closure
1005 * @param num_peers number of peers in 'peers'
1006 * @param peers_ handle to peers run in the testbed
1007 * @param links_succeeded the number of overlay link connection attempts that
1009 * @param links_failed the number of overlay link connection attempts that
1013 main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h,
1014 unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers_,
1015 unsigned int links_succeeded, unsigned int links_failed)
1019 GNUNET_assert(NULL == cls);
1020 GNUNET_assert(num_masters + num_slaves == num_peers);
1021 GNUNET_assert(NULL != peers_);
1023 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1024 _("Benchmarking solver `%s' on preference `%s' with %u master and %u slave peers\n"),
1025 solver, pref_str, num_masters, num_slaves);
1027 shutdown_task = GNUNET_SCHEDULER_add_delayed (
1028 GNUNET_TIME_relative_multiply (TEST_TIMEOUT,
1029 num_masters + num_slaves), &do_shutdown, NULL );
1031 /* Setup master peers */
1032 for (c_m = 0; c_m < num_masters; c_m++)
1034 GNUNET_assert(NULL != peers_[c_m]);
1035 mps[c_m].peer = peers_[c_m];
1037 mps[c_m].master = GNUNET_YES;
1038 mps[c_m].partners = GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer));
1039 /* Initialize partners */
1040 for (c_s = 0; c_s < num_slaves; c_s++)
1042 mps[c_m].partners[c_s].me = &mps[c_m];
1043 mps[c_m].partners[c_s].dest = &sps[c_s];
1045 mps[c_m].peer_id_op = GNUNET_TESTBED_peer_get_information (
1046 mps[c_m].peer, GNUNET_TESTBED_PIT_IDENTITY,
1047 &peerinformation_cb,
1051 /* Setup slave peers */
1052 for (c_s = 0; c_s < num_slaves; c_s++)
1054 GNUNET_assert(NULL != peers_[c_s + num_masters]);
1055 sps[c_s].peer = peers_[c_s + num_masters];
1056 sps[c_s].no = c_s + num_masters;
1057 sps[c_s].master = GNUNET_NO;
1058 sps[c_s].partners = GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer));
1059 /* Initialize partners */
1060 for (c_m = 0; c_m < num_masters; c_m++)
1062 sps[c_s].partners[c_m].me = &sps[c_s];
1063 sps[c_s].partners[c_m].dest = &mps[c_m];
1065 sps[c_s].peer_id_op = GNUNET_TESTBED_peer_get_information (
1066 sps[c_s].peer, GNUNET_TESTBED_PIT_IDENTITY,
1067 &peerinformation_cb,
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))) && (num_slaves >= 1))
1146 fprintf (stderr, "Starting %u slave peers\n", num_slaves);
1148 num_slaves = DEFAULT_SLAVES_NUM;
1151 num_slaves = DEFAULT_SLAVES_NUM;
1153 for (c = 0; c < (argc -1); c++)
1155 if (0 == strcmp(argv[c], "-m"))
1160 if ((0L != (num_masters = strtol (argv[c + 1], NULL, 10))) && (num_masters >= 2))
1161 fprintf (stderr, "Starting %u master peers\n", num_masters);
1163 num_masters = DEFAULT_MASTERS_NUM;
1166 num_masters = DEFAULT_MASTERS_NUM;
1168 state.connected_ATS_service = GNUNET_NO;
1169 state.connected_CORE_service = GNUNET_NO;
1170 state.connected_PEERS = GNUNET_NO;
1172 mps = GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer));
1173 sps = GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer));
1175 /* Start topology */
1176 uint64_t event_mask;
1178 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
1179 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
1180 (void) GNUNET_TESTBED_test_run ("perf_ats",
1181 conf_name, num_slaves + num_masters,
1182 event_mask, &controller_event_cb, NULL,
1185 GNUNET_free (solver);
1186 GNUNET_free (pref_str);
1187 GNUNET_free (conf_name);
1188 GNUNET_free (test_name);
1195 /* end of file perf_ats.c */