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 * @param config the configuration handle to lookup the path of the testbed helper
140 * @return GNUNET_YES if testbed service can be started on the given host
141 * remotely; GNUNET_NO if not
144 GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
145 const struct GNUNET_CONFIGURATION_Handle *config);
149 * Obtain the host's hostname.
151 * @param host handle to the host, NULL means 'localhost'
152 * @return hostname of the host
155 GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host);
159 * Enumeration with (at most 64) possible event types that
160 * can be monitored using the testbed framework.
162 enum GNUNET_TESTBED_EventType
165 * A peer has been started.
167 GNUNET_TESTBED_ET_PEER_START = 0,
170 * A peer has been stopped.
172 GNUNET_TESTBED_ET_PEER_STOP = 1,
175 * A connection between two peers was established.
177 GNUNET_TESTBED_ET_CONNECT = 2,
180 * A connection between two peers was torn down.
182 GNUNET_TESTBED_ET_DISCONNECT = 3,
185 * A requested testbed operation has been completed.
187 GNUNET_TESTBED_ET_OPERATION_FINISHED = 4,
190 * The 'GNUNET_TESTBED_run' operation has been completed
192 GNUNET_TESTBED_ET_TESTBED_ONLINE = 5
198 * Types of information that can be requested about a peer.
200 enum GNUNET_TESTBED_PeerInformationType
204 * Special value (not valid for requesting information)
205 * that is used in the event struct if a 'generic' pointer
206 * is returned (for other operations not related to this
209 GNUNET_TESTBED_PIT_GENERIC = 0,
212 * What configuration is the peer using? Returns a 'const struct
213 * GNUNET_CONFIGURATION_Handle *'. Valid until
214 * 'GNUNET_TESTNIG_operation_done' is called. However, the
215 * values may be inaccurate if the peer is reconfigured in
218 GNUNET_TESTBED_PIT_CONFIGURATION,
221 * What is the identity of the peer? Returns a
222 * 'const struct GNUNET_PeerIdentity *'. Valid until
223 * 'GNUNET_TESTNIG_operation_done' is called.
225 GNUNET_TESTBED_PIT_IDENTITY
231 * Argument to GNUNET_TESTBED_ControllerCallback with details about
234 struct GNUNET_TESTBED_EventInformation
240 enum GNUNET_TESTBED_EventType type;
243 * Details about the event.
249 * Details about peer start event.
254 * Handle for the host where the peer
257 struct GNUNET_TESTBED_Host *host;
260 * Handle for the peer that was started.
262 struct GNUNET_TESTBED_Peer *peer;
267 * Details about peer stop event.
273 * Handle for the peer that was started.
275 struct GNUNET_TESTBED_Peer *peer;
280 * Details about connect event.
285 * Handle for one of the connected peers.
287 struct GNUNET_TESTBED_Peer *peer1;
290 * Handle for one of the connected peers.
292 struct GNUNET_TESTBED_Peer *peer2;
297 * Details about disconnect event.
302 * Handle for one of the disconnected peers.
304 struct GNUNET_TESTBED_Peer *peer1;
307 * Handle for one of the disconnected peers.
309 struct GNUNET_TESTBED_Peer *peer2;
314 * Details about an operation finished event.
320 * Handle for the operation that was finished.
322 struct GNUNET_TESTBED_Operation *operation;
325 * Closure that was passed in when the event was
331 * Error message for the operation, NULL on success.
336 * No result (NULL pointer) or generic result
337 * (whatever the GNUNET_TESTBED_ConnectAdapter returned).
341 } operation_finished;
344 * Details about an testbed run completed event.
350 * Error message for the operation, NULL on success.
355 * Array of peers now running (valid until
356 * 'GNUNET_TESTBED_testbed_stop' is called). Note that it is
357 * not allowed to call 'GNUNET_TESTBED_peer_destroy' on peers
360 struct GNUNET_TESTBED_Peer **peers;
363 * Size of the 'peers' array.
365 unsigned int num_peers;
367 } testbed_run_finished;
375 * Signature of the event handler function called by the
376 * respective event controller.
379 * @param event information about the event
381 typedef void (*GNUNET_TESTBED_ControllerCallback)(void *cls,
382 const struct GNUNET_TESTBED_EventInformation *event);
386 * Opaque Handle for Controller process
388 struct GNUNET_TESTBED_ControllerProc;
392 * Callback to signal successfull startup of the controller process
394 * @param cls the closure from GNUNET_TESTBED_controller_start()
395 * @param cfg the configuration with which the controller has been started;
396 * NULL if status is not GNUNET_OK
397 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
398 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
400 typedef void (*GNUNET_TESTBED_ControllerStatusCallback) (void *cls,
401 const struct GNUNET_CONFIGURATION_Handle *cfg,
406 * Starts a controller process at the host.
408 * @param controller_ip the ip address of the controller. Will be set as TRUSTED
409 * host when starting testbed controller at host
410 * @param host the host where the controller has to be started; NULL for
412 * @param cfg template configuration to use for the remote controller; the
413 * remote controller will be started with a slightly modified
414 * configuration (port numbers, unix domain sockets and service home
415 * values are changed as per TESTING library on the remote host)
416 * @param cb function called when the controller is successfully started or
417 * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
418 * called if cb is called with GNUNET_SYSERR as status. Will never be
419 * called in the same task as 'GNUNET_TESTBED_controller_start'
420 * (synchronous errors will be signalled by returning NULL). This
421 * parameter cannot be NULL.
422 * @param cls closure for above callbacks
423 * @return the controller process handle, NULL on errors
425 struct GNUNET_TESTBED_ControllerProc *
426 GNUNET_TESTBED_controller_start (const char *controller_ip,
427 struct GNUNET_TESTBED_Host *host,
428 const struct GNUNET_CONFIGURATION_Handle *cfg,
429 GNUNET_TESTBED_ControllerStatusCallback cb,
434 * Stop the controller process (also will terminate all peers and controllers
435 * dependent on this controller). This function blocks until the testbed has
436 * been fully terminated (!). The controller status cb from
437 * GNUNET_TESTBED_controller_start() will not be called.
439 * @param cproc the controller process handle
442 GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc);
446 * Connect to a controller process using the given configuration at the
449 * @param cfg configuration to use
450 * @param host host to run the controller on; This should be the same host if
451 * the controller was previously started with
452 * GNUNET_TESTBED_controller_start; NULL for localhost
453 * @param host host where this controller is being run;
454 * @param event_mask bit mask with set of events to call 'cc' for;
455 * or-ed values of "1LL" shifted by the
456 * respective 'enum GNUNET_TESTBED_EventType'
457 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) | ...")
458 * @param cc controller callback to invoke on events
459 * @param cc_cls closure for cc
460 * @return handle to the controller
462 struct GNUNET_TESTBED_Controller *
463 GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
464 struct GNUNET_TESTBED_Host *host,
466 GNUNET_TESTBED_ControllerCallback cc,
471 * Configure shared services at a controller. Using this function,
472 * you can specify that certain services (such as "resolver")
473 * should not be run for each peer but instead be shared
474 * across N peers on the specified host. This function
475 * must be called before any peers are created at the host.
477 * @param controller controller to configure
478 * @param service_name name of the service to share
479 * @param num_peers number of peers that should share one instance
480 * of the specified service (1 for no sharing is the default),
481 * use 0 to disable the service
484 GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller *controller,
485 const char *service_name,
490 * Stop the given controller (also will terminate all peers and
491 * controllers dependent on this controller). This function
492 * blocks until the testbed has been fully terminated (!).
494 * @param controller handle to controller to stop
497 GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *controller);
501 * Opaque handle for host registration
503 struct GNUNET_TESTBED_HostRegistrationHandle;
507 * Callback which will be called to after a host registration succeeded or failed
509 * @param cls the closure
510 * @param emsg the error message; NULL if host registration is successful
512 typedef void (* GNUNET_TESTBED_HostRegistrationCompletion) (void *cls,
517 * Register a host with the controller
519 * @param controller the controller handle
520 * @param host the host to register
521 * @param cc the completion callback to call to inform the status of
522 * registration. After calling this callback the registration handle
523 * will be invalid. Cannot be NULL
524 * @param cc_cls the closure for the cc
525 * @return handle to the host registration which can be used to cancel the
526 * registration; NULL if another registration handle is present and
529 struct GNUNET_TESTBED_HostRegistrationHandle *
530 GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
531 struct GNUNET_TESTBED_Host *host,
532 GNUNET_TESTBED_HostRegistrationCompletion cc,
537 * Cancel the pending registration. Note that the registration message will
538 * already be queued to be sent to the service, cancellation has only the
539 * effect that the registration completion callback for the registration is
540 * never called and from our perspective the host is not registered until the
541 * completion callback is called.
543 * @param handle the registration handle to cancel
546 GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
551 * Callback to be called when an operation is completed
553 * @param cls the callback closure from functions generating an operation
554 * @param op the operation that has been finished
555 * @param emsg error message in case the operation has failed; will be NULL if
556 * operation has executed successfully.
558 typedef void (*GNUNET_TESTBED_OperationCompletionCallback) (void *cls,
560 GNUNET_TESTBED_Operation
566 * Create a link from slave controller to delegated controller. Whenever the
567 * master controller is asked to start a peer at the delegated controller the
568 * request will be routed towards slave controller (if a route exists). The
569 * slave controller will then route it to the delegated controller. The
570 * configuration of the delegated controller is given and is used to either
571 * create the delegated controller or to connect to an existing controller. Note
572 * that while starting the delegated controller the configuration will be
573 * modified to accommodate available free ports. the 'is_subordinate' specifies
574 * if the given delegated controller should be started and managed by the slave
575 * controller, or if the delegated controller already has a master and the slave
576 * controller connects to it as a non master controller. The success or failure
577 * of this operation will be signalled through the
578 * GNUNET_TESTBED_ControllerCallback() with an event of type
579 * GNUNET_TESTBED_ET_OPERATION_FINISHED
581 * @param op_cls the operation closure for the event which is generated to
582 * signal success or failure of this operation
583 * @param master handle to the master controller who creates the association
584 * @param delegated_host requests to which host should be delegated; cannot be NULL
585 * @param slave_host which host is used to run the slave controller; use NULL to
586 * make the master controller connect to the delegated host
587 * @param slave_cfg configuration to use for the slave controller
588 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
589 * be started by the slave controller; GNUNET_NO if the slave
590 * controller has to connect to the already started delegated
591 * controller via TCP/IP
592 * @return the operation handle
594 struct GNUNET_TESTBED_Operation *
595 GNUNET_TESTBED_controller_link (void *op_cls,
596 struct GNUNET_TESTBED_Controller *master,
597 struct GNUNET_TESTBED_Host *delegated_host,
598 struct GNUNET_TESTBED_Host *slave_host,
599 const struct GNUNET_CONFIGURATION_Handle
605 * Same as the GNUNET_TESTBED_controller_link, however expects configuration in
606 * serialized and compressed
608 * @param op_cls the operation closure for the event which is generated to
609 * signal success or failure of this operation
610 * @param master handle to the master controller who creates the association
611 * @param delegated_host requests to which host should be delegated; cannot be NULL
612 * @param slave_host which host is used to run the slave controller; use NULL to
613 * make the master controller connect to the delegated host
614 * @param sxcfg serialized and compressed configuration
615 * @param sxcfg_size the size sxcfg
616 * @param scfg_size the size of uncompressed serialized configuration
617 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
618 * be started by the slave controller; GNUNET_NO if the slave
619 * controller has to connect to the already started delegated
620 * controller via TCP/IP
621 * @return the operation handle
623 struct GNUNET_TESTBED_Operation *
624 GNUNET_TESTBED_controller_link_2 (void *op_cls,
625 struct GNUNET_TESTBED_Controller *master,
626 struct GNUNET_TESTBED_Host *delegated_host,
627 struct GNUNET_TESTBED_Host *slave_host,
635 * Function to acquire the configuration of a running slave controller. The
636 * completion of the operation is signalled through the controller_cb from
637 * GNUNET_TESTBED_controller_connect(). If the operation is successful the
638 * handle to the configuration is available in the generic pointer of
639 * operation_finished field of struct GNUNET_TESTBED_EventInformation.
641 * @param op_cls the closure for the operation
642 * @param master the handle to master controller
643 * @param slave_host the host where the slave controller is running; the handle
644 * to the slave_host should remain valid until this operation is
645 * cancelled or marked as finished
646 * @return the operation handle; NULL if the slave_host is not registered at
649 struct GNUNET_TESTBED_Operation *
650 GNUNET_TESTBED_get_slave_config (void *op_cls,
651 struct GNUNET_TESTBED_Controller *master,
652 struct GNUNET_TESTBED_Host *slave_host);
656 * Functions of this signature are called when a peer has been successfully
659 * @param cls the closure from GNUNET_TESTBED_peer_create()
660 * @param peer the handle for the created peer; NULL on any error during
662 * @param emsg NULL if peer is not NULL; else MAY contain the error description
664 typedef void (*GNUNET_TESTBED_PeerCreateCallback) (void *cls,
665 struct GNUNET_TESTBED_Peer *peer,
670 * Create the given peer at the specified host using the given
671 * controller. If the given controller is not running on the target
672 * host, it should find or create a controller at the target host and
673 * delegate creating the peer. Explicit delegation paths can be setup
674 * using 'GNUNET_TESTBED_controller_link'. If no explicit delegation
675 * path exists, a direct link with a subordinate controller is setup
676 * for the first delegated peer to a particular host; the subordinate
677 * controller is then destroyed once the last peer that was delegated
678 * to the remote host is stopped.
680 * Creating the peer only creates the handle to manipulate and further
681 * configure the peer; use "GNUNET_TESTBED_peer_start" and
682 * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's
685 * Note that the given configuration will be adjusted by the
686 * controller to avoid port/path conflicts with other peers.
687 * The "final" configuration can be obtained using
688 * 'GNUNET_TESTBED_peer_get_information'.
690 * @param controller controller process to use
691 * @param host host to run the peer on
692 * @param cfg Template configuration to use for the peer. Should exist until
693 * operation is cancelled or GNUNET_TESTBED_operation_done() is called
694 * @param cb the callback to call when the peer has been created
695 * @param cls the closure to the above callback
696 * @return the operation handle
698 struct GNUNET_TESTBED_Operation *
699 GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
700 struct GNUNET_TESTBED_Host *host,
701 const struct GNUNET_CONFIGURATION_Handle *cfg,
702 GNUNET_TESTBED_PeerCreateCallback cb,
707 * Functions of this signature are called when a peer has been successfully
708 * started or stopped.
710 * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
711 * @param emsg NULL on success; otherwise an error description
713 typedef void (*GNUNET_TESTBED_PeerChurnCallback) (void *cls,
718 * Start the given peer.
720 * @param op_cls the closure for this operation; will be set in
721 * event->details.operation_finished.op_cls when this operation fails.
722 * @param peer peer to start
723 * @param pcc function to call upon completion
724 * @param pcc_cls closure for 'pcc'
725 * @return handle to the operation
727 struct GNUNET_TESTBED_Operation *
728 GNUNET_TESTBED_peer_start (void *op_cls,
729 struct GNUNET_TESTBED_Peer *peer,
730 GNUNET_TESTBED_PeerChurnCallback pcc,
735 * Stop the given peer. The handle remains valid (use
736 * "GNUNET_TESTBED_peer_destroy" to fully clean up the
737 * state of the peer).
739 * @param peer peer to stop
740 * @param pcc function to call upon completion
741 * @param pcc_cls closure for 'pcc'
742 * @return handle to the operation
744 struct GNUNET_TESTBED_Operation *
745 GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer,
746 GNUNET_TESTBED_PeerChurnCallback pcc,
751 * Data returned from GNUNET_TESTBED_peer_get_information
753 struct GNUNET_TESTBED_PeerInformation
756 * Peer information type; captures which of the types
757 * in the 'op_result' is actually in use.
759 enum GNUNET_TESTBED_PeerInformationType pit;
762 * The result of the get information operation; Choose according to the pit
767 * The configuration of the peer
769 struct GNUNET_CONFIGURATION_Handle *cfg;
772 * The identity of the peer
774 struct GNUNET_PeerIdentity *id;
780 * Callback to be called when the requested peer information is available
782 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
783 * @param op the operation this callback corresponds to
784 * @param pinfo the result; will be NULL if the operation has failed
785 * @param emsg error message if the operation has failed; will be NULL if the
786 * operation is successfull
788 typedef void (*GNUNET_TESTBED_PeerInfoCallback) (void *cb_cls,
789 struct GNUNET_TESTBED_Operation
792 GNUNET_TESTBED_PeerInformation
798 * Request information about a peer. The controller callback will not be called
799 * with event type GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this
800 * operation is available. Instead, the GNUNET_TESTBED_PeerInfoCallback() will
803 * @param peer peer to request information about
804 * @param pit desired information
805 * @param cb the convenience callback to be called when results for this
806 * operation are available
807 * @param cb_cls the closure for the above callback
808 * @return handle to the operation
810 struct GNUNET_TESTBED_Operation *
811 GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
812 enum GNUNET_TESTBED_PeerInformationType
814 GNUNET_TESTBED_PeerInfoCallback cb,
819 * Change peer configuration. Must only be called while the
820 * peer is stopped. Ports and paths cannot be changed this
823 * @param peer peer to change configuration for
824 * @param cfg new configuration (differences to existing
825 * configuration only)
826 * @return handle to the operation
828 struct GNUNET_TESTBED_Operation *
829 GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
830 const struct GNUNET_CONFIGURATION_Handle *cfg);
834 * Destroy the given peer; the peer should have been
835 * stopped first (if it was started).
837 * @param peer peer to stop
838 * @return handle to the operation
840 struct GNUNET_TESTBED_Operation *
841 GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer);
845 * Options for peer connections.
847 enum GNUNET_TESTBED_ConnectOption
850 * No option (not valid as an argument).
852 GNUNET_TESTBED_CO_NONE = 0,
855 * Allow or disallow a connection between the specified peers.
856 * Followed by GNUNET_NO (int) if a connection is disallowed
857 * or GNUNET_YES if a connection is allowed. Note that the
858 * default (all connections allowed or disallowed) is
859 * specified in the configuration of the controller.
861 GNUNET_TESTBED_CO_ALLOW = 1,
864 * FIXME: add (and implement) options to limit connection to
865 * particular transports, force simulation of particular latencies
866 * or message loss rates, or set bandwidth limitations.
873 * Manipulate the P2P underlay topology by configuring a link
876 * @param op_cls closure argument to give with the operation event
877 * @param p1 first peer
878 * @param p2 second peer
879 * @param co option to change
880 * @param ap option-specific values
881 * @return handle to the operation, NULL if configuring the link at this
882 * time is not allowed
884 struct GNUNET_TESTBED_Operation *
885 GNUNET_TESTBED_underlay_configure_link_va (void *op_cls,
886 struct GNUNET_TESTBED_Peer *p1,
887 struct GNUNET_TESTBED_Peer *p2,
888 enum GNUNET_TESTBED_ConnectOption co,
893 * Manipulate the P2P underlay topology by configuring a link
896 * @param op_cls closure argument to give with the operation event
897 * @param p1 first peer
898 * @param p2 second peer
899 * @param co option to change
900 * @param ... option-specific values
901 * @return handle to the operation, NULL if configuring the link at this
902 * time is not allowed
904 struct GNUNET_TESTBED_Operation *
905 GNUNET_TESTBED_underlay_configure_link (void *op_cls,
906 struct GNUNET_TESTBED_Peer *p1,
907 struct GNUNET_TESTBED_Peer *p2,
908 enum GNUNET_TESTBED_ConnectOption co, ...);
913 * Topologies and topology options supported for testbeds. Options should always
914 * end with GNUNET_TESTBED_TOPOLOGY_OPTION_END
916 enum GNUNET_TESTBED_TopologyOption
919 * A clique (everyone connected to everyone else). No options. If there are N
920 * peers this topology results in (N * (N -1)) connections.
922 GNUNET_TESTBED_TOPOLOGY_CLIQUE,
925 * Small-world network (2d torus plus random links). Followed
926 * by the number of random links to add (unsigned int).
928 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD,
931 * Small-world network (ring plus random links). Followed
932 * by the number of random links to add (unsigned int).
934 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING,
937 * Ring topology. No options.
939 GNUNET_TESTBED_TOPOLOGY_RING,
942 * 2-d torus. No options.
944 GNUNET_TESTBED_TOPOLOGY_2D_TORUS,
947 * Random graph. Followed by the number of random links to be established
950 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
953 * Certain percentage of peers are unable to communicate directly
954 * replicating NAT conditions. Followed by the fraction of
955 * NAT'ed peers (float).
957 GNUNET_TESTBED_TOPOLOGY_INTERNAT,
960 * Scale free topology. FIXME: options?
962 GNUNET_TESTBED_TOPOLOGY_SCALE_FREE,
965 * Straight line topology. No options.
967 GNUNET_TESTBED_TOPOLOGY_LINE,
970 * All peers are disconnected. No options.
972 GNUNET_TESTBED_TOPOLOGY_NONE,
975 * Read a topology from a given file. Followed by the name of the file (const char *).
977 GNUNET_TESTBED_TOPOLOGY_FROM_FILE,
980 * The options should always end with this
982 GNUNET_TESTBED_TOPOLOGY_OPTION_END,
984 /* The following are not topologies but influence how the topology has to be
985 setup. These options should follow the topology specific options (if
986 required by the chosen topology). Note that these should be given before
987 GNUNET_TESTBED_TOPOLOGY_OPTION_END */
990 * Disable automatic retrying for failed overlay connections. The default is
991 * to always retry failed overlay connections. This parameter takes no options.
993 GNUNET_TESTBED_TOPOLOGY_DISABLE_AUTO_RETRY
998 * Configure overall network topology to have a particular shape.
1000 * @param op_cls closure argument to give with the operation event
1001 * @param num_peers number of peers in 'peers'
1002 * @param peers array of 'num_peers' with the peers to configure
1003 * @param topo desired underlay topology to use
1004 * @param ap topology-specific options
1005 * @return handle to the operation, NULL if configuring the topology
1006 * is not allowed at this time
1008 struct GNUNET_TESTBED_Operation *
1009 GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
1010 unsigned int num_peers,
1011 struct GNUNET_TESTBED_Peer **peers,
1012 enum GNUNET_TESTBED_TopologyOption topo,
1017 * Configure overall network topology to have a particular shape.
1019 * @param op_cls closure argument to give with the operation event
1020 * @param num_peers number of peers in 'peers'
1021 * @param peers array of 'num_peers' with the peers to configure
1022 * @param topo desired underlay topology to use
1023 * @param ... topology-specific options
1024 * @return handle to the operation, NULL if configuring the topology
1025 * is not allowed at this time
1027 struct GNUNET_TESTBED_Operation *
1028 GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
1029 unsigned int num_peers,
1030 struct GNUNET_TESTBED_Peer **peers,
1031 enum GNUNET_TESTBED_TopologyOption topo,
1036 * Both peers must have been started before calling this function.
1037 * This function then obtains a HELLO from 'p1', gives it to 'p2'
1038 * and asks 'p2' to connect to 'p1'.
1040 * @param op_cls closure argument to give with the operation event
1041 * @param cb the callback to call when this operation has finished
1042 * @param cb_cls the closure for the above callback
1043 * @param p1 first peer
1044 * @param p2 second peer
1045 * @return handle to the operation, NULL if connecting these two
1046 * peers is fundamentally not possible at this time (peers
1047 * not running or underlay disallows)
1049 struct GNUNET_TESTBED_Operation *
1050 GNUNET_TESTBED_overlay_connect (void *op_cls,
1051 GNUNET_TESTBED_OperationCompletionCallback cb,
1053 struct GNUNET_TESTBED_Peer *p1,
1054 struct GNUNET_TESTBED_Peer *p2);
1058 * All peers must have been started before calling this function.
1059 * This function then connects the given peers in the P2P overlay
1060 * using the given topology.
1062 * @param op_cls closure argument to give with the operation event
1063 * @param num_peers number of peers in 'peers'
1064 * @param peers array of 'num_peers' with the peers to configure
1065 * @param topo desired underlay topology to use
1066 * @param va topology-specific options
1067 * @return handle to the operation, NULL if connecting these
1068 * peers is fundamentally not possible at this time (peers
1069 * not running or underlay disallows) or if num_peers is less than 2
1071 struct GNUNET_TESTBED_Operation *
1072 GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
1073 unsigned int num_peers,
1074 struct GNUNET_TESTBED_Peer **peers,
1075 enum GNUNET_TESTBED_TopologyOption topo,
1080 * All peers must have been started before calling this function.
1081 * This function then connects the given peers in the P2P overlay
1082 * using the given topology.
1084 * @param op_cls closure argument to give with the operation event
1085 * @param num_peers number of peers in 'peers'
1086 * @param peers array of 'num_peers' with the peers to configure
1087 * @param topo desired underlay topology to use
1088 * @param ... topology-specific options
1089 * @return handle to the operation, NULL if connecting these
1090 * peers is fundamentally not possible at this time (peers
1091 * not running or underlay disallows) or if num_peers is less than 2
1093 struct GNUNET_TESTBED_Operation *
1094 GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
1095 unsigned int num_peers,
1096 struct GNUNET_TESTBED_Peer **peers,
1097 enum GNUNET_TESTBED_TopologyOption topo,
1102 * Ask the testbed controller to write the current overlay topology to
1103 * a file. Naturally, the file will only contain a snapshot as the
1104 * topology may evolve all the time.
1105 * FIXME: needs continuation!?
1107 * @param controller overlay controller to inspect
1108 * @param filename name of the file the topology should
1112 GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller *controller,
1113 const char *filename);
1117 * Adapter function called to establish a connection to
1120 * @param cls closure
1121 * @param cfg configuration of the peer to connect to; will be available until
1122 * GNUNET_TESTBED_operation_done() is called on the operation returned
1123 * from GNUNET_TESTBED_service_connect()
1124 * @return service handle to return in 'op_result', NULL on error
1126 typedef void * (*GNUNET_TESTBED_ConnectAdapter)(void *cls,
1127 const struct GNUNET_CONFIGURATION_Handle *cfg);
1131 * Adapter function called to destroy a connection to
1134 * @param cls closure
1135 * @param op_result service handle returned from the connect adapter
1137 typedef void (*GNUNET_TESTBED_DisconnectAdapter)(void *cls,
1142 * Callback to be called when a service connect operation is completed
1144 * @param cls the callback closure from functions generating an operation
1145 * @param op the operation that has been finished
1146 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
1147 * @param emsg error message in case the operation has failed; will be NULL if
1148 * operation has executed successfully.
1150 typedef void (*GNUNET_TESTBED_ServiceConnectCompletionCallback) (void *cls,
1152 GNUNET_TESTBED_Operation
1161 * Connect to a service offered by the given peer. Will ensure that
1162 * the request is queued to not overwhelm our ability to create and
1163 * maintain connections with other systems. The actual service
1164 * handle is then returned via the 'op_result' member in the event
1165 * callback. The 'ca' callback is used to create the connection
1166 * when the time is right; the 'da' callback will be used to
1167 * destroy the connection (upon 'GNUNET_TESTBED_operation_done').
1168 * 'GNUNET_TESTBED_operation_cancel' can be used to abort this
1169 * operation until the event callback has been called.
1171 * @param op_cls closure to pass in operation event
1172 * @param peer peer that runs the service
1173 * @param service_name name of the service to connect to
1174 * @param cb the callback to call when this operation finishes
1175 * @param cb_cls closure for the above callback
1176 * @param ca helper function to establish the connection
1177 * @param da helper function to close the connection
1178 * @param cada_cls closure for ca and da
1179 * @return handle for the operation
1181 struct GNUNET_TESTBED_Operation *
1182 GNUNET_TESTBED_service_connect (void *op_cls,
1183 struct GNUNET_TESTBED_Peer *peer,
1184 const char *service_name,
1185 GNUNET_TESTBED_ServiceConnectCompletionCallback cb,
1187 GNUNET_TESTBED_ConnectAdapter ca,
1188 GNUNET_TESTBED_DisconnectAdapter da,
1193 * This function is used to signal that the event information (struct
1194 * GNUNET_TESTBED_EventInformation) from an operation has been fully processed
1195 * i.e. if the event callback is ever called for this operation. If the event
1196 * callback for this operation has not yet been called, calling this function
1197 * cancels the operation, frees its resources and ensures the no event is
1198 * generated with respect to this operation. Note that however cancelling an
1199 * operation does NOT guarantee that the operation will be fully undone (or that
1200 * nothing ever happened).
1202 * This function MUST be called for every operation to fully remove the
1203 * operation from the operation queue. After calling this function, if
1204 * operation is completed and its event information is of type
1205 * GNUNET_TESTBED_ET_OPERATION_FINISHED, the 'op_result' becomes invalid (!).
1207 * If the operation is generated from GNUNET_TESTBED_service_connect() then
1208 * calling this function on such as operation calls the disconnect adapter if
1209 * the connect adapter was ever called.
1211 * @param operation operation to signal completion or cancellation
1214 GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation);
1218 * Configure and run a testbed using the given
1219 * master controller on 'num_hosts' starting
1220 * 'num_peers' using the given peer configuration.
1222 * @param controller master controller for the testbed
1223 * (must not be destroyed until after the
1224 * testbed is destroyed).
1225 * @param num_hosts number of hosts in 'hosts', 0 to only
1227 * @param hosts list of hosts to use for the testbed
1228 * @param num_peers number of peers to start
1229 * @param peer_cfg peer configuration template to use
1230 * @param underlay_topology underlay topology to create
1231 * @param va topology-specific options
1232 * @return handle to the testbed
1234 struct GNUNET_TESTBED_Testbed *
1235 GNUNET_TESTBED_create_va (struct GNUNET_TESTBED_Controller *controller,
1236 unsigned int num_hosts,
1237 struct GNUNET_TESTBED_Host **hosts,
1238 unsigned int num_peers,
1239 const struct GNUNET_CONFIGURATION_Handle *peer_cfg,
1240 enum GNUNET_TESTBED_TopologyOption underlay_topology,
1245 * Configure and run a testbed using the given
1246 * master controller on 'num_hosts' starting
1247 * 'num_peers' using the given peer configuration.
1249 * @param controller master controller for the testbed
1250 * (must not be destroyed until after the
1251 * testbed is destroyed).
1252 * @param num_hosts number of hosts in 'hosts', 0 to only
1254 * @param hosts list of hosts to use for the testbed
1255 * @param num_peers number of peers to start
1256 * @param peer_cfg peer configuration template to use
1257 * @param underlay_topology underlay topology to create
1258 * @param ... topology-specific options
1260 struct GNUNET_TESTBED_Testbed *
1261 GNUNET_TESTBED_create (struct GNUNET_TESTBED_Controller *controller,
1262 unsigned int num_hosts,
1263 struct GNUNET_TESTBED_Host **hosts,
1264 unsigned int num_peers,
1265 const struct GNUNET_CONFIGURATION_Handle *peer_cfg,
1266 enum GNUNET_TESTBED_TopologyOption underlay_topology,
1271 * Destroy a testbed. Stops all running peers and then
1272 * destroys all peers. Does NOT destroy the master controller.
1274 * @param testbed testbed to destroy
1277 GNUNET_TESTBED_destroy (struct GNUNET_TESTBED_Testbed *testbed);
1281 * Callback function to process statistic values from all peers.
1283 * @param cls closure
1284 * @param peer the peer the statistic belong to
1285 * @param subsystem name of subsystem that created the statistic
1286 * @param name the name of the datum
1287 * @param value the current value
1288 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
1289 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
1291 typedef int (*GNUNET_TESTBED_StatisticsIterator) (void *cls,
1292 const struct GNUNET_TESTBED_Peer *peer,
1293 const char *subsystem,
1300 * Convenience method that iterates over all (running) peers
1301 * and retrieves all statistics from each peer.
1303 * @param num_peers number of peers to iterate over
1304 * @param peers array of peers to iterate over
1305 * @param proc processing function for each statistic retrieved
1306 * @param cont continuation to call once call is completed(?)
1307 * @param cls closure to pass to proc and cont
1308 * @return operation handle to cancel the operation
1310 struct GNUNET_TESTBED_Operation *
1311 GNUNET_TESTBED_get_statistics (unsigned int num_peers,
1312 struct GNUNET_TESTBED_Peer **peers,
1313 GNUNET_TESTBED_StatisticsIterator proc,
1314 GNUNET_TESTBED_OperationCompletionCallback cont,
1319 * Convenience method for running a testbed with
1320 * a single call. Underlay and overlay topology
1321 * are configured using the "UNDERLAY" and "OVERLAY"
1322 * options in the "[testbed]" section of the configuration\
1323 * (with possible options given in "UNDERLAY_XXX" and/or
1326 * The testbed is to be terminated using a call to
1327 * "GNUNET_SCHEDULER_shutdown".
1329 * @param host_filename name of the file with the 'hosts', NULL
1330 * to run everything on 'localhost'
1331 * @param cfg configuration to use (for testbed, controller and peers)
1332 * @param num_peers number of peers to start; FIXME: maybe put that ALSO into
1333 * cfg?; should be greater than 0
1334 * @param event_mask bit mask with set of events to call 'cc' for;
1335 * or-ed values of "1LL" shifted by the
1336 * respective 'enum GNUNET_TESTBED_EventType'
1337 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1338 * @param cc controller callback to invoke on events; This callback is called
1339 * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1340 * set in the event_mask as this is the only way get access to the
1341 * handle of each peer
1342 * @param cc_cls closure for cc
1343 * @param master task to run once the testbed is ready
1344 * @param master_cls closure for 'task'.
1347 GNUNET_TESTBED_run (const char *host_filename,
1348 const struct GNUNET_CONFIGURATION_Handle *cfg,
1349 unsigned int num_peers,
1350 uint64_t event_mask,
1351 GNUNET_TESTBED_ControllerCallback cc,
1353 GNUNET_SCHEDULER_Task master,
1358 * Signature of a main function for a testcase.
1360 * @param cls closure
1361 * @param num_peers number of peers in 'peers'
1362 * @param peers handle to peers run in the testbed
1364 typedef void (*GNUNET_TESTBED_TestMaster)(void *cls,
1365 unsigned int num_peers,
1366 struct GNUNET_TESTBED_Peer **peers);
1370 * Convenience method for running a "simple" test on the local system
1371 * with a single call from 'main'. Underlay and overlay topology are
1372 * configured using the "UNDERLAY" and "OVERLAY" options in the
1373 * "[testbed]" section of the configuration (with possible options
1374 * given in "UNDERLAY_XXX" and/or "OVERLAY_XXX").
1376 * The test is to be terminated using a call to
1377 * "GNUNET_SCHEDULER_shutdown". If starting the test fails,
1378 * the program is stopped without 'master' ever being run.
1380 * NOTE: this function should be called from 'main', NOT from
1381 * within a GNUNET_SCHEDULER-loop. This function will initialze
1382 * the scheduler loop, the testbed and then pass control to
1385 * @param testname name of the testcase (to configure logging, etc.)
1386 * @param cfg_filename configuration filename to use
1387 * (for testbed, controller and peers)
1388 * @param num_peers number of peers to start; should be greter than 0
1389 * @param event_mask bit mask with set of events to call 'cc' for;
1390 * or-ed values of "1LL" shifted by the
1391 * respective 'enum GNUNET_TESTBED_EventType'
1392 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1393 * @param cc controller callback to invoke on events; This callback is called
1394 * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1395 * set in the event_mask as this is the only way get access to the
1396 * handle of each peer
1397 * @param cc_cls closure for cc
1398 * @param test_master task to run once the test is ready
1399 * @param test_master_cls closure for 'task'.
1402 GNUNET_TESTBED_test_run (const char *testname,
1403 const char *cfg_filename,
1404 unsigned int num_peers,
1405 uint64_t event_mask,
1406 GNUNET_TESTBED_ControllerCallback cc,
1408 GNUNET_TESTBED_TestMaster test_master,
1409 void *test_master_cls);
1412 #if 0 /* keep Emacsens' auto-indent happy */