diff options
author | wachs <wachs@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-12-06 13:16:17 +0000 |
---|---|---|
committer | wachs <wachs@140774ce-b5e7-0310-ab8b-a85725594a96> | 2012-12-06 13:16:17 +0000 |
commit | 0829bf8fde5e50c35c4f86a3672817619ed6a61b (patch) | |
tree | 2699c67ea55cc3964670e49e60dae24feea04ac1 /src/ats | |
parent | 6329cce487a5fa3d536b0f2466f2cb548abf6289 (diff) |
ats info
git-svn-id: https://gnunet.org/svn/gnunet@25293 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/test_ats_api_scheduling_add_address.c | 74 | ||||
-rw-r--r-- | src/ats/test_ats_api_scheduling_update_address.c | 76 |
2 files changed, 145 insertions, 5 deletions
diff --git a/src/ats/test_ats_api_scheduling_add_address.c b/src/ats/test_ats_api_scheduling_add_address.c index ce69cad4f1..2083293c57 100644 --- a/src/ats/test_ats_api_scheduling_add_address.c +++ b/src/ats/test_ats_api_scheduling_add_address.c @@ -61,6 +61,16 @@ struct GNUNET_HELLO_Address test_hello_address; */ static void *test_session; +/** + * Test ats info + */ +struct GNUNET_ATS_Information test_ats_info[2]; + +/** + * Test ats count + */ +uint32_t test_ats_count; + static void create_test_address (struct Test_Address *dest, char * plugin, void *session, void *addr, size_t addrlen) @@ -141,6 +151,51 @@ compare_addresses (const struct GNUNET_HELLO_Address *address1, void *session1, return GNUNET_OK; } + +static int +compare_ats (const struct GNUNET_ATS_Information *ats_is, uint32_t ats_count_is, + const struct GNUNET_ATS_Information *ats_should, uint32_t ats_count_should) +{ + unsigned int c_o; + unsigned int c_i; + char *prop[] = GNUNET_ATS_PropertyStrings; + uint32_t type1; + uint32_t type2; + uint32_t val1; + uint32_t val2; + int res = GNUNET_OK; + + for (c_o = 0; c_o < ats_count_is; c_o++) + { + for (c_i = 0; c_i < ats_count_should; c_i++) + { + type1 = ntohl(ats_is[c_o].type); + type2 = ntohl(ats_should[c_i].type); + if (type1 == type2) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS type `%s'\n", + prop[type1]); + val1 = ntohl(ats_is[c_o].value); + val2 = ntohl(ats_should[c_i].value); + if (val1 != val2) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ATS value `%s' not equal: %u != %u\n", + prop[type1], + val1, val2); + res = GNUNET_SYSERR; + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS value `%s' equal: %u == %u\n", + prop[type1], + val1, val2); + } + } + } + } + return res; +} + static void address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, struct Session *session, @@ -151,16 +206,23 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, { if (GNUNET_OK == compare_addresses (address, session, &test_hello_address, test_session)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback with correct address `%s'\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stage 0: Callback with correct address `%s'\n", GNUNET_i2s (&address->peer)); ret = 0; } else { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback with invalid address `%s'\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stage 0: Callback with invalid address `%s'\n", GNUNET_i2s (&address->peer)); ret = 1; } + + if (GNUNET_OK != compare_ats(atsi, ats_count, test_ats_info, test_ats_count)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage 0: Callback with incorrect ats info \n"); + ret = 1; + } + GNUNET_ATS_suggest_address_cancel (sched_ats, &p.id); GNUNET_SCHEDULER_add_now (&end, NULL); } @@ -197,6 +259,12 @@ run (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s_full(&p.id)); + /* 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_DISTANCE); + test_ats_info[1].value = htonl(1); + test_ats_count = 2; /* Adding address without session */ test_session = &test_addr; @@ -205,7 +273,7 @@ run (void *cls, test_hello_address.transport_name = test_addr.plugin; test_hello_address.address = test_addr.addr; test_hello_address.address_length = test_addr.addr_len; - GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, NULL, 0); + GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, test_ats_info, test_ats_count); GNUNET_ATS_suggest_address (sched_ats, &p.id); } diff --git a/src/ats/test_ats_api_scheduling_update_address.c b/src/ats/test_ats_api_scheduling_update_address.c index ce2bf40ee5..ace4cc86e3 100644 --- a/src/ats/test_ats_api_scheduling_update_address.c +++ b/src/ats/test_ats_api_scheduling_update_address.c @@ -63,6 +63,17 @@ struct GNUNET_HELLO_Address test_hello_address; */ static void *test_session; +/** + * Test ats info + */ +struct GNUNET_ATS_Information test_ats_info[2]; + +/** + * Test ats count + */ +uint32_t test_ats_count; + + static void create_test_address (struct Test_Address *dest, char * plugin, void *session, void *addr, size_t addrlen) { @@ -143,6 +154,50 @@ compare_addresses (const struct GNUNET_HELLO_Address *address1, void *session1, return GNUNET_OK; } +static int +compare_ats (const struct GNUNET_ATS_Information *ats_is, uint32_t ats_count_is, + const struct GNUNET_ATS_Information *ats_should, uint32_t ats_count_should) +{ + unsigned int c_o; + unsigned int c_i; + char *prop[] = GNUNET_ATS_PropertyStrings; + uint32_t type1; + uint32_t type2; + uint32_t val1; + uint32_t val2; + int res = GNUNET_OK; + + for (c_o = 0; c_o < ats_count_is; c_o++) + { + for (c_i = 0; c_i < ats_count_should; c_i++) + { + type1 = ntohl(ats_is[c_o].type); + type2 = ntohl(ats_should[c_i].type); + if (type1 == type2) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS type `%s'\n", + prop[type1]); + val1 = ntohl(ats_is[c_o].value); + val2 = ntohl(ats_should[c_i].value); + if (val1 != val2) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ATS value `%s' not equal: %u != %u\n", + prop[type1], + val1, val2); + res = GNUNET_SYSERR; + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS value `%s' equal: %u == %u\n", + prop[type1], + val1, val2); + } + } + } + } + return res; +} + static void address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, struct Session *session, @@ -163,6 +218,16 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, } else { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage 0: Callback with incorrect address `%s'\n", + GNUNET_i2s (&address->peer)); + ret = 1; + GNUNET_SCHEDULER_add_now (&end, NULL); + return; + } + + if (GNUNET_OK != compare_ats(atsi, ats_count, test_ats_info, test_ats_count)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage 0: Callback with incorrect ats info \n"); ret = 1; GNUNET_SCHEDULER_add_now (&end, NULL); return; @@ -185,7 +250,7 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, } else { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stage 1: Callback with incorrect address `%s'\n", + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage 1: Callback with incorrect address `%s'\n", GNUNET_i2s (&address->peer)); ret = 1; } @@ -225,6 +290,13 @@ run (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s_full(&p.id)); + /* 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_DISTANCE); + test_ats_info[1].value = htonl(1); + test_ats_count = 2; + /* Adding address without session */ test_session = &test_addr; create_test_address (&test_addr, "test", &test_addr, "test", strlen ("test") + 1); @@ -232,7 +304,7 @@ run (void *cls, test_hello_address.transport_name = test_addr.plugin; test_hello_address.address = test_addr.addr; test_hello_address.address_length = test_addr.addr_len; - GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, NULL, 0); + GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, test_ats_info, test_ats_count); /* Request address */ GNUNET_ATS_suggest_address (sched_ats, &p.id); |