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));
1710 static enum GNUNET_ATS_Property
1711 parse_property_string (const char *str)
1713 enum GNUNET_ATS_Property c;
1715 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
1716 if (0 == strcmp(str,
1717 GNUNET_ATS_print_property_type (c)))
1724 load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o,
1728 const struct GNUNET_CONFIGURATION_Handle *cfg)
1735 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1736 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1737 sec_name, op_name, &o->peer_id))
1739 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1740 op_counter, "START_SET_PROPERTY", op_name);
1741 GNUNET_free (op_name);
1742 return GNUNET_SYSERR;
1744 GNUNET_free (op_name);
1747 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1748 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1749 sec_name, op_name, &o->address_id))
1751 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1752 op_counter, "START_SET_PROPERTY", op_name);
1753 GNUNET_free (op_name);
1754 return GNUNET_SYSERR;
1756 GNUNET_free (op_name);
1759 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1760 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1761 sec_name, op_name, &type)) )
1763 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1764 op_counter, "START_SET_PROPERTY", op_name);
1765 GNUNET_free (op_name);
1766 return GNUNET_SYSERR;
1769 /* Load arguments for set_rate, start_send, set_preference */
1770 if (0 == strcmp (type, "constant"))
1772 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1774 else if (0 == strcmp (type, "linear"))
1776 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1778 else if (0 == strcmp (type, "sinus"))
1780 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1782 else if (0 == strcmp (type, "random"))
1784 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1788 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1789 op_counter, op_name, e->id);
1791 GNUNET_free (op_name);
1792 return GNUNET_SYSERR;
1795 GNUNET_free (op_name);
1799 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1800 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1801 sec_name, op_name, &o->base_rate))
1803 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1804 op_counter, op_name, e->id);
1805 GNUNET_free (op_name);
1806 return GNUNET_SYSERR;
1808 GNUNET_free (op_name);
1812 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1813 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1814 sec_name, op_name, &o->max_rate))
1816 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1817 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1818 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1820 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1821 op_counter, op_name, e->id);
1822 GNUNET_free (op_name);
1823 return GNUNET_SYSERR;
1826 GNUNET_free (op_name);
1829 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1830 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1831 sec_name, op_name, &o->period))
1833 o->period = e->duration;
1835 GNUNET_free (op_name);
1838 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1839 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1840 sec_name, op_name, &o->frequency))
1842 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1843 op_counter, op_name, e->id);
1844 GNUNET_free (op_name);
1845 return GNUNET_SYSERR;
1847 GNUNET_free (op_name);
1849 /* Get preference */
1850 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1851 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1852 sec_name, op_name, &prop))
1854 fprintf (stderr, "Missing property in operation %u `%s' in episode %u\n",
1855 op_counter, op_name, e->id);
1856 GNUNET_free (op_name);
1857 GNUNET_free_non_null (prop);
1858 return GNUNET_SYSERR;
1861 if (0 == (o->prop_type = parse_property_string(prop)))
1863 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1864 op_counter, op_name, e->id);
1865 GNUNET_free (op_name);
1867 return GNUNET_SYSERR;
1871 GNUNET_free (op_name);
1873 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1874 "Found operation %s: [%llu:%llu] %s = %llu\n",
1875 "START_SET_PROPERTY", o->peer_id, o->address_id,
1876 GNUNET_ATS_print_property_type (o->prop_type), o->base_rate);
1882 load_op_stop_set_property (struct GNUNET_ATS_TEST_Operation *o,
1886 const struct GNUNET_CONFIGURATION_Handle *cfg)
1892 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1893 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1894 sec_name, op_name, &o->peer_id))
1896 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1897 op_counter, "STOP_SET_PROPERTY", op_name);
1898 GNUNET_free (op_name);
1899 return GNUNET_SYSERR;
1901 GNUNET_free (op_name);
1904 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1905 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1906 sec_name, op_name, &o->address_id))
1908 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1909 op_counter, "STOP_SET_PROPERTY", op_name);
1910 GNUNET_free (op_name);
1911 return GNUNET_SYSERR;
1913 GNUNET_free (op_name);
1916 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1917 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1918 sec_name, op_name, &pref))
1920 fprintf (stderr, "Missing property in operation %u `%s' in episode `%s'\n",
1921 op_counter, "STOP_SET_PROPERTY", op_name);
1922 GNUNET_free (op_name);
1923 GNUNET_free_non_null (pref);
1924 return GNUNET_SYSERR;
1927 if (0 == (o->prop_type = parse_property_string(pref)))
1929 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1930 op_counter, op_name, e->id);
1931 GNUNET_free (op_name);
1932 GNUNET_free_non_null (pref);
1933 return GNUNET_SYSERR;
1937 GNUNET_free (op_name);
1939 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1940 "Found operation %s: [%llu:%llu] %s\n",
1941 "STOP_SET_PROPERTY", o->peer_id, o->address_id,
1942 GNUNET_ATS_print_property_type (o->prop_type));
1949 load_op_start_request (struct GNUNET_ATS_TEST_Operation *o,
1953 const struct GNUNET_CONFIGURATION_Handle *cfg)
1958 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1959 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1960 sec_name, op_name, &o->peer_id))
1962 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1963 op_counter, "START_REQUEST", op_name);
1964 GNUNET_free (op_name);
1965 return GNUNET_SYSERR;
1967 GNUNET_free (op_name);
1972 load_op_stop_request (struct GNUNET_ATS_TEST_Operation *o,
1976 const struct GNUNET_CONFIGURATION_Handle *cfg)
1981 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1982 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1983 sec_name, op_name, &o->peer_id))
1985 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1986 op_counter, "STOP_REQUEST", op_name);
1987 GNUNET_free (op_name);
1988 return GNUNET_SYSERR;
1990 GNUNET_free (op_name);
1996 load_episode (struct Experiment *e, struct Episode *cur,
1997 struct GNUNET_CONFIGURATION_Handle *cfg)
1999 struct GNUNET_ATS_TEST_Operation *o;
2005 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Parsing episode %u\n",cur->id);
2006 GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
2010 /* Load operation */
2011 GNUNET_asprintf(&op_name, "op-%u-operation", op_counter);
2012 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
2013 sec_name, op_name, &op))
2015 GNUNET_free (op_name);
2018 o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
2019 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "==== Parsing operation %u: `%s'\n",
2022 /* operations = set_rate, start_send, stop_send, set_preference */
2023 if (0 == strcmp (op, "address_add"))
2025 o->type = SOLVER_OP_ADD_ADDRESS;
2026 res = load_op_add_address (o, cur,
2027 op_counter, sec_name, cfg);
2029 else if (0 == strcmp (op, "address_del"))
2031 o->type = SOLVER_OP_DEL_ADDRESS;
2032 res = load_op_del_address (o, cur,
2033 op_counter, sec_name, cfg);
2035 else if (0 == strcmp (op, "start_set_property"))
2037 o->type = SOLVER_OP_START_SET_PROPERTY;
2038 res = load_op_start_set_property (o, cur,
2039 op_counter, sec_name, cfg);
2041 else if (0 == strcmp (op, "stop_set_property"))
2043 o->type = SOLVER_OP_STOP_SET_PROPERTY;
2044 res = load_op_stop_set_property (o, cur,
2045 op_counter, sec_name, cfg);
2047 else if (0 == strcmp (op, "start_set_preference"))
2049 o->type = SOLVER_OP_START_SET_PREFERENCE;
2050 res = load_op_start_set_preference (o, cur,
2051 op_counter, sec_name, cfg);
2053 else if (0 == strcmp (op, "stop_set_preference"))
2055 o->type = SOLVER_OP_STOP_SET_PREFERENCE;
2056 res = load_op_stop_set_preference (o, cur,
2057 op_counter, sec_name, cfg);
2059 else if (0 == strcmp (op, "start_request"))
2061 o->type = SOLVER_OP_START_REQUEST;
2062 res = load_op_start_request (o, cur,
2063 op_counter, sec_name, cfg);
2065 else if (0 == strcmp (op, "stop_request"))
2067 o->type = SOLVER_OP_STOP_REQUEST;
2068 res = load_op_stop_request(o, cur,
2069 op_counter, sec_name, cfg);
2073 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
2074 op_counter, op, cur->id);
2075 res = GNUNET_SYSERR;
2079 GNUNET_free (op_name);
2081 if (GNUNET_SYSERR == res)
2084 GNUNET_free (sec_name);
2085 return GNUNET_SYSERR;
2088 GNUNET_CONTAINER_DLL_insert_tail (cur->head,cur->tail, o);
2091 GNUNET_free (sec_name);
2096 load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
2100 struct GNUNET_TIME_Relative e_duration;
2101 struct Episode *cur;
2102 struct Episode *last;
2108 GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
2109 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
2110 sec_name, "duration", &e_duration))
2112 GNUNET_free (sec_name);
2116 cur = GNUNET_new (struct Episode);
2117 cur->duration = e_duration;
2118 cur->id = e_counter;
2120 if (GNUNET_OK != load_episode (e, cur, cfg))
2122 GNUNET_free (sec_name);
2124 return GNUNET_SYSERR;
2127 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Found episode %u with duration %s \n",
2129 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
2131 /* Update experiment */
2133 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
2134 /* Put in linked list */
2140 GNUNET_free (sec_name);
2148 timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
2150 struct Experiment *e = cls;
2151 e->experiment_timeout_task = NULL;
2152 fprintf (stderr, "Experiment timeout!\n");
2154 if (NULL != e->episode_timeout_task)
2156 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2157 e->episode_timeout_task = NULL;
2160 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
2164 struct ATS_Address *
2165 create_ats_address (const struct GNUNET_PeerIdentity *peer,
2166 const char *plugin_name,
2167 const void *plugin_addr,
2168 size_t plugin_addr_len,
2169 uint32_t session_id,
2172 struct ATS_Address *aa = NULL;
2174 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1);
2175 aa->atsi = GNUNET_new (struct GNUNET_ATS_Information);
2176 aa->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
2177 aa->atsi[0].value = htonl (network);
2181 aa->addr_len = plugin_addr_len;
2183 aa->plugin = (char *) &aa[1] + plugin_addr_len;
2184 memcpy (&aa[1], plugin_addr, plugin_addr_len);
2185 memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
2186 aa->session_id = session_id;
2187 aa->active = GNUNET_NO;
2188 aa->used = GNUNET_NO;
2189 aa->solver_information = NULL;
2190 aa->assigned_bw_in = 0;
2191 aa->assigned_bw_out = 0;
2199 enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
2202 struct TestAddress *a;
2205 if (NULL == (p = find_peer_by_id (op->peer_id)))
2207 p = GNUNET_new (struct TestPeer);
2208 p->id = op->peer_id;
2209 p->assigned_bw_in = 0;
2210 p->assigned_bw_out = 0;
2211 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
2212 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
2214 p->pref_abs[c] = DEFAULT_ABS_PREFERENCE;
2215 p->pref_norm[c] = DEFAULT_REL_PREFERENCE;
2218 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p);
2221 if (NULL != (find_address_by_id (p, op->address_id)))
2223 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Duplicate address %u for peer %u\n",
2224 op->address_id, op->peer_id);
2228 a = GNUNET_new (struct TestAddress);
2229 a->aid = op->address_id;
2230 a->network = op->address_network;
2231 a->ats_addr = create_ats_address (&p->peer_id, op->plugin, op->address,
2232 strlen (op->address) + 1, op->address_session, op->address_network);
2233 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
2234 GNUNET_CONTAINER_DLL_insert_tail (p->addr_head, p->addr_tail, a);
2236 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
2237 a->prop_norm[c] = DEFAULT_REL_QUALITY;
2239 GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, a->ats_addr,
2240 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2242 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u in network `%s'\n",
2243 op->address_id, op->peer_id, GNUNET_ATS_print_network_type(a->network));
2245 sh->env.sf.s_add (sh->solver, a->ats_addr, op->address_network);
2251 enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
2254 struct TestAddress *a;
2255 struct PropertyGenerator *pg;
2257 if (NULL == (p = find_peer_by_id (op->peer_id)))
2260 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2261 "Deleting address for unknown peer %u\n", op->peer_id);
2265 if (NULL == (a =find_address_by_id (p, op->address_id)))
2268 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2269 "Deleting address for unknown peer %u\n", op->peer_id);
2273 while (NULL != (pg = find_prop_gen (p->id, a->aid, 0)))
2275 GNUNET_ATS_solver_generate_property_stop (pg);
2278 GNUNET_assert (GNUNET_YES ==
2279 GNUNET_CONTAINER_multipeermap_remove (sh->addresses,
2282 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2283 "Removing address %u for peer %u\n",
2287 sh->env.sf.s_del (sh->solver, a->ats_addr, GNUNET_NO);
2291 GNUNET_ATS_solver_logging_now (l);
2293 GNUNET_CONTAINER_DLL_remove(p->addr_head, p->addr_tail, a);
2295 GNUNET_free_non_null(a->ats_addr->atsi);
2296 GNUNET_free (a->ats_addr);
2302 enforce_start_property (struct GNUNET_ATS_TEST_Operation *op)
2304 struct PropertyGenerator *pg;
2306 struct TestAddress *a;
2308 if (NULL != (pg = find_prop_gen (op->peer_id, op->address_id, op->prop_type)))
2310 GNUNET_ATS_solver_generate_property_stop (pg);
2314 if (NULL == (p = find_peer_by_id (op->peer_id)))
2317 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2318 "Starting property generation for unknown peer %u\n", op->peer_id);
2322 if (NULL == (a = find_address_by_id (p, op->address_id)))
2325 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2326 "Setting property for unknown address %u\n", op->peer_id);
2330 GNUNET_ATS_solver_generate_property_start (op->peer_id,
2342 enforce_stop_property (struct GNUNET_ATS_TEST_Operation *op)
2344 struct PropertyGenerator *pg = find_prop_gen(op->peer_id, op->address_id,
2348 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2349 "Stopping preference generation for peer %u address %u\n", op->peer_id,
2351 GNUNET_ATS_solver_generate_property_stop (pg);
2355 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2356 "Cannot find preference generator for peer %u address %u\n",
2357 op->peer_id, op->address_id);
2363 enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
2365 struct PreferenceGenerator *pg;
2366 if (NULL != (pg = find_pref_gen (op->peer_id, op->pref_type)))
2368 GNUNET_ATS_solver_generate_preferences_stop (pg);
2372 if (NULL == (find_peer_by_id (op->peer_id)))
2375 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2376 "Starting preference generation for unknown peer %u\n", op->peer_id);
2380 GNUNET_ATS_solver_generate_preferences_start (op->peer_id,
2393 enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
2395 struct PreferenceGenerator *pg = find_pref_gen(op->peer_id,
2399 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2400 "Stopping property generation for peer %u address %u\n", op->peer_id,
2402 GNUNET_ATS_solver_generate_preferences_stop (pg);
2406 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2407 "Cannot find preference generator for peer %u address %u\n",
2408 op->peer_id, op->address_id);
2415 enforce_start_request (struct GNUNET_ATS_TEST_Operation *op)
2418 const struct ATS_Address *res;
2420 if (NULL == (p = find_peer_by_id (op->peer_id)))
2423 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2424 "Requesting address for unknown peer %u\n", op->peer_id);
2428 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n",
2430 p->is_requested = GNUNET_YES;
2432 res = sh->env.sf.s_get (sh->solver, &p->peer_id);
2435 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Suggested address for peer %u: %llu %llu\n",
2437 res->assigned_bw_in,
2438 res->assigned_bw_out);
2440 GNUNET_ATS_solver_logging_now (l);
2445 enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op)
2449 if (NULL == (p = find_peer_by_id (op->peer_id)))
2452 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2453 "Requesting address for unknown peer %u\n", op->peer_id);
2459 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop requesting address for peer %u\n",
2461 p->is_requested = GNUNET_NO;
2462 p->assigned_bw_in = 0;
2463 p->assigned_bw_out = 0;
2464 sh->env.sf.s_get_stop (sh->solver, &p->peer_id);
2468 GNUNET_ATS_solver_logging_now (l);
2473 static void enforce_episode (struct Episode *ep)
2475 struct GNUNET_ATS_TEST_Operation *cur;
2476 for (cur = ep->head; NULL != cur; cur = cur->next)
2478 switch (cur->type) {
2479 case SOLVER_OP_ADD_ADDRESS:
2480 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2481 print_op (cur->type), cur->peer_id, cur->address_id);
2482 enforce_add_address (cur);
2484 case SOLVER_OP_DEL_ADDRESS:
2485 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2486 print_op (cur->type), cur->peer_id, cur->address_id);
2487 enforce_del_address (cur);
2489 case SOLVER_OP_START_SET_PROPERTY:
2490 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2491 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2492 enforce_start_property (cur);
2494 case SOLVER_OP_STOP_SET_PROPERTY:
2495 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2496 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2497 enforce_stop_property (cur);
2499 case SOLVER_OP_START_SET_PREFERENCE:
2500 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2501 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2502 enforce_start_preference (cur);
2504 case SOLVER_OP_STOP_SET_PREFERENCE:
2505 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2506 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2507 enforce_stop_preference (cur);
2509 case SOLVER_OP_START_REQUEST:
2510 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2511 print_op (cur->type), cur->peer_id);
2512 enforce_start_request (cur);
2514 case SOLVER_OP_STOP_REQUEST:
2515 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2516 print_op (cur->type), cur->peer_id);
2517 enforce_stop_request (cur);
2526 timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
2528 struct Experiment *e = cls;
2529 e->episode_timeout_task = NULL;
2530 if (NULL != e->ep_done_cb)
2531 e->ep_done_cb (e->cur);
2533 /* Scheduling next */
2534 e->cur = e->cur->next;
2538 fprintf (stderr, "Last episode done!\n");
2539 if (NULL != e->experiment_timeout_task)
2541 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2542 e->experiment_timeout_task = NULL;
2544 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
2548 fprintf (stderr, "Running episode %u with timeout %s\n",
2550 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2551 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2552 &timeout_episode, e);
2553 enforce_episode(e->cur);
2560 GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
2561 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
2562 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
2564 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
2565 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
2566 e->e_done_cb = e_done_cb;
2567 e->ep_done_cb = ep_done_cb;
2568 e->start_time = GNUNET_TIME_absolute_get();
2570 /* Start total time out */
2571 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
2572 &timeout_experiment, e);
2575 if (NULL == e->start)
2582 fprintf (stderr, "Running episode %u with timeout %s\n",
2584 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2585 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2586 &timeout_episode, e);
2587 enforce_episode(e->cur);
2592 GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
2594 if (NULL != e->experiment_timeout_task)
2596 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2597 e->experiment_timeout_task = NULL;
2599 if (NULL != e->episode_timeout_task)
2601 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2602 e->episode_timeout_task = NULL;
2606 GNUNET_CONFIGURATION_destroy(e->cfg);
2609 free_experiment (e);
2614 GNUNET_ATS_solvers_experimentation_load (char *filename)
2616 struct Experiment *e;
2617 struct GNUNET_CONFIGURATION_Handle *cfg;
2620 cfg = GNUNET_CONFIGURATION_create();
2621 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
2623 fprintf (stderr, "Failed to load `%s'\n", filename);
2624 GNUNET_CONFIGURATION_destroy (cfg);
2628 e = create_experiment ();
2630 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2633 fprintf (stderr, "Invalid %s \n", "name");
2634 free_experiment (e);
2638 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment name: `%s'\n", e->name);
2640 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2641 "log_prefix", &e->log_prefix))
2643 fprintf (stderr, "Invalid %s \n", "log_prefix");
2644 free_experiment (e);
2648 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging prefix: `%s'\n",
2651 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2652 "log_output_dir", &e->log_output_dir))
2654 e->log_output_dir = NULL;
2657 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging output directory: `%s'\n",
2661 if (GNUNET_SYSERR == (e->log_append_time_stamp = GNUNET_CONFIGURATION_get_value_yesno(cfg,
2662 "experiment", "log_append_time_stamp")))
2663 e->log_append_time_stamp = GNUNET_YES;
2664 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging append timestamp: `%s'\n",
2665 (GNUNET_YES == e->log_append_time_stamp) ? "yes" : "no");
2668 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2669 "cfg_file", &e->cfg_file))
2671 fprintf (stderr, "Invalid %s \n", "cfg_file");
2672 free_experiment (e);
2677 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment configuration: `%s'\n", e->cfg_file);
2678 e->cfg = GNUNET_CONFIGURATION_create();
2679 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file))
2681 fprintf (stderr, "Invalid configuration %s \n", "cfg_file");
2682 free_experiment (e);
2688 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2689 "log_freq", &e->log_freq))
2691 fprintf (stderr, "Invalid %s \n", "log_freq");
2692 free_experiment (e);
2696 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging frequency: `%s'\n",
2697 GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
2699 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2700 "max_duration", &e->max_duration))
2702 fprintf (stderr, "Invalid %s", "max_duration");
2703 free_experiment (e);
2707 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment duration: `%s'\n",
2708 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
2710 if (GNUNET_SYSERR == load_episodes (e, cfg))
2712 GNUNET_ATS_solvers_experimentation_stop (e);
2713 GNUNET_CONFIGURATION_destroy (cfg);
2715 fprintf (stderr, "Failed to load experiment\n");
2718 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loaded %u episodes with total duration %s\n",
2720 GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
2722 GNUNET_CONFIGURATION_destroy (cfg);
2733 free_all_it (void *cls,
2734 const struct GNUNET_PeerIdentity *key,
2737 struct ATS_Address *address = value;
2738 GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (sh->env.addresses,
2740 GNUNET_free (address);
2746 GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh)
2748 GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
2750 GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
2752 GAS_normalization_stop();
2754 GNUNET_CONTAINER_multipeermap_iterate (sh->addresses, &free_all_it, NULL);
2755 GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
2756 GNUNET_free (sh->plugin);
2761 * Load quotas for networks from configuration
2763 * @param cfg configuration handle
2764 * @param out_dest where to write outbound quotas
2765 * @param in_dest where to write inbound quotas
2766 * @param dest_length length of inbound and outbound arrays
2767 * @return number of networks loaded
2770 GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
2771 unsigned long long *out_dest,
2772 unsigned long long *in_dest,
2775 char * entry_in = NULL;
2776 char * entry_out = NULL;
2777 char * quota_out_str;
2778 char * quota_in_str;
2782 for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
2786 GNUNET_asprintf (&entry_out,
2788 GNUNET_ATS_print_network_type (c));
2789 GNUNET_asprintf (&entry_in,
2791 GNUNET_ATS_print_network_type (c));
2794 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
2797 if (0 == strcmp(quota_out_str, BIG_M_STRING))
2799 out_dest[c] = GNUNET_ATS_MaxBandwidth;
2802 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
2804 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c])))
2807 if (GNUNET_NO == res)
2809 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2810 _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2811 GNUNET_ATS_print_network_type (c),
2813 GNUNET_ATS_DefaultBandwidth);
2814 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2819 "Outbound quota configure for network `%s' is %llu\n",
2820 GNUNET_ATS_print_network_type (c),
2823 GNUNET_free (quota_out_str);
2827 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2828 _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
2829 GNUNET_ATS_print_network_type (c),
2830 GNUNET_ATS_DefaultBandwidth);
2831 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2835 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str))
2838 if (0 == strcmp(quota_in_str, BIG_M_STRING))
2840 in_dest[c] = GNUNET_ATS_MaxBandwidth;
2843 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
2845 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c])))
2848 if (GNUNET_NO == res)
2850 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2851 _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2852 GNUNET_ATS_print_network_type (c),
2854 GNUNET_ATS_DefaultBandwidth);
2855 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
2859 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2860 "Inbound quota configured for network `%s' is %llu\n",
2861 GNUNET_ATS_print_network_type (c),
2864 GNUNET_free (quota_in_str);
2868 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2869 _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
2870 GNUNET_ATS_print_network_type (c),
2871 GNUNET_ATS_DefaultBandwidth);
2872 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2874 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2875 "Loaded quota for network `%s' (in/out): %llu %llu\n",
2876 GNUNET_ATS_print_network_type (c),
2879 GNUNET_free (entry_out);
2880 GNUNET_free (entry_in);
2882 return GNUNET_ATS_NetworkTypeCount;
2887 * Information callback for the solver
2889 * @param cls the closure
2890 * @param op the solver operation
2891 * @param stat status of the solver operation
2892 * @param add additional solver information
2895 solver_info_cb (void *cls,
2896 enum GAS_Solver_Operation op,
2897 enum GAS_Solver_Status stat,
2898 enum GAS_Solver_Additional_Information add)
2903 add_info = "GAS_INFO_NONE";
2906 add_info = "GAS_INFO_MLP_FULL";
2908 case GAS_INFO_UPDATED:
2909 add_info = "GAS_INFO_MLP_UPDATED";
2911 case GAS_INFO_PROP_ALL:
2912 add_info = "GAS_INFO_PROP_ALL";
2914 case GAS_INFO_PROP_SINGLE:
2915 add_info = "GAS_INFO_PROP_SINGLE";
2918 add_info = "INVALID";
2924 case GAS_OP_SOLVE_START:
2925 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2926 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
2927 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2929 case GAS_OP_SOLVE_STOP:
2930 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2931 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
2932 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2935 case GAS_OP_SOLVE_SETUP_START:
2936 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2937 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
2938 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2941 case GAS_OP_SOLVE_SETUP_STOP:
2942 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2943 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
2944 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2947 case GAS_OP_SOLVE_MLP_LP_START:
2948 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2949 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
2950 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2952 case GAS_OP_SOLVE_MLP_LP_STOP:
2953 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2954 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
2955 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2958 case GAS_OP_SOLVE_MLP_MLP_START:
2959 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2960 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
2961 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2963 case GAS_OP_SOLVE_MLP_MLP_STOP:
2964 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2965 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
2966 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2968 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
2969 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2970 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
2971 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2973 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
2974 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2975 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
2976 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2984 solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address)
2986 struct GNUNET_TIME_Relative duration;
2988 static struct PreferenceGenerator *pg;
2990 if ( (0 == address->assigned_bw_out) && (0 == address->assigned_bw_in) )
2992 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2993 "Solver notified to disconnect peer `%s'\n",
2994 GNUNET_i2s (&address->peer));
2996 p = find_peer_by_pid(&address->peer);
2999 p->assigned_bw_out = address->assigned_bw_out;
3000 p->assigned_bw_in = address->assigned_bw_in;
3002 for (pg = pref_gen_head; NULL != pg; pg = pg->next)
3004 if (pg->peer == p->id)
3006 duration = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update);
3007 delta = duration.rel_value_us * pg->last_assigned_bw_out;
3008 pg->feedback_bw_out_acc += delta;
3010 delta = duration.rel_value_us * pg->last_assigned_bw_in;
3011 pg->feedback_bw_in_acc += delta;
3013 pg->last_assigned_bw_in = address->assigned_bw_in;
3014 pg->last_assigned_bw_out = address->assigned_bw_out;
3015 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
3019 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3020 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
3021 GNUNET_i2s (&address->peer),
3023 address->assigned_bw_out,
3024 address->assigned_bw_in);
3027 GNUNET_ATS_solver_logging_now (l);
3033 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
3036 if (GNUNET_YES == opt_disable_normalization)
3038 if (NULL == (p = find_peer_by_pid (id)))
3043 return GAS_normalization_get_preferences_by_peer (id);
3048 get_property_cb (void *cls, const struct ATS_Address *address)
3051 struct TestAddress *a;
3053 if (GNUNET_YES == opt_disable_normalization)
3055 p = find_peer_by_pid (&address->peer);
3058 a = find_address_by_ats_address (p, address);
3061 return GAS_normalization_get_properties ((struct ATS_Address *) address);
3066 set_updated_property ( struct ATS_Address *address, uint32_t type, double prop_rel)
3069 struct TestAddress *a;
3071 if (NULL == (p = find_peer_by_pid (&address->peer)))
3077 if (NULL == (a = find_address_by_ats_address (p, address)))
3082 a->prop_norm[type] = prop_rel;
3083 sh->env.sf.s_address_update_property (sh->solver, address, type, a->prop_abs [type], prop_rel);
3088 normalized_property_changed_cb (void *cls, struct ATS_Address *address,
3089 uint32_t type, double prop_rel)
3092 struct PreferenceGenerator *pg;
3093 struct GNUNET_TIME_Relative duration;
3096 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3097 "Normalized property %s for peer `%s' changed to %.3f \n",
3098 GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer),
3101 if (NULL != (p = find_peer_by_pid (&address->peer)))
3103 for (pg = pref_gen_head; NULL != pg; pg = pg->next)
3105 if (pg->peer == p->id)
3107 duration = GNUNET_TIME_absolute_get_duration(pg->feedback_last_delay_update);
3108 delta = duration.rel_value_us * pg->last_delay_value;
3109 pg->feedback_delay_acc += delta;
3111 pg->last_delay_value = prop_rel;
3112 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
3118 set_updated_property (address, type, prop_rel);
3122 set_updated_preference (const struct GNUNET_PeerIdentity *peer,
3123 enum GNUNET_ATS_PreferenceKind kind,
3128 if (NULL == (p = find_peer_by_pid (peer)))
3134 p->pref_norm[kind] = pref_rel;
3135 sh->env.sf.s_pref (sh->solver, peer, kind, pref_rel);
3140 normalized_preference_changed_cb (void *cls,
3141 const struct GNUNET_PeerIdentity *peer,
3142 enum GNUNET_ATS_PreferenceKind kind,
3145 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3146 "Normalized preference %s for peer `%s' changed to %.3f \n",
3147 GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer),
3150 set_updated_preference(peer, kind, pref_rel);
3154 struct SolverHandle *
3155 GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
3157 struct SolverHandle *sh;
3162 case GNUNET_ATS_SOLVER_PROPORTIONAL:
3163 solver_str = "proportional";
3165 case GNUNET_ATS_SOLVER_MLP:
3168 case GNUNET_ATS_SOLVER_RIL:
3177 sh = GNUNET_new (struct SolverHandle);
3178 GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
3180 sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
3182 /* setup environment */
3183 sh->env.cfg = e->cfg;
3184 sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg);
3185 sh->env.addresses = sh->addresses;
3186 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
3187 sh->env.get_preferences = &get_preferences_cb;
3188 sh->env.get_property = &get_property_cb;
3189 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
3190 sh->env.info_cb = &solver_info_cb;
3191 sh->env.info_cb_cls = NULL;
3192 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
3193 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
3194 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
3195 sh->env.networks[c] = networks[c];
3198 /* start normalization */
3199 GAS_normalization_start (&normalized_preference_changed_cb, NULL,
3200 &normalized_property_changed_cb, NULL );
3203 if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg,
3204 sh->env.out_quota, sh->env.in_quota, GNUNET_ATS_NetworkTypeCount))
3207 GNUNET_free (sh->plugin);
3213 sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
3214 if (NULL == sh->solver)
3216 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
3218 GNUNET_free (sh->plugin);
3229 struct TestPeer *cur;
3230 struct TestPeer *next;
3232 struct TestAddress *cur_a;
3233 struct TestAddress *next_a;
3236 GNUNET_ATS_solver_logging_stop (l);
3238 /* Stop all preference generation */
3239 GNUNET_ATS_solver_generate_preferences_stop_all ();
3241 /* Stop all property generation */
3242 GNUNET_ATS_solver_generate_property_stop_all ();
3246 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Printing log information \n");
3247 GNUNET_ATS_solver_logging_eval (l);
3251 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Saving log information \n");
3252 GNUNET_ATS_solver_logging_write_to_disk (l, e->log_append_time_stamp,
3258 GNUNET_ATS_solver_logging_free (l);
3262 /* Clean up experiment */
3265 GNUNET_ATS_solvers_experimentation_stop (e);
3270 while (NULL != (cur = next))
3273 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, cur);
3274 next_a = cur->addr_head;
3275 while (NULL != (cur_a = next_a))
3277 next_a = cur_a->next;
3278 GNUNET_CONTAINER_DLL_remove (cur->addr_head, cur->addr_tail, cur_a);
3279 GNUNET_free (cur_a);
3285 GNUNET_ATS_solvers_solver_stop (sh);
3294 experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success)
3296 if (GNUNET_OK == success)
3297 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n",
3298 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
3300 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
3302 GNUNET_SCHEDULER_add_now (&done, NULL);
3306 episode_done_cb (struct Episode *ep)
3308 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
3321 GNUNET_ATS_solvers_experimentation_stop (e);
3326 GNUNET_ATS_solvers_solver_stop (sh);
3332 run (void *cls, char * const *args, const char *cfgfile,
3333 const struct GNUNET_CONFIGURATION_Handle *cfg)
3335 enum GNUNET_ATS_Solvers solver;
3338 if (NULL == opt_exp_file)
3340 fprintf (stderr, "No experiment given ...\n");
3346 if (NULL == opt_solver)
3348 fprintf (stderr, "No solver given ...\n");
3354 if (0 == strcmp(opt_solver, "mlp"))
3356 solver = GNUNET_ATS_SOLVER_MLP;
3358 else if (0 == strcmp(opt_solver, "proportional"))
3360 solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
3362 else if (0 == strcmp(opt_solver, "ril"))
3364 solver = GNUNET_ATS_SOLVER_RIL;
3368 fprintf (stderr, "No solver given ...");
3374 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
3375 default_properties[c] = DEFAULT_REL_QUALITY;
3377 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
3378 default_preferences[c] = DEFAULT_REL_PREFERENCE;
3380 /* load experiment */
3381 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading experiment\n");
3382 e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
3385 fprintf (stderr, "Failed to load experiment ...\n");
3392 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading solver\n");
3393 sh = GNUNET_ATS_solvers_solver_start (solver);
3396 fprintf (stderr, "Failed to start solver ...\n");
3403 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Start logging \n");
3404 l = GNUNET_ATS_solver_logging_start (e->log_freq);
3406 /* run experiment */
3407 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Running experiment \n");
3408 GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb,
3409 experiment_done_cb);
3416 * Main function of the benchmark
3418 * @param argc argument count
3419 * @param argv argument values
3422 main (int argc, char *argv[])
3424 opt_exp_file = NULL;
3426 opt_log = GNUNET_NO;
3427 opt_save = GNUNET_NO;
3431 static struct GNUNET_GETOPT_CommandLineOption options[] =
3433 { 's', "solver", NULL,
3434 gettext_noop ("solver to use"),
3435 1, &GNUNET_GETOPT_set_string, &opt_solver},
3436 { 'e', "experiment", NULL,
3437 gettext_noop ("experiment to use"),
3438 1, &GNUNET_GETOPT_set_string, &opt_exp_file},
3439 { 'V', "verbose", NULL,
3440 gettext_noop ("be verbose"),
3441 0, &GNUNET_GETOPT_set_one, &opt_verbose},
3442 { 'p', "print", NULL,
3443 gettext_noop ("print logging"),
3444 0, &GNUNET_GETOPT_set_one, &opt_print},
3445 { 'f', "file", NULL,
3446 gettext_noop ("save logging to disk"),
3447 0, &GNUNET_GETOPT_set_one, &opt_save},
3449 gettext_noop ("disable normalization"),
3450 0, &GNUNET_GETOPT_set_one, &opt_disable_normalization},
3451 GNUNET_GETOPT_OPTION_END
3454 GNUNET_PROGRAM_run (argc, argv, "gnunet-ats-solver-eval",
3455 NULL, options, &run, argv[0]);
3459 /* end of file ats-testing-experiment.c*/