/*
This file is part of GNUnet.
Copyright (C) 2010-2013, 2016, 2017 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file ats-tests/ats-testing.c
* @brief ats testing library: setup topology
* solvers
* @author Christian Grothoff
* @author Matthias Wachs
*/
#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;
};
struct GNUNET_CONFIGURATION_Handle *cfg;
struct GNUNET_ATS_TEST_Topology *top;
/**
* Shutdown nicely
*
* @param cls NULL
*/
static void
do_shutdown (void *cls)
{
int c_m;
int c_s;
int c_op;
struct BenchmarkPeer *p;
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];
if (NULL != top->mps[c_m].peer_id_op)
{
GNUNET_TESTBED_operation_done (p->peer_id_op);
p->peer_id_op = NULL;
}
if (NULL != p->ats_task)
GNUNET_SCHEDULER_cancel (p->ats_task);
p->ats_task = NULL;
for (c_op = 0; c_op < p->num_partners; c_op++)
{
if ( (NULL != p->core_connect_ops) &&
(NULL != p->core_connect_ops[c_op].connect_op) )
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Failed to connect peer 0 and %u\n",
c_op);
GNUNET_TESTBED_operation_done (p->core_connect_ops[c_op].connect_op);
p->core_connect_ops[c_op].connect_op = NULL;
}
}
if (NULL != p->ats_perf_op)
{
GNUNET_TESTBED_operation_done (p->ats_perf_op);
p->ats_perf_op = NULL;
}
if (NULL != p->comm_op)
{
GNUNET_TESTBED_operation_done (p->comm_op);
p->comm_op = NULL;
}
GNUNET_free_non_null (p->core_connect_ops);
GNUNET_free(p->partners);
p->partners = NULL;
}
for (c_s = 0; c_s < top->num_slaves; c_s++)
{
p = &top->sps[c_s];
if (NULL != p->peer_id_op)
{
GNUNET_TESTBED_operation_done (p->peer_id_op);
p->peer_id_op = NULL;
}
if (NULL != p->ats_perf_op)
{
GNUNET_TESTBED_operation_done (p->ats_perf_op);
p->ats_perf_op = NULL;
}
if (NULL != p->comm_op)
{
GNUNET_TESTBED_operation_done (p->comm_op);
p->comm_op = NULL;
}
GNUNET_free(p->partners);
p->partners = NULL;
}
GNUNET_SCHEDULER_shutdown ();
GNUNET_free (top);
top = NULL;
}
static struct BenchmarkPartner *
find_partner (struct BenchmarkPeer *me,
const struct GNUNET_PeerIdentity *peer)
{
int c_m;
for (c_m = 0; c_m < me->num_partners; c_m++)
{
/* Find a partner with other as destination */
if (0 == memcmp (peer,
&me->partners[c_m].dest->id,
sizeof (struct GNUNET_PeerIdentity)))
{
return &me->partners[c_m];
}
}
return NULL;
}
static struct BenchmarkPeer *
find_peer (const struct GNUNET_PeerIdentity * peer)
{
int c_p;
for (c_p = 0; c_p < top->num_masters; c_p++)
{
if (0 == memcmp (&top->mps[c_p].id,
peer,
sizeof(struct GNUNET_PeerIdentity)))
return &top->mps[c_p];
}
for (c_p = 0; c_p < top->num_slaves; c_p++)
{
if (0 == memcmp (&top->sps[c_p].id,
peer,
sizeof(struct GNUNET_PeerIdentity)))
return &top