/*
This file is part of GNUnet.
- (C) 2010-2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2010-2013 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
* @file ats-tests/ats-testing.c
struct GNUNET_TESTBED_Operation *connect_op;
};
+struct GNUNET_CONFIGURATION_Handle *cfg;
struct GNUNET_ATS_TEST_Topology *top;
+
/**
* Shutdown nicely
*
* @param cls NULL
- * @param tc the task context
*/
static void
-do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_shutdown (void *cls)
{
int c_m;
int c_s;
int c_op;
struct BenchmarkPeer *p;
- top->shutdown_task = GNUNET_SCHEDULER_NO_TASK;
top->state.benchmarking = GNUNET_NO;
GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n"));
p->peer_id_op = NULL;
}
- if (GNUNET_SCHEDULER_NO_TASK != p->ats_task)
+ if (NULL != p->ats_task)
GNUNET_SCHEDULER_cancel (p->ats_task);
- p->ats_task = GNUNET_SCHEDULER_NO_TASK;
+ p->ats_task = NULL;
for (c_op = 0; c_op < p->num_partners; c_op++)
{
if (me->core_slave_connections == top->num_slaves)
{
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Master [%u] connected all slaves\n",
- me->no);
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+ "Master [%u] connected all slaves\n",
+ me->no);
}
completed = GNUNET_YES;
for (c = 0; c < top->num_masters; c++)
}
if (GNUNET_YES == completed)
{
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "All master peers connected all slave peers\n", id,
- GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "All master peers connected all slave peers\n");
top->state.connected_CORE = GNUNET_YES;
/* Notify about setup done */
if (NULL != top->done_cb)
static void *
-transport_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
+transport_connect_adapter (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct BenchmarkPeer *me = cls;
return me->th;
}
+
static void
transport_disconnect_adapter (void *cls, void *op_result)
{
static void
-connect_completion_callback (void *cls, struct GNUNET_TESTBED_Operation *op,
- const char *emsg)
+connect_completion_callback (void *cls,
+ struct GNUNET_TESTBED_Operation *op,
+ const char *emsg)
{
struct TestbedConnectOperation *cop = cls;
static int ops = 0;
if (NULL == emsg)
{
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- _("Connected master [%u] with slave [%u]\n"), cop->master->no,
- cop->slave->no);
+ _("Connected master [%u] with slave [%u]\n"),
+ cop->master->no,
+ cop->slave->no);
}
else
{
_("Failed to connect master peer [%u] with slave [%u]\n"),
cop->master->no, cop->slave->no);
GNUNET_break(0);
- if (GNUNET_SCHEDULER_NO_TASK != top->shutdown_task)
- GNUNET_SCHEDULER_cancel (top->shutdown_task);
- top->shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
+ GNUNET_SCHEDULER_shutdown ();
}
GNUNET_TESTBED_operation_done (op);
ops++;
}
}
+
static void
-do_connect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_connect_peers (void *cls)
{
int c_m;
int c_s;
_("Could not connect master [%u] and slave [%u]\n"), p->no,
top->sps[c_s].no);
GNUNET_break(0);
- if (GNUNET_SCHEDULER_NO_TASK != top->shutdown_task)
- GNUNET_SCHEDULER_cancel (top->shutdown_task);
- top->shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
+ GNUNET_SCHEDULER_shutdown ();
return;
}
}
static void
-comm_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
- void *ca_result, const char *emsg)
+comm_connect_completion_cb (void *cls,
+ struct GNUNET_TESTBED_Operation *op,
+ void *ca_result,
+ const char *emsg)
{
static int comm_done = 0;
+
if ((NULL != emsg) || (NULL == ca_result))
{
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+ "Initialization failed, shutdown\n");
GNUNET_break(0);
- if (GNUNET_SCHEDULER_NO_TASK != top->shutdown_task)
- GNUNET_SCHEDULER_cancel (top->shutdown_task);
- top->shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
+ GNUNET_SCHEDULER_shutdown ();
return;
}
comm_done++;
}
}
+
static void
-do_comm_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_comm_connect (void *cls)
{
int c_s;
int c_m;
}
}
+
static void
ats_performance_info_cb (void *cls,
- const struct GNUNET_HELLO_Address *address,
- int address_active,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_HELLO_Address *address,
+ int address_active,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+ const struct GNUNET_ATS_Properties *ats_prop)
{
struct BenchmarkPeer *me = cls;
struct BenchmarkPartner *p;
- int c_a;
int log;
char *peer_id;
+ if (NULL == address)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer %u: ATS Service disconnected!\n",
+ me->no);
+ return;
+ }
+
p = find_partner (me, &address->peer);
if (NULL == p)
{
p->bandwidth_in = ntohl (bandwidth_in.value__);
p->bandwidth_out = ntohl (bandwidth_out.value__);
- for (c_a = 0; c_a < ats_count; c_a++)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s [%u] received ATS information: %s %s %u\n",
- (GNUNET_YES == p->me->master) ? "Master" : "Slave",
- p->me->no,
- GNUNET_i2s (&p->dest->id),
- GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)),
- ntohl(ats[c_a].value));
- switch (ntohl (ats[c_a].type ))
- {
- case GNUNET_ATS_ARRAY_TERMINATOR:
- break;
- case GNUNET_ATS_UTILIZATION_OUT:
- if (p->ats_utilization_up != ntohl (ats[c_a].value))
- log = GNUNET_YES;
- p->ats_utilization_up = ntohl (ats[c_a].value);
-
- break;
- case GNUNET_ATS_UTILIZATION_IN:
- if (p->ats_utilization_down != ntohl (ats[c_a].value))
- log = GNUNET_YES;
- p->ats_utilization_down = ntohl (ats[c_a].value);
- break;
- case GNUNET_ATS_NETWORK_TYPE:
- if (p->ats_network_type != ntohl (ats[c_a].value))
- log = GNUNET_YES;
- p->ats_network_type = ntohl (ats[c_a].value);
- break;
- case GNUNET_ATS_QUALITY_NET_DELAY:
- if (p->ats_delay != ntohl (ats[c_a].value))
- log = GNUNET_YES;
- p->ats_delay = ntohl (ats[c_a].value);
- break;
- case GNUNET_ATS_QUALITY_NET_DISTANCE:
- if (p->ats_distance != ntohl (ats[c_a].value))
- log = GNUNET_YES;
- p->ats_distance = ntohl (ats[c_a].value);
- GNUNET_break (0);
- break;
- case GNUNET_ATS_COST_WAN:
- if (p->ats_cost_wan != ntohl (ats[c_a].value))
- log = GNUNET_YES;
- p->ats_cost_wan = ntohl (ats[c_a].value);
- break;
- case GNUNET_ATS_COST_LAN:
- if (p->ats_cost_lan != ntohl (ats[c_a].value))
- log = GNUNET_YES;
- p->ats_cost_lan = ntohl (ats[c_a].value);
- break;
- case GNUNET_ATS_COST_WLAN:
- if (p->ats_cost_wlan != ntohl (ats[c_a].value))
- log = GNUNET_YES;
- p->ats_cost_wlan = ntohl (ats[c_a].value);
- break;
- default:
- break;
- }
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s [%u] received ATS information: %s\n",
+ (GNUNET_YES == p->me->master) ? "Master" : "Slave",
+ p->me->no,
+ GNUNET_i2s (&p->dest->id));
+
+ p->props.utilization_out = ats_prop->utilization_out;
+ p->props.utilization_in = ats_prop->utilization_in;
+ p->props.scope = ats_prop->scope;
+ p->props.delay = ats_prop->delay;
+ p->props.distance = ats_prop->distance;
+
if (GNUNET_YES == log)
- top->ats_perf_cb (cls, address, address_active, bandwidth_out, bandwidth_in,
- ats, ats_count);
+ top->ats_perf_cb (cls, address,
+ address_active,
+ bandwidth_out,
+ bandwidth_in,
+ ats_prop);
GNUNET_free(peer_id);
}
{
struct BenchmarkPeer *me = cls;
- me->ats_perf_handle = GNUNET_ATS_performance_init (cfg, ats_performance_info_cb, me);
+ me->ats_perf_handle = GNUNET_ATS_performance_init (cfg,
+ &ats_performance_info_cb, me);
if (NULL == me->ats_perf_handle)
GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
"Failed to create ATS performance handle \n");
if ((NULL != emsg) || (NULL == ca_result))
{
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+ "Initialization failed, shutdown\n");
GNUNET_break(0);
- if (GNUNET_SCHEDULER_NO_TASK != top->shutdown_task)
- GNUNET_SCHEDULER_cancel (top->shutdown_task);
- top->shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
+ GNUNET_SCHEDULER_shutdown ();
return;
}
op_done++;
static void
-do_connect_ats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_connect_ats (void *cls)
{
int c_m;
int c_s;
{
int c_m;
int c_s;
+
GNUNET_assert(NULL == cls);
GNUNET_assert(top->num_masters + top->num_slaves == num_peers);
GNUNET_assert(NULL != peers_);
- top->shutdown_task = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown, top);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ top);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Setting up %u masters and %u slaves\n",
- top->num_masters, top->num_slaves);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Setting up %u masters and %u slaves\n",
+ top->num_masters,
+ top->num_slaves);
/* Setup master peers */
for (c_m = 0; c_m < top->num_masters; c_m++)
{
top->sps[c_s].partners[c_m].me = &top->sps[c_s];
top->sps[c_s].partners[c_m].dest = &top->mps[c_m];
+
+ /* Initialize properties */
+ top->sps[c_s].partners[c_m].props.delay = GNUNET_TIME_UNIT_ZERO;
+ top->sps[c_s].partners[c_m].props.distance = 0;
+ top->sps[c_s].partners[c_m].props.scope = GNUNET_ATS_NET_UNSPECIFIED;
+ top->sps[c_s].partners[c_m].props.utilization_in = 0;
+ top->sps[c_s].partners[c_m].props.utilization_out = 0;
}
/* Get configuration */
top->sps[c_s].peer_id_op = GNUNET_TESTBED_peer_get_information (top->sps[c_s].peer,
*/
static void
controller_event_cb (void *cls,
- const struct GNUNET_TESTBED_EventInformation *event)
+ const struct GNUNET_TESTBED_EventInformation *event)
{
- struct GNUNET_ATS_TEST_Topology *top = cls;
switch (event->type)
{
case GNUNET_TESTBED_ET_CONNECT:
break;
default:
GNUNET_break(0);
- GNUNET_SCHEDULER_cancel (top->shutdown_task);
- top->shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL );
+ GNUNET_SCHEDULER_shutdown ();
}
}
+struct BenchmarkPeer *
+GNUNET_ATS_TEST_get_peer (int src)
+{
+ if (src > top->num_masters)
+ return NULL;
+ return &top->mps[src];
+}
+
+
+struct BenchmarkPartner *
+GNUNET_ATS_TEST_get_partner (int src, int dest)
+{
+ if (src > top->num_masters)
+ return NULL;
+ if (dest > top->num_slaves)
+ return NULL;
+ return &top->mps[src].partners[dest];
+}
+
+
+/**
+ * Create a topology for ats testing
+ *
+ * @param name test name
+ * @param cfg_file configuration file to use for the peers
+ * @param num_slaves number of slaves
+ * @param num_masters number of masters
+ * @param test_core connect to CORE service (GNUNET_YES) or transport (GNUNET_NO)
+ * @param done_cb function to call when topology is setup
+ * @param done_cb_cls cls for callback
+ * @param transport_recv_cb callback to call when data are received
+ * @param log_request_cb callback to call when logging is required
+ */
void
GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file,
- unsigned int num_slaves,
- unsigned int num_masters,
- int test_core,
- GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
- void *done_cb_cls,
- GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb,
- GNUNET_ATS_AddressInformationCallback log_request_cb)
+ unsigned int num_slaves,
+ unsigned int num_masters,
+ int test_core,
+ GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
+ void *done_cb_cls,
+ GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb,
+ GNUNET_ATS_AddressInformationCallback log_request_cb)
{
-
static struct GNUNET_CORE_MessageHandler handlers[] = {
{&comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 },
{&comm_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 },
event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
(void) GNUNET_TESTBED_test_run (name, cfg_file,
- num_slaves + num_masters, event_mask, &controller_event_cb, NULL,
- &main_run, NULL);
+ num_slaves + num_masters,
+ event_mask,
+ &controller_event_cb, NULL,
+ &main_run, NULL);
}
+
+/**
+ * Shutdown topology
+ */
void
GNUNET_ATS_TEST_shutdown_topology (void)
{
if (NULL == top)
return;
-
GNUNET_SCHEDULER_shutdown();
}