/*
This file is part of GNUnet.
- (C) 2010-2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2010-2013 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet-ats-solver-eval.h"
+#include "gnunet-service-ats_normalization.h"
+#include "gnunet-service-ats_preferences.c"
#define BIG_M_STRING "unlimited"
+/**
+ * Handle for statistics.
+ */
+struct GNUNET_STATISTICS_Handle *GSA_stats;
+
+
static struct Experiment *e;
static struct LoggingHandle *l;
static struct SolverHandle *sh;
static struct TestPeer *peer_head;
+
static struct TestPeer *peer_tail;
static double default_properties[GNUNET_ATS_PropertyCount];
}
}
-struct AddressLookupCtx
-{
- struct ATS_Address *res;
- char *plugin;
- char *addr;
-};
-
-
-int find_address_it (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
-{
- struct AddressLookupCtx *ctx = cls;
- struct ATS_Address *addr = value;
-
- if ( (0 == strcmp (ctx->plugin, addr->plugin)) &&
- (0 == strcmp (ctx->addr, addr->addr)) )
- {
- ctx->res = addr;
- return GNUNET_NO;
- }
- return GNUNET_YES;
-}
static struct TestPeer *
find_peer_by_id (int id)
}
-static struct TestAddress *
-find_address_by_ats_address (struct TestPeer *p, const struct ATS_Address *addr)
-{
- struct TestAddress *cur;
- for (cur = p->addr_head; NULL != cur; cur = cur->next)
- if ((0 == strcmp(cur->ats_addr->plugin, addr->plugin)) &&
- (cur->ats_addr->addr_len == addr->addr_len) &&
- (0 == memcmp (cur->ats_addr->addr, addr->addr, addr->addr_len)))
- return cur;
- return NULL;
-}
-
-
/**
* Logging
*/
-
void
GNUNET_ATS_solver_logging_now (struct LoggingHandle *l)
{
log_a->aid = cur_addr->aid;
log_a->active = cur_addr->ats_addr->active;
log_a->network = cur_addr->network;
- log_a->used = cur_addr->ats_addr->used;
log_a->assigned_bw_in = cur_addr->ats_addr->assigned_bw_in;
log_a->assigned_bw_out = cur_addr->ats_addr->assigned_bw_out;
for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
log_a->prop_abs[c], log_a->prop_norm[c]);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t Active = %i\n", log_a->active);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t BW in = %llu\n", ntohl(log_a->assigned_bw_in.value__));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t BW out = %llu\n", ntohl(log_a->assigned_bw_out.value__));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t BW in = %llu\n", log_a->assigned_bw_in);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t BW out = %llu\n", log_a->assigned_bw_out);
GNUNET_CONTAINER_DLL_insert_tail (log_p->addr_head, log_p->addr_tail, log_a);
}
logging_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct LoggingHandle *l = cls;
- l->logging_task = GNUNET_SCHEDULER_NO_TASK;
+ l->logging_task = NULL;
GNUNET_ATS_solver_logging_now (l);
void
GNUNET_ATS_solver_logging_stop (struct LoggingHandle *l)
{
- if (GNUNET_SCHEDULER_NO_TASK != l->logging_task)
+ if (NULL != l->logging_task)
GNUNET_SCHEDULER_cancel (l->logging_task);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop logging\n");
- l->logging_task = GNUNET_SCHEDULER_NO_TASK;
+ l->logging_task = NULL;
}
static struct LoggingFileHandle *
{
fprintf (stderr, "Cannot open `%s' to write log data!\n", filename);
GNUNET_free (filename);
+ GNUNET_free (cur);
goto cleanup;
}
GNUNET_free (filename);
propstring = GNUNET_strdup(propstring_tmp);
GNUNET_free (propstring_tmp);
}
- if (GNUNET_YES==log_p->is_requested)
- GNUNET_break (0);
- GNUNET_asprintf(&datastring,"%llu;%llu;%u;%u;%i;%u;%u;%s;%s\n",
- GNUNET_TIME_absolute_get_difference(l->head->timestamp, lts->timestamp).rel_value_us / 1000,
- lts->delta,
- log_p->is_requested,
- log_a->network,
- log_a->active,
- ntohl (log_a->assigned_bw_in.value__),
- ntohl (log_a->assigned_bw_out.value__),
- propstring, prefstring);
+ GNUNET_asprintf (&datastring, "%llu;%llu;%u;%u;%i;%u;%u;%s;%s\n",
+ GNUNET_TIME_absolute_get_difference (l->head->timestamp,
+ lts->timestamp).rel_value_us / 1000, lts->delta,
+ log_p->is_requested, log_a->network, log_a->active,
+ log_a->assigned_bw_in, log_a->assigned_bw_out, propstring,
+ prefstring);
GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring));
GNUNET_free (datastring);
{
fprintf (stderr, "\tPeer pid %llu address %llu: %u %u %u\n",
log_p->id, log_a->aid, log_a->active,
- ntohl(log_a->assigned_bw_in.value__),
- ntohl(log_a->assigned_bw_out.value__));
+ log_a->assigned_bw_in,
+ log_a->assigned_bw_out);
for (c = 1; c < GNUNET_ATS_PropertyCount; c++)
{
struct LoggingAddress *log_a_cur;
struct LoggingAddress *log_a_next;
- if (GNUNET_SCHEDULER_NO_TASK != l->logging_task)
+ if (NULL != l->logging_task)
GNUNET_SCHEDULER_cancel (l->logging_task);
- l->logging_task = GNUNET_SCHEDULER_NO_TASK;
+ l->logging_task = NULL;
lts_next = l->head;
while (NULL != (lts_cur = lts_next))
double prop_value;
struct GNUNET_ATS_Information atsi;
- pg->set_task = GNUNET_SCHEDULER_NO_TASK;
+ pg->set_task = NULL;
if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains_value (sh->addresses,
&pg->test_peer->peer_id, pg->test_address->ats_addr))
}
if (NULL == (p = find_peer_by_id (pg->peer)))
{
+ GNUNET_break (0);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Setting property generation for unknown peer %u\n",
pg->peer);
+ return;
}
if (NULL == (a = find_address_by_id (p, pg->address_id)))
{
+ GNUNET_break (0);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Setting property generation for unknown peer %u\n",
pg->peer);
+ return;
}
prop_value = get_property (pg);
atsi.value = htonl ((uint32_t) prop_value);
/* set performance here! */
- sh->env.sf.s_bulk_start (sh->solver);
+ sh->sf->s_bulk_start (sh->sf->cls);
if (GNUNET_YES == opt_disable_normalization)
{
a->prop_abs[pg->ats_property] = prop_value;
a->prop_norm[pg->ats_property] = prop_value;
- sh->env.sf.s_address_update_property (sh->solver, a->ats_addr,
+ sh->sf->s_address_update_property (sh->sf->cls, a->ats_addr,
pg->ats_property, prop_value, prop_value);
}
else
- GAS_normalization_normalize_property (sh->addresses,
- pg->test_address->ats_addr, &atsi, 1);
- sh->env.sf.s_bulk_stop (sh->solver);
+ GAS_normalization_update_property (pg->test_address->ats_addr, &atsi, 1);
+ sh->sf->s_bulk_stop (sh->sf->cls);
pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
&set_prop_task, pg);
-
}
+
/**
* Set ats_property to 0 to find all pgs
*/
-
static struct PropertyGenerator *
find_prop_gen (unsigned int peer, unsigned int address,
uint32_t ats_property)
{
GNUNET_CONTAINER_DLL_remove (prop_gen_head, prop_gen_tail, pg);
- if (GNUNET_SCHEDULER_NO_TASK != pg->set_task)
+ if (NULL != pg->set_task)
{
GNUNET_SCHEDULER_cancel (pg->set_task);
- pg->set_task = GNUNET_SCHEDULER_NO_TASK;
+ pg->set_task = NULL;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Removing old up preference generator peer [%u] address [%u] `%s'\n",
}
-
/**
* Stop all preferences generators
*/
/**
* Preference Generators
*/
-
static struct PreferenceGenerator *pref_gen_head;
static struct PreferenceGenerator *pref_gen_tail;
+
static double
get_preference (struct PreferenceGenerator *pg)
{
return pref_value;
}
+static void
+set_feedback_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct PreferenceGenerator *pg = cls;
+ struct TestPeer *p;
+ double feedback;
+ uint32_t bw_acc_out;
+ uint32_t bw_acc_in;
+ uint32_t delay_acc_in;
+ struct GNUNET_TIME_Relative dur;
+ double p_new;
+
+ pg->feedback_task = NULL;
+
+ if (NULL == (p = find_peer_by_id (pg->peer)))
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Setting feedback for unknown peer %u\n", pg->peer);
+ return;
+ }
+
+ switch (pg->kind)
+ {
+ case GNUNET_ATS_PREFERENCE_BANDWIDTH:
+ dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update);
+ bw_acc_in = dur.rel_value_us *pg->last_assigned_bw_in + pg->feedback_bw_in_acc;
+ pg->feedback_bw_in_acc = 0;
+
+ bw_acc_out = dur.rel_value_us *pg->last_assigned_bw_out + pg->feedback_bw_out_acc;
+ p_new = get_preference (pg);
+ feedback = (p_new / pg->pref_bw_old) * (bw_acc_in + bw_acc_out) /
+ (2 *GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us);
+
+ break;
+ case GNUNET_ATS_PREFERENCE_LATENCY:
+ dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_delay_update);
+ delay_acc_in =dur.rel_value_us *pg->last_delay_value + pg->feedback_delay_acc;
+ pg->feedback_delay_acc = 0;
+
+ p_new = get_preference (pg);
+ feedback = (p_new / pg->pref_latency_old) * (delay_acc_in) /
+ (GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us);
+
+ break;
+ default:
+ GNUNET_break (0);
+ feedback = 0.0;
+ break;
+ }
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+ "Giving feedback for peer [%u] for client %p pref %s of %.3f\n",
+ pg->peer, NULL + (pg->client_id),
+ GNUNET_ATS_print_preference_type (pg->kind),
+ feedback);
+
+ sh->sf->s_feedback (sh->sf->cls, NULL + (pg->client_id), &p->peer_id,
+ pg->feedback_frequency, pg->kind, feedback);
+ pg->feedback_last = GNUNET_TIME_absolute_get();
+
+
+ pg->feedback_bw_out_acc = 0;
+ pg->feedback_bw_in_acc = 0;
+ pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
+
+ pg->feedback_delay_acc = 0;
+ pg->feedback_last_delay_update = GNUNET_TIME_absolute_get();
+
+
+ pg->feedback_task = GNUNET_SCHEDULER_add_delayed (pg->feedback_frequency,
+ &set_feedback_task, pg);
+}
+
static void
set_pref_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PreferenceGenerator *pg = cls;
struct TestPeer *p;
double pref_value;
- pg->set_task = GNUNET_SCHEDULER_NO_TASK;
+ pg->set_task = NULL;
if (NULL == (p = find_peer_by_id (pg->peer)))
{
}
pref_value = get_preference (pg);
+ switch (pg->kind) {
+ case GNUNET_ATS_PREFERENCE_BANDWIDTH:
+ pg->pref_bw_old = pref_value;
+ break;
+ case GNUNET_ATS_PREFERENCE_LATENCY:
+ pg->pref_latency_old = pref_value;
+ break;
+ default:
+ break;
+ }
+
p->pref_abs[pg->kind] = pref_value;
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
pg->peer, NULL + (pg->client_id),
GNUNET_ATS_print_preference_type (pg->kind), pref_value);
- sh->env.sf.s_bulk_start (sh->solver);
if (GNUNET_YES == opt_disable_normalization)
{
p->pref_abs[pg->kind] = pref_value;
p->pref_norm[pg->kind] = pref_value;
- sh->env.sf.s_pref (sh->solver, &p->peer_id, pg->kind, pref_value);
+ sh->sf->s_pref (sh->sf->cls, &p->peer_id, pg->kind, pref_value);
}
else
- GAS_normalization_normalize_preference (NULL + (pg->client_id),
- &p->peer_id, pg->kind, pref_value);
- sh->env.sf.s_bulk_stop (sh->solver);
-
- switch (pg->kind) {
- case GNUNET_ATS_PREFERENCE_BANDWIDTH:
- //p->pref_bandwidth = pref_value;
- break;
- case GNUNET_ATS_PREFERENCE_LATENCY:
- //p->pref_delay = pref_value;
- break;
- default:
- break;
- }
+ normalize_preference (NULL + (pg->client_id),
+ &p->peer_id,
+ pg->kind,
+ pref_value);
pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
- set_pref_task, pg);
-
+ &set_pref_task,
+ pg);
}
+
static struct PreferenceGenerator *
find_pref_gen (unsigned int peer, enum GNUNET_ATS_PreferenceKind kind)
{
{
GNUNET_CONTAINER_DLL_remove (pref_gen_head, pref_gen_tail, pg);
- if (GNUNET_SCHEDULER_NO_TASK != pg->set_task)
+ if (NULL != pg->feedback_task)
+ {
+ GNUNET_SCHEDULER_cancel (pg->feedback_task);
+ pg->feedback_task = NULL;
+ }
+
+ if (NULL != pg->set_task)
{
GNUNET_SCHEDULER_cancel (pg->set_task);
- pg->set_task = GNUNET_SCHEDULER_NO_TASK;
+ pg->set_task = NULL;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Removing old up preference generator peer [%u] `%s'\n",
}
+static struct TestAddress*
+find_active_address (struct TestPeer *p)
+{
+ struct TestAddress *cur;
+ for (cur = p->addr_head; NULL != cur; cur = cur->next)
+ if (GNUNET_YES == cur->ats_addr->active)
+ return cur;
+ return NULL;
+}
+
+
/**
* Generate between the source master and the partner and set property with a
* value depending on the generator.
* @param period duration of a period of generation (~ 1/frequency)
* @param frequency how long to generate property
* @param kind ATS preference to generate
+ * @param feedback_frequency how often to give feedback
* @return the preference generator
*/
struct PreferenceGenerator *
long int value_rate,
struct GNUNET_TIME_Relative period,
struct GNUNET_TIME_Relative frequency,
- enum GNUNET_ATS_PreferenceKind kind)
+ enum GNUNET_ATS_PreferenceKind kind,
+ struct GNUNET_TIME_Relative feedback_frequency)
{
struct PreferenceGenerator *pg;
+ struct TestPeer *p;
+
+ if (NULL == (p = find_peer_by_id (peer)))
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Starting preference for unknown peer %u\n", peer);
+ return NULL;
+ }
pg = GNUNET_new (struct PreferenceGenerator);
GNUNET_CONTAINER_DLL_insert (pref_gen_head, pref_gen_tail, pg);
pg->duration_period = period;
pg->frequency = frequency;
pg->time_start = GNUNET_TIME_absolute_get();
+ pg->feedback_frequency = feedback_frequency;
switch (type) {
case GNUNET_ATS_TEST_TG_CONSTANT:
}
pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, pg);
+ if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != feedback_frequency.rel_value_us)
+ {
+ struct TestAddress * addr = find_active_address(p);
+
+ pg->last_assigned_bw_in = p->assigned_bw_in;
+ pg->last_assigned_bw_out = p->assigned_bw_out;
+ pg->feedback_bw_in_acc = 0;
+ pg->feedback_bw_out_acc = 0;
+ pg->last_delay_value = addr->prop_norm[GNUNET_ATS_QUALITY_NET_DELAY];
+ pg->feedback_delay_acc = 0;
+
+ pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
+ pg->feedback_last_delay_update = GNUNET_TIME_absolute_get();
+ pg->feedback_last = GNUNET_TIME_absolute_get();
+ pg->feedback_task = GNUNET_SCHEDULER_add_delayed (feedback_frequency,
+ &set_feedback_task, pg);
+ }
+
return pg;
}
/**
* Experiments
*/
-
-const char *
+static const char *
print_op (enum OperationType op)
{
switch (op) {
return "";
}
+
static struct Experiment *
create_experiment ()
{
return e;
}
+
static void
free_experiment (struct Experiment *e)
{
return GNUNET_OK;
}
+
static int
load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
struct Episode *e,
return GNUNET_OK;
}
+
static enum GNUNET_ATS_Property
parse_preference_string (const char * str)
{
if (0 == strcmp(str, props[c]))
return c;
return 0;
-};
+}
+
static int
load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
GNUNET_free (pref);
GNUNET_free (op_name);
+ /* Get feedback delay */
+ GNUNET_asprintf(&op_name, "op-%u-feedback_delay", op_counter);
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time (cfg,
+ sec_name, op_name, &o->feedback_delay))
+ {
+ fprintf (stderr, "Using feedback delay %llu in operation %u `%s' in episode %u\n",
+ (long long unsigned int) o->feedback_delay.rel_value_us,
+ op_counter, op_name, e->id);
+ }
+ else
+ o->feedback_delay = GNUNET_TIME_UNIT_FOREVER_REL;
+ GNUNET_free (op_name);
+
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Found operation %s: [%llu:%llu]: %s = %llu\n",
"START_SET_PREFERENCE", o->peer_id, o->address_id,
return GNUNET_OK;
}
+
static int
load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
struct Episode *e,
return GNUNET_OK;
}
+
static enum GNUNET_ATS_Property
-parse_property_string (const char * str)
+parse_property_string (const char *str)
{
- int c = 0;
- char *props[GNUNET_ATS_PropertyCount] = GNUNET_ATS_PropertyStrings;
+ enum GNUNET_ATS_Property c;
for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
- if (0 == strcmp(str, props[c]))
+ if (0 == strcmp(str,
+ GNUNET_ATS_print_property_type (c)))
return c;
return 0;
-};
+}
+
static int
load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o,
timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
{
struct Experiment *e = cls;
- e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ e->experiment_timeout_task = NULL;
fprintf (stderr, "Experiment timeout!\n");
- if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
+ if (NULL != e->episode_timeout_task)
{
GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
- e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ e->episode_timeout_task = NULL;
}
e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
memcpy (&aa[1], plugin_addr, plugin_addr_len);
memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
aa->session_id = session_id;
- aa->active = GNUNET_NO;
- aa->used = GNUNET_NO;
- aa->solver_information = NULL;
- aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0);
- aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0);
return aa;
}
{
p = GNUNET_new (struct TestPeer);
p->id = op->peer_id;
+ p->assigned_bw_in = 0;
+ p->assigned_bw_out = 0;
memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u in network `%s'\n",
op->address_id, op->peer_id, GNUNET_ATS_print_network_type(a->network));
- sh->env.sf.s_add (sh->solver, a->ats_addr, op->address_network);
+ sh->sf->s_add (sh->sf->cls, a->ats_addr, op->address_network);
}
GNUNET_ATS_solver_generate_property_stop (pg);
}
- GNUNET_CONTAINER_multipeermap_remove (sh->addresses, &p->peer_id, a->ats_addr);
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Removing address %u for peer %u\n",
- op->address_id, op->peer_id);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_remove (sh->addresses,
+ &p->peer_id,
+ a->ats_addr));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Removing address %u for peer %u\n",
+ op->address_id,
+ op->peer_id);
- sh->env.sf.s_del (sh->solver, a->ats_addr, GNUNET_NO);
+ sh->sf->s_del (sh->sf->cls, a->ats_addr, GNUNET_NO);
if (NULL != l)
{
op->max_rate,
op->period,
op->frequency,
- op->pref_type);
+ op->pref_type,
+ op->frequency);
}
static void
op->peer_id);
p->is_requested = GNUNET_YES;
- res = sh->env.sf.s_get (sh->solver, &p->peer_id);
+ res = sh->sf->s_get (sh->sf->cls, &p->peer_id);
if (NULL != res)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Suggested address for peer %u: %llu %llu\n",
op->peer_id,
- ntohl(res->assigned_bw_in.value__),
- ntohl(res->assigned_bw_out.value__));
+ res->assigned_bw_in,
+ res->assigned_bw_out);
if (NULL != l)
GNUNET_ATS_solver_logging_now (l);
}
return;
}
+
+
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop requesting address for peer %u\n",
op->peer_id);
p->is_requested = GNUNET_NO;
- sh->env.sf.s_get_stop (sh->solver, &p->peer_id);
+ p->assigned_bw_in = 0;
+ p->assigned_bw_out = 0;
+ sh->sf->s_get_stop (sh->sf->cls, &p->peer_id);
if (NULL != l)
{
timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
{
struct Experiment *e = cls;
- e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ e->episode_timeout_task = NULL;
if (NULL != e->ep_done_cb)
e->ep_done_cb (e->cur);
{
/* done */
fprintf (stderr, "Last episode done!\n");
- if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
+ if (NULL != e->experiment_timeout_task)
{
GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
- e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ e->experiment_timeout_task = NULL;
}
e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
return;
void
GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
{
- if (GNUNET_SCHEDULER_NO_TASK != e->experiment_timeout_task)
+ if (NULL != e->experiment_timeout_task)
{
GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
- e->experiment_timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ e->experiment_timeout_task = NULL;
}
- if (GNUNET_SCHEDULER_NO_TASK != e->episode_timeout_task)
+ if (NULL != e->episode_timeout_task)
{
GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
- e->episode_timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ e->episode_timeout_task = NULL;
}
if (NULL != e->cfg)
{
{
GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
GNUNET_NO);
- GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
-
+ GNUNET_PLUGIN_unload (sh->plugin, sh->sf);
+ sh->sf = NULL;
GAS_normalization_stop();
- GNUNET_CONTAINER_multipeermap_iterate (sh->addresses, &free_all_it, NULL);
+ GNUNET_CONTAINER_multipeermap_iterate (sh->addresses,
+ &free_all_it,
+ NULL);
GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
GNUNET_free (sh->plugin);
GNUNET_free (sh);
}
+
/**
* Load quotas for networks from configuration
*
unsigned long long *in_dest,
int dest_length)
{
- char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
char * entry_in = NULL;
char * entry_out = NULL;
char * quota_out_str;
{
in_dest[c] = 0;
out_dest[c] = 0;
- GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]);
- GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]);
+ GNUNET_asprintf (&entry_out,
+ "%s_QUOTA_OUT",
+ GNUNET_ATS_print_network_type (c));
+ GNUNET_asprintf (&entry_in,
+ "%s_QUOTA_IN",
+ GNUNET_ATS_print_network_type (c));
/* quota out */
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
if (GNUNET_NO == res)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
- network_str[c], quota_out_str, GNUNET_ATS_DefaultBandwidth);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
+ GNUNET_ATS_print_network_type (c),
+ quota_out_str,
+ GNUNET_ATS_DefaultBandwidth);
out_dest[c] = GNUNET_ATS_DefaultBandwidth;
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Outbound quota configure for network `%s' is %llu\n"),
- network_str[c], out_dest[c]);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Outbound quota configure for network `%s' is %llu\n",
+ GNUNET_ATS_print_network_type (c),
+ out_dest[c]);
}
GNUNET_free (quota_out_str);
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
- network_str[c], GNUNET_ATS_DefaultBandwidth);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
+ GNUNET_ATS_print_network_type (c),
+ GNUNET_ATS_DefaultBandwidth);
out_dest[c] = GNUNET_ATS_DefaultBandwidth;
}
if (GNUNET_NO == res)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
- network_str[c], quota_in_str, GNUNET_ATS_DefaultBandwidth);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
+ GNUNET_ATS_print_network_type (c),
+ quota_in_str,
+ GNUNET_ATS_DefaultBandwidth);
in_dest[c] = GNUNET_ATS_DefaultBandwidth;
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Inbound quota configured for network `%s' is %llu\n"),
- network_str[c], in_dest[c]);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Inbound quota configured for network `%s' is %llu\n",
+ GNUNET_ATS_print_network_type (c),
+ in_dest[c]);
}
GNUNET_free (quota_in_str);
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
- network_str[c], GNUNET_ATS_DefaultBandwidth);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
+ GNUNET_ATS_print_network_type (c),
+ GNUNET_ATS_DefaultBandwidth);
out_dest[c] = GNUNET_ATS_DefaultBandwidth;
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loaded quota for network `%s' (in/out): %llu %llu\n", network_str[c], in_dest[c], out_dest[c]);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Loaded quota for network `%s' (in/out): %llu %llu\n",
+ GNUNET_ATS_print_network_type (c),
+ in_dest[c],
+ out_dest[c]);
GNUNET_free (entry_out);
GNUNET_free (entry_in);
}
return GNUNET_ATS_NetworkTypeCount;
}
+
/**
* Information callback for the solver
*
*/
static void
solver_info_cb (void *cls,
- enum GAS_Solver_Operation op,
- enum GAS_Solver_Status stat,
- enum GAS_Solver_Additional_Information add)
+ enum GAS_Solver_Operation op,
+ enum GAS_Solver_Status stat,
+ enum GAS_Solver_Additional_Information add)
{
char *add_info;
switch (add) {
static void
solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address)
{
- if ( (0 == ntohl (address->assigned_bw_out.value__)) &&
- (0 == ntohl (address->assigned_bw_in.value__)) )
+ struct GNUNET_TIME_Relative duration;
+ struct TestPeer *p;
+ static struct PreferenceGenerator *pg;
+ uint32_t delta;
+ if ( (0 == address->assigned_bw_out) && (0 == address->assigned_bw_in) )
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Solver notified to disconnect peer `%s'\n",
GNUNET_i2s (&address->peer));
+ }
+ p = find_peer_by_pid(&address->peer);
+ if (NULL == p)
return;
+ p->assigned_bw_out = address->assigned_bw_out;
+ p->assigned_bw_in = address->assigned_bw_in;
+
+ for (pg = pref_gen_head; NULL != pg; pg = pg->next)
+ {
+ if (pg->peer == p->id)
+ {
+ duration = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update);
+ delta = duration.rel_value_us * pg->last_assigned_bw_out;
+ pg->feedback_bw_out_acc += delta;
+
+ delta = duration.rel_value_us * pg->last_assigned_bw_in;
+ pg->feedback_bw_in_acc += delta;
+
+ pg->last_assigned_bw_in = address->assigned_bw_in;
+ pg->last_assigned_bw_out = address->assigned_bw_out;
+ pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
+ }
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
- GNUNET_i2s (&address->peer),
- address,
- (unsigned int) ntohl (address->assigned_bw_out.value__),
- (unsigned int) ntohl (address->assigned_bw_in.value__));
- /*if (GNUNET_YES == ph.bulk_running)
- GNUNET_break (0);*/
+ "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
+ GNUNET_i2s (&address->peer),
+ address,
+ address->assigned_bw_out,
+ address->assigned_bw_in);
+
if (NULL != l)
GNUNET_ATS_solver_logging_now (l);
return p->pref_abs;
}
else
- return GAS_normalization_get_preferences_by_peer (id);
-}
-
-
-const double *
-get_property_cb (void *cls, const struct ATS_Address *address)
-{
- struct TestPeer *p;
- struct TestAddress *a;
-
- if (GNUNET_YES == opt_disable_normalization)
- {
- p = find_peer_by_pid (&address->peer);
- a = find_address_by_ats_address (p, address);
- return a->prop_abs;
- }
- else
- return GAS_normalization_get_properties ((struct ATS_Address *) address);
-}
-
-static void
-set_updated_property ( struct ATS_Address *address, uint32_t type, double prop_rel)
-{
- struct TestPeer *p;
- struct TestAddress *a;
-
- if (NULL == (p = find_peer_by_pid (&address->peer)))
- {
- GNUNET_break (0);
- return;
- }
-
- if (NULL == (a = find_address_by_ats_address (p, address)))
- {
- GNUNET_break (0);
- return;
- }
- a->prop_norm[type] = prop_rel;
- sh->env.sf.s_address_update_property (sh->solver, address, type, a->prop_abs [type], prop_rel);
-}
-
-
-static void
-normalized_property_changed_cb (void *cls, struct ATS_Address *address,
- uint32_t type, double prop_rel)
-{
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Normalized property %s for peer `%s' changed to %.3f \n",
- GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer),
- prop_rel);
-
- set_updated_property (address, type, prop_rel);
-}
-
-static void
-set_updated_preference (const struct GNUNET_PeerIdentity *peer,
- enum GNUNET_ATS_PreferenceKind kind,
- double pref_rel)
-{
- struct TestPeer *p;
-
- if (NULL == (p = find_peer_by_pid (peer)))
- {
- GNUNET_break (0);
- return;
- }
-
- p->pref_norm[kind] = pref_rel;
- sh->env.sf.s_pref (sh->solver, peer, kind, pref_rel);
-}
-
-
-static void
-normalized_preference_changed_cb (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- enum GNUNET_ATS_PreferenceKind kind,
- double pref_rel)
-{
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Normalized preference %s for peer `%s' changed to %.3f \n",
- GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer),
- pref_rel);
-
- set_updated_preference(peer, kind, pref_rel);
+ return GAS_preference_get_by_peer (NULL,
+ id);
}
{
struct SolverHandle *sh;
char * solver_str;
- int c;
switch (type) {
case GNUNET_ATS_SOLVER_PROPORTIONAL:
}
sh = GNUNET_new (struct SolverHandle);
- GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str);
-
+ GNUNET_asprintf (&sh->plugin,
+ "libgnunet_plugin_ats_%s",
+ solver_str);
sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
+
/* setup environment */
sh->env.cfg = e->cfg;
sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg);
sh->env.addresses = sh->addresses;
sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
sh->env.get_preferences = &get_preferences_cb;
- sh->env.get_property = &get_property_cb;
sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
sh->env.info_cb = &solver_info_cb;
- sh->env.info_cb_cls = NULL;
sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
- int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
- for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
- sh->env.networks[c] = networks[c];
-
/* start normalization */
- GAS_normalization_start (&normalized_preference_changed_cb, NULL,
- &normalized_property_changed_cb, NULL );
+ GAS_normalization_start ();
/* load quotas */
if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg,
return NULL;
}
- sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
- if (NULL == sh->solver)
+ sh->sf = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
+ if (NULL == sh->sf)
{
fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
GNUNET_break(0);
return sh;
}
+
static void
done ()
{
return res;
}
/* end of file ats-testing-experiment.c*/
-