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 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.
17 * @file testbed/testbed_api.h
18 * @brief Interface for functions internally exported from testbed_api.c
19 * @author Sree Harsha Totakura
25 #include "gnunet_util_lib.h"
26 #include "gnunet_testbed_service.h"
28 #include "testbed_helper.h"
31 * Testbed Helper binary name
33 #define HELPER_TESTBED_BINARY "gnunet-helper-testbed"
37 * Enumeration of operations
42 * Peer create operation
47 * Peer start operation
57 * Peer destroy operation
62 * Get peer information operation
72 * Overlay connection operation
82 * Link controllers operation
87 * Get slave config operation
92 * Stop and destroy all peers
97 * Start/stop service at a peer
105 * Enumeration of states of OperationContext
107 enum OperationContextState
110 * The initial state where the associated operation has just been created
111 * and is waiting in the operation queues to be started
116 * The operation has been started. It may occupy some resources which are to
117 * be freed if cancelled.
122 * The operation has finished. The end results of this operation may occupy
123 * some resources which are to be freed by operation_done
130 * Context information for GNUNET_TESTBED_Operation
132 struct OperationContext
135 * The controller to which this operation context belongs to
137 struct GNUNET_TESTBED_Controller *c;
142 struct GNUNET_TESTBED_Operation *op;
145 * The operation closure
150 * Data relevant to the operation
155 * The id of the opearation
160 * The type of operation
162 enum OperationType type;
165 * The state of the operation
167 enum OperationContextState state;
172 * Operation empty callback
177 (*TESTBED_opcq_empty_cb) (void *cls);
181 * Handle to interact with a GNUnet testbed controller. Each
182 * controller has at least one master handle which is created when the
183 * controller is created; this master handle interacts with the
184 * controller process, destroying it destroys the controller (by
185 * closing stdin of the controller process). Additionally,
186 * controllers can interact with each other (in a P2P fashion); those
187 * links are established via TCP/IP on the controller's service port.
189 struct GNUNET_TESTBED_Controller
192 * The host where the controller is running
194 struct GNUNET_TESTBED_Host *host;
197 * The controller callback
199 GNUNET_TESTBED_ControllerCallback cc;
202 * The closure for controller callback
207 * The configuration to use while connecting to controller
209 struct GNUNET_CONFIGURATION_Handle *cfg;
212 * The message queue to the controller service
214 struct GNUNET_MQ_Handle *mq;
217 * The host registration handle; NULL if no current registration requests are
220 struct GNUNET_TESTBED_HostRegistrationHandle *rh;
223 * The map of active operation contexts
225 struct GNUNET_CONTAINER_MultiHashMap32 *opc_map;
228 * If this callback is not NULL, schedule it as a task when opc_map gets empty
230 TESTBED_opcq_empty_cb opcq_empty_cb;
233 * Closure for the above task
235 void *opcq_empty_cls;
238 * Operation queue for simultaneous operations
240 struct OperationQueue *opq_parallel_operations;
243 * Operation queue for simultaneous service connections
245 struct OperationQueue *opq_parallel_service_connections;
248 * Operation queue for simultaneous topology configuration operations
250 struct OperationQueue *opq_parallel_topology_config_operations;
253 * handle for hashtable of barrier handles, values are
254 * of type `struct GNUNET_TESTBED_Barrier`.
256 struct GNUNET_CONTAINER_MultiHashMap *barrier_map;
259 * The controller event mask
264 * The operation id counter. use current value and increment
266 uint32_t operation_counter;
274 struct GNUNET_TESTBED_Barrier
277 * hashcode identifying this barrier in the hashmap
279 struct GNUNET_HashCode key;
282 * The controller handle given while initiliasing this barrier
284 struct GNUNET_TESTBED_Controller *c;
287 * The name of the barrier
292 * The continuation callback to call when we have a status update on this
294 GNUNET_TESTBED_barrier_status_cb cb;
297 * the closure for the above callback
302 * Should the barrier crossed status message be echoed back to the controller?
310 * Queues a message in send queue for sending to the service
312 * @param controller the handle to the controller
313 * @param msg the message to queue
317 GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
318 struct GNUNET_MessageHeader *msg);
322 * Inserts the given operation context into the operation context map of the
323 * given controller. Creates the operation context map if one does not exist
326 * @param c the controller
327 * @param opc the operation context to be inserted
330 GNUNET_TESTBED_insert_opc_ (struct GNUNET_TESTBED_Controller *c,
331 struct OperationContext *opc);
335 * Removes the given operation context from the operation context map of the
338 * @param c the controller
339 * @param opc the operation context to remove
342 GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c,
343 struct OperationContext *opc);
347 * Compresses given configuration using zlib compress
349 * @param config the serialized configuration
350 * @param size the size of config
351 * @param xconfig will be set to the compressed configuration (memory is fresly
353 * @return the size of the xconfig
356 GNUNET_TESTBED_compress_config_ (const char *config,
362 * Function to serialize and compress using zlib a configuration through a
363 * configuration handle
365 * @param cfg the configuration
366 * @param size the size of configuration when serialize. Will be set on success.
367 * @param xsize the sizeo of the compressed configuration. Will be set on success.
368 * @return the serialized and compressed configuration
371 GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg,
377 * Creates a helper initialization message. This function is here because we
378 * want to use this in testing
380 * @param trusted_ip the ip address of the controller which will be set as TRUSTED
381 * HOST(all connections form this ip are permitted by the testbed) when
382 * starting testbed controller at host. This can either be a single ip
383 * address or a network address in CIDR notation.
384 * @param hostname the hostname of the destination this message is intended for
385 * @param cfg the configuration that has to used to start the testbed service
387 * @return the initialization message
389 struct GNUNET_TESTBED_HelperInit *
390 GNUNET_TESTBED_create_helper_init_msg_ (const char *cname,
391 const char *hostname,
392 const struct GNUNET_CONFIGURATION_Handle *cfg);
396 * Sends the given message as an operation. The given callback is called when a
397 * reply for the operation is available. Call
398 * GNUNET_TESTBED_forward_operation_msg_cancel_() to cleanup the returned
399 * operation context if the cc hasn't been called
401 * @param controller the controller to which the message has to be sent
402 * @param operation_id the operation id of the message
403 * @param msg the message to send
404 * @param cc the callback to call when reply is available
405 * @param cc_cls the closure for the above callback
406 * @return the operation context which can be used to cancel the forwarded
409 struct OperationContext *
410 GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller *controller,
411 uint64_t operation_id,
412 const struct GNUNET_MessageHeader *msg,
413 GNUNET_MQ_MessageCallback cc,
417 * Function to cancel an operation created by simply forwarding an operation
420 * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_()
423 GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc);
427 * Generates configuration by uncompressing configuration in given message. The
428 * given message should be of the following types:
429 * #GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG,
430 * #GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG
432 * @param msg the message containing compressed configuration
433 * @return handle to the parsed configuration
435 struct GNUNET_CONFIGURATION_Handle *
436 GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg);
440 * Checks the integrity of the OpeationFailureEventMessage and if good returns
441 * the error message it contains.
443 * @param msg the OperationFailureEventMessage
444 * @return the error message
447 GNUNET_TESTBED_parse_error_string_ (const struct GNUNET_TESTBED_OperationFailureEventMessage *msg);
451 * Function to return the operation id for a controller. The operation id is
452 * created from the controllers host id and its internal operation counter.
454 * @param controller the handle to the controller whose operation id has to be incremented
455 * @return the incremented operation id.
458 GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller);
462 * Like GNUNET_TESTBED_get_slave_config(), however without the host registration
463 * check. Another difference is that this function takes the id of the slave
466 * @param op_cls the closure for the operation
467 * @param master the handle to master controller
468 * @param slave_host_id id of the host where the slave controller is running to
469 * the slave_host should remain valid until this operation is cancelled
470 * or marked as finished
471 * @return the operation handle;
473 struct GNUNET_TESTBED_Operation *
474 GNUNET_TESTBED_get_slave_config_ (void *op_cls,
475 struct GNUNET_TESTBED_Controller *master,
476 uint32_t slave_host_id);
481 * Initialise a barrier and call the given callback when the required percentage
482 * of peers (quorum) reach the barrier OR upon error.
484 * @param controller the handle to the controller
485 * @param name identification name of the barrier
486 * @param quorum the percentage of peers that is required to reach the barrier.
487 * Peers signal reaching a barrier by calling
488 * GNUNET_TESTBED_barrier_reached().
489 * @param cb the callback to call when the barrier is reached or upon error.
491 * @param cls closure for the above callback
492 * @param echo #GNUNET_YES to echo the barrier crossed status message back to the
494 * @return barrier handle; NULL upon error
496 struct GNUNET_TESTBED_Barrier *
497 GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller,
500 GNUNET_TESTBED_barrier_status_cb cb,
506 * Remove a barrier and it was the last one in the barrier hash map, destroy the
509 * @param barrier the barrier to remove
512 GNUNET_TESTBED_barrier_remove_ (struct GNUNET_TESTBED_Barrier *barrier);
517 /* end of testbed_api.h */