diff options
Diffstat (limited to 'src/ats/test_ats_solver_add_address.c')
-rw-r--r-- | src/ats/test_ats_solver_add_address.c | 265 |
1 files changed, 0 insertions, 265 deletions
diff --git a/src/ats/test_ats_solver_add_address.c b/src/ats/test_ats_solver_add_address.c deleted file mode 100644 index b2f0eacd2..000000000 --- a/src/ats/test_ats_solver_add_address.c +++ /dev/null | |||
@@ -1,265 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010-2013 Christian Grothoff (and other contributing authors) | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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. | ||
19 | */ | ||
20 | /** | ||
21 | * @file ats/test_ats_solver_add_address.c | ||
22 | * @brief solver test: add address | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_testbed_service.h" | ||
29 | #include "gnunet_ats_service.h" | ||
30 | #include "test_ats_api_common.h" | ||
31 | |||
32 | /** | ||
33 | * Timeout task | ||
34 | */ | ||
35 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
36 | |||
37 | /** | ||
38 | * Statistics handle | ||
39 | */ | ||
40 | static struct GNUNET_STATISTICS_Handle *stats; | ||
41 | |||
42 | /** | ||
43 | * Scheduling handle | ||
44 | */ | ||
45 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
46 | |||
47 | /** | ||
48 | * Return value | ||
49 | */ | ||
50 | static int ret; | ||
51 | |||
52 | /** | ||
53 | * Test address | ||
54 | */ | ||
55 | static struct Test_Address test_addr; | ||
56 | |||
57 | /** | ||
58 | * Test peer | ||
59 | */ | ||
60 | static struct PeerContext p; | ||
61 | |||
62 | /** | ||
63 | * HELLO address | ||
64 | */ | ||
65 | static struct GNUNET_HELLO_Address test_hello_address; | ||
66 | |||
67 | /** | ||
68 | * Session | ||
69 | */ | ||
70 | static void *test_session; | ||
71 | |||
72 | /** | ||
73 | * Test ats info | ||
74 | */ | ||
75 | static struct GNUNET_ATS_Information test_ats_info[2]; | ||
76 | |||
77 | /** | ||
78 | * Test ats count | ||
79 | */ | ||
80 | static uint32_t test_ats_count; | ||
81 | |||
82 | |||
83 | static int | ||
84 | stat_cb (void *cls, | ||
85 | const char *subsystem, | ||
86 | const char *name, | ||
87 | uint64_t value, | ||
88 | int is_persistent); | ||
89 | |||
90 | |||
91 | static void | ||
92 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
93 | { | ||
94 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n"); | ||
95 | |||
96 | if (NULL != die_task) | ||
97 | { | ||
98 | GNUNET_SCHEDULER_cancel (die_task); | ||
99 | die_task = NULL; | ||
100 | } | ||
101 | |||
102 | if (NULL != sched_ats) | ||
103 | { | ||
104 | GNUNET_ATS_scheduling_done (sched_ats); | ||
105 | sched_ats = NULL; | ||
106 | } | ||
107 | |||
108 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
109 | if (NULL != stats) | ||
110 | { | ||
111 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
112 | stats = NULL; | ||
113 | } | ||
114 | free_test_address (&test_addr); | ||
115 | ret = 0; | ||
116 | } | ||
117 | |||
118 | |||
119 | static void | ||
120 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
121 | { | ||
122 | die_task = NULL; | ||
123 | end ( NULL, NULL); | ||
124 | ret = GNUNET_SYSERR; | ||
125 | } | ||
126 | |||
127 | |||
128 | static void | ||
129 | address_suggest_cb (void *cls, | ||
130 | const struct GNUNET_PeerIdentity *peer, | ||
131 | const struct GNUNET_HELLO_Address *address, | ||
132 | struct Session *session, | ||
133 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
134 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
135 | { | ||
136 | /* ignored in this test */ | ||
137 | } | ||
138 | |||
139 | |||
140 | static int | ||
141 | stat_cb (void *cls, | ||
142 | const char *subsystem, | ||
143 | const char *name, | ||
144 | uint64_t value, | ||
145 | int is_persistent) | ||
146 | { | ||
147 | |||
148 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
149 | "ATS statistics: `%s' `%s' %llu\n", | ||
150 | subsystem, | ||
151 | name, | ||
152 | value); | ||
153 | if (1 == value) | ||
154 | { | ||
155 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
156 | } | ||
157 | return GNUNET_OK; | ||
158 | } | ||
159 | |||
160 | |||
161 | static void | ||
162 | run (void *cls, | ||
163 | const struct GNUNET_CONFIGURATION_Handle *mycfg, | ||
164 | struct GNUNET_TESTING_Peer *peer) | ||
165 | { | ||
166 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
167 | stats = GNUNET_STATISTICS_create ("ats", mycfg); | ||
168 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
169 | |||
170 | |||
171 | /* Connect to ATS scheduling */ | ||
172 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); | ||
173 | if (NULL == sched_ats) | ||
174 | { | ||
175 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
176 | "Could not connect to ATS scheduling!\n"); | ||
177 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
178 | return; | ||
179 | } | ||
180 | |||
181 | /* Set up peer */ | ||
182 | memset (&p.id, '1', sizeof (p.id)); | ||
183 | |||
184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", | ||
185 | GNUNET_i2s_full(&p.id)); | ||
186 | |||
187 | /* Prepare ATS Information */ | ||
188 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
189 | test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); | ||
190 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
191 | test_ats_info[1].value = htonl(1); | ||
192 | test_ats_count = 2; | ||
193 | |||
194 | /* Adding address without session */ | ||
195 | test_session = NULL; | ||
196 | create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); | ||
197 | test_hello_address.peer = p.id; | ||
198 | test_hello_address.transport_name = test_addr.plugin; | ||
199 | test_hello_address.address = test_addr.addr; | ||
200 | test_hello_address.address_length = test_addr.addr_len; | ||
201 | |||
202 | /* Adding address */ | ||
203 | GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, test_ats_info, test_ats_count); | ||
204 | } | ||
205 | |||
206 | |||
207 | int | ||
208 | main (int argc, char *argv[]) | ||
209 | { | ||
210 | char *sep; | ||
211 | char *src_filename = GNUNET_strdup (__FILE__); | ||
212 | char *test_filename = GNUNET_strdup (argv[0]); | ||
213 | char *config_file; | ||
214 | char *solver; | ||
215 | |||
216 | ret = 0; | ||
217 | |||
218 | if (NULL == (sep = (strstr (src_filename,".c")))) | ||
219 | { | ||
220 | GNUNET_break (0); | ||
221 | return -1; | ||
222 | } | ||
223 | sep[0] = '\0'; | ||
224 | |||
225 | if (NULL != (sep = strstr (test_filename, ".exe"))) | ||
226 | sep[0] = '\0'; | ||
227 | |||
228 | if (NULL == (solver = strstr (test_filename, src_filename))) | ||
229 | { | ||
230 | GNUNET_break (0); | ||
231 | return -1; | ||
232 | } | ||
233 | solver += strlen (src_filename) +1; | ||
234 | |||
235 | if (0 == strcmp(solver, "proportional")) | ||
236 | { | ||
237 | config_file = "test_ats_solver_proportional.conf"; | ||
238 | } | ||
239 | else if (0 == strcmp(solver, "mlp")) | ||
240 | { | ||
241 | config_file = "test_ats_solver_mlp.conf"; | ||
242 | } | ||
243 | else if ((0 == strcmp(solver, "ril"))) | ||
244 | { | ||
245 | config_file = "test_ats_solver_ril.conf"; | ||
246 | } | ||
247 | else | ||
248 | { | ||
249 | GNUNET_break (0); | ||
250 | GNUNET_free (src_filename); | ||
251 | GNUNET_free (test_filename); | ||
252 | return 1; | ||
253 | } | ||
254 | |||
255 | GNUNET_free (src_filename); | ||
256 | GNUNET_free (test_filename); | ||
257 | |||
258 | if (0 != GNUNET_TESTING_peer_run ("test-ats-solver", | ||
259 | config_file, &run, NULL )) | ||
260 | return GNUNET_SYSERR; | ||
261 | |||
262 | return ret; | ||
263 | } | ||
264 | |||
265 | /* end of file test_ats_solver_add_address.c */ | ||