*/
static int opt_verbose;
+/**
+ * cmd option -p: print logs
+ */
+static int opt_print;
+
static int res;
static void
}
}
+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_log (GNUNET_ERROR_TYPE_INFO, "Logging\n");
+ GNUNET_ATS_solver_logging_now (l);
l->logging_task = GNUNET_SCHEDULER_add_delayed (l->log_freq, &logging_task, l);
return l;
}
-void
-GNUNET_ATS_solver_logging_now (struct LoggingHandle *l)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging\n");
-}
-
void
GNUNET_ATS_solver_logging_stop (struct LoggingHandle *l)
{
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);
}
{
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;
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;
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,
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;
}
o->type = SOLVER_OP_START_SET_PREFERENCE;
res = load_op_start_set_preference (o, cur,
op_counter, sec_name, cfg);
- break;
}
else if (0 == strcmp (op, "stop_set_preference"))
{
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);
}
-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;
-}
-
struct ATS_Address *
create_ats_address (const struct GNUNET_PeerIdentity *peer,
const char *plugin_name,
return aa;
}
+
+
static void
enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
{
- struct ATS_Address *addr;
struct TestPeer *p;
+ struct TestAddress *a;
if (NULL == (p = find_peer_by_id (op->peer_id)))
{
p = GNUNET_new (struct TestPeer);
p->id = op->peer_id;
- memset (&p->peer_id, '0', sizeof (p->peer_id));
+ memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p);
}
- addr = create_ats_address (&p->peer_id, op->plugin, op->address,
+ if (NULL != (find_address_by_id (p, op->address_id)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Duplicate address %u for peer %u\n",
+ op->address_id, op->peer_id);
+ return;
+ }
+
+ 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);
- GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, addr,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ 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);
+ op->address_id, op->peer_id);
- sh->env.sf.s_add (sh->solver, addr, op->address_network);
+ sh->env.sf.s_add (sh->solver, a->ats_addr, op->address_network);
}
-struct AddressLookupCtx
-{
- struct ATS_Address *res;
- struct GNUNET_ATS_TEST_Operation *op;
-};
-
-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->op->plugin, addr->plugin)) &&
- (0 == strcmp (ctx->op->address, addr->addr)) )
- {
- ctx->res = addr;
- return GNUNET_NO;
- }
- return GNUNET_YES;
-}
static void
enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
return;
}
- ctx.op = op;
+ 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);
return;
}
+ if (NULL == (find_address_by_id (p, op->address_id)))
+ {
+ 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",
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,
+ p, a,
op->gen_type,
op->base_rate,
op->max_rate,
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->client_id,
op->gen_type,
op->base_rate,
op->max_rate,
}
- 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;
}
+
+
/**
* Solver
*/
+static int
+free_all_it (void *cls,
+ const struct GNUNET_PeerIdentity *key,
+ void *value)
+{
+ struct ATS_Address *address = value;
+ GNUNET_break (GNUNET_OK != GNUNET_CONTAINER_multipeermap_remove (sh->env.addresses,
+ key, value));
+ GNUNET_free (address);
+
+ return GNUNET_OK;
+}
+
void
GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh)
{
GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
GNUNET_NO);
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);
/**
* 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
}
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);
}
/* 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,
return sh;
}
-static int
-free_all_it (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
-{
- struct ATS_Address *address = value;
- GNUNET_CONTAINER_multipeermap_remove (sh->env.addresses, key, value);
- GNUNET_free (address);
-
- return GNUNET_OK;
-}
-
static void
done ()
{
struct TestPeer *cur;
struct TestPeer *next;
- /* Clean up experiment */
+
+ 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 ();
+
+ /* 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);
{
next = cur->next;
GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, cur);
- GNUNET_break (0);
- GNUNET_CONTAINER_multipeermap_iterate (sh->env.addresses, &free_all_it, NULL);
-
+ 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_solver_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);
}
{ '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
};