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 GNUNET_asprintf(&datastring,"%llu;%llu;%u;%u;%i;%u;%u;%s;%s\n",
432 GNUNET_TIME_absolute_get_difference(l->head->timestamp, lts->timestamp).rel_value_us / 1000,
437 ntohl (log_a->assigned_bw_in.value__),
438 ntohl (log_a->assigned_bw_out.value__),
439 propstring, prefstring);
441 GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring));
442 GNUNET_free (datastring);
443 GNUNET_free (prefstring);
444 GNUNET_free (propstring);
451 for (cur = next; NULL != cur; cur = next)
454 GNUNET_CONTAINER_DLL_remove (lf_head, lf_tail, cur);
455 if (NULL != cur->f_hd)
456 GNUNET_DISK_file_close (cur->f_hd);
463 GNUNET_ATS_solver_logging_eval (struct LoggingHandle *l)
465 struct LoggingTimeStep *lts;
466 struct LoggingPeer *log_p;
467 struct LoggingAddress *log_a;
470 for (lts = l->head; NULL != lts; lts = lts->next)
472 fprintf (stderr, "Log step %llu %llu: \n",
473 (long long unsigned int) lts->timestamp.abs_value_us,
474 (long long unsigned int) lts->delta.rel_value_us);
476 for (log_p = lts->head; NULL != log_p; log_p = log_p->next)
478 fprintf (stderr,"\tLogging peer pid %llu\n", log_p->id);
479 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
481 fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n",
482 GNUNET_ATS_print_preference_type(c),
483 log_p->pref_abs[c], log_p->pref_norm[c]);
486 for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next)
488 fprintf (stderr, "\tPeer pid %llu address %llu: %u %u %u\n",
489 log_p->id, log_a->aid, log_a->active,
490 ntohl(log_a->assigned_bw_in.value__),
491 ntohl(log_a->assigned_bw_out.value__));
493 for (c = 1; c < GNUNET_ATS_PropertyCount; c++)
495 if (GNUNET_ATS_NETWORK_TYPE == c)
497 fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n",
498 GNUNET_ATS_print_property_type(c),
499 log_a->prop_abs[c], log_a->prop_norm[c]);
507 GNUNET_ATS_solver_logging_free (struct LoggingHandle *l)
509 struct LoggingTimeStep *lts_cur;
510 struct LoggingTimeStep *lts_next;
511 struct LoggingPeer *log_p_cur;
512 struct LoggingPeer *log_p_next;
513 struct LoggingAddress *log_a_cur;
514 struct LoggingAddress *log_a_next;
516 if (GNUNET_SCHEDULER_NO_TASK != l->logging_task)
517 GNUNET_SCHEDULER_cancel (l->logging_task);
518 l->logging_task = GNUNET_SCHEDULER_NO_TASK;
521 while (NULL != (lts_cur = lts_next))
523 lts_next = lts_cur->next;
525 log_p_next = lts_cur->head;
526 while (NULL != (log_p_cur = log_p_next))
528 log_p_next = log_p_cur->next;
530 log_a_next = log_p_cur->addr_head;
531 while (NULL != (log_a_cur = log_a_next))
533 log_a_next = log_a_cur->next;
535 GNUNET_CONTAINER_DLL_remove (log_p_cur->addr_head, log_p_cur->addr_tail, log_a_cur);
536 GNUNET_free (log_a_cur);
539 GNUNET_CONTAINER_DLL_remove (lts_cur->head, lts_cur->tail, log_p_cur);
540 GNUNET_free (log_p_cur);
543 GNUNET_CONTAINER_DLL_remove (l->head, l->tail, lts_cur);
544 GNUNET_free (lts_cur);
551 * Property Generators
554 static struct PropertyGenerator *prop_gen_head;
555 static struct PropertyGenerator *prop_gen_tail;
558 get_property (struct PropertyGenerator *pg)
560 struct GNUNET_TIME_Relative time_delta;
564 /* Calculate the current preference value */
566 case GNUNET_ATS_TEST_TG_CONSTANT:
567 pref_value = pg->base_value;
569 case GNUNET_ATS_TEST_TG_LINEAR:
570 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
571 /* Calculate point of time in the current period */
572 time_delta.rel_value_us = time_delta.rel_value_us %
573 pg->duration_period.rel_value_us;
574 delta_value = ((double) time_delta.rel_value_us /
575 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
576 if ((pg->max_value < pg->base_value) &&
577 ((pg->max_value - pg->base_value) > pg->base_value))
579 /* This will cause an underflow */
582 pref_value = pg->base_value + delta_value;
584 case GNUNET_ATS_TEST_TG_RANDOM:
585 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
586 10000 * (pg->max_value - pg->base_value)) / 10000;
587 pref_value = pg->base_value + delta_value;
589 case GNUNET_ATS_TEST_TG_SINUS:
590 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
591 /* Calculate point of time in the current period */
592 time_delta.rel_value_us = time_delta.rel_value_us %
593 pg->duration_period.rel_value_us;
594 if ((pg->max_value - pg->base_value) > pg->base_value)
596 /* This will cause an underflow for second half of sinus period,
597 * will be detected in general when experiments are loaded */
600 delta_value = (pg->max_value - pg->base_value) *
601 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
602 time_delta.rel_value_us);
603 pref_value = pg->base_value + delta_value;
609 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current property value is %f\n",
616 set_prop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
618 struct PropertyGenerator *pg = cls;
620 struct TestAddress *a;
622 struct GNUNET_ATS_Information atsi;
624 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
626 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains_value (sh->addresses,
627 &pg->test_peer->peer_id, pg->test_address->ats_addr))
630 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
631 "Setting property generation for unknown address [%u:%u]\n",
632 pg->peer, pg->address_id);
635 if (NULL == (p = find_peer_by_id (pg->peer)))
637 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
638 "Setting property generation for unknown peer %u\n",
641 if (NULL == (a = find_address_by_id (p, pg->address_id)))
643 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
644 "Setting property generation for unknown peer %u\n",
648 prop_value = get_property (pg);
649 a->prop_abs[pg->ats_property] = prop_value;
651 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
652 "Setting property for peer [%u] address [%u] for %s to %f\n",
653 pg->peer, pg->address_id,
654 GNUNET_ATS_print_property_type (pg->ats_property), prop_value);
656 atsi.type = htonl (pg->ats_property);
657 atsi.value = htonl ((uint32_t) prop_value);
659 /* set performance here! */
660 sh->env.sf.s_bulk_start (sh->solver);
661 if (GNUNET_YES == opt_disable_normalization)
663 a->prop_abs[pg->ats_property] = prop_value;
664 a->prop_norm[pg->ats_property] = prop_value;
665 sh->env.sf.s_address_update_property (sh->solver, a->ats_addr,
666 pg->ats_property, prop_value, prop_value);
669 GAS_normalization_normalize_property (sh->addresses,
670 pg->test_address->ats_addr, &atsi, 1);
671 sh->env.sf.s_bulk_stop (sh->solver);
673 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
679 * Set ats_property to 0 to find all pgs
682 static struct PropertyGenerator *
683 find_prop_gen (unsigned int peer, unsigned int address,
684 uint32_t ats_property)
686 struct PropertyGenerator *cur;
687 for (cur = prop_gen_head; NULL != cur; cur = cur->next)
688 if ((cur->peer == peer) && (cur->address_id == address))
690 if ((cur->ats_property == ats_property) || (0 == ats_property))
697 GNUNET_ATS_solver_generate_property_stop (struct PropertyGenerator *pg)
699 GNUNET_CONTAINER_DLL_remove (prop_gen_head, prop_gen_tail, pg);
701 if (GNUNET_SCHEDULER_NO_TASK != pg->set_task)
703 GNUNET_SCHEDULER_cancel (pg->set_task);
704 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
706 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
707 "Removing old up preference generator peer [%u] address [%u] `%s'\n",
708 pg->peer, pg->address_id,
709 GNUNET_ATS_print_property_type(pg->ats_property));
716 * Generate between the source master and the partner and set property with a
717 * value depending on the generator.
720 * @param address_id partner
721 * @param test_peer the peer
722 * @param test_address the address
723 * @param type type of generator
724 * @param base_value base value
725 * @param value_rate maximum value
726 * @param period duration of a period of generation (~ 1/frequency)
727 * @param frequency how long to generate property
728 * @param ats_property ATS property to generate
729 * @return the property generator
731 struct PropertyGenerator *
732 GNUNET_ATS_solver_generate_property_start (unsigned int peer,
733 unsigned int address_id,
734 struct TestPeer *test_peer,
735 struct TestAddress *test_address,
736 enum GeneratorType type,
739 struct GNUNET_TIME_Relative period,
740 struct GNUNET_TIME_Relative frequency,
741 uint32_t ats_property)
743 struct PropertyGenerator *pg;
745 pg = GNUNET_new (struct PropertyGenerator);
746 GNUNET_CONTAINER_DLL_insert (prop_gen_head, prop_gen_tail, pg);
749 pg->test_address = test_address;
750 pg->test_peer = test_peer;
751 pg->address_id = address_id;
752 pg->ats_property = ats_property;
753 pg->base_value = base_value;
754 pg->max_value = value_rate;
755 pg->duration_period = period;
756 pg->frequency = frequency;
757 pg->time_start = GNUNET_TIME_absolute_get();
760 case GNUNET_ATS_TEST_TG_CONSTANT:
761 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
762 "Setting up %s property generator peer [%u] address [%u] `%s'"\
764 print_generator_type(type), pg->peer, pg->address_id,
765 GNUNET_ATS_print_property_type (ats_property),
768 case GNUNET_ATS_TEST_TG_LINEAR:
769 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
770 "Setting up %s property generator peer [%u] address [%u] `%s' " \
771 "min %u Bips max %u Bips\n",
772 print_generator_type(type), pg->peer, pg->address_id,
773 GNUNET_ATS_print_property_type(ats_property),
774 base_value, value_rate);
776 case GNUNET_ATS_TEST_TG_SINUS:
777 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
778 "Setting up %s property generator peer [%u] address [%u] `%s' "\
779 "baserate %u Bips, amplitude %u Bps\n",
780 print_generator_type(type), pg->peer, pg->address_id,
781 GNUNET_ATS_print_property_type(ats_property),
782 base_value, value_rate);
784 case GNUNET_ATS_TEST_TG_RANDOM:
785 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
786 "Setting up %s property generator peer [%u] address [%u] `%s' "\
787 "min %u Bips max %u Bps\n",
788 print_generator_type(type), pg->peer, pg->address_id,
789 GNUNET_ATS_print_property_type(ats_property),
790 base_value, value_rate);
796 pg->set_task = GNUNET_SCHEDULER_add_now (&set_prop_task, pg);
803 * Stop all preferences generators
806 GNUNET_ATS_solver_generate_property_stop_all ()
808 struct PropertyGenerator *cur;
809 struct PropertyGenerator *next;
810 next = prop_gen_head;
811 for (cur = next; NULL != cur; cur = next)
814 GNUNET_ATS_solver_generate_property_stop (cur);
820 * Preference Generators
823 static struct PreferenceGenerator *pref_gen_head;
824 static struct PreferenceGenerator *pref_gen_tail;
827 get_preference (struct PreferenceGenerator *pg)
829 struct GNUNET_TIME_Relative time_delta;
833 /* Calculate the current preference value */
835 case GNUNET_ATS_TEST_TG_CONSTANT:
836 pref_value = pg->base_value;
838 case GNUNET_ATS_TEST_TG_LINEAR:
839 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
840 /* Calculate point of time in the current period */
841 time_delta.rel_value_us = time_delta.rel_value_us %
842 pg->duration_period.rel_value_us;
843 delta_value = ((double) time_delta.rel_value_us /
844 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
845 if ((pg->max_value < pg->base_value) &&
846 ((pg->max_value - pg->base_value) > pg->base_value))
848 /* This will cause an underflow */
851 pref_value = pg->base_value + delta_value;
853 case GNUNET_ATS_TEST_TG_RANDOM:
854 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
855 10000 * (pg->max_value - pg->base_value)) / 10000;
856 pref_value = pg->base_value + delta_value;
858 case GNUNET_ATS_TEST_TG_SINUS:
859 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
860 /* Calculate point of time in the current period */
861 time_delta.rel_value_us = time_delta.rel_value_us %
862 pg->duration_period.rel_value_us;
863 if ((pg->max_value - pg->base_value) > pg->base_value)
865 /* This will cause an underflow for second half of sinus period,
866 * will be detected in general when experiments are loaded */
869 delta_value = (pg->max_value - pg->base_value) *
870 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
871 time_delta.rel_value_us);
872 pref_value = pg->base_value + delta_value;
878 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
885 set_pref_task (void *cls,
886 const struct GNUNET_SCHEDULER_TaskContext *tc)
888 struct PreferenceGenerator *pg = cls;
891 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
893 if (NULL == (p = find_peer_by_id (pg->peer)))
896 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
897 "Setting preference for unknown peer %u\n", pg->peer);
901 pref_value = get_preference (pg);
902 p->pref_abs[pg->kind] = pref_value;
904 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
905 "Setting preference for peer [%u] for client %p pref %s to %f\n",
906 pg->peer, NULL + (pg->client_id),
907 GNUNET_ATS_print_preference_type (pg->kind), pref_value);
909 sh->env.sf.s_bulk_start (sh->solver);
910 if (GNUNET_YES == opt_disable_normalization)
912 p->pref_abs[pg->kind] = pref_value;
913 p->pref_norm[pg->kind] = pref_value;
914 sh->env.sf.s_pref (sh->solver, &p->peer_id, pg->kind, pref_value);
917 GAS_normalization_normalize_preference (NULL + (pg->client_id),
918 &p->peer_id, pg->kind, pref_value);
919 sh->env.sf.s_bulk_stop (sh->solver);
922 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
923 //p->pref_bandwidth = pref_value;
925 case GNUNET_ATS_PREFERENCE_LATENCY:
926 //p->pref_delay = pref_value;
932 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
937 static struct PreferenceGenerator *
938 find_pref_gen (unsigned int peer, enum GNUNET_ATS_PreferenceKind kind)
940 struct PreferenceGenerator *cur;
941 for (cur = pref_gen_head; NULL != cur; cur = cur->next)
942 if (cur->peer == peer)
944 if ((cur->kind == kind) || (GNUNET_ATS_PREFERENCE_END == kind))
951 GNUNET_ATS_solver_generate_preferences_stop (struct PreferenceGenerator *pg)
953 GNUNET_CONTAINER_DLL_remove (pref_gen_head, pref_gen_tail, pg);
955 if (GNUNET_SCHEDULER_NO_TASK != pg->set_task)
957 GNUNET_SCHEDULER_cancel (pg->set_task);
958 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
960 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
961 "Removing old up preference generator peer [%u] `%s'\n",
962 pg->peer, GNUNET_ATS_print_preference_type(pg->kind));
969 * Generate between the source master and the partner and set property with a
970 * value depending on the generator.
973 * @param address_id partner
974 * @param client_id the client
975 * @param type type of generator
976 * @param base_value base value
977 * @param value_rate maximum value
978 * @param period duration of a period of generation (~ 1/frequency)
979 * @param frequency how long to generate property
980 * @param kind ATS preference to generate
981 * @return the preference generator
983 struct PreferenceGenerator *
984 GNUNET_ATS_solver_generate_preferences_start (unsigned int peer,
985 unsigned int address_id,
986 unsigned int client_id,
987 enum GeneratorType type,
990 struct GNUNET_TIME_Relative period,
991 struct GNUNET_TIME_Relative frequency,
992 enum GNUNET_ATS_PreferenceKind kind)
994 struct PreferenceGenerator *pg;
996 pg = GNUNET_new (struct PreferenceGenerator);
997 GNUNET_CONTAINER_DLL_insert (pref_gen_head, pref_gen_tail, pg);
1000 pg->client_id = client_id;
1002 pg->base_value = base_value;
1003 pg->max_value = value_rate;
1004 pg->duration_period = period;
1005 pg->frequency = frequency;
1006 pg->time_start = GNUNET_TIME_absolute_get();
1009 case GNUNET_ATS_TEST_TG_CONSTANT:
1010 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1011 "Setting up %s preference generator peer [%u] `%s' max %u Bips\n",
1012 print_generator_type (type), pg->peer,
1013 GNUNET_ATS_print_preference_type(kind),
1016 case GNUNET_ATS_TEST_TG_LINEAR:
1017 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1018 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bips\n",
1019 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1020 base_value, value_rate);
1022 case GNUNET_ATS_TEST_TG_SINUS:
1023 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1024 "Setting up %s preference generator peer [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
1025 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1026 base_value, value_rate);
1028 case GNUNET_ATS_TEST_TG_RANDOM:
1029 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1030 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bps\n",
1031 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1032 base_value, value_rate);
1038 pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, pg);
1045 * Stop all preferences generators
1048 GNUNET_ATS_solver_generate_preferences_stop_all ()
1050 struct PreferenceGenerator *cur;
1051 struct PreferenceGenerator *next;
1052 next = pref_gen_head;
1053 for (cur = next; NULL != cur; cur = next)
1056 GNUNET_ATS_solver_generate_preferences_stop(cur);
1067 print_op (enum OperationType op)
1070 case SOLVER_OP_ADD_ADDRESS:
1071 return "ADD_ADDRESS";
1072 case SOLVER_OP_DEL_ADDRESS:
1073 return "DEL_ADDRESS";
1074 case SOLVER_OP_START_SET_PREFERENCE:
1075 return "START_SET_PREFERENCE";
1076 case SOLVER_OP_STOP_SET_PREFERENCE:
1077 return "STOP_STOP_PREFERENCE";
1078 case SOLVER_OP_START_SET_PROPERTY:
1079 return "START_SET_PROPERTY";
1080 case SOLVER_OP_STOP_SET_PROPERTY:
1081 return "STOP_SET_PROPERTY";
1082 case SOLVER_OP_START_REQUEST:
1083 return "START_REQUEST";
1084 case SOLVER_OP_STOP_REQUEST:
1085 return "STOP_REQUEST";
1092 static struct Experiment *
1093 create_experiment ()
1095 struct Experiment *e;
1096 e = GNUNET_new (struct Experiment);
1099 e->total_duration = GNUNET_TIME_UNIT_ZERO;
1104 free_experiment (struct Experiment *e)
1106 struct Episode *cur;
1107 struct Episode *next;
1108 struct GNUNET_ATS_TEST_Operation *cur_o;
1109 struct GNUNET_ATS_TEST_Operation *next_o;
1112 for (cur = next; NULL != cur; cur = next)
1117 for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
1119 next_o = cur_o->next;
1120 GNUNET_free_non_null (cur_o->address);
1121 GNUNET_free_non_null (cur_o->plugin);
1122 GNUNET_free (cur_o);
1127 GNUNET_free_non_null (e->name);
1128 GNUNET_free_non_null (e->log_prefix);
1129 GNUNET_free_non_null (e->log_output_dir);
1130 GNUNET_free_non_null (e->cfg_file);
1136 load_op_add_address (struct GNUNET_ATS_TEST_Operation *o,
1140 const struct GNUNET_CONFIGURATION_Handle *cfg)
1146 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1147 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1148 sec_name, op_name, &o->peer_id))
1150 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1151 op_counter, "ADD_ADDRESS", op_name);
1152 GNUNET_free (op_name);
1153 return GNUNET_SYSERR;
1155 GNUNET_free (op_name);
1158 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1159 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1160 sec_name, op_name, &o->address_id))
1162 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1163 op_counter, "ADD_ADDRESS", op_name);
1164 GNUNET_free (op_name);
1165 return GNUNET_SYSERR;
1167 GNUNET_free (op_name);
1170 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
1171 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1172 sec_name, op_name, &o->plugin))
1174 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
1175 op_counter, "ADD_ADDRESS", op_name);
1176 GNUNET_free (op_name);
1177 return GNUNET_SYSERR;
1179 GNUNET_free (op_name);
1182 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
1183 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1184 sec_name, op_name, &o->address))
1186 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
1187 op_counter, "ADD_ADDRESS", op_name);
1188 GNUNET_free (op_name);
1189 return GNUNET_SYSERR;
1191 GNUNET_free (op_name);
1194 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
1195 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1196 sec_name, op_name, &o->address_session))
1198 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
1199 op_counter, "ADD_ADDRESS", op_name);
1200 GNUNET_free (op_name);
1201 return GNUNET_SYSERR;
1203 GNUNET_free (op_name);
1206 GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter);
1207 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1208 sec_name, op_name, &op_network))
1210 fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
1211 op_counter, "ADD_ADDRESS", op_name);
1212 GNUNET_free (op_name);
1213 return GNUNET_SYSERR;
1217 GNUNET_STRINGS_utf8_toupper (op_network,op_network);
1218 if (0 == strcmp(op_network, "UNSPECIFIED"))
1220 o->address_network = GNUNET_ATS_NET_UNSPECIFIED;
1222 else if (0 == strcmp(op_network, "LOOPBACK"))
1224 o->address_network = GNUNET_ATS_NET_LOOPBACK;
1226 else if (0 == strcmp(op_network, "LAN"))
1228 o->address_network = GNUNET_ATS_NET_LAN;
1230 else if (0 == strcmp(op_network, "WAN"))
1232 o->address_network = GNUNET_ATS_NET_WAN;
1234 else if (0 == strcmp(op_network, "WLAN"))
1236 o->address_network = GNUNET_ATS_NET_WLAN;
1238 else if (0 == strcmp(op_network, "BT"))
1240 o->address_network = GNUNET_ATS_NET_BT;
1244 fprintf (stderr, "Invalid address-network in operation %u `%s' in episode `%s': `%s'\n",
1245 op_counter, "ADD_ADDRESS", op_name, op_network);
1246 GNUNET_free (op_network);
1247 GNUNET_free (op_name);
1248 return GNUNET_SYSERR;
1251 GNUNET_free (op_network);
1252 GNUNET_free (op_name);
1254 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1255 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
1256 "ADD_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
1262 load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
1266 const struct GNUNET_CONFIGURATION_Handle *cfg)
1272 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1273 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1274 sec_name, op_name, &o->peer_id))
1276 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1277 op_counter, "DEL_ADDRESS", op_name);
1278 GNUNET_free (op_name);
1279 return GNUNET_SYSERR;
1281 GNUNET_free (op_name);
1284 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1285 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1286 sec_name, op_name, &o->address_id))
1288 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1289 op_counter, "DEL_ADDRESS", op_name);
1290 GNUNET_free (op_name);
1291 return GNUNET_SYSERR;
1293 GNUNET_free (op_name);
1297 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
1298 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1299 sec_name, op_name, &o->plugin))
1301 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
1302 op_counter, "DEL_ADDRESS", op_name);
1303 GNUNET_free (op_name);
1304 return GNUNET_SYSERR;
1306 GNUNET_free (op_name);
1309 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
1310 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1311 sec_name, op_name, &o->address))
1313 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
1314 op_counter, "DEL_ADDRESS", op_name);
1315 GNUNET_free (op_name);
1316 return GNUNET_SYSERR;
1318 GNUNET_free (op_name);
1321 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
1322 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1323 sec_name, op_name, &o->address_session))
1325 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
1326 op_counter, "DEL_ADDRESS", op_name);
1327 GNUNET_free (op_name);
1328 return GNUNET_SYSERR;
1330 GNUNET_free (op_name);
1333 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1334 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
1335 "DEL_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
1340 static enum GNUNET_ATS_Property
1341 parse_preference_string (const char * str)
1344 char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
1346 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
1347 if (0 == strcmp(str, props[c]))
1353 load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1357 const struct GNUNET_CONFIGURATION_Handle *cfg)
1364 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1365 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1366 sec_name, op_name, &o->peer_id))
1368 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1369 op_counter, "START_SET_PREFERENCE", op_name);
1370 GNUNET_free (op_name);
1371 return GNUNET_SYSERR;
1373 GNUNET_free (op_name);
1376 GNUNET_asprintf(&op_name, "op-%u-client-id", op_counter);
1377 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1378 sec_name, op_name, &o->client_id))
1380 fprintf (stderr, "Missing client-id in operation %u `%s' in episode `%s'\n",
1381 op_counter, "START_SET_PREFERENCE", op_name);
1382 GNUNET_free (op_name);
1383 return GNUNET_SYSERR;
1385 GNUNET_free (op_name);
1388 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1389 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1390 sec_name, op_name, &type)) )
1392 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1393 op_counter, "START_SET_PREFERENCE", op_name);
1394 GNUNET_free (op_name);
1395 return GNUNET_SYSERR;
1398 /* Load arguments for set_rate, start_send, set_preference */
1399 if (0 == strcmp (type, "constant"))
1401 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1403 else if (0 == strcmp (type, "linear"))
1405 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1407 else if (0 == strcmp (type, "sinus"))
1409 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1411 else if (0 == strcmp (type, "random"))
1413 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1417 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1418 op_counter, op_name, e->id);
1420 GNUNET_free (op_name);
1421 return GNUNET_SYSERR;
1424 GNUNET_free (op_name);
1428 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1429 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1430 sec_name, op_name, &o->base_rate))
1432 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1433 op_counter, op_name, e->id);
1434 GNUNET_free (op_name);
1435 return GNUNET_SYSERR;
1437 GNUNET_free (op_name);
1441 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1442 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1443 sec_name, op_name, &o->max_rate))
1445 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1446 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1447 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1449 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1450 op_counter, op_name, e->id);
1451 GNUNET_free (op_name);
1452 return GNUNET_SYSERR;
1455 GNUNET_free (op_name);
1458 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1459 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1460 sec_name, op_name, &o->period))
1462 o->period = e->duration;
1464 GNUNET_free (op_name);
1467 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1468 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1469 sec_name, op_name, &o->frequency))
1471 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1472 op_counter, op_name, e->id);
1473 GNUNET_free (op_name);
1474 return GNUNET_SYSERR;
1476 GNUNET_free (op_name);
1478 /* Get preference */
1479 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1480 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1481 sec_name, op_name, &pref))
1483 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
1484 op_counter, op_name, e->id);
1485 GNUNET_free (op_name);
1486 return GNUNET_SYSERR;
1489 if (0 == (o->pref_type = parse_preference_string(pref)))
1491 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1492 op_counter, op_name, e->id);
1493 GNUNET_free (op_name);
1495 return GNUNET_SYSERR;
1498 GNUNET_free (op_name);
1500 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1501 "Found operation %s: [%llu:%llu]: %s = %llu\n",
1502 "START_SET_PREFERENCE", o->peer_id, o->address_id,
1503 GNUNET_ATS_print_preference_type(o->pref_type), o->base_rate);
1509 load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1513 const struct GNUNET_CONFIGURATION_Handle *cfg)
1519 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1520 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1521 sec_name, op_name, &o->peer_id))
1523 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1524 op_counter, "STOP_SET_PREFERENCE", op_name);
1525 GNUNET_free (op_name);
1526 return GNUNET_SYSERR;
1528 GNUNET_free (op_name);
1531 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1532 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1533 sec_name, op_name, &o->address_id))
1535 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1536 op_counter, "STOP_SET_PREFERENCE", op_name);
1537 GNUNET_free (op_name);
1538 return GNUNET_SYSERR;
1540 GNUNET_free (op_name);
1542 /* Get preference */
1543 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1544 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1545 sec_name, op_name, &pref))
1547 fprintf (stderr, "Missing preference in operation %u `%s' in episode `%s'\n",
1548 op_counter, "STOP_SET_PREFERENCE", op_name);
1549 GNUNET_free (op_name);
1550 return GNUNET_SYSERR;
1553 if (0 == (o->pref_type = parse_preference_string(pref)))
1555 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1556 op_counter, op_name, e->id);
1557 GNUNET_free (op_name);
1559 return GNUNET_SYSERR;
1562 GNUNET_free (op_name);
1564 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1565 "Found operation %s: [%llu:%llu]: %s\n",
1566 "STOP_SET_PREFERENCE", o->peer_id, o->address_id,
1567 GNUNET_ATS_print_preference_type(o->pref_type));
1571 static enum GNUNET_ATS_Property
1572 parse_property_string (const char * str)
1575 char *props[GNUNET_ATS_PropertyCount] = GNUNET_ATS_PropertyStrings;
1577 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
1578 if (0 == strcmp(str, props[c]))
1584 load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o,
1588 const struct GNUNET_CONFIGURATION_Handle *cfg)
1595 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1596 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1597 sec_name, op_name, &o->peer_id))
1599 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1600 op_counter, "START_SET_PROPERTY", op_name);
1601 GNUNET_free (op_name);
1602 return GNUNET_SYSERR;
1604 GNUNET_free (op_name);
1607 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1608 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1609 sec_name, op_name, &o->address_id))
1611 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1612 op_counter, "START_SET_PROPERTY", op_name);
1613 GNUNET_free (op_name);
1614 return GNUNET_SYSERR;
1616 GNUNET_free (op_name);
1619 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1620 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1621 sec_name, op_name, &type)) )
1623 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1624 op_counter, "START_SET_PROPERTY", op_name);
1625 GNUNET_free (op_name);
1626 return GNUNET_SYSERR;
1629 /* Load arguments for set_rate, start_send, set_preference */
1630 if (0 == strcmp (type, "constant"))
1632 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1634 else if (0 == strcmp (type, "linear"))
1636 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1638 else if (0 == strcmp (type, "sinus"))
1640 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1642 else if (0 == strcmp (type, "random"))
1644 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1648 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1649 op_counter, op_name, e->id);
1651 GNUNET_free (op_name);
1652 return GNUNET_SYSERR;
1655 GNUNET_free (op_name);
1659 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1660 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1661 sec_name, op_name, &o->base_rate))
1663 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1664 op_counter, op_name, e->id);
1665 GNUNET_free (op_name);
1666 return GNUNET_SYSERR;
1668 GNUNET_free (op_name);
1672 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1673 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1674 sec_name, op_name, &o->max_rate))
1676 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1677 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1678 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1680 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1681 op_counter, op_name, e->id);
1682 GNUNET_free (op_name);
1683 return GNUNET_SYSERR;
1686 GNUNET_free (op_name);
1689 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1690 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1691 sec_name, op_name, &o->period))
1693 o->period = e->duration;
1695 GNUNET_free (op_name);
1698 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1699 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1700 sec_name, op_name, &o->frequency))
1702 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1703 op_counter, op_name, e->id);
1704 GNUNET_free (op_name);
1705 return GNUNET_SYSERR;
1707 GNUNET_free (op_name);
1709 /* Get preference */
1710 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1711 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1712 sec_name, op_name, &prop))
1714 fprintf (stderr, "Missing property in operation %u `%s' in episode %u\n",
1715 op_counter, op_name, e->id);
1716 GNUNET_free (op_name);
1717 GNUNET_free_non_null (prop);
1718 return GNUNET_SYSERR;
1721 if (0 == (o->prop_type = parse_property_string(prop)))
1723 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1724 op_counter, op_name, e->id);
1725 GNUNET_free (op_name);
1727 return GNUNET_SYSERR;
1731 GNUNET_free (op_name);
1733 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1734 "Found operation %s: [%llu:%llu] %s = %llu\n",
1735 "START_SET_PROPERTY", o->peer_id, o->address_id,
1736 GNUNET_ATS_print_property_type (o->prop_type), o->base_rate);
1742 load_op_stop_set_property (struct GNUNET_ATS_TEST_Operation *o,
1746 const struct GNUNET_CONFIGURATION_Handle *cfg)
1752 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1753 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1754 sec_name, op_name, &o->peer_id))
1756 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1757 op_counter, "STOP_SET_PROPERTY", op_name);
1758 GNUNET_free (op_name);
1759 return GNUNET_SYSERR;
1761 GNUNET_free (op_name);
1764 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1765 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1766 sec_name, op_name, &o->address_id))
1768 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1769 op_counter, "STOP_SET_PROPERTY", op_name);
1770 GNUNET_free (op_name);
1771 return GNUNET_SYSERR;
1773 GNUNET_free (op_name);
1776 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1777 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1778 sec_name, op_name, &pref))
1780 fprintf (stderr, "Missing property in operation %u `%s' in episode `%s'\n",
1781 op_counter, "STOP_SET_PROPERTY", op_name);
1782 GNUNET_free (op_name);
1783 GNUNET_free_non_null (pref);
1784 return GNUNET_SYSERR;
1787 if (0 == (o->prop_type = parse_property_string(pref)))
1789 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1790 op_counter, op_name, e->id);
1791 GNUNET_free (op_name);
1792 GNUNET_free_non_null (pref);
1793 return GNUNET_SYSERR;
1797 GNUNET_free (op_name);
1799 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1800 "Found operation %s: [%llu:%llu] %s\n",
1801 "STOP_SET_PROPERTY", o->peer_id, o->address_id,
1802 GNUNET_ATS_print_property_type (o->prop_type));
1809 load_op_start_request (struct GNUNET_ATS_TEST_Operation *o,
1813 const struct GNUNET_CONFIGURATION_Handle *cfg)
1818 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1819 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1820 sec_name, op_name, &o->peer_id))
1822 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1823 op_counter, "START_REQUEST", op_name);
1824 GNUNET_free (op_name);
1825 return GNUNET_SYSERR;
1827 GNUNET_free (op_name);
1832 load_op_stop_request (struct GNUNET_ATS_TEST_Operation *o,
1836 const struct GNUNET_CONFIGURATION_Handle *cfg)
1841 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1842 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1843 sec_name, op_name, &o->peer_id))
1845 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1846 op_counter, "STOP_REQUEST", op_name);
1847 GNUNET_free (op_name);
1848 return GNUNET_SYSERR;
1850 GNUNET_free (op_name);
1856 load_episode (struct Experiment *e, struct Episode *cur,
1857 struct GNUNET_CONFIGURATION_Handle *cfg)
1859 struct GNUNET_ATS_TEST_Operation *o;
1865 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Parsing episode %u\n",cur->id);
1866 GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
1870 /* Load operation */
1871 GNUNET_asprintf(&op_name, "op-%u-operation", op_counter);
1872 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1873 sec_name, op_name, &op))
1875 GNUNET_free (op_name);
1878 o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
1879 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "==== Parsing operation %u: `%s'\n",
1882 /* operations = set_rate, start_send, stop_send, set_preference */
1883 if (0 == strcmp (op, "address_add"))
1885 o->type = SOLVER_OP_ADD_ADDRESS;
1886 res = load_op_add_address (o, cur,
1887 op_counter, sec_name, cfg);
1889 else if (0 == strcmp (op, "address_del"))
1891 o->type = SOLVER_OP_DEL_ADDRESS;
1892 res = load_op_del_address (o, cur,
1893 op_counter, sec_name, cfg);
1895 else if (0 == strcmp (op, "start_set_property"))
1897 o->type = SOLVER_OP_START_SET_PROPERTY;
1898 res = load_op_start_set_property (o, cur,
1899 op_counter, sec_name, cfg);
1901 else if (0 == strcmp (op, "stop_set_property"))
1903 o->type = SOLVER_OP_STOP_SET_PROPERTY;
1904 res = load_op_stop_set_property (o, cur,
1905 op_counter, sec_name, cfg);
1907 else if (0 == strcmp (op, "start_set_preference"))
1909 o->type = SOLVER_OP_START_SET_PREFERENCE;
1910 res = load_op_start_set_preference (o, cur,
1911 op_counter, sec_name, cfg);
1913 else if (0 == strcmp (op, "stop_set_preference"))
1915 o->type = SOLVER_OP_STOP_SET_PREFERENCE;
1916 res = load_op_stop_set_preference (o, cur,
1917 op_counter, sec_name, cfg);
1919 else if (0 == strcmp (op, "start_request"))
1921 o->type = SOLVER_OP_START_REQUEST;
1922 res = load_op_start_request (o, cur,
1923 op_counter, sec_name, cfg);
1925 else if (0 == strcmp (op, "stop_request"))
1927 o->type = SOLVER_OP_STOP_REQUEST;
1928 res = load_op_stop_request(o, cur,
1929 op_counter, sec_name, cfg);
1933 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
1934 op_counter, op, cur->id);
1935 res = GNUNET_SYSERR;
1939 GNUNET_free (op_name);
1941 if (GNUNET_SYSERR == res)
1944 GNUNET_free (sec_name);
1945 return GNUNET_SYSERR;
1948 GNUNET_CONTAINER_DLL_insert_tail (cur->head,cur->tail, o);
1951 GNUNET_free (sec_name);
1956 load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
1960 struct GNUNET_TIME_Relative e_duration;
1961 struct Episode *cur;
1962 struct Episode *last;
1968 GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
1969 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
1970 sec_name, "duration", &e_duration))
1972 GNUNET_free (sec_name);
1976 cur = GNUNET_new (struct Episode);
1977 cur->duration = e_duration;
1978 cur->id = e_counter;
1980 if (GNUNET_OK != load_episode (e, cur, cfg))
1982 GNUNET_free (sec_name);
1984 return GNUNET_SYSERR;
1987 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Found episode %u with duration %s \n",
1989 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
1991 /* Update experiment */
1993 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
1994 /* Put in linked list */
2000 GNUNET_free (sec_name);
2008 timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
2010 struct Experiment *e = cls;
2011 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2012 fprintf (stderr, "Experiment timeout!\n");
2014 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
2016 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2017 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2020 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
2024 struct ATS_Address *
2025 create_ats_address (const struct GNUNET_PeerIdentity *peer,
2026 const char *plugin_name,
2027 const void *plugin_addr,
2028 size_t plugin_addr_len,
2029 uint32_t session_id,
2032 struct ATS_Address *aa = NULL;
2034 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1);
2035 aa->atsi = GNUNET_new (struct GNUNET_ATS_Information);
2036 aa->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
2037 aa->atsi[0].value = htonl (network);
2041 aa->addr_len = plugin_addr_len;
2043 aa->plugin = (char *) &aa[1] + plugin_addr_len;
2044 memcpy (&aa[1], plugin_addr, plugin_addr_len);
2045 memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
2046 aa->session_id = session_id;
2047 aa->active = GNUNET_NO;
2048 aa->used = GNUNET_NO;
2049 aa->solver_information = NULL;
2050 aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0);
2051 aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0);
2059 enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
2062 struct TestAddress *a;
2065 if (NULL == (p = find_peer_by_id (op->peer_id)))
2067 p = GNUNET_new (struct TestPeer);
2068 p->id = op->peer_id;
2069 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
2070 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
2072 p->pref_abs[c] = DEFAULT_ABS_PREFERENCE;
2073 p->pref_norm[c] = DEFAULT_REL_PREFERENCE;
2076 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p);
2079 if (NULL != (find_address_by_id (p, op->address_id)))
2081 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Duplicate address %u for peer %u\n",
2082 op->address_id, op->peer_id);
2086 a = GNUNET_new (struct TestAddress);
2087 a->aid = op->address_id;
2088 a->network = op->address_network;
2089 a->ats_addr = create_ats_address (&p->peer_id, op->plugin, op->address,
2090 strlen (op->address) + 1, op->address_session, op->address_network);
2091 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
2092 GNUNET_CONTAINER_DLL_insert_tail (p->addr_head, p->addr_tail, a);
2094 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
2095 a->prop_norm[c] = DEFAULT_REL_QUALITY;
2097 GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, a->ats_addr,
2098 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2100 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u in network `%s'\n",
2101 op->address_id, op->peer_id, GNUNET_ATS_print_network_type(a->network));
2103 sh->env.sf.s_add (sh->solver, a->ats_addr, op->address_network);
2109 enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
2112 struct TestAddress *a;
2113 struct PropertyGenerator *pg;
2115 if (NULL == (p = find_peer_by_id (op->peer_id)))
2118 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2119 "Deleting address for unknown peer %u\n", op->peer_id);
2123 if (NULL == (a =find_address_by_id (p, op->address_id)))
2126 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2127 "Deleting address for unknown peer %u\n", op->peer_id);
2131 while (NULL != (pg = find_prop_gen (p->id, a->aid, 0)))
2133 GNUNET_ATS_solver_generate_property_stop (pg);
2136 GNUNET_CONTAINER_multipeermap_remove (sh->addresses, &p->peer_id, a->ats_addr);
2138 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Removing address %u for peer %u\n",
2139 op->address_id, op->peer_id);
2141 sh->env.sf.s_del (sh->solver, a->ats_addr, GNUNET_NO);
2145 GNUNET_ATS_solver_logging_now (l);
2147 GNUNET_CONTAINER_DLL_remove(p->addr_head, p->addr_tail, a);
2149 GNUNET_free_non_null(a->ats_addr->atsi);
2150 GNUNET_free (a->ats_addr);
2156 enforce_start_property (struct GNUNET_ATS_TEST_Operation *op)
2158 struct PropertyGenerator *pg;
2160 struct TestAddress *a;
2162 if (NULL != (pg = find_prop_gen (op->peer_id, op->address_id, op->prop_type)))
2164 GNUNET_ATS_solver_generate_property_stop (pg);
2168 if (NULL == (p = find_peer_by_id (op->peer_id)))
2171 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2172 "Starting property generation for unknown peer %u\n", op->peer_id);
2176 if (NULL == (a = find_address_by_id (p, op->address_id)))
2179 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2180 "Setting property for unknown address %u\n", op->peer_id);
2184 GNUNET_ATS_solver_generate_property_start (op->peer_id,
2196 enforce_stop_property (struct GNUNET_ATS_TEST_Operation *op)
2198 struct PropertyGenerator *pg = find_prop_gen(op->peer_id, op->address_id,
2202 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2203 "Stopping preference generation for peer %u address %u\n", op->peer_id,
2205 GNUNET_ATS_solver_generate_property_stop (pg);
2209 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2210 "Cannot find preference generator for peer %u address %u\n",
2211 op->peer_id, op->address_id);
2217 enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
2219 struct PreferenceGenerator *pg;
2220 if (NULL != (pg = find_pref_gen (op->peer_id, op->pref_type)))
2222 GNUNET_ATS_solver_generate_preferences_stop (pg);
2226 if (NULL == (find_peer_by_id (op->peer_id)))
2229 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2230 "Starting preference generation for unknown peer %u\n", op->peer_id);
2234 GNUNET_ATS_solver_generate_preferences_start (op->peer_id,
2246 enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
2248 struct PreferenceGenerator *pg = find_pref_gen(op->peer_id,
2252 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2253 "Stopping property generation for peer %u address %u\n", op->peer_id,
2255 GNUNET_ATS_solver_generate_preferences_stop (pg);
2259 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2260 "Cannot find preference generator for peer %u address %u\n",
2261 op->peer_id, op->address_id);
2268 enforce_start_request (struct GNUNET_ATS_TEST_Operation *op)
2271 const struct ATS_Address *res;
2273 if (NULL == (p = find_peer_by_id (op->peer_id)))
2276 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2277 "Requesting address for unknown peer %u\n", op->peer_id);
2281 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n",
2283 p->is_requested = GNUNET_YES;
2285 res = sh->env.sf.s_get (sh->solver, &p->peer_id);
2288 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Suggested address for peer %u: %llu %llu\n",
2290 ntohl(res->assigned_bw_in.value__),
2291 ntohl(res->assigned_bw_out.value__));
2293 GNUNET_ATS_solver_logging_now (l);
2298 enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op)
2302 if (NULL == (p = find_peer_by_id (op->peer_id)))
2305 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2306 "Requesting address for unknown peer %u\n", op->peer_id);
2310 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop requesting address for peer %u\n",
2312 p->is_requested = GNUNET_NO;
2313 sh->env.sf.s_get_stop (sh->solver, &p->peer_id);
2317 GNUNET_ATS_solver_logging_now (l);
2322 static void enforce_episode (struct Episode *ep)
2324 struct GNUNET_ATS_TEST_Operation *cur;
2325 for (cur = ep->head; NULL != cur; cur = cur->next)
2327 switch (cur->type) {
2328 case SOLVER_OP_ADD_ADDRESS:
2329 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2330 print_op (cur->type), cur->peer_id, cur->address_id);
2331 enforce_add_address (cur);
2333 case SOLVER_OP_DEL_ADDRESS:
2334 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2335 print_op (cur->type), cur->peer_id, cur->address_id);
2336 enforce_del_address (cur);
2338 case SOLVER_OP_START_SET_PROPERTY:
2339 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2340 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2341 enforce_start_property (cur);
2343 case SOLVER_OP_STOP_SET_PROPERTY:
2344 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2345 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2346 enforce_stop_property (cur);
2348 case SOLVER_OP_START_SET_PREFERENCE:
2349 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2350 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2351 enforce_start_preference (cur);
2353 case SOLVER_OP_STOP_SET_PREFERENCE:
2354 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2355 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2356 enforce_stop_preference (cur);
2358 case SOLVER_OP_START_REQUEST:
2359 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2360 print_op (cur->type), cur->peer_id);
2361 enforce_start_request (cur);
2363 case SOLVER_OP_STOP_REQUEST:
2364 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2365 print_op (cur->type), cur->peer_id);
2366 enforce_stop_request (cur);
2375 timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
2377 struct Experiment *e = cls;
2378 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2379 if (NULL != e->ep_done_cb)
2380 e->ep_done_cb (e->cur);
2382 /* Scheduling next */
2383 e->cur = e->cur->next;
2387 fprintf (stderr, "Last episode done!\n");
2388 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
2390 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2391 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2393 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
2397 fprintf (stderr, "Running episode %u with timeout %s\n",
2399 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2400 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2401 &timeout_episode, e);
2402 enforce_episode(e->cur);
2409 GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
2410 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
2411 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
2413 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
2414 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
2415 e->e_done_cb = e_done_cb;
2416 e->ep_done_cb = ep_done_cb;
2417 e->start_time = GNUNET_TIME_absolute_get();
2419 /* Start total time out */
2420 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
2421 &timeout_experiment, e);
2424 if (NULL == e->start)
2431 fprintf (stderr, "Running episode %u with timeout %s\n",
2433 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2434 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2435 &timeout_episode, e);
2436 enforce_episode(e->cur);
2441 GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
2443 if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
2445 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2446 e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2448 if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
2450 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2451 e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
2455 GNUNET_CONFIGURATION_destroy(e->cfg);
2458 free_experiment (e);
2463 GNUNET_ATS_solvers_experimentation_load (char *filename)
2465 struct Experiment *e;
2466 struct GNUNET_CONFIGURATION_Handle *cfg;
2469 cfg = GNUNET_CONFIGURATION_create();
2470 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
2472 fprintf (stderr, "Failed to load `%s'\n", filename);
2473 GNUNET_CONFIGURATION_destroy (cfg);
2477 e = create_experiment ();
2479 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2482 fprintf (stderr, "Invalid %s \n", "name");
2483 free_experiment (e);
2487 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment name: `%s'\n", e->name);
2489 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2490 "log_prefix", &e->log_prefix))
2492 fprintf (stderr, "Invalid %s \n", "log_prefix");
2493 free_experiment (e);
2497 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging prefix: `%s'\n",
2500 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2501 "log_output_dir", &e->log_output_dir))
2503 e->log_output_dir = NULL;
2506 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging output directory: `%s'\n",
2510 if (GNUNET_SYSERR == (e->log_append_time_stamp = GNUNET_CONFIGURATION_get_value_yesno(cfg,
2511 "experiment", "log_append_time_stamp")))
2512 e->log_append_time_stamp = GNUNET_YES;
2513 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging append timestamp: `%s'\n",
2514 (GNUNET_YES == e->log_append_time_stamp) ? "yes" : "no");
2517 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2518 "cfg_file", &e->cfg_file))
2520 fprintf (stderr, "Invalid %s \n", "cfg_file");
2521 free_experiment (e);
2526 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment configuration: `%s'\n", e->cfg_file);
2527 e->cfg = GNUNET_CONFIGURATION_create();
2528 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file))
2530 fprintf (stderr, "Invalid configuration %s \n", "cfg_file");
2531 free_experiment (e);
2537 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2538 "log_freq", &e->log_freq))
2540 fprintf (stderr, "Invalid %s \n", "log_freq");
2541 free_experiment (e);
2545 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging frequency: `%s'\n",
2546 GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
2548 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2549 "max_duration", &e->max_duration))
2551 fprintf (stderr, "Invalid %s", "max_duration");
2552 free_experiment (e);
2556 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment duration: `%s'\n",
2557 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
2559 if (GNUNET_SYSERR == load_episodes (e, cfg))
2561 GNUNET_ATS_solvers_experimentation_stop (e);
2562 GNUNET_CONFIGURATION_destroy (cfg);
2564 fprintf (stderr, "Failed to load experiment\n");
2567 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loaded %u episodes with total duration %s\n",
2569 GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
2571 GNUNET_CONFIGURATION_destroy (cfg);
2582 free_all_it (void *cls,
2583 const struct GNUNET_PeerIdentity *key,
2586 struct ATS_Address *address = value;
2587 GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (sh->env.addresses,
2589 GNUNET_free (address);
2595 GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh)
2597 GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
2599 GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
2601 GAS_normalization_stop();
2603 GNUNET_CONTAINER_multipeermap_iterate (sh->addresses, &free_all_it, NULL);
2604 GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
2605 GNUNET_free (sh->plugin);
2610 * Load quotas for networks from configuration
2612 * @param cfg configuration handle
2613 * @param out_dest where to write outbound quotas
2614 * @param in_dest where to write inbound quotas
2615 * @param dest_length length of inbound and outbound arrays
2616 * @return number of networks loaded
2619 GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
2620 unsigned long long *out_dest,
2621 unsigned long long *in_dest,
2624 char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
2625 char * entry_in = NULL;
2626 char * entry_out = NULL;
2627 char * quota_out_str;
2628 char * quota_in_str;
2632 for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
2636 GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]);
2637 GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]);
2640 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
2643 if (0 == strcmp(quota_out_str, BIG_M_STRING))
2645 out_dest[c] = GNUNET_ATS_MaxBandwidth;
2648 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
2650 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c])))
2653 if (GNUNET_NO == res)
2655 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2656 network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth);
2657 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Outbound quota configure for network `%s' is %llu\n"),
2662 network_str[c], out_dest[c]);
2664 GNUNET_free (quota_out_str);
2668 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
2669 network_str[c], GNUNET_ATS_DefaultBandwidth);
2670 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2674 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str))
2677 if (0 == strcmp(quota_in_str, BIG_M_STRING))
2679 in_dest[c] = GNUNET_ATS_MaxBandwidth;
2682 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
2684 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c])))
2687 if (GNUNET_NO == res)
2689 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2690 network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth);
2691 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
2695 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Inbound quota configured for network `%s' is %llu\n"),
2696 network_str[c], in_dest[c]);
2698 GNUNET_free (quota_in_str);
2702 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
2703 network_str[c], GNUNET_ATS_DefaultBandwidth);
2704 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2706 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]);
2707 GNUNET_free (entry_out);
2708 GNUNET_free (entry_in);
2710 return GNUNET_ATS_NetworkTypeCount;
2714 * Information callback for the solver
2716 * @param cls the closure
2717 * @param op the solver operation
2718 * @param stat status of the solver operation
2719 * @param add additional solver information
2722 solver_info_cb (void *cls,
2723 enum GAS_Solver_Operation op,
2724 enum GAS_Solver_Status stat,
2725 enum GAS_Solver_Additional_Information add)
2730 add_info = "GAS_INFO_NONE";
2733 add_info = "GAS_INFO_MLP_FULL";
2735 case GAS_INFO_UPDATED:
2736 add_info = "GAS_INFO_MLP_UPDATED";
2738 case GAS_INFO_PROP_ALL:
2739 add_info = "GAS_INFO_PROP_ALL";
2741 case GAS_INFO_PROP_SINGLE:
2742 add_info = "GAS_INFO_PROP_SINGLE";
2745 add_info = "INVALID";
2751 case GAS_OP_SOLVE_START:
2752 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2753 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
2754 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2756 case GAS_OP_SOLVE_STOP:
2757 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2758 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
2759 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2762 case GAS_OP_SOLVE_SETUP_START:
2763 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2764 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
2765 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2768 case GAS_OP_SOLVE_SETUP_STOP:
2769 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2770 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
2771 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2774 case GAS_OP_SOLVE_MLP_LP_START:
2775 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2776 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
2777 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2779 case GAS_OP_SOLVE_MLP_LP_STOP:
2780 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2781 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
2782 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2785 case GAS_OP_SOLVE_MLP_MLP_START:
2786 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2787 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
2788 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2790 case GAS_OP_SOLVE_MLP_MLP_STOP:
2791 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2792 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
2793 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2795 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
2796 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2797 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
2798 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2800 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
2801 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2802 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
2803 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2811 solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address)
2813 if ( (0 == ntohl (address->assigned_bw_out.value__)) &&
2814 (0 == ntohl (address->assigned_bw_in.value__)) )
2816 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2817 "Solver notified to disconnect peer `%s'\n",
2818 GNUNET_i2s (&address->peer));
2822 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2823 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
2824 GNUNET_i2s (&address->peer),
2826 (unsigned int) ntohl (address->assigned_bw_out.value__),
2827 (unsigned int) ntohl (address->assigned_bw_in.value__));
2828 /*if (GNUNET_YES == ph.bulk_running)
2831 GNUNET_ATS_solver_logging_now (l);
2837 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
2840 if (GNUNET_YES == opt_disable_normalization)
2842 if (NULL == (p = find_peer_by_pid (id)))
2847 return GAS_normalization_get_preferences_by_peer (id);
2852 get_property_cb (void *cls, const struct ATS_Address *address)
2855 struct TestAddress *a;
2857 if (GNUNET_YES == opt_disable_normalization)
2859 p = find_peer_by_pid (&address->peer);
2860 a = find_address_by_ats_address (p, address);
2864 return GAS_normalization_get_properties ((struct ATS_Address *) address);
2868 set_updated_property ( struct ATS_Address *address, uint32_t type, double prop_rel)
2871 struct TestAddress *a;
2873 if (NULL == (p = find_peer_by_pid (&address->peer)))
2879 if (NULL == (a = find_address_by_ats_address (p, address)))
2884 a->prop_norm[type] = prop_rel;
2885 sh->env.sf.s_address_update_property (sh->solver, address, type, a->prop_abs [type], prop_rel);
2890 normalized_property_changed_cb (void *cls, struct ATS_Address *address,
2891 uint32_t type, double prop_rel)
2893 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2894 "Normalized property %s for peer `%s' changed to %.3f \n",
2895 GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer),
2898 set_updated_property (address, type, prop_rel);
2902 set_updated_preference (const struct GNUNET_PeerIdentity *peer,
2903 enum GNUNET_ATS_PreferenceKind kind,
2908 if (NULL == (p = find_peer_by_pid (peer)))
2914 p->pref_norm[kind] = pref_rel;
2915 sh->env.sf.s_pref (sh->solver, peer, kind, pref_rel);
2920 normalized_preference_changed_cb (void *cls,
2921 const struct GNUNET_PeerIdentity *peer,
2922 enum GNUNET_ATS_PreferenceKind kind,
2925 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2926 "Normalized preference %s for peer `%s' changed to %.3f \n",
2927 GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer),
2930 set_updated_preference(peer, kind, pref_rel);
2934 struct SolverHandle *
2935 GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
2937 struct SolverHandle *sh;
2942 case GNUNET_ATS_SOLVER_PROPORTIONAL:
2943 solver_str = "proportional";
2945 case GNUNET_ATS_SOLVER_MLP:
2948 case GNUNET_ATS_SOLVER_RIL:
2957 sh = GNUNET_new (struct SolverHandle);
2958 GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
2960 sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
2961 /* setup environment */
2962 sh->env.cfg = e->cfg;
2963 sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg);
2964 sh->env.addresses = sh->addresses;
2965 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
2966 sh->env.get_preferences = &get_preferences_cb;
2967 sh->env.get_property = &get_property_cb;
2968 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
2969 sh->env.info_cb = &solver_info_cb;
2970 sh->env.info_cb_cls = NULL;
2971 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
2972 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
2973 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
2974 sh->env.networks[c] = networks[c];
2977 /* start normalization */
2978 GAS_normalization_start (&normalized_preference_changed_cb, NULL,
2979 &normalized_property_changed_cb, NULL );
2982 if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg,
2983 sh->env.out_quota, sh->env.in_quota, GNUNET_ATS_NetworkTypeCount))
2986 GNUNET_free (sh->plugin);
2992 sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
2993 if (NULL == sh->solver)
2995 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
2997 GNUNET_free (sh->plugin);
3008 struct TestPeer *cur;
3009 struct TestPeer *next;
3011 struct TestAddress *cur_a;
3012 struct TestAddress *next_a;
3015 GNUNET_ATS_solver_logging_stop (l);
3017 /* Stop all preference generation */
3018 GNUNET_ATS_solver_generate_preferences_stop_all ();
3020 /* Stop all property generation */
3021 GNUNET_ATS_solver_generate_property_stop_all ();
3025 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Printing log information \n");
3026 GNUNET_ATS_solver_logging_eval (l);
3030 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Saving log information \n");
3031 GNUNET_ATS_solver_logging_write_to_disk (l, e->log_append_time_stamp,
3037 GNUNET_ATS_solver_logging_free (l);
3041 /* Clean up experiment */
3044 GNUNET_ATS_solvers_experimentation_stop (e);
3049 while (NULL != (cur = next))
3052 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, cur);
3053 next_a = cur->addr_head;
3054 while (NULL != (cur_a = next_a))
3056 next_a = cur_a->next;
3057 GNUNET_CONTAINER_DLL_remove (cur->addr_head, cur->addr_tail, cur_a);
3058 GNUNET_free (cur_a);
3064 GNUNET_ATS_solvers_solver_stop (sh);
3073 experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success)
3075 if (GNUNET_OK == success)
3076 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n",
3077 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
3079 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
3081 GNUNET_SCHEDULER_add_now (&done, NULL);
3085 episode_done_cb (struct Episode *ep)
3087 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
3100 GNUNET_ATS_solvers_experimentation_stop (e);
3105 GNUNET_ATS_solvers_solver_stop (sh);
3111 run (void *cls, char * const *args, const char *cfgfile,
3112 const struct GNUNET_CONFIGURATION_Handle *cfg)
3114 enum GNUNET_ATS_Solvers solver;
3117 if (NULL == opt_exp_file)
3119 fprintf (stderr, "No experiment given ...\n");
3125 if (NULL == opt_solver)
3127 fprintf (stderr, "No solver given ...\n");
3133 if (0 == strcmp(opt_solver, "mlp"))
3135 solver = GNUNET_ATS_SOLVER_MLP;
3137 else if (0 == strcmp(opt_solver, "proportional"))
3139 solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
3141 else if (0 == strcmp(opt_solver, "ril"))
3143 solver = GNUNET_ATS_SOLVER_RIL;
3147 fprintf (stderr, "No solver given ...");
3153 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
3154 default_properties[c] = DEFAULT_REL_QUALITY;
3156 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
3157 default_preferences[c] = DEFAULT_REL_PREFERENCE;
3159 /* load experiment */
3160 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading experiment\n");
3161 e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
3164 fprintf (stderr, "Failed to load experiment ...\n");
3171 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading solver\n");
3172 sh = GNUNET_ATS_solvers_solver_start (solver);
3175 fprintf (stderr, "Failed to start solver ...\n");
3182 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Start logging \n");
3183 l = GNUNET_ATS_solver_logging_start (e->log_freq);
3185 /* run experiment */
3186 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Running experiment \n");
3187 GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb,
3188 experiment_done_cb);
3195 * Main function of the benchmark
3197 * @param argc argument count
3198 * @param argv argument values
3201 main (int argc, char *argv[])
3203 opt_exp_file = NULL;
3205 opt_log = GNUNET_NO;
3206 opt_save = GNUNET_NO;
3210 static struct GNUNET_GETOPT_CommandLineOption options[] =
3212 { 's', "solver", NULL,
3213 gettext_noop ("solver to use"),
3214 1, &GNUNET_GETOPT_set_string, &opt_solver},
3215 { 'e', "experiment", NULL,
3216 gettext_noop ("experiment to use"),
3217 1, &GNUNET_GETOPT_set_string, &opt_exp_file},
3218 { 'V', "verbose", NULL,
3219 gettext_noop ("be verbose"),
3220 0, &GNUNET_GETOPT_set_one, &opt_verbose},
3221 { 'p', "print", NULL,
3222 gettext_noop ("print logging"),
3223 0, &GNUNET_GETOPT_set_one, &opt_print},
3224 { 'f', "file", NULL,
3225 gettext_noop ("save logging to disk"),
3226 0, &GNUNET_GETOPT_set_one, &opt_save},
3228 gettext_noop ("disable normalization"),
3229 0, &GNUNET_GETOPT_set_one, &opt_disable_normalization},
3230 GNUNET_GETOPT_OPTION_END
3233 GNUNET_PROGRAM_run (argc, argv, "gnunet-ats-solver-eval",
3234 NULL, options, &run, argv[0]);
3238 /* end of file ats-testing-experiment.c*/