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;
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);
86 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
87 if (die_task != GNUNET_SCHEDULER_NO_TASK)
89 GNUNET_SCHEDULER_cancel (die_task);
90 die_task = GNUNET_SCHEDULER_NO_TASK;
92 GNUNET_ATS_scheduling_done (sched_ats);
94 free_test_address (&test_addr);
99 address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
100 struct Session *session,
101 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
102 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
103 const struct GNUNET_ATS_Information *atsi,
106 static int stage = 0;
109 GNUNET_ATS_suggest_address_cancel (sched_ats, &p[0].id);
112 /* Prepare ATS Information */
114 test_ats_info[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
115 test_ats_info[0].value = htonl(20);
118 GNUNET_ATS_address_update (sched_ats, &test_hello_address[0], NULL, test_ats_info, test_ats_count);
120 test_ats_info[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
121 test_ats_info[0].value = htonl(20);
124 GNUNET_ATS_address_update (sched_ats, &test_hello_address[0], NULL, test_ats_info, test_ats_count);
127 /* Request address */
134 const struct GNUNET_CONFIGURATION_Handle *cfg,
135 struct GNUNET_TESTING_Peer *peer)
137 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
139 /* Connect to ATS scheduling */
140 sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
141 if (sched_ats == NULL)
143 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n");
150 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p[0].id.hashPubKey))
152 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n");
158 GNUNET_assert (0 == strcmp (PEERID0, GNUNET_i2s_full (&p[0].id)));
160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
161 GNUNET_i2s_full(&p[0].id));
164 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID1, &p[1].id.hashPubKey))
166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n");
172 GNUNET_assert (0 == strcmp (PEERID1, GNUNET_i2s_full (&p[1].id)));
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
175 GNUNET_i2s_full(&p[1].id));
179 /* Adding address for peer 0 */
180 create_test_address (&test_addr, "test", &test_addr, "test", strlen ("test") + 1);
181 /* Prepare ATS Information */
182 test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
183 test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN);
184 test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
185 test_ats_info[1].value = htonl(30);
188 test_hello_address[0].peer = p[0].id;
189 test_hello_address[0].transport_name = test_addr.plugin;
190 test_hello_address[0].address = test_addr.addr;
191 test_hello_address[0].address_length = test_addr.addr_len;
192 GNUNET_ATS_address_add (sched_ats, &test_hello_address[0], NULL, test_ats_info, test_ats_count);
194 /* Adding address for peer 1 */
195 create_test_address (&test_addr, "test", &test_addr, "test", strlen ("test") + 1);
196 test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
197 test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN);
198 test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
199 test_ats_info[1].value = htonl(10);
202 test_hello_address[1].peer = p[1].id;
203 test_hello_address[1].transport_name = test_addr.plugin;
204 test_hello_address[1].address = test_addr.addr;
205 test_hello_address[1].address_length = test_addr.addr_len;
206 GNUNET_ATS_address_add (sched_ats, &test_hello_address[1], NULL, test_ats_info, test_ats_count);
208 /* Adding 2nd address for peer 1 */
209 test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
210 test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN);
211 test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
212 test_ats_info[1].value = htonl(20);
215 test_hello_address[2].peer = p[1].id;
216 test_hello_address[2].transport_name = test_addr.plugin;
217 test_hello_address[2].address = test_addr.addr;
218 test_hello_address[2].address_length = test_addr.addr_len;
219 GNUNET_ATS_address_add (sched_ats, &test_hello_address[3], NULL, test_ats_info, test_ats_count);
221 /* Request address */
222 GNUNET_ATS_suggest_address (sched_ats, &p[0].id);
227 main (int argc, char *argv[])
229 if (0 != GNUNET_TESTING_peer_run ("test_ats_normalization_update_quality",
236 /* end of file test_ats_normalization_update_quality.c*/