diff options
Diffstat (limited to 'src/testbed/testbed_api_cmd_netjail_start_testbed.c')
-rw-r--r-- | src/testbed/testbed_api_cmd_netjail_start_testbed.c | 162 |
1 files changed, 137 insertions, 25 deletions
diff --git a/src/testbed/testbed_api_cmd_netjail_start_testbed.c b/src/testbed/testbed_api_cmd_netjail_start_testbed.c index dc8196e94..585825cbc 100644 --- a/src/testbed/testbed_api_cmd_netjail_start_testbed.c +++ b/src/testbed/testbed_api_cmd_netjail_start_testbed.c | |||
@@ -28,13 +28,36 @@ | |||
28 | #include "gnunet_testbed_ng_service.h" | 28 | #include "gnunet_testbed_ng_service.h" |
29 | #include "testbed_api.h" | 29 | #include "testbed_api.h" |
30 | #include "testbed_api_hosts.h" | 30 | #include "testbed_api_hosts.h" |
31 | #include "testbed_helper.h" | ||
31 | 32 | ||
32 | #define NETJAIL_EXEC_SCRIPT "./netjail_exec.sh" | 33 | #define NETJAIL_EXEC_SCRIPT "./netjail_exec.sh" |
33 | 34 | ||
35 | struct HelperMessage; | ||
36 | |||
37 | struct HelperMessage | ||
38 | { | ||
39 | |||
40 | struct HelperMessage *next; | ||
41 | |||
42 | struct HelperMessage *prev; | ||
43 | |||
44 | /** | ||
45 | * Size of the original message. | ||
46 | */ | ||
47 | uint16_t bytes_msg; | ||
48 | |||
49 | /* Followed by @e bytes_msg of msg.*/ | ||
50 | }; | ||
51 | |||
52 | |||
34 | 53 | ||
35 | struct NetJailState | 54 | struct NetJailState |
36 | { | 55 | { |
37 | 56 | ||
57 | struct HelperMessage *hp_messages_head; | ||
58 | |||
59 | struct HelperMessage *hp_messages_tail; | ||
60 | |||
38 | /** | 61 | /** |
39 | * The process handle | 62 | * The process handle |
40 | */ | 63 | */ |
@@ -64,6 +87,8 @@ struct NetJailState | |||
64 | 87 | ||
65 | unsigned int number_of_testbeds_started; | 88 | unsigned int number_of_testbeds_started; |
66 | 89 | ||
90 | unsigned int number_of_peers_started; | ||
91 | |||
67 | /** | 92 | /** |
68 | * The host where the controller is running | 93 | * The host where the controller is running |
69 | */ | 94 | */ |
@@ -112,7 +137,7 @@ netjail_exec_traits (void *cls, | |||
112 | { | 137 | { |
113 | struct NetJailState *ns = cls; | 138 | struct NetJailState *ns = cls; |
114 | struct GNUNET_HELPER_Handle **helper = ns->helper; | 139 | struct GNUNET_HELPER_Handle **helper = ns->helper; |
115 | struct GNUNET_TESTBED_Host **hosts = ns->host; | 140 | struct HelperMessage *hp_messages_head = ns->hp_messages_head; |
116 | 141 | ||
117 | 142 | ||
118 | struct GNUNET_TESTING_Trait traits[] = { | 143 | struct GNUNET_TESTING_Trait traits[] = { |
@@ -123,8 +148,8 @@ netjail_exec_traits (void *cls, | |||
123 | }, | 148 | }, |
124 | { | 149 | { |
125 | .index = 1, | 150 | .index = 1, |
126 | .trait_name = "hosts", | 151 | .trait_name = "hp_msgs_head", |
127 | .ptr = (const void *) hosts, | 152 | .ptr = (const void *) hp_messages_head, |
128 | }, | 153 | }, |
129 | GNUNET_TESTING_trait_end () | 154 | GNUNET_TESTING_trait_end () |
130 | }; | 155 | }; |
@@ -162,13 +187,14 @@ GNUNET_TESTBED_get_trait_helper_handles (const struct | |||
162 | * @return #GNUNET_OK on success. | 187 | * @return #GNUNET_OK on success. |
163 | */ | 188 | */ |
164 | int | 189 | int |
165 | GNUNET_TESTBED_get_trait_hosts (const struct | 190 | GNUNET_TESTBED_get_trait_helper_messages (const struct |
166 | GNUNET_TESTING_Command *cmd, | 191 | GNUNET_TESTING_Command *cmd, |
167 | struct GNUNET_TESTBED_Host ***hosts) | 192 | struct HelperMessage *** |
193 | hp_messages_head) | ||
168 | { | 194 | { |
169 | return cmd->traits (cmd->cls, | 195 | return cmd->traits (cmd->cls, |
170 | (const void **) hosts, | 196 | (const void **) hp_messages_head, |
171 | "hosts", | 197 | "hp_msgs_head", |
172 | (unsigned int) 1); | 198 | (unsigned int) 1); |
173 | } | 199 | } |
174 | 200 | ||
@@ -214,15 +240,32 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message) | |||
214 | { | 240 | { |
215 | struct TestbedCount *tbc = cls; | 241 | struct TestbedCount *tbc = cls; |
216 | struct NetJailState *ns = tbc->ns; | 242 | struct NetJailState *ns = tbc->ns; |
217 | struct GNUNET_TESTBED_Host *host = ns->host[tbc->count - 1]; | 243 | struct HelperMessage *hp_msg; |
244 | |||
245 | if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type)) | ||
246 | { | ||
247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
248 | "helper_mst tbc->count: %d\n", | ||
249 | tbc->count); | ||
250 | // GNUNET_TESTBED_extract_cfg (host, message); | ||
251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
252 | "Received message from helper.\n"); | ||
253 | ns->number_of_testbeds_started++; | ||
254 | } | ||
255 | else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED == ntohs ( | ||
256 | message->type)) | ||
257 | { | ||
258 | ns->number_of_peers_started++; | ||
259 | } | ||
260 | else | ||
261 | { | ||
262 | hp_msg = GNUNET_new (struct HelperMessage); | ||
263 | hp_msg->bytes_msg = message->size; | ||
264 | memcpy (&hp_msg[1], message, message->size); | ||
265 | GNUNET_CONTAINER_DLL_insert (ns->hp_messages_head, ns->hp_messages_tail, | ||
266 | hp_msg); | ||
267 | } | ||
218 | 268 | ||
219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
220 | "helper_mst tbc->count: %d\n", | ||
221 | tbc->count); | ||
222 | GNUNET_TESTBED_extract_cfg (host, message); | ||
223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
224 | "Received message from helper.\n"); | ||
225 | ns->number_of_testbeds_started++; | ||
226 | return GNUNET_OK; | 269 | return GNUNET_OK; |
227 | } | 270 | } |
228 | 271 | ||
@@ -235,6 +278,32 @@ exp_cb (void *cls) | |||
235 | } | 278 | } |
236 | 279 | ||
237 | 280 | ||
281 | static struct GNUNET_CMDS_HelperInit * | ||
282 | create_helper_init_msg_ (char *m_char, | ||
283 | char *n_char, | ||
284 | const char *plugin_name) | ||
285 | { | ||
286 | struct GNUNET_CMDS_HelperInit *msg; | ||
287 | uint16_t plugin_name_len; | ||
288 | uint16_t msg_size; | ||
289 | |||
290 | GNUNET_assert (NULL != plugin_name); | ||
291 | plugin_name_len = strlen (plugin_name); | ||
292 | msg_size = sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_len; | ||
293 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
294 | "msg_size: %d \n", | ||
295 | msg_size); | ||
296 | msg = GNUNET_malloc (msg_size); | ||
297 | msg->header.size = htons (msg_size); | ||
298 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT); | ||
299 | msg->plugin_name_size = htons (plugin_name_len); | ||
300 | GNUNET_memcpy ((char *) &msg[1], | ||
301 | plugin_name, | ||
302 | plugin_name_len); | ||
303 | return msg; | ||
304 | } | ||
305 | |||
306 | |||
238 | static void | 307 | static void |
239 | start_testbed (struct NetJailState *ns, struct | 308 | start_testbed (struct NetJailState *ns, struct |
240 | GNUNET_CONFIGURATION_Handle *config, | 309 | GNUNET_CONFIGURATION_Handle *config, |
@@ -242,13 +311,15 @@ start_testbed (struct NetJailState *ns, struct | |||
242 | char *m_char) | 311 | char *m_char) |
243 | { | 312 | { |
244 | struct GNUNET_CONFIGURATION_Handle *cfg; | 313 | struct GNUNET_CONFIGURATION_Handle *cfg; |
245 | struct GNUNET_TESTBED_HelperInit *msg; | 314 | struct GNUNET_CMDS_HelperInit *msg; |
246 | struct TestbedCount *tbc; | 315 | struct TestbedCount *tbc; |
247 | char *const script_argv[] = {NETJAIL_EXEC_SCRIPT, | 316 | char *const script_argv[] = {NETJAIL_EXEC_SCRIPT, |
248 | m_char, | ||
249 | n_char, | 317 | n_char, |
318 | m_char, | ||
250 | GNUNET_OS_get_libexec_binary_path ( | 319 | GNUNET_OS_get_libexec_binary_path ( |
251 | HELPER_CMDS_BINARY), | 320 | HELPER_CMDS_BINARY), |
321 | ns->global_n, | ||
322 | ns->local_m, | ||
252 | NULL}; | 323 | NULL}; |
253 | unsigned int m = atoi (m_char); | 324 | unsigned int m = atoi (m_char); |
254 | unsigned int n = atoi (n_char); | 325 | unsigned int n = atoi (n_char); |
@@ -291,7 +362,9 @@ start_testbed (struct NetJailState *ns, struct | |||
291 | 362 | ||
292 | struct GNUNET_HELPER_Handle *helper = ns->helper[tbc->count - 1]; | 363 | struct GNUNET_HELPER_Handle *helper = ns->helper[tbc->count - 1]; |
293 | 364 | ||
294 | msg = GNUNET_TESTBED_create_helper_init_msg_ ("127.0.0.1", NULL, config); | 365 | msg = create_helper_init_msg_ (m_char, |
366 | n_char, | ||
367 | "libgnunet_plugin_testcmd"); | ||
295 | GNUNET_array_append (ns->msg, ns->n_msg, &msg->header); | 368 | GNUNET_array_append (ns->msg, ns->n_msg, &msg->header); |
296 | 369 | ||
297 | GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send ( | 370 | GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send ( |
@@ -300,6 +373,10 @@ start_testbed (struct NetJailState *ns, struct | |||
300 | GNUNET_NO, | 373 | GNUNET_NO, |
301 | &clear_msg, | 374 | &clear_msg, |
302 | tbc)); | 375 | tbc)); |
376 | |||
377 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
378 | "Message send!\n"); | ||
379 | |||
303 | if (NULL == ns->shandle[tbc->count - 1]) | 380 | if (NULL == ns->shandle[tbc->count - 1]) |
304 | { | 381 | { |
305 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 382 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -348,14 +425,49 @@ netjail_start_finish (void *cls, | |||
348 | { | 425 | { |
349 | unsigned int ret = GNUNET_NO; | 426 | unsigned int ret = GNUNET_NO; |
350 | struct NetJailState *ns = cls; | 427 | struct NetJailState *ns = cls; |
428 | unsigned int total_number = atoi (ns->local_m) * atoi (ns->global_n); | ||
429 | struct GNUNET_CMDS_PEER_STARTED *reply; | ||
430 | size_t msg_length; | ||
431 | struct GNUNET_HELPER_Handle *helper; | ||
432 | struct TestbedCount *tbc; | ||
351 | 433 | ||
352 | if (ns->number_of_testbeds_started == atoi (ns->local_m) * atoi ( | 434 | if (ns->number_of_testbeds_started == total_number) |
353 | ns->global_n)) | ||
354 | { | 435 | { |
355 | ret = GNUNET_YES; | 436 | /* ret = GNUNET_YES; |
356 | cont (cont_cls); | 437 | cont (cont_cls);*/ |
357 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 438 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
358 | "All helper started!\n"); | 439 | "All helpers started!\n"); |
440 | } | ||
441 | |||
442 | if (ns->number_of_peers_started == total_number) | ||
443 | { | ||
444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
445 | "All peers started!\n"); | ||
446 | |||
447 | for (int i = 1; i <= atoi (ns->global_n); i++) { | ||
448 | for (int j = 1; j <= atoi (ns->local_m); j++) | ||
449 | { | ||
450 | tbc = GNUNET_new (struct TestbedCount); | ||
451 | tbc->ns = ns; | ||
452 | tbc->count = (j - 1) * atoi (ns->local_m) + i + atoi (ns->global_n) | ||
453 | * atoi (ns->local_m); | ||
454 | helper = ns->helper[tbc->count - 1]; | ||
455 | msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED); | ||
456 | reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED); | ||
457 | reply->header.type = htons ( | ||
458 | GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED); | ||
459 | reply->header.size = htons ((uint16_t) msg_length); | ||
460 | |||
461 | GNUNET_array_append (ns->msg, ns->n_msg, &reply->header); | ||
462 | |||
463 | GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send ( | ||
464 | helper, | ||
465 | &reply->header, | ||
466 | GNUNET_NO, | ||
467 | &clear_msg, | ||
468 | tbc)); | ||
469 | } | ||
470 | } | ||
359 | } | 471 | } |
360 | return ret; | 472 | return ret; |
361 | } | 473 | } |