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;
83 print_generator_type (enum GeneratorType g)
86 case GNUNET_ATS_TEST_TG_CONSTANT:
88 case GNUNET_ATS_TEST_TG_LINEAR:
90 case GNUNET_ATS_TEST_TG_RANDOM:
92 case GNUNET_ATS_TEST_TG_SINUS:
100 struct AddressLookupCtx
102 struct ATS_Address *res;
108 int find_address_it (void *cls,
109 const struct GNUNET_PeerIdentity *key,
112 struct AddressLookupCtx *ctx = cls;
113 struct ATS_Address *addr = value;
115 if ( (0 == strcmp (ctx->plugin, addr->plugin)) &&
116 (0 == strcmp (ctx->addr, addr->addr)) )
124 static struct TestPeer *
125 find_peer_by_id (int id)
127 struct TestPeer *cur;
128 for (cur = peer_head; NULL != cur; cur = cur->next)
134 static struct TestPeer *
135 find_peer_by_pid (const struct GNUNET_PeerIdentity *pid)
137 struct TestPeer *cur;
138 for (cur = peer_head; NULL != cur; cur = cur->next)
139 if (0 == memcmp (&cur->peer_id, pid, sizeof (struct GNUNET_PeerIdentity)))
144 static struct TestAddress *
145 find_address_by_id (struct TestPeer *peer, int aid)
147 struct TestAddress *cur;
148 for (cur = peer->addr_head; NULL != cur; cur = cur->next)
155 static struct TestAddress *
156 find_address_by_ats_address (struct TestPeer *p, const struct ATS_Address *addr)
158 struct TestAddress *cur;
159 for (cur = p->addr_head; NULL != cur; cur = cur->next)
160 if ((0 == strcmp(cur->ats_addr->plugin, addr->plugin)) &&
161 (cur->ats_addr->addr_len == addr->addr_len) &&
162 (0 == memcmp (cur->ats_addr->addr, addr->addr, addr->addr_len)))
173 GNUNET_ATS_solver_logging_now (struct LoggingHandle *l)
175 struct LoggingTimeStep *lts;
176 struct TestPeer *cur;
177 struct TestAddress *cur_addr;
178 struct LoggingPeer *log_p;
179 struct LoggingAddress *log_a;
182 lts = GNUNET_new (struct LoggingTimeStep);
183 GNUNET_CONTAINER_DLL_insert_tail(l->head, l->tail, lts);
184 lts->timestamp = GNUNET_TIME_absolute_get();
185 if (NULL == lts->prev)
186 lts->delta = GNUNET_TIME_UNIT_ZERO;
188 lts->delta = GNUNET_TIME_absolute_get_duration(lts->prev->timestamp);
190 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging %llu, delta %llu\n",
191 lts->timestamp.abs_value_us, lts->delta.rel_value_us);
194 /* Store logging data here */
195 for (cur = peer_head; NULL != cur; cur = cur->next)
197 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging peer id %llu\n", cur->id);
199 log_p = GNUNET_new (struct LoggingPeer);
201 log_p->peer_id = cur->peer_id;
202 log_p->is_requested = cur->is_requested;
203 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
205 log_p->pref_abs[c] = cur->pref_abs[c];
206 log_p->pref_norm[c] = cur->pref_norm[c];
207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t %s = %.2f %.2f [abs/rel]\n",
208 GNUNET_ATS_print_preference_type(c),
209 log_p->pref_abs[c], log_p->pref_norm[c]);
211 GNUNET_CONTAINER_DLL_insert_tail(lts->head, lts->tail, log_p);
213 for (cur_addr = cur->addr_head; NULL != cur_addr; cur_addr = cur_addr->next)
215 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging peer id %llu address %llu \n",
216 cur->id, cur_addr->aid);
217 log_a = GNUNET_new (struct LoggingAddress);
218 log_a->aid = cur_addr->aid;
219 log_a->active = cur_addr->ats_addr->active;
220 log_a->network = cur_addr->network;
221 log_a->used = cur_addr->ats_addr->used;
222 log_a->assigned_bw_in = cur_addr->ats_addr->assigned_bw_in;
223 log_a->assigned_bw_out = cur_addr->ats_addr->assigned_bw_out;
224 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
226 log_a->prop_abs[c] = cur_addr->prop_abs[c];
227 log_a->prop_norm[c] = cur_addr->prop_norm[c];
228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t %s = %.2f %.2f [abs/rel]\n",
229 GNUNET_ATS_print_property_type(c),
230 log_a->prop_abs[c], log_a->prop_norm[c]);
232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t Active = %i\n", log_a->active);
233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t BW in = %llu\n", ntohl(log_a->assigned_bw_in.value__));
234 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t BW out = %llu\n", ntohl(log_a->assigned_bw_out.value__));
236 GNUNET_CONTAINER_DLL_insert_tail (log_p->addr_head, log_p->addr_tail, log_a);
242 logging_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
244 struct LoggingHandle *l = cls;
245 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
247 GNUNET_ATS_solver_logging_now (l);
249 l->logging_task = GNUNET_SCHEDULER_add_delayed (l->log_freq, &logging_task, l);
253 struct LoggingHandle *
254 GNUNET_ATS_solver_logging_start (struct GNUNET_TIME_Relative freq)
256 struct LoggingHandle *l;
257 l = GNUNET_new (struct LoggingHandle);
259 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start logging every %s\n",
260 GNUNET_STRINGS_relative_time_to_string(freq, GNUNET_NO));
262 l->logging_task = GNUNET_SCHEDULER_add_now (&logging_task, l);
267 GNUNET_ATS_solver_logging_stop (struct LoggingHandle *l)
269 if (GNUNET_SCHEDULER_NO_TASK != l->logging_task)
270 GNUNET_SCHEDULER_cancel (l->logging_task);
272 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop logging\n");
274 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
277 static struct LoggingFileHandle *
278 find_logging_file_handle (struct LoggingFileHandle *lf_head,
279 struct LoggingFileHandle *lf_tail,
280 int peer_id, int address_id)
282 struct LoggingFileHandle *res;
284 for (res = lf_head; NULL != res; res = res->next)
285 if ((res->pid == peer_id) && (res->aid == address_id))
292 GNUNET_ATS_solver_logging_write_to_disk (struct LoggingHandle *l, int add_time_stamp,
295 struct LoggingTimeStep *lts;
296 struct LoggingPeer *log_p;
297 struct LoggingAddress *log_a;
298 struct LoggingFileHandle *lf_head;
299 struct LoggingFileHandle *lf_tail;
300 struct LoggingFileHandle *cur;
301 struct LoggingFileHandle *next;
305 char * propstring_tmp;
307 char * prefstring_tmp;
312 if (NULL != output_dir)
314 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (output_dir))
316 fprintf (stderr, "Failed to create directory `%s'\n", output_dir);
321 fprintf (stderr, "Created directory `%s'\n", output_dir);
322 use_dir = GNUNET_YES;
329 for (lts = l->head; NULL != lts; lts = lts->next)
332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing log step %llu\n",
333 (long long unsigned int) lts->timestamp.abs_value_us);
335 for (log_p = lts->head; NULL != log_p; log_p = log_p->next)
337 for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next)
340 cur = find_logging_file_handle (lf_head, lf_tail, log_p->id,
344 cur = GNUNET_new (struct LoggingFileHandle);
345 cur->aid = log_a->aid;
346 cur->pid = log_p->id;
348 if (GNUNET_YES == add_time_stamp)
349 GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u_%llu.log",
350 (GNUNET_YES == use_dir) ? output_dir : "",
351 (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "",
356 l->head->timestamp.abs_value_us);
358 GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u.log",
359 (GNUNET_YES == use_dir) ? output_dir : "",
360 (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "",
366 fprintf (stderr, "Add writing log data for peer %llu address %llu to file `%s'\n",
367 cur->pid, cur->aid, filename);
370 cur->f_hd = GNUNET_DISK_file_open (filename,
371 GNUNET_DISK_OPEN_READWRITE |
372 GNUNET_DISK_OPEN_CREATE |
373 GNUNET_DISK_OPEN_TRUNCATE,
374 GNUNET_DISK_PERM_USER_READ |
375 GNUNET_DISK_PERM_USER_WRITE |
376 GNUNET_DISK_PERM_GROUP_READ |
377 GNUNET_DISK_PERM_OTHER_READ);
378 if (NULL == cur->f_hd)
380 fprintf (stderr, "Cannot open `%s' to write log data!\n", filename);
381 GNUNET_free (filename);
384 GNUNET_free (filename);
385 GNUNET_CONTAINER_DLL_insert (lf_head, lf_tail, cur);
387 GNUNET_asprintf(&datastring,"#time delta;log duration;peer_requested;addr net; addr_active; bw in; bw out; " \
388 "UTILIZATION_UP [abs/rel]; UTILIZATION_UP; UTILIZATION_DOWN; UTILIZATION_DOWN; " \
389 "UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_DOWN; UTILIZATION_PAYLOAD_DOWN;"\
391 "DISTANCE ;DISTANCE ; COST_WAN; COST_WAN; COST_LAN; COST_LAN; " \
392 "COST_WLAN; COST_WLAN;COST_BT; COST_BT; PREF BW abs; PREF BW rel; PREF LATENCY abs; PREF LATENCY rel;\n");
393 GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring));
394 GNUNET_free (datastring);
398 prefstring = GNUNET_strdup("");
399 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
402 fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n",
403 GNUNET_ATS_print_preference_type(c),
404 log_p->pref_abs[c], log_p->pref_norm[c]);
406 GNUNET_asprintf(&prefstring_tmp,"%s;%.3f;%.3f",
407 prefstring, log_p->pref_abs[c], log_p->pref_norm[c]);
410 GNUNET_free (prefstring);
411 prefstring = GNUNET_strdup(prefstring_tmp);
412 GNUNET_free (prefstring_tmp);
416 propstring = GNUNET_strdup("");
417 for (c = 1; c < GNUNET_ATS_PropertyCount; c++)
419 if (GNUNET_ATS_NETWORK_TYPE == c)
422 fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n",
423 GNUNET_ATS_print_property_type(c),
424 log_a->prop_abs[c], log_a->prop_norm[c]);*/
425 GNUNET_asprintf(&propstring_tmp,"%s%.3f;%.3f;",
426 propstring, log_a->prop_abs[c], log_a->prop_norm[c]);
427 GNUNET_free (propstring);
428 propstring = GNUNET_strdup(propstring_tmp);
429 GNUNET_free (propstring_tmp);
431 if (GNUNET_YES==log_p->is_requested)
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",
887 set_pref_task (void *cls,
888 const struct GNUNET_SCHEDULER_TaskContext *tc)
890 struct PreferenceGenerator *pg = cls;
893 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
895 if (NULL == (p = find_peer_by_id (pg->peer)))
898 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
899 "Setting preference for unknown peer %u\n", pg->peer);
903 pref_value = get_preference (pg);
904 p->pref_abs[pg->kind] = pref_value;
906 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
907 "Setting preference for peer [%u] for client %p pref %s to %f\n",
908 pg->peer, NULL + (pg->client_id),
909 GNUNET_ATS_print_preference_type (pg->kind), pref_value);
911 sh->env.sf.s_bulk_start (sh->solver);
912 if (GNUNET_YES == opt_disable_normalization)
914 p->pref_abs[pg->kind] = pref_value;
915 p->pref_norm[pg->kind] = pref_value;
916 sh->env.sf.s_pref (sh->solver, &p->peer_id, pg->kind, pref_value);
919 GAS_normalization_normalize_preference (NULL + (pg->client_id),
920 &p->peer_id, pg->kind, pref_value);
921 sh->env.sf.s_bulk_stop (sh->solver);
924 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
925 //p->pref_bandwidth = pref_value;
927 case GNUNET_ATS_PREFERENCE_LATENCY:
928 //p->pref_delay = pref_value;
934 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
939 static struct PreferenceGenerator *
940 find_pref_gen (unsigned int peer, enum GNUNET_ATS_PreferenceKind kind)
942 struct PreferenceGenerator *cur;
943 for (cur = pref_gen_head; NULL != cur; cur = cur->next)
944 if (cur->peer == peer)
946 if ((cur->kind == kind) || (GNUNET_ATS_PREFERENCE_END == kind))
953 GNUNET_ATS_solver_generate_preferences_stop (struct PreferenceGenerator *pg)
955 GNUNET_CONTAINER_DLL_remove (pref_gen_head, pref_gen_tail, pg);
957 if (GNUNET_SCHEDULER_NO_TASK != pg->set_task)
959 GNUNET_SCHEDULER_cancel (pg->set_task);
960 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
962 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
963 "Removing old up preference generator peer [%u] `%s'\n",
964 pg->peer, GNUNET_ATS_print_preference_type(pg->kind));
971 * Generate between the source master and the partner and set property with a
972 * value depending on the generator.
975 * @param address_id partner
976 * @param client_id the client
977 * @param type type of generator
978 * @param base_value base value
979 * @param value_rate maximum value
980 * @param period duration of a period of generation (~ 1/frequency)
981 * @param frequency how long to generate property
982 * @param kind ATS preference to generate
983 * @return the preference generator
985 struct PreferenceGenerator *
986 GNUNET_ATS_solver_generate_preferences_start (unsigned int peer,
987 unsigned int address_id,
988 unsigned int client_id,
989 enum GeneratorType type,
992 struct GNUNET_TIME_Relative period,
993 struct GNUNET_TIME_Relative frequency,
994 enum GNUNET_ATS_PreferenceKind kind)
996 struct PreferenceGenerator *pg;
998 pg = GNUNET_new (struct PreferenceGenerator);
999 GNUNET_CONTAINER_DLL_insert (pref_gen_head, pref_gen_tail, pg);
1002 pg->client_id = client_id;
1004 pg->base_value = base_value;
1005 pg->max_value = value_rate;
1006 pg->duration_period = period;
1007 pg->frequency = frequency;
1008 pg->time_start = GNUNET_TIME_absolute_get();
1011 case GNUNET_ATS_TEST_TG_CONSTANT:
1012 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1013 "Setting up %s preference generator peer [%u] `%s' max %u Bips\n",
1014 print_generator_type (type), pg->peer,
1015 GNUNET_ATS_print_preference_type(kind),
1018 case GNUNET_ATS_TEST_TG_LINEAR:
1019 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1020 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bips\n",
1021 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1022 base_value, value_rate);
1024 case GNUNET_ATS_TEST_TG_SINUS:
1025 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1026 "Setting up %s preference generator peer [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
1027 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1028 base_value, value_rate);
1030 case GNUNET_ATS_TEST_TG_RANDOM:
1031 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1032 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bps\n",
1033 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1034 base_value, value_rate);
1040 pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, pg);
1047 * Stop all preferences generators
1050 GNUNET_ATS_solver_generate_preferences_stop_all ()
1052 struct PreferenceGenerator *cur;
1053 struct PreferenceGenerator *next;
1054 next = pref_gen_head;
1055 for (cur = next; NULL != cur; cur = next)
1058 GNUNET_ATS_solver_generate_preferences_stop(cur);
1069 print_op (enum OperationType op)
1072 case SOLVER_OP_ADD_ADDRESS:
1073 return "ADD_ADDRESS";
1074 case SOLVER_OP_DEL_ADDRESS:
1075 return "DEL_ADDRESS";
1076 case SOLVER_OP_START_SET_PREFERENCE:
1077 return "START_SET_PREFERENCE";
1078 case SOLVER_OP_STOP_SET_PREFERENCE:
1079 return "STOP_STOP_PREFERENCE";
1080 case SOLVER_OP_START_SET_PROPERTY:
1081 return "START_SET_PROPERTY";
1082 case SOLVER_OP_STOP_SET_PROPERTY:
1083 return "STOP_SET_PROPERTY";
1084 case SOLVER_OP_START_REQUEST:
1085 return "START_REQUEST";
1086 case SOLVER_OP_STOP_REQUEST:
1087 return "STOP_REQUEST";
1094 static struct Experiment *
1095 create_experiment ()
1097 struct Experiment *e;
1098 e = GNUNET_new (struct Experiment);
1101 e->total_duration = GNUNET_TIME_UNIT_ZERO;
1106 free_experiment (struct Experiment *e)
1108 struct Episode *cur;
1109 struct Episode *next;
1110 struct GNUNET_ATS_TEST_Operation *cur_o;
1111 struct GNUNET_ATS_TEST_Operation *next_o;
1114 for (cur = next; NULL != cur; cur = next)
1119 for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
1121 next_o = cur_o->next;
1122 GNUNET_free_non_null (cur_o->address);
1123 GNUNET_free_non_null (cur_o->plugin);
1124 GNUNET_free (cur_o);
1129 GNUNET_free_non_null (e->name);
1130 GNUNET_free_non_null (e->log_prefix);
1131 GNUNET_free_non_null (e->log_output_dir);
1132 GNUNET_free_non_null (e->cfg_file);
1138 load_op_add_address (struct GNUNET_ATS_TEST_Operation *o,
1142 const struct GNUNET_CONFIGURATION_Handle *cfg)
1148 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1149 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1150 sec_name, op_name, &o->peer_id))
1152 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1153 op_counter, "ADD_ADDRESS", op_name);
1154 GNUNET_free (op_name);
1155 return GNUNET_SYSERR;
1157 GNUNET_free (op_name);
1160 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1161 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1162 sec_name, op_name, &o->address_id))
1164 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1165 op_counter, "ADD_ADDRESS", op_name);
1166 GNUNET_free (op_name);
1167 return GNUNET_SYSERR;
1169 GNUNET_free (op_name);
1172 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
1173 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1174 sec_name, op_name, &o->plugin))
1176 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
1177 op_counter, "ADD_ADDRESS", op_name);
1178 GNUNET_free (op_name);
1179 return GNUNET_SYSERR;
1181 GNUNET_free (op_name);
1184 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
1185 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1186 sec_name, op_name, &o->address))
1188 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
1189 op_counter, "ADD_ADDRESS", op_name);
1190 GNUNET_free (op_name);
1191 return GNUNET_SYSERR;
1193 GNUNET_free (op_name);
1196 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
1197 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1198 sec_name, op_name, &o->address_session))
1200 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
1201 op_counter, "ADD_ADDRESS", op_name);
1202 GNUNET_free (op_name);
1203 return GNUNET_SYSERR;
1205 GNUNET_free (op_name);
1208 GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter);
1209 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1210 sec_name, op_name, &op_network))
1212 fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
1213 op_counter, "ADD_ADDRESS", op_name);
1214 GNUNET_free (op_name);
1215 return GNUNET_SYSERR;
1219 GNUNET_STRINGS_utf8_toupper (op_network,op_network);
1220 if (0 == strcmp(op_network, "UNSPECIFIED"))
1222 o->address_network = GNUNET_ATS_NET_UNSPECIFIED;
1224 else if (0 == strcmp(op_network, "LOOPBACK"))
1226 o->address_network = GNUNET_ATS_NET_LOOPBACK;
1228 else if (0 == strcmp(op_network, "LAN"))
1230 o->address_network = GNUNET_ATS_NET_LAN;
1232 else if (0 == strcmp(op_network, "WAN"))
1234 o->address_network = GNUNET_ATS_NET_WAN;
1236 else if (0 == strcmp(op_network, "WLAN"))
1238 o->address_network = GNUNET_ATS_NET_WLAN;
1240 else if (0 == strcmp(op_network, "BT"))
1242 o->address_network = GNUNET_ATS_NET_BT;
1246 fprintf (stderr, "Invalid address-network in operation %u `%s' in episode `%s': `%s'\n",
1247 op_counter, "ADD_ADDRESS", op_name, op_network);
1248 GNUNET_free (op_network);
1249 GNUNET_free (op_name);
1250 return GNUNET_SYSERR;
1253 GNUNET_free (op_network);
1254 GNUNET_free (op_name);
1256 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1257 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
1258 "ADD_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
1264 load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
1268 const struct GNUNET_CONFIGURATION_Handle *cfg)
1274 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1275 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1276 sec_name, op_name, &o->peer_id))
1278 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1279 op_counter, "DEL_ADDRESS", op_name);
1280 GNUNET_free (op_name);
1281 return GNUNET_SYSERR;
1283 GNUNET_free (op_name);
1286 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1287 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1288 sec_name, op_name, &o->address_id))
1290 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1291 op_counter, "DEL_ADDRESS", op_name);
1292 GNUNET_free (op_name);
1293 return GNUNET_SYSERR;
1295 GNUNET_free (op_name);
1299 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
1300 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1301 sec_name, op_name, &o->plugin))
1303 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
1304 op_counter, "DEL_ADDRESS", op_name);
1305 GNUNET_free (op_name);
1306 return GNUNET_SYSERR;
1308 GNUNET_free (op_name);
1311 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
1312 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1313 sec_name, op_name, &o->address))
1315 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
1316 op_counter, "DEL_ADDRESS", op_name);
1317 GNUNET_free (op_name);
1318 return GNUNET_SYSERR;
1320 GNUNET_free (op_name);
1323 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
1324 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1325 sec_name, op_name, &o->address_session))
1327 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
1328 op_counter, "DEL_ADDRESS", op_name);
1329 GNUNET_free (op_name);
1330 return GNUNET_SYSERR;
1332 GNUNET_free (op_name);
1335 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1336 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
1337 "DEL_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
1342 static enum GNUNET_ATS_Property
1343 parse_preference_string (const char * str)
1346 char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
1348 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
1349 if (0 == strcmp(str, props[c]))
1355 load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1359 const struct GNUNET_CONFIGURATION_Handle *cfg)
1366 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1367 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1368 sec_name, op_name, &o->peer_id))
1370 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1371 op_counter, "START_SET_PREFERENCE", op_name);
1372 GNUNET_free (op_name);
1373 return GNUNET_SYSERR;
1375 GNUNET_free (op_name);
1378 GNUNET_asprintf(&op_name, "op-%u-client-id", op_counter);
1379 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1380 sec_name, op_name, &o->client_id))
1382 fprintf (stderr, "Missing client-id in operation %u `%s' in episode `%s'\n",
1383 op_counter, "START_SET_PREFERENCE", op_name);
1384 GNUNET_free (op_name);
1385 return GNUNET_SYSERR;
1387 GNUNET_free (op_name);
1390 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1391 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1392 sec_name, op_name, &type)) )
1394 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1395 op_counter, "START_SET_PREFERENCE", op_name);
1396 GNUNET_free (op_name);
1397 return GNUNET_SYSERR;
1400 /* Load arguments for set_rate, start_send, set_preference */
1401 if (0 == strcmp (type, "constant"))
1403 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1405 else if (0 == strcmp (type, "linear"))
1407 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1409 else if (0 == strcmp (type, "sinus"))
1411 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1413 else if (0 == strcmp (type, "random"))
1415 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1419 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1420 op_counter, op_name, e->id);
1422 GNUNET_free (op_name);
1423 return GNUNET_SYSERR;
1426 GNUNET_free (op_name);
1430 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1431 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1432 sec_name, op_name, &o->base_rate))
1434 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1435 op_counter, op_name, e->id);
1436 GNUNET_free (op_name);
1437 return GNUNET_SYSERR;
1439 GNUNET_free (op_name);
1443 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1444 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1445 sec_name, op_name, &o->max_rate))
1447 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1448 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1449 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1451 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1452 op_counter, op_name, e->id);
1453 GNUNET_free (op_name);
1454 return GNUNET_SYSERR;
1457 GNUNET_free (op_name);
1460 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1461 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1462 sec_name, op_name, &o->period))
1464 o->period = e->duration;
1466 GNUNET_free (op_name);
1469 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1470 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1471 sec_name, op_name, &o->frequency))
1473 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1474 op_counter, op_name, e->id);
1475 GNUNET_free (op_name);
1476 return GNUNET_SYSERR;
1478 GNUNET_free (op_name);
1480 /* Get preference */
1481 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1482 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1483 sec_name, op_name, &pref))
1485 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
1486 op_counter, op_name, e->id);
1487 GNUNET_free (op_name);
1488 return GNUNET_SYSERR;
1491 if (0 == (o->pref_type = parse_preference_string(pref)))
1493 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1494 op_counter, op_name, e->id);
1495 GNUNET_free (op_name);
1497 return GNUNET_SYSERR;
1500 GNUNET_free (op_name);
1502 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1503 "Found operation %s: [%llu:%llu]: %s = %llu\n",
1504 "START_SET_PREFERENCE", o->peer_id, o->address_id,
1505 GNUNET_ATS_print_preference_type(o->pref_type), o->base_rate);
1511 load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1515 const struct GNUNET_CONFIGURATION_Handle *cfg)
1521 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1522 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1523 sec_name, op_name, &o->peer_id))
1525 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1526 op_counter, "STOP_SET_PREFERENCE", op_name);
1527 GNUNET_free (op_name);
1528 return GNUNET_SYSERR;
1530 GNUNET_free (op_name);
1533 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1534 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1535 sec_name, op_name, &o->address_id))
1537 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1538 op_counter, "STOP_SET_PREFERENCE", op_name);
1539 GNUNET_free (op_name);
1540 return GNUNET_SYSERR;
1542 GNUNET_free (op_name);
1544 /* Get preference */
1545 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1546 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1547 sec_name, op_name, &pref))
1549 fprintf (stderr, "Missing preference in operation %u `%s' in episode `%s'\n",
1550 op_counter, "STOP_SET_PREFERENCE", op_name);
1551 GNUNET_free (op_name);
1552 return GNUNET_SYSERR;
1555 if (0 == (o->pref_type = parse_preference_string(pref)))
1557 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1558 op_counter, op_name, e->id);
1559 GNUNET_free (op_name);
1561 return GNUNET_SYSERR;
1564 GNUNET_free (op_name);
1566 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1567 "Found operation %s: [%llu:%llu]: %s\n",
1568 "STOP_SET_PREFERENCE", o->peer_id, o->address_id,
1569 GNUNET_ATS_print_preference_type(o->pref_type));
1573 static enum GNUNET_ATS_Property
1574 parse_property_string (const char * str)
1577 char *props[GNUNET_ATS_PropertyCount] = GNUNET_ATS_PropertyStrings;
1579 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
1580 if (0 == strcmp(str, props[c]))
1586 load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o,
1590 const struct GNUNET_CONFIGURATION_Handle *cfg)
1597 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1598 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1599 sec_name, op_name, &o->peer_id))
1601 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1602 op_counter, "START_SET_PROPERTY", op_name);
1603 GNUNET_free (op_name);
1604 return GNUNET_SYSERR;
1606 GNUNET_free (op_name);
1609 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1610 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1611 sec_name, op_name, &o->address_id))
1613 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1614 op_counter, "START_SET_PROPERTY", op_name);
1615 GNUNET_free (op_name);
1616 return GNUNET_SYSERR;
1618 GNUNET_free (op_name);
1621 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1622 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1623 sec_name, op_name, &type)) )
1625 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1626 op_counter, "START_SET_PROPERTY", op_name);
1627 GNUNET_free (op_name);
1628 return GNUNET_SYSERR;
1631 /* Load arguments for set_rate, start_send, set_preference */
1632 if (0 == strcmp (type, "constant"))
1634 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1636 else if (0 == strcmp (type, "linear"))
1638 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1640 else if (0 == strcmp (type, "sinus"))
1642 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1644 else if (0 == strcmp (type, "random"))
1646 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1650 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1651 op_counter, op_name, e->id);
1653 GNUNET_free (op_name);
1654 return GNUNET_SYSERR;
1657 GNUNET_free (op_name);
1661 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1662 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1663 sec_name, op_name, &o->base_rate))
1665 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1666 op_counter, op_name, e->id);
1667 GNUNET_free (op_name);
1668 return GNUNET_SYSERR;
1670 GNUNET_free (op_name);
1674 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1675 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1676 sec_name, op_name, &o->max_rate))
1678 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1679 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1680 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1682 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1683 op_counter, op_name, e->id);
1684 GNUNET_free (op_name);
1685 return GNUNET_SYSERR;
1688 GNUNET_free (op_name);
1691 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1692 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1693 sec_name, op_name, &o->period))
1695 o->period = e->duration;
1697 GNUNET_free (op_name);
1700 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1701 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1702 sec_name, op_name, &o->frequency))
1704 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1705 op_counter, op_name, e->id);
1706 GNUNET_free (op_name);
1707 return GNUNET_SYSERR;
1709 GNUNET_free (op_name);
1711 /* Get preference */
1712 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1713 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1714 sec_name, op_name, &prop))
1716 fprintf (stderr, "Missing property in operation %u `%s' in episode %u\n",
1717 op_counter, op_name, e->id);
1718 GNUNET_free (op_name);
1719 GNUNET_free_non_null (prop);
1720 return GNUNET_SYSERR;
1723 if (0 == (o->prop_type = parse_property_string(prop)))
1725 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1726 op_counter, op_name, e->id);
1727 GNUNET_free (op_name);
1729 return GNUNET_SYSERR;
1733 GNUNET_free (op_name);
1735 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1736 "Found operation %s: [%llu:%llu] %s = %llu\n",
1737 "START_SET_PROPERTY", o->peer_id, o->address_id,
1738 GNUNET_ATS_print_property_type (o->prop_type), o->base_rate);
1744 load_op_stop_set_property (struct GNUNET_ATS_TEST_Operation *o,
1748 const struct GNUNET_CONFIGURATION_Handle *cfg)
1754 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1755 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1756 sec_name, op_name, &o->peer_id))
1758 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1759 op_counter, "STOP_SET_PROPERTY", op_name);
1760 GNUNET_free (op_name);
1761 return GNUNET_SYSERR;
1763 GNUNET_free (op_name);
1766 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1767 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1768 sec_name, op_name, &o->address_id))
1770 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1771 op_counter, "STOP_SET_PROPERTY", op_name);
1772 GNUNET_free (op_name);
1773 return GNUNET_SYSERR;
1775 GNUNET_free (op_name);
1778 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1779 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1780 sec_name, op_name, &pref))
1782 fprintf (stderr, "Missing property in operation %u `%s' in episode `%s'\n",
1783 op_counter, "STOP_SET_PROPERTY", op_name);
1784 GNUNET_free (op_name);
1785 GNUNET_free_non_null (pref);
1786 return GNUNET_SYSERR;
1789 if (0 == (o->prop_type = parse_property_string(pref)))
1791 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1792 op_counter, op_name, e->id);
1793 GNUNET_free (op_name);
1794 GNUNET_free_non_null (pref);
1795 return GNUNET_SYSERR;
1799 GNUNET_free (op_name);
1801 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1802 "Found operation %s: [%llu:%llu] %s\n",
1803 "STOP_SET_PROPERTY", o->peer_id, o->address_id,
1804 GNUNET_ATS_print_property_type (o->prop_type));
1811 load_op_start_request (struct GNUNET_ATS_TEST_Operation *o,
1815 const struct GNUNET_CONFIGURATION_Handle *cfg)
1820 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1821 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1822 sec_name, op_name, &o->peer_id))
1824 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1825 op_counter, "START_REQUEST", op_name);
1826 GNUNET_free (op_name);
1827 return GNUNET_SYSERR;
1829 GNUNET_free (op_name);
1834 load_op_stop_request (struct GNUNET_ATS_TEST_Operation *o,
1838 const struct GNUNET_CONFIGURATION_Handle *cfg)
1843 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1844 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1845 sec_name, op_name, &o->peer_id))
1847 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1848 op_counter, "STOP_REQUEST", op_name);
1849 GNUNET_free (op_name);
1850 return GNUNET_SYSERR;
1852 GNUNET_free (op_name);
1858 load_episode (struct Experiment *e, struct Episode *cur,
1859 struct GNUNET_CONFIGURATION_Handle *cfg)
1861 struct GNUNET_ATS_TEST_Operation *o;
1867 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Parsing episode %u\n",cur->id);
1868 GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
1872 /* Load operation */
1873 GNUNET_asprintf(&op_name, "op-%u-operation", op_counter);
1874 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1875 sec_name, op_name, &op))
1877 GNUNET_free (op_name);
1880 o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
1881 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "==== Parsing operation %u: `%s'\n",
1884 /* operations = set_rate, start_send, stop_send, set_preference */
1885 if (0 == strcmp (op, "address_add"))
1887 o->type = SOLVER_OP_ADD_ADDRESS;
1888 res = load_op_add_address (o, cur,
1889 op_counter, sec_name, cfg);
1891 else if (0 == strcmp (op, "address_del"))
1893 o->type = SOLVER_OP_DEL_ADDRESS;
1894 res = load_op_del_address (o, cur,
1895 op_counter, sec_name, cfg);
1897 else if (0 == strcmp (op, "start_set_property"))
1899 o->type = SOLVER_OP_START_SET_PROPERTY;
1900 res = load_op_start_set_property (o, cur,
1901 op_counter, sec_name, cfg);
1903 else if (0 == strcmp (op, "stop_set_property"))
1905 o->type = SOLVER_OP_STOP_SET_PROPERTY;
1906 res = load_op_stop_set_property (o, cur,
1907 op_counter, sec_name, cfg);
1909 else if (0 == strcmp (op, "start_set_preference"))
1911 o->type = SOLVER_OP_START_SET_PREFERENCE;
1912 res = load_op_start_set_preference (o, cur,
1913 op_counter, sec_name, cfg);
1915 else if (0 == strcmp (op, "stop_set_preference"))
1917 o->type = SOLVER_OP_STOP_SET_PREFERENCE;
1918 res = load_op_stop_set_preference (o, cur,
1919 op_counter, sec_name, cfg);
1921 else if (0 == strcmp (op, "start_request"))
1923 o->type = SOLVER_OP_START_REQUEST;
1924 res = load_op_start_request (o, cur,
1925 op_counter, sec_name, cfg);
1927 else if (0 == strcmp (op, "stop_request"))
1929 o->type = SOLVER_OP_STOP_REQUEST;
1930 res = load_op_stop_request(o, cur,
1931 op_counter, sec_name, cfg);
1935 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
1936 op_counter, op, cur->id);
1937 res = GNUNET_SYSERR;
1941 GNUNET_free (op_name);
1943 if (GNUNET_SYSERR == res)
1946 GNUNET_free (sec_name);
1947 return GNUNET_SYSERR;
1950 GNUNET_CONTAINER_DLL_insert_tail (cur->head,cur->tail, o);
1953 GNUNET_free (sec_name);
1958 load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
1962 struct GNUNET_TIME_Relative e_duration;
1963 struct Episode *cur;
1964 struct Episode *last;
1970 GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
1971 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
1972 sec_name, "duration", &e_duration))
1974 GNUNET_free (sec_name);
1978 cur = GNUNET_new (struct Episode);
1979 cur->duration = e_duration;
1980 cur->id = e_counter;
1982 if (GNUNET_OK != load_episode (e, cur, cfg))
1984 GNUNET_free (sec_name);
1986 return GNUNET_SYSERR;
1989 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Found episode %u with duration %s \n",
1991 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
1993 /* Update experiment */
1995 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
1996 /* Put in linked list */
2002 GNUNET_free (sec_name);
2010 timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
2012 struct Experiment *e = cls;
2013 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2014 fprintf (stderr, "Experiment timeout!\n");
2016 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
2018 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2019 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2022 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
2026 struct ATS_Address *
2027 create_ats_address (const struct GNUNET_PeerIdentity *peer,
2028 const char *plugin_name,
2029 const void *plugin_addr,
2030 size_t plugin_addr_len,
2031 uint32_t session_id,
2034 struct ATS_Address *aa = NULL;
2036 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1);
2037 aa->atsi = GNUNET_new (struct GNUNET_ATS_Information);
2038 aa->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
2039 aa->atsi[0].value = htonl (network);
2043 aa->addr_len = plugin_addr_len;
2045 aa->plugin = (char *) &aa[1] + plugin_addr_len;
2046 memcpy (&aa[1], plugin_addr, plugin_addr_len);
2047 memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
2048 aa->session_id = session_id;
2049 aa->active = GNUNET_NO;
2050 aa->used = GNUNET_NO;
2051 aa->solver_information = NULL;
2052 aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0);
2053 aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0);
2061 enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
2064 struct TestAddress *a;
2067 if (NULL == (p = find_peer_by_id (op->peer_id)))
2069 p = GNUNET_new (struct TestPeer);
2070 p->id = op->peer_id;
2071 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
2072 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
2074 p->pref_abs[c] = DEFAULT_ABS_PREFERENCE;
2075 p->pref_norm[c] = DEFAULT_REL_PREFERENCE;
2078 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p);
2081 if (NULL != (find_address_by_id (p, op->address_id)))
2083 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Duplicate address %u for peer %u\n",
2084 op->address_id, op->peer_id);
2088 a = GNUNET_new (struct TestAddress);
2089 a->aid = op->address_id;
2090 a->network = op->address_network;
2091 a->ats_addr = create_ats_address (&p->peer_id, op->plugin, op->address,
2092 strlen (op->address) + 1, op->address_session, op->address_network);
2093 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
2094 GNUNET_CONTAINER_DLL_insert_tail (p->addr_head, p->addr_tail, a);
2096 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
2097 a->prop_norm[c] = DEFAULT_REL_QUALITY;
2099 GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, a->ats_addr,
2100 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2102 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u in network `%s'\n",
2103 op->address_id, op->peer_id, GNUNET_ATS_print_network_type(a->network));
2105 sh->env.sf.s_add (sh->solver, a->ats_addr, op->address_network);
2111 enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
2114 struct TestAddress *a;
2115 struct PropertyGenerator *pg;
2117 if (NULL == (p = find_peer_by_id (op->peer_id)))
2120 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2121 "Deleting address for unknown peer %u\n", op->peer_id);
2125 if (NULL == (a =find_address_by_id (p, op->address_id)))
2128 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2129 "Deleting address for unknown peer %u\n", op->peer_id);
2133 while (NULL != (pg = find_prop_gen (p->id, a->aid, 0)))
2135 GNUNET_ATS_solver_generate_property_stop (pg);
2138 GNUNET_CONTAINER_multipeermap_remove (sh->addresses, &p->peer_id, a->ats_addr);
2140 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Removing address %u for peer %u\n",
2141 op->address_id, op->peer_id);
2143 sh->env.sf.s_del (sh->solver, a->ats_addr, GNUNET_NO);
2147 GNUNET_ATS_solver_logging_now (l);
2149 GNUNET_CONTAINER_DLL_remove(p->addr_head, p->addr_tail, a);
2151 GNUNET_free_non_null(a->ats_addr->atsi);
2152 GNUNET_free (a->ats_addr);
2158 enforce_start_property (struct GNUNET_ATS_TEST_Operation *op)
2160 struct PropertyGenerator *pg;
2162 struct TestAddress *a;
2164 if (NULL != (pg = find_prop_gen (op->peer_id, op->address_id, op->prop_type)))
2166 GNUNET_ATS_solver_generate_property_stop (pg);
2170 if (NULL == (p = find_peer_by_id (op->peer_id)))
2173 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2174 "Starting property generation for unknown peer %u\n", op->peer_id);
2178 if (NULL == (a = find_address_by_id (p, op->address_id)))
2181 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2182 "Setting property for unknown address %u\n", op->peer_id);
2186 GNUNET_ATS_solver_generate_property_start (op->peer_id,
2198 enforce_stop_property (struct GNUNET_ATS_TEST_Operation *op)
2200 struct PropertyGenerator *pg = find_prop_gen(op->peer_id, op->address_id,
2204 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2205 "Stopping preference generation for peer %u address %u\n", op->peer_id,
2207 GNUNET_ATS_solver_generate_property_stop (pg);
2211 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2212 "Cannot find preference generator for peer %u address %u\n",
2213 op->peer_id, op->address_id);
2219 enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
2221 struct PreferenceGenerator *pg;
2222 if (NULL != (pg = find_pref_gen (op->peer_id, op->pref_type)))
2224 GNUNET_ATS_solver_generate_preferences_stop (pg);
2228 if (NULL == (find_peer_by_id (op->peer_id)))
2231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2232 "Starting preference generation for unknown peer %u\n", op->peer_id);
2236 GNUNET_ATS_solver_generate_preferences_start (op->peer_id,
2248 enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
2250 struct PreferenceGenerator *pg = find_pref_gen(op->peer_id,
2254 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2255 "Stopping property generation for peer %u address %u\n", op->peer_id,
2257 GNUNET_ATS_solver_generate_preferences_stop (pg);
2261 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2262 "Cannot find preference generator for peer %u address %u\n",
2263 op->peer_id, op->address_id);
2270 enforce_start_request (struct GNUNET_ATS_TEST_Operation *op)
2273 const struct ATS_Address *res;
2275 if (NULL == (p = find_peer_by_id (op->peer_id)))
2278 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2279 "Requesting address for unknown peer %u\n", op->peer_id);
2283 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n",
2285 p->is_requested = GNUNET_YES;
2287 res = sh->env.sf.s_get (sh->solver, &p->peer_id);
2290 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Suggested address for peer %u: %llu %llu\n",
2292 ntohl(res->assigned_bw_in.value__),
2293 ntohl(res->assigned_bw_out.value__));
2295 GNUNET_ATS_solver_logging_now (l);
2300 enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op)
2304 if (NULL == (p = find_peer_by_id (op->peer_id)))
2307 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2308 "Requesting address for unknown peer %u\n", op->peer_id);
2312 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop requesting address for peer %u\n",
2314 p->is_requested = GNUNET_NO;
2315 sh->env.sf.s_get_stop (sh->solver, &p->peer_id);
2319 GNUNET_ATS_solver_logging_now (l);
2324 static void enforce_episode (struct Episode *ep)
2326 struct GNUNET_ATS_TEST_Operation *cur;
2327 for (cur = ep->head; NULL != cur; cur = cur->next)
2329 switch (cur->type) {
2330 case SOLVER_OP_ADD_ADDRESS:
2331 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2332 print_op (cur->type), cur->peer_id, cur->address_id);
2333 enforce_add_address (cur);
2335 case SOLVER_OP_DEL_ADDRESS:
2336 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2337 print_op (cur->type), cur->peer_id, cur->address_id);
2338 enforce_del_address (cur);
2340 case SOLVER_OP_START_SET_PROPERTY:
2341 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2342 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2343 enforce_start_property (cur);
2345 case SOLVER_OP_STOP_SET_PROPERTY:
2346 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2347 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2348 enforce_stop_property (cur);
2350 case SOLVER_OP_START_SET_PREFERENCE:
2351 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2352 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2353 enforce_start_preference (cur);
2355 case SOLVER_OP_STOP_SET_PREFERENCE:
2356 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2357 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2358 enforce_stop_preference (cur);
2360 case SOLVER_OP_START_REQUEST:
2361 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2362 print_op (cur->type), cur->peer_id);
2363 enforce_start_request (cur);
2365 case SOLVER_OP_STOP_REQUEST:
2366 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2367 print_op (cur->type), cur->peer_id);
2368 enforce_stop_request (cur);
2377 timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
2379 struct Experiment *e = cls;
2380 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2381 if (NULL != e->ep_done_cb)
2382 e->ep_done_cb (e->cur);
2384 /* Scheduling next */
2385 e->cur = e->cur->next;
2389 fprintf (stderr, "Last episode done!\n");
2390 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
2392 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2393 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2395 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
2399 fprintf (stderr, "Running episode %u with timeout %s\n",
2401 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2402 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2403 &timeout_episode, e);
2404 enforce_episode(e->cur);
2411 GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
2412 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
2413 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
2415 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
2416 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
2417 e->e_done_cb = e_done_cb;
2418 e->ep_done_cb = ep_done_cb;
2419 e->start_time = GNUNET_TIME_absolute_get();
2421 /* Start total time out */
2422 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
2423 &timeout_experiment, e);
2426 if (NULL == e->start)
2433 fprintf (stderr, "Running episode %u with timeout %s\n",
2435 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2436 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2437 &timeout_episode, e);
2438 enforce_episode(e->cur);
2443 GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
2445 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
2447 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2448 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2450 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
2452 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2453 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2457 GNUNET_CONFIGURATION_destroy(e->cfg);
2460 free_experiment (e);
2465 GNUNET_ATS_solvers_experimentation_load (char *filename)
2467 struct Experiment *e;
2468 struct GNUNET_CONFIGURATION_Handle *cfg;
2471 cfg = GNUNET_CONFIGURATION_create();
2472 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
2474 fprintf (stderr, "Failed to load `%s'\n", filename);
2475 GNUNET_CONFIGURATION_destroy (cfg);
2479 e = create_experiment ();
2481 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2484 fprintf (stderr, "Invalid %s \n", "name");
2485 free_experiment (e);
2489 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment name: `%s'\n", e->name);
2491 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2492 "log_prefix", &e->log_prefix))
2494 fprintf (stderr, "Invalid %s \n", "log_prefix");
2495 free_experiment (e);
2499 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging prefix: `%s'\n",
2502 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2503 "log_output_dir", &e->log_output_dir))
2505 e->log_output_dir = NULL;
2508 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging output directory: `%s'\n",
2512 if (GNUNET_SYSERR == (e->log_append_time_stamp = GNUNET_CONFIGURATION_get_value_yesno(cfg,
2513 "experiment", "log_append_time_stamp")))
2514 e->log_append_time_stamp = GNUNET_YES;
2515 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging append timestamp: `%s'\n",
2516 (GNUNET_YES == e->log_append_time_stamp) ? "yes" : "no");
2519 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2520 "cfg_file", &e->cfg_file))
2522 fprintf (stderr, "Invalid %s \n", "cfg_file");
2523 free_experiment (e);
2528 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment configuration: `%s'\n", e->cfg_file);
2529 e->cfg = GNUNET_CONFIGURATION_create();
2530 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file))
2532 fprintf (stderr, "Invalid configuration %s \n", "cfg_file");
2533 free_experiment (e);
2539 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2540 "log_freq", &e->log_freq))
2542 fprintf (stderr, "Invalid %s \n", "log_freq");
2543 free_experiment (e);
2547 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging frequency: `%s'\n",
2548 GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
2550 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2551 "max_duration", &e->max_duration))
2553 fprintf (stderr, "Invalid %s", "max_duration");
2554 free_experiment (e);
2558 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment duration: `%s'\n",
2559 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
2561 if (GNUNET_SYSERR == load_episodes (e, cfg))
2563 GNUNET_ATS_solvers_experimentation_stop (e);
2564 GNUNET_CONFIGURATION_destroy (cfg);
2566 fprintf (stderr, "Failed to load experiment\n");
2569 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loaded %u episodes with total duration %s\n",
2571 GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
2573 GNUNET_CONFIGURATION_destroy (cfg);
2584 free_all_it (void *cls,
2585 const struct GNUNET_PeerIdentity *key,
2588 struct ATS_Address *address = value;
2589 GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (sh->env.addresses,
2591 GNUNET_free (address);
2597 GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh)
2599 GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
2601 GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
2603 GAS_normalization_stop();
2605 GNUNET_CONTAINER_multipeermap_iterate (sh->addresses, &free_all_it, NULL);
2606 GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
2607 GNUNET_free (sh->plugin);
2612 * Load quotas for networks from configuration
2614 * @param cfg configuration handle
2615 * @param out_dest where to write outbound quotas
2616 * @param in_dest where to write inbound quotas
2617 * @param dest_length length of inbound and outbound arrays
2618 * @return number of networks loaded
2621 GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
2622 unsigned long long *out_dest,
2623 unsigned long long *in_dest,
2626 char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
2627 char * entry_in = NULL;
2628 char * entry_out = NULL;
2629 char * quota_out_str;
2630 char * quota_in_str;
2634 for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
2638 GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]);
2639 GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]);
2642 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
2645 if (0 == strcmp(quota_out_str, BIG_M_STRING))
2647 out_dest[c] = GNUNET_ATS_MaxBandwidth;
2650 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
2652 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c])))
2655 if (GNUNET_NO == res)
2657 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2658 network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth);
2659 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Outbound quota configure for network `%s' is %llu\n"),
2664 network_str[c], out_dest[c]);
2666 GNUNET_free (quota_out_str);
2670 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
2671 network_str[c], GNUNET_ATS_DefaultBandwidth);
2672 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2676 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str))
2679 if (0 == strcmp(quota_in_str, BIG_M_STRING))
2681 in_dest[c] = GNUNET_ATS_MaxBandwidth;
2684 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
2686 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c])))
2689 if (GNUNET_NO == res)
2691 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2692 network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth);
2693 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
2697 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Inbound quota configured for network `%s' is %llu\n"),
2698 network_str[c], in_dest[c]);
2700 GNUNET_free (quota_in_str);
2704 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
2705 network_str[c], GNUNET_ATS_DefaultBandwidth);
2706 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2708 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]);
2709 GNUNET_free (entry_out);
2710 GNUNET_free (entry_in);
2712 return GNUNET_ATS_NetworkTypeCount;
2716 * Information callback for the solver
2718 * @param cls the closure
2719 * @param op the solver operation
2720 * @param stat status of the solver operation
2721 * @param add additional solver information
2724 solver_info_cb (void *cls,
2725 enum GAS_Solver_Operation op,
2726 enum GAS_Solver_Status stat,
2727 enum GAS_Solver_Additional_Information add)
2732 add_info = "GAS_INFO_NONE";
2735 add_info = "GAS_INFO_MLP_FULL";
2737 case GAS_INFO_UPDATED:
2738 add_info = "GAS_INFO_MLP_UPDATED";
2740 case GAS_INFO_PROP_ALL:
2741 add_info = "GAS_INFO_PROP_ALL";
2743 case GAS_INFO_PROP_SINGLE:
2744 add_info = "GAS_INFO_PROP_SINGLE";
2747 add_info = "INVALID";
2753 case GAS_OP_SOLVE_START:
2754 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2755 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
2756 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2758 case GAS_OP_SOLVE_STOP:
2759 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2760 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
2761 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2764 case GAS_OP_SOLVE_SETUP_START:
2765 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2766 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
2767 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2770 case GAS_OP_SOLVE_SETUP_STOP:
2771 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2772 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
2773 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2776 case GAS_OP_SOLVE_MLP_LP_START:
2777 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2778 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
2779 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2781 case GAS_OP_SOLVE_MLP_LP_STOP:
2782 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2783 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
2784 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2787 case GAS_OP_SOLVE_MLP_MLP_START:
2788 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2789 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
2790 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2792 case GAS_OP_SOLVE_MLP_MLP_STOP:
2793 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2794 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
2795 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2797 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
2798 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2799 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
2800 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2802 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
2803 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2804 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
2805 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2813 solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address)
2815 if ( (0 == ntohl (address->assigned_bw_out.value__)) &&
2816 (0 == ntohl (address->assigned_bw_in.value__)) )
2818 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2819 "Solver notified to disconnect peer `%s'\n",
2820 GNUNET_i2s (&address->peer));
2824 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2825 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
2826 GNUNET_i2s (&address->peer),
2828 (unsigned int) ntohl (address->assigned_bw_out.value__),
2829 (unsigned int) ntohl (address->assigned_bw_in.value__));
2830 /*if (GNUNET_YES == ph.bulk_running)
2833 GNUNET_ATS_solver_logging_now (l);
2839 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
2842 if (GNUNET_YES == opt_disable_normalization)
2844 if (NULL == (p = find_peer_by_pid (id)))
2849 return GAS_normalization_get_preferences_by_peer (id);
2854 get_property_cb (void *cls, const struct ATS_Address *address)
2857 struct TestAddress *a;
2859 if (GNUNET_YES == opt_disable_normalization)
2861 p = find_peer_by_pid (&address->peer);
2862 a = find_address_by_ats_address (p, address);
2866 return GAS_normalization_get_properties ((struct ATS_Address *) address);
2870 set_updated_property ( struct ATS_Address *address, uint32_t type, double prop_rel)
2873 struct TestAddress *a;
2875 if (NULL == (p = find_peer_by_pid (&address->peer)))
2881 if (NULL == (a = find_address_by_ats_address (p, address)))
2886 a->prop_norm[type] = prop_rel;
2887 sh->env.sf.s_address_update_property (sh->solver, address, type, a->prop_abs [type], prop_rel);
2892 normalized_property_changed_cb (void *cls, struct ATS_Address *address,
2893 uint32_t type, double prop_rel)
2895 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2896 "Normalized property %s for peer `%s' changed to %.3f \n",
2897 GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer),
2900 set_updated_property (address, type, prop_rel);
2904 set_updated_preference (const struct GNUNET_PeerIdentity *peer,
2905 enum GNUNET_ATS_PreferenceKind kind,
2910 if (NULL == (p = find_peer_by_pid (peer)))
2916 p->pref_norm[kind] = pref_rel;
2917 sh->env.sf.s_pref (sh->solver, peer, kind, pref_rel);
2922 normalized_preference_changed_cb (void *cls,
2923 const struct GNUNET_PeerIdentity *peer,
2924 enum GNUNET_ATS_PreferenceKind kind,
2927 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2928 "Normalized preference %s for peer `%s' changed to %.3f \n",
2929 GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer),
2932 set_updated_preference(peer, kind, pref_rel);
2936 struct SolverHandle *
2937 GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
2939 struct SolverHandle *sh;
2944 case GNUNET_ATS_SOLVER_PROPORTIONAL:
2945 solver_str = "proportional";
2947 case GNUNET_ATS_SOLVER_MLP:
2950 case GNUNET_ATS_SOLVER_RIL:
2959 sh = GNUNET_new (struct SolverHandle);
2960 GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
2962 sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
2963 /* setup environment */
2964 sh->env.cfg = e->cfg;
2965 sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg);
2966 sh->env.addresses = sh->addresses;
2967 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
2968 sh->env.get_preferences = &get_preferences_cb;
2969 sh->env.get_property = &get_property_cb;
2970 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
2971 sh->env.info_cb = &solver_info_cb;
2972 sh->env.info_cb_cls = NULL;
2973 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
2974 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
2975 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
2976 sh->env.networks[c] = networks[c];
2979 /* start normalization */
2980 GAS_normalization_start (&normalized_preference_changed_cb, NULL,
2981 &normalized_property_changed_cb, NULL );
2984 if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg,
2985 sh->env.out_quota, sh->env.in_quota, GNUNET_ATS_NetworkTypeCount))
2988 GNUNET_free (sh->plugin);
2994 sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
2995 if (NULL == sh->solver)
2997 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
2999 GNUNET_free (sh->plugin);
3010 struct TestPeer *cur;
3011 struct TestPeer *next;
3013 struct TestAddress *cur_a;
3014 struct TestAddress *next_a;
3017 GNUNET_ATS_solver_logging_stop (l);
3019 /* Stop all preference generation */
3020 GNUNET_ATS_solver_generate_preferences_stop_all ();
3022 /* Stop all property generation */
3023 GNUNET_ATS_solver_generate_property_stop_all ();
3027 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Printing log information \n");
3028 GNUNET_ATS_solver_logging_eval (l);
3032 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Saving log information \n");
3033 GNUNET_ATS_solver_logging_write_to_disk (l, e->log_append_time_stamp,
3039 GNUNET_ATS_solver_logging_free (l);
3043 /* Clean up experiment */
3046 GNUNET_ATS_solvers_experimentation_stop (e);
3051 while (NULL != (cur = next))
3054 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, cur);
3055 next_a = cur->addr_head;
3056 while (NULL != (cur_a = next_a))
3058 next_a = cur_a->next;
3059 GNUNET_CONTAINER_DLL_remove (cur->addr_head, cur->addr_tail, cur_a);
3060 GNUNET_free (cur_a);
3066 GNUNET_ATS_solvers_solver_stop (sh);
3075 experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success)
3077 if (GNUNET_OK == success)
3078 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n",
3079 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
3081 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
3083 GNUNET_SCHEDULER_add_now (&done, NULL);
3087 episode_done_cb (struct Episode *ep)
3089 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
3102 GNUNET_ATS_solvers_experimentation_stop (e);
3107 GNUNET_ATS_solvers_solver_stop (sh);
3113 run (void *cls, char * const *args, const char *cfgfile,
3114 const struct GNUNET_CONFIGURATION_Handle *cfg)
3116 enum GNUNET_ATS_Solvers solver;
3119 if (NULL == opt_exp_file)
3121 fprintf (stderr, "No experiment given ...\n");
3127 if (NULL == opt_solver)
3129 fprintf (stderr, "No solver given ...\n");
3135 if (0 == strcmp(opt_solver, "mlp"))
3137 solver = GNUNET_ATS_SOLVER_MLP;
3139 else if (0 == strcmp(opt_solver, "proportional"))
3141 solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
3143 else if (0 == strcmp(opt_solver, "ril"))
3145 solver = GNUNET_ATS_SOLVER_RIL;
3149 fprintf (stderr, "No solver given ...");
3155 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
3156 default_properties[c] = DEFAULT_REL_QUALITY;
3158 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
3159 default_preferences[c] = DEFAULT_REL_PREFERENCE;
3161 /* load experiment */
3162 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading experiment\n");
3163 e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
3166 fprintf (stderr, "Failed to load experiment ...\n");
3173 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading solver\n");
3174 sh = GNUNET_ATS_solvers_solver_start (solver);
3177 fprintf (stderr, "Failed to start solver ...\n");
3184 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Start logging \n");
3185 l = GNUNET_ATS_solver_logging_start (e->log_freq);
3187 /* run experiment */
3188 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Running experiment \n");
3189 GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb,
3190 experiment_done_cb);
3197 * Main function of the benchmark
3199 * @param argc argument count
3200 * @param argv argument values
3203 main (int argc, char *argv[])
3205 opt_exp_file = NULL;
3207 opt_log = GNUNET_NO;
3208 opt_save = GNUNET_NO;
3212 static struct GNUNET_GETOPT_CommandLineOption options[] =
3214 { 's', "solver", NULL,
3215 gettext_noop ("solver to use"),
3216 1, &GNUNET_GETOPT_set_string, &opt_solver},
3217 { 'e', "experiment", NULL,
3218 gettext_noop ("experiment to use"),
3219 1, &GNUNET_GETOPT_set_string, &opt_exp_file},
3220 { 'V', "verbose", NULL,
3221 gettext_noop ("be verbose"),
3222 0, &GNUNET_GETOPT_set_one, &opt_verbose},
3223 { 'p', "print", NULL,
3224 gettext_noop ("print logging"),
3225 0, &GNUNET_GETOPT_set_one, &opt_print},
3226 { 'f', "file", NULL,
3227 gettext_noop ("save logging to disk"),
3228 0, &GNUNET_GETOPT_set_one, &opt_save},
3230 gettext_noop ("disable normalization"),
3231 0, &GNUNET_GETOPT_set_one, &opt_disable_normalization},
3232 GNUNET_GETOPT_OPTION_END
3235 GNUNET_PROGRAM_run (argc, argv, "gnunet-ats-solver-eval",
3236 NULL, options, &run, argv[0]);
3240 /* end of file ats-testing-experiment.c*/