2 This file is part of GNUnet
3 (C) 2008--2013 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.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;
74 * Create a host to run peers and controllers on.
76 * @param hostname name of the host, use "NULL" for localhost
77 * @param username username to use for the login; may be NULL
78 * @param cfg the configuration to use as a template while starting a controller
79 * on this host. Operation queue sizes specific to a host are also
80 * read from this configuration handle
81 * @param port port number to use for ssh; use 0 to let ssh decide
82 * @return handle to the host, NULL on error
84 struct GNUNET_TESTBED_Host *
85 GNUNET_TESTBED_host_create (const char *hostname,
87 const struct GNUNET_CONFIGURATION_Handle *cfg,
93 * Create a host to run peers and controllers on. This function is used
94 * if a peer learns about a host via IPC between controllers (and thus
95 * some higher-level controller has already determined the unique IDs).
97 * @param id global host ID assigned to the host; 0 is
98 * reserved to always mean 'localhost'
99 * @param hostname name of the host, use "NULL" for localhost
100 * @param username username to use for the login; may be NULL
101 * @param cfg the configuration to use as a template while starting a controller
102 * on this host. Operation queue sizes specific to a host are also
103 * read from this configuration handle
104 * @param port port number to use for ssh; use 0 to let ssh decide
105 * @return handle to the host, NULL on error
107 struct GNUNET_TESTBED_Host *
108 GNUNET_TESTBED_host_create_with_id (uint32_t id,
109 const char *hostname,
110 const char *username,
111 const struct GNUNET_CONFIGURATION_Handle
117 * Load a set of hosts from a configuration file.
119 * @param filename file with the host specification
120 * @param cfg the configuration to use as a template while starting a controller
121 * on any of the loaded hosts. Operation queue sizes specific to a host
122 * are also read from this configuration handle
123 * @param hosts set to the hosts found in the file; caller must free this if
124 * number of hosts returned is greater than 0
125 * @return number of hosts returned in 'hosts', 0 on error
128 GNUNET_TESTBED_hosts_load_from_file (const char *filename,
129 const struct GNUNET_CONFIGURATION_Handle
131 struct GNUNET_TESTBED_Host ***hosts);
135 * Loads the set of host allocated by the LoadLeveler Job Scheduler. This
136 * function is only available when compiled with support for LoadLeveler and is
137 * used for running on the SuperMUC
139 * @param cfg the configuration to use as a template while starting a controller
140 * on any of the loaded hosts. Operation queue sizes specific to a host
141 * are also read from this configuration handle
142 * @param hosts set to the hosts found in the file; caller must free this if
143 * number of hosts returned is greater than 0
144 * @return number of hosts returned in 'hosts', 0 on error
147 GNUNET_TESTBED_hosts_load_from_loadleveler (const struct
148 GNUNET_CONFIGURATION_Handle *cfg,
149 struct GNUNET_TESTBED_Host
153 * Destroy a host handle. Must only be called once everything
154 * running on that host has been stopped.
156 * @param host handle to destroy
159 GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host);
163 * The handle for whether a host is habitable or not
165 struct GNUNET_TESTBED_HostHabitableCheckHandle;
169 * Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to
170 * inform whether the given host is habitable or not. The Handle returned by
171 * GNUNET_TESTBED_is_host_habitable() is invalid after this callback is called
173 * @param cls the closure given to GNUNET_TESTBED_is_host_habitable()
174 * @param host the host whose status is being reported; will be NULL if the host
175 * given to GNUNET_TESTBED_is_host_habitable() is NULL
176 * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
178 typedef void (*GNUNET_TESTBED_HostHabitableCallback) (void *cls,
186 * Checks whether a host can be used to start testbed service
188 * @param host the host to check
189 * @param config the configuration handle to lookup the path of the testbed
191 * @param cb the callback to call to inform about habitability of the given host
192 * @param cb_cls the closure for the callback
193 * @return NULL upon any error or a handle which can be passed to
194 * GNUNET_TESTBED_is_host_habitable_cancel()
196 struct GNUNET_TESTBED_HostHabitableCheckHandle *
197 GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host,
198 const struct GNUNET_CONFIGURATION_Handle
200 GNUNET_TESTBED_HostHabitableCallback cb,
205 * Function to cancel a request started using GNUNET_TESTBED_is_host_habitable()
207 * @param handle the habitability check handle
210 GNUNET_TESTBED_is_host_habitable_cancel (struct
211 GNUNET_TESTBED_HostHabitableCheckHandle
215 * Obtain the host's hostname.
217 * @param host handle to the host, NULL means 'localhost'
218 * @return hostname of the host
221 GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host);
225 * Enumeration with (at most 64) possible event types that
226 * can be monitored using the testbed framework.
228 enum GNUNET_TESTBED_EventType
231 * A peer has been started.
233 GNUNET_TESTBED_ET_PEER_START = 0,
236 * A peer has been stopped.
238 GNUNET_TESTBED_ET_PEER_STOP = 1,
241 * A connection between two peers was established.
243 GNUNET_TESTBED_ET_CONNECT = 2,
246 * A connection between two peers was torn down.
248 GNUNET_TESTBED_ET_DISCONNECT = 3,
251 * A requested testbed operation has been completed.
253 GNUNET_TESTBED_ET_OPERATION_FINISHED = 4,
259 * Types of information that can be requested about a peer.
261 enum GNUNET_TESTBED_PeerInformationType
265 * Special value (not valid for requesting information)
266 * that is used in the event struct if a 'generic' pointer
267 * is returned (for other operations not related to this
270 GNUNET_TESTBED_PIT_GENERIC = 0,
273 * What configuration is the peer using? Returns a 'const struct
274 * GNUNET_CONFIGURATION_Handle *'. Valid until
275 * 'GNUNET_TESTNIG_operation_done' is called. However, the
276 * values may be inaccurate if the peer is reconfigured in
279 GNUNET_TESTBED_PIT_CONFIGURATION,
282 * What is the identity of the peer? Returns a
283 * 'const struct GNUNET_PeerIdentity *'. Valid until
284 * 'GNUNET_TESTNIG_operation_done' is called.
286 GNUNET_TESTBED_PIT_IDENTITY
292 * Argument to GNUNET_TESTBED_ControllerCallback with details about
295 struct GNUNET_TESTBED_EventInformation
301 enum GNUNET_TESTBED_EventType type;
304 * Handle for the corresponding operation that generated this event
306 struct GNUNET_TESTBED_Operation *op;
309 * Closure given while creating the above operation
314 * Details about the event.
320 * Details about peer start event.
325 * Handle for the host where the peer
328 struct GNUNET_TESTBED_Host *host;
331 * Handle for the peer that was started.
333 struct GNUNET_TESTBED_Peer *peer;
338 * Details about peer stop event.
344 * Handle for the peer that was started.
346 struct GNUNET_TESTBED_Peer *peer;
351 * Details about connect event.
356 * Handle for one of the connected peers.
358 struct GNUNET_TESTBED_Peer *peer1;
361 * Handle for one of the connected peers.
363 struct GNUNET_TESTBED_Peer *peer2;
368 * Details about disconnect event.
373 * Handle for one of the disconnected peers.
375 struct GNUNET_TESTBED_Peer *peer1;
378 * Handle for one of the disconnected peers.
380 struct GNUNET_TESTBED_Peer *peer2;
385 * Details about an operation finished event.
390 * Error message for the operation, NULL on success.
395 * No result (NULL pointer) or generic result
396 * (whatever the GNUNET_TESTBED_ConnectAdapter returned).
400 } operation_finished;
408 * Signature of the event handler function called by the
409 * respective event controller.
412 * @param event information about the event
414 typedef void (*GNUNET_TESTBED_ControllerCallback)(void *cls,
415 const struct GNUNET_TESTBED_EventInformation *event);
419 * Opaque Handle for Controller process
421 struct GNUNET_TESTBED_ControllerProc;
425 * Callback to signal successfull startup of the controller process
427 * @param cls the closure from GNUNET_TESTBED_controller_start()
428 * @param cfg the configuration with which the controller has been started;
429 * NULL if status is not GNUNET_OK
430 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
431 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
433 typedef void (*GNUNET_TESTBED_ControllerStatusCallback) (void *cls,
434 const struct GNUNET_CONFIGURATION_Handle *cfg,
439 * Starts a controller process at the given host. The given host's configration
440 * is used as a Template configuration to use for the remote controller; the
441 * remote controller will be started with a slightly modified configuration
442 * (port numbers, unix domain sockets and service home values are changed as per
443 * TESTING library on the remote host). The modified configuration replaces the
444 * host's existing configuration before signalling success through the
445 * GNUNET_TESTBED_ControllerStatusCallback()
447 * @param trusted_ip the ip address of the controller which will be set as TRUSTED
448 * HOST(all connections form this ip are permitted by the testbed) when
449 * starting testbed controller at host. This can either be a single ip
450 * address or a network address in CIDR notation.
451 * @param host the host where the controller has to be started. CANNOT be NULL.
452 * @param cb function called when the controller is successfully started or
453 * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be
454 * called if cb is called with GNUNET_SYSERR as status. Will never be
455 * called in the same task as 'GNUNET_TESTBED_controller_start'
456 * (synchronous errors will be signalled by returning NULL). This
457 * parameter cannot be NULL.
458 * @param cls closure for above callbacks
459 * @return the controller process handle, NULL on errors
461 struct GNUNET_TESTBED_ControllerProc *
462 GNUNET_TESTBED_controller_start (const char *trusted_ip,
463 struct GNUNET_TESTBED_Host *host,
464 GNUNET_TESTBED_ControllerStatusCallback cb,
469 * Stop the controller process (also will terminate all peers and controllers
470 * dependent on this controller). This function blocks until the testbed has
471 * been fully terminated (!). The controller status cb from
472 * GNUNET_TESTBED_controller_start() will not be called.
474 * @param cproc the controller process handle
477 GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc);
481 * Connect to a controller process. The configuration to use for the connection
482 * is retreived from the given host where a controller is started using
483 * GNUNET_TESTBED_controller_start().
485 * @param host host to run the controller on; This should be the same host if
486 * the controller was previously started with
487 * GNUNET_TESTBED_controller_start()
488 * @param event_mask bit mask with set of events to call 'cc' for;
489 * or-ed values of "1LL" shifted by the
490 * respective 'enum GNUNET_TESTBED_EventType'
491 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) | ...")
492 * @param cc controller callback to invoke on events
493 * @param cc_cls closure for cc
494 * @return handle to the controller
496 struct GNUNET_TESTBED_Controller *
497 GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
499 GNUNET_TESTBED_ControllerCallback cc,
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 c handle to controller to stop
511 GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c);
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. This makes the controller aware of the
532 * host. A host should be registered at the controller before starting a
533 * sub-controller on that host using GNUNET_TESTBED_controller_link().
535 * @param controller the controller handle
536 * @param host the host to register
537 * @param cc the completion callback to call to inform the status of
538 * registration. After calling this callback the registration handle
539 * will be invalid. Cannot be NULL
540 * @param cc_cls the closure for the cc
541 * @return handle to the host registration which can be used to cancel the
542 * registration; NULL if another registration handle is present and
545 struct GNUNET_TESTBED_HostRegistrationHandle *
546 GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller,
547 struct GNUNET_TESTBED_Host *host,
548 GNUNET_TESTBED_HostRegistrationCompletion cc,
553 * Cancel the pending registration. Note that the registration message will
554 * already be queued to be sent to the service, cancellation has only the
555 * effect that the registration completion callback for the registration is
556 * never called and from our perspective the host is not registered until the
557 * completion callback is called.
559 * @param handle the registration handle to cancel
562 GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle
567 * Callback to be called when an operation is completed
569 * @param cls the callback closure from functions generating an operation
570 * @param op the operation that has been finished
571 * @param emsg error message in case the operation has failed; will be NULL if
572 * operation has executed successfully.
574 typedef void (*GNUNET_TESTBED_OperationCompletionCallback) (void *cls,
576 GNUNET_TESTBED_Operation
582 * Create a link from slave controller to delegated controller. Whenever the
583 * master controller is asked to start a peer at the delegated controller the
584 * request will be routed towards slave controller (if a route exists). The
585 * slave controller will then route it to the delegated controller. The
586 * configuration of the delegated controller is given and is used to either
587 * create the delegated controller or to connect to an existing controller. Note
588 * that while starting the delegated controller the configuration will be
589 * modified to accommodate available free ports. the 'is_subordinate' specifies
590 * if the given delegated controller should be started and managed by the slave
591 * controller, or if the delegated controller already has a master and the slave
592 * controller connects to it as a non master controller. The success or failure
593 * of this operation will be signalled through the
594 * GNUNET_TESTBED_ControllerCallback() with an event of type
595 * GNUNET_TESTBED_ET_OPERATION_FINISHED
597 * @param op_cls the operation closure for the event which is generated to
598 * signal success or failure of this operation
599 * @param master handle to the master controller who creates the association
600 * @param delegated_host requests to which host should be delegated; cannot be NULL
601 * @param slave_host which host is used to run the slave controller; use NULL to
602 * make the master controller connect to the delegated host
603 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
604 * be started by the slave controller; GNUNET_NO if the slave
605 * controller has to connect to the already started delegated
606 * controller via TCP/IP
607 * @return the operation handle
609 struct GNUNET_TESTBED_Operation *
610 GNUNET_TESTBED_controller_link (void *op_cls,
611 struct GNUNET_TESTBED_Controller *master,
612 struct GNUNET_TESTBED_Host *delegated_host,
613 struct GNUNET_TESTBED_Host *slave_host,
618 * Same as the GNUNET_TESTBED_controller_link, however expects configuration in
619 * serialized and compressed
621 * @param op_cls the operation closure for the event which is generated to
622 * signal success or failure of this operation
623 * @param master handle to the master controller who creates the association
624 * @param delegated_host requests to which host should be delegated; cannot be NULL
625 * @param slave_host which host is used to run the slave controller; use NULL to
626 * make the master controller connect to the delegated host
627 * @param sxcfg serialized and compressed configuration
628 * @param sxcfg_size the size sxcfg
629 * @param scfg_size the size of uncompressed serialized configuration
630 * @param is_subordinate GNUNET_YES if the controller at delegated_host should
631 * be started by the slave controller; GNUNET_NO if the slave
632 * controller has to connect to the already started delegated
633 * controller via TCP/IP
634 * @return the operation handle
636 struct GNUNET_TESTBED_Operation *
637 GNUNET_TESTBED_controller_link_2 (void *op_cls,
638 struct GNUNET_TESTBED_Controller *master,
639 struct GNUNET_TESTBED_Host *delegated_host,
640 struct GNUNET_TESTBED_Host *slave_host,
648 * Function to acquire the configuration of a running slave controller. The
649 * completion of the operation is signalled through the controller_cb from
650 * GNUNET_TESTBED_controller_connect(). If the operation is successful the
651 * handle to the configuration is available in the generic pointer of
652 * operation_finished field of struct GNUNET_TESTBED_EventInformation.
654 * @param op_cls the closure for the operation
655 * @param master the handle to master controller
656 * @param slave_host the host where the slave controller is running; the handle
657 * to the slave_host should remain valid until this operation is
658 * cancelled or marked as finished
659 * @return the operation handle; NULL if the slave_host is not registered at
662 struct GNUNET_TESTBED_Operation *
663 GNUNET_TESTBED_get_slave_config (void *op_cls,
664 struct GNUNET_TESTBED_Controller *master,
665 struct GNUNET_TESTBED_Host *slave_host);
669 * Functions of this signature are called when a peer has been successfully
672 * @param cls the closure from GNUNET_TESTBED_peer_create()
673 * @param peer the handle for the created peer; NULL on any error during
675 * @param emsg NULL if peer is not NULL; else MAY contain the error description
677 typedef void (*GNUNET_TESTBED_PeerCreateCallback) (void *cls,
678 struct GNUNET_TESTBED_Peer *peer,
683 * Create the given peer at the specified host using the given
684 * controller. If the given controller is not running on the target
685 * host, it should find or create a controller at the target host and
686 * delegate creating the peer. Explicit delegation paths can be setup
687 * using 'GNUNET_TESTBED_controller_link'. If no explicit delegation
688 * path exists, a direct link with a subordinate controller is setup
689 * for the first delegated peer to a particular host; the subordinate
690 * controller is then destroyed once the last peer that was delegated
691 * to the remote host is stopped.
693 * Creating the peer only creates the handle to manipulate and further
694 * configure the peer; use "GNUNET_TESTBED_peer_start" and
695 * "GNUNET_TESTBED_peer_stop" to actually start/stop the peer's
698 * Note that the given configuration will be adjusted by the
699 * controller to avoid port/path conflicts with other peers.
700 * The "final" configuration can be obtained using
701 * 'GNUNET_TESTBED_peer_get_information'.
703 * @param controller controller process to use
704 * @param host host to run the peer on; cannot be NULL
705 * @param cfg Template configuration to use for the peer. Should exist until
706 * operation is cancelled or GNUNET_TESTBED_operation_done() is called
707 * @param cb the callback to call when the peer has been created
708 * @param cls the closure to the above callback
709 * @return the operation handle
711 struct GNUNET_TESTBED_Operation *
712 GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
713 struct GNUNET_TESTBED_Host *host,
714 const struct GNUNET_CONFIGURATION_Handle *cfg,
715 GNUNET_TESTBED_PeerCreateCallback cb,
720 * Functions of this signature are called when a peer has been successfully
721 * started or stopped.
723 * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
724 * @param emsg NULL on success; otherwise an error description
726 typedef void (*GNUNET_TESTBED_PeerChurnCallback) (void *cls,
731 * Start the given peer.
733 * @param op_cls the closure for this operation; will be set in the event
735 * @param peer peer to start
736 * @param pcc function to call upon completion
737 * @param pcc_cls closure for 'pcc'
738 * @return handle to the operation
740 struct GNUNET_TESTBED_Operation *
741 GNUNET_TESTBED_peer_start (void *op_cls,
742 struct GNUNET_TESTBED_Peer *peer,
743 GNUNET_TESTBED_PeerChurnCallback pcc,
748 * Stop the given peer. The handle remains valid (use
749 * "GNUNET_TESTBED_peer_destroy" to fully clean up the
750 * state of the peer).
752 * @param op_cls the closure for this operation; will be set in the event
754 * @param peer peer to stop
755 * @param pcc function to call upon completion
756 * @param pcc_cls closure for 'pcc'
757 * @return handle to the operation
759 struct GNUNET_TESTBED_Operation *
760 GNUNET_TESTBED_peer_stop (void *op_cls,
761 struct GNUNET_TESTBED_Peer *peer,
762 GNUNET_TESTBED_PeerChurnCallback pcc,
767 * Data returned from GNUNET_TESTBED_peer_get_information
769 struct GNUNET_TESTBED_PeerInformation
772 * Peer information type; captures which of the types
773 * in the 'op_result' is actually in use.
775 enum GNUNET_TESTBED_PeerInformationType pit;
778 * The result of the get information operation; Choose according to the pit
783 * The configuration of the peer
785 struct GNUNET_CONFIGURATION_Handle *cfg;
788 * The identity of the peer
790 struct GNUNET_PeerIdentity *id;
796 * Callback to be called when the requested peer information is available
797 * The peer information in the callback is valid until the operation 'op' is canceled.
799 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
800 * @param op the operation this callback corresponds to
801 * @param pinfo the result; will be NULL if the operation has failed
802 * @param emsg error message if the operation has failed; will be NULL if the
803 * operation is successfull
805 typedef void (*GNUNET_TESTBED_PeerInfoCallback) (void *cb_cls,
806 struct GNUNET_TESTBED_Operation
809 GNUNET_TESTBED_PeerInformation
815 * Request information about a peer. The controller callback will not be called
816 * with event type GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this
817 * operation is available. Instead, the GNUNET_TESTBED_PeerInfoCallback() will
819 * The peer information in the callback is valid until the operation is canceled.
821 * @param peer peer to request information about
822 * @param pit desired information
823 * @param cb the convenience callback to be called when results for this
824 * operation are available
825 * @param cb_cls the closure for the above callback
826 * @return handle to the operation
828 struct GNUNET_TESTBED_Operation *
829 GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer,
830 enum GNUNET_TESTBED_PeerInformationType
832 GNUNET_TESTBED_PeerInfoCallback cb,
837 * Change peer configuration. Must only be called while the
838 * peer is stopped. Ports and paths cannot be changed this
841 * @param peer peer to change configuration for
842 * @param cfg new configuration (differences to existing
843 * configuration only)
844 * @return handle to the operation
846 struct GNUNET_TESTBED_Operation *
847 GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer,
848 const struct GNUNET_CONFIGURATION_Handle *cfg);
852 * Destroy the given peer; the peer should have been
853 * stopped first (if it was started).
855 * @param peer peer to stop
856 * @return handle to the operation
858 struct GNUNET_TESTBED_Operation *
859 GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer);
863 * Start or stop given service at a peer. This should not be called to
864 * start/stop the peer's ARM service. Use GNUNET_TESTBED_peer_start(),
865 * GNUNET_TESTBED_peer_stop() for starting/stopping peer's ARM service. Success
866 * or failure of the generated operation is signalled through the controller
867 * event callback and/or operation completion callback.
869 * @param op_cls the closure for the operation
870 * @param peer the peer whose service is to be started/stopped
871 * @param service_name the name of the service
872 * @param cb the operation completion callback
873 * @param cb_cls the closure for the operation completion callback
874 * @param start 1 to start the service; 0 to stop the service
875 * @return an operation handle; NULL upon error (peer not running)
877 struct GNUNET_TESTBED_Operation *
878 GNUNET_TESTBED_peer_manage_service (void *op_cls,
879 struct GNUNET_TESTBED_Peer *peer,
880 const char *service_name,
881 GNUNET_TESTBED_OperationCompletionCallback cb,
887 * Stops and destroys all peers. Is equivalent of calling
888 * GNUNET_TESTBED_peer_stop() and GNUNET_TESTBED_peer_destroy() on all peers,
889 * except that the peer stop event and operation finished event corresponding to
890 * the respective functions are not generated. This function should be called
891 * when there are no other pending operations. If there are pending operations,
892 * it will return NULL
894 * @param c the controller to send this message to
895 * @param op_cls closure for the operation
896 * @param cb the callback to call when all peers are stopped and destroyed
897 * @param cb_cls the closure for the callback
898 * @return operation handle on success; NULL if any pending operations are
901 struct GNUNET_TESTBED_Operation *
902 GNUNET_TESTBED_shutdown_peers (struct GNUNET_TESTBED_Controller *c,
904 GNUNET_TESTBED_OperationCompletionCallback cb,
910 * Options for peer connections.
912 enum GNUNET_TESTBED_ConnectOption
915 * No option (not valid as an argument).
917 GNUNET_TESTBED_CO_NONE = 0,
920 * Allow or disallow a connection between the specified peers.
921 * Followed by GNUNET_NO (int) if a connection is disallowed
922 * or GNUNET_YES if a connection is allowed. Note that the
923 * default (all connections allowed or disallowed) is
924 * specified in the configuration of the controller.
926 GNUNET_TESTBED_CO_ALLOW = 1,
929 * FIXME: add (and implement) options to limit connection to
930 * particular transports, force simulation of particular latencies
931 * or message loss rates, or set bandwidth limitations.
938 * Manipulate the P2P underlay topology by configuring a link
941 * @param op_cls closure argument to give with the operation event
942 * @param p1 first peer
943 * @param p2 second peer
944 * @param co option to change
945 * @param ap option-specific values
946 * @return handle to the operation, NULL if configuring the link at this
947 * time is not allowed
949 struct GNUNET_TESTBED_Operation *
950 GNUNET_TESTBED_underlay_configure_link_va (void *op_cls,
951 struct GNUNET_TESTBED_Peer *p1,
952 struct GNUNET_TESTBED_Peer *p2,
953 enum GNUNET_TESTBED_ConnectOption co,
958 * Manipulate the P2P underlay topology by configuring a link
961 * @param op_cls closure argument to give with the operation event
962 * @param p1 first peer
963 * @param p2 second peer
964 * @param co option to change
965 * @param ... option-specific values
966 * @return handle to the operation, NULL if configuring the link at this
967 * time is not allowed
969 struct GNUNET_TESTBED_Operation *
970 GNUNET_TESTBED_underlay_configure_link (void *op_cls,
971 struct GNUNET_TESTBED_Peer *p1,
972 struct GNUNET_TESTBED_Peer *p2,
973 enum GNUNET_TESTBED_ConnectOption co, ...);
978 * Topologies and topology options supported for testbeds. Options should always
979 * end with GNUNET_TESTBED_TOPOLOGY_OPTION_END
981 enum GNUNET_TESTBED_TopologyOption
984 * A clique (everyone connected to everyone else). No options. If there are N
985 * peers this topology results in (N * (N -1)) connections.
987 GNUNET_TESTBED_TOPOLOGY_CLIQUE,
990 * Small-world network (2d torus plus random links). Followed
991 * by the number of random links to add (unsigned int).
993 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD,
996 * Small-world network (ring plus random links). Followed
997 * by the number of random links to add (unsigned int).
999 GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING,
1002 * Ring topology. No options.
1004 GNUNET_TESTBED_TOPOLOGY_RING,
1007 * 2-d torus. No options.
1009 GNUNET_TESTBED_TOPOLOGY_2D_TORUS,
1012 * Random graph. Followed by the number of random links to be established
1015 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
1018 * Certain percentage of peers are unable to communicate directly
1019 * replicating NAT conditions. Followed by the fraction of
1020 * NAT'ed peers (float).
1022 GNUNET_TESTBED_TOPOLOGY_INTERNAT,
1025 * Scale free topology. No options.
1027 GNUNET_TESTBED_TOPOLOGY_SCALE_FREE,
1030 * Straight line topology. No options.
1032 GNUNET_TESTBED_TOPOLOGY_LINE,
1035 * Read a topology from a given file. Followed by the name of the file (const char *).
1037 GNUNET_TESTBED_TOPOLOGY_FROM_FILE,
1040 * All peers are disconnected. No options.
1042 GNUNET_TESTBED_TOPOLOGY_NONE,
1045 * The options should always end with this
1047 GNUNET_TESTBED_TOPOLOGY_OPTION_END,
1049 /* The following are not topologies but influence how the topology has to be
1050 setup. These options should follow the topology specific options (if
1051 required by the chosen topology). Note that these should be given before
1052 GNUNET_TESTBED_TOPOLOGY_OPTION_END */
1055 * How many times should the failed overlay connect operations be retried
1056 * before giving up. The default if this option is not specified is to retry
1057 * 3 times. This option takes and unsigned integer as a parameter. Use this
1058 * option with parameter 0 to disable retrying of failed overlay connect
1061 GNUNET_TESTBED_TOPOLOGY_RETRY_CNT
1066 * Configure overall network topology to have a particular shape.
1068 * @param op_cls closure argument to give with the operation event
1069 * @param num_peers number of peers in 'peers'
1070 * @param peers array of 'num_peers' with the peers to configure
1071 * @param topo desired underlay topology to use
1072 * @param ap topology-specific options
1073 * @return handle to the operation, NULL if configuring the topology
1074 * is not allowed at this time
1076 struct GNUNET_TESTBED_Operation *
1077 GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls,
1078 unsigned int num_peers,
1079 struct GNUNET_TESTBED_Peer **peers,
1080 enum GNUNET_TESTBED_TopologyOption topo,
1085 * Configure overall network topology to have a particular shape.
1087 * @param op_cls closure argument to give with the operation event
1088 * @param num_peers number of peers in 'peers'
1089 * @param peers array of 'num_peers' with the peers to configure
1090 * @param topo desired underlay topology to use
1091 * @param ... topology-specific options
1092 * @return handle to the operation, NULL if configuring the topology
1093 * is not allowed at this time
1095 struct GNUNET_TESTBED_Operation *
1096 GNUNET_TESTBED_underlay_configure_topology (void *op_cls,
1097 unsigned int num_peers,
1098 struct GNUNET_TESTBED_Peer **peers,
1099 enum GNUNET_TESTBED_TopologyOption topo,
1104 * Both peers must have been started before calling this function.
1105 * This function then obtains a HELLO from 'p1', gives it to 'p2'
1106 * and asks 'p2' to connect to 'p1'.
1108 * @param op_cls closure argument to give with the operation event
1109 * @param cb the callback to call when this operation has finished
1110 * @param cb_cls the closure for the above callback
1111 * @param p1 first peer
1112 * @param p2 second peer
1113 * @return handle to the operation, NULL if connecting these two
1114 * peers is fundamentally not possible at this time (peers
1115 * not running or underlay disallows)
1117 struct GNUNET_TESTBED_Operation *
1118 GNUNET_TESTBED_overlay_connect (void *op_cls,
1119 GNUNET_TESTBED_OperationCompletionCallback cb,
1121 struct GNUNET_TESTBED_Peer *p1,
1122 struct GNUNET_TESTBED_Peer *p2);
1126 * Callbacks of this type are called when topology configuration is completed
1128 * @param cls the operation closure given to
1129 * GNUNET_TESTBED_overlay_configure_topology_va() and
1130 * GNUNET_TESTBED_overlay_configure() calls
1131 * @param nsuccess the number of successful overlay connects
1132 * @param nfailures the number of overlay connects which failed
1134 typedef void (*GNUNET_TESTBED_TopologyCompletionCallback) (void *cls,
1135 unsigned int nsuccess,
1136 unsigned int nfailures);
1140 * All peers must have been started before calling this function.
1141 * This function then connects the given peers in the P2P overlay
1142 * using the given topology.
1144 * @param op_cls closure argument to give with the peer connect operation events
1145 * generated through this function
1146 * @param num_peers number of peers in 'peers'
1147 * @param peers array of 'num_peers' with the peers to configure
1148 * @param max_connections the maximums number of overlay connections that will
1149 * be made to achieve the given topology
1150 * @param comp_cb the completion callback to call when the topology generation
1152 * @param comp_cb_cls closure for the above completion callback
1153 * @param topo desired underlay topology to use
1154 * @param va topology-specific options
1155 * @return handle to the operation, NULL if connecting these
1156 * peers is fundamentally not possible at this time (peers
1157 * not running or underlay disallows) or if num_peers is less than 2
1159 struct GNUNET_TESTBED_Operation *
1160 GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
1161 unsigned int num_peers,
1162 struct GNUNET_TESTBED_Peer **peers,
1163 unsigned int *max_connections,
1164 GNUNET_TESTBED_TopologyCompletionCallback
1167 enum GNUNET_TESTBED_TopologyOption topo,
1172 * All peers must have been started before calling this function.
1173 * This function then connects the given peers in the P2P overlay
1174 * using the given topology.
1176 * @param op_cls closure argument to give with the peer connect operation events
1177 * generated through this function
1178 * @param num_peers number of peers in 'peers'
1179 * @param peers array of 'num_peers' with the peers to configure
1180 * @param max_connections the maximums number of overlay connections that will
1181 * be made to achieve the given topology
1182 * @param comp_cb the completion callback to call when the topology generation
1184 * @param comp_cb_cls closure for the above completion callback
1185 * @param topo desired underlay topology to use
1186 * @param ... topology-specific options
1187 * @return handle to the operation, NULL if connecting these
1188 * peers is fundamentally not possible at this time (peers
1189 * not running or underlay disallows) or if num_peers is less than 2
1191 struct GNUNET_TESTBED_Operation *
1192 GNUNET_TESTBED_overlay_configure_topology (void *op_cls,
1193 unsigned int num_peers,
1194 struct GNUNET_TESTBED_Peer **peers,
1195 unsigned int *max_connections,
1196 GNUNET_TESTBED_TopologyCompletionCallback
1199 enum GNUNET_TESTBED_TopologyOption topo,
1204 * Ask the testbed controller to write the current overlay topology to
1205 * a file. Naturally, the file will only contain a snapshot as the
1206 * topology may evolve all the time.
1207 * FIXME: needs continuation!?
1209 * @param controller overlay controller to inspect
1210 * @param filename name of the file the topology should
1214 GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller *controller,
1215 const char *filename);
1219 * Adapter function called to establish a connection to
1222 * @param cls closure
1223 * @param cfg configuration of the peer to connect to; will be available until
1224 * GNUNET_TESTBED_operation_done() is called on the operation returned
1225 * from GNUNET_TESTBED_service_connect()
1226 * @return service handle to return in 'op_result', NULL on error
1228 typedef void * (*GNUNET_TESTBED_ConnectAdapter)(void *cls,
1229 const struct GNUNET_CONFIGURATION_Handle *cfg);
1233 * Adapter function called to destroy a connection to
1236 * @param cls closure
1237 * @param op_result service handle returned from the connect adapter
1239 typedef void (*GNUNET_TESTBED_DisconnectAdapter)(void *cls,
1244 * Callback to be called when a service connect operation is completed
1246 * @param cls the callback closure from functions generating an operation
1247 * @param op the operation that has been finished
1248 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
1249 * @param emsg error message in case the operation has failed; will be NULL if
1250 * operation has executed successfully.
1252 typedef void (*GNUNET_TESTBED_ServiceConnectCompletionCallback) (void *cls,
1254 GNUNET_TESTBED_Operation
1263 * Connect to a service offered by the given peer. Will ensure that
1264 * the request is queued to not overwhelm our ability to create and
1265 * maintain connections with other systems. The actual service
1266 * handle is then returned via the 'op_result' member in the event
1267 * callback. The 'ca' callback is used to create the connection
1268 * when the time is right; the 'da' callback will be used to
1269 * destroy the connection (upon 'GNUNET_TESTBED_operation_done').
1270 * 'GNUNET_TESTBED_operation_cancel' can be used to abort this
1271 * operation until the event callback has been called.
1273 * @param op_cls closure to pass in operation event // FIXME: didn't we say we'd no longer use the global callback for these? -CG
1274 * @param peer peer that runs the service
1275 * @param service_name name of the service to connect to
1276 * @param cb the callback to call when this operation finishes
1277 * @param cb_cls closure for the above callback
1278 * @param ca helper function to establish the connection
1279 * @param da helper function to close the connection
1280 * @param cada_cls closure for ca and da
1281 * @return handle for the operation
1283 struct GNUNET_TESTBED_Operation *
1284 GNUNET_TESTBED_service_connect (void *op_cls,
1285 struct GNUNET_TESTBED_Peer *peer,
1286 const char *service_name,
1287 GNUNET_TESTBED_ServiceConnectCompletionCallback cb,
1289 GNUNET_TESTBED_ConnectAdapter ca,
1290 GNUNET_TESTBED_DisconnectAdapter da,
1295 * This function is used to signal that the event information (struct
1296 * GNUNET_TESTBED_EventInformation) from an operation has been fully processed
1297 * i.e. if the event callback is ever called for this operation. If the event
1298 * callback for this operation has not yet been called, calling this function
1299 * cancels the operation, frees its resources and ensures the no event is
1300 * generated with respect to this operation. Note that however cancelling an
1301 * operation does NOT guarantee that the operation will be fully undone (or that
1302 * nothing ever happened).
1304 * This function MUST be called for every operation to fully remove the
1305 * operation from the operation queue. After calling this function, if
1306 * operation is completed and its event information is of type
1307 * GNUNET_TESTBED_ET_OPERATION_FINISHED, the 'op_result' becomes invalid (!).
1309 * If the operation is generated from GNUNET_TESTBED_service_connect() then
1310 * calling this function on such as operation calls the disconnect adapter if
1311 * the connect adapter was ever called.
1313 * @param operation operation to signal completion or cancellation
1316 GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation);
1320 * Callback function to process statistic values from all peers.
1322 * @param cls closure
1323 * @param peer the peer the statistic belong to
1324 * @param subsystem name of subsystem that created the statistic
1325 * @param name the name of the datum
1326 * @param value the current value
1327 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
1328 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
1330 typedef int (*GNUNET_TESTBED_StatisticsIterator) (void *cls,
1331 const struct GNUNET_TESTBED_Peer *peer,
1332 const char *subsystem,
1339 * Convenience method that iterates over all (running) peers
1340 * and retrieves all statistics from each peer.
1342 * @param num_peers number of peers to iterate over
1343 * @param peers array of peers to iterate over
1344 * @param subsystem limit to the specified subsystem, NULL for all subsystems
1345 * @param name name of the statistic value, NULL for all values
1346 * @param proc processing function for each statistic retrieved
1347 * @param cont continuation to call once call is completed. The completion of this
1348 * operation is *ONLY* signalled through this callback -- no
1349 * GNUNET_TESTBED_ET_OPERATION_FINISHED is generated
1350 * @param cls closure to pass to proc and cont
1351 * @return operation handle to cancel the operation
1353 struct GNUNET_TESTBED_Operation *
1354 GNUNET_TESTBED_get_statistics (unsigned int num_peers,
1355 struct GNUNET_TESTBED_Peer **peers,
1356 const char *subsystem, const char *name,
1357 GNUNET_TESTBED_StatisticsIterator proc,
1358 GNUNET_TESTBED_OperationCompletionCallback cont,
1363 * Signature of a main function for a testcase.
1365 * @param cls closure
1366 * @param num_peers number of peers in 'peers'
1367 * @param peers handle to peers run in the testbed. NULL upon timeout (see
1368 * GNUNET_TESTBED_test_run()).
1369 * @param links_succeeded the number of overlay link connection attempts that
1371 * @param links_failed the number of overlay link connection attempts that
1374 typedef void (*GNUNET_TESTBED_TestMaster)(void *cls,
1375 unsigned int num_peers,
1376 struct GNUNET_TESTBED_Peer **peers,
1377 unsigned int links_succeeded,
1378 unsigned int links_failed);
1382 * Convenience method for running a testbed with
1383 * a single call. Underlay and overlay topology
1384 * are configured using the "UNDERLAY" and "OVERLAY"
1385 * options in the "[testbed]" section of the configuration\
1386 * (with possible options given in "UNDERLAY_XXX" and/or
1389 * The test_master callback will be called once the testbed setup is finished or
1390 * upon a timeout. This timeout is given through the configuration file by
1391 * setting the option "SETUP_TIMEOUT" in "[TESTBED]" section.
1393 * The testbed is to be terminated using a call to
1394 * "GNUNET_SCHEDULER_shutdown".
1396 * @param host_filename name of the file with the 'hosts', NULL
1397 * to run everything on 'localhost'
1398 * @param cfg configuration to use (for testbed, controller and peers)
1399 * @param num_peers number of peers to start; FIXME: maybe put that ALSO into
1400 * cfg?; should be greater than 0
1401 * @param event_mask bit mask with set of events to call 'cc' for;
1402 * or-ed values of "1LL" shifted by the
1403 * respective 'enum GNUNET_TESTBED_EventType'
1404 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1405 * @param cc controller callback to invoke on events; This callback is called
1406 * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1407 * set in the event_mask as this is the only way get access to the
1408 * handle of each peer
1409 * @param cc_cls closure for cc
1410 * @param test_master this callback will be called once the test is ready or
1412 * @param test_master_cls closure for 'test_master'.
1415 GNUNET_TESTBED_run (const char *host_filename,
1416 const struct GNUNET_CONFIGURATION_Handle *cfg,
1417 unsigned int num_peers,
1418 uint64_t event_mask,
1419 GNUNET_TESTBED_ControllerCallback cc,
1421 GNUNET_TESTBED_TestMaster test_master,
1422 void *test_master_cls);
1426 * Convenience method for running a "simple" test on the local system
1427 * with a single call from 'main'. Underlay and overlay topology are
1428 * configured using the "UNDERLAY" and "OVERLAY" options in the
1429 * "[TESTBED]" section of the configuration (with possible options
1430 * given in "UNDERLAY_XXX" and/or "OVERLAY_XXX").
1432 * The test_master callback will be called once the testbed setup is finished or
1433 * upon a timeout. This timeout is given through the configuration file by
1434 * setting the option "SETUP_TIMEOUT" in "[TESTBED]" section.
1436 * The test is to be terminated using a call to
1437 * "GNUNET_SCHEDULER_shutdown". If starting the test fails,
1438 * the program is stopped without 'master' ever being run.
1440 * NOTE: this function should be called from 'main', NOT from
1441 * within a GNUNET_SCHEDULER-loop. This function will initialze
1442 * the scheduler loop, the testbed and then pass control to
1445 * @param testname name of the testcase (to configure logging, etc.)
1446 * @param cfg_filename configuration filename to use
1447 * (for testbed, controller and peers)
1448 * @param num_peers number of peers to start; should be greter than 0
1449 * @param event_mask bit mask with set of events to call 'cc' for;
1450 * or-ed values of "1LL" shifted by the
1451 * respective 'enum GNUNET_TESTBED_EventType'
1452 * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...")
1453 * @param cc controller callback to invoke on events; This callback is called
1454 * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't
1455 * set in the event_mask as this is the only way get access to the
1456 * handle of each peer
1457 * @param cc_cls closure for cc
1458 * @param test_master this callback will be called once the test is ready or
1460 * @param test_master_cls closure for 'test_master'.
1461 * @return GNUNET_SYSERR on error, GNUNET_OK on success
1464 GNUNET_TESTBED_test_run (const char *testname,
1465 const char *cfg_filename,
1466 unsigned int num_peers,
1467 uint64_t event_mask,
1468 GNUNET_TESTBED_ControllerCallback cc,
1470 GNUNET_TESTBED_TestMaster test_master,
1471 void *test_master_cls);
1474 #if 0 /* keep Emacsens' auto-indent happy */