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
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
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
47 * Peer create operation
52 * Peer start operation
62 * Peer destroy operation
67 * Get peer information operation
77 * Overlay connection operation
87 * Link controllers operation
92 * Get slave config operation
97 * Stop and destroy all peers
102 * Start/stop service at a peer
110 * Enumeration of states of OperationContext
112 enum OperationContextState
115 * The initial state where the associated operation has just been created
116 * and is waiting in the operation queues to be started
121 * The operation has been started. It may occupy some resources which are to
122 * be freed if cancelled.
127 * The operation has finished. The end results of this operation may occupy
128 * some resources which are to be freed by operation_done
135 * Context information for GNUNET_TESTBED_Operation
137 struct OperationContext
140 * The controller to which this operation context belongs to
142 struct GNUNET_TESTBED_Controller *c;
147 struct GNUNET_TESTBED_Operation *op;
150 * The operation closure
155 * Data relevant to the operation
160 * The id of the opearation
165 * The type of operation
167 enum OperationType type;
170 * The state of the operation
172 enum OperationContextState state;
177 * Operation empty callback
182 (*TESTBED_opcq_empty_cb) (void *cls);
186 * Handle to interact with a GNUnet testbed controller. Each
187 * controller has at least one master handle which is created when the
188 * controller is created; this master handle interacts with the
189 * controller process, destroying it destroys the controller (by
190 * closing stdin of the controller process). Additionally,
191 * controllers can interact with each other (in a P2P fashion); those
192 * links are established via TCP/IP on the controller's service port.
194 struct GNUNET_TESTBED_Controller
197 * The host where the controller is running
199 struct GNUNET_TESTBED_Host *host;
202 * The controller callback
204 GNUNET_TESTBED_ControllerCallback cc;
207 * The closure for controller callback
212 * The configuration to use while connecting to controller
214 struct GNUNET_CONFIGURATION_Handle *cfg;
217 * The message queue to the controller service
219 struct GNUNET_MQ_Handle *mq;
222 * The host registration handle; NULL if no current registration requests are
225 struct GNUNET_TESTBED_HostRegistrationHandle *rh;
228 * The map of active operation contexts
230 struct GNUNET_CONTAINER_MultiHashMap32 *opc_map;
233 * If this callback is not NULL, schedule it as a task when opc_map gets empty
235 TESTBED_opcq_empty_cb opcq_empty_cb;
238 * Closure for the above task
240 void *opcq_empty_cls;
243 * Operation queue for simultaneous operations
245 struct OperationQueue *opq_parallel_operations;
248 * Operation queue for simultaneous service connections
250 struct OperationQueue *opq_parallel_service_connections;
253 * Operation queue for simultaneous topology configuration operations
255 struct OperationQueue *opq_parallel_topology_config_operations;
258 * handle for hashtable of barrier handles, values are
259 * of type `struct GNUNET_TESTBED_Barrier`.
261 struct GNUNET_CONTAINER_MultiHashMap *barrier_map;
264 * The controller event mask
269 * The operation id counter. use current value and increment
271 uint32_t operation_counter;
279 struct GNUNET_TESTBED_Barrier
282 * hashcode identifying this barrier in the hashmap
284 struct GNUNET_HashCode key;
287 * The controller handle given while initiliasing this barrier
289 struct GNUNET_TESTBED_Controller *c;
292 * The name of the barrier
297 * The continuation callback to call when we have a status update on this
299 GNUNET_TESTBED_barrier_status_cb cb;
302 * the closure for the above callback
307 * Should the barrier crossed status message be echoed back to the controller?
315 * Queues a message in send queue for sending to the service
317 * @param controller the handle to the controller
318 * @param msg the message to queue
322 GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
323 struct GNUNET_MessageHeader *msg);
327 * Inserts the given operation context into the operation context map of the
328 * given controller. Creates the operation context map if one does not exist
331 * @param c the controller
332 * @param opc the operation context to be inserted
335 GNUNET_TESTBED_insert_opc_ (struct GNUNET_TESTBED_Controller *c,
336 struct OperationContext *opc);
340 * Removes the given operation context from the operation context map of the
343 * @param c the controller
344 * @param opc the operation context to remove
347 GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c,
348 struct OperationContext *opc);
352 * Compresses given configuration using zlib compress
354 * @param config the serialized configuration
355 * @param size the size of config
356 * @param xconfig will be set to the compressed configuration (memory is fresly
358 * @return the size of the xconfig
361 GNUNET_TESTBED_compress_config_ (const char *config,
367 * Function to serialize and compress using zlib a configuration through a
368 * configuration handle
370 * @param cfg the configuration
371 * @param size the size of configuration when serialize. Will be set on success.
372 * @param xsize the sizeo of the compressed configuration. Will be set on success.
373 * @return the serialized and compressed configuration
376 GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg,
382 * Creates a helper initialization message. This function is here because we
383 * want to use this in testing
385 * @param trusted_ip the ip address of the controller which will be set as TRUSTED
386 * HOST(all connections form this ip are permitted by the testbed) when
387 * starting testbed controller at host. This can either be a single ip
388 * address or a network address in CIDR notation.
389 * @param hostname the hostname of the destination this message is intended for
390 * @param cfg the configuration that has to used to start the testbed service
392 * @return the initialization message
394 struct GNUNET_TESTBED_HelperInit *
395 GNUNET_TESTBED_create_helper_init_msg_ (const char *cname,
396 const char *hostname,
397 const struct GNUNET_CONFIGURATION_Handle *cfg);
401 * Sends the given message as an operation. The given callback is called when a
402 * reply for the operation is available. Call
403 * GNUNET_TESTBED_forward_operation_msg_cancel_() to cleanup the returned
404 * operation context if the cc hasn't been called
406 * @param controller the controller to which the message has to be sent
407 * @param operation_id the operation id of the message
408 * @param msg the message to send
409 * @param cc the callback to call when reply is available
410 * @param cc_cls the closure for the above callback
411 * @return the operation context which can be used to cancel the forwarded
414 struct OperationContext *
415 GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller *controller,
416 uint64_t operation_id,
417 const struct GNUNET_MessageHeader *msg,
418 GNUNET_CLIENT_MessageHandler cc,
422 * Function to cancel an operation created by simply forwarding an operation
425 * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_()
428 GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc);
432 * Generates configuration by uncompressing configuration in given message. The
433 * given message should be of the following types:
434 * #GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG,
435 * #GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG
437 * @param msg the message containing compressed configuration
438 * @return handle to the parsed configuration
440 struct GNUNET_CONFIGURATION_Handle *
441 GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg);
445 * Checks the integrity of the OpeationFailureEventMessage and if good returns
446 * the error message it contains.
448 * @param msg the OperationFailureEventMessage
449 * @return the error message
452 GNUNET_TESTBED_parse_error_string_ (const struct GNUNET_TESTBED_OperationFailureEventMessage *msg);
456 * Function to return the operation id for a controller. The operation id is
457 * created from the controllers host id and its internal operation counter.
459 * @param controller the handle to the controller whose operation id has to be incremented
460 * @return the incremented operation id.
463 GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller);
467 * Like GNUNET_TESTBED_get_slave_config(), however without the host registration
468 * check. Another difference is that this function takes the id of the slave
471 * @param op_cls the closure for the operation
472 * @param master the handle to master controller
473 * @param slave_host_id id of the host where the slave controller is running to
474 * the slave_host should remain valid until this operation is cancelled
475 * or marked as finished
476 * @return the operation handle;
478 struct GNUNET_TESTBED_Operation *
479 GNUNET_TESTBED_get_slave_config_ (void *op_cls,
480 struct GNUNET_TESTBED_Controller *master,
481 uint32_t slave_host_id);
486 * Initialise a barrier and call the given callback when the required percentage
487 * of peers (quorum) reach the barrier OR upon error.
489 * @param controller the handle to the controller
490 * @param name identification name of the barrier
491 * @param quorum the percentage of peers that is required to reach the barrier.
492 * Peers signal reaching a barrier by calling
493 * GNUNET_TESTBED_barrier_reached().
494 * @param cb the callback to call when the barrier is reached or upon error.
496 * @param cls closure for the above callback
497 * @param echo #GNUNET_YES to echo the barrier crossed status message back to the
499 * @return barrier handle; NULL upon error
501 struct GNUNET_TESTBED_Barrier *
502 GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller,
505 GNUNET_TESTBED_barrier_status_cb cb,
511 * Remove a barrier and it was the last one in the barrier hash map, destroy the
514 * @param barrier the barrier to remove
517 GNUNET_TESTBED_barrier_remove_ (struct GNUNET_TESTBED_Barrier *barrier);
522 /* end of testbed_api.h */