/*
This file is part of GNUnet
(C) 2008--2012 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3, 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
General Public License for more details.
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.
*/
/**
* @file testbed/testbed_api_testbed.c
* @brief high-level testbed management
* @author Christian Grothoff
* @author Sree Harsha Totakura
*/
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testbed_service.h"
#include "testbed_api_peers.h"
#include "testbed_api_hosts.h"
#include "testbed_api_topology.h"
/**
* Generic loggins shorthand
*/
#define LOG(kind,...) \
GNUNET_log_from (kind, "testbed-api-testbed", __VA_ARGS__)
/**
* Debug logging shortcut
*/
#define DEBUG(...) \
LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
/**
* DLL of operations
*/
struct DLLOperation
{
/**
* The testbed operation handle
*/
struct GNUNET_TESTBED_Operation *op;
/**
* Context information for GNUNET_TESTBED_run()
*/
struct RunContext *rc;
/**
* Closure
*/
void *cls;
/**
* The next pointer for DLL
*/
struct DLLOperation *next;
/**
* The prev pointer for DLL
*/
struct DLLOperation *prev;
};
/**
* States of RunContext
*/
enum State
{
/**
* Initial state
*/
RC_INIT = 0,
/**
* Controllers on given hosts started and linked
*/
RC_LINKED,
/**
* Peers are created
*/
RC_PEERS_CREATED,
/**
* The testbed run is ready and the master callback can be called now. At this
* time the peers are all started and if a topology is provided in the
* configuration the topology would have been attempted
*/
RC_READY,
/**
* Peers are stopped
*/
RC_PEERS_STOPPED,
/**
* Peers are destroyed
*/
RC_PEERS_DESTROYED
};
/**
* Testbed Run Handle
*/
struct RunContext
{
/**
* The controller handle
*/
struct GNUNET_TESTBED_Controller *c;
/**
* The configuration of the controller. This is based on the cfg given to the
* function GNUNET_TESTBED_run(). We also use this config as a template while
* for peers
*/
struct GNUNET_CONFIGURATION_Handle *cfg;
/**
* Handle to the host on which the controller runs
*/
struct GNUNET_TESTBED_Host *h;
/**
* The handle to the controller process
*/
struct GNUNET_TESTBED_ControllerProc *cproc;
/**
* The callback to use as controller callback
*/
GNUNET_TESTBED_ControllerCallback cc;
/**
* The pointer to the controller callback
*/
void *cc_cls;
/**
* The trusted IP string
*/
char *trusted_ip;
/**
* TestMaster callback to call when testbed initialization is done
*/
GNUNET_TESTBED_TestMaster test_master;
/**
* The closure for the TestMaster callback
*/
void *test_master_cls;
/**
* The head element of DLL operations
*/
struct DLLOperation *dll_op_head;
/**
* The tail element of DLL operations
*/
struct DLLOperation *dll_op_tail;
/**
* An array of hosts loaded from the hostkeys file
*/
struct GNUNET_TESTBED_Host **hosts;
/**
* The handle for whether a host is habitable or not
*/
struct GNUNET_TESTBED_HostHabitableCheckHandle **hc_handles;
/**
* Array of peers which we create
*/
struct GNUNET_TESTBED_Peer **peers;
/**
* The topology generation operation. Will be null if no topology is set in
* the configuration
*/
struct GNUNET_TESTBED_Operation *topology_operation;
/**
* The file containing topology data. Only used if the topology is set to 'FROM_FILE'
*/
char *topo_file;
/**
* Host registration handle
*/
struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
/**
* Profiling start time
*/
struct GNUNET_TIME_Absolute pstart_time;
/**
* Host registration task
*/
GNUNET_SCHEDULER_TaskIdentifier register_hosts_task;
/**
* Task to be run while shutting down
*/
GNUNET_SCHEDULER_TaskIdentifier shutdown_run_task;
/**
* The event mask for the controller
*/
uint64_t event_mask;
/**
* State of this context
*/
enum State state;
/**
* The topology which has to be achieved with the peers started in this context
*/
enum GNUNET_TESTBED_TopologyOption topology;
/**
* Have we already shutdown
*/
int shutdown;
/**
* Number of hosts in the given host file
*/
unsigned int num_hosts;
/**
* Number of registered hosts. Also used as a counter while checking
* habitabillity of hosts
*/
unsigned int reg_hosts;
/**
* Current peer count for an operation; Set this to 0 and increment for each
* successful operation on a peer
*/
unsigned int peer_count;
/**
* number of peers to start
*/
unsigned int num_peers;
/**
* counter to count overlay connect attempts. This counter includes both
* successful and failed overlay connects
*/
unsigned int oc_count