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 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 const 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 hostname where to run the peers; can be NULL (to run
167 * everything on localhost).
168 * @param va Additional hosts can be specified using a NULL-terminated list of
169 * varargs, hosts will then be used round-robin from that
170 * list; va only contains anything if hostname != NULL.
171 * @return NULL on error, otherwise handle to control peer group
173 struct GNUNET_TESTING_PeerGroup *
174 GNUNET_TESTING_daemons_start_va (struct GNUNET_SCHEDULER_Handle *sched,
175 const struct GNUNET_CONFIGURATION_Handle *cfg,
177 GNUNET_TESTING_NotifyDaemonRunning cb,
179 const char *hostname,
184 * Start count gnunetd processes with the same set of
185 * transports and applications. The port numbers will
186 * be computed by adding delta each time (zero
187 * times for the first peer).
189 * @param sched scheduler to use
190 * @param cfg configuration template to use
191 * @param total number of daemons to start
192 * @param timeout how long is this allowed to take?
193 * @param cb function to call on each daemon that was started
194 * @param cb_cls closure for cb
195 * @param hostname where to run the peers; can be NULL (to run
196 * everything on localhost). Additional
197 * hosts can be specified using a NULL-terminated list of
198 * varargs, hosts will then be used round-robin from that
200 * @return NULL on error, otherwise handle to control peer group
202 struct GNUNET_TESTING_PeerGroup *
203 GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
204 struct GNUNET_CONFIGURATION_Handle *cfg,
206 GNUNET_TESTING_NotifyDaemonRunning cb,
208 const char *hostname,
213 * Shutdown all peers started in the given group.
215 * @param pg handle to the peer group
218 GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg);
222 * Handle to an entire testbed of GNUnet peers.
224 struct GNUNET_TESTING_Testbed;
228 * Topologies supported for testbeds.
230 enum GNUNET_TESTING_Topology
233 * A clique (everyone connected to everyone else).
235 GNUNET_TESTING_TOPOLOGY_CLIQUE,
238 * Small-world network (2d torus plus random links).
240 GNUNET_TESTING_TOPOLOGY_SMALL_WORLD,
245 GNUNET_TESTING_TOPOLOGY_RING,
250 GNUNET_TESTING_TOPOLOGY_2D_TORUS,
255 GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI,
258 * All peers are disconnected.
260 GNUNET_TESTING_TOPOLOGY_NONE
265 * Start "count" GNUnet daemons with a particular topology.
267 * @param sched scheduler to use
268 * @param cfg configuration template to use
269 * @param count number of peers the testbed should have
270 * @param topology desired topology (enforced via F2F)
271 * @param cb function to call on each daemon that was started
272 * @param cb_cls closure for cb
273 * @param hostname where to run the peers; can be NULL (to run
274 * everything on localhost). Additional
275 * hosts can be specified using a NULL-terminated list of
276 * varargs, hosts will then be used round-robin from that
278 * @return handle to control the testbed
280 struct GNUNET_TESTING_Testbed *
281 GNUNET_TESTING_testbed_start (struct GNUNET_SCHEDULER_Handle *sched,
282 const struct GNUNET_CONFIGURATION_Handle *cfg,
284 enum GNUNET_TESTING_Topology topology,
285 GNUNET_TESTING_NotifyDaemonRunning cb,
287 const char *hostname,
292 * Stop all of the daemons started with the start function.
294 * @param tb handle for the testbed
295 * @param cb function to call when done
296 * @param cb_cls closure for cb
299 GNUNET_TESTING_testbed_stop (struct GNUNET_TESTING_Testbed *tb,
300 GNUNET_TESTING_NotifyCompletion cb,
305 * Simulate churn in the testbed by stopping some peers (and possibly
306 * re-starting others if churn is called multiple times). This
307 * function can only be used to create leave-join churn (peers "never"
308 * leave for good). First "voff" random peers that are currently
309 * online will be taken offline; then "von" random peers that are then
310 * offline will be put back online. No notifications will be
311 * generated for any of these operations except for the callback upon
312 * completion. Note that the implementation is at liberty to keep
313 * the ARM service itself (but none of the other services or daemons)
314 * running even though the "peer" is being varied offline.
316 * @param tb handle for the testbed
317 * @param voff number of peers that should go offline
318 * @param von number of peers that should come back online;
319 * must be zero on first call (since "testbed_start"
320 * always starts all of the peers)
321 * @param cb function to call at the end
322 * @param cb_cls closure for cb
325 GNUNET_TESTING_testbed_churn (struct GNUNET_TESTING_Testbed *tb,
328 GNUNET_TESTING_NotifyCompletion cb,
332 #if 0 /* keep Emacsens' auto-indent happy */