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
117 * @return number of hosts returned in 'hosts', 0 on error
120 GNUNET_TESTBED_hosts_load_from_file (const char *filename,
121 struct GNUNET_TESTBED_Host **hosts);
125 * Destroy a host handle. Must only be called once everything
126 * running on that host has been stopped.
128 * @param host handle to destroy
131 GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host);
135 * Enumeration with (at most 64) possible event types that
136 * can be monitored using the testbed framework.
138 enum GNUNET_TESTBED_EventType
141 * A peer has been started.
143 GNUNET_TESTBED_ET_PEER_START = 0,
146 * A peer has been stopped.
148 GNUNET_TESTBED_ET_PEER_STOP = 1,
151 * A connection between two peers was established.
153 GNUNET_TESTBED_ET_CONNECT = 2,
156 * A connection between two peers was torn down.
158 GNUNET_TESTBED_ET_DISCONNECT = 3,
161 * A requested testbed operation has been completed.
163 GNUNET_TESTBED_ET_OPERATION_FINISHED = 4,
166 * The 'GNUNET_TESTBED_run' operation has been completed
168 GNUNET_TESTBED_ET_TESTBED_ONLINE = 5
174 * Types of information that can be requested about a peer.
176 enum GNUNET_TESTBED_PeerInformationType
180 * Special value (not valid for requesting information)
181 * that is used in the event struct if a 'generic' pointer
182 * is returned (for other operations not related to this
185 GNUNET_TESTBED_PIT_GENERIC = 0,
188 * What host is the peer running on? Returns a 'const struct
189 * GNUNET_TESTBED_Host *'. Valid until
190 * 'GNUNET_TESTBED_operation_done' is called.
192 GNUNET_TESTBED_PIT_HOST,
195 * What configuration is the peer using? Returns a 'const struct
196 * GNUNET_CONFIGURATION_Handle *'. Valid until
197 * 'GNUNET_TESTNIG_operation_done' is called. However, the
198 * values may be inaccurate if the peer is reconfigured in
201 GNUNET_TESTBED_PIT_CONFIGURATION,
204 * What is the identity of the peer? Returns a
205 * 'const struct GNUNET_PeerIdentity *'. Valid until
206 * 'GNUNET_TESTNIG_operation_done' is called.
208 GNUNET_TESTBED_PIT_IDENTITY
214 * Argument to GNUNET_TESTBED_ControllerCallback with details about
217 struct GNUNET_TESTBED_EventInformation
223 enum GNUNET_TESTBED_EventType type;
226 * Details about the event.
232 * Details about peer start event.
237 * Handle for the host where the peer
240 struct GNUNET_TESTBED_Host *host;
243 * Handle for the peer that was started.
245 struct GNUNET_TESTBED_Peer *peer;
250 * Details about peer stop event.
256 * Handle for the peer that was started.
258 struct GNUNET_TESTBED_Peer *peer;
263 * Details about connect event.
268 * Handle for one of the connected peers.
270 struct GNUNET_TESTBED_Peer *peer1;
273 * Handle for one of the connected peers.
275 struct GNUNET_TESTBED_Peer *peer2;
280 * Details about disconnect event.
285 * Handle for one of the disconnected peers.
287 struct GNUNET_TESTBED_Peer *peer1;
290 * Handle for one of the disconnected peers.
292 struct GNUNET_TESTBED_Peer *peer2;
297 * Details about an operation finished event.
303 * Handle for the operation that was finished.
305 struct GNUNET_TESTBED_Operation *operation;
308 * Closure that was passed in when the event was
314 * Error message for the operation, NULL on success.
319 * Peer information type; captures which of the types
320 * in the 'op_result' is actually in use.
322 enum GNUNET_TESTBED_PeerInformationType pit;
325 * Pointer to an operation-specific return value; NULL on error;
326 * can be NULL for certain operations. Valid until
327 * 'GNUNET_TESTBED_operation_done' is called.
332 * No result (NULL pointer) or generic result
333 * (whatever the GNUNET_TESTBED_ConnectAdapter returned).
338 * Identity of host running the peer.
340 struct GNUNET_TESTBED_Host *host;
343 * Identity of the peer.
345 const struct GNUNET_PeerIdentity *pid;
348 * Configuration of the peer.
350 const struct GNUNET_CONFIGURATION_Handle *cfg;
354 } operation_finished;
358 * Details about an testbed run completed event.
364 * Error message for the operation, NULL on success.
369 * Array of peers now running (valid until
370 * 'GNUNET_TESTBED_testbed_stop' is called). Note that it is
371 * not allowed to call 'GNUNET_TESTBED_peer_destroy' on peers
374 struct GNUNET_TESTBED_Peer **peers;
377 * Size of the 'peers' array.
379 unsigned int num_peers;
381 } testbed_run_finished;
389 * Signature of the event handler function called by the
390 * respective event controller.
393 * @param event information about the event
395 typedef void (*GNUNET_TESTBED_ControllerCallback)(void *cls,
396 const struct GNUNET_TESTBED_EventInformation *event);
400 * Opaque Handle for Controller process
402 struct GNUNET_TESTBED_ControllerProc;
406 * Callback to signal successfull startup of the controller process
408 * @param cls the closure from GNUNET_TESTBED_controller_start()
409 * @param cfg the configuration with which the controller has been started;
410 * NULL if status is not GNUNET_OK
411 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
412 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
414 typedef void (*GNUNET_TESTBED_ControllerStatusCallback) (void *cls,
415 const struct GNUNET_CONFIGURATION_Handle *cfg,
420 * Starts a controller process at the host. FIXME: add controller start callback
421 * with the configuration with which the controller is started
423 * @param controller_ip the ip address of the controller. Will be set as TRUSTED
424 * host when starting testbed controller at host
425 * @param host the host where the controller has to be started; NULL for
427 * @param cfg template configuration to use for the remote controller; the
428 * remote controller will be started with a slightly modified
429 * configuration (port numbers, unix domain sockets and service home
430 * values are changed as per TESTING library on the remote host)
431 * @param cb function called when the controller is successfully started or
432 * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
433 * called if cb is called with GNUNET_SYSERR as status. Will never be
434 * called in the same task as 'GNUNET_TESTBED_controller_start'
435 * (synchronous errors will be signalled by returning NULL). This
436 * parameter cannot be NULL.
437 * @param cls closure for above callbacks
438 * @return the controller process handle, NULL on errors
440 struct GNUNET_TESTBED_ControllerProc *
441 GNUNET_TESTBED_controller_start (const char *controller_ip,
442 struct GNUNET_TESTBED_Host *host,
443 const struct GNUNET_CONFIGURATION_Handle *cfg,
444 GNUNET_TESTBED_ControllerStatusCallback cb,
449 * Stop the controller process (also will terminate all peers and controllers
450 * dependent on this controller). This function blocks until the testbed has
451 * been fully terminated (!).
453 * @param cproc the controller process handle
456 GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc);
460 * Connect to a controller process using the given configuration at the
463 * @param cfg configuration to use
464 * @param host host to run the controller on; This should be the same host if
465 * the controller was previously started with
466 * GNUNET_TESTBED_controller_start; NULL for localhost
467 * @param host host where this controller is being run;
468 * @param event_mask bit mask with set of events to call 'cc' for;
469 * or-ed values of "1LL" shifted by the
470 * respective 'enum GNUNET_TESTBED_EventType'
471 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) | ...")
472 * @param cc controller callback to invoke on events
473 * @param cc_cls closure for cc
474 * @return handle to the controller
476 struct GNUNET_TESTBED_Controller *
477 GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
478 struct GNUNET_TESTBED_Host *host,
480 GNUNET_TESTBED_ControllerCallback cc,
485 * Configure shared services at a controller. Using this function,
486 * you can specify that certain services (such as "resolver")
487 * should not be run for each peer but instead be shared
488 * across N peers on the specified host. This function
489 * must be called before any peers are created at the host.
491 * @param controller controller to configure
492 * @param service_name name of the service to share
493 * @param num_peers number of peers that should share one instance
494 * of the specified service (1 for no sharing is the default),
495 * use 0 to disable the service
498 GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller *controller,
499 const char *service_name,
504 * Stop the given controller (also will terminate all peers and
505 * controllers dependent on this controller). This function
506 * blocks until the testbed has been fully terminated (!).
508 * @param controller handle to controller to stop
511 GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *controller);
515 * Opaque handle for host registration
517 struct GNUNET_TESTBED_HostRegistrationHandle;
521 * Callback which will be called to after a host registration succeeded or failed
523 * @param cls the closure
524 * @param emsg the error message; NULL if host registration is successful
526 typedef void (* GNUNET_TESTBED_HostRegistrationCompletion) (void *cls,
531 * Register a host with the controller
533 * @param controller the controller handle
534 * @param host the host to register
535 * @param cc the completion callback to call to inform the status of
536 * registration. After calling this callback the registration handle
537 * will be invalid. Cannot be NULL
538 * @param cc_cls the closure for the cc
539 * @return handle to the host registration which can be used to cancel the
540 * registration; NULL if another registration handle is present and
543 struct GNUNET_TESTBED_HostRegistrationHandle *
544 GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
545 struct GNUNET_TESTBED_Host *host,
546 GNUNET_TESTBED_HostRegistrationCompletion cc,
551 * Cancel the pending registration. Note that the registration message will
552 * already be queued to be sent to the service, cancellation has only the
553 * effect that the registration completion callback for the registration is
554 * never called and from our perspective the host is not registered until the
555 * completion callback is called.
557 * @param handle the registration handle to cancel
560 GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
565 * Create a link from slave controller to delegated controller. Whenever the
566 * master controller is asked to start a peer at the delegated controller the
567 * request will be routed towards slave controller (if a route exists). The
568 * slave controller will then route it to the delegated controller. The
569 * configuration of the slave controller is given and to be used to either
570 * create the slave controller or to connect to an existing slave controller
571 * process. 'is_subordinate' specifies if the given slave controller should be
572 * started and managed by the master controller, or if the slave already has a
573 * master and this is just a secondary master that is also allowed to use the
576 * @param master handle to the master controller who creates the association
577 * @param delegated_host requests to which host should be delegated; cannot be NULL
578 * @param slave_host which host is used to run the slave controller; use NULL to
579 * make the master controller connect to the delegated host
580 * @param slave_cfg configuration to use for the slave controller
581 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
582 * be started by the master controller; GNUNET_NO if we are just
583 * allowed to use the slave via TCP/IP
586 GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master,
587 struct GNUNET_TESTBED_Host *delegated_host,
588 struct GNUNET_TESTBED_Host *slave_host,
589 const struct GNUNET_CONFIGURATION_Handle *slave_cfg,
594 * Same as the GNUNET_TESTBED_controller_link, however expects configuration in
595 * serialized and compressed
597 * @param master handle to the master controller who creates the association
598 * @param delegated_host requests to which host should be delegated; cannot be NULL
599 * @param slave_host which host is used to run the slave controller; use NULL to
600 * make the master controller connect to the delegated host
601 * @param sxcfg serialized and compressed configuration
602 * @param sxcfg_size the size scfg
603 * @param scfg_size the size of uncompressed serialized configuration
604 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
605 * be started by the master controller; GNUNET_NO if we are just
606 * allowed to use the slave via TCP/IP
609 GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master,
610 struct GNUNET_TESTBED_Host *delegated_host,
611 struct GNUNET_TESTBED_Host *slave_host,
619 * Functions of this signature are called when a peer has been successfully
622 * @param cls the closure from GNUNET_TESTBED_peer_create()
623 * @param peer the handle for the created peer; NULL on any error during
625 * @param emsg NULL if peer is not NULL; else MAY contain the error description
627 typedef void (*GNUNET_TESTBED_PeerCreateCallback) (void *cls,
628 struct GNUNET_TESTBED_Peer *peer,
633 * Create the given peer at the specified host using the given
634 * controller. If the given controller is not running on the target
635 * host, it should find or create a controller at the target host and
636 * delegate creating the peer. Explicit delegation paths can be setup
637 * using 'GNUNET_TESTBED_controller_link'. If no explicit delegation
638 * path exists, a direct link with a subordinate controller is setup
639 * for the first delegated peer to a particular host; the subordinate
640 * controller is then destroyed once the last peer that was delegated
641 * to the remote host is stopped.
643 * Creating the peer only creates the handle to manipulate and further
644 * configure the peer; use "GNUNET_TESTBED_peer_start" and
645 * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's
648 * Note that the given configuration will be adjusted by the
649 * controller to avoid port/path conflicts with other peers.
650 * The "final" configuration can be obtained using
651 * 'GNUNET_TESTBED_peer_get_information'.
653 * @param controller controller process to use
654 * @param host host to run the peer on
655 * @param cfg configuration to use for the peer
656 * @param cb the callback to call when the peer has been created
657 * @param cls the closure to the above callback
658 * @return the operation handle
660 struct GNUNET_TESTBED_Operation *
661 GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
662 struct GNUNET_TESTBED_Host *host,
663 const struct GNUNET_CONFIGURATION_Handle *cfg,
664 GNUNET_TESTBED_PeerCreateCallback cb,
669 * Start the given peer.
671 * @param peer peer to start
672 * @return handle to the operation
674 struct GNUNET_TESTBED_Operation *
675 GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer);
679 * Stop the given peer. The handle remains valid (use
680 * "GNUNET_TESTBED_peer_destroy" to fully clean up the
681 * state of the peer).
683 * @param peer peer to stop
684 * @return handle to the operation
686 struct GNUNET_TESTBED_Operation *
687 GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer);
691 * Request information about a peer.
693 * @param peer peer to request information about
694 * @param pit desired information
695 * @return handle to the operation
697 struct GNUNET_TESTBED_Operation *
698 GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
699 enum GNUNET_TESTBED_PeerInformationType pit);
703 * Change peer configuration. Must only be called while the
704 * peer is stopped. Ports and paths cannot be changed this
707 * @param peer peer to change configuration for
708 * @param cfg new configuration (differences to existing
709 * configuration only)
710 * @return handle to the operation
712 struct GNUNET_TESTBED_Operation *
713 GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
714 const struct GNUNET_CONFIGURATION_Handle *cfg);
718 * Destroy the given peer; the peer should have been
719 * stopped first (if it was started).
721 * @param peer peer to stop
722 * @return handle to the operation
724 struct GNUNET_TESTBED_Operation *
725 GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer);
729 * Options for peer connections.
731 enum GNUNET_TESTBED_ConnectOption
734 * No option (not valid as an argument).
736 GNUNET_TESTBED_CO_NONE = 0,
739 * Allow or disallow a connection between the specified peers.
740 * Followed by GNUNET_NO (int) if a connection is disallowed
741 * or GNUNET_YES if a connection is allowed. Note that the
742 * default (all connections allowed or disallowed) is
743 * specified in the configuration of the controller.
745 GNUNET_TESTBED_CO_ALLOW = 1,
748 * FIXME: add (and implement) options to limit connection to
749 * particular transports, force simulation of particular latencies
750 * or message loss rates, or set bandwidth limitations.
757 * Manipulate the P2P underlay topology by configuring a link
760 * @param op_cls closure argument to give with the operation event
761 * @param p1 first peer
762 * @param p2 second peer
763 * @param co option to change
764 * @param ap option-specific values
765 * @return handle to the operation, NULL if configuring the link at this
766 * time is not allowed
768 struct GNUNET_TESTBED_Operation *
769 GNUNET_TESTBED_underlay_configure_link_va (void *op_cls,
770 struct GNUNET_TESTBED_Peer *p1,
771 struct GNUNET_TESTBED_Peer *p2,
772 enum GNUNET_TESTBED_ConnectOption co,
777 * Manipulate the P2P underlay topology by configuring a link
780 * @param op_cls closure argument to give with the operation event
781 * @param p1 first peer
782 * @param p2 second peer
783 * @param co option to change
784 * @param ... option-specific values
785 * @return handle to the operation, NULL if configuring the link at this
786 * time is not allowed
788 struct GNUNET_TESTBED_Operation *
789 GNUNET_TESTBED_underlay_configure_link (void *op_cls,
790 struct GNUNET_TESTBED_Peer *p1,
791 struct GNUNET_TESTBED_Peer *p2,
792 enum GNUNET_TESTBED_ConnectOption co, ...);
797 * Topologies supported for testbeds.
799 enum GNUNET_TESTBED_TopologyOption
802 * A clique (everyone connected to everyone else). No options.
804 GNUNET_TESTBED_TOPOLOGY_CLIQUE,
807 * Small-world network (2d torus plus random links). Followed
808 * by the number of random links to add (unsigned int).
810 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD,
813 * Small-world network (ring plus random links). Followed
814 * by the number of random links to add (unsigned int).
816 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING,
819 * Ring topology. No options.
821 GNUNET_TESTBED_TOPOLOGY_RING,
824 * 2-d torus. No options.
826 GNUNET_TESTBED_TOPOLOGY_2D_TORUS,
829 * Random graph. Followed by the link density, that is the
830 * percentage of links present in relation to a clique
833 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
836 * Certain percentage of peers are unable to communicate directly
837 * replicating NAT conditions. Followed by the fraction of
838 * NAT'ed peers (float).
840 GNUNET_TESTBED_TOPOLOGY_INTERNAT,
843 * Scale free topology. FIXME: options?
845 GNUNET_TESTBED_TOPOLOGY_SCALE_FREE,
848 * Straight line topology. No options.
850 GNUNET_TESTBED_TOPOLOGY_LINE,
853 * All peers are disconnected. No options.
855 GNUNET_TESTBED_TOPOLOGY_NONE,
858 * Read a topology from a given file. Followed by the name of the file (const char *).
860 GNUNET_TESTBED_TOPOLOGY_FROM_FILE
865 * Configure overall network topology to have a particular shape.
867 * @param op_cls closure argument to give with the operation event
868 * @param num_peers number of peers in 'peers'
869 * @param peers array of 'num_peers' with the peers to configure
870 * @param topo desired underlay topology to use
871 * @param ap topology-specific options
872 * @return handle to the operation, NULL if configuring the topology
873 * is not allowed at this time
875 struct GNUNET_TESTBED_Operation *
876 GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
877 unsigned int num_peers,
878 struct GNUNET_TESTBED_Peer **peers,
879 enum GNUNET_TESTBED_TopologyOption topo,
884 * Configure overall network topology to have a particular shape.
886 * @param op_cls closure argument to give with the operation event
887 * @param num_peers number of peers in 'peers'
888 * @param peers array of 'num_peers' with the peers to configure
889 * @param topo desired underlay topology to use
890 * @param ... topology-specific options
891 * @return handle to the operation, NULL if configuring the topology
892 * is not allowed at this time
894 struct GNUNET_TESTBED_Operation *
895 GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
896 unsigned int num_peers,
897 struct GNUNET_TESTBED_Peer **peers,
898 enum GNUNET_TESTBED_TopologyOption topo,
903 * Both peers must have been started before calling this function.
904 * This function then obtains a HELLO from 'p1', gives it to 'p2'
905 * and asks 'p2' to connect to 'p1'.
907 * @param op_cls closure argument to give with the operation event
908 * @param p1 first peer
909 * @param p2 second peer
910 * @return handle to the operation, NULL if connecting these two
911 * peers is fundamentally not possible at this time (peers
912 * not running or underlay disallows)
914 struct GNUNET_TESTBED_Operation *
915 GNUNET_TESTBED_overlay_connect (void *op_cls,
916 struct GNUNET_TESTBED_Peer *p1,
917 struct GNUNET_TESTBED_Peer *p2);
921 * All peers must have been started before calling this function.
922 * This function then connects the given peers in the P2P overlay
923 * using the given topology.
925 * @param op_cls closure argument to give with the operation event
926 * @param num_peers number of peers in 'peers'
927 * @param peers array of 'num_peers' with the peers to configure
928 * @param topo desired underlay topology to use
929 * @param va topology-specific options
930 * @return handle to the operation, NULL if connecting these
931 * peers is fundamentally not possible at this time (peers
932 * not running or underlay disallows)
934 struct GNUNET_TESTBED_Operation *
935 GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
936 unsigned int num_peers,
937 struct GNUNET_TESTBED_Peer *peers,
938 enum GNUNET_TESTBED_TopologyOption topo,
943 * All peers must have been started before calling this function.
944 * This function then connects the given peers in the P2P overlay
945 * using the given topology.
947 * @param op_cls closure argument to give with the operation event
948 * @param num_peers number of peers in 'peers'
949 * @param peers array of 'num_peers' with the peers to configure
950 * @param topo desired underlay topology to use
951 * @param ... topology-specific options
952 * @return handle to the operation, NULL if connecting these
953 * peers is fundamentally not possible at this time (peers
954 * not running or underlay disallows)
956 struct GNUNET_TESTBED_Operation *
957 GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
958 unsigned int num_peers,
959 struct GNUNET_TESTBED_Peer *peers,
960 enum GNUNET_TESTBED_TopologyOption topo,
965 * Ask the testbed controller to write the current overlay topology to
966 * a file. Naturally, the file will only contain a snapshot as the
967 * topology may evolve all the time.
969 * @param controller overlay controller to inspect
970 * @param filename name of the file the topology should
974 GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller *controller,
975 const char *filename);
979 * Adapter function called to establish a connection to
983 * @param cfg configuration of the peer to connect to
984 * @return service handle to return in 'op_result', NULL on error
986 typedef void * (*GNUNET_TESTBED_ConnectAdapter)(void *cls,
987 const struct GNUNET_CONFIGURATION_Handle *cfg);
991 * Adapter function called to destroy a connection to
995 * @param op_result service handle returned from the connect adapter
997 typedef void (*GNUNET_TESTBED_DisconnectAdapter)(void *cls,
1002 * Connect to a service offered by the given peer. Will ensure that
1003 * the request is queued to not overwhelm our ability to create and
1004 * maintain connections with other systems. The actual service
1005 * handle is then returned via the 'op_result' member in the event
1006 * callback. The 'ca' callback is used to create the connection
1007 * when the time is right; the 'da' callback will be used to
1008 * destroy the connection (upon 'GNUNET_TESTBED_operation_done').
1009 * 'GNUNET_TESTBED_operation_cancel' can be used to abort this
1010 * operation until the event callback has been called.
1012 * @param op_cls closure to pass in operation event
1013 * @param peer peer that runs the service
1014 * @param service_name name of the service to connect to
1015 * @param ca helper function to establish the connection
1016 * @param da helper function to close the connection
1017 * @param cada_cls closure for ca and da
1018 * @return handle for the operation
1020 struct GNUNET_TESTBED_Operation *
1021 GNUNET_TESTBED_service_connect (void *op_cls,
1022 struct GNUNET_TESTBED_Peer *peer,
1023 const char *service_name,
1024 GNUNET_TESTBED_ConnectAdapter ca,
1025 GNUNET_TESTBED_DisconnectAdapter da,
1030 * Cancel a pending operation. Releases all resources
1031 * of the operation and will ensure that no event
1032 * is generated for the operation. Does NOT guarantee
1033 * that the operation will be fully undone (or that
1034 * nothing ever happened).
1036 * @param operation operation to cancel
1039 GNUNET_TESTBED_operation_cancel (struct GNUNET_TESTBED_Operation *operation);
1043 * Signal that the information from an operation has been fully
1044 * processed. This function MUST be called for each event
1045 * of type 'operation_finished' to fully remove the operation
1046 * from the operation queue. After calling this function, the
1047 * 'op_result' becomes invalid (!).
1049 * @param operation operation to signal completion for
1052 GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation);
1056 * Configure and run a testbed using the given
1057 * master controller on 'num_hosts' starting
1058 * 'num_peers' using the given peer configuration.
1060 * @param controller master controller for the testbed
1061 * (must not be destroyed until after the
1062 * testbed is destroyed).
1063 * @param num_hosts number of hosts in 'hosts', 0 to only
1065 * @param hosts list of hosts to use for the testbed
1066 * @param num_peers number of peers to start
1067 * @param peer_cfg peer configuration template to use
1068 * @param underlay_topology underlay topology to create
1069 * @param va topology-specific options
1070 * @return handle to the testbed
1072 struct GNUNET_TESTBED_Testbed *
1073 GNUNET_TESTBED_create_va (struct GNUNET_TESTBED_Controller *controller,
1074 unsigned int num_hosts,
1075 struct GNUNET_TESTBED_Host **hosts,
1076 unsigned int num_peers,
1077 const struct GNUNET_CONFIGURATION_Handle *peer_cfg,
1078 enum GNUNET_TESTBED_TopologyOption underlay_topology,
1083 * Configure and run a testbed using the given
1084 * master controller on 'num_hosts' starting
1085 * 'num_peers' using the given peer configuration.
1087 * @param controller master controller for the testbed
1088 * (must not be destroyed until after the
1089 * testbed is destroyed).
1090 * @param num_hosts number of hosts in 'hosts', 0 to only
1092 * @param hosts list of hosts to use for the testbed
1093 * @param num_peers number of peers to start
1094 * @param peer_cfg peer configuration template to use
1095 * @param underlay_topology underlay topology to create
1096 * @param ... topology-specific options
1098 struct GNUNET_TESTBED_Testbed *
1099 GNUNET_TESTBED_create (struct GNUNET_TESTBED_Controller *controller,
1100 unsigned int num_hosts,
1101 struct GNUNET_TESTBED_Host **hosts,
1102 unsigned int num_peers,
1103 const struct GNUNET_CONFIGURATION_Handle *peer_cfg,
1104 enum GNUNET_TESTBED_TopologyOption underlay_topology,
1109 * Destroy a testbed. Stops all running peers and then
1110 * destroys all peers. Does NOT destroy the master controller.
1112 * @param testbed testbed to destroy
1115 GNUNET_TESTBED_destroy (struct GNUNET_TESTBED_Testbed *testbed);
1119 * Convenience method for running a testbed with
1120 * a single call. Underlay and overlay topology
1121 * are configured using the "UNDERLAY" and "OVERLAY"
1122 * options in the "[testbed]" section of the configuration\
1123 * (with possible options given in "UNDERLAY_XXX" and/or
1126 * The testbed is to be terminated using a call to
1127 * "GNUNET_SCHEDULER_shutdown".
1129 * @param host_filename name of the file with the 'hosts', NULL
1130 * to run everything on 'localhost'
1131 * @param cfg configuration to use (for testbed, controller and peers)
1132 * @param num_peers number of peers to start; FIXME: maybe put that ALSO into cfg?
1133 * @param event_mask bit mask with set of events to call 'cc' for;
1134 * or-ed values of "1LL" shifted by the
1135 * respective 'enum GNUNET_TESTBED_EventType'
1136 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1137 * @param cc controller callback to invoke on events
1138 * @param cc_cls closure for cc
1139 * @param master task to run once the testbed is ready
1140 * @param master_cls closure for 'task'.
1143 GNUNET_TESTBED_run (const char *host_filename,
1144 const struct GNUNET_CONFIGURATION_Handle *cfg,
1145 unsigned int num_peers,
1146 uint64_t event_mask,
1147 GNUNET_TESTBED_ControllerCallback cc,
1149 GNUNET_SCHEDULER_Task master,
1154 * Signature of a main function for a testcase.
1156 * @param cls closure
1157 * @param num_peers number of peers in 'peers'
1158 * @param peers handle to peers run in the testbed
1160 typedef void (*GNUNET_TESTBED_TestMaster)(void *cls,
1161 unsigned int num_peers,
1162 struct GNUNET_TESTBED_Peer **peers);
1166 * Convenience method for running a "simple" test on the local system
1167 * with a single call from 'main'. Underlay and overlay topology are
1168 * configured using the "UNDERLAY" and "OVERLAY" options in the
1169 * "[testbed]" section of the configuration (with possible options
1170 * given in "UNDERLAY_XXX" and/or "OVERLAY_XXX").
1172 * The test is to be terminated using a call to
1173 * "GNUNET_SCHEDULER_shutdown". If starting the test fails,
1174 * the program is stopped without 'master' ever being run.
1176 * NOTE: this function should be called from 'main', NOT from
1177 * within a GNUNET_SCHEDULER-loop. This function will initialze
1178 * the scheduler loop, the testbed and then pass control to
1181 * @param testname name of the testcase (to configure logging, etc.)
1182 * @param cfg_filename configuration filename to use
1183 * (for testbed, controller and peers)
1184 * @param num_peers number of peers to start
1185 * @param test_master task to run once the test is ready
1186 * @param test_master_cls closure for 'task'.
1189 GNUNET_TESTBED_test_run (const char *testname,
1190 const char *cfg_filename,
1191 unsigned int num_peers,
1192 GNUNET_TESTBED_TestMaster test_master,
1193 void *test_master_cls);
1196 #if 0 /* keep Emacsens' auto-indent happy */