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