2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file ats/test_ats_normalization_update_quality.c
22 * @brief test updating an address
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_ats_service.h"
28 #include "gnunet_testing_lib.h"
30 #include "test_ats_api_common.h"
32 static GNUNET_SCHEDULER_TaskIdentifier die_task;
37 static struct GNUNET_ATS_SchedulingHandle *sched_ats;
47 static struct Test_Address test_addr[3];
52 static struct PeerContext p[2];
58 struct GNUNET_HELLO_Address test_hello_address[3];
63 struct GNUNET_ATS_Information test_ats_info[3];
68 uint32_t test_ats_count;
72 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
74 die_task = GNUNET_SCHEDULER_NO_TASK;
76 if (sched_ats != NULL)
77 GNUNET_ATS_scheduling_done (sched_ats);
78 free_test_address (&test_addr[0]);
79 free_test_address (&test_addr[1]);
80 free_test_address (&test_addr[2]);
88 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
89 if (die_task != GNUNET_SCHEDULER_NO_TASK)
91 GNUNET_SCHEDULER_cancel (die_task);
92 die_task = GNUNET_SCHEDULER_NO_TASK;
94 GNUNET_ATS_scheduling_done (sched_ats);
96 free_test_address (&test_addr[0]);
97 free_test_address (&test_addr[1]);
98 free_test_address (&test_addr[2]);
103 address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
104 struct Session *session,
105 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
106 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
107 const struct GNUNET_ATS_Information *atsi,
110 static int stage = 0;
113 GNUNET_ATS_suggest_address_cancel (sched_ats, &p[0].id);
116 /* Prepare ATS Information */
118 test_ats_info[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
119 test_ats_info[0].value = htonl(20);
122 GNUNET_ATS_address_update (sched_ats, &test_hello_address[0], NULL, test_ats_info, test_ats_count);
124 test_ats_info[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
125 test_ats_info[0].value = htonl(20);
128 GNUNET_ATS_address_update (sched_ats, &test_hello_address[0], NULL, test_ats_info, test_ats_count);
131 /* Request address */
138 const struct GNUNET_CONFIGURATION_Handle *cfg,
139 struct GNUNET_TESTING_Peer *peer)
141 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
143 /* Connect to ATS scheduling */
144 sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
145 if (sched_ats == NULL)
147 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n");
154 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p[0].id.hashPubKey))
156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n");
162 GNUNET_assert (0 == strcmp (PEERID0, GNUNET_i2s_full (&p[0].id)));
164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
165 GNUNET_i2s_full(&p[0].id));
168 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID1, &p[1].id.hashPubKey))
170 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n");
176 GNUNET_assert (0 == strcmp (PEERID1, GNUNET_i2s_full (&p[1].id)));
178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
179 GNUNET_i2s_full(&p[1].id));
183 /* Adding address for peer 0 */
184 create_test_address (&test_addr[0], "test", &test_addr, "test_p0_a0", strlen ("test_p0_a0") + 1);
185 /* Prepare ATS Information */
186 test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
187 test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN);
188 test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
189 test_ats_info[1].value = htonl(30);
192 test_hello_address[0].peer = p[0].id;
193 test_hello_address[0].transport_name = test_addr[0].plugin;
194 test_hello_address[0].address = test_addr[0].addr;
195 test_hello_address[0].address_length = test_addr[0].addr_len;
196 GNUNET_ATS_address_add (sched_ats, &test_hello_address[0], NULL, test_ats_info, test_ats_count);
198 /* Adding address for peer 1 */
199 create_test_address (&test_addr[1], "test", &test_addr, "test_p1_a0", strlen ("test_p1_a0") + 1);
200 test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
201 test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN);
202 test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
203 test_ats_info[1].value = htonl(10);
206 test_hello_address[1].peer = p[1].id;
207 test_hello_address[1].transport_name = test_addr[1].plugin;
208 test_hello_address[1].address = test_addr[1].addr;
209 test_hello_address[1].address_length = test_addr[1].addr_len;
210 GNUNET_ATS_address_add (sched_ats, &test_hello_address[1], NULL, test_ats_info, test_ats_count);
212 /* Adding 2nd address for peer 1 */
213 test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
214 test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN);
215 test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
216 test_ats_info[1].value = htonl(20);
219 create_test_address (&test_addr[2], "test", &test_addr, "test_p1_a1", strlen ("test_p1_a1") + 1);
220 test_hello_address[2].peer = p[1].id;
221 test_hello_address[2].transport_name = test_addr[2].plugin;
222 test_hello_address[2].address = test_addr[2].addr;
223 test_hello_address[2].address_length = test_addr[2].addr_len;
224 GNUNET_ATS_address_add (sched_ats, &test_hello_address[2], NULL, test_ats_info, test_ats_count);
226 /* Request address */
227 GNUNET_ATS_suggest_address (sched_ats, &p[0].id);
232 main (int argc, char *argv[])
234 if (0 != GNUNET_TESTING_peer_run ("test_ats_normalization_update_quality",
241 /* end of file test_ats_normalization_update_quality.c*/