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 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
186 typedef void (*TESTBED_opcq_empty_cb) (void *cls);
190 * Handle to interact with a GNUnet testbed controller. Each
191 * controller has at least one master handle which is created when the
192 * controller is created; this master handle interacts with the
193 * controller process, destroying it destroys the controller (by
194 * closing stdin of the controller process). Additionally,
195 * controllers can interact with each other (in a P2P fashion); those
196 * links are established via TCP/IP on the controller's service port.
198 struct GNUNET_TESTBED_Controller
201 * The host where the controller is running
203 struct GNUNET_TESTBED_Host *host;
206 * The controller callback
208 GNUNET_TESTBED_ControllerCallback cc;
211 * The closure for controller callback
216 * The configuration to use while connecting to controller
218 struct GNUNET_CONFIGURATION_Handle *cfg;
221 * The client connection handle to the controller service
223 struct GNUNET_CLIENT_Connection *client;
226 * The head of the message queue
228 struct MessageQueue *mq_head;
231 * The tail of the message queue
233 struct MessageQueue *mq_tail;
236 * The client transmit handle
238 struct GNUNET_CLIENT_TransmitHandle *th;
241 * The host registration handle; NULL if no current registration requests are
244 struct GNUNET_TESTBED_HostRegistrationHandle *rh;
247 * The map of active operation contexts
249 struct GNUNET_CONTAINER_MultiHashMap32 *opc_map;
252 * If this callback is not NULL, schedule it as a task when opc_map gets empty
254 TESTBED_opcq_empty_cb opcq_empty_cb;
257 * Closure for the above task
259 void *opcq_empty_cls;
262 * Operation queue for simultaneous operations
264 struct OperationQueue *opq_parallel_operations;
267 * Operation queue for simultaneous service connections
269 struct OperationQueue *opq_parallel_service_connections;
272 * Operation queue for simultaneous topology configuration operations
274 struct OperationQueue *opq_parallel_topology_config_operations;
277 * The controller event mask
282 * Did we start the receive loop yet?
287 * The operation id counter. use current value and increment
289 uint32_t operation_counter;
295 * Queues a message in send queue for sending to the service
297 * @param controller the handle to the controller
298 * @param msg the message to queue
301 GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller,
302 struct GNUNET_MessageHeader *msg);
306 * Inserts the given operation context into the operation context map of the
307 * given controller. Creates the operation context map if one does not exist
310 * @param c the controller
311 * @param opc the operation context to be inserted
314 GNUNET_TESTBED_insert_opc_ (struct GNUNET_TESTBED_Controller *c,
315 struct OperationContext *opc);
319 * Removes the given operation context from the operation context map of the
322 * @param c the controller
323 * @param opc the operation context to remove
326 GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c,
327 struct OperationContext *opc);
331 * Compresses given configuration using zlib compress
333 * @param config the serialized configuration
334 * @param size the size of config
335 * @param xconfig will be set to the compressed configuration (memory is fresly
337 * @return the size of the xconfig
340 GNUNET_TESTBED_compress_config_ (const char *config, size_t size,
345 * Function to serialize and compress using zlib a configuration through a
346 * configuration handle
348 * @param cfg the configuration
349 * @param size the size of configuration when serialize. Will be set on success.
350 * @param xsize the sizeo of the compressed configuration. Will be set on success.
351 * @return the serialized and compressed configuration
354 GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg,
355 size_t *size, size_t *xsize);
359 * Creates a helper initialization message. This function is here because we
360 * want to use this in testing
362 * @param trusted_ip the ip address of the controller which will be set as TRUSTED
363 * HOST(all connections form this ip are permitted by the testbed) when
364 * starting testbed controller at host. This can either be a single ip
365 * address or a network address in CIDR notation.
366 * @param hostname the hostname of the destination this message is intended for
367 * @param cfg the configuration that has to used to start the testbed service
369 * @return the initialization message
371 struct GNUNET_TESTBED_HelperInit *
372 GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, const char *hostname,
373 const struct GNUNET_CONFIGURATION_Handle
378 * Sends the given message as an operation. The given callback is called when a
379 * reply for the operation is available. Call
380 * GNUNET_TESTBED_forward_operation_msg_cancel_() to cleanup the returned
381 * operation context if the cc hasn't been called
383 * @param controller the controller to which the message has to be sent
384 * @param operation_id the operation id of the message
385 * @param msg the message to send
386 * @param cc the callback to call when reply is available
387 * @param cc_cls the closure for the above callback
388 * @return the operation context which can be used to cancel the forwarded
391 struct OperationContext *
392 GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller
393 *controller, uint64_t operation_id,
394 const struct GNUNET_MessageHeader *msg,
395 GNUNET_CLIENT_MessageHandler cc,
399 * Function to cancel an operation created by simply forwarding an operation
402 * @param opc the operation context from GNUNET_TESTBED_forward_operation_msg_()
405 GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc);
409 * Generates configuration by uncompressing configuration in given message. The
410 * given message should be of the following types:
411 * GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG,
412 * GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG
414 * @param msg the message containing compressed configuration
415 * @return handle to the parsed configuration
417 struct GNUNET_CONFIGURATION_Handle *
418 GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg);
422 * Checks the integrity of the OpeationFailureEventMessage and if good returns
423 * the error message it contains.
425 * @param msg the OperationFailureEventMessage
426 * @return the error message
429 GNUNET_TESTBED_parse_error_string_ (const struct
430 GNUNET_TESTBED_OperationFailureEventMessage
435 * Function to return the operation id for a controller. The operation id is
436 * created from the controllers host id and its internal operation counter.
438 * @param controller the handle to the controller whose operation id has to be incremented
439 * @return the incremented operation id.
442 GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller);
446 * Like GNUNET_TESTBED_get_slave_config(), however without the host registration
447 * check. Another difference is that this function takes the id of the slave
450 * @param op_cls the closure for the operation
451 * @param master the handle to master controller
452 * @param slave_host_id id of the host where the slave controller is running to
453 * the slave_host should remain valid until this operation is cancelled
454 * or marked as finished
455 * @return the operation handle;
457 struct GNUNET_TESTBED_Operation *
458 GNUNET_TESTBED_get_slave_config_ (void *op_cls,
459 struct GNUNET_TESTBED_Controller *master,
460 uint32_t slave_host_id);
464 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages. This
465 * function is defined in @file testbed_api_barriers.c
467 * @param c the controller handle to determine the connection this message
469 * @param msg the barrier status message
470 * @return GNUNET_OK to keep the connection active; GNUNET_SYSERR to tear it
471 * down signalling an error
474 GNUNET_TESTBED_handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c,
475 const struct GNUNET_TESTBED_BarrierStatusMsg
482 /* end of testbed_api.h */