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"
29 #include "gnunet-service-ats_normalization.h"
30 #include "gnunet-service-ats_preferences.h"
32 #define BIG_M_STRING "unlimited"
35 * Handle for statistics.
37 struct GNUNET_STATISTICS_Handle *GSA_stats;
40 static struct Experiment *e;
42 static struct LoggingHandle *l;
44 static struct SolverHandle *sh;
46 static struct TestPeer *peer_head;
48 static struct TestPeer *peer_tail;
50 static double default_properties[GNUNET_ATS_PropertyCount];
51 static double default_preferences[GNUNET_ATS_PreferenceCount];
54 * cmd option -e: experiment file
56 static char *opt_exp_file;
58 static char *opt_solver;
61 * cmd option -l: enable logging
66 * cmd option -p: enable plots
71 * cmd option -v: verbose logs
73 static int opt_verbose;
76 * cmd option -p: print logs
81 * cmd option -d: disable normalization
83 static int opt_disable_normalization;
91 get_property_cb (void *cls, const struct ATS_Address *address);
94 print_generator_type (enum GeneratorType g)
97 case GNUNET_ATS_TEST_TG_CONSTANT:
99 case GNUNET_ATS_TEST_TG_LINEAR:
101 case GNUNET_ATS_TEST_TG_RANDOM:
103 case GNUNET_ATS_TEST_TG_SINUS:
111 struct AddressLookupCtx
113 struct ATS_Address *res;
119 int find_address_it (void *cls,
120 const struct GNUNET_PeerIdentity *key,
123 struct AddressLookupCtx *ctx = cls;
124 struct ATS_Address *addr = value;
126 if ( (0 == strcmp (ctx->plugin, addr->plugin)) &&
127 (0 == strcmp (ctx->addr, addr->addr)) )
135 static struct TestPeer *
136 find_peer_by_id (int id)
138 struct TestPeer *cur;
139 for (cur = peer_head; NULL != cur; cur = cur->next)
145 static struct TestPeer *
146 find_peer_by_pid (const struct GNUNET_PeerIdentity *pid)
148 struct TestPeer *cur;
149 for (cur = peer_head; NULL != cur; cur = cur->next)
150 if (0 == memcmp (&cur->peer_id, pid, sizeof (struct GNUNET_PeerIdentity)))
155 static struct TestAddress *
156 find_address_by_id (struct TestPeer *peer, int aid)
158 struct TestAddress *cur;
159 for (cur = peer->addr_head; NULL != cur; cur = cur->next)
166 static struct TestAddress *
167 find_address_by_ats_address (struct TestPeer *p, const struct ATS_Address *addr)
169 struct TestAddress *cur;
170 for (cur = p->addr_head; NULL != cur; cur = cur->next)
171 if ((0 == strcmp(cur->ats_addr->plugin, addr->plugin)) &&
172 (cur->ats_addr->addr_len == addr->addr_len) &&
173 (0 == memcmp (cur->ats_addr->addr, addr->addr, addr->addr_len)))
184 GNUNET_ATS_solver_logging_now (struct LoggingHandle *l)
186 struct LoggingTimeStep *lts;
187 struct TestPeer *cur;
188 struct TestAddress *cur_addr;
189 struct LoggingPeer *log_p;
190 struct LoggingAddress *log_a;
193 lts = GNUNET_new (struct LoggingTimeStep);
194 GNUNET_CONTAINER_DLL_insert_tail(l->head, l->tail, lts);
195 lts->timestamp = GNUNET_TIME_absolute_get();
196 if (NULL == lts->prev)
197 lts->delta = GNUNET_TIME_UNIT_ZERO;
199 lts->delta = GNUNET_TIME_absolute_get_duration(lts->prev->timestamp);
201 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging %llu, delta %llu\n",
202 lts->timestamp.abs_value_us, lts->delta.rel_value_us);
205 /* Store logging data here */
206 for (cur = peer_head; NULL != cur; cur = cur->next)
208 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging peer id %llu\n", cur->id);
210 log_p = GNUNET_new (struct LoggingPeer);
212 log_p->peer_id = cur->peer_id;
213 log_p->is_requested = cur->is_requested;
214 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
216 log_p->pref_abs[c] = cur->pref_abs[c];
217 log_p->pref_norm[c] = cur->pref_norm[c];
218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t %s = %.2f %.2f [abs/rel]\n",
219 GNUNET_ATS_print_preference_type(c),
220 log_p->pref_abs[c], log_p->pref_norm[c]);
222 GNUNET_CONTAINER_DLL_insert_tail(lts->head, lts->tail, log_p);
224 for (cur_addr = cur->addr_head; NULL != cur_addr; cur_addr = cur_addr->next)
226 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging peer id %llu address %llu \n",
227 cur->id, cur_addr->aid);
228 log_a = GNUNET_new (struct LoggingAddress);
229 log_a->aid = cur_addr->aid;
230 log_a->active = cur_addr->ats_addr->active;
231 log_a->network = cur_addr->network;
232 log_a->used = cur_addr->ats_addr->used;
233 log_a->assigned_bw_in = cur_addr->ats_addr->assigned_bw_in;
234 log_a->assigned_bw_out = cur_addr->ats_addr->assigned_bw_out;
235 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
237 log_a->prop_abs[c] = cur_addr->prop_abs[c];
238 log_a->prop_norm[c] = cur_addr->prop_norm[c];
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t %s = %.2f %.2f [abs/rel]\n",
240 GNUNET_ATS_print_property_type(c),
241 log_a->prop_abs[c], log_a->prop_norm[c]);
243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t Active = %i\n", log_a->active);
244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t BW in = %llu\n", log_a->assigned_bw_in);
245 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t BW out = %llu\n", log_a->assigned_bw_out);
247 GNUNET_CONTAINER_DLL_insert_tail (log_p->addr_head, log_p->addr_tail, log_a);
253 logging_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
255 struct LoggingHandle *l = cls;
256 l->logging_task = NULL;
258 GNUNET_ATS_solver_logging_now (l);
260 l->logging_task = GNUNET_SCHEDULER_add_delayed (l->log_freq, &logging_task, l);
264 struct LoggingHandle *
265 GNUNET_ATS_solver_logging_start (struct GNUNET_TIME_Relative freq)
267 struct LoggingHandle *l;
268 l = GNUNET_new (struct LoggingHandle);
270 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start logging every %s\n",
271 GNUNET_STRINGS_relative_time_to_string(freq, GNUNET_NO));
273 l->logging_task = GNUNET_SCHEDULER_add_now (&logging_task, l);
278 GNUNET_ATS_solver_logging_stop (struct LoggingHandle *l)
280 if (NULL != l->logging_task)
281 GNUNET_SCHEDULER_cancel (l->logging_task);
283 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop logging\n");
285 l->logging_task = NULL;
288 static struct LoggingFileHandle *
289 find_logging_file_handle (struct LoggingFileHandle *lf_head,
290 struct LoggingFileHandle *lf_tail,
291 int peer_id, int address_id)
293 struct LoggingFileHandle *res;
295 for (res = lf_head; NULL != res; res = res->next)
296 if ((res->pid == peer_id) && (res->aid == address_id))
303 GNUNET_ATS_solver_logging_write_to_disk (struct LoggingHandle *l, int add_time_stamp,
306 struct LoggingTimeStep *lts;
307 struct LoggingPeer *log_p;
308 struct LoggingAddress *log_a;
309 struct LoggingFileHandle *lf_head;
310 struct LoggingFileHandle *lf_tail;
311 struct LoggingFileHandle *cur;
312 struct LoggingFileHandle *next;
316 char * propstring_tmp;
318 char * prefstring_tmp;
323 if (NULL != output_dir)
325 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (output_dir))
327 fprintf (stderr, "Failed to create directory `%s'\n", output_dir);
332 fprintf (stderr, "Created directory `%s'\n", output_dir);
333 use_dir = GNUNET_YES;
340 for (lts = l->head; NULL != lts; lts = lts->next)
343 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing log step %llu\n",
344 (long long unsigned int) lts->timestamp.abs_value_us);
346 for (log_p = lts->head; NULL != log_p; log_p = log_p->next)
348 for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next)
351 cur = find_logging_file_handle (lf_head, lf_tail, log_p->id,
355 cur = GNUNET_new (struct LoggingFileHandle);
356 cur->aid = log_a->aid;
357 cur->pid = log_p->id;
359 if (GNUNET_YES == add_time_stamp)
360 GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u_%llu.log",
361 (GNUNET_YES == use_dir) ? output_dir : "",
362 (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "",
367 l->head->timestamp.abs_value_us);
369 GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u.log",
370 (GNUNET_YES == use_dir) ? output_dir : "",
371 (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "",
377 fprintf (stderr, "Add writing log data for peer %llu address %llu to file `%s'\n",
378 cur->pid, cur->aid, filename);
381 cur->f_hd = GNUNET_DISK_file_open (filename,
382 GNUNET_DISK_OPEN_READWRITE |
383 GNUNET_DISK_OPEN_CREATE |
384 GNUNET_DISK_OPEN_TRUNCATE,
385 GNUNET_DISK_PERM_USER_READ |
386 GNUNET_DISK_PERM_USER_WRITE |
387 GNUNET_DISK_PERM_GROUP_READ |
388 GNUNET_DISK_PERM_OTHER_READ);
389 if (NULL == cur->f_hd)
391 fprintf (stderr, "Cannot open `%s' to write log data!\n", filename);
392 GNUNET_free (filename);
396 GNUNET_free (filename);
397 GNUNET_CONTAINER_DLL_insert (lf_head, lf_tail, cur);
399 GNUNET_asprintf(&datastring,"#time delta;log duration;peer_requested;addr net; addr_active; bw in; bw out; " \
400 "UTILIZATION_UP [abs/rel]; UTILIZATION_UP; UTILIZATION_DOWN; UTILIZATION_DOWN; " \
401 "UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_DOWN; UTILIZATION_PAYLOAD_DOWN;"\
403 "DISTANCE ;DISTANCE ; COST_WAN; COST_WAN; COST_LAN; COST_LAN; " \
404 "COST_WLAN; COST_WLAN;COST_BT; COST_BT; PREF BW abs; PREF BW rel; PREF LATENCY abs; PREF LATENCY rel;\n");
405 GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring));
406 GNUNET_free (datastring);
410 prefstring = GNUNET_strdup("");
411 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
414 fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n",
415 GNUNET_ATS_print_preference_type(c),
416 log_p->pref_abs[c], log_p->pref_norm[c]);
418 GNUNET_asprintf(&prefstring_tmp,"%s;%.3f;%.3f",
419 prefstring, log_p->pref_abs[c], log_p->pref_norm[c]);
422 GNUNET_free (prefstring);
423 prefstring = GNUNET_strdup(prefstring_tmp);
424 GNUNET_free (prefstring_tmp);
428 propstring = GNUNET_strdup("");
429 for (c = 1; c < GNUNET_ATS_PropertyCount; c++)
431 if (GNUNET_ATS_NETWORK_TYPE == c)
434 fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n",
435 GNUNET_ATS_print_property_type(c),
436 log_a->prop_abs[c], log_a->prop_norm[c]);*/
437 GNUNET_asprintf(&propstring_tmp,"%s%.3f;%.3f;",
438 propstring, log_a->prop_abs[c], log_a->prop_norm[c]);
439 GNUNET_free (propstring);
440 propstring = GNUNET_strdup(propstring_tmp);
441 GNUNET_free (propstring_tmp);
443 GNUNET_asprintf (&datastring, "%llu;%llu;%u;%u;%i;%u;%u;%s;%s\n",
444 GNUNET_TIME_absolute_get_difference (l->head->timestamp,
445 lts->timestamp).rel_value_us / 1000, lts->delta,
446 log_p->is_requested, log_a->network, log_a->active,
447 log_a->assigned_bw_in, log_a->assigned_bw_out, propstring,
450 GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring));
451 GNUNET_free (datastring);
452 GNUNET_free (prefstring);
453 GNUNET_free (propstring);
460 for (cur = next; NULL != cur; cur = next)
463 GNUNET_CONTAINER_DLL_remove (lf_head, lf_tail, cur);
464 if (NULL != cur->f_hd)
465 GNUNET_DISK_file_close (cur->f_hd);
472 GNUNET_ATS_solver_logging_eval (struct LoggingHandle *l)
474 struct LoggingTimeStep *lts;
475 struct LoggingPeer *log_p;
476 struct LoggingAddress *log_a;
479 for (lts = l->head; NULL != lts; lts = lts->next)
481 fprintf (stderr, "Log step %llu %llu: \n",
482 (long long unsigned int) lts->timestamp.abs_value_us,
483 (long long unsigned int) lts->delta.rel_value_us);
485 for (log_p = lts->head; NULL != log_p; log_p = log_p->next)
487 fprintf (stderr,"\tLogging peer pid %llu\n", log_p->id);
488 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
490 fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n",
491 GNUNET_ATS_print_preference_type(c),
492 log_p->pref_abs[c], log_p->pref_norm[c]);
495 for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next)
497 fprintf (stderr, "\tPeer pid %llu address %llu: %u %u %u\n",
498 log_p->id, log_a->aid, log_a->active,
499 log_a->assigned_bw_in,
500 log_a->assigned_bw_out);
502 for (c = 1; c < GNUNET_ATS_PropertyCount; c++)
504 if (GNUNET_ATS_NETWORK_TYPE == c)
506 fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n",
507 GNUNET_ATS_print_property_type(c),
508 log_a->prop_abs[c], log_a->prop_norm[c]);
516 GNUNET_ATS_solver_logging_free (struct LoggingHandle *l)
518 struct LoggingTimeStep *lts_cur;
519 struct LoggingTimeStep *lts_next;
520 struct LoggingPeer *log_p_cur;
521 struct LoggingPeer *log_p_next;
522 struct LoggingAddress *log_a_cur;
523 struct LoggingAddress *log_a_next;
525 if (NULL != l->logging_task)
526 GNUNET_SCHEDULER_cancel (l->logging_task);
527 l->logging_task = NULL;
530 while (NULL != (lts_cur = lts_next))
532 lts_next = lts_cur->next;
534 log_p_next = lts_cur->head;
535 while (NULL != (log_p_cur = log_p_next))
537 log_p_next = log_p_cur->next;
539 log_a_next = log_p_cur->addr_head;
540 while (NULL != (log_a_cur = log_a_next))
542 log_a_next = log_a_cur->next;
544 GNUNET_CONTAINER_DLL_remove (log_p_cur->addr_head, log_p_cur->addr_tail, log_a_cur);
545 GNUNET_free (log_a_cur);
548 GNUNET_CONTAINER_DLL_remove (lts_cur->head, lts_cur->tail, log_p_cur);
549 GNUNET_free (log_p_cur);
552 GNUNET_CONTAINER_DLL_remove (l->head, l->tail, lts_cur);
553 GNUNET_free (lts_cur);
560 * Property Generators
563 static struct PropertyGenerator *prop_gen_head;
564 static struct PropertyGenerator *prop_gen_tail;
567 get_property (struct PropertyGenerator *pg)
569 struct GNUNET_TIME_Relative time_delta;
573 /* Calculate the current preference value */
575 case GNUNET_ATS_TEST_TG_CONSTANT:
576 pref_value = pg->base_value;
578 case GNUNET_ATS_TEST_TG_LINEAR:
579 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
580 /* Calculate point of time in the current period */
581 time_delta.rel_value_us = time_delta.rel_value_us %
582 pg->duration_period.rel_value_us;
583 delta_value = ((double) time_delta.rel_value_us /
584 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
585 if ((pg->max_value < pg->base_value) &&
586 ((pg->max_value - pg->base_value) > pg->base_value))
588 /* This will cause an underflow */
591 pref_value = pg->base_value + delta_value;
593 case GNUNET_ATS_TEST_TG_RANDOM:
594 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
595 10000 * (pg->max_value - pg->base_value)) / 10000;
596 pref_value = pg->base_value + delta_value;
598 case GNUNET_ATS_TEST_TG_SINUS:
599 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
600 /* Calculate point of time in the current period */
601 time_delta.rel_value_us = time_delta.rel_value_us %
602 pg->duration_period.rel_value_us;
603 if ((pg->max_value - pg->base_value) > pg->base_value)
605 /* This will cause an underflow for second half of sinus period,
606 * will be detected in general when experiments are loaded */
609 delta_value = (pg->max_value - pg->base_value) *
610 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
611 time_delta.rel_value_us);
612 pref_value = pg->base_value + delta_value;
618 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current property value is %f\n",
625 set_prop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
627 struct PropertyGenerator *pg = cls;
629 struct TestAddress *a;
631 struct GNUNET_ATS_Information atsi;
635 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains_value (sh->addresses,
636 &pg->test_peer->peer_id, pg->test_address->ats_addr))
639 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
640 "Setting property generation for unknown address [%u:%u]\n",
641 pg->peer, pg->address_id);
644 if (NULL == (p = find_peer_by_id (pg->peer)))
647 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
648 "Setting property generation for unknown peer %u\n",
652 if (NULL == (a = find_address_by_id (p, pg->address_id)))
655 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
656 "Setting property generation for unknown peer %u\n",
661 prop_value = get_property (pg);
662 a->prop_abs[pg->ats_property] = prop_value;
664 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
665 "Setting property for peer [%u] address [%u] for %s to %f\n",
666 pg->peer, pg->address_id,
667 GNUNET_ATS_print_property_type (pg->ats_property), prop_value);
669 atsi.type = htonl (pg->ats_property);
670 atsi.value = htonl ((uint32_t) prop_value);
672 /* set performance here! */
673 sh->env.sf.s_bulk_start (sh->solver);
674 if (GNUNET_YES == opt_disable_normalization)
676 a->prop_abs[pg->ats_property] = prop_value;
677 a->prop_norm[pg->ats_property] = prop_value;
678 sh->env.sf.s_address_update_property (sh->solver, a->ats_addr,
679 pg->ats_property, prop_value, prop_value);
682 GAS_normalization_normalize_property (pg->test_address->ats_addr, &atsi, 1);
683 sh->env.sf.s_bulk_stop (sh->solver);
685 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
691 * Set ats_property to 0 to find all pgs
694 static struct PropertyGenerator *
695 find_prop_gen (unsigned int peer, unsigned int address,
696 uint32_t ats_property)
698 struct PropertyGenerator *cur;
699 for (cur = prop_gen_head; NULL != cur; cur = cur->next)
700 if ((cur->peer == peer) && (cur->address_id == address))
702 if ((cur->ats_property == ats_property) || (0 == ats_property))
709 GNUNET_ATS_solver_generate_property_stop (struct PropertyGenerator *pg)
711 GNUNET_CONTAINER_DLL_remove (prop_gen_head, prop_gen_tail, pg);
713 if (NULL != pg->set_task)
715 GNUNET_SCHEDULER_cancel (pg->set_task);
718 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
719 "Removing old up preference generator peer [%u] address [%u] `%s'\n",
720 pg->peer, pg->address_id,
721 GNUNET_ATS_print_property_type(pg->ats_property));
728 * Generate between the source master and the partner and set property with a
729 * value depending on the generator.
732 * @param address_id partner
733 * @param test_peer the peer
734 * @param test_address the address
735 * @param type type of generator
736 * @param base_value base value
737 * @param value_rate maximum value
738 * @param period duration of a period of generation (~ 1/frequency)
739 * @param frequency how long to generate property
740 * @param ats_property ATS property to generate
741 * @return the property generator
743 struct PropertyGenerator *
744 GNUNET_ATS_solver_generate_property_start (unsigned int peer,
745 unsigned int address_id,
746 struct TestPeer *test_peer,
747 struct TestAddress *test_address,
748 enum GeneratorType type,
751 struct GNUNET_TIME_Relative period,
752 struct GNUNET_TIME_Relative frequency,
753 uint32_t ats_property)
755 struct PropertyGenerator *pg;
757 pg = GNUNET_new (struct PropertyGenerator);
758 GNUNET_CONTAINER_DLL_insert (prop_gen_head, prop_gen_tail, pg);
761 pg->test_address = test_address;
762 pg->test_peer = test_peer;
763 pg->address_id = address_id;
764 pg->ats_property = ats_property;
765 pg->base_value = base_value;
766 pg->max_value = value_rate;
767 pg->duration_period = period;
768 pg->frequency = frequency;
769 pg->time_start = GNUNET_TIME_absolute_get();
772 case GNUNET_ATS_TEST_TG_CONSTANT:
773 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
774 "Setting up %s property generator peer [%u] address [%u] `%s'"\
776 print_generator_type(type), pg->peer, pg->address_id,
777 GNUNET_ATS_print_property_type (ats_property),
780 case GNUNET_ATS_TEST_TG_LINEAR:
781 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
782 "Setting up %s property generator peer [%u] address [%u] `%s' " \
783 "min %u Bips max %u Bips\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_SINUS:
789 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
790 "Setting up %s property generator peer [%u] address [%u] `%s' "\
791 "baserate %u Bips, amplitude %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);
796 case GNUNET_ATS_TEST_TG_RANDOM:
797 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
798 "Setting up %s property generator peer [%u] address [%u] `%s' "\
799 "min %u Bips max %u Bps\n",
800 print_generator_type(type), pg->peer, pg->address_id,
801 GNUNET_ATS_print_property_type(ats_property),
802 base_value, value_rate);
808 pg->set_task = GNUNET_SCHEDULER_add_now (&set_prop_task, pg);
815 * Stop all preferences generators
818 GNUNET_ATS_solver_generate_property_stop_all ()
820 struct PropertyGenerator *cur;
821 struct PropertyGenerator *next;
822 next = prop_gen_head;
823 for (cur = next; NULL != cur; cur = next)
826 GNUNET_ATS_solver_generate_property_stop (cur);
832 * Preference Generators
834 static struct PreferenceGenerator *pref_gen_head;
835 static struct PreferenceGenerator *pref_gen_tail;
839 get_preference (struct PreferenceGenerator *pg)
841 struct GNUNET_TIME_Relative time_delta;
845 /* Calculate the current preference value */
847 case GNUNET_ATS_TEST_TG_CONSTANT:
848 pref_value = pg->base_value;
850 case GNUNET_ATS_TEST_TG_LINEAR:
851 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
852 /* Calculate point of time in the current period */
853 time_delta.rel_value_us = time_delta.rel_value_us %
854 pg->duration_period.rel_value_us;
855 delta_value = ((double) time_delta.rel_value_us /
856 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
857 if ((pg->max_value < pg->base_value) &&
858 ((pg->max_value - pg->base_value) > pg->base_value))
860 /* This will cause an underflow */
863 pref_value = pg->base_value + delta_value;
865 case GNUNET_ATS_TEST_TG_RANDOM:
866 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
867 10000 * (pg->max_value - pg->base_value)) / 10000;
868 pref_value = pg->base_value + delta_value;
870 case GNUNET_ATS_TEST_TG_SINUS:
871 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
872 /* Calculate point of time in the current period */
873 time_delta.rel_value_us = time_delta.rel_value_us %
874 pg->duration_period.rel_value_us;
875 if ((pg->max_value - pg->base_value) > pg->base_value)
877 /* This will cause an underflow for second half of sinus period,
878 * will be detected in general when experiments are loaded */
881 delta_value = (pg->max_value - pg->base_value) *
882 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
883 time_delta.rel_value_us);
884 pref_value = pg->base_value + delta_value;
890 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
896 set_feedback_task (void *cls,
897 const struct GNUNET_SCHEDULER_TaskContext *tc)
899 struct PreferenceGenerator *pg = cls;
904 uint32_t delay_acc_in;
905 struct GNUNET_TIME_Relative dur;
908 pg->feedback_task = NULL;
910 if (NULL == (p = find_peer_by_id (pg->peer)))
913 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
914 "Setting feedback for unknown peer %u\n", pg->peer);
920 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
921 dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update);
922 bw_acc_in = dur.rel_value_us *pg->last_assigned_bw_in + pg->feedback_bw_in_acc;
923 pg->feedback_bw_in_acc = 0;
925 bw_acc_out = dur.rel_value_us *pg->last_assigned_bw_out + pg->feedback_bw_out_acc;
926 p_new = get_preference (pg);
927 feedback = (p_new / pg->pref_bw_old) * (bw_acc_in + bw_acc_out) /
928 (2 *GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us);
931 case GNUNET_ATS_PREFERENCE_LATENCY:
932 dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_delay_update);
933 delay_acc_in =dur.rel_value_us *pg->last_delay_value + pg->feedback_delay_acc;
934 pg->feedback_delay_acc = 0;
936 p_new = get_preference (pg);
937 feedback = (p_new / pg->pref_latency_old) * (delay_acc_in) /
938 (GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us);
946 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
947 "Giving feedback for peer [%u] for client %p pref %s of %.3f\n",
948 pg->peer, NULL + (pg->client_id),
949 GNUNET_ATS_print_preference_type (pg->kind),
952 sh->env.sf.s_feedback (sh->solver, NULL + (pg->client_id), &p->peer_id,
953 pg->feedback_frequency, pg->kind, feedback);
954 pg->feedback_last = GNUNET_TIME_absolute_get();
957 pg->feedback_bw_out_acc = 0;
958 pg->feedback_bw_in_acc = 0;
959 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
961 pg->feedback_delay_acc = 0;
962 pg->feedback_last_delay_update = GNUNET_TIME_absolute_get();
965 pg->feedback_task = GNUNET_SCHEDULER_add_delayed (pg->feedback_frequency,
966 &set_feedback_task, pg);
971 set_pref_task (void *cls,
972 const struct GNUNET_SCHEDULER_TaskContext *tc)
974 struct PreferenceGenerator *pg = cls;
979 if (NULL == (p = find_peer_by_id (pg->peer)))
982 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
983 "Setting preference for unknown peer %u\n", pg->peer);
987 pref_value = get_preference (pg);
989 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
990 pg->pref_bw_old = pref_value;
992 case GNUNET_ATS_PREFERENCE_LATENCY:
993 pg->pref_latency_old = pref_value;
999 p->pref_abs[pg->kind] = pref_value;
1001 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1002 "Setting preference for peer [%u] for client %p pref %s to %f\n",
1003 pg->peer, NULL + (pg->client_id),
1004 GNUNET_ATS_print_preference_type (pg->kind), pref_value);
1006 sh->env.sf.s_bulk_start (sh->solver);
1007 if (GNUNET_YES == opt_disable_normalization)
1009 p->pref_abs[pg->kind] = pref_value;
1010 p->pref_norm[pg->kind] = pref_value;
1011 sh->env.sf.s_pref (sh->solver, &p->peer_id, pg->kind, pref_value);
1014 GAS_normalization_normalize_preference (NULL + (pg->client_id),
1015 &p->peer_id, pg->kind, pref_value);
1016 sh->env.sf.s_bulk_stop (sh->solver);
1018 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
1023 static struct PreferenceGenerator *
1024 find_pref_gen (unsigned int peer, enum GNUNET_ATS_PreferenceKind kind)
1026 struct PreferenceGenerator *cur;
1027 for (cur = pref_gen_head; NULL != cur; cur = cur->next)
1028 if (cur->peer == peer)
1030 if ((cur->kind == kind) || (GNUNET_ATS_PREFERENCE_END == kind))
1037 GNUNET_ATS_solver_generate_preferences_stop (struct PreferenceGenerator *pg)
1039 GNUNET_CONTAINER_DLL_remove (pref_gen_head, pref_gen_tail, pg);
1041 if (NULL != pg->feedback_task)
1043 GNUNET_SCHEDULER_cancel (pg->feedback_task);
1044 pg->feedback_task = NULL;
1047 if (NULL != pg->set_task)
1049 GNUNET_SCHEDULER_cancel (pg->set_task);
1050 pg->set_task = NULL;
1052 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1053 "Removing old up preference generator peer [%u] `%s'\n",
1054 pg->peer, GNUNET_ATS_print_preference_type(pg->kind));
1060 find_active_address (struct TestPeer *p)
1062 struct TestAddress *cur;
1063 for (cur = p->addr_head; NULL != cur; cur = cur->next)
1064 if (GNUNET_YES == cur->ats_addr->active)
1070 * Generate between the source master and the partner and set property with a
1071 * value depending on the generator.
1073 * @param peer source
1074 * @param address_id partner
1075 * @param client_id the client
1076 * @param type type of generator
1077 * @param base_value base value
1078 * @param value_rate maximum value
1079 * @param period duration of a period of generation (~ 1/frequency)
1080 * @param frequency how long to generate property
1081 * @param kind ATS preference to generate
1082 * @param feedback_frequency how often to give feedback
1083 * @return the preference generator
1085 struct PreferenceGenerator *
1086 GNUNET_ATS_solver_generate_preferences_start (unsigned int peer,
1087 unsigned int address_id,
1088 unsigned int client_id,
1089 enum GeneratorType type,
1090 long int base_value,
1091 long int value_rate,
1092 struct GNUNET_TIME_Relative period,
1093 struct GNUNET_TIME_Relative frequency,
1094 enum GNUNET_ATS_PreferenceKind kind,
1095 struct GNUNET_TIME_Relative feedback_frequency)
1097 struct PreferenceGenerator *pg;
1100 if (NULL == (p = find_peer_by_id (peer)))
1103 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1104 "Starting preference for unknown peer %u\n", peer);
1108 pg = GNUNET_new (struct PreferenceGenerator);
1109 GNUNET_CONTAINER_DLL_insert (pref_gen_head, pref_gen_tail, pg);
1112 pg->client_id = client_id;
1114 pg->base_value = base_value;
1115 pg->max_value = value_rate;
1116 pg->duration_period = period;
1117 pg->frequency = frequency;
1118 pg->time_start = GNUNET_TIME_absolute_get();
1119 pg->feedback_frequency = feedback_frequency;
1122 case GNUNET_ATS_TEST_TG_CONSTANT:
1123 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1124 "Setting up %s preference generator peer [%u] `%s' max %u Bips\n",
1125 print_generator_type (type), pg->peer,
1126 GNUNET_ATS_print_preference_type(kind),
1129 case GNUNET_ATS_TEST_TG_LINEAR:
1130 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1131 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bips\n",
1132 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1133 base_value, value_rate);
1135 case GNUNET_ATS_TEST_TG_SINUS:
1136 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1137 "Setting up %s preference generator peer [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
1138 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1139 base_value, value_rate);
1141 case GNUNET_ATS_TEST_TG_RANDOM:
1142 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1143 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bps\n",
1144 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1145 base_value, value_rate);
1151 pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, pg);
1152 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != feedback_frequency.rel_value_us)
1154 struct TestAddress * addr = find_active_address(p);
1155 const double *properties = get_property_cb (NULL, addr->ats_addr);
1157 pg->last_assigned_bw_in = p->assigned_bw_in;
1158 pg->last_assigned_bw_out = p->assigned_bw_out;
1159 pg->feedback_bw_in_acc = 0;
1160 pg->feedback_bw_out_acc = 0;
1162 pg->last_delay_value = properties[GNUNET_ATS_QUALITY_NET_DELAY];
1163 pg->feedback_delay_acc = 0;
1165 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
1166 pg->feedback_last_delay_update = GNUNET_TIME_absolute_get();
1167 pg->feedback_last = GNUNET_TIME_absolute_get();
1168 pg->feedback_task = GNUNET_SCHEDULER_add_delayed (feedback_frequency,
1169 &set_feedback_task, pg);
1178 * Stop all preferences generators
1181 GNUNET_ATS_solver_generate_preferences_stop_all ()
1183 struct PreferenceGenerator *cur;
1184 struct PreferenceGenerator *next;
1185 next = pref_gen_head;
1186 for (cur = next; NULL != cur; cur = next)
1189 GNUNET_ATS_solver_generate_preferences_stop(cur);
1200 print_op (enum OperationType op)
1203 case SOLVER_OP_ADD_ADDRESS:
1204 return "ADD_ADDRESS";
1205 case SOLVER_OP_DEL_ADDRESS:
1206 return "DEL_ADDRESS";
1207 case SOLVER_OP_START_SET_PREFERENCE:
1208 return "START_SET_PREFERENCE";
1209 case SOLVER_OP_STOP_SET_PREFERENCE:
1210 return "STOP_STOP_PREFERENCE";
1211 case SOLVER_OP_START_SET_PROPERTY:
1212 return "START_SET_PROPERTY";
1213 case SOLVER_OP_STOP_SET_PROPERTY:
1214 return "STOP_SET_PROPERTY";
1215 case SOLVER_OP_START_REQUEST:
1216 return "START_REQUEST";
1217 case SOLVER_OP_STOP_REQUEST:
1218 return "STOP_REQUEST";
1225 static struct Experiment *
1226 create_experiment ()
1228 struct Experiment *e;
1229 e = GNUNET_new (struct Experiment);
1232 e->total_duration = GNUNET_TIME_UNIT_ZERO;
1237 free_experiment (struct Experiment *e)
1239 struct Episode *cur;
1240 struct Episode *next;
1241 struct GNUNET_ATS_TEST_Operation *cur_o;
1242 struct GNUNET_ATS_TEST_Operation *next_o;
1245 for (cur = next; NULL != cur; cur = next)
1250 for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
1252 next_o = cur_o->next;
1253 GNUNET_free_non_null (cur_o->address);
1254 GNUNET_free_non_null (cur_o->plugin);
1255 GNUNET_free (cur_o);
1260 GNUNET_free_non_null (e->name);
1261 GNUNET_free_non_null (e->log_prefix);
1262 GNUNET_free_non_null (e->log_output_dir);
1263 GNUNET_free_non_null (e->cfg_file);
1269 load_op_add_address (struct GNUNET_ATS_TEST_Operation *o,
1273 const struct GNUNET_CONFIGURATION_Handle *cfg)
1279 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1280 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1281 sec_name, op_name, &o->peer_id))
1283 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1284 op_counter, "ADD_ADDRESS", op_name);
1285 GNUNET_free (op_name);
1286 return GNUNET_SYSERR;
1288 GNUNET_free (op_name);
1291 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1292 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1293 sec_name, op_name, &o->address_id))
1295 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1296 op_counter, "ADD_ADDRESS", op_name);
1297 GNUNET_free (op_name);
1298 return GNUNET_SYSERR;
1300 GNUNET_free (op_name);
1303 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
1304 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1305 sec_name, op_name, &o->plugin))
1307 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
1308 op_counter, "ADD_ADDRESS", op_name);
1309 GNUNET_free (op_name);
1310 return GNUNET_SYSERR;
1312 GNUNET_free (op_name);
1315 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
1316 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1317 sec_name, op_name, &o->address))
1319 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
1320 op_counter, "ADD_ADDRESS", op_name);
1321 GNUNET_free (op_name);
1322 return GNUNET_SYSERR;
1324 GNUNET_free (op_name);
1327 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
1328 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1329 sec_name, op_name, &o->address_session))
1331 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
1332 op_counter, "ADD_ADDRESS", op_name);
1333 GNUNET_free (op_name);
1334 return GNUNET_SYSERR;
1336 GNUNET_free (op_name);
1339 GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter);
1340 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1341 sec_name, op_name, &op_network))
1343 fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
1344 op_counter, "ADD_ADDRESS", op_name);
1345 GNUNET_free (op_name);
1346 return GNUNET_SYSERR;
1350 GNUNET_STRINGS_utf8_toupper (op_network,op_network);
1351 if (0 == strcmp(op_network, "UNSPECIFIED"))
1353 o->address_network = GNUNET_ATS_NET_UNSPECIFIED;
1355 else if (0 == strcmp(op_network, "LOOPBACK"))
1357 o->address_network = GNUNET_ATS_NET_LOOPBACK;
1359 else if (0 == strcmp(op_network, "LAN"))
1361 o->address_network = GNUNET_ATS_NET_LAN;
1363 else if (0 == strcmp(op_network, "WAN"))
1365 o->address_network = GNUNET_ATS_NET_WAN;
1367 else if (0 == strcmp(op_network, "WLAN"))
1369 o->address_network = GNUNET_ATS_NET_WLAN;
1371 else if (0 == strcmp(op_network, "BT"))
1373 o->address_network = GNUNET_ATS_NET_BT;
1377 fprintf (stderr, "Invalid address-network in operation %u `%s' in episode `%s': `%s'\n",
1378 op_counter, "ADD_ADDRESS", op_name, op_network);
1379 GNUNET_free (op_network);
1380 GNUNET_free (op_name);
1381 return GNUNET_SYSERR;
1384 GNUNET_free (op_network);
1385 GNUNET_free (op_name);
1387 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1388 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
1389 "ADD_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
1395 load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
1399 const struct GNUNET_CONFIGURATION_Handle *cfg)
1405 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1406 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1407 sec_name, op_name, &o->peer_id))
1409 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1410 op_counter, "DEL_ADDRESS", op_name);
1411 GNUNET_free (op_name);
1412 return GNUNET_SYSERR;
1414 GNUNET_free (op_name);
1417 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1418 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1419 sec_name, op_name, &o->address_id))
1421 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1422 op_counter, "DEL_ADDRESS", op_name);
1423 GNUNET_free (op_name);
1424 return GNUNET_SYSERR;
1426 GNUNET_free (op_name);
1430 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
1431 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1432 sec_name, op_name, &o->plugin))
1434 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
1435 op_counter, "DEL_ADDRESS", op_name);
1436 GNUNET_free (op_name);
1437 return GNUNET_SYSERR;
1439 GNUNET_free (op_name);
1442 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
1443 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1444 sec_name, op_name, &o->address))
1446 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
1447 op_counter, "DEL_ADDRESS", op_name);
1448 GNUNET_free (op_name);
1449 return GNUNET_SYSERR;
1451 GNUNET_free (op_name);
1454 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
1455 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1456 sec_name, op_name, &o->address_session))
1458 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
1459 op_counter, "DEL_ADDRESS", op_name);
1460 GNUNET_free (op_name);
1461 return GNUNET_SYSERR;
1463 GNUNET_free (op_name);
1466 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1467 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
1468 "DEL_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
1473 static enum GNUNET_ATS_Property
1474 parse_preference_string (const char * str)
1477 char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
1479 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
1480 if (0 == strcmp(str, props[c]))
1486 load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1490 const struct GNUNET_CONFIGURATION_Handle *cfg)
1497 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1498 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1499 sec_name, op_name, &o->peer_id))
1501 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1502 op_counter, "START_SET_PREFERENCE", op_name);
1503 GNUNET_free (op_name);
1504 return GNUNET_SYSERR;
1506 GNUNET_free (op_name);
1509 GNUNET_asprintf(&op_name, "op-%u-client-id", op_counter);
1510 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1511 sec_name, op_name, &o->client_id))
1513 fprintf (stderr, "Missing client-id in operation %u `%s' in episode `%s'\n",
1514 op_counter, "START_SET_PREFERENCE", op_name);
1515 GNUNET_free (op_name);
1516 return GNUNET_SYSERR;
1518 GNUNET_free (op_name);
1521 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1522 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1523 sec_name, op_name, &type)) )
1525 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1526 op_counter, "START_SET_PREFERENCE", op_name);
1527 GNUNET_free (op_name);
1528 return GNUNET_SYSERR;
1531 /* Load arguments for set_rate, start_send, set_preference */
1532 if (0 == strcmp (type, "constant"))
1534 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1536 else if (0 == strcmp (type, "linear"))
1538 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1540 else if (0 == strcmp (type, "sinus"))
1542 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1544 else if (0 == strcmp (type, "random"))
1546 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1550 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1551 op_counter, op_name, e->id);
1553 GNUNET_free (op_name);
1554 return GNUNET_SYSERR;
1557 GNUNET_free (op_name);
1561 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1562 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1563 sec_name, op_name, &o->base_rate))
1565 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1566 op_counter, op_name, e->id);
1567 GNUNET_free (op_name);
1568 return GNUNET_SYSERR;
1570 GNUNET_free (op_name);
1574 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1575 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1576 sec_name, op_name, &o->max_rate))
1578 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1579 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1580 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1582 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1583 op_counter, op_name, e->id);
1584 GNUNET_free (op_name);
1585 return GNUNET_SYSERR;
1588 GNUNET_free (op_name);
1591 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1592 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1593 sec_name, op_name, &o->period))
1595 o->period = e->duration;
1597 GNUNET_free (op_name);
1600 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1601 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1602 sec_name, op_name, &o->frequency))
1604 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1605 op_counter, op_name, e->id);
1606 GNUNET_free (op_name);
1607 return GNUNET_SYSERR;
1609 GNUNET_free (op_name);
1611 /* Get preference */
1612 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1613 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1614 sec_name, op_name, &pref))
1616 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
1617 op_counter, op_name, e->id);
1618 GNUNET_free (op_name);
1619 return GNUNET_SYSERR;
1622 if (0 == (o->pref_type = parse_preference_string(pref)))
1624 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1625 op_counter, op_name, e->id);
1626 GNUNET_free (op_name);
1628 return GNUNET_SYSERR;
1631 GNUNET_free (op_name);
1633 /* Get feedback delay */
1634 GNUNET_asprintf(&op_name, "op-%u-feedback_delay", op_counter);
1635 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time (cfg,
1636 sec_name, op_name, &o->feedback_delay))
1638 fprintf (stderr, "Using feedback delay %llu in operation %u `%s' in episode %u\n",
1639 (long long unsigned int) o->feedback_delay.rel_value_us,
1640 op_counter, op_name, e->id);
1643 o->feedback_delay = GNUNET_TIME_UNIT_FOREVER_REL;
1644 GNUNET_free (op_name);
1646 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1647 "Found operation %s: [%llu:%llu]: %s = %llu\n",
1648 "START_SET_PREFERENCE", o->peer_id, o->address_id,
1649 GNUNET_ATS_print_preference_type(o->pref_type), o->base_rate);
1655 load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1659 const struct GNUNET_CONFIGURATION_Handle *cfg)
1665 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1666 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1667 sec_name, op_name, &o->peer_id))
1669 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1670 op_counter, "STOP_SET_PREFERENCE", op_name);
1671 GNUNET_free (op_name);
1672 return GNUNET_SYSERR;
1674 GNUNET_free (op_name);
1677 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1678 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1679 sec_name, op_name, &o->address_id))
1681 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1682 op_counter, "STOP_SET_PREFERENCE", op_name);
1683 GNUNET_free (op_name);
1684 return GNUNET_SYSERR;
1686 GNUNET_free (op_name);
1688 /* Get preference */
1689 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1690 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1691 sec_name, op_name, &pref))
1693 fprintf (stderr, "Missing preference in operation %u `%s' in episode `%s'\n",
1694 op_counter, "STOP_SET_PREFERENCE", op_name);
1695 GNUNET_free (op_name);
1696 return GNUNET_SYSERR;
1699 if (0 == (o->pref_type = parse_preference_string(pref)))
1701 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1702 op_counter, op_name, e->id);
1703 GNUNET_free (op_name);
1705 return GNUNET_SYSERR;
1708 GNUNET_free (op_name);
1710 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1711 "Found operation %s: [%llu:%llu]: %s\n",
1712 "STOP_SET_PREFERENCE", o->peer_id, o->address_id,
1713 GNUNET_ATS_print_preference_type(o->pref_type));
1718 static enum GNUNET_ATS_Property
1719 parse_property_string (const char *str)
1721 enum GNUNET_ATS_Property c;
1723 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
1724 if (0 == strcmp(str,
1725 GNUNET_ATS_print_property_type (c)))
1732 load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o,
1736 const struct GNUNET_CONFIGURATION_Handle *cfg)
1743 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1744 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1745 sec_name, op_name, &o->peer_id))
1747 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1748 op_counter, "START_SET_PROPERTY", op_name);
1749 GNUNET_free (op_name);
1750 return GNUNET_SYSERR;
1752 GNUNET_free (op_name);
1755 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1756 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1757 sec_name, op_name, &o->address_id))
1759 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1760 op_counter, "START_SET_PROPERTY", op_name);
1761 GNUNET_free (op_name);
1762 return GNUNET_SYSERR;
1764 GNUNET_free (op_name);
1767 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1768 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1769 sec_name, op_name, &type)) )
1771 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1772 op_counter, "START_SET_PROPERTY", op_name);
1773 GNUNET_free (op_name);
1774 return GNUNET_SYSERR;
1777 /* Load arguments for set_rate, start_send, set_preference */
1778 if (0 == strcmp (type, "constant"))
1780 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1782 else if (0 == strcmp (type, "linear"))
1784 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1786 else if (0 == strcmp (type, "sinus"))
1788 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1790 else if (0 == strcmp (type, "random"))
1792 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1796 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1797 op_counter, op_name, e->id);
1799 GNUNET_free (op_name);
1800 return GNUNET_SYSERR;
1803 GNUNET_free (op_name);
1807 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1808 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1809 sec_name, op_name, &o->base_rate))
1811 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1812 op_counter, op_name, e->id);
1813 GNUNET_free (op_name);
1814 return GNUNET_SYSERR;
1816 GNUNET_free (op_name);
1820 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1821 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1822 sec_name, op_name, &o->max_rate))
1824 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1825 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1826 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1828 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1829 op_counter, op_name, e->id);
1830 GNUNET_free (op_name);
1831 return GNUNET_SYSERR;
1834 GNUNET_free (op_name);
1837 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1838 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1839 sec_name, op_name, &o->period))
1841 o->period = e->duration;
1843 GNUNET_free (op_name);
1846 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1847 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1848 sec_name, op_name, &o->frequency))
1850 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1851 op_counter, op_name, e->id);
1852 GNUNET_free (op_name);
1853 return GNUNET_SYSERR;
1855 GNUNET_free (op_name);
1857 /* Get preference */
1858 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1859 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1860 sec_name, op_name, &prop))
1862 fprintf (stderr, "Missing property in operation %u `%s' in episode %u\n",
1863 op_counter, op_name, e->id);
1864 GNUNET_free (op_name);
1865 GNUNET_free_non_null (prop);
1866 return GNUNET_SYSERR;
1869 if (0 == (o->prop_type = parse_property_string(prop)))
1871 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1872 op_counter, op_name, e->id);
1873 GNUNET_free (op_name);
1875 return GNUNET_SYSERR;
1879 GNUNET_free (op_name);
1881 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1882 "Found operation %s: [%llu:%llu] %s = %llu\n",
1883 "START_SET_PROPERTY", o->peer_id, o->address_id,
1884 GNUNET_ATS_print_property_type (o->prop_type), o->base_rate);
1890 load_op_stop_set_property (struct GNUNET_ATS_TEST_Operation *o,
1894 const struct GNUNET_CONFIGURATION_Handle *cfg)
1900 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1901 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1902 sec_name, op_name, &o->peer_id))
1904 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1905 op_counter, "STOP_SET_PROPERTY", op_name);
1906 GNUNET_free (op_name);
1907 return GNUNET_SYSERR;
1909 GNUNET_free (op_name);
1912 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1913 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1914 sec_name, op_name, &o->address_id))
1916 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1917 op_counter, "STOP_SET_PROPERTY", op_name);
1918 GNUNET_free (op_name);
1919 return GNUNET_SYSERR;
1921 GNUNET_free (op_name);
1924 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1925 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1926 sec_name, op_name, &pref))
1928 fprintf (stderr, "Missing property in operation %u `%s' in episode `%s'\n",
1929 op_counter, "STOP_SET_PROPERTY", op_name);
1930 GNUNET_free (op_name);
1931 GNUNET_free_non_null (pref);
1932 return GNUNET_SYSERR;
1935 if (0 == (o->prop_type = parse_property_string(pref)))
1937 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1938 op_counter, op_name, e->id);
1939 GNUNET_free (op_name);
1940 GNUNET_free_non_null (pref);
1941 return GNUNET_SYSERR;
1945 GNUNET_free (op_name);
1947 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1948 "Found operation %s: [%llu:%llu] %s\n",
1949 "STOP_SET_PROPERTY", o->peer_id, o->address_id,
1950 GNUNET_ATS_print_property_type (o->prop_type));
1957 load_op_start_request (struct GNUNET_ATS_TEST_Operation *o,
1961 const struct GNUNET_CONFIGURATION_Handle *cfg)
1966 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1967 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1968 sec_name, op_name, &o->peer_id))
1970 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1971 op_counter, "START_REQUEST", op_name);
1972 GNUNET_free (op_name);
1973 return GNUNET_SYSERR;
1975 GNUNET_free (op_name);
1980 load_op_stop_request (struct GNUNET_ATS_TEST_Operation *o,
1984 const struct GNUNET_CONFIGURATION_Handle *cfg)
1989 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1990 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1991 sec_name, op_name, &o->peer_id))
1993 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1994 op_counter, "STOP_REQUEST", op_name);
1995 GNUNET_free (op_name);
1996 return GNUNET_SYSERR;
1998 GNUNET_free (op_name);
2004 load_episode (struct Experiment *e, struct Episode *cur,
2005 struct GNUNET_CONFIGURATION_Handle *cfg)
2007 struct GNUNET_ATS_TEST_Operation *o;
2013 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Parsing episode %u\n",cur->id);
2014 GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
2018 /* Load operation */
2019 GNUNET_asprintf(&op_name, "op-%u-operation", op_counter);
2020 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
2021 sec_name, op_name, &op))
2023 GNUNET_free (op_name);
2026 o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
2027 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "==== Parsing operation %u: `%s'\n",
2030 /* operations = set_rate, start_send, stop_send, set_preference */
2031 if (0 == strcmp (op, "address_add"))
2033 o->type = SOLVER_OP_ADD_ADDRESS;
2034 res = load_op_add_address (o, cur,
2035 op_counter, sec_name, cfg);
2037 else if (0 == strcmp (op, "address_del"))
2039 o->type = SOLVER_OP_DEL_ADDRESS;
2040 res = load_op_del_address (o, cur,
2041 op_counter, sec_name, cfg);
2043 else if (0 == strcmp (op, "start_set_property"))
2045 o->type = SOLVER_OP_START_SET_PROPERTY;
2046 res = load_op_start_set_property (o, cur,
2047 op_counter, sec_name, cfg);
2049 else if (0 == strcmp (op, "stop_set_property"))
2051 o->type = SOLVER_OP_STOP_SET_PROPERTY;
2052 res = load_op_stop_set_property (o, cur,
2053 op_counter, sec_name, cfg);
2055 else if (0 == strcmp (op, "start_set_preference"))
2057 o->type = SOLVER_OP_START_SET_PREFERENCE;
2058 res = load_op_start_set_preference (o, cur,
2059 op_counter, sec_name, cfg);
2061 else if (0 == strcmp (op, "stop_set_preference"))
2063 o->type = SOLVER_OP_STOP_SET_PREFERENCE;
2064 res = load_op_stop_set_preference (o, cur,
2065 op_counter, sec_name, cfg);
2067 else if (0 == strcmp (op, "start_request"))
2069 o->type = SOLVER_OP_START_REQUEST;
2070 res = load_op_start_request (o, cur,
2071 op_counter, sec_name, cfg);
2073 else if (0 == strcmp (op, "stop_request"))
2075 o->type = SOLVER_OP_STOP_REQUEST;
2076 res = load_op_stop_request(o, cur,
2077 op_counter, sec_name, cfg);
2081 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
2082 op_counter, op, cur->id);
2083 res = GNUNET_SYSERR;
2087 GNUNET_free (op_name);
2089 if (GNUNET_SYSERR == res)
2092 GNUNET_free (sec_name);
2093 return GNUNET_SYSERR;
2096 GNUNET_CONTAINER_DLL_insert_tail (cur->head,cur->tail, o);
2099 GNUNET_free (sec_name);
2104 load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
2108 struct GNUNET_TIME_Relative e_duration;
2109 struct Episode *cur;
2110 struct Episode *last;
2116 GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
2117 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
2118 sec_name, "duration", &e_duration))
2120 GNUNET_free (sec_name);
2124 cur = GNUNET_new (struct Episode);
2125 cur->duration = e_duration;
2126 cur->id = e_counter;
2128 if (GNUNET_OK != load_episode (e, cur, cfg))
2130 GNUNET_free (sec_name);
2132 return GNUNET_SYSERR;
2135 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Found episode %u with duration %s \n",
2137 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
2139 /* Update experiment */
2141 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
2142 /* Put in linked list */
2148 GNUNET_free (sec_name);
2156 timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
2158 struct Experiment *e = cls;
2159 e->experiment_timeout_task = NULL;
2160 fprintf (stderr, "Experiment timeout!\n");
2162 if (NULL != e->episode_timeout_task)
2164 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2165 e->episode_timeout_task = NULL;
2168 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
2172 struct ATS_Address *
2173 create_ats_address (const struct GNUNET_PeerIdentity *peer,
2174 const char *plugin_name,
2175 const void *plugin_addr,
2176 size_t plugin_addr_len,
2177 uint32_t session_id,
2180 struct ATS_Address *aa = NULL;
2182 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1);
2183 aa->atsi = GNUNET_new (struct GNUNET_ATS_Information);
2184 aa->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
2185 aa->atsi[0].value = htonl (network);
2189 aa->addr_len = plugin_addr_len;
2191 aa->plugin = (char *) &aa[1] + plugin_addr_len;
2192 memcpy (&aa[1], plugin_addr, plugin_addr_len);
2193 memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
2194 aa->session_id = session_id;
2195 aa->active = GNUNET_NO;
2196 aa->used = GNUNET_NO;
2197 aa->solver_information = NULL;
2198 aa->assigned_bw_in = 0;
2199 aa->assigned_bw_out = 0;
2207 enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
2210 struct TestAddress *a;
2213 if (NULL == (p = find_peer_by_id (op->peer_id)))
2215 p = GNUNET_new (struct TestPeer);
2216 p->id = op->peer_id;
2217 p->assigned_bw_in = 0;
2218 p->assigned_bw_out = 0;
2219 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
2220 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
2222 p->pref_abs[c] = DEFAULT_ABS_PREFERENCE;
2223 p->pref_norm[c] = DEFAULT_REL_PREFERENCE;
2226 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p);
2229 if (NULL != (find_address_by_id (p, op->address_id)))
2231 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Duplicate address %u for peer %u\n",
2232 op->address_id, op->peer_id);
2236 a = GNUNET_new (struct TestAddress);
2237 a->aid = op->address_id;
2238 a->network = op->address_network;
2239 a->ats_addr = create_ats_address (&p->peer_id, op->plugin, op->address,
2240 strlen (op->address) + 1, op->address_session, op->address_network);
2241 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
2242 GNUNET_CONTAINER_DLL_insert_tail (p->addr_head, p->addr_tail, a);
2244 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
2245 a->prop_norm[c] = DEFAULT_REL_QUALITY;
2247 GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, a->ats_addr,
2248 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2250 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u in network `%s'\n",
2251 op->address_id, op->peer_id, GNUNET_ATS_print_network_type(a->network));
2253 sh->env.sf.s_add (sh->solver, a->ats_addr, op->address_network);
2259 enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
2262 struct TestAddress *a;
2263 struct PropertyGenerator *pg;
2265 if (NULL == (p = find_peer_by_id (op->peer_id)))
2268 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2269 "Deleting address for unknown peer %u\n", op->peer_id);
2273 if (NULL == (a =find_address_by_id (p, op->address_id)))
2276 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2277 "Deleting address for unknown peer %u\n", op->peer_id);
2281 while (NULL != (pg = find_prop_gen (p->id, a->aid, 0)))
2283 GNUNET_ATS_solver_generate_property_stop (pg);
2286 GNUNET_assert (GNUNET_YES ==
2287 GNUNET_CONTAINER_multipeermap_remove (sh->addresses,
2290 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2291 "Removing address %u for peer %u\n",
2295 sh->env.sf.s_del (sh->solver, a->ats_addr, GNUNET_NO);
2299 GNUNET_ATS_solver_logging_now (l);
2301 GNUNET_CONTAINER_DLL_remove(p->addr_head, p->addr_tail, a);
2303 GNUNET_free_non_null(a->ats_addr->atsi);
2304 GNUNET_free (a->ats_addr);
2310 enforce_start_property (struct GNUNET_ATS_TEST_Operation *op)
2312 struct PropertyGenerator *pg;
2314 struct TestAddress *a;
2316 if (NULL != (pg = find_prop_gen (op->peer_id, op->address_id, op->prop_type)))
2318 GNUNET_ATS_solver_generate_property_stop (pg);
2322 if (NULL == (p = find_peer_by_id (op->peer_id)))
2325 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2326 "Starting property generation for unknown peer %u\n", op->peer_id);
2330 if (NULL == (a = find_address_by_id (p, op->address_id)))
2333 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2334 "Setting property for unknown address %u\n", op->peer_id);
2338 GNUNET_ATS_solver_generate_property_start (op->peer_id,
2350 enforce_stop_property (struct GNUNET_ATS_TEST_Operation *op)
2352 struct PropertyGenerator *pg = find_prop_gen(op->peer_id, op->address_id,
2356 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2357 "Stopping preference generation for peer %u address %u\n", op->peer_id,
2359 GNUNET_ATS_solver_generate_property_stop (pg);
2363 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2364 "Cannot find preference generator for peer %u address %u\n",
2365 op->peer_id, op->address_id);
2371 enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
2373 struct PreferenceGenerator *pg;
2374 if (NULL != (pg = find_pref_gen (op->peer_id, op->pref_type)))
2376 GNUNET_ATS_solver_generate_preferences_stop (pg);
2380 if (NULL == (find_peer_by_id (op->peer_id)))
2383 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2384 "Starting preference generation for unknown peer %u\n", op->peer_id);
2388 GNUNET_ATS_solver_generate_preferences_start (op->peer_id,
2401 enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
2403 struct PreferenceGenerator *pg = find_pref_gen(op->peer_id,
2407 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2408 "Stopping property generation for peer %u address %u\n", op->peer_id,
2410 GNUNET_ATS_solver_generate_preferences_stop (pg);
2414 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2415 "Cannot find preference generator for peer %u address %u\n",
2416 op->peer_id, op->address_id);
2423 enforce_start_request (struct GNUNET_ATS_TEST_Operation *op)
2426 const struct ATS_Address *res;
2428 if (NULL == (p = find_peer_by_id (op->peer_id)))
2431 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2432 "Requesting address for unknown peer %u\n", op->peer_id);
2436 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n",
2438 p->is_requested = GNUNET_YES;
2440 res = sh->env.sf.s_get (sh->solver, &p->peer_id);
2443 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Suggested address for peer %u: %llu %llu\n",
2445 res->assigned_bw_in,
2446 res->assigned_bw_out);
2448 GNUNET_ATS_solver_logging_now (l);
2453 enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op)
2457 if (NULL == (p = find_peer_by_id (op->peer_id)))
2460 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2461 "Requesting address for unknown peer %u\n", op->peer_id);
2467 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop requesting address for peer %u\n",
2469 p->is_requested = GNUNET_NO;
2470 p->assigned_bw_in = 0;
2471 p->assigned_bw_out = 0;
2472 sh->env.sf.s_get_stop (sh->solver, &p->peer_id);
2476 GNUNET_ATS_solver_logging_now (l);
2481 static void enforce_episode (struct Episode *ep)
2483 struct GNUNET_ATS_TEST_Operation *cur;
2484 for (cur = ep->head; NULL != cur; cur = cur->next)
2486 switch (cur->type) {
2487 case SOLVER_OP_ADD_ADDRESS:
2488 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2489 print_op (cur->type), cur->peer_id, cur->address_id);
2490 enforce_add_address (cur);
2492 case SOLVER_OP_DEL_ADDRESS:
2493 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2494 print_op (cur->type), cur->peer_id, cur->address_id);
2495 enforce_del_address (cur);
2497 case SOLVER_OP_START_SET_PROPERTY:
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_property (cur);
2502 case SOLVER_OP_STOP_SET_PROPERTY:
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_property (cur);
2507 case SOLVER_OP_START_SET_PREFERENCE:
2508 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2509 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2510 enforce_start_preference (cur);
2512 case SOLVER_OP_STOP_SET_PREFERENCE:
2513 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2514 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2515 enforce_stop_preference (cur);
2517 case SOLVER_OP_START_REQUEST:
2518 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2519 print_op (cur->type), cur->peer_id);
2520 enforce_start_request (cur);
2522 case SOLVER_OP_STOP_REQUEST:
2523 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2524 print_op (cur->type), cur->peer_id);
2525 enforce_stop_request (cur);
2534 timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
2536 struct Experiment *e = cls;
2537 e->episode_timeout_task = NULL;
2538 if (NULL != e->ep_done_cb)
2539 e->ep_done_cb (e->cur);
2541 /* Scheduling next */
2542 e->cur = e->cur->next;
2546 fprintf (stderr, "Last episode done!\n");
2547 if (NULL != e->experiment_timeout_task)
2549 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2550 e->experiment_timeout_task = NULL;
2552 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
2556 fprintf (stderr, "Running episode %u with timeout %s\n",
2558 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2559 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2560 &timeout_episode, e);
2561 enforce_episode(e->cur);
2568 GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
2569 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
2570 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
2572 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
2573 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
2574 e->e_done_cb = e_done_cb;
2575 e->ep_done_cb = ep_done_cb;
2576 e->start_time = GNUNET_TIME_absolute_get();
2578 /* Start total time out */
2579 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
2580 &timeout_experiment, e);
2583 if (NULL == e->start)
2590 fprintf (stderr, "Running episode %u with timeout %s\n",
2592 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2593 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2594 &timeout_episode, e);
2595 enforce_episode(e->cur);
2600 GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
2602 if (NULL != e->experiment_timeout_task)
2604 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2605 e->experiment_timeout_task = NULL;
2607 if (NULL != e->episode_timeout_task)
2609 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2610 e->episode_timeout_task = NULL;
2614 GNUNET_CONFIGURATION_destroy(e->cfg);
2617 free_experiment (e);
2622 GNUNET_ATS_solvers_experimentation_load (char *filename)
2624 struct Experiment *e;
2625 struct GNUNET_CONFIGURATION_Handle *cfg;
2628 cfg = GNUNET_CONFIGURATION_create();
2629 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
2631 fprintf (stderr, "Failed to load `%s'\n", filename);
2632 GNUNET_CONFIGURATION_destroy (cfg);
2636 e = create_experiment ();
2638 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2641 fprintf (stderr, "Invalid %s \n", "name");
2642 free_experiment (e);
2646 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment name: `%s'\n", e->name);
2648 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2649 "log_prefix", &e->log_prefix))
2651 fprintf (stderr, "Invalid %s \n", "log_prefix");
2652 free_experiment (e);
2656 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging prefix: `%s'\n",
2659 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2660 "log_output_dir", &e->log_output_dir))
2662 e->log_output_dir = NULL;
2665 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging output directory: `%s'\n",
2669 if (GNUNET_SYSERR == (e->log_append_time_stamp = GNUNET_CONFIGURATION_get_value_yesno(cfg,
2670 "experiment", "log_append_time_stamp")))
2671 e->log_append_time_stamp = GNUNET_YES;
2672 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging append timestamp: `%s'\n",
2673 (GNUNET_YES == e->log_append_time_stamp) ? "yes" : "no");
2676 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2677 "cfg_file", &e->cfg_file))
2679 fprintf (stderr, "Invalid %s \n", "cfg_file");
2680 free_experiment (e);
2685 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment configuration: `%s'\n", e->cfg_file);
2686 e->cfg = GNUNET_CONFIGURATION_create();
2687 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file))
2689 fprintf (stderr, "Invalid configuration %s \n", "cfg_file");
2690 free_experiment (e);
2696 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2697 "log_freq", &e->log_freq))
2699 fprintf (stderr, "Invalid %s \n", "log_freq");
2700 free_experiment (e);
2704 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging frequency: `%s'\n",
2705 GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
2707 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2708 "max_duration", &e->max_duration))
2710 fprintf (stderr, "Invalid %s", "max_duration");
2711 free_experiment (e);
2715 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment duration: `%s'\n",
2716 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
2718 if (GNUNET_SYSERR == load_episodes (e, cfg))
2720 GNUNET_ATS_solvers_experimentation_stop (e);
2721 GNUNET_CONFIGURATION_destroy (cfg);
2723 fprintf (stderr, "Failed to load experiment\n");
2726 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loaded %u episodes with total duration %s\n",
2728 GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
2730 GNUNET_CONFIGURATION_destroy (cfg);
2741 free_all_it (void *cls,
2742 const struct GNUNET_PeerIdentity *key,
2745 struct ATS_Address *address = value;
2746 GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (sh->env.addresses,
2748 GNUNET_free (address);
2754 GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh)
2756 GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
2758 GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
2760 GAS_normalization_stop();
2762 GNUNET_CONTAINER_multipeermap_iterate (sh->addresses, &free_all_it, NULL);
2763 GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
2764 GNUNET_free (sh->plugin);
2769 * Load quotas for networks from configuration
2771 * @param cfg configuration handle
2772 * @param out_dest where to write outbound quotas
2773 * @param in_dest where to write inbound quotas
2774 * @param dest_length length of inbound and outbound arrays
2775 * @return number of networks loaded
2778 GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
2779 unsigned long long *out_dest,
2780 unsigned long long *in_dest,
2783 char * entry_in = NULL;
2784 char * entry_out = NULL;
2785 char * quota_out_str;
2786 char * quota_in_str;
2790 for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
2794 GNUNET_asprintf (&entry_out,
2796 GNUNET_ATS_print_network_type (c));
2797 GNUNET_asprintf (&entry_in,
2799 GNUNET_ATS_print_network_type (c));
2802 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
2805 if (0 == strcmp(quota_out_str, BIG_M_STRING))
2807 out_dest[c] = GNUNET_ATS_MaxBandwidth;
2810 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
2812 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c])))
2815 if (GNUNET_NO == res)
2817 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2818 _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2819 GNUNET_ATS_print_network_type (c),
2821 GNUNET_ATS_DefaultBandwidth);
2822 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2827 "Outbound quota configure for network `%s' is %llu\n",
2828 GNUNET_ATS_print_network_type (c),
2831 GNUNET_free (quota_out_str);
2835 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2836 _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
2837 GNUNET_ATS_print_network_type (c),
2838 GNUNET_ATS_DefaultBandwidth);
2839 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2843 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str))
2846 if (0 == strcmp(quota_in_str, BIG_M_STRING))
2848 in_dest[c] = GNUNET_ATS_MaxBandwidth;
2851 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
2853 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c])))
2856 if (GNUNET_NO == res)
2858 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2859 _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2860 GNUNET_ATS_print_network_type (c),
2862 GNUNET_ATS_DefaultBandwidth);
2863 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
2867 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2868 "Inbound quota configured for network `%s' is %llu\n",
2869 GNUNET_ATS_print_network_type (c),
2872 GNUNET_free (quota_in_str);
2876 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2877 _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
2878 GNUNET_ATS_print_network_type (c),
2879 GNUNET_ATS_DefaultBandwidth);
2880 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2882 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2883 "Loaded quota for network `%s' (in/out): %llu %llu\n",
2884 GNUNET_ATS_print_network_type (c),
2887 GNUNET_free (entry_out);
2888 GNUNET_free (entry_in);
2890 return GNUNET_ATS_NetworkTypeCount;
2895 * Information callback for the solver
2897 * @param cls the closure
2898 * @param op the solver operation
2899 * @param stat status of the solver operation
2900 * @param add additional solver information
2903 solver_info_cb (void *cls,
2904 enum GAS_Solver_Operation op,
2905 enum GAS_Solver_Status stat,
2906 enum GAS_Solver_Additional_Information add)
2911 add_info = "GAS_INFO_NONE";
2914 add_info = "GAS_INFO_MLP_FULL";
2916 case GAS_INFO_UPDATED:
2917 add_info = "GAS_INFO_MLP_UPDATED";
2919 case GAS_INFO_PROP_ALL:
2920 add_info = "GAS_INFO_PROP_ALL";
2922 case GAS_INFO_PROP_SINGLE:
2923 add_info = "GAS_INFO_PROP_SINGLE";
2926 add_info = "INVALID";
2932 case GAS_OP_SOLVE_START:
2933 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2934 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
2935 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2937 case GAS_OP_SOLVE_STOP:
2938 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2939 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
2940 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2943 case GAS_OP_SOLVE_SETUP_START:
2944 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2945 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
2946 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2949 case GAS_OP_SOLVE_SETUP_STOP:
2950 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2951 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
2952 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2955 case GAS_OP_SOLVE_MLP_LP_START:
2956 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2957 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
2958 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2960 case GAS_OP_SOLVE_MLP_LP_STOP:
2961 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2962 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
2963 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2966 case GAS_OP_SOLVE_MLP_MLP_START:
2967 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2968 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
2969 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2971 case GAS_OP_SOLVE_MLP_MLP_STOP:
2972 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2973 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
2974 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2976 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
2977 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2978 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
2979 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2981 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
2982 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2983 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
2984 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2992 solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address)
2994 struct GNUNET_TIME_Relative duration;
2996 static struct PreferenceGenerator *pg;
2998 if ( (0 == address->assigned_bw_out) && (0 == address->assigned_bw_in) )
3000 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3001 "Solver notified to disconnect peer `%s'\n",
3002 GNUNET_i2s (&address->peer));
3004 p = find_peer_by_pid(&address->peer);
3007 p->assigned_bw_out = address->assigned_bw_out;
3008 p->assigned_bw_in = address->assigned_bw_in;
3010 for (pg = pref_gen_head; NULL != pg; pg = pg->next)
3012 if (pg->peer == p->id)
3014 duration = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update);
3015 delta = duration.rel_value_us * pg->last_assigned_bw_out;
3016 pg->feedback_bw_out_acc += delta;
3018 delta = duration.rel_value_us * pg->last_assigned_bw_in;
3019 pg->feedback_bw_in_acc += delta;
3021 pg->last_assigned_bw_in = address->assigned_bw_in;
3022 pg->last_assigned_bw_out = address->assigned_bw_out;
3023 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
3027 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3028 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
3029 GNUNET_i2s (&address->peer),
3031 address->assigned_bw_out,
3032 address->assigned_bw_in);
3035 GNUNET_ATS_solver_logging_now (l);
3041 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
3044 if (GNUNET_YES == opt_disable_normalization)
3046 if (NULL == (p = find_peer_by_pid (id)))
3051 return GAS_normalization_get_preferences_by_peer (NULL,
3057 get_property_cb (void *cls, const struct ATS_Address *address)
3060 struct TestAddress *a;
3062 if (GNUNET_YES == opt_disable_normalization)
3064 p = find_peer_by_pid (&address->peer);
3067 a = find_address_by_ats_address (p, address);
3070 return GAS_normalization_get_properties (NULL,
3075 struct SolverHandle *
3076 GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
3078 struct SolverHandle *sh;
3083 case GNUNET_ATS_SOLVER_PROPORTIONAL:
3084 solver_str = "proportional";
3086 case GNUNET_ATS_SOLVER_MLP:
3089 case GNUNET_ATS_SOLVER_RIL:
3098 sh = GNUNET_new (struct SolverHandle);
3099 GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
3101 sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
3103 /* setup environment */
3104 sh->env.cfg = e->cfg;
3105 sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg);
3106 sh->env.addresses = sh->addresses;
3107 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
3108 sh->env.get_preferences = &get_preferences_cb;
3109 sh->env.get_property = &get_property_cb;
3110 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
3111 sh->env.info_cb = &solver_info_cb;
3112 sh->env.info_cb_cls = NULL;
3113 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
3114 int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
3115 for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
3116 sh->env.networks[c] = networks[c];
3119 /* start normalization */
3120 GAS_normalization_start ();
3123 if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg,
3124 sh->env.out_quota, sh->env.in_quota, GNUNET_ATS_NetworkTypeCount))
3127 GNUNET_free (sh->plugin);
3133 sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
3134 if (NULL == sh->solver)
3136 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
3138 GNUNET_free (sh->plugin);
3149 struct TestPeer *cur;
3150 struct TestPeer *next;
3152 struct TestAddress *cur_a;
3153 struct TestAddress *next_a;
3156 GNUNET_ATS_solver_logging_stop (l);
3158 /* Stop all preference generation */
3159 GNUNET_ATS_solver_generate_preferences_stop_all ();
3161 /* Stop all property generation */
3162 GNUNET_ATS_solver_generate_property_stop_all ();
3166 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Printing log information \n");
3167 GNUNET_ATS_solver_logging_eval (l);
3171 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Saving log information \n");
3172 GNUNET_ATS_solver_logging_write_to_disk (l, e->log_append_time_stamp,
3178 GNUNET_ATS_solver_logging_free (l);
3182 /* Clean up experiment */
3185 GNUNET_ATS_solvers_experimentation_stop (e);
3190 while (NULL != (cur = next))
3193 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, cur);
3194 next_a = cur->addr_head;
3195 while (NULL != (cur_a = next_a))
3197 next_a = cur_a->next;
3198 GNUNET_CONTAINER_DLL_remove (cur->addr_head, cur->addr_tail, cur_a);
3199 GNUNET_free (cur_a);
3205 GNUNET_ATS_solvers_solver_stop (sh);
3214 experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success)
3216 if (GNUNET_OK == success)
3217 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n",
3218 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
3220 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
3222 GNUNET_SCHEDULER_add_now (&done, NULL);
3226 episode_done_cb (struct Episode *ep)
3228 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
3241 GNUNET_ATS_solvers_experimentation_stop (e);
3246 GNUNET_ATS_solvers_solver_stop (sh);
3252 run (void *cls, char * const *args, const char *cfgfile,
3253 const struct GNUNET_CONFIGURATION_Handle *cfg)
3255 enum GNUNET_ATS_Solvers solver;
3258 if (NULL == opt_exp_file)
3260 fprintf (stderr, "No experiment given ...\n");
3266 if (NULL == opt_solver)
3268 fprintf (stderr, "No solver given ...\n");
3274 if (0 == strcmp(opt_solver, "mlp"))
3276 solver = GNUNET_ATS_SOLVER_MLP;
3278 else if (0 == strcmp(opt_solver, "proportional"))
3280 solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
3282 else if (0 == strcmp(opt_solver, "ril"))
3284 solver = GNUNET_ATS_SOLVER_RIL;
3288 fprintf (stderr, "No solver given ...");
3294 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
3295 default_properties[c] = DEFAULT_REL_QUALITY;
3297 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
3298 default_preferences[c] = DEFAULT_REL_PREFERENCE;
3300 /* load experiment */
3301 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading experiment\n");
3302 e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
3305 fprintf (stderr, "Failed to load experiment ...\n");
3312 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading solver\n");
3313 sh = GNUNET_ATS_solvers_solver_start (solver);
3316 fprintf (stderr, "Failed to start solver ...\n");
3323 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Start logging \n");
3324 l = GNUNET_ATS_solver_logging_start (e->log_freq);
3326 /* run experiment */
3327 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Running experiment \n");
3328 GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb,
3329 experiment_done_cb);
3336 * Main function of the benchmark
3338 * @param argc argument count
3339 * @param argv argument values
3342 main (int argc, char *argv[])
3344 opt_exp_file = NULL;
3346 opt_log = GNUNET_NO;
3347 opt_save = GNUNET_NO;
3351 static struct GNUNET_GETOPT_CommandLineOption options[] =
3353 { 's', "solver", NULL,
3354 gettext_noop ("solver to use"),
3355 1, &GNUNET_GETOPT_set_string, &opt_solver},
3356 { 'e', "experiment", NULL,
3357 gettext_noop ("experiment to use"),
3358 1, &GNUNET_GETOPT_set_string, &opt_exp_file},
3359 { 'V', "verbose", NULL,
3360 gettext_noop ("be verbose"),
3361 0, &GNUNET_GETOPT_set_one, &opt_verbose},
3362 { 'p', "print", NULL,
3363 gettext_noop ("print logging"),
3364 0, &GNUNET_GETOPT_set_one, &opt_print},
3365 { 'f', "file", NULL,
3366 gettext_noop ("save logging to disk"),
3367 0, &GNUNET_GETOPT_set_one, &opt_save},
3369 gettext_noop ("disable normalization"),
3370 0, &GNUNET_GETOPT_set_one, &opt_disable_normalization},
3371 GNUNET_GETOPT_OPTION_END
3374 GNUNET_PROGRAM_run (argc, argv, "gnunet-ats-solver-eval",
3375 NULL, options, &run, argv[0]);
3379 /* end of file ats-testing-experiment.c*/