X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fats-tests%2Fats-testing.c;h=08a61367b9796b7f86ac0445391b7870a999c689;hb=ee1c5c74a2409a52af706e613bd86a26341abba8;hp=5289c4ae73deee179f6a07abe7d62d36984225f4;hpb=1f3f45c08b82899a5350633dc6f1030216a1e150;p=oweals%2Fgnunet.git diff --git a/src/ats-tests/ats-testing.c b/src/ats-tests/ats-testing.c index 5289c4ae7..08a61367b 100644 --- a/src/ats-tests/ats-testing.c +++ b/src/ats-tests/ats-testing.c @@ -18,22 +18,38 @@ 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 @@ -48,24 +64,14 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 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]; @@ -153,8 +159,9 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_free(p->partners); p->partners = NULL; } - GNUNET_SCHEDULER_shutdown (); + GNUNET_free (top); + top = NULL; } static struct BenchmarkPartner * @@ -250,8 +257,9 @@ comm_connect_cb (void *cls, const struct GNUNET_PeerIdentity * peer) "All master peers connected all slave peers\n", id, GNUNET_i2s (peer)); top->state.connected_CORE = GNUNET_YES; - GNUNET_break (0); - //GNUNET_SCHEDULER_add_now (&do_benchmark, NULL ); + /* Notify about setup done */ + if (NULL != top->done_cb) + top->done_cb (top->done_cb_cls, top->mps, top->sps); } } GNUNET_free(id); @@ -315,12 +323,66 @@ core_disconnect_adapter (void *cls, void *op_result) } + + +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"); @@ -370,8 +432,6 @@ connect_completion_callback (void *cls, struct GNUNET_TESTBED_Operation *op, if (ops == top->num_masters * top->num_slaves) { top->state.connected_PEERS = GNUNET_YES; - GNUNET_break (0); - //GNUNET_SCHEDULER_add_now (&do_benchmark, NULL ); } } @@ -440,7 +500,6 @@ comm_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op, GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all %s services\n", (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT"); top->state.connected_COMM_service = GNUNET_YES; - GNUNET_break (0); GNUNET_SCHEDULER_add_now (&do_connect_peers, NULL ); } } @@ -481,13 +540,14 @@ do_comm_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } } - - 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; @@ -526,54 +586,53 @@ ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address, 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); } @@ -584,8 +643,7 @@ ats_perf_connect_adapter (void *cls, { 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"); @@ -703,10 +761,9 @@ main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h, 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 */ @@ -717,7 +774,7 @@ main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h, 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; @@ -778,17 +835,32 @@ controller_event_cb (void *cls, } } -struct GNUNET_ATS_TEST_Topology * + +void GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file, unsigned int num_slaves, unsigned int num_masters, - struct GNUNET_CORE_MessageHandler *handlers, - GNUNET_TRANSPORT_ReceiveCallback transport_recv_cb) + 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 }, + { NULL, 0, 0 } }; + top = GNUNET_new (struct GNUNET_ATS_TEST_Topology); top->num_masters = num_masters; top->num_slaves = num_slaves; top->handlers = handlers; + 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)); @@ -801,14 +873,19 @@ GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file, (void) GNUNET_TESTBED_test_run (name, cfg_file, num_slaves + num_masters, event_mask, &controller_event_cb, NULL, &main_run, NULL); - - return NULL; } void -GNUNET_ATS_TEST_destroy_topology (struct GNUNET_ATS_TEST_Topology *top) +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 */