/*
This file is part of GNUnet.
- (C) 2011 Christian Grothoff (and other contributing authors)
+ (C) 2011-2014 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
* @author Fabian Oehlmann
* @author Matthias Wachs
*/
-#include "plugin_ats_ril.h"
+#include "platform.h"
+#include <float.h>
+#include <math.h>
+#include "gnunet_ats_plugin.h"
+#include "gnunet-service-ats_addresses.h"
+
+
#define LOG(kind,...) GNUNET_log_from (kind, "ats-ril",__VA_ARGS__)
/**
* Inbound bandwidth assigned by the agent
*/
- unsigned long long bw_in;
+ uint32_t bw_in;
/**
* Outbound bandwidth assigned by the agent
*/
- unsigned long long bw_out;
+ uint32_t bw_out;
/**
* Flag whether a suggestion has to be issued
/**
* Total available inbound bandwidth
*/
- unsigned long long bw_in_available;
+ uint32_t bw_in_available;
/**
* Bandwidth inbound assigned in network after last step
*/
- unsigned long long bw_in_assigned;
+ uint32_t bw_in_assigned;
/**
* Bandwidth inbound actually utilized in the network
*/
- unsigned long long bw_in_utilized;
+ uint32_t bw_in_utilized;
/**
* Total available outbound bandwidth
*/
- unsigned long long bw_out_available;
+ uint32_t bw_out_available;
/**
* Bandwidth outbound assigned in network after last step
/**
* The solver-plugin environment of the solver-plugin API
*/
- struct GNUNET_ATS_PluginEnvironment *plugin_envi;
-
- /**
- * Statistics handle
- */
- struct GNUNET_STATISTICS_Handle *stats;
+ struct GNUNET_ATS_PluginEnvironment *env;
/**
* Number of performed steps
/**
* Task identifier of the next time-step to be executed
*/
- GNUNET_SCHEDULER_TaskIdentifier step_next_task_id;
+ struct GNUNET_SCHEDULER_Task * step_next_task_id;
/**
* Variable discount factor, dependent on time between steps
enum GAS_Solver_Operation op,
enum GAS_Solver_Status stat)
{
- if (NULL != solver->plugin_envi->info_cb)
- solver->plugin_envi->info_cb (solver->plugin_envi->info_cb_cls, op, stat, GAS_INFO_NONE);
+ if (NULL != solver->env->info_cb)
+ solver->env->info_cb (solver->env->cls, op, stat, GAS_INFO_NONE);
}
/**
if (NULL != agent->address_inuse)
{
agent->address_inuse->active = GNUNET_NO;
- agent->address_inuse->assigned_bw_in.value__ = htonl (0);
- agent->address_inuse->assigned_bw_out.value__ = htonl (0);
+ agent->address_inuse->assigned_bw_in = 0;
+ agent->address_inuse->assigned_bw_out = 0;
}
if (NULL != new_address)
{
LOG(GNUNET_ERROR_TYPE_DEBUG, " set address active: %s\n", agent->is_active ? "yes" : "no");
new_address->active = agent->is_active;
- new_address->assigned_bw_in.value__ = htonl (agent->bw_in);
- new_address->assigned_bw_out.value__ = htonl (agent->bw_out);
+ new_address->assigned_bw_in = agent->bw_in;
+ new_address->assigned_bw_out = agent->bw_out;
}
notify |= GNUNET_YES;
}
if (agent->bw_in != new_bw_in)
{
agent->bw_in = new_bw_in;
- new_address->assigned_bw_in.value__ = htonl (new_bw_in);
+ new_address->assigned_bw_in = new_bw_in;
notify |= GNUNET_YES;
}
if (agent->bw_out != new_bw_out)
{
agent->bw_out = new_bw_out;
- new_address->assigned_bw_out.value__ = htonl (new_bw_out);
+ new_address->assigned_bw_out = new_bw_out;
notify |= GNUNET_YES;
}
}
}
else if (agent->address_inuse)
{
- //disconnect case, no new address
- GNUNET_assert(0 == ntohl (agent->address_inuse->assigned_bw_in.value__));
- GNUNET_assert(0 == ntohl (agent->address_inuse->assigned_bw_out.value__));
+ /* disconnect case, no new address */
+ GNUNET_assert(0 == agent->address_inuse->assigned_bw_in);
+ GNUNET_assert(0 == agent->address_inuse->assigned_bw_out);
agent->bw_in = 0;
agent->bw_out = 0;
double delay_norm;
double pref_match;
- preferences = agent->envi->plugin_envi->get_preferences (agent->envi->plugin_envi->get_preference_cls,
- &agent->peer);
+ preferences = agent->envi->env->get_preferences (agent->envi->env->cls,
+ &agent->peer);
delay_atsi = (double) ril_get_atsi (agent->address_inuse, GNUNET_ATS_QUALITY_NET_DELAY);
delay_norm = RIL_UTILITY_DELAY_MAX*exp(-delay_atsi*0.00001);
over_in = net->bw_in_utilized - net->bw_in_available;
if (RIL_ACTION_BW_IN_INC == agent->a_old)
{
- over_in *= 2;
+ /* increase quadratically */
+ over_in *= over_in;
}
}
if (net->bw_out_utilized > net->bw_out_available)
over_out = net->bw_out_utilized - net->bw_out_available;
if (RIL_ACTION_BW_OUT_INC == agent->a_old)
{
- over_out *= 2;
+ /* increase quadratically */
+ over_out *= over_out;
}
}
- over_max = (over_in + over_out) / RIL_MIN_BW;
+ over_max = (over_in + over_out) / (RIL_MIN_BW * RIL_MIN_BW);
return -1.0 * (double) over_max;
}
GNUNET_assert(RIL_ACTION_INVALID != a_next);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "step() Step# %llu R: %f IN %llu OUT %llu A: %d\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "step() Step# %llu R: %f IN %llu OUT %llu A: %d\n",
agent->step_count,
reward,
agent->bw_in/1024,
{
struct GAS_RIL_Handle *solver = cls;
- solver->step_next_task_id = GNUNET_SCHEDULER_NO_TASK;
+ solver->step_next_task_id = NULL;
ril_step (solver);
}
time_next = GNUNET_TIME_UNIT_ZERO;
}
- if ((GNUNET_SCHEDULER_NO_TASK == solver->step_next_task_id) && (GNUNET_NO == solver->done))
+ if ((NULL == solver->step_next_task_id) && (GNUNET_NO == solver->done))
{
solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed (time_next, &ril_step_scheduler_task,
solver);
for (cur = solver->agents_head; NULL != cur; cur = cur->next)
{
if (cur->suggestion_issue) {
- solver->plugin_envi->bandwidth_changed_cb(solver->plugin_envi->bw_changed_cb_cls, cur->suggestion_address);
+ solver->env->bandwidth_changed_cb(solver->env->cls, cur->suggestion_address);
cur->suggestion_issue = GNUNET_NO;
}
}
* @param kind the kind to change the preference
* @param pref_rel the normalized preference value for this kind over all clients
*/
-void
+static void
GAS_ril_address_change_preference (void *solver,
- const struct GNUNET_PeerIdentity *peer,
- enum GNUNET_ATS_PreferenceKind kind,
- double pref_rel)
+ const struct GNUNET_PeerIdentity *peer,
+ enum GNUNET_ATS_PreferenceKind kind,
+ double pref_rel)
{
LOG(GNUNET_ERROR_TYPE_DEBUG,
"API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n",
ril_step (s);
}
-/**
- * Entry point for the plugin
- *
- * @param cls pointer to the 'struct GNUNET_ATS_PluginEnvironment'
- */
-void *
-libgnunet_plugin_ats_ril_init (void *cls)
-{
- struct GNUNET_ATS_PluginEnvironment *env = cls;
- struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle);
- struct RIL_Scope * cur;
- int c;
- char *string;
-
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_init() Initializing RIL solver\n");
-
- GNUNET_assert(NULL != env);
- GNUNET_assert(NULL != env->cfg);
- GNUNET_assert(NULL != env->stats);
- GNUNET_assert(NULL != env->bandwidth_changed_cb);
- GNUNET_assert(NULL != env->get_preferences);
- GNUNET_assert(NULL != env->get_property);
-
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_RBF_DIVISOR", &solver->parameters.rbf_divisor))
- {
- solver->parameters.rbf_divisor = RIL_DEFAULT_RBF_DIVISOR;
- }
-
- if (GNUNET_OK
- != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MIN",
- &solver->parameters.step_time_min))
- {
- solver->parameters.step_time_min = RIL_DEFAULT_STEP_TIME_MIN;
- }
-
- if (GNUNET_OK
- != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MAX",
- &solver->parameters.step_time_max))
- {
- solver->parameters.step_time_max = RIL_DEFAULT_STEP_TIME_MAX;
- }
-
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_ALGORITHM", &string))
- {
- solver->parameters.algorithm = !strcmp (string, "SARSA") ? RIL_ALGO_SARSA : RIL_ALGO_Q;
- GNUNET_free (string);
- }
- else
- {
- solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM;
- }
-
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SELECT", &string))
- {
- solver->parameters.select = !strcmp (string, "EGREEDY") ? RIL_SELECT_EGREEDY : RIL_SELECT_SOFTMAX;
- GNUNET_free (string);
- }
- else
- {
- solver->parameters.select = RIL_DEFAULT_SELECT;
- }
-
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_DISCOUNT_BETA", &string))
- {
- solver->parameters.beta = strtod (string, NULL);
- GNUNET_free (string);
- if (!(solver->parameters.beta > 0))
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "RIL_DISCOUNT_BETA not configured as positive number. Set to default value of %f instead.\n", RIL_DEFAULT_DISCOUNT_BETA);
- solver->parameters.beta = RIL_DEFAULT_DISCOUNT_BETA;
- }
- }
- else
- {
- solver->parameters.beta = RIL_DEFAULT_DISCOUNT_BETA;
- }
-
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_DISCOUNT_GAMMA", &string))
- {
- solver->parameters.gamma = strtod (string, NULL);
- GNUNET_free (string);
- if (!(solver->parameters.gamma < 1) || (solver->parameters.gamma < 0))
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "RIL_DISCOUNT_GAMMA not configured in range [0,1[. Set to default value of %f instead.\n", RIL_DEFAULT_DISCOUNT_GAMMA);
- solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_GAMMA;
- }
- }
- else
- {
- solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_GAMMA;
- }
-
- if (GNUNET_OK
- == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_GRADIENT_STEP_SIZE", &string))
- {
- solver->parameters.alpha = strtod (string, NULL);
- GNUNET_free (string);
- if (!(solver->parameters.alpha > 0) || solver->parameters.alpha > 1)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "RIL_GRADIENT_STEP_SIZE not configured in range ]0,1]. Set to default value of %f instead.\n", RIL_DEFAULT_GRADIENT_STEP_SIZE);
- solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE;
- }
- }
- else
- {
- solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE;
- }
-
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_TRACE_DECAY", &string))
- {
- solver->parameters.lambda = strtod (string, NULL);
- GNUNET_free (string);
- if (solver->parameters.lambda < 0 || solver->parameters.lambda > 1)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "RIL_TRACE_DECAY not configured in range [0,1]. Set to default value of %f instead.\n", RIL_DEFAULT_TRACE_DECAY);
- solver->parameters.lambda = RIL_DEFAULT_TRACE_DECAY;
- }
- }
- else
- {
- solver->parameters.lambda = RIL_DEFAULT_TRACE_DECAY;
- }
-
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_EXPLORE_RATIO", &string))
- {
- solver->parameters.epsilon_init = strtod (string, NULL);
- GNUNET_free (string);
- if (solver->parameters.epsilon_init < 0 || solver->parameters.epsilon_init > 1)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "RIL_EXPLORE_RATIO not configured in range [0,1]. Set to default value of %f instead.\n", RIL_DEFAULT_EXPLORE_RATIO);
- solver->parameters.epsilon_init = RIL_DEFAULT_EXPLORE_RATIO;
- }
- }
- else
- {
- solver->parameters.epsilon_init = RIL_DEFAULT_EXPLORE_RATIO;
- }
-
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_EXPLORE_DECAY", &string))
- {
- solver->parameters.epsilon_decay = strtod (string, NULL);
- GNUNET_free (string);
- if (solver->parameters.epsilon_decay < 0 || solver->parameters.epsilon_decay > 1)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "RIL_EXPLORE_RATIO not configured in range [0,1]. Set to default value of %f instead.\n", RIL_DEFAULT_EXPLORE_DECAY);
- solver->parameters.epsilon_decay = RIL_DEFAULT_EXPLORE_DECAY;
- }
- }
- else
- {
- solver->parameters.epsilon_decay = RIL_DEFAULT_EXPLORE_DECAY;
- }
-
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_TEMPERATURE", &string))
- {
- solver->parameters.temperature_init = strtod (string, NULL);
- GNUNET_free (string);
- if (solver->parameters.temperature_init <= 0)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "RIL_TEMPERATURE not positive. Set to default value of %f instead.\n", RIL_DEFAULT_TEMPERATURE);
- solver->parameters.temperature_init = RIL_DEFAULT_TEMPERATURE;
- }
- }
- else
- {
- solver->parameters.temperature_init = RIL_DEFAULT_TEMPERATURE;
- }
-
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_TEMPERATURE_DECAY", &string))
- {
- solver->parameters.temperature_decay = strtod (string, NULL);
- GNUNET_free (string);
- if (solver->parameters.temperature_decay <= 0 || solver->parameters.temperature_decay > 1)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "RIL_TEMPERATURE_DECAY not in range [0,1]. Set to default value of %f instead.\n", RIL_DEFAULT_TEMPERATURE_DECAY);
- solver->parameters.temperature_decay = RIL_DEFAULT_TEMPERATURE_DECAY;
- }
- }
- else
- {
- solver->parameters.temperature_decay = RIL_DEFAULT_TEMPERATURE_DECAY;
- }
-
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "ats", "RIL_SIMULATE", &solver->simulate))
- {
- solver->simulate = GNUNET_NO;
- }
-
- if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(env->cfg, "ats", "RIL_REPLACE_TRACES"))
- {
- solver->parameters.eligibility_trace_mode = RIL_E_REPLACE;
- }
- else
- {
- solver->parameters.eligibility_trace_mode = RIL_E_ACCUMULATE;
- }
-
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SOCIAL_WELFARE", &string))
- {
- solver->parameters.social_welfare = !strcmp (string, "NASH") ? RIL_WELFARE_NASH : RIL_WELFARE_EGALITARIAN;
- GNUNET_free (string);
- }
- else
- {
- solver->parameters.social_welfare = RIL_DEFAULT_WELFARE;
- }
-
- env->sf.s_add = &GAS_ril_address_add;
- env->sf.s_address_update_property = &GAS_ril_address_property_changed;
- env->sf.s_address_update_session = &GAS_ril_address_session_changed;
- env->sf.s_address_update_inuse = &GAS_ril_address_inuse_changed;
- env->sf.s_address_update_network = &GAS_ril_address_change_network;
- env->sf.s_get = &GAS_ril_get_preferred_address;
- env->sf.s_get_stop = &GAS_ril_stop_get_preferred_address;
- env->sf.s_pref = &GAS_ril_address_change_preference;
- env->sf.s_feedback = &GAS_ril_address_preference_feedback;
- env->sf.s_del = &GAS_ril_address_delete;
- env->sf.s_bulk_start = &GAS_ril_bulk_start;
- env->sf.s_bulk_stop = &GAS_ril_bulk_stop;
-
- solver->plugin_envi = env;
- solver->networks_count = env->network_count;
- solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Scope));
- solver->step_count = 0;
- solver->done = GNUNET_NO;
-
- for (c = 0; c < env->network_count; c++)
- {
- cur = &solver->network_entries[c];
- cur->type = env->networks[c];
- cur->bw_in_available = env->in_quota[c];
- cur->bw_out_available = env->out_quota[c];
- LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Quotas for %s network: IN %llu - OUT %llu\n", GNUNET_ATS_print_network_type(cur->type), cur->bw_in_available/1024, cur->bw_out_available/1024);
- }
-
- LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Parameters:\n");
- LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Algorithm = %s, alpha = %f, beta = %f, lambda = %f\n",
- solver->parameters.algorithm ? "Q" : "SARSA",
- solver->parameters.alpha,
- solver->parameters.beta,
- solver->parameters.lambda);
- LOG(GNUNET_ERROR_TYPE_DEBUG, "init() exploration_ratio = %f, temperature = %f, ActionSelection = %s\n",
- solver->parameters.epsilon,
- solver->parameters.temperature,
- solver->parameters.select ? "EGREEDY" : "SOFTMAX");
- LOG(GNUNET_ERROR_TYPE_DEBUG, "init() RBF_DIVISOR = %llu\n",
- solver->parameters.rbf_divisor);
-
- return solver;
-}
-
-/**
- * Exit point for the plugin
- *
- * @param cls the solver handle
- */
-void *
-libgnunet_plugin_ats_ril_done (void *cls)
-{
- struct GAS_RIL_Handle *s = cls;
- struct RIL_Peer_Agent *cur_agent;
- struct RIL_Peer_Agent *next_agent;
-
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n");
-
- s->done = GNUNET_YES;
-
- cur_agent = s->agents_head;
- while (NULL != cur_agent)
- {
- next_agent = cur_agent->next;
- GNUNET_CONTAINER_DLL_remove(s->agents_head, s->agents_tail, cur_agent);
- agent_die (s, cur_agent);
- cur_agent = next_agent;
- }
-
- if (GNUNET_SCHEDULER_NO_TASK != s->step_next_task_id)
- {
- GNUNET_SCHEDULER_cancel (s->step_next_task_id);
- }
- GNUNET_free(s->network_entries);
- GNUNET_free(s);
-
- return NULL;
-}
/**
* Add a new address for a peer to the solver
* @param address the address to add
* @param network network type of this address
*/
-void
-GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network)
+static void
+GAS_ril_address_add (void *solver,
+ struct ATS_Address *address,
+ uint32_t network)
{
struct GAS_RIL_Handle *s = solver;
struct RIL_Peer_Agent *agent;
int i;
unsigned int zero;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "API_address_add()\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "API_address_add()\n");
net = ril_get_network (s, network);
address->solver_information = net;
* @param address the address to remove
* @param session_only delete only session not whole address
*/
-void
-GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_only)
+static void
+GAS_ril_address_delete (void *solver,
+ struct ATS_Address *address,
+ int session_only)
{
struct GAS_RIL_Handle *s = solver;
struct RIL_Peer_Agent *agent;
int i;
struct RIL_Scope *net;
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_delete() Delete %s%s %s address %s for peer '%s'\n",
- session_only ? "session for " : "", address->active ? "active" : "inactive", address->plugin,
- address->addr, GNUNET_i2s (&address->peer));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "API_address_delete() Delete %s%s %s address %s for peer '%s'\n",
+ session_only ? "session for " : "", address->active ? "active" : "inactive", address->plugin,
+ address->addr,
+ GNUNET_i2s (&address->peer));
agent = ril_get_agent (s, &address->peer, GNUNET_NO);
if (NULL == agent)
* @param abs_value the absolute value of the property
* @param rel_value the normalized value
*/
-void
+static void
GAS_ril_address_property_changed (void *solver,
- struct ATS_Address *address,
- uint32_t type,
- uint32_t abs_value,
- double rel_value)
+ struct ATS_Address *address,
+ uint32_t type,
+ uint32_t abs_value,
+ double rel_value)
{
+ struct GAS_RIL_Handle *s = solver;
+
LOG(GNUNET_ERROR_TYPE_DEBUG,
"API_address_property_changed() Property '%s' for peer '%s' address %s changed "
- "to %.2f \n", GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer),
+ "to %.2f \n",
+ GNUNET_ATS_print_property_type (type),
+ GNUNET_i2s (&address->peer),
address->addr, rel_value);
- struct GAS_RIL_Handle *s = solver;
s->parameters.temperature = s->parameters.temperature_init;
s->parameters.epsilon = s->parameters.epsilon_init;
ril_step (s);
}
-/**
- * Update the session of an address in the solver
- *
- * NOTE: values in addresses are already updated
- *
- * @param solver solver handle
- * @param address the address
- * @param cur_session the current session
- * @param new_session the new session
- */
-void
-GAS_ril_address_session_changed (void *solver,
- struct ATS_Address *address,
- uint32_t cur_session,
- uint32_t new_session)
-{
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_session_changed()\n");
-}
-
-/**
- * Notify the solver that an address is (not) actively used by transport
- * to communicate with a remote peer
- *
- * NOTE: values in addresses are already updated
- *
- * @param solver solver handle
- * @param address the address
- * @param in_use usage state
- */
-void
-GAS_ril_address_inuse_changed (void *solver, struct ATS_Address *address, int in_use)
-{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "API_address_inuse_changed() Usage for %s address of peer '%s' changed to %s\n",
- address->plugin, GNUNET_i2s (&address->peer), (GNUNET_YES == in_use) ? "USED" : "UNUSED");
-}
-
-/**
- * Notify solver that the network an address is located in has changed
- *
- * NOTE: values in addresses are already updated
- *
- * @param solver solver handle
- * @param address the address
- * @param current_network the current network
- * @param new_network the new network
- */
-void
-GAS_ril_address_change_network (void *solver,
- struct ATS_Address *address,
- uint32_t current_network,
- uint32_t new_network)
-{
- struct GAS_RIL_Handle *s = solver;
- struct RIL_Peer_Agent *agent;
-
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_change_network() Network type changed, moving "
- "%s address of peer %s from '%s' to '%s'\n",
- (GNUNET_YES == address->active) ? "active" : "inactive", GNUNET_i2s (&address->peer),
- GNUNET_ATS_print_network_type (current_network), GNUNET_ATS_print_network_type (new_network));
-
- s->parameters.temperature = s->parameters.temperature_init;
- s->parameters.epsilon = s->parameters.epsilon_init;
-
- if (address->active && !ril_network_is_active (solver, new_network))
- {
- GAS_ril_address_delete (solver, address, GNUNET_NO);
- return;
- }
-
- agent = ril_get_agent (s, &address->peer, GNUNET_NO);
- if (NULL == agent)
- {
- GNUNET_assert(!ril_network_is_active (solver, current_network));
-
- GAS_ril_address_add (s, address, new_network);
- return;
- }
-
- address->solver_information = ril_get_network(solver, new_network);
-}
/**
* Give feedback about the current assignment
* @param kind the kind to change the preference
* @param score the score
*/
-void
+static void
GAS_ril_address_preference_feedback (void *solver,
- void *application,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TIME_Relative scope,
- enum GNUNET_ATS_PreferenceKind kind,
- double score)
-{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for "
- "preference %s for %d seconds\n", GNUNET_i2s (peer), "UNKNOWN",
- GNUNET_ATS_print_preference_type (kind), scope.rel_value_us / 1000000);
+ struct GNUNET_SERVER_Client *application,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TIME_Relative scope,
+ enum GNUNET_ATS_PreferenceKind kind,
+ double score)
+{
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for "
+ "preference %s for %d seconds\n",
+ GNUNET_i2s (peer),
+ "UNKNOWN",
+ GNUNET_ATS_print_preference_type (kind),
+ scope.rel_value_us / 1000000);
}
+
/**
* Start a bulk operation
*
* @param solver the solver
*/
-void
+static void
GAS_ril_bulk_start (void *solver)
{
struct GAS_RIL_Handle *s = solver;
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_start() lock: %d\n", s->bulk_lock+1);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "API_bulk_start() lock: %d\n", s->bulk_lock+1);
s->bulk_lock++;
}
+
/**
* Bulk operation done
*
* @param solver the solver handle
*/
-void
+static void
GAS_ril_bulk_stop (void *solver)
{
struct GAS_RIL_Handle *s = solver;
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_stop() lock: %d\n", s->bulk_lock-1);
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "API_bulk_stop() lock: %d\n",
+ s->bulk_lock - 1);
if (s->bulk_lock < 1)
{
}
}
+
/**
* Tell solver to notify ATS if the address to use changes for a specific
* peer using the bandwidth changed callback
* @param solver the solver handle
* @param peer the identity of the peer
*/
-const struct ATS_Address *
-GAS_ril_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *peer)
+static const struct ATS_Address *
+GAS_ril_get_preferred_address (void *solver,
+ const struct GNUNET_PeerIdentity *peer)
{
struct GAS_RIL_Handle *s = solver;
struct RIL_Peer_Agent *agent;
* @param solver the solver handle
* @param peer the peer
*/
-void
-GAS_ril_stop_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *peer)
+static void
+GAS_ril_stop_get_preferred_address (void *solver,
+ const struct GNUNET_PeerIdentity *peer)
{
struct GAS_RIL_Handle *s = solver;
struct RIL_Peer_Agent *agent;
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_stop_get_preferred_address()");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "API_stop_get_preferred_address()");
agent = ril_get_agent (s, peer, GNUNET_NO);
GNUNET_i2s (peer), agent->address_inuse->plugin);
}
+
+/**
+ * Entry point for the plugin
+ *
+ * @param cls pointer to the 'struct GNUNET_ATS_PluginEnvironment'
+ */
+void *
+libgnunet_plugin_ats_ril_init (void *cls)
+{
+ static struct GNUNET_ATS_SolverFunctions sf;
+ struct GNUNET_ATS_PluginEnvironment *env = cls;
+ struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle);
+ struct RIL_Scope * cur;
+ int c;
+ char *string;
+ float f_tmp;
+
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "API_init() Initializing RIL solver\n");
+
+ GNUNET_assert(NULL != env);
+ GNUNET_assert(NULL != env->cfg);
+ GNUNET_assert(NULL != env->stats);
+ GNUNET_assert(NULL != env->bandwidth_changed_cb);
+ GNUNET_assert(NULL != env->get_preferences);
+ GNUNET_assert(NULL != env->get_property);
+
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_RBF_DIVISOR", &solver->parameters.rbf_divisor))
+ {
+ solver->parameters.rbf_divisor = RIL_DEFAULT_RBF_DIVISOR;
+ }
+
+ if (GNUNET_OK
+ != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MIN",
+ &solver->parameters.step_time_min))
+ {
+ solver->parameters.step_time_min = RIL_DEFAULT_STEP_TIME_MIN;
+ }
+
+ if (GNUNET_OK
+ != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MAX",
+ &solver->parameters.step_time_max))
+ {
+ solver->parameters.step_time_max = RIL_DEFAULT_STEP_TIME_MAX;
+ }
+
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_ALGORITHM", &string))
+ {
+ GNUNET_STRINGS_utf8_toupper (string, string);
+ if (0 == strcmp (string, "SARSA"))
+ {
+ solver->parameters.algorithm = RIL_ALGO_SARSA;
+ }
+ if (0 == strcmp (string, "Q-LEARNING"))
+ {
+ solver->parameters.algorithm = RIL_ALGO_Q;
+ }
+
+ GNUNET_free (string);
+ }
+ else
+ {
+ solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM;
+ }
+
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SELECT", &string))
+ {
+ solver->parameters.select = !strcmp (string, "EGREEDY") ? RIL_SELECT_EGREEDY : RIL_SELECT_SOFTMAX;
+ GNUNET_free (string);
+ }
+ else
+ {
+ solver->parameters.select = RIL_DEFAULT_SELECT;
+ }
+
+
+ solver->parameters.beta = RIL_DEFAULT_DISCOUNT_BETA;
+ if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+ "RIL_DISCOUNT_BETA", &f_tmp))
+ {
+ if (f_tmp < 0.0)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
+ "RIL_DISCOUNT_BETA", f_tmp);
+ }
+ else
+ {
+ solver->parameters.beta = f_tmp;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
+ "RIL_DISCOUNT_BETA", f_tmp);
+ }
+ }
+
+ solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_GAMMA;
+ if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+ "RIL_DISCOUNT_GAMMA", &f_tmp))
+ {
+ if ((f_tmp < 0.0) || (f_tmp > 1.0))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
+ "RIL_DISCOUNT_GAMMA", f_tmp);
+ }
+ else
+ {
+ solver->parameters.gamma = f_tmp;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
+ "RIL_DISCOUNT_GAMMA", f_tmp);
+ }
+ }
+
+ solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE;
+ if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+ "RIL_GRADIENT_STEP_SIZE", &f_tmp))
+ {
+ if ((f_tmp < 0.0) || (f_tmp > 1.0))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
+ "RIL_GRADIENT_STEP_SIZE", f_tmp);
+ }
+ else
+ {
+ solver->parameters.alpha = f_tmp;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
+ "RIL_GRADIENT_STEP_SIZE", f_tmp);
+ }
+ }
+
+ solver->parameters.lambda = RIL_DEFAULT_TRACE_DECAY;
+ if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+ "RIL_TRACE_DECAY", &f_tmp))
+ {
+ if ((f_tmp < 0.0) || (f_tmp > 1.0))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
+ "RIL_TRACE_DECAY", f_tmp);
+ }
+ else
+ {
+ solver->parameters.lambda = f_tmp;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
+ "RIL_TRACE_DECAY", f_tmp);
+ }
+ }
+
+ solver->parameters.epsilon_init = RIL_DEFAULT_EXPLORE_RATIO;
+ if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+ "RIL_EXPLORE_RATIO", &f_tmp))
+ {
+ if ((f_tmp < 0.0) || (f_tmp > 1.0))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
+ "RIL_EXPLORE_RATIO", f_tmp);
+ }
+ else
+ {
+ solver->parameters.epsilon_init = f_tmp;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
+ "RIL_EXPLORE_RATIO", f_tmp);
+ }
+ }
+
+ solver->parameters.epsilon_decay = RIL_DEFAULT_EXPLORE_DECAY;
+ if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+ "RIL_EXPLORE_DECAY", &f_tmp))
+ {
+ if ((f_tmp < 0.0) || (f_tmp > 1.0))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
+ "RIL_EXPLORE_DECAY", f_tmp);
+ }
+ else
+ {
+ solver->parameters.epsilon_decay = f_tmp;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
+ "RIL_EXPLORE_DECAY", f_tmp);
+ }
+ }
+
+ solver->parameters.temperature_init = RIL_DEFAULT_TEMPERATURE;
+ if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+ "RIL_TEMPERATURE", &f_tmp))
+ {
+ if (f_tmp <= 0.0)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
+ "RIL_TEMPERATURE", f_tmp);
+ }
+ else
+ {
+ solver->parameters.temperature_init = f_tmp;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
+ "RIL_TEMPERATURE", f_tmp);
+ }
+ }
+
+ solver->parameters.temperature_decay = RIL_DEFAULT_TEMPERATURE_DECAY;
+ if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+ "RIL_TEMPERATURE_DECAY", &f_tmp))
+ {
+ if ((f_tmp <= 0.0) || solver->parameters.temperature_decay > 1)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
+ "RIL_TEMPERATURE_DECAY", f_tmp);
+ }
+ else
+ {
+ solver->parameters.temperature_decay = f_tmp;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
+ "RIL_TEMPERATURE_DECAY", f_tmp);
+ }
+ }
+
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "ats", "RIL_SIMULATE", &solver->simulate))
+ {
+ solver->simulate = GNUNET_NO;
+ }
+
+ if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(env->cfg, "ats", "RIL_REPLACE_TRACES"))
+ {
+ solver->parameters.eligibility_trace_mode = RIL_E_REPLACE;
+ }
+ else
+ {
+ solver->parameters.eligibility_trace_mode = RIL_E_ACCUMULATE;
+ }
+
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SOCIAL_WELFARE", &string))
+ {
+ solver->parameters.social_welfare = !strcmp (string, "NASH") ? RIL_WELFARE_NASH : RIL_WELFARE_EGALITARIAN;
+ GNUNET_free (string);
+ }
+ else
+ {
+ solver->parameters.social_welfare = RIL_DEFAULT_WELFARE;
+ }
+
+ solver->env = env;
+ sf.cls = solver;
+ sf.s_add = &GAS_ril_address_add;
+ sf.s_address_update_property = &GAS_ril_address_property_changed;
+ sf.s_get = &GAS_ril_get_preferred_address;
+ sf.s_get_stop = &GAS_ril_stop_get_preferred_address;
+ sf.s_pref = &GAS_ril_address_change_preference;
+ sf.s_feedback = &GAS_ril_address_preference_feedback;
+ sf.s_del = &GAS_ril_address_delete;
+ sf.s_bulk_start = &GAS_ril_bulk_start;
+ sf.s_bulk_stop = &GAS_ril_bulk_stop;
+
+ solver->networks_count = env->network_count;
+ solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Scope));
+ solver->step_count = 0;
+ solver->done = GNUNET_NO;
+
+ for (c = 0; c < env->network_count; c++)
+ {
+ cur = &solver->network_entries[c];
+ cur->type = env->networks[c];
+ cur->bw_in_available = env->in_quota[c];
+ cur->bw_out_available = env->out_quota[c];
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Quotas for %s network: IN %llu - OUT %llu\n", GNUNET_ATS_print_network_type(cur->type), cur->bw_in_available/1024, cur->bw_out_available/1024);
+ }
+
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Parameters:\n");
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Algorithm = %s, alpha = %f, beta = %f, lambda = %f\n",
+ solver->parameters.algorithm ? "Q" : "SARSA",
+ solver->parameters.alpha,
+ solver->parameters.beta,
+ solver->parameters.lambda);
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "init() exploration_ratio = %f, temperature = %f, ActionSelection = %s\n",
+ solver->parameters.epsilon,
+ solver->parameters.temperature,
+ solver->parameters.select ? "EGREEDY" : "SOFTMAX");
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "init() RBF_DIVISOR = %llu\n",
+ solver->parameters.rbf_divisor);
+
+ return &sf;
+}
+
+
+/**
+ * Exit point for the plugin
+ *
+ * @param cls the solver handle
+ */
+void *
+libgnunet_plugin_ats_ril_done (void *cls)
+{
+ struct GNUNET_ATS_SolverFunctions *sf = cls;
+ struct GAS_RIL_Handle *s = sf->cls;
+ struct RIL_Peer_Agent *cur_agent;
+ struct RIL_Peer_Agent *next_agent;
+
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n");
+
+ s->done = GNUNET_YES;
+
+ cur_agent = s->agents_head;
+ while (NULL != cur_agent)
+ {
+ next_agent = cur_agent->next;
+ GNUNET_CONTAINER_DLL_remove(s->agents_head, s->agents_tail, cur_agent);
+ agent_die (s, cur_agent);
+ cur_agent = next_agent;
+ }
+
+ if (NULL != s->step_next_task_id)
+ {
+ GNUNET_SCHEDULER_cancel (s->step_next_task_id);
+ }
+ GNUNET_free(s->network_entries);
+ GNUNET_free(s);
+
+ return NULL;
+}
+
+
/* end of plugin_ats_ril.c */