diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-10-02 14:54:16 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-10-02 14:54:16 +0000 |
commit | 7b32b05be57fd86b25dab886c363c998515d107a (patch) | |
tree | 4d39cc33d156106c637964c9737487d9a4f5cf78 /src/testbed/test_testbed_api_controllerlink.c | |
parent | 79d6a55f151f2913a48942c5d3ad5a1cde2f4ce8 (diff) | |
download | gnunet-7b32b05be57fd86b25dab886c363c998515d107a.tar.gz gnunet-7b32b05be57fd86b25dab886c363c998515d107a.zip |
test case for lateral connections between controllers
Diffstat (limited to 'src/testbed/test_testbed_api_controllerlink.c')
-rw-r--r-- | src/testbed/test_testbed_api_controllerlink.c | 213 |
1 files changed, 162 insertions, 51 deletions
diff --git a/src/testbed/test_testbed_api_controllerlink.c b/src/testbed/test_testbed_api_controllerlink.c index 2bb3f8d27..2a9add64a 100644 --- a/src/testbed/test_testbed_api_controllerlink.c +++ b/src/testbed/test_testbed_api_controllerlink.c | |||
@@ -24,6 +24,19 @@ | |||
24 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | 24 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> |
25 | */ | 25 | */ |
26 | 26 | ||
27 | |||
28 | /** | ||
29 | * The controller architecture we try to achieve in this test case: | ||
30 | * | ||
31 | * Master Controller | ||
32 | * // \\ | ||
33 | * // \\ | ||
34 | * Slave Controller 1---------Slave Controller 3 | ||
35 | * || | ||
36 | * || | ||
37 | * Slave Controller 2 | ||
38 | */ | ||
39 | |||
27 | #include "platform.h" | 40 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 41 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_testing_lib-new.h" | 42 | #include "gnunet_testing_lib-new.h" |
@@ -47,75 +60,96 @@ | |||
47 | enum Stage | 60 | enum Stage |
48 | { | 61 | { |
49 | 62 | ||
50 | /** | 63 | /** |
51 | * Initial stage | 64 | * Initial stage |
52 | */ | 65 | */ |
53 | INIT, | 66 | INIT, |
54 | 67 | ||
55 | /** | 68 | /** |
56 | * Master controller has started | 69 | * Master controller has started |
57 | */ | 70 | */ |
58 | MASTER_STARTED, | 71 | MASTER_STARTED, |
59 | 72 | ||
60 | /** | 73 | /** |
61 | * The first slave has been registered at master controller | 74 | * The first slave has been registered at master controller |
62 | */ | 75 | */ |
63 | SLAVE1_REGISTERED, | 76 | SLAVE1_REGISTERED, |
64 | 77 | ||
65 | /** | 78 | /** |
66 | * The second slave has been registered at the master controller | 79 | * The second slave has been registered at the master controller |
67 | */ | 80 | */ |
68 | SLAVE2_REGISTERED, | 81 | SLAVE2_REGISTERED, |
69 | 82 | ||
70 | /** | 83 | /** |
71 | * Link from master to slave 1 has been successfully created | 84 | * Link from master to slave 1 has been successfully created |
72 | */ | 85 | */ |
73 | SLAVE1_LINK_SUCCESS, | 86 | SLAVE1_LINK_SUCCESS, |
74 | 87 | ||
75 | /** | 88 | /** |
76 | * Link from slave 1 to slave 2 has been successfully created. | 89 | * Link from slave 1 to slave 2 has been successfully created. |
77 | */ | 90 | */ |
78 | SLAVE2_LINK_SUCCESS, | 91 | SLAVE2_LINK_SUCCESS, |
79 | 92 | ||
80 | /** | 93 | /** |
81 | * Peer create on slave 1 successful | 94 | * Peer create on slave 1 successful |
82 | */ | 95 | */ |
83 | SLAVE1_PEER_CREATE_SUCCESS, | 96 | SLAVE1_PEER_CREATE_SUCCESS, |
84 | 97 | ||
85 | /** | 98 | /** |
86 | * Peer create on slave 2 successful | 99 | * Peer create on slave 2 successful |
87 | */ | 100 | */ |
88 | SLAVE2_PEER_CREATE_SUCCESS, | 101 | SLAVE2_PEER_CREATE_SUCCESS, |
89 | 102 | ||
90 | /** | 103 | /** |
91 | * Peer startup on slave 1 successful | 104 | * Peer startup on slave 1 successful |
92 | */ | 105 | */ |
93 | SLAVE1_PEER_START_SUCCESS, | 106 | SLAVE1_PEER_START_SUCCESS, |
94 | 107 | ||
95 | /** | 108 | /** |
96 | * Peer on slave 1 successfully stopped | 109 | * Peer on slave 1 successfully stopped |
97 | */ | 110 | */ |
98 | SLAVE1_PEER_STOP_SUCCESS, | 111 | SLAVE1_PEER_STOP_SUCCESS, |
99 | 112 | ||
100 | /** | 113 | /** |
101 | * Peer startup on slave 2 successful | 114 | * Peer startup on slave 2 successful |
102 | */ | 115 | */ |
103 | SLAVE2_PEER_START_SUCCESS, | 116 | SLAVE2_PEER_START_SUCCESS, |
104 | 117 | ||
105 | /** | 118 | /** |
106 | * Peer on slave 2 successfully stopped | 119 | * Peer on slave 2 successfully stopped |
107 | */ | 120 | */ |
108 | SLAVE2_PEER_STOP_SUCCESS, | 121 | SLAVE2_PEER_STOP_SUCCESS, |
109 | 122 | ||
110 | /** | 123 | /** |
111 | * Peer destroy on slave 1 successful | 124 | * Peer destroy on slave 1 successful |
112 | */ | 125 | */ |
113 | SLAVE1_PEER_DESTROY_SUCCESS, | 126 | SLAVE1_PEER_DESTROY_SUCCESS, |
114 | 127 | ||
115 | /** | 128 | /** |
116 | * Peer destory on slave 2 successful; Marks test as successful | 129 | * Peer destory on slave 2 successful |
117 | */ | 130 | */ |
118 | SUCCESS | 131 | SLAVE2_PEER_DESTROY_SUCCESS, |
132 | |||
133 | /** | ||
134 | * Slave 3 has successfully registered | ||
135 | */ | ||
136 | SLAVE3_REGISTERED, | ||
137 | |||
138 | /** | ||
139 | * Slave 3 has successfully started | ||
140 | */ | ||
141 | SLAVE3_STARTED, | ||
142 | |||
143 | /** | ||
144 | * The configuration of slave 3 is acquired | ||
145 | */ | ||
146 | SLAVE3_GET_CONFIG_SUCCESS, | ||
147 | |||
148 | /** | ||
149 | * Slave 1 has linked to slave 3; Also marks test as success | ||
150 | */ | ||
151 | SLAVE3_LINK_SUCCESS, | ||
152 | |||
119 | }; | 153 | }; |
120 | 154 | ||
121 | /** | 155 | /** |
@@ -144,6 +178,11 @@ static struct GNUNET_TESTBED_Host *slave; | |||
144 | static struct GNUNET_TESTBED_Host *slave2; | 178 | static struct GNUNET_TESTBED_Host *slave2; |
145 | 179 | ||
146 | /** | 180 | /** |
181 | * Host for slave 3 | ||
182 | */ | ||
183 | static struct GNUNET_TESTBED_Host *slave3; | ||
184 | |||
185 | /** | ||
147 | * Slave host registration handle | 186 | * Slave host registration handle |
148 | */ | 187 | */ |
149 | static struct GNUNET_TESTBED_HostRegistrationHandle *rh; | 188 | static struct GNUNET_TESTBED_HostRegistrationHandle *rh; |
@@ -154,6 +193,11 @@ static struct GNUNET_TESTBED_HostRegistrationHandle *rh; | |||
154 | static struct GNUNET_CONFIGURATION_Handle *cfg; | 193 | static struct GNUNET_CONFIGURATION_Handle *cfg; |
155 | 194 | ||
156 | /** | 195 | /** |
196 | * Configuration of slave 3 controller | ||
197 | */ | ||
198 | static struct GNUNET_CONFIGURATION_Handle *cfg3; | ||
199 | |||
200 | /** | ||
157 | * Abort task | 201 | * Abort task |
158 | */ | 202 | */ |
159 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; | 203 | static GNUNET_SCHEDULER_TaskIdentifier abort_task; |
@@ -195,6 +239,8 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
195 | { | 239 | { |
196 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | 240 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) |
197 | GNUNET_SCHEDULER_cancel (abort_task); | 241 | GNUNET_SCHEDULER_cancel (abort_task); |
242 | if (NULL != slave3) | ||
243 | GNUNET_TESTBED_host_destroy (slave3); | ||
198 | if (NULL != slave2) | 244 | if (NULL != slave2) |
199 | GNUNET_TESTBED_host_destroy (slave2); | 245 | GNUNET_TESTBED_host_destroy (slave2); |
200 | if (NULL != slave) | 246 | if (NULL != slave) |
@@ -205,11 +251,12 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
205 | GNUNET_TESTBED_controller_disconnect (mc); | 251 | GNUNET_TESTBED_controller_disconnect (mc); |
206 | if (NULL != cfg) | 252 | if (NULL != cfg) |
207 | GNUNET_CONFIGURATION_destroy (cfg); | 253 | GNUNET_CONFIGURATION_destroy (cfg); |
254 | if (NULL != cfg3) | ||
255 | GNUNET_CONFIGURATION_destroy (cfg3); | ||
208 | if (NULL != cp) | 256 | if (NULL != cp) |
209 | GNUNET_TESTBED_controller_stop (cp); | 257 | GNUNET_TESTBED_controller_stop (cp); |
210 | if (NULL != rh) | 258 | if (NULL != rh) |
211 | GNUNET_TESTBED_cancel_registration (rh); | 259 | GNUNET_TESTBED_cancel_registration (rh); |
212 | |||
213 | } | 260 | } |
214 | 261 | ||
215 | 262 | ||
@@ -229,6 +276,21 @@ do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
229 | 276 | ||
230 | 277 | ||
231 | /** | 278 | /** |
279 | * Calls abort now | ||
280 | * | ||
281 | * @param | ||
282 | * @return | ||
283 | */ | ||
284 | static void | ||
285 | do_abort_now (void *cls) | ||
286 | { | ||
287 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | ||
288 | GNUNET_SCHEDULER_cancel (abort_task); | ||
289 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); | ||
290 | } | ||
291 | |||
292 | |||
293 | /** | ||
232 | * Task for inserting delay between tests | 294 | * Task for inserting delay between tests |
233 | * | 295 | * |
234 | * @param | 296 | * @param |
@@ -310,6 +372,16 @@ check_operation_success (const struct GNUNET_TESTBED_EventInformation *event) | |||
310 | 372 | ||
311 | 373 | ||
312 | /** | 374 | /** |
375 | * Callback which will be called to after a host registration succeeded or failed | ||
376 | * | ||
377 | * @param cls the host which has been registered | ||
378 | * @param emsg the error message; NULL if host registration is successful | ||
379 | */ | ||
380 | static void | ||
381 | registration_cont (void *cls, const char *emsg); | ||
382 | |||
383 | |||
384 | /** | ||
313 | * Signature of the event handler function called by the | 385 | * Signature of the event handler function called by the |
314 | * respective event controller. | 386 | * respective event controller. |
315 | * | 387 | * |
@@ -385,8 +457,36 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
385 | case SLAVE1_PEER_DESTROY_SUCCESS: | 457 | case SLAVE1_PEER_DESTROY_SUCCESS: |
386 | check_operation_success (event); | 458 | check_operation_success (event); |
387 | GNUNET_TESTBED_operation_done (op); | 459 | GNUNET_TESTBED_operation_done (op); |
388 | result = SUCCESS; | 460 | op = NULL; |
389 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 461 | result = SLAVE2_PEER_DESTROY_SUCCESS; |
462 | slave3 = GNUNET_TESTBED_host_create_with_id (3, "127.0.0.1", NULL, 0); | ||
463 | rh = GNUNET_TESTBED_register_host (mc, slave3, ®istration_cont, NULL); | ||
464 | break; | ||
465 | case SLAVE3_REGISTERED: | ||
466 | check_operation_success (event); | ||
467 | GNUNET_TESTBED_operation_done (op); | ||
468 | op = NULL; | ||
469 | result = SLAVE3_STARTED; | ||
470 | op = GNUNET_TESTBED_get_slave_config (NULL, mc, slave3); | ||
471 | GNUNET_assert (NULL != op); | ||
472 | break; | ||
473 | case SLAVE3_STARTED: | ||
474 | GNUNET_assert (NULL != event); | ||
475 | GNUNET_assert (GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type); | ||
476 | GNUNET_assert (event->details.operation_finished.operation == op); | ||
477 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); | ||
478 | GNUNET_assert (NULL == event->details.operation_finished.emsg); | ||
479 | cfg3 = GNUNET_CONFIGURATION_dup (event->details.operation_finished.generic); | ||
480 | GNUNET_TESTBED_operation_done (op); | ||
481 | result = SLAVE3_GET_CONFIG_SUCCESS; | ||
482 | op = GNUNET_TESTBED_controller_link (mc, slave3, slave, cfg3, GNUNET_NO); | ||
483 | break; | ||
484 | case SLAVE3_GET_CONFIG_SUCCESS: | ||
485 | result = SLAVE3_LINK_SUCCESS; | ||
486 | GNUNET_TESTBED_operation_done (op); | ||
487 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
488 | (GNUNET_TIME_UNIT_SECONDS, 3), | ||
489 | &do_shutdown, NULL); | ||
390 | break; | 490 | break; |
391 | default: | 491 | default: |
392 | GNUNET_assert (0); | 492 | GNUNET_assert (0); |
@@ -423,8 +523,17 @@ registration_cont (void *cls, const char *emsg) | |||
423 | op = GNUNET_TESTBED_controller_link (mc, slave, NULL, cfg, GNUNET_YES); | 523 | op = GNUNET_TESTBED_controller_link (mc, slave, NULL, cfg, GNUNET_YES); |
424 | GNUNET_assert (NULL != op); | 524 | GNUNET_assert (NULL != op); |
425 | break; | 525 | break; |
526 | case SLAVE2_PEER_DESTROY_SUCCESS: | ||
527 | GNUNET_assert (NULL == emsg); | ||
528 | GNUNET_assert (NULL != mc); | ||
529 | GNUNET_assert (NULL == op); | ||
530 | result = SLAVE3_REGISTERED; | ||
531 | op = GNUNET_TESTBED_controller_link (mc, slave3, NULL, cfg, GNUNET_YES); | ||
532 | GNUNET_assert (NULL != op); | ||
533 | break; | ||
426 | default: | 534 | default: |
427 | GNUNET_assert (0); | 535 | GNUNET_break (0); |
536 | do_abort_now (NULL); | ||
428 | } | 537 | } |
429 | } | 538 | } |
430 | 539 | ||
@@ -459,8 +568,10 @@ status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, | |||
459 | rh = GNUNET_TESTBED_register_host (mc, slave, ®istration_cont, NULL); | 568 | rh = GNUNET_TESTBED_register_host (mc, slave, ®istration_cont, NULL); |
460 | GNUNET_assert (NULL != rh); | 569 | GNUNET_assert (NULL != rh); |
461 | break; | 570 | break; |
462 | default: | 571 | default: |
463 | GNUNET_assert (0); | 572 | GNUNET_break (0); |
573 | cp = NULL; | ||
574 | do_abort_now (NULL); | ||
464 | } | 575 | } |
465 | } | 576 | } |
466 | 577 | ||
@@ -536,7 +647,7 @@ main (int argc, char **argv) | |||
536 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | 647 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, |
537 | "test_testbed_api_controllerlink", "nohelp", options, | 648 | "test_testbed_api_controllerlink", "nohelp", options, |
538 | &run, NULL); | 649 | &run, NULL); |
539 | if ((GNUNET_OK != ret) || (SUCCESS != result)) | 650 | if ((GNUNET_OK != ret) || (SLAVE3_LINK_SUCCESS != result)) |
540 | return 1; | 651 | return 1; |
541 | return 0; | 652 | return 0; |
542 | } | 653 | } |