GNUnet  0.19.4
testbed_api_operations.h File Reference

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

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

Definition at line 1043 of file testbed_api_operations.c.

1045 {
1046  struct OperationQueue *queue;
1047  struct FeedbackCtx *fctx;
1048 
1049  queue = GNUNET_new (struct OperationQueue);
1050  queue->type = type;
1052  {
1053  queue->max_active = max_active;
1054  }
1055  else
1056  {
1057  fctx = GNUNET_new (struct FeedbackCtx);
1058  fctx->max_active_bound = max_active;
1060  queue->fctx = fctx;
1062  }
1063  return queue;
1064 }
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 1096 of file testbed_api_operations.c.

1097 {
1098  if (GNUNET_YES != is_queue_empty (queue))
1099  {
1100  GNUNET_assert (0 == queue->expired); /* Are you calling twice on same queue? */
1101  queue->expired = 1;
1103  return;
1104  }
1105  queue_destroy (queue);
1106 }
@ GNUNET_YES
#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 1117 of file testbed_api_operations.c.

1118 {
1119  if (GNUNET_NO == is_queue_empty (queue))
1120  return GNUNET_NO;
1122  return GNUNET_YES;
1123 }
@ GNUNET_NO
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 1158 of file testbed_api_operations.c.

1160 {
1161  struct QueueEntry *entry;
1162 
1163  queue->max_active = max_active;
1164  queue->overload = 0;
1165  while ((queue->active > queue->max_active)
1166  && (NULL != (entry = queue->rq_head)))
1167  defer (entry->op);
1169 }
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 1184 of file testbed_api_operations.c.

1187 {
1188  unsigned int qsize;
1189 
1190  GNUNET_assert (0 < nres);
1191  qsize = op->nqueues;
1192  GNUNET_array_append (op->queues, op->nqueues, queue);
1193  GNUNET_array_append (op->nres, qsize, nres);
1194  GNUNET_assert (qsize == op->nqueues);
1195 }
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 1210 of file testbed_api_operations.c.

1212 {
1214 }
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 1227 of file testbed_api_operations.c.

1228 {
1229  GNUNET_assert (NULL == op->rq_entry);
1231  (void) check_readiness (op);
1232 }
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 1288 of file testbed_api_operations.c.

1289 {
1290  struct QueueEntry *entry;
1291  struct OperationQueue *opq;
1292  unsigned int i;
1293 
1294  if (OP_STATE_INIT == op->state)
1295  {
1296  GNUNET_free (op);
1297  return;
1298  }
1299  if (OP_STATE_READY == op->state)
1300  rq_remove (op);
1301  if (OP_STATE_INACTIVE == op->state) /* Activate the operation if inactive */
1303  if (OP_STATE_ACTIVE == op->state)
1304  update_tslots (op);
1305  GNUNET_assert (NULL != op->queues);
1306  GNUNET_assert (NULL != op->qentries);
1307  for (i = 0; i < op->nqueues; i++)
1308  {
1309  entry = op->qentries[i];
1310  remove_queue_entry (op, i);
1311  opq = op->queues[i];
1312  switch (op->state)
1313  {
1314  case OP_STATE_INIT:
1315  case OP_STATE_INACTIVE:
1316  GNUNET_assert (0);
1317  break;
1318 
1319  case OP_STATE_WAITING:
1320  break;
1321 
1322  case OP_STATE_ACTIVE:
1323  case OP_STATE_READY:
1324  GNUNET_assert (0 != opq->active);
1325  GNUNET_assert (opq->active >= entry->nres);
1326  opq->active -= entry->nres;
1327  recheck_waiting (opq);
1328  break;
1329  }
1330  GNUNET_free (entry);
1331  }
1332  GNUNET_free (op->qentries);
1333  GNUNET_free (op->queues);
1334  GNUNET_free (op->nres);
1335  if (NULL != op->release)
1336  op->release (op->cb_cls);
1337  GNUNET_free (op);
1338 }
#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 1245 of file testbed_api_operations.c.

1246 {
1247  struct OperationQueue **queues;
1248  size_t ms;
1249  unsigned int nqueues;
1250  unsigned int i;
1251 
1252  GNUNET_assert (OP_STATE_ACTIVE == op->state);
1254  nqueues = op->nqueues;
1255  ms = sizeof(struct OperationQueue *) * nqueues;
1256  queues = GNUNET_malloc (ms);
1257  /* Cloning is needed as the operation be released by waiting operations and
1258  hence its nqueues memory ptr will be freed */
1259  GNUNET_memcpy (queues, op->queues, ms);
1260  for (i = 0; i < nqueues; i++)
1261  recheck_waiting (queues[i]);
1262  GNUNET_free (queues);
1263 }
#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 1274 of file testbed_api_operations.c.

1275 {
1276  GNUNET_assert (OP_STATE_INACTIVE == op->state);
1278 }

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 1347 of file testbed_api_operations.c.

1348 {
1349  op->failed = GNUNET_YES;
1350 }

References GNUNET_YES, and op.

Referenced by handle_op_fail_event().

Here is the caller graph for this function: