2 This file is part of GNUnet
3 Copyright (C) 2008--2013 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file testbed/testbed_api.h
23 * @brief Interface for functions internally exported from testbed_api.c
24 * @author Sree Harsha Totakura
30 #include "gnunet_util_lib.h"
31 #include "gnunet_testbed_service.h"
33 #include "testbed_helper.h"
36 * Testbed Helper binary name
38 #define HELPER_TESTBED_BINARY "gnunet-helper-testbed"
42 * Enumeration of operations
46 * Peer create operation
51 * Peer start operation
61 * Peer destroy operation
66 * Get peer information operation
76 * Overlay connection operation
86 * Link controllers operation
91 * Get slave config operation
96 * Stop and destroy all peers
101 * Start/stop service at a peer
109 * Enumeration of states of OperationContext
111 enum OperationContextState {
113 * The initial state where the associated operation has just been created
114 * and is waiting in the operation queues to be started
119 * The operation has been started. It may occupy some resources which are to
120 * be freed if cancelled.
125 * The operation has finished. The end results of this operation may occupy
126 * some resources which are to be freed by operation_done
133 * Context information for GNUNET_TESTBED_Operation
135 struct OperationContext {
137 * The controller to which this operation context belongs to
139 struct GNUNET_TESTBED_Controller *c;
144 struct GNUNET_TESTBED_Operation *op;
147 * The operation closure
152 * Data relevant to the operation
157 * The id of the opearation
162 * The type of operation
164 enum OperationType type;
167 * The state of the operation
169 enum OperationContextState state;
174 * Operation empty callback
179 (*TESTBED_opcq_empty_cb) (void *cls);
183 * Handle to interact with a GNUnet testbed controller. Each
184 * controller has at least one master handle which is created when the
185 * controller is created; this master handle interacts with the
186 * controller process, destroying it destroys the controller (by
187 * closing stdin of the controller process). Additionally,
188 * controllers can interact with each other (in a P2P fashion); those
189 * links are established via TCP/IP on the controller's service port.
191 struct GNUNET_TESTBED_Controller {
193 * The host where the controller is running
195 struct GNUNET_TESTBED_Host *host;
198 * The controller callback
200 GNUNET_TESTBED_ControllerCallback cc;
203 * The closure for controller callback
208 * The configuration to use while connecting to controller
210 struct GNUNET_CONFIGURATION_Handle *cfg;
213 * The message queue to the controller service
215 struct GNUNET_MQ_Handle *mq;
218 * The host registration handle; NULL if no current registration requests are
221 struct GNUNET_TESTBED_HostRegistrationHandle *rh;
224 * The map of active operation contexts
226 struct GNUNET_CONTAINER_MultiHashMap32 *opc_map;
229 * If this callback is not NULL, schedule it as a task when opc_map gets empty
231 TESTBED_opcq_empty_cb opcq_empty_cb;
234 * Closure for the above task
236 void *opcq_empty_cls;
239 * Operation queue for simultaneous operations
241 struct OperationQueue *opq_parallel_operations;
244 * Operation queue for simultaneous service connections
246 struct OperationQueue *opq_parallel_service_connections;
249 * Operation queue for simultaneous topology configuration operations
251 struct OperationQueue *opq_parallel_topology_config_operations;
254 * handle for hashtable of barrier handles, values are
255 * of type `struct GNUNET_TESTBED_Barrier`.
257 struct GNUNET_CONTAINER_MultiHashMap *barrier_map;
260 * The controller event mask
265 * The operation id counter. use current value and increment
267 uint32_t operation_counter;
274 struct GNUNET_TESTBED_Barrier {
276 * hashcode identifying this barrier in the hashmap
278 struct GNUNET_HashCode key;
281 * The controller handle given while initiliasing this barrier
283 struct GNUNET_TESTBED_Controller *c;
286 * The name of the barrier
291 * The continuation callback to call when we have a status update on this
293 GNUNET_TESTBED_barrier_status_cb cb;
296 * the closure for the above callback
301 * Should the barrier crossed status message be echoed back to the controller?
309 * Queues a message in send queue for sending to the service
311 * @param controller the handle to the controller
312 * @param msg the message to queue
316 GNUNET_TESTBED_queue_message_(struct GNUNET_TESTBED_Controller *controller,
317 struct GNUNET_MessageHeader *msg);
321 * Inserts the given operation context into the operation context map of the
322 * given controller. Creates the operation context map if one does not exist
325 * @param c the controller
326 * @param opc the operation context to be inserted
329 GNUNET_TESTBED_insert_opc_(struct GNUNET_TESTBED_Controller *c,
330 struct OperationContext *opc);
334 * Removes the given operation context from the operation context map of the
337 * @param c the controller
338 * @param opc the operation context to remove
341 GNUNET_TESTBED_remove_opc_(const struct GNUNET_TESTBED_Controller *c,
342 struct OperationContext *opc);
346 * Compresses given configuration using zlib compress
348 * @param config the serialized configuration
349 * @param size the size of config
350 * @param xconfig will be set to the compressed configuration (memory is fresly
352 * @return the size of the xconfig
355 GNUNET_TESTBED_compress_config_(const char *config,
361 * Function to serialize and compress using zlib a configuration through a
362 * configuration handle
364 * @param cfg the configuration
365 * @param size the size of configuration when serialize. Will be set on success.
366 * @param xsize the sizeo of the compressed configuration. Will be set on success.
367 * @return the serialized and compressed configuration
370 GNUNET_TESTBED_compress_cfg_(const struct GNUNET_CONFIGURATION_Handle *cfg,
376 * Creates a helper initialization message. This function is here because we
377 * want to use this in testing
379 * @param trusted_ip the ip address of the controller which will be set as TRUSTED
380 * HOST(all connections form this ip are permitted by the testbed) when
381 * starting testbed controller at host. This can either be a single ip
382 * address or a network address in CIDR notation.
383 * @param hostname the hostname of the destination this message is intended for
384 * @param cfg the configuration that has to used to start the testbed service
386 * @return the initialization message
388 struct GNUNET_TESTBED_HelperInit *
389 GNUNET_TESTBED_create_helper_init_msg_(const char *cname,
390 const char *hostname,
391 const struct GNUNET_CONFIGURATION_Handle *cfg);
395 * Sends the given message as an operation. The given callback is called when a
396 * reply for the operation is available. Call
397 * GNUNET_TESTBED_forward_operation_msg_cancel_() to cleanup the returned
398 * operation context if the cc hasn't been called
400 * @param controller the controller to which the message has to be sent
401 * @param operation_id the operation id of the message
402 * @param msg the message to send
403 * @param cc the callback to call when reply is available
404 * @param cc_cls the closure for the above callback
405 * @return the operation context which can be used to cancel the forwarded
408 struct OperationContext *
409 GNUNET_TESTBED_forward_operation_msg_(struct GNUNET_TESTBED_Controller *controller,
410 uint64_t operation_id,
411 const struct GNUNET_MessageHeader *msg,
412 GNUNET_MQ_MessageCallback cc,
416 * Function to cancel an operation created by simply forwarding an operation
419 * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_()
422 GNUNET_TESTBED_forward_operation_msg_cancel_(struct OperationContext *opc);
426 * Generates configuration by uncompressing configuration in given message. The
427 * given message should be of the following types:
428 * #GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG,
429 * #GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG
431 * @param msg the message containing compressed configuration
432 * @return handle to the parsed configuration
434 struct GNUNET_CONFIGURATION_Handle *
435 GNUNET_TESTBED_extract_config_(const struct GNUNET_MessageHeader *msg);
439 * Checks the integrity of the OpeationFailureEventMessage and if good returns
440 * the error message it contains.
442 * @param msg the OperationFailureEventMessage
443 * @return the error message
446 GNUNET_TESTBED_parse_error_string_(const struct GNUNET_TESTBED_OperationFailureEventMessage *msg);
450 * Function to return the operation id for a controller. The operation id is
451 * created from the controllers host id and its internal operation counter.
453 * @param controller the handle to the controller whose operation id has to be incremented
454 * @return the incremented operation id.
457 GNUNET_TESTBED_get_next_op_id(struct GNUNET_TESTBED_Controller *controller);
461 * Like GNUNET_TESTBED_get_slave_config(), however without the host registration
462 * check. Another difference is that this function takes the id of the slave
465 * @param op_cls the closure for the operation
466 * @param master the handle to master controller
467 * @param slave_host_id id of the host where the slave controller is running to
468 * the slave_host should remain valid until this operation is cancelled
469 * or marked as finished
470 * @return the operation handle;
472 struct GNUNET_TESTBED_Operation *
473 GNUNET_TESTBED_get_slave_config_(void *op_cls,
474 struct GNUNET_TESTBED_Controller *master,
475 uint32_t slave_host_id);
480 * Initialise a barrier and call the given callback when the required percentage
481 * of peers (quorum) reach the barrier OR upon error.
483 * @param controller the handle to the controller
484 * @param name identification name of the barrier
485 * @param quorum the percentage of peers that is required to reach the barrier.
486 * Peers signal reaching a barrier by calling
487 * GNUNET_TESTBED_barrier_reached().
488 * @param cb the callback to call when the barrier is reached or upon error.
490 * @param cls closure for the above callback
491 * @param echo #GNUNET_YES to echo the barrier crossed status message back to the
493 * @return barrier handle; NULL upon error
495 struct GNUNET_TESTBED_Barrier *
496 GNUNET_TESTBED_barrier_init_(struct GNUNET_TESTBED_Controller *controller,
499 GNUNET_TESTBED_barrier_status_cb cb,
505 * Remove a barrier and it was the last one in the barrier hash map, destroy the
508 * @param barrier the barrier to remove
511 GNUNET_TESTBED_barrier_remove_(struct GNUNET_TESTBED_Barrier *barrier);
516 /* end of testbed_api.h */