/*
This file is part of GNUnet.
- (C) 2011-2014 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2011-2014 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
struct ATS_Address *address_naked;
};
+
struct RIL_Peer_Agent
{
/**
/**
* Last perceived state feature vector
*/
- double * s_old;
+ double *s_old;
/**
* Last chosen action
/**
* Address in use
*/
- struct ATS_Address * address_inuse;
+ struct ATS_Address *address_inuse;
/**
* Head of addresses DLL
*/
- struct RIL_Address_Wrapped * addresses_head;
+ struct RIL_Address_Wrapped *addresses_head;
/**
* Tail of addresses DLL
*/
- struct RIL_Address_Wrapped * addresses_tail;
+ struct RIL_Address_Wrapped *addresses_tail;
/**
* Inbound bandwidth assigned by the agent
/**
* The address which has to be issued
*/
- struct ATS_Address * suggestion_address;
+ struct ATS_Address *suggestion_address;
/**
* The agent's last objective value
* @return estimation value
*/
static double
-agent_q (struct RIL_Peer_Agent *agent, double *state, int action)
+agent_q (struct RIL_Peer_Agent *agent,
+ const double *state,
+ int action)
{
- int i;
- double result = 0;
+ unsigned int i;
+ double result = 0.0;
for (i = 0; i < agent->m; i++)
- {
result += state[i] * agent->W[action][i];
- }
- GNUNET_assert(!isnan(result));
-
- //prevent crash when learning diverges
+ /* prevent crashes if learning diverges */
+ if (isnan(result))
+ return isnan(result) * UINT32_MAX;
if (isinf(result))
- {
return isinf(result) * UINT32_MAX;
- }
return result;
}
enum GAS_Solver_Operation op,
enum GAS_Solver_Status stat)
{
- if (NULL != solver->env->info_cb)
- solver->env->info_cb (solver->env->cls, op, stat, GAS_INFO_NONE);
+ solver->env->info_cb (solver->env->cls,
+ op,
+ stat,
+ GAS_INFO_NONE);
}
/**
* @param new_address the address which is to be used
* @param new_bw_in the new amount of inbound bandwidth set for this address
* @param new_bw_out the new amount of outbound bandwidth set for this address
- * @param silent disables invocation of the bw_changed callback, if GNUNET_YES
+ * @param silent disables invocation of the bw_changed callback, if #GNUNET_YES
*/
static void
envi_set_active_suggestion (struct GAS_RIL_Handle *solver,
{
int notify = GNUNET_NO;
- LOG(GNUNET_ERROR_TYPE_DEBUG, " set_active_suggestion() for peer '%s'\n", GNUNET_i2s (&agent->peer));
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ " set_active_suggestion() for peer '%s'\n",
+ GNUNET_i2s (&agent->peer));
//address change
if (agent->address_inuse != new_address)
return state;
}
-/**
- * Retrieves an ATS information value of an address
- *
- * @param address the address in question
- * @param type the ATS information type
- * @return the value
- */
-static unsigned int
-ril_get_atsi (struct ATS_Address *address, uint32_t type)
-{
- int c1;
- GNUNET_assert(NULL != address);
-
- if ((NULL == address->atsi) || (0 == address->atsi_count))
- return GNUNET_ATS_QUALITY_NET_DELAY == type ? UINT32_MAX : 1;
-
- for (c1 = 0; c1 < address->atsi_count; c1++)
- {
- if (ntohl (address->atsi[c1].type) == type)
- return ntohl (address->atsi[c1].value);
- }
- return GNUNET_ATS_QUALITY_NET_DELAY == type ? UINT32_MAX : 1;
-}
/**
* Returns the utility value of the connection an agent manages
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_atsi = agent->address_inuse->norm_delay.norm;
delay_norm = RIL_UTILITY_DELAY_MAX*exp(-delay_atsi*0.00001);
pref_match = preferences[GNUNET_ATS_PREFERENCE_LATENCY] * delay_norm;
pref_match += preferences[GNUNET_ATS_PREFERENCE_BANDWIDTH] *
sqrt((double) (agent->bw_in/RIL_MIN_BW) * (double) (agent->bw_out/RIL_MIN_BW));
-// sqrt((double) (ril_get_atsi (agent->address_inuse, GNUNET_ATS_UTILIZATION_IN)/RIL_MIN_BW) * (double) (ril_get_atsi (agent->address_inuse, GNUNET_ATS_UTILIZATION_OUT)/RIL_MIN_BW));
-
-// return (double) (agent->bw_in/RIL_MIN_BW);
-// return sqrt((double) (agent->bw_in/RIL_MIN_BW) * (double) (agent->bw_out/RIL_MIN_BW));
return pref_match;
}
if (agent_action_is_possible(agent, i))
{
eqt[i] = exp(agent_q(agent,state,i) / agent->envi->parameters.temperature);
+ if (isinf (eqt[i]))
+ eqt[i] = isinf(eqt[i]) * UINT32_MAX;
sum += eqt[i];
}
}
static void
ril_step (struct GAS_RIL_Handle *solver);
+
/**
* Task for the scheduler, which performs one step and lets the solver know that
* no further step is scheduled.
*
* @param cls the solver handle
- * @param tc the task context for the scheduler
*/
static void
-ril_step_scheduler_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+ril_step_scheduler_task (void *cls)
{
struct GAS_RIL_Handle *solver = cls;
if (net->type == type)
{
if (direction_in)
- sum += ril_get_atsi (cur->address_inuse, GNUNET_ATS_UTILIZATION_IN);
+ sum += cur->address_inuse->norm_utilization_in.norm;
else
- sum += ril_get_atsi (cur->address_inuse, GNUNET_ATS_UTILIZATION_OUT);
+ sum += cur->address_inuse->norm_utilization_out.norm;
}
}
}
ril_networks_update_state (solver);
- solver->step_count += 1;
+ solver->step_count++;
ril_step_schedule_next (solver);
ril_inform (solver, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS);
for (cur = solver->agents_head; NULL != cur; cur = cur->next)
{
if (cur->suggestion_issue) {
- solver->env->bandwidth_changed_cb(solver->env->cls, cur->suggestion_address);
+ solver->env->bandwidth_changed_cb (solver->env->cls,
+ cur->suggestion_address);
cur->suggestion_issue = GNUNET_NO;
}
}
*
* @param solver the solver handle
* @param address the address to remove
- * @param session_only delete only session not whole address
*/
static void
GAS_ril_address_delete (void *solver,
- struct ATS_Address *address,
- int session_only)
+ struct ATS_Address *address)
{
struct GAS_RIL_Handle *s = solver;
struct RIL_Peer_Agent *agent;
struct RIL_Address_Wrapped *address_wrapped;
- int address_was_used = address->active;
int address_index;
unsigned int m_new;
unsigned int n_new;
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,
+ "API_address_delete() Delete %s %s address %s for peer '%s'\n",
+ address->active ? "active" : "inactive",
+ address->plugin,
address->addr,
GNUNET_i2s (&address->peer));
if (NULL == agent)
{
net = address->solver_information;
- GNUNET_assert(!ril_network_is_active (s, net->type));
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "No agent allocated for peer yet, since address was in inactive network\n");
+ GNUNET_assert(! ril_network_is_active (s, net->type));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "No agent allocated for peer yet, since address was in inactive network\n");
return;
}
if (NULL == address_wrapped)
{
net = address->solver_information;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Address not considered by agent, address was in inactive network\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Address not considered by agent, address was in inactive network\n");
return;
}
-
- GNUNET_CONTAINER_DLL_remove(agent->addresses_head, agent->addresses_tail, address_wrapped);
- GNUNET_free(address_wrapped);
+ GNUNET_CONTAINER_DLL_remove (agent->addresses_head,
+ agent->addresses_tail,
+ address_wrapped);
+ GNUNET_free (address_wrapped);
//decrease W
m_new = agent->m - ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1));
}
//decrease old state vector
ril_cut_from_vector ((void **) &agent->s_old, sizeof(double),
- address_index * ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)),
- ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), agent->m);
+ address_index * ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)),
+ ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), agent->m);
agent->m = m_new;
agent->n = n_new;
- if (address_was_used)
+ if (agent->address_inuse == address)
{
if (NULL != agent->addresses_head) //if peer has an address left, use it
{
- envi_set_active_suggestion (s, agent, agent->addresses_head->address_naked, agent->bw_in, agent->bw_out,
- GNUNET_YES);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Active address died, suggesting alternative!\n");
+ envi_set_active_suggestion (s,
+ agent,
+ agent->addresses_head->address_naked,
+ agent->bw_in,
+ agent->bw_out,
+ GNUNET_YES);
}
else
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Active address died, suggesting disconnect!\n");
envi_set_active_suggestion (s, agent, NULL, 0, 0, GNUNET_NO);
}
}
-
ril_step (solver);
+ if (agent->suggestion_address == address)
+ {
+ agent->suggestion_issue = GNUNET_NO;
+ agent->suggestion_address = NULL;
+ }
+ GNUNET_assert (agent->address_inuse != address);
}
+
/**
* Update the properties of an address in the solver
*
* @param solver solver handle
* @param address the address
- * @param type the ATSI type in HBO
- * @param abs_value the absolute value of the property
- * @param rel_value the normalized value
*/
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)
{
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),
- address->addr, rel_value);
-
-
+ "Properties for peer '%s' address changed\n",
+ GNUNET_i2s (&address->peer));
s->parameters.temperature = s->parameters.temperature_init;
s->parameters.epsilon = s->parameters.epsilon_init;
ril_step (s);
* @param solver the solver handle
* @param peer the identity of the peer
*/
-static const struct ATS_Address *
+static void
GAS_ril_get_preferred_address (void *solver,
const struct GNUNET_PeerIdentity *peer)
{
s->parameters.temperature = s->parameters.temperature_init;
s->parameters.epsilon = s->parameters.epsilon_init;
}
- return agent->address_inuse;
+ if (NULL != agent->address_inuse)
+ s->env->bandwidth_changed_cb (s->env->cls,
+ agent->address_inuse);
}
+
/**
* Tell solver stop notifying ATS about changes for this peers
*
ril_step (s);
LOG(GNUNET_ERROR_TYPE_DEBUG,
- "API_stop_get_preferred_address() Paused agent for peer '%s' with %s address\n",
- GNUNET_i2s (peer), agent->address_inuse->plugin);
+ "API_stop_get_preferred_address() Paused agent for peer '%s'\n",
+ GNUNET_i2s (peer));
}
char *string;
float f_tmp;
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_init() Initializing RIL solver\n");
+ 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);
+ 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);
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_RBF_DIVISOR", &solver->parameters.rbf_divisor))
{
for (c = 0; c < env->network_count; c++)
{
cur = &solver->network_entries[c];
- cur->type = env->networks[c];
+ cur->type = 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() 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");