diff options
-rw-r--r-- | src/testbed/testbed_api.c | 194 | ||||
-rw-r--r-- | src/testbed/testbed_api.h | 98 | ||||
-rw-r--r-- | src/testbed/testbed_api_hosts.c | 265 | ||||
-rw-r--r-- | src/testbed/testbed_api_hosts.h | 109 | ||||
-rw-r--r-- | src/testbed/testbed_api_peers.c | 13 |
5 files changed, 336 insertions, 343 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index f0ba0f5a1..ad77003fc 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -1322,27 +1322,6 @@ oprelease_get_slave_config (void *cls) | |||
1322 | 1322 | ||
1323 | 1323 | ||
1324 | /** | 1324 | /** |
1325 | * Initializes the operation queue for parallel overlay connects | ||
1326 | * | ||
1327 | * @param c the controller handle | ||
1328 | * @param npoc the number of parallel overlay connects - the queue size | ||
1329 | */ | ||
1330 | static void | ||
1331 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (struct | ||
1332 | GNUNET_TESTBED_Controller *c, | ||
1333 | unsigned int npoc) | ||
1334 | { | ||
1335 | fprintf (stderr, "%d", npoc); | ||
1336 | GNUNET_free_non_null (c->tslots); | ||
1337 | c->tslots_filled = 0; | ||
1338 | c->num_parallel_connects = npoc; | ||
1339 | c->tslots = GNUNET_malloc (npoc * sizeof (struct TimeSlot)); | ||
1340 | GNUNET_TESTBED_operation_queue_reset_max_active_ | ||
1341 | (c->opq_parallel_overlay_connect_operations, npoc); | ||
1342 | } | ||
1343 | |||
1344 | |||
1345 | /** | ||
1346 | * Function to copy NULL terminated list of arguments | 1325 | * Function to copy NULL terminated list of arguments |
1347 | * | 1326 | * |
1348 | * @param argv the NULL terminated list of arguments. Cannot be NULL. | 1327 | * @param argv the NULL terminated list of arguments. Cannot be NULL. |
@@ -1718,10 +1697,6 @@ GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle | |||
1718 | controller->opq_parallel_topology_config_operations = | 1697 | controller->opq_parallel_topology_config_operations = |
1719 | GNUNET_TESTBED_operation_queue_create_ ((unsigned int) | 1698 | GNUNET_TESTBED_operation_queue_create_ ((unsigned int) |
1720 | max_parallel_topology_config_operations); | 1699 | max_parallel_topology_config_operations); |
1721 | controller->opq_parallel_overlay_connect_operations = | ||
1722 | GNUNET_TESTBED_operation_queue_create_ (0); | ||
1723 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (controller, 1); | ||
1724 | controller->poc_sd = GNUNET_TESTBED_SD_init_ (10); | ||
1725 | controller_hostname = GNUNET_TESTBED_host_get_hostname (host); | 1700 | controller_hostname = GNUNET_TESTBED_host_get_hostname (host); |
1726 | if (NULL == controller_hostname) | 1701 | if (NULL == controller_hostname) |
1727 | controller_hostname = "127.0.0.1"; | 1702 | controller_hostname = "127.0.0.1"; |
@@ -1812,10 +1787,6 @@ GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller | |||
1812 | (controller->opq_parallel_service_connections); | 1787 | (controller->opq_parallel_service_connections); |
1813 | GNUNET_TESTBED_operation_queue_destroy_ | 1788 | GNUNET_TESTBED_operation_queue_destroy_ |
1814 | (controller->opq_parallel_topology_config_operations); | 1789 | (controller->opq_parallel_topology_config_operations); |
1815 | GNUNET_TESTBED_operation_queue_destroy_ | ||
1816 | (controller->opq_parallel_overlay_connect_operations); | ||
1817 | GNUNET_TESTBED_SD_destroy_ (controller->poc_sd); | ||
1818 | GNUNET_free_non_null (controller->tslots); | ||
1819 | GNUNET_free (controller); | 1790 | GNUNET_free (controller); |
1820 | } | 1791 | } |
1821 | 1792 | ||
@@ -2430,169 +2401,4 @@ GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller * controller) | |||
2430 | } | 2401 | } |
2431 | 2402 | ||
2432 | 2403 | ||
2433 | /** | ||
2434 | * Returns a timing slot which will be exclusively locked | ||
2435 | * | ||
2436 | * @param c the controller handle | ||
2437 | * @param key a pointer which is associated to the returned slot; should not be | ||
2438 | * NULL. It serves as a key to determine the correct owner of the slot | ||
2439 | * @return the time slot index in the array of time slots in the controller | ||
2440 | * handle | ||
2441 | */ | ||
2442 | unsigned int | ||
2443 | GNUNET_TESTBED_get_tslot_ (struct GNUNET_TESTBED_Controller *c, void *key) | ||
2444 | { | ||
2445 | unsigned int slot; | ||
2446 | |||
2447 | GNUNET_assert (NULL != c->tslots); | ||
2448 | GNUNET_assert (NULL != key); | ||
2449 | for (slot = 0; slot < c->num_parallel_connects; slot++) | ||
2450 | if (NULL == c->tslots[slot].key) | ||
2451 | { | ||
2452 | c->tslots[slot].key = key; | ||
2453 | return slot; | ||
2454 | } | ||
2455 | GNUNET_assert (0); /* We should always find a free tslot */ | ||
2456 | } | ||
2457 | |||
2458 | |||
2459 | /** | ||
2460 | * Decides whether any change in the number of parallel overlay connects is | ||
2461 | * necessary to adapt to the load on the system | ||
2462 | * | ||
2463 | * @param c the controller handle | ||
2464 | */ | ||
2465 | static void | ||
2466 | decide_npoc (struct GNUNET_TESTBED_Controller *c) | ||
2467 | { | ||
2468 | struct GNUNET_TIME_Relative avg; | ||
2469 | int sd; | ||
2470 | unsigned int slot; | ||
2471 | unsigned int nvals; | ||
2472 | |||
2473 | if (c->tslots_filled != c->num_parallel_connects) | ||
2474 | return; | ||
2475 | avg = GNUNET_TIME_UNIT_ZERO; | ||
2476 | nvals = 0; | ||
2477 | for (slot = 0; slot < c->num_parallel_connects; slot++) | ||
2478 | { | ||
2479 | avg = GNUNET_TIME_relative_add (avg, c->tslots[slot].time); | ||
2480 | nvals += c->tslots[slot].nvals; | ||
2481 | } | ||
2482 | GNUNET_assert (nvals >= c->num_parallel_connects); | ||
2483 | avg = GNUNET_TIME_relative_divide (avg, nvals); | ||
2484 | GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value != avg.rel_value); | ||
2485 | sd = GNUNET_TESTBED_SD_deviation_factor_ (c->poc_sd, (unsigned int) avg.rel_value); | ||
2486 | if ( (sd <= 5) || | ||
2487 | (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
2488 | c->num_parallel_connects)) ) | ||
2489 | GNUNET_TESTBED_SD_add_data_ (c->poc_sd, (unsigned int) avg.rel_value); | ||
2490 | if (GNUNET_SYSERR == sd) | ||
2491 | { | ||
2492 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (c, | ||
2493 | c->num_parallel_connects); | ||
2494 | return; | ||
2495 | } | ||
2496 | GNUNET_assert (0 <= sd); | ||
2497 | if (0 == sd) | ||
2498 | { | ||
2499 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (c, | ||
2500 | c->num_parallel_connects | ||
2501 | * 2); | ||
2502 | return; | ||
2503 | } | ||
2504 | if (1 == sd) | ||
2505 | { | ||
2506 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (c, | ||
2507 | c->num_parallel_connects | ||
2508 | + 1); | ||
2509 | return; | ||
2510 | } | ||
2511 | if (1 == c->num_parallel_connects) | ||
2512 | { | ||
2513 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (c, 1); | ||
2514 | return; | ||
2515 | } | ||
2516 | if (2 == sd) | ||
2517 | { | ||
2518 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (c, | ||
2519 | c->num_parallel_connects | ||
2520 | - 1); | ||
2521 | return; | ||
2522 | } | ||
2523 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (c, | ||
2524 | c->num_parallel_connects / | ||
2525 | 2); | ||
2526 | } | ||
2527 | |||
2528 | |||
2529 | /** | ||
2530 | * Releases a time slot thus making it available for be used again | ||
2531 | * | ||
2532 | * @param c the controller handle | ||
2533 | * @param index the index of the the time slot | ||
2534 | * @param key the key to prove ownership of the timeslot | ||
2535 | * @return GNUNET_YES if the time slot is successfully removed; GNUNET_NO if the | ||
2536 | * time slot cannot be removed - this could be because of the index | ||
2537 | * greater than existing number of time slots or `key' being different | ||
2538 | */ | ||
2539 | int | ||
2540 | GNUNET_TESTBED_release_time_slot_ (struct GNUNET_TESTBED_Controller *c, | ||
2541 | unsigned int index, void *key) | ||
2542 | { | ||
2543 | struct TimeSlot *slot; | ||
2544 | |||
2545 | GNUNET_assert (NULL != key); | ||
2546 | if (index >= c->num_parallel_connects) | ||
2547 | return GNUNET_NO; | ||
2548 | slot = &c->tslots[index]; | ||
2549 | if (key != slot->key) | ||
2550 | return GNUNET_NO; | ||
2551 | slot->key = NULL; | ||
2552 | return GNUNET_YES; | ||
2553 | } | ||
2554 | |||
2555 | |||
2556 | /** | ||
2557 | * Function to update a time slot | ||
2558 | * | ||
2559 | * @param c the controller handle | ||
2560 | * @param index the index of the time slot to update | ||
2561 | * @param key the key to identify ownership of the slot | ||
2562 | * @param time the new time | ||
2563 | * @param failed should this reading be treated as coming from a fail event | ||
2564 | */ | ||
2565 | void | ||
2566 | GNUNET_TESTBED_update_time_slot_ (struct GNUNET_TESTBED_Controller *c, | ||
2567 | unsigned int index, void *key, | ||
2568 | struct GNUNET_TIME_Relative time, int failed) | ||
2569 | { | ||
2570 | struct TimeSlot *slot; | ||
2571 | |||
2572 | if (GNUNET_YES == failed) | ||
2573 | { | ||
2574 | if (1 == c->num_parallel_connects) | ||
2575 | { | ||
2576 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (c, 1); | ||
2577 | return; | ||
2578 | } | ||
2579 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (c, | ||
2580 | c->num_parallel_connects | ||
2581 | - 1); | ||
2582 | } | ||
2583 | if (GNUNET_NO == GNUNET_TESTBED_release_time_slot_ (c, index, key)) | ||
2584 | return; | ||
2585 | slot = &c->tslots[index]; | ||
2586 | slot->nvals++; | ||
2587 | if (GNUNET_TIME_UNIT_ZERO.rel_value == slot->time.rel_value) | ||
2588 | { | ||
2589 | slot->time = time; | ||
2590 | c->tslots_filled++; | ||
2591 | decide_npoc (c); | ||
2592 | return; | ||
2593 | } | ||
2594 | slot->time = GNUNET_TIME_relative_add (slot->time, time); | ||
2595 | } | ||
2596 | |||
2597 | |||
2598 | /* end of testbed_api.c */ | 2404 | /* end of testbed_api.c */ |
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h index d6c04a6a2..26b0d5843 100644 --- a/src/testbed/testbed_api.h +++ b/src/testbed/testbed_api.h | |||
@@ -178,34 +178,6 @@ struct OperationContext | |||
178 | 178 | ||
179 | 179 | ||
180 | /** | 180 | /** |
181 | * Opaque handle for SD calculations | ||
182 | */ | ||
183 | struct SDHandle; | ||
184 | |||
185 | |||
186 | /** | ||
187 | * A slot to record time taken by an overlay connect operation | ||
188 | */ | ||
189 | struct TimeSlot | ||
190 | { | ||
191 | /** | ||
192 | * A key to identify this timeslot | ||
193 | */ | ||
194 | void *key; | ||
195 | |||
196 | /** | ||
197 | * Time | ||
198 | */ | ||
199 | struct GNUNET_TIME_Relative time; | ||
200 | |||
201 | /** | ||
202 | * Number of timing values accumulated | ||
203 | */ | ||
204 | unsigned int nvals; | ||
205 | }; | ||
206 | |||
207 | |||
208 | /** | ||
209 | * Handle to interact with a GNUnet testbed controller. Each | 181 | * Handle to interact with a GNUnet testbed controller. Each |
210 | * controller has at least one master handle which is created when the | 182 | * controller has at least one master handle which is created when the |
211 | * controller is created; this master handle interacts with the | 183 | * controller is created; this master handle interacts with the |
@@ -298,23 +270,6 @@ struct GNUNET_TESTBED_Controller | |||
298 | struct OperationQueue *opq_parallel_topology_config_operations; | 270 | struct OperationQueue *opq_parallel_topology_config_operations; |
299 | 271 | ||
300 | /** | 272 | /** |
301 | * Operation queue for simultaneous overlay connect operations | ||
302 | */ | ||
303 | struct OperationQueue *opq_parallel_overlay_connect_operations; | ||
304 | |||
305 | /** | ||
306 | * An array of timing slots; size should be equal to the current number of parallel | ||
307 | * overlay connects | ||
308 | */ | ||
309 | struct TimeSlot *tslots; | ||
310 | |||
311 | /** | ||
312 | * Handle for SD calculations amount parallel overlay connect operation finish | ||
313 | * times | ||
314 | */ | ||
315 | struct SDHandle *poc_sd; | ||
316 | |||
317 | /** | ||
318 | * The controller event mask | 273 | * The controller event mask |
319 | */ | 274 | */ |
320 | uint64_t event_mask; | 275 | uint64_t event_mask; |
@@ -330,16 +285,6 @@ struct GNUNET_TESTBED_Controller | |||
330 | int aux_host; | 285 | int aux_host; |
331 | 286 | ||
332 | /** | 287 | /** |
333 | * The number of parallel overlay connects we do currently | ||
334 | */ | ||
335 | unsigned int num_parallel_connects; | ||
336 | |||
337 | /** | ||
338 | * Counter to indicate when all the available time slots are filled | ||
339 | */ | ||
340 | unsigned int tslots_filled; | ||
341 | |||
342 | /** | ||
343 | * The operation id counter. use current value and increment | 288 | * The operation id counter. use current value and increment |
344 | */ | 289 | */ |
345 | uint32_t operation_counter; | 290 | uint32_t operation_counter; |
@@ -541,49 +486,6 @@ GNUNET_TESTBED_controller_link_ (void *op_cls, | |||
541 | *slave_cfg, int is_subordinate); | 486 | *slave_cfg, int is_subordinate); |
542 | 487 | ||
543 | 488 | ||
544 | /** | ||
545 | * Returns a timing slot which will be exclusively locked | ||
546 | * | ||
547 | * @param c the controller handle | ||
548 | * @param key a pointer which is associated to the returned slot; should not be | ||
549 | * NULL. It serves as a key to determine the correct owner of the slot | ||
550 | * @return the time slot index in the array of time slots in the controller | ||
551 | * handle | ||
552 | */ | ||
553 | unsigned int | ||
554 | GNUNET_TESTBED_get_tslot_ (struct GNUNET_TESTBED_Controller *c, void *key); | ||
555 | |||
556 | |||
557 | /** | ||
558 | * Function to update a time slot | ||
559 | * | ||
560 | * @param c the controller handle | ||
561 | * @param index the index of the time slot to update | ||
562 | * @param key the key to identify ownership of the slot | ||
563 | * @param time the new time | ||
564 | * @param failed should this reading be treated as coming from a fail event | ||
565 | */ | ||
566 | void | ||
567 | GNUNET_TESTBED_update_time_slot_ (struct GNUNET_TESTBED_Controller *c, | ||
568 | unsigned int index, void *key, | ||
569 | struct GNUNET_TIME_Relative time, int failed); | ||
570 | |||
571 | |||
572 | /** | ||
573 | * Releases a time slot thus making it available for be used again | ||
574 | * | ||
575 | * @param c the controller handle | ||
576 | * @param index the index of the the time slot | ||
577 | * @param key the key to prove ownership of the timeslot | ||
578 | * @return GNUNET_YES if the time slot is successfully removed; GNUNET_NO if the | ||
579 | * time slot cannot be removed - this could be because of the index | ||
580 | * greater than existing number of time slots or `key' being different | ||
581 | */ | ||
582 | int | ||
583 | GNUNET_TESTBED_release_time_slot_ (struct GNUNET_TESTBED_Controller *c, | ||
584 | unsigned int index, void *key); | ||
585 | |||
586 | |||
587 | 489 | ||
588 | 490 | ||
589 | #endif | 491 | #endif |
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index 293f3493b..3f305d2a0 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c | |||
@@ -33,6 +33,8 @@ | |||
33 | 33 | ||
34 | #include "testbed_api.h" | 34 | #include "testbed_api.h" |
35 | #include "testbed_api_hosts.h" | 35 | #include "testbed_api_hosts.h" |
36 | #include "testbed_api_operations.h" | ||
37 | #include "testbed_api_sd.h" | ||
36 | 38 | ||
37 | /** | 39 | /** |
38 | * Generic logging shorthand | 40 | * Generic logging shorthand |
@@ -69,6 +71,28 @@ struct RegisteredController | |||
69 | 71 | ||
70 | 72 | ||
71 | /** | 73 | /** |
74 | * A slot to record time taken by an overlay connect operation | ||
75 | */ | ||
76 | struct TimeSlot | ||
77 | { | ||
78 | /** | ||
79 | * A key to identify this timeslot | ||
80 | */ | ||
81 | void *key; | ||
82 | |||
83 | /** | ||
84 | * Time | ||
85 | */ | ||
86 | struct GNUNET_TIME_Relative time; | ||
87 | |||
88 | /** | ||
89 | * Number of timing values accumulated | ||
90 | */ | ||
91 | unsigned int nvals; | ||
92 | }; | ||
93 | |||
94 | |||
95 | /** | ||
72 | * Opaque handle to a host running experiments managed by the testing framework. | 96 | * Opaque handle to a host running experiments managed by the testing framework. |
73 | * The master process must be able to SSH to this host without password (via | 97 | * The master process must be able to SSH to this host without password (via |
74 | * ssh-agent). | 98 | * ssh-agent). |
@@ -107,6 +131,34 @@ struct GNUNET_TESTBED_Host | |||
107 | struct RegisteredController *rc_tail; | 131 | struct RegisteredController *rc_tail; |
108 | 132 | ||
109 | /** | 133 | /** |
134 | * Operation queue for simultaneous overlay connect operations target at this | ||
135 | * host | ||
136 | */ | ||
137 | struct OperationQueue *opq_parallel_overlay_connect_operations; | ||
138 | |||
139 | /** | ||
140 | * An array of timing slots; size should be equal to the current number of parallel | ||
141 | * overlay connects | ||
142 | */ | ||
143 | struct TimeSlot *tslots; | ||
144 | |||
145 | /** | ||
146 | * Handle for SD calculations amount parallel overlay connect operation finish | ||
147 | * times | ||
148 | */ | ||
149 | struct SDHandle *poc_sd; | ||
150 | |||
151 | /** | ||
152 | * The number of parallel overlay connects we do currently | ||
153 | */ | ||
154 | unsigned int num_parallel_connects; | ||
155 | |||
156 | /** | ||
157 | * Counter to indicate when all the available time slots are filled | ||
158 | */ | ||
159 | unsigned int tslots_filled; | ||
160 | |||
161 | /** | ||
110 | * Global ID we use to refer to a host on the network | 162 | * Global ID we use to refer to a host on the network |
111 | */ | 163 | */ |
112 | uint32_t id; | 164 | uint32_t id; |
@@ -241,7 +293,11 @@ GNUNET_TESTBED_host_create_with_id (uint32_t id, const char *hostname, | |||
241 | host->hostname = (NULL != hostname) ? GNUNET_strdup (hostname) : NULL; | 293 | host->hostname = (NULL != hostname) ? GNUNET_strdup (hostname) : NULL; |
242 | host->username = (NULL != username) ? GNUNET_strdup (username) : NULL; | 294 | host->username = (NULL != username) ? GNUNET_strdup (username) : NULL; |
243 | host->id = id; | 295 | host->id = id; |
244 | host->port = (0 == port) ? 22 : port; | 296 | host->port = (0 == port) ? 22 : port; |
297 | host->opq_parallel_overlay_connect_operations = | ||
298 | GNUNET_TESTBED_operation_queue_create_ (0); | ||
299 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (host, 1); | ||
300 | host->poc_sd = GNUNET_TESTBED_SD_init_ (10); | ||
245 | new_size = host_list_size; | 301 | new_size = host_list_size; |
246 | while (id >= new_size) | 302 | while (id >= new_size) |
247 | new_size += HOST_LIST_GROW_STEP; | 303 | new_size += HOST_LIST_GROW_STEP; |
@@ -389,6 +445,10 @@ GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host) | |||
389 | } | 445 | } |
390 | GNUNET_free_non_null ((char *) host->username); | 446 | GNUNET_free_non_null ((char *) host->username); |
391 | GNUNET_free_non_null ((char *) host->hostname); | 447 | GNUNET_free_non_null ((char *) host->hostname); |
448 | GNUNET_TESTBED_operation_queue_destroy_ | ||
449 | (host->opq_parallel_overlay_connect_operations); | ||
450 | GNUNET_TESTBED_SD_destroy_ (host->poc_sd); | ||
451 | GNUNET_free_non_null (host->tslots); | ||
392 | GNUNET_free (host); | 452 | GNUNET_free (host); |
393 | while (host_list_size >= HOST_LIST_GROW_STEP) | 453 | while (host_list_size >= HOST_LIST_GROW_STEP) |
394 | { | 454 | { |
@@ -661,4 +721,207 @@ GNUNET_TESTBED_is_host_habitable_cancel (struct | |||
661 | GNUNET_free (handle); | 721 | GNUNET_free (handle); |
662 | } | 722 | } |
663 | 723 | ||
724 | |||
725 | /** | ||
726 | * Initializes the operation queue for parallel overlay connects | ||
727 | * | ||
728 | * @param h the host handle | ||
729 | * @param npoc the number of parallel overlay connects - the queue size | ||
730 | */ | ||
731 | void | ||
732 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (struct | ||
733 | GNUNET_TESTBED_Host *h, | ||
734 | unsigned int npoc) | ||
735 | { | ||
736 | fprintf (stderr, "%d", npoc); | ||
737 | GNUNET_free_non_null (h->tslots); | ||
738 | h->tslots_filled = 0; | ||
739 | h->num_parallel_connects = npoc; | ||
740 | h->tslots = GNUNET_malloc (npoc * sizeof (struct TimeSlot)); | ||
741 | GNUNET_TESTBED_operation_queue_reset_max_active_ | ||
742 | (h->opq_parallel_overlay_connect_operations, npoc); | ||
743 | } | ||
744 | |||
745 | |||
746 | /** | ||
747 | * Returns a timing slot which will be exclusively locked | ||
748 | * | ||
749 | * @param h the host handle | ||
750 | * @param key a pointer which is associated to the returned slot; should not be | ||
751 | * NULL. It serves as a key to determine the correct owner of the slot | ||
752 | * @return the time slot index in the array of time slots in the controller | ||
753 | * handle | ||
754 | */ | ||
755 | unsigned int | ||
756 | GNUNET_TESTBED_get_tslot_ (struct GNUNET_TESTBED_Host *h, void *key) | ||
757 | { | ||
758 | unsigned int slot; | ||
759 | |||
760 | GNUNET_assert (NULL != h->tslots); | ||
761 | GNUNET_assert (NULL != key); | ||
762 | for (slot = 0; slot < h->num_parallel_connects; slot++) | ||
763 | if (NULL == h->tslots[slot].key) | ||
764 | { | ||
765 | h->tslots[slot].key = key; | ||
766 | return slot; | ||
767 | } | ||
768 | GNUNET_assert (0); /* We should always find a free tslot */ | ||
769 | } | ||
770 | |||
771 | |||
772 | /** | ||
773 | * Decides whether any change in the number of parallel overlay connects is | ||
774 | * necessary to adapt to the load on the system | ||
775 | * | ||
776 | * @param h the host handle | ||
777 | */ | ||
778 | static void | ||
779 | decide_npoc (struct GNUNET_TESTBED_Host *h) | ||
780 | { | ||
781 | struct GNUNET_TIME_Relative avg; | ||
782 | int sd; | ||
783 | unsigned int slot; | ||
784 | unsigned int nvals; | ||
785 | |||
786 | if (h->tslots_filled != h->num_parallel_connects) | ||
787 | return; | ||
788 | avg = GNUNET_TIME_UNIT_ZERO; | ||
789 | nvals = 0; | ||
790 | for (slot = 0; slot < h->num_parallel_connects; slot++) | ||
791 | { | ||
792 | avg = GNUNET_TIME_relative_add (avg, h->tslots[slot].time); | ||
793 | nvals += h->tslots[slot].nvals; | ||
794 | } | ||
795 | GNUNET_assert (nvals >= h->num_parallel_connects); | ||
796 | avg = GNUNET_TIME_relative_divide (avg, nvals); | ||
797 | GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value != avg.rel_value); | ||
798 | sd = GNUNET_TESTBED_SD_deviation_factor_ (h->poc_sd, (unsigned int) avg.rel_value); | ||
799 | if ( (sd <= 5) || | ||
800 | (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
801 | h->num_parallel_connects)) ) | ||
802 | GNUNET_TESTBED_SD_add_data_ (h->poc_sd, (unsigned int) avg.rel_value); | ||
803 | if (GNUNET_SYSERR == sd) | ||
804 | { | ||
805 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h, | ||
806 | h->num_parallel_connects); | ||
807 | return; | ||
808 | } | ||
809 | GNUNET_assert (0 <= sd); | ||
810 | if (0 == sd) | ||
811 | { | ||
812 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h, | ||
813 | h->num_parallel_connects | ||
814 | * 2); | ||
815 | return; | ||
816 | } | ||
817 | if (1 == sd) | ||
818 | { | ||
819 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h, | ||
820 | h->num_parallel_connects | ||
821 | + 1); | ||
822 | return; | ||
823 | } | ||
824 | if (1 == h->num_parallel_connects) | ||
825 | { | ||
826 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h, 1); | ||
827 | return; | ||
828 | } | ||
829 | if (2 == sd) | ||
830 | { | ||
831 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h, | ||
832 | h->num_parallel_connects | ||
833 | - 1); | ||
834 | return; | ||
835 | } | ||
836 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h, | ||
837 | h->num_parallel_connects / | ||
838 | 2); | ||
839 | } | ||
840 | |||
841 | |||
842 | /** | ||
843 | * Releases a time slot thus making it available for be used again | ||
844 | * | ||
845 | * @param h the host handle | ||
846 | * @param index the index of the the time slot | ||
847 | * @param key the key to prove ownership of the timeslot | ||
848 | * @return GNUNET_YES if the time slot is successfully removed; GNUNET_NO if the | ||
849 | * time slot cannot be removed - this could be because of the index | ||
850 | * greater than existing number of time slots or `key' being different | ||
851 | */ | ||
852 | int | ||
853 | GNUNET_TESTBED_release_time_slot_ (struct GNUNET_TESTBED_Host *h, | ||
854 | unsigned int index, void *key) | ||
855 | { | ||
856 | struct TimeSlot *slot; | ||
857 | |||
858 | GNUNET_assert (NULL != key); | ||
859 | if (index >= h->num_parallel_connects) | ||
860 | return GNUNET_NO; | ||
861 | slot = &h->tslots[index]; | ||
862 | if (key != slot->key) | ||
863 | return GNUNET_NO; | ||
864 | slot->key = NULL; | ||
865 | return GNUNET_YES; | ||
866 | } | ||
867 | |||
868 | |||
869 | /** | ||
870 | * Function to update a time slot | ||
871 | * | ||
872 | * @param h the host handle | ||
873 | * @param index the index of the time slot to update | ||
874 | * @param key the key to identify ownership of the slot | ||
875 | * @param time the new time | ||
876 | * @param failed should this reading be treated as coming from a fail event | ||
877 | */ | ||
878 | void | ||
879 | GNUNET_TESTBED_update_time_slot_ (struct GNUNET_TESTBED_Host *h, | ||
880 | unsigned int index, void *key, | ||
881 | struct GNUNET_TIME_Relative time, int failed) | ||
882 | { | ||
883 | struct TimeSlot *slot; | ||
884 | |||
885 | if (GNUNET_YES == failed) | ||
886 | { | ||
887 | if (1 == h->num_parallel_connects) | ||
888 | { | ||
889 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h, 1); | ||
890 | return; | ||
891 | } | ||
892 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h, | ||
893 | h->num_parallel_connects | ||
894 | - 1); | ||
895 | } | ||
896 | if (GNUNET_NO == GNUNET_TESTBED_release_time_slot_ (h, index, key)) | ||
897 | return; | ||
898 | slot = &h->tslots[index]; | ||
899 | slot->nvals++; | ||
900 | if (GNUNET_TIME_UNIT_ZERO.rel_value == slot->time.rel_value) | ||
901 | { | ||
902 | slot->time = time; | ||
903 | h->tslots_filled++; | ||
904 | decide_npoc (h); | ||
905 | return; | ||
906 | } | ||
907 | slot->time = GNUNET_TIME_relative_add (slot->time, time); | ||
908 | } | ||
909 | |||
910 | |||
911 | /** | ||
912 | * Queues the given operation in the queue for parallel overlay connects of the | ||
913 | * given host | ||
914 | * | ||
915 | * @param h the host handle | ||
916 | * @param op the operation to queue in the given host's parally overlay connect | ||
917 | * queue | ||
918 | */ | ||
919 | void | ||
920 | GNUNET_TESTBED_host_queue_oc (struct GNUNET_TESTBED_Host *h, | ||
921 | struct GNUNET_TESTBED_Operation *op) | ||
922 | { | ||
923 | GNUNET_TESTBED_operation_queue_insert_ | ||
924 | (h->opq_parallel_overlay_connect_operations, op); | ||
925 | } | ||
926 | |||
664 | /* end of testbed_api_hosts.c */ | 927 | /* end of testbed_api_hosts.c */ |
diff --git a/src/testbed/testbed_api_hosts.h b/src/testbed/testbed_api_hosts.h index c0f42909a..f2a2e63e8 100644 --- a/src/testbed/testbed_api_hosts.h +++ b/src/testbed/testbed_api_hosts.h | |||
@@ -87,49 +87,6 @@ GNUNET_TESTBED_host_get_ssh_port_ (const struct GNUNET_TESTBED_Host *host); | |||
87 | 87 | ||
88 | 88 | ||
89 | /** | 89 | /** |
90 | * Opaque wrapper around GNUNET_HELPER_Handle | ||
91 | */ | ||
92 | struct GNUNET_TESTBED_HelperHandle; | ||
93 | |||
94 | |||
95 | /* /\** */ | ||
96 | /* * Run a given helper process at the given host. Communication */ | ||
97 | /* * with the helper will be via GNUnet messages on stdin/stdout. */ | ||
98 | /* * Runs the process via 'ssh' at the specified host, or locally. */ | ||
99 | /* * Essentially an SSH-wrapper around the 'gnunet_helper_lib.h' API. */ | ||
100 | /* * */ | ||
101 | /* * @param controller_ip the ip address of the controller. Will be set as TRUSTED */ | ||
102 | /* * host when starting testbed controller at host */ | ||
103 | /* * @param host host to use, use "NULL" for localhost */ | ||
104 | /* * @param binary_argv binary name and command-line arguments to give to the */ | ||
105 | /* * binary */ | ||
106 | /* * @param cfg template configuration to use for the remote controller; the */ | ||
107 | /* * remote controller will be started with a slightly modified */ | ||
108 | /* * configuration (port numbers, unix domain sockets and service home */ | ||
109 | /* * values are changed as per TESTING library on the remote host) */ | ||
110 | /* * @param cb the callback to run when helper process dies; cannot be NULL */ | ||
111 | /* * @param cb_cls the closure for the above callback */ | ||
112 | /* * @return handle to terminate the command, NULL on error */ | ||
113 | /* *\/ */ | ||
114 | /* struct GNUNET_TESTBED_HelperHandle * */ | ||
115 | /* GNUNET_TESTBED_host_run_ (const char *controller_ip, */ | ||
116 | /* const struct GNUNET_TESTBED_Host *host, */ | ||
117 | /* const struct GNUNET_CONFIGURATION_Handle *cfg, */ | ||
118 | /* GNUNET_HELPER_ExceptionCallback cb, */ | ||
119 | /* void *cb_cls); */ | ||
120 | |||
121 | |||
122 | |||
123 | /* /\** */ | ||
124 | /* * Stops a helper in the HelperHandle using GNUNET_HELPER_stop */ | ||
125 | /* * */ | ||
126 | /* * @param handle the handle returned from GNUNET_TESTBED_host_start_ */ | ||
127 | /* *\/ */ | ||
128 | /* void */ | ||
129 | /* GNUNET_TESTBED_host_stop_ (struct GNUNET_TESTBED_HelperHandle *handle); */ | ||
130 | |||
131 | |||
132 | /** | ||
133 | * Marks a host as registered with a controller | 90 | * Marks a host as registered with a controller |
134 | * | 91 | * |
135 | * @param host the host to mark | 92 | * @param host the host to mark |
@@ -154,6 +111,72 @@ GNUNET_TESTBED_is_host_registered_ (const struct GNUNET_TESTBED_Host *host, | |||
154 | *controller); | 111 | *controller); |
155 | 112 | ||
156 | 113 | ||
114 | /** | ||
115 | * (re)sets the operation queue for parallel overlay connects | ||
116 | * | ||
117 | * @param h the host handle | ||
118 | * @param npoc the number of parallel overlay connects - the queue size | ||
119 | */ | ||
120 | void | ||
121 | GNUNET_TESTBED_set_num_parallel_overlay_connects_ (struct | ||
122 | GNUNET_TESTBED_Host *h, | ||
123 | unsigned int npoc); | ||
124 | |||
125 | |||
126 | /** | ||
127 | * Releases a time slot thus making it available for be used again | ||
128 | * | ||
129 | * @param h the host handle | ||
130 | * @param index the index of the the time slot | ||
131 | * @param key the key to prove ownership of the timeslot | ||
132 | * @return GNUNET_YES if the time slot is successfully removed; GNUNET_NO if the | ||
133 | * time slot cannot be removed - this could be because of the index | ||
134 | * greater than existing number of time slots or `key' being different | ||
135 | */ | ||
136 | int | ||
137 | GNUNET_TESTBED_release_time_slot_ (struct GNUNET_TESTBED_Host *h, | ||
138 | unsigned int index, void *key); | ||
139 | |||
140 | |||
141 | /** | ||
142 | * Function to update a time slot | ||
143 | * | ||
144 | * @param h the host handle | ||
145 | * @param index the index of the time slot to update | ||
146 | * @param key the key to identify ownership of the slot | ||
147 | * @param time the new time | ||
148 | * @param failed should this reading be treated as coming from a fail event | ||
149 | */ | ||
150 | void | ||
151 | GNUNET_TESTBED_update_time_slot_ (struct GNUNET_TESTBED_Host *h, | ||
152 | unsigned int index, void *key, | ||
153 | struct GNUNET_TIME_Relative time, int failed); | ||
154 | |||
155 | |||
156 | /** | ||
157 | * Returns a timing slot which will be exclusively locked | ||
158 | * | ||
159 | * @param h the host handle | ||
160 | * @param key a pointer which is associated to the returned slot; should not be | ||
161 | * NULL. It serves as a key to determine the correct owner of the slot | ||
162 | * @return the time slot index in the array of time slots in the controller | ||
163 | * handle | ||
164 | */ | ||
165 | unsigned int | ||
166 | GNUNET_TESTBED_get_tslot_ (struct GNUNET_TESTBED_Host *h, void *key); | ||
167 | |||
168 | |||
169 | /** | ||
170 | * Queues the given operation in the queue for parallel overlay connects of the | ||
171 | * given host | ||
172 | * | ||
173 | * @param h the host handle | ||
174 | * @param op the operation to queue in the given host's parally overlay connect | ||
175 | * queue | ||
176 | */ | ||
177 | void | ||
178 | GNUNET_TESTBED_host_queue_oc (struct GNUNET_TESTBED_Host *h, | ||
179 | struct GNUNET_TESTBED_Operation *op); | ||
157 | 180 | ||
158 | #endif | 181 | #endif |
159 | /* end of testbed_api_hosts.h */ | 182 | /* end of testbed_api_hosts.h */ |
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c index 908428a83..039922fae 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c | |||
@@ -340,7 +340,7 @@ opstart_overlay_connect (void *cls) | |||
340 | opc->state = OPC_STATE_STARTED; | 340 | opc->state = OPC_STATE_STARTED; |
341 | data = opc->data; | 341 | data = opc->data; |
342 | GNUNET_assert (NULL != data); | 342 | GNUNET_assert (NULL != data); |
343 | data->tslot_index = GNUNET_TESTBED_get_tslot_ (opc->c, data); | 343 | data->tslot_index = GNUNET_TESTBED_get_tslot_ (data->p1->host, data); |
344 | data->tstart = GNUNET_TIME_absolute_get (); | 344 | data->tstart = GNUNET_TIME_absolute_get (); |
345 | msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)); | 345 | msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_OverlayConnectMessage)); |
346 | msg->header.size = | 346 | msg->header.size = |
@@ -373,13 +373,14 @@ oprelease_overlay_connect (void *cls) | |||
373 | case OPC_STATE_INIT: | 373 | case OPC_STATE_INIT: |
374 | break; | 374 | break; |
375 | case OPC_STATE_STARTED: | 375 | case OPC_STATE_STARTED: |
376 | (void) GNUNET_TESTBED_release_time_slot_ (opc->c, data->tslot_index, data); | 376 | (void) GNUNET_TESTBED_release_time_slot_ (data->p1->host, data->tslot_index, |
377 | data); | ||
377 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); | 378 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); |
378 | break; | 379 | break; |
379 | case OPC_STATE_FINISHED: | 380 | case OPC_STATE_FINISHED: |
380 | duration = GNUNET_TIME_absolute_get_duration (data->tstart); | 381 | duration = GNUNET_TIME_absolute_get_duration (data->tstart); |
381 | GNUNET_TESTBED_update_time_slot_ (opc->c, data->tslot_index, data, duration, | 382 | GNUNET_TESTBED_update_time_slot_ (data->p1->host, data->tslot_index, data, |
382 | data->failed); | 383 | duration, data->failed); |
383 | } | 384 | } |
384 | GNUNET_free (data); | 385 | GNUNET_free (data); |
385 | GNUNET_free (opc); | 386 | GNUNET_free (opc); |
@@ -693,9 +694,7 @@ GNUNET_TESTBED_overlay_connect (void *op_cls, | |||
693 | opc->op = | 694 | opc->op = |
694 | GNUNET_TESTBED_operation_create_ (opc, &opstart_overlay_connect, | 695 | GNUNET_TESTBED_operation_create_ (opc, &opstart_overlay_connect, |
695 | &oprelease_overlay_connect); | 696 | &oprelease_overlay_connect); |
696 | GNUNET_TESTBED_operation_queue_insert_ (opc-> | 697 | GNUNET_TESTBED_host_queue_oc (p1->host, opc->op); |
697 | c->opq_parallel_overlay_connect_operations, | ||
698 | opc->op); | ||
699 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | 698 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); |
700 | return opc->op; | 699 | return opc->op; |
701 | } | 700 | } |