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