2 This file is part of GNUnet.
3 Copyright (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.c"
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:
112 static struct TestPeer *
113 find_peer_by_id (int id)
115 struct TestPeer *cur;
116 for (cur = peer_head; NULL != cur; cur = cur->next)
122 static struct TestPeer *
123 find_peer_by_pid (const struct GNUNET_PeerIdentity *pid)
125 struct TestPeer *cur;
126 for (cur = peer_head; NULL != cur; cur = cur->next)
127 if (0 == memcmp (&cur->peer_id, pid, sizeof (struct GNUNET_PeerIdentity)))
132 static struct TestAddress *
133 find_address_by_id (struct TestPeer *peer, int aid)
135 struct TestAddress *cur;
136 for (cur = peer->addr_head; NULL != cur; cur = cur->next)
143 static struct TestAddress *
144 find_address_by_ats_address (struct TestPeer *p, const struct ATS_Address *addr)
146 struct TestAddress *cur;
147 for (cur = p->addr_head; NULL != cur; cur = cur->next)
148 if ((0 == strcmp(cur->ats_addr->plugin, addr->plugin)) &&
149 (cur->ats_addr->addr_len == addr->addr_len) &&
150 (0 == memcmp (cur->ats_addr->addr, addr->addr, addr->addr_len)))
161 GNUNET_ATS_solver_logging_now (struct LoggingHandle *l)
163 struct LoggingTimeStep *lts;
164 struct TestPeer *cur;
165 struct TestAddress *cur_addr;
166 struct LoggingPeer *log_p;
167 struct LoggingAddress *log_a;
170 lts = GNUNET_new (struct LoggingTimeStep);
171 GNUNET_CONTAINER_DLL_insert_tail(l->head, l->tail, lts);
172 lts->timestamp = GNUNET_TIME_absolute_get();
173 if (NULL == lts->prev)
174 lts->delta = GNUNET_TIME_UNIT_ZERO;
176 lts->delta = GNUNET_TIME_absolute_get_duration(lts->prev->timestamp);
178 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging %llu, delta %llu\n",
179 lts->timestamp.abs_value_us, lts->delta.rel_value_us);
182 /* Store logging data here */
183 for (cur = peer_head; NULL != cur; cur = cur->next)
185 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging peer id %llu\n", cur->id);
187 log_p = GNUNET_new (struct LoggingPeer);
189 log_p->peer_id = cur->peer_id;
190 log_p->is_requested = cur->is_requested;
191 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
193 log_p->pref_abs[c] = cur->pref_abs[c];
194 log_p->pref_norm[c] = cur->pref_norm[c];
195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t %s = %.2f %.2f [abs/rel]\n",
196 GNUNET_ATS_print_preference_type(c),
197 log_p->pref_abs[c], log_p->pref_norm[c]);
199 GNUNET_CONTAINER_DLL_insert_tail(lts->head, lts->tail, log_p);
201 for (cur_addr = cur->addr_head; NULL != cur_addr; cur_addr = cur_addr->next)
203 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging peer id %llu address %llu \n",
204 cur->id, cur_addr->aid);
205 log_a = GNUNET_new (struct LoggingAddress);
206 log_a->aid = cur_addr->aid;
207 log_a->active = cur_addr->ats_addr->active;
208 log_a->network = cur_addr->network;
209 log_a->assigned_bw_in = cur_addr->ats_addr->assigned_bw_in;
210 log_a->assigned_bw_out = cur_addr->ats_addr->assigned_bw_out;
211 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
213 log_a->prop_abs[c] = cur_addr->prop_abs[c];
214 log_a->prop_norm[c] = cur_addr->prop_norm[c];
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t %s = %.2f %.2f [abs/rel]\n",
216 GNUNET_ATS_print_property_type(c),
217 log_a->prop_abs[c], log_a->prop_norm[c]);
219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t Active = %i\n", log_a->active);
220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t BW in = %llu\n", log_a->assigned_bw_in);
221 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t BW out = %llu\n", log_a->assigned_bw_out);
223 GNUNET_CONTAINER_DLL_insert_tail (log_p->addr_head, log_p->addr_tail, log_a);
229 logging_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
231 struct LoggingHandle *l = cls;
232 l->logging_task = NULL;
234 GNUNET_ATS_solver_logging_now (l);
236 l->logging_task = GNUNET_SCHEDULER_add_delayed (l->log_freq, &logging_task, l);
240 struct LoggingHandle *
241 GNUNET_ATS_solver_logging_start (struct GNUNET_TIME_Relative freq)
243 struct LoggingHandle *l;
244 l = GNUNET_new (struct LoggingHandle);
246 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start logging every %s\n",
247 GNUNET_STRINGS_relative_time_to_string(freq, GNUNET_NO));
249 l->logging_task = GNUNET_SCHEDULER_add_now (&logging_task, l);
254 GNUNET_ATS_solver_logging_stop (struct LoggingHandle *l)
256 if (NULL != l->logging_task)
257 GNUNET_SCHEDULER_cancel (l->logging_task);
259 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop logging\n");
261 l->logging_task = NULL;
264 static struct LoggingFileHandle *
265 find_logging_file_handle (struct LoggingFileHandle *lf_head,
266 struct LoggingFileHandle *lf_tail,
267 int peer_id, int address_id)
269 struct LoggingFileHandle *res;
271 for (res = lf_head; NULL != res; res = res->next)
272 if ((res->pid == peer_id) && (res->aid == address_id))
279 GNUNET_ATS_solver_logging_write_to_disk (struct LoggingHandle *l, int add_time_stamp,
282 struct LoggingTimeStep *lts;
283 struct LoggingPeer *log_p;
284 struct LoggingAddress *log_a;
285 struct LoggingFileHandle *lf_head;
286 struct LoggingFileHandle *lf_tail;
287 struct LoggingFileHandle *cur;
288 struct LoggingFileHandle *next;
292 char * propstring_tmp;
294 char * prefstring_tmp;
299 if (NULL != output_dir)
301 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (output_dir))
303 fprintf (stderr, "Failed to create directory `%s'\n", output_dir);
308 fprintf (stderr, "Created directory `%s'\n", output_dir);
309 use_dir = GNUNET_YES;
316 for (lts = l->head; NULL != lts; lts = lts->next)
319 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing log step %llu\n",
320 (long long unsigned int) lts->timestamp.abs_value_us);
322 for (log_p = lts->head; NULL != log_p; log_p = log_p->next)
324 for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next)
327 cur = find_logging_file_handle (lf_head, lf_tail, log_p->id,
331 cur = GNUNET_new (struct LoggingFileHandle);
332 cur->aid = log_a->aid;
333 cur->pid = log_p->id;
335 if (GNUNET_YES == add_time_stamp)
336 GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u_%llu.log",
337 (GNUNET_YES == use_dir) ? output_dir : "",
338 (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "",
343 l->head->timestamp.abs_value_us);
345 GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u.log",
346 (GNUNET_YES == use_dir) ? output_dir : "",
347 (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "",
353 fprintf (stderr, "Add writing log data for peer %llu address %llu to file `%s'\n",
354 cur->pid, cur->aid, filename);
357 cur->f_hd = GNUNET_DISK_file_open (filename,
358 GNUNET_DISK_OPEN_READWRITE |
359 GNUNET_DISK_OPEN_CREATE |
360 GNUNET_DISK_OPEN_TRUNCATE,
361 GNUNET_DISK_PERM_USER_READ |
362 GNUNET_DISK_PERM_USER_WRITE |
363 GNUNET_DISK_PERM_GROUP_READ |
364 GNUNET_DISK_PERM_OTHER_READ);
365 if (NULL == cur->f_hd)
367 fprintf (stderr, "Cannot open `%s' to write log data!\n", filename);
368 GNUNET_free (filename);
372 GNUNET_free (filename);
373 GNUNET_CONTAINER_DLL_insert (lf_head, lf_tail, cur);
375 GNUNET_asprintf(&datastring,"#time delta;log duration;peer_requested;addr net; addr_active; bw in; bw out; " \
376 "UTILIZATION_UP [abs/rel]; UTILIZATION_UP; UTILIZATION_DOWN; UTILIZATION_DOWN; " \
377 "UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_DOWN; UTILIZATION_PAYLOAD_DOWN;"\
379 "DISTANCE ;DISTANCE ; COST_WAN; COST_WAN; COST_LAN; COST_LAN; " \
380 "COST_WLAN; COST_WLAN;COST_BT; COST_BT; PREF BW abs; PREF BW rel; PREF LATENCY abs; PREF LATENCY rel;\n");
381 GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring));
382 GNUNET_free (datastring);
386 prefstring = GNUNET_strdup("");
387 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
390 fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n",
391 GNUNET_ATS_print_preference_type(c),
392 log_p->pref_abs[c], log_p->pref_norm[c]);
394 GNUNET_asprintf(&prefstring_tmp,"%s;%.3f;%.3f",
395 prefstring, log_p->pref_abs[c], log_p->pref_norm[c]);
398 GNUNET_free (prefstring);
399 prefstring = GNUNET_strdup(prefstring_tmp);
400 GNUNET_free (prefstring_tmp);
404 propstring = GNUNET_strdup("");
405 for (c = 1; c < GNUNET_ATS_PropertyCount; c++)
407 if (GNUNET_ATS_NETWORK_TYPE == c)
410 fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n",
411 GNUNET_ATS_print_property_type(c),
412 log_a->prop_abs[c], log_a->prop_norm[c]);*/
413 GNUNET_asprintf(&propstring_tmp,"%s%.3f;%.3f;",
414 propstring, log_a->prop_abs[c], log_a->prop_norm[c]);
415 GNUNET_free (propstring);
416 propstring = GNUNET_strdup(propstring_tmp);
417 GNUNET_free (propstring_tmp);
419 GNUNET_asprintf (&datastring, "%llu;%llu;%u;%u;%i;%u;%u;%s;%s\n",
420 GNUNET_TIME_absolute_get_difference (l->head->timestamp,
421 lts->timestamp).rel_value_us / 1000, lts->delta,
422 log_p->is_requested, log_a->network, log_a->active,
423 log_a->assigned_bw_in, log_a->assigned_bw_out, propstring,
426 GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring));
427 GNUNET_free (datastring);
428 GNUNET_free (prefstring);
429 GNUNET_free (propstring);
436 for (cur = next; NULL != cur; cur = next)
439 GNUNET_CONTAINER_DLL_remove (lf_head, lf_tail, cur);
440 if (NULL != cur->f_hd)
441 GNUNET_DISK_file_close (cur->f_hd);
448 GNUNET_ATS_solver_logging_eval (struct LoggingHandle *l)
450 struct LoggingTimeStep *lts;
451 struct LoggingPeer *log_p;
452 struct LoggingAddress *log_a;
455 for (lts = l->head; NULL != lts; lts = lts->next)
457 fprintf (stderr, "Log step %llu %llu: \n",
458 (long long unsigned int) lts->timestamp.abs_value_us,
459 (long long unsigned int) lts->delta.rel_value_us);
461 for (log_p = lts->head; NULL != log_p; log_p = log_p->next)
463 fprintf (stderr,"\tLogging peer pid %llu\n", log_p->id);
464 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
466 fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n",
467 GNUNET_ATS_print_preference_type(c),
468 log_p->pref_abs[c], log_p->pref_norm[c]);
471 for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next)
473 fprintf (stderr, "\tPeer pid %llu address %llu: %u %u %u\n",
474 log_p->id, log_a->aid, log_a->active,
475 log_a->assigned_bw_in,
476 log_a->assigned_bw_out);
478 for (c = 1; c < GNUNET_ATS_PropertyCount; c++)
480 if (GNUNET_ATS_NETWORK_TYPE == c)
482 fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n",
483 GNUNET_ATS_print_property_type(c),
484 log_a->prop_abs[c], log_a->prop_norm[c]);
492 GNUNET_ATS_solver_logging_free (struct LoggingHandle *l)
494 struct LoggingTimeStep *lts_cur;
495 struct LoggingTimeStep *lts_next;
496 struct LoggingPeer *log_p_cur;
497 struct LoggingPeer *log_p_next;
498 struct LoggingAddress *log_a_cur;
499 struct LoggingAddress *log_a_next;
501 if (NULL != l->logging_task)
502 GNUNET_SCHEDULER_cancel (l->logging_task);
503 l->logging_task = NULL;
506 while (NULL != (lts_cur = lts_next))
508 lts_next = lts_cur->next;
510 log_p_next = lts_cur->head;
511 while (NULL != (log_p_cur = log_p_next))
513 log_p_next = log_p_cur->next;
515 log_a_next = log_p_cur->addr_head;
516 while (NULL != (log_a_cur = log_a_next))
518 log_a_next = log_a_cur->next;
520 GNUNET_CONTAINER_DLL_remove (log_p_cur->addr_head, log_p_cur->addr_tail, log_a_cur);
521 GNUNET_free (log_a_cur);
524 GNUNET_CONTAINER_DLL_remove (lts_cur->head, lts_cur->tail, log_p_cur);
525 GNUNET_free (log_p_cur);
528 GNUNET_CONTAINER_DLL_remove (l->head, l->tail, lts_cur);
529 GNUNET_free (lts_cur);
536 * Property Generators
539 static struct PropertyGenerator *prop_gen_head;
540 static struct PropertyGenerator *prop_gen_tail;
543 get_property (struct PropertyGenerator *pg)
545 struct GNUNET_TIME_Relative time_delta;
549 /* Calculate the current preference value */
551 case GNUNET_ATS_TEST_TG_CONSTANT:
552 pref_value = pg->base_value;
554 case GNUNET_ATS_TEST_TG_LINEAR:
555 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
556 /* Calculate point of time in the current period */
557 time_delta.rel_value_us = time_delta.rel_value_us %
558 pg->duration_period.rel_value_us;
559 delta_value = ((double) time_delta.rel_value_us /
560 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
561 if ((pg->max_value < pg->base_value) &&
562 ((pg->max_value - pg->base_value) > pg->base_value))
564 /* This will cause an underflow */
567 pref_value = pg->base_value + delta_value;
569 case GNUNET_ATS_TEST_TG_RANDOM:
570 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
571 10000 * (pg->max_value - pg->base_value)) / 10000;
572 pref_value = pg->base_value + delta_value;
574 case GNUNET_ATS_TEST_TG_SINUS:
575 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
576 /* Calculate point of time in the current period */
577 time_delta.rel_value_us = time_delta.rel_value_us %
578 pg->duration_period.rel_value_us;
579 if ((pg->max_value - pg->base_value) > pg->base_value)
581 /* This will cause an underflow for second half of sinus period,
582 * will be detected in general when experiments are loaded */
585 delta_value = (pg->max_value - pg->base_value) *
586 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
587 time_delta.rel_value_us);
588 pref_value = pg->base_value + delta_value;
594 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current property value is %f\n",
601 set_prop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
603 struct PropertyGenerator *pg = cls;
605 struct TestAddress *a;
607 struct GNUNET_ATS_Information atsi;
611 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains_value (sh->addresses,
612 &pg->test_peer->peer_id, pg->test_address->ats_addr))
615 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
616 "Setting property generation for unknown address [%u:%u]\n",
617 pg->peer, pg->address_id);
620 if (NULL == (p = find_peer_by_id (pg->peer)))
623 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
624 "Setting property generation for unknown peer %u\n",
628 if (NULL == (a = find_address_by_id (p, pg->address_id)))
631 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
632 "Setting property generation for unknown peer %u\n",
637 prop_value = get_property (pg);
638 a->prop_abs[pg->ats_property] = prop_value;
640 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
641 "Setting property for peer [%u] address [%u] for %s to %f\n",
642 pg->peer, pg->address_id,
643 GNUNET_ATS_print_property_type (pg->ats_property), prop_value);
645 atsi.type = htonl (pg->ats_property);
646 atsi.value = htonl ((uint32_t) prop_value);
648 /* set performance here! */
649 sh->sf->s_bulk_start (sh->sf->cls);
650 if (GNUNET_YES == opt_disable_normalization)
652 a->prop_abs[pg->ats_property] = prop_value;
653 a->prop_norm[pg->ats_property] = prop_value;
654 sh->sf->s_address_update_property (sh->sf->cls, a->ats_addr,
655 pg->ats_property, prop_value, prop_value);
658 GAS_normalization_normalize_property (pg->test_address->ats_addr, &atsi, 1);
659 sh->sf->s_bulk_stop (sh->sf->cls);
661 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
667 * Set ats_property to 0 to find all pgs
670 static struct PropertyGenerator *
671 find_prop_gen (unsigned int peer, unsigned int address,
672 uint32_t ats_property)
674 struct PropertyGenerator *cur;
675 for (cur = prop_gen_head; NULL != cur; cur = cur->next)
676 if ((cur->peer == peer) && (cur->address_id == address))
678 if ((cur->ats_property == ats_property) || (0 == ats_property))
685 GNUNET_ATS_solver_generate_property_stop (struct PropertyGenerator *pg)
687 GNUNET_CONTAINER_DLL_remove (prop_gen_head, prop_gen_tail, pg);
689 if (NULL != pg->set_task)
691 GNUNET_SCHEDULER_cancel (pg->set_task);
694 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
695 "Removing old up preference generator peer [%u] address [%u] `%s'\n",
696 pg->peer, pg->address_id,
697 GNUNET_ATS_print_property_type(pg->ats_property));
704 * Generate between the source master and the partner and set property with a
705 * value depending on the generator.
708 * @param address_id partner
709 * @param test_peer the peer
710 * @param test_address the address
711 * @param type type of generator
712 * @param base_value base value
713 * @param value_rate maximum value
714 * @param period duration of a period of generation (~ 1/frequency)
715 * @param frequency how long to generate property
716 * @param ats_property ATS property to generate
717 * @return the property generator
719 struct PropertyGenerator *
720 GNUNET_ATS_solver_generate_property_start (unsigned int peer,
721 unsigned int address_id,
722 struct TestPeer *test_peer,
723 struct TestAddress *test_address,
724 enum GeneratorType type,
727 struct GNUNET_TIME_Relative period,
728 struct GNUNET_TIME_Relative frequency,
729 uint32_t ats_property)
731 struct PropertyGenerator *pg;
733 pg = GNUNET_new (struct PropertyGenerator);
734 GNUNET_CONTAINER_DLL_insert (prop_gen_head, prop_gen_tail, pg);
737 pg->test_address = test_address;
738 pg->test_peer = test_peer;
739 pg->address_id = address_id;
740 pg->ats_property = ats_property;
741 pg->base_value = base_value;
742 pg->max_value = value_rate;
743 pg->duration_period = period;
744 pg->frequency = frequency;
745 pg->time_start = GNUNET_TIME_absolute_get();
748 case GNUNET_ATS_TEST_TG_CONSTANT:
749 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
750 "Setting up %s property generator peer [%u] address [%u] `%s'"\
752 print_generator_type(type), pg->peer, pg->address_id,
753 GNUNET_ATS_print_property_type (ats_property),
756 case GNUNET_ATS_TEST_TG_LINEAR:
757 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
758 "Setting up %s property generator peer [%u] address [%u] `%s' " \
759 "min %u Bips max %u Bips\n",
760 print_generator_type(type), pg->peer, pg->address_id,
761 GNUNET_ATS_print_property_type(ats_property),
762 base_value, value_rate);
764 case GNUNET_ATS_TEST_TG_SINUS:
765 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
766 "Setting up %s property generator peer [%u] address [%u] `%s' "\
767 "baserate %u Bips, amplitude %u Bps\n",
768 print_generator_type(type), pg->peer, pg->address_id,
769 GNUNET_ATS_print_property_type(ats_property),
770 base_value, value_rate);
772 case GNUNET_ATS_TEST_TG_RANDOM:
773 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
774 "Setting up %s property generator peer [%u] address [%u] `%s' "\
775 "min %u Bips max %u Bps\n",
776 print_generator_type(type), pg->peer, pg->address_id,
777 GNUNET_ATS_print_property_type(ats_property),
778 base_value, value_rate);
784 pg->set_task = GNUNET_SCHEDULER_add_now (&set_prop_task, pg);
791 * Stop all preferences generators
794 GNUNET_ATS_solver_generate_property_stop_all ()
796 struct PropertyGenerator *cur;
797 struct PropertyGenerator *next;
798 next = prop_gen_head;
799 for (cur = next; NULL != cur; cur = next)
802 GNUNET_ATS_solver_generate_property_stop (cur);
808 * Preference Generators
810 static struct PreferenceGenerator *pref_gen_head;
811 static struct PreferenceGenerator *pref_gen_tail;
815 get_preference (struct PreferenceGenerator *pg)
817 struct GNUNET_TIME_Relative time_delta;
821 /* Calculate the current preference value */
823 case GNUNET_ATS_TEST_TG_CONSTANT:
824 pref_value = pg->base_value;
826 case GNUNET_ATS_TEST_TG_LINEAR:
827 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
828 /* Calculate point of time in the current period */
829 time_delta.rel_value_us = time_delta.rel_value_us %
830 pg->duration_period.rel_value_us;
831 delta_value = ((double) time_delta.rel_value_us /
832 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
833 if ((pg->max_value < pg->base_value) &&
834 ((pg->max_value - pg->base_value) > pg->base_value))
836 /* This will cause an underflow */
839 pref_value = pg->base_value + delta_value;
841 case GNUNET_ATS_TEST_TG_RANDOM:
842 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
843 10000 * (pg->max_value - pg->base_value)) / 10000;
844 pref_value = pg->base_value + delta_value;
846 case GNUNET_ATS_TEST_TG_SINUS:
847 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
848 /* Calculate point of time in the current period */
849 time_delta.rel_value_us = time_delta.rel_value_us %
850 pg->duration_period.rel_value_us;
851 if ((pg->max_value - pg->base_value) > pg->base_value)
853 /* This will cause an underflow for second half of sinus period,
854 * will be detected in general when experiments are loaded */
857 delta_value = (pg->max_value - pg->base_value) *
858 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
859 time_delta.rel_value_us);
860 pref_value = pg->base_value + delta_value;
866 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
872 set_feedback_task (void *cls,
873 const struct GNUNET_SCHEDULER_TaskContext *tc)
875 struct PreferenceGenerator *pg = cls;
880 uint32_t delay_acc_in;
881 struct GNUNET_TIME_Relative dur;
884 pg->feedback_task = NULL;
886 if (NULL == (p = find_peer_by_id (pg->peer)))
889 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
890 "Setting feedback for unknown peer %u\n", pg->peer);
896 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
897 dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update);
898 bw_acc_in = dur.rel_value_us *pg->last_assigned_bw_in + pg->feedback_bw_in_acc;
899 pg->feedback_bw_in_acc = 0;
901 bw_acc_out = dur.rel_value_us *pg->last_assigned_bw_out + pg->feedback_bw_out_acc;
902 p_new = get_preference (pg);
903 feedback = (p_new / pg->pref_bw_old) * (bw_acc_in + bw_acc_out) /
904 (2 *GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us);
907 case GNUNET_ATS_PREFERENCE_LATENCY:
908 dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_delay_update);
909 delay_acc_in =dur.rel_value_us *pg->last_delay_value + pg->feedback_delay_acc;
910 pg->feedback_delay_acc = 0;
912 p_new = get_preference (pg);
913 feedback = (p_new / pg->pref_latency_old) * (delay_acc_in) /
914 (GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us);
922 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
923 "Giving feedback for peer [%u] for client %p pref %s of %.3f\n",
924 pg->peer, NULL + (pg->client_id),
925 GNUNET_ATS_print_preference_type (pg->kind),
928 sh->sf->s_feedback (sh->sf->cls, NULL + (pg->client_id), &p->peer_id,
929 pg->feedback_frequency, pg->kind, feedback);
930 pg->feedback_last = GNUNET_TIME_absolute_get();
933 pg->feedback_bw_out_acc = 0;
934 pg->feedback_bw_in_acc = 0;
935 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
937 pg->feedback_delay_acc = 0;
938 pg->feedback_last_delay_update = GNUNET_TIME_absolute_get();
941 pg->feedback_task = GNUNET_SCHEDULER_add_delayed (pg->feedback_frequency,
942 &set_feedback_task, pg);
947 set_pref_task (void *cls,
948 const struct GNUNET_SCHEDULER_TaskContext *tc)
950 struct PreferenceGenerator *pg = cls;
955 if (NULL == (p = find_peer_by_id (pg->peer)))
958 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
959 "Setting preference for unknown peer %u\n", pg->peer);
963 pref_value = get_preference (pg);
965 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
966 pg->pref_bw_old = pref_value;
968 case GNUNET_ATS_PREFERENCE_LATENCY:
969 pg->pref_latency_old = pref_value;
975 p->pref_abs[pg->kind] = pref_value;
977 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
978 "Setting preference for peer [%u] for client %p pref %s to %f\n",
979 pg->peer, NULL + (pg->client_id),
980 GNUNET_ATS_print_preference_type (pg->kind), pref_value);
982 if (GNUNET_YES == opt_disable_normalization)
984 p->pref_abs[pg->kind] = pref_value;
985 p->pref_norm[pg->kind] = pref_value;
986 sh->sf->s_pref (sh->sf->cls, &p->peer_id, pg->kind, pref_value);
989 normalize_preference (NULL + (pg->client_id),
994 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
1000 static struct PreferenceGenerator *
1001 find_pref_gen (unsigned int peer, enum GNUNET_ATS_PreferenceKind kind)
1003 struct PreferenceGenerator *cur;
1004 for (cur = pref_gen_head; NULL != cur; cur = cur->next)
1005 if (cur->peer == peer)
1007 if ((cur->kind == kind) || (GNUNET_ATS_PREFERENCE_END == kind))
1014 GNUNET_ATS_solver_generate_preferences_stop (struct PreferenceGenerator *pg)
1016 GNUNET_CONTAINER_DLL_remove (pref_gen_head, pref_gen_tail, pg);
1018 if (NULL != pg->feedback_task)
1020 GNUNET_SCHEDULER_cancel (pg->feedback_task);
1021 pg->feedback_task = NULL;
1024 if (NULL != pg->set_task)
1026 GNUNET_SCHEDULER_cancel (pg->set_task);
1027 pg->set_task = NULL;
1029 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1030 "Removing old up preference generator peer [%u] `%s'\n",
1031 pg->peer, GNUNET_ATS_print_preference_type(pg->kind));
1037 find_active_address (struct TestPeer *p)
1039 struct TestAddress *cur;
1040 for (cur = p->addr_head; NULL != cur; cur = cur->next)
1041 if (GNUNET_YES == cur->ats_addr->active)
1047 * Generate between the source master and the partner and set property with a
1048 * value depending on the generator.
1050 * @param peer source
1051 * @param address_id partner
1052 * @param client_id the client
1053 * @param type type of generator
1054 * @param base_value base value
1055 * @param value_rate maximum value
1056 * @param period duration of a period of generation (~ 1/frequency)
1057 * @param frequency how long to generate property
1058 * @param kind ATS preference to generate
1059 * @param feedback_frequency how often to give feedback
1060 * @return the preference generator
1062 struct PreferenceGenerator *
1063 GNUNET_ATS_solver_generate_preferences_start (unsigned int peer,
1064 unsigned int address_id,
1065 unsigned int client_id,
1066 enum GeneratorType type,
1067 long int base_value,
1068 long int value_rate,
1069 struct GNUNET_TIME_Relative period,
1070 struct GNUNET_TIME_Relative frequency,
1071 enum GNUNET_ATS_PreferenceKind kind,
1072 struct GNUNET_TIME_Relative feedback_frequency)
1074 struct PreferenceGenerator *pg;
1077 if (NULL == (p = find_peer_by_id (peer)))
1080 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1081 "Starting preference for unknown peer %u\n", peer);
1085 pg = GNUNET_new (struct PreferenceGenerator);
1086 GNUNET_CONTAINER_DLL_insert (pref_gen_head, pref_gen_tail, pg);
1089 pg->client_id = client_id;
1091 pg->base_value = base_value;
1092 pg->max_value = value_rate;
1093 pg->duration_period = period;
1094 pg->frequency = frequency;
1095 pg->time_start = GNUNET_TIME_absolute_get();
1096 pg->feedback_frequency = feedback_frequency;
1099 case GNUNET_ATS_TEST_TG_CONSTANT:
1100 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1101 "Setting up %s preference generator peer [%u] `%s' max %u Bips\n",
1102 print_generator_type (type), pg->peer,
1103 GNUNET_ATS_print_preference_type(kind),
1106 case GNUNET_ATS_TEST_TG_LINEAR:
1107 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1108 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bips\n",
1109 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1110 base_value, value_rate);
1112 case GNUNET_ATS_TEST_TG_SINUS:
1113 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1114 "Setting up %s preference generator peer [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
1115 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1116 base_value, value_rate);
1118 case GNUNET_ATS_TEST_TG_RANDOM:
1119 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1120 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bps\n",
1121 print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
1122 base_value, value_rate);
1128 pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, pg);
1129 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != feedback_frequency.rel_value_us)
1131 struct TestAddress * addr = find_active_address(p);
1132 const double *properties = get_property_cb (NULL, addr->ats_addr);
1134 pg->last_assigned_bw_in = p->assigned_bw_in;
1135 pg->last_assigned_bw_out = p->assigned_bw_out;
1136 pg->feedback_bw_in_acc = 0;
1137 pg->feedback_bw_out_acc = 0;
1139 pg->last_delay_value = properties[GNUNET_ATS_QUALITY_NET_DELAY];
1140 pg->feedback_delay_acc = 0;
1142 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
1143 pg->feedback_last_delay_update = GNUNET_TIME_absolute_get();
1144 pg->feedback_last = GNUNET_TIME_absolute_get();
1145 pg->feedback_task = GNUNET_SCHEDULER_add_delayed (feedback_frequency,
1146 &set_feedback_task, pg);
1155 * Stop all preferences generators
1158 GNUNET_ATS_solver_generate_preferences_stop_all ()
1160 struct PreferenceGenerator *cur;
1161 struct PreferenceGenerator *next;
1162 next = pref_gen_head;
1163 for (cur = next; NULL != cur; cur = next)
1166 GNUNET_ATS_solver_generate_preferences_stop(cur);
1177 print_op (enum OperationType op)
1180 case SOLVER_OP_ADD_ADDRESS:
1181 return "ADD_ADDRESS";
1182 case SOLVER_OP_DEL_ADDRESS:
1183 return "DEL_ADDRESS";
1184 case SOLVER_OP_START_SET_PREFERENCE:
1185 return "START_SET_PREFERENCE";
1186 case SOLVER_OP_STOP_SET_PREFERENCE:
1187 return "STOP_STOP_PREFERENCE";
1188 case SOLVER_OP_START_SET_PROPERTY:
1189 return "START_SET_PROPERTY";
1190 case SOLVER_OP_STOP_SET_PROPERTY:
1191 return "STOP_SET_PROPERTY";
1192 case SOLVER_OP_START_REQUEST:
1193 return "START_REQUEST";
1194 case SOLVER_OP_STOP_REQUEST:
1195 return "STOP_REQUEST";
1202 static struct Experiment *
1203 create_experiment ()
1205 struct Experiment *e;
1206 e = GNUNET_new (struct Experiment);
1209 e->total_duration = GNUNET_TIME_UNIT_ZERO;
1214 free_experiment (struct Experiment *e)
1216 struct Episode *cur;
1217 struct Episode *next;
1218 struct GNUNET_ATS_TEST_Operation *cur_o;
1219 struct GNUNET_ATS_TEST_Operation *next_o;
1222 for (cur = next; NULL != cur; cur = next)
1227 for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
1229 next_o = cur_o->next;
1230 GNUNET_free_non_null (cur_o->address);
1231 GNUNET_free_non_null (cur_o->plugin);
1232 GNUNET_free (cur_o);
1237 GNUNET_free_non_null (e->name);
1238 GNUNET_free_non_null (e->log_prefix);
1239 GNUNET_free_non_null (e->log_output_dir);
1240 GNUNET_free_non_null (e->cfg_file);
1246 load_op_add_address (struct GNUNET_ATS_TEST_Operation *o,
1250 const struct GNUNET_CONFIGURATION_Handle *cfg)
1256 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1257 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1258 sec_name, op_name, &o->peer_id))
1260 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1261 op_counter, "ADD_ADDRESS", op_name);
1262 GNUNET_free (op_name);
1263 return GNUNET_SYSERR;
1265 GNUNET_free (op_name);
1268 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1269 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1270 sec_name, op_name, &o->address_id))
1272 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1273 op_counter, "ADD_ADDRESS", op_name);
1274 GNUNET_free (op_name);
1275 return GNUNET_SYSERR;
1277 GNUNET_free (op_name);
1280 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
1281 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1282 sec_name, op_name, &o->plugin))
1284 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
1285 op_counter, "ADD_ADDRESS", op_name);
1286 GNUNET_free (op_name);
1287 return GNUNET_SYSERR;
1289 GNUNET_free (op_name);
1292 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
1293 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1294 sec_name, op_name, &o->address))
1296 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
1297 op_counter, "ADD_ADDRESS", op_name);
1298 GNUNET_free (op_name);
1299 return GNUNET_SYSERR;
1301 GNUNET_free (op_name);
1304 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
1305 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1306 sec_name, op_name, &o->address_session))
1308 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
1309 op_counter, "ADD_ADDRESS", op_name);
1310 GNUNET_free (op_name);
1311 return GNUNET_SYSERR;
1313 GNUNET_free (op_name);
1316 GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter);
1317 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1318 sec_name, op_name, &op_network))
1320 fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
1321 op_counter, "ADD_ADDRESS", op_name);
1322 GNUNET_free (op_name);
1323 return GNUNET_SYSERR;
1327 GNUNET_STRINGS_utf8_toupper (op_network,op_network);
1328 if (0 == strcmp(op_network, "UNSPECIFIED"))
1330 o->address_network = GNUNET_ATS_NET_UNSPECIFIED;
1332 else if (0 == strcmp(op_network, "LOOPBACK"))
1334 o->address_network = GNUNET_ATS_NET_LOOPBACK;
1336 else if (0 == strcmp(op_network, "LAN"))
1338 o->address_network = GNUNET_ATS_NET_LAN;
1340 else if (0 == strcmp(op_network, "WAN"))
1342 o->address_network = GNUNET_ATS_NET_WAN;
1344 else if (0 == strcmp(op_network, "WLAN"))
1346 o->address_network = GNUNET_ATS_NET_WLAN;
1348 else if (0 == strcmp(op_network, "BT"))
1350 o->address_network = GNUNET_ATS_NET_BT;
1354 fprintf (stderr, "Invalid address-network in operation %u `%s' in episode `%s': `%s'\n",
1355 op_counter, "ADD_ADDRESS", op_name, op_network);
1356 GNUNET_free (op_network);
1357 GNUNET_free (op_name);
1358 return GNUNET_SYSERR;
1361 GNUNET_free (op_network);
1362 GNUNET_free (op_name);
1364 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1365 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
1366 "ADD_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
1372 load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
1376 const struct GNUNET_CONFIGURATION_Handle *cfg)
1382 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1383 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1384 sec_name, op_name, &o->peer_id))
1386 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1387 op_counter, "DEL_ADDRESS", op_name);
1388 GNUNET_free (op_name);
1389 return GNUNET_SYSERR;
1391 GNUNET_free (op_name);
1394 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1395 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1396 sec_name, op_name, &o->address_id))
1398 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1399 op_counter, "DEL_ADDRESS", op_name);
1400 GNUNET_free (op_name);
1401 return GNUNET_SYSERR;
1403 GNUNET_free (op_name);
1407 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
1408 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1409 sec_name, op_name, &o->plugin))
1411 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
1412 op_counter, "DEL_ADDRESS", op_name);
1413 GNUNET_free (op_name);
1414 return GNUNET_SYSERR;
1416 GNUNET_free (op_name);
1419 GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
1420 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1421 sec_name, op_name, &o->address))
1423 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
1424 op_counter, "DEL_ADDRESS", op_name);
1425 GNUNET_free (op_name);
1426 return GNUNET_SYSERR;
1428 GNUNET_free (op_name);
1431 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
1432 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1433 sec_name, op_name, &o->address_session))
1435 fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
1436 op_counter, "DEL_ADDRESS", op_name);
1437 GNUNET_free (op_name);
1438 return GNUNET_SYSERR;
1440 GNUNET_free (op_name);
1443 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1444 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
1445 "DEL_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
1450 static enum GNUNET_ATS_Property
1451 parse_preference_string (const char * str)
1454 char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
1456 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
1457 if (0 == strcmp(str, props[c]))
1463 load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1467 const struct GNUNET_CONFIGURATION_Handle *cfg)
1474 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1475 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1476 sec_name, op_name, &o->peer_id))
1478 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1479 op_counter, "START_SET_PREFERENCE", op_name);
1480 GNUNET_free (op_name);
1481 return GNUNET_SYSERR;
1483 GNUNET_free (op_name);
1486 GNUNET_asprintf(&op_name, "op-%u-client-id", op_counter);
1487 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1488 sec_name, op_name, &o->client_id))
1490 fprintf (stderr, "Missing client-id in operation %u `%s' in episode `%s'\n",
1491 op_counter, "START_SET_PREFERENCE", op_name);
1492 GNUNET_free (op_name);
1493 return GNUNET_SYSERR;
1495 GNUNET_free (op_name);
1498 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1499 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1500 sec_name, op_name, &type)) )
1502 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1503 op_counter, "START_SET_PREFERENCE", op_name);
1504 GNUNET_free (op_name);
1505 return GNUNET_SYSERR;
1508 /* Load arguments for set_rate, start_send, set_preference */
1509 if (0 == strcmp (type, "constant"))
1511 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1513 else if (0 == strcmp (type, "linear"))
1515 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1517 else if (0 == strcmp (type, "sinus"))
1519 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1521 else if (0 == strcmp (type, "random"))
1523 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1527 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1528 op_counter, op_name, e->id);
1530 GNUNET_free (op_name);
1531 return GNUNET_SYSERR;
1534 GNUNET_free (op_name);
1538 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1539 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1540 sec_name, op_name, &o->base_rate))
1542 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1543 op_counter, op_name, e->id);
1544 GNUNET_free (op_name);
1545 return GNUNET_SYSERR;
1547 GNUNET_free (op_name);
1551 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1552 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1553 sec_name, op_name, &o->max_rate))
1555 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1556 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1557 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1559 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1560 op_counter, op_name, e->id);
1561 GNUNET_free (op_name);
1562 return GNUNET_SYSERR;
1565 GNUNET_free (op_name);
1568 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1569 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1570 sec_name, op_name, &o->period))
1572 o->period = e->duration;
1574 GNUNET_free (op_name);
1577 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1578 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1579 sec_name, op_name, &o->frequency))
1581 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1582 op_counter, op_name, e->id);
1583 GNUNET_free (op_name);
1584 return GNUNET_SYSERR;
1586 GNUNET_free (op_name);
1588 /* Get preference */
1589 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1590 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1591 sec_name, op_name, &pref))
1593 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
1594 op_counter, op_name, e->id);
1595 GNUNET_free (op_name);
1596 return GNUNET_SYSERR;
1599 if (0 == (o->pref_type = parse_preference_string(pref)))
1601 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1602 op_counter, op_name, e->id);
1603 GNUNET_free (op_name);
1605 return GNUNET_SYSERR;
1608 GNUNET_free (op_name);
1610 /* Get feedback delay */
1611 GNUNET_asprintf(&op_name, "op-%u-feedback_delay", op_counter);
1612 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time (cfg,
1613 sec_name, op_name, &o->feedback_delay))
1615 fprintf (stderr, "Using feedback delay %llu in operation %u `%s' in episode %u\n",
1616 (long long unsigned int) o->feedback_delay.rel_value_us,
1617 op_counter, op_name, e->id);
1620 o->feedback_delay = GNUNET_TIME_UNIT_FOREVER_REL;
1621 GNUNET_free (op_name);
1623 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1624 "Found operation %s: [%llu:%llu]: %s = %llu\n",
1625 "START_SET_PREFERENCE", o->peer_id, o->address_id,
1626 GNUNET_ATS_print_preference_type(o->pref_type), o->base_rate);
1632 load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1636 const struct GNUNET_CONFIGURATION_Handle *cfg)
1642 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1643 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1644 sec_name, op_name, &o->peer_id))
1646 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1647 op_counter, "STOP_SET_PREFERENCE", op_name);
1648 GNUNET_free (op_name);
1649 return GNUNET_SYSERR;
1651 GNUNET_free (op_name);
1654 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1655 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1656 sec_name, op_name, &o->address_id))
1658 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1659 op_counter, "STOP_SET_PREFERENCE", op_name);
1660 GNUNET_free (op_name);
1661 return GNUNET_SYSERR;
1663 GNUNET_free (op_name);
1665 /* Get preference */
1666 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
1667 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1668 sec_name, op_name, &pref))
1670 fprintf (stderr, "Missing preference in operation %u `%s' in episode `%s'\n",
1671 op_counter, "STOP_SET_PREFERENCE", op_name);
1672 GNUNET_free (op_name);
1673 return GNUNET_SYSERR;
1676 if (0 == (o->pref_type = parse_preference_string(pref)))
1678 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1679 op_counter, op_name, e->id);
1680 GNUNET_free (op_name);
1682 return GNUNET_SYSERR;
1685 GNUNET_free (op_name);
1687 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1688 "Found operation %s: [%llu:%llu]: %s\n",
1689 "STOP_SET_PREFERENCE", o->peer_id, o->address_id,
1690 GNUNET_ATS_print_preference_type(o->pref_type));
1695 static enum GNUNET_ATS_Property
1696 parse_property_string (const char *str)
1698 enum GNUNET_ATS_Property c;
1700 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
1701 if (0 == strcmp(str,
1702 GNUNET_ATS_print_property_type (c)))
1709 load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o,
1713 const struct GNUNET_CONFIGURATION_Handle *cfg)
1720 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1721 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1722 sec_name, op_name, &o->peer_id))
1724 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1725 op_counter, "START_SET_PROPERTY", op_name);
1726 GNUNET_free (op_name);
1727 return GNUNET_SYSERR;
1729 GNUNET_free (op_name);
1732 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1733 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1734 sec_name, op_name, &o->address_id))
1736 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1737 op_counter, "START_SET_PROPERTY", op_name);
1738 GNUNET_free (op_name);
1739 return GNUNET_SYSERR;
1741 GNUNET_free (op_name);
1744 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
1745 if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1746 sec_name, op_name, &type)) )
1748 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1749 op_counter, "START_SET_PROPERTY", op_name);
1750 GNUNET_free (op_name);
1751 return GNUNET_SYSERR;
1754 /* Load arguments for set_rate, start_send, set_preference */
1755 if (0 == strcmp (type, "constant"))
1757 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1759 else if (0 == strcmp (type, "linear"))
1761 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1763 else if (0 == strcmp (type, "sinus"))
1765 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1767 else if (0 == strcmp (type, "random"))
1769 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1773 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1774 op_counter, op_name, e->id);
1776 GNUNET_free (op_name);
1777 return GNUNET_SYSERR;
1780 GNUNET_free (op_name);
1784 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
1785 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1786 sec_name, op_name, &o->base_rate))
1788 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1789 op_counter, op_name, e->id);
1790 GNUNET_free (op_name);
1791 return GNUNET_SYSERR;
1793 GNUNET_free (op_name);
1797 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
1798 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1799 sec_name, op_name, &o->max_rate))
1801 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1802 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1803 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1805 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1806 op_counter, op_name, e->id);
1807 GNUNET_free (op_name);
1808 return GNUNET_SYSERR;
1811 GNUNET_free (op_name);
1814 GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
1815 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1816 sec_name, op_name, &o->period))
1818 o->period = e->duration;
1820 GNUNET_free (op_name);
1823 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
1824 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1825 sec_name, op_name, &o->frequency))
1827 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1828 op_counter, op_name, e->id);
1829 GNUNET_free (op_name);
1830 return GNUNET_SYSERR;
1832 GNUNET_free (op_name);
1834 /* Get preference */
1835 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1836 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1837 sec_name, op_name, &prop))
1839 fprintf (stderr, "Missing property in operation %u `%s' in episode %u\n",
1840 op_counter, op_name, e->id);
1841 GNUNET_free (op_name);
1842 GNUNET_free_non_null (prop);
1843 return GNUNET_SYSERR;
1846 if (0 == (o->prop_type = parse_property_string(prop)))
1848 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1849 op_counter, op_name, e->id);
1850 GNUNET_free (op_name);
1852 return GNUNET_SYSERR;
1856 GNUNET_free (op_name);
1858 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1859 "Found operation %s: [%llu:%llu] %s = %llu\n",
1860 "START_SET_PROPERTY", o->peer_id, o->address_id,
1861 GNUNET_ATS_print_property_type (o->prop_type), o->base_rate);
1867 load_op_stop_set_property (struct GNUNET_ATS_TEST_Operation *o,
1871 const struct GNUNET_CONFIGURATION_Handle *cfg)
1877 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1878 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1879 sec_name, op_name, &o->peer_id))
1881 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1882 op_counter, "STOP_SET_PROPERTY", op_name);
1883 GNUNET_free (op_name);
1884 return GNUNET_SYSERR;
1886 GNUNET_free (op_name);
1889 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
1890 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1891 sec_name, op_name, &o->address_id))
1893 fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
1894 op_counter, "STOP_SET_PROPERTY", op_name);
1895 GNUNET_free (op_name);
1896 return GNUNET_SYSERR;
1898 GNUNET_free (op_name);
1901 GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
1902 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1903 sec_name, op_name, &pref))
1905 fprintf (stderr, "Missing property in operation %u `%s' in episode `%s'\n",
1906 op_counter, "STOP_SET_PROPERTY", op_name);
1907 GNUNET_free (op_name);
1908 GNUNET_free_non_null (pref);
1909 return GNUNET_SYSERR;
1912 if (0 == (o->prop_type = parse_property_string(pref)))
1914 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1915 op_counter, op_name, e->id);
1916 GNUNET_free (op_name);
1917 GNUNET_free_non_null (pref);
1918 return GNUNET_SYSERR;
1922 GNUNET_free (op_name);
1924 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1925 "Found operation %s: [%llu:%llu] %s\n",
1926 "STOP_SET_PROPERTY", o->peer_id, o->address_id,
1927 GNUNET_ATS_print_property_type (o->prop_type));
1934 load_op_start_request (struct GNUNET_ATS_TEST_Operation *o,
1938 const struct GNUNET_CONFIGURATION_Handle *cfg)
1943 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
1944 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1945 sec_name, op_name, &o->peer_id))
1947 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1948 op_counter, "START_REQUEST", op_name);
1949 GNUNET_free (op_name);
1950 return GNUNET_SYSERR;
1952 GNUNET_free (op_name);
1957 load_op_stop_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, "STOP_REQUEST", op_name);
1972 GNUNET_free (op_name);
1973 return GNUNET_SYSERR;
1975 GNUNET_free (op_name);
1981 load_episode (struct Experiment *e, struct Episode *cur,
1982 struct GNUNET_CONFIGURATION_Handle *cfg)
1984 struct GNUNET_ATS_TEST_Operation *o;
1990 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Parsing episode %u\n",cur->id);
1991 GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
1995 /* Load operation */
1996 GNUNET_asprintf(&op_name, "op-%u-operation", op_counter);
1997 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
1998 sec_name, op_name, &op))
2000 GNUNET_free (op_name);
2003 o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
2004 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "==== Parsing operation %u: `%s'\n",
2007 /* operations = set_rate, start_send, stop_send, set_preference */
2008 if (0 == strcmp (op, "address_add"))
2010 o->type = SOLVER_OP_ADD_ADDRESS;
2011 res = load_op_add_address (o, cur,
2012 op_counter, sec_name, cfg);
2014 else if (0 == strcmp (op, "address_del"))
2016 o->type = SOLVER_OP_DEL_ADDRESS;
2017 res = load_op_del_address (o, cur,
2018 op_counter, sec_name, cfg);
2020 else if (0 == strcmp (op, "start_set_property"))
2022 o->type = SOLVER_OP_START_SET_PROPERTY;
2023 res = load_op_start_set_property (o, cur,
2024 op_counter, sec_name, cfg);
2026 else if (0 == strcmp (op, "stop_set_property"))
2028 o->type = SOLVER_OP_STOP_SET_PROPERTY;
2029 res = load_op_stop_set_property (o, cur,
2030 op_counter, sec_name, cfg);
2032 else if (0 == strcmp (op, "start_set_preference"))
2034 o->type = SOLVER_OP_START_SET_PREFERENCE;
2035 res = load_op_start_set_preference (o, cur,
2036 op_counter, sec_name, cfg);
2038 else if (0 == strcmp (op, "stop_set_preference"))
2040 o->type = SOLVER_OP_STOP_SET_PREFERENCE;
2041 res = load_op_stop_set_preference (o, cur,
2042 op_counter, sec_name, cfg);
2044 else if (0 == strcmp (op, "start_request"))
2046 o->type = SOLVER_OP_START_REQUEST;
2047 res = load_op_start_request (o, cur,
2048 op_counter, sec_name, cfg);
2050 else if (0 == strcmp (op, "stop_request"))
2052 o->type = SOLVER_OP_STOP_REQUEST;
2053 res = load_op_stop_request(o, cur,
2054 op_counter, sec_name, cfg);
2058 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
2059 op_counter, op, cur->id);
2060 res = GNUNET_SYSERR;
2064 GNUNET_free (op_name);
2066 if (GNUNET_SYSERR == res)
2069 GNUNET_free (sec_name);
2070 return GNUNET_SYSERR;
2073 GNUNET_CONTAINER_DLL_insert_tail (cur->head,cur->tail, o);
2076 GNUNET_free (sec_name);
2081 load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
2085 struct GNUNET_TIME_Relative e_duration;
2086 struct Episode *cur;
2087 struct Episode *last;
2093 GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
2094 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
2095 sec_name, "duration", &e_duration))
2097 GNUNET_free (sec_name);
2101 cur = GNUNET_new (struct Episode);
2102 cur->duration = e_duration;
2103 cur->id = e_counter;
2105 if (GNUNET_OK != load_episode (e, cur, cfg))
2107 GNUNET_free (sec_name);
2109 return GNUNET_SYSERR;
2112 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Found episode %u with duration %s \n",
2114 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
2116 /* Update experiment */
2118 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
2119 /* Put in linked list */
2125 GNUNET_free (sec_name);
2133 timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
2135 struct Experiment *e = cls;
2136 e->experiment_timeout_task = NULL;
2137 fprintf (stderr, "Experiment timeout!\n");
2139 if (NULL != e->episode_timeout_task)
2141 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2142 e->episode_timeout_task = NULL;
2145 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
2149 struct ATS_Address *
2150 create_ats_address (const struct GNUNET_PeerIdentity *peer,
2151 const char *plugin_name,
2152 const void *plugin_addr,
2153 size_t plugin_addr_len,
2154 uint32_t session_id,
2157 struct ATS_Address *aa = NULL;
2159 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1);
2160 aa->atsi = GNUNET_new (struct GNUNET_ATS_Information);
2161 aa->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
2162 aa->atsi[0].value = htonl (network);
2166 aa->addr_len = plugin_addr_len;
2168 aa->plugin = (char *) &aa[1] + plugin_addr_len;
2169 memcpy (&aa[1], plugin_addr, plugin_addr_len);
2170 memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
2171 aa->session_id = session_id;
2179 enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
2182 struct TestAddress *a;
2185 if (NULL == (p = find_peer_by_id (op->peer_id)))
2187 p = GNUNET_new (struct TestPeer);
2188 p->id = op->peer_id;
2189 p->assigned_bw_in = 0;
2190 p->assigned_bw_out = 0;
2191 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
2192 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
2194 p->pref_abs[c] = DEFAULT_ABS_PREFERENCE;
2195 p->pref_norm[c] = DEFAULT_REL_PREFERENCE;
2198 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p);
2201 if (NULL != (find_address_by_id (p, op->address_id)))
2203 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Duplicate address %u for peer %u\n",
2204 op->address_id, op->peer_id);
2208 a = GNUNET_new (struct TestAddress);
2209 a->aid = op->address_id;
2210 a->network = op->address_network;
2211 a->ats_addr = create_ats_address (&p->peer_id, op->plugin, op->address,
2212 strlen (op->address) + 1, op->address_session, op->address_network);
2213 memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
2214 GNUNET_CONTAINER_DLL_insert_tail (p->addr_head, p->addr_tail, a);
2216 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
2217 a->prop_norm[c] = DEFAULT_REL_QUALITY;
2219 GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, a->ats_addr,
2220 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2222 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u in network `%s'\n",
2223 op->address_id, op->peer_id, GNUNET_ATS_print_network_type(a->network));
2225 sh->sf->s_add (sh->sf->cls, a->ats_addr, op->address_network);
2231 enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
2234 struct TestAddress *a;
2235 struct PropertyGenerator *pg;
2237 if (NULL == (p = find_peer_by_id (op->peer_id)))
2240 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2241 "Deleting address for unknown peer %u\n", op->peer_id);
2245 if (NULL == (a =find_address_by_id (p, op->address_id)))
2248 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2249 "Deleting address for unknown peer %u\n", op->peer_id);
2253 while (NULL != (pg = find_prop_gen (p->id, a->aid, 0)))
2255 GNUNET_ATS_solver_generate_property_stop (pg);
2258 GNUNET_assert (GNUNET_YES ==
2259 GNUNET_CONTAINER_multipeermap_remove (sh->addresses,
2262 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2263 "Removing address %u for peer %u\n",
2267 sh->sf->s_del (sh->sf->cls, a->ats_addr, GNUNET_NO);
2271 GNUNET_ATS_solver_logging_now (l);
2273 GNUNET_CONTAINER_DLL_remove(p->addr_head, p->addr_tail, a);
2275 GNUNET_free_non_null(a->ats_addr->atsi);
2276 GNUNET_free (a->ats_addr);
2282 enforce_start_property (struct GNUNET_ATS_TEST_Operation *op)
2284 struct PropertyGenerator *pg;
2286 struct TestAddress *a;
2288 if (NULL != (pg = find_prop_gen (op->peer_id, op->address_id, op->prop_type)))
2290 GNUNET_ATS_solver_generate_property_stop (pg);
2294 if (NULL == (p = find_peer_by_id (op->peer_id)))
2297 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2298 "Starting property generation for unknown peer %u\n", op->peer_id);
2302 if (NULL == (a = find_address_by_id (p, op->address_id)))
2305 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2306 "Setting property for unknown address %u\n", op->peer_id);
2310 GNUNET_ATS_solver_generate_property_start (op->peer_id,
2322 enforce_stop_property (struct GNUNET_ATS_TEST_Operation *op)
2324 struct PropertyGenerator *pg = find_prop_gen(op->peer_id, op->address_id,
2328 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2329 "Stopping preference generation for peer %u address %u\n", op->peer_id,
2331 GNUNET_ATS_solver_generate_property_stop (pg);
2335 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2336 "Cannot find preference generator for peer %u address %u\n",
2337 op->peer_id, op->address_id);
2343 enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
2345 struct PreferenceGenerator *pg;
2346 if (NULL != (pg = find_pref_gen (op->peer_id, op->pref_type)))
2348 GNUNET_ATS_solver_generate_preferences_stop (pg);
2352 if (NULL == (find_peer_by_id (op->peer_id)))
2355 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2356 "Starting preference generation for unknown peer %u\n", op->peer_id);
2360 GNUNET_ATS_solver_generate_preferences_start (op->peer_id,
2373 enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
2375 struct PreferenceGenerator *pg = find_pref_gen(op->peer_id,
2379 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2380 "Stopping property generation for peer %u address %u\n", op->peer_id,
2382 GNUNET_ATS_solver_generate_preferences_stop (pg);
2386 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2387 "Cannot find preference generator for peer %u address %u\n",
2388 op->peer_id, op->address_id);
2395 enforce_start_request (struct GNUNET_ATS_TEST_Operation *op)
2398 const struct ATS_Address *res;
2400 if (NULL == (p = find_peer_by_id (op->peer_id)))
2403 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2404 "Requesting address for unknown peer %u\n", op->peer_id);
2408 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n",
2410 p->is_requested = GNUNET_YES;
2412 res = sh->sf->s_get (sh->sf->cls, &p->peer_id);
2415 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Suggested address for peer %u: %llu %llu\n",
2417 res->assigned_bw_in,
2418 res->assigned_bw_out);
2420 GNUNET_ATS_solver_logging_now (l);
2425 enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op)
2429 if (NULL == (p = find_peer_by_id (op->peer_id)))
2432 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2433 "Requesting address for unknown peer %u\n", op->peer_id);
2439 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop requesting address for peer %u\n",
2441 p->is_requested = GNUNET_NO;
2442 p->assigned_bw_in = 0;
2443 p->assigned_bw_out = 0;
2444 sh->sf->s_get_stop (sh->sf->cls, &p->peer_id);
2448 GNUNET_ATS_solver_logging_now (l);
2453 static void enforce_episode (struct Episode *ep)
2455 struct GNUNET_ATS_TEST_Operation *cur;
2456 for (cur = ep->head; NULL != cur; cur = cur->next)
2458 switch (cur->type) {
2459 case SOLVER_OP_ADD_ADDRESS:
2460 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2461 print_op (cur->type), cur->peer_id, cur->address_id);
2462 enforce_add_address (cur);
2464 case SOLVER_OP_DEL_ADDRESS:
2465 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2466 print_op (cur->type), cur->peer_id, cur->address_id);
2467 enforce_del_address (cur);
2469 case SOLVER_OP_START_SET_PROPERTY:
2470 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2471 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2472 enforce_start_property (cur);
2474 case SOLVER_OP_STOP_SET_PROPERTY:
2475 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2476 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2477 enforce_stop_property (cur);
2479 case SOLVER_OP_START_SET_PREFERENCE:
2480 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2481 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2482 enforce_start_preference (cur);
2484 case SOLVER_OP_STOP_SET_PREFERENCE:
2485 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2486 print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
2487 enforce_stop_preference (cur);
2489 case SOLVER_OP_START_REQUEST:
2490 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2491 print_op (cur->type), cur->peer_id);
2492 enforce_start_request (cur);
2494 case SOLVER_OP_STOP_REQUEST:
2495 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2496 print_op (cur->type), cur->peer_id);
2497 enforce_stop_request (cur);
2506 timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
2508 struct Experiment *e = cls;
2509 e->episode_timeout_task = NULL;
2510 if (NULL != e->ep_done_cb)
2511 e->ep_done_cb (e->cur);
2513 /* Scheduling next */
2514 e->cur = e->cur->next;
2518 fprintf (stderr, "Last episode done!\n");
2519 if (NULL != e->experiment_timeout_task)
2521 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2522 e->experiment_timeout_task = NULL;
2524 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
2528 fprintf (stderr, "Running episode %u with timeout %s\n",
2530 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2531 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2532 &timeout_episode, e);
2533 enforce_episode(e->cur);
2540 GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
2541 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
2542 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
2544 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
2545 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
2546 e->e_done_cb = e_done_cb;
2547 e->ep_done_cb = ep_done_cb;
2548 e->start_time = GNUNET_TIME_absolute_get();
2550 /* Start total time out */
2551 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
2552 &timeout_experiment, e);
2555 if (NULL == e->start)
2562 fprintf (stderr, "Running episode %u with timeout %s\n",
2564 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
2565 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2566 &timeout_episode, e);
2567 enforce_episode(e->cur);
2572 GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
2574 if (NULL != e->experiment_timeout_task)
2576 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2577 e->experiment_timeout_task = NULL;
2579 if (NULL != e->episode_timeout_task)
2581 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2582 e->episode_timeout_task = NULL;
2586 GNUNET_CONFIGURATION_destroy(e->cfg);
2589 free_experiment (e);
2594 GNUNET_ATS_solvers_experimentation_load (char *filename)
2596 struct Experiment *e;
2597 struct GNUNET_CONFIGURATION_Handle *cfg;
2600 cfg = GNUNET_CONFIGURATION_create();
2601 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
2603 fprintf (stderr, "Failed to load `%s'\n", filename);
2604 GNUNET_CONFIGURATION_destroy (cfg);
2608 e = create_experiment ();
2610 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2613 fprintf (stderr, "Invalid %s \n", "name");
2614 free_experiment (e);
2618 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment name: `%s'\n", e->name);
2620 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
2621 "log_prefix", &e->log_prefix))
2623 fprintf (stderr, "Invalid %s \n", "log_prefix");
2624 free_experiment (e);
2628 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging prefix: `%s'\n",
2631 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2632 "log_output_dir", &e->log_output_dir))
2634 e->log_output_dir = NULL;
2637 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging output directory: `%s'\n",
2641 if (GNUNET_SYSERR == (e->log_append_time_stamp = GNUNET_CONFIGURATION_get_value_yesno(cfg,
2642 "experiment", "log_append_time_stamp")))
2643 e->log_append_time_stamp = GNUNET_YES;
2644 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging append timestamp: `%s'\n",
2645 (GNUNET_YES == e->log_append_time_stamp) ? "yes" : "no");
2648 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
2649 "cfg_file", &e->cfg_file))
2651 fprintf (stderr, "Invalid %s \n", "cfg_file");
2652 free_experiment (e);
2657 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment configuration: `%s'\n", e->cfg_file);
2658 e->cfg = GNUNET_CONFIGURATION_create();
2659 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file))
2661 fprintf (stderr, "Invalid configuration %s \n", "cfg_file");
2662 free_experiment (e);
2668 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2669 "log_freq", &e->log_freq))
2671 fprintf (stderr, "Invalid %s \n", "log_freq");
2672 free_experiment (e);
2676 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging frequency: `%s'\n",
2677 GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
2679 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2680 "max_duration", &e->max_duration))
2682 fprintf (stderr, "Invalid %s", "max_duration");
2683 free_experiment (e);
2687 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment duration: `%s'\n",
2688 GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
2690 if (GNUNET_SYSERR == load_episodes (e, cfg))
2692 GNUNET_ATS_solvers_experimentation_stop (e);
2693 GNUNET_CONFIGURATION_destroy (cfg);
2695 fprintf (stderr, "Failed to load experiment\n");
2698 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loaded %u episodes with total duration %s\n",
2700 GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
2702 GNUNET_CONFIGURATION_destroy (cfg);
2713 free_all_it (void *cls,
2714 const struct GNUNET_PeerIdentity *key,
2717 struct ATS_Address *address = value;
2718 GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (sh->env.addresses,
2720 GNUNET_free (address);
2726 GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh)
2728 GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
2730 GNUNET_PLUGIN_unload (sh->plugin, sh->sf);
2732 GAS_normalization_stop();
2734 GNUNET_CONTAINER_multipeermap_iterate (sh->addresses,
2737 GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
2738 GNUNET_free (sh->plugin);
2744 * Load quotas for networks from configuration
2746 * @param cfg configuration handle
2747 * @param out_dest where to write outbound quotas
2748 * @param in_dest where to write inbound quotas
2749 * @param dest_length length of inbound and outbound arrays
2750 * @return number of networks loaded
2753 GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
2754 unsigned long long *out_dest,
2755 unsigned long long *in_dest,
2758 char * entry_in = NULL;
2759 char * entry_out = NULL;
2760 char * quota_out_str;
2761 char * quota_in_str;
2765 for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
2769 GNUNET_asprintf (&entry_out,
2771 GNUNET_ATS_print_network_type (c));
2772 GNUNET_asprintf (&entry_in,
2774 GNUNET_ATS_print_network_type (c));
2777 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
2780 if (0 == strcmp(quota_out_str, BIG_M_STRING))
2782 out_dest[c] = GNUNET_ATS_MaxBandwidth;
2785 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
2787 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c])))
2790 if (GNUNET_NO == res)
2792 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2793 _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2794 GNUNET_ATS_print_network_type (c),
2796 GNUNET_ATS_DefaultBandwidth);
2797 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2801 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2802 "Outbound quota configure for network `%s' is %llu\n",
2803 GNUNET_ATS_print_network_type (c),
2806 GNUNET_free (quota_out_str);
2810 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2811 _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
2812 GNUNET_ATS_print_network_type (c),
2813 GNUNET_ATS_DefaultBandwidth);
2814 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2818 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str))
2821 if (0 == strcmp(quota_in_str, BIG_M_STRING))
2823 in_dest[c] = GNUNET_ATS_MaxBandwidth;
2826 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
2828 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c])))
2831 if (GNUNET_NO == res)
2833 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2834 _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2835 GNUNET_ATS_print_network_type (c),
2837 GNUNET_ATS_DefaultBandwidth);
2838 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
2842 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2843 "Inbound quota configured for network `%s' is %llu\n",
2844 GNUNET_ATS_print_network_type (c),
2847 GNUNET_free (quota_in_str);
2851 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2852 _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
2853 GNUNET_ATS_print_network_type (c),
2854 GNUNET_ATS_DefaultBandwidth);
2855 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2857 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2858 "Loaded quota for network `%s' (in/out): %llu %llu\n",
2859 GNUNET_ATS_print_network_type (c),
2862 GNUNET_free (entry_out);
2863 GNUNET_free (entry_in);
2865 return GNUNET_ATS_NetworkTypeCount;
2870 * Information callback for the solver
2872 * @param cls the closure
2873 * @param op the solver operation
2874 * @param stat status of the solver operation
2875 * @param add additional solver information
2878 solver_info_cb (void *cls,
2879 enum GAS_Solver_Operation op,
2880 enum GAS_Solver_Status stat,
2881 enum GAS_Solver_Additional_Information add)
2886 add_info = "GAS_INFO_NONE";
2889 add_info = "GAS_INFO_MLP_FULL";
2891 case GAS_INFO_UPDATED:
2892 add_info = "GAS_INFO_MLP_UPDATED";
2894 case GAS_INFO_PROP_ALL:
2895 add_info = "GAS_INFO_PROP_ALL";
2897 case GAS_INFO_PROP_SINGLE:
2898 add_info = "GAS_INFO_PROP_SINGLE";
2901 add_info = "INVALID";
2907 case GAS_OP_SOLVE_START:
2908 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2909 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
2910 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2912 case GAS_OP_SOLVE_STOP:
2913 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2914 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
2915 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2918 case GAS_OP_SOLVE_SETUP_START:
2919 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2920 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
2921 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2924 case GAS_OP_SOLVE_SETUP_STOP:
2925 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2926 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
2927 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2930 case GAS_OP_SOLVE_MLP_LP_START:
2931 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2932 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
2933 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2935 case GAS_OP_SOLVE_MLP_LP_STOP:
2936 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2937 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
2938 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2941 case GAS_OP_SOLVE_MLP_MLP_START:
2942 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2943 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
2944 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2946 case GAS_OP_SOLVE_MLP_MLP_STOP:
2947 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2948 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
2949 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2951 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
2952 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2953 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
2954 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2956 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
2957 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2958 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
2959 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
2967 solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address)
2969 struct GNUNET_TIME_Relative duration;
2971 static struct PreferenceGenerator *pg;
2973 if ( (0 == address->assigned_bw_out) && (0 == address->assigned_bw_in) )
2975 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2976 "Solver notified to disconnect peer `%s'\n",
2977 GNUNET_i2s (&address->peer));
2979 p = find_peer_by_pid(&address->peer);
2982 p->assigned_bw_out = address->assigned_bw_out;
2983 p->assigned_bw_in = address->assigned_bw_in;
2985 for (pg = pref_gen_head; NULL != pg; pg = pg->next)
2987 if (pg->peer == p->id)
2989 duration = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update);
2990 delta = duration.rel_value_us * pg->last_assigned_bw_out;
2991 pg->feedback_bw_out_acc += delta;
2993 delta = duration.rel_value_us * pg->last_assigned_bw_in;
2994 pg->feedback_bw_in_acc += delta;
2996 pg->last_assigned_bw_in = address->assigned_bw_in;
2997 pg->last_assigned_bw_out = address->assigned_bw_out;
2998 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
3002 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3003 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
3004 GNUNET_i2s (&address->peer),
3006 address->assigned_bw_out,
3007 address->assigned_bw_in);
3010 GNUNET_ATS_solver_logging_now (l);
3016 get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
3019 if (GNUNET_YES == opt_disable_normalization)
3021 if (NULL == (p = find_peer_by_pid (id)))
3026 return GAS_normalization_get_preferences_by_peer (NULL,
3032 get_property_cb (void *cls, const struct ATS_Address *address)
3035 struct TestAddress *a;
3037 if (GNUNET_YES == opt_disable_normalization)
3039 p = find_peer_by_pid (&address->peer);
3042 a = find_address_by_ats_address (p, address);
3045 return GAS_normalization_get_properties (NULL,
3050 struct SolverHandle *
3051 GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
3053 struct SolverHandle *sh;
3057 case GNUNET_ATS_SOLVER_PROPORTIONAL:
3058 solver_str = "proportional";
3060 case GNUNET_ATS_SOLVER_MLP:
3063 case GNUNET_ATS_SOLVER_RIL:
3072 sh = GNUNET_new (struct SolverHandle);
3073 GNUNET_asprintf (&sh->plugin,
3074 "libgnunet_plugin_ats_%s",
3076 sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
3078 /* setup environment */
3079 sh->env.cfg = e->cfg;
3080 sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg);
3081 sh->env.addresses = sh->addresses;
3082 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
3083 sh->env.get_preferences = &get_preferences_cb;
3084 sh->env.get_property = &get_property_cb;
3085 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
3086 sh->env.info_cb = &solver_info_cb;
3087 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
3089 /* start normalization */
3090 GAS_normalization_start ();
3093 if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg,
3094 sh->env.out_quota, sh->env.in_quota, GNUNET_ATS_NetworkTypeCount))
3097 GNUNET_free (sh->plugin);
3103 sh->sf = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
3106 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
3108 GNUNET_free (sh->plugin);
3120 struct TestPeer *cur;
3121 struct TestPeer *next;
3123 struct TestAddress *cur_a;
3124 struct TestAddress *next_a;
3127 GNUNET_ATS_solver_logging_stop (l);
3129 /* Stop all preference generation */
3130 GNUNET_ATS_solver_generate_preferences_stop_all ();
3132 /* Stop all property generation */
3133 GNUNET_ATS_solver_generate_property_stop_all ();
3137 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Printing log information \n");
3138 GNUNET_ATS_solver_logging_eval (l);
3142 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Saving log information \n");
3143 GNUNET_ATS_solver_logging_write_to_disk (l, e->log_append_time_stamp,
3149 GNUNET_ATS_solver_logging_free (l);
3153 /* Clean up experiment */
3156 GNUNET_ATS_solvers_experimentation_stop (e);
3161 while (NULL != (cur = next))
3164 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, cur);
3165 next_a = cur->addr_head;
3166 while (NULL != (cur_a = next_a))
3168 next_a = cur_a->next;
3169 GNUNET_CONTAINER_DLL_remove (cur->addr_head, cur->addr_tail, cur_a);
3170 GNUNET_free (cur_a);
3176 GNUNET_ATS_solvers_solver_stop (sh);
3185 experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success)
3187 if (GNUNET_OK == success)
3188 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n",
3189 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
3191 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
3193 GNUNET_SCHEDULER_add_now (&done, NULL);
3197 episode_done_cb (struct Episode *ep)
3199 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
3212 GNUNET_ATS_solvers_experimentation_stop (e);
3217 GNUNET_ATS_solvers_solver_stop (sh);
3223 run (void *cls, char * const *args, const char *cfgfile,
3224 const struct GNUNET_CONFIGURATION_Handle *cfg)
3226 enum GNUNET_ATS_Solvers solver;
3229 if (NULL == opt_exp_file)
3231 fprintf (stderr, "No experiment given ...\n");
3237 if (NULL == opt_solver)
3239 fprintf (stderr, "No solver given ...\n");
3245 if (0 == strcmp(opt_solver, "mlp"))
3247 solver = GNUNET_ATS_SOLVER_MLP;
3249 else if (0 == strcmp(opt_solver, "proportional"))
3251 solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
3253 else if (0 == strcmp(opt_solver, "ril"))
3255 solver = GNUNET_ATS_SOLVER_RIL;
3259 fprintf (stderr, "No solver given ...");
3265 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
3266 default_properties[c] = DEFAULT_REL_QUALITY;
3268 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
3269 default_preferences[c] = DEFAULT_REL_PREFERENCE;
3271 /* load experiment */
3272 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading experiment\n");
3273 e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
3276 fprintf (stderr, "Failed to load experiment ...\n");
3283 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading solver\n");
3284 sh = GNUNET_ATS_solvers_solver_start (solver);
3287 fprintf (stderr, "Failed to start solver ...\n");
3294 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Start logging \n");
3295 l = GNUNET_ATS_solver_logging_start (e->log_freq);
3297 /* run experiment */
3298 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Running experiment \n");
3299 GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb,
3300 experiment_done_cb);
3307 * Main function of the benchmark
3309 * @param argc argument count
3310 * @param argv argument values
3313 main (int argc, char *argv[])
3315 opt_exp_file = NULL;
3317 opt_log = GNUNET_NO;
3318 opt_save = GNUNET_NO;
3322 static struct GNUNET_GETOPT_CommandLineOption options[] =
3324 { 's', "solver", NULL,
3325 gettext_noop ("solver to use"),
3326 1, &GNUNET_GETOPT_set_string, &opt_solver},
3327 { 'e', "experiment", NULL,
3328 gettext_noop ("experiment to use"),
3329 1, &GNUNET_GETOPT_set_string, &opt_exp_file},
3330 { 'V', "verbose", NULL,
3331 gettext_noop ("be verbose"),
3332 0, &GNUNET_GETOPT_set_one, &opt_verbose},
3333 { 'p', "print", NULL,
3334 gettext_noop ("print logging"),
3335 0, &GNUNET_GETOPT_set_one, &opt_print},
3336 { 'f', "file", NULL,
3337 gettext_noop ("save logging to disk"),
3338 0, &GNUNET_GETOPT_set_one, &opt_save},
3340 gettext_noop ("disable normalization"),
3341 0, &GNUNET_GETOPT_set_one, &opt_disable_normalization},
3342 GNUNET_GETOPT_OPTION_END
3345 GNUNET_PROGRAM_run (argc, argv, "gnunet-ats-solver-eval",
3346 NULL, options, &run, argv[0]);
3350 /* end of file ats-testing-experiment.c*/