aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-06-24 15:06:45 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-06-24 15:06:45 +0000
commit7ba01a86dfa31c8e4b97e099437fbbfba32d191b (patch)
tree9cba59bb369223f840dbc55cd68f1095c10ad92f
parent1e007a89197769e4e0f5ad36b583689a27f33cac (diff)
implemented ats property normalization with callback to address
to do: recalculate min/max to prevent outdated max values have an impact on normalization
-rw-r--r--src/ats/Makefile.am10
-rw-r--r--src/ats/ats_api_scheduling.c15
-rw-r--r--src/ats/gnunet-service-ats_addresses.c39
-rw-r--r--src/ats/gnunet-service-ats_addresses.h1
-rw-r--r--src/ats/gnunet-service-ats_normalization.c125
-rw-r--r--src/ats/gnunet-service-ats_normalization.h20
-rw-r--r--src/ats/perf_ats_mlp.c12
-rw-r--r--src/ats/test_ats_mlp.c11
-rw-r--r--src/ats/test_ats_mlp_update.c12
-rw-r--r--src/ats/test_ats_normalization_update_quality.c237
10 files changed, 438 insertions, 44 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index 1b7b9d818e..3f51e3cca5 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -71,6 +71,7 @@ check_PROGRAMS = \
test_ats_api_scheduling_destroy_session \
test_ats_api_scheduling_destroy_inbound_connection \
test_ats_api_scheduling_block_and_reset \
+ test_ats_normalization_update_quality \
test_ats_change_preference \
test_ats_simplistic \
test_ats_simplistic_switch_networks \
@@ -232,6 +233,15 @@ perf_ats_mlp_LDADD = \
$(top_builddir)/src/ats/libgnunetats.la
endif
+test_ats_normalization_update_quality_SOURCES = \
+ test_ats_normalization_update_quality.c test_ats_api_common.c
+test_ats_normalization_update_quality_LDADD = \
+ $(GN_LIBGLPK) \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/statistics/libgnunetstatistics.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ $(top_builddir)/src/ats/libgnunetats.la
+
#test_ats_mlp_averaging_SOURCES = \
# $(GN_MLP_SRC) test_ats_mlp_averaging.c test_ats_api_common.c
#test_ats_mlp_averaging_LDADD = \
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c
index acd2522456..bbbdc153c4 100644
--- a/src/ats/ats_api_scheduling.c
+++ b/src/ats/ats_api_scheduling.c
@@ -846,6 +846,21 @@ GNUNET_ATS_print_network_type (uint32_t net)
return NULL;
}
+/**
+ * Convert a ATS property to a string
+ *
+ * @param type the atsi type
+ * @return a string or NULL if invalid
+ */
+const char *
+GNUNET_ATS_print_property_type (uint32_t type)
+{
+ char *props[GNUNET_ATS_PropertyCount] = GNUNET_ATS_PropertyStrings;
+ if ((type > 0) && (type < GNUNET_ATS_PropertyCount))
+ return props[type];
+ return NULL;
+}
+
/**
* Returns where the address is located: LAN or WAN or ...
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index d7c4100ea0..03400136a2 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -809,6 +809,7 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' session id %u, %p\n",
GNUNET_i2s (peer), session_id, aa);
/* Tell solver about new address */
+ GAS_normalization_normalize_property (aa, atsi, atsi_count);
handle->s_add (handle->solver, handle->addresses, aa, addr_net);
/* Notify performance clients about new address */
GAS_performance_notify_all_clients (&aa->peer,
@@ -852,6 +853,7 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
}
/* Notify solver about update with atsi information and session */
+ GAS_normalization_normalize_property (ea, atsi, atsi_count);
handle->s_update (handle->solver, handle->addresses, ea, session_id, ea->used, atsi_delta, atsi_delta_count);
GNUNET_free_non_null (atsi_delta);
@@ -1308,6 +1310,15 @@ GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle,
NULL));
}
+
+/**
+ * The preference changed for a peer
+ *
+ * @param cls the address handle
+ * @param peer the peer
+ * @param kind the ATS kind
+ * @param double the new relative preference value
+ */
static void
normalized_preference_changed_cb (void *cls,
const struct GNUNET_PeerIdentity *peer,
@@ -1320,6 +1331,31 @@ normalized_preference_changed_cb (void *cls,
handle->s_pref (handle->solver, handle->addresses, peer, kind, pref_rel);
}
+
+/**
+ * The relative value for a property changed
+ *
+ * @param cls the address handle
+ * @param peer the peer
+ * @param kind the ATS kind
+ * @param double the new relative preference value
+ */
+static void
+normalized_property_changed_cb (void *cls,
+ const struct ATS_Address *peer,
+ uint32_t type,
+ double prop_rel)
+{
+ GNUNET_assert (NULL != cls);
+ //struct GAS_Addresses_Handle *handle = cls;
+ /* Tell solver about update */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Normalized property %s for peer `%s' changed to %.3f \n",
+ GNUNET_ATS_print_property_type (type),
+ GNUNET_i2s (&peer->peer),
+ prop_rel);
+}
+
const double *
get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
{
@@ -1626,7 +1662,8 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_assert (NULL != ah->s_del);
GNUNET_assert (NULL != ah->s_done);
- GAS_normalization_start (&normalized_preference_changed_cb, ah);
+ GAS_normalization_start (&normalized_preference_changed_cb, ah,
+ &normalized_property_changed_cb, ah);
quota_count = load_quotas(cfg, quotas_in, quotas_out, GNUNET_ATS_NetworkTypeCount);
ah->solver = ah->s_init (cfg, stats,
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h
index cfc54b2eaa..8c462ed8cf 100644
--- a/src/ats/gnunet-service-ats_addresses.h
+++ b/src/ats/gnunet-service-ats_addresses.h
@@ -237,6 +237,7 @@ struct GAS_Addresses_Handle;
struct GAS_NormalizationInfo
{
unsigned int index;
+ uint32_t avg;
uint32_t atsi_abs[GAS_normalization_queue_length];
};
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c
index f5dbf04c90..84a07b0d8e 100644
--- a/src/ats/gnunet-service-ats_normalization.c
+++ b/src/ats/gnunet-service-ats_normalization.c
@@ -29,6 +29,7 @@
#include "gnunet-service-ats_addresses.h"
#include "gnunet-service-ats_normalization.h"
+#define LOG(kind,...) GNUNET_log_from (kind, "ats-normalization",__VA_ARGS__)
/**
@@ -144,6 +145,17 @@ static void *pref_changed_cb_cls;
/**
+ * Callback to call on changing property values
+ */
+GAS_Normalization_property_changed_cb prop_ch_cb;
+
+/**
+ * Closure for callback to call on changing property values
+ */
+void *prop_ch_cb_cls;
+
+
+/**
* Hashmap to store peer information for preference normalization
*/
static struct GNUNET_CONTAINER_MultiHashMap *preference_peers;
@@ -395,13 +407,12 @@ preference_aging (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
* @param kind the kind to change the preference
* @param score_abs the normalized score
*/
-float
+void
GAS_normalization_normalize_preference (void *src,
const struct GNUNET_PeerIdentity *peer,
enum GNUNET_ATS_PreferenceKind kind,
float score_abs)
{
- float score_rel;
struct PreferenceClient *c_cur;
struct PreferencePeer *p_cur;
struct PeerRelative *r_cur;
@@ -421,7 +432,7 @@ GAS_normalization_normalize_preference (void *src,
if (kind >= GNUNET_ATS_PreferenceCount)
{
GNUNET_break (0);
- return 0.0;
+ return;
}
/* Find preference client */
@@ -472,9 +483,7 @@ GAS_normalization_normalize_preference (void *src,
GNUNET_CONTAINER_multihashmap_put (preference_peers, &r_cur->id.hashPubKey,
r_cur, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
}
-
- score_rel = update_preference (c_cur, p_cur, kind, score_abs);
- return score_rel;
+ update_preference (c_cur, p_cur, kind, score_abs);
}
@@ -521,14 +530,15 @@ struct Property properties[GNUNET_ATS_QualityPropertiesCount];
* @return the new average or GNUNET_ATS_VALUE_UNDEFINED
*/
-uint32_t property_average (struct ATS_Address *address,
- const struct GNUNET_ATS_Information *atsi)
+uint32_t
+property_average (struct ATS_Address *address,
+ const struct GNUNET_ATS_Information *atsi)
{
struct GAS_NormalizationInfo *ni;
uint32_t current_type;
uint32_t current_val;
-
- uint32_t sum;
+ uint32_t res;
+ uint64_t sum;
uint32_t count;
unsigned int c1;
unsigned int index;
@@ -557,6 +567,7 @@ uint32_t property_average (struct ATS_Address *address,
ni->index = 0;
count = 0;
+ sum = 0;
for (c1 = 0; c1 < GAS_normalization_queue_length; c1++)
{
if (GNUNET_ATS_VALUE_UNDEFINED != ni->atsi_abs[c1])
@@ -572,52 +583,84 @@ uint32_t property_average (struct ATS_Address *address,
}
}
GNUNET_assert (0 != count);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New average from %u elements: %u\n", count, sum / count);
- return 0;
+ res = sum / count;
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "New average of `%s' created by adding %u from %u elements: %u\n",
+ GNUNET_ATS_print_property_type(current_type),
+ current_val, count, res , sum);
+ ni->avg = res;
+ return res;
}
-double property_normalize (struct Property *p,
- struct ATS_Address *address,
- uint32_t type,
- uint32_t avg_value)
+/**
+ * Normalize avg_value to a range of values between [1.0, 2.0]
+ * based on min max values currently known.
+ *
+ * @param property p the property
+ * @param address the address
+ * @param type the atsi type
+ * @param avg_value the value to normalize
+ */
+
+static void
+property_normalize (struct Property *p,
+ struct ATS_Address *address,
+ uint32_t type,
+ uint32_t avg_value)
{
double res;
double delta;
+ uint32_t current_min;
+
/* Normalize the values of this property */
- if (p->max < avg_value)
+ if (avg_value > p->max)
{
p->max = avg_value;
if (GNUNET_NO == p->have_max)
p->have_max = GNUNET_YES;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "New maximum of %u for property %u\n",
- p->max, avg_value);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "New maximum of %u for property %s\n",
+ p->max, GNUNET_ATS_print_property_type (type));
}
- if (p->min > avg_value)
+
+ if ((avg_value < p->min) && (avg_value < p->max))
{
p->min = avg_value;
if (GNUNET_NO == p->have_min)
p->have_min = GNUNET_YES;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "New minimum of %u for property %u\n",
- p->min, avg_value);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "New minimum of %u for property %s\n",
+ p->min, GNUNET_ATS_print_property_type (type));
}
- if ((GNUNET_YES == p->have_max) && (GNUNET_YES == p->have_min))
+ current_min = p->min;
+ if (UINT32_MAX == p->min)
+ current_min = 0; /* If we do not have a minimum we use 0.0 */
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Normalizing %u: new normalized property `%s' using min=%u max=%u\n",
+ avg_value,
+ GNUNET_ATS_print_property_type (type),
+ current_min, p->max);
+
+ if (GNUNET_YES == p->have_max)
{
- delta = p->max - p->min;
- res = (delta + avg_value) / (delta);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "New normalized value of %f for property %u\n",
- res, type);
- return res;
+ delta = p->max - current_min;
+ res = (delta + (avg_value - current_min)) / (delta);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer `%s': New normalized value of %f for property %s\n",
+ GNUNET_i2s (&address->peer), res, GNUNET_ATS_print_property_type (type));
+ if (NULL != prop_ch_cb)
+ prop_ch_cb (prop_ch_cb_cls, address, type, res);
}
-
- return DEFAULT_REL_QUALITY;
}
-
+/**
+ * Update and normalize a atsi performance information
+ *
+ * @param address the address to update
+ * @param atsi the array of performance information
+ * @param atsi_count the number of atsi information in the array
+ */
void
GAS_normalization_normalize_property (struct ATS_Address *address,
const struct GNUNET_ATS_Information *atsi,
@@ -633,6 +676,9 @@ GAS_normalization_normalize_property (struct ATS_Address *address,
GNUNET_assert (NULL != address);
GNUNET_assert (NULL != atsi);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating %u elements for peer `%s'\n",
+ atsi_count, GNUNET_i2s (&address->peer));
+
for (c1 = 0; c1 < atsi_count; c1++)
{
current_type = ntohl (atsi[c1].type);
@@ -648,7 +694,6 @@ GAS_normalization_normalize_property (struct ATS_Address *address,
/* Invalid property, continue with next element */
continue;
}
-
/* Averaging */
current_val = property_average (address, &atsi[c1]);
if (GNUNET_ATS_VALUE_UNDEFINED == current_val)
@@ -662,7 +707,6 @@ GAS_normalization_normalize_property (struct ATS_Address *address,
cur_prop = &properties[c2];
property_normalize (cur_prop, address, ntohl(atsi[c1].type), current_val);
}
-
}
@@ -676,7 +720,9 @@ GAS_normalization_normalize_property (struct ATS_Address *address,
*/
void
GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb,
- void *pref_ch_cb_cls)
+ void *pref_ch_cb_cls,
+ GAS_Normalization_property_changed_cb property_ch_cb,
+ void *property_ch_cb_cls)
{
int c1;
int i;
@@ -685,7 +731,7 @@ GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb,
for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++)
{
- properties[c1].min = 0;
+ properties[c1].min = UINT32_MAX;
properties[c1].max = 0;
properties[c1].have_max = GNUNET_NO;
properties[c1].have_min = GNUNET_NO;
@@ -693,6 +739,9 @@ GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb,
pref_changed_cb = pref_ch_cb;
pref_changed_cb_cls = pref_ch_cb_cls;
+ prop_ch_cb = property_ch_cb;
+ prop_ch_cb_cls = pref_ch_cb_cls;
+
for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE;
return;
diff --git a/src/ats/gnunet-service-ats_normalization.h b/src/ats/gnunet-service-ats_normalization.h
index 24b6b50510..75158ac72e 100644
--- a/src/ats/gnunet-service-ats_normalization.h
+++ b/src/ats/gnunet-service-ats_normalization.h
@@ -41,6 +41,12 @@ typedef void
enum GNUNET_ATS_PreferenceKind kind,
double pref_rel);
+typedef void
+(*GAS_Normalization_property_changed_cb) (void *cls,
+ const struct ATS_Address *peer,
+ uint32_t type,
+ double prop_rel);
+
/**
* Get the normalized preference values for a specific peer
*
@@ -59,12 +65,19 @@ GAS_normalization_get_preferences (const struct GNUNET_PeerIdentity *id);
* @param kind the kind to change the preference
* @param score_abs the normalized score
*/
-float
+void
GAS_normalization_normalize_preference (void *src,
const struct GNUNET_PeerIdentity *peer,
enum GNUNET_ATS_PreferenceKind kind,
float score_abs);
+/**
+ * Update and normalize a atsi performance information
+ *
+ * @param address the address to update
+ * @param atsi the array of performance information
+ * @param atsi_count the number of atsi information in the array
+ */
void
GAS_normalization_normalize_property (struct ATS_Address *address,
const struct GNUNET_ATS_Information *atsi,
@@ -77,7 +90,10 @@ GAS_normalization_normalize_property (struct ATS_Address *address,
* @param pref_ch_cb_cls cls for the callback
*/
void
-GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb, void *pref_ch_cb_cls);
+GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb,
+ void *pref_ch_cb_cls,
+ GAS_Normalization_property_changed_cb property_ch_ch_cls,
+ void *property_ch_cb_cls);
/**
diff --git a/src/ats/perf_ats_mlp.c b/src/ats/perf_ats_mlp.c
index eb9e504a24..a9a1423876 100644
--- a/src/ats/perf_ats_mlp.c
+++ b/src/ats/perf_ats_mlp.c
@@ -141,6 +141,16 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address)
}
+static void
+normalized_property_changed_cb (void *cls,
+ const struct ATS_Address *peer,
+ uint32_t type,
+ double prop_rel)
+{
+ /* TODO */
+}
+
+
static const double *
get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
{
@@ -281,7 +291,7 @@ check (void *cls, char *const *args, const char *cfgfile,
end_now (1);
return;
}
- GAS_normalization_start (NULL, NULL);
+ GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL);
/* Load quotas */
if (GNUNET_ATS_NetworkTypeCount != load_quotas (cfg, quotas_out, quotas_in,
GNUNET_ATS_NetworkTypeCount))
diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c
index 3438606f42..abdc74bdb1 100644
--- a/src/ats/test_ats_mlp.c
+++ b/src/ats/test_ats_mlp.c
@@ -133,6 +133,15 @@ get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
return GAS_normalization_get_preferences (id);
}
+static void
+normalized_property_changed_cb (void *cls,
+ const struct ATS_Address *peer,
+ uint32_t type,
+ double prop_rel)
+{
+ /* TODO */
+}
+
static void
bandwidth_changed_cb (void *cls, struct ATS_Address *address)
@@ -200,7 +209,7 @@ check (void *cls, char *const *args, const char *cfgfile,
end_now (1);
return;
}
- GAS_normalization_start (NULL, NULL);
+ GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL);
/* Setup address hashmap */
addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
diff --git a/src/ats/test_ats_mlp_update.c b/src/ats/test_ats_mlp_update.c
index 8f89efc6a9..e806bd85dd 100644
--- a/src/ats/test_ats_mlp_update.c
+++ b/src/ats/test_ats_mlp_update.c
@@ -140,6 +140,16 @@ get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
}
static void
+normalized_property_changed_cb (void *cls,
+ const struct ATS_Address *peer,
+ uint32_t type,
+ double prop_rel)
+{
+ /* TODO */
+}
+
+
+static void
bandwidth_changed_cb (void *cls, struct ATS_Address *address)
{
static int cb_p0 = GNUNET_NO;
@@ -194,7 +204,7 @@ check (void *cls, char *const *args, const char *cfgfile,
end_now (1);
return;
}
- GAS_normalization_start (NULL, NULL);
+ GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL);
/* Setup address hashmap */
addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
diff --git a/src/ats/test_ats_normalization_update_quality.c b/src/ats/test_ats_normalization_update_quality.c
new file mode 100644
index 0000000000..b6f378bc35
--- /dev/null
+++ b/src/ats/test_ats_normalization_update_quality.c
@@ -0,0 +1,237 @@
+/*
+ This file is part of GNUnet.
+ (C) 2010,2011 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
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ 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.
+*/
+/**
+ * @file ats/test_ats_api_scheduling_update_address.c
+ * @brief test updating an address: add address, get and compare it, update it
+ * get it again and compre
+ * @author Christian Grothoff
+ * @author Matthias Wachs
+ */
+#include "platform.h"
+#include "gnunet_ats_service.h"
+#include "gnunet_testing_lib.h"
+#include "ats.h"
+#include "test_ats_api_common.h"
+
+static GNUNET_SCHEDULER_TaskIdentifier die_task;
+
+/**
+ * Scheduling handle
+ */
+static struct GNUNET_ATS_SchedulingHandle *sched_ats;
+
+/**
+ * Return value
+ */
+static int ret;
+
+/**
+ * Test address
+ */
+static struct Test_Address test_addr;
+
+/**
+ * Test peer
+ */
+static struct PeerContext p[2];
+
+/**
+ * HELLO test address
+ */
+
+struct GNUNET_HELLO_Address test_hello_address[3];
+
+/**
+ * Test ats info
+ */
+struct GNUNET_ATS_Information test_ats_info[3];
+
+/**
+ * Test ats count
+ */
+uint32_t test_ats_count;
+
+
+static void
+end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ die_task = GNUNET_SCHEDULER_NO_TASK;
+
+ if (sched_ats != NULL)
+ GNUNET_ATS_scheduling_done (sched_ats);
+ free_test_address (&test_addr);
+ ret = 0;
+}
+
+
+static void
+end ()
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
+ if (die_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (die_task);
+ die_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ GNUNET_ATS_scheduling_done (sched_ats);
+ sched_ats = NULL;
+ free_test_address (&test_addr);
+}
+
+
+static void
+address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
+ struct Session *session,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+ const struct GNUNET_ATS_Information *atsi,
+ uint32_t ats_count)
+{
+ static int stage = 0;
+ if (0 == stage)
+ {
+ GNUNET_ATS_suggest_address_cancel (sched_ats, &p[0].id);
+
+ /* Update address */
+ /* Prepare ATS Information */
+
+ test_ats_info[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
+ test_ats_info[0].value = htonl(20);
+ test_ats_count = 1;
+
+ GNUNET_ATS_address_update (sched_ats, &test_hello_address[0], NULL, test_ats_info, test_ats_count);
+
+ test_ats_info[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
+ test_ats_info[0].value = htonl(20);
+ test_ats_count = 1;
+
+ GNUNET_ATS_address_update (sched_ats, &test_hello_address[0], NULL, test_ats_info, test_ats_count);
+
+
+ /* Request address */
+ stage ++;
+ }
+}
+
+static void
+run (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Peer *peer)
+{
+ die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
+
+ /* Connect to ATS scheduling */
+ sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
+ if (sched_ats == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n");
+ ret = 1;
+ end ();
+ return;
+ }
+
+ /* Set up peer */
+ if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p[0].id.hashPubKey))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n");
+ ret = GNUNET_SYSERR;
+ end ();
+ return;
+ }
+
+ GNUNET_assert (0 == strcmp (PEERID0, GNUNET_i2s_full (&p[0].id)));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
+ GNUNET_i2s_full(&p[0].id));
+
+ /* Set up peer */
+ if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID1, &p[1].id.hashPubKey))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n");
+ ret = GNUNET_SYSERR;
+ end ();
+ return;
+ }
+
+ GNUNET_assert (0 == strcmp (PEERID1, GNUNET_i2s_full (&p[1].id)));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
+ GNUNET_i2s_full(&p[1].id));
+
+
+
+ /* Adding address for peer 0 */
+ create_test_address (&test_addr, "test", &test_addr, "test", strlen ("test") + 1);
+ /* Prepare ATS Information */
+ test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
+ test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN);
+ test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
+ test_ats_info[1].value = htonl(30);
+ test_ats_count = 2;
+
+ test_hello_address[0].peer = p[0].id;
+ test_hello_address[0].transport_name = test_addr.plugin;
+ test_hello_address[0].address = test_addr.addr;
+ test_hello_address[0].address_length = test_addr.addr_len;
+ GNUNET_ATS_address_add (sched_ats, &test_hello_address[0], NULL, test_ats_info, test_ats_count);
+
+ /* Adding address for peer 1 */
+ create_test_address (&test_addr, "test", &test_addr, "test", strlen ("test") + 1);
+ test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
+ test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN);
+ test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
+ test_ats_info[1].value = htonl(10);
+ test_ats_count = 2;
+
+ test_hello_address[1].peer = p[1].id;
+ test_hello_address[1].transport_name = test_addr.plugin;
+ test_hello_address[1].address = test_addr.addr;
+ test_hello_address[1].address_length = test_addr.addr_len;
+ GNUNET_ATS_address_add (sched_ats, &test_hello_address[1], NULL, test_ats_info, test_ats_count);
+
+ /* Adding 2nd address for peer 1 */
+ test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
+ test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN);
+ test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
+ test_ats_info[1].value = htonl(20);
+ test_ats_count = 2;
+
+ test_hello_address[3].peer = p[1].id;
+ test_hello_address[3].transport_name = test_addr.plugin;
+ test_hello_address[3].address = test_addr.addr;
+ test_hello_address[3].address_length = test_addr.addr_len;
+ GNUNET_ATS_address_add (sched_ats, &test_hello_address[3], NULL, test_ats_info, test_ats_count);
+
+ /* Request address */
+ GNUNET_ATS_suggest_address (sched_ats, &p[0].id);
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ if (0 != GNUNET_TESTING_peer_run ("test_ats_api_scheduling_update_address",
+ "test_ats_api.conf",
+ &run, NULL))
+ return 1;
+ return ret;
+}
+
+/* end of file test_ats_api_scheduling_update_address.c */