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 * Prototype of a function that will be called whenever
74 * two daemons are connected by the testing library.
77 * @param first peer id for first daemon
78 * @param second peer id for the second daemon
79 * @param first_cfg config for the first daemon
80 * @param second_cfg config for the second daemon
81 * @param first_daemon handle for the first daemon
82 * @param second_daemon handle for the second daemon
83 * @param emsg error message (NULL on success)
85 typedef void (*GNUNET_TESTING_NotifyConnection)(void *cls,
86 const struct GNUNET_PeerIdentity *first,
87 const struct GNUNET_PeerIdentity *second,
88 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
89 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
90 struct GNUNET_TESTING_Daemon *first_daemon,
91 struct GNUNET_TESTING_Daemon *second_daemon,
95 * Starts a GNUnet daemon. GNUnet must be installed on the target
96 * system and available in the PATH. The machine must furthermore be
97 * reachable via "ssh" (unless the hostname is "NULL") without the
98 * need to enter a password.
100 * @param sched scheduler to use
101 * @param cfg configuration to use
102 * @param hostname name of the machine where to run GNUnet
103 * (use NULL for localhost).
104 * @param cb function to call with the result
105 * @param cb_cls closure for cb
106 * @return handle to the daemon (actual start will be completed asynchronously)
108 struct GNUNET_TESTING_Daemon *
109 GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
110 const struct GNUNET_CONFIGURATION_Handle *cfg,
111 const char *hostname,
112 GNUNET_TESTING_NotifyDaemonRunning cb,
117 * Prototype of a function that will be called when a
118 * particular operation was completed the testing library.
121 * @param emsg NULL on success
123 typedef void (*GNUNET_TESTING_NotifyCompletion)(void *cls,
128 * Stops a GNUnet daemon.
130 * @param d the daemon that should be stopped
131 * @param cb function called once the daemon was stopped
132 * @param cb_cls closure for cb
134 void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
135 GNUNET_TESTING_NotifyCompletion cb,
140 * Changes the configuration of a GNUnet daemon.
142 * @param d the daemon that should be modified
143 * @param cfg the new configuration for the daemon
144 * @param cb function called once the configuration was changed
145 * @param cb_cls closure for cb
147 void GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
148 struct GNUNET_CONFIGURATION_Handle *cfg,
149 GNUNET_TESTING_NotifyCompletion cb,
153 * Get the short name of a running peer
155 * @param d the daemon handle
158 GNUNET_TESTING_daemon_get_shortname(struct GNUNET_TESTING_Daemon *d);
161 * Establish a connection between two GNUnet daemons.
163 * @param d1 handle for the first daemon
164 * @param d2 handle for the second daemon
165 * @param timeout how long is the connection attempt
167 * @param cb function to call at the end
168 * @param cb_cls closure for cb
170 void GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
171 struct GNUNET_TESTING_Daemon *d2,
172 struct GNUNET_TIME_Relative timeout,
173 GNUNET_TESTING_NotifyConnection cb,
179 * Handle to a group of GNUnet peers.
181 struct GNUNET_TESTING_PeerGroup;
185 * Start count gnunetd processes with the same set of transports and
186 * applications. The port numbers (any option called "PORT") will be
187 * adjusted to ensure that no two peers running on the same system
188 * have the same port(s) in their respective configurations.
190 * @param sched scheduler to use
191 * @param cfg configuration template to use
192 * @param total number of daemons to start
193 * @param cb function to call on each daemon that was started
194 * @param cb_cls closure for cb
195 * @param connect_callback function to call each time two hosts are connected
196 * @param connect_callback_cls closure for connect_callback
197 * @param hostnames space-separated list of hostnames to use,
198 * NULL to use localhost only
199 * @return NULL on error, otherwise handle to control peer group
201 struct GNUNET_TESTING_PeerGroup *
202 GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
203 const struct GNUNET_CONFIGURATION_Handle *cfg,
205 GNUNET_TESTING_NotifyDaemonRunning cb,
207 GNUNET_TESTING_NotifyConnection connect_callback,
208 void *connect_callback_cls,
209 const char *hostnames);
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);
221 GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg);
225 * Handle to an entire testbed of GNUnet peers.
227 struct GNUNET_TESTING_Testbed;
231 * Topologies supported for testbeds.
233 enum GNUNET_TESTING_Topology
236 * A clique (everyone connected to everyone else).
238 GNUNET_TESTING_TOPOLOGY_CLIQUE,
241 * Small-world network (2d torus plus random links).
243 GNUNET_TESTING_TOPOLOGY_SMALL_WORLD,
248 GNUNET_TESTING_TOPOLOGY_RING,
253 GNUNET_TESTING_TOPOLOGY_2D_TORUS,
258 GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI,
261 * Certain percentage of peers are unable to communicate directly
262 * replicating NAT conditions
264 GNUNET_TESTING_TOPOLOGY_INTERNAT,
267 * All peers are disconnected.
269 GNUNET_TESTING_TOPOLOGY_NONE
274 * Start "count" GNUnet daemons with a particular topology.
276 * @param sched scheduler to use
277 * @param cfg configuration template to use
278 * @param count number of peers the testbed should have
279 * @param topology desired topology (enforced via F2F)
280 * @param cb function to call on each daemon that was started
281 * @param cb_cls closure for cb
282 * @param hostname where to run the peers; can be NULL (to run
283 * everything on localhost). Additional
284 * hosts can be specified using a NULL-terminated list of
285 * varargs, hosts will then be used round-robin from that
287 * @return handle to control the testbed
289 struct GNUNET_TESTING_Testbed *
290 GNUNET_TESTING_testbed_start (struct GNUNET_SCHEDULER_Handle *sched,
291 const struct GNUNET_CONFIGURATION_Handle *cfg,
293 enum GNUNET_TESTING_Topology topology,
294 GNUNET_TESTING_NotifyDaemonRunning cb,
296 const char *hostname,
301 * Stop all of the daemons started with the start function.
303 * @param tb handle for the testbed
304 * @param cb function to call when done
305 * @param cb_cls closure for cb
308 GNUNET_TESTING_testbed_stop (struct GNUNET_TESTING_Testbed *tb,
309 GNUNET_TESTING_NotifyCompletion cb,
314 * Simulate churn in the testbed by stopping some peers (and possibly
315 * re-starting others if churn is called multiple times). This
316 * function can only be used to create leave-join churn (peers "never"
317 * leave for good). First "voff" random peers that are currently
318 * online will be taken offline; then "von" random peers that are then
319 * offline will be put back online. No notifications will be
320 * generated for any of these operations except for the callback upon
321 * completion. Note that the implementation is at liberty to keep
322 * the ARM service itself (but none of the other services or daemons)
323 * running even though the "peer" is being varied offline.
325 * @param tb handle for the testbed
326 * @param voff number of peers that should go offline
327 * @param von number of peers that should come back online;
328 * must be zero on first call (since "testbed_start"
329 * always starts all of the peers)
330 * @param cb function to call at the end
331 * @param cb_cls closure for cb
334 GNUNET_TESTING_testbed_churn (struct GNUNET_TESTING_Testbed *tb,
337 GNUNET_TESTING_NotifyCompletion cb,
341 #if 0 /* keep Emacsens' auto-indent happy */