aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-07-31 18:48:06 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-07-31 18:48:06 +0000
commit94c672c467be073e9b62fe2c1b45267163f74db5 (patch)
tree837418d6d890d930e3444c48f62554c394301a38 /src/testbed
parente7cbb8d414b22af3d41759170e9bfad198dd9774 (diff)
downloadgnunet-94c672c467be073e9b62fe2c1b45267163f74db5.tar.gz
gnunet-94c672c467be073e9b62fe2c1b45267163f74db5.zip
peer start/stop with new operations handling
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/testbed_api.c57
-rw-r--r--src/testbed/testbed_api_operations.c5
-rw-r--r--src/testbed/testbed_api_peers.c138
3 files changed, 135 insertions, 65 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index cb7180882..21ade1cea 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -156,6 +156,28 @@ struct GNUNET_TESTBED_HostRegistrationHandle
156 156
157 157
158/** 158/**
159 * Returns the operation context with the given id if found in the Operation
160 * context queues of the controller
161 *
162 * @param c the controller whose queues are searched
163 * @param id the id which has to be checked
164 * @return the matching operation context; NULL if no match found
165 */
166static struct OperationContext *
167find_opc (const struct GNUNET_TESTBED_Controller *c, const uint64_t id)
168{
169 struct OperationContext *opc;
170
171 for (opc = c->ocq_head; NULL != opc; opc = opc->next)
172 {
173 if (id == opc->id)
174 return opc;
175 }
176 return NULL;
177}
178
179
180/**
159 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from 181 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from
160 * controller (testbed service) 182 * controller (testbed service)
161 * 183 *
@@ -230,12 +252,7 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c,
230 252
231 op_id = GNUNET_ntohll (msg->operation_id); 253 op_id = GNUNET_ntohll (msg->operation_id);
232 LOG_DEBUG ("Operation %ul successful\n", op_id); 254 LOG_DEBUG ("Operation %ul successful\n", op_id);
233 for (opc = c->ocq_head; NULL != opc; opc = opc->next) 255 if (NULL == (opc = find_opc (c, op_id)))
234 {
235 if (opc->id == op_id)
236 break;
237 }
238 if (NULL == opc)
239 { 256 {
240 LOG_DEBUG ("Operation not found\n"); 257 LOG_DEBUG ("Operation not found\n");
241 return GNUNET_YES; 258 return GNUNET_YES;
@@ -302,12 +319,7 @@ handle_peer_create_success (struct GNUNET_TESTBED_Controller *c,
302 GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage) 319 GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage)
303 == ntohs (msg->header.size)); 320 == ntohs (msg->header.size));
304 op_id = GNUNET_ntohll (msg->operation_id); 321 op_id = GNUNET_ntohll (msg->operation_id);
305 for (opc = c->ocq_head; NULL != opc; opc = opc->next) 322 if (NULL == (opc = find_opc (c, op_id)))
306 {
307 if (opc->id == op_id)
308 break;
309 }
310 if (NULL == opc)
311 { 323 {
312 LOG_DEBUG ("Operation context for PeerCreateSuccessEvent not found\n"); 324 LOG_DEBUG ("Operation context for PeerCreateSuccessEvent not found\n");
313 return GNUNET_YES; 325 return GNUNET_YES;
@@ -340,7 +352,7 @@ static int
340handle_peer_event (struct GNUNET_TESTBED_Controller *c, 352handle_peer_event (struct GNUNET_TESTBED_Controller *c,
341 const struct GNUNET_TESTBED_PeerEventMessage *msg) 353 const struct GNUNET_TESTBED_PeerEventMessage *msg)
342{ 354{
343 struct GNUNET_TESTBED_Operation *op; 355 struct OperationContext *opc;
344 struct GNUNET_TESTBED_Peer *peer; 356 struct GNUNET_TESTBED_Peer *peer;
345 struct GNUNET_TESTBED_EventInformation event; 357 struct GNUNET_TESTBED_EventInformation event;
346 uint64_t op_id; 358 uint64_t op_id;
@@ -348,18 +360,13 @@ handle_peer_event (struct GNUNET_TESTBED_Controller *c,
348 GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerEventMessage) 360 GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerEventMessage)
349 == ntohs (msg->header.size)); 361 == ntohs (msg->header.size));
350 op_id = GNUNET_ntohll (msg->operation_id); 362 op_id = GNUNET_ntohll (msg->operation_id);
351 for (op = c->op_head; NULL != op; op = op->next) 363 if (NULL == (opc = find_opc (c, op_id)))
352 {
353 if (op->operation_id == op_id)
354 break;
355 }
356 if (NULL == op)
357 { 364 {
358 LOG_DEBUG ("Operation not found\n"); 365 LOG_DEBUG ("Operation not found\n");
359 return GNUNET_YES; 366 return GNUNET_YES;
360 } 367 }
361 GNUNET_assert ((OP_PEER_START == op->type) || (OP_PEER_STOP == op->type)); 368 GNUNET_assert ((OP_PEER_START == opc->type) || (OP_PEER_STOP == opc->type));
362 peer = op->data; 369 peer = opc->data;
363 GNUNET_assert (NULL != peer); 370 GNUNET_assert (NULL != peer);
364 event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type); 371 event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type);
365 switch (event.type) 372 switch (event.type)
@@ -376,7 +383,6 @@ handle_peer_event (struct GNUNET_TESTBED_Controller *c,
376 default: 383 default:
377 GNUNET_assert (0); /* We should never reach this state */ 384 GNUNET_assert (0); /* We should never reach this state */
378 } 385 }
379 GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op);
380 if (0 != ((GNUNET_TESTBED_ET_PEER_START | GNUNET_TESTBED_ET_PEER_STOP) 386 if (0 != ((GNUNET_TESTBED_ET_PEER_START | GNUNET_TESTBED_ET_PEER_STOP)
381 & c->event_mask)) 387 & c->event_mask))
382 { 388 {
@@ -1343,14 +1349,11 @@ GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation)
1343 switch (operation->type) 1349 switch (operation->type)
1344 { 1350 {
1345 case OP_PEER_CREATE: 1351 case OP_PEER_CREATE:
1346 GNUNET_TESTBED_operation_release_ (operation);
1347 return;
1348 case OP_PEER_DESTROY: 1352 case OP_PEER_DESTROY:
1349 GNUNET_TESTBED_operation_release_ (operation);
1350 return;
1351 case OP_PEER_START: 1353 case OP_PEER_START:
1352 case OP_PEER_STOP: 1354 case OP_PEER_STOP:
1353 break; 1355 GNUNET_TESTBED_operation_release_ (operation);
1356 return;
1354 case OP_PEER_INFO: 1357 case OP_PEER_INFO:
1355 { 1358 {
1356 struct PeerInfoData2 *data; 1359 struct PeerInfoData2 *data;
diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c
index 6ad15e22e..a3e3c30b1 100644
--- a/src/testbed/testbed_api_operations.c
+++ b/src/testbed/testbed_api_operations.c
@@ -73,6 +73,9 @@ struct OperationQueue
73}; 73};
74 74
75 75
76/**
77 * Operation state
78 */
76enum OperationState 79enum OperationState
77 { 80 {
78 /** 81 /**
@@ -86,8 +89,6 @@ enum OperationState
86 OP_STATE_STARTED, 89 OP_STATE_STARTED,
87 }; 90 };
88 91
89
90
91 92
92/** 93/**
93 * Opaque handle to an abstract operation to be executed by the testing framework. 94 * Opaque handle to an abstract operation to be executed by the testing framework.
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index 4f9fa768c..ca4e46e39 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -112,8 +112,7 @@ opstart_peer_destroy (void *cls)
112 msg->operation_id = GNUNET_htonll (opc->id); 112 msg->operation_id = GNUNET_htonll (opc->id);
113 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, 113 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head,
114 opc->c->ocq_tail, opc); 114 opc->c->ocq_tail, opc);
115 GNUNET_TESTBED_queue_message_ (peer->controller, 115 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
116 (struct GNUNET_MessageHeader *) msg);
117} 116}
118 117
119 118
@@ -133,6 +132,87 @@ oprelease_peer_destroy (void *cls)
133 132
134 133
135/** 134/**
135 * Function to called when a peer start operation is ready
136 *
137 * @param cls the closure from GNUNET_TESTBED_operation_create_()
138 */
139static void
140opstart_peer_start (void *cls)
141{
142 struct OperationContext *opc = cls;
143 struct GNUNET_TESTBED_PeerStartMessage *msg;
144 struct GNUNET_TESTBED_Peer *peer;
145
146 GNUNET_assert (OP_PEER_START == opc->type);
147 GNUNET_assert (NULL != opc->data);
148 peer = opc->data;
149 GNUNET_assert ((PS_CREATED == peer->state) || (PS_STOPPED == peer->state));
150 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStartMessage));
151 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStartMessage));
152 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER);
153 msg->peer_id = htonl (peer->unique_id);
154 msg->operation_id = GNUNET_htonll (opc->id);
155 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
156 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
157}
158
159
160/**
161 * Callback which will be called when peer start type operation is released
162 *
163 * @param cls the closure from GNUNET_TESTBED_operation_create_()
164 */
165static void
166oprelease_peer_start (void *cls)
167{
168 struct OperationContext *opc = cls;
169
170 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
171 GNUNET_free (opc);
172}
173
174
175/**
176 * Function to called when a peer stop operation is ready
177 *
178 * @param cls the closure from GNUNET_TESTBED_operation_create_()
179 */
180static void
181opstart_peer_stop (void *cls)
182{
183 struct OperationContext *opc = cls;
184 struct GNUNET_TESTBED_PeerStopMessage *msg;
185 struct GNUNET_TESTBED_Peer *peer;
186
187 GNUNET_assert (NULL != opc->data);
188 peer = opc->data;
189 GNUNET_assert (PS_STARTED == peer->state);
190 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
191 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER);
192 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
193 msg->peer_id = htonl (peer->unique_id);
194 msg->operation_id = GNUNET_htonll (opc->id);
195 GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc);
196 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
197}
198
199
200/**
201 * Callback which will be called when peer stop type operation is released
202 *
203 * @param cls the closure from GNUNET_TESTBED_operation_create_()
204 */
205static void
206oprelease_peer_stop (void *cls)
207{
208 struct OperationContext *opc = cls;
209
210 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
211 GNUNET_free (opc);
212}
213
214
215/**
136 * Lookup a peer by ID. 216 * Lookup a peer by ID.
137 * 217 *
138 * @param id global peer ID assigned to the peer 218 * @param id global peer ID assigned to the peer
@@ -268,24 +348,17 @@ GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller,
268struct GNUNET_TESTBED_Operation * 348struct GNUNET_TESTBED_Operation *
269GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer) 349GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer)
270{ 350{
271 struct GNUNET_TESTBED_Operation *op; 351 struct OperationContext *opc;
272 struct GNUNET_TESTBED_PeerStartMessage *msg;
273 352
274 GNUNET_assert ((PS_CREATED == peer->state) || (PS_STOPPED == peer->state)); 353 opc = GNUNET_malloc (sizeof (struct OperationContext));
275 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); 354 opc->c = peer->controller;
276 op->operation_id = peer->controller->operation_counter++; 355 opc->data = peer;
277 op->controller = peer->controller; 356 opc->id = opc->c->operation_counter++;
278 op->type = OP_PEER_START; 357 opc->type = OP_PEER_START;
279 op->data = peer; 358 opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_start,
280 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStartMessage)); 359 &oprelease_peer_start);
281 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStartMessage)); 360 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_peer_create, opc->op);
282 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER); 361 return opc->op;
283 msg->peer_id = htonl (peer->unique_id);
284 msg->operation_id = GNUNET_htonll (op->operation_id);
285 GNUNET_CONTAINER_DLL_insert_tail (peer->controller->op_head,
286 peer->controller->op_tail, op);
287 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
288 return op;
289} 362}
290 363
291 364
@@ -300,24 +373,17 @@ GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer)
300struct GNUNET_TESTBED_Operation * 373struct GNUNET_TESTBED_Operation *
301GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer) 374GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer)
302{ 375{
303 struct GNUNET_TESTBED_Operation *op; 376 struct OperationContext *opc;
304 struct GNUNET_TESTBED_PeerStopMessage *msg;
305 377
306 GNUNET_assert (PS_STARTED == peer->state); 378 opc = GNUNET_malloc (sizeof (struct OperationContext));
307 op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); 379 opc->c = peer->controller;
308 op->operation_id = peer->controller->operation_counter++; 380 opc->data = peer;
309 op->controller = peer->controller; 381 opc->id = opc->c->operation_counter++;
310 op->type = OP_PEER_STOP; 382 opc->type = OP_PEER_STOP;
311 op->data = peer; 383 opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_stop,
312 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStopMessage)); 384 &oprelease_peer_stop);
313 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER); 385 GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_peer_create, opc->op);
314 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStopMessage)); 386 return opc->op;
315 msg->peer_id = htonl (peer->unique_id);
316 msg->operation_id = GNUNET_htonll (op->operation_id);
317 GNUNET_CONTAINER_DLL_insert_tail (peer->controller->op_head,
318 peer->controller->op_tail, op);
319 GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header);
320 return op;
321} 387}
322 388
323 389