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 configuration is the peer using? Returns a 'const struct
189 * GNUNET_CONFIGURATION_Handle *'. Valid until
190 * 'GNUNET_TESTNIG_operation_done' is called. However, the
191 * values may be inaccurate if the peer is reconfigured in
194 GNUNET_TESTBED_PIT_CONFIGURATION,
197 * What is the identity of the peer? Returns a
198 * 'const struct GNUNET_PeerIdentity *'. Valid until
199 * 'GNUNET_TESTNIG_operation_done' is called.
201 GNUNET_TESTBED_PIT_IDENTITY
207 * Argument to GNUNET_TESTBED_ControllerCallback with details about
210 struct GNUNET_TESTBED_EventInformation
216 enum GNUNET_TESTBED_EventType type;
219 * Details about the event.
225 * Details about peer start event.
230 * Handle for the host where the peer
233 struct GNUNET_TESTBED_Host *host;
236 * Handle for the peer that was started.
238 struct GNUNET_TESTBED_Peer *peer;
243 * Details about peer stop event.
249 * Handle for the peer that was started.
251 struct GNUNET_TESTBED_Peer *peer;
256 * Details about connect event.
261 * Handle for one of the connected peers.
263 struct GNUNET_TESTBED_Peer *peer1;
266 * Handle for one of the connected peers.
268 struct GNUNET_TESTBED_Peer *peer2;
273 * Details about disconnect event.
278 * Handle for one of the disconnected peers.
280 struct GNUNET_TESTBED_Peer *peer1;
283 * Handle for one of the disconnected peers.
285 struct GNUNET_TESTBED_Peer *peer2;
290 * Details about an operation finished event.
296 * Handle for the operation that was finished.
298 struct GNUNET_TESTBED_Operation *operation;
301 * Closure that was passed in when the event was
307 * Error message for the operation, NULL on success.
312 * No result (NULL pointer) or generic result
313 * (whatever the GNUNET_TESTBED_ConnectAdapter returned).
317 } operation_finished;
321 * Details about an testbed run completed event.
327 * Error message for the operation, NULL on success.
332 * Array of peers now running (valid until
333 * 'GNUNET_TESTBED_testbed_stop' is called). Note that it is
334 * not allowed to call 'GNUNET_TESTBED_peer_destroy' on peers
337 struct GNUNET_TESTBED_Peer **peers;
340 * Size of the 'peers' array.
342 unsigned int num_peers;
344 } testbed_run_finished;
352 * Signature of the event handler function called by the
353 * respective event controller.
356 * @param event information about the event
358 typedef void (*GNUNET_TESTBED_ControllerCallback)(void *cls,
359 const struct GNUNET_TESTBED_EventInformation *event);
363 * Opaque Handle for Controller process
365 struct GNUNET_TESTBED_ControllerProc;
369 * Callback to signal successfull startup of the controller process
371 * @param cls the closure from GNUNET_TESTBED_controller_start()
372 * @param cfg the configuration with which the controller has been started;
373 * NULL if status is not GNUNET_OK
374 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
375 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
377 typedef void (*GNUNET_TESTBED_ControllerStatusCallback) (void *cls,
378 const struct GNUNET_CONFIGURATION_Handle *cfg,
383 * Starts a controller process at the host. FIXME: add controller start callback
384 * with the configuration with which the controller is started
386 * @param controller_ip the ip address of the controller. Will be set as TRUSTED
387 * host when starting testbed controller at host
388 * @param host the host where the controller has to be started; NULL for
390 * @param cfg template configuration to use for the remote controller; the
391 * remote controller will be started with a slightly modified
392 * configuration (port numbers, unix domain sockets and service home
393 * values are changed as per TESTING library on the remote host)
394 * @param cb function called when the controller is successfully started or
395 * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
396 * called if cb is called with GNUNET_SYSERR as status. Will never be
397 * called in the same task as 'GNUNET_TESTBED_controller_start'
398 * (synchronous errors will be signalled by returning NULL). This
399 * parameter cannot be NULL.
400 * @param cls closure for above callbacks
401 * @return the controller process handle, NULL on errors
403 struct GNUNET_TESTBED_ControllerProc *
404 GNUNET_TESTBED_controller_start (const char *controller_ip,
405 struct GNUNET_TESTBED_Host *host,
406 const struct GNUNET_CONFIGURATION_Handle *cfg,
407 GNUNET_TESTBED_ControllerStatusCallback cb,
412 * Stop the controller process (also will terminate all peers and controllers
413 * dependent on this controller). This function blocks until the testbed has
414 * been fully terminated (!).
416 * @param cproc the controller process handle
419 GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc);
423 * Connect to a controller process using the given configuration at the
426 * @param cfg configuration to use
427 * @param host host to run the controller on; This should be the same host if
428 * the controller was previously started with
429 * GNUNET_TESTBED_controller_start; NULL for localhost
430 * @param host host where this controller is being run;
431 * @param event_mask bit mask with set of events to call 'cc' for;
432 * or-ed values of "1LL" shifted by the
433 * respective 'enum GNUNET_TESTBED_EventType'
434 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) | ...")
435 * @param cc controller callback to invoke on events
436 * @param cc_cls closure for cc
437 * @return handle to the controller
439 struct GNUNET_TESTBED_Controller *
440 GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
441 struct GNUNET_TESTBED_Host *host,
443 GNUNET_TESTBED_ControllerCallback cc,
448 * Configure shared services at a controller. Using this function,
449 * you can specify that certain services (such as "resolver")
450 * should not be run for each peer but instead be shared
451 * across N peers on the specified host. This function
452 * must be called before any peers are created at the host.
454 * @param controller controller to configure
455 * @param service_name name of the service to share
456 * @param num_peers number of peers that should share one instance
457 * of the specified service (1 for no sharing is the default),
458 * use 0 to disable the service
461 GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller *controller,
462 const char *service_name,
467 * Stop the given controller (also will terminate all peers and
468 * controllers dependent on this controller). This function
469 * blocks until the testbed has been fully terminated (!).
471 * @param controller handle to controller to stop
474 GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *controller);
478 * Opaque handle for host registration
480 struct GNUNET_TESTBED_HostRegistrationHandle;
484 * Callback which will be called to after a host registration succeeded or failed
486 * @param cls the closure
487 * @param emsg the error message; NULL if host registration is successful
489 typedef void (* GNUNET_TESTBED_HostRegistrationCompletion) (void *cls,
494 * Register a host with the controller
496 * @param controller the controller handle
497 * @param host the host to register
498 * @param cc the completion callback to call to inform the status of
499 * registration. After calling this callback the registration handle
500 * will be invalid. Cannot be NULL
501 * @param cc_cls the closure for the cc
502 * @return handle to the host registration which can be used to cancel the
503 * registration; NULL if another registration handle is present and
506 struct GNUNET_TESTBED_HostRegistrationHandle *
507 GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
508 struct GNUNET_TESTBED_Host *host,
509 GNUNET_TESTBED_HostRegistrationCompletion cc,
514 * Cancel the pending registration. Note that the registration message will
515 * already be queued to be sent to the service, cancellation has only the
516 * effect that the registration completion callback for the registration is
517 * never called and from our perspective the host is not registered until the
518 * completion callback is called.
520 * @param handle the registration handle to cancel
523 GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
528 * Callback to be called when an operation is completed
530 * @param cls the callback closure from functions generating an operation
531 * @param op the operation that has been finished
532 * @param emsg error message in case the operation has failed; will be NULL if
533 * operation has executed successfully.
535 typedef void (*GNUNET_TESTBED_OperationCompletionCallback) (void *cls,
537 GNUNET_TESTBED_Operation
543 * Create a link from slave controller to delegated controller. Whenever the
544 * master controller is asked to start a peer at the delegated controller the
545 * request will be routed towards slave controller (if a route exists). The
546 * slave controller will then route it to the delegated controller. The
547 * configuration of the slave controller is given and to be used to either
548 * create the slave controller or to connect to an existing slave controller
549 * process. 'is_subordinate' specifies if the given slave controller should be
550 * started and managed by the master controller, or if the slave already has a
551 * master and this is just a secondary master that is also allowed to use the
554 * @param master handle to the master controller who creates the association
555 * @param delegated_host requests to which host should be delegated; cannot be NULL
556 * @param slave_host which host is used to run the slave controller; use NULL to
557 * make the master controller connect to the delegated host
558 * @param slave_cfg configuration to use for the slave controller
559 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
560 * be started by the master controller; GNUNET_NO if we are just
561 * allowed to use the slave via TCP/IP
562 * @return the operation handle
564 struct GNUNET_TESTBED_Operation *
565 GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master,
566 struct GNUNET_TESTBED_Host *delegated_host,
567 struct GNUNET_TESTBED_Host *slave_host,
568 const struct GNUNET_CONFIGURATION_Handle *slave_cfg,
573 * Same as the GNUNET_TESTBED_controller_link, however expects configuration in
574 * serialized and compressed
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 sxcfg serialized and compressed configuration
581 * @param sxcfg_size the size scfg
582 * @param scfg_size the size of uncompressed serialized configuration
583 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
584 * be started by the master controller; GNUNET_NO if we are just
585 * allowed to use the slave via TCP/IP
586 * @return the operation handle
588 struct GNUNET_TESTBED_Operation *
589 GNUNET_TESTBED_controller_link_2 (struct GNUNET_TESTBED_Controller *master,
590 struct GNUNET_TESTBED_Host *delegated_host,
591 struct GNUNET_TESTBED_Host *slave_host,
599 * Functions of this signature are called when a peer has been successfully
602 * @param cls the closure from GNUNET_TESTBED_peer_create()
603 * @param peer the handle for the created peer; NULL on any error during
605 * @param emsg NULL if peer is not NULL; else MAY contain the error description
607 typedef void (*GNUNET_TESTBED_PeerCreateCallback) (void *cls,
608 struct GNUNET_TESTBED_Peer *peer,
613 * Create the given peer at the specified host using the given
614 * controller. If the given controller is not running on the target
615 * host, it should find or create a controller at the target host and
616 * delegate creating the peer. Explicit delegation paths can be setup
617 * using 'GNUNET_TESTBED_controller_link'. If no explicit delegation
618 * path exists, a direct link with a subordinate controller is setup
619 * for the first delegated peer to a particular host; the subordinate
620 * controller is then destroyed once the last peer that was delegated
621 * to the remote host is stopped.
623 * Creating the peer only creates the handle to manipulate and further
624 * configure the peer; use "GNUNET_TESTBED_peer_start" and
625 * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's
628 * Note that the given configuration will be adjusted by the
629 * controller to avoid port/path conflicts with other peers.
630 * The "final" configuration can be obtained using
631 * 'GNUNET_TESTBED_peer_get_information'.
633 * @param controller controller process to use
634 * @param host host to run the peer on
635 * @param cfg Template configuration to use for the peer. Should exist until
636 * operation is cancelled or GNUNET_TESTBED_operation_done() is called
637 * @param cb the callback to call when the peer has been created
638 * @param cls the closure to the above callback
639 * @return the operation handle
641 struct GNUNET_TESTBED_Operation *
642 GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
643 struct GNUNET_TESTBED_Host *host,
644 const struct GNUNET_CONFIGURATION_Handle *cfg,
645 GNUNET_TESTBED_PeerCreateCallback cb,
650 * Start the given peer.
652 * @param peer peer to start
653 * @return handle to the operation
655 struct GNUNET_TESTBED_Operation *
656 GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer);
660 * Stop the given peer. The handle remains valid (use
661 * "GNUNET_TESTBED_peer_destroy" to fully clean up the
662 * state of the peer).
664 * @param peer peer to stop
665 * @return handle to the operation
667 struct GNUNET_TESTBED_Operation *
668 GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer);
672 * Data returned from GNUNET_TESTBED_peer_get_information
674 struct GNUNET_TESTBED_PeerInformation
677 * Peer information type; captures which of the types
678 * in the 'op_result' is actually in use.
680 enum GNUNET_TESTBED_PeerInformationType pit;
683 * The result of the get information operation; Choose according to the pit
688 * The configuration of the peer
690 struct GNUNET_CONFIGURATION_Handle *cfg;
693 * The identity of the peer
695 struct GNUNET_PeerIdentity *id;
701 * Callback to be called when the requested peer information is available
703 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
704 * @param op the operation this callback corresponds to
705 * @param pinfo the result; will be NULL if the operation has failed
706 * @param emsg error message if the operation has failed; will be NULL if the
707 * operation is successfull
709 typedef void (*GNUNET_TESTBED_PeerInfoCallback) (void *cb_cls,
710 struct GNUNET_TESTBED_Operation
713 GNUNET_TESTBED_PeerInformation
719 * Request information about a peer. The controller callback will be called with
720 * event type GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this
721 * operation is available
723 * @param peer peer to request information about
724 * @param pit desired information
725 * @param cb the convenience callback to be called when results for this
726 * operation are available
727 * @param cb_cls the closure for the above callback
728 * @return handle to the operation
730 struct GNUNET_TESTBED_Operation *
731 GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
732 enum GNUNET_TESTBED_PeerInformationType
734 GNUNET_TESTBED_PeerInfoCallback cb,
739 * Change peer configuration. Must only be called while the
740 * peer is stopped. Ports and paths cannot be changed this
743 * @param peer peer to change configuration for
744 * @param cfg new configuration (differences to existing
745 * configuration only)
746 * @return handle to the operation
748 struct GNUNET_TESTBED_Operation *
749 GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
750 const struct GNUNET_CONFIGURATION_Handle *cfg);
754 * Destroy the given peer; the peer should have been
755 * stopped first (if it was started).
757 * @param peer peer to stop
758 * @return handle to the operation
760 struct GNUNET_TESTBED_Operation *
761 GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer);
765 * Options for peer connections.
767 enum GNUNET_TESTBED_ConnectOption
770 * No option (not valid as an argument).
772 GNUNET_TESTBED_CO_NONE = 0,
775 * Allow or disallow a connection between the specified peers.
776 * Followed by GNUNET_NO (int) if a connection is disallowed
777 * or GNUNET_YES if a connection is allowed. Note that the
778 * default (all connections allowed or disallowed) is
779 * specified in the configuration of the controller.
781 GNUNET_TESTBED_CO_ALLOW = 1,
784 * FIXME: add (and implement) options to limit connection to
785 * particular transports, force simulation of particular latencies
786 * or message loss rates, or set bandwidth limitations.
793 * Manipulate the P2P underlay topology by configuring a link
796 * @param op_cls closure argument to give with the operation event
797 * @param p1 first peer
798 * @param p2 second peer
799 * @param co option to change
800 * @param ap option-specific values
801 * @return handle to the operation, NULL if configuring the link at this
802 * time is not allowed
804 struct GNUNET_TESTBED_Operation *
805 GNUNET_TESTBED_underlay_configure_link_va (void *op_cls,
806 struct GNUNET_TESTBED_Peer *p1,
807 struct GNUNET_TESTBED_Peer *p2,
808 enum GNUNET_TESTBED_ConnectOption co,
813 * Manipulate the P2P underlay topology by configuring a link
816 * @param op_cls closure argument to give with the operation event
817 * @param p1 first peer
818 * @param p2 second peer
819 * @param co option to change
820 * @param ... option-specific values
821 * @return handle to the operation, NULL if configuring the link at this
822 * time is not allowed
824 struct GNUNET_TESTBED_Operation *
825 GNUNET_TESTBED_underlay_configure_link (void *op_cls,
826 struct GNUNET_TESTBED_Peer *p1,
827 struct GNUNET_TESTBED_Peer *p2,
828 enum GNUNET_TESTBED_ConnectOption co, ...);
833 * Topologies supported for testbeds.
835 enum GNUNET_TESTBED_TopologyOption
838 * A clique (everyone connected to everyone else). No options.
840 GNUNET_TESTBED_TOPOLOGY_CLIQUE,
843 * Small-world network (2d torus plus random links). Followed
844 * by the number of random links to add (unsigned int).
846 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD,
849 * Small-world network (ring plus random links). Followed
850 * by the number of random links to add (unsigned int).
852 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING,
855 * Ring topology. No options.
857 GNUNET_TESTBED_TOPOLOGY_RING,
860 * 2-d torus. No options.
862 GNUNET_TESTBED_TOPOLOGY_2D_TORUS,
865 * Random graph. Followed by the link density, that is the
866 * percentage of links present in relation to a clique
869 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
872 * Certain percentage of peers are unable to communicate directly
873 * replicating NAT conditions. Followed by the fraction of
874 * NAT'ed peers (float).
876 GNUNET_TESTBED_TOPOLOGY_INTERNAT,
879 * Scale free topology. FIXME: options?
881 GNUNET_TESTBED_TOPOLOGY_SCALE_FREE,
884 * Straight line topology. No options.
886 GNUNET_TESTBED_TOPOLOGY_LINE,
889 * All peers are disconnected. No options.
891 GNUNET_TESTBED_TOPOLOGY_NONE,
894 * Read a topology from a given file. Followed by the name of the file (const char *).
896 GNUNET_TESTBED_TOPOLOGY_FROM_FILE
901 * Configure overall network topology to have a particular shape.
903 * @param op_cls closure argument to give with the operation event
904 * @param num_peers number of peers in 'peers'
905 * @param peers array of 'num_peers' with the peers to configure
906 * @param topo desired underlay topology to use
907 * @param ap topology-specific options
908 * @return handle to the operation, NULL if configuring the topology
909 * is not allowed at this time
911 struct GNUNET_TESTBED_Operation *
912 GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
913 unsigned int num_peers,
914 struct GNUNET_TESTBED_Peer **peers,
915 enum GNUNET_TESTBED_TopologyOption topo,
920 * Configure overall network topology to have a particular shape.
922 * @param op_cls closure argument to give with the operation event
923 * @param num_peers number of peers in 'peers'
924 * @param peers array of 'num_peers' with the peers to configure
925 * @param topo desired underlay topology to use
926 * @param ... topology-specific options
927 * @return handle to the operation, NULL if configuring the topology
928 * is not allowed at this time
930 struct GNUNET_TESTBED_Operation *
931 GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
932 unsigned int num_peers,
933 struct GNUNET_TESTBED_Peer **peers,
934 enum GNUNET_TESTBED_TopologyOption topo,
939 * Both peers must have been started before calling this function.
940 * This function then obtains a HELLO from 'p1', gives it to 'p2'
941 * and asks 'p2' to connect to 'p1'.
943 * @param op_cls closure argument to give with the operation event
944 * @param cb the callback to call when this operation has finished
945 * @param cb_cls the closure for the above callback
946 * @param p1 first peer
947 * @param p2 second peer
948 * @return handle to the operation, NULL if connecting these two
949 * peers is fundamentally not possible at this time (peers
950 * not running or underlay disallows)
952 struct GNUNET_TESTBED_Operation *
953 GNUNET_TESTBED_overlay_connect (void *op_cls,
954 GNUNET_TESTBED_OperationCompletionCallback cb,
956 struct GNUNET_TESTBED_Peer *p1,
957 struct GNUNET_TESTBED_Peer *p2);
961 * All peers must have been started before calling this function.
962 * This function then connects the given peers in the P2P overlay
963 * using the given topology.
965 * @param op_cls closure argument to give with the operation event
966 * @param num_peers number of peers in 'peers'
967 * @param peers array of 'num_peers' with the peers to configure
968 * @param topo desired underlay topology to use
969 * @param va topology-specific options
970 * @return handle to the operation, NULL if connecting these
971 * peers is fundamentally not possible at this time (peers
972 * not running or underlay disallows)
974 struct GNUNET_TESTBED_Operation *
975 GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
976 unsigned int num_peers,
977 struct GNUNET_TESTBED_Peer *peers,
978 enum GNUNET_TESTBED_TopologyOption topo,
983 * All peers must have been started before calling this function.
984 * This function then connects the given peers in the P2P overlay
985 * using the given topology.
987 * @param op_cls closure argument to give with the operation event
988 * @param num_peers number of peers in 'peers'
989 * @param peers array of 'num_peers' with the peers to configure
990 * @param topo desired underlay topology to use
991 * @param ... topology-specific options
992 * @return handle to the operation, NULL if connecting these
993 * peers is fundamentally not possible at this time (peers
994 * not running or underlay disallows)
996 struct GNUNET_TESTBED_Operation *
997 GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
998 unsigned int num_peers,
999 struct GNUNET_TESTBED_Peer *peers,
1000 enum GNUNET_TESTBED_TopologyOption topo,
1005 * Ask the testbed controller to write the current overlay topology to
1006 * a file. Naturally, the file will only contain a snapshot as the
1007 * topology may evolve all the time.
1009 * @param controller overlay controller to inspect
1010 * @param filename name of the file the topology should
1014 GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller *controller,
1015 const char *filename);
1019 * Adapter function called to establish a connection to
1022 * @param cls closure
1023 * @param cfg configuration of the peer to connect to; will be available until
1024 * GNUNET_TESTBED_operation_done() is called on the operation returned
1025 * from GNUNET_TESTBED_service_connect()
1026 * @return service handle to return in 'op_result', NULL on error
1028 typedef void * (*GNUNET_TESTBED_ConnectAdapter)(void *cls,
1029 const struct GNUNET_CONFIGURATION_Handle *cfg);
1033 * Adapter function called to destroy a connection to
1036 * @param cls closure
1037 * @param op_result service handle returned from the connect adapter
1039 typedef void (*GNUNET_TESTBED_DisconnectAdapter)(void *cls,
1044 * Callback to be called when a service connect operation is completed
1046 * @param cls the callback closure from functions generating an operation
1047 * @param op the operation that has been finished
1048 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
1049 * @param emsg error message in case the operation has failed; will be NULL if
1050 * operation has executed successfully.
1052 typedef void (*GNUNET_TESTBED_ServiceConnectCompletionCallback) (void *cls,
1054 GNUNET_TESTBED_Operation
1063 * Connect to a service offered by the given peer. Will ensure that
1064 * the request is queued to not overwhelm our ability to create and
1065 * maintain connections with other systems. The actual service
1066 * handle is then returned via the 'op_result' member in the event
1067 * callback. The 'ca' callback is used to create the connection
1068 * when the time is right; the 'da' callback will be used to
1069 * destroy the connection (upon 'GNUNET_TESTBED_operation_done').
1070 * 'GNUNET_TESTBED_operation_cancel' can be used to abort this
1071 * operation until the event callback has been called.
1073 * @param op_cls closure to pass in operation event
1074 * @param peer peer that runs the service
1075 * @param service_name name of the service to connect to
1076 * @param cb the callback to call when this operation finishes
1077 * @param cb_cls closure for the above callback
1078 * @param ca helper function to establish the connection
1079 * @param da helper function to close the connection
1080 * @param cada_cls closure for ca and da
1081 * @return handle for the operation
1083 struct GNUNET_TESTBED_Operation *
1084 GNUNET_TESTBED_service_connect (void *op_cls,
1085 struct GNUNET_TESTBED_Peer *peer,
1086 const char *service_name,
1087 GNUNET_TESTBED_ServiceConnectCompletionCallback cb,
1089 GNUNET_TESTBED_ConnectAdapter ca,
1090 GNUNET_TESTBED_DisconnectAdapter da,
1095 * Cancel a pending operation. Releases all resources
1096 * of the operation and will ensure that no event
1097 * is generated for the operation. Does NOT guarantee
1098 * that the operation will be fully undone (or that
1099 * nothing ever happened).
1101 * @param operation operation to cancel
1104 GNUNET_TESTBED_operation_cancel (struct GNUNET_TESTBED_Operation *operation);
1108 * Signal that the information from an operation has been fully
1109 * processed. This function MUST be called for each event
1110 * of type 'operation_finished' to fully remove the operation
1111 * from the operation queue. After calling this function, the
1112 * 'op_result' becomes invalid (!).
1114 * @param operation operation to signal completion for
1117 GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation);
1121 * Configure and run a testbed using the given
1122 * master controller on 'num_hosts' starting
1123 * 'num_peers' using the given peer configuration.
1125 * @param controller master controller for the testbed
1126 * (must not be destroyed until after the
1127 * testbed is destroyed).
1128 * @param num_hosts number of hosts in 'hosts', 0 to only
1130 * @param hosts list of hosts to use for the testbed
1131 * @param num_peers number of peers to start
1132 * @param peer_cfg peer configuration template to use
1133 * @param underlay_topology underlay topology to create
1134 * @param va topology-specific options
1135 * @return handle to the testbed
1137 struct GNUNET_TESTBED_Testbed *
1138 GNUNET_TESTBED_create_va (struct GNUNET_TESTBED_Controller *controller,
1139 unsigned int num_hosts,
1140 struct GNUNET_TESTBED_Host **hosts,
1141 unsigned int num_peers,
1142 const struct GNUNET_CONFIGURATION_Handle *peer_cfg,
1143 enum GNUNET_TESTBED_TopologyOption underlay_topology,
1148 * Configure and run a testbed using the given
1149 * master controller on 'num_hosts' starting
1150 * 'num_peers' using the given peer configuration.
1152 * @param controller master controller for the testbed
1153 * (must not be destroyed until after the
1154 * testbed is destroyed).
1155 * @param num_hosts number of hosts in 'hosts', 0 to only
1157 * @param hosts list of hosts to use for the testbed
1158 * @param num_peers number of peers to start
1159 * @param peer_cfg peer configuration template to use
1160 * @param underlay_topology underlay topology to create
1161 * @param ... topology-specific options
1163 struct GNUNET_TESTBED_Testbed *
1164 GNUNET_TESTBED_create (struct GNUNET_TESTBED_Controller *controller,
1165 unsigned int num_hosts,
1166 struct GNUNET_TESTBED_Host **hosts,
1167 unsigned int num_peers,
1168 const struct GNUNET_CONFIGURATION_Handle *peer_cfg,
1169 enum GNUNET_TESTBED_TopologyOption underlay_topology,
1174 * Destroy a testbed. Stops all running peers and then
1175 * destroys all peers. Does NOT destroy the master controller.
1177 * @param testbed testbed to destroy
1180 GNUNET_TESTBED_destroy (struct GNUNET_TESTBED_Testbed *testbed);
1184 * Convenience method for running a testbed with
1185 * a single call. Underlay and overlay topology
1186 * are configured using the "UNDERLAY" and "OVERLAY"
1187 * options in the "[testbed]" section of the configuration\
1188 * (with possible options given in "UNDERLAY_XXX" and/or
1191 * The testbed is to be terminated using a call to
1192 * "GNUNET_SCHEDULER_shutdown".
1194 * @param host_filename name of the file with the 'hosts', NULL
1195 * to run everything on 'localhost'
1196 * @param cfg configuration to use (for testbed, controller and peers)
1197 * @param num_peers number of peers to start; FIXME: maybe put that ALSO into
1198 * cfg?; should be greater than 0
1199 * @param event_mask bit mask with set of events to call 'cc' for;
1200 * or-ed values of "1LL" shifted by the
1201 * respective 'enum GNUNET_TESTBED_EventType'
1202 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1203 * @param cc controller callback to invoke on events; This callback is called
1204 * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1205 * set in the event_mask as this is the only way get access to the
1206 * handle of each peer
1207 * @param cc_cls closure for cc
1208 * @param master task to run once the testbed is ready
1209 * @param master_cls closure for 'task'.
1212 GNUNET_TESTBED_run (const char *host_filename,
1213 const struct GNUNET_CONFIGURATION_Handle *cfg,
1214 unsigned int num_peers,
1215 uint64_t event_mask,
1216 GNUNET_TESTBED_ControllerCallback cc,
1218 GNUNET_SCHEDULER_Task master,
1223 * Signature of a main function for a testcase.
1225 * @param cls closure
1226 * @param num_peers number of peers in 'peers'
1227 * @param peers handle to peers run in the testbed
1229 typedef void (*GNUNET_TESTBED_TestMaster)(void *cls,
1230 unsigned int num_peers,
1231 struct GNUNET_TESTBED_Peer **peers);
1235 * Convenience method for running a "simple" test on the local system
1236 * with a single call from 'main'. Underlay and overlay topology are
1237 * configured using the "UNDERLAY" and "OVERLAY" options in the
1238 * "[testbed]" section of the configuration (with possible options
1239 * given in "UNDERLAY_XXX" and/or "OVERLAY_XXX").
1241 * The test is to be terminated using a call to
1242 * "GNUNET_SCHEDULER_shutdown". If starting the test fails,
1243 * the program is stopped without 'master' ever being run.
1245 * NOTE: this function should be called from 'main', NOT from
1246 * within a GNUNET_SCHEDULER-loop. This function will initialze
1247 * the scheduler loop, the testbed and then pass control to
1250 * @param testname name of the testcase (to configure logging, etc.)
1251 * @param cfg_filename configuration filename to use
1252 * (for testbed, controller and peers)
1253 * @param num_peers number of peers to start; should be greter than 0
1254 * @param event_mask bit mask with set of events to call 'cc' for;
1255 * or-ed values of "1LL" shifted by the
1256 * respective 'enum GNUNET_TESTBED_EventType'
1257 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1258 * @param cc controller callback to invoke on events; This callback is called
1259 * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1260 * set in the event_mask as this is the only way get access to the
1261 * handle of each peer
1262 * @param cc_cls closure for cc
1263 * @param test_master task to run once the test is ready
1264 * @param test_master_cls closure for 'task'.
1267 GNUNET_TESTBED_test_run (const char *testname,
1268 const char *cfg_filename,
1269 unsigned int num_peers,
1270 uint64_t event_mask,
1271 GNUNET_TESTBED_ControllerCallback cc,
1273 GNUNET_TESTBED_TestMaster test_master,
1274 void *test_master_cls);
1277 #if 0 /* keep Emacsens' auto-indent happy */