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 d handle for the daemon
62 * @param emsg error message (NULL on success)
64 typedef void (*GNUNET_TESTING_NotifyDaemonRunning)(void *cls,
65 const struct GNUNET_PeerIdentity *id,
66 const struct GNUNET_CONFIGURATION_Handle *cfg,
67 struct GNUNET_TESTING_Daemon *d,
72 * Starts a GNUnet daemon.
74 * @param sched scheduler to use
75 * @param cfg configuration to use
76 * @param service_home directory to use as the service home directory
77 * @param transports transport services that should be loaded
78 * @param applications application services and daemons that should be started
79 * @param port_offset offset to add to all ports for all services
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,
89 const char *service_home,
90 const char *transports,
91 const char *applications,
94 GNUNET_TESTING_NotifyDaemonRunning cb,
99 * Prototype of a function that will be called when a
100 * particular operation was completed the testing library.
103 * @param emsg NULL on success
105 typedef void (*GNUNET_TESTING_NotifyCompletion)(void *cls,
110 * Stops a GNUnet daemon.
112 * @param d the daemon that should be stopped
113 * @param cb function called once the daemon was stopped
114 * @param cb_cls closure for cb
116 void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
117 GNUNET_TESTING_NotifyCompletion cb,
122 * Changes the configuration of a GNUnet daemon.
124 * @param d the daemon that should be modified
125 * @param cfg the new configuration for the daemon
126 * @param cb function called once the configuration was changed
127 * @param cb_cls closure for cb
129 void GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d,
130 struct GNUNET_CONFIGURATION_Handle *cfg,
131 GNUNET_TESTING_NotifyCompletion cb,
137 * Establish a connection between two GNUnet daemons.
139 * @param d1 handle for the first daemon
140 * @param d2 handle for the second daemon
141 * @param timeout how long is the connection attempt
143 * @param cb function to call at the end
144 * @param cb_cls closure for cb
146 void GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
147 struct GNUNET_TESTING_Daemon *d2,
148 struct GNUNET_TIME_Relative timeout,
149 GNUNET_TESTING_NotifyCompletion cb,
155 * Start count gnunetd processes with the same set of
156 * transports and applications. The port numbers will
157 * be computed by adding delta each time (zero
158 * times for the first peer).
160 * @param sched scheduler to use
161 * @param cfg configuration to use
162 * @param total number of daemons to start
163 * @param service_home_prefix path to use as the prefix for the home of the services;
164 * a number will be added for the different peers
165 * @param transports which transports should all peers use
166 * @param applications which applications should be used?
167 * @param cb function to call on each daemon that was started
168 * @param cb_cls closure for cb
169 * @param cbe function to call at the end
170 * @param cbe_cls closure for cbe
171 * @param hostname where to run the peers; can be NULL (to run
172 * everything on localhost).
173 * @param va Additional hosts can be specified using a NULL-terminated list of
174 * varargs, hosts will then be used round-robin from that
175 * list; va only contains anything if hostname != NULL.
178 GNUNET_TESTING_daemons_start_va (struct GNUNET_SCHEDULER_Handle *sched,
179 struct GNUNET_CONFIGURATION_Handle *cfg,
181 const char *service_home_prefix,
182 const char *transports,
183 const char *applications,
184 GNUNET_TESTING_NotifyDaemonRunning cb,
186 GNUNET_TESTING_NotifyCompletion cbe,
188 const char *hostname,
192 * Start count gnunetd processes with the same set of
193 * transports and applications. The port numbers will
194 * be computed by adding delta each time (zero
195 * times for the first peer).
197 * @param total number of daemons to start
198 * @param service_home_prefix path to use as the prefix for the home of the services
199 * @param transports which transports should all peers use
200 * @param applications which applications should be used?
201 * @param timeout how long is this allowed to take?
202 * @param cb function to call on each daemon that was started
203 * @param cb_cls closure for cb
204 * @param cbe function to call at the end
205 * @param cbe_cls closure for cbe
206 * @param hostname where to run the peers; can be NULL (to run
207 * everything on localhost). Additional
208 * hosts can be specified using a NULL-terminated list of
209 * varargs, hosts will then be used round-robin from that
213 GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
214 struct GNUNET_CONFIGURATION_Handle *cfg,
216 const char *service_home_prefix,
217 const char *transports,
218 const char *applications,
219 GNUNET_TESTING_NotifyDaemonRunning cb,
221 GNUNET_TESTING_NotifyCompletion cbe,
223 const char *hostname,
228 * Handle to an entire testbed of GNUnet peers.
230 struct GNUNET_TESTING_Testbed;
233 * Prototype of a function that will be called when
234 * a testbed is being created.
237 * @param tb NULL on error
239 typedef void (*GNUNET_TESTING_NotifyTestbedRunning)(void *cls,
240 struct GNUNET_TESTING_Testbed *tb);
244 * Topologies supported for testbeds.
246 enum GNUNET_TESTING_Topology
249 * A clique (everyone connected to everyone else).
251 GNUNET_TESTING_TOPOLOGY_CLIQUE,
254 * Small-world network (2d torus plus random links).
256 GNUNET_TESTING_TOPOLOGY_SMALL_WORLD,
261 GNUNET_TESTING_TOPOLOGY_RING,
266 GNUNET_TESTING_TOPOLOGY_2D_TORUS,
271 GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI,
274 * All peers are disconnected.
276 GNUNET_TESTING_TOPOLOGY_NONE
282 * Start count GNUnet daemons with a particular
285 * @param size number of peers the testbed should have
286 * @param topology desired topology (enforced via F2F)
287 * @param service_home_prefix path to use as the prefix for the home of the services
288 * @param transports which transports should all peers use
289 * @param applications which applications should be used?
290 * @param timeout how long is this allowed to take?
291 * @param cb function to call on each daemon that was started
292 * @param cb_cls closure for cb
293 * @param cte function to call at the end
294 * @param cte_cls closure for cbe
295 * @param hostname where to run the peers; can be NULL (to run
296 * everything on localhost). Additional
297 * hosts can be specified using a NULL-terminated list of
298 * varargs, hosts will then be used round-robin from that
302 GNUNET_TESTING_testbed_start (struct GNUNET_SCHEDULER_Handle *sched,
303 struct GNUNET_CONFIGURATION_Handle *cfg,
305 enum GNUNET_TESTING_Topology topology,
306 const char *service_home_prefix,
307 const char *transports,
308 const char *applications,
309 GNUNET_TESTING_NotifyDaemonRunning cb,
311 GNUNET_TESTING_NotifyTestbedRunning cte,
313 const char *hostname,
320 * Stop all of the daemons started with the start function.
322 * @param tb handle for the testbed
323 * @param cb function to call at the end
324 * @param cb_cls closure for cb
327 GNUNET_TESTING_testbed_stop (struct GNUNET_TESTING_Testbed *tb,
328 GNUNET_TESTING_NotifyCompletion cb,
334 * Simulate churn in the testbed by stopping some peers (and possibly
335 * re-starting others if churn is called multiple times). This
336 * function can only be used to create leave-join churn (peers "never"
337 * leave for good). First "voff" random peers that are currently
338 * online will be taken offline; then "von" random peers that are then
339 * offline will be put back online. No notifications will be
340 * generated for any of these operations except for the callback upon
341 * completion. Note that the implementation is at liberty to keep
342 * the ARM service itself (but none of the other services or daemons)
343 * running even though the "peer" is being varied offline.
345 * @param tb handle for the testbed
346 * @param voff number of peers that should go offline
347 * @param von number of peers that should come back online;
348 * must be zero on first call (since "testbed_start"
349 * always starts all of the peers)
350 * @param cb function to call at the end
351 * @param cb_cls closure for cb
354 GNUNET_TESTING_testbed_churn (struct GNUNET_TESTING_Testbed *tb,
357 GNUNET_TESTING_NotifyCompletion cb,
362 #if 0 /* keep Emacsens' auto-indent happy */