From e3e2e5839cc3f7c1efb4bee1826f185169b034fa Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Wed, 10 Oct 2012 10:59:34 +0000 Subject: operation id generation from controller host id and internal counter --- src/testbed/testbed_api.c | 25 ++++++++++++++++++++++--- src/testbed/testbed_api.h | 13 ++++++++++++- src/testbed/testbed_api_peers.c | 12 ++++++------ src/testbed/testbed_api_services.c | 2 +- 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 9bed63a97..2dab869dc 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c @@ -959,7 +959,7 @@ handle_need_controller_config (struct GNUNET_TESTBED_Controller *c, uint64_t sub_op_id; GNUNET_assert (NULL == oc_data->sub_opc); - sub_op_id = oc_data->p1->controller->operation_counter++; + sub_op_id = GNUNET_TESTBED_get_next_op_id (oc_data->p1->controller); get_cfg_msg = GNUNET_TESTBED_generate_slavegetconfig_msg_ (sub_op_id, GNUNET_TESTBED_host_get_id_ (oc_data->p2->host)); @@ -1873,7 +1873,7 @@ GNUNET_TESTBED_controller_link_2 (void *op_cls, opc->c = master; opc->data = data; opc->type = OP_LINK_CONTROLLERS; - opc->id = master->operation_counter++; + opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); opc->state = OPC_STATE_INIT; msg->operation_id = GNUNET_htonll (opc->id); opc->op = @@ -2003,7 +2003,7 @@ GNUNET_TESTBED_get_slave_config (void *op_cls, opc = GNUNET_malloc (sizeof (struct OperationContext)); opc->state = OPC_STATE_INIT; opc->c = master; - opc->id = master->operation_counter++; + opc->id = GNUNET_TESTBED_get_next_op_id (master); opc->type = OP_GET_SLAVE_CONFIG; opc->data = data; opc->op = @@ -2220,4 +2220,23 @@ GNUNET_TESTBED_parse_error_string_ (const struct return emsg; } + +/** + * Function to return the operation id for a controller. The operation id is + * created from the controllers host id and its internal operation counter. + * + * @param controller the handle to the controller whose operation id has to be incremented + * @return the incremented operation id. + */ +uint64_t +GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller) +{ + uint64_t op_id; + + op_id = (uint64_t) GNUNET_TESTBED_host_get_id_ (controller->host); + op_id = op_id << 32; + op_id |= (uint64_t) controller->operation_counter++; + return op_id; +} + /* end of testbed_api.c */ diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h index 020d951a2..251b8a56a 100644 --- a/src/testbed/testbed_api.h +++ b/src/testbed/testbed_api.h @@ -299,7 +299,7 @@ struct GNUNET_TESTBED_Controller /** * The operation id counter. use current value and increment */ - uint64_t operation_counter; + uint32_t operation_counter; /** * The controller event mask @@ -424,5 +424,16 @@ GNUNET_TESTBED_parse_error_string_ (const struct GNUNET_TESTBED_OperationFailureEventMessage *msg); + +/** + * Function to return the operation id for a controller. The operation id is + * created from the controllers host id and its internal operation counter. + * + * @param controller the handle to the controller whose operation id has to be incremented + * @return the incremented operation id. + */ +uint64_t +GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller *controller); + #endif /* end of testbed_api.h */ diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c index ab54cecfa..f9d0929ef 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c @@ -439,7 +439,7 @@ GNUNET_TESTBED_peer_create_with_id_ (uint32_t unique_id, opc = GNUNET_malloc (sizeof (struct OperationContext)); opc->c = controller; opc->data = data; - opc->id = controller->operation_counter++; + opc->id = GNUNET_TESTBED_get_next_op_id (controller); opc->type = OP_PEER_CREATE; opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_create, @@ -515,7 +515,7 @@ GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer, opc = GNUNET_malloc (sizeof (struct OperationContext)); opc->c = peer->controller; opc->data = data; - opc->id = opc->c->operation_counter++; + opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); opc->type = OP_PEER_START; opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_start, @@ -551,7 +551,7 @@ GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer, opc = GNUNET_malloc (sizeof (struct OperationContext)); opc->c = peer->controller; opc->data = data; - opc->id = opc->c->operation_counter++; + opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); opc->type = OP_PEER_STOP; opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_stop, @@ -595,7 +595,7 @@ GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, opc->c = peer->controller; opc->data = data; opc->type = OP_PEER_INFO; - opc->id = opc->c->operation_counter++; + opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_getinfo, &oprelease_peer_getinfo); @@ -641,7 +641,7 @@ GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer) opc = GNUNET_malloc (sizeof (struct OperationContext)); opc->data = peer; opc->c = peer->controller; - opc->id = peer->controller->operation_counter++; + opc->id = GNUNET_TESTBED_get_next_op_id (peer->controller); opc->type = OP_PEER_DESTROY; opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_destroy, @@ -710,7 +710,7 @@ GNUNET_TESTBED_overlay_connect (void *op_cls, opc = GNUNET_malloc (sizeof (struct OperationContext)); opc->data = data; opc->c = p1->controller; - opc->id = opc->c->operation_counter++; + opc->id = GNUNET_TESTBED_get_next_op_id (opc->c); opc->type = OP_OVERLAY_CONNECT; opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_overlay_connect, diff --git a/src/testbed/testbed_api_services.c b/src/testbed/testbed_api_services.c index 53a2bdc3c..16ea06077 100644 --- a/src/testbed/testbed_api_services.c +++ b/src/testbed/testbed_api_services.c @@ -190,7 +190,7 @@ opstart_service_connect (void *cls) GNUNET_assert (NULL != data); GNUNET_assert (NULL != data->peer); c = data->peer->controller; - op_id = c->operation_counter++; + op_id = GNUNET_TESTBED_get_next_op_id (c); msg = GNUNET_TESTBED_generate_peergetconfig_msg_ (data->peer->unique_id, op_id); data->opc = -- cgit v1.2.3