2 This file is part of GNUnet
3 (C) 2008, 2009, 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_testbed_service.h
23 * @brief API for writing tests and creating large-scale
24 * emulation testbeds for GNUnet.
25 * @author Christian Grothoff
28 #ifndef GNUNET_TESTBED_SERVICE_H
29 #define GNUNET_TESTBED_SERVICE_H
31 #include "gnunet_util_lib.h"
32 #include "gnunet_testing_lib-new.h"
37 #if 0 /* keep Emacsens' auto-indent happy */
44 * Opaque handle to a host running experiments managed by the testbed framework.
45 * The master process must be able to SSH to this host without password (via
48 struct GNUNET_TESTBED_Host;
51 * Opaque handle to a peer controlled by the testbed framework. A peer runs
52 * at a particular host.
54 struct GNUNET_TESTBED_Peer;
57 * Opaque handle to an abstract operation to be executed by the testbed framework.
59 struct GNUNET_TESTBED_Operation;
62 * Handle to interact with a GNUnet testbed controller. Each
63 * controller has at least one master handle which is created when the
64 * controller is created; this master handle interacts with the
65 * controller process, destroying it destroys the controller (by
66 * closing stdin of the controller process). Additionally,
67 * controllers can interact with each other (in a P2P fashion); those
68 * links are established via TCP/IP on the controller's service port.
70 struct GNUNET_TESTBED_Controller;
73 * Handle to a large-scale testbed that is managed at a high level.
75 struct GNUNET_TESTBED_Testbed;
79 * Create a host to run peers and controllers on.
81 * @param hostname name of the host, use "NULL" for localhost
82 * @param username username to use for the login; may be NULL
83 * @param port port number to use for ssh; use 0 to let ssh decide
84 * @return handle to the host, NULL on error
86 struct GNUNET_TESTBED_Host *
87 GNUNET_TESTBED_host_create (const char *hostname,
94 * Create a host to run peers and controllers on. This function is used
95 * if a peer learns about a host via IPC between controllers (and thus
96 * some higher-level controller has already determined the unique IDs).
98 * @param id global host ID assigned to the host; 0 is
99 * reserved to always mean 'localhost'
100 * @param hostname name of the host, use "NULL" for localhost
101 * @param username username to use for the login; may be NULL
102 * @param port port number to use for ssh; use 0 to let ssh decide
103 * @return handle to the host, NULL on error
105 struct GNUNET_TESTBED_Host *
106 GNUNET_TESTBED_host_create_with_id (uint32_t id,
107 const char *hostname,
108 const char *username,
113 * Load a set of hosts from a configuration file.
115 * @param filename file with the host specification
116 * @param hosts set to the hosts found in the file; caller must free this if
117 * number of hosts returned is greater than 0
118 * @return number of hosts returned in 'hosts', 0 on error
121 GNUNET_TESTBED_hosts_load_from_file (const char *filename,
122 struct GNUNET_TESTBED_Host ***hosts);
126 * Destroy a host handle. Must only be called once everything
127 * running on that host has been stopped.
129 * @param host handle to destroy
132 GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host);
136 * Checks whether a host can be used to start testbed service
138 * @param host the host to check
139 * @return GNUNET_YES if testbed service can be started on the given host
140 * remotely; GNUNET_NO if not
143 GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host);
147 * Enumeration with (at most 64) possible event types that
148 * can be monitored using the testbed framework.
150 enum GNUNET_TESTBED_EventType
153 * A peer has been started.
155 GNUNET_TESTBED_ET_PEER_START = 0,
158 * A peer has been stopped.
160 GNUNET_TESTBED_ET_PEER_STOP = 1,
163 * A connection between two peers was established.
165 GNUNET_TESTBED_ET_CONNECT = 2,
168 * A connection between two peers was torn down.
170 GNUNET_TESTBED_ET_DISCONNECT = 3,
173 * A requested testbed operation has been completed.
175 GNUNET_TESTBED_ET_OPERATION_FINISHED = 4,
178 * The 'GNUNET_TESTBED_run' operation has been completed
180 GNUNET_TESTBED_ET_TESTBED_ONLINE = 5
186 * Types of information that can be requested about a peer.
188 enum GNUNET_TESTBED_PeerInformationType
192 * Special value (not valid for requesting information)
193 * that is used in the event struct if a 'generic' pointer
194 * is returned (for other operations not related to this
197 GNUNET_TESTBED_PIT_GENERIC = 0,
200 * What configuration is the peer using? Returns a 'const struct
201 * GNUNET_CONFIGURATION_Handle *'. Valid until
202 * 'GNUNET_TESTNIG_operation_done' is called. However, the
203 * values may be inaccurate if the peer is reconfigured in
206 GNUNET_TESTBED_PIT_CONFIGURATION,
209 * What is the identity of the peer? Returns a
210 * 'const struct GNUNET_PeerIdentity *'. Valid until
211 * 'GNUNET_TESTNIG_operation_done' is called.
213 GNUNET_TESTBED_PIT_IDENTITY
219 * Argument to GNUNET_TESTBED_ControllerCallback with details about
222 struct GNUNET_TESTBED_EventInformation
228 enum GNUNET_TESTBED_EventType type;
231 * Details about the event.
237 * Details about peer start event.
242 * Handle for the host where the peer
245 struct GNUNET_TESTBED_Host *host;
248 * Handle for the peer that was started.
250 struct GNUNET_TESTBED_Peer *peer;
255 * Details about peer stop event.
261 * Handle for the peer that was started.
263 struct GNUNET_TESTBED_Peer *peer;
268 * Details about connect event.
273 * Handle for one of the connected peers.
275 struct GNUNET_TESTBED_Peer *peer1;
278 * Handle for one of the connected peers.
280 struct GNUNET_TESTBED_Peer *peer2;
285 * Details about disconnect event.
290 * Handle for one of the disconnected peers.
292 struct GNUNET_TESTBED_Peer *peer1;
295 * Handle for one of the disconnected peers.
297 struct GNUNET_TESTBED_Peer *peer2;
302 * Details about an operation finished event.
308 * Handle for the operation that was finished.
310 struct GNUNET_TESTBED_Operation *operation;
313 * Closure that was passed in when the event was
319 * Error message for the operation, NULL on success.
324 * No result (NULL pointer) or generic result
325 * (whatever the GNUNET_TESTBED_ConnectAdapter returned).
329 } operation_finished;
332 * Details about an testbed run completed event.
338 * Error message for the operation, NULL on success.
343 * Array of peers now running (valid until
344 * 'GNUNET_TESTBED_testbed_stop' is called). Note that it is
345 * not allowed to call 'GNUNET_TESTBED_peer_destroy' on peers
348 struct GNUNET_TESTBED_Peer **peers;
351 * Size of the 'peers' array.
353 unsigned int num_peers;
355 } testbed_run_finished;
363 * Signature of the event handler function called by the
364 * respective event controller.
367 * @param event information about the event
369 typedef void (*GNUNET_TESTBED_ControllerCallback)(void *cls,
370 const struct GNUNET_TESTBED_EventInformation *event);
374 * Opaque Handle for Controller process
376 struct GNUNET_TESTBED_ControllerProc;
380 * Callback to signal successfull startup of the controller process
382 * @param cls the closure from GNUNET_TESTBED_controller_start()
383 * @param cfg the configuration with which the controller has been started;
384 * NULL if status is not GNUNET_OK
385 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
386 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
388 typedef void (*GNUNET_TESTBED_ControllerStatusCallback) (void *cls,
389 const struct GNUNET_CONFIGURATION_Handle *cfg,
394 * Starts a controller process at the host.
396 * @param controller_ip the ip address of the controller. Will be set as TRUSTED
397 * host when starting testbed controller at host
398 * @param host the host where the controller has to be started; NULL for
400 * @param cfg template configuration to use for the remote controller; the
401 * remote controller will be started with a slightly modified
402 * configuration (port numbers, unix domain sockets and service home
403 * values are changed as per TESTING library on the remote host)
404 * @param cb function called when the controller is successfully started or
405 * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
406 * called if cb is called with GNUNET_SYSERR as status. Will never be
407 * called in the same task as 'GNUNET_TESTBED_controller_start'
408 * (synchronous errors will be signalled by returning NULL). This
409 * parameter cannot be NULL.
410 * @param cls closure for above callbacks
411 * @return the controller process handle, NULL on errors
413 struct GNUNET_TESTBED_ControllerProc *
414 GNUNET_TESTBED_controller_start (const char *controller_ip,
415 struct GNUNET_TESTBED_Host *host,
416 const struct GNUNET_CONFIGURATION_Handle *cfg,
417 GNUNET_TESTBED_ControllerStatusCallback cb,
422 * Stop the controller process (also will terminate all peers and controllers
423 * dependent on this controller). This function blocks until the testbed has
424 * been fully terminated (!). The controller status cb from
425 * GNUNET_TESTBED_controller_start() will not be called.
427 * @param cproc the controller process handle
430 GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc);
434 * Connect to a controller process using the given configuration at the
437 * @param cfg configuration to use
438 * @param host host to run the controller on; This should be the same host if
439 * the controller was previously started with
440 * GNUNET_TESTBED_controller_start; NULL for localhost
441 * @param host host where this controller is being run;
442 * @param event_mask bit mask with set of events to call 'cc' for;
443 * or-ed values of "1LL" shifted by the
444 * respective 'enum GNUNET_TESTBED_EventType'
445 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) | ...")
446 * @param cc controller callback to invoke on events
447 * @param cc_cls closure for cc
448 * @return handle to the controller
450 struct GNUNET_TESTBED_Controller *
451 GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
452 struct GNUNET_TESTBED_Host *host,
454 GNUNET_TESTBED_ControllerCallback cc,
459 * Configure shared services at a controller. Using this function,
460 * you can specify that certain services (such as "resolver")
461 * should not be run for each peer but instead be shared
462 * across N peers on the specified host. This function
463 * must be called before any peers are created at the host.
465 * @param controller controller to configure
466 * @param service_name name of the service to share
467 * @param num_peers number of peers that should share one instance
468 * of the specified service (1 for no sharing is the default),
469 * use 0 to disable the service
472 GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller *controller,
473 const char *service_name,
478 * Stop the given controller (also will terminate all peers and
479 * controllers dependent on this controller). This function
480 * blocks until the testbed has been fully terminated (!).
482 * @param controller handle to controller to stop
485 GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *controller);
489 * Opaque handle for host registration
491 struct GNUNET_TESTBED_HostRegistrationHandle;
495 * Callback which will be called to after a host registration succeeded or failed
497 * @param cls the closure
498 * @param emsg the error message; NULL if host registration is successful
500 typedef void (* GNUNET_TESTBED_HostRegistrationCompletion) (void *cls,
505 * Register a host with the controller
507 * @param controller the controller handle
508 * @param host the host to register
509 * @param cc the completion callback to call to inform the status of
510 * registration. After calling this callback the registration handle
511 * will be invalid. Cannot be NULL
512 * @param cc_cls the closure for the cc
513 * @return handle to the host registration which can be used to cancel the
514 * registration; NULL if another registration handle is present and
517 struct GNUNET_TESTBED_HostRegistrationHandle *
518 GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
519 struct GNUNET_TESTBED_Host *host,
520 GNUNET_TESTBED_HostRegistrationCompletion cc,
525 * Cancel the pending registration. Note that the registration message will
526 * already be queued to be sent to the service, cancellation has only the
527 * effect that the registration completion callback for the registration is
528 * never called and from our perspective the host is not registered until the
529 * completion callback is called.
531 * @param handle the registration handle to cancel
534 GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
539 * Callback to be called when an operation is completed
541 * @param cls the callback closure from functions generating an operation
542 * @param op the operation that has been finished
543 * @param emsg error message in case the operation has failed; will be NULL if
544 * operation has executed successfully.
546 typedef void (*GNUNET_TESTBED_OperationCompletionCallback) (void *cls,
548 GNUNET_TESTBED_Operation
554 * Create a link from slave controller to delegated controller. Whenever the
555 * master controller is asked to start a peer at the delegated controller the
556 * request will be routed towards slave controller (if a route exists). The
557 * slave controller will then route it to the delegated controller. The
558 * configuration of the delegated controller is given and is used to either
559 * create the delegated controller or to connect to an existing controller. Note
560 * that while starting the delegated controller the configuration will be
561 * modified to accommodate available free ports. the 'is_subordinate' specifies
562 * if the given delegated controller should be started and managed by the slave
563 * controller, or if the delegated controller already has a master and the slave
564 * controller connects to it as a non master controller. The success or failure
565 * of this operation will be signalled through the
566 * GNUNET_TESTBED_ControllerCallback() with an event of type
567 * GNUNET_TESTBED_ET_OPERATION_FINISHED
569 * @param op_cls the operation closure for the event which is generated to
570 * signal success or failure of this operation
571 * @param master handle to the master controller who creates the association
572 * @param delegated_host requests to which host should be delegated; cannot be NULL
573 * @param slave_host which host is used to run the slave controller; use NULL to
574 * make the master controller connect to the delegated host
575 * @param slave_cfg configuration to use for the slave controller
576 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
577 * be started by the slave controller; GNUNET_NO if the slave
578 * controller has to connect to the already started delegated
579 * controller via TCP/IP
580 * @return the operation handle
582 struct GNUNET_TESTBED_Operation *
583 GNUNET_TESTBED_controller_link (void *op_cls,
584 struct GNUNET_TESTBED_Controller *master,
585 struct GNUNET_TESTBED_Host *delegated_host,
586 struct GNUNET_TESTBED_Host *slave_host,
587 const struct GNUNET_CONFIGURATION_Handle
593 * Same as the GNUNET_TESTBED_controller_link, however expects configuration in
594 * serialized and compressed
596 * @param op_cls the operation closure for the event which is generated to
597 * signal success or failure of this operation
598 * @param master handle to the master controller who creates the association
599 * @param delegated_host requests to which host should be delegated; cannot be NULL
600 * @param slave_host which host is used to run the slave controller; use NULL to
601 * make the master controller connect to the delegated host
602 * @param sxcfg serialized and compressed configuration
603 * @param sxcfg_size the size sxcfg
604 * @param scfg_size the size of uncompressed serialized configuration
605 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
606 * be started by the slave controller; GNUNET_NO if the slave
607 * controller has to connect to the already started delegated
608 * controller via TCP/IP
609 * @return the operation handle
611 struct GNUNET_TESTBED_Operation *
612 GNUNET_TESTBED_controller_link_2 (void *op_cls,
613 struct GNUNET_TESTBED_Controller *master,
614 struct GNUNET_TESTBED_Host *delegated_host,
615 struct GNUNET_TESTBED_Host *slave_host,
623 * Function to acquire the configuration of a running slave controller. The
624 * completion of the operation is signalled through the controller_cb from
625 * GNUNET_TESTBED_controller_connect(). If the operation is successful the
626 * handle to the configuration is available in the generic pointer of
627 * operation_finished field of struct GNUNET_TESTBED_EventInformation.
629 * @param op_cls the closure for the operation
630 * @param master the handle to master controller
631 * @param slave_host the host where the slave controller is running; the handle
632 * to the slave_host should remain valid until this operation is
633 * cancelled or marked as finished
634 * @return the operation handle; NULL if the slave_host is not registered at
637 struct GNUNET_TESTBED_Operation *
638 GNUNET_TESTBED_get_slave_config (void *op_cls,
639 struct GNUNET_TESTBED_Controller *master,
640 struct GNUNET_TESTBED_Host *slave_host);
644 * Functions of this signature are called when a peer has been successfully
647 * @param cls the closure from GNUNET_TESTBED_peer_create()
648 * @param peer the handle for the created peer; NULL on any error during
650 * @param emsg NULL if peer is not NULL; else MAY contain the error description
652 typedef void (*GNUNET_TESTBED_PeerCreateCallback) (void *cls,
653 struct GNUNET_TESTBED_Peer *peer,
658 * Create the given peer at the specified host using the given
659 * controller. If the given controller is not running on the target
660 * host, it should find or create a controller at the target host and
661 * delegate creating the peer. Explicit delegation paths can be setup
662 * using 'GNUNET_TESTBED_controller_link'. If no explicit delegation
663 * path exists, a direct link with a subordinate controller is setup
664 * for the first delegated peer to a particular host; the subordinate
665 * controller is then destroyed once the last peer that was delegated
666 * to the remote host is stopped.
668 * Creating the peer only creates the handle to manipulate and further
669 * configure the peer; use "GNUNET_TESTBED_peer_start" and
670 * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's
673 * Note that the given configuration will be adjusted by the
674 * controller to avoid port/path conflicts with other peers.
675 * The "final" configuration can be obtained using
676 * 'GNUNET_TESTBED_peer_get_information'.
678 * @param controller controller process to use
679 * @param host host to run the peer on
680 * @param cfg Template configuration to use for the peer. Should exist until
681 * operation is cancelled or GNUNET_TESTBED_operation_done() is called
682 * @param cb the callback to call when the peer has been created
683 * @param cls the closure to the above callback
684 * @return the operation handle
686 struct GNUNET_TESTBED_Operation *
687 GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
688 struct GNUNET_TESTBED_Host *host,
689 const struct GNUNET_CONFIGURATION_Handle *cfg,
690 GNUNET_TESTBED_PeerCreateCallback cb,
695 * Functions of this signature are called when a peer has been successfully
696 * started or stopped.
698 * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
699 * @param emsg NULL on success; otherwise an error description
701 typedef void (*GNUNET_TESTBED_PeerChurnCallback) (void *cls,
706 * Start the given peer.
708 * @param op_cls the closure for this operation; will be set in
709 * event->details.operation_finished.op_cls when this operation fails.
710 * @param peer peer to start
711 * @param pcc function to call upon completion
712 * @param pcc_cls closure for 'pcc'
713 * @return handle to the operation
715 struct GNUNET_TESTBED_Operation *
716 GNUNET_TESTBED_peer_start (void *op_cls,
717 struct GNUNET_TESTBED_Peer *peer,
718 GNUNET_TESTBED_PeerChurnCallback pcc,
723 * Stop the given peer. The handle remains valid (use
724 * "GNUNET_TESTBED_peer_destroy" to fully clean up the
725 * state of the peer).
727 * @param peer peer to stop
728 * @param pcc function to call upon completion
729 * @param pcc_cls closure for 'pcc'
730 * @return handle to the operation
732 struct GNUNET_TESTBED_Operation *
733 GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer,
734 GNUNET_TESTBED_PeerChurnCallback pcc,
739 * Data returned from GNUNET_TESTBED_peer_get_information
741 struct GNUNET_TESTBED_PeerInformation
744 * Peer information type; captures which of the types
745 * in the 'op_result' is actually in use.
747 enum GNUNET_TESTBED_PeerInformationType pit;
750 * The result of the get information operation; Choose according to the pit
755 * The configuration of the peer
757 struct GNUNET_CONFIGURATION_Handle *cfg;
760 * The identity of the peer
762 struct GNUNET_PeerIdentity *id;
768 * Callback to be called when the requested peer information is available
770 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
771 * @param op the operation this callback corresponds to
772 * @param pinfo the result; will be NULL if the operation has failed
773 * @param emsg error message if the operation has failed; will be NULL if the
774 * operation is successfull
776 typedef void (*GNUNET_TESTBED_PeerInfoCallback) (void *cb_cls,
777 struct GNUNET_TESTBED_Operation
780 GNUNET_TESTBED_PeerInformation
786 * Request information about a peer. The controller callback will not be called
787 * with event type GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this
788 * operation is available. Instead, the GNUNET_TESTBED_PeerInfoCallback() will
791 * @param peer peer to request information about
792 * @param pit desired information
793 * @param cb the convenience callback to be called when results for this
794 * operation are available
795 * @param cb_cls the closure for the above callback
796 * @return handle to the operation
798 struct GNUNET_TESTBED_Operation *
799 GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
800 enum GNUNET_TESTBED_PeerInformationType
802 GNUNET_TESTBED_PeerInfoCallback cb,
807 * Change peer configuration. Must only be called while the
808 * peer is stopped. Ports and paths cannot be changed this
811 * @param peer peer to change configuration for
812 * @param cfg new configuration (differences to existing
813 * configuration only)
814 * @return handle to the operation
816 struct GNUNET_TESTBED_Operation *
817 GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
818 const struct GNUNET_CONFIGURATION_Handle *cfg);
822 * Destroy the given peer; the peer should have been
823 * stopped first (if it was started).
825 * @param peer peer to stop
826 * @return handle to the operation
828 struct GNUNET_TESTBED_Operation *
829 GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer);
833 * Options for peer connections.
835 enum GNUNET_TESTBED_ConnectOption
838 * No option (not valid as an argument).
840 GNUNET_TESTBED_CO_NONE = 0,
843 * Allow or disallow a connection between the specified peers.
844 * Followed by GNUNET_NO (int) if a connection is disallowed
845 * or GNUNET_YES if a connection is allowed. Note that the
846 * default (all connections allowed or disallowed) is
847 * specified in the configuration of the controller.
849 GNUNET_TESTBED_CO_ALLOW = 1,
852 * FIXME: add (and implement) options to limit connection to
853 * particular transports, force simulation of particular latencies
854 * or message loss rates, or set bandwidth limitations.
861 * Manipulate the P2P underlay topology by configuring a link
864 * @param op_cls closure argument to give with the operation event
865 * @param p1 first peer
866 * @param p2 second peer
867 * @param co option to change
868 * @param ap option-specific values
869 * @return handle to the operation, NULL if configuring the link at this
870 * time is not allowed
872 struct GNUNET_TESTBED_Operation *
873 GNUNET_TESTBED_underlay_configure_link_va (void *op_cls,
874 struct GNUNET_TESTBED_Peer *p1,
875 struct GNUNET_TESTBED_Peer *p2,
876 enum GNUNET_TESTBED_ConnectOption co,
881 * Manipulate the P2P underlay topology by configuring a link
884 * @param op_cls closure argument to give with the operation event
885 * @param p1 first peer
886 * @param p2 second peer
887 * @param co option to change
888 * @param ... option-specific values
889 * @return handle to the operation, NULL if configuring the link at this
890 * time is not allowed
892 struct GNUNET_TESTBED_Operation *
893 GNUNET_TESTBED_underlay_configure_link (void *op_cls,
894 struct GNUNET_TESTBED_Peer *p1,
895 struct GNUNET_TESTBED_Peer *p2,
896 enum GNUNET_TESTBED_ConnectOption co, ...);
901 * Topologies supported for testbeds.
903 enum GNUNET_TESTBED_TopologyOption
906 * A clique (everyone connected to everyone else). No options.
908 GNUNET_TESTBED_TOPOLOGY_CLIQUE,
911 * Small-world network (2d torus plus random links). Followed
912 * by the number of random links to add (unsigned int).
914 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD,
917 * Small-world network (ring plus random links). Followed
918 * by the number of random links to add (unsigned int).
920 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING,
923 * Ring topology. No options.
925 GNUNET_TESTBED_TOPOLOGY_RING,
928 * 2-d torus. No options.
930 GNUNET_TESTBED_TOPOLOGY_2D_TORUS,
933 * Random graph. Followed by the link density, that is the
934 * percentage of links present in relation to a clique
937 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
940 * Certain percentage of peers are unable to communicate directly
941 * replicating NAT conditions. Followed by the fraction of
942 * NAT'ed peers (float).
944 GNUNET_TESTBED_TOPOLOGY_INTERNAT,
947 * Scale free topology. FIXME: options?
949 GNUNET_TESTBED_TOPOLOGY_SCALE_FREE,
952 * Straight line topology. No options.
954 GNUNET_TESTBED_TOPOLOGY_LINE,
957 * All peers are disconnected. No options.
959 GNUNET_TESTBED_TOPOLOGY_NONE,
962 * Read a topology from a given file. Followed by the name of the file (const char *).
964 GNUNET_TESTBED_TOPOLOGY_FROM_FILE
969 * Configure overall network topology to have a particular shape.
971 * @param op_cls closure argument to give with the operation event
972 * @param num_peers number of peers in 'peers'
973 * @param peers array of 'num_peers' with the peers to configure
974 * @param topo desired underlay topology to use
975 * @param ap topology-specific options
976 * @return handle to the operation, NULL if configuring the topology
977 * is not allowed at this time
979 struct GNUNET_TESTBED_Operation *
980 GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
981 unsigned int num_peers,
982 struct GNUNET_TESTBED_Peer **peers,
983 enum GNUNET_TESTBED_TopologyOption topo,
988 * Configure overall network topology to have a particular shape.
990 * @param op_cls closure argument to give with the operation event
991 * @param num_peers number of peers in 'peers'
992 * @param peers array of 'num_peers' with the peers to configure
993 * @param topo desired underlay topology to use
994 * @param ... topology-specific options
995 * @return handle to the operation, NULL if configuring the topology
996 * is not allowed at this time
998 struct GNUNET_TESTBED_Operation *
999 GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
1000 unsigned int num_peers,
1001 struct GNUNET_TESTBED_Peer **peers,
1002 enum GNUNET_TESTBED_TopologyOption topo,
1007 * Both peers must have been started before calling this function.
1008 * This function then obtains a HELLO from 'p1', gives it to 'p2'
1009 * and asks 'p2' to connect to 'p1'.
1011 * @param op_cls closure argument to give with the operation event
1012 * @param cb the callback to call when this operation has finished
1013 * @param cb_cls the closure for the above callback
1014 * @param p1 first peer
1015 * @param p2 second peer
1016 * @return handle to the operation, NULL if connecting these two
1017 * peers is fundamentally not possible at this time (peers
1018 * not running or underlay disallows)
1020 struct GNUNET_TESTBED_Operation *
1021 GNUNET_TESTBED_overlay_connect (void *op_cls,
1022 GNUNET_TESTBED_OperationCompletionCallback cb,
1024 struct GNUNET_TESTBED_Peer *p1,
1025 struct GNUNET_TESTBED_Peer *p2);
1029 * All peers must have been started before calling this function.
1030 * This function then connects the given peers in the P2P overlay
1031 * using the given topology.
1033 * @param op_cls closure argument to give with the operation event
1034 * @param num_peers number of peers in 'peers'
1035 * @param peers array of 'num_peers' with the peers to configure
1036 * @param topo desired underlay topology to use
1037 * @param va topology-specific options
1038 * @return handle to the operation, NULL if connecting these
1039 * peers is fundamentally not possible at this time (peers
1040 * not running or underlay disallows) or if num_peers is less than 2
1042 struct GNUNET_TESTBED_Operation *
1043 GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
1044 unsigned int num_peers,
1045 struct GNUNET_TESTBED_Peer **peers,
1046 enum GNUNET_TESTBED_TopologyOption topo,
1051 * All peers must have been started before calling this function.
1052 * This function then connects the given peers in the P2P overlay
1053 * using the given topology.
1055 * @param op_cls closure argument to give with the operation event
1056 * @param num_peers number of peers in 'peers'
1057 * @param peers array of 'num_peers' with the peers to configure
1058 * @param topo desired underlay topology to use
1059 * @param ... topology-specific options
1060 * @return handle to the operation, NULL if connecting these
1061 * peers is fundamentally not possible at this time (peers
1062 * not running or underlay disallows) or if num_peers is less than 2
1064 struct GNUNET_TESTBED_Operation *
1065 GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
1066 unsigned int num_peers,
1067 struct GNUNET_TESTBED_Peer **peers,
1068 enum GNUNET_TESTBED_TopologyOption topo,
1073 * Ask the testbed controller to write the current overlay topology to
1074 * a file. Naturally, the file will only contain a snapshot as the
1075 * topology may evolve all the time.
1076 * FIXME: needs continuation!?
1078 * @param controller overlay controller to inspect
1079 * @param filename name of the file the topology should
1083 GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller *controller,
1084 const char *filename);
1088 * Adapter function called to establish a connection to
1091 * @param cls closure
1092 * @param cfg configuration of the peer to connect to; will be available until
1093 * GNUNET_TESTBED_operation_done() is called on the operation returned
1094 * from GNUNET_TESTBED_service_connect()
1095 * @return service handle to return in 'op_result', NULL on error
1097 typedef void * (*GNUNET_TESTBED_ConnectAdapter)(void *cls,
1098 const struct GNUNET_CONFIGURATION_Handle *cfg);
1102 * Adapter function called to destroy a connection to
1105 * @param cls closure
1106 * @param op_result service handle returned from the connect adapter
1108 typedef void (*GNUNET_TESTBED_DisconnectAdapter)(void *cls,
1113 * Callback to be called when a service connect operation is completed
1115 * @param cls the callback closure from functions generating an operation
1116 * @param op the operation that has been finished
1117 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
1118 * @param emsg error message in case the operation has failed; will be NULL if
1119 * operation has executed successfully.
1121 typedef void (*GNUNET_TESTBED_ServiceConnectCompletionCallback) (void *cls,
1123 GNUNET_TESTBED_Operation
1132 * Connect to a service offered by the given peer. Will ensure that
1133 * the request is queued to not overwhelm our ability to create and
1134 * maintain connections with other systems. The actual service
1135 * handle is then returned via the 'op_result' member in the event
1136 * callback. The 'ca' callback is used to create the connection
1137 * when the time is right; the 'da' callback will be used to
1138 * destroy the connection (upon 'GNUNET_TESTBED_operation_done').
1139 * 'GNUNET_TESTBED_operation_cancel' can be used to abort this
1140 * operation until the event callback has been called.
1142 * @param op_cls closure to pass in operation event
1143 * @param peer peer that runs the service
1144 * @param service_name name of the service to connect to
1145 * @param cb the callback to call when this operation finishes
1146 * @param cb_cls closure for the above callback
1147 * @param ca helper function to establish the connection
1148 * @param da helper function to close the connection
1149 * @param cada_cls closure for ca and da
1150 * @return handle for the operation
1152 struct GNUNET_TESTBED_Operation *
1153 GNUNET_TESTBED_service_connect (void *op_cls,
1154 struct GNUNET_TESTBED_Peer *peer,
1155 const char *service_name,
1156 GNUNET_TESTBED_ServiceConnectCompletionCallback cb,
1158 GNUNET_TESTBED_ConnectAdapter ca,
1159 GNUNET_TESTBED_DisconnectAdapter da,
1164 * Cancel a pending operation. Releases all resources
1165 * of the operation and will ensure that no event
1166 * is generated for the operation. Does NOT guarantee
1167 * that the operation will be fully undone (or that
1168 * nothing ever happened).
1170 * @param operation operation to cancel
1173 GNUNET_TESTBED_operation_cancel (struct GNUNET_TESTBED_Operation *operation);
1177 * Signal that the information from an operation has been fully
1178 * processed. This function MUST be called for each event
1179 * of type 'operation_finished' to fully remove the operation
1180 * from the operation queue. After calling this function, the
1181 * 'op_result' becomes invalid (!).
1183 * @param operation operation to signal completion for
1186 GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation);
1190 * Configure and run a testbed using the given
1191 * master controller on 'num_hosts' starting
1192 * 'num_peers' using the given peer configuration.
1194 * @param controller master controller for the testbed
1195 * (must not be destroyed until after the
1196 * testbed is destroyed).
1197 * @param num_hosts number of hosts in 'hosts', 0 to only
1199 * @param hosts list of hosts to use for the testbed
1200 * @param num_peers number of peers to start
1201 * @param peer_cfg peer configuration template to use
1202 * @param underlay_topology underlay topology to create
1203 * @param va topology-specific options
1204 * @return handle to the testbed
1206 struct GNUNET_TESTBED_Testbed *
1207 GNUNET_TESTBED_create_va (struct GNUNET_TESTBED_Controller *controller,
1208 unsigned int num_hosts,
1209 struct GNUNET_TESTBED_Host **hosts,
1210 unsigned int num_peers,
1211 const struct GNUNET_CONFIGURATION_Handle *peer_cfg,
1212 enum GNUNET_TESTBED_TopologyOption underlay_topology,
1217 * Configure and run a testbed using the given
1218 * master controller on 'num_hosts' starting
1219 * 'num_peers' using the given peer configuration.
1221 * @param controller master controller for the testbed
1222 * (must not be destroyed until after the
1223 * testbed is destroyed).
1224 * @param num_hosts number of hosts in 'hosts', 0 to only
1226 * @param hosts list of hosts to use for the testbed
1227 * @param num_peers number of peers to start
1228 * @param peer_cfg peer configuration template to use
1229 * @param underlay_topology underlay topology to create
1230 * @param ... topology-specific options
1232 struct GNUNET_TESTBED_Testbed *
1233 GNUNET_TESTBED_create (struct GNUNET_TESTBED_Controller *controller,
1234 unsigned int num_hosts,
1235 struct GNUNET_TESTBED_Host **hosts,
1236 unsigned int num_peers,
1237 const struct GNUNET_CONFIGURATION_Handle *peer_cfg,
1238 enum GNUNET_TESTBED_TopologyOption underlay_topology,
1243 * Destroy a testbed. Stops all running peers and then
1244 * destroys all peers. Does NOT destroy the master controller.
1246 * @param testbed testbed to destroy
1249 GNUNET_TESTBED_destroy (struct GNUNET_TESTBED_Testbed *testbed);
1253 * Callback function to process statistic values from all peers.
1255 * @param cls closure
1256 * @param peer the peer the statistic belong to
1257 * @param subsystem name of subsystem that created the statistic
1258 * @param name the name of the datum
1259 * @param value the current value
1260 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
1261 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
1263 typedef int (*GNUNET_TESTBED_StatisticsIterator) (void *cls,
1264 const struct GNUNET_TESTBED_Peer *peer,
1265 const char *subsystem,
1272 * Convenience method that iterates over all (running) peers
1273 * and retrieves all statistics from each peer.
1275 * @param num_peers number of peers to iterate over
1276 * @param peers array of peers to iterate over
1277 * @param proc processing function for each statistic retrieved
1278 * @param cont continuation to call once call is completed(?)
1279 * @param cls closure to pass to proc and cont
1280 * @return operation handle to cancel the operation
1282 struct GNUNET_TESTBED_Operation *
1283 GNUNET_TESTBED_get_statistics (unsigned int num_peers,
1284 struct GNUNET_TESTBED_Peer **peers,
1285 GNUNET_TESTBED_StatisticsIterator proc,
1286 GNUNET_TESTBED_OperationCompletionCallback cont,
1291 * Convenience method for running a testbed with
1292 * a single call. Underlay and overlay topology
1293 * are configured using the "UNDERLAY" and "OVERLAY"
1294 * options in the "[testbed]" section of the configuration\
1295 * (with possible options given in "UNDERLAY_XXX" and/or
1298 * The testbed is to be terminated using a call to
1299 * "GNUNET_SCHEDULER_shutdown".
1301 * @param host_filename name of the file with the 'hosts', NULL
1302 * to run everything on 'localhost'
1303 * @param cfg configuration to use (for testbed, controller and peers)
1304 * @param num_peers number of peers to start; FIXME: maybe put that ALSO into
1305 * cfg?; should be greater than 0
1306 * @param event_mask bit mask with set of events to call 'cc' for;
1307 * or-ed values of "1LL" shifted by the
1308 * respective 'enum GNUNET_TESTBED_EventType'
1309 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1310 * @param cc controller callback to invoke on events; This callback is called
1311 * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1312 * set in the event_mask as this is the only way get access to the
1313 * handle of each peer
1314 * @param cc_cls closure for cc
1315 * @param master task to run once the testbed is ready
1316 * @param master_cls closure for 'task'.
1319 GNUNET_TESTBED_run (const char *host_filename,
1320 const struct GNUNET_CONFIGURATION_Handle *cfg,
1321 unsigned int num_peers,
1322 uint64_t event_mask,
1323 GNUNET_TESTBED_ControllerCallback cc,
1325 GNUNET_SCHEDULER_Task master,
1330 * Signature of a main function for a testcase.
1332 * @param cls closure
1333 * @param num_peers number of peers in 'peers'
1334 * @param peers handle to peers run in the testbed
1336 typedef void (*GNUNET_TESTBED_TestMaster)(void *cls,
1337 unsigned int num_peers,
1338 struct GNUNET_TESTBED_Peer **peers);
1342 * Convenience method for running a "simple" test on the local system
1343 * with a single call from 'main'. Underlay and overlay topology are
1344 * configured using the "UNDERLAY" and "OVERLAY" options in the
1345 * "[testbed]" section of the configuration (with possible options
1346 * given in "UNDERLAY_XXX" and/or "OVERLAY_XXX").
1348 * The test is to be terminated using a call to
1349 * "GNUNET_SCHEDULER_shutdown". If starting the test fails,
1350 * the program is stopped without 'master' ever being run.
1352 * NOTE: this function should be called from 'main', NOT from
1353 * within a GNUNET_SCHEDULER-loop. This function will initialze
1354 * the scheduler loop, the testbed and then pass control to
1357 * @param testname name of the testcase (to configure logging, etc.)
1358 * @param cfg_filename configuration filename to use
1359 * (for testbed, controller and peers)
1360 * @param num_peers number of peers to start; should be greter than 0
1361 * @param event_mask bit mask with set of events to call 'cc' for;
1362 * or-ed values of "1LL" shifted by the
1363 * respective 'enum GNUNET_TESTBED_EventType'
1364 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1365 * @param cc controller callback to invoke on events; This callback is called
1366 * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1367 * set in the event_mask as this is the only way get access to the
1368 * handle of each peer
1369 * @param cc_cls closure for cc
1370 * @param test_master task to run once the test is ready
1371 * @param test_master_cls closure for 'task'.
1374 GNUNET_TESTBED_test_run (const char *testname,
1375 const char *cfg_filename,
1376 unsigned int num_peers,
1377 uint64_t event_mask,
1378 GNUNET_TESTBED_ControllerCallback cc,
1380 GNUNET_TESTBED_TestMaster test_master,
1381 void *test_master_cls);
1384 #if 0 /* keep Emacsens' auto-indent happy */