aboutsummaryrefslogtreecommitdiff
path: root/src/ats/test_ats_simplistic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/test_ats_simplistic.c')
-rw-r--r--src/ats/test_ats_simplistic.c207
1 files changed, 162 insertions, 45 deletions
diff --git a/src/ats/test_ats_simplistic.c b/src/ats/test_ats_simplistic.c
index 8da88cf60..cf047ff43 100644
--- a/src/ats/test_ats_simplistic.c
+++ b/src/ats/test_ats_simplistic.c
@@ -36,6 +36,8 @@
36#include "ats.h" 36#include "ats.h"
37#include "test_ats_api_common.h" 37#include "test_ats_api_common.h"
38 38
39#define DEBUG_ATS_INFO GNUNET_NO
40
39static GNUNET_SCHEDULER_TaskIdentifier die_task; 41static GNUNET_SCHEDULER_TaskIdentifier die_task;
40 42
41/** 43/**
@@ -56,7 +58,8 @@ static struct Test_Address test_addr[2];
56/** 58/**
57 * Test peer 59 * Test peer
58 */ 60 */
59static struct PeerContext p; 61static struct PeerContext p[2];
62
60 63
61/** 64/**
62 * HELLO address 65 * HELLO address
@@ -189,22 +192,28 @@ compare_ats (const struct GNUNET_ATS_Information *ats_is, uint32_t ats_count_is,
189 type2 = ntohl(ats_should[c_i].type); 192 type2 = ntohl(ats_should[c_i].type);
190 if (type1 == type2) 193 if (type1 == type2)
191 { 194 {
195#if DEBUG_ATS_INFO
192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS type `%s'\n", 196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS type `%s'\n",
193 prop[type1]); 197 prop[type1]);
198#endif
194 val1 = ntohl(ats_is[c_o].value); 199 val1 = ntohl(ats_is[c_o].value);
195 val2 = ntohl(ats_should[c_i].value); 200 val2 = ntohl(ats_should[c_i].value);
196 if (val1 != val2) 201 if (val1 != val2)
197 { 202 {
203#if DEBUG_ATS_INFO
198 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ATS value `%s' not equal: %u != %u\n", 204 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ATS value `%s' not equal: %u != %u\n",
199 prop[type1], 205 prop[type1],
200 val1, val2); 206 val1, val2);
207#endif
201 res = GNUNET_SYSERR; 208 res = GNUNET_SYSERR;
202 } 209 }
203 else 210 else
204 { 211 {
212#if DEBUG_ATS_INFO
205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS value `%s' equal: %u == %u\n", 213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS value `%s' equal: %u == %u\n",
206 prop[type1], 214 prop[type1],
207 val1, val2); 215 val1, val2);
216#endif
208 } 217 }
209 } 218 }
210 } 219 }
@@ -220,50 +229,144 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
220 const struct GNUNET_ATS_Information *atsi, 229 const struct GNUNET_ATS_Information *atsi,
221 uint32_t ats_count) 230 uint32_t ats_count)
222{ 231{
223 if (GNUNET_OK == compare_addresses (address, session, &test_hello_address[0], test_session[0])) 232 static int stage = 0;
224 { 233 unsigned int bw_in = ntohl(bandwidth_in.value__);
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stage 0: Callback with correct address `%s'\n", 234 unsigned int bw_out = ntohl(bandwidth_out.value__);
226 GNUNET_i2s (&address->peer)); 235 if (0 == stage)
227 ret = 0;
228 }
229 else
230 { 236 {
231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stage 0: Callback with invalid address `%s'\n", 237 if (GNUNET_OK == compare_addresses (address, session, &test_hello_address[0], test_session[0]))
232 GNUNET_i2s (&address->peer)); 238 {
239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stage 0: Callback with correct address `%s'\n",
240 GNUNET_i2s (&address->peer));
241 ret = 0;
242 }
243 else
244 {
245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stage 0: Callback with invalid address `%s'\n",
246 GNUNET_i2s (&address->peer));
247 ret = 1;
248 }
249
250 if (GNUNET_OK != compare_ats(atsi, ats_count, test_ats_info, test_ats_count))
251 {
252 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage 0: Callback with incorrect ats info \n");
233 ret = 1; 253 ret = 1;
234 } 254 }
235 255
236 if (GNUNET_OK != compare_ats(atsi, ats_count, test_ats_info, test_ats_count)) 256 if (bw_in > wan_quota_in)
237 { 257 {
238 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage 0: Callback with incorrect ats info \n"); 258 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggested WAN inbound quota %u bigger than allowed quota %llu \n",
239 ret = 1; 259 bw_in, wan_quota_in);
240 } 260 ret = 1;
261 }
262 else
263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suggested WAN inbound quota %u, allowed quota %llu \n",
264 bw_in, wan_quota_in);
241 265
242 if (ntohl(bandwidth_in.value__) > wan_quota_in) 266 if (bw_out > wan_quota_out)
243 { 267 {
244 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggested WAN inbound quota %u bigger than allowed quota %llu \n", 268 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggested WAN outbound quota %u bigger than allowed quota %llu \n",
245 (unsigned int) ntohl(bandwidth_in.value__), wan_quota_in); 269 bw_out, wan_quota_out);
246 ret = 1; 270 ret = 1;
247 } 271 }
248 else 272 else
249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suggested WAN inbound quota %u, allowed quota %llu \n", 273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suggested WAN outbound quota %u, allowed quota %llu \n",
250 (unsigned int) ntohl(bandwidth_in.value__), wan_quota_in); 274 bw_out, wan_quota_out);
251 275
252 if (ntohl(bandwidth_out.value__) > wan_quota_out) 276 if (1 == ret)
277 {
278 GNUNET_ATS_suggest_address_cancel (sched_ats, &p[0].id);
279 GNUNET_SCHEDULER_add_now (&end, NULL);
280 return;
281 }
282 p[0].bw_out_assigned = bw_out;
283 p[0].bw_in_assigned = bw_in;
284 stage ++;
285
286 /* Add a 2nd address */
287 /* Prepare ATS Information */
288 test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
289 test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN);
290 test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
291 test_ats_info[1].value = htonl(1);
292 test_ats_count = 2;
293
294 /* Adding address with session */
295 test_session[1] = &test_addr[1];
296 create_test_address (&test_addr[1], "test1", test_session[1], "test1", strlen ("test1") + 1);
297 test_hello_address[1].peer = p[1].id;
298 test_hello_address[1].transport_name = test_addr[1].plugin;
299 test_hello_address[1].address = test_addr[1].addr;
300 test_hello_address[1].address_length = test_addr[1].addr_len;
301 GNUNET_ATS_address_add (sched_ats, &test_hello_address[1], test_session[1], test_ats_info, test_ats_count);
302 }
303 if (1 == stage)
253 { 304 {
254 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggested WAN outbound quota %u bigger than allowed quota %llu \n", 305 /* Expecting callback for address[0] with updated quota and no callback for address[1]*/
255 (unsigned int) ntohl(bandwidth_out.value__), wan_quota_out); 306 if (GNUNET_OK == compare_addresses (address, session, &test_hello_address[0], test_session[0]))
256 ret = 1; 307 {
308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stage 1: Callback with correct address `%s'\n",
309 GNUNET_i2s (&address->peer));
310 ret = 0;
311 }
312 else
313 {
314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stage 1: Callback with invalid address `%s'\n",
315 GNUNET_i2s (&address->peer));
316 ret = 1;
317 }
318
319 if (GNUNET_OK != compare_ats(atsi, ats_count, test_ats_info, test_ats_count))
320 {
321 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage 1: Callback with incorrect ats info \n");
322 ret = 1;
323 }
324
325 if (bw_in > wan_quota_in)
326 {
327 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggested WAN inbound quota %u bigger than allowed quota %llu \n",
328 bw_in, wan_quota_in);
329 ret = 1;
330 }
331 else if (p[0].bw_in_assigned > bw_in)
332 {
333 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggested WAN inbound quota %u bigger than last quota %llu \n",
334 bw_in, p[0].bw_in_assigned);
335 ret = 1;
336 }
337 else
338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suggested WAN inbound quota %u, allowed quota %llu \n",
339 bw_in, wan_quota_in);
340
341 if (bw_out > wan_quota_out)
342 {
343 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggested WAN outbound quota %u bigger than allowed quota %llu \n",
344 bw_out, wan_quota_out);
345 ret = 1;
346 }
347 else if (p[0].bw_out_assigned > bw_out)
348 {
349 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggested WAN inbound quota %u bigger than last quota %llu \n",
350 bw_out, p[0].bw_out_assigned);
351 ret = 1;
352 }
353 else
354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suggested WAN outbound quota %u, allowed quota %llu \n",
355 bw_out, wan_quota_out);
356
357 if (1 == ret)
358 {
359 GNUNET_ATS_suggest_address_cancel (sched_ats, &p[1].id);
360 GNUNET_SCHEDULER_add_now (&end, NULL);
361 return;
362 }
363 stage ++;
364
365 GNUNET_ATS_suggest_address_cancel (sched_ats, &p[1].id);
366 GNUNET_SCHEDULER_add_now (&end, NULL);
367 return;
257 } 368 }
258 else
259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suggested WAN outbound quota %u, allowed quota %llu \n",
260 (unsigned int) ntohl(bandwidth_out.value__), wan_quota_out);
261
262
263
264 369
265 GNUNET_ATS_suggest_address_cancel (sched_ats, &p.id);
266 GNUNET_SCHEDULER_add_now (&end, NULL);
267} 370}
268 371
269static void 372static void
@@ -320,8 +423,22 @@ run (void *cls,
320 return; 423 return;
321 } 424 }
322 425
323 /* Set up peer */ 426 /* Set up peer 0 */
324 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID, &p.id.hashPubKey)) 427 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p[0].id.hashPubKey))
428 {
429 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n");
430 ret = GNUNET_SYSERR;
431 end ();
432 return;
433 }
434
435 GNUNET_assert (0 == strcmp (PEERID0, GNUNET_i2s_full (&p[0].id)));
436
437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
438 GNUNET_i2s(&p[0].id));
439
440 /* Set up peer 1*/
441 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID1, &p[1].id.hashPubKey))
325 { 442 {
326 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); 443 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n");
327 ret = GNUNET_SYSERR; 444 ret = GNUNET_SYSERR;
@@ -329,10 +446,10 @@ run (void *cls,
329 return; 446 return;
330 } 447 }
331 448
332 GNUNET_assert (0 == strcmp (PEERID, GNUNET_i2s_full (&p.id))); 449 GNUNET_assert (0 == strcmp (PEERID1, GNUNET_i2s_full (&p[1].id)));
333 450
334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", 451 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
335 GNUNET_i2s(&p.id)); 452 GNUNET_i2s(&p[1].id));
336 453
337 /* Prepare ATS Information */ 454 /* Prepare ATS Information */
338 test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); 455 test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
@@ -341,16 +458,16 @@ run (void *cls,
341 test_ats_info[1].value = htonl(1); 458 test_ats_info[1].value = htonl(1);
342 test_ats_count = 2; 459 test_ats_count = 2;
343 460
344 /* Adding address without session */ 461 /* Adding address with session */
345 test_session[0] = &test_addr[0]; 462 test_session[0] = &test_addr[0];
346 create_test_address (&test_addr[0], "test", test_session, "test", strlen ("test") + 1); 463 create_test_address (&test_addr[0], "test0", test_session[0], "test0", strlen ("test0") + 1);
347 test_hello_address[0].peer = p.id; 464 test_hello_address[0].peer = p[0].id;
348 test_hello_address[0].transport_name = test_addr[0].plugin; 465 test_hello_address[0].transport_name = test_addr[0].plugin;
349 test_hello_address[0].address = test_addr[0].addr; 466 test_hello_address[0].address = test_addr[0].addr;
350 test_hello_address[0].address_length = test_addr[0].addr_len; 467 test_hello_address[0].address_length = test_addr[0].addr_len;
351 GNUNET_ATS_address_add (sched_ats, &test_hello_address[0], test_session[0], test_ats_info, test_ats_count); 468 GNUNET_ATS_address_add (sched_ats, &test_hello_address[0], test_session[0], test_ats_info, test_ats_count);
352 469
353 GNUNET_ATS_suggest_address (sched_ats, &p.id); 470 GNUNET_ATS_suggest_address (sched_ats, &p[0].id);
354} 471}
355 472
356 473