2 This file is part of GNUnet.
3 (C) 2010-2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file ats-tests/ats-testing-experiment.c
22 * @brief ats benchmark: controlled experiment execution
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_util_lib.h"
28 #include "gnunet-ats-solver-eval.h"
30 #define BIG_M_STRING "unlimited"
32 static struct Experiment *e;
34 static struct LoggingHandle *l;
36 static struct SolverHandle *sh;
38 static struct TestPeer *peer_head;
39 static struct TestPeer *peer_tail;
41 static double default_properties[GNUNET_ATS_PropertyCount];
42 static double default_preferences[GNUNET_ATS_PreferenceCount];
45 * cmd option -e: experiment file
47 static char *opt_exp_file;
49 static char *opt_solver;
52 * cmd option -l: enable logging
57 * cmd option -p: enable plots
62 * cmd option -v: verbose logs
64 static int opt_verbose;
67 * cmd option -p: print logs
72 * cmd option -d: disable normalization
74 static int opt_disable_normalization;
82 get_property_cb (void *cls, const struct ATS_Address *address);
85 print_generator_type (enum GeneratorType g)
88 case GNUNET_ATS_TEST_TG_CONSTANT:
90 case GNUNET_ATS_TEST_TG_LINEAR:
92 case GNUNET_ATS_TEST_TG_RANDOM:
94 case GNUNET_ATS_TEST_TG_SINUS:
102 struct AddressLookupCtx
104 struct ATS_Address *res;
110 int find_address_it (void *cls,
111 const struct GNUNET_PeerIdentity *key,
114 struct AddressLookupCtx *ctx = cls;
115 struct ATS_Address *addr = value;
117 if ( (0 == strcmp (ctx->plugin, addr->plugin)) &&
118 (0 == strcmp (ctx->addr, addr->addr)) )
126 static struct TestPeer *
127 find_peer_by_id (int id)
129 struct TestPeer *cur;
130 for (cur = peer_head; NULL != cur; cur = cur->next)
136 static struct TestPeer *
137 find_peer_by_pid (const struct GNUNET_PeerIdentity *pid)
139 struct TestPeer *cur;
140 for (cur = peer_head; NULL != cur; cur = cur->next)
141 if (0 == memcmp (&cur->peer_id, pid, sizeof (struct GNUNET_PeerIdentity)))
146 static struct TestAddress *
147 find_address_by_id (struct TestPeer *peer, int aid)
149 struct TestAddress *cur;
150 for (cur = peer->addr_head; NULL != cur; cur = cur->next)
157 static struct TestAddress *
158 find_address_by_ats_address (struct TestPeer *p, const struct ATS_Address *addr)
160 struct TestAddress *cur;
161 for (cur = p->addr_head; NULL != cur; cur = cur->next)
162 if ((0 == strcmp(cur->ats_addr->plugin, addr->plugin)) &&
163 (cur->ats_addr->addr_len == addr->addr_len) &&
164 (0 == memcmp (cur->ats_addr->addr, addr->addr, addr->addr_len)))
175 GNUNET_ATS_solver_logging_now (struct LoggingHandle *l)
177 struct LoggingTimeStep *lts;
178 struct TestPeer *cur;
179 struct TestAddress *cur_addr;
180 struct LoggingPeer *log_p;
181 struct LoggingAddress *log_a;
184 lts = GNUNET_new (struct LoggingTimeStep);
185 GNUNET_CONTAINER_DLL_insert_tail(l->head, l->tail, lts);
186 lts->timestamp = GNUNET_TIME_absolute_get();
187 if (NULL == lts->prev)
188 lts->delta = GNUNET_TIME_UNIT_ZERO;
190 lts->delta = GNUNET_TIME_absolute_get_duration(lts->prev->timestamp);
192 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging %llu, delta %llu\n",
193 lts->timestamp.abs_value_us, lts->delta.rel_value_us);
196 /* Store logging data here */
197 for (cur = peer_head; NULL != cur; cur = cur->next)
199 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging peer id %llu\n", cur->id);
201 log_p = GNUNET_new (struct LoggingPeer);
203 log_p->peer_id = cur->peer_id;
204 log_p->is_requested = cur->is_requested;
205 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
207 log_p->pref_abs[c] = cur->pref_abs[c];
208 log_p->pref_norm[c] = cur->pref_norm[c];
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t %s = %.2f %.2f [abs/rel]\n",
210 GNUNET_ATS_print_preference_type(c),
211 log_p->pref_abs[c], log_p->pref_norm[c]);
213 GNUNET_CONTAINER_DLL_insert_tail(lts->head, lts->tail, log_p);
215 for (cur_addr = cur->addr_head; NULL != cur_addr; cur_addr = cur_addr->next)
217 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging peer id %llu address %llu \n",
218 cur->id, cur_addr->aid);
219 log_a = GNUNET_new (struct LoggingAddress);
220 log_a->aid = cur_addr->aid;
221 log_a->active = cur_addr->ats_addr->active;
222 log_a->network = cur_addr->network;
223 log_a->used = cur_addr->ats_addr->used;
224 log_a->assigned_bw_in = cur_addr->ats_addr->assigned_bw_in;
225 log_a->assigned_bw_out = cur_addr->ats_addr->assigned_bw_out;
226 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
228 log_a->prop_abs[c] = cur_addr->prop_abs[c];
229 log_a->prop_norm[c] = cur_addr->prop_norm[c];
230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t %s = %.2f %.2f [abs/rel]\n",
231 GNUNET_ATS_print_property_type(c),
232 log_a->prop_abs[c], log_a->prop_norm[c]);
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t Active = %i\n", log_a->active);
235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t BW in = %llu\n", log_a->assigned_bw_in);
236 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t BW out = %llu\n", log_a->assigned_bw_out);
238 GNUNET_CONTAINER_DLL_insert_tail (log_p->addr_head, log_p->addr_tail, log_a);
244 logging_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
246 struct LoggingHandle *l = cls;
247 l->logging_task = NULL;
249 GNUNET_ATS_solver_logging_now (l);
251 l->logging_task = GNUNET_SCHEDULER_add_delayed (l->log_freq, &logging_task, l);
255 struct LoggingHandle *
256 GNUNET_ATS_solver_logging_start (struct GNUNET_TIME_Relative freq)
258 struct LoggingHandle *l;
259 l = GNUNET_new (struct LoggingHandle);
261 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start logging every %s\n",
262 GNUNET_STRINGS_relative_time_to_string(freq, GNUNET_NO));
264 l->logging_task = GNUNET_SCHEDULER_add_now (&logging_task, l);
269 GNUNET_ATS_solver_logging_stop (struct LoggingHandle *l)
271 if (NULL != l->logging_task)
272 GNUNET_SCHEDULER_cancel (l->logging_task);
274 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop logging\n");
276 l->logging_task = NULL;
279 static struct LoggingFileHandle *
280 find_logging_file_handle (struct LoggingFileHandle *lf_head,
281 struct LoggingFileHandle *lf_tail,
282 int peer_id, int address_id)
284 struct LoggingFileHandle *res;
286 for (res = lf_head; NULL != res; res = res->next)
287 if ((res->pid == peer_id) && (res->aid == address_id))
294 GNUNET_ATS_solver_logging_write_to_disk (struct LoggingHandle *l, int add_time_stamp,
297 struct LoggingTimeStep *lts;
298 struct LoggingPeer *log_p;
299 struct LoggingAddress *log_a;
300 struct LoggingFileHandle *lf_head;
301 struct LoggingFileHandle *lf_tail;
302 struct LoggingFileHandle *cur;
303 struct LoggingFileHandle *next;
307 char * propstring_tmp;
309 char * prefstring_tmp;
314 if (NULL != output_dir)
316 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (output_dir))
318 fprintf (stderr, "Failed to create directory `%s'\n", output_dir);
323 fprintf (stderr, "Created directory `%s'\n", output_dir);
324 use_dir = GNUNET_YES;
331 for (lts = l->head; NULL != lts; lts = lts->next)
334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing log step %llu\n",
335 (long long unsigned int) lts->timestamp.abs_value_us);
337 for (log_p = lts->head; NULL != log_p; log_p = log_p->next)
339 for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next)
342 cur = find_logging_file_handle (lf_head, lf_tail, log_p->id,
346 cur = GNUNET_new (struct LoggingFileHandle);
347 cur->aid = log_a->aid;
348 cur->pid = log_p->id;
350 if (GNUNET_YES == add_time_stamp)
351 GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u_%llu.log",
352 (GNUNET_YES == use_dir) ? output_dir : "",
353 (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "",
358 l->head->timestamp.abs_value_us);
360 GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u.log",
361 (GNUNET_YES == use_dir) ? output_dir : "",
362 (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "",
368 fprintf (stderr, "Add writing log data for peer %llu address %llu to file `%s'\n",
369 cur->pid, cur->aid, filename);
372 cur->f_hd = GNUNET_DISK_file_open (filename,
373 GNUNET_DISK_OPEN_READWRITE |
374 GNUNET_DISK_OPEN_CREATE |
375 GNUNET_DISK_OPEN_TRUNCATE,
376 GNUNET_DISK_PERM_USER_READ |
377 GNUNET_DISK_PERM_USER_WRITE |
378 GNUNET_DISK_PERM_GROUP_READ |
379 GNUNET_DISK_PERM_OTHER_READ);
380 if (NULL == cur->f_hd)
382 fprintf (stderr, "Cannot open `%s' to write log data!\n", filename);
383 GNUNET_free (filename);
387 GNUNET_free (filename);
388 GNUNET_CONTAINER_DLL_insert (lf_head, lf_tail, cur);
390 GNUNET_asprintf(&datastring,"#time delta;log duration;peer_requested;addr net; addr_active; bw in; bw out; " \
391 "UTILIZATION_UP [abs/rel]; UTILIZATION_UP; UTILIZATION_DOWN; UTILIZATION_DOWN; " \
392 "UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_DOWN; UTILIZATION_PAYLOAD_DOWN;"\
394 "DISTANCE ;DISTANCE ; COST_WAN; COST_WAN; COST_LAN; COST_LAN; " \
395 "COST_WLAN; COST_WLAN;COST_BT; COST_BT; PREF BW abs; PREF BW rel; PREF LATENCY abs; PREF LATENCY rel;\n");
396 GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring));
397 GNUNET_free (datastring);
401 prefstring = GNUNET_strdup("");
402 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
405 fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n",
406 GNUNET_ATS_print_preference_type(c),
407 log_p->pref_abs[c], log_p->pref_norm[c]);
409 GNUNET_asprintf(&prefstring_tmp,"%s;%.3f;%.3f",
410 prefstring, log_p->pref_abs[c], log_p->pref_norm[c]);
413 GNUNET_free (prefstring);
414 prefstring = GNUNET_strdup(prefstring_tmp);
415 GNUNET_free (prefstring_tmp);
419 propstring = GNUNET_strdup("");
420 for (c = 1; c < GNUNET_ATS_PropertyCount; c++)
422 if (GNUNET_ATS_NETWORK_TYPE == c)
425 fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n",
426 GNUNET_ATS_print_property_type(c),
427 log_a->prop_abs[c], log_a->prop_norm[c]);*/
428 GNUNET_asprintf(&propstring_tmp,"%s%.3f;%.3f;",
429 propstring, log_a->prop_abs[c], log_a->prop_norm[c]);
430 GNUNET_free (propstring);
431 propstring = GNUNET_strdup(propstring_tmp);
432 GNUNET_free (propstring_tmp);
434 GNUNET_asprintf (&datastring, "%llu;%llu;%u;%u;%i;%u;%u;%s;%s\n",
435 GNUNET_TIME_absolute_get_difference (l->head->timestamp,
436 lts->timestamp).rel_value_us / 1000, lts->delta,
437 log_p->is_requested, log_a->network, log_a->active,
438 log_a->assigned_bw_in, log_a->assigned_bw_out, propstring,
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 log_a->assigned_bw_in,
491 log_a->assigned_bw_out);
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 (NULL != l->logging_task)
517 GNUNET_SCHEDULER_cancel (l->logging_task);
518 l->logging_task = NULL;
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;
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)))
638 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
639 "Setting property generation for unknown peer %u\n",
643 if (NULL == (a = find_address_by_id (p, pg->address_id)))
646 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
647 "Setting property generation for unknown peer %u\n",
652 prop_value = get_property (pg);
653 a->prop_abs[pg->ats_property] = prop_value;
655 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
656 "Setting property for peer [%u] address [%u] for %s to %f\n",
657 pg->peer, pg->address_id,
658 GNUNET_ATS_print_property_type (pg->ats_property), prop_value);
660 atsi.type = htonl (pg->ats_property);
661 atsi.value = htonl ((uint32_t) prop_value);
663 /* set performance here! */
664 sh->env.sf.s_bulk_start (sh->solver);
665 if (GNUNET_YES == opt_disable_normalization)
667 a->prop_abs[pg->ats_property] = prop_value;
668 a->prop_norm[pg->ats_property] = prop_value;
669 sh->env.sf.s_address_update_property (sh->solver, a->ats_addr,
670 pg->ats_property, prop_value, prop_value);
673 GAS_normalization_normalize_property (sh->addresses,
674 pg->test_address->ats_addr, &atsi, 1);
675 sh->env.sf.s_bulk_stop (sh->solver);
677 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
683 * Set ats_property to 0 to find all pgs
686 static struct PropertyGenerator *
687 find_prop_gen (unsigned int peer, unsigned int address,
688 uint32_t ats_property)
690 struct PropertyGenerator *cur;
691 for (cur = prop_gen_head; NULL != cur; cur = cur->next)
692 if ((cur->peer == peer) && (cur->address_id == address))
694 if ((cur->ats_property == ats_property) || (0 == ats_property))
701 GNUNET_ATS_solver_generate_property_stop (struct PropertyGenerator *pg)
703 GNUNET_CONTAINER_DLL_remove (prop_gen_head, prop_gen_tail, pg);
705 if (NULL != pg->set_task)
707 GNUNET_SCHEDULER_cancel (pg->set_task);
710 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
711 "Removing old up preference generator peer [%u] address [%u] `%s'\n",
712 pg->peer, pg->address_id,
713 GNUNET_ATS_print_property_type(pg->ats_property));
720 * Generate between the source master and the partner and set property with a
721 * value depending on the generator.
724 * @param address_id partner
725 * @param test_peer the peer
726 * @param test_address the address
727 * @param type type of generator
728 * @param base_value base value
729 * @param value_rate maximum value
730 * @param period duration of a period of generation (~ 1/frequency)
731 * @param frequency how long to generate property
732 * @param ats_property ATS property to generate
733 * @return the property generator
735 struct PropertyGenerator *
736 GNUNET_ATS_solver_generate_property_start (unsigned int peer,
737 unsigned int address_id,
738 struct TestPeer *test_peer,
739 struct TestAddress *test_address,
740 enum GeneratorType type,
743 struct GNUNET_TIME_Relative period,
744 struct GNUNET_TIME_Relative frequency,
745 uint32_t ats_property)
747 struct PropertyGenerator *pg;
749 pg = GNUNET_new (struct PropertyGenerator);
750 GNUNET_CONTAINER_DLL_insert (prop_gen_head, prop_gen_tail, pg);
753 pg->test_address = test_address;
754 pg->test_peer = test_peer;
755 pg->address_id = address_id;
756 pg->ats_property = ats_property;
757 pg->base_value = base_value;
758 pg->max_value = value_rate;
759 pg->duration_period = period;
760 pg->frequency = frequency;
761 pg->time_start = GNUNET_TIME_absolute_get();
764 case GNUNET_ATS_TEST_TG_CONSTANT:
765 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
766 "Setting up %s property generator peer [%u] address [%u] `%s'"\
768 print_generator_type(type), pg->peer, pg->address_id,
769 GNUNET_ATS_print_property_type (ats_property),
772 case GNUNET_ATS_TEST_TG_LINEAR:
773 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
774 "Setting up %s property generator peer [%u] address [%u] `%s' " \
775 "min %u Bips max %u Bips\n",
776 print_generator_type(type), pg->peer, pg->address_id,
777 GNUNET_ATS_print_property_type(ats_property),
778 base_value, value_rate);
780 case GNUNET_ATS_TEST_TG_SINUS:
781 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
782 "Setting up %s property generator peer [%u] address [%u] `%s' "\
783 "baserate %u Bips, amplitude %u Bps\n",
784 print_generator_type(type), pg->peer, pg->address_id,
785 GNUNET_ATS_print_property_type(ats_property),
786 base_value, value_rate);
788 case GNUNET_ATS_TEST_TG_RANDOM:
789 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
790 "Setting up %s property generator peer [%u] address [%u] `%s' "\
791 "min %u Bips max %u Bps\n",
792 print_generator_type(type), pg->peer, pg->address_id,
793 GNUNET_ATS_print_property_type(ats_property),
794 base_value, value_rate);
800 pg->set_task = GNUNET_SCHEDULER_add_now (&set_prop_task, pg);
807 * Stop all preferences generators
810 GNUNET_ATS_solver_generate_property_stop_all ()
812 struct PropertyGenerator *cur;
813 struct PropertyGenerator *next;
814 next = prop_gen_head;
815 for (cur = next; NULL != cur; cur = next)
818 GNUNET_ATS_solver_generate_property_stop (cur);
824 * Preference Generators
826 static struct PreferenceGenerator *pref_gen_head;
827 static struct PreferenceGenerator *pref_gen_tail;
831 get_preference (struct PreferenceGenerator *pg)
833 struct GNUNET_TIME_Relative time_delta;
837 /* Calculate the current preference value */
839 case GNUNET_ATS_TEST_TG_CONSTANT:
840 pref_value = pg->base_value;
842 case GNUNET_ATS_TEST_TG_LINEAR:
843 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
844 /* Calculate point of time in the current period */
845 time_delta.rel_value_us = time_delta.rel_value_us %
846 pg->duration_period.rel_value_us;
847 delta_value = ((double) time_delta.rel_value_us /
848 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
849 if ((pg->max_value < pg->base_value) &&
850 ((pg->max_value - pg->base_value) > pg->base_value))
852 /* This will cause an underflow */
855 pref_value = pg->base_value + delta_value;
857 case GNUNET_ATS_TEST_TG_RANDOM:
858 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
859 10000 * (pg->max_value - pg->base_value)) / 10000;
860 pref_value = pg->base_value + delta_value;
862 case GNUNET_ATS_TEST_TG_SINUS:
863 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
864 /* Calculate point of time in the current period */
865 time_delta.rel_value_us = time_delta.rel_value_us %
866 pg->duration_period.rel_value_us;
867 if ((pg->max_value - pg->base_value) > pg->base_value)
869 /* This will cause an underflow for second half of sinus period,
870 * will be detected in general when experiments are loaded */
873 delta_value = (pg->max_value - pg->base_value) *
874 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
875 time_delta.rel_value_us);
876 pref_value = pg->base_value + delta_value;
882 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
888 set_feedback_task (void *cls,
889 const struct GNUNET_SCHEDULER_TaskContext *tc)
891 struct PreferenceGenerator *pg = cls;
896 uint32_t delay_acc_in;
897 struct GNUNET_TIME_Relative dur;
900 pg->feedback_task = NULL;
902 if (NULL == (p = find_peer_by_id (pg->peer)))
905 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
906 "Setting feedback for unknown peer %u\n", pg->peer);
912 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
913 dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update);
914 bw_acc_in = dur.rel_value_us *pg->last_assigned_bw_in + pg->feedback_bw_in_acc;
915 pg->feedback_bw_in_acc = 0;
917 bw_acc_out = dur.rel_value_us *pg->last_assigned_bw_out + pg->feedback_bw_out_acc;
918 p_new = get_preference (pg);
919 feedback = (p_new / pg->pref_bw_old) * (bw_acc_in + bw_acc_out) /
920 (2 *GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us);
923 case GNUNET_ATS_PREFERENCE_LATENCY:
924 dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_delay_update);
925 delay_acc_in =dur.rel_value_us *pg->last_delay_value + pg->feedback_delay_acc;
926 pg->feedback_delay_acc = 0;
928 p_new = get_preference (pg);
929 feedback = (p_new / pg->pref_latency_old) * (delay_acc_in) /
930 (GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us);
938 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
939 "Giving feedback for peer [%u] for client %p pref %s of %.3f\n",
940 pg->peer, NULL + (pg->client_id),
941 GNUNET_ATS_print_preference_type (pg->kind),
944 sh->env.sf.s_feedback (sh->solver, NULL + (pg->client_id), &p->peer_id,
945 pg->feedback_frequency, pg->kind, feedback);
946 pg->feedback_last = GNUNET_TIME_absolute_get();
949 pg->feedback_bw_out_acc = 0;
950 pg->feedback_bw_in_acc = 0;
951 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
953 pg->feedback_delay_acc = 0;
954 pg->feedback_last_delay_update = GNUNET_TIME_absolute_get();
957 pg->feedback_task = GNUNET_SCHEDULER_add_delayed (pg->feedback_frequency,
958 &set_feedback_task, pg);
963 set_pref_task (void *cls,
964 const struct GNUNET_SCHEDULER_TaskContext *tc)
966 struct PreferenceGenerator *pg = cls;
971 if (NULL == (p = find_peer_by_id (pg->peer)))
974 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
975 "Setting preference for unknown peer %u\n", pg->peer);
979 pref_value = get_preference (pg);
981 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
982 pg->pref_bw_old = pref_value;
984 case GNUNET_ATS_PREFERENCE_LATENCY:
985 pg->pref_latency_old = pref_value;
991 p->pref_abs[pg->kind] = pref_value;
993 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
994 "Setting preference for peer [%u] for client %p pref %s to %f\n",
995 pg->peer, NULL + (pg->client_id),
996 GNUNET_ATS_print_preference_type (pg->kind), pref_value);
998 sh->env.sf.s_bulk_start (sh->solver);
999 if (GNUNET_YES == opt_disable_normalization)
1001 p->pref_abs[pg->kind] = pref_value;
1002 p->pref_norm[pg->kind] = pref_value;
1003 sh->env.sf.s_pref (sh->solver, &p->peer_id, pg->kind, pref_value);
1006 GAS_normalization_normalize_preference (NULL + (pg->client_id),
1007 &p->peer_id, pg->kind, pref_value);
1008 sh->env.sf.s_bulk_stop (sh->solver);
1010 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
1015 static struct PreferenceGenerator *
1016 find_pref_gen (unsigned int peer, enum GNUNET_ATS_PreferenceKind kind)
1018 struct PreferenceGenerator *cur;
1019 for (cur = pref_gen_head; NULL != cur; cur = cur->next)
1020 if (cur->peer == peer)
1022 if ((cur->kind == kind) || (GNUNET_ATS_PREFERENCE_END == kind))
1029 GNUNET_ATS_solver_generate_preferences_stop (struct PreferenceGenerator *pg)
1031 GNUNET_CONTAINER_DLL_remove (pref_gen_head, pref_gen_tail, pg);
1033 if (NULL != pg->feedback_task)
1035 GNUNET_SCHEDULER_cancel (pg->feedback_task);
1036 pg->feedback_task = NULL;
1039 if (NULL != pg->set_task)
1041 GNUNET_SCHEDULER_cancel (pg->set_task);
1042 pg->set_task = NULL;
1044 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1045 "Removing old up preference generator peer [%u] `%s'\n",
1046 pg->peer, GNUNET_ATS_print_preference_type(pg->kind));
1052 find_active_address (struct TestPeer *p)
1054 struct TestAddress *cur;
1055 for (cur = p->addr_head; NULL != cur; cur = cur->next)
1056 if (GNUNET_YES == cur->ats_addr->active)
1062 * Generate between the source master and the partner and set property with a
1063 * value depending on the generator.
1065 * @param peer source
1066 * @param address_id partner
1067 * @param client_id the client
1068 * @param type type of generator
1069 * @param base_value base value
1070 * @param value_rate maximum value
1071 * @param period duration of a period of generation (~ 1/frequency)
1072 * @param frequency how long to generate property
1073 * @param kind ATS preference to generate
1074 * @param feedback_frequency how often to give feedback
1075 * @return the preference generator
1077 struct PreferenceGenerator *
1078 GNUNET_ATS_solver_generate_preferences_start (unsigned int peer,
1079 unsigned int address_id,
1080 unsigned int client_id,
1081 enum GeneratorType type,
1082 long int base_value,
1083 long int value_rate,
1084 struct GNUNET_TIME_Relative period,
1085 struct GNUNET_TIME_Relative frequency,
1086 enum GNUNET_ATS_PreferenceKind kind,
1087 struct GNUNET_TIME_Relative feedback_frequency)
1089 struct PreferenceGenerator *pg;
1092 if (NULL == (p = find_peer_by_id (peer)))
1095 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1096 "Starting preference for unknown peer %u\n", peer);
1100 pg = GNUNET_new (struct PreferenceGenerator);
1101 GNUNET_CONTAINER_DLL_insert (pref_gen_head, pref_gen_tail, pg);
1104 pg->client_id = client_id;
1106 pg->base_value = base_value;
1107 pg->max_value = value_rate;
1108 pg->duration_period = period;
1109 pg->frequency = frequency;
1110 pg->time_start = GNUNET_TIME_absolute_get();
1111 pg->feedback_frequency = feedback_frequency;
1114 case GNUNET_ATS_TEST_TG_CONSTANT:
1115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1116 "Setting up %s preference generator peer [%u] `%s' max %u Bips\n",
1117 print_generator_type (type), pg->peer,
1118 GNUNET_ATS_print_preference_type(kind),
1121 case GNUNET_ATS_TEST_TG_LINEAR:
1122 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1123 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bips\n",
1124 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1125 base_value, value_rate);
1127 case GNUNET_ATS_TEST_TG_SINUS:
1128 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1129 "Setting up %s preference generator peer [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
1130 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1131 base_value, value_rate);
1133 case GNUNET_ATS_TEST_TG_RANDOM:
1134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1135 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bps\n",
1136 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1137 base_value, value_rate);
1143 pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, pg);
1144 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != feedback_frequency.rel_value_us)
1146 struct TestAddress * addr = find_active_address(p);
1147 const double *properties = get_property_cb (NULL, addr->ats_addr);
1149 pg->last_assigned_bw_in = p->assigned_bw_in;
1150 pg->last_assigned_bw_out = p->assigned_bw_out;
1151 pg->feedback_bw_in_acc = 0;
1152 pg->feedback_bw_out_acc = 0;
1154 pg->last_delay_value = properties[GNUNET_ATS_QUALITY_NET_DELAY];
1155 pg->feedback_delay_acc = 0;
1157 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
1158 pg->feedback_last_delay_update = GNUNET_TIME_absolute_get();
1159 pg->feedback_last = GNUNET_TIME_absolute_get();
1160 pg->feedback_task = GNUNET_SCHEDULER_add_delayed (feedback_frequency,
1161 &set_feedback_task, pg);
1170 * Stop all preferences generators
1173 GNUNET_ATS_solver_generate_preferences_stop_all ()
1175 struct PreferenceGenerator *cur;
1176 struct PreferenceGenerator *next;
1177 next = pref_gen_head;
1178 for (cur = next; NULL != cur; cur = next)
1181 GNUNET_ATS_solver_generate_preferences_stop(cur);
1192 print_op (enum OperationType op)
1195 case SOLVER_OP_ADD_ADDRESS:
1196 return "ADD_ADDRESS";
1197 case SOLVER_OP_DEL_ADDRESS:
1198 return "DEL_ADDRESS";
1199 case SOLVER_OP_START_SET_PREFERENCE:
1200 return "START_SET_PREFERENCE";
1201 case SOLVER_OP_STOP_SET_PREFERENCE:
1202 return "STOP_STOP_PREFERENCE";
1203 case SOLVER_OP_START_SET_PROPERTY:
1204 return "START_SET_PROPERTY";
1205 case SOLVER_OP_STOP_SET_PROPERTY:
1206 return "STOP_SET_PROPERTY";
1207 case SOLVER_OP_START_REQUEST:
1208 return "START_REQUEST";
1209 case SOLVER_OP_STOP_REQUEST:
1210 return "STOP_REQUEST";
1217 static struct Experiment *
1218 create_experiment ()
1220 struct Experiment *e;
1221 e = GNUNET_new (struct Experiment);
1224 e->total_duration = GNUNET_TIME_UNIT_ZERO;
1229 free_experiment (struct Experiment *e)
1231 struct Episode *cur;
1232 struct Episode *next;
1233 struct GNUNET_ATS_TEST_Operation *cur_o;
1234 struct GNUNET_ATS_TEST_Operation *next_o;
1237 for (cur = next; NULL != cur; cur = next)
1242 for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
1244 next_o = cur_o->next;
1245 GNUNET_free_non_null (cur_o->address);
1246 GNUNET_free_non_null (cur_o->plugin);
1247 GNUNET_free (cur_o);
1252 GNUNET_free_non_null (e->name);
1253 GNUNET_free_non_null (e->log_prefix);
1254 GNUNET_free_non_null (e->log_output_dir);
1255 GNUNET_free_non_null (e->cfg_file);
1261 load_op_add_address (struct GNUNET_ATS_TEST_Operation *o,
1265 const struct GNUNET_CONFIGURATION_Handle *cfg)
1271 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1272 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1273 sec_name, op_name, &o->peer_id))
1275 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1276 op_counter, "ADD_ADDRESS", op_name);
1277 GNUNET_free (op_name);
1278 return GNUNET_SYSERR;
1280 GNUNET_free (op_name);
1283 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1284 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1285 sec_name, op_name, &o->address_id))
1287 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1288 op_counter, "ADD_ADDRESS", op_name);
1289 GNUNET_free (op_name);
1290 return GNUNET_SYSERR;
1292 GNUNET_free (op_name);
1295 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
1296 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1297 sec_name, op_name, &o->plugin))
1299 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
1300 op_counter, "ADD_ADDRESS", op_name);
1301 GNUNET_free (op_name);
1302 return GNUNET_SYSERR;
1304 GNUNET_free (op_name);
1307 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
1308 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1309 sec_name, op_name, &o->address))
1311 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
1312 op_counter, "ADD_ADDRESS", op_name);
1313 GNUNET_free (op_name);
1314 return GNUNET_SYSERR;
1316 GNUNET_free (op_name);
1319 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
1320 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1321 sec_name, op_name, &o->address_session))
1323 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
1324 op_counter, "ADD_ADDRESS", op_name);
1325 GNUNET_free (op_name);
1326 return GNUNET_SYSERR;
1328 GNUNET_free (op_name);
1331 GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter);
1332 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1333 sec_name, op_name, &op_network))
1335 fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
1336 op_counter, "ADD_ADDRESS", op_name);
1337 GNUNET_free (op_name);
1338 return GNUNET_SYSERR;
1342 GNUNET_STRINGS_utf8_toupper (op_network,op_network);
1343 if (0 == strcmp(op_network, "UNSPECIFIED"))
1345 o->address_network = GNUNET_ATS_NET_UNSPECIFIED;
1347 else if (0 == strcmp(op_network, "LOOPBACK"))
1349 o->address_network = GNUNET_ATS_NET_LOOPBACK;
1351 else if (0 == strcmp(op_network, "LAN"))
1353 o->address_network = GNUNET_ATS_NET_LAN;
1355 else if (0 == strcmp(op_network, "WAN"))
1357 o->address_network = GNUNET_ATS_NET_WAN;
1359 else if (0 == strcmp(op_network, "WLAN"))
1361 o->address_network = GNUNET_ATS_NET_WLAN;
1363 else if (0 == strcmp(op_network, "BT"))
1365 o->address_network = GNUNET_ATS_NET_BT;
1369 fprintf (stderr, "Invalid address-network in operation %u `%s' in episode `%s': `%s'\n",
1370 op_counter, "ADD_ADDRESS", op_name, op_network);
1371 GNUNET_free (op_network);
1372 GNUNET_free (op_name);
1373 return GNUNET_SYSERR;
1376 GNUNET_free (op_network);
1377 GNUNET_free (op_name);
1379 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1380 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
1381 "ADD_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
1387 load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
1391 const struct GNUNET_CONFIGURATION_Handle *cfg)
1397 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1398 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1399 sec_name, op_name, &o->peer_id))
1401 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1402 op_counter, "DEL_ADDRESS", op_name);
1403 GNUNET_free (op_name);
1404 return GNUNET_SYSERR;
1406 GNUNET_free (op_name);
1409 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1410 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1411 sec_name, op_name, &o->address_id))
1413 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1414 op_counter, "DEL_ADDRESS", op_name);
1415 GNUNET_free (op_name);
1416 return GNUNET_SYSERR;
1418 GNUNET_free (op_name);
1422 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
1423 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1424 sec_name, op_name, &o->plugin))
1426 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
1427 op_counter, "DEL_ADDRESS", op_name);
1428 GNUNET_free (op_name);
1429 return GNUNET_SYSERR;
1431 GNUNET_free (op_name);
1434 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
1435 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1436 sec_name, op_name, &o->address))
1438 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
1439 op_counter, "DEL_ADDRESS", op_name);
1440 GNUNET_free (op_name);
1441 return GNUNET_SYSERR;
1443 GNUNET_free (op_name);
1446 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
1447 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1448 sec_name, op_name, &o->address_session))
1450 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
1451 op_counter, "DEL_ADDRESS", op_name);
1452 GNUNET_free (op_name);
1453 return GNUNET_SYSERR;
1455 GNUNET_free (op_name);
1458 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1459 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
1460 "DEL_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
1465 static enum GNUNET_ATS_Property
1466 parse_preference_string (const char * str)
1469 char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
1471 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
1472 if (0 == strcmp(str, props[c]))
1478 load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1482 const struct GNUNET_CONFIGURATION_Handle *cfg)
1489 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1490 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1491 sec_name, op_name, &o->peer_id))
1493 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1494 op_counter, "START_SET_PREFERENCE", op_name);
1495 GNUNET_free (op_name);
1496 return GNUNET_SYSERR;
1498 GNUNET_free (op_name);
1501 GNUNET_asprintf(&op_name, "op-%u-client-id", op_counter);
1502 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1503 sec_name, op_name, &o->client_id))
1505 fprintf (stderr, "Missing client-id in operation %u `%s' in episode `%s'\n",
1506 op_counter, "START_SET_PREFERENCE", op_name);
1507 GNUNET_free (op_name);
1508 return GNUNET_SYSERR;
1510 GNUNET_free (op_name);
1513 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1514 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1515 sec_name, op_name, &type)) )
1517 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1518 op_counter, "START_SET_PREFERENCE", op_name);
1519 GNUNET_free (op_name);
1520 return GNUNET_SYSERR;
1523 /* Load arguments for set_rate, start_send, set_preference */
1524 if (0 == strcmp (type, "constant"))
1526 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1528 else if (0 == strcmp (type, "linear"))
1530 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1532 else if (0 == strcmp (type, "sinus"))
1534 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1536 else if (0 == strcmp (type, "random"))
1538 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1542 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1543 op_counter, op_name, e->id);
1545 GNUNET_free (op_name);
1546 return GNUNET_SYSERR;
1549 GNUNET_free (op_name);
1553 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1554 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1555 sec_name, op_name, &o->base_rate))
1557 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1558 op_counter, op_name, e->id);
1559 GNUNET_free (op_name);
1560 return GNUNET_SYSERR;
1562 GNUNET_free (op_name);
1566 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1567 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1568 sec_name, op_name, &o->max_rate))
1570 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1571 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1572 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1574 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1575 op_counter, op_name, e->id);
1576 GNUNET_free (op_name);
1577 return GNUNET_SYSERR;
1580 GNUNET_free (op_name);
1583 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1584 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1585 sec_name, op_name, &o->period))
1587 o->period = e->duration;
1589 GNUNET_free (op_name);
1592 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1593 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1594 sec_name, op_name, &o->frequency))
1596 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1597 op_counter, op_name, e->id);
1598 GNUNET_free (op_name);
1599 return GNUNET_SYSERR;
1601 GNUNET_free (op_name);
1603 /* Get preference */
1604 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1605 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1606 sec_name, op_name, &pref))
1608 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
1609 op_counter, op_name, e->id);
1610 GNUNET_free (op_name);
1611 return GNUNET_SYSERR;
1614 if (0 == (o->pref_type = parse_preference_string(pref)))
1616 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1617 op_counter, op_name, e->id);
1618 GNUNET_free (op_name);
1620 return GNUNET_SYSERR;
1623 GNUNET_free (op_name);
1625 /* Get feedback delay */
1626 GNUNET_asprintf(&op_name, "op-%u-feedback_delay", op_counter);
1627 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time (cfg,
1628 sec_name, op_name, &o->feedback_delay))
1630 fprintf (stderr, "Using feedback delay %llu in operation %u `%s' in episode %u\n",
1631 (long long unsigned int) o->feedback_delay.rel_value_us,
1632 op_counter, op_name, e->id);
1635 o->feedback_delay = GNUNET_TIME_UNIT_FOREVER_REL;
1636 GNUNET_free (op_name);
1638 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1639 "Found operation %s: [%llu:%llu]: %s = %llu\n",
1640 "START_SET_PREFERENCE", o->peer_id, o->address_id,
1641 GNUNET_ATS_print_preference_type(o->pref_type), o->base_rate);
1647 load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1651 const struct GNUNET_CONFIGURATION_Handle *cfg)
1657 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1658 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1659 sec_name, op_name, &o->peer_id))
1661 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1662 op_counter, "STOP_SET_PREFERENCE", op_name);
1663 GNUNET_free (op_name);
1664 return GNUNET_SYSERR;
1666 GNUNET_free (op_name);
1669 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1670 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1671 sec_name, op_name, &o->address_id))
1673 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1674 op_counter, "STOP_SET_PREFERENCE", op_name);
1675 GNUNET_free (op_name);
1676 return GNUNET_SYSERR;
1678 GNUNET_free (op_name);
1680 /* Get preference */
1681 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1682 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1683 sec_name, op_name, &pref))
1685 fprintf (stderr, "Missing preference in operation %u `%s' in episode `%s'\n",
1686 op_counter, "STOP_SET_PREFERENCE", op_name);
1687 GNUNET_free (op_name);
1688 return GNUNET_SYSERR;
1691 if (0 == (o->pref_type = parse_preference_string(pref)))
1693 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1694 op_counter, op_name, e->id);
1695 GNUNET_free (op_name);
1697 return GNUNET_SYSERR;
1700 GNUNET_free (op_name);
1702 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1703 "Found operation %s: [%llu:%llu]: %s\n",
1704 "STOP_SET_PREFERENCE", o->peer_id, o->address_id,
1705 GNUNET_ATS_print_preference_type(o->pref_type));
1709 static enum GNUNET_ATS_Property
1710 parse_property_string (const char * str)
1713 char *props[GNUNET_ATS_PropertyCount] = GNUNET_ATS_PropertyStrings;
1715 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
1716 if (0 == strcmp(str, props[c]))
1722 load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o,
1726 const struct GNUNET_CONFIGURATION_Handle *cfg)
1733 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1734 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1735 sec_name, op_name, &o->peer_id))
1737 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1738 op_counter, "START_SET_PROPERTY", op_name);
1739 GNUNET_free (op_name);
1740 return GNUNET_SYSERR;
1742 GNUNET_free (op_name);
1745 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1746 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1747 sec_name, op_name, &o->address_id))
1749 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1750 op_counter, "START_SET_PROPERTY", op_name);
1751 GNUNET_free (op_name);
1752 return GNUNET_SYSERR;
1754 GNUNET_free (op_name);
1757 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1758 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1759 sec_name, op_name, &type)) )
1761 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1762 op_counter, "START_SET_PROPERTY", op_name);
1763 GNUNET_free (op_name);
1764 return GNUNET_SYSERR;
1767 /* Load arguments for set_rate, start_send, set_preference */
1768 if (0 == strcmp (type, "constant"))
1770 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1772 else if (0 == strcmp (type, "linear"))
1774 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1776 else if (0 == strcmp (type, "sinus"))
1778 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1780 else if (0 == strcmp (type, "random"))
1782 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1786 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1787 op_counter, op_name, e->id);
1789 GNUNET_free (op_name);
1790 return GNUNET_SYSERR;
1793 GNUNET_free (op_name);
1797 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1798 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1799 sec_name, op_name, &o->base_rate))
1801 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1802 op_counter, op_name, e->id);
1803 GNUNET_free (op_name);
1804 return GNUNET_SYSERR;
1806 GNUNET_free (op_name);
1810 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1811 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1812 sec_name, op_name, &o->max_rate))
1814 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1815 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1816 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1818 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1819 op_counter, op_name, e->id);
1820 GNUNET_free (op_name);
1821 return GNUNET_SYSERR;
1824 GNUNET_free (op_name);
1827 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1828 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1829 sec_name, op_name, &o->period))
1831 o->period = e->duration;
1833 GNUNET_free (op_name);
1836 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1837 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1838 sec_name, op_name, &o->frequency))
1840 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1841 op_counter, op_name, e->id);
1842 GNUNET_free (op_name);
1843 return GNUNET_SYSERR;
1845 GNUNET_free (op_name);
1847 /* Get preference */
1848 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1849 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1850 sec_name, op_name, &prop))
1852 fprintf (stderr, "Missing property in operation %u `%s' in episode %u\n",
1853 op_counter, op_name, e->id);
1854 GNUNET_free (op_name);
1855 GNUNET_free_non_null (prop);
1856 return GNUNET_SYSERR;
1859 if (0 == (o->prop_type = parse_property_string(prop)))
1861 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1862 op_counter, op_name, e->id);
1863 GNUNET_free (op_name);
1865 return GNUNET_SYSERR;
1869 GNUNET_free (op_name);
1871 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1872 "Found operation %s: [%llu:%llu] %s = %llu\n",
1873 "START_SET_PROPERTY", o->peer_id, o->address_id,
1874 GNUNET_ATS_print_property_type (o->prop_type), o->base_rate);
1880 load_op_stop_set_property (struct GNUNET_ATS_TEST_Operation *o,
1884 const struct GNUNET_CONFIGURATION_Handle *cfg)
1890 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1891 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1892 sec_name, op_name, &o->peer_id))
1894 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1895 op_counter, "STOP_SET_PROPERTY", op_name);
1896 GNUNET_free (op_name);
1897 return GNUNET_SYSERR;
1899 GNUNET_free (op_name);
1902 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1903 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1904 sec_name, op_name, &o->address_id))
1906 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1907 op_counter, "STOP_SET_PROPERTY", op_name);
1908 GNUNET_free (op_name);
1909 return GNUNET_SYSERR;
1911 GNUNET_free (op_name);
1914 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1915 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1916 sec_name, op_name, &pref))
1918 fprintf (stderr, "Missing property in operation %u `%s' in episode `%s'\n",
1919 op_counter, "STOP_SET_PROPERTY", op_name);
1920 GNUNET_free (op_name);
1921 GNUNET_free_non_null (pref);
1922 return GNUNET_SYSERR;
1925 if (0 == (o->prop_type = parse_property_string(pref)))
1927 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1928 op_counter, op_name, e->id);
1929 GNUNET_free (op_name);
1930 GNUNET_free_non_null (pref);
1931 return GNUNET_SYSERR;
1935 GNUNET_free (op_name);
1937 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1938 "Found operation %s: [%llu:%llu] %s\n",
1939 "STOP_SET_PROPERTY", o->peer_id, o->address_id,
1940 GNUNET_ATS_print_property_type (o->prop_type));
1947 load_op_start_request (struct GNUNET_ATS_TEST_Operation *o,
1951 const struct GNUNET_CONFIGURATION_Handle *cfg)
1956 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1957 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1958 sec_name, op_name, &o->peer_id))
1960 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1961 op_counter, "START_REQUEST", op_name);
1962 GNUNET_free (op_name);
1963 return GNUNET_SYSERR;
1965 GNUNET_free (op_name);
1970 load_op_stop_request (struct GNUNET_ATS_TEST_Operation *o,
1974 const struct GNUNET_CONFIGURATION_Handle *cfg)
1979 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1980 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1981 sec_name, op_name, &o->peer_id))
1983 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1984 op_counter, "STOP_REQUEST", op_name);
1985 GNUNET_free (op_name);
1986 return GNUNET_SYSERR;
1988 GNUNET_free (op_name);
1994 load_episode (struct Experiment *e, struct Episode *cur,
1995 struct GNUNET_CONFIGURATION_Handle *cfg)
1997 struct GNUNET_ATS_TEST_Operation *o;
2003 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Parsing episode %u\n",cur->id);
2004 GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
2008 /* Load operation */
2009 GNUNET_asprintf(&op_name, "op-%u-operation", op_counter);
2010 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
2011 sec_name, op_name, &op))
2013 GNUNET_free (op_name);
2016 o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
2017 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "==== Parsing operation %u: `%s'\n",
2020 /* operations = set_rate, start_send, stop_send, set_preference */
2021 if (0 == strcmp (op, "address_add"))
2023 o->type = SOLVER_OP_ADD_ADDRESS;
2024 res = load_op_add_address (o, cur,
2025 op_counter, sec_name, cfg);
2027 else if (0 == strcmp (op, "address_del"))
2029 o->type = SOLVER_OP_DEL_ADDRESS;
2030 res = load_op_del_address (o, cur,
2031 op_counter, sec_name, cfg);
2033 else if (0 == strcmp (op, "start_set_property"))
2035 o->type = SOLVER_OP_START_SET_PROPERTY;
2036 res = load_op_start_set_property (o, cur,
2037 op_counter, sec_name, cfg);
2039 else if (0 == strcmp (op, "stop_set_property"))
2041 o->type = SOLVER_OP_STOP_SET_PROPERTY;
2042 res = load_op_stop_set_property (o, cur,
2043 op_counter, sec_name, cfg);
2045 else if (0 == strcmp (op, "start_set_preference"))
2047 o->type = SOLVER_OP_START_SET_PREFERENCE;
2048 res = load_op_start_set_preference (o, cur,
2049 op_counter, sec_name, cfg);
2051 else if (0 == strcmp (op, "stop_set_preference"))
2053 o->type = SOLVER_OP_STOP_SET_PREFERENCE;
2054 res = load_op_stop_set_preference (o, cur,
2055 op_counter, sec_name, cfg);
2057 else if (0 == strcmp (op, "start_request"))
2059 o->type = SOLVER_OP_START_REQUEST;
2060 res = load_op_start_request (o, cur,
2061 op_counter, sec_name, cfg);
2063 else if (0 == strcmp (op, "stop_request"))
2065 o->type = SOLVER_OP_STOP_REQUEST;
2066 res = load_op_stop_request(o, cur,
2067 op_counter, sec_name, cfg);
2071 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
2072 op_counter, op, cur->id);
2073 res = GNUNET_SYSERR;
2077 GNUNET_free (op_name);
2079 if (GNUNET_SYSERR == res)
2082 GNUNET_free (sec_name);
2083 return GNUNET_SYSERR;
2086 GNUNET_CONTAINER_DLL_insert_tail (cur->head,cur->tail, o);
2089 GNUNET_free (sec_name);
2094 load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
2098 struct GNUNET_TIME_Relative e_duration;
2099 struct Episode *cur;
2100 struct Episode *last;
2106 GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
2107 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
2108 sec_name, "duration", &e_duration))
2110 GNUNET_free (sec_name);
2114 cur = GNUNET_new (struct Episode);
2115 cur->duration = e_duration;
2116 cur->id = e_counter;
2118 if (GNUNET_OK != load_episode (e, cur, cfg))
2120 GNUNET_free (sec_name);
2122 return GNUNET_SYSERR;
2125 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Found episode %u with duration %s \n",
2127 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
2129 /* Update experiment */
2131 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
2132 /* Put in linked list */
2138 GNUNET_free (sec_name);
2146 timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
2148 struct Experiment *e = cls;
2149 e->experiment_timeout_task = NULL;
2150 fprintf (stderr, "Experiment timeout!\n");
2152 if (NULL != e->episode_timeout_task)
2154 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2155 e->episode_timeout_task = NULL;
2158 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
2162 struct ATS_Address *
2163 create_ats_address (const struct GNUNET_PeerIdentity *peer,
2164 const char *plugin_name,
2165 const void *plugin_addr,
2166 size_t plugin_addr_len,
2167 uint32_t session_id,
2170 struct ATS_Address *aa = NULL;
2172 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1);
2173 aa->atsi = GNUNET_new (struct GNUNET_ATS_Information);
2174 aa->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
2175 aa->atsi[0].value = htonl (network);
2179 aa->addr_len = plugin_addr_len;
2181 aa->plugin = (char *) &aa[1] + plugin_addr_len;
2182 memcpy (&aa[1], plugin_addr, plugin_addr_len);
2183 memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
2184 aa->session_id = session_id;
2185 aa->active = GNUNET_NO;
2186 aa->used = GNUNET_NO;
2187 aa->solver_information = NULL;
2188 aa->assigned_bw_in = 0;
2189 aa->assigned_bw_out = 0;
2197 enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
2200 struct TestAddress *a;
2203 if (NULL == (p = find_peer_by_id (op->peer_id)))
2205 p = GNUNET_new (struct TestPeer);
2206 p->id = op->peer_id;
2207 p->assigned_bw_in = 0;
2208 p->assigned_bw_out = 0;
2209 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
2210 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
2212 p->pref_abs[c] = DEFAULT_ABS_PREFERENCE;
2213 p->pref_norm[c] = DEFAULT_REL_PREFERENCE;
2216 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p);
2219 if (NULL != (find_address_by_id (p, op->address_id)))
2221 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Duplicate address %u for peer %u\n",
2222 op->address_id, op->peer_id);
2226 a = GNUNET_new (struct TestAddress);
2227 a->aid = op->address_id;
2228 a->network = op->address_network;
2229 a->ats_addr = create_ats_address (&p->peer_id, op->plugin, op->address,
2230 strlen (op->address) + 1, op->address_session, op->address_network);
2231 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
2232 GNUNET_CONTAINER_DLL_insert_tail (p->addr_head, p->addr_tail, a);
2234 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
2235 a->prop_norm[c] = DEFAULT_REL_QUALITY;
2237 GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, a->ats_addr,
2238 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2240 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u in network `%s'\n",
2241 op->address_id, op->peer_id, GNUNET_ATS_print_network_type(a->network));
2243 sh->env.sf.s_add (sh->solver, a->ats_addr, op->address_network);
2249 enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
2252 struct TestAddress *a;
2253 struct PropertyGenerator *pg;
2255 if (NULL == (p = find_peer_by_id (op->peer_id)))
2258 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2259 "Deleting address for unknown peer %u\n", op->peer_id);
2263 if (NULL == (a =find_address_by_id (p, op->address_id)))
2266 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2267 "Deleting address for unknown peer %u\n", op->peer_id);
2271 while (NULL != (pg = find_prop_gen (p->id, a->aid, 0)))
2273 GNUNET_ATS_solver_generate_property_stop (pg);
2276 GNUNET_assert (GNUNET_YES ==
2277 GNUNET_CONTAINER_multipeermap_remove (sh->addresses,
2280 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2281 "Removing address %u for peer %u\n",
2285 sh->env.sf.s_del (sh->solver, a->ats_addr, GNUNET_NO);
2289 GNUNET_ATS_solver_logging_now (l);
2291 GNUNET_CONTAINER_DLL_remove(p->addr_head, p->addr_tail, a);
2293 GNUNET_free_non_null(a->ats_addr->atsi);
2294 GNUNET_free (a->ats_addr);
2300 enforce_start_property (struct GNUNET_ATS_TEST_Operation *op)
2302 struct PropertyGenerator *pg;
2304 struct TestAddress *a;
2306 if (NULL != (pg = find_prop_gen (op->peer_id, op->address_id, op->prop_type)))
2308 GNUNET_ATS_solver_generate_property_stop (pg);
2312 if (NULL == (p = find_peer_by_id (op->peer_id)))
2315 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2316 "Starting property generation for unknown peer %u\n", op->peer_id);
2320 if (NULL == (a = find_address_by_id (p, op->address_id)))
2323 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2324 "Setting property for unknown address %u\n", op->peer_id);
2328 GNUNET_ATS_solver_generate_property_start (op->peer_id,
2340 enforce_stop_property (struct GNUNET_ATS_TEST_Operation *op)
2342 struct PropertyGenerator *pg = find_prop_gen(op->peer_id, op->address_id,
2346 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2347 "Stopping preference generation for peer %u address %u\n", op->peer_id,
2349 GNUNET_ATS_solver_generate_property_stop (pg);
2353 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2354 "Cannot find preference generator for peer %u address %u\n",
2355 op->peer_id, op->address_id);
2361 enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
2363 struct PreferenceGenerator *pg;
2364 if (NULL != (pg = find_pref_gen (op->peer_id, op->pref_type)))
2366 GNUNET_ATS_solver_generate_preferences_stop (pg);
2370 if (NULL == (find_peer_by_id (op->peer_id)))
2373 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2374 "Starting preference generation for unknown peer %u\n", op->peer_id);
2378 GNUNET_ATS_solver_generate_preferences_start (op->peer_id,
2391 enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
2393 struct PreferenceGenerator *pg = find_pref_gen(op->peer_id,
2397 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2398 "Stopping property generation for peer %u address %u\n", op->peer_id,
2400 GNUNET_ATS_solver_generate_preferences_stop (pg);
2404 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2405 "Cannot find preference generator for peer %u address %u\n",
2406 op->peer_id, op->address_id);
2413 enforce_start_request (struct GNUNET_ATS_TEST_Operation *op)
2416 const struct ATS_Address *res;
2418 if (NULL == (p = find_peer_by_id (op->peer_id)))
2421 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2422 "Requesting address for unknown peer %u\n", op->peer_id);
2426 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n",
2428 p->is_requested = GNUNET_YES;
2430 res = sh->env.sf.s_get (sh->solver, &p->peer_id);
2433 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Suggested address for peer %u: %llu %llu\n",
2435 res->assigned_bw_in,
2436 res->assigned_bw_out);
2438 GNUNET_ATS_solver_logging_now (l);
2443 enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op)
2447 if (NULL == (p = find_peer_by_id (op->peer_id)))
2450 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2451 "Requesting address for unknown peer %u\n", op->peer_id);
2457 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop requesting address for peer %u\n",
2459 p->is_requested = GNUNET_NO;
2460 p->assigned_bw_in = 0;
2461 p->assigned_bw_out = 0;
2462 sh->env.sf.s_get_stop (sh->solver, &p->peer_id);
2466 GNUNET_ATS_solver_logging_now (l);
2471 static void enforce_episode (struct Episode *ep)
2473 struct GNUNET_ATS_TEST_Operation *cur;
2474 for (cur = ep->head; NULL != cur; cur = cur->next)
2476 switch (cur->type) {
2477 case SOLVER_OP_ADD_ADDRESS:
2478 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2479 print_op (cur->type), cur->peer_id, cur->address_id);
2480 enforce_add_address (cur);
2482 case SOLVER_OP_DEL_ADDRESS:
2483 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2484 print_op (cur->type), cur->peer_id, cur->address_id);
2485 enforce_del_address (cur);
2487 case SOLVER_OP_START_SET_PROPERTY:
2488 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2489 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2490 enforce_start_property (cur);
2492 case SOLVER_OP_STOP_SET_PROPERTY:
2493 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2494 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2495 enforce_stop_property (cur);
2497 case SOLVER_OP_START_SET_PREFERENCE:
2498 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2499 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2500 enforce_start_preference (cur);
2502 case SOLVER_OP_STOP_SET_PREFERENCE:
2503 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2504 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2505 enforce_stop_preference (cur);
2507 case SOLVER_OP_START_REQUEST:
2508 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2509 print_op (cur->type), cur->peer_id);
2510 enforce_start_request (cur);
2512 case SOLVER_OP_STOP_REQUEST:
2513 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2514 print_op (cur->type), cur->peer_id);
2515 enforce_stop_request (cur);
2524 timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
2526 struct Experiment *e = cls;
2527 e->episode_timeout_task = NULL;
2528 if (NULL != e->ep_done_cb)
2529 e->ep_done_cb (e->cur);
2531 /* Scheduling next */
2532 e->cur = e->cur->next;
2536 fprintf (stderr, "Last episode done!\n");
2537 if (NULL != e->experiment_timeout_task)
2539 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2540 e->experiment_timeout_task = NULL;
2542 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
2546 fprintf (stderr, "Running episode %u with timeout %s\n",
2548 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2549 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2550 &timeout_episode, e);
2551 enforce_episode(e->cur);
2558 GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
2559 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
2560 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
2562 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
2563 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
2564 e->e_done_cb = e_done_cb;
2565 e->ep_done_cb = ep_done_cb;
2566 e->start_time = GNUNET_TIME_absolute_get();
2568 /* Start total time out */
2569 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
2570 &timeout_experiment, e);
2573 if (NULL == e->start)
2580 fprintf (stderr, "Running episode %u with timeout %s\n",
2582 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2583 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2584 &timeout_episode, e);
2585 enforce_episode(e->cur);
2590 GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
2592 if (NULL != e->experiment_timeout_task)
2594 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2595 e->experiment_timeout_task = NULL;
2597 if (NULL != e->episode_timeout_task)
2599 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2600 e->episode_timeout_task = NULL;
2604 GNUNET_CONFIGURATION_destroy(e->cfg);
2607 free_experiment (e);
2612 GNUNET_ATS_solvers_experimentation_load (char *filename)
2614 struct Experiment *e;
2615 struct GNUNET_CONFIGURATION_Handle *cfg;
2618 cfg = GNUNET_CONFIGURATION_create();
2619 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
2621 fprintf (stderr, "Failed to load `%s'\n", filename);
2622 GNUNET_CONFIGURATION_destroy (cfg);
2626 e = create_experiment ();
2628 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2631 fprintf (stderr, "Invalid %s \n", "name");
2632 free_experiment (e);
2636 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment name: `%s'\n", e->name);
2638 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2639 "log_prefix", &e->log_prefix))
2641 fprintf (stderr, "Invalid %s \n", "log_prefix");
2642 free_experiment (e);
2646 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging prefix: `%s'\n",
2649 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2650 "log_output_dir", &e->log_output_dir))
2652 e->log_output_dir = NULL;
2655 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging output directory: `%s'\n",
2659 if (GNUNET_SYSERR == (e->log_append_time_stamp = GNUNET_CONFIGURATION_get_value_yesno(cfg,
2660 "experiment", "log_append_time_stamp")))
2661 e->log_append_time_stamp = GNUNET_YES;
2662 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging append timestamp: `%s'\n",
2663 (GNUNET_YES == e->log_append_time_stamp) ? "yes" : "no");
2666 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2667 "cfg_file", &e->cfg_file))
2669 fprintf (stderr, "Invalid %s \n", "cfg_file");
2670 free_experiment (e);
2675 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment configuration: `%s'\n", e->cfg_file);
2676 e->cfg = GNUNET_CONFIGURATION_create();
2677 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file))
2679 fprintf (stderr, "Invalid configuration %s \n", "cfg_file");
2680 free_experiment (e);
2686 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2687 "log_freq", &e->log_freq))
2689 fprintf (stderr, "Invalid %s \n", "log_freq");
2690 free_experiment (e);
2694 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging frequency: `%s'\n",
2695 GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
2697 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2698 "max_duration", &e->max_duration))
2700 fprintf (stderr, "Invalid %s", "max_duration");
2701 free_experiment (e);
2705 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment duration: `%s'\n",
2706 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
2708 if (GNUNET_SYSERR == load_episodes (e, cfg))
2710 GNUNET_ATS_solvers_experimentation_stop (e);
2711 GNUNET_CONFIGURATION_destroy (cfg);
2713 fprintf (stderr, "Failed to load experiment\n");
2716 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loaded %u episodes with total duration %s\n",
2718 GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
2720 GNUNET_CONFIGURATION_destroy (cfg);
2731 free_all_it (void *cls,
2732 const struct GNUNET_PeerIdentity *key,
2735 struct ATS_Address *address = value;
2736 GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (sh->env.addresses,
2738 GNUNET_free (address);
2744 GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh)
2746 GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
2748 GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
2750 GAS_normalization_stop();
2752 GNUNET_CONTAINER_multipeermap_iterate (sh->addresses, &free_all_it, NULL);
2753 GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
2754 GNUNET_free (sh->plugin);
2759 * Load quotas for networks from configuration
2761 * @param cfg configuration handle
2762 * @param out_dest where to write outbound quotas
2763 * @param in_dest where to write inbound quotas
2764 * @param dest_length length of inbound and outbound arrays
2765 * @return number of networks loaded
2768 GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
2769 unsigned long long *out_dest,
2770 unsigned long long *in_dest,
2773 char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
2774 char * entry_in = NULL;
2775 char * entry_out = NULL;
2776 char * quota_out_str;
2777 char * quota_in_str;
2781 for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
2785 GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]);
2786 GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]);
2789 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
2792 if (0 == strcmp(quota_out_str, BIG_M_STRING))
2794 out_dest[c] = GNUNET_ATS_MaxBandwidth;
2797 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
2799 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c])))
2802 if (GNUNET_NO == res)
2804 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2805 network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth);
2806 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2810 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Outbound quota configure for network `%s' is %llu\n"),
2811 network_str[c], out_dest[c]);
2813 GNUNET_free (quota_out_str);
2817 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
2818 network_str[c], GNUNET_ATS_DefaultBandwidth);
2819 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2823 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str))
2826 if (0 == strcmp(quota_in_str, BIG_M_STRING))
2828 in_dest[c] = GNUNET_ATS_MaxBandwidth;
2831 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
2833 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c])))
2836 if (GNUNET_NO == res)
2838 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2839 network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth);
2840 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
2844 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Inbound quota configured for network `%s' is %llu\n"),
2845 network_str[c], in_dest[c]);
2847 GNUNET_free (quota_in_str);
2851 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
2852 network_str[c], GNUNET_ATS_DefaultBandwidth);
2853 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2855 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]);
2856 GNUNET_free (entry_out);
2857 GNUNET_free (entry_in);
2859 return GNUNET_ATS_NetworkTypeCount;
2863 * Information callback for the solver
2865 * @param cls the closure
2866 * @param op the solver operation
2867 * @param stat status of the solver operation
2868 * @param add additional solver information
2871 solver_info_cb (void *cls,
2872 enum GAS_Solver_Operation op,
2873 enum GAS_Solver_Status stat,
2874 enum GAS_Solver_Additional_Information add)
2879 add_info = "GAS_INFO_NONE";
2882 add_info = "GAS_INFO_MLP_FULL";
2884 case GAS_INFO_UPDATED:
2885 add_info = "GAS_INFO_MLP_UPDATED";
2887 case GAS_INFO_PROP_ALL:
2888 add_info = "GAS_INFO_PROP_ALL";
2890 case GAS_INFO_PROP_SINGLE:
2891 add_info = "GAS_INFO_PROP_SINGLE";
2894 add_info = "INVALID";
2900 case GAS_OP_SOLVE_START:
2901 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2902 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
2903 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2905 case GAS_OP_SOLVE_STOP:
2906 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2907 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
2908 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2911 case GAS_OP_SOLVE_SETUP_START:
2912 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2913 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
2914 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2917 case GAS_OP_SOLVE_SETUP_STOP:
2918 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2919 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
2920 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2923 case GAS_OP_SOLVE_MLP_LP_START:
2924 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2925 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
2926 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2928 case GAS_OP_SOLVE_MLP_LP_STOP:
2929 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2930 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
2931 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2934 case GAS_OP_SOLVE_MLP_MLP_START:
2935 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2936 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
2937 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2939 case GAS_OP_SOLVE_MLP_MLP_STOP:
2940 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2941 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
2942 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2944 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
2945 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2946 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
2947 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2949 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
2950 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2951 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
2952 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2960 solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address)
2962 struct GNUNET_TIME_Relative duration;
2964 static struct PreferenceGenerator *pg;
2966 if ( (0 == address->assigned_bw_out) && (0 == address->assigned_bw_in) )
2968 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2969 "Solver notified to disconnect peer `%s'\n",
2970 GNUNET_i2s (&address->peer));
2972 p = find_peer_by_pid(&address->peer);
2975 p->assigned_bw_out = address->assigned_bw_out;
2976 p->assigned_bw_in = address->assigned_bw_in;
2978 for (pg = pref_gen_head; NULL != pg; pg = pg->next)
2980 if (pg->peer == p->id)
2982 duration = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update);
2983 delta = duration.rel_value_us * pg->last_assigned_bw_out;
2984 pg->feedback_bw_out_acc += delta;
2986 delta = duration.rel_value_us * pg->last_assigned_bw_in;
2987 pg->feedback_bw_in_acc += delta;
2989 pg->last_assigned_bw_in = address->assigned_bw_in;
2990 pg->last_assigned_bw_out = address->assigned_bw_out;
2991 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
2995 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2996 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
2997 GNUNET_i2s (&address->peer),
2999 address->assigned_bw_out,
3000 address->assigned_bw_in);
3003 GNUNET_ATS_solver_logging_now (l);
3009 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
3012 if (GNUNET_YES == opt_disable_normalization)
3014 if (NULL == (p = find_peer_by_pid (id)))
3019 return GAS_normalization_get_preferences_by_peer (id);
3024 get_property_cb (void *cls, const struct ATS_Address *address)
3027 struct TestAddress *a;
3029 if (GNUNET_YES == opt_disable_normalization)
3031 p = find_peer_by_pid (&address->peer);
3034 a = find_address_by_ats_address (p, address);
3037 return GAS_normalization_get_properties ((struct ATS_Address *) address);
3042 set_updated_property ( struct ATS_Address *address, uint32_t type, double prop_rel)
3045 struct TestAddress *a;
3047 if (NULL == (p = find_peer_by_pid (&address->peer)))
3053 if (NULL == (a = find_address_by_ats_address (p, address)))
3058 a->prop_norm[type] = prop_rel;
3059 sh->env.sf.s_address_update_property (sh->solver, address, type, a->prop_abs [type], prop_rel);
3064 normalized_property_changed_cb (void *cls, struct ATS_Address *address,
3065 uint32_t type, double prop_rel)
3068 struct PreferenceGenerator *pg;
3069 struct GNUNET_TIME_Relative duration;
3072 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3073 "Normalized property %s for peer `%s' changed to %.3f \n",
3074 GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer),
3077 if (NULL != (p = find_peer_by_pid (&address->peer)))
3079 for (pg = pref_gen_head; NULL != pg; pg = pg->next)
3081 if (pg->peer == p->id)
3083 duration = GNUNET_TIME_absolute_get_duration(pg->feedback_last_delay_update);
3084 delta = duration.rel_value_us * pg->last_delay_value;
3085 pg->feedback_delay_acc += delta;
3087 pg->last_delay_value = prop_rel;
3088 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
3094 set_updated_property (address, type, prop_rel);
3098 set_updated_preference (const struct GNUNET_PeerIdentity *peer,
3099 enum GNUNET_ATS_PreferenceKind kind,
3104 if (NULL == (p = find_peer_by_pid (peer)))
3110 p->pref_norm[kind] = pref_rel;
3111 sh->env.sf.s_pref (sh->solver, peer, kind, pref_rel);
3116 normalized_preference_changed_cb (void *cls,
3117 const struct GNUNET_PeerIdentity *peer,
3118 enum GNUNET_ATS_PreferenceKind kind,
3121 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3122 "Normalized preference %s for peer `%s' changed to %.3f \n",
3123 GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer),
3126 set_updated_preference(peer, kind, pref_rel);
3130 struct SolverHandle *
3131 GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
3133 struct SolverHandle *sh;
3138 case GNUNET_ATS_SOLVER_PROPORTIONAL:
3139 solver_str = "proportional";
3141 case GNUNET_ATS_SOLVER_MLP:
3144 case GNUNET_ATS_SOLVER_RIL:
3153 sh = GNUNET_new (struct SolverHandle);
3154 GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
3156 sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
3158 /* setup environment */
3159 sh->env.cfg = e->cfg;
3160 sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg);
3161 sh->env.addresses = sh->addresses;
3162 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
3163 sh->env.get_preferences = &get_preferences_cb;
3164 sh->env.get_property = &get_property_cb;
3165 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
3166 sh->env.info_cb = &solver_info_cb;
3167 sh->env.info_cb_cls = NULL;
3168 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
3169 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
3170 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
3171 sh->env.networks[c] = networks[c];
3174 /* start normalization */
3175 GAS_normalization_start (&normalized_preference_changed_cb, NULL,
3176 &normalized_property_changed_cb, NULL );
3179 if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg,
3180 sh->env.out_quota, sh->env.in_quota, GNUNET_ATS_NetworkTypeCount))
3183 GNUNET_free (sh->plugin);
3189 sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
3190 if (NULL == sh->solver)
3192 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
3194 GNUNET_free (sh->plugin);
3205 struct TestPeer *cur;
3206 struct TestPeer *next;
3208 struct TestAddress *cur_a;
3209 struct TestAddress *next_a;
3212 GNUNET_ATS_solver_logging_stop (l);
3214 /* Stop all preference generation */
3215 GNUNET_ATS_solver_generate_preferences_stop_all ();
3217 /* Stop all property generation */
3218 GNUNET_ATS_solver_generate_property_stop_all ();
3222 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Printing log information \n");
3223 GNUNET_ATS_solver_logging_eval (l);
3227 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Saving log information \n");
3228 GNUNET_ATS_solver_logging_write_to_disk (l, e->log_append_time_stamp,
3234 GNUNET_ATS_solver_logging_free (l);
3238 /* Clean up experiment */
3241 GNUNET_ATS_solvers_experimentation_stop (e);
3246 while (NULL != (cur = next))
3249 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, cur);
3250 next_a = cur->addr_head;
3251 while (NULL != (cur_a = next_a))
3253 next_a = cur_a->next;
3254 GNUNET_CONTAINER_DLL_remove (cur->addr_head, cur->addr_tail, cur_a);
3255 GNUNET_free (cur_a);
3261 GNUNET_ATS_solvers_solver_stop (sh);
3270 experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success)
3272 if (GNUNET_OK == success)
3273 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n",
3274 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
3276 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
3278 GNUNET_SCHEDULER_add_now (&done, NULL);
3282 episode_done_cb (struct Episode *ep)
3284 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
3297 GNUNET_ATS_solvers_experimentation_stop (e);
3302 GNUNET_ATS_solvers_solver_stop (sh);
3308 run (void *cls, char * const *args, const char *cfgfile,
3309 const struct GNUNET_CONFIGURATION_Handle *cfg)
3311 enum GNUNET_ATS_Solvers solver;
3314 if (NULL == opt_exp_file)
3316 fprintf (stderr, "No experiment given ...\n");
3322 if (NULL == opt_solver)
3324 fprintf (stderr, "No solver given ...\n");
3330 if (0 == strcmp(opt_solver, "mlp"))
3332 solver = GNUNET_ATS_SOLVER_MLP;
3334 else if (0 == strcmp(opt_solver, "proportional"))
3336 solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
3338 else if (0 == strcmp(opt_solver, "ril"))
3340 solver = GNUNET_ATS_SOLVER_RIL;
3344 fprintf (stderr, "No solver given ...");
3350 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
3351 default_properties[c] = DEFAULT_REL_QUALITY;
3353 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
3354 default_preferences[c] = DEFAULT_REL_PREFERENCE;
3356 /* load experiment */
3357 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading experiment\n");
3358 e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
3361 fprintf (stderr, "Failed to load experiment ...\n");
3368 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading solver\n");
3369 sh = GNUNET_ATS_solvers_solver_start (solver);
3372 fprintf (stderr, "Failed to start solver ...\n");
3379 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Start logging \n");
3380 l = GNUNET_ATS_solver_logging_start (e->log_freq);
3382 /* run experiment */
3383 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Running experiment \n");
3384 GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb,
3385 experiment_done_cb);
3392 * Main function of the benchmark
3394 * @param argc argument count
3395 * @param argv argument values
3398 main (int argc, char *argv[])
3400 opt_exp_file = NULL;
3402 opt_log = GNUNET_NO;
3403 opt_save = GNUNET_NO;
3407 static struct GNUNET_GETOPT_CommandLineOption options[] =
3409 { 's', "solver", NULL,
3410 gettext_noop ("solver to use"),
3411 1, &GNUNET_GETOPT_set_string, &opt_solver},
3412 { 'e', "experiment", NULL,
3413 gettext_noop ("experiment to use"),
3414 1, &GNUNET_GETOPT_set_string, &opt_exp_file},
3415 { 'V', "verbose", NULL,
3416 gettext_noop ("be verbose"),
3417 0, &GNUNET_GETOPT_set_one, &opt_verbose},
3418 { 'p', "print", NULL,
3419 gettext_noop ("print logging"),
3420 0, &GNUNET_GETOPT_set_one, &opt_print},
3421 { 'f', "file", NULL,
3422 gettext_noop ("save logging to disk"),
3423 0, &GNUNET_GETOPT_set_one, &opt_save},
3425 gettext_noop ("disable normalization"),
3426 0, &GNUNET_GETOPT_set_one, &opt_disable_normalization},
3427 GNUNET_GETOPT_OPTION_END
3430 GNUNET_PROGRAM_run (argc, argv, "gnunet-ats-solver-eval",
3431 NULL, options, &run, argv[0]);
3435 /* end of file ats-testing-experiment.c*/