-adding missing break statements
[oweals/gnunet.git] / src / include / gnunet_testbed_service.h
1 /*
2       This file is part of GNUnet
3       (C) 2008--2013 Christian Grothoff (and other contributing authors)
4
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 3, or (at your
8       option) any later version.
9
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.
14
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.
19  */
20
21 /**
22  * @file include/gnunet_testbed_service.h
23  * @brief API for writing tests and creating large-scale
24  *        emulation testbeds for GNUnet.
25  * @author Christian Grothoff
26  */
27
28 #ifndef GNUNET_TESTBED_SERVICE_H
29 #define GNUNET_TESTBED_SERVICE_H
30
31 #include "gnunet_util_lib.h"
32 #include "gnunet_testing_lib.h"
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #if 0                           /* keep Emacsens' auto-indent happy */
38 }
39 #endif
40 #endif
41
42
43 /**
44  * Opaque handle to a host running experiments managed by the testbed framework.
45  * The master process must be able to SSH to this host without password (via
46  * ssh-agent).
47  */
48 struct GNUNET_TESTBED_Host;
49
50 /**
51  * Opaque handle to a peer controlled by the testbed framework.  A peer runs
52  * at a particular host.
53  */
54 struct GNUNET_TESTBED_Peer;
55
56 /**
57  * Opaque handle to an abstract operation to be executed by the testbed framework.
58  */
59 struct GNUNET_TESTBED_Operation;
60
61 /**
62  * Handle to interact with a GNUnet testbed controller.  Each
63  * controller has at least one master handle which is created when the
64  * controller is created; this master handle interacts with the
65  * controller process, destroying it destroys the controller (by
66  * closing stdin of the controller process).  Additionally,
67  * controllers can interact with each other (in a P2P fashion); those
68  * links are established via TCP/IP on the controller's service port.
69  */
70 struct GNUNET_TESTBED_Controller;
71
72
73 /**
74  * Create a host to run peers and controllers on.
75  *
76  * @param hostname name of the host, use "NULL" for localhost
77  * @param username username to use for the login; may be NULL
78  * @param cfg the configuration to use as a template while starting a controller
79  *          on this host.  Operation queue sizes specific to a host are also
80  *          read from this configuration handle
81  * @param port port number to use for ssh; use 0 to let ssh decide
82  * @return handle to the host, NULL on error
83  */
84 struct GNUNET_TESTBED_Host *
85 GNUNET_TESTBED_host_create (const char *hostname,
86                             const char *username,
87                             const struct GNUNET_CONFIGURATION_Handle *cfg,
88                             uint16_t port);
89
90
91
92 /**
93  * Create a host to run peers and controllers on.  This function is used
94  * if a peer learns about a host via IPC between controllers (and thus
95  * some higher-level controller has already determined the unique IDs).
96  *
97  * @param id global host ID assigned to the host; 0 is
98  *        reserved to always mean 'localhost'
99  * @param hostname name of the host, use "NULL" for localhost
100  * @param username username to use for the login; may be NULL
101  * @param cfg the configuration to use as a template while starting a controller
102  *          on this host.  Operation queue sizes specific to a host are also
103  *          read from this configuration handle
104  * @param port port number to use for ssh; use 0 to let ssh decide
105  * @return handle to the host, NULL on error
106  */
107 struct GNUNET_TESTBED_Host *
108 GNUNET_TESTBED_host_create_with_id (uint32_t id,
109                                     const char *hostname,
110                                     const char *username,
111                                     const struct GNUNET_CONFIGURATION_Handle
112                                     *cfg,
113                                     uint16_t port);
114
115
116 /**
117  * Load a set of hosts from a configuration file.  The hostfile format is
118  * specified at https://gnunet.org/content/hosts-file-format
119  *
120  * @param filename file with the host specification
121  * @param cfg the configuration to use as a template while starting a controller
122  *          on any of the loaded hosts.  Operation queue sizes specific to a host
123  *          are also read from this configuration handle
124  * @param hosts set to the hosts found in the file; caller must free this if
125  *          number of hosts returned is greater than 0
126  * @return number of hosts returned in 'hosts', 0 on error
127  */
128 unsigned int
129 GNUNET_TESTBED_hosts_load_from_file (const char *filename,
130                                      const struct GNUNET_CONFIGURATION_Handle
131                                      *cfg,
132                                      struct GNUNET_TESTBED_Host ***hosts);
133
134
135 /**
136  * Loads the set of host allocated by the LoadLeveler Job Scheduler.  This
137  * function is only available when compiled with support for LoadLeveler and is
138  * used for running on the SuperMUC
139  *
140  * @param cfg the configuration to use as a template while starting a controller
141  *          on any of the loaded hosts.  Operation queue sizes specific to a host
142  *          are also read from this configuration handle
143  * @param hosts set to the hosts found in the file; caller must free this if
144  *          number of hosts returned is greater than 0
145  * @return number of hosts returned in 'hosts', 0 on error
146  */
147 unsigned int
148 GNUNET_TESTBED_hosts_load_from_loadleveler (const struct
149                                             GNUNET_CONFIGURATION_Handle *cfg,
150                                             struct GNUNET_TESTBED_Host
151                                             ***hosts);
152
153 /**
154  * Destroy a host handle.  Must only be called once everything
155  * running on that host has been stopped.
156  *
157  * @param host handle to destroy
158  */
159 void
160 GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host);
161
162
163 /**
164  * The handle for whether a host is habitable or not
165  */
166 struct GNUNET_TESTBED_HostHabitableCheckHandle;
167
168
169 /**
170  * Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to
171  * inform whether the given host is habitable or not. The Handle returned by
172  * GNUNET_TESTBED_is_host_habitable() is invalid after this callback is called
173  *
174  * @param cls the closure given to GNUNET_TESTBED_is_host_habitable()
175  * @param host the host whose status is being reported; will be NULL if the host
176  *          given to GNUNET_TESTBED_is_host_habitable() is NULL
177  * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
178  */
179 typedef void (*GNUNET_TESTBED_HostHabitableCallback) (void *cls,
180                                                       const struct
181                                                       GNUNET_TESTBED_Host
182                                                       *host,
183                                                       int status);
184
185
186 /**
187  * Checks whether a host can be used to start testbed service
188  *
189  * @param host the host to check
190  * @param config the configuration handle to lookup the path of the testbed
191  *          helper
192  * @param cb the callback to call to inform about habitability of the given host
193  * @param cb_cls the closure for the callback
194  * @return NULL upon any error or a handle which can be passed to
195  *           GNUNET_TESTBED_is_host_habitable_cancel()
196  */
197 struct GNUNET_TESTBED_HostHabitableCheckHandle *
198 GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
199                                   const struct GNUNET_CONFIGURATION_Handle
200                                   *config,
201                                   GNUNET_TESTBED_HostHabitableCallback cb,
202                                   void *cb_cls);
203
204
205 /**
206  * Function to cancel a request started using GNUNET_TESTBED_is_host_habitable()
207  *
208  * @param handle the habitability check handle
209  */
210 void
211 GNUNET_TESTBED_is_host_habitable_cancel (struct
212                                          GNUNET_TESTBED_HostHabitableCheckHandle
213                                          *handle);
214
215 /**
216  * Obtain the host's hostname.
217  *
218  * @param host handle to the host, NULL means 'localhost'
219  * @return hostname of the host
220  */
221 const char *
222 GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host);
223
224
225 /**
226  * Enumeration with (at most 64) possible event types that
227  * can be monitored using the testbed framework.
228  */
229 enum GNUNET_TESTBED_EventType
230 {
231   /**
232    * A peer has been started.
233    */
234   GNUNET_TESTBED_ET_PEER_START = 0,
235
236   /**
237    * A peer has been stopped.
238    */
239   GNUNET_TESTBED_ET_PEER_STOP = 1,
240
241   /**
242    * A connection between two peers was established.
243    */
244   GNUNET_TESTBED_ET_CONNECT = 2,
245
246   /**
247    * A connection between two peers was torn down.
248    */
249   GNUNET_TESTBED_ET_DISCONNECT = 3,
250
251   /**
252    * A requested testbed operation has been completed.
253    */
254   GNUNET_TESTBED_ET_OPERATION_FINISHED = 4,
255
256 };
257
258
259 /**
260  * Types of information that can be requested about a peer.
261  */
262 enum GNUNET_TESTBED_PeerInformationType
263 {
264
265   /**
266    * Special value (not valid for requesting information)
267    * that is used in the event struct if a 'generic' pointer
268    * is returned (for other operations not related to this
269    * enumeration).
270    */
271   GNUNET_TESTBED_PIT_GENERIC = 0,
272
273   /**
274    * What configuration is the peer using?  Returns a 'const struct
275    * GNUNET_CONFIGURATION_Handle *'.  Valid until
276    * 'GNUNET_TESTNIG_operation_done' is called.  However, the
277    * values may be inaccurate if the peer is reconfigured in
278    * the meantime.
279    */
280   GNUNET_TESTBED_PIT_CONFIGURATION,
281
282   /**
283    * What is the identity of the peer?  Returns a
284    * 'const struct GNUNET_PeerIdentity *'.  Valid until
285    * 'GNUNET_TESTNIG_operation_done' is called.
286    */
287   GNUNET_TESTBED_PIT_IDENTITY
288
289 };
290
291
292 /**
293  * Argument to GNUNET_TESTBED_ControllerCallback with details about
294  * the event.
295  */
296 struct GNUNET_TESTBED_EventInformation
297 {
298
299   /**
300    * Type of the event.
301    */
302   enum GNUNET_TESTBED_EventType type;
303
304   /**
305    * Handle for the corresponding operation that generated this event
306    */
307   struct GNUNET_TESTBED_Operation *op;
308
309   /**
310    * Closure given while creating the above operation
311    */
312   void *op_cls;
313
314   /**
315    * Details about the event.
316    */
317   union
318   {
319
320     /**
321      * Details about peer start event.
322      */
323     struct
324     {
325       /**
326        * Handle for the host where the peer
327        * was started.
328        */
329       struct GNUNET_TESTBED_Host *host;
330
331       /**
332        * Handle for the peer that was started.
333        */
334       struct GNUNET_TESTBED_Peer *peer;
335
336     } peer_start;
337
338     /**
339      * Details about peer stop event.
340      */
341     struct
342     {
343
344       /**
345        * Handle for the peer that was started.
346        */
347       struct GNUNET_TESTBED_Peer *peer;
348
349     } peer_stop;
350
351     /**
352      * Details about connect event.
353      */
354     struct
355     {
356       /**
357        * Handle for one of the connected peers.
358        */
359       struct GNUNET_TESTBED_Peer *peer1;
360
361       /**
362        * Handle for one of the connected peers.
363        */
364       struct GNUNET_TESTBED_Peer *peer2;
365
366     } peer_connect;
367
368     /**
369      * Details about disconnect event.
370      */
371     struct
372     {
373       /**
374        * Handle for one of the disconnected peers.
375        */
376       struct GNUNET_TESTBED_Peer *peer1;
377
378       /**
379        * Handle for one of the disconnected peers.
380        */
381       struct GNUNET_TESTBED_Peer *peer2;
382
383     } peer_disconnect;
384
385     /**
386      * Details about an operation finished event.
387      */
388     struct
389     {
390       /**
391        * Error message for the operation, NULL on success.
392        */
393       const char *emsg;
394
395       /**
396        * No result (NULL pointer) or generic result
397        * (whatever the GNUNET_TESTBED_ConnectAdapter returned).
398        */
399       void *generic;
400
401     } operation_finished;
402
403   } details;
404
405 };
406
407
408 /**
409  * Signature of the event handler function called by the
410  * respective event controller.
411  *
412  * @param cls closure
413  * @param event information about the event
414  */
415 typedef void (*GNUNET_TESTBED_ControllerCallback)(void *cls,
416                                                   const struct GNUNET_TESTBED_EventInformation *event);
417
418
419 /**
420  * Opaque Handle for Controller process
421  */
422 struct GNUNET_TESTBED_ControllerProc;
423
424
425 /**
426  * Callback to signal successfull startup of the controller process
427  *
428  * @param cls the closure from GNUNET_TESTBED_controller_start()
429  * @param cfg the configuration with which the controller has been started;
430  *          NULL if status is not GNUNET_OK
431  * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
432  *          GNUNET_TESTBED_controller_stop() shouldn't be called in this case
433  */
434 typedef void (*GNUNET_TESTBED_ControllerStatusCallback) (void *cls,
435                                                         const struct GNUNET_CONFIGURATION_Handle *cfg,
436                                                         int status);
437
438
439 /**
440  * Starts a controller process at the given host.  The given host's configration
441  * is used as a Template configuration to use for the remote controller; the
442  * remote controller will be started with a slightly modified configuration
443  * (port numbers, unix domain sockets and service home values are changed as per
444  * TESTING library on the remote host).  The modified configuration replaces the
445  * host's existing configuration before signalling success through the
446  * GNUNET_TESTBED_ControllerStatusCallback()
447  *
448  * @param trusted_ip the ip address of the controller which will be set as TRUSTED
449  *          HOST(all connections form this ip are permitted by the testbed) when
450  *          starting testbed controller at host. This can either be a single ip
451  *          address or a network address in CIDR notation.
452  * @param host the host where the controller has to be started.  CANNOT be NULL.
453  * @param cb function called when the controller is successfully started or
454  *          dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
455  *          called if cb is called with GNUNET_SYSERR as status. Will never be
456  *          called in the same task as 'GNUNET_TESTBED_controller_start'
457  *          (synchronous errors will be signalled by returning NULL). This
458  *          parameter cannot be NULL.
459  * @param cls closure for above callbacks
460  * @return the controller process handle, NULL on errors
461  */
462 struct GNUNET_TESTBED_ControllerProc *
463 GNUNET_TESTBED_controller_start (const char *trusted_ip,
464                                  struct GNUNET_TESTBED_Host *host,
465                                  GNUNET_TESTBED_ControllerStatusCallback cb,
466                                  void *cls);
467
468
469 /**
470  * Stop the controller process (also will terminate all peers and controllers
471  * dependent on this controller).  This function blocks until the testbed has
472  * been fully terminated (!). The controller status cb from
473  * GNUNET_TESTBED_controller_start() will not be called.
474  *
475  * @param cproc the controller process handle
476  */
477 void
478 GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc);
479
480
481 /**
482  * Connect to a controller process.  The configuration to use for the connection
483  * is retreived from the given host where a controller is started using
484  * GNUNET_TESTBED_controller_start().
485  *
486  * @param host host to run the controller on; This should be the same host if
487  *          the controller was previously started with
488  *          GNUNET_TESTBED_controller_start()
489  * @param event_mask bit mask with set of events to call 'cc' for;
490  *                   or-ed values of "1LL" shifted by the
491  *                   respective 'enum GNUNET_TESTBED_EventType'
492  *                   (i.e.  "(1LL << GNUNET_TESTBED_ET_CONNECT) | ...")
493  * @param cc controller callback to invoke on events
494  * @param cc_cls closure for cc
495  * @return handle to the controller
496  */
497 struct GNUNET_TESTBED_Controller *
498 GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
499                                    uint64_t event_mask,
500                                    GNUNET_TESTBED_ControllerCallback cc,
501                                    void *cc_cls);
502
503
504 /**
505  * Stop the given controller (also will terminate all peers and
506  * controllers dependent on this controller).  This function
507  * blocks until the testbed has been fully terminated (!).
508  *
509  * @param c handle to controller to stop
510  */
511 void
512 GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c);
513
514
515 /**
516  * Opaque handle for host registration
517  */
518 struct GNUNET_TESTBED_HostRegistrationHandle;
519
520
521 /**
522  * Callback which will be called to after a host registration succeeded or failed
523  *
524  * @param cls the closure
525  * @param emsg the error message; NULL if host registration is successful
526  */
527 typedef void (* GNUNET_TESTBED_HostRegistrationCompletion) (void *cls,
528                                                             const char *emsg);
529
530
531 /**
532  * Register a host with the controller. This makes the controller aware of the
533  * host. A host should be registered at the controller before starting a
534  * sub-controller on that host using GNUNET_TESTBED_controller_link().
535  *
536  * @param controller the controller handle
537  * @param host the host to register
538  * @param cc the completion callback to call to inform the status of
539  *          registration. After calling this callback the registration handle
540  *          will be invalid. Cannot be NULL
541  * @param cc_cls the closure for the cc
542  * @return handle to the host registration which can be used to cancel the
543  *           registration; NULL if another registration handle is present and
544  *           is not cancelled
545  */
546 struct GNUNET_TESTBED_HostRegistrationHandle *
547 GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
548                               struct GNUNET_TESTBED_Host *host,
549                               GNUNET_TESTBED_HostRegistrationCompletion cc,
550                               void *cc_cls);
551
552
553 /**
554  * Cancel the pending registration. Note that the registration message will
555  * already be queued to be sent to the service, cancellation has only the
556  * effect that the registration completion callback for the registration is
557  * never called and from our perspective the host is not registered until the
558  * completion callback is called.
559  *
560  * @param handle the registration handle to cancel
561  */
562 void
563 GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
564                                     *handle);
565
566
567 /**
568  * Callback to be called when an operation is completed
569  *
570  * @param cls the callback closure from functions generating an operation
571  * @param op the operation that has been finished
572  * @param emsg error message in case the operation has failed; will be NULL if
573  *          operation has executed successfully.
574  */
575 typedef void (*GNUNET_TESTBED_OperationCompletionCallback) (void *cls,
576                                                             struct
577                                                             GNUNET_TESTBED_Operation
578                                                             *op,
579                                                             const char *emsg);
580
581
582 /**
583  * Create a link from slave controller to delegated controller. Whenever the
584  * master controller is asked to start a peer at the delegated controller the
585  * request will be routed towards slave controller (if a route exists). The
586  * slave controller will then route it to the delegated controller. The
587  * configuration of the delegated controller is given and is used to either
588  * create the delegated controller or to connect to an existing controller. Note
589  * that while starting the delegated controller the configuration will be
590  * modified to accommodate available free ports.  the 'is_subordinate' specifies
591  * if the given delegated controller should be started and managed by the slave
592  * controller, or if the delegated controller already has a master and the slave
593  * controller connects to it as a non master controller. The success or failure
594  * of this operation will be signalled through the
595  * GNUNET_TESTBED_ControllerCallback() with an event of type
596  * #GNUNET_TESTBED_ET_OPERATION_FINISHED
597  *
598  * @param op_cls the operation closure for the event which is generated to
599  *          signal success or failure of this operation
600  * @param master handle to the master controller who creates the association
601  * @param delegated_host requests to which host should be delegated; cannot be NULL
602  * @param slave_host which host is used to run the slave controller; use NULL to
603  *          make the master controller connect to the delegated host
604  * @param is_subordinate #GNUNET_YES if the controller at delegated_host should
605  *          be started by the slave controller; #GNUNET_NO if the slave
606  *          controller has to connect to the already started delegated
607  *          controller via TCP/IP
608  * @return the operation handle
609  */
610 struct GNUNET_TESTBED_Operation *
611 GNUNET_TESTBED_controller_link (void *op_cls,
612                                 struct GNUNET_TESTBED_Controller *master,
613                                 struct GNUNET_TESTBED_Host *delegated_host,
614                                 struct GNUNET_TESTBED_Host *slave_host,
615                                 int is_subordinate);
616
617
618 /**
619  * Function to acquire the configuration of a running slave controller. The
620  * completion of the operation is signalled through the controller_cb from
621  * GNUNET_TESTBED_controller_connect(). If the operation is successful the
622  * handle to the configuration is available in the generic pointer of
623  * operation_finished field of `struct GNUNET_TESTBED_EventInformation`.
624  *
625  * @param op_cls the closure for the operation
626  * @param master the handle to master controller
627  * @param slave_host the host where the slave controller is running; the handle
628  *          to the slave_host should remain valid until this operation is
629  *          cancelled or marked as finished
630  * @return the operation handle; NULL if the slave_host is not registered at
631  *           master
632  */
633 struct GNUNET_TESTBED_Operation *
634 GNUNET_TESTBED_get_slave_config (void *op_cls,
635                                  struct GNUNET_TESTBED_Controller *master,
636                                  struct GNUNET_TESTBED_Host *slave_host);
637
638
639 /**
640  * Functions of this signature are called when a peer has been successfully
641  * created
642  *
643  * @param cls the closure from GNUNET_TESTBED_peer_create()
644  * @param peer the handle for the created peer; NULL on any error during
645  *          creation
646  * @param emsg NULL if peer is not NULL; else MAY contain the error description
647  */
648 typedef void (*GNUNET_TESTBED_PeerCreateCallback) (void *cls,
649                                                    struct GNUNET_TESTBED_Peer *peer,
650                                                    const char *emsg);
651
652
653 /**
654  * Create the given peer at the specified host using the given
655  * controller.  If the given controller is not running on the target
656  * host, it should find or create a controller at the target host and
657  * delegate creating the peer.  Explicit delegation paths can be setup
658  * using 'GNUNET_TESTBED_controller_link'.  If no explicit delegation
659  * path exists, a direct link with a subordinate controller is setup
660  * for the first delegated peer to a particular host; the subordinate
661  * controller is then destroyed once the last peer that was delegated
662  * to the remote host is stopped.
663  *
664  * Creating the peer only creates the handle to manipulate and further
665  * configure the peer; use #GNUNET_TESTBED_peer_start and
666  * #GNUNET_TESTBED_peer_stop to actually start/stop the peer's
667  * processes.
668  *
669  * Note that the given configuration will be adjusted by the
670  * controller to avoid port/path conflicts with other peers.
671  * The "final" configuration can be obtained using
672  * #GNUNET_TESTBED_peer_get_information.
673  *
674  * @param controller controller process to use
675  * @param host host to run the peer on; cannot be NULL
676  * @param cfg Template configuration to use for the peer. Should exist until
677  *          operation is cancelled or GNUNET_TESTBED_operation_done() is called
678  * @param cb the callback to call when the peer has been created
679  * @param cls the closure to the above callback
680  * @return the operation handle
681  */
682 struct GNUNET_TESTBED_Operation *
683 GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
684                             struct GNUNET_TESTBED_Host *host,
685                             const struct GNUNET_CONFIGURATION_Handle *cfg,
686                             GNUNET_TESTBED_PeerCreateCallback cb,
687                             void *cls);
688
689
690 /**
691  * Functions of this signature are called when a peer has been successfully
692  * started or stopped.
693  *
694  * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
695  * @param emsg NULL on success; otherwise an error description
696  */
697 typedef void (*GNUNET_TESTBED_PeerChurnCallback) (void *cls,
698                                                   const char *emsg);
699
700
701 /**
702  * Start the given peer.
703  *
704  * @param op_cls the closure for this operation; will be set in the event
705  *          information
706  * @param peer peer to start
707  * @param pcc function to call upon completion
708  * @param pcc_cls closure for 'pcc'
709  * @return handle to the operation
710  */
711 struct GNUNET_TESTBED_Operation *
712 GNUNET_TESTBED_peer_start (void *op_cls,
713                            struct GNUNET_TESTBED_Peer *peer,
714                            GNUNET_TESTBED_PeerChurnCallback pcc,
715                            void *pcc_cls);
716
717
718 /**
719  * Stop the given peer.  The handle remains valid (use
720  * #GNUNET_TESTBED_peer_destroy to fully clean up the
721  * state of the peer).
722  *
723  * @param op_cls the closure for this operation; will be set in the event
724  *          information
725  * @param peer peer to stop
726  * @param pcc function to call upon completion
727  * @param pcc_cls closure for 'pcc'
728  * @return handle to the operation
729  */
730 struct GNUNET_TESTBED_Operation *
731 GNUNET_TESTBED_peer_stop (void *op_cls,
732                           struct GNUNET_TESTBED_Peer *peer,
733                           GNUNET_TESTBED_PeerChurnCallback pcc,
734                           void *pcc_cls);
735
736
737 /**
738  * Data returned from GNUNET_TESTBED_peer_get_information
739  */
740 struct GNUNET_TESTBED_PeerInformation
741 {
742   /**
743    * Peer information type; captures which of the types
744    * in the 'op_result' is actually in use.
745    */
746   enum GNUNET_TESTBED_PeerInformationType pit;
747
748   /**
749    * The result of the get information operation; Choose according to the pit
750    */
751   union
752   {
753     /**
754      * The configuration of the peer
755      */
756     struct GNUNET_CONFIGURATION_Handle *cfg;
757
758     /**
759      * The identity of the peer
760      */
761     struct GNUNET_PeerIdentity *id;
762   } result;
763 };
764
765
766 /**
767  * Callback to be called when the requested peer information is available
768  * The peer information in the callback is valid until the operation 'op' is canceled.
769  *
770  * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
771  * @param op the operation this callback corresponds to
772  * @param pinfo the result; will be NULL if the operation has failed
773  * @param emsg error message if the operation has failed; will be NULL if the
774  *          operation is successfull
775  */
776 typedef void (*GNUNET_TESTBED_PeerInfoCallback) (void *cb_cls,
777                                                  struct GNUNET_TESTBED_Operation
778                                                  *op,
779                                                  const struct
780                                                  GNUNET_TESTBED_PeerInformation
781                                                  *pinfo,
782                                                  const char *emsg);
783
784
785 /**
786  * Request information about a peer. The controller callback will not be called
787  * with event type #GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this
788  * operation is available. Instead, the GNUNET_TESTBED_PeerInfoCallback() will
789  * be called.
790  * The peer information in the callback is valid until the operation is canceled.
791  *
792  * @param peer peer to request information about
793  * @param pit desired information
794  * @param cb the convenience callback to be called when results for this
795  *          operation are available
796  * @param cb_cls the closure for @a cb
797  * @return handle to the operation
798  */
799 struct GNUNET_TESTBED_Operation *
800 GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
801                                      enum GNUNET_TESTBED_PeerInformationType
802                                      pit,
803                                      GNUNET_TESTBED_PeerInfoCallback cb,
804                                      void *cb_cls);
805
806
807 /**
808  * Change @a peer configuration.  Ports and paths cannot be changed this
809  * way.
810  *
811  * @param peer peer to change configuration for
812  * @param cfg new configuration
813  * @return handle to the operation
814  */
815 struct GNUNET_TESTBED_Operation *
816 GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
817                                           const struct GNUNET_CONFIGURATION_Handle *cfg);
818
819
820 /**
821  * Destroy the given peer; the peer should have been
822  * stopped first (if it was started).
823  *
824  * @param peer peer to stop
825  * @return handle to the operation
826  */
827 struct GNUNET_TESTBED_Operation *
828 GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer);
829
830
831 /**
832  * Start or stop given service at a peer.  This should not be called to
833  * start/stop the peer's ARM service.  Use GNUNET_TESTBED_peer_start(),
834  * GNUNET_TESTBED_peer_stop() for starting/stopping peer's ARM service.  Success
835  * or failure of the generated operation is signalled through the controller
836  * event callback and/or operation completion callback.
837  *
838  * @param op_cls the closure for the operation
839  * @param peer the peer whose service is to be started/stopped
840  * @param service_name the name of the service
841  * @param cb the operation completion callback
842  * @param cb_cls the closure for @a cb
843  * @param start 1 to start the service; 0 to stop the service
844  * @return an operation handle; NULL upon error (peer not running)
845  */
846 struct GNUNET_TESTBED_Operation *
847 GNUNET_TESTBED_peer_manage_service (void *op_cls,
848                                     struct GNUNET_TESTBED_Peer *peer,
849                                     const char *service_name,
850                                     GNUNET_TESTBED_OperationCompletionCallback cb,
851                                     void *cb_cls,
852                                     unsigned int start);
853
854
855 /**
856  * Stops and destroys all peers.  Is equivalent of calling
857  * GNUNET_TESTBED_peer_stop() and GNUNET_TESTBED_peer_destroy() on all peers,
858  * except that the peer stop event and operation finished event corresponding to
859  * the respective functions are not generated.  This function should be called
860  * when there are no other pending operations.  If there are pending operations,
861  * it will return NULL
862  *
863  * @param c the controller to send this message to
864  * @param op_cls closure for the operation
865  * @param cb the callback to call when all peers are stopped and destroyed
866  * @param cb_cls the closure for the callback
867  * @return operation handle on success; NULL if any pending operations are
868  *           present
869  */
870 struct GNUNET_TESTBED_Operation *
871 GNUNET_TESTBED_shutdown_peers (struct GNUNET_TESTBED_Controller *c,
872                                void *op_cls,
873                                GNUNET_TESTBED_OperationCompletionCallback cb,
874                                void *cb_cls);
875
876
877
878 /**
879  * Options for peer connections.
880  */
881 enum GNUNET_TESTBED_ConnectOption
882 {
883   /**
884    * No option (not valid as an argument).
885    */
886   GNUNET_TESTBED_CO_NONE = 0,
887
888   /**
889    * Allow or disallow a connection between the specified peers.
890    * Followed by #GNUNET_NO (int) if a connection is disallowed
891    * or #GNUNET_YES if a connection is allowed.  Note that the
892    * default (all connections allowed or disallowed) is
893    * specified in the configuration of the controller.
894    */
895   GNUNET_TESTBED_CO_ALLOW = 1,
896
897   /**
898    * FIXME: add (and implement) options to limit connection to
899    * particular transports, force simulation of particular latencies
900    * or message loss rates, or set bandwidth limitations.
901    */
902
903 };
904
905
906 /**
907  * Manipulate the P2P underlay topology by configuring a link
908  * between two peers.
909  *
910  * @param op_cls closure argument to give with the operation event
911  * @param p1 first peer
912  * @param p2 second peer
913  * @param co option to change
914  * @param ap option-specific values
915  * @return handle to the operation, NULL if configuring the link at this
916  *         time is not allowed
917  */
918 struct GNUNET_TESTBED_Operation *
919 GNUNET_TESTBED_underlay_configure_link_va (void *op_cls,
920                                            struct GNUNET_TESTBED_Peer *p1,
921                                            struct GNUNET_TESTBED_Peer *p2,
922                                            enum GNUNET_TESTBED_ConnectOption co,
923                                            va_list ap);
924
925
926 /**
927  * Manipulate the P2P underlay topology by configuring a link
928  * between two peers.
929  *
930  * @param op_cls closure argument to give with the operation event
931  * @param p1 first peer
932  * @param p2 second peer
933  * @param co option to change
934  * @param ... option-specific values
935  * @return handle to the operation, NULL if configuring the link at this
936  *         time is not allowed
937  */
938 struct GNUNET_TESTBED_Operation *
939 GNUNET_TESTBED_underlay_configure_link (void *op_cls,
940                                         struct GNUNET_TESTBED_Peer *p1,
941                                         struct GNUNET_TESTBED_Peer *p2,
942                                         enum GNUNET_TESTBED_ConnectOption co, ...);
943
944
945
946 /**
947  * Topologies and topology options supported for testbeds. Options should always
948  * end with GNUNET_TESTBED_TOPOLOGY_OPTION_END
949  */
950 enum GNUNET_TESTBED_TopologyOption
951 {
952   /**
953    * A clique (everyone connected to everyone else).  No options. If there are N
954    * peers this topology results in (N * (N -1)) connections.
955    */
956   GNUNET_TESTBED_TOPOLOGY_CLIQUE,
957
958   /**
959    * Small-world network (2d torus plus random links).  Followed
960    * by the number of random links to add (unsigned int).
961    */
962   GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD,
963
964   /**
965    * Small-world network (ring plus random links).  Followed
966    * by the number of random links to add (unsigned int).
967    */
968   GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING,
969
970   /**
971    * Ring topology.  No options.
972    */
973   GNUNET_TESTBED_TOPOLOGY_RING,
974
975   /**
976    * 2-d torus.  No options.
977    */
978   GNUNET_TESTBED_TOPOLOGY_2D_TORUS,
979
980   /**
981    * Random graph.  Followed by the number of random links to be established
982    * (unsigned int)
983    */
984   GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
985
986   /**
987    * Certain percentage of peers are unable to communicate directly
988    * replicating NAT conditions.  Followed by the fraction of
989    * NAT'ed peers (float).
990    */
991   GNUNET_TESTBED_TOPOLOGY_INTERNAT,
992
993   /**
994    * Scale free topology.  It is generated according to the method described in
995    * "Emergence of Scaling in Random Networks." Science 286, 509-512, 1999.
996    *
997    * This options takes two arguments in the following order: an uint16_t to
998    * determine the maximum number of edges a peer is permitted to have while
999    * generating scale free topology, a good value for this argument is 70; and
1000    * an uint8_t to determine the number of edges to be established when adding a
1001    * new node to the scale free network, a good value for this argument is 4.
1002    */
1003   GNUNET_TESTBED_TOPOLOGY_SCALE_FREE,
1004
1005   /**
1006    * Straight line topology.  No options.
1007    */
1008   GNUNET_TESTBED_TOPOLOGY_LINE,
1009
1010   /**
1011    * Read a topology from a given file.  Followed by the name of the file (const char *).
1012    */
1013   GNUNET_TESTBED_TOPOLOGY_FROM_FILE,
1014
1015   /**
1016    * All peers are disconnected.  No options.
1017    */
1018   GNUNET_TESTBED_TOPOLOGY_NONE,
1019
1020   /**
1021    * The options should always end with this
1022    */
1023   GNUNET_TESTBED_TOPOLOGY_OPTION_END,
1024
1025   /* The following are not topologies but influence how the topology has to be
1026      setup. These options should follow the topology specific options (if
1027      required by the chosen topology). Note that these should be given before
1028      GNUNET_TESTBED_TOPOLOGY_OPTION_END */
1029
1030   /**
1031    * How many times should the failed overlay connect operations be retried
1032    * before giving up.  The default if this option is not specified is to retry
1033    * 3 times.  This option takes and unsigned integer as a parameter.  Use this
1034    * option with parameter 0 to disable retrying of failed overlay connect
1035    * operations.
1036    */
1037   GNUNET_TESTBED_TOPOLOGY_RETRY_CNT
1038 };
1039
1040
1041 /**
1042  * Configure overall network topology to have a particular shape.
1043  *
1044  * @param op_cls closure argument to give with the operation event
1045  * @param num_peers number of peers in 'peers'
1046  * @param peers array of 'num_peers' with the peers to configure
1047  * @param topo desired underlay topology to use
1048  * @param ap topology-specific options
1049  * @return handle to the operation, NULL if configuring the topology
1050  *         is not allowed at this time
1051  */
1052 struct GNUNET_TESTBED_Operation *
1053 GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
1054                                                unsigned int num_peers,
1055                                                struct GNUNET_TESTBED_Peer **peers,
1056                                                enum GNUNET_TESTBED_TopologyOption topo,
1057                                                va_list ap);
1058
1059
1060 /**
1061  * Configure overall network topology to have a particular shape.
1062  *
1063  * @param op_cls closure argument to give with the operation event
1064  * @param num_peers number of peers in 'peers'
1065  * @param peers array of 'num_peers' with the peers to configure
1066  * @param topo desired underlay topology to use
1067  * @param ... topology-specific options
1068  * @return handle to the operation, NULL if configuring the topology
1069  *         is not allowed at this time
1070  */
1071 struct GNUNET_TESTBED_Operation *
1072 GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
1073                                             unsigned int num_peers,
1074                                             struct GNUNET_TESTBED_Peer **peers,
1075                                             enum GNUNET_TESTBED_TopologyOption topo,
1076                                             ...);
1077
1078
1079 /**
1080  * Both peers must have been started before calling this function.
1081  * This function then obtains a HELLO from @a p1, gives it to @a p2
1082  * and asks @a p2 to connect to @a p1.
1083  *
1084  * @param op_cls closure argument to give with the operation event
1085  * @param cb the callback to call when this operation has finished
1086  * @param cb_cls the closure for @a cb
1087  * @param p1 first peer
1088  * @param p2 second peer
1089  * @return handle to the operation, NULL if connecting these two
1090  *         peers is fundamentally not possible at this time (peers
1091  *         not running or underlay disallows)
1092  */
1093 struct GNUNET_TESTBED_Operation *
1094 GNUNET_TESTBED_overlay_connect (void *op_cls,
1095                                 GNUNET_TESTBED_OperationCompletionCallback cb,
1096                                 void *cb_cls,
1097                                 struct GNUNET_TESTBED_Peer *p1,
1098                                 struct GNUNET_TESTBED_Peer *p2);
1099
1100
1101 /**
1102  * Callbacks of this type are called when topology configuration is completed
1103  *
1104  * @param cls the operation closure given to
1105  *          GNUNET_TESTBED_overlay_configure_topology_va() and
1106  *          GNUNET_TESTBED_overlay_configure() calls
1107  * @param nsuccess the number of successful overlay connects
1108  * @param nfailures the number of overlay connects which failed
1109  */
1110 typedef void (*GNUNET_TESTBED_TopologyCompletionCallback) (void *cls,
1111                                                           unsigned int nsuccess,
1112                                                           unsigned int nfailures);
1113
1114
1115 /**
1116  * All peers must have been started before calling this function.
1117  * This function then connects the given peers in the P2P overlay
1118  * using the given topology.
1119  *
1120  * @param op_cls closure argument to give with the peer connect operation events
1121  *          generated through this function
1122  * @param num_peers number of peers in 'peers'
1123  * @param peers array of 'num_peers' with the peers to configure
1124  * @param max_connections the maximums number of overlay connections that will
1125  *          be made to achieve the given topology
1126  * @param comp_cb the completion callback to call when the topology generation
1127  *          is completed
1128  * @param comp_cb_cls closure for the @a comp_cb
1129  * @param topo desired underlay topology to use
1130  * @param va topology-specific options
1131  * @return handle to the operation, NULL if connecting these
1132  *         peers is fundamentally not possible at this time (peers
1133  *         not running or underlay disallows) or if num_peers is less than 2
1134  */
1135 struct GNUNET_TESTBED_Operation *
1136 GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
1137                                               unsigned int num_peers,
1138                                               struct GNUNET_TESTBED_Peer **peers,
1139                                               unsigned int *max_connections,
1140                                               GNUNET_TESTBED_TopologyCompletionCallback
1141                                               comp_cb,
1142                                               void *comp_cb_cls,
1143                                               enum GNUNET_TESTBED_TopologyOption topo,
1144                                               va_list va);
1145
1146
1147 /**
1148  * All peers must have been started before calling this function.
1149  * This function then connects the given peers in the P2P overlay
1150  * using the given topology.
1151  *
1152  * @param op_cls closure argument to give with the peer connect operation events
1153  *          generated through this function
1154  * @param num_peers number of peers in 'peers'
1155  * @param peers array of 'num_peers' with the peers to configure
1156  * @param max_connections the maximums number of overlay connections that will
1157  *          be made to achieve the given topology
1158  * @param comp_cb the completion callback to call when the topology generation
1159  *          is completed
1160  * @param comp_cb_cls closure for the above completion callback
1161  * @param topo desired underlay topology to use
1162  * @param ... topology-specific options
1163  * @return handle to the operation, NULL if connecting these
1164  *         peers is fundamentally not possible at this time (peers
1165  *         not running or underlay disallows) or if num_peers is less than 2
1166  */
1167 struct GNUNET_TESTBED_Operation *
1168 GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
1169                                            unsigned int num_peers,
1170                                            struct GNUNET_TESTBED_Peer **peers,
1171                                            unsigned int *max_connections,
1172                                            GNUNET_TESTBED_TopologyCompletionCallback
1173                                            comp_cb,
1174                                            void *comp_cb_cls,
1175                                            enum GNUNET_TESTBED_TopologyOption topo,
1176                                            ...);
1177
1178
1179 /**
1180  * Ask the testbed controller to write the current overlay topology to
1181  * a file.  Naturally, the file will only contain a snapshot as the
1182  * topology may evolve all the time.
1183  * FIXME: needs continuation!?
1184  *
1185  * @param controller overlay controller to inspect
1186  * @param filename name of the file the topology should
1187  *        be written to.
1188  */
1189 void
1190 GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller *controller,
1191                                                const char *filename);
1192
1193
1194 /**
1195  * Adapter function called to establish a connection to
1196  * a service.
1197  *
1198  * @param cls closure
1199  * @param cfg configuration of the peer to connect to; will be available until
1200  *          GNUNET_TESTBED_operation_done() is called on the operation returned
1201  *          from GNUNET_TESTBED_service_connect()
1202  * @return service handle to return in 'op_result', NULL on error
1203  */
1204 typedef void * (*GNUNET_TESTBED_ConnectAdapter)(void *cls,
1205                                                 const struct GNUNET_CONFIGURATION_Handle *cfg);
1206
1207
1208 /**
1209  * Adapter function called to destroy a connection to
1210  * a service.
1211  *
1212  * @param cls closure
1213  * @param op_result service handle returned from the connect adapter
1214  */
1215 typedef void (*GNUNET_TESTBED_DisconnectAdapter)(void *cls,
1216                                                  void *op_result);
1217
1218
1219 /**
1220  * Callback to be called when a service connect operation is completed
1221  *
1222  * @param cls the callback closure from functions generating an operation
1223  * @param op the operation that has been finished
1224  * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
1225  * @param emsg error message in case the operation has failed; will be NULL if
1226  *          operation has executed successfully.
1227  */
1228 typedef void (*GNUNET_TESTBED_ServiceConnectCompletionCallback) (void *cls,
1229                                                                  struct
1230                                                                  GNUNET_TESTBED_Operation
1231                                                                  *op,
1232                                                                  void
1233                                                                  *ca_result,
1234                                                                  const char
1235                                                                  *emsg );
1236
1237
1238 /**
1239  * Connect to a service offered by the given peer.  Will ensure that
1240  * the request is queued to not overwhelm our ability to create and
1241  * maintain connections with other systems.  The actual service
1242  * handle is then returned via the 'op_result' member in the event
1243  * callback.  The @a ca callback is used to create the connection
1244  * when the time is right; the @a da callback will be used to
1245  * destroy the connection (upon #GNUNET_TESTBED_operation_done).
1246  * #GNUNET_TESTBED_operation_done can be used to abort this
1247  * operation until the event callback has been called.
1248  *
1249  * @param op_cls closure to pass in operation event // FIXME: didn't we say we'd no longer use the global callback for these? -CG
1250  * @param peer peer that runs the service
1251  * @param service_name name of the service to connect to
1252  * @param cb the callback to call when this operation is ready (that is,
1253  *        right after the connect adapter returns)
1254  * @param cb_cls closure for @a cb
1255  * @param ca helper function to establish the connection
1256  * @param da helper function to close the connection
1257  * @param cada_cls closure for @a ca and @a da
1258  * @return handle for the operation
1259  */
1260 struct GNUNET_TESTBED_Operation *
1261 GNUNET_TESTBED_service_connect (void *op_cls,
1262                                 struct GNUNET_TESTBED_Peer *peer,
1263                                 const char *service_name,
1264                                 GNUNET_TESTBED_ServiceConnectCompletionCallback cb,
1265                                 void *cb_cls,
1266                                 GNUNET_TESTBED_ConnectAdapter ca,
1267                                 GNUNET_TESTBED_DisconnectAdapter da,
1268                                 void *cada_cls);
1269
1270
1271 /**
1272  * This function is used to signal that the event information (struct
1273  * GNUNET_TESTBED_EventInformation) from an operation has been fully processed
1274  * i.e. if the event callback is ever called for this operation. If the event
1275  * callback for this operation has not yet been called, calling this function
1276  * cancels the operation, frees its resources and ensures the no event is
1277  * generated with respect to this operation. Note that however cancelling an
1278  * operation does NOT guarantee that the operation will be fully undone (or that
1279  * nothing ever happened).
1280  *
1281  * This function MUST be called for every operation to fully remove the
1282  * operation from the operation queue.  After calling this function, if
1283  * operation is completed and its event information is of type
1284  * GNUNET_TESTBED_ET_OPERATION_FINISHED, the 'op_result' becomes invalid (!).
1285
1286  * If the operation is generated from GNUNET_TESTBED_service_connect() then
1287  * calling this function on such as operation calls the disconnect adapter if
1288  * the connect adapter was ever called.
1289  *
1290  * @param operation operation to signal completion or cancellation
1291  */
1292 void
1293 GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation);
1294
1295
1296 /**
1297  * Callback function to process statistic values from all peers.
1298  *
1299  * @param cls closure
1300  * @param peer the peer the statistic belong to
1301  * @param subsystem name of subsystem that created the statistic
1302  * @param name the name of the datum
1303  * @param value the current value
1304  * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
1305  * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
1306  */
1307 typedef int (*GNUNET_TESTBED_StatisticsIterator) (void *cls,
1308                                                   const struct GNUNET_TESTBED_Peer *peer,
1309                                                   const char *subsystem,
1310                                                   const char *name,
1311                                                   uint64_t value,
1312                                                   int is_persistent);
1313
1314
1315 /**
1316  * Convenience method that iterates over all (running) peers
1317  * and retrieves all statistics from each peer.
1318  *
1319  * @param num_peers number of peers to iterate over
1320  * @param peers array of peers to iterate over
1321  * @param subsystem limit to the specified subsystem, NULL for all subsystems
1322  * @param name name of the statistic value, NULL for all values
1323  * @param proc processing function for each statistic retrieved
1324  * @param cont continuation to call once call is completed.  The completion of this
1325  *          operation is *ONLY* signalled through this callback -- no
1326  *          GNUNET_TESTBED_ET_OPERATION_FINISHED is generated
1327  * @param cls closure to pass to proc and cont
1328  * @return operation handle to cancel the operation
1329  */
1330 struct GNUNET_TESTBED_Operation *
1331 GNUNET_TESTBED_get_statistics (unsigned int num_peers,
1332                                struct GNUNET_TESTBED_Peer **peers,
1333                                const char *subsystem, const char *name,
1334                                GNUNET_TESTBED_StatisticsIterator proc,
1335                                GNUNET_TESTBED_OperationCompletionCallback cont,
1336                                void *cls);
1337
1338 /**
1339  * Handle for testbed run helper funtions
1340  */
1341 struct GNUNET_TESTBED_RunHandle;
1342
1343 /**
1344  * Signature of a main function for a testcase.
1345  *
1346  * @param cls closure
1347  * @param h the run handle
1348  * @param num_peers number of peers in 'peers'
1349  * @param peers handle to peers run in the testbed.  NULL upon timeout (see
1350  *          GNUNET_TESTBED_test_run()).
1351  * @param links_succeeded the number of overlay link connection attempts that
1352  *          succeeded
1353  * @param links_failed the number of overlay link connection attempts that
1354  *          failed
1355  * @see GNUNET_TESTBED_test_run()
1356  */
1357 typedef void (*GNUNET_TESTBED_TestMaster)(void *cls,
1358                                           struct GNUNET_TESTBED_RunHandle *h,
1359                                           unsigned int num_peers,
1360                                           struct GNUNET_TESTBED_Peer **peers,
1361                                           unsigned int links_succeeded,
1362                                           unsigned int links_failed);
1363
1364
1365 /**
1366  * Convenience method for running a testbed with
1367  * a single call.  Underlay and overlay topology
1368  * are configured using the "UNDERLAY" and "OVERLAY"
1369  * options in the "[testbed]" section of the configuration\
1370  * (with possible options given in "UNDERLAY_XXX" and/or
1371  * "OVERLAY_XXX").
1372  *
1373  * The test_master callback will be called once the testbed setup is finished or
1374  * upon a timeout.  This timeout is given through the configuration file by
1375  * setting the option "SETUP_TIMEOUT" in "[TESTBED]" section.
1376  *
1377  * The testbed is to be terminated using a call to
1378  * "GNUNET_SCHEDULER_shutdown".
1379  *
1380  * @param host_filename name of the file with the 'hosts', NULL
1381  *        to run everything on 'localhost'
1382  * @param cfg configuration to use (for testbed, controller and peers)
1383  * @param num_peers number of peers to start; FIXME: maybe put that ALSO into
1384  *        cfg?; should be greater than 0
1385  * @param event_mask bit mask with set of events to call 'cc' for;
1386  *                   or-ed values of "1LL" shifted by the
1387  *                   respective 'enum GNUNET_TESTBED_EventType'
1388  *                   (i.e.  "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1389  * @param cc controller callback to invoke on events; This callback is called
1390  *        for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1391  *        set in the event_mask as this is the only way get access to the
1392  *        handle of each peer
1393  * @param cc_cls closure for cc
1394  * @param test_master this callback will be called once the test is ready or
1395  *          upon timeout
1396  * @param test_master_cls closure for 'test_master'.
1397  */
1398 void
1399 GNUNET_TESTBED_run (const char *host_filename,
1400                     const struct GNUNET_CONFIGURATION_Handle *cfg,
1401                     unsigned int num_peers,
1402                     uint64_t event_mask,
1403                     GNUNET_TESTBED_ControllerCallback cc,
1404                     void *cc_cls,
1405                     GNUNET_TESTBED_TestMaster test_master,
1406                     void *test_master_cls);
1407
1408
1409 /**
1410  * Convenience method for running a "simple" test on the local system
1411  * with a single call from 'main'.  Underlay and overlay topology are
1412  * configured using the "UNDERLAY" and "OVERLAY" options in the
1413  * "[TESTBED]" section of the configuration (with possible options
1414  * given in "UNDERLAY_XXX" and/or "OVERLAY_XXX").
1415  *
1416  * The test_master callback will be called once the testbed setup is finished or
1417  * upon a timeout.  This timeout is given through the configuration file by
1418  * setting the option "SETUP_TIMEOUT" in "[TESTBED]" section.
1419  *
1420  * The test is to be terminated using a call to
1421  * "GNUNET_SCHEDULER_shutdown".  If starting the test fails,
1422  * the program is stopped without 'master' ever being run.
1423  *
1424  * NOTE: this function should be called from 'main', NOT from
1425  * within a GNUNET_SCHEDULER-loop.  This function will initialze
1426  * the scheduler loop, the testbed and then pass control to
1427  * 'master'.
1428  *
1429  * @param testname name of the testcase (to configure logging, etc.)
1430  * @param cfg_filename configuration filename to use
1431  *              (for testbed, controller and peers)
1432  * @param num_peers number of peers to start; should be greter than 0
1433  * @param event_mask bit mask with set of events to call 'cc' for;
1434  *                   or-ed values of "1LL" shifted by the
1435  *                   respective 'enum GNUNET_TESTBED_EventType'
1436  *                   (i.e.  "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1437  * @param cc controller callback to invoke on events; This callback is called
1438  *        for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1439  *        set in the event_mask as this is the only way get access to the
1440  *        handle of each peer
1441  * @param cc_cls closure for @a cc
1442  * @param test_master this callback will be called once the test is ready or
1443  *          upon timeout
1444  * @param test_master_cls closure for @a test_master.
1445  * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1446  */
1447 int
1448 GNUNET_TESTBED_test_run (const char *testname,
1449                          const char *cfg_filename,
1450                          unsigned int num_peers,
1451                          uint64_t event_mask,
1452                          GNUNET_TESTBED_ControllerCallback cc,
1453                          void *cc_cls,
1454                          GNUNET_TESTBED_TestMaster test_master,
1455                          void *test_master_cls);
1456
1457
1458 /**
1459  * Obtain handle to the master controller from a testbed run.  The handle
1460  * returned should not be disconnected.
1461  *
1462  * @param h the testbed run handle
1463  * @return handle to the master controller
1464  */
1465 struct GNUNET_TESTBED_Controller *
1466 GNUNET_TESTBED_run_get_controller_handle (struct GNUNET_TESTBED_RunHandle *h);
1467
1468 /**
1469  * Opaque handle for barrier
1470  */
1471 struct GNUNET_TESTBED_Barrier;
1472
1473
1474 /**
1475  * Status of a barrier
1476  */
1477 enum GNUNET_TESTBED_BarrierStatus
1478 {
1479   /**
1480    * Barrier initialised successfully
1481    */
1482   GNUNET_TESTBED_BARRIERSTATUS_INITIALISED = 1,
1483
1484   /**
1485    * Barrier is crossed
1486    */
1487   GNUNET_TESTBED_BARRIERSTATUS_CROSSED,
1488
1489   /**
1490    * Error status
1491    */
1492   GNUNET_TESTBED_BARRIERSTATUS_ERROR,
1493
1494 };
1495
1496
1497 /**
1498  * Functions of this type are to be given as callback argument to
1499  * GNUNET_TESTBED_barrier_init().  The callback will be called when status
1500  * information is available for the barrier.
1501  *
1502  * @param cls the closure given to GNUNET_TESTBED_barrier_init()
1503  * @param name the name of the barrier
1504  * @param barrier the barrier handle
1505  * @param status status of the barrier; GNUNET_OK if the barrier is crossed;
1506  *   GNUNET_SYSERR upon error
1507  * @param emsg if the status were to be GNUNET_SYSERR, this parameter has the
1508  *   error messsage
1509  */
1510 typedef void (*GNUNET_TESTBED_barrier_status_cb) (void *cls,
1511                                                   const char *name,
1512                                                   struct GNUNET_TESTBED_Barrier
1513                                                   *barrier,
1514                                                   enum GNUNET_TESTBED_BarrierStatus status,
1515                                                   const char *emsg);
1516
1517
1518 /**
1519  * Initialise a barrier and call the given callback when the required percentage
1520  * of peers (quorum) reach the barrier.
1521  *
1522  * @param controller the handle to the controller
1523  * @param name identification name of the barrier
1524  * @param quorum the percentage of peers that is required to reach the barrier.
1525  *   Peers signal reaching a barrier by calling
1526  *   GNUNET_TESTBED_barrier_reached().
1527  * @param cb the callback to call when the barrier is reached or upon error.
1528  *   Cannot be NULL.
1529  * @param cls closure for the above callback
1530  * @return barrier handle
1531  */
1532 struct GNUNET_TESTBED_Barrier *
1533 GNUNET_TESTBED_barrier_init (struct GNUNET_TESTBED_Controller *controller,
1534                              const char *name,
1535                              unsigned int quorum,
1536                              GNUNET_TESTBED_barrier_status_cb cb, void *cls);
1537
1538
1539 /**
1540  * Cancel a barrier.
1541  *
1542  * @param barrier the barrier handle
1543  */
1544 void
1545 GNUNET_TESTBED_barrier_cancel (struct GNUNET_TESTBED_Barrier *barrier);
1546
1547
1548 /**
1549  * Opaque handle for barrier wait
1550  */
1551 struct GNUNET_TESTBED_BarrierWaitHandle;
1552
1553
1554 /**
1555  * Functions of this type are to be given as acallback argumetn to
1556  * GNUNET_TESTBED_barrier_wait().  The callback will be called when the barrier
1557  * corresponding given in GNUNET_TESTBED_barrier_wait() is crossed or cancelled.
1558  *
1559  * @param cls closure pointer given to GNUNET_TESTBED_barrier_wait()
1560  * @param name the barrier name
1561  * @param status GNUNET_SYSERR in case of error while waiting for the barrier;
1562  *   GNUNET_OK if the barrier is crossed
1563  */
1564 typedef void (*GNUNET_TESTBED_barrier_wait_cb) (void *cls,
1565                                                 const char *name,
1566                                                 int status);
1567
1568
1569 /**
1570  * Wait for a barrier to be crossed.  This function should be called by the
1571  * peers which have been started by the testbed.  If the peer is not started by
1572  * testbed this function may return error
1573  *
1574  * @param name the name of the barrier
1575  * @param cb the barrier wait callback
1576  * @param cls the closure for the above callback
1577  * @return barrier wait handle which can be used to cancel the waiting at
1578  *   anytime before the callback is called.  NULL upon error.
1579  */
1580 struct GNUNET_TESTBED_BarrierWaitHandle *
1581 GNUNET_TESTBED_barrier_wait (const char *name,
1582                              GNUNET_TESTBED_barrier_wait_cb cb,
1583                              void *cls);
1584
1585
1586 /**
1587  * Cancel a barrier wait handle.  Should not be called in or after the callback
1588  * given to GNUNET_TESTBED_barrier_wait() has been called.
1589  *
1590  * @param h the barrier wait handle
1591  */
1592 void
1593 GNUNET_TESTBED_barrier_wait_cancel (struct GNUNET_TESTBED_BarrierWaitHandle *h);
1594
1595
1596 #if 0                           /* keep Emacsens' auto-indent happy */
1597 {
1598 #endif
1599
1600
1601 #ifdef __cplusplus
1602 }
1603 #endif
1604
1605 #endif