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 to the daemon, NULL if starting the daemon failed
63 typedef void (*GNUNET_TESTING_NotifyDaemonRunning)(void *cls,
64 const struct GNUNET_PeerIdentity *id,
65 struct GNUNET_TESTING_Daemon *d);
69 * Starts a GNUnet daemon.
71 * @param service_home directory to use as the service home directory
72 * @param transports transport services that should be loaded
73 * @param applications application services and daemons that should be started
74 * @param port_offset offset to add to all ports for all services
75 * @param hostname name of the machine where to run GNUnet
76 * (use NULL for localhost).
77 * @param cb function to call with the result
78 * @param cb_cls closure for cb
81 GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched,
82 struct GNUNET_CONFIGURATION_Handle *cfg,
83 const char *service_home,
84 const char *transports,
85 const char *applications,
88 GNUNET_TESTING_NotifyDaemonRunning cb,
93 * Prototype of a function that will be called when a
94 * particular operation was completed the testing library.
97 * @param success GNUNET_YES on success
99 typedef void (*GNUNET_TESTING_NotifyCompletion)(void *cls,
104 * Stops a GNUnet daemon.
106 * @param d the daemon that should be stopped
107 * @param cb function called once the daemon was stopped
108 * @param cb_cls closure for cb
110 void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d,
111 GNUNET_TESTING_NotifyCompletion cb,
117 * Establish a connection between two GNUnet daemons.
119 * @param d1 handle for the first daemon
120 * @param d2 handle for the second daemon
121 * @param cb function to call at the end
122 * @param cb_cls closure for cb
124 void GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
125 struct GNUNET_TESTING_Daemon *d2,
126 GNUNET_TESTING_NotifyCompletion cb,
132 * Start count gnunetd processes with the same set of
133 * transports and applications. The port numbers will
134 * be computed by adding delta each time (zero
135 * times for the first peer).
137 * @param total number of daemons to start
138 * @param service_home_prefix path to use as the prefix for the home of the services
139 * @param transports which transports should all peers use
140 * @param applications which applications should be used?
141 * @param timeout how long is this allowed to take?
142 * @param cb function to call on each daemon that was started
143 * @param cb_cls closure for cb
144 * @param cbe function to call at the end
145 * @param cbe_cls closure for cbe
146 * @param hostname where to run the peers; can be NULL (to run
147 * everything on localhost).
148 * @param va Additional hosts can be specified using a NULL-terminated list of
149 * varargs, hosts will then be used round-robin from that
150 * list; va only contains anything if hostname != NULL.
153 GNUNET_TESTING_daemons_start_va (struct GNUNET_SCHEDULER_Handle *sched,
154 struct GNUNET_CONFIGURATION_Handle *cfg,
156 const char *service_home_prefix,
157 const char *transports,
158 const char *applications,
159 GNUNET_TESTING_NotifyDaemonRunning cb,
161 GNUNET_TESTING_NotifyCompletion cbe,
163 const char *hostname,
167 * Start count gnunetd processes with the same set of
168 * transports and applications. The port numbers will
169 * be computed by adding delta each time (zero
170 * times for the first peer).
172 * @param total number of daemons to start
173 * @param service_home_prefix path to use as the prefix for the home of the services
174 * @param transports which transports should all peers use
175 * @param applications which applications should be used?
176 * @param timeout how long is this allowed to take?
177 * @param cb function to call on each daemon that was started
178 * @param cb_cls closure for cb
179 * @param cbe function to call at the end
180 * @param cbe_cls closure for cbe
181 * @param hostname where to run the peers; can be NULL (to run
182 * everything on localhost). Additional
183 * hosts can be specified using a NULL-terminated list of
184 * varargs, hosts will then be used round-robin from that
188 GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
189 struct GNUNET_CONFIGURATION_Handle *cfg,
191 const char *service_home_prefix,
192 const char *transports,
193 const char *applications,
194 GNUNET_TESTING_NotifyDaemonRunning cb,
196 GNUNET_TESTING_NotifyCompletion cbe,
198 const char *hostname,
203 * Handle to an entire testbed of GNUnet peers.
205 struct GNUNET_TESTING_Testbed;
208 * Prototype of a function that will be called when
209 * a testbed is being created.
212 * @param tb NULL on error
214 typedef void (*GNUNET_TESTING_NotifyTestbedRunning)(void *cls,
215 struct GNUNET_TESTING_Testbed *tb);
219 * Topologies supported for testbeds.
221 enum GNUNET_TESTING_Topology
224 * A clique (everyone connected to everyone else).
226 GNUNET_TESTING_TOPOLOGY_CLIQUE,
229 * Small-world network (2d torus plus random links).
231 GNUNET_TESTING_TOPOLOGY_SMALL_WORLD,
236 GNUNET_TESTING_TOPOLOGY_RING,
241 GNUNET_TESTING_TOPOLOGY_2D_TORUS,
246 GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI,
249 * All peers are disconnected.
251 GNUNET_TESTING_TOPOLOGY_NONE
257 * Start count GNUnet daemons with a particular
260 * @param size number of peers the testbed should have
261 * @param topology desired topology (enforced via F2F)
262 * @param service_home_prefix path to use as the prefix for the home of the services
263 * @param transports which transports should all peers use
264 * @param applications which applications should be used?
265 * @param timeout how long is this allowed to take?
266 * @param cb function to call on each daemon that was started
267 * @param cb_cls closure for cb
268 * @param cte function to call at the end
269 * @param cte_cls closure for cbe
270 * @param hostname where to run the peers; can be NULL (to run
271 * everything on localhost). Additional
272 * hosts can be specified using a NULL-terminated list of
273 * varargs, hosts will then be used round-robin from that
277 GNUNET_TESTING_testbed_start (struct GNUNET_SCHEDULER_Handle *sched,
278 struct GNUNET_CONFIGURATION_Handle *cfg,
280 enum GNUNET_TESTING_Topology topology,
281 const char *service_home_prefix,
282 const char *transports,
283 const char *applications,
284 GNUNET_TESTING_NotifyDaemonRunning cb,
286 GNUNET_TESTING_NotifyTestbedRunning cte,
288 const char *hostname,
295 * Stop all of the daemons started with the start function.
297 * @param tb handle for the testbed
298 * @param cb function to call at the end
299 * @param cb_cls closure for cb
302 GNUNET_TESTING_testbed_stop (struct GNUNET_TESTING_Testbed *tb,
303 GNUNET_TESTING_NotifyCompletion cb,
309 * Simulate churn in the testbed by stopping some peers (and possibly
310 * re-starting others if churn is called multiple times). This
311 * function can only be used to create leave-join churn (peers "never"
312 * leave for good). First "voff" random peers that are currently
313 * online will be taken offline; then "von" random peers that are then
314 * offline will be put back online. No notifications will be
315 * generated for any of these operations except for the callback upon
316 * completion. Note that the implementation is at liberty to keep
317 * the ARM service itself (but none of the other services or daemons)
318 * running even though the "peer" is being varied offline.
320 * @param tb handle for the testbed
321 * @param voff number of peers that should go offline
322 * @param von number of peers that should come back online;
323 * must be zero on first call (since "testbed_start"
324 * always starts all of the peers)
325 * @param cb function to call at the end
326 * @param cb_cls closure for cb
329 GNUNET_TESTING_testbed_churn (struct GNUNET_TESTING_Testbed *tb,
332 GNUNET_TESTING_NotifyCompletion cb,
337 #if 0 /* keep Emacsens' auto-indent happy */