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-tests/ats-testing.c
22 * @brief ats testing library: setup topology and provide logging to test ats
24 * @author Christian Grothoff
25 * @author Matthias Wachs
27 #include "ats-testing.h"
30 * Overall state of the performance benchmark
35 * Are we connected to ATS service of all peers: GNUNET_YES/NO
37 int connected_ATS_service;
40 * Are we connected to CORE service of all peers: GNUNET_YES/NO
42 int connected_COMM_service;
45 * Are we connected to all peers: GNUNET_YES/NO
50 * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
55 * Are we connected to CORE service of all peers: GNUNET_YES/NO
64 * Connect peers with testbed
66 struct TestbedConnectOperation
69 * The benchmarking master initiating this connection
71 struct BenchmarkPeer *master;
74 * The benchmarking slave to connect to
76 struct BenchmarkPeer *slave;
79 * Testbed operation to connect peers
81 struct GNUNET_TESTBED_Operation *connect_op;
84 struct GNUNET_ATS_TEST_Topology
89 GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
94 GNUNET_SCHEDULER_TaskIdentifier progress_task;
102 * Test result logging
106 /**Test core (GNUNET_YES) or transport (GNUNET_NO)
126 * ATS preference value
131 * Number master peers
133 unsigned int num_masters;
136 * Array of master peers
138 struct BenchmarkPeer *mps;
143 unsigned int num_slaves;
146 * Array of slave peers
148 struct BenchmarkPeer *sps;
153 struct GNUNET_TIME_Relative perf_duration;
158 struct GNUNET_TIME_Relative log_frequency;
163 struct BenchmarkState state;
165 struct GNUNET_CORE_MessageHandler *handlers;
167 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
169 GNUNET_ATS_TESTING_TopologySetupDoneCallback done_cb;
170 GNUNET_ATS_AddressInformationCallback ats_perf_cb;
176 static struct GNUNET_ATS_TEST_Topology *top;
178 struct TrafficGenerator *tg_head;
179 struct TrafficGenerator *tg_tail;
181 struct TrafficGenerator
183 struct TrafficGenerator *prev;
184 struct TrafficGenerator *next;
186 struct BenchmarkPeer *src;
187 struct BenchmarkPartner *dest;
189 GNUNET_SCHEDULER_Task next_send;
190 struct GNUNET_TIME_Absolute last_sent;
191 struct GNUNET_TIME_Relative delta;
198 * @param tc the task context
201 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
206 struct BenchmarkPeer *p;
207 struct TrafficGenerator *cur;
208 struct TrafficGenerator *next;
210 if (GNUNET_YES == top->logging)
211 GNUNET_ATS_TEST_logging_stop ();
213 top->shutdown_task = GNUNET_SCHEDULER_NO_TASK;
215 top->state.benchmarking = GNUNET_NO;
218 for (cur = next; NULL != cur; cur = next)
221 GNUNET_ATS_TEST_generate_traffic_stop(cur);
224 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n"));
226 for (c_m = 0; c_m < top->num_masters; c_m++)
229 if (NULL != top->mps[c_m].peer_id_op)
231 GNUNET_TESTBED_operation_done (p->peer_id_op);
232 p->peer_id_op = NULL;
235 if (GNUNET_SCHEDULER_NO_TASK != p->ats_task)
236 GNUNET_SCHEDULER_cancel (p->ats_task);
237 p->ats_task = GNUNET_SCHEDULER_NO_TASK;
239 for (c_op = 0; c_op < p->num_partners; c_op++)
241 if (NULL != p->partners[c_op].cth)
243 GNUNET_CORE_notify_transmit_ready_cancel (p->partners[c_op].cth);
244 p->partners[c_op].cth = NULL;
246 if (NULL != p->partners[c_op].tth)
248 GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->partners[c_op].tth);
249 p->partners[c_op].tth = NULL;
251 if ( (NULL != p->core_connect_ops) &&
252 (NULL != p->core_connect_ops[c_op].connect_op) )
254 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
255 _("Failed to connect peer 0 and %u\n"), c_op);
256 GNUNET_TESTBED_operation_done (
257 p->core_connect_ops[c_op].connect_op);
258 p->core_connect_ops[c_op].connect_op = NULL;
262 if (NULL != p->ats_perf_op)
264 GNUNET_TESTBED_operation_done (p->ats_perf_op);
265 p->ats_perf_op = NULL;
268 if (NULL != p->comm_op)
270 GNUNET_TESTBED_operation_done (p->comm_op);
273 GNUNET_free_non_null (p->core_connect_ops);
274 GNUNET_free(p->partners);
278 for (c_s = 0; c_s < top->num_slaves; c_s++)
281 if (NULL != p->peer_id_op)
283 GNUNET_TESTBED_operation_done (p->peer_id_op);
284 p->peer_id_op = NULL;
287 for (c_op = 0; c_op < p->num_partners; c_op++)
289 if (NULL != p->partners[c_op].cth)
291 GNUNET_CORE_notify_transmit_ready_cancel (p->partners[c_op].cth);
292 p->partners[c_op].cth = NULL;
294 if (NULL != p->partners[c_op].tth)
296 GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->partners[c_op].tth);
297 p->partners[c_op].tth = NULL;
300 if (NULL != p->ats_perf_op)
302 GNUNET_TESTBED_operation_done (p->ats_perf_op);
303 p->ats_perf_op = NULL;
305 if (NULL != p->comm_op)
307 GNUNET_TESTBED_operation_done (p->comm_op);
310 GNUNET_free(p->partners);
313 GNUNET_SCHEDULER_shutdown ();
318 static struct BenchmarkPartner *
319 find_partner (struct BenchmarkPeer *me, const struct GNUNET_PeerIdentity * peer)
322 GNUNET_assert (NULL != me);
323 GNUNET_assert (NULL != peer);
325 for (c_m = 0; c_m < me->num_partners; c_m++)
327 /* Find a partner with other as destination */
328 if (0 == memcmp (peer, &me->partners[c_m].dest->id,
329 sizeof(struct GNUNET_PeerIdentity)))
331 return &me->partners[c_m];
339 static struct BenchmarkPeer *
340 find_peer (const struct GNUNET_PeerIdentity * peer)
344 for (c_p = 0; c_p < top->num_masters; c_p++)
346 if (0 == memcmp (&top->mps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity)))
347 return &top->mps[c_p];
350 for (c_p = 0; c_p < top->num_slaves; c_p++)
352 if (0 == memcmp (&top->sps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity)))
353 return &top->sps[c_p];
360 * Method called whenever a given peer connects.
363 * @param peer peer identity this notification is about
366 comm_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
368 struct BenchmarkPeer *me = cls;
369 struct BenchmarkPeer *remote;
374 remote = find_peer (peer);
377 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unknown peer connected: `%s'\n", GNUNET_i2s (peer));
382 id = GNUNET_strdup (GNUNET_i2s (&me->id));
383 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s [%u] `%s' connected to %s [%u] %s\n",
384 (me->master == GNUNET_YES) ? "Master": "Slave", me->no, id,
385 (remote->master == GNUNET_YES) ? "Master": "Slave", remote->no,
388 me->core_connections++;
389 if ((GNUNET_YES == me->master) && (GNUNET_NO == remote->master)
390 && (GNUNET_NO == top->state.connected_CORE))
392 me->core_slave_connections++;
394 if (me->core_slave_connections == top->num_slaves)
396 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Master [%u] connected all slaves\n",
399 completed = GNUNET_YES;
400 for (c = 0; c < top->num_masters; c++)
402 if (top->mps[c].core_slave_connections != top->num_slaves)
403 completed = GNUNET_NO;
405 if (GNUNET_YES == completed)
407 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
408 "All master peers connected all slave peers\n", id,
410 top->state.connected_CORE = GNUNET_YES;
411 /* Notify about setup done */
412 if (NULL != top->done_cb)
413 top->done_cb (top->done_cb_cls, top->mps, top->sps);
420 comm_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
422 struct BenchmarkPeer *me = cls;
423 struct BenchmarkPartner *p;
426 if (NULL == (p = find_partner (me, peer)))
429 id = GNUNET_strdup (GNUNET_i2s (&me->id));
430 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s disconnected from %s \n", id,
432 GNUNET_assert(me->core_connections > 0);
433 me->core_connections--;
435 if ((GNUNET_YES == top->state.benchmarking)
436 && ((GNUNET_YES == me->master) || (GNUNET_YES == p->dest->master)))
438 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
439 "%s disconnected from %s while benchmarking \n", id, GNUNET_i2s (peer));
442 GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->tth);
447 GNUNET_CORE_notify_transmit_ready_cancel (p->cth);
456 core_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
458 struct BenchmarkPeer *me = cls;
460 me->ch = GNUNET_CORE_connect (cfg, me, NULL, comm_connect_cb,
461 comm_disconnect_cb, NULL, GNUNET_NO, NULL, GNUNET_NO, top->handlers);
463 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create core connection \n");
468 core_disconnect_adapter (void *cls, void *op_result)
470 struct BenchmarkPeer *me = cls;
472 GNUNET_CORE_disconnect (me->ch);
479 send_ping_ready_cb (void *cls, size_t size, void *buf)
481 struct BenchmarkPartner *p = cls;
482 static char msgbuf[TEST_MESSAGE_SIZE];
483 struct GNUNET_MessageHeader *msg;
490 if (size < TEST_MESSAGE_SIZE)
496 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Master [%u]: Sending PING to [%u]\n",
497 p->me->no, p->dest->no);
516 msg = (struct GNUNET_MessageHeader *) &msgbuf;
517 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
518 msg->type = htons (TEST_MESSAGE_TYPE_PING);
519 msg->size = htons (TEST_MESSAGE_SIZE);
520 memcpy (buf, msg, TEST_MESSAGE_SIZE);
523 p->bytes_sent += TEST_MESSAGE_SIZE;
524 p->me->total_messages_sent++;
525 p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
527 return TEST_MESSAGE_SIZE;
532 comm_schedule_send (struct BenchmarkPartner *p)
534 p->last_message_sent = GNUNET_TIME_absolute_get();
535 if (GNUNET_YES == top->test_core)
537 p->cth = GNUNET_CORE_notify_transmit_ready (
538 p->me->ch, GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, &p->dest->id,
539 TEST_MESSAGE_SIZE, &send_ping_ready_cb, p);
543 p->tth = GNUNET_TRANSPORT_notify_transmit_ready (
544 p->me->th, &p->dest->id, TEST_MESSAGE_SIZE, 0,GNUNET_TIME_UNIT_MINUTES,
545 &send_ping_ready_cb, p);
549 static struct TrafficGenerator *
550 find_tg (struct BenchmarkPartner *p)
552 struct TrafficGenerator *cur;
553 for (cur = tg_head; NULL != cur; cur = cur->next)
554 if ( (0 == memcmp (&p->me->id, &cur->dest->me, sizeof (cur->dest->me))) &&
555 (0 == memcmp (&p->dest->id, &cur->dest->dest->id, sizeof (cur->dest->dest->id))) )
562 core_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
563 const struct GNUNET_MessageHeader *message)
565 struct BenchmarkPeer *me = cls;
566 struct BenchmarkPartner *p = NULL;
567 struct TrafficGenerator *tg;
569 if (NULL == (p = find_partner (me, other)))
572 return GNUNET_SYSERR;
575 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
576 "Master [%u]: Received PONG from [%u], next message\n", me->no,
579 p->messages_received++;
580 p->bytes_received += TEST_MESSAGE_SIZE;
581 p->me->total_messages_received++;
582 p->me->total_bytes_received += TEST_MESSAGE_SIZE;
583 p->total_app_rtt += GNUNET_TIME_absolute_get_difference(p->last_message_sent,
584 GNUNET_TIME_absolute_get()).rel_value_us;
589 if (GNUNET_TIME_absolute_max(GNUNET_TIME_absolute_get(), tg->next_send))*/
590 comm_schedule_send (p);
595 comm_send_pong_ready (void *cls, size_t size, void *buf)
597 static char msgbuf[TEST_MESSAGE_SIZE];
598 struct BenchmarkPartner *p = cls;
599 struct GNUNET_MessageHeader *msg;
601 if (GNUNET_YES == top->test_core)
607 p->bytes_sent += TEST_MESSAGE_SIZE;
608 p->me->total_messages_sent++;
609 p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
611 msg = (struct GNUNET_MessageHeader *) &msgbuf;
612 memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
613 msg->type = htons (TEST_MESSAGE_TYPE_PONG);
614 msg->size = htons (TEST_MESSAGE_SIZE);
615 memcpy (buf, msg, TEST_MESSAGE_SIZE);
617 return TEST_MESSAGE_SIZE;
622 core_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
623 const struct GNUNET_MessageHeader *message)
625 struct BenchmarkPeer *me = cls;
626 struct BenchmarkPartner *p = NULL;
628 if (NULL == (p = find_partner(me, other)))
631 return GNUNET_SYSERR;
634 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
635 "Slave [%u]: Received PING from [%u], sending PONG\n", me->no,
638 p->messages_received++;
639 p->bytes_received += TEST_MESSAGE_SIZE;
640 p->me->total_messages_received++;
641 p->me->total_bytes_received += TEST_MESSAGE_SIZE;
643 if (GNUNET_YES == top->test_core)
645 GNUNET_assert (NULL == p->cth);
647 p->cth = GNUNET_CORE_notify_transmit_ready (me->ch, GNUNET_NO, 0,
648 GNUNET_TIME_UNIT_MINUTES, &p->dest->id, TEST_MESSAGE_SIZE,
649 &comm_send_pong_ready, p);
653 GNUNET_assert (NULL == p->tth);
654 p->tth = GNUNET_TRANSPORT_notify_transmit_ready (me->th, &p->dest->id,
655 TEST_MESSAGE_SIZE, 0, GNUNET_TIME_UNIT_MINUTES, &comm_send_pong_ready,
662 test_recv_cb (void *cls,
663 const struct GNUNET_PeerIdentity * peer,
664 const struct GNUNET_MessageHeader * message)
666 if (TEST_MESSAGE_SIZE != ntohs (message->size) ||
667 (TEST_MESSAGE_TYPE_PING != ntohs (message->type) &&
668 TEST_MESSAGE_TYPE_PONG != ntohs (message->type)))
672 if (TEST_MESSAGE_TYPE_PING == ntohs (message->type))
673 core_handle_ping (cls, peer, message);
674 if (TEST_MESSAGE_TYPE_PONG == ntohs (message->type))
675 core_handle_pong (cls, peer, message);
680 transport_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
682 struct BenchmarkPeer *me = cls;
684 me->th = GNUNET_TRANSPORT_connect (cfg, &me->id, me, &test_recv_cb,
685 &comm_connect_cb, &comm_disconnect_cb);
687 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create transport connection \n");
692 transport_disconnect_adapter (void *cls, void *op_result)
694 struct BenchmarkPeer *me = cls;
696 GNUNET_TRANSPORT_disconnect (me->th);
702 connect_completion_callback (void *cls, struct GNUNET_TESTBED_Operation *op,
705 struct TestbedConnectOperation *cop = cls;
710 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
711 _("Connected master [%u] with slave [%u]\n"), cop->master->no,
716 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
717 _("Failed to connect master peer [%u] with slave [%u]\n"),
718 cop->master->no, cop->slave->no);
720 if (GNUNET_SCHEDULER_NO_TASK != top->shutdown_task)
721 GNUNET_SCHEDULER_cancel (top->shutdown_task);
722 top->shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
724 GNUNET_TESTBED_operation_done (op);
726 for (c = 0; c < top->num_slaves; c++)
728 if (cop == &cop->master->core_connect_ops[c])
729 cop->master->core_connect_ops[c].connect_op = NULL;
731 if (ops == top->num_masters * top->num_slaves)
733 top->state.connected_PEERS = GNUNET_YES;
738 do_connect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
742 struct BenchmarkPeer *p;
744 if ((top->state.connected_ATS_service == GNUNET_NO) ||
745 (top->state.connected_COMM_service == GNUNET_NO))
748 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Connecting peers on CORE level\n"));
750 for (c_m = 0; c_m < top->num_masters; c_m++)
753 p->core_connect_ops = GNUNET_malloc (top->num_slaves *
754 sizeof (struct TestbedConnectOperation));
756 for (c_s = 0; c_s < top->num_slaves; c_s++)
758 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
759 _("Connecting master [%u] with slave [%u]\n"), p->no, top->sps[c_s].no);
760 p->core_connect_ops[c_s].master = p;
761 p->core_connect_ops[c_s].slave = &top->sps[c_s];
762 p->core_connect_ops[c_s].connect_op = GNUNET_TESTBED_overlay_connect (
763 NULL, &connect_completion_callback, &p->core_connect_ops[c_s],
764 top->sps[c_s].peer, p->peer);
765 if (NULL == p->core_connect_ops[c_s].connect_op)
767 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
768 _("Could not connect master [%u] and slave [%u]\n"), p->no,
771 if (GNUNET_SCHEDULER_NO_TASK != top->shutdown_task)
772 GNUNET_SCHEDULER_cancel (top->shutdown_task);
773 top->shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
782 comm_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
783 void *ca_result, const char *emsg)
785 static int comm_done = 0;
786 if ((NULL != emsg) || (NULL == ca_result))
788 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
790 if (GNUNET_SCHEDULER_NO_TASK != top->shutdown_task)
791 GNUNET_SCHEDULER_cancel (top->shutdown_task);
792 top->shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
797 if (comm_done == top->num_slaves + top->num_masters)
799 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all %s services\n",
800 (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT");
801 top->state.connected_COMM_service = GNUNET_YES;
802 GNUNET_SCHEDULER_add_now (&do_connect_peers, NULL );
807 do_comm_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
811 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all %s services\n",
812 (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT");
813 for (c_m = 0; c_m < top->num_masters; c_m++)
815 if (GNUNET_YES == top->test_core)
816 top->mps[c_m].comm_op = GNUNET_TESTBED_service_connect (NULL, top->mps[c_m].peer,
817 "core", &comm_connect_completion_cb, NULL, &core_connect_adapter,
818 &core_disconnect_adapter, &top->mps[c_m]);
821 top->mps[c_m].comm_op = GNUNET_TESTBED_service_connect (NULL, top->mps[c_m].peer,
822 "transport", &comm_connect_completion_cb, NULL, &transport_connect_adapter,
823 &transport_disconnect_adapter, &top->mps[c_m]);
827 for (c_s = 0; c_s < top->num_slaves; c_s++)
829 if (GNUNET_YES == top->test_core)
830 top->sps[c_s].comm_op = GNUNET_TESTBED_service_connect (NULL, top->sps[c_s].peer,
831 "core", &comm_connect_completion_cb, NULL, &core_connect_adapter,
832 &core_disconnect_adapter, &top->sps[c_s]);
835 top->sps[c_s].comm_op = GNUNET_TESTBED_service_connect (NULL, top->sps[c_s].peer,
836 "transport", &comm_connect_completion_cb, NULL, &transport_connect_adapter,
837 &transport_disconnect_adapter, &top->sps[c_s]);
843 ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
844 int address_active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
845 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
846 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
848 struct BenchmarkPeer *me = cls;
849 struct BenchmarkPartner *p;
854 p = find_partner (me, &address->peer);
857 /* This is not one of my partners
858 * Will happen since the peers will connect to each other due to gossiping
862 peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
865 if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) ||
866 (p->bandwidth_out != ntohl (bandwidth_out.value__)))
868 p->bandwidth_in = ntohl (bandwidth_in.value__);
869 p->bandwidth_out = ntohl (bandwidth_out.value__);
871 for (c_a = 0; c_a < ats_count; c_a++)
873 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s [%u] received ATS information: %s %s %u\n",
874 (GNUNET_YES == p->me->master) ? "Master" : "Slave",
876 GNUNET_i2s (&p->dest->id),
877 GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)),
878 ntohl(ats[c_a].value));
879 switch (ntohl (ats[c_a].type ))
881 case GNUNET_ATS_ARRAY_TERMINATOR:
883 case GNUNET_ATS_UTILIZATION_OUT:
884 if (p->ats_utilization_up != ntohl (ats[c_a].value))
886 p->ats_utilization_up = ntohl (ats[c_a].value);
889 case GNUNET_ATS_UTILIZATION_IN:
890 if (p->ats_utilization_down != ntohl (ats[c_a].value))
892 p->ats_utilization_down = ntohl (ats[c_a].value);
894 case GNUNET_ATS_NETWORK_TYPE:
895 if (p->ats_network_type != ntohl (ats[c_a].value))
897 p->ats_network_type = ntohl (ats[c_a].value);
899 case GNUNET_ATS_QUALITY_NET_DELAY:
900 if (p->ats_delay != ntohl (ats[c_a].value))
902 p->ats_delay = ntohl (ats[c_a].value);
904 case GNUNET_ATS_QUALITY_NET_DISTANCE:
905 if (p->ats_distance != ntohl (ats[c_a].value))
907 p->ats_distance = ntohl (ats[c_a].value);
910 case GNUNET_ATS_COST_WAN:
911 if (p->ats_cost_wan != ntohl (ats[c_a].value))
913 p->ats_cost_wan = ntohl (ats[c_a].value);
915 case GNUNET_ATS_COST_LAN:
916 if (p->ats_cost_lan != ntohl (ats[c_a].value))
918 p->ats_cost_lan = ntohl (ats[c_a].value);
920 case GNUNET_ATS_COST_WLAN:
921 if (p->ats_cost_wlan != ntohl (ats[c_a].value))
923 p->ats_cost_wlan = ntohl (ats[c_a].value);
929 if ((GNUNET_YES == top->logging) && (GNUNET_YES == log))
930 GNUNET_ATS_TEST_logging_now();
932 top->ats_perf_cb (cls, address, address_active, bandwidth_out, bandwidth_in,
934 GNUNET_free(peer_id);
939 ats_perf_connect_adapter (void *cls,
940 const struct GNUNET_CONFIGURATION_Handle *cfg)
942 struct BenchmarkPeer *me = cls;
944 me->ats_perf_handle = GNUNET_ATS_performance_init (cfg, ats_performance_info_cb, me);
945 if (NULL == me->ats_perf_handle)
946 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
947 "Failed to create ATS performance handle \n");
948 return me->ats_perf_handle;
952 ats_perf_disconnect_adapter (void *cls, void *op_result)
954 struct BenchmarkPeer *me = cls;
956 GNUNET_ATS_performance_done (me->ats_perf_handle);
957 me->ats_perf_handle = NULL;
961 ats_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
962 void *ca_result, const char *emsg)
964 static int op_done = 0;
966 if ((NULL != emsg) || (NULL == ca_result))
968 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
970 if (GNUNET_SCHEDULER_NO_TASK != top->shutdown_task)
971 GNUNET_SCHEDULER_cancel (top->shutdown_task);
972 top->shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
976 if (op_done == (top->num_masters + top->num_slaves))
978 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all ATS services\n");
979 top->state.connected_ATS_service = GNUNET_YES;
980 GNUNET_SCHEDULER_add_now (&do_comm_connect, NULL );
986 do_connect_ats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
991 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all ATS services\n");
992 for (c_m = 0; c_m < top->num_masters; c_m++)
994 top->mps[c_m].ats_perf_op = GNUNET_TESTBED_service_connect (NULL,
996 "ats", ats_connect_completion_cb, NULL,
997 &ats_perf_connect_adapter,
998 &ats_perf_disconnect_adapter, &top->mps[c_m]);
1001 for (c_s = 0; c_s < top->num_slaves; c_s++)
1003 top->sps[c_s].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, top->sps[c_s].peer,
1004 "ats", ats_connect_completion_cb, NULL, &ats_perf_connect_adapter,
1005 &ats_perf_disconnect_adapter, &top->sps[c_s]);
1012 peerinformation_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op,
1013 const struct GNUNET_TESTBED_PeerInformation*pinfo, const char *emsg)
1015 struct BenchmarkPeer *p = cb_cls;
1016 static int done = 0;
1018 GNUNET_assert(pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY);
1020 p->id = *pinfo->result.id;
1021 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%s [%u] has peer id `%s'\n",
1022 (p->master == GNUNET_YES) ? "Master" : "Slave", p->no,
1023 GNUNET_i2s (&p->id));
1025 GNUNET_TESTBED_operation_done (op);
1026 p->peer_id_op = NULL;
1029 if (done == top->num_slaves + top->num_masters)
1031 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1032 "Retrieved all peer ID, connect to ATS\n");
1033 GNUNET_SCHEDULER_add_now (&do_connect_ats, NULL );
1038 * Signature of a main function for a testcase.
1040 * @param cls closure
1041 * @param num_peers number of peers in 'peers'
1042 * @param peers_ handle to peers run in the testbed
1043 * @param links_succeeded the number of overlay link connection attempts that
1045 * @param links_failed the number of overlay link connection attempts that
1049 main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h,
1050 unsigned int num_peers,
1051 struct GNUNET_TESTBED_Peer **peers_,
1052 unsigned int links_succeeded,
1053 unsigned int links_failed)
1057 GNUNET_assert(NULL == cls);
1058 GNUNET_assert(top->num_masters + top->num_slaves == num_peers);
1059 GNUNET_assert(NULL != peers_);
1061 top->shutdown_task = GNUNET_SCHEDULER_add_delayed (
1062 GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown, top);
1064 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Setting up %u masters and %u slaves\n",
1065 top->num_masters, top->num_slaves);
1067 /* Setup master peers */
1068 for (c_m = 0; c_m < top->num_masters; c_m++)
1070 GNUNET_assert(NULL != peers_[c_m]);
1071 top->mps[c_m].peer = peers_[c_m];
1072 top->mps[c_m].no = c_m;
1073 top->mps[c_m].master = GNUNET_YES;
1074 top->mps[c_m].pref_partner = &top->sps[c_m];
1075 top->mps[c_m].pref_value = TEST_ATS_PREFERENCE_DEFAULT;
1076 top->mps[c_m].partners =
1077 GNUNET_malloc (top->num_slaves * sizeof (struct BenchmarkPartner));
1078 top->mps[c_m].num_partners = top->num_slaves;
1079 /* Initialize partners */
1080 for (c_s = 0; c_s < top->num_slaves; c_s++)
1082 top->mps[c_m].partners[c_s].me = &top->mps[c_m];
1083 top->mps[c_m].partners[c_s].dest = &top->sps[c_s];
1085 /* Get configuration */
1086 top->mps[c_m].peer_id_op = GNUNET_TESTBED_peer_get_information (top->mps[c_m].peer,
1087 GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &top->mps[c_m]);
1090 /* Setup slave peers */
1091 for (c_s = 0; c_s < top->num_slaves; c_s++)
1093 GNUNET_assert(NULL != peers_[c_s + top->num_masters]);
1094 top->sps[c_s].peer = peers_[c_s + top->num_masters];
1095 top->sps[c_s].no = c_s + top->num_masters;
1096 top->sps[c_s].master = GNUNET_NO;
1097 top->sps[c_s].partners =
1098 GNUNET_malloc (top->num_masters * sizeof (struct BenchmarkPartner));
1099 top->sps[c_s].num_partners = top->num_masters;
1100 /* Initialize partners */
1101 for (c_m = 0; c_m < top->num_masters; c_m++)
1103 top->sps[c_s].partners[c_m].me = &top->sps[c_s];
1104 top->sps[c_s].partners[c_m].dest = &top->mps[c_m];
1106 /* Get configuration */
1107 top->sps[c_s].peer_id_op = GNUNET_TESTBED_peer_get_information (top->sps[c_s].peer,
1108 GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &top->sps[c_s]);
1113 * Controller event callback
1116 * @param event the controller event
1119 controller_event_cb (void *cls,
1120 const struct GNUNET_TESTBED_EventInformation *event)
1122 struct GNUNET_ATS_TEST_Topology *top = cls;
1123 switch (event->type)
1125 case GNUNET_TESTBED_ET_CONNECT:
1127 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
1131 GNUNET_SCHEDULER_cancel (top->shutdown_task);
1132 top->shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL );
1138 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
1139 unsigned int num_slaves,
1140 unsigned int num_masters,
1142 GNUNET_ATS_TESTING_TopologySetupDoneCallback done_cb,
1144 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb,
1145 GNUNET_ATS_AddressInformationCallback ats_perf_cb)
1148 static struct GNUNET_CORE_MessageHandler handlers[] = {
1149 {&core_handle_ping, TEST_MESSAGE_TYPE_PING, 0 },
1150 {&core_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 },
1153 top = GNUNET_new (struct GNUNET_ATS_TEST_Topology);
1154 top->num_masters = num_masters;
1155 top->num_slaves = num_slaves;
1156 top->handlers = handlers;
1157 top->done_cb = done_cb;
1158 top->done_cb_cls = done_cb_cls;
1159 top->test_core = test_core;
1160 top->transport_recv_cb = transport_recv_cb;
1161 top->ats_perf_cb = ats_perf_cb;
1163 top->mps = GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer));
1164 top->sps = GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer));
1166 /* Start topology */
1167 uint64_t event_mask;
1169 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
1170 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
1171 (void) GNUNET_TESTBED_test_run (name, cfg_file,
1172 num_slaves + num_masters, event_mask, &controller_event_cb, NULL,
1177 GNUNET_ATS_TEST_shutdown_topology (void)
1182 GNUNET_SCHEDULER_shutdown();
1187 struct TrafficGenerator *
1188 GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
1189 struct BenchmarkPartner *dest, unsigned int rate,
1190 struct GNUNET_TIME_Relative duration)
1192 struct TrafficGenerator * tg;
1195 tg = GNUNET_new (struct TrafficGenerator);
1196 GNUNET_CONTAINER_DLL_insert (tg_head, tg_tail, tg);
1201 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1202 "Setting up traffic generator between master[%u] `%s' and slave [%u] `%s' sending with %u Bytes/sec\n",
1203 dest->me->no, GNUNET_i2s (&dest->me->id),
1204 dest->dest->no, GNUNET_i2s (&dest->dest->id),
1209 if (NULL != dest->cth)
1214 dest->cth = GNUNET_CORE_notify_transmit_ready (src->ch, GNUNET_NO,
1215 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, &dest->dest->id,
1216 TEST_MESSAGE_SIZE, &send_ping_ready_cb, dest);
1220 if (NULL != dest->tth)
1225 dest->tth = GNUNET_TRANSPORT_notify_transmit_ready (src->th, &dest->dest->id,
1226 TEST_MESSAGE_SIZE, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
1227 &send_ping_ready_cb, dest);
1228 tg->last_sent = GNUNET_TIME_absolute_get();
1229 tg->delta.rel_value_us = (GNUNET_TIME_UNIT_SECONDS.rel_value_us / (rate / TEST_MESSAGE_SIZE));
1235 GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg)
1237 GNUNET_CONTAINER_DLL_remove (tg_head, tg_tail, tg);
1241 if (NULL != tg->dest->cth)
1243 GNUNET_CORE_notify_transmit_ready_cancel (tg->dest->cth);
1244 tg->dest->cth = NULL;
1249 if (NULL != tg->dest->tth)
1251 GNUNET_TRANSPORT_notify_transmit_ready_cancel (tg->dest->tth);
1252 tg->dest->tth = NULL;
1258 /* end of file ats-testing.c */