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
109 * The message queue for sending messages to the controller service
115 * Enumeration of states of OperationContext
117 enum OperationContextState
120 * The initial state where the associated operation has just been created
121 * and is waiting in the operation queues to be started
126 * The operation has been started. It may occupy some resources which are to
127 * be freed if cancelled.
132 * The operation has finished. The end results of this operation may occupy
133 * some resources which are to be freed by operation_done
140 * Context information for GNUNET_TESTBED_Operation
142 struct OperationContext
145 * The controller to which this operation context belongs to
147 struct GNUNET_TESTBED_Controller *c;
152 struct GNUNET_TESTBED_Operation *op;
155 * The operation closure
160 * Data relevant to the operation
165 * The id of the opearation
170 * The type of operation
172 enum OperationType type;
175 * The state of the operation
177 enum OperationContextState state;
182 * Operation empty callback
187 (*TESTBED_opcq_empty_cb) (void *cls);
191 * Handle to interact with a GNUnet testbed controller. Each
192 * controller has at least one master handle which is created when the
193 * controller is created; this master handle interacts with the
194 * controller process, destroying it destroys the controller (by
195 * closing stdin of the controller process). Additionally,
196 * controllers can interact with each other (in a P2P fashion); those
197 * links are established via TCP/IP on the controller's service port.
199 struct GNUNET_TESTBED_Controller
202 * The host where the controller is running
204 struct GNUNET_TESTBED_Host *host;
207 * The controller callback
209 GNUNET_TESTBED_ControllerCallback cc;
212 * The closure for controller callback
217 * The configuration to use while connecting to controller
219 struct GNUNET_CONFIGURATION_Handle *cfg;
222 * The client connection handle to the controller service
224 struct GNUNET_CLIENT_Connection *client;
227 * The head of the message queue
229 struct MessageQueue *mq_head;
232 * The tail of the message queue
234 struct MessageQueue *mq_tail;
237 * The client transmit handle
239 struct GNUNET_CLIENT_TransmitHandle *th;
242 * The host registration handle; NULL if no current registration requests are
245 struct GNUNET_TESTBED_HostRegistrationHandle *rh;
248 * The map of active operation contexts
250 struct GNUNET_CONTAINER_MultiHashMap32 *opc_map;
253 * If this callback is not NULL, schedule it as a task when opc_map gets empty
255 TESTBED_opcq_empty_cb opcq_empty_cb;
258 * Closure for the above task
260 void *opcq_empty_cls;
263 * Operation queue for simultaneous operations
265 struct OperationQueue *opq_parallel_operations;
268 * Operation queue for simultaneous service connections
270 struct OperationQueue *opq_parallel_service_connections;
273 * Operation queue for simultaneous topology configuration operations
275 struct OperationQueue *opq_parallel_topology_config_operations;
278 * handle for hashtable of barrier handles, values are
279 * of type `struct GNUNET_TESTBED_Barrier`.
281 struct GNUNET_CONTAINER_MultiHashMap *barrier_map;
284 * The controller event mask
289 * Did we start the receive loop yet?
294 * The operation id counter. use current value and increment
296 uint32_t operation_counter;
304 struct GNUNET_TESTBED_Barrier
307 * hashcode identifying this barrier in the hashmap
309 struct GNUNET_HashCode key;
312 * The controller handle given while initiliasing this barrier
314 struct GNUNET_TESTBED_Controller *c;
317 * The name of the barrier
322 * The continuation callback to call when we have a status update on this
324 GNUNET_TESTBED_barrier_status_cb cb;
327 * the closure for the above callback
332 * Should the barrier crossed status message be echoed back to the controller?
340 * Queues a message in send queue for sending to the service
342 * @param controller the handle to the controller
343 * @param msg the message to queue
346 GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
347 struct GNUNET_MessageHeader *msg);
351 * Inserts the given operation context into the operation context map of the
352 * given controller. Creates the operation context map if one does not exist
355 * @param c the controller
356 * @param opc the operation context to be inserted
359 GNUNET_TESTBED_insert_opc_ (struct GNUNET_TESTBED_Controller *c,
360 struct OperationContext *opc);
364 * Removes the given operation context from the operation context map of the
367 * @param c the controller
368 * @param opc the operation context to remove
371 GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c,
372 struct OperationContext *opc);
376 * Compresses given configuration using zlib compress
378 * @param config the serialized configuration
379 * @param size the size of config
380 * @param xconfig will be set to the compressed configuration (memory is fresly
382 * @return the size of the xconfig
385 GNUNET_TESTBED_compress_config_ (const char *config, size_t size,
390 * Function to serialize and compress using zlib a configuration through a
391 * configuration handle
393 * @param cfg the configuration
394 * @param size the size of configuration when serialize. Will be set on success.
395 * @param xsize the sizeo of the compressed configuration. Will be set on success.
396 * @return the serialized and compressed configuration
399 GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg,
400 size_t *size, size_t *xsize);
404 * Creates a helper initialization message. This function is here because we
405 * want to use this in testing
407 * @param trusted_ip the ip address of the controller which will be set as TRUSTED
408 * HOST(all connections form this ip are permitted by the testbed) when
409 * starting testbed controller at host. This can either be a single ip
410 * address or a network address in CIDR notation.
411 * @param hostname the hostname of the destination this message is intended for
412 * @param cfg the configuration that has to used to start the testbed service
414 * @return the initialization message
416 struct GNUNET_TESTBED_HelperInit *
417 GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, const char *hostname,
418 const struct GNUNET_CONFIGURATION_Handle
423 * Sends the given message as an operation. The given callback is called when a
424 * reply for the operation is available. Call
425 * GNUNET_TESTBED_forward_operation_msg_cancel_() to cleanup the returned
426 * operation context if the cc hasn't been called
428 * @param controller the controller to which the message has to be sent
429 * @param operation_id the operation id of the message
430 * @param msg the message to send
431 * @param cc the callback to call when reply is available
432 * @param cc_cls the closure for the above callback
433 * @return the operation context which can be used to cancel the forwarded
436 struct OperationContext *
437 GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller
438 *controller, uint64_t operation_id,
439 const struct GNUNET_MessageHeader *msg,
440 GNUNET_CLIENT_MessageHandler cc,
444 * Function to cancel an operation created by simply forwarding an operation
447 * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_()
450 GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc);
454 * Generates configuration by uncompressing configuration in given message. The
455 * given message should be of the following types:
456 * GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG,
457 * GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG
459 * @param msg the message containing compressed configuration
460 * @return handle to the parsed configuration
462 struct GNUNET_CONFIGURATION_Handle *
463 GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg);
467 * Checks the integrity of the OpeationFailureEventMessage and if good returns
468 * the error message it contains.
470 * @param msg the OperationFailureEventMessage
471 * @return the error message
474 GNUNET_TESTBED_parse_error_string_ (const struct
475 GNUNET_TESTBED_OperationFailureEventMessage
480 * Function to return the operation id for a controller. The operation id is
481 * created from the controllers host id and its internal operation counter.
483 * @param controller the handle to the controller whose operation id has to be incremented
484 * @return the incremented operation id.
487 GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller);
491 * Like GNUNET_TESTBED_get_slave_config(), however without the host registration
492 * check. Another difference is that this function takes the id of the slave
495 * @param op_cls the closure for the operation
496 * @param master the handle to master controller
497 * @param slave_host_id id of the host where the slave controller is running to
498 * the slave_host should remain valid until this operation is cancelled
499 * or marked as finished
500 * @return the operation handle;
502 struct GNUNET_TESTBED_Operation *
503 GNUNET_TESTBED_get_slave_config_ (void *op_cls,
504 struct GNUNET_TESTBED_Controller *master,
505 uint32_t slave_host_id);
509 /* end of testbed_api.h */