#include "gnunet_util_lib.h"
#include "gnunet-ats-solver-eval.h"
-
#define BIG_M_STRING "unlimited"
static struct Experiment *e;
-static struct GNUNET_ATS_TESTING_SolverHandle *sh;
+static struct LoggingHandle *l;
+
+static struct SolverHandle *sh;
+
+static struct TestPeer *peer_head;
+static struct TestPeer *peer_tail;
/**
* cmd option -e: experiment file
*/
static int opt_verbose;
+/**
+ * cmd option -p: print logs
+ */
+static int opt_print;
+
static int res;
static void
end_now ();
+static char *
+print_generator_type (enum GeneratorType g)
+{
+ switch (g) {
+ case GNUNET_ATS_TEST_TG_CONSTANT:
+ return "CONSTANT";
+ case GNUNET_ATS_TEST_TG_LINEAR:
+ return "LINEAR";
+ case GNUNET_ATS_TEST_TG_RANDOM:
+ return "RANDOM";
+ case GNUNET_ATS_TEST_TG_SINUS:
+ return "SINUS";
+ default:
+ return "INVALID";
+ break;
+ }
+}
+
+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)
+{
+ struct TestPeer *cur;
+ for (cur = peer_head; NULL != cur; cur = cur->next)
+ if (cur->id == id)
+ return cur;
+ return NULL;
+}
+
+static struct TestAddress *
+find_address_by_id (struct TestPeer *peer, int aid)
+{
+ struct TestAddress *cur;
+ for (cur = peer->addr_head; NULL != cur; cur = cur->next)
+ if (cur->aid == aid)
+ return cur;
+ return NULL;
+}
+
+
+
+/**
+ * Logging
+ */
+
+void
+GNUNET_ATS_solver_logging_now (struct LoggingHandle *l)
+{
+ struct LoggingTimeStep *lts;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging\n");
+
+ lts = GNUNET_new (struct LoggingTimeStep);
+ lts->timestamp = GNUNET_TIME_absolute_get();
+
+ /* Store logging data here */
+
+ GNUNET_CONTAINER_DLL_insert_tail(l->head, l->tail, lts);
+
+}
+
+static void
+logging_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct LoggingHandle *l = cls;
+ l->logging_task = GNUNET_SCHEDULER_NO_TASK;
+
+ GNUNET_ATS_solver_logging_now (l);
+
+ l->logging_task = GNUNET_SCHEDULER_add_delayed (l->log_freq, &logging_task, l);
+
+}
+
+struct LoggingHandle *
+GNUNET_ATS_solver_logging_start (struct GNUNET_TIME_Relative freq)
+{
+ struct LoggingHandle *l;
+ l = GNUNET_new (struct LoggingHandle);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start logging every %s\n",
+ GNUNET_STRINGS_relative_time_to_string(freq, GNUNET_NO));
+
+ /* Iterate over peers */
+
+ l->log_freq = freq;
+ l->logging_task = GNUNET_SCHEDULER_add_now (&logging_task, l);
+
+ return l;
+}
+
+void
+GNUNET_ATS_solver_logging_stop (struct LoggingHandle *l)
+{
+ if (GNUNET_SCHEDULER_NO_TASK != 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;
+}
+
+void
+GNUNET_ATS_solver_logging_eval (struct LoggingHandle *l)
+{
+ struct LoggingTimeStep *lts;
+
+ for (lts = l->head; NULL != lts; lts = lts->next)
+ {
+ fprintf (stderr, "Log %llu: \n", (long long unsigned int) lts->timestamp.abs_value_us);
+ }
+}
+
+void
+GNUNET_ATS_solver_logging_free (struct LoggingHandle *l)
+{
+ struct LoggingTimeStep *cur;
+ struct LoggingTimeStep *next;
+
+ if (GNUNET_SCHEDULER_NO_TASK != l->logging_task)
+ GNUNET_SCHEDULER_cancel (l->logging_task);
+ l->logging_task = GNUNET_SCHEDULER_NO_TASK;
+
+ next = l->head;
+ while (NULL != (cur = next))
+ {
+ next = cur->next;
+ GNUNET_CONTAINER_DLL_remove (l->head, l->tail, cur);
+ GNUNET_free (cur);
+ }
+
+ GNUNET_free (l);
+}
/**
* Property Generators
static void
-set_prop_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+set_prop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PropertyGenerator *pg = cls;
double pref_value;
+ struct GNUNET_ATS_Information atsi;
+
pg->set_task = GNUNET_SCHEDULER_NO_TASK;
+ if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains_value (sh->addresses,
+ &pg->test_peer->peer_id, pg->test_address->ats_addr))
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Setting property generation for unknown address [%u:%u]\n",
+ pg->peer, pg->address_id);
+ return;
+ }
+
pref_value = get_property (pg);
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
pg->peer, pg->address_id,
GNUNET_ATS_print_property_type (pg->ats_property), pref_value);
- /* set performance here!
- GNUNET_ATS_performance_change_preference(p->me->ats_perf_handle,
- &p->dest->id, p->pg->kind, pref_value, GNUNET_ATS_PREFERENCE_END);
-*/
+
+ atsi.type = htonl (pg->ats_property);
+ atsi.value = htonl ((uint32_t) pref_value);
+
+ /* set performance here! */
+ sh->env.sf.s_bulk_start (sh->solver);
+ GAS_normalization_normalize_property (sh->addresses,
+ pg->test_address->ats_addr, &atsi, 1);
+ sh->env.sf.s_bulk_stop (sh->solver);
switch (pg->ats_property) {
case GNUNET_ATS_PREFERENCE_BANDWIDTH:
/**
- * Generate between the source master and the partner and set preferences with a
+ * Generate between the source master and the partner and set property with a
* value depending on the generator.
*
- * @param src source
- * @param dest partner
- * @param type type of preferences to generate
- * @param base_rate traffic base rate to send data with
- * @param max_rate traffic maximum rate to send data with
- * @param period duration of a period of traffic generation (~ 1/frequency)
- * @param duration how long to generate traffic
- * @return the traffic generator
+ * @param peer source
+ * @param address_id partner
+ * @param test_peer the peer
+ * @param test_address the address
+ * @param type type of generator
+ * @param base_value base value
+ * @param value_rate maximum value
+ * @param period duration of a period of generation (~ 1/frequency)
+ * @param frequency how long to generate property
+ * @param ats_property ATS property to generate
+ * @return the property generator
*/
struct PropertyGenerator *
GNUNET_ATS_solver_generate_property_start (unsigned int peer,
unsigned int address_id,
+ struct TestPeer *test_peer,
+ struct TestAddress *test_address,
enum GeneratorType type,
long int base_value,
long int value_rate,
GNUNET_CONTAINER_DLL_insert (prop_gen_head, prop_gen_tail, pg);
pg->type = type;
pg->peer = peer;
+ pg->test_address = test_address;
+ pg->test_peer = test_peer;
pg->address_id = address_id;
pg->ats_property = ats_property;
pg->base_value = base_value;
switch (type) {
case GNUNET_ATS_TEST_TG_CONSTANT:
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up constant property generator peer [%u] address [%u] `%s' max %u Bips\n",
- pg->peer, pg->address_id, GNUNET_ATS_print_property_type (ats_property),
+ "Setting up %s property generator peer [%u] address [%u] `%s'"\
+ "max %u Bips\n",
+ print_generator_type(type), pg->peer, pg->address_id,
+ GNUNET_ATS_print_property_type (ats_property),
base_value);
break;
case GNUNET_ATS_TEST_TG_LINEAR:
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up linear property generator peer [%u] address [%u] `%s' min %u Bips max %u Bips\n",
- pg->peer, pg->address_id, GNUNET_ATS_print_property_type(ats_property),
+ "Setting up %s property generator peer [%u] address [%u] `%s' " \
+ "min %u Bips max %u Bips\n",
+ print_generator_type(type), pg->peer, pg->address_id,
+ GNUNET_ATS_print_property_type(ats_property),
base_value, value_rate);
break;
case GNUNET_ATS_TEST_TG_SINUS:
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up sinus property generator peer [%u] address [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
- pg->peer, pg->address_id, GNUNET_ATS_print_property_type(ats_property),
+ "Setting up %s property generator peer [%u] address [%u] `%s' "\
+ "baserate %u Bips, amplitude %u Bps\n",
+ print_generator_type(type), pg->peer, pg->address_id,
+ GNUNET_ATS_print_property_type(ats_property),
base_value, value_rate);
-
break;
case GNUNET_ATS_TEST_TG_RANDOM:
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up random property generator peer [%u] address [%u] `%s' min %u Bips max %u Bps\n",
- pg->peer, pg->address_id, GNUNET_ATS_print_property_type(ats_property),
+ "Setting up %s property generator peer [%u] address [%u] `%s' "\
+ "min %u Bips max %u Bps\n",
+ print_generator_type(type), pg->peer, pg->address_id,
+ GNUNET_ATS_print_property_type(ats_property),
base_value, value_rate);
break;
default:
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct PreferenceGenerator *pg = cls;
+ struct TestPeer *p;
double pref_value;
pg->set_task = GNUNET_SCHEDULER_NO_TASK;
+ if (NULL == (p = find_peer_by_id (pg->peer)))
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Setting preference for unknown peer %u\n", pg->peer);
+ return;
+ }
+
pref_value = get_preference (pg);
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Setting preference for peer [%u] address [%u] for %s to %f\n",
- pg->peer, pg->address_id,
+ "Setting preference for peer [%u] address [%u] for client %p pref %s to %f\n",
+ pg->peer, pg->address_id, NULL + (pg->client_id),
GNUNET_ATS_print_preference_type (pg->kind), pref_value);
- /* set performance here!
- GNUNET_ATS_performance_change_preference(p->me->ats_perf_handle,
- &p->dest->id, p->pg->kind, pref_value, GNUNET_ATS_PREFERENCE_END);
-*/
+ sh->env.sf.s_bulk_start (sh->solver);
+ 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:
/**
- * Generate between the source master and the partner and set preferences with a
+ * Generate between the source master and the partner and set property with a
* value depending on the generator.
*
- * @param src source
- * @param dest partner
- * @param type type of preferences to generate
- * @param base_rate traffic base rate to send data with
- * @param max_rate traffic maximum rate to send data with
- * @param period duration of a period of traffic generation (~ 1/frequency)
- * @param duration how long to generate traffic
- * @return the traffic generator
+ * @param peer source
+ * @param address_id partner
+ * @param client_id the client
+ * @param type type of generator
+ * @param base_value base value
+ * @param value_rate maximum value
+ * @param period duration of a period of generation (~ 1/frequency)
+ * @param frequency how long to generate property
+ * @param kind ATS preference to generate
+ * @return the preference generator
*/
struct PreferenceGenerator *
GNUNET_ATS_solver_generate_preferences_start (unsigned int peer,
unsigned int address_id,
+ unsigned int client_id,
enum GeneratorType type,
long int base_value,
long int value_rate,
pg->type = type;
pg->peer = peer;
pg->address_id = address_id;
+ pg->client_id = client_id;
pg->kind = kind;
pg->base_value = base_value;
pg->max_value = value_rate;
switch (type) {
case GNUNET_ATS_TEST_TG_CONSTANT:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Setting up constant preference generator peer [%u] address [%u] `%s' max %u Bips\n",
- pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
+ "Setting up %s preference generator peer [%u] address [%u] `%s' max %u Bips\n",
+ print_generator_type (type), pg->peer, pg->address_id,
+ GNUNET_ATS_print_preference_type(kind),
base_value);
break;
case GNUNET_ATS_TEST_TG_LINEAR:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Setting up linear preference generator peer [%u] address [%u] `%s' min %u Bips max %u Bips\n",
- pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
+ "Setting up %s preference generator peer [%u] address [%u] `%s' min %u Bips max %u Bips\n",
+ print_generator_type (type), pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
base_value, value_rate);
break;
case GNUNET_ATS_TEST_TG_SINUS:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Setting up sinus preference generator peer [%u] address [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
- pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
+ "Setting up %s preference generator peer [%u] address [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
+ print_generator_type (type), pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
base_value, value_rate);
-
break;
case GNUNET_ATS_TEST_TG_RANDOM:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Setting up random preference generator peer [%u] address [%u] `%s' min %u Bips max %u Bps\n",
- pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
+ "Setting up %s preference generator peer [%u] address [%u] `%s' min %u Bips max %u Bps\n",
+ print_generator_type (type), pg->peer, pg->address_id, GNUNET_ATS_print_preference_type(kind),
base_value, value_rate);
break;
default:
case SOLVER_OP_STOP_SET_PREFERENCE:
return "STOP_STOP_PREFERENCE";
case SOLVER_OP_START_SET_PROPERTY:
- return "START_SET_PROPERTY";
+ return "START_SET_PROPERTY";
case SOLVER_OP_STOP_SET_PROPERTY:
return "STOP_SET_PROPERTY";
+ case SOLVER_OP_START_REQUEST:
+ return "START_REQUEST";
+ case SOLVER_OP_STOP_REQUEST:
+ return "STOP_REQUEST";
default:
break;
}
struct Experiment *e;
e = GNUNET_new (struct Experiment);
e->name = NULL;
- e->num_masters = 0;
- e->num_slaves = 0;
e->start = NULL;
e->total_duration = GNUNET_TIME_UNIT_ZERO;
return e;
}
GNUNET_free (op_name);
+ /* address id */
+ GNUNET_asprintf(&op_name, "op-%u-client-id", op_counter);
+ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
+ sec_name, op_name, &o->client_id))
+ {
+ fprintf (stderr, "Missing client-id in operation %u `%s' in episode `%s'\n",
+ op_counter, "START_SET_PREFERENCE", op_name);
+ GNUNET_free (op_name);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (op_name);
+
/* generator */
GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
/* Load arguments for set_rate, start_send, set_preference */
if (0 == strcmp (type, "constant"))
{
- o->tg_type = GNUNET_ATS_TEST_TG_CONSTANT;
+ o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
}
else if (0 == strcmp (type, "linear"))
{
- o->tg_type = GNUNET_ATS_TEST_TG_LINEAR;
+ o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
}
else if (0 == strcmp (type, "sinus"))
{
- o->tg_type = GNUNET_ATS_TEST_TG_SINUS;
+ o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
}
else if (0 == strcmp (type, "random"))
{
- o->tg_type = GNUNET_ATS_TEST_TG_RANDOM;
+ o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
}
else
{
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
sec_name, op_name, &o->max_rate))
{
- if ((GNUNET_ATS_TEST_TG_LINEAR == o->tg_type) ||
- (GNUNET_ATS_TEST_TG_RANDOM == o->tg_type) ||
- (GNUNET_ATS_TEST_TG_SINUS == o->tg_type))
+ if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
+ (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
+ (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
{
fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
op_counter, op_name, e->id);
/* Load arguments for set_rate, start_send, set_preference */
if (0 == strcmp (type, "constant"))
{
- o->tg_type = GNUNET_ATS_TEST_TG_CONSTANT;
- GNUNET_break (0);
+ o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
}
else if (0 == strcmp (type, "linear"))
{
- o->tg_type = GNUNET_ATS_TEST_TG_LINEAR;
- GNUNET_break (0);
+ o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
}
else if (0 == strcmp (type, "sinus"))
{
- o->tg_type = GNUNET_ATS_TEST_TG_SINUS;
- GNUNET_break (0);
+ o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
}
else if (0 == strcmp (type, "random"))
{
- o->tg_type = GNUNET_ATS_TEST_TG_RANDOM;
- GNUNET_break (0);
+ o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
}
else
{
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
sec_name, op_name, &o->max_rate))
{
- if ((GNUNET_ATS_TEST_TG_LINEAR == o->tg_type) ||
- (GNUNET_ATS_TEST_TG_RANDOM == o->tg_type) ||
- (GNUNET_ATS_TEST_TG_SINUS == o->tg_type))
+ if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
+ (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
+ (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
{
fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
op_counter, op_name, e->id);
fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
op_counter, op_name, e->id);
GNUNET_free (op_name);
- GNUNET_free (pref);
GNUNET_free_non_null (pref);
return GNUNET_SYSERR;
}
return GNUNET_OK;
}
+
+static int
+load_op_start_request (struct GNUNET_ATS_TEST_Operation *o,
+ struct Episode *e,
+ int op_counter,
+ char *sec_name,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ char *op_name;
+
+ /* peer id */
+ GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
+ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
+ sec_name, op_name, &o->peer_id))
+ {
+ fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
+ op_counter, "START_REQUEST", op_name);
+ GNUNET_free (op_name);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (op_name);
+ return GNUNET_OK;
+}
+
+static int
+load_op_stop_request (struct GNUNET_ATS_TEST_Operation *o,
+ struct Episode *e,
+ int op_counter,
+ char *sec_name,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ char *op_name;
+
+ /* peer id */
+ GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
+ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
+ sec_name, op_name, &o->peer_id))
+ {
+ fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
+ op_counter, "STOP_REQUEST", op_name);
+ GNUNET_free (op_name);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (op_name);
+ return GNUNET_OK;
+}
+
+
static int
load_episode (struct Experiment *e, struct Episode *cur,
struct GNUNET_CONFIGURATION_Handle *cfg)
char *op_name;
char *op;
int op_counter = 0;
+ int res;
fprintf (stderr, "Parsing episode %u\n",cur->id);
GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
if (0 == strcmp (op, "address_add"))
{
o->type = SOLVER_OP_ADD_ADDRESS;
- if (GNUNET_SYSERR == load_op_add_address (o, cur,
- op_counter, sec_name, cfg))
- {
- GNUNET_free (o);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (sec_name);
- return GNUNET_SYSERR;
- }
+ res = load_op_add_address (o, cur,
+ op_counter, sec_name, cfg);
}
else if (0 == strcmp (op, "address_del"))
{
o->type = SOLVER_OP_DEL_ADDRESS;
- if (GNUNET_SYSERR == load_op_del_address (o, cur,
- op_counter, sec_name, cfg))
- {
- GNUNET_free (o);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (sec_name);
- return GNUNET_SYSERR;
- }
+ res = load_op_del_address (o, cur,
+ op_counter, sec_name, cfg);
}
else if (0 == strcmp (op, "start_set_property"))
{
o->type = SOLVER_OP_START_SET_PROPERTY;
- if (GNUNET_SYSERR == load_op_start_set_property (o, cur,
- op_counter, sec_name, cfg))
- {
- GNUNET_free (o);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (sec_name);
- return GNUNET_SYSERR;
- }
+ res = load_op_start_set_property (o, cur,
+ op_counter, sec_name, cfg);
}
else if (0 == strcmp (op, "stop_set_property"))
{
o->type = SOLVER_OP_STOP_SET_PROPERTY;
- if (GNUNET_SYSERR == load_op_stop_set_property (o, cur,
- op_counter, sec_name, cfg))
- {
- GNUNET_free (o);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (sec_name);
- return GNUNET_SYSERR;
- }
+ res = load_op_stop_set_property (o, cur,
+ op_counter, sec_name, cfg);
}
else if (0 == strcmp (op, "start_set_preference"))
{
o->type = SOLVER_OP_START_SET_PREFERENCE;
- if (GNUNET_SYSERR == load_op_start_set_preference (o, cur,
- op_counter, sec_name, cfg))
- {
- GNUNET_free (o);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (sec_name);
- return GNUNET_SYSERR;
- }
+ res = load_op_start_set_preference (o, cur,
+ op_counter, sec_name, cfg);
}
else if (0 == strcmp (op, "stop_set_preference"))
{
o->type = SOLVER_OP_STOP_SET_PREFERENCE;
- if (GNUNET_SYSERR == load_op_stop_set_preference (o, cur,
- op_counter, sec_name, cfg))
- {
- GNUNET_free (o);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (sec_name);
- return GNUNET_SYSERR;
- }
- }
- else
- {
- fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (o);
- GNUNET_free (op);
- GNUNET_free (op_name);
- GNUNET_free (sec_name);
- return GNUNET_SYSERR;
+ res = load_op_stop_set_preference (o, cur,
+ op_counter, sec_name, cfg);
}
- GNUNET_free (op);
- GNUNET_free (op_name);
-
- GNUNET_CONTAINER_DLL_insert (cur->head,cur->tail, o);
- op_counter++;
- }
- GNUNET_free (sec_name);
-
-
-#if 0
- /* Get source */
- GNUNET_asprintf(&op_name, "op-%u-src", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->src_id))
+ else if (0 == strcmp (op, "start_request"))
{
- fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (op);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
+ o->type = SOLVER_OP_START_REQUEST;
+ res = load_op_start_request (o, cur,
+ op_counter, sec_name, cfg);
}
- if (o->src_id > (e->num_masters - 1))
+ else if (0 == strcmp (op, "stop_request"))
{
- fprintf (stderr, "Invalid src %llu in operation %u `%s' in episode %u\n",
- o->src_id, op_counter, op, cur->id);
- GNUNET_free (op);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
+ o->type = SOLVER_OP_STOP_REQUEST;
+ res = load_op_stop_request(o, cur,
+ op_counter, sec_name, cfg);
}
- GNUNET_free (op_name);
-
- /* Get destination */
- GNUNET_asprintf(&op_name, "op-%u-dest", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->dest_id))
+ else
{
- fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n",
+ fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
op_counter, op, cur->id);
- GNUNET_free (op);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
+ res = GNUNET_SYSERR;
}
- if (o->dest_id > (e->num_slaves - 1))
- {
- fprintf (stderr, "Invalid destination %llu in operation %u `%s' in episode %u\n",
- o->dest_id, op_counter, op, cur->id);
- GNUNET_free (op);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
-
- GNUNET_asprintf(&op_name, "op-%u-type", op_counter);
- if ( (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_string(cfg,
- sec_name, op_name, &type)) &&
- ((STOP_SEND != o->type) || (STOP_PREFERENCE != o->type)))
- {
- /* Load arguments for set_rate, start_send, set_preference */
- if (0 == strcmp (type, "constant"))
- {
- o->tg_type = GNUNET_ATS_TEST_TG_CONSTANT;
- }
- else if (0 == strcmp (type, "linear"))
- {
- o->tg_type = GNUNET_ATS_TEST_TG_LINEAR;
- }
- else if (0 == strcmp (type, "sinus"))
- {
- o->tg_type = GNUNET_ATS_TEST_TG_SINUS;
- }
- else if (0 == strcmp (type, "random"))
- {
- o->tg_type = GNUNET_ATS_TEST_TG_RANDOM;
- }
- else
- {
- fprintf (stderr, "Invalid type %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (type);
- GNUNET_free (op);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
-
- /* Get base rate */
- GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->base_rate))
- {
- fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (type);
- GNUNET_free (op);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* Get max rate */
- GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->max_rate))
- {
- if ((GNUNET_ATS_TEST_TG_LINEAR == o->tg_type) ||
- (GNUNET_ATS_TEST_TG_RANDOM == o->tg_type) ||
- (GNUNET_ATS_TEST_TG_SINUS == o->tg_type))
- {
- fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (type);
- GNUNET_free (op_name);
- GNUNET_free (op);
- return GNUNET_SYSERR;
- }
- }
- GNUNET_free (op_name);
-
- /* Get period */
- GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
- sec_name, op_name, &o->period))
- {
- o->period = cur->duration;
- }
- GNUNET_free (op_name);
-
- if (START_PREFERENCE == o->type)
- {
- /* Get frequency */
- GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
- sec_name, op_name, &o->frequency))
- {
- fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (type);
- GNUNET_free (op_name);
- GNUNET_free (op);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
-
- /* Get preference */
- GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
- sec_name, op_name, &pref))
- {
- fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (type);
- GNUNET_free (op_name);
- GNUNET_free (op);
- GNUNET_free_non_null (pref);
- return GNUNET_SYSERR;
- }
-
- if (0 == strcmp(pref, "bandwidth"))
- o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
- else if (0 == strcmp(pref, "latency"))
- o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY;
- else
- {
- fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- GNUNET_free (type);
- GNUNET_free (op_name);
- GNUNET_free (op);
- GNUNET_free (pref);
- GNUNET_free_non_null (pref);
- return GNUNET_SYSERR;
- }
- GNUNET_free (pref);
- GNUNET_free (op_name);
- }
- }
+ GNUNET_free (op);
+ GNUNET_free (op_name);
- /* Safety checks */
- if ((GNUNET_ATS_TEST_TG_LINEAR == o->tg_type) ||
- (GNUNET_ATS_TEST_TG_SINUS == o->tg_type))
+ if (GNUNET_SYSERR == res)
{
- if ((o->max_rate - o->base_rate) > o->base_rate)
- {
- /* This will cause an underflow */
- GNUNET_break (0);
- }
- fprintf (stderr, "Selected max rate and base rate cannot be used for desired traffic form!\n");
+ GNUNET_free (o);
+ GNUNET_free (sec_name);
+ return GNUNET_SYSERR;
}
- if ((START_SEND == o->type) || (START_PREFERENCE == o->type))
- fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n",
- op_counter, cur->id, print_op (o->type), o->src_id,
- o->dest_id, (NULL != type) ? type : "",
- o->base_rate, o->max_rate,
- GNUNET_STRINGS_relative_time_to_string (o->period, GNUNET_YES));
- else
- fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n",
- op_counter, cur->id, print_op (o->type), o->src_id, o->dest_id);
-
- GNUNET_free_non_null (type);
- GNUNET_free (op);
-#endif
-
+ GNUNET_CONTAINER_DLL_insert_tail (cur->head,cur->tail, o);
+ op_counter++;
+ }
+ GNUNET_free (sec_name);
return GNUNET_OK;
}
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
sec_name, "duration", &e_duration))
{
+ fprintf (stderr, "Missing duration in episode %u \n",e_counter);
GNUNET_free (sec_name);
break;
}
if (NULL == last)
e->start = cur;
else
- last->next = cur;
+ last->next = cur;
GNUNET_free (sec_name);
e_counter ++;
GNUNET_SYSERR);
}
+struct ATS_Address *
+create_ats_address (const struct GNUNET_PeerIdentity *peer,
+ const char *plugin_name,
+ const void *plugin_addr, size_t plugin_addr_len,
+ uint32_t session_id)
+{
+ struct ATS_Address *aa = NULL;
+
+ aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1);
+ aa->peer = *peer;
+ aa->addr_len = plugin_addr_len;
+ aa->addr = &aa[1];
+ aa->plugin = (char *) &aa[1] + plugin_addr_len;
+ 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;
+}
+
+
+
static void
enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
{
- /*
- struct BenchmarkPeer *peer;
- struct BenchmarkPartner *partner;
+ struct TestPeer *p;
+ struct TestAddress *a;
- peer = GNUNET_ATS_TEST_get_peer (op->src_id);
- if (NULL == peer)
+ if (NULL == (p = find_peer_by_id (op->peer_id)))
{
- GNUNET_break (0);
- return;
+ p = GNUNET_new (struct TestPeer);
+ p->id = op->peer_id;
+ memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
+ GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p);
}
- partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
- if (NULL == partner)
+ if (NULL != (find_address_by_id (p, op->address_id)))
{
- GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Duplicate address %u for peer %u\n",
+ op->address_id, op->peer_id);
return;
}
- fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
+ a = GNUNET_new (struct TestAddress);
+ a->aid = op->address_id;
+ a->ats_addr = create_ats_address (&p->peer_id, op->plugin, op->address,
+ strlen (op->address) + 1, op->address_session);
+ memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
+ GNUNET_CONTAINER_DLL_insert (p->addr_head, p->addr_tail, a);
- if (NULL != partner->tg)
- {
- fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",op->src_id, op->dest_id);
- GNUNET_ATS_TEST_generate_traffic_stop(partner->tg);
- partner->tg = NULL;
- }
+ GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, a->ats_addr,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u\n",
+ op->address_id, op->peer_id);
+
+ sh->env.sf.s_add (sh->solver, a->ats_addr, op->address_network);
- partner->tg = GNUNET_ATS_TEST_generate_traffic_start(peer, partner,
- op->tg_type, op->base_rate, op->max_rate, op->period,
- GNUNET_TIME_UNIT_FOREVER_REL);
- */
}
+
static void
enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
{
- /*
- struct BenchmarkPartner *p;
- p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id);
- if (NULL == p)
+ struct TestPeer *p;
+ struct AddressLookupCtx ctx;
+
+ if (NULL == (p = find_peer_by_id (op->peer_id)))
{
GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Deleting address for unknown peer %u\n", op->peer_id);
return;
}
- fprintf (stderr, "Found master %llu slave %llu\n",op->src_id, op->dest_id);
+ ctx.plugin = op->plugin;
+ ctx.addr = op->address;
+ ctx.res = NULL;
+ GNUNET_CONTAINER_multipeermap_get_multiple (sh->addresses, &p->peer_id,
+ find_address_it, &ctx);
+ if (NULL == ctx.res)
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Deleting unknown address for peer %u\n", op->peer_id);
+ return;
+ }
- if (NULL != p->tg)
+ if (NULL == (find_address_by_id (p, op->address_id)))
{
- fprintf (stderr, "Stopping traffic between master %llu slave %llu\n",
- op->src_id, op->dest_id);
- GNUNET_ATS_TEST_generate_traffic_stop(p->tg);
- p->tg = NULL;
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Deleting address for unknown peer %u\n", op->peer_id);
+ return;
}
- */
+
+ GNUNET_CONTAINER_multipeermap_remove (sh->addresses, &p->peer_id, ctx.res);
+
+ 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, ctx.res, GNUNET_NO);
+ GNUNET_free (ctx.res);
+
}
static void
enforce_start_property (struct GNUNET_ATS_TEST_Operation *op)
{
struct PropertyGenerator *pg;
+ struct TestPeer *p;
+ struct TestAddress *a;
+
if (NULL != (pg = find_prop_gen (op->peer_id, op->address_id, op->prop_type)))
{
GNUNET_ATS_solver_generate_property_stop (pg);
GNUNET_free (pg);
}
+ if (NULL == (p = find_peer_by_id (op->peer_id)))
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Starting property generation for unknown peer %u\n", op->peer_id);
+ return;
+ }
+
+ if (NULL == (a = find_address_by_id (p, op->address_id)))
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Setting property for unknown address %u\n", op->peer_id);
+ return;
+ }
+
GNUNET_ATS_solver_generate_property_start (op->peer_id,
op->address_id,
- op->type,
+ p, a,
+ op->gen_type,
op->base_rate,
op->max_rate,
op->period,
GNUNET_free (pg);
}
+ if (NULL == (find_peer_by_id (op->peer_id)))
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Starting preference generation for unknown peer %u\n", op->peer_id);
+ return;
+ }
+
GNUNET_ATS_solver_generate_preferences_start (op->peer_id,
op->address_id,
- op->type,
+ op->client_id,
+ op->gen_type,
op->base_rate,
op->max_rate,
op->period,
GNUNET_ATS_solver_generate_preferences_stop (pg);
}
+
+static void
+enforce_start_request (struct GNUNET_ATS_TEST_Operation *op)
+{
+ struct TestPeer *p;
+ const struct ATS_Address *res;
+
+ if (NULL == (p = find_peer_by_id (op->peer_id)))
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Requesting address for unknown peer %u\n", op->peer_id);
+ return;
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n",
+ op->peer_id);
+
+ res = sh->env.sf.s_get (sh->solver, &p->peer_id);
+ if (NULL != res)
+ {
+
+ }
+
+}
+
+static void
+enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op)
+{
+ struct TestPeer *p;
+
+ if (NULL == (p = find_peer_by_id (op->peer_id)))
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Requesting address for unknown peer %u\n", op->peer_id);
+ return;
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop requesting address for peer %u\n",
+ op->peer_id);
+
+ sh->env.sf.s_get_stop (sh->solver, &p->peer_id);
+}
+
static void enforce_episode (struct Episode *ep)
{
struct GNUNET_ATS_TEST_Operation *cur;
print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
enforce_stop_preference (cur);
break;
+ case SOLVER_OP_START_REQUEST:
+ fprintf (stderr, "Enforcing operation: %s [%llu]\n",
+ print_op (cur->type), cur->peer_id);
+ enforce_start_request (cur);
+ break;
+ case SOLVER_OP_STOP_REQUEST:
+ fprintf (stderr, "Enforcing operation: %s [%llu]\n",
+ print_op (cur->type), cur->peer_id);
+ enforce_stop_request (cur);
+ break;
default:
break;
}
}
else
{
- fprintf (stderr, "Experiment name: `%s'\n", e->cfg_file);
+ fprintf (stderr, "Experiment configuration: `%s'\n", e->cfg_file);
e->cfg = GNUNET_CONFIGURATION_create();
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file))
{
}
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
- "masters", &e->num_masters))
- {
- fprintf (stderr, "Invalid %s", "masters");
- free_experiment (e);
- return NULL;
- }
- else
- fprintf (stderr, "Experiment masters: `%llu'\n",
- e->num_masters);
-
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment",
- "slaves", &e->num_slaves))
- {
- fprintf (stderr, "Invalid %s", "slaves");
- free_experiment (e);
- return NULL;
- }
- else
- fprintf (stderr, "Experiment slaves: `%llu'\n",
- e->num_slaves);
-
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
"log_freq", &e->log_freq))
{
return e;
}
-/**
- * Logging
- */
/**
* Solver
*/
-struct GNUNET_ATS_TESTING_SolverHandle
+static int
+free_all_it (void *cls,
+ const struct GNUNET_PeerIdentity *key,
+ void *value)
{
- char * plugin;
- struct GNUNET_ATS_PluginEnvironment env;
- void *solver;
- struct GNUNET_CONTAINER_MultiPeerMap *addresses;
-};
+ struct ATS_Address *address = value;
+ GNUNET_break (GNUNET_OK != GNUNET_CONTAINER_multipeermap_remove (sh->env.addresses,
+ key, value));
+ GNUNET_free (address);
-enum GNUNET_ATS_Solvers
-{
- GNUNET_ATS_SOLVER_PROPORTIONAL,
- GNUNET_ATS_SOLVER_MLP,
- GNUNET_ATS_SOLVER_RIL,
-};
+ return GNUNET_OK;
+}
void
-GNUNET_ATS_solvers_solver_stop (struct GNUNET_ATS_TESTING_SolverHandle *sh)
+GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh)
{
GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
GNUNET_NO);
- GNUNET_CONTAINER_multipeermap_destroy(sh->env.addresses);
GNUNET_PLUGIN_unload (sh->plugin, sh->solver);
+ GNUNET_CONTAINER_multipeermap_iterate (sh->addresses, &free_all_it, NULL);
GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
GNUNET_free (sh->plugin);
GNUNET_free (sh);
network_str[c], GNUNET_ATS_DefaultBandwidth);
out_dest[c] = GNUNET_ATS_DefaultBandwidth;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "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", network_str[c], in_dest[c], out_dest[c]);
GNUNET_free (entry_out);
GNUNET_free (entry_in);
}
/**
* Information callback for the solver
*
+ * @param cls the closure
* @param op the solver operation
* @param stat status of the solver operation
* @param add additional solver information
{
if ( (0 == ntohl (address->assigned_bw_out.value__)) &&
(0 == ntohl (address->assigned_bw_in.value__)) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Solver notified to disconnect peer `%s'\n",
+ GNUNET_i2s (&address->peer));
return;
+ }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
GNUNET_i2s (&address->peer),
address,
}
static void
-normalized_property_changed_cb (void *cls, struct ATS_Address *peer,
+normalized_property_changed_cb (void *cls, struct ATS_Address *address,
uint32_t type, double prop_rel)
{
- /* TODO */
+ 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);
+
+ sh->env.sf.s_address_update_property (sh->solver, address, type, 0, prop_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);
+
+ sh->env.sf.s_pref (sh->solver, peer, kind, pref_rel);
}
-struct GNUNET_ATS_TESTING_SolverHandle *
+struct SolverHandle *
GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
{
- struct GNUNET_ATS_TESTING_SolverHandle *sh;
+ struct SolverHandle *sh;
char * solver_str;
- unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
- unsigned long long quotas_out[GNUNET_ATS_NetworkTypeCount];
switch (type) {
case GNUNET_ATS_SOLVER_PROPORTIONAL:
break;
}
- sh = GNUNET_new (struct GNUNET_ATS_TESTING_SolverHandle);
+ sh = GNUNET_new (struct SolverHandle);
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 = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
+ 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.info_cb = &solver_info_cb;
sh->env.info_cb_cls = NULL;
+
/* start normalization */
- GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL );
+ GAS_normalization_start (&normalized_preference_changed_cb, NULL,
+ &normalized_property_changed_cb, NULL );
/* load quotas */
if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg,
- quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount))
+ sh->env.out_quota, sh->env.in_quota, GNUNET_ATS_NetworkTypeCount))
{
GNUNET_break(0);
GNUNET_free (sh->plugin);
end_now ();
return NULL;
}
-
- sh->addresses = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
-
return sh;
}
static void
done ()
{
- /* Clean up experiment */
+ struct TestPeer *cur;
+ struct TestPeer *next;
+
+ struct TestAddress *cur_a;
+ struct TestAddress *next_a;
+
+ /* Stop logging */
+ GNUNET_ATS_solver_logging_stop (l);
+
+ /* Stop all preference generation */
GNUNET_ATS_solver_generate_preferences_stop_all ();
- GNUNET_ATS_solvers_experimentation_stop (e);
- e = NULL;
+ /* Stop all property generation */
+ GNUNET_ATS_solver_generate_property_stop_all ();
+
+ /* Clean up experiment */
+ if (NULL != e)
+ {
+ GNUNET_ATS_solvers_experimentation_stop (e);
+ e = NULL;
+ }
+
+ if (opt_print)
+ GNUNET_ATS_solver_logging_eval (l);
+
+ if (NULL != l)
+ {
+ GNUNET_ATS_solver_logging_free (l);
+ l = NULL;
+ }
+
+ next = peer_head;
+ while (NULL != (cur = next))
+ {
+ next = cur->next;
+ GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, cur);
+ next_a = cur->addr_head;
+ while (NULL != (cur_a = next_a))
+ {
+ next_a = cur_a->next;
+ GNUNET_CONTAINER_DLL_remove (cur->addr_head, cur->addr_tail, cur_a);
+ GNUNET_free (cur_a);
+ }
+ GNUNET_free (cur);
+ }
+ if (NULL != sh)
+ {
+ GNUNET_ATS_solvers_solver_stop (sh);
+ sh = NULL;
+ }
/* Shutdown */
end_now();
-
}
static void
else
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
- /* Stop logging */
- // GNUNET_ATS_TEST_logging_stop (l);
-
- /* Stop traffic generation */
- // GNUNET_ATS_TEST_generate_traffic_stop_all();
-
- /* Stop all preference generations */
- GNUNET_ATS_solver_generate_preferences_stop_all ();
-
- /*
- evaluate (duration);
- if (opt_log)
- GNUNET_ATS_TEST_logging_write_to_file(l, opt_exp_file, opt_plot);
-
- if (NULL != l)
- {
- GNUNET_ATS_TEST_logging_stop (l);
- GNUNET_ATS_TEST_logging_clean_up (l);
- l = NULL;
- }
- */
GNUNET_SCHEDULER_add_now (&done, NULL);
}
return;
}
-
/* load solver */
sh = GNUNET_ATS_solvers_solver_start (solver);
if (NULL == sh)
}
/* start logging */
-
+ l = GNUNET_ATS_solver_logging_start (e->log_freq);
/* run experiment */
GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb,
{ 'e', "experiment", NULL,
gettext_noop ("experiment to use"),
1, &GNUNET_GETOPT_set_one, &opt_verbose},
+ { 'p', "print", NULL,
+ gettext_noop ("print logging"),
+ 0, &GNUNET_GETOPT_set_one, &opt_print},
GNUNET_GETOPT_OPTION_END
};
- GNUNET_PROGRAM_run (argc, argv, argv[0], NULL, options, &run, argv[0]);
+ GNUNET_PROGRAM_run (argc, argv, "gnunet-ats-solver-eval",
+ NULL, options, &run, argv[0]);
return res;
}