/*
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
- * @brief ats testing library: setup topology and provide logging to test ats
+ * @brief ats testing library: setup topology
* solvers
* @author Christian Grothoff
* @author Matthias Wachs
*/
#include "ats-testing.h"
-/**
- * Overall state of the performance benchmark
- */
-struct BenchmarkState
-{
- /**
- * Are we connected to ATS service of all peers: GNUNET_YES/NO
- */
- int connected_ATS_service;
-
- /**
- * Are we connected to CORE service of all peers: GNUNET_YES/NO
- */
- int connected_COMM_service;
-
- /**
- * Are we connected to all peers: GNUNET_YES/NO
- */
- int connected_PEERS;
-
- /**
- * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
- */
- int connected_CORE;
-
- /**
- * Are we connected to CORE service of all peers: GNUNET_YES/NO
- */
- int benchmarking;
-};
-
-
-
/**
* Connect peers with testbed
struct GNUNET_TESTBED_Operation *connect_op;
};
-struct GNUNET_ATS_TEST_Topology
-{
- /**
- * Shutdown task
- */
- GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
-
- /**
- * Progress task
- */
- GNUNET_SCHEDULER_TaskIdentifier progress_task;
-
- /**
- * Test result
- */
- int result;
-
- /**
- * Test result logging
- */
- int logging;
-
- /**Test core (GNUNET_YES) or transport (GNUNET_NO)
- */
- int test_core;
-
- /**
- * Solver string
- */
- char *solver;
-
- /**
- * Preference string
- */
- char *testname;
+struct GNUNET_CONFIGURATION_Handle *cfg;
- /**
- * Preference string
- */
- char *pref_str;
+struct GNUNET_ATS_TEST_Topology *top;
- /**
- * ATS preference value
- */
- int pref_val;
-
- /**
- * Number master peers
- */
- unsigned int num_masters;
-
- /**
- * Array of master peers
- */
- struct BenchmarkPeer *mps;
-
- /**
- * Number slave peers
- */
- unsigned int num_slaves;
-
- /**
- * Array of slave peers
- */
- struct BenchmarkPeer *sps;
-
- /**
- * Benchmark duration
- */
- struct GNUNET_TIME_Relative perf_duration;
-
- /**
- * Logging frequency
- */
- struct GNUNET_TIME_Relative log_frequency;
-
- /**
- * Benchmark state
- */
- struct BenchmarkState state;
-
- struct GNUNET_CORE_MessageHandler *handlers;
-
- GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb;
-
- GNUNET_ATS_TESTING_TopologySetupDoneCallback done_cb;
- GNUNET_ATS_AddressInformationCallback ats_perf_cb;
- void *done_cb_cls;
-};
-
-
-
-static struct GNUNET_ATS_TEST_Topology *top;
-
-struct TrafficGenerator *tg_head;
-struct TrafficGenerator *tg_tail;
-
-struct TrafficGenerator
-{
- struct TrafficGenerator *prev;
- struct TrafficGenerator *next;
-
- struct BenchmarkPeer *src;
- struct BenchmarkPartner *dest;
- unsigned int rate;
- GNUNET_SCHEDULER_Task next_send;
- struct GNUNET_TIME_Absolute last_sent;
- struct GNUNET_TIME_Relative delta;
-};
/**
* 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;
- struct TrafficGenerator *cur;
- struct TrafficGenerator *next;
-
- if (GNUNET_YES == top->logging)
- GNUNET_ATS_TEST_logging_stop ();
-
- top->shutdown_task = GNUNET_SCHEDULER_NO_TASK;
top->state.benchmarking = GNUNET_NO;
- next = tg_head;
- for (cur = next; NULL != cur; cur = next)
- {
- next = cur->next;
- GNUNET_ATS_TEST_generate_traffic_stop(cur);
- }
-
GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n"));
+ GNUNET_ATS_TEST_generate_traffic_stop_all ();
+
for (c_m = 0; c_m < top->num_masters; c_m++)
{
p = &top->mps[c_m];
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 size_t
-send_ping_ready_cb (void *cls, size_t size, void *buf)
-{
- struct BenchmarkPartner *p = cls;
- static char msgbuf[TEST_MESSAGE_SIZE];
- struct GNUNET_MessageHeader *msg;
-
- if (NULL == buf)
- {
- GNUNET_break (0);
- return 0;
- }
- if (size < TEST_MESSAGE_SIZE)
- {
- GNUNET_break (0);
- return 0;
- }
-
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Master [%u]: Sending PING to [%u]\n",
- p->me->no, p->dest->no);
-
- if (top->test_core)
- {
- if (NULL == p->cth)
- {
- GNUNET_break (0);
- }
- p->cth = NULL;
- }
- else
- {
- if (NULL == p->tth)
- {
- GNUNET_break (0);
- }
- p->tth = NULL;
- }
-
- msg = (struct GNUNET_MessageHeader *) &msgbuf;
- memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
- msg->type = htons (TEST_MESSAGE_TYPE_PING);
- msg->size = htons (TEST_MESSAGE_SIZE);
- memcpy (buf, msg, TEST_MESSAGE_SIZE);
-
- p->messages_sent++;
- p->bytes_sent += TEST_MESSAGE_SIZE;
- p->me->total_messages_sent++;
- p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
-
- return TEST_MESSAGE_SIZE;
-}
-
-
-static void
-comm_schedule_send (struct BenchmarkPartner *p)
-{
- p->last_message_sent = GNUNET_TIME_absolute_get();
- if (GNUNET_YES == top->test_core)
- {
- p->cth = GNUNET_CORE_notify_transmit_ready (
- p->me->ch, GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, &p->dest->id,
- TEST_MESSAGE_SIZE, &send_ping_ready_cb, p);
- }
- else
- {
- p->tth = GNUNET_TRANSPORT_notify_transmit_ready (
- p->me->th, &p->dest->id, TEST_MESSAGE_SIZE, 0,GNUNET_TIME_UNIT_MINUTES,
- &send_ping_ready_cb, p);
- }
-}
-
-static struct TrafficGenerator *
-find_tg (struct BenchmarkPartner *p)
-{
- struct TrafficGenerator *cur;
- for (cur = tg_head; NULL != cur; cur = cur->next)
- if ( (0 == memcmp (&p->me->id, &cur->dest->me, sizeof (cur->dest->me))) &&
- (0 == memcmp (&p->dest->id, &cur->dest->dest->id, sizeof (cur->dest->dest->id))) )
- return cur;
-
- return NULL;
-}
static int
-core_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
+comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message)
{
struct BenchmarkPeer *me = cls;
struct BenchmarkPartner *p = NULL;
- struct TrafficGenerator *tg;
if (NULL == (p = find_partner (me, other)))
{
return GNUNET_SYSERR;
}
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Master [%u]: Received PONG from [%u], next message\n", me->no,
- p->dest->no);
+ GNUNET_ATS_TEST_traffic_handle_pong (p);
- p->messages_received++;
- p->bytes_received += TEST_MESSAGE_SIZE;
- p->me->total_messages_received++;
- p->me->total_bytes_received += TEST_MESSAGE_SIZE;
- p->total_app_rtt += GNUNET_TIME_absolute_get_difference(p->last_message_sent,
- GNUNET_TIME_absolute_get()).rel_value_us;
-
-
- tg = find_tg(p);
-/*
- if (GNUNET_TIME_absolute_max(GNUNET_TIME_absolute_get(), tg->next_send))*/
- comm_schedule_send (p);
return GNUNET_OK;
}
-static size_t
-comm_send_pong_ready (void *cls, size_t size, void *buf)
-{
- static char msgbuf[TEST_MESSAGE_SIZE];
- struct BenchmarkPartner *p = cls;
- struct GNUNET_MessageHeader *msg;
-
- if (GNUNET_YES == top->test_core)
- p->cth = NULL;
- else
- p->tth = NULL;
-
- p->messages_sent++;
- p->bytes_sent += TEST_MESSAGE_SIZE;
- p->me->total_messages_sent++;
- p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
-
- msg = (struct GNUNET_MessageHeader *) &msgbuf;
- memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
- msg->type = htons (TEST_MESSAGE_TYPE_PONG);
- msg->size = htons (TEST_MESSAGE_SIZE);
- memcpy (buf, msg, TEST_MESSAGE_SIZE);
-
- return TEST_MESSAGE_SIZE;
-}
-
-
static int
-core_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
+comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message)
{
struct BenchmarkPeer *me = cls;
GNUNET_break(0);
return GNUNET_SYSERR;
}
-
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Slave [%u]: Received PING from [%u], sending PONG\n", me->no,
- p->dest->no);
-
- p->messages_received++;
- p->bytes_received += TEST_MESSAGE_SIZE;
- p->me->total_messages_received++;
- p->me->total_bytes_received += TEST_MESSAGE_SIZE;
-
- if (GNUNET_YES == top->test_core)
- {
- GNUNET_assert (NULL == p->cth);
-
- p->cth = GNUNET_CORE_notify_transmit_ready (me->ch, GNUNET_NO, 0,
- GNUNET_TIME_UNIT_MINUTES, &p->dest->id, TEST_MESSAGE_SIZE,
- &comm_send_pong_ready, p);
- }
- else
- {
- GNUNET_assert (NULL == p->tth);
- p->tth = GNUNET_TRANSPORT_notify_transmit_ready (me->th, &p->dest->id,
- TEST_MESSAGE_SIZE, 0, GNUNET_TIME_UNIT_MINUTES, &comm_send_pong_ready,
- p);
- }
+ GNUNET_ATS_TEST_traffic_handle_ping (p);
return GNUNET_OK;
}
return;
}
if (TEST_MESSAGE_TYPE_PING == ntohs (message->type))
- core_handle_ping (cls, peer, message);
+ comm_handle_ping (cls, peer, message);
if (TEST_MESSAGE_TYPE_PONG == ntohs (message->type))
- core_handle_pong (cls, peer, message);
+ comm_handle_pong (cls, peer, message);
}
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)
+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_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;
- }
- }
- if ((GNUNET_YES == top->logging) && (GNUNET_YES == log))
- GNUNET_ATS_TEST_logging_now();
-
- top->ats_perf_cb (cls, address, address_active, bandwidth_out, bandwidth_in,
- ats, ats_count);
+ 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_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;
* Signature of a main function for a testcase.
*
* @param cls closure
+ * @param h testbed handle
* @param num_peers number of peers in 'peers'
* @param peers_ handle to peers run in the testbed
* @param links_succeeded the number of overlay link connection attempts that
{
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_TESTING_TopologySetupDoneCallback done_cb,
- void *done_cb_cls,
- GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb,
- GNUNET_ATS_AddressInformationCallback ats_perf_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[] = {
- {&core_handle_ping, TEST_MESSAGE_TYPE_PING, 0 },
- {&core_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 },
+ {&comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 },
+ {&comm_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 },
{ NULL, 0, 0 } };
top = GNUNET_new (struct GNUNET_ATS_TEST_Topology);
top->done_cb_cls = done_cb_cls;
top->test_core = test_core;
top->transport_recv_cb = transport_recv_cb;
- top->ats_perf_cb = ats_perf_cb;
+ top->ats_perf_cb = log_request_cb;
top->mps = GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer));
top->sps = GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer));
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();
}
-struct TrafficGenerator *
-GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
- struct BenchmarkPartner *dest, unsigned int rate,
- struct GNUNET_TIME_Relative duration)
-{
- struct TrafficGenerator * tg;
- tg = NULL;
-
- tg = GNUNET_new (struct TrafficGenerator);
- GNUNET_CONTAINER_DLL_insert (tg_head, tg_tail, tg);
- tg->src = src;
- tg->dest = dest;
- tg->rate = rate;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up traffic generator between master[%u] `%s' and slave [%u] `%s' sending with %u Bytes/sec\n",
- dest->me->no, GNUNET_i2s (&dest->me->id),
- dest->dest->no, GNUNET_i2s (&dest->dest->id),
- rate);
-
- if (top->test_core)
- {
- if (NULL != dest->cth)
- {
- GNUNET_break (0);
- return tg;
- }
- dest->cth = GNUNET_CORE_notify_transmit_ready (src->ch, GNUNET_NO,
- UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, &dest->dest->id,
- TEST_MESSAGE_SIZE, &send_ping_ready_cb, dest);
- }
- else
- {
- if (NULL != dest->tth)
- {
- GNUNET_break (0);
- return tg;
- }
- dest->tth = GNUNET_TRANSPORT_notify_transmit_ready (src->th, &dest->dest->id,
- TEST_MESSAGE_SIZE, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
- &send_ping_ready_cb, dest);
- tg->last_sent = GNUNET_TIME_absolute_get();
- tg->delta.rel_value_us = (GNUNET_TIME_UNIT_SECONDS.rel_value_us / (rate / TEST_MESSAGE_SIZE));
- }
- return tg;
-}
-
-void
-GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg)
-{
- GNUNET_CONTAINER_DLL_remove (tg_head, tg_tail, tg);
-
- if (top->test_core)
- {
- if (NULL != tg->dest->cth)
- {
- GNUNET_CORE_notify_transmit_ready_cancel (tg->dest->cth);
- tg->dest->cth = NULL;
- }
- }
- else
- {
- if (NULL != tg->dest->tth)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel (tg->dest->tth);
- tg->dest->tth = NULL;
- }
- }
- GNUNET_free (tg);
-}
/* end of file ats-testing.c */