2 This file is part of GNUnet
3 (C) 2008, 2009, 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_testbed_service.h
23 * @brief API for writing tests and creating large-scale
24 * emulation testbeds for GNUnet.
25 * @author Christian Grothoff
28 #ifndef GNUNET_TESTBED_SERVICE_H
29 #define GNUNET_TESTBED_SERVICE_H
31 #include "gnunet_util_lib.h"
32 #include "gnunet_testing_lib-new.h"
37 #if 0 /* keep Emacsens' auto-indent happy */
44 * Opaque handle to a host running experiments managed by the testbed framework.
45 * The master process must be able to SSH to this host without password (via
48 struct GNUNET_TESTBED_Host;
51 * Opaque handle to a peer controlled by the testbed framework. A peer runs
52 * at a particular host.
54 struct GNUNET_TESTBED_Peer;
57 * Opaque handle to an abstract operation to be executed by the testbed framework.
59 struct GNUNET_TESTBED_Operation;
62 * Handle to interact with a GNUnet testbed controller. Each
63 * controller has at least one master handle which is created when the
64 * controller is created; this master handle interacts with the
65 * controller process, destroying it destroys the controller (by
66 * closing stdin of the controller process). Additionally,
67 * controllers can interact with each other (in a P2P fashion); those
68 * links are established via TCP/IP on the controller's service port.
70 struct GNUNET_TESTBED_Controller;
73 * Handle to a large-scale testbed that is managed at a high level.
75 struct GNUNET_TESTBED_Testbed;
79 * Create a host to run peers and controllers on.
81 * @param hostname name of the host, use "NULL" for localhost
82 * @param username username to use for the login; may be NULL
83 * @param port port number to use for ssh; use 0 to let ssh decide
84 * @return handle to the host, NULL on error
86 struct GNUNET_TESTBED_Host *
87 GNUNET_TESTBED_host_create (const char *hostname,
94 * Create a host to run peers and controllers on. This function is used
95 * if a peer learns about a host via IPC between controllers (and thus
96 * some higher-level controller has already determined the unique IDs).
98 * @param id global host ID assigned to the host; 0 is
99 * reserved to always mean 'localhost'
100 * @param hostname name of the host, use "NULL" for localhost
101 * @param username username to use for the login; may be NULL
102 * @param port port number to use for ssh; use 0 to let ssh decide
103 * @return handle to the host, NULL on error
105 struct GNUNET_TESTBED_Host *
106 GNUNET_TESTBED_host_create_with_id (uint32_t id,
107 const char *hostname,
108 const char *username,
113 * Load a set of hosts from a configuration file.
115 * @param filename file with the host specification
116 * @param hosts set to the hosts found in the file; caller must free this if
117 * number of hosts returned is greater than 0
118 * @return number of hosts returned in 'hosts', 0 on error
121 GNUNET_TESTBED_hosts_load_from_file (const char *filename,
122 struct GNUNET_TESTBED_Host ***hosts);
126 * Destroy a host handle. Must only be called once everything
127 * running on that host has been stopped.
129 * @param host handle to destroy
132 GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host);
136 * Checks whether a host can be used to start testbed service
138 * @param host the host to check
139 * @return GNUNET_YES if testbed service can be started on the given host
140 * remotely; GNUNET_NO if not
143 GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host);
147 * Obtain the host's hostname.
149 * @param host handle to the host, NULL means 'localhost'
150 * @return hostname of the host
153 GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host);
157 * Enumeration with (at most 64) possible event types that
158 * can be monitored using the testbed framework.
160 enum GNUNET_TESTBED_EventType
163 * A peer has been started.
165 GNUNET_TESTBED_ET_PEER_START = 0,
168 * A peer has been stopped.
170 GNUNET_TESTBED_ET_PEER_STOP = 1,
173 * A connection between two peers was established.
175 GNUNET_TESTBED_ET_CONNECT = 2,
178 * A connection between two peers was torn down.
180 GNUNET_TESTBED_ET_DISCONNECT = 3,
183 * A requested testbed operation has been completed.
185 GNUNET_TESTBED_ET_OPERATION_FINISHED = 4,
188 * The 'GNUNET_TESTBED_run' operation has been completed
190 GNUNET_TESTBED_ET_TESTBED_ONLINE = 5
196 * Types of information that can be requested about a peer.
198 enum GNUNET_TESTBED_PeerInformationType
202 * Special value (not valid for requesting information)
203 * that is used in the event struct if a 'generic' pointer
204 * is returned (for other operations not related to this
207 GNUNET_TESTBED_PIT_GENERIC = 0,
210 * What configuration is the peer using? Returns a 'const struct
211 * GNUNET_CONFIGURATION_Handle *'. Valid until
212 * 'GNUNET_TESTNIG_operation_done' is called. However, the
213 * values may be inaccurate if the peer is reconfigured in
216 GNUNET_TESTBED_PIT_CONFIGURATION,
219 * What is the identity of the peer? Returns a
220 * 'const struct GNUNET_PeerIdentity *'. Valid until
221 * 'GNUNET_TESTNIG_operation_done' is called.
223 GNUNET_TESTBED_PIT_IDENTITY
229 * Argument to GNUNET_TESTBED_ControllerCallback with details about
232 struct GNUNET_TESTBED_EventInformation
238 enum GNUNET_TESTBED_EventType type;
241 * Details about the event.
247 * Details about peer start event.
252 * Handle for the host where the peer
255 struct GNUNET_TESTBED_Host *host;
258 * Handle for the peer that was started.
260 struct GNUNET_TESTBED_Peer *peer;
265 * Details about peer stop event.
271 * Handle for the peer that was started.
273 struct GNUNET_TESTBED_Peer *peer;
278 * Details about connect event.
283 * Handle for one of the connected peers.
285 struct GNUNET_TESTBED_Peer *peer1;
288 * Handle for one of the connected peers.
290 struct GNUNET_TESTBED_Peer *peer2;
295 * Details about disconnect event.
300 * Handle for one of the disconnected peers.
302 struct GNUNET_TESTBED_Peer *peer1;
305 * Handle for one of the disconnected peers.
307 struct GNUNET_TESTBED_Peer *peer2;
312 * Details about an operation finished event.
318 * Handle for the operation that was finished.
320 struct GNUNET_TESTBED_Operation *operation;
323 * Closure that was passed in when the event was
329 * Error message for the operation, NULL on success.
334 * No result (NULL pointer) or generic result
335 * (whatever the GNUNET_TESTBED_ConnectAdapter returned).
339 } operation_finished;
342 * Details about an testbed run completed event.
348 * Error message for the operation, NULL on success.
353 * Array of peers now running (valid until
354 * 'GNUNET_TESTBED_testbed_stop' is called). Note that it is
355 * not allowed to call 'GNUNET_TESTBED_peer_destroy' on peers
358 struct GNUNET_TESTBED_Peer **peers;
361 * Size of the 'peers' array.
363 unsigned int num_peers;
365 } testbed_run_finished;
373 * Signature of the event handler function called by the
374 * respective event controller.
377 * @param event information about the event
379 typedef void (*GNUNET_TESTBED_ControllerCallback)(void *cls,
380 const struct GNUNET_TESTBED_EventInformation *event);
384 * Opaque Handle for Controller process
386 struct GNUNET_TESTBED_ControllerProc;
390 * Callback to signal successfull startup of the controller process
392 * @param cls the closure from GNUNET_TESTBED_controller_start()
393 * @param cfg the configuration with which the controller has been started;
394 * NULL if status is not GNUNET_OK
395 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
396 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
398 typedef void (*GNUNET_TESTBED_ControllerStatusCallback) (void *cls,
399 const struct GNUNET_CONFIGURATION_Handle *cfg,
404 * Starts a controller process at the host.
406 * @param controller_ip the ip address of the controller. Will be set as TRUSTED
407 * host when starting testbed controller at host
408 * @param host the host where the controller has to be started; NULL for
410 * @param cfg template configuration to use for the remote controller; the
411 * remote controller will be started with a slightly modified
412 * configuration (port numbers, unix domain sockets and service home
413 * values are changed as per TESTING library on the remote host)
414 * @param cb function called when the controller is successfully started or
415 * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
416 * called if cb is called with GNUNET_SYSERR as status. Will never be
417 * called in the same task as 'GNUNET_TESTBED_controller_start'
418 * (synchronous errors will be signalled by returning NULL). This
419 * parameter cannot be NULL.
420 * @param cls closure for above callbacks
421 * @return the controller process handle, NULL on errors
423 struct GNUNET_TESTBED_ControllerProc *
424 GNUNET_TESTBED_controller_start (const char *controller_ip,
425 struct GNUNET_TESTBED_Host *host,
426 const struct GNUNET_CONFIGURATION_Handle *cfg,
427 GNUNET_TESTBED_ControllerStatusCallback cb,
432 * Stop the controller process (also will terminate all peers and controllers
433 * dependent on this controller). This function blocks until the testbed has
434 * been fully terminated (!). The controller status cb from
435 * GNUNET_TESTBED_controller_start() will not be called.
437 * @param cproc the controller process handle
440 GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc);
444 * Connect to a controller process using the given configuration at the
447 * @param cfg configuration to use
448 * @param host host to run the controller on; This should be the same host if
449 * the controller was previously started with
450 * GNUNET_TESTBED_controller_start; NULL for localhost
451 * @param host host where this controller is being run;
452 * @param event_mask bit mask with set of events to call 'cc' for;
453 * or-ed values of "1LL" shifted by the
454 * respective 'enum GNUNET_TESTBED_EventType'
455 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) | ...")
456 * @param cc controller callback to invoke on events
457 * @param cc_cls closure for cc
458 * @return handle to the controller
460 struct GNUNET_TESTBED_Controller *
461 GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
462 struct GNUNET_TESTBED_Host *host,
464 GNUNET_TESTBED_ControllerCallback cc,
469 * Configure shared services at a controller. Using this function,
470 * you can specify that certain services (such as "resolver")
471 * should not be run for each peer but instead be shared
472 * across N peers on the specified host. This function
473 * must be called before any peers are created at the host.
475 * @param controller controller to configure
476 * @param service_name name of the service to share
477 * @param num_peers number of peers that should share one instance
478 * of the specified service (1 for no sharing is the default),
479 * use 0 to disable the service
482 GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller *controller,
483 const char *service_name,
488 * Stop the given controller (also will terminate all peers and
489 * controllers dependent on this controller). This function
490 * blocks until the testbed has been fully terminated (!).
492 * @param controller handle to controller to stop
495 GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *controller);
499 * Opaque handle for host registration
501 struct GNUNET_TESTBED_HostRegistrationHandle;
505 * Callback which will be called to after a host registration succeeded or failed
507 * @param cls the closure
508 * @param emsg the error message; NULL if host registration is successful
510 typedef void (* GNUNET_TESTBED_HostRegistrationCompletion) (void *cls,
515 * Register a host with the controller
517 * @param controller the controller handle
518 * @param host the host to register
519 * @param cc the completion callback to call to inform the status of
520 * registration. After calling this callback the registration handle
521 * will be invalid. Cannot be NULL
522 * @param cc_cls the closure for the cc
523 * @return handle to the host registration which can be used to cancel the
524 * registration; NULL if another registration handle is present and
527 struct GNUNET_TESTBED_HostRegistrationHandle *
528 GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
529 struct GNUNET_TESTBED_Host *host,
530 GNUNET_TESTBED_HostRegistrationCompletion cc,
535 * Cancel the pending registration. Note that the registration message will
536 * already be queued to be sent to the service, cancellation has only the
537 * effect that the registration completion callback for the registration is
538 * never called and from our perspective the host is not registered until the
539 * completion callback is called.
541 * @param handle the registration handle to cancel
544 GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
549 * Callback to be called when an operation is completed
551 * @param cls the callback closure from functions generating an operation
552 * @param op the operation that has been finished
553 * @param emsg error message in case the operation has failed; will be NULL if
554 * operation has executed successfully.
556 typedef void (*GNUNET_TESTBED_OperationCompletionCallback) (void *cls,
558 GNUNET_TESTBED_Operation
564 * Create a link from slave controller to delegated controller. Whenever the
565 * master controller is asked to start a peer at the delegated controller the
566 * request will be routed towards slave controller (if a route exists). The
567 * slave controller will then route it to the delegated controller. The
568 * configuration of the delegated controller is given and is used to either
569 * create the delegated controller or to connect to an existing controller. Note
570 * that while starting the delegated controller the configuration will be
571 * modified to accommodate available free ports. the 'is_subordinate' specifies
572 * if the given delegated controller should be started and managed by the slave
573 * controller, or if the delegated controller already has a master and the slave
574 * controller connects to it as a non master controller. The success or failure
575 * of this operation will be signalled through the
576 * GNUNET_TESTBED_ControllerCallback() with an event of type
577 * GNUNET_TESTBED_ET_OPERATION_FINISHED
579 * @param op_cls the operation closure for the event which is generated to
580 * signal success or failure of this operation
581 * @param master handle to the master controller who creates the association
582 * @param delegated_host requests to which host should be delegated; cannot be NULL
583 * @param slave_host which host is used to run the slave controller; use NULL to
584 * make the master controller connect to the delegated host
585 * @param slave_cfg configuration to use for the slave controller
586 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
587 * be started by the slave controller; GNUNET_NO if the slave
588 * controller has to connect to the already started delegated
589 * controller via TCP/IP
590 * @return the operation handle
592 struct GNUNET_TESTBED_Operation *
593 GNUNET_TESTBED_controller_link (void *op_cls,
594 struct GNUNET_TESTBED_Controller *master,
595 struct GNUNET_TESTBED_Host *delegated_host,
596 struct GNUNET_TESTBED_Host *slave_host,
597 const struct GNUNET_CONFIGURATION_Handle
603 * Same as the GNUNET_TESTBED_controller_link, however expects configuration in
604 * serialized and compressed
606 * @param op_cls the operation closure for the event which is generated to
607 * signal success or failure of this operation
608 * @param master handle to the master controller who creates the association
609 * @param delegated_host requests to which host should be delegated; cannot be NULL
610 * @param slave_host which host is used to run the slave controller; use NULL to
611 * make the master controller connect to the delegated host
612 * @param sxcfg serialized and compressed configuration
613 * @param sxcfg_size the size sxcfg
614 * @param scfg_size the size of uncompressed serialized configuration
615 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
616 * be started by the slave controller; GNUNET_NO if the slave
617 * controller has to connect to the already started delegated
618 * controller via TCP/IP
619 * @return the operation handle
621 struct GNUNET_TESTBED_Operation *
622 GNUNET_TESTBED_controller_link_2 (void *op_cls,
623 struct GNUNET_TESTBED_Controller *master,
624 struct GNUNET_TESTBED_Host *delegated_host,
625 struct GNUNET_TESTBED_Host *slave_host,
633 * Function to acquire the configuration of a running slave controller. The
634 * completion of the operation is signalled through the controller_cb from
635 * GNUNET_TESTBED_controller_connect(). If the operation is successful the
636 * handle to the configuration is available in the generic pointer of
637 * operation_finished field of struct GNUNET_TESTBED_EventInformation.
639 * @param op_cls the closure for the operation
640 * @param master the handle to master controller
641 * @param slave_host the host where the slave controller is running; the handle
642 * to the slave_host should remain valid until this operation is
643 * cancelled or marked as finished
644 * @return the operation handle; NULL if the slave_host is not registered at
647 struct GNUNET_TESTBED_Operation *
648 GNUNET_TESTBED_get_slave_config (void *op_cls,
649 struct GNUNET_TESTBED_Controller *master,
650 struct GNUNET_TESTBED_Host *slave_host);
654 * Functions of this signature are called when a peer has been successfully
657 * @param cls the closure from GNUNET_TESTBED_peer_create()
658 * @param peer the handle for the created peer; NULL on any error during
660 * @param emsg NULL if peer is not NULL; else MAY contain the error description
662 typedef void (*GNUNET_TESTBED_PeerCreateCallback) (void *cls,
663 struct GNUNET_TESTBED_Peer *peer,
668 * Create the given peer at the specified host using the given
669 * controller. If the given controller is not running on the target
670 * host, it should find or create a controller at the target host and
671 * delegate creating the peer. Explicit delegation paths can be setup
672 * using 'GNUNET_TESTBED_controller_link'. If no explicit delegation
673 * path exists, a direct link with a subordinate controller is setup
674 * for the first delegated peer to a particular host; the subordinate
675 * controller is then destroyed once the last peer that was delegated
676 * to the remote host is stopped.
678 * Creating the peer only creates the handle to manipulate and further
679 * configure the peer; use "GNUNET_TESTBED_peer_start" and
680 * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's
683 * Note that the given configuration will be adjusted by the
684 * controller to avoid port/path conflicts with other peers.
685 * The "final" configuration can be obtained using
686 * 'GNUNET_TESTBED_peer_get_information'.
688 * @param controller controller process to use
689 * @param host host to run the peer on
690 * @param cfg Template configuration to use for the peer. Should exist until
691 * operation is cancelled or GNUNET_TESTBED_operation_done() is called
692 * @param cb the callback to call when the peer has been created
693 * @param cls the closure to the above callback
694 * @return the operation handle
696 struct GNUNET_TESTBED_Operation *
697 GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
698 struct GNUNET_TESTBED_Host *host,
699 const struct GNUNET_CONFIGURATION_Handle *cfg,
700 GNUNET_TESTBED_PeerCreateCallback cb,
705 * Functions of this signature are called when a peer has been successfully
706 * started or stopped.
708 * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
709 * @param emsg NULL on success; otherwise an error description
711 typedef void (*GNUNET_TESTBED_PeerChurnCallback) (void *cls,
716 * Start the given peer.
718 * @param op_cls the closure for this operation; will be set in
719 * event->details.operation_finished.op_cls when this operation fails.
720 * @param peer peer to start
721 * @param pcc function to call upon completion
722 * @param pcc_cls closure for 'pcc'
723 * @return handle to the operation
725 struct GNUNET_TESTBED_Operation *
726 GNUNET_TESTBED_peer_start (void *op_cls,
727 struct GNUNET_TESTBED_Peer *peer,
728 GNUNET_TESTBED_PeerChurnCallback pcc,
733 * Stop the given peer. The handle remains valid (use
734 * "GNUNET_TESTBED_peer_destroy" to fully clean up the
735 * state of the peer).
737 * @param peer peer to stop
738 * @param pcc function to call upon completion
739 * @param pcc_cls closure for 'pcc'
740 * @return handle to the operation
742 struct GNUNET_TESTBED_Operation *
743 GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer,
744 GNUNET_TESTBED_PeerChurnCallback pcc,
749 * Data returned from GNUNET_TESTBED_peer_get_information
751 struct GNUNET_TESTBED_PeerInformation
754 * Peer information type; captures which of the types
755 * in the 'op_result' is actually in use.
757 enum GNUNET_TESTBED_PeerInformationType pit;
760 * The result of the get information operation; Choose according to the pit
765 * The configuration of the peer
767 struct GNUNET_CONFIGURATION_Handle *cfg;
770 * The identity of the peer
772 struct GNUNET_PeerIdentity *id;
778 * Callback to be called when the requested peer information is available
780 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
781 * @param op the operation this callback corresponds to
782 * @param pinfo the result; will be NULL if the operation has failed
783 * @param emsg error message if the operation has failed; will be NULL if the
784 * operation is successfull
786 typedef void (*GNUNET_TESTBED_PeerInfoCallback) (void *cb_cls,
787 struct GNUNET_TESTBED_Operation
790 GNUNET_TESTBED_PeerInformation
796 * Request information about a peer. The controller callback will not be called
797 * with event type GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this
798 * operation is available. Instead, the GNUNET_TESTBED_PeerInfoCallback() will
801 * @param peer peer to request information about
802 * @param pit desired information
803 * @param cb the convenience callback to be called when results for this
804 * operation are available
805 * @param cb_cls the closure for the above callback
806 * @return handle to the operation
808 struct GNUNET_TESTBED_Operation *
809 GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
810 enum GNUNET_TESTBED_PeerInformationType
812 GNUNET_TESTBED_PeerInfoCallback cb,
817 * Change peer configuration. Must only be called while the
818 * peer is stopped. Ports and paths cannot be changed this
821 * @param peer peer to change configuration for
822 * @param cfg new configuration (differences to existing
823 * configuration only)
824 * @return handle to the operation
826 struct GNUNET_TESTBED_Operation *
827 GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
828 const struct GNUNET_CONFIGURATION_Handle *cfg);
832 * Destroy the given peer; the peer should have been
833 * stopped first (if it was started).
835 * @param peer peer to stop
836 * @return handle to the operation
838 struct GNUNET_TESTBED_Operation *
839 GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer);
843 * Options for peer connections.
845 enum GNUNET_TESTBED_ConnectOption
848 * No option (not valid as an argument).
850 GNUNET_TESTBED_CO_NONE = 0,
853 * Allow or disallow a connection between the specified peers.
854 * Followed by GNUNET_NO (int) if a connection is disallowed
855 * or GNUNET_YES if a connection is allowed. Note that the
856 * default (all connections allowed or disallowed) is
857 * specified in the configuration of the controller.
859 GNUNET_TESTBED_CO_ALLOW = 1,
862 * FIXME: add (and implement) options to limit connection to
863 * particular transports, force simulation of particular latencies
864 * or message loss rates, or set bandwidth limitations.
871 * Manipulate the P2P underlay topology by configuring a link
874 * @param op_cls closure argument to give with the operation event
875 * @param p1 first peer
876 * @param p2 second peer
877 * @param co option to change
878 * @param ap option-specific values
879 * @return handle to the operation, NULL if configuring the link at this
880 * time is not allowed
882 struct GNUNET_TESTBED_Operation *
883 GNUNET_TESTBED_underlay_configure_link_va (void *op_cls,
884 struct GNUNET_TESTBED_Peer *p1,
885 struct GNUNET_TESTBED_Peer *p2,
886 enum GNUNET_TESTBED_ConnectOption co,
891 * Manipulate the P2P underlay topology by configuring a link
894 * @param op_cls closure argument to give with the operation event
895 * @param p1 first peer
896 * @param p2 second peer
897 * @param co option to change
898 * @param ... option-specific values
899 * @return handle to the operation, NULL if configuring the link at this
900 * time is not allowed
902 struct GNUNET_TESTBED_Operation *
903 GNUNET_TESTBED_underlay_configure_link (void *op_cls,
904 struct GNUNET_TESTBED_Peer *p1,
905 struct GNUNET_TESTBED_Peer *p2,
906 enum GNUNET_TESTBED_ConnectOption co, ...);
911 * Topologies and topology options supported for testbeds. Options should always
912 * end with GNUNET_TESTBED_TOPOLOGY_OPTION_END
914 enum GNUNET_TESTBED_TopologyOption
917 * A clique (everyone connected to everyone else). No options. If there are N
918 * peers this topology results in (N * (N -1)) connections.
920 GNUNET_TESTBED_TOPOLOGY_CLIQUE,
923 * Small-world network (2d torus plus random links). Followed
924 * by the number of random links to add (unsigned int).
926 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD,
929 * Small-world network (ring plus random links). Followed
930 * by the number of random links to add (unsigned int).
932 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING,
935 * Ring topology. No options.
937 GNUNET_TESTBED_TOPOLOGY_RING,
940 * 2-d torus. No options.
942 GNUNET_TESTBED_TOPOLOGY_2D_TORUS,
945 * Random graph. Followed by the number of random links to be established
948 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
951 * Certain percentage of peers are unable to communicate directly
952 * replicating NAT conditions. Followed by the fraction of
953 * NAT'ed peers (float).
955 GNUNET_TESTBED_TOPOLOGY_INTERNAT,
958 * Scale free topology. FIXME: options?
960 GNUNET_TESTBED_TOPOLOGY_SCALE_FREE,
963 * Straight line topology. No options.
965 GNUNET_TESTBED_TOPOLOGY_LINE,
968 * All peers are disconnected. No options.
970 GNUNET_TESTBED_TOPOLOGY_NONE,
973 * Read a topology from a given file. Followed by the name of the file (const char *).
975 GNUNET_TESTBED_TOPOLOGY_FROM_FILE,
978 * The options should always end with this
980 GNUNET_TESTBED_TOPOLOGY_OPTION_END,
982 /* The following are not topologies but influence how the topology has to be
983 setup. These options should follow the topology specific options (if
984 required by the chosen topology). Note that these should be given before
985 GNUNET_TESTBED_TOPOLOGY_OPTION_END */
988 * Disable automatic retrying for failed overlay connections. The default is
989 * to always retry failed overlay connections. This parameter takes no options.
991 GNUNET_TESTBED_TOPOLOGY_DISABLE_AUTO_RETRY
996 * Configure overall network topology to have a particular shape.
998 * @param op_cls closure argument to give with the operation event
999 * @param num_peers number of peers in 'peers'
1000 * @param peers array of 'num_peers' with the peers to configure
1001 * @param topo desired underlay topology to use
1002 * @param ap topology-specific options
1003 * @return handle to the operation, NULL if configuring the topology
1004 * is not allowed at this time
1006 struct GNUNET_TESTBED_Operation *
1007 GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
1008 unsigned int num_peers,
1009 struct GNUNET_TESTBED_Peer **peers,
1010 enum GNUNET_TESTBED_TopologyOption topo,
1015 * Configure overall network topology to have a particular shape.
1017 * @param op_cls closure argument to give with the operation event
1018 * @param num_peers number of peers in 'peers'
1019 * @param peers array of 'num_peers' with the peers to configure
1020 * @param topo desired underlay topology to use
1021 * @param ... topology-specific options
1022 * @return handle to the operation, NULL if configuring the topology
1023 * is not allowed at this time
1025 struct GNUNET_TESTBED_Operation *
1026 GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
1027 unsigned int num_peers,
1028 struct GNUNET_TESTBED_Peer **peers,
1029 enum GNUNET_TESTBED_TopologyOption topo,
1034 * Both peers must have been started before calling this function.
1035 * This function then obtains a HELLO from 'p1', gives it to 'p2'
1036 * and asks 'p2' to connect to 'p1'.
1038 * @param op_cls closure argument to give with the operation event
1039 * @param cb the callback to call when this operation has finished
1040 * @param cb_cls the closure for the above callback
1041 * @param p1 first peer
1042 * @param p2 second peer
1043 * @return handle to the operation, NULL if connecting these two
1044 * peers is fundamentally not possible at this time (peers
1045 * not running or underlay disallows)
1047 struct GNUNET_TESTBED_Operation *
1048 GNUNET_TESTBED_overlay_connect (void *op_cls,
1049 GNUNET_TESTBED_OperationCompletionCallback cb,
1051 struct GNUNET_TESTBED_Peer *p1,
1052 struct GNUNET_TESTBED_Peer *p2);
1056 * All peers must have been started before calling this function.
1057 * This function then connects the given peers in the P2P overlay
1058 * using the given topology.
1060 * @param op_cls closure argument to give with the operation event
1061 * @param num_peers number of peers in 'peers'
1062 * @param peers array of 'num_peers' with the peers to configure
1063 * @param topo desired underlay topology to use
1064 * @param va topology-specific options
1065 * @return handle to the operation, NULL if connecting these
1066 * peers is fundamentally not possible at this time (peers
1067 * not running or underlay disallows) or if num_peers is less than 2
1069 struct GNUNET_TESTBED_Operation *
1070 GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
1071 unsigned int num_peers,
1072 struct GNUNET_TESTBED_Peer **peers,
1073 enum GNUNET_TESTBED_TopologyOption topo,
1078 * All peers must have been started before calling this function.
1079 * This function then connects the given peers in the P2P overlay
1080 * using the given topology.
1082 * @param op_cls closure argument to give with the operation event
1083 * @param num_peers number of peers in 'peers'
1084 * @param peers array of 'num_peers' with the peers to configure
1085 * @param topo desired underlay topology to use
1086 * @param ... topology-specific options
1087 * @return handle to the operation, NULL if connecting these
1088 * peers is fundamentally not possible at this time (peers
1089 * not running or underlay disallows) or if num_peers is less than 2
1091 struct GNUNET_TESTBED_Operation *
1092 GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
1093 unsigned int num_peers,
1094 struct GNUNET_TESTBED_Peer **peers,
1095 enum GNUNET_TESTBED_TopologyOption topo,
1100 * Ask the testbed controller to write the current overlay topology to
1101 * a file. Naturally, the file will only contain a snapshot as the
1102 * topology may evolve all the time.
1103 * FIXME: needs continuation!?
1105 * @param controller overlay controller to inspect
1106 * @param filename name of the file the topology should
1110 GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller *controller,
1111 const char *filename);
1115 * Adapter function called to establish a connection to
1118 * @param cls closure
1119 * @param cfg configuration of the peer to connect to; will be available until
1120 * GNUNET_TESTBED_operation_done() is called on the operation returned
1121 * from GNUNET_TESTBED_service_connect()
1122 * @return service handle to return in 'op_result', NULL on error
1124 typedef void * (*GNUNET_TESTBED_ConnectAdapter)(void *cls,
1125 const struct GNUNET_CONFIGURATION_Handle *cfg);
1129 * Adapter function called to destroy a connection to
1132 * @param cls closure
1133 * @param op_result service handle returned from the connect adapter
1135 typedef void (*GNUNET_TESTBED_DisconnectAdapter)(void *cls,
1140 * Callback to be called when a service connect operation is completed
1142 * @param cls the callback closure from functions generating an operation
1143 * @param op the operation that has been finished
1144 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
1145 * @param emsg error message in case the operation has failed; will be NULL if
1146 * operation has executed successfully.
1148 typedef void (*GNUNET_TESTBED_ServiceConnectCompletionCallback) (void *cls,
1150 GNUNET_TESTBED_Operation
1159 * Connect to a service offered by the given peer. Will ensure that
1160 * the request is queued to not overwhelm our ability to create and
1161 * maintain connections with other systems. The actual service
1162 * handle is then returned via the 'op_result' member in the event
1163 * callback. The 'ca' callback is used to create the connection
1164 * when the time is right; the 'da' callback will be used to
1165 * destroy the connection (upon 'GNUNET_TESTBED_operation_done').
1166 * 'GNUNET_TESTBED_operation_cancel' can be used to abort this
1167 * operation until the event callback has been called.
1169 * @param op_cls closure to pass in operation event
1170 * @param peer peer that runs the service
1171 * @param service_name name of the service to connect to
1172 * @param cb the callback to call when this operation finishes
1173 * @param cb_cls closure for the above callback
1174 * @param ca helper function to establish the connection
1175 * @param da helper function to close the connection
1176 * @param cada_cls closure for ca and da
1177 * @return handle for the operation
1179 struct GNUNET_TESTBED_Operation *
1180 GNUNET_TESTBED_service_connect (void *op_cls,
1181 struct GNUNET_TESTBED_Peer *peer,
1182 const char *service_name,
1183 GNUNET_TESTBED_ServiceConnectCompletionCallback cb,
1185 GNUNET_TESTBED_ConnectAdapter ca,
1186 GNUNET_TESTBED_DisconnectAdapter da,
1191 * This function is used to signal that the event information (struct
1192 * GNUNET_TESTBED_EventInformation) from an operation has been fully processed
1193 * i.e. if the event callback is ever called for this operation. If the event
1194 * callback for this operation has not yet been called, calling this function
1195 * cancels the operation, frees its resources and ensures the no event is
1196 * generated with respect to this operation. Note that however cancelling an
1197 * operation does NOT guarantee that the operation will be fully undone (or that
1198 * nothing ever happened).
1200 * This function MUST be called for every operation to fully remove the
1201 * operation from the operation queue. After calling this function, if
1202 * operation is completed and its event information is of type
1203 * GNUNET_TESTBED_ET_OPERATION_FINISHED, the 'op_result' becomes invalid (!).
1205 * If the operation is generated from GNUNET_TESTBED_service_connect() then
1206 * calling this function on such as operation calls the disconnect adapter if
1207 * the connect adapter was ever called.
1209 * @param operation operation to signal completion or cancellation
1212 GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation);
1216 * Configure and run a testbed using the given
1217 * master controller on 'num_hosts' starting
1218 * 'num_peers' using the given peer configuration.
1220 * @param controller master controller for the testbed
1221 * (must not be destroyed until after the
1222 * testbed is destroyed).
1223 * @param num_hosts number of hosts in 'hosts', 0 to only
1225 * @param hosts list of hosts to use for the testbed
1226 * @param num_peers number of peers to start
1227 * @param peer_cfg peer configuration template to use
1228 * @param underlay_topology underlay topology to create
1229 * @param va topology-specific options
1230 * @return handle to the testbed
1232 struct GNUNET_TESTBED_Testbed *
1233 GNUNET_TESTBED_create_va (struct GNUNET_TESTBED_Controller *controller,
1234 unsigned int num_hosts,
1235 struct GNUNET_TESTBED_Host **hosts,
1236 unsigned int num_peers,
1237 const struct GNUNET_CONFIGURATION_Handle *peer_cfg,
1238 enum GNUNET_TESTBED_TopologyOption underlay_topology,
1243 * Configure and run a testbed using the given
1244 * master controller on 'num_hosts' starting
1245 * 'num_peers' using the given peer configuration.
1247 * @param controller master controller for the testbed
1248 * (must not be destroyed until after the
1249 * testbed is destroyed).
1250 * @param num_hosts number of hosts in 'hosts', 0 to only
1252 * @param hosts list of hosts to use for the testbed
1253 * @param num_peers number of peers to start
1254 * @param peer_cfg peer configuration template to use
1255 * @param underlay_topology underlay topology to create
1256 * @param ... topology-specific options
1258 struct GNUNET_TESTBED_Testbed *
1259 GNUNET_TESTBED_create (struct GNUNET_TESTBED_Controller *controller,
1260 unsigned int num_hosts,
1261 struct GNUNET_TESTBED_Host **hosts,
1262 unsigned int num_peers,
1263 const struct GNUNET_CONFIGURATION_Handle *peer_cfg,
1264 enum GNUNET_TESTBED_TopologyOption underlay_topology,
1269 * Destroy a testbed. Stops all running peers and then
1270 * destroys all peers. Does NOT destroy the master controller.
1272 * @param testbed testbed to destroy
1275 GNUNET_TESTBED_destroy (struct GNUNET_TESTBED_Testbed *testbed);
1279 * Callback function to process statistic values from all peers.
1281 * @param cls closure
1282 * @param peer the peer the statistic belong to
1283 * @param subsystem name of subsystem that created the statistic
1284 * @param name the name of the datum
1285 * @param value the current value
1286 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
1287 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
1289 typedef int (*GNUNET_TESTBED_StatisticsIterator) (void *cls,
1290 const struct GNUNET_TESTBED_Peer *peer,
1291 const char *subsystem,
1298 * Convenience method that iterates over all (running) peers
1299 * and retrieves all statistics from each peer.
1301 * @param num_peers number of peers to iterate over
1302 * @param peers array of peers to iterate over
1303 * @param proc processing function for each statistic retrieved
1304 * @param cont continuation to call once call is completed(?)
1305 * @param cls closure to pass to proc and cont
1306 * @return operation handle to cancel the operation
1308 struct GNUNET_TESTBED_Operation *
1309 GNUNET_TESTBED_get_statistics (unsigned int num_peers,
1310 struct GNUNET_TESTBED_Peer **peers,
1311 GNUNET_TESTBED_StatisticsIterator proc,
1312 GNUNET_TESTBED_OperationCompletionCallback cont,
1317 * Convenience method for running a testbed with
1318 * a single call. Underlay and overlay topology
1319 * are configured using the "UNDERLAY" and "OVERLAY"
1320 * options in the "[testbed]" section of the configuration\
1321 * (with possible options given in "UNDERLAY_XXX" and/or
1324 * The testbed is to be terminated using a call to
1325 * "GNUNET_SCHEDULER_shutdown".
1327 * @param host_filename name of the file with the 'hosts', NULL
1328 * to run everything on 'localhost'
1329 * @param cfg configuration to use (for testbed, controller and peers)
1330 * @param num_peers number of peers to start; FIXME: maybe put that ALSO into
1331 * cfg?; should be greater than 0
1332 * @param event_mask bit mask with set of events to call 'cc' for;
1333 * or-ed values of "1LL" shifted by the
1334 * respective 'enum GNUNET_TESTBED_EventType'
1335 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1336 * @param cc controller callback to invoke on events; This callback is called
1337 * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1338 * set in the event_mask as this is the only way get access to the
1339 * handle of each peer
1340 * @param cc_cls closure for cc
1341 * @param master task to run once the testbed is ready
1342 * @param master_cls closure for 'task'.
1345 GNUNET_TESTBED_run (const char *host_filename,
1346 const struct GNUNET_CONFIGURATION_Handle *cfg,
1347 unsigned int num_peers,
1348 uint64_t event_mask,
1349 GNUNET_TESTBED_ControllerCallback cc,
1351 GNUNET_SCHEDULER_Task master,
1356 * Signature of a main function for a testcase.
1358 * @param cls closure
1359 * @param num_peers number of peers in 'peers'
1360 * @param peers handle to peers run in the testbed
1362 typedef void (*GNUNET_TESTBED_TestMaster)(void *cls,
1363 unsigned int num_peers,
1364 struct GNUNET_TESTBED_Peer **peers);
1368 * Convenience method for running a "simple" test on the local system
1369 * with a single call from 'main'. Underlay and overlay topology are
1370 * configured using the "UNDERLAY" and "OVERLAY" options in the
1371 * "[testbed]" section of the configuration (with possible options
1372 * given in "UNDERLAY_XXX" and/or "OVERLAY_XXX").
1374 * The test is to be terminated using a call to
1375 * "GNUNET_SCHEDULER_shutdown". If starting the test fails,
1376 * the program is stopped without 'master' ever being run.
1378 * NOTE: this function should be called from 'main', NOT from
1379 * within a GNUNET_SCHEDULER-loop. This function will initialze
1380 * the scheduler loop, the testbed and then pass control to
1383 * @param testname name of the testcase (to configure logging, etc.)
1384 * @param cfg_filename configuration filename to use
1385 * (for testbed, controller and peers)
1386 * @param num_peers number of peers to start; should be greter than 0
1387 * @param event_mask bit mask with set of events to call 'cc' for;
1388 * or-ed values of "1LL" shifted by the
1389 * respective 'enum GNUNET_TESTBED_EventType'
1390 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1391 * @param cc controller callback to invoke on events; This callback is called
1392 * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1393 * set in the event_mask as this is the only way get access to the
1394 * handle of each peer
1395 * @param cc_cls closure for cc
1396 * @param test_master task to run once the test is ready
1397 * @param test_master_cls closure for 'task'.
1400 GNUNET_TESTBED_test_run (const char *testname,
1401 const char *cfg_filename,
1402 unsigned int num_peers,
1403 uint64_t event_mask,
1404 GNUNET_TESTBED_ControllerCallback cc,
1406 GNUNET_TESTBED_TestMaster test_master,
1407 void *test_master_cls);
1410 #if 0 /* keep Emacsens' auto-indent happy */