Boston, MA 02111-1307, USA.
*/
/**
- * @file ats/perf_ats.c
- * @brief ats benchmark: start peers and modify preferences, monitor change over time
+ * @file ats-tests/ats-testing.c
+ * @brief ats testing library: setup topology
+ * solvers
* @author Christian Grothoff
* @author Matthias Wachs
*/
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testbed_service.h"
-#include "gnunet_ats_service.h"
-#include "gnunet_core_service.h"
#include "ats-testing.h"
+/**
+ * Connect peers with testbed
+ */
+struct TestbedConnectOperation
+{
+ /**
+ * The benchmarking master initiating this connection
+ */
+ struct BenchmarkPeer *master;
+
+ /**
+ * The benchmarking slave to connect to
+ */
+ struct BenchmarkPeer *slave;
+
+ /**
+ * Testbed operation to connect peers
+ */
+ struct GNUNET_TESTBED_Operation *connect_op;
+};
-static struct GNUNET_ATS_TEST_Topology *top;
+struct GNUNET_ATS_TEST_Topology *top;
/**
* Shutdown nicely
int c_s;
int c_op;
struct BenchmarkPeer *p;
-/*
- if (GNUNET_YES == logging)
- perf_logging_stop();
-*/
- top->shutdown_task = GNUNET_SCHEDULER_NO_TASK;
-/*
- if (GNUNET_SCHEDULER_NO_TASK != progress_task)
- {
- fprintf (stderr, "0\n");
- GNUNET_SCHEDULER_cancel (progress_task);
- }
- progress_task = GNUNET_SCHEDULER_NO_TASK;
-*/
- //evaluate ();
+ top->shutdown_task = GNUNET_SCHEDULER_NO_TASK;
top->state.benchmarking = GNUNET_NO;
+
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];
GNUNET_free(p->partners);
p->partners = NULL;
}
-
GNUNET_SCHEDULER_shutdown ();
+ GNUNET_free (top);
+ top = NULL;
}
static struct BenchmarkPartner *
"All master peers connected all slave peers\n", id,
GNUNET_i2s (peer));
top->state.connected_CORE = GNUNET_YES;
+ /* Notify about setup done */
+ if (NULL != top->done_cb)
+ top->done_cb (top->done_cb_cls, top->mps, top->sps);
}
}
GNUNET_free(id);
}
+
+
+static int
+comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct BenchmarkPeer *me = cls;
+ struct BenchmarkPartner *p = NULL;
+
+ if (NULL == (p = find_partner (me, other)))
+ {
+ GNUNET_break(0);
+ return GNUNET_SYSERR;
+ }
+
+ GNUNET_ATS_TEST_traffic_handle_pong (p);
+
+ return GNUNET_OK;
+}
+
+static int
+comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct BenchmarkPeer *me = cls;
+ struct BenchmarkPartner *p = NULL;
+
+ if (NULL == (p = find_partner(me, other)))
+ {
+ GNUNET_break(0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_ATS_TEST_traffic_handle_ping (p);
+ return GNUNET_OK;
+}
+
+static void
+test_recv_cb (void *cls,
+ const struct GNUNET_PeerIdentity * peer,
+ const struct GNUNET_MessageHeader * message)
+{
+ if (TEST_MESSAGE_SIZE != ntohs (message->size) ||
+ (TEST_MESSAGE_TYPE_PING != ntohs (message->type) &&
+ TEST_MESSAGE_TYPE_PONG != ntohs (message->type)))
+ {
+ return;
+ }
+ if (TEST_MESSAGE_TYPE_PING == ntohs (message->type))
+ comm_handle_ping (cls, peer, message);
+ if (TEST_MESSAGE_TYPE_PONG == ntohs (message->type))
+ comm_handle_pong (cls, peer, message);
+}
+
+
static void *
transport_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct BenchmarkPeer *me = cls;
- me->th = GNUNET_TRANSPORT_connect (cfg, &me->id, me, top->transport_recv_cb,
+ me->th = GNUNET_TRANSPORT_connect (cfg, &me->id, me, &test_recv_cb,
&comm_connect_cb, &comm_disconnect_cb);
if (NULL == me->th)
GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create transport connection \n");
if (ops == top->num_masters * top->num_slaves)
{
top->state.connected_PEERS = GNUNET_YES;
- /* Notify about setup done */
- if (NULL != top->done_cb)
- top->done_cb (top->done_cb_cls, top->mps, top->sps);
}
}
}
}
-
-
static void
-ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
- int address_active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+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_ATS_Information *ats,
+ uint32_t ats_count)
{
struct BenchmarkPeer *me = cls;
struct BenchmarkPartner *p;
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))
- {
-// collect_log_now();
- }
+ 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 == log)
+ top->ats_perf_cb (cls, address, address_active, bandwidth_out, bandwidth_in,
+ ats, ats_count);
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");
GNUNET_assert(NULL != peers_);
top->shutdown_task = GNUNET_SCHEDULER_add_delayed (
- GNUNET_TIME_relative_multiply (TEST_TIMEOUT, top->num_masters + top->num_slaves),
- &do_shutdown, top );
+ GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown, top);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Setting up %u masters and %u slaves\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Setting up %u masters and %u slaves\n",
top->num_masters, top->num_slaves);
/* Setup master peers */
top->mps[c_m].no = c_m;
top->mps[c_m].master = GNUNET_YES;
top->mps[c_m].pref_partner = &top->sps[c_m];
- top->mps[c_m].pref_value = TEST_ATS_PREFRENCE_START;
+ top->mps[c_m].pref_value = TEST_ATS_PREFERENCE_DEFAULT;
top->mps[c_m].partners =
GNUNET_malloc (top->num_slaves * sizeof (struct BenchmarkPartner));
top->mps[c_m].num_partners = top->num_slaves;
}
}
+
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,
+ GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb,
void *done_cb_cls,
- struct GNUNET_CORE_MessageHandler *handlers,
- GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb)
+ 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 },
+ { NULL, 0, 0 } };
+
top = GNUNET_new (struct GNUNET_ATS_TEST_Topology);
top->num_masters = num_masters;
top->num_slaves = num_slaves;
top->done_cb = done_cb;
top->done_cb_cls = done_cb_cls;
top->test_core = test_core;
+ top->transport_recv_cb = transport_recv_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));
void
GNUNET_ATS_TEST_shutdown_topology (void)
{
+ if (NULL == top)
+ return;
+
GNUNET_SCHEDULER_shutdown();
}
-/* end of file perf_ats.c */
+
+
+
+
+/* end of file ats-testing.c */