2 This file is part of GNUnet.
3 (C) 2010-2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file ats-tests/ats-testing-experiment.c
22 * @brief ats benchmark: controlled experiment execution
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_util_lib.h"
28 #include "gnunet-ats-solver-eval.h"
30 #define BIG_M_STRING "unlimited"
32 static struct Experiment *e;
34 static struct LoggingHandle *l;
36 static struct SolverHandle *sh;
38 static struct TestPeer *peer_head;
39 static struct TestPeer *peer_tail;
41 static double default_properties[GNUNET_ATS_PropertyCount];
42 static double default_preferences[GNUNET_ATS_PreferenceCount];
45 * cmd option -e: experiment file
47 static char *opt_exp_file;
49 static char *opt_solver;
52 * cmd option -l: enable logging
57 * cmd option -p: enable plots
62 * cmd option -v: verbose logs
64 static int opt_verbose;
67 * cmd option -p: print logs
72 * cmd option -d: disable normalization
74 static int opt_disable_normalization;
82 get_property_cb (void *cls, const struct ATS_Address *address);
85 print_generator_type (enum GeneratorType g)
88 case GNUNET_ATS_TEST_TG_CONSTANT:
90 case GNUNET_ATS_TEST_TG_LINEAR:
92 case GNUNET_ATS_TEST_TG_RANDOM:
94 case GNUNET_ATS_TEST_TG_SINUS:
102 struct AddressLookupCtx
104 struct ATS_Address *res;
110 int find_address_it (void *cls,
111 const struct GNUNET_PeerIdentity *key,
114 struct AddressLookupCtx *ctx = cls;
115 struct ATS_Address *addr = value;
117 if ( (0 == strcmp (ctx->plugin, addr->plugin)) &&
118 (0 == strcmp (ctx->addr, addr->addr)) )
126 static struct TestPeer *
127 find_peer_by_id (int id)
129 struct TestPeer *cur;
130 for (cur = peer_head; NULL != cur; cur = cur->next)
136 static struct TestPeer *
137 find_peer_by_pid (const struct GNUNET_PeerIdentity *pid)
139 struct TestPeer *cur;
140 for (cur = peer_head; NULL != cur; cur = cur->next)
141 if (0 == memcmp (&cur->peer_id, pid, sizeof (struct GNUNET_PeerIdentity)))
146 static struct TestAddress *
147 find_address_by_id (struct TestPeer *peer, int aid)
149 struct TestAddress *cur;
150 for (cur = peer->addr_head; NULL != cur; cur = cur->next)
157 static struct TestAddress *
158 find_address_by_ats_address (struct TestPeer *p, const struct ATS_Address *addr)
160 struct TestAddress *cur;
161 for (cur = p->addr_head; NULL != cur; cur = cur->next)
162 if ((0 == strcmp(cur->ats_addr->plugin, addr->plugin)) &&
163 (cur->ats_addr->addr_len == addr->addr_len) &&
164 (0 == memcmp (cur->ats_addr->addr, addr->addr, addr->addr_len)))
175 GNUNET_ATS_solver_logging_now (struct LoggingHandle *l)
177 struct LoggingTimeStep *lts;
178 struct TestPeer *cur;
179 struct TestAddress *cur_addr;
180 struct LoggingPeer *log_p;
181 struct LoggingAddress *log_a;
184 lts = GNUNET_new (struct LoggingTimeStep);
185 GNUNET_CONTAINER_DLL_insert_tail(l->head, l->tail, lts);
186 lts->timestamp = GNUNET_TIME_absolute_get();
187 if (NULL == lts->prev)
188 lts->delta = GNUNET_TIME_UNIT_ZERO;
190 lts->delta = GNUNET_TIME_absolute_get_duration(lts->prev->timestamp);
192 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging %llu, delta %llu\n",
193 lts->timestamp.abs_value_us, lts->delta.rel_value_us);
196 /* Store logging data here */
197 for (cur = peer_head; NULL != cur; cur = cur->next)
199 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging peer id %llu\n", cur->id);
201 log_p = GNUNET_new (struct LoggingPeer);
203 log_p->peer_id = cur->peer_id;
204 log_p->is_requested = cur->is_requested;
205 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
207 log_p->pref_abs[c] = cur->pref_abs[c];
208 log_p->pref_norm[c] = cur->pref_norm[c];
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t %s = %.2f %.2f [abs/rel]\n",
210 GNUNET_ATS_print_preference_type(c),
211 log_p->pref_abs[c], log_p->pref_norm[c]);
213 GNUNET_CONTAINER_DLL_insert_tail(lts->head, lts->tail, log_p);
215 for (cur_addr = cur->addr_head; NULL != cur_addr; cur_addr = cur_addr->next)
217 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging peer id %llu address %llu \n",
218 cur->id, cur_addr->aid);
219 log_a = GNUNET_new (struct LoggingAddress);
220 log_a->aid = cur_addr->aid;
221 log_a->active = cur_addr->ats_addr->active;
222 log_a->network = cur_addr->network;
223 log_a->used = cur_addr->ats_addr->used;
224 log_a->assigned_bw_in = cur_addr->ats_addr->assigned_bw_in;
225 log_a->assigned_bw_out = cur_addr->ats_addr->assigned_bw_out;
226 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
228 log_a->prop_abs[c] = cur_addr->prop_abs[c];
229 log_a->prop_norm[c] = cur_addr->prop_norm[c];
230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t %s = %.2f %.2f [abs/rel]\n",
231 GNUNET_ATS_print_property_type(c),
232 log_a->prop_abs[c], log_a->prop_norm[c]);
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t Active = %i\n", log_a->active);
235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t BW in = %llu\n", ntohl(log_a->assigned_bw_in.value__));
236 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t BW out = %llu\n", ntohl(log_a->assigned_bw_out.value__));
238 GNUNET_CONTAINER_DLL_insert_tail (log_p->addr_head, log_p->addr_tail, log_a);
244 logging_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
246 struct LoggingHandle *l = cls;
247 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
249 GNUNET_ATS_solver_logging_now (l);
251 l->logging_task = GNUNET_SCHEDULER_add_delayed (l->log_freq, &logging_task, l);
255 struct LoggingHandle *
256 GNUNET_ATS_solver_logging_start (struct GNUNET_TIME_Relative freq)
258 struct LoggingHandle *l;
259 l = GNUNET_new (struct LoggingHandle);
261 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start logging every %s\n",
262 GNUNET_STRINGS_relative_time_to_string(freq, GNUNET_NO));
264 l->logging_task = GNUNET_SCHEDULER_add_now (&logging_task, l);
269 GNUNET_ATS_solver_logging_stop (struct LoggingHandle *l)
271 if (GNUNET_SCHEDULER_NO_TASK != l->logging_task)
272 GNUNET_SCHEDULER_cancel (l->logging_task);
274 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop logging\n");
276 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
279 static struct LoggingFileHandle *
280 find_logging_file_handle (struct LoggingFileHandle *lf_head,
281 struct LoggingFileHandle *lf_tail,
282 int peer_id, int address_id)
284 struct LoggingFileHandle *res;
286 for (res = lf_head; NULL != res; res = res->next)
287 if ((res->pid == peer_id) && (res->aid == address_id))
294 GNUNET_ATS_solver_logging_write_to_disk (struct LoggingHandle *l, int add_time_stamp,
297 struct LoggingTimeStep *lts;
298 struct LoggingPeer *log_p;
299 struct LoggingAddress *log_a;
300 struct LoggingFileHandle *lf_head;
301 struct LoggingFileHandle *lf_tail;
302 struct LoggingFileHandle *cur;
303 struct LoggingFileHandle *next;
307 char * propstring_tmp;
309 char * prefstring_tmp;
314 if (NULL != output_dir)
316 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (output_dir))
318 fprintf (stderr, "Failed to create directory `%s'\n", output_dir);
323 fprintf (stderr, "Created directory `%s'\n", output_dir);
324 use_dir = GNUNET_YES;
331 for (lts = l->head; NULL != lts; lts = lts->next)
334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing log step %llu\n",
335 (long long unsigned int) lts->timestamp.abs_value_us);
337 for (log_p = lts->head; NULL != log_p; log_p = log_p->next)
339 for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next)
342 cur = find_logging_file_handle (lf_head, lf_tail, log_p->id,
346 cur = GNUNET_new (struct LoggingFileHandle);
347 cur->aid = log_a->aid;
348 cur->pid = log_p->id;
350 if (GNUNET_YES == add_time_stamp)
351 GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u_%llu.log",
352 (GNUNET_YES == use_dir) ? output_dir : "",
353 (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "",
358 l->head->timestamp.abs_value_us);
360 GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u.log",
361 (GNUNET_YES == use_dir) ? output_dir : "",
362 (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "",
368 fprintf (stderr, "Add writing log data for peer %llu address %llu to file `%s'\n",
369 cur->pid, cur->aid, filename);
372 cur->f_hd = GNUNET_DISK_file_open (filename,
373 GNUNET_DISK_OPEN_READWRITE |
374 GNUNET_DISK_OPEN_CREATE |
375 GNUNET_DISK_OPEN_TRUNCATE,
376 GNUNET_DISK_PERM_USER_READ |
377 GNUNET_DISK_PERM_USER_WRITE |
378 GNUNET_DISK_PERM_GROUP_READ |
379 GNUNET_DISK_PERM_OTHER_READ);
380 if (NULL == cur->f_hd)
382 fprintf (stderr, "Cannot open `%s' to write log data!\n", filename);
383 GNUNET_free (filename);
386 GNUNET_free (filename);
387 GNUNET_CONTAINER_DLL_insert (lf_head, lf_tail, cur);
389 GNUNET_asprintf(&datastring,"#time delta;log duration;peer_requested;addr net; addr_active; bw in; bw out; " \
390 "UTILIZATION_UP [abs/rel]; UTILIZATION_UP; UTILIZATION_DOWN; UTILIZATION_DOWN; " \
391 "UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_DOWN; UTILIZATION_PAYLOAD_DOWN;"\
393 "DISTANCE ;DISTANCE ; COST_WAN; COST_WAN; COST_LAN; COST_LAN; " \
394 "COST_WLAN; COST_WLAN;COST_BT; COST_BT; PREF BW abs; PREF BW rel; PREF LATENCY abs; PREF LATENCY rel;\n");
395 GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring));
396 GNUNET_free (datastring);
400 prefstring = GNUNET_strdup("");
401 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
404 fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n",
405 GNUNET_ATS_print_preference_type(c),
406 log_p->pref_abs[c], log_p->pref_norm[c]);
408 GNUNET_asprintf(&prefstring_tmp,"%s;%.3f;%.3f",
409 prefstring, log_p->pref_abs[c], log_p->pref_norm[c]);
412 GNUNET_free (prefstring);
413 prefstring = GNUNET_strdup(prefstring_tmp);
414 GNUNET_free (prefstring_tmp);
418 propstring = GNUNET_strdup("");
419 for (c = 1; c < GNUNET_ATS_PropertyCount; c++)
421 if (GNUNET_ATS_NETWORK_TYPE == c)
424 fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n",
425 GNUNET_ATS_print_property_type(c),
426 log_a->prop_abs[c], log_a->prop_norm[c]);*/
427 GNUNET_asprintf(&propstring_tmp,"%s%.3f;%.3f;",
428 propstring, log_a->prop_abs[c], log_a->prop_norm[c]);
429 GNUNET_free (propstring);
430 propstring = GNUNET_strdup(propstring_tmp);
431 GNUNET_free (propstring_tmp);
433 GNUNET_asprintf(&datastring,"%llu;%llu;%u;%u;%i;%u;%u;%s;%s\n",
434 GNUNET_TIME_absolute_get_difference(l->head->timestamp, lts->timestamp).rel_value_us / 1000,
439 ntohl (log_a->assigned_bw_in.value__),
440 ntohl (log_a->assigned_bw_out.value__),
441 propstring, prefstring);
443 GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring));
444 GNUNET_free (datastring);
445 GNUNET_free (prefstring);
446 GNUNET_free (propstring);
453 for (cur = next; NULL != cur; cur = next)
456 GNUNET_CONTAINER_DLL_remove (lf_head, lf_tail, cur);
457 if (NULL != cur->f_hd)
458 GNUNET_DISK_file_close (cur->f_hd);
465 GNUNET_ATS_solver_logging_eval (struct LoggingHandle *l)
467 struct LoggingTimeStep *lts;
468 struct LoggingPeer *log_p;
469 struct LoggingAddress *log_a;
472 for (lts = l->head; NULL != lts; lts = lts->next)
474 fprintf (stderr, "Log step %llu %llu: \n",
475 (long long unsigned int) lts->timestamp.abs_value_us,
476 (long long unsigned int) lts->delta.rel_value_us);
478 for (log_p = lts->head; NULL != log_p; log_p = log_p->next)
480 fprintf (stderr,"\tLogging peer pid %llu\n", log_p->id);
481 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
483 fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n",
484 GNUNET_ATS_print_preference_type(c),
485 log_p->pref_abs[c], log_p->pref_norm[c]);
488 for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next)
490 fprintf (stderr, "\tPeer pid %llu address %llu: %u %u %u\n",
491 log_p->id, log_a->aid, log_a->active,
492 ntohl(log_a->assigned_bw_in.value__),
493 ntohl(log_a->assigned_bw_out.value__));
495 for (c = 1; c < GNUNET_ATS_PropertyCount; c++)
497 if (GNUNET_ATS_NETWORK_TYPE == c)
499 fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n",
500 GNUNET_ATS_print_property_type(c),
501 log_a->prop_abs[c], log_a->prop_norm[c]);
509 GNUNET_ATS_solver_logging_free (struct LoggingHandle *l)
511 struct LoggingTimeStep *lts_cur;
512 struct LoggingTimeStep *lts_next;
513 struct LoggingPeer *log_p_cur;
514 struct LoggingPeer *log_p_next;
515 struct LoggingAddress *log_a_cur;
516 struct LoggingAddress *log_a_next;
518 if (GNUNET_SCHEDULER_NO_TASK != l->logging_task)
519 GNUNET_SCHEDULER_cancel (l->logging_task);
520 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
523 while (NULL != (lts_cur = lts_next))
525 lts_next = lts_cur->next;
527 log_p_next = lts_cur->head;
528 while (NULL != (log_p_cur = log_p_next))
530 log_p_next = log_p_cur->next;
532 log_a_next = log_p_cur->addr_head;
533 while (NULL != (log_a_cur = log_a_next))
535 log_a_next = log_a_cur->next;
537 GNUNET_CONTAINER_DLL_remove (log_p_cur->addr_head, log_p_cur->addr_tail, log_a_cur);
538 GNUNET_free (log_a_cur);
541 GNUNET_CONTAINER_DLL_remove (lts_cur->head, lts_cur->tail, log_p_cur);
542 GNUNET_free (log_p_cur);
545 GNUNET_CONTAINER_DLL_remove (l->head, l->tail, lts_cur);
546 GNUNET_free (lts_cur);
553 * Property Generators
556 static struct PropertyGenerator *prop_gen_head;
557 static struct PropertyGenerator *prop_gen_tail;
560 get_property (struct PropertyGenerator *pg)
562 struct GNUNET_TIME_Relative time_delta;
566 /* Calculate the current preference value */
568 case GNUNET_ATS_TEST_TG_CONSTANT:
569 pref_value = pg->base_value;
571 case GNUNET_ATS_TEST_TG_LINEAR:
572 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
573 /* Calculate point of time in the current period */
574 time_delta.rel_value_us = time_delta.rel_value_us %
575 pg->duration_period.rel_value_us;
576 delta_value = ((double) time_delta.rel_value_us /
577 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
578 if ((pg->max_value < pg->base_value) &&
579 ((pg->max_value - pg->base_value) > pg->base_value))
581 /* This will cause an underflow */
584 pref_value = pg->base_value + delta_value;
586 case GNUNET_ATS_TEST_TG_RANDOM:
587 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
588 10000 * (pg->max_value - pg->base_value)) / 10000;
589 pref_value = pg->base_value + delta_value;
591 case GNUNET_ATS_TEST_TG_SINUS:
592 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
593 /* Calculate point of time in the current period */
594 time_delta.rel_value_us = time_delta.rel_value_us %
595 pg->duration_period.rel_value_us;
596 if ((pg->max_value - pg->base_value) > pg->base_value)
598 /* This will cause an underflow for second half of sinus period,
599 * will be detected in general when experiments are loaded */
602 delta_value = (pg->max_value - pg->base_value) *
603 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
604 time_delta.rel_value_us);
605 pref_value = pg->base_value + delta_value;
611 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current property value is %f\n",
618 set_prop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
620 struct PropertyGenerator *pg = cls;
622 struct TestAddress *a;
624 struct GNUNET_ATS_Information atsi;
626 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
628 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains_value (sh->addresses,
629 &pg->test_peer->peer_id, pg->test_address->ats_addr))
632 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
633 "Setting property generation for unknown address [%u:%u]\n",
634 pg->peer, pg->address_id);
637 if (NULL == (p = find_peer_by_id (pg->peer)))
639 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
640 "Setting property generation for unknown peer %u\n",
643 if (NULL == (a = find_address_by_id (p, pg->address_id)))
645 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
646 "Setting property generation for unknown peer %u\n",
650 prop_value = get_property (pg);
651 a->prop_abs[pg->ats_property] = prop_value;
653 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
654 "Setting property for peer [%u] address [%u] for %s to %f\n",
655 pg->peer, pg->address_id,
656 GNUNET_ATS_print_property_type (pg->ats_property), prop_value);
658 atsi.type = htonl (pg->ats_property);
659 atsi.value = htonl ((uint32_t) prop_value);
661 /* set performance here! */
662 sh->env.sf.s_bulk_start (sh->solver);
663 if (GNUNET_YES == opt_disable_normalization)
665 a->prop_abs[pg->ats_property] = prop_value;
666 a->prop_norm[pg->ats_property] = prop_value;
667 sh->env.sf.s_address_update_property (sh->solver, a->ats_addr,
668 pg->ats_property, prop_value, prop_value);
671 GAS_normalization_normalize_property (sh->addresses,
672 pg->test_address->ats_addr, &atsi, 1);
673 sh->env.sf.s_bulk_stop (sh->solver);
675 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
681 * Set ats_property to 0 to find all pgs
684 static struct PropertyGenerator *
685 find_prop_gen (unsigned int peer, unsigned int address,
686 uint32_t ats_property)
688 struct PropertyGenerator *cur;
689 for (cur = prop_gen_head; NULL != cur; cur = cur->next)
690 if ((cur->peer == peer) && (cur->address_id == address))
692 if ((cur->ats_property == ats_property) || (0 == ats_property))
699 GNUNET_ATS_solver_generate_property_stop (struct PropertyGenerator *pg)
701 GNUNET_CONTAINER_DLL_remove (prop_gen_head, prop_gen_tail, pg);
703 if (GNUNET_SCHEDULER_NO_TASK != pg->set_task)
705 GNUNET_SCHEDULER_cancel (pg->set_task);
706 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
708 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
709 "Removing old up preference generator peer [%u] address [%u] `%s'\n",
710 pg->peer, pg->address_id,
711 GNUNET_ATS_print_property_type(pg->ats_property));
718 * Generate between the source master and the partner and set property with a
719 * value depending on the generator.
722 * @param address_id partner
723 * @param test_peer the peer
724 * @param test_address the address
725 * @param type type of generator
726 * @param base_value base value
727 * @param value_rate maximum value
728 * @param period duration of a period of generation (~ 1/frequency)
729 * @param frequency how long to generate property
730 * @param ats_property ATS property to generate
731 * @return the property generator
733 struct PropertyGenerator *
734 GNUNET_ATS_solver_generate_property_start (unsigned int peer,
735 unsigned int address_id,
736 struct TestPeer *test_peer,
737 struct TestAddress *test_address,
738 enum GeneratorType type,
741 struct GNUNET_TIME_Relative period,
742 struct GNUNET_TIME_Relative frequency,
743 uint32_t ats_property)
745 struct PropertyGenerator *pg;
747 pg = GNUNET_new (struct PropertyGenerator);
748 GNUNET_CONTAINER_DLL_insert (prop_gen_head, prop_gen_tail, pg);
751 pg->test_address = test_address;
752 pg->test_peer = test_peer;
753 pg->address_id = address_id;
754 pg->ats_property = ats_property;
755 pg->base_value = base_value;
756 pg->max_value = value_rate;
757 pg->duration_period = period;
758 pg->frequency = frequency;
759 pg->time_start = GNUNET_TIME_absolute_get();
762 case GNUNET_ATS_TEST_TG_CONSTANT:
763 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
764 "Setting up %s property generator peer [%u] address [%u] `%s'"\
766 print_generator_type(type), pg->peer, pg->address_id,
767 GNUNET_ATS_print_property_type (ats_property),
770 case GNUNET_ATS_TEST_TG_LINEAR:
771 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
772 "Setting up %s property generator peer [%u] address [%u] `%s' " \
773 "min %u Bips max %u Bips\n",
774 print_generator_type(type), pg->peer, pg->address_id,
775 GNUNET_ATS_print_property_type(ats_property),
776 base_value, value_rate);
778 case GNUNET_ATS_TEST_TG_SINUS:
779 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
780 "Setting up %s property generator peer [%u] address [%u] `%s' "\
781 "baserate %u Bips, amplitude %u Bps\n",
782 print_generator_type(type), pg->peer, pg->address_id,
783 GNUNET_ATS_print_property_type(ats_property),
784 base_value, value_rate);
786 case GNUNET_ATS_TEST_TG_RANDOM:
787 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
788 "Setting up %s property generator peer [%u] address [%u] `%s' "\
789 "min %u Bips max %u Bps\n",
790 print_generator_type(type), pg->peer, pg->address_id,
791 GNUNET_ATS_print_property_type(ats_property),
792 base_value, value_rate);
798 pg->set_task = GNUNET_SCHEDULER_add_now (&set_prop_task, pg);
805 * Stop all preferences generators
808 GNUNET_ATS_solver_generate_property_stop_all ()
810 struct PropertyGenerator *cur;
811 struct PropertyGenerator *next;
812 next = prop_gen_head;
813 for (cur = next; NULL != cur; cur = next)
816 GNUNET_ATS_solver_generate_property_stop (cur);
822 * Preference Generators
825 static struct PreferenceGenerator *pref_gen_head;
826 static struct PreferenceGenerator *pref_gen_tail;
829 get_preference (struct PreferenceGenerator *pg)
831 struct GNUNET_TIME_Relative time_delta;
835 /* Calculate the current preference value */
837 case GNUNET_ATS_TEST_TG_CONSTANT:
838 pref_value = pg->base_value;
840 case GNUNET_ATS_TEST_TG_LINEAR:
841 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
842 /* Calculate point of time in the current period */
843 time_delta.rel_value_us = time_delta.rel_value_us %
844 pg->duration_period.rel_value_us;
845 delta_value = ((double) time_delta.rel_value_us /
846 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
847 if ((pg->max_value < pg->base_value) &&
848 ((pg->max_value - pg->base_value) > pg->base_value))
850 /* This will cause an underflow */
853 pref_value = pg->base_value + delta_value;
855 case GNUNET_ATS_TEST_TG_RANDOM:
856 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
857 10000 * (pg->max_value - pg->base_value)) / 10000;
858 pref_value = pg->base_value + delta_value;
860 case GNUNET_ATS_TEST_TG_SINUS:
861 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
862 /* Calculate point of time in the current period */
863 time_delta.rel_value_us = time_delta.rel_value_us %
864 pg->duration_period.rel_value_us;
865 if ((pg->max_value - pg->base_value) > pg->base_value)
867 /* This will cause an underflow for second half of sinus period,
868 * will be detected in general when experiments are loaded */
871 delta_value = (pg->max_value - pg->base_value) *
872 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
873 time_delta.rel_value_us);
874 pref_value = pg->base_value + delta_value;
880 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
886 set_feedback_task (void *cls,
887 const struct GNUNET_SCHEDULER_TaskContext *tc)
889 struct PreferenceGenerator *pg = cls;
894 uint32_t delay_acc_in;
895 struct GNUNET_TIME_Relative dur;
898 pg->feedback_task = GNUNET_SCHEDULER_NO_TASK;
900 if (NULL == (p = find_peer_by_id (pg->peer)))
903 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
904 "Setting feedback for unknown peer %u\n", pg->peer);
909 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
910 dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update);
911 bw_acc_in = dur.rel_value_us *pg->last_assigned_bw_in + pg->feedback_bw_in_acc;
912 pg->feedback_bw_in_acc = 0;
914 bw_acc_out = dur.rel_value_us *pg->last_assigned_bw_out + pg->feedback_bw_out_acc;
915 p_new = get_preference (pg);
916 feedback = (p_new / pg->pref_bw_old) * (bw_acc_in + bw_acc_out) /
917 (2 *GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us);
920 case GNUNET_ATS_PREFERENCE_LATENCY:
921 dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_delay_update);
922 delay_acc_in =dur.rel_value_us *pg->last_delay_value + pg->feedback_delay_acc;
923 pg->feedback_delay_acc = 0;
925 p_new = get_preference (pg);
926 feedback = (p_new / pg->pref_latency_old) * (delay_acc_in) /
927 (GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us);
933 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
934 "Giving feedback for peer [%u] for client %p pref %s of %.3f\n",
935 pg->peer, NULL + (pg->client_id),
936 GNUNET_ATS_print_preference_type (pg->kind),
939 sh->env.sf.s_feedback (sh->solver, NULL + (pg->client_id), &p->peer_id,
940 pg->feedback_frequency, pg->kind, feedback);
941 pg->feedback_last = GNUNET_TIME_absolute_get();
944 pg->feedback_bw_out_acc = 0;
945 pg->feedback_bw_in_acc = 0;
946 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
948 pg->feedback_delay_acc = 0;
949 pg->feedback_last_delay_update = GNUNET_TIME_absolute_get();
952 pg->feedback_task = GNUNET_SCHEDULER_add_delayed (pg->feedback_frequency,
953 &set_feedback_task, pg);
957 set_pref_task (void *cls,
958 const struct GNUNET_SCHEDULER_TaskContext *tc)
960 struct PreferenceGenerator *pg = cls;
963 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
965 if (NULL == (p = find_peer_by_id (pg->peer)))
968 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
969 "Setting preference for unknown peer %u\n", pg->peer);
973 pref_value = get_preference (pg);
975 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
976 pg->pref_bw_old = pref_value;
978 case GNUNET_ATS_PREFERENCE_LATENCY:
979 pg->pref_latency_old = pref_value;
985 p->pref_abs[pg->kind] = pref_value;
987 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
988 "Setting preference for peer [%u] for client %p pref %s to %f\n",
989 pg->peer, NULL + (pg->client_id),
990 GNUNET_ATS_print_preference_type (pg->kind), pref_value);
992 sh->env.sf.s_bulk_start (sh->solver);
993 if (GNUNET_YES == opt_disable_normalization)
995 p->pref_abs[pg->kind] = pref_value;
996 p->pref_norm[pg->kind] = pref_value;
997 sh->env.sf.s_pref (sh->solver, &p->peer_id, pg->kind, pref_value);
1000 GAS_normalization_normalize_preference (NULL + (pg->client_id),
1001 &p->peer_id, pg->kind, pref_value);
1002 sh->env.sf.s_bulk_stop (sh->solver);
1004 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
1009 static struct PreferenceGenerator *
1010 find_pref_gen (unsigned int peer, enum GNUNET_ATS_PreferenceKind kind)
1012 struct PreferenceGenerator *cur;
1013 for (cur = pref_gen_head; NULL != cur; cur = cur->next)
1014 if (cur->peer == peer)
1016 if ((cur->kind == kind) || (GNUNET_ATS_PREFERENCE_END == kind))
1023 GNUNET_ATS_solver_generate_preferences_stop (struct PreferenceGenerator *pg)
1025 GNUNET_CONTAINER_DLL_remove (pref_gen_head, pref_gen_tail, pg);
1027 if (GNUNET_SCHEDULER_NO_TASK != pg->feedback_task)
1029 GNUNET_SCHEDULER_cancel (pg->feedback_task);
1030 pg->feedback_task = GNUNET_SCHEDULER_NO_TASK;
1033 if (GNUNET_SCHEDULER_NO_TASK != pg->set_task)
1035 GNUNET_SCHEDULER_cancel (pg->set_task);
1036 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
1038 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1039 "Removing old up preference generator peer [%u] `%s'\n",
1040 pg->peer, GNUNET_ATS_print_preference_type(pg->kind));
1046 find_active_address (struct TestPeer *p)
1048 struct TestAddress *cur;
1049 for (cur = p->addr_head; NULL != cur; cur = cur->next)
1050 if (GNUNET_YES == cur->ats_addr->active)
1056 * Generate between the source master and the partner and set property with a
1057 * value depending on the generator.
1059 * @param peer source
1060 * @param address_id partner
1061 * @param client_id the client
1062 * @param type type of generator
1063 * @param base_value base value
1064 * @param value_rate maximum value
1065 * @param period duration of a period of generation (~ 1/frequency)
1066 * @param frequency how long to generate property
1067 * @param kind ATS preference to generate
1068 * @return the preference generator
1070 struct PreferenceGenerator *
1071 GNUNET_ATS_solver_generate_preferences_start (unsigned int peer,
1072 unsigned int address_id,
1073 unsigned int client_id,
1074 enum GeneratorType type,
1075 long int base_value,
1076 long int value_rate,
1077 struct GNUNET_TIME_Relative period,
1078 struct GNUNET_TIME_Relative frequency,
1079 enum GNUNET_ATS_PreferenceKind kind,
1080 struct GNUNET_TIME_Relative feedback_frequency)
1082 struct PreferenceGenerator *pg;
1085 if (NULL == (p = find_peer_by_id (peer)))
1088 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1089 "Starting preference for unknown peer %u\n", peer);
1093 pg = GNUNET_new (struct PreferenceGenerator);
1094 GNUNET_CONTAINER_DLL_insert (pref_gen_head, pref_gen_tail, pg);
1097 pg->client_id = client_id;
1099 pg->base_value = base_value;
1100 pg->max_value = value_rate;
1101 pg->duration_period = period;
1102 pg->frequency = frequency;
1103 pg->time_start = GNUNET_TIME_absolute_get();
1104 pg->feedback_frequency = feedback_frequency;
1107 case GNUNET_ATS_TEST_TG_CONSTANT:
1108 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1109 "Setting up %s preference generator peer [%u] `%s' max %u Bips\n",
1110 print_generator_type (type), pg->peer,
1111 GNUNET_ATS_print_preference_type(kind),
1114 case GNUNET_ATS_TEST_TG_LINEAR:
1115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1116 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bips\n",
1117 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1118 base_value, value_rate);
1120 case GNUNET_ATS_TEST_TG_SINUS:
1121 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1122 "Setting up %s preference generator peer [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
1123 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1124 base_value, value_rate);
1126 case GNUNET_ATS_TEST_TG_RANDOM:
1127 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1128 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bps\n",
1129 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1130 base_value, value_rate);
1136 pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, pg);
1137 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != feedback_frequency.rel_value_us)
1139 struct TestAddress * addr = find_active_address(p);
1140 const double *properties = get_property_cb (NULL, addr->ats_addr);
1142 pg->last_assigned_bw_in = ntohl(p->assigned_bw_in.value__);
1143 pg->last_assigned_bw_out = ntohl(p->assigned_bw_out.value__);
1144 pg->feedback_bw_in_acc = 0;
1145 pg->feedback_bw_out_acc = 0;
1147 pg->last_delay_value = properties[GNUNET_ATS_QUALITY_NET_DELAY];
1148 pg->feedback_delay_acc = 0;
1150 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
1151 pg->feedback_last_delay_update = GNUNET_TIME_absolute_get();
1152 pg->feedback_last = GNUNET_TIME_absolute_get();
1153 pg->feedback_task = GNUNET_SCHEDULER_add_delayed (feedback_frequency,
1154 &set_feedback_task, pg);
1163 * Stop all preferences generators
1166 GNUNET_ATS_solver_generate_preferences_stop_all ()
1168 struct PreferenceGenerator *cur;
1169 struct PreferenceGenerator *next;
1170 next = pref_gen_head;
1171 for (cur = next; NULL != cur; cur = next)
1174 GNUNET_ATS_solver_generate_preferences_stop(cur);
1185 print_op (enum OperationType op)
1188 case SOLVER_OP_ADD_ADDRESS:
1189 return "ADD_ADDRESS";
1190 case SOLVER_OP_DEL_ADDRESS:
1191 return "DEL_ADDRESS";
1192 case SOLVER_OP_START_SET_PREFERENCE:
1193 return "START_SET_PREFERENCE";
1194 case SOLVER_OP_STOP_SET_PREFERENCE:
1195 return "STOP_STOP_PREFERENCE";
1196 case SOLVER_OP_START_SET_PROPERTY:
1197 return "START_SET_PROPERTY";
1198 case SOLVER_OP_STOP_SET_PROPERTY:
1199 return "STOP_SET_PROPERTY";
1200 case SOLVER_OP_START_REQUEST:
1201 return "START_REQUEST";
1202 case SOLVER_OP_STOP_REQUEST:
1203 return "STOP_REQUEST";
1210 static struct Experiment *
1211 create_experiment ()
1213 struct Experiment *e;
1214 e = GNUNET_new (struct Experiment);
1217 e->total_duration = GNUNET_TIME_UNIT_ZERO;
1222 free_experiment (struct Experiment *e)
1224 struct Episode *cur;
1225 struct Episode *next;
1226 struct GNUNET_ATS_TEST_Operation *cur_o;
1227 struct GNUNET_ATS_TEST_Operation *next_o;
1230 for (cur = next; NULL != cur; cur = next)
1235 for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
1237 next_o = cur_o->next;
1238 GNUNET_free_non_null (cur_o->address);
1239 GNUNET_free_non_null (cur_o->plugin);
1240 GNUNET_free (cur_o);
1245 GNUNET_free_non_null (e->name);
1246 GNUNET_free_non_null (e->log_prefix);
1247 GNUNET_free_non_null (e->log_output_dir);
1248 GNUNET_free_non_null (e->cfg_file);
1254 load_op_add_address (struct GNUNET_ATS_TEST_Operation *o,
1258 const struct GNUNET_CONFIGURATION_Handle *cfg)
1264 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1265 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1266 sec_name, op_name, &o->peer_id))
1268 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1269 op_counter, "ADD_ADDRESS", op_name);
1270 GNUNET_free (op_name);
1271 return GNUNET_SYSERR;
1273 GNUNET_free (op_name);
1276 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1277 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1278 sec_name, op_name, &o->address_id))
1280 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1281 op_counter, "ADD_ADDRESS", op_name);
1282 GNUNET_free (op_name);
1283 return GNUNET_SYSERR;
1285 GNUNET_free (op_name);
1288 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
1289 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1290 sec_name, op_name, &o->plugin))
1292 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
1293 op_counter, "ADD_ADDRESS", op_name);
1294 GNUNET_free (op_name);
1295 return GNUNET_SYSERR;
1297 GNUNET_free (op_name);
1300 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
1301 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1302 sec_name, op_name, &o->address))
1304 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
1305 op_counter, "ADD_ADDRESS", op_name);
1306 GNUNET_free (op_name);
1307 return GNUNET_SYSERR;
1309 GNUNET_free (op_name);
1312 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
1313 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1314 sec_name, op_name, &o->address_session))
1316 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
1317 op_counter, "ADD_ADDRESS", op_name);
1318 GNUNET_free (op_name);
1319 return GNUNET_SYSERR;
1321 GNUNET_free (op_name);
1324 GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter);
1325 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1326 sec_name, op_name, &op_network))
1328 fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
1329 op_counter, "ADD_ADDRESS", op_name);
1330 GNUNET_free (op_name);
1331 return GNUNET_SYSERR;
1335 GNUNET_STRINGS_utf8_toupper (op_network,op_network);
1336 if (0 == strcmp(op_network, "UNSPECIFIED"))
1338 o->address_network = GNUNET_ATS_NET_UNSPECIFIED;
1340 else if (0 == strcmp(op_network, "LOOPBACK"))
1342 o->address_network = GNUNET_ATS_NET_LOOPBACK;
1344 else if (0 == strcmp(op_network, "LAN"))
1346 o->address_network = GNUNET_ATS_NET_LAN;
1348 else if (0 == strcmp(op_network, "WAN"))
1350 o->address_network = GNUNET_ATS_NET_WAN;
1352 else if (0 == strcmp(op_network, "WLAN"))
1354 o->address_network = GNUNET_ATS_NET_WLAN;
1356 else if (0 == strcmp(op_network, "BT"))
1358 o->address_network = GNUNET_ATS_NET_BT;
1362 fprintf (stderr, "Invalid address-network in operation %u `%s' in episode `%s': `%s'\n",
1363 op_counter, "ADD_ADDRESS", op_name, op_network);
1364 GNUNET_free (op_network);
1365 GNUNET_free (op_name);
1366 return GNUNET_SYSERR;
1369 GNUNET_free (op_network);
1370 GNUNET_free (op_name);
1372 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1373 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
1374 "ADD_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
1380 load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
1384 const struct GNUNET_CONFIGURATION_Handle *cfg)
1390 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1391 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1392 sec_name, op_name, &o->peer_id))
1394 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1395 op_counter, "DEL_ADDRESS", op_name);
1396 GNUNET_free (op_name);
1397 return GNUNET_SYSERR;
1399 GNUNET_free (op_name);
1402 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1403 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1404 sec_name, op_name, &o->address_id))
1406 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1407 op_counter, "DEL_ADDRESS", op_name);
1408 GNUNET_free (op_name);
1409 return GNUNET_SYSERR;
1411 GNUNET_free (op_name);
1415 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
1416 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1417 sec_name, op_name, &o->plugin))
1419 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
1420 op_counter, "DEL_ADDRESS", op_name);
1421 GNUNET_free (op_name);
1422 return GNUNET_SYSERR;
1424 GNUNET_free (op_name);
1427 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
1428 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1429 sec_name, op_name, &o->address))
1431 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
1432 op_counter, "DEL_ADDRESS", op_name);
1433 GNUNET_free (op_name);
1434 return GNUNET_SYSERR;
1436 GNUNET_free (op_name);
1439 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
1440 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1441 sec_name, op_name, &o->address_session))
1443 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
1444 op_counter, "DEL_ADDRESS", op_name);
1445 GNUNET_free (op_name);
1446 return GNUNET_SYSERR;
1448 GNUNET_free (op_name);
1451 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1452 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
1453 "DEL_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
1458 static enum GNUNET_ATS_Property
1459 parse_preference_string (const char * str)
1462 char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
1464 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
1465 if (0 == strcmp(str, props[c]))
1471 load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1475 const struct GNUNET_CONFIGURATION_Handle *cfg)
1482 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1483 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1484 sec_name, op_name, &o->peer_id))
1486 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1487 op_counter, "START_SET_PREFERENCE", op_name);
1488 GNUNET_free (op_name);
1489 return GNUNET_SYSERR;
1491 GNUNET_free (op_name);
1494 GNUNET_asprintf(&op_name, "op-%u-client-id", op_counter);
1495 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1496 sec_name, op_name, &o->client_id))
1498 fprintf (stderr, "Missing client-id in operation %u `%s' in episode `%s'\n",
1499 op_counter, "START_SET_PREFERENCE", op_name);
1500 GNUNET_free (op_name);
1501 return GNUNET_SYSERR;
1503 GNUNET_free (op_name);
1506 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1507 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1508 sec_name, op_name, &type)) )
1510 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1511 op_counter, "START_SET_PREFERENCE", op_name);
1512 GNUNET_free (op_name);
1513 return GNUNET_SYSERR;
1516 /* Load arguments for set_rate, start_send, set_preference */
1517 if (0 == strcmp (type, "constant"))
1519 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1521 else if (0 == strcmp (type, "linear"))
1523 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1525 else if (0 == strcmp (type, "sinus"))
1527 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1529 else if (0 == strcmp (type, "random"))
1531 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1535 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1536 op_counter, op_name, e->id);
1538 GNUNET_free (op_name);
1539 return GNUNET_SYSERR;
1542 GNUNET_free (op_name);
1546 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1547 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1548 sec_name, op_name, &o->base_rate))
1550 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1551 op_counter, op_name, e->id);
1552 GNUNET_free (op_name);
1553 return GNUNET_SYSERR;
1555 GNUNET_free (op_name);
1559 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1560 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1561 sec_name, op_name, &o->max_rate))
1563 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1564 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1565 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1567 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1568 op_counter, op_name, e->id);
1569 GNUNET_free (op_name);
1570 return GNUNET_SYSERR;
1573 GNUNET_free (op_name);
1576 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1577 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1578 sec_name, op_name, &o->period))
1580 o->period = e->duration;
1582 GNUNET_free (op_name);
1585 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1586 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1587 sec_name, op_name, &o->frequency))
1589 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1590 op_counter, op_name, e->id);
1591 GNUNET_free (op_name);
1592 return GNUNET_SYSERR;
1594 GNUNET_free (op_name);
1596 /* Get preference */
1597 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1598 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1599 sec_name, op_name, &pref))
1601 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
1602 op_counter, op_name, e->id);
1603 GNUNET_free (op_name);
1604 return GNUNET_SYSERR;
1607 if (0 == (o->pref_type = parse_preference_string(pref)))
1609 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1610 op_counter, op_name, e->id);
1611 GNUNET_free (op_name);
1613 return GNUNET_SYSERR;
1616 GNUNET_free (op_name);
1618 /* Get feedback delay */
1619 GNUNET_asprintf(&op_name, "op-%u-feedback_delay", op_counter);
1620 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time (cfg,
1621 sec_name, op_name, &o->feedback_delay))
1623 fprintf (stderr, "Using feedback delay %llu in operation %u `%s' in episode %u\n",
1624 (long long unsigned int) o->feedback_delay.rel_value_us,
1625 op_counter, op_name, e->id);
1628 o->feedback_delay = GNUNET_TIME_UNIT_FOREVER_REL;
1629 GNUNET_free (op_name);
1631 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1632 "Found operation %s: [%llu:%llu]: %s = %llu\n",
1633 "START_SET_PREFERENCE", o->peer_id, o->address_id,
1634 GNUNET_ATS_print_preference_type(o->pref_type), o->base_rate);
1640 load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1644 const struct GNUNET_CONFIGURATION_Handle *cfg)
1650 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1651 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1652 sec_name, op_name, &o->peer_id))
1654 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1655 op_counter, "STOP_SET_PREFERENCE", op_name);
1656 GNUNET_free (op_name);
1657 return GNUNET_SYSERR;
1659 GNUNET_free (op_name);
1662 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1663 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1664 sec_name, op_name, &o->address_id))
1666 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1667 op_counter, "STOP_SET_PREFERENCE", op_name);
1668 GNUNET_free (op_name);
1669 return GNUNET_SYSERR;
1671 GNUNET_free (op_name);
1673 /* Get preference */
1674 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1675 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1676 sec_name, op_name, &pref))
1678 fprintf (stderr, "Missing preference in operation %u `%s' in episode `%s'\n",
1679 op_counter, "STOP_SET_PREFERENCE", op_name);
1680 GNUNET_free (op_name);
1681 return GNUNET_SYSERR;
1684 if (0 == (o->pref_type = parse_preference_string(pref)))
1686 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1687 op_counter, op_name, e->id);
1688 GNUNET_free (op_name);
1690 return GNUNET_SYSERR;
1693 GNUNET_free (op_name);
1695 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1696 "Found operation %s: [%llu:%llu]: %s\n",
1697 "STOP_SET_PREFERENCE", o->peer_id, o->address_id,
1698 GNUNET_ATS_print_preference_type(o->pref_type));
1702 static enum GNUNET_ATS_Property
1703 parse_property_string (const char * str)
1706 char *props[GNUNET_ATS_PropertyCount] = GNUNET_ATS_PropertyStrings;
1708 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
1709 if (0 == strcmp(str, props[c]))
1715 load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o,
1719 const struct GNUNET_CONFIGURATION_Handle *cfg)
1726 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1727 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1728 sec_name, op_name, &o->peer_id))
1730 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1731 op_counter, "START_SET_PROPERTY", op_name);
1732 GNUNET_free (op_name);
1733 return GNUNET_SYSERR;
1735 GNUNET_free (op_name);
1738 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1739 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1740 sec_name, op_name, &o->address_id))
1742 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1743 op_counter, "START_SET_PROPERTY", op_name);
1744 GNUNET_free (op_name);
1745 return GNUNET_SYSERR;
1747 GNUNET_free (op_name);
1750 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1751 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1752 sec_name, op_name, &type)) )
1754 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1755 op_counter, "START_SET_PROPERTY", op_name);
1756 GNUNET_free (op_name);
1757 return GNUNET_SYSERR;
1760 /* Load arguments for set_rate, start_send, set_preference */
1761 if (0 == strcmp (type, "constant"))
1763 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1765 else if (0 == strcmp (type, "linear"))
1767 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1769 else if (0 == strcmp (type, "sinus"))
1771 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1773 else if (0 == strcmp (type, "random"))
1775 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1779 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1780 op_counter, op_name, e->id);
1782 GNUNET_free (op_name);
1783 return GNUNET_SYSERR;
1786 GNUNET_free (op_name);
1790 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1791 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1792 sec_name, op_name, &o->base_rate))
1794 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1795 op_counter, op_name, e->id);
1796 GNUNET_free (op_name);
1797 return GNUNET_SYSERR;
1799 GNUNET_free (op_name);
1803 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1804 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1805 sec_name, op_name, &o->max_rate))
1807 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1808 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1809 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1811 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1812 op_counter, op_name, e->id);
1813 GNUNET_free (op_name);
1814 return GNUNET_SYSERR;
1817 GNUNET_free (op_name);
1820 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1821 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1822 sec_name, op_name, &o->period))
1824 o->period = e->duration;
1826 GNUNET_free (op_name);
1829 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1830 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1831 sec_name, op_name, &o->frequency))
1833 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1834 op_counter, op_name, e->id);
1835 GNUNET_free (op_name);
1836 return GNUNET_SYSERR;
1838 GNUNET_free (op_name);
1840 /* Get preference */
1841 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1842 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1843 sec_name, op_name, &prop))
1845 fprintf (stderr, "Missing property in operation %u `%s' in episode %u\n",
1846 op_counter, op_name, e->id);
1847 GNUNET_free (op_name);
1848 GNUNET_free_non_null (prop);
1849 return GNUNET_SYSERR;
1852 if (0 == (o->prop_type = parse_property_string(prop)))
1854 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1855 op_counter, op_name, e->id);
1856 GNUNET_free (op_name);
1858 return GNUNET_SYSERR;
1862 GNUNET_free (op_name);
1864 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1865 "Found operation %s: [%llu:%llu] %s = %llu\n",
1866 "START_SET_PROPERTY", o->peer_id, o->address_id,
1867 GNUNET_ATS_print_property_type (o->prop_type), o->base_rate);
1873 load_op_stop_set_property (struct GNUNET_ATS_TEST_Operation *o,
1877 const struct GNUNET_CONFIGURATION_Handle *cfg)
1883 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1884 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1885 sec_name, op_name, &o->peer_id))
1887 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1888 op_counter, "STOP_SET_PROPERTY", op_name);
1889 GNUNET_free (op_name);
1890 return GNUNET_SYSERR;
1892 GNUNET_free (op_name);
1895 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1896 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1897 sec_name, op_name, &o->address_id))
1899 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1900 op_counter, "STOP_SET_PROPERTY", op_name);
1901 GNUNET_free (op_name);
1902 return GNUNET_SYSERR;
1904 GNUNET_free (op_name);
1907 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1908 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1909 sec_name, op_name, &pref))
1911 fprintf (stderr, "Missing property in operation %u `%s' in episode `%s'\n",
1912 op_counter, "STOP_SET_PROPERTY", op_name);
1913 GNUNET_free (op_name);
1914 GNUNET_free_non_null (pref);
1915 return GNUNET_SYSERR;
1918 if (0 == (o->prop_type = parse_property_string(pref)))
1920 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1921 op_counter, op_name, e->id);
1922 GNUNET_free (op_name);
1923 GNUNET_free_non_null (pref);
1924 return GNUNET_SYSERR;
1928 GNUNET_free (op_name);
1930 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1931 "Found operation %s: [%llu:%llu] %s\n",
1932 "STOP_SET_PROPERTY", o->peer_id, o->address_id,
1933 GNUNET_ATS_print_property_type (o->prop_type));
1940 load_op_start_request (struct GNUNET_ATS_TEST_Operation *o,
1944 const struct GNUNET_CONFIGURATION_Handle *cfg)
1949 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1950 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1951 sec_name, op_name, &o->peer_id))
1953 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1954 op_counter, "START_REQUEST", op_name);
1955 GNUNET_free (op_name);
1956 return GNUNET_SYSERR;
1958 GNUNET_free (op_name);
1963 load_op_stop_request (struct GNUNET_ATS_TEST_Operation *o,
1967 const struct GNUNET_CONFIGURATION_Handle *cfg)
1972 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1973 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1974 sec_name, op_name, &o->peer_id))
1976 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1977 op_counter, "STOP_REQUEST", op_name);
1978 GNUNET_free (op_name);
1979 return GNUNET_SYSERR;
1981 GNUNET_free (op_name);
1987 load_episode (struct Experiment *e, struct Episode *cur,
1988 struct GNUNET_CONFIGURATION_Handle *cfg)
1990 struct GNUNET_ATS_TEST_Operation *o;
1996 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Parsing episode %u\n",cur->id);
1997 GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
2001 /* Load operation */
2002 GNUNET_asprintf(&op_name, "op-%u-operation", op_counter);
2003 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
2004 sec_name, op_name, &op))
2006 GNUNET_free (op_name);
2009 o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
2010 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "==== Parsing operation %u: `%s'\n",
2013 /* operations = set_rate, start_send, stop_send, set_preference */
2014 if (0 == strcmp (op, "address_add"))
2016 o->type = SOLVER_OP_ADD_ADDRESS;
2017 res = load_op_add_address (o, cur,
2018 op_counter, sec_name, cfg);
2020 else if (0 == strcmp (op, "address_del"))
2022 o->type = SOLVER_OP_DEL_ADDRESS;
2023 res = load_op_del_address (o, cur,
2024 op_counter, sec_name, cfg);
2026 else if (0 == strcmp (op, "start_set_property"))
2028 o->type = SOLVER_OP_START_SET_PROPERTY;
2029 res = load_op_start_set_property (o, cur,
2030 op_counter, sec_name, cfg);
2032 else if (0 == strcmp (op, "stop_set_property"))
2034 o->type = SOLVER_OP_STOP_SET_PROPERTY;
2035 res = load_op_stop_set_property (o, cur,
2036 op_counter, sec_name, cfg);
2038 else if (0 == strcmp (op, "start_set_preference"))
2040 o->type = SOLVER_OP_START_SET_PREFERENCE;
2041 res = load_op_start_set_preference (o, cur,
2042 op_counter, sec_name, cfg);
2044 else if (0 == strcmp (op, "stop_set_preference"))
2046 o->type = SOLVER_OP_STOP_SET_PREFERENCE;
2047 res = load_op_stop_set_preference (o, cur,
2048 op_counter, sec_name, cfg);
2050 else if (0 == strcmp (op, "start_request"))
2052 o->type = SOLVER_OP_START_REQUEST;
2053 res = load_op_start_request (o, cur,
2054 op_counter, sec_name, cfg);
2056 else if (0 == strcmp (op, "stop_request"))
2058 o->type = SOLVER_OP_STOP_REQUEST;
2059 res = load_op_stop_request(o, cur,
2060 op_counter, sec_name, cfg);
2064 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
2065 op_counter, op, cur->id);
2066 res = GNUNET_SYSERR;
2070 GNUNET_free (op_name);
2072 if (GNUNET_SYSERR == res)
2075 GNUNET_free (sec_name);
2076 return GNUNET_SYSERR;
2079 GNUNET_CONTAINER_DLL_insert_tail (cur->head,cur->tail, o);
2082 GNUNET_free (sec_name);
2087 load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
2091 struct GNUNET_TIME_Relative e_duration;
2092 struct Episode *cur;
2093 struct Episode *last;
2099 GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
2100 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
2101 sec_name, "duration", &e_duration))
2103 GNUNET_free (sec_name);
2107 cur = GNUNET_new (struct Episode);
2108 cur->duration = e_duration;
2109 cur->id = e_counter;
2111 if (GNUNET_OK != load_episode (e, cur, cfg))
2113 GNUNET_free (sec_name);
2115 return GNUNET_SYSERR;
2118 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Found episode %u with duration %s \n",
2120 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
2122 /* Update experiment */
2124 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
2125 /* Put in linked list */
2131 GNUNET_free (sec_name);
2139 timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
2141 struct Experiment *e = cls;
2142 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2143 fprintf (stderr, "Experiment timeout!\n");
2145 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
2147 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2148 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2151 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
2155 struct ATS_Address *
2156 create_ats_address (const struct GNUNET_PeerIdentity *peer,
2157 const char *plugin_name,
2158 const void *plugin_addr,
2159 size_t plugin_addr_len,
2160 uint32_t session_id,
2163 struct ATS_Address *aa = NULL;
2165 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1);
2166 aa->atsi = GNUNET_new (struct GNUNET_ATS_Information);
2167 aa->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
2168 aa->atsi[0].value = htonl (network);
2172 aa->addr_len = plugin_addr_len;
2174 aa->plugin = (char *) &aa[1] + plugin_addr_len;
2175 memcpy (&aa[1], plugin_addr, plugin_addr_len);
2176 memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
2177 aa->session_id = session_id;
2178 aa->active = GNUNET_NO;
2179 aa->used = GNUNET_NO;
2180 aa->solver_information = NULL;
2181 aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0);
2182 aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0);
2190 enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
2193 struct TestAddress *a;
2196 if (NULL == (p = find_peer_by_id (op->peer_id)))
2198 p = GNUNET_new (struct TestPeer);
2199 p->id = op->peer_id;
2200 p->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0);
2201 p->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0);
2202 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
2203 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
2205 p->pref_abs[c] = DEFAULT_ABS_PREFERENCE;
2206 p->pref_norm[c] = DEFAULT_REL_PREFERENCE;
2209 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p);
2212 if (NULL != (find_address_by_id (p, op->address_id)))
2214 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Duplicate address %u for peer %u\n",
2215 op->address_id, op->peer_id);
2219 a = GNUNET_new (struct TestAddress);
2220 a->aid = op->address_id;
2221 a->network = op->address_network;
2222 a->ats_addr = create_ats_address (&p->peer_id, op->plugin, op->address,
2223 strlen (op->address) + 1, op->address_session, op->address_network);
2224 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
2225 GNUNET_CONTAINER_DLL_insert_tail (p->addr_head, p->addr_tail, a);
2227 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
2228 a->prop_norm[c] = DEFAULT_REL_QUALITY;
2230 GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, a->ats_addr,
2231 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2233 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u in network `%s'\n",
2234 op->address_id, op->peer_id, GNUNET_ATS_print_network_type(a->network));
2236 sh->env.sf.s_add (sh->solver, a->ats_addr, op->address_network);
2242 enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
2245 struct TestAddress *a;
2246 struct PropertyGenerator *pg;
2248 if (NULL == (p = find_peer_by_id (op->peer_id)))
2251 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2252 "Deleting address for unknown peer %u\n", op->peer_id);
2256 if (NULL == (a =find_address_by_id (p, op->address_id)))
2259 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2260 "Deleting address for unknown peer %u\n", op->peer_id);
2264 while (NULL != (pg = find_prop_gen (p->id, a->aid, 0)))
2266 GNUNET_ATS_solver_generate_property_stop (pg);
2269 GNUNET_CONTAINER_multipeermap_remove (sh->addresses, &p->peer_id, a->ats_addr);
2271 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Removing address %u for peer %u\n",
2272 op->address_id, op->peer_id);
2274 sh->env.sf.s_del (sh->solver, a->ats_addr, GNUNET_NO);
2278 GNUNET_ATS_solver_logging_now (l);
2280 GNUNET_CONTAINER_DLL_remove(p->addr_head, p->addr_tail, a);
2282 GNUNET_free_non_null(a->ats_addr->atsi);
2283 GNUNET_free (a->ats_addr);
2289 enforce_start_property (struct GNUNET_ATS_TEST_Operation *op)
2291 struct PropertyGenerator *pg;
2293 struct TestAddress *a;
2295 if (NULL != (pg = find_prop_gen (op->peer_id, op->address_id, op->prop_type)))
2297 GNUNET_ATS_solver_generate_property_stop (pg);
2301 if (NULL == (p = find_peer_by_id (op->peer_id)))
2304 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2305 "Starting property generation for unknown peer %u\n", op->peer_id);
2309 if (NULL == (a = find_address_by_id (p, op->address_id)))
2312 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2313 "Setting property for unknown address %u\n", op->peer_id);
2317 GNUNET_ATS_solver_generate_property_start (op->peer_id,
2329 enforce_stop_property (struct GNUNET_ATS_TEST_Operation *op)
2331 struct PropertyGenerator *pg = find_prop_gen(op->peer_id, op->address_id,
2335 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2336 "Stopping preference generation for peer %u address %u\n", op->peer_id,
2338 GNUNET_ATS_solver_generate_property_stop (pg);
2342 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2343 "Cannot find preference generator for peer %u address %u\n",
2344 op->peer_id, op->address_id);
2350 enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
2352 struct PreferenceGenerator *pg;
2353 if (NULL != (pg = find_pref_gen (op->peer_id, op->pref_type)))
2355 GNUNET_ATS_solver_generate_preferences_stop (pg);
2359 if (NULL == (find_peer_by_id (op->peer_id)))
2362 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2363 "Starting preference generation for unknown peer %u\n", op->peer_id);
2367 GNUNET_ATS_solver_generate_preferences_start (op->peer_id,
2380 enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
2382 struct PreferenceGenerator *pg = find_pref_gen(op->peer_id,
2386 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2387 "Stopping property generation for peer %u address %u\n", op->peer_id,
2389 GNUNET_ATS_solver_generate_preferences_stop (pg);
2393 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2394 "Cannot find preference generator for peer %u address %u\n",
2395 op->peer_id, op->address_id);
2402 enforce_start_request (struct GNUNET_ATS_TEST_Operation *op)
2405 const struct ATS_Address *res;
2407 if (NULL == (p = find_peer_by_id (op->peer_id)))
2410 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2411 "Requesting address for unknown peer %u\n", op->peer_id);
2415 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n",
2417 p->is_requested = GNUNET_YES;
2419 res = sh->env.sf.s_get (sh->solver, &p->peer_id);
2422 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Suggested address for peer %u: %llu %llu\n",
2424 ntohl(res->assigned_bw_in.value__),
2425 ntohl(res->assigned_bw_out.value__));
2427 GNUNET_ATS_solver_logging_now (l);
2432 enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op)
2436 if (NULL == (p = find_peer_by_id (op->peer_id)))
2439 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2440 "Requesting address for unknown peer %u\n", op->peer_id);
2446 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop requesting address for peer %u\n",
2448 p->is_requested = GNUNET_NO;
2449 p->assigned_bw_in.value__ = htonl(0);
2450 p->assigned_bw_out.value__ = htonl(0);
2451 sh->env.sf.s_get_stop (sh->solver, &p->peer_id);
2455 GNUNET_ATS_solver_logging_now (l);
2460 static void enforce_episode (struct Episode *ep)
2462 struct GNUNET_ATS_TEST_Operation *cur;
2463 for (cur = ep->head; NULL != cur; cur = cur->next)
2465 switch (cur->type) {
2466 case SOLVER_OP_ADD_ADDRESS:
2467 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2468 print_op (cur->type), cur->peer_id, cur->address_id);
2469 enforce_add_address (cur);
2471 case SOLVER_OP_DEL_ADDRESS:
2472 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2473 print_op (cur->type), cur->peer_id, cur->address_id);
2474 enforce_del_address (cur);
2476 case SOLVER_OP_START_SET_PROPERTY:
2477 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2478 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2479 enforce_start_property (cur);
2481 case SOLVER_OP_STOP_SET_PROPERTY:
2482 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2483 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2484 enforce_stop_property (cur);
2486 case SOLVER_OP_START_SET_PREFERENCE:
2487 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2488 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2489 enforce_start_preference (cur);
2491 case SOLVER_OP_STOP_SET_PREFERENCE:
2492 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2493 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2494 enforce_stop_preference (cur);
2496 case SOLVER_OP_START_REQUEST:
2497 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2498 print_op (cur->type), cur->peer_id);
2499 enforce_start_request (cur);
2501 case SOLVER_OP_STOP_REQUEST:
2502 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2503 print_op (cur->type), cur->peer_id);
2504 enforce_stop_request (cur);
2513 timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
2515 struct Experiment *e = cls;
2516 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2517 if (NULL != e->ep_done_cb)
2518 e->ep_done_cb (e->cur);
2520 /* Scheduling next */
2521 e->cur = e->cur->next;
2525 fprintf (stderr, "Last episode done!\n");
2526 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
2528 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2529 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2531 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
2535 fprintf (stderr, "Running episode %u with timeout %s\n",
2537 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2538 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2539 &timeout_episode, e);
2540 enforce_episode(e->cur);
2547 GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
2548 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
2549 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
2551 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
2552 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
2553 e->e_done_cb = e_done_cb;
2554 e->ep_done_cb = ep_done_cb;
2555 e->start_time = GNUNET_TIME_absolute_get();
2557 /* Start total time out */
2558 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
2559 &timeout_experiment, e);
2562 if (NULL == e->start)
2569 fprintf (stderr, "Running episode %u with timeout %s\n",
2571 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2572 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2573 &timeout_episode, e);
2574 enforce_episode(e->cur);
2579 GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
2581 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
2583 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2584 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2586 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
2588 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2589 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2593 GNUNET_CONFIGURATION_destroy(e->cfg);
2596 free_experiment (e);
2601 GNUNET_ATS_solvers_experimentation_load (char *filename)
2603 struct Experiment *e;
2604 struct GNUNET_CONFIGURATION_Handle *cfg;
2607 cfg = GNUNET_CONFIGURATION_create();
2608 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
2610 fprintf (stderr, "Failed to load `%s'\n", filename);
2611 GNUNET_CONFIGURATION_destroy (cfg);
2615 e = create_experiment ();
2617 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2620 fprintf (stderr, "Invalid %s \n", "name");
2621 free_experiment (e);
2625 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment name: `%s'\n", e->name);
2627 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2628 "log_prefix", &e->log_prefix))
2630 fprintf (stderr, "Invalid %s \n", "log_prefix");
2631 free_experiment (e);
2635 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging prefix: `%s'\n",
2638 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2639 "log_output_dir", &e->log_output_dir))
2641 e->log_output_dir = NULL;
2644 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging output directory: `%s'\n",
2648 if (GNUNET_SYSERR == (e->log_append_time_stamp = GNUNET_CONFIGURATION_get_value_yesno(cfg,
2649 "experiment", "log_append_time_stamp")))
2650 e->log_append_time_stamp = GNUNET_YES;
2651 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging append timestamp: `%s'\n",
2652 (GNUNET_YES == e->log_append_time_stamp) ? "yes" : "no");
2655 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2656 "cfg_file", &e->cfg_file))
2658 fprintf (stderr, "Invalid %s \n", "cfg_file");
2659 free_experiment (e);
2664 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment configuration: `%s'\n", e->cfg_file);
2665 e->cfg = GNUNET_CONFIGURATION_create();
2666 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file))
2668 fprintf (stderr, "Invalid configuration %s \n", "cfg_file");
2669 free_experiment (e);
2675 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2676 "log_freq", &e->log_freq))
2678 fprintf (stderr, "Invalid %s \n", "log_freq");
2679 free_experiment (e);
2683 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging frequency: `%s'\n",
2684 GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
2686 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2687 "max_duration", &e->max_duration))
2689 fprintf (stderr, "Invalid %s", "max_duration");
2690 free_experiment (e);
2694 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment duration: `%s'\n",
2695 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
2697 if (GNUNET_SYSERR == load_episodes (e, cfg))
2699 GNUNET_ATS_solvers_experimentation_stop (e);
2700 GNUNET_CONFIGURATION_destroy (cfg);
2702 fprintf (stderr, "Failed to load experiment\n");
2705 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loaded %u episodes with total duration %s\n",
2707 GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
2709 GNUNET_CONFIGURATION_destroy (cfg);
2720 free_all_it (void *cls,
2721 const struct GNUNET_PeerIdentity *key,
2724 struct ATS_Address *address = value;
2725 GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (sh->env.addresses,
2727 GNUNET_free (address);
2733 GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh)
2735 GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
2737 GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
2739 GAS_normalization_stop();
2741 GNUNET_CONTAINER_multipeermap_iterate (sh->addresses, &free_all_it, NULL);
2742 GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
2743 GNUNET_free (sh->plugin);
2748 * Load quotas for networks from configuration
2750 * @param cfg configuration handle
2751 * @param out_dest where to write outbound quotas
2752 * @param in_dest where to write inbound quotas
2753 * @param dest_length length of inbound and outbound arrays
2754 * @return number of networks loaded
2757 GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
2758 unsigned long long *out_dest,
2759 unsigned long long *in_dest,
2762 char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
2763 char * entry_in = NULL;
2764 char * entry_out = NULL;
2765 char * quota_out_str;
2766 char * quota_in_str;
2770 for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
2774 GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]);
2775 GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]);
2778 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
2781 if (0 == strcmp(quota_out_str, BIG_M_STRING))
2783 out_dest[c] = GNUNET_ATS_MaxBandwidth;
2786 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
2788 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c])))
2791 if (GNUNET_NO == res)
2793 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2794 network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth);
2795 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2799 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Outbound quota configure for network `%s' is %llu\n"),
2800 network_str[c], out_dest[c]);
2802 GNUNET_free (quota_out_str);
2806 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
2807 network_str[c], GNUNET_ATS_DefaultBandwidth);
2808 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2812 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str))
2815 if (0 == strcmp(quota_in_str, BIG_M_STRING))
2817 in_dest[c] = GNUNET_ATS_MaxBandwidth;
2820 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
2822 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c])))
2825 if (GNUNET_NO == res)
2827 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2828 network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth);
2829 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
2833 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Inbound quota configured for network `%s' is %llu\n"),
2834 network_str[c], in_dest[c]);
2836 GNUNET_free (quota_in_str);
2840 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
2841 network_str[c], GNUNET_ATS_DefaultBandwidth);
2842 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2844 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loaded quota for network `%s' (in/out): %llu %llu\n", network_str[c], in_dest[c], out_dest[c]);
2845 GNUNET_free (entry_out);
2846 GNUNET_free (entry_in);
2848 return GNUNET_ATS_NetworkTypeCount;
2852 * Information callback for the solver
2854 * @param cls the closure
2855 * @param op the solver operation
2856 * @param stat status of the solver operation
2857 * @param add additional solver information
2860 solver_info_cb (void *cls,
2861 enum GAS_Solver_Operation op,
2862 enum GAS_Solver_Status stat,
2863 enum GAS_Solver_Additional_Information add)
2868 add_info = "GAS_INFO_NONE";
2871 add_info = "GAS_INFO_MLP_FULL";
2873 case GAS_INFO_UPDATED:
2874 add_info = "GAS_INFO_MLP_UPDATED";
2876 case GAS_INFO_PROP_ALL:
2877 add_info = "GAS_INFO_PROP_ALL";
2879 case GAS_INFO_PROP_SINGLE:
2880 add_info = "GAS_INFO_PROP_SINGLE";
2883 add_info = "INVALID";
2889 case GAS_OP_SOLVE_START:
2890 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2891 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
2892 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2894 case GAS_OP_SOLVE_STOP:
2895 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2896 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
2897 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2900 case GAS_OP_SOLVE_SETUP_START:
2901 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2902 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
2903 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2906 case GAS_OP_SOLVE_SETUP_STOP:
2907 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2908 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
2909 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2912 case GAS_OP_SOLVE_MLP_LP_START:
2913 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2914 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
2915 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2917 case GAS_OP_SOLVE_MLP_LP_STOP:
2918 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2919 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
2920 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2923 case GAS_OP_SOLVE_MLP_MLP_START:
2924 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2925 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
2926 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2928 case GAS_OP_SOLVE_MLP_MLP_STOP:
2929 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2930 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
2931 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2933 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
2934 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2935 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
2936 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2938 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
2939 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2940 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
2941 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2949 solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address)
2951 struct GNUNET_TIME_Relative duration;
2953 static struct PreferenceGenerator *pg;
2955 if ( (0 == ntohl (address->assigned_bw_out.value__)) &&
2956 (0 == ntohl (address->assigned_bw_in.value__)) )
2958 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2959 "Solver notified to disconnect peer `%s'\n",
2960 GNUNET_i2s (&address->peer));
2962 p = find_peer_by_pid(&address->peer);
2965 p->assigned_bw_out = address->assigned_bw_out;
2966 p->assigned_bw_in = address->assigned_bw_in;
2968 for (pg = pref_gen_head; NULL != pg; pg = pg->next)
2970 if (pg->peer == p->id)
2972 duration = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update);
2973 delta = duration.rel_value_us * pg->last_assigned_bw_out;
2974 pg->feedback_bw_out_acc += delta;
2976 delta = duration.rel_value_us * pg->last_assigned_bw_in;
2977 pg->feedback_bw_in_acc += delta;
2979 pg->last_assigned_bw_in = ntohl (address->assigned_bw_in.value__);
2980 pg->last_assigned_bw_out = ntohl (address->assigned_bw_out.value__);
2981 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
2985 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2986 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
2987 GNUNET_i2s (&address->peer),
2989 (unsigned int) ntohl (address->assigned_bw_out.value__),
2990 (unsigned int) ntohl (address->assigned_bw_in.value__));
2992 GNUNET_ATS_solver_logging_now (l);
2998 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
3001 if (GNUNET_YES == opt_disable_normalization)
3003 if (NULL == (p = find_peer_by_pid (id)))
3008 return GAS_normalization_get_preferences_by_peer (id);
3013 get_property_cb (void *cls, const struct ATS_Address *address)
3016 struct TestAddress *a;
3018 if (GNUNET_YES == opt_disable_normalization)
3020 p = find_peer_by_pid (&address->peer);
3021 a = find_address_by_ats_address (p, address);
3025 return GAS_normalization_get_properties ((struct ATS_Address *) address);
3029 set_updated_property ( struct ATS_Address *address, uint32_t type, double prop_rel)
3032 struct TestAddress *a;
3034 if (NULL == (p = find_peer_by_pid (&address->peer)))
3040 if (NULL == (a = find_address_by_ats_address (p, address)))
3045 a->prop_norm[type] = prop_rel;
3046 sh->env.sf.s_address_update_property (sh->solver, address, type, a->prop_abs [type], prop_rel);
3051 normalized_property_changed_cb (void *cls, struct ATS_Address *address,
3052 uint32_t type, double prop_rel)
3055 struct PreferenceGenerator *pg;
3056 struct GNUNET_TIME_Relative duration;
3059 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3060 "Normalized property %s for peer `%s' changed to %.3f \n",
3061 GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer),
3064 if (NULL != (p = find_peer_by_pid (&address->peer)))
3066 for (pg = pref_gen_head; NULL != pg; pg = pg->next)
3068 if (pg->peer == p->id)
3070 duration = GNUNET_TIME_absolute_get_duration(pg->feedback_last_delay_update);
3071 delta = duration.rel_value_us * pg->last_delay_value;
3072 pg->feedback_delay_acc += delta;
3074 pg->last_delay_value = prop_rel;
3075 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
3081 set_updated_property (address, type, prop_rel);
3085 set_updated_preference (const struct GNUNET_PeerIdentity *peer,
3086 enum GNUNET_ATS_PreferenceKind kind,
3091 if (NULL == (p = find_peer_by_pid (peer)))
3097 p->pref_norm[kind] = pref_rel;
3098 sh->env.sf.s_pref (sh->solver, peer, kind, pref_rel);
3103 normalized_preference_changed_cb (void *cls,
3104 const struct GNUNET_PeerIdentity *peer,
3105 enum GNUNET_ATS_PreferenceKind kind,
3108 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3109 "Normalized preference %s for peer `%s' changed to %.3f \n",
3110 GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer),
3113 set_updated_preference(peer, kind, pref_rel);
3117 struct SolverHandle *
3118 GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
3120 struct SolverHandle *sh;
3125 case GNUNET_ATS_SOLVER_PROPORTIONAL:
3126 solver_str = "proportional";
3128 case GNUNET_ATS_SOLVER_MLP:
3131 case GNUNET_ATS_SOLVER_RIL:
3140 sh = GNUNET_new (struct SolverHandle);
3141 GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
3143 sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
3145 /* setup environment */
3146 sh->env.cfg = e->cfg;
3147 sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg);
3148 sh->env.addresses = sh->addresses;
3149 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
3150 sh->env.get_preferences = &get_preferences_cb;
3151 sh->env.get_property = &get_property_cb;
3152 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
3153 sh->env.info_cb = &solver_info_cb;
3154 sh->env.info_cb_cls = NULL;
3155 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
3156 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
3157 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
3158 sh->env.networks[c] = networks[c];
3161 /* start normalization */
3162 GAS_normalization_start (&normalized_preference_changed_cb, NULL,
3163 &normalized_property_changed_cb, NULL );
3166 if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg,
3167 sh->env.out_quota, sh->env.in_quota, GNUNET_ATS_NetworkTypeCount))
3170 GNUNET_free (sh->plugin);
3176 sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
3177 if (NULL == sh->solver)
3179 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
3181 GNUNET_free (sh->plugin);
3192 struct TestPeer *cur;
3193 struct TestPeer *next;
3195 struct TestAddress *cur_a;
3196 struct TestAddress *next_a;
3199 GNUNET_ATS_solver_logging_stop (l);
3201 /* Stop all preference generation */
3202 GNUNET_ATS_solver_generate_preferences_stop_all ();
3204 /* Stop all property generation */
3205 GNUNET_ATS_solver_generate_property_stop_all ();
3209 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Printing log information \n");
3210 GNUNET_ATS_solver_logging_eval (l);
3214 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Saving log information \n");
3215 GNUNET_ATS_solver_logging_write_to_disk (l, e->log_append_time_stamp,
3221 GNUNET_ATS_solver_logging_free (l);
3225 /* Clean up experiment */
3228 GNUNET_ATS_solvers_experimentation_stop (e);
3233 while (NULL != (cur = next))
3236 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, cur);
3237 next_a = cur->addr_head;
3238 while (NULL != (cur_a = next_a))
3240 next_a = cur_a->next;
3241 GNUNET_CONTAINER_DLL_remove (cur->addr_head, cur->addr_tail, cur_a);
3242 GNUNET_free (cur_a);
3248 GNUNET_ATS_solvers_solver_stop (sh);
3257 experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success)
3259 if (GNUNET_OK == success)
3260 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n",
3261 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
3263 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
3265 GNUNET_SCHEDULER_add_now (&done, NULL);
3269 episode_done_cb (struct Episode *ep)
3271 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
3284 GNUNET_ATS_solvers_experimentation_stop (e);
3289 GNUNET_ATS_solvers_solver_stop (sh);
3295 run (void *cls, char * const *args, const char *cfgfile,
3296 const struct GNUNET_CONFIGURATION_Handle *cfg)
3298 enum GNUNET_ATS_Solvers solver;
3301 if (NULL == opt_exp_file)
3303 fprintf (stderr, "No experiment given ...\n");
3309 if (NULL == opt_solver)
3311 fprintf (stderr, "No solver given ...\n");
3317 if (0 == strcmp(opt_solver, "mlp"))
3319 solver = GNUNET_ATS_SOLVER_MLP;
3321 else if (0 == strcmp(opt_solver, "proportional"))
3323 solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
3325 else if (0 == strcmp(opt_solver, "ril"))
3327 solver = GNUNET_ATS_SOLVER_RIL;
3331 fprintf (stderr, "No solver given ...");
3337 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
3338 default_properties[c] = DEFAULT_REL_QUALITY;
3340 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
3341 default_preferences[c] = DEFAULT_REL_PREFERENCE;
3343 /* load experiment */
3344 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading experiment\n");
3345 e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
3348 fprintf (stderr, "Failed to load experiment ...\n");
3355 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading solver\n");
3356 sh = GNUNET_ATS_solvers_solver_start (solver);
3359 fprintf (stderr, "Failed to start solver ...\n");
3366 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Start logging \n");
3367 l = GNUNET_ATS_solver_logging_start (e->log_freq);
3369 /* run experiment */
3370 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Running experiment \n");
3371 GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb,
3372 experiment_done_cb);
3379 * Main function of the benchmark
3381 * @param argc argument count
3382 * @param argv argument values
3385 main (int argc, char *argv[])
3387 opt_exp_file = NULL;
3389 opt_log = GNUNET_NO;
3390 opt_save = GNUNET_NO;
3394 static struct GNUNET_GETOPT_CommandLineOption options[] =
3396 { 's', "solver", NULL,
3397 gettext_noop ("solver to use"),
3398 1, &GNUNET_GETOPT_set_string, &opt_solver},
3399 { 'e', "experiment", NULL,
3400 gettext_noop ("experiment to use"),
3401 1, &GNUNET_GETOPT_set_string, &opt_exp_file},
3402 { 'V', "verbose", NULL,
3403 gettext_noop ("be verbose"),
3404 0, &GNUNET_GETOPT_set_one, &opt_verbose},
3405 { 'p', "print", NULL,
3406 gettext_noop ("print logging"),
3407 0, &GNUNET_GETOPT_set_one, &opt_print},
3408 { 'f', "file", NULL,
3409 gettext_noop ("save logging to disk"),
3410 0, &GNUNET_GETOPT_set_one, &opt_save},
3412 gettext_noop ("disable normalization"),
3413 0, &GNUNET_GETOPT_set_one, &opt_disable_normalization},
3414 GNUNET_GETOPT_OPTION_END
3417 GNUNET_PROGRAM_run (argc, argv, "gnunet-ats-solver-eval",
3418 NULL, options, &run, argv[0]);
3422 /* end of file ats-testing-experiment.c*/