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
24 * @author Christian Grothoff
25 * @author Matthias Wachs
27 #include "ats-testing.h"
31 * Connect peers with testbed
33 struct TestbedConnectOperation
36 * The benchmarking master initiating this connection
38 struct BenchmarkPeer *master;
41 * The benchmarking slave to connect to
43 struct BenchmarkPeer *slave;
46 * Testbed operation to connect peers
48 struct GNUNET_TESTBED_Operation *connect_op;
51 struct GNUNET_CONFIGURATION_Handle *cfg;
53 struct GNUNET_ATS_TEST_Topology *top;
59 * @param tc the task context
62 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
67 struct BenchmarkPeer *p;
69 top->shutdown_task = GNUNET_SCHEDULER_NO_TASK;
70 top->state.benchmarking = GNUNET_NO;
72 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n"));
74 GNUNET_ATS_TEST_generate_traffic_stop_all ();
76 for (c_m = 0; c_m < top->num_masters; c_m++)
79 if (NULL != top->mps[c_m].peer_id_op)
81 GNUNET_TESTBED_operation_done (p->peer_id_op);
85 if (GNUNET_SCHEDULER_NO_TASK != p->ats_task)
86 GNUNET_SCHEDULER_cancel (p->ats_task);
87 p->ats_task = GNUNET_SCHEDULER_NO_TASK;
89 for (c_op = 0; c_op < p->num_partners; c_op++)
91 if (NULL != p->partners[c_op].cth)
93 GNUNET_CORE_notify_transmit_ready_cancel (p->partners[c_op].cth);
94 p->partners[c_op].cth = NULL;
96 if (NULL != p->partners[c_op].tth)
98 GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->partners[c_op].tth);
99 p->partners[c_op].tth = NULL;
101 if ( (NULL != p->core_connect_ops) &&
102 (NULL != p->core_connect_ops[c_op].connect_op) )
104 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
105 _("Failed to connect peer 0 and %u\n"), c_op);
106 GNUNET_TESTBED_operation_done (
107 p->core_connect_ops[c_op].connect_op);
108 p->core_connect_ops[c_op].connect_op = NULL;
112 if (NULL != p->ats_perf_op)
114 GNUNET_TESTBED_operation_done (p->ats_perf_op);
115 p->ats_perf_op = NULL;
118 if (NULL != p->comm_op)
120 GNUNET_TESTBED_operation_done (p->comm_op);
123 GNUNET_free_non_null (p->core_connect_ops);
124 GNUNET_free(p->partners);
128 for (c_s = 0; c_s < top->num_slaves; c_s++)
131 if (NULL != p->peer_id_op)
133 GNUNET_TESTBED_operation_done (p->peer_id_op);
134 p->peer_id_op = NULL;
137 for (c_op = 0; c_op < p->num_partners; c_op++)
139 if (NULL != p->partners[c_op].cth)
141 GNUNET_CORE_notify_transmit_ready_cancel (p->partners[c_op].cth);
142 p->partners[c_op].cth = NULL;
144 if (NULL != p->partners[c_op].tth)
146 GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->partners[c_op].tth);
147 p->partners[c_op].tth = NULL;
150 if (NULL != p->ats_perf_op)
152 GNUNET_TESTBED_operation_done (p->ats_perf_op);
153 p->ats_perf_op = NULL;
155 if (NULL != p->comm_op)
157 GNUNET_TESTBED_operation_done (p->comm_op);
160 GNUNET_free(p->partners);
163 GNUNET_SCHEDULER_shutdown ();
168 static struct BenchmarkPartner *
169 find_partner (struct BenchmarkPeer *me, const struct GNUNET_PeerIdentity * peer)
172 GNUNET_assert (NULL != me);
173 GNUNET_assert (NULL != peer);
175 for (c_m = 0; c_m < me->num_partners; c_m++)
177 /* Find a partner with other as destination */
178 if (0 == memcmp (peer, &me->partners[c_m].dest->id,
179 sizeof(struct GNUNET_PeerIdentity)))
181 return &me->partners[c_m];
189 static struct BenchmarkPeer *
190 find_peer (const struct GNUNET_PeerIdentity * peer)
194 for (c_p = 0; c_p < top->num_masters; c_p++)
196 if (0 == memcmp (&top->mps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity)))
197 return &top->mps[c_p];
200 for (c_p = 0; c_p < top->num_slaves; c_p++)
202 if (0 == memcmp (&top->sps[c_p].id, peer, sizeof(struct GNUNET_PeerIdentity)))
203 return &top->sps[c_p];
210 * Method called whenever a given peer connects.
213 * @param peer peer identity this notification is about
216 comm_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
218 struct BenchmarkPeer *me = cls;
219 struct BenchmarkPeer *remote;
224 remote = find_peer (peer);
227 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unknown peer connected: `%s'\n", GNUNET_i2s (peer));
232 id = GNUNET_strdup (GNUNET_i2s (&me->id));
233 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s [%u] `%s' connected to %s [%u] %s\n",
234 (me->master == GNUNET_YES) ? "Master": "Slave", me->no, id,
235 (remote->master == GNUNET_YES) ? "Master": "Slave", remote->no,
238 me->core_connections++;
239 if ((GNUNET_YES == me->master) && (GNUNET_NO == remote->master)
240 && (GNUNET_NO == top->state.connected_CORE))
242 me->core_slave_connections++;
244 if (me->core_slave_connections == top->num_slaves)
246 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Master [%u] connected all slaves\n",
249 completed = GNUNET_YES;
250 for (c = 0; c < top->num_masters; c++)
252 if (top->mps[c].core_slave_connections != top->num_slaves)
253 completed = GNUNET_NO;
255 if (GNUNET_YES == completed)
257 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
258 "All master peers connected all slave peers\n", id,
260 top->state.connected_CORE = GNUNET_YES;
261 /* Notify about setup done */
262 if (NULL != top->done_cb)
263 top->done_cb (top->done_cb_cls, top->mps, top->sps);
270 comm_disconnect_cb (void *cls, const struct GNUNET_PeerIdentity * peer)
272 struct BenchmarkPeer *me = cls;
273 struct BenchmarkPartner *p;
276 if (NULL == (p = find_partner (me, peer)))
279 id = GNUNET_strdup (GNUNET_i2s (&me->id));
280 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s disconnected from %s \n", id,
282 GNUNET_assert(me->core_connections > 0);
283 me->core_connections--;
285 if ((GNUNET_YES == top->state.benchmarking)
286 && ((GNUNET_YES == me->master) || (GNUNET_YES == p->dest->master)))
288 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
289 "%s disconnected from %s while benchmarking \n", id, GNUNET_i2s (peer));
292 GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->tth);
297 GNUNET_CORE_notify_transmit_ready_cancel (p->cth);
306 core_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
308 struct BenchmarkPeer *me = cls;
310 me->ch = GNUNET_CORE_connect (cfg, me, NULL, comm_connect_cb,
311 comm_disconnect_cb, NULL, GNUNET_NO, NULL, GNUNET_NO, top->handlers);
313 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create core connection \n");
318 core_disconnect_adapter (void *cls, void *op_result)
320 struct BenchmarkPeer *me = cls;
322 GNUNET_CORE_disconnect (me->ch);
330 comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
331 const struct GNUNET_MessageHeader *message)
333 struct BenchmarkPeer *me = cls;
334 struct BenchmarkPartner *p = NULL;
336 if (NULL == (p = find_partner (me, other)))
339 return GNUNET_SYSERR;
342 GNUNET_ATS_TEST_traffic_handle_pong (p);
348 comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
349 const struct GNUNET_MessageHeader *message)
351 struct BenchmarkPeer *me = cls;
352 struct BenchmarkPartner *p = NULL;
354 if (NULL == (p = find_partner(me, other)))
357 return GNUNET_SYSERR;
359 GNUNET_ATS_TEST_traffic_handle_ping (p);
364 test_recv_cb (void *cls,
365 const struct GNUNET_PeerIdentity * peer,
366 const struct GNUNET_MessageHeader * message)
368 if (TEST_MESSAGE_SIZE != ntohs (message->size) ||
369 (TEST_MESSAGE_TYPE_PING != ntohs (message->type) &&
370 TEST_MESSAGE_TYPE_PONG != ntohs (message->type)))
374 if (TEST_MESSAGE_TYPE_PING == ntohs (message->type))
375 comm_handle_ping (cls, peer, message);
376 if (TEST_MESSAGE_TYPE_PONG == ntohs (message->type))
377 comm_handle_pong (cls, peer, message);
382 transport_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
384 struct BenchmarkPeer *me = cls;
386 me->th = GNUNET_TRANSPORT_connect (cfg, &me->id, me, &test_recv_cb,
387 &comm_connect_cb, &comm_disconnect_cb);
389 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create transport connection \n");
394 transport_disconnect_adapter (void *cls, void *op_result)
396 struct BenchmarkPeer *me = cls;
398 GNUNET_TRANSPORT_disconnect (me->th);
404 connect_completion_callback (void *cls, struct GNUNET_TESTBED_Operation *op,
407 struct TestbedConnectOperation *cop = cls;
412 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
413 _("Connected master [%u] with slave [%u]\n"), cop->master->no,
418 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
419 _("Failed to connect master peer [%u] with slave [%u]\n"),
420 cop->master->no, cop->slave->no);
422 if (GNUNET_SCHEDULER_NO_TASK != top->shutdown_task)
423 GNUNET_SCHEDULER_cancel (top->shutdown_task);
424 top->shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
426 GNUNET_TESTBED_operation_done (op);
428 for (c = 0; c < top->num_slaves; c++)
430 if (cop == &cop->master->core_connect_ops[c])
431 cop->master->core_connect_ops[c].connect_op = NULL;
433 if (ops == top->num_masters * top->num_slaves)
435 top->state.connected_PEERS = GNUNET_YES;
440 do_connect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
444 struct BenchmarkPeer *p;
446 if ((top->state.connected_ATS_service == GNUNET_NO) ||
447 (top->state.connected_COMM_service == GNUNET_NO))
450 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Connecting peers on CORE level\n"));
452 for (c_m = 0; c_m < top->num_masters; c_m++)
455 p->core_connect_ops = GNUNET_malloc (top->num_slaves *
456 sizeof (struct TestbedConnectOperation));
458 for (c_s = 0; c_s < top->num_slaves; c_s++)
460 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
461 _("Connecting master [%u] with slave [%u]\n"), p->no, top->sps[c_s].no);
462 p->core_connect_ops[c_s].master = p;
463 p->core_connect_ops[c_s].slave = &top->sps[c_s];
464 p->core_connect_ops[c_s].connect_op = GNUNET_TESTBED_overlay_connect (
465 NULL, &connect_completion_callback, &p->core_connect_ops[c_s],
466 top->sps[c_s].peer, p->peer);
467 if (NULL == p->core_connect_ops[c_s].connect_op)
469 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
470 _("Could not connect master [%u] and slave [%u]\n"), p->no,
473 if (GNUNET_SCHEDULER_NO_TASK != top->shutdown_task)
474 GNUNET_SCHEDULER_cancel (top->shutdown_task);
475 top->shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
484 comm_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
485 void *ca_result, const char *emsg)
487 static int comm_done = 0;
488 if ((NULL != emsg) || (NULL == ca_result))
490 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
492 if (GNUNET_SCHEDULER_NO_TASK != top->shutdown_task)
493 GNUNET_SCHEDULER_cancel (top->shutdown_task);
494 top->shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
499 if (comm_done == top->num_slaves + top->num_masters)
501 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all %s services\n",
502 (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT");
503 top->state.connected_COMM_service = GNUNET_YES;
504 GNUNET_SCHEDULER_add_now (&do_connect_peers, NULL );
509 do_comm_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
513 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all %s services\n",
514 (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT");
515 for (c_m = 0; c_m < top->num_masters; c_m++)
517 if (GNUNET_YES == top->test_core)
518 top->mps[c_m].comm_op = GNUNET_TESTBED_service_connect (NULL, top->mps[c_m].peer,
519 "core", &comm_connect_completion_cb, NULL, &core_connect_adapter,
520 &core_disconnect_adapter, &top->mps[c_m]);
523 top->mps[c_m].comm_op = GNUNET_TESTBED_service_connect (NULL, top->mps[c_m].peer,
524 "transport", &comm_connect_completion_cb, NULL, &transport_connect_adapter,
525 &transport_disconnect_adapter, &top->mps[c_m]);
529 for (c_s = 0; c_s < top->num_slaves; c_s++)
531 if (GNUNET_YES == top->test_core)
532 top->sps[c_s].comm_op = GNUNET_TESTBED_service_connect (NULL, top->sps[c_s].peer,
533 "core", &comm_connect_completion_cb, NULL, &core_connect_adapter,
534 &core_disconnect_adapter, &top->sps[c_s]);
537 top->sps[c_s].comm_op = GNUNET_TESTBED_service_connect (NULL, top->sps[c_s].peer,
538 "transport", &comm_connect_completion_cb, NULL, &transport_connect_adapter,
539 &transport_disconnect_adapter, &top->sps[c_s]);
545 ats_performance_info_cb (void *cls,
546 const struct GNUNET_HELLO_Address *address,
548 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
549 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
550 const struct GNUNET_ATS_Information *ats,
553 struct BenchmarkPeer *me = cls;
554 struct BenchmarkPartner *p;
561 p = find_partner (me, &address->peer);
564 /* This is not one of my partners
565 * Will happen since the peers will connect to each other due to gossiping
569 peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
572 if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) ||
573 (p->bandwidth_out != ntohl (bandwidth_out.value__)))
575 p->bandwidth_in = ntohl (bandwidth_in.value__);
576 p->bandwidth_out = ntohl (bandwidth_out.value__);
578 for (c_a = 0; c_a < ats_count; c_a++)
580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s [%u] received ATS information: %s %s %u\n",
581 (GNUNET_YES == p->me->master) ? "Master" : "Slave",
583 GNUNET_i2s (&p->dest->id),
584 GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)),
585 ntohl(ats[c_a].value));
586 switch (ntohl (ats[c_a].type ))
588 case GNUNET_ATS_ARRAY_TERMINATOR:
590 case GNUNET_ATS_UTILIZATION_OUT:
591 if (p->ats_utilization_up != ntohl (ats[c_a].value))
593 p->ats_utilization_up = ntohl (ats[c_a].value);
596 case GNUNET_ATS_UTILIZATION_IN:
597 if (p->ats_utilization_down != ntohl (ats[c_a].value))
599 p->ats_utilization_down = ntohl (ats[c_a].value);
601 case GNUNET_ATS_NETWORK_TYPE:
602 if (p->ats_network_type != ntohl (ats[c_a].value))
604 p->ats_network_type = ntohl (ats[c_a].value);
606 case GNUNET_ATS_QUALITY_NET_DELAY:
607 if (p->ats_delay != ntohl (ats[c_a].value))
609 p->ats_delay = ntohl (ats[c_a].value);
611 case GNUNET_ATS_QUALITY_NET_DISTANCE:
612 if (p->ats_distance != ntohl (ats[c_a].value))
614 p->ats_distance = ntohl (ats[c_a].value);
617 case GNUNET_ATS_COST_WAN:
618 if (p->ats_cost_wan != ntohl (ats[c_a].value))
620 p->ats_cost_wan = ntohl (ats[c_a].value);
622 case GNUNET_ATS_COST_LAN:
623 if (p->ats_cost_lan != ntohl (ats[c_a].value))
625 p->ats_cost_lan = ntohl (ats[c_a].value);
627 case GNUNET_ATS_COST_WLAN:
628 if (p->ats_cost_wlan != ntohl (ats[c_a].value))
630 p->ats_cost_wlan = ntohl (ats[c_a].value);
636 if (GNUNET_YES == log)
637 top->ats_perf_cb (cls, address, address_active, bandwidth_out, bandwidth_in,
639 GNUNET_free(peer_id);
644 ats_perf_connect_adapter (void *cls,
645 const struct GNUNET_CONFIGURATION_Handle *cfg)
647 struct BenchmarkPeer *me = cls;
649 me->ats_perf_handle = GNUNET_ATS_performance_init (cfg, ats_performance_info_cb, me);
650 if (NULL == me->ats_perf_handle)
651 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
652 "Failed to create ATS performance handle \n");
653 return me->ats_perf_handle;
657 ats_perf_disconnect_adapter (void *cls, void *op_result)
659 struct BenchmarkPeer *me = cls;
661 GNUNET_ATS_performance_done (me->ats_perf_handle);
662 me->ats_perf_handle = NULL;
666 ats_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
667 void *ca_result, const char *emsg)
669 static int op_done = 0;
671 if ((NULL != emsg) || (NULL == ca_result))
673 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
675 if (GNUNET_SCHEDULER_NO_TASK != top->shutdown_task)
676 GNUNET_SCHEDULER_cancel (top->shutdown_task);
677 top->shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
681 if (op_done == (top->num_masters + top->num_slaves))
683 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all ATS services\n");
684 top->state.connected_ATS_service = GNUNET_YES;
685 GNUNET_SCHEDULER_add_now (&do_comm_connect, NULL );
691 do_connect_ats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
696 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connecting to all ATS services\n");
697 for (c_m = 0; c_m < top->num_masters; c_m++)
699 top->mps[c_m].ats_perf_op = GNUNET_TESTBED_service_connect (NULL,
701 "ats", ats_connect_completion_cb, NULL,
702 &ats_perf_connect_adapter,
703 &ats_perf_disconnect_adapter, &top->mps[c_m]);
706 for (c_s = 0; c_s < top->num_slaves; c_s++)
708 top->sps[c_s].ats_perf_op = GNUNET_TESTBED_service_connect (NULL, top->sps[c_s].peer,
709 "ats", ats_connect_completion_cb, NULL, &ats_perf_connect_adapter,
710 &ats_perf_disconnect_adapter, &top->sps[c_s]);
717 peerinformation_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op,
718 const struct GNUNET_TESTBED_PeerInformation*pinfo, const char *emsg)
720 struct BenchmarkPeer *p = cb_cls;
723 GNUNET_assert(pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY);
725 p->id = *pinfo->result.id;
726 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%s [%u] has peer id `%s'\n",
727 (p->master == GNUNET_YES) ? "Master" : "Slave", p->no,
728 GNUNET_i2s (&p->id));
730 GNUNET_TESTBED_operation_done (op);
731 p->peer_id_op = NULL;
734 if (done == top->num_slaves + top->num_masters)
736 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
737 "Retrieved all peer ID, connect to ATS\n");
738 GNUNET_SCHEDULER_add_now (&do_connect_ats, NULL );
743 * Signature of a main function for a testcase.
746 * @param h testbed handle
747 * @param num_peers number of peers in 'peers'
748 * @param peers_ handle to peers run in the testbed
749 * @param links_succeeded the number of overlay link connection attempts that
751 * @param links_failed the number of overlay link connection attempts that
755 main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h,
756 unsigned int num_peers,
757 struct GNUNET_TESTBED_Peer **peers_,
758 unsigned int links_succeeded,
759 unsigned int links_failed)
763 GNUNET_assert(NULL == cls);
764 GNUNET_assert(top->num_masters + top->num_slaves == num_peers);
765 GNUNET_assert(NULL != peers_);
767 top->shutdown_task = GNUNET_SCHEDULER_add_delayed (
768 GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown, top);
770 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Setting up %u masters and %u slaves\n",
771 top->num_masters, top->num_slaves);
773 /* Setup master peers */
774 for (c_m = 0; c_m < top->num_masters; c_m++)
776 GNUNET_assert(NULL != peers_[c_m]);
777 top->mps[c_m].peer = peers_[c_m];
778 top->mps[c_m].no = c_m;
779 top->mps[c_m].master = GNUNET_YES;
780 top->mps[c_m].pref_partner = &top->sps[c_m];
781 top->mps[c_m].pref_value = TEST_ATS_PREFERENCE_DEFAULT;
782 top->mps[c_m].partners =
783 GNUNET_malloc (top->num_slaves * sizeof (struct BenchmarkPartner));
784 top->mps[c_m].num_partners = top->num_slaves;
785 /* Initialize partners */
786 for (c_s = 0; c_s < top->num_slaves; c_s++)
788 top->mps[c_m].partners[c_s].me = &top->mps[c_m];
789 top->mps[c_m].partners[c_s].dest = &top->sps[c_s];
791 /* Get configuration */
792 top->mps[c_m].peer_id_op = GNUNET_TESTBED_peer_get_information (top->mps[c_m].peer,
793 GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &top->mps[c_m]);
796 /* Setup slave peers */
797 for (c_s = 0; c_s < top->num_slaves; c_s++)
799 GNUNET_assert(NULL != peers_[c_s + top->num_masters]);
800 top->sps[c_s].peer = peers_[c_s + top->num_masters];
801 top->sps[c_s].no = c_s + top->num_masters;
802 top->sps[c_s].master = GNUNET_NO;
803 top->sps[c_s].partners =
804 GNUNET_malloc (top->num_masters * sizeof (struct BenchmarkPartner));
805 top->sps[c_s].num_partners = top->num_masters;
806 /* Initialize partners */
807 for (c_m = 0; c_m < top->num_masters; c_m++)
809 top->sps[c_s].partners[c_m].me = &top->sps[c_s];
810 top->sps[c_s].partners[c_m].dest = &top->mps[c_m];
812 /* Get configuration */
813 top->sps[c_s].peer_id_op = GNUNET_TESTBED_peer_get_information (top->sps[c_s].peer,
814 GNUNET_TESTBED_PIT_IDENTITY, &peerinformation_cb, &top->sps[c_s]);
819 * Controller event callback
822 * @param event the controller event
825 controller_event_cb (void *cls,
826 const struct GNUNET_TESTBED_EventInformation *event)
828 struct GNUNET_ATS_TEST_Topology *top = cls;
831 case GNUNET_TESTBED_ET_CONNECT:
833 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
837 GNUNET_SCHEDULER_cancel (top->shutdown_task);
838 top->shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL );
842 struct BenchmarkPeer *
843 GNUNET_ATS_TEST_get_peer (int src)
845 if (src > top->num_masters)
847 return &top->mps[src];
850 struct BenchmarkPartner *
851 GNUNET_ATS_TEST_get_partner (int src, int dest)
853 if (src > top->num_masters)
855 if (dest > top->num_slaves)
857 return &top->mps[src].partners[dest];
861 * Create a topology for ats testing
863 * @param name test name
864 * @param cfg_file configuration file to use for the peers
865 * @param num_slaves number of slaves
866 * @param num_masters number of masters
867 * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
868 * @param done_cb function to call when topology is setup
869 * @param done_cb_cls cls for callback
870 * @param transport_recv_cb callback to call when data are received
871 * @param log_request_cb callback to call when logging is required
874 GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
875 unsigned int num_slaves,
876 unsigned int num_masters,
878 GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
880 GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb,
881 GNUNET_ATS_AddressInformationCallback log_request_cb)
884 static struct GNUNET_CORE_MessageHandler handlers[] = {
885 {&comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 },
886 {&comm_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 },
889 top = GNUNET_new (struct GNUNET_ATS_TEST_Topology);
890 top->num_masters = num_masters;
891 top->num_slaves = num_slaves;
892 top->handlers = handlers;
893 top->done_cb = done_cb;
894 top->done_cb_cls = done_cb_cls;
895 top->test_core = test_core;
896 top->transport_recv_cb = transport_recv_cb;
897 top->ats_perf_cb = log_request_cb;
899 top->mps = GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer));
900 top->sps = GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer));
905 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
906 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
907 (void) GNUNET_TESTBED_test_run (name, cfg_file,
908 num_slaves + num_masters, event_mask, &controller_event_cb, NULL,
916 GNUNET_ATS_TEST_shutdown_topology (void)
921 GNUNET_SCHEDULER_shutdown();
928 /* end of file ats-testing.c */