summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-08 13:04:27 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-08 13:04:27 +0000
commitb644458a5800a53f3b0196fe559d51a21dca70b9 (patch)
treefa7f8b8a497d5306b68f9f2fe41e565365f8c5c9
parent6115a1150c65bd4a33ed61c6e96594c4a73d86ac (diff)
downloadgnunet-b644458a5800a53f3b0196fe559d51a21dca70b9.tar.gz
gnunet-b644458a5800a53f3b0196fe559d51a21dca70b9.zip
simplify normalization logic, also have clients access norm array of address directly
-rw-r--r--src/ats/gnunet-ats-solver-eval.c59
-rw-r--r--src/ats/gnunet-service-ats_addresses.c1
-rw-r--r--src/ats/gnunet-service-ats_normalization.c275
-rw-r--r--src/ats/gnunet-service-ats_normalization.h13
-rw-r--r--src/ats/gnunet-service-ats_plugins.c3
-rw-r--r--src/ats/gnunet-service-ats_plugins.h2
-rw-r--r--src/ats/plugin_ats_mlp.c19
-rw-r--r--src/ats/plugin_ats_proportional.c20
-rw-r--r--src/ats/plugin_ats_ril.c18
-rw-r--r--src/include/gnunet_ats_plugin.h21
10 files changed, 142 insertions, 289 deletions
diff --git a/src/ats/gnunet-ats-solver-eval.c b/src/ats/gnunet-ats-solver-eval.c
index 5bffb6821..e1340580e 100644
--- a/src/ats/gnunet-ats-solver-eval.c
+++ b/src/ats/gnunet-ats-solver-eval.c
@@ -87,8 +87,6 @@ static int res;
87static void 87static void
88end_now (); 88end_now ();
89 89
90const double *
91get_property_cb (void *cls, const struct ATS_Address *address);
92 90
93static char * 91static char *
94print_generator_type (enum GeneratorType g) 92print_generator_type (enum GeneratorType g)
@@ -140,23 +138,9 @@ find_address_by_id (struct TestPeer *peer, int aid)
140} 138}
141 139
142 140
143static struct TestAddress *
144find_address_by_ats_address (struct TestPeer *p, const struct ATS_Address *addr)
145{
146 struct TestAddress *cur;
147 for (cur = p->addr_head; NULL != cur; cur = cur->next)
148 if ((0 == strcmp(cur->ats_addr->plugin, addr->plugin)) &&
149 (cur->ats_addr->addr_len == addr->addr_len) &&
150 (0 == memcmp (cur->ats_addr->addr, addr->addr, addr->addr_len)))
151 return cur;
152 return NULL;
153}
154
155
156/** 141/**
157 * Logging 142 * Logging
158 */ 143 */
159
160void 144void
161GNUNET_ATS_solver_logging_now (struct LoggingHandle *l) 145GNUNET_ATS_solver_logging_now (struct LoggingHandle *l)
162{ 146{
@@ -660,13 +644,12 @@ set_prop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
660 644
661 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency, 645 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
662 &set_prop_task, pg); 646 &set_prop_task, pg);
663
664} 647}
665 648
649
666/** 650/**
667 * Set ats_property to 0 to find all pgs 651 * Set ats_property to 0 to find all pgs
668 */ 652 */
669
670static struct PropertyGenerator * 653static struct PropertyGenerator *
671find_prop_gen (unsigned int peer, unsigned int address, 654find_prop_gen (unsigned int peer, unsigned int address,
672 uint32_t ats_property) 655 uint32_t ats_property)
@@ -786,7 +769,6 @@ GNUNET_ATS_solver_generate_property_start (unsigned int peer,
786} 769}
787 770
788 771
789
790/** 772/**
791 * Stop all preferences generators 773 * Stop all preferences generators
792 */ 774 */
@@ -1033,7 +1015,8 @@ GNUNET_ATS_solver_generate_preferences_stop (struct PreferenceGenerator *pg)
1033 GNUNET_free (pg); 1015 GNUNET_free (pg);
1034} 1016}
1035 1017
1036struct TestAddress* 1018
1019static struct TestAddress*
1037find_active_address (struct TestPeer *p) 1020find_active_address (struct TestPeer *p)
1038{ 1021{
1039 struct TestAddress *cur; 1022 struct TestAddress *cur;
@@ -1043,6 +1026,7 @@ find_active_address (struct TestPeer *p)
1043 return NULL; 1026 return NULL;
1044} 1027}
1045 1028
1029
1046/** 1030/**
1047 * Generate between the source master and the partner and set property with a 1031 * Generate between the source master and the partner and set property with a
1048 * value depending on the generator. 1032 * value depending on the generator.
@@ -1129,14 +1113,12 @@ GNUNET_ATS_solver_generate_preferences_start (unsigned int peer,
1129 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != feedback_frequency.rel_value_us) 1113 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != feedback_frequency.rel_value_us)
1130 { 1114 {
1131 struct TestAddress * addr = find_active_address(p); 1115 struct TestAddress * addr = find_active_address(p);
1132 const double *properties = get_property_cb (NULL, addr->ats_addr);
1133 1116
1134 pg->last_assigned_bw_in = p->assigned_bw_in; 1117 pg->last_assigned_bw_in = p->assigned_bw_in;
1135 pg->last_assigned_bw_out = p->assigned_bw_out; 1118 pg->last_assigned_bw_out = p->assigned_bw_out;
1136 pg->feedback_bw_in_acc = 0; 1119 pg->feedback_bw_in_acc = 0;
1137 pg->feedback_bw_out_acc = 0; 1120 pg->feedback_bw_out_acc = 0;
1138 1121 pg->last_delay_value = addr->prop_norm[GNUNET_ATS_QUALITY_NET_DELAY];
1139 pg->last_delay_value = properties[GNUNET_ATS_QUALITY_NET_DELAY];
1140 pg->feedback_delay_acc = 0; 1122 pg->feedback_delay_acc = 0;
1141 1123
1142 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get(); 1124 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
@@ -1172,8 +1154,7 @@ GNUNET_ATS_solver_generate_preferences_stop_all ()
1172/** 1154/**
1173 * Experiments 1155 * Experiments
1174 */ 1156 */
1175 1157static const char *
1176const char *
1177print_op (enum OperationType op) 1158print_op (enum OperationType op)
1178{ 1159{
1179 switch (op) { 1160 switch (op) {
@@ -1199,6 +1180,7 @@ print_op (enum OperationType op)
1199 return ""; 1180 return "";
1200} 1181}
1201 1182
1183
1202static struct Experiment * 1184static struct Experiment *
1203create_experiment () 1185create_experiment ()
1204{ 1186{
@@ -1210,6 +1192,7 @@ create_experiment ()
1210 return e; 1192 return e;
1211} 1193}
1212 1194
1195
1213static void 1196static void
1214free_experiment (struct Experiment *e) 1197free_experiment (struct Experiment *e)
1215{ 1198{
@@ -1368,6 +1351,7 @@ load_op_add_address (struct GNUNET_ATS_TEST_Operation *o,
1368 return GNUNET_OK; 1351 return GNUNET_OK;
1369} 1352}
1370 1353
1354
1371static int 1355static int
1372load_op_del_address (struct GNUNET_ATS_TEST_Operation *o, 1356load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
1373 struct Episode *e, 1357 struct Episode *e,
@@ -1447,6 +1431,7 @@ load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
1447 return GNUNET_OK; 1431 return GNUNET_OK;
1448} 1432}
1449 1433
1434
1450static enum GNUNET_ATS_Property 1435static enum GNUNET_ATS_Property
1451parse_preference_string (const char * str) 1436parse_preference_string (const char * str)
1452{ 1437{
@@ -1457,7 +1442,8 @@ parse_preference_string (const char * str)
1457 if (0 == strcmp(str, props[c])) 1442 if (0 == strcmp(str, props[c]))
1458 return c; 1443 return c;
1459 return 0; 1444 return 0;
1460}; 1445}
1446
1461 1447
1462static int 1448static int
1463load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o, 1449load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
@@ -1628,6 +1614,7 @@ load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1628 return GNUNET_OK; 1614 return GNUNET_OK;
1629} 1615}
1630 1616
1617
1631static int 1618static int
1632load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o, 1619load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1633 struct Episode *e, 1620 struct Episode *e,
@@ -3028,25 +3015,6 @@ get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
3028} 3015}
3029 3016
3030 3017
3031const double *
3032get_property_cb (void *cls, const struct ATS_Address *address)
3033{
3034 struct TestPeer *p;
3035 struct TestAddress *a;
3036
3037 if (GNUNET_YES == opt_disable_normalization)
3038 {
3039 p = find_peer_by_pid (&address->peer);
3040 if (NULL == p)
3041 return NULL;
3042 a = find_address_by_ats_address (p, address);
3043 return a->prop_abs;
3044 }
3045 return GAS_normalization_get_properties (NULL,
3046 address);
3047}
3048
3049
3050struct SolverHandle * 3018struct SolverHandle *
3051GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type) 3019GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
3052{ 3020{
@@ -3081,7 +3049,6 @@ GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
3081 sh->env.addresses = sh->addresses; 3049 sh->env.addresses = sh->addresses;
3082 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb; 3050 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
3083 sh->env.get_preferences = &get_preferences_cb; 3051 sh->env.get_preferences = &get_preferences_cb;
3084 sh->env.get_property = &get_property_cb;
3085 sh->env.network_count = GNUNET_ATS_NetworkTypeCount; 3052 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
3086 sh->env.info_cb = &solver_info_cb; 3053 sh->env.info_cb = &solver_info_cb;
3087 sh->env.network_count = GNUNET_ATS_NetworkTypeCount; 3054 sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index 6c40c6fc8..0a35570c7 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -412,6 +412,7 @@ create_address (const struct GNUNET_PeerIdentity *peer,
412 for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++) 412 for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++)
413 { 413 {
414 aa->atsin[c1].avg_queue_index = 0; 414 aa->atsin[c1].avg_queue_index = 0;
415 aa->atsin[c1].norm = DEFAULT_REL_QUALITY;
415 for (c2 = 0; c2 < GAS_normalization_queue_length; c2++) 416 for (c2 = 0; c2 < GAS_normalization_queue_length; c2++)
416 aa->atsin[c1].atsi_abs[c2] = GNUNET_ATS_VALUE_UNDEFINED; 417 aa->atsin[c1].atsi_abs[c2] = GNUNET_ATS_VALUE_UNDEFINED;
417 } 418 }
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c
index 23b7b0cb7..b3d8eba3f 100644
--- a/src/ats/gnunet-service-ats_normalization.c
+++ b/src/ats/gnunet-service-ats_normalization.c
@@ -27,6 +27,7 @@
27 * FIXME: rename to 'properties'!? merge with addresses!? 27 * FIXME: rename to 'properties'!? merge with addresses!?
28 */ 28 */
29#include "platform.h" 29#include "platform.h"
30#include <float.h>
30#include "gnunet_ats_service.h" 31#include "gnunet_ats_service.h"
31#include "gnunet-service-ats_addresses.h" 32#include "gnunet-service-ats_addresses.h"
32#include "gnunet-service-ats_normalization.h" 33#include "gnunet-service-ats_normalization.h"
@@ -36,7 +37,7 @@
36 37
37 38
38/** 39/**
39 * Quality Normalization 40 * Range information for normalization of quality properties.
40 */ 41 */
41struct Property 42struct Property
42{ 43{
@@ -46,9 +47,9 @@ struct Property
46 uint32_t prop_type; 47 uint32_t prop_type;
47 48
48 /** 49 /**
49 * Corresponding enum value. FIXME: type? 50 * Corresponding enum value of the respective quality property.
50 */ 51 */
51 uint32_t atsi_type; 52 enum GNUNET_ATS_Property atsi_type;
52 53
53 /** 54 /**
54 * Minimum value we see for this property across all addresses. 55 * Minimum value we see for this property across all addresses.
@@ -63,80 +64,34 @@ struct Property
63 64
64 65
65/** 66/**
66 * Range information for all properties we see. 67 * Range information for all quality properties we see.
67 */ 68 */
68static struct Property properties[GNUNET_ATS_QualityPropertiesCount]; 69static struct Property properties[GNUNET_ATS_QualityPropertiesCount];
69 70
70 71
71/**
72 * Get the normalized properties values for a specific peer or
73 * the default values if no normalized values are available.
74 *
75 * @param cls ignored
76 * @param address the address
77 * @return pointer to the values, can be indexed with GNUNET_ATS_PreferenceKind
78 */
79const double *
80GAS_normalization_get_properties (void *cls,
81 const struct ATS_Address *address)
82{
83 static double norm_values[GNUNET_ATS_QualityPropertiesCount];
84 unsigned int i;
85
86 for (i = 0; i < GNUNET_ATS_QualityPropertiesCount; i++)
87 {
88 if ((address->atsin[i].norm >= 1.0) && (address->atsin[i].norm <= 2.0))
89 norm_values[i] = address->atsin[i].norm;
90 else
91 norm_values[i] = DEFAULT_REL_QUALITY;
92 }
93 return norm_values;
94}
95
96 72
97/** 73/**
98 * Normalize a specific ATS type with the values in queue. 74 * Add the value from @a atsi to the running average of the
75 * given @a ni quality property.
99 * 76 *
100 * @param address the address 77 * @param ni normalization information to update
101 * @param atsi the ats information 78 * @param atsi the ats information
102 * @return the new average or #GNUNET_ATS_VALUE_UNDEFINED
103 */ 79 */
104static uint32_t 80static void
105property_average (struct ATS_Address *address, 81property_average (struct GAS_NormalizationInfo *ni,
106 const struct GNUNET_ATS_Information *atsi) 82 const struct GNUNET_ATS_Information *atsi)
107{ 83{
108 struct GAS_NormalizationInfo *ni;
109 uint32_t current_type;
110 uint32_t current_val; 84 uint32_t current_val;
111 uint32_t res; 85 uint32_t res;
112 uint64_t sum; 86 uint64_t sum;
113 uint32_t count; 87 uint32_t count;
114 unsigned int c1; 88 unsigned int c1;
115 unsigned int index;
116 unsigned int props[] = GNUNET_ATS_QualityProperties;
117 89
118 /* Average the values of this property */
119 current_type = ntohl (atsi->type);
120 current_val = ntohl (atsi->value); 90 current_val = ntohl (atsi->value);
121 91 GNUNET_assert (GNUNET_ATS_VALUE_UNDEFINED != current_val);
122 for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++) 92 ni->atsi_abs[ni->avg_queue_index++] = current_val;
123 {
124 if (current_type == props[c1])
125 break;
126 }
127 if (c1 == GNUNET_ATS_QualityPropertiesCount)
128 {
129 GNUNET_break(0);
130 return GNUNET_ATS_VALUE_UNDEFINED;
131 }
132 index = c1;
133
134 ni = &address->atsin[index];
135 ni->atsi_abs[ni->avg_queue_index] = current_val;
136 ni->avg_queue_index++;
137 if (GAS_normalization_queue_length == ni->avg_queue_index) 93 if (GAS_normalization_queue_length == ni->avg_queue_index)
138 ni->avg_queue_index = 0; 94 ni->avg_queue_index = 0;
139
140 count = 0; 95 count = 0;
141 sum = 0; 96 sum = 0;
142 for (c1 = 0; c1 < GAS_normalization_queue_length; c1++) 97 for (c1 = 0; c1 < GAS_normalization_queue_length; c1++)
@@ -144,26 +99,12 @@ property_average (struct ATS_Address *address,
144 if (GNUNET_ATS_VALUE_UNDEFINED != ni->atsi_abs[c1]) 99 if (GNUNET_ATS_VALUE_UNDEFINED != ni->atsi_abs[c1])
145 { 100 {
146 count++; 101 count++;
147 if (GNUNET_ATS_VALUE_UNDEFINED > (sum + ni->atsi_abs[c1])) 102 sum += ni->atsi_abs[c1];
148 sum += ni->atsi_abs[c1];
149 else
150 {
151 sum = GNUNET_ATS_VALUE_UNDEFINED - 1;
152 GNUNET_break(0);
153 }
154 } 103 }
155 } 104 }
156 GNUNET_assert(0 != count); 105 GNUNET_assert (0 != count);
157 res = sum / count; 106 res = sum / count;
158 LOG(GNUNET_ERROR_TYPE_DEBUG,
159 "New average of `%s' created by adding %u from %u elements: %u\n",
160 GNUNET_ATS_print_property_type (current_type),
161 current_val,
162 count,
163 res,
164 sum);
165 ni->avg = res; 107 ni->avg = res;
166 return res;
167} 108}
168 109
169 110
@@ -190,8 +131,9 @@ struct FindMinMaxCtx
190 131
191 132
192/** 133/**
193 * Function called on X to find the minimum and maximum 134 * Function called for all addresses and peers to find the minimum and
194 * values for a given property. 135 * maximum (averaged) values for a given quality property. Given
136 * those, we can then calculate the normalized score.
195 * 137 *
196 * @param cls the `struct FindMinMaxCtx` 138 * @param cls the `struct FindMinMaxCtx`
197 * @param h which peer are we looking at (ignored) 139 * @param h which peer are we looking at (ignored)
@@ -220,34 +162,34 @@ find_min_max_it (void *cls,
220 * 162 *
221 * @param cls the `struct Property` with details on the 163 * @param cls the `struct Property` with details on the
222 * property and its global range 164 * property and its global range
223 * @param h which peer are we looking at (ignored) 165 * @param key which peer are we looking at (ignored)
224 * @param k the address for that peer, from where we get 166 * @param value the address for that peer, from where we get
225 * the original value and where we write the 167 * the original value and where we write the
226 * normalized value 168 * normalized value
227 * @return #GNUNET_OK (continue to iterate) 169 * @return #GNUNET_OK (continue to iterate)
228 */ 170 */
229static int 171static int
230normalize_address (void *cls, 172normalize_address (void *cls,
231 const struct GNUNET_PeerIdentity *h, 173 const struct GNUNET_PeerIdentity *key,
232 void *k) 174 void *value)
233{ 175{
234 struct Property *p = cls; 176 struct Property *p = cls;
235 struct ATS_Address *address = k; 177 struct ATS_Address *address = value;
236 double delta; 178 double delta;
237 double backup; 179 double update;
238 uint32_t avg_value; 180 uint32_t avg_value;
239 181
240 backup = address->atsin[p->prop_type].norm;
241 avg_value = address->atsin[p->prop_type].avg; 182 avg_value = address->atsin[p->prop_type].avg;
242 delta = p->max - p->min; 183 delta = p->max - p->min;
243 /* max - 2 * min + avg_value / max - min */ 184 /* max - 2 * min + avg_value / (max - min) */
244 if (0 != delta) 185 if (delta > DBL_EPSILON)
245 address->atsin[p->prop_type].norm = (delta + (avg_value - p->min)) / (delta); 186 update = DEFAULT_REL_QUALITY + (avg_value - p->min) / delta;
246 else 187 else
247 address->atsin[p->prop_type].norm = DEFAULT_REL_QUALITY; 188 update = DEFAULT_REL_QUALITY;
248 189
249 if (backup == address->atsin[p->prop_type].norm) 190 if (update == address->atsin[p->prop_type].norm)
250 return GNUNET_OK; 191 return GNUNET_OK;
192 address->atsin[p->prop_type].norm = update;
251 193
252 LOG (GNUNET_ERROR_TYPE_DEBUG, 194 LOG (GNUNET_ERROR_TYPE_DEBUG,
253 "Normalize `%s' address %p's '%s' with value %u to range [%u..%u] = %.3f\n", 195 "Normalize `%s' address %p's '%s' with value %u to range [%u..%u] = %.3f\n",
@@ -258,84 +200,31 @@ normalize_address (void *cls,
258 p->min, 200 p->min,
259 p->max, 201 p->max,
260 address->atsin[p->prop_type].norm); 202 address->atsin[p->prop_type].norm);
261 GAS_normalized_property_changed (address,
262 p->atsi_type,
263 address->atsin[p->prop_type].norm);
264 return GNUNET_OK; 203 return GNUNET_OK;
265} 204}
266 205
267 206
268/** 207/**
269 * Normalize @a avg_value to a range of values between [1.0, 2.0] 208 * Notify about change in normalized property.
270 * based on min/max values currently known.
271 * 209 *
272 * @param p the property 210 * @param cls the `struct Property` with details on the
273 * @param address the address 211 * property and its global range
274 * @param avg_value the value to normalize 212 * @param key which peer are we looking at (ignored)
213 * @param value the address for that peer
214 * @return #GNUNET_OK (continue to iterate)
275 */ 215 */
276static void 216static int
277property_normalize (struct Property *p, 217notify_change (void *cls,
278 struct ATS_Address *address, 218 const struct GNUNET_PeerIdentity *key,
279 uint32_t avg_value) 219 void *value)
280{ 220{
281 struct FindMinMaxCtx find_ctx; 221 struct Property *p = cls;
282 int addr_count; 222 struct ATS_Address *address = value;
283 int limits_changed;
284
285 find_ctx.p = p;
286 find_ctx.max = 0;
287 find_ctx.min = UINT32_MAX;
288 addr_count = GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
289 &find_min_max_it,
290 &find_ctx);
291 if (0 == addr_count)
292 {
293 GNUNET_break(0);
294 return;
295 }
296
297 limits_changed = GNUNET_NO;
298 if (find_ctx.max != p->max)
299 {
300 LOG (GNUNET_ERROR_TYPE_DEBUG,
301 "Normalizing %s: new maximum %u -> recalculate all values\n",
302 GNUNET_ATS_print_property_type (p->atsi_type),
303 find_ctx.max);
304 p->max = find_ctx.max;
305 limits_changed = GNUNET_YES;
306 }
307
308 if ((find_ctx.min != p->min) && (find_ctx.min < p->max))
309 {
310 LOG (GNUNET_ERROR_TYPE_DEBUG,
311 "Normalizing %s: new minimum %u -> recalculate all values\n",
312 GNUNET_ATS_print_property_type (p->atsi_type),
313 find_ctx.min,
314 find_ctx.max);
315 p->min = find_ctx.min;
316 limits_changed = GNUNET_YES;
317 }
318 else if (find_ctx.min == p->max)
319 {
320 /* Only one value, so minimum has to be 0 */
321 p->min = 0;
322 }
323 223
324 /* Normalize the values of this property */ 224 GAS_normalized_property_changed (address,
325 if (GNUNET_NO == limits_changed) 225 p->atsi_type,
326 { 226 address->atsin[p->prop_type].norm);
327 /* normalize just this address */ 227 return GNUNET_OK;
328 normalize_address (p,
329 &address->peer,
330 address);
331 }
332 else
333 {
334 /* limits changed, normalize all addresses */
335 GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
336 &normalize_address,
337 p);
338 }
339} 228}
340 229
341 230
@@ -351,12 +240,12 @@ GAS_normalization_normalize_property (struct ATS_Address *address,
351 const struct GNUNET_ATS_Information *atsi, 240 const struct GNUNET_ATS_Information *atsi,
352 uint32_t atsi_count) 241 uint32_t atsi_count)
353{ 242{
354 struct Property *cur_prop;
355 unsigned int c1; 243 unsigned int c1;
356 unsigned int c2; 244 unsigned int c2;
357 uint32_t current_type; 245 uint32_t current_type;
358 uint32_t current_val; 246 uint32_t old;
359 unsigned int existing_properties[] = GNUNET_ATS_QualityProperties; 247 struct FindMinMaxCtx find_ctx;
248 int range_changed;
360 249
361 LOG (GNUNET_ERROR_TYPE_DEBUG, 250 LOG (GNUNET_ERROR_TYPE_DEBUG,
362 "Updating %u elements for peer `%s'\n", 251 "Updating %u elements for peer `%s'\n",
@@ -368,30 +257,64 @@ GAS_normalization_normalize_property (struct ATS_Address *address,
368 current_type = ntohl (atsi[c1].type); 257 current_type = ntohl (atsi[c1].type);
369 258
370 for (c2 = 0; c2 < GNUNET_ATS_QualityPropertiesCount; c2++) 259 for (c2 = 0; c2 < GNUNET_ATS_QualityPropertiesCount; c2++)
371 { 260 if (current_type == properties[c2].atsi_type)
372 /* Check if type is valid */
373 if (current_type == existing_properties[c2])
374 break; 261 break;
375 }
376 if (GNUNET_ATS_QualityPropertiesCount == c2) 262 if (GNUNET_ATS_QualityPropertiesCount == c2)
377 { 263 {
378 /* Invalid property, continue with next element */ 264 /* Not a quality property, continue with next element */
379 continue; 265 continue;
380 } 266 }
381 /* Averaging */ 267 /* Calculate running average */
382 current_val = property_average (address, &atsi[c1]); 268 old = address->atsin[c2].avg;
383 if (GNUNET_ATS_VALUE_UNDEFINED == current_val) 269 property_average (&address->atsin[c2],
270 &atsi[c1]);
271 if (old == address->atsin[c2].avg)
272 continue; /* no change */
273 range_changed = GNUNET_NO;
274 if ( (old == properties[c2].min) ||
275 (old == properties[c2].max) ||
276 (address->atsin[c2].avg < properties[c2].min) ||
277 (address->atsin[c2].avg > properties[c2].max) )
384 { 278 {
385 GNUNET_break(0); 279 /* need to re-calculate min/max range, as it may have changed */
386 continue; 280 find_ctx.p = &properties[c2];
281 find_ctx.max = 0;
282 find_ctx.min = UINT32_MAX;
283 if (0 ==
284 GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
285 &find_min_max_it,
286 &find_ctx))
287 {
288 GNUNET_break(0);
289 continue;
290 }
291 if ( (find_ctx.min != properties[c2].min) ||
292 (find_ctx.max != properties[c2].max) )
293 {
294 properties[c2].min = find_ctx.min;
295 properties[c2].max = find_ctx.max;
296 /* limits changed, (re)normalize all addresses */
297 range_changed = GNUNET_YES;
298 }
387 } 299 }
300 if (GNUNET_YES == range_changed)
301 GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
302 &normalize_address,
303 &properties[c2]);
304 else
305 normalize_address (&properties[c2],
306 &address->peer,
307 address);
308 /* after all peers have been updated, notify about changes */
309 if (GNUNET_YES == range_changed)
310 GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
311 &notify_change,
312 &properties[c2]);
313 else
314 notify_change (&properties[c2],
315 &address->peer,
316 address);
388 317
389 /* Normalizing */
390 /* Check min, max */
391 cur_prop = &properties[c2];
392 property_normalize (cur_prop,
393 address,
394 current_val);
395 } 318 }
396 GAS_plugin_solver_unlock (); 319 GAS_plugin_solver_unlock ();
397} 320}
@@ -404,7 +327,7 @@ void
404GAS_normalization_start () 327GAS_normalization_start ()
405{ 328{
406 unsigned int c1; 329 unsigned int c1;
407 unsigned int existing_properties[] = GNUNET_ATS_QualityProperties; 330 const unsigned int existing_properties[] = GNUNET_ATS_QualityProperties;
408 331
409 for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++) 332 for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++)
410 { 333 {
diff --git a/src/ats/gnunet-service-ats_normalization.h b/src/ats/gnunet-service-ats_normalization.h
index d3f10bb13..add02ba42 100644
--- a/src/ats/gnunet-service-ats_normalization.h
+++ b/src/ats/gnunet-service-ats_normalization.h
@@ -35,19 +35,6 @@
35 35
36 36
37/** 37/**
38 * Get the normalized properties values for a specific peer or
39 * the default values if no normalized values are available.
40 *
41 * @param cls ignored
42 * @param address the address
43 * @return pointer to the values, can be indexed with GNUNET_ATS_PreferenceKind
44 */
45const double *
46GAS_normalization_get_properties (void *cls,
47 const struct ATS_Address *address);
48
49
50/**
51 * Update and normalize a @a atsi performance information 38 * Update and normalize a @a atsi performance information
52 * 39 *
53 * @param address the address to update 40 * @param address the address to update
diff --git a/src/ats/gnunet-service-ats_plugins.c b/src/ats/gnunet-service-ats_plugins.c
index ad39ab441..8448e4c4e 100644
--- a/src/ats/gnunet-service-ats_plugins.c
+++ b/src/ats/gnunet-service-ats_plugins.c
@@ -78,7 +78,7 @@ GAS_normalized_preference_changed (const struct GNUNET_PeerIdentity *peer,
78 */ 78 */
79void 79void
80GAS_normalized_property_changed (struct ATS_Address *address, 80GAS_normalized_property_changed (struct ATS_Address *address,
81 uint32_t type, 81 enum GNUNET_ATS_Property type,
82 double prop_rel) 82 double prop_rel)
83{ 83{
84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -432,7 +432,6 @@ GAS_plugins_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
432 env.info_cb = &solver_info_cb; 432 env.info_cb = &solver_info_cb;
433 env.bandwidth_changed_cb = &bandwidth_changed_cb; 433 env.bandwidth_changed_cb = &bandwidth_changed_cb;
434 env.get_preferences = &GAS_normalization_get_preferences_by_peer; 434 env.get_preferences = &GAS_normalization_get_preferences_by_peer;
435 env.get_property = &GAS_normalization_get_properties;
436 env.cfg = cfg; 435 env.cfg = cfg;
437 env.stats = GSA_stats; 436 env.stats = GSA_stats;
438 env.addresses = GSA_addresses; 437 env.addresses = GSA_addresses;
diff --git a/src/ats/gnunet-service-ats_plugins.h b/src/ats/gnunet-service-ats_plugins.h
index 5b521165b..09c4b36f6 100644
--- a/src/ats/gnunet-service-ats_plugins.h
+++ b/src/ats/gnunet-service-ats_plugins.h
@@ -73,7 +73,7 @@ GAS_normalized_preference_changed (const struct GNUNET_PeerIdentity *peer,
73 */ 73 */
74void 74void
75GAS_normalized_property_changed (struct ATS_Address *address, 75GAS_normalized_property_changed (struct ATS_Address *address,
76 uint32_t type, 76 enum GNUNET_ATS_Property type,
77 double prop_rel); 77 double prop_rel);
78 78
79 79
diff --git a/src/ats/plugin_ats_mlp.c b/src/ats/plugin_ats_mlp.c
index 89be5ae7d..152b52d15 100644
--- a/src/ats/plugin_ats_mlp.c
+++ b/src/ats/plugin_ats_mlp.c
@@ -960,9 +960,8 @@ mlp_create_problem_add_address_information (void *cls,
960 struct ATS_Peer *peer; 960 struct ATS_Peer *peer;
961 struct MLP_information *mlpi; 961 struct MLP_information *mlpi;
962 char *name; 962 char *name;
963 const double *props; 963 double prop;
964 double cur_bigm; 964 double cur_bigm;
965
966 uint32_t addr_net; 965 uint32_t addr_net;
967 uint32_t addr_net_index; 966 uint32_t addr_net_index;
968 unsigned long long max_quota; 967 unsigned long long max_quota;
@@ -1111,15 +1110,21 @@ mlp_create_problem_add_address_information (void *cls,
1111 /* For all quality metrics, set quality of this address */ 1110 /* For all quality metrics, set quality of this address */
1112 if (GNUNET_YES == mlp->opt_dbg_optimize_quality) 1111 if (GNUNET_YES == mlp->opt_dbg_optimize_quality)
1113 { 1112 {
1114 props = mlp->env->get_property (mlp->env->cls, address);
1115 for (c = 0; c < mlp->pv.m_q; c++) 1113 for (c = 0; c < mlp->pv.m_q; c++)
1116 { 1114 {
1117 if ((props[c] < 1.0) && (props[c] > 2.0)) 1115 prop = address->atsin[c].norm;
1116 if ((prop < 1.0) && (prop > 2.0))
1118 { 1117 {
1119 fprintf (stderr, "PROP == %.3f \t ", props[c]); 1118 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1119 "PROP == %.3f \t ",
1120 prop);
1120 GNUNET_break (0); 1121 GNUNET_break (0);
1121 } 1122 }
1122 mlp_create_problem_set_value (p, p->r_q[c], mlpi->c_b, props[c], __LINE__); 1123 mlp_create_problem_set_value (p,
1124 p->r_q[c],
1125 mlpi->c_b,
1126 prop,
1127 __LINE__);
1123 } 1128 }
1124 } 1129 }
1125 } 1130 }
@@ -1911,7 +1916,7 @@ GAS_mlp_address_add (void *solver,
1911static void 1916static void
1912GAS_mlp_address_property_changed (void *solver, 1917GAS_mlp_address_property_changed (void *solver,
1913 struct ATS_Address *address, 1918 struct ATS_Address *address,
1914 uint32_t type, 1919 enum GNUNET_ATS_Property type,
1915 uint32_t abs_value, 1920 uint32_t abs_value,
1916 double rel_value) 1921 double rel_value)
1917{ 1922{
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c
index e45244ec0..ad85f805e 100644
--- a/src/ats/plugin_ats_proportional.c
+++ b/src/ats/plugin_ats_proportional.c
@@ -687,8 +687,6 @@ find_best_address_it (void *cls,
687 struct AddressSolverInformation *asi; 687 struct AddressSolverInformation *asi;
688 struct GNUNET_TIME_Relative active_time; 688 struct GNUNET_TIME_Relative active_time;
689 struct GNUNET_TIME_Relative min_active_time; 689 struct GNUNET_TIME_Relative min_active_time;
690 const double *norm_prop_cur;
691 const double *norm_prop_best;
692 double best_delay; 690 double best_delay;
693 double best_distance; 691 double best_distance;
694 double cur_delay; 692 double cur_delay;
@@ -738,19 +736,12 @@ find_best_address_it (void *cls,
738 } 736 }
739 737
740 /* Now compare ATS information */ 738 /* Now compare ATS information */
741 norm_prop_cur = ctx->s->env->get_property (ctx->s->env->cls,
742 current);
743 index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE); 739 index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE);
744 cur_distance = norm_prop_cur[index]; 740 cur_distance = current->atsin[index].norm;
741 best_distance = ctx->best->atsin[index].norm;
745 index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY); 742 index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
746 cur_delay = norm_prop_cur[index]; 743 cur_delay = current->atsin[index].norm;
747 744 best_delay = ctx->best->atsin[index].norm;
748 norm_prop_best = ctx->s->env->get_property (ctx->s->env->cls,
749 ctx->best);
750 index = find_property_index (GNUNET_ATS_QUALITY_NET_DISTANCE);
751 best_distance = norm_prop_best[index];
752 index = find_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
753 best_delay = norm_prop_best[index];
754 745
755 /* user shorter distance */ 746 /* user shorter distance */
756 if (cur_distance < best_distance) 747 if (cur_distance < best_distance)
@@ -1614,7 +1605,7 @@ GAS_proportional_address_add (void *solver,
1614static void 1605static void
1615GAS_proportional_address_property_changed (void *solver, 1606GAS_proportional_address_property_changed (void *solver,
1616 struct ATS_Address *address, 1607 struct ATS_Address *address,
1617 uint32_t type, 1608 enum GNUNET_ATS_Property type,
1618 uint32_t abs_value, 1609 uint32_t abs_value,
1619 double rel_value) 1610 double rel_value)
1620{ 1611{
@@ -1738,7 +1729,6 @@ libgnunet_plugin_ats_proportional_init (void *cls)
1738 GNUNET_assert (NULL != env->cfg); 1729 GNUNET_assert (NULL != env->cfg);
1739 GNUNET_assert (NULL != env->bandwidth_changed_cb); 1730 GNUNET_assert (NULL != env->bandwidth_changed_cb);
1740 GNUNET_assert (NULL != env->get_preferences); 1731 GNUNET_assert (NULL != env->get_preferences);
1741 GNUNET_assert (NULL != env->get_property);
1742 1732
1743 s = GNUNET_new (struct GAS_PROPORTIONAL_Handle); 1733 s = GNUNET_new (struct GAS_PROPORTIONAL_Handle);
1744 s->env = env; 1734 s->env = env;
diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c
index 850655a27..bd3c5e4a5 100644
--- a/src/ats/plugin_ats_ril.c
+++ b/src/ats/plugin_ats_ril.c
@@ -2375,14 +2375,14 @@ GAS_ril_address_delete (void *solver,
2375 * 2375 *
2376 * @param solver solver handle 2376 * @param solver solver handle
2377 * @param address the address 2377 * @param address the address
2378 * @param type the ATSI type in HBO 2378 * @param type the ATSI type
2379 * @param abs_value the absolute value of the property 2379 * @param abs_value the absolute value of the property
2380 * @param rel_value the normalized value 2380 * @param rel_value the normalized value
2381 */ 2381 */
2382static void 2382static void
2383GAS_ril_address_property_changed (void *solver, 2383GAS_ril_address_property_changed (void *solver,
2384 struct ATS_Address *address, 2384 struct ATS_Address *address,
2385 uint32_t type, 2385 enum GNUNET_ATS_Property type,
2386 uint32_t abs_value, 2386 uint32_t abs_value,
2387 double rel_value) 2387 double rel_value)
2388{ 2388{
@@ -2583,14 +2583,14 @@ libgnunet_plugin_ats_ril_init (void *cls)
2583 char *string; 2583 char *string;
2584 float f_tmp; 2584 float f_tmp;
2585 2585
2586 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_init() Initializing RIL solver\n"); 2586 LOG (GNUNET_ERROR_TYPE_DEBUG,
2587 "API_init() Initializing RIL solver\n");
2587 2588
2588 GNUNET_assert(NULL != env); 2589 GNUNET_assert (NULL != env);
2589 GNUNET_assert(NULL != env->cfg); 2590 GNUNET_assert (NULL != env->cfg);
2590 GNUNET_assert(NULL != env->stats); 2591 GNUNET_assert (NULL != env->stats);
2591 GNUNET_assert(NULL != env->bandwidth_changed_cb); 2592 GNUNET_assert (NULL != env->bandwidth_changed_cb);
2592 GNUNET_assert(NULL != env->get_preferences); 2593 GNUNET_assert (NULL != env->get_preferences);
2593 GNUNET_assert(NULL != env->get_property);
2594 2594
2595 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_RBF_DIVISOR", &solver->parameters.rbf_divisor)) 2595 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_RBF_DIVISOR", &solver->parameters.rbf_divisor))
2596 { 2596 {
diff --git a/src/include/gnunet_ats_plugin.h b/src/include/gnunet_ats_plugin.h
index e57b95a0f..5fdc33f71 100644
--- a/src/include/gnunet_ats_plugin.h
+++ b/src/include/gnunet_ats_plugin.h
@@ -134,7 +134,7 @@ typedef void
134typedef void 134typedef void
135(*GAS_solver_address_property_changed) (void *solver, 135(*GAS_solver_address_property_changed) (void *solver,
136 struct ATS_Address *address, 136 struct ATS_Address *address,
137 uint32_t type, 137 enum GNUNET_ATS_Property type,
138 uint32_t abs_value, 138 uint32_t abs_value,
139 double rel_value); 139 double rel_value);
140 140
@@ -402,20 +402,6 @@ typedef const double *
402 402
403 403
404/** 404/**
405 * Callback to call from solver to obtain transport properties for an
406 * address
407 *
408 * @param cls the cls
409 * @param address the address
410 * @return carry of double values containing the preferences with
411 * GNUNET_ATS_PreferenceCount elements
412 */
413typedef const double *
414(*GAS_get_properties) (void *cls,
415 const struct ATS_Address *address);
416
417
418/**
419 * The ATS plugin will pass a pointer to a struct 405 * The ATS plugin will pass a pointer to a struct
420 * of this type as to the initialization function 406 * of this type as to the initialization function
421 * of the ATS plugins. 407 * of the ATS plugins.
@@ -453,11 +439,6 @@ struct GNUNET_ATS_PluginEnvironment
453 GAS_get_preferences get_preferences; 439 GAS_get_preferences get_preferences;
454 440
455 /** 441 /**
456 * ATS addresses function to obtain property values
457 */
458 GAS_get_properties get_property;
459
460 /**
461 * Callback for solver to call with status information, 442 * Callback for solver to call with status information,
462 * can be NULL 443 * can be NULL
463 */ 444 */