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