GNUnet  0.11.x
Typedefs | Enumerations | Functions
testbed_api_operations.h File Reference

internal API to access the 'operations' subsystem More...

#include "gnunet_testbed_service.h"
#include "gnunet_helper_lib.h"
Include dependency graph for testbed_api_operations.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* OperationStart) (void *cls)
 Function to call to start an operation once all queues the operation is part of declare that the operation can be activated. More...
 
typedef void(* OperationRelease) (void *cls)
 Function to call to cancel an operation (release all associated resources). More...
 

Enumerations

enum  OperationQueueType { OPERATION_QUEUE_TYPE_FIXED , OPERATION_QUEUE_TYPE_ADAPTIVE }
 The type of operation queue. More...
 

Functions

struct OperationQueueGNUNET_TESTBED_operation_queue_create_ (enum OperationQueueType type, unsigned int max_active)
 Create an operation queue. More...
 
void GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue)
 Destroy an operation queue. More...
 
int GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue)
 Destroys the operation queue if it is empty. More...
 
void GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue, unsigned int max_active)
 Function to reset the maximum number of operations in the given queue. More...
 
void GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue, struct GNUNET_TESTBED_Operation *op, unsigned int nres)
 Add an operation to a queue. More...
 
void GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue, struct GNUNET_TESTBED_Operation *op)
 Add an operation to a queue. More...
 
void GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation *op)
 Marks the given operation as waiting on the queues. More...
 
struct GNUNET_TESTBED_OperationGNUNET_TESTBED_operation_create_ (void *cls, OperationStart start, OperationRelease release)
 Create an 'operation' to be performed. More...
 
void GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *op)
 An operation is 'done' (was cancelled or finished); remove it from the queues and release associated resources. More...
 
void GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op)
 Marks an active operation as inactive - the operation will be kept in a ready-to-be-released state and continues to hold resources until another operation contents for them. More...
 
void GNUNET_TESTBED_operation_activate_ (struct GNUNET_TESTBED_Operation *op)
 Marks and inactive operation as active. More...
 
void GNUNET_TESTBED_operation_mark_failed (struct GNUNET_TESTBED_Operation *op)
 Marks an operation as failed. More...
 

Detailed Description

internal API to access the 'operations' subsystem

Author
Christian Grothoff

Definition in file testbed_api_operations.h.

Typedef Documentation

◆ OperationStart

typedef void(* OperationStart) (void *cls)

Function to call to start an operation once all queues the operation is part of declare that the operation can be activated.

Parameters
clsthe closure from GNUNET_TESTBED_operation_create_()

Definition at line 157 of file testbed_api_operations.h.

◆ OperationRelease

typedef void(* OperationRelease) (void *cls)

Function to call to cancel an operation (release all associated resources).

This can be because of a call to "GNUNET_TESTBED_operation_cancel" (before the operation generated an event) or AFTER the operation generated an event due to a call to "GNUNET_TESTBED_operation_done". Thus it is not guaranteed that a callback to the 'OperationStart' precedes the call to 'OperationRelease'. Implementations of this function are expected to clean up whatever state is in 'cls' and release all resources associated with the operation.

Parameters
clsthe closure from GNUNET_TESTBED_operation_create_()

Definition at line 173 of file testbed_api_operations.h.

Enumeration Type Documentation

◆ OperationQueueType

The type of operation queue.

Enumerator
OPERATION_QUEUE_TYPE_FIXED 

Operation queue which permits a fixed maximum number of operations to be active at any time.

OPERATION_QUEUE_TYPE_ADAPTIVE 

Operation queue which adapts the number of operations to be active based on the operation completion times of previously executed operation in it.

Definition at line 43 of file testbed_api_operations.h.

44 {
50 
56 };
@ OPERATION_QUEUE_TYPE_ADAPTIVE
Operation queue which adapts the number of operations to be active based on the operation completion ...
@ OPERATION_QUEUE_TYPE_FIXED
Operation queue which permits a fixed maximum number of operations to be active at any time.

Function Documentation

◆ GNUNET_TESTBED_operation_queue_create_()

struct OperationQueue* GNUNET_TESTBED_operation_queue_create_ ( enum OperationQueueType  type,
unsigned int  max_active 
)

Create an operation queue.

Parameters
typethe type of operation queue
max_activemaximum number of operations in this queue that can be active in parallel at the same time.
Returns
handle to the queue
Parameters
typethe type of operation queue
max_activemaximum number of operations in this queue that can be active in parallel at the same time
Returns
handle to the queue

Definition at line 1051 of file testbed_api_operations.c.

1053 {
1054  struct OperationQueue *queue;
1055  struct FeedbackCtx *fctx;
1056 
1057  queue = GNUNET_new (struct OperationQueue);
1058  queue->type = type;
1060  {
1061  queue->max_active = max_active;
1062  }
1063  else
1064  {
1065  fctx = GNUNET_new (struct FeedbackCtx);
1066  fctx->max_active_bound = max_active;
1068  queue->fctx = fctx;
1070  }
1071  return queue;
1072 }
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Context for operation queues of type OPERATION_QUEUE_TYPE_ADAPTIVE.
unsigned int max_active_bound
Bound on the maximum number of operations which can be active.
struct SDHandle * sd
Handle for calculating standard deviation.
Queue of operations where we can only support a certain number of concurrent operations of a particul...
static void adaptive_queue_set_max_active(struct OperationQueue *queue, unsigned int n)
Cleansup the existing timing slots and sets new timing slots in the given queue to accommodate given ...
#define ADAPTIVE_QUEUE_DEFAULT_HISTORY
The number of readings containing past operation's timing information that we keep track of for adapt...
#define ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE
The number of parallel operations we start with by default for adaptive queues.
struct SDHandle * GNUNET_TESTBED_SD_init_(unsigned int max_cnt)
Initialize standard deviation calculation handle.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

References ADAPTIVE_QUEUE_DEFAULT_HISTORY, ADAPTIVE_QUEUE_DEFAULT_MAX_ACTIVE, adaptive_queue_set_max_active(), GNUNET_new, GNUNET_TESTBED_SD_init_(), FeedbackCtx::max_active_bound, OPERATION_QUEUE_TYPE_FIXED, queue(), FeedbackCtx::sd, and type.

Referenced by GNUNET_TESTBED_controller_connect(), GNUNET_TESTBED_get_statistics(), GNUNET_TESTBED_host_create_with_id(), and testbed_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_queue_destroy_()

void GNUNET_TESTBED_operation_queue_destroy_ ( struct OperationQueue queue)

Destroy an operation queue.

The queue MUST be empty at this time.

Parameters
queuequeue to destroy

Destroy an operation queue.

If the queue is still in use by operations it is marked as expired and its resources are released in the destructor GNUNET_TESTBED_operations_fini().

Parameters
queuequeue to destroy

Definition at line 1104 of file testbed_api_operations.c.

1105 {
1106  if (GNUNET_YES != is_queue_empty (queue))
1107  {
1108  GNUNET_assert (0 == queue->expired); /* Are you calling twice on same queue? */
1109  queue->expired = 1;
1111  return;
1112  }
1113  queue_destroy (queue);
1114 }
@ GNUNET_YES
Definition: gnunet_common.h:97
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
static void queue_destroy(struct OperationQueue *queue)
Cleanup the given operation queue.
static unsigned int n_expired_opqs
Number of expired operation queues in the above array.
static struct OperationQueue ** expired_opqs
Array of operation queues which are to be destroyed.
static int is_queue_empty(struct OperationQueue *opq)
Checks if the given operation queue is empty or not.

References expired_opqs, GNUNET_array_append, GNUNET_assert, GNUNET_YES, is_queue_empty(), n_expired_opqs, queue(), and queue_destroy().

Referenced by GNUNET_TESTBED_controller_disconnect(), GNUNET_TESTBED_host_destroy(), GNUNET_TESTBED_operation_queue_destroy_empty_(), and shutdown_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_queue_destroy_empty_()

int GNUNET_TESTBED_operation_queue_destroy_empty_ ( struct OperationQueue queue)

Destroys the operation queue if it is empty.

If not empty return GNUNET_NO.

Parameters
queuethe queue to destroy if empty
Returns
GNUNET_YES if the queue is destroyed. GNUNET_NO if not (because it is not empty)

Definition at line 1125 of file testbed_api_operations.c.

1126 {
1127  if (GNUNET_NO == is_queue_empty (queue))
1128  return GNUNET_NO;
1130  return GNUNET_YES;
1131 }
@ GNUNET_NO
Definition: gnunet_common.h:94
void GNUNET_TESTBED_operation_queue_destroy_(struct OperationQueue *queue)
Destroys an operation queue.

References GNUNET_NO, GNUNET_TESTBED_operation_queue_destroy_(), GNUNET_YES, is_queue_empty(), and queue().

Referenced by oprelease_get_stats().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_queue_reset_max_active_()

void GNUNET_TESTBED_operation_queue_reset_max_active_ ( struct OperationQueue queue,
unsigned int  max_active 
)

Function to reset the maximum number of operations in the given queue.

If max_active is lesser than the number of currently active operations, the active operations are not stopped immediately.

Parameters
queuethe operation queue which has to be modified
max_activethe new maximum number of active operations

Definition at line 1166 of file testbed_api_operations.c.

1168 {
1169  struct QueueEntry *entry;
1170 
1171  queue->max_active = max_active;
1172  queue->overload = 0;
1173  while ((queue->active > queue->max_active)
1174  && (NULL != (entry = queue->rq_head)))
1175  defer (entry->op);
1177 }
An entry in the operation queue.
struct GNUNET_TESTBED_Operation * op
The operation this entry holds.
static void recheck_waiting(struct OperationQueue *opq)
Rechecks if any of the operations in the given operation queue's waiting list can be made active.
static void defer(struct GNUNET_TESTBED_Operation *op)
Defers a ready to be executed operation back to waiting.

References defer(), QueueEntry::op, queue(), and recheck_waiting().

Referenced by adaptive_queue_set_max_active().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_queue_insert2_()

void GNUNET_TESTBED_operation_queue_insert2_ ( struct OperationQueue queue,
struct GNUNET_TESTBED_Operation op,
unsigned int  nres 
)

Add an operation to a queue.

An operation can be in multiple queues at once. Once the operation is inserted into all the queues GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start waiting for the operation to become active.

Parameters
queuequeue to add the operation to
opoperation to add to the queue
nresthe number of units of the resources of queue needed by the operation. Should be greater than 0.

Definition at line 1192 of file testbed_api_operations.c.

1195 {
1196  unsigned int qsize;
1197 
1198  GNUNET_assert (0 < nres);
1199  qsize = op->nqueues;
1200  GNUNET_array_append (op->queues, op->nqueues, queue);
1201  GNUNET_array_append (op->nres, qsize, nres);
1202  GNUNET_assert (qsize == op->nqueues);
1203 }
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144

References GNUNET_array_append, GNUNET_assert, QueueEntry::nres, op, and queue().

Referenced by GNUNET_TESTBED_operation_queue_insert_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_queue_insert_()

void GNUNET_TESTBED_operation_queue_insert_ ( struct OperationQueue queue,
struct GNUNET_TESTBED_Operation op 
)

Add an operation to a queue.

An operation can be in multiple queues at once. Once the operation is inserted into all the queues GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start waiting for the operation to become active.

Parameters
queuequeue to add the operation to
opoperation to add to the queue

An operation can be in multiple queues at once. Once the operation is inserted into all the queues GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start waiting for the operation to become active. The operation is assumed to take 1 queue resource. Use GNUNET_TESTBED_operation_queue_insert2_() if it requires more than 1

Parameters
queuequeue to add the operation to
opoperation to add to the queue

Definition at line 1218 of file testbed_api_operations.c.

1220 {
1222 }
void GNUNET_TESTBED_operation_queue_insert2_(struct OperationQueue *queue, struct GNUNET_TESTBED_Operation *op, unsigned int nres)
Add an operation to a queue.

References GNUNET_TESTBED_operation_queue_insert2_(), op, and queue().

Referenced by GNUNET_TESTBED_controller_link(), GNUNET_TESTBED_get_slave_config_(), GNUNET_TESTBED_get_statistics(), GNUNET_TESTBED_host_queue_oc_(), GNUNET_TESTBED_overlay_configure_topology_va(), GNUNET_TESTBED_peer_create(), GNUNET_TESTBED_peer_destroy(), GNUNET_TESTBED_peer_get_information(), GNUNET_TESTBED_peer_manage_service(), GNUNET_TESTBED_peer_start(), GNUNET_TESTBED_peer_stop(), GNUNET_TESTBED_peer_update_configuration(), GNUNET_TESTBED_service_connect(), GNUNET_TESTBED_shutdown_peers(), GST_connection_pool_get_handle(), and GST_neighbour_get_connection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_begin_wait_()

void GNUNET_TESTBED_operation_begin_wait_ ( struct GNUNET_TESTBED_Operation op)

Marks the given operation as waiting on the queues.

Once all queues permit the operation to become active, the operation will be activated. The actual activation will occur in a separate task (thus allowing multiple queue insertions to be made without having the first one instantly trigger the operation if the first queue has sufficient resources).

Parameters
opthe operation to marks as waiting

Definition at line 1235 of file testbed_api_operations.c.

1236 {
1237  GNUNET_assert (NULL == op->rq_entry);
1239  (void) check_readiness (op);
1240 }
static int check_readiness(struct GNUNET_TESTBED_Operation *op)
Checks for the readiness of an operation and schedules a operation start task.
static void change_state(struct GNUNET_TESTBED_Operation *op, enum OperationState state)
Changes the state of the operation while moving its associated queue entries in the operation's opera...
@ OP_STATE_WAITING
The operation is currently waiting for resources.

References change_state(), check_readiness(), GNUNET_assert, op, and OP_STATE_WAITING.

Referenced by GNUNET_TESTBED_controller_link(), GNUNET_TESTBED_get_slave_config_(), GNUNET_TESTBED_get_statistics(), GNUNET_TESTBED_overlay_configure_topology_va(), GNUNET_TESTBED_overlay_connect(), GNUNET_TESTBED_peer_create(), GNUNET_TESTBED_peer_destroy(), GNUNET_TESTBED_peer_get_information(), GNUNET_TESTBED_peer_manage_service(), GNUNET_TESTBED_peer_start(), GNUNET_TESTBED_peer_stop(), GNUNET_TESTBED_peer_update_configuration(), GNUNET_TESTBED_service_connect(), GNUNET_TESTBED_shutdown_peers(), GST_connection_pool_get_handle(), and GST_neighbour_get_connection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_create_()

struct GNUNET_TESTBED_Operation* GNUNET_TESTBED_operation_create_ ( void *  cls,
OperationStart  start,
OperationRelease  release 
)

Create an 'operation' to be performed.

Parameters
clsclosure for the callbacks
startfunction to call to start the operation
releasefunction to call to close down the operation
Returns
handle to the operation

Definition at line 1028 of file testbed_api_operations.c.

1030 {
1031  struct GNUNET_TESTBED_Operation *op;
1032 
1034  op->start = start;
1035  op->state = OP_STATE_INIT;
1036  op->release = release;
1037  op->cb_cls = cls;
1038  return op;
1039 }
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
Opaque handle to an abstract operation to be executed by the testing framework.
OperationRelease release
Function to call to clean up after the operation (which may or may not have been started yet).
@ OP_STATE_INIT
The operation is just created and is in initial state.

References GNUNET_new, op, OP_STATE_INIT, GNUNET_TESTBED_Operation::release, and start.

Referenced by GNUNET_TESTBED_controller_link(), GNUNET_TESTBED_get_slave_config_(), GNUNET_TESTBED_get_statistics(), GNUNET_TESTBED_overlay_configure_topology_va(), GNUNET_TESTBED_overlay_connect(), GNUNET_TESTBED_peer_create(), GNUNET_TESTBED_peer_destroy(), GNUNET_TESTBED_peer_get_information(), GNUNET_TESTBED_peer_manage_service(), GNUNET_TESTBED_peer_start(), GNUNET_TESTBED_peer_stop(), GNUNET_TESTBED_peer_update_configuration(), GNUNET_TESTBED_service_connect(), GNUNET_TESTBED_shutdown_peers(), GST_connection_pool_get_handle(), and GST_neighbour_get_connection().

Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_release_()

void GNUNET_TESTBED_operation_release_ ( struct GNUNET_TESTBED_Operation op)

An operation is 'done' (was cancelled or finished); remove it from the queues and release associated resources.

Parameters
opoperation that finished

Definition at line 1296 of file testbed_api_operations.c.

1297 {
1298  struct QueueEntry *entry;
1299  struct OperationQueue *opq;
1300  unsigned int i;
1301 
1302  if (OP_STATE_INIT == op->state)
1303  {
1304  GNUNET_free (op);
1305  return;
1306  }
1307  if (OP_STATE_READY == op->state)
1308  rq_remove (op);
1309  if (OP_STATE_INACTIVE == op->state) /* Activate the operation if inactive */
1311  if (OP_STATE_ACTIVE == op->state)
1312  update_tslots (op);
1313  GNUNET_assert (NULL != op->queues);
1314  GNUNET_assert (NULL != op->qentries);
1315  for (i = 0; i < op->nqueues; i++)
1316  {
1317  entry = op->qentries[i];
1318  remove_queue_entry (op, i);
1319  opq = op->queues[i];
1320  switch (op->state)
1321  {
1322  case OP_STATE_INIT:
1323  case OP_STATE_INACTIVE:
1324  GNUNET_assert (0);
1325  break;
1326 
1327  case OP_STATE_WAITING:
1328  break;
1329 
1330  case OP_STATE_ACTIVE:
1331  case OP_STATE_READY:
1332  GNUNET_assert (0 != opq->active);
1333  GNUNET_assert (opq->active >= entry->nres);
1334  opq->active -= entry->nres;
1335  recheck_waiting (opq);
1336  break;
1337  }
1338  GNUNET_free (entry);
1339  }
1340  GNUNET_free (op->qentries);
1341  GNUNET_free (op->queues);
1342  GNUNET_free (op->nres);
1343  if (NULL != op->release)
1344  op->release (op->cb_cls);
1345  GNUNET_free (op);
1346 }
#define GNUNET_free(ptr)
Wrapper around free.
unsigned int active
Number of operations that are currently active in this queue.
unsigned int nres
How many units of resources does the operation need.
void GNUNET_TESTBED_operation_activate_(struct GNUNET_TESTBED_Operation *op)
Marks and inactive operation as active.
static void update_tslots(struct GNUNET_TESTBED_Operation *op)
update tslots with the operation's completion time.
static void rq_remove(struct GNUNET_TESTBED_Operation *op)
Removes an operation from the ready queue.
static void remove_queue_entry(struct GNUNET_TESTBED_Operation *op, unsigned int index)
Removes a queue entry of an operation from one of the operation queues' lists depending on the state ...
@ OP_STATE_ACTIVE
The operation has started and is active.
@ OP_STATE_READY
The operation is ready to be started.
@ OP_STATE_INACTIVE
The operation is inactive.

References OperationQueue::active, GNUNET_assert, GNUNET_free, GNUNET_TESTBED_operation_activate_(), QueueEntry::nres, op, OP_STATE_ACTIVE, OP_STATE_INACTIVE, OP_STATE_INIT, OP_STATE_READY, OP_STATE_WAITING, recheck_waiting(), remove_queue_entry(), rq_remove(), and update_tslots().

Referenced by check_readiness(), GNUNET_TESTBED_operation_done(), and GST_neighbour_list_clean().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_inactivate_()

void GNUNET_TESTBED_operation_inactivate_ ( struct GNUNET_TESTBED_Operation op)

Marks an active operation as inactive - the operation will be kept in a ready-to-be-released state and continues to hold resources until another operation contents for them.

Parameters
opthe operation to be marked as inactive. The operation start callback should have been called before for this operation to mark it as inactive.

Definition at line 1253 of file testbed_api_operations.c.

1254 {
1255  struct OperationQueue **queues;
1256  size_t ms;
1257  unsigned int nqueues;
1258  unsigned int i;
1259 
1260  GNUNET_assert (OP_STATE_ACTIVE == op->state);
1262  nqueues = op->nqueues;
1263  ms = sizeof(struct OperationQueue *) * nqueues;
1264  queues = GNUNET_malloc (ms);
1265  /* Cloning is needed as the operation be released by waiting operations and
1266  hence its nqueues memory ptr will be freed */
1267  GNUNET_memcpy (queues, op->queues, ms);
1268  for (i = 0; i < nqueues; i++)
1269  recheck_waiting (queues[i]);
1270  GNUNET_free (queues);
1271 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_malloc(size)
Wrapper around malloc.

References change_state(), GNUNET_assert, GNUNET_free, GNUNET_malloc, GNUNET_memcpy, op, OP_STATE_ACTIVE, OP_STATE_INACTIVE, and recheck_waiting().

Referenced by GST_neighbour_get_connection_cancel(), and GST_neighbour_release_connection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_activate_()

void GNUNET_TESTBED_operation_activate_ ( struct GNUNET_TESTBED_Operation op)

Marks and inactive operation as active.

This function should be called to ensure that the oprelease callback will not be called until it is either marked as inactive or released.

Parameters
opthe operation to be marked as active

Definition at line 1282 of file testbed_api_operations.c.

1283 {
1284  GNUNET_assert (OP_STATE_INACTIVE == op->state);
1286 }

References change_state(), GNUNET_assert, op, OP_STATE_ACTIVE, and OP_STATE_INACTIVE.

Referenced by GNUNET_TESTBED_operation_release_(), and trigger_notifications().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTBED_operation_mark_failed()

void GNUNET_TESTBED_operation_mark_failed ( struct GNUNET_TESTBED_Operation op)

Marks an operation as failed.

Parameters
opthe operation to be marked as failed

Definition at line 1355 of file testbed_api_operations.c.

1356 {
1357  op->failed = GNUNET_YES;
1358 }

References GNUNET_YES, and op.

Referenced by handle_op_fail_event().

Here is the caller graph for this function: