aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-02-25 15:38:01 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-02-25 15:38:01 +0000
commitf2a58ae1caa79ddda66ea8c6a056e466394fba0d (patch)
tree87bd0f92b135c8c78051fd26341fed7a8957dbb1 /src
parent2bfda1b61e4fffb4ff562bf52c26ce9a4bb095ab (diff)
downloadgnunet-f2a58ae1caa79ddda66ea8c6a056e466394fba0d.tar.gz
gnunet-f2a58ae1caa79ddda66ea8c6a056e466394fba0d.zip
changes
Diffstat (limited to 'src')
-rw-r--r--src/ats/gnunet-service-ats_addresses_mlp.c11
-rw-r--r--src/ats/test_ats_mlp.c100
2 files changed, 68 insertions, 43 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c
index 5d92be3a6..3e03e6adc 100644
--- a/src/ats/gnunet-service-ats_addresses_mlp.c
+++ b/src/ats/gnunet-service-ats_addresses_mlp.c
@@ -1026,7 +1026,7 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value
1026 if ((GLP_YES == mlp_use) && (GNUNET_NO == address->active)) 1026 if ((GLP_YES == mlp_use) && (GNUNET_NO == address->active))
1027 { 1027 {
1028 /* Address switch: Activate address*/ 1028 /* Address switch: Activate address*/
1029 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %f : enabling address\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw); 1029 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : enabling address\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw);
1030 address->active = GNUNET_YES; 1030 address->active = GNUNET_YES;
1031 address->assigned_bw_in.value__ = htonl (mlp_bw); 1031 address->assigned_bw_in.value__ = htonl (mlp_bw);
1032 address->assigned_bw_out.value__ = htonl (mlp_bw); 1032 address->assigned_bw_out.value__ = htonl (mlp_bw);
@@ -1035,7 +1035,7 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value
1035 else if ((GLP_NO == mlp_use) && (GNUNET_YES == address->active)) 1035 else if ((GLP_NO == mlp_use) && (GNUNET_YES == address->active))
1036 { 1036 {
1037 /* Address switch: Disable address*/ 1037 /* Address switch: Disable address*/
1038 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %f : disabling address\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw); 1038 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : disabling address\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw);
1039 address->active = GNUNET_NO; 1039 address->active = GNUNET_NO;
1040 /* Set bandwidth to 0 */ 1040 /* Set bandwidth to 0 */
1041 address->assigned_bw_in.value__ = htonl (0); 1041 address->assigned_bw_in.value__ = htonl (0);
@@ -1046,14 +1046,14 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value
1046 (mlp_bw != ntohl(address->assigned_bw_in.value__))) 1046 (mlp_bw != ntohl(address->assigned_bw_in.value__)))
1047 { 1047 {
1048 /* Bandwidth changed */ 1048 /* Bandwidth changed */
1049 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %f : bandwidth changed\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw); 1049 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : bandwidth changed\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw);
1050 address->assigned_bw_in.value__ = htonl (mlp_bw); 1050 address->assigned_bw_in.value__ = htonl (mlp_bw);
1051 address->assigned_bw_out.value__ = htonl (mlp_bw); 1051 address->assigned_bw_out.value__ = htonl (mlp_bw);
1052 mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address); 1052 mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address);
1053 } 1053 }
1054 else 1054 else
1055 { 1055 {
1056 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %f : no change\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw); 1056 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : no change\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw);
1057 } 1057 }
1058 1058
1059 return GNUNET_OK; 1059 return GNUNET_OK;
@@ -1430,7 +1430,8 @@ GAS_mlp_get_preferred_address (void *solver,
1430 /* Added new peer, we have to rebuild problem before solving */ 1430 /* Added new peer, we have to rebuild problem before solving */
1431 mlp->mlp_prob_changed = GNUNET_YES; 1431 mlp->mlp_prob_changed = GNUNET_YES;
1432 } 1432 }
1433 GAS_mlp_solve_problem (mlp, addresses); 1433 if (GNUNET_YES == mlp->mlp_auto_solve)
1434 GAS_mlp_solve_problem (mlp, addresses);
1434 1435
1435 /* Get prefered address */ 1436 /* Get prefered address */
1436 GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, 1437 GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c
index 918edef02..366a18298 100644
--- a/src/ats/test_ats_mlp.c
+++ b/src/ats/test_ats_mlp.c
@@ -121,25 +121,52 @@ end_now (int res)
121} 121}
122 122
123static void 123static void
124bandwidth_changed_cb (void *cls, struct ATS_Address *address) 124end_correctly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
125{ 125{
126 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP suggests for peer `%s' address `%s':`%s' in %llu out %llu \n", 126 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Test ending with success\n"));
127 GNUNET_i2s(&address->peer), address->plugin, address->addr, 127 end_now (0);
128 ntohl(address->assigned_bw_in.value__),
129 ntohl(address->assigned_bw_out.value__));
130 //end_now (0);
131} 128}
132 129
133static void 130static void
134end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 131end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
135{ 132{
136 timeout_task = GNUNET_SCHEDULER_NO_TASK; 133 timeout_task = GNUNET_SCHEDULER_NO_TASK;
137 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Test failed: timeout\n")); 134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Test ending with timeout\n"));
138 end_now (1); 135 end_now (1);
139} 136}
140 137
141 138
142static void 139static void
140bandwidth_changed_cb (void *cls, struct ATS_Address *address)
141{
142 static int cb_p0 = GNUNET_NO;
143 static int cb_p1 = GNUNET_NO;
144
145 unsigned long long in = ntohl(address->assigned_bw_in.value__);
146 unsigned long long out = ntohl(address->assigned_bw_out.value__);
147
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MLP suggests for peer `%s' address `%s':`%s' in %llu out %llu \n",
149 GNUNET_i2s(&address->peer),
150 address->plugin,
151 address->addr,
152 in, out);
153
154 if ((in > 0) && (out > 0) &&
155 (0 == memcmp(&p[0], &address->peer, sizeof (address->peer))))
156 cb_p0 ++;
157
158 if ((in > 0) && (out > 0) &&
159 (0 == memcmp(&p[1], &address->peer, sizeof (address->peer))))
160 cb_p1 ++;
161
162 if ((1 == cb_p0) && (1 == cb_p1))
163 GNUNET_SCHEDULER_add_now (&end_correctly, NULL);
164 else if ((1 > cb_p0) || (1 > cb_p1))
165 GNUNET_SCHEDULER_add_now (&end_badly, NULL);
166}
167
168
169static void
143check (void *cls, char *const *args, const char *cfgfile, 170check (void *cls, char *const *args, const char *cfgfile,
144 const struct GNUNET_CONFIGURATION_Handle *cfg) 171 const struct GNUNET_CONFIGURATION_Handle *cfg)
145{ 172{
@@ -185,6 +212,7 @@ check (void *cls, char *const *args, const char *cfgfile,
185 end_now (1); 212 end_now (1);
186 return; 213 return;
187 } 214 }
215 mlp->mlp_auto_solve = GNUNET_NO;
188 216
189 /* Create peer 0 */ 217 /* Create peer 0 */
190 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p[0].hashPubKey)) 218 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p[0].hashPubKey))
@@ -202,35 +230,46 @@ check (void *cls, char *const *args, const char *cfgfile,
202 return; 230 return;
203 } 231 }
204 232
205 /* Create address 3 */ 233 /* Create address 0 */
206 address[2] = create_address (&p[1], "test_plugin2", "test_addr2", strlen("test_addr2")+1, 0); 234 address[0] = create_address (&p[0], "test_plugin0", "test_addr0", strlen("test_addr0")+1, 0);
207 if (NULL == address[2]) 235 if (NULL == address[0])
208 { 236 {
209 GNUNET_break (0); 237 GNUNET_break (0);
210 end_now (1); 238 end_now (1);
211 return; 239 return;
212 } 240 }
213 GNUNET_CONTAINER_multihashmap_put (addresses, &p[1].hashPubKey, address[2], 241 GNUNET_CONTAINER_multihashmap_put (addresses, &p[0].hashPubKey, address[0],
214 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 242 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
243 /* Adding address 0 */
244 GAS_mlp_address_add (mlp, addresses, address[0]);
215 245
216 246 /* Create address 1 */
247 address[1] = create_address (&p[0], "test_plugin1", "test_addr1", strlen("test_addr1")+1, 0);
248 if (NULL == address[1])
249 {
250 GNUNET_break (0);
251 end_now (1);
252 return;
253 }
254 GNUNET_CONTAINER_multihashmap_put (addresses, &p[0].hashPubKey, address[1],
255 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
217 /* Adding address 1*/ 256 /* Adding address 1*/
218 GAS_mlp_address_add (mlp, addresses, address[2]); 257 GAS_mlp_address_add (mlp, addresses, address[1]);
219 258
220 259
221 /* Create address 0 */ 260 /* Create address 3 */
222 address[0] = create_address (&p[0], "test_plugin0", "test_addr0", strlen("test_addr0")+1, 0); 261 address[2] = create_address (&p[1], "test_plugin2", "test_addr2", strlen("test_addr2")+1, 0);
223 if (NULL == address[0]) 262 if (NULL == address[2])
224 { 263 {
225 GNUNET_break (0); 264 GNUNET_break (0);
226 end_now (1); 265 end_now (1);
227 return; 266 return;
228 } 267 }
229 GNUNET_CONTAINER_multihashmap_put (addresses, &p[0].hashPubKey, address[0], 268 GNUNET_CONTAINER_multihashmap_put (addresses, &p[1].hashPubKey, address[2],
230 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 269 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
270 /* Adding address 3*/
271 GAS_mlp_address_add (mlp, addresses, address[2]);
231 272
232 /* Adding address 0 */
233 GAS_mlp_address_add (mlp, addresses, address[0]);
234 273
235 /* Updating address 0*/ 274 /* Updating address 0*/
236 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); 275 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
@@ -239,32 +278,17 @@ check (void *cls, char *const *args, const char *cfgfile,
239 278
240 /* Retrieving preferred address for peer and wait for callback */ 279 /* Retrieving preferred address for peer and wait for callback */
241 GAS_mlp_get_preferred_address (mlp, addresses, &p[0]); 280 GAS_mlp_get_preferred_address (mlp, addresses, &p[0]);
242 281 GAS_mlp_get_preferred_address (mlp, addresses, &p[1]);
243 /* Create address 1 */
244 address[1] = create_address (&p[0], "test_plugin1", "test_addr1", strlen("test_addr1")+1, 0);
245 if (NULL == address[1])
246 {
247 GNUNET_break (0);
248 end_now (1);
249 return;
250 }
251 GNUNET_CONTAINER_multihashmap_put (addresses, &p[0].hashPubKey, address[1],
252 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
253 282
254 283
255 /* Adding address 1*/ 284#if 0
256 GAS_mlp_address_add (mlp, addresses, address[1]);
257
258 /* Updating address 1*/ 285 /* Updating address 1*/
259 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); 286 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
260 ats.value = htonl (GNUNET_ATS_NET_WAN); 287 ats.value = htonl (GNUNET_ATS_NET_WAN);
261 GAS_mlp_address_update (mlp, addresses, address[1], 1, GNUNET_NO, &ats, 1); 288 GAS_mlp_address_update (mlp, addresses, address[1], 1, GNUNET_NO, &ats, 1);
262
263 GAS_mlp_address_delete (mlp, addresses, address[0], GNUNET_NO); 289 GAS_mlp_address_delete (mlp, addresses, address[0], GNUNET_NO);
264 290#endif
265 end_now (0); 291 GAS_mlp_solve_problem (mlp, addresses);
266 //struct GAS_MLP_SolutionContext ctx;
267 //GAS_mlp_solve_problem (mlp, &ctx);
268} 292}
269 293
270 294