aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-08-24 17:52:55 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-08-24 17:52:55 +0000
commitd78b1ed8679e564865d86e8693939c2e9ff60c75 (patch)
tree25c0f2ece22df0460a4b8d1dc124b2ee6bf54896 /src
parent00f9e9d51ce75db87e7dec55da378e1ae495d6da (diff)
downloadgnunet-d78b1ed8679e564865d86e8693939c2e9ff60c75.tar.gz
gnunet-d78b1ed8679e564865d86e8693939c2e9ff60c75.zip
peer start/stop forwarding with tests
Diffstat (limited to 'src')
-rw-r--r--src/testbed/gnunet-service-testbed.c53
-rw-r--r--src/testbed/test_testbed_api_controllerlink.c92
-rw-r--r--src/testbed/testbed_api.c14
3 files changed, 148 insertions, 11 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index 8976864f8..8e6ab2325 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -1776,6 +1776,8 @@ handle_peer_start (void *cls,
1776{ 1776{
1777 const struct GNUNET_TESTBED_PeerStartMessage *msg; 1777 const struct GNUNET_TESTBED_PeerStartMessage *msg;
1778 struct GNUNET_TESTBED_PeerEventMessage *reply; 1778 struct GNUNET_TESTBED_PeerEventMessage *reply;
1779 struct ForwardedOperationContext *fopc;
1780 struct Peer *peer;
1779 uint32_t peer_id; 1781 uint32_t peer_id;
1780 1782
1781 msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message; 1783 msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message;
@@ -1784,15 +1786,35 @@ handle_peer_start (void *cls,
1784 || (NULL == peer_list[peer_id])) 1786 || (NULL == peer_list[peer_id]))
1785 { 1787 {
1786 GNUNET_break (0); 1788 GNUNET_break (0);
1787 /* FIXME: reply with failure message or forward to slave controller */ 1789 LOG (GNUNET_ERROR_TYPE_ERROR,
1790 "Asked to start a non existent peer with id: %u\n", peer_id);
1791 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1792 return;
1793 }
1794 peer = peer_list[peer_id];
1795 if (GNUNET_YES == peer->is_remote)
1796 {
1797 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1798 GNUNET_SERVER_client_keep (client);
1799 fopc->client = client;
1800 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1801 fopc->opc =
1802 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
1803 fopc->operation_id,
1804 &msg->header,
1805 &forwarded_operation_reply_relay,
1806 fopc);
1807 fopc->timeout_task =
1808 GNUNET_SCHEDULER_add_delayed (TIMEOUT,
1809 &forwarded_operation_timeout, fopc);
1788 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1810 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1789 return; 1811 return;
1790 } 1812 }
1791 if (GNUNET_OK != 1813 if (GNUNET_OK !=
1792 GNUNET_TESTING_peer_start (peer_list[peer_id]->details.local.peer)) 1814 GNUNET_TESTING_peer_start (peer->details.local.peer))
1793 { 1815 {
1794 /* FIXME: return FAILURE message */ 1816 send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id),
1795 GNUNET_break (0); 1817 "Failed to start");
1796 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1818 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1797 return; 1819 return;
1798 } 1820 }
@@ -1822,6 +1844,8 @@ handle_peer_stop (void *cls,
1822{ 1844{
1823 const struct GNUNET_TESTBED_PeerStopMessage *msg; 1845 const struct GNUNET_TESTBED_PeerStopMessage *msg;
1824 struct GNUNET_TESTBED_PeerEventMessage *reply; 1846 struct GNUNET_TESTBED_PeerEventMessage *reply;
1847 struct ForwardedOperationContext *fopc;
1848 struct Peer *peer;
1825 uint32_t peer_id; 1849 uint32_t peer_id;
1826 1850
1827 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message; 1851 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message;
@@ -1832,8 +1856,27 @@ handle_peer_stop (void *cls,
1832 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1856 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1833 return; 1857 return;
1834 } 1858 }
1859 peer = peer_list[peer_id];
1860 if (GNUNET_YES == peer->is_remote)
1861 {
1862 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
1863 GNUNET_SERVER_client_keep (client);
1864 fopc->client = client;
1865 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
1866 fopc->opc =
1867 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.controller,
1868 fopc->operation_id,
1869 &msg->header,
1870 &forwarded_operation_reply_relay,
1871 fopc);
1872 fopc->timeout_task =
1873 GNUNET_SCHEDULER_add_delayed (TIMEOUT,
1874 &forwarded_operation_timeout, fopc);
1875 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1876 return;
1877 }
1835 if (GNUNET_OK != 1878 if (GNUNET_OK !=
1836 GNUNET_TESTING_peer_stop (peer_list[peer_id]->details.local.peer)) 1879 GNUNET_TESTING_peer_stop (peer->details.local.peer))
1837 { 1880 {
1838 /* FIXME: return FAILURE message */ 1881 /* FIXME: return FAILURE message */
1839 GNUNET_break (0); 1882 GNUNET_break (0);
diff --git a/src/testbed/test_testbed_api_controllerlink.c b/src/testbed/test_testbed_api_controllerlink.c
index 48ce2546e..a5f84b6ce 100644
--- a/src/testbed/test_testbed_api_controllerlink.c
+++ b/src/testbed/test_testbed_api_controllerlink.c
@@ -88,6 +88,26 @@ enum Stage
88 SLAVE2_PEER_CREATE_SUCCESS, 88 SLAVE2_PEER_CREATE_SUCCESS,
89 89
90 /** 90 /**
91 * Peer startup on slave 1 successful
92 */
93 SLAVE1_PEER_START_SUCCESS,
94
95 /**
96 * Peer on slave 1 successfully stopped
97 */
98 SLAVE1_PEER_STOP_SUCCESS,
99
100 /**
101 * Peer startup on slave 2 successful
102 */
103 SLAVE2_PEER_START_SUCCESS,
104
105 /**
106 * Peer on slave 2 successfully stopped
107 */
108 SLAVE2_PEER_STOP_SUCCESS,
109
110 /**
91 * Peer destroy on slave 1 successful 111 * Peer destroy on slave 1 successful
92 */ 112 */
93 SLAVE1_PEER_DESTROY_SUCCESS, 113 SLAVE1_PEER_DESTROY_SUCCESS,
@@ -200,7 +220,7 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
200 * @param tc the task context 220 * @param tc the task context
201 */ 221 */
202static void 222static void
203do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) 223do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
204{ 224{
205 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); 225 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
206 abort_task = GNUNET_SCHEDULER_NO_TASK; 226 abort_task = GNUNET_SCHEDULER_NO_TASK;
@@ -209,6 +229,31 @@ do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
209 229
210 230
211/** 231/**
232 * Task for inserting delay between tests
233 *
234 * @param
235 * @return
236 */
237static void
238delay_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
239{
240 switch (result)
241 {
242 case SLAVE1_PEER_START_SUCCESS:
243 op = GNUNET_TESTBED_peer_stop (slave1_peer);
244 GNUNET_assert (NULL != op);
245 break;
246 case SLAVE2_PEER_START_SUCCESS:
247 op = GNUNET_TESTBED_peer_stop (slave2_peer);
248 GNUNET_assert (NULL != op);
249 break;
250 default:
251 GNUNET_assert (0);
252 }
253}
254
255
256/**
212 * Functions of this signature are called when a peer has been successfully 257 * Functions of this signature are called when a peer has been successfully
213 * created 258 * created
214 * 259 *
@@ -237,7 +282,7 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
237 result = SLAVE2_PEER_CREATE_SUCCESS; 282 result = SLAVE2_PEER_CREATE_SUCCESS;
238 slave2_peer = peer; 283 slave2_peer = peer;
239 GNUNET_TESTBED_operation_done (op); 284 GNUNET_TESTBED_operation_done (op);
240 op = GNUNET_TESTBED_peer_destroy (slave1_peer); 285 op = GNUNET_TESTBED_peer_start (slave1_peer);
241 GNUNET_assert (NULL != op); 286 GNUNET_assert (NULL != op);
242 break; 287 break;
243 default: 288 default:
@@ -297,11 +342,47 @@ controller_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
297 GNUNET_assert (NULL != op); 342 GNUNET_assert (NULL != op);
298 break; 343 break;
299 case SLAVE2_PEER_CREATE_SUCCESS: 344 case SLAVE2_PEER_CREATE_SUCCESS:
345 GNUNET_assert (GNUNET_TESTBED_ET_PEER_START == event->type);
346 GNUNET_assert (event->details.peer_start.host == slave);
347 GNUNET_assert (event->details.peer_start.peer == slave1_peer);
348 GNUNET_TESTBED_operation_done (op);
349 result = SLAVE1_PEER_START_SUCCESS;
350 GNUNET_SCHEDULER_add_delayed
351 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
352 &delay_task, NULL);
353 break;
354 case SLAVE1_PEER_START_SUCCESS:
355 GNUNET_assert (GNUNET_TESTBED_ET_PEER_STOP == event->type);
356 GNUNET_assert (event->details.peer_stop.peer == slave1_peer);
357 GNUNET_TESTBED_operation_done (op);
358 result = SLAVE1_PEER_STOP_SUCCESS;
359 op = GNUNET_TESTBED_peer_start (slave2_peer);
360 GNUNET_assert (NULL != op);
361 break;
362 case SLAVE1_PEER_STOP_SUCCESS:
363 GNUNET_assert (GNUNET_TESTBED_ET_PEER_START == event->type);
364 GNUNET_assert (event->details.peer_start.host == slave2);
365 GNUNET_assert (event->details.peer_start.peer == slave2_peer);
366 GNUNET_TESTBED_operation_done (op);
367 result = SLAVE2_PEER_START_SUCCESS;
368 GNUNET_SCHEDULER_add_delayed
369 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
370 &delay_task, NULL);
371 break;
372 case SLAVE2_PEER_START_SUCCESS:
373 GNUNET_assert (GNUNET_TESTBED_ET_PEER_STOP == event->type);
374 GNUNET_assert (event->details.peer_stop.peer == slave2_peer);
375 GNUNET_TESTBED_operation_done (op);
376 result = SLAVE2_PEER_STOP_SUCCESS;
377 op = GNUNET_TESTBED_peer_destroy (slave1_peer);
378 GNUNET_assert (NULL != op);
379 break;
380 case SLAVE2_PEER_STOP_SUCCESS:
300 check_operation_success (event); 381 check_operation_success (event);
301 GNUNET_TESTBED_operation_done (op); 382 GNUNET_TESTBED_operation_done (op);
302 result = SLAVE1_PEER_DESTROY_SUCCESS; 383 result = SLAVE1_PEER_DESTROY_SUCCESS;
303 op = GNUNET_TESTBED_peer_destroy (slave2_peer); 384 op = GNUNET_TESTBED_peer_destroy (slave2_peer);
304 GNUNET_assert (NULL != slave2_peer); 385 GNUNET_assert (NULL != op);
305 break; 386 break;
306 case SLAVE1_PEER_DESTROY_SUCCESS: 387 case SLAVE1_PEER_DESTROY_SUCCESS:
307 check_operation_success (event); 388 check_operation_success (event);
@@ -438,13 +519,14 @@ int main (int argc, char **argv)
438 GNUNET_assert (GNUNET_SYSERR != ret); 519 GNUNET_assert (GNUNET_SYSERR != ret);
439 (void) usleep (300); 520 (void) usleep (300);
440 } while (GNUNET_NO == ret); 521 } while (GNUNET_NO == ret);
522 GNUNET_OS_process_destroy (auxp);
441 if (0 != code) 523 if (0 != code)
442 { 524 {
443 (void) printf ("Unable to run the test as this system is not configured " 525 (void) printf ("Unable to run the test as this system is not configured "
444 "to use password less SSH logins to localhost.\n" 526 "to use password less SSH logins to localhost.\n"
445 "Marking test as successful\n"); 527 "Marking test as successful\n");
446 return 0; 528 return 0;
447 } 529 }
448 result = INIT; 530 result = INIT;
449 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, 531 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
450 "test_testbed_api_controllerlink", "nohelp", options, &run, 532 "test_testbed_api_controllerlink", "nohelp", options, &run,
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index ff4509f12..bf459b2bd 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -370,7 +370,7 @@ handle_peer_create_success (struct GNUNET_TESTBED_Controller *c,
370 GNUNET_free (fo_data); 370 GNUNET_free (fo_data);
371 GNUNET_free (opc); 371 GNUNET_free (opc);
372 return GNUNET_YES; 372 return GNUNET_YES;
373 } 373 }
374 GNUNET_assert (OP_PEER_CREATE == opc->type); 374 GNUNET_assert (OP_PEER_CREATE == opc->type);
375 GNUNET_assert (NULL != opc->data); 375 GNUNET_assert (NULL != opc->data);
376 data = opc->data; 376 data = opc->data;
@@ -415,6 +415,18 @@ handle_peer_event (struct GNUNET_TESTBED_Controller *c,
415 LOG_DEBUG ("Operation not found\n"); 415 LOG_DEBUG ("Operation not found\n");
416 return GNUNET_YES; 416 return GNUNET_YES;
417 } 417 }
418 if (OP_FORWARDED == opc->type)
419 {
420 struct ForwardedOperationData *fo_data;
421
422 fo_data = opc->data;
423 if (NULL != fo_data->cc)
424 fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg);
425 GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc);
426 GNUNET_free (fo_data);
427 GNUNET_free (opc);
428 return GNUNET_YES;
429 }
418 GNUNET_assert ((OP_PEER_START == opc->type) || (OP_PEER_STOP == opc->type)); 430 GNUNET_assert ((OP_PEER_START == opc->type) || (OP_PEER_STOP == opc->type));
419 peer = opc->data; 431 peer = opc->data;
420 GNUNET_assert (NULL != peer); 432 GNUNET_assert (NULL != peer);