2 This file is part of GNUnet
3 (C) 2008, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_testing_lib.h
23 * @brief convenience API for writing testcases for GNUnet
24 * Many testcases need to start and stop gnunetd,
25 * and this library is supposed to make that easier
26 * for TESTCASES. Normal programs should always
27 * use functions from gnunet_{util,arm}_lib.h. This API is
28 * ONLY for writing testcases!
29 * @author Christian Grothoff
32 #ifndef GNUNET_TESTING_LIB_H
33 #define GNUNET_TESTING_LIB_H
35 #include "gnunet_util_lib.h"
40 #if 0 /* keep Emacsens' auto-indent happy */
48 * Handle for a GNUnet daemon (technically a set of
49 * daemons; the handle is really for the master ARM
50 * daemon) started by the testing library.
52 struct GNUNET_TESTING_Daemon;
56 * Prototype of a function that will be called whenever
57 * a daemon was started by the testing library.
60 * @param id identifier for the daemon, NULL on error
61 * @param cfg configuration used by this daemon
62 * @param d handle for the daemon
63 * @param emsg error message (NULL on success)
65 typedef void (*GNUNET_TESTING_NotifyDaemonRunning)(void *cls,
66 const struct GNUNET_PeerIdentity *id,
67 const struct GNUNET_CONFIGURATION_Handle *cfg,
68 struct GNUNET_TESTING_Daemon *d,
73 * Starts a GNUnet daemon. GNUnet must be installed on the target
74 * system and available in the PATH. The machine must furthermore be
75 * reachable via "ssh" (unless the hostname is "NULL") without the
76 * need to enter a password.
78 * @param sched scheduler to use
79 * @param cfg configuration to use
80 * @param hostname name of the machine where to run GNUnet
81 * (use NULL for localhost).
82 * @param cb function to call with the result
83 * @param cb_cls closure for cb
84 * @return handle to the daemon (actual start will be completed asynchronously)
86 struct GNUNET_TESTING_Daemon *
87 GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
88 const struct GNUNET_CONFIGURATION_Handle *cfg,
90 GNUNET_TESTING_NotifyDaemonRunning cb,
95 * Prototype of a function that will be called when a
96 * particular operation was completed the testing library.
99 * @param emsg NULL on success
101 typedef void (*GNUNET_TESTING_NotifyCompletion)(void *cls,
106 * Stops a GNUnet daemon.
108 * @param d the daemon that should be stopped
109 * @param cb function called once the daemon was stopped
110 * @param cb_cls closure for cb
112 void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
113 GNUNET_TESTING_NotifyCompletion cb,
118 * Changes the configuration of a GNUnet daemon.
120 * @param d the daemon that should be modified
121 * @param cfg the new configuration for the daemon
122 * @param cb function called once the configuration was changed
123 * @param cb_cls closure for cb
125 void GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
126 struct GNUNET_CONFIGURATION_Handle *cfg,
127 GNUNET_TESTING_NotifyCompletion cb,
132 * Establish a connection between two GNUnet daemons.
134 * @param d1 handle for the first daemon
135 * @param d2 handle for the second daemon
136 * @param timeout how long is the connection attempt
138 * @param cb function to call at the end
139 * @param cb_cls closure for cb
141 void GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
142 struct GNUNET_TESTING_Daemon *d2,
143 struct GNUNET_TIME_Relative timeout,
144 GNUNET_TESTING_NotifyCompletion cb,
150 * Handle to a group of GNUnet peers.
152 struct GNUNET_TESTING_PeerGroup;
156 * Start count gnunetd processes with the same set of transports and
157 * applications. The port numbers (any option called "PORT") will be
158 * adjusted to ensure that no two peers running on the same system
159 * have the same port(s) in their respective configurations.
161 * @param sched scheduler to use
162 * @param cfg configuration template to use
163 * @param total number of daemons to start
164 * @param cb function to call on each daemon that was started
165 * @param cb_cls closure for cb
166 * @param hostnames space-separated list of hostnames to use,
167 * NULL to use localhost only
168 * @return NULL on error, otherwise handle to control peer group
170 struct GNUNET_TESTING_PeerGroup *
171 GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
172 const struct GNUNET_CONFIGURATION_Handle *cfg,
174 GNUNET_TESTING_NotifyDaemonRunning cb,
176 const char *hostnames);
180 * Shutdown all peers started in the given group.
182 * @param pg handle to the peer group
185 GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg);
189 * Handle to an entire testbed of GNUnet peers.
191 struct GNUNET_TESTING_Testbed;
195 * Topologies supported for testbeds.
197 enum GNUNET_TESTING_Topology
200 * A clique (everyone connected to everyone else).
202 GNUNET_TESTING_TOPOLOGY_CLIQUE,
205 * Small-world network (2d torus plus random links).
207 GNUNET_TESTING_TOPOLOGY_SMALL_WORLD,
212 GNUNET_TESTING_TOPOLOGY_RING,
217 GNUNET_TESTING_TOPOLOGY_2D_TORUS,
222 GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI,
225 * All peers are disconnected.
227 GNUNET_TESTING_TOPOLOGY_NONE
232 * Start "count" GNUnet daemons with a particular topology.
234 * @param sched scheduler to use
235 * @param cfg configuration template to use
236 * @param count number of peers the testbed should have
237 * @param topology desired topology (enforced via F2F)
238 * @param cb function to call on each daemon that was started
239 * @param cb_cls closure for cb
240 * @param hostname where to run the peers; can be NULL (to run
241 * everything on localhost). Additional
242 * hosts can be specified using a NULL-terminated list of
243 * varargs, hosts will then be used round-robin from that
245 * @return handle to control the testbed
247 struct GNUNET_TESTING_Testbed *
248 GNUNET_TESTING_testbed_start (struct GNUNET_SCHEDULER_Handle *sched,
249 const struct GNUNET_CONFIGURATION_Handle *cfg,
251 enum GNUNET_TESTING_Topology topology,
252 GNUNET_TESTING_NotifyDaemonRunning cb,
254 const char *hostname,
259 * Stop all of the daemons started with the start function.
261 * @param tb handle for the testbed
262 * @param cb function to call when done
263 * @param cb_cls closure for cb
266 GNUNET_TESTING_testbed_stop (struct GNUNET_TESTING_Testbed *tb,
267 GNUNET_TESTING_NotifyCompletion cb,
272 * Simulate churn in the testbed by stopping some peers (and possibly
273 * re-starting others if churn is called multiple times). This
274 * function can only be used to create leave-join churn (peers "never"
275 * leave for good). First "voff" random peers that are currently
276 * online will be taken offline; then "von" random peers that are then
277 * offline will be put back online. No notifications will be
278 * generated for any of these operations except for the callback upon
279 * completion. Note that the implementation is at liberty to keep
280 * the ARM service itself (but none of the other services or daemons)
281 * running even though the "peer" is being varied offline.
283 * @param tb handle for the testbed
284 * @param voff number of peers that should go offline
285 * @param von number of peers that should come back online;
286 * must be zero on first call (since "testbed_start"
287 * always starts all of the peers)
288 * @param cb function to call at the end
289 * @param cb_cls closure for cb
292 GNUNET_TESTING_testbed_churn (struct GNUNET_TESTING_Testbed *tb,
295 GNUNET_TESTING_NotifyCompletion cb,
299 #if 0 /* keep Emacsens' auto-indent happy */