diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-11 16:17:20 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-11 16:17:20 +0000 |
commit | 8af9412585b17289e8fa5ca905eaa33415927dc3 (patch) | |
tree | f4cc0ed3a8b745a04832157a173a9eefc8f28e89 /src | |
parent | 567ca9a20a7afe3573cb1c11ad89c116a0650fe7 (diff) | |
download | gnunet-8af9412585b17289e8fa5ca905eaa33415927dc3.tar.gz gnunet-8af9412585b17289e8fa5ca905eaa33415927dc3.zip |
new testsuite, obsoleting (most of) the old one
Diffstat (limited to 'src')
29 files changed, 1833 insertions, 6312 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index 2a14ae73f..63917b907 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am | |||
@@ -18,23 +18,6 @@ if USE_COVERAGE | |||
18 | AM_CFLAGS = -fprofile-arcs -ftest-coverage | 18 | AM_CFLAGS = -fprofile-arcs -ftest-coverage |
19 | endif | 19 | endif |
20 | 20 | ||
21 | #noinst_PROGRAMS = \ | ||
22 | # gnunet-ats-solver-eval | ||
23 | |||
24 | if HAVE_LIBGLPK | ||
25 | GN_LIBGLPK = -lglpk | ||
26 | GN_MLP_LIB = libgnunet_plugin_ats_mlp.la | ||
27 | GN_MLP_PERF = perf_ats_mlp | ||
28 | GN_MLP_ADD_ADDRESS = test_ats_solver_add_address_mlp | ||
29 | GN_MLP_ADD_REQUEST_ADDRESS = test_ats_solver_add_address_and_request_mlp | ||
30 | GN_MLP_ADD_REQUEST_ADDRESS_DELAYED = test_ats_solver_add_address_and_request_delayed_mlp | ||
31 | GN_MLP_REQUEST_ADD_ADDRESS = test_ats_solver_request_and_add_address_mlp | ||
32 | GN_MLP_REQUEST_DELETE_ADDRESS = test_ats_solver_request_and_delete_address_mlp | ||
33 | GN_MLP_PREFERENCES_ADDRESS = test_ats_solver_preferences_mlp | ||
34 | GN_MLP_ALTERNATIVE_DELETE_ADDRESS = test_ats_solver_alternative_after_delete_address_mlp | ||
35 | GN_MLP_SOLVER_PERF = perf_ats_solver_mlp | ||
36 | endif | ||
37 | |||
38 | lib_LTLIBRARIES = libgnunetats.la | 21 | lib_LTLIBRARIES = libgnunetats.la |
39 | 22 | ||
40 | plugin_LTLIBRARIES = \ | 23 | plugin_LTLIBRARIES = \ |
@@ -42,21 +25,10 @@ plugin_LTLIBRARIES = \ | |||
42 | $(GN_MLP_LIB) \ | 25 | $(GN_MLP_LIB) \ |
43 | libgnunet_plugin_ats_ril.la | 26 | libgnunet_plugin_ats_ril.la |
44 | 27 | ||
45 | #gnunet_ats_solver_eval_SOURCES = \ | 28 | if HAVE_LIBGLPK |
46 | # gnunet-ats-solver-eval.c gnunet-ats-solver-eval.h \ | 29 | plugin_LTLIBRARIES += \ |
47 | # gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ | 30 | libgnunet_plugin_ats_mlp.la |
48 | # gnunet-service-ats_plugins.c gnunet-service-ats_plugins.h \ | 31 | endif |
49 | # gnunet-service-ats_connectivity.c gnunet-service-ats_connectivity.h \ | ||
50 | # gnunet-service-ats_feedback.c gnunet-service-ats_feedback.h \ | ||
51 | # gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ | ||
52 | # gnunet-service-ats_reservations.c gnunet-service-ats_reservations.h \ | ||
53 | # gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \ | ||
54 | # gnunet-service-ats_normalization.c | ||
55 | #gnunet_ats_solver_eval_LDADD = \ | ||
56 | # $(top_builddir)/src/util/libgnunetutil.la \ | ||
57 | # libgnunetats.la \ | ||
58 | # $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
59 | # $(LTLIBINTL) | ||
60 | 32 | ||
61 | libgnunetats_la_SOURCES = \ | 33 | libgnunetats_la_SOURCES = \ |
62 | ats_api_connectivity.c \ | 34 | ats_api_connectivity.c \ |
@@ -90,7 +62,8 @@ libgnunet_plugin_ats_mlp_la_LIBADD = \ | |||
90 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 62 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
91 | $(top_builddir)/src/util/libgnunetutil.la | 63 | $(top_builddir)/src/util/libgnunetutil.la |
92 | libgnunet_plugin_ats_mlp_la_LDFLAGS = \ | 64 | libgnunet_plugin_ats_mlp_la_LDFLAGS = \ |
93 | $(GN_PLUGIN_LDFLAGS) $(GN_LIBGLPK) | 65 | $(GN_PLUGIN_LDFLAGS) \ |
66 | -lglpk | ||
94 | endif | 67 | endif |
95 | 68 | ||
96 | libgnunet_plugin_ats_ril_la_SOURCES = \ | 69 | libgnunet_plugin_ats_ril_la_SOURCES = \ |
@@ -107,7 +80,7 @@ libexec_PROGRAMS = \ | |||
107 | gnunet-service-ats | 80 | gnunet-service-ats |
108 | 81 | ||
109 | gnunet_service_ats_SOURCES = \ | 82 | gnunet_service_ats_SOURCES = \ |
110 | gnunet-service-ats.c gnunet-service-ats.h\ | 83 | gnunet-service-ats.c gnunet-service-ats.h \ |
111 | gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ | 84 | gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ |
112 | gnunet-service-ats_connectivity.c gnunet-service-ats_connectivity.h \ | 85 | gnunet-service-ats_connectivity.c gnunet-service-ats_connectivity.h \ |
113 | gnunet-service-ats_feedback.c gnunet-service-ats_feedback.h \ | 86 | gnunet-service-ats_feedback.c gnunet-service-ats_feedback.h \ |
@@ -125,44 +98,12 @@ gnunet_service_ats_LDADD = \ | |||
125 | 98 | ||
126 | if HAVE_TESTING | 99 | if HAVE_TESTING |
127 | TESTING_TESTS = \ | 100 | TESTING_TESTS = \ |
128 | test_ats_api_scheduling_init \ | 101 | test_ats_api_proportional \ |
129 | test_ats_api_scheduling_add_address \ | 102 | test_ats_api_ril |
130 | test_ats_api_scheduling_add_address_duplicate \ | 103 | if HAVE_LIBGLPK |
131 | test_ats_api_scheduling_add_address_inbound \ | 104 | TESTING_TESTS += \ |
132 | test_ats_api_scheduling_destroy_address \ | 105 | test_ats_api_mlp |
133 | test_ats_api_scheduling_add_session \ | 106 | endif |
134 | test_ats_api_delayed_service_scheduling_add_address \ | ||
135 | test_ats_api_performance_list_all_addresses \ | ||
136 | test_ats_api_delayed_service_performance_list_all_addresses \ | ||
137 | test_ats_api_performance_list_peer_addresses \ | ||
138 | test_ats_api_performance_list_all_addresses_active \ | ||
139 | test_ats_api_performance_monitor \ | ||
140 | test_ats_api_delayed_service_performance_monitor \ | ||
141 | test_ats_api_performance_monitor_initial_callback \ | ||
142 | test_ats_solver_add_address_proportional \ | ||
143 | test_ats_solver_add_address_and_request_proportional \ | ||
144 | test_ats_solver_add_address_and_request_delayed_proportional\ | ||
145 | test_ats_solver_request_and_add_address_proportional \ | ||
146 | test_ats_solver_request_and_delete_address_proportional \ | ||
147 | test_ats_solver_alternative_after_delete_address_proportional \ | ||
148 | test_ats_solver_preferences_proportional \ | ||
149 | test_ats_solver_preferences_ril \ | ||
150 | $(GN_MLP_ADD_ADDRESS) \ | ||
151 | $(GN_MLP_ADD_REQUEST_ADDRESS) \ | ||
152 | $(GN_MLP_ADD_REQUEST_ADDRESS_DELAYED) \ | ||
153 | $(GN_MLP_REQUEST_ADD_ADDRESS) \ | ||
154 | $(GN_MLP_REQUEST_DELETE_ADDRESS) \ | ||
155 | $(GN_MLP_ALTERNATIVE_DELETE_ADDRESS) \ | ||
156 | $(GN_MLP_PREFERENCES_ADDRESS) \ | ||
157 | test_ats_solver_add_address_ril \ | ||
158 | test_ats_solver_add_address_and_request_ril \ | ||
159 | test_ats_solver_add_address_and_request_delayed_ril \ | ||
160 | test_ats_solver_request_and_add_address_ril \ | ||
161 | test_ats_solver_request_and_delete_address_ril \ | ||
162 | test_ats_solver_alternative_after_delete_address_ril \ | ||
163 | perf_ats_solver_proportional \ | ||
164 | $(GN_MLP_SOLVER_PERF) \ | ||
165 | perf_ats_solver_ril | ||
166 | endif | 107 | endif |
167 | 108 | ||
168 | check_PROGRAMS = \ | 109 | check_PROGRAMS = \ |
@@ -173,438 +114,36 @@ AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PAT | |||
173 | TESTS = $(check_PROGRAMS) | 114 | TESTS = $(check_PROGRAMS) |
174 | endif | 115 | endif |
175 | 116 | ||
176 | # scheduling API tests | 117 | test_ats_api_proportional_SOURCES = \ |
177 | 118 | test_ats_api.c \ | |
178 | test_ats_api_scheduling_init_SOURCES = \ | 119 | test_ats_lib.c test_ats_lib.h |
179 | test_ats_api_scheduling_init.c \ | 120 | test_ats_api_proportional_LDADD = \ |
180 | test_ats_api_common.c test_ats_api_common.h | ||
181 | test_ats_api_scheduling_init_LDADD = \ | ||
182 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
183 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
184 | libgnunetats.la \ | ||
185 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
186 | |||
187 | test_ats_api_scheduling_add_address_SOURCES = \ | ||
188 | test_ats_api_scheduling_add_address.c \ | ||
189 | test_ats_api_common.c test_ats_api_common.h | ||
190 | test_ats_api_scheduling_add_address_LDADD = \ | ||
191 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
192 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
193 | libgnunetats.la \ | ||
194 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
195 | |||
196 | test_ats_api_delayed_service_scheduling_add_address_SOURCES = \ | ||
197 | test_ats_api_delayed_service_scheduling_add_address.c \ | ||
198 | test_ats_api_common.c test_ats_api_common.h | ||
199 | test_ats_api_delayed_service_scheduling_add_address_LDADD = \ | ||
200 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
201 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
202 | libgnunetats.la \ | ||
203 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
204 | |||
205 | test_ats_api_scheduling_add_address_inbound_SOURCES = \ | ||
206 | test_ats_api_scheduling_add_address_inbound.c \ | ||
207 | test_ats_api_common.c test_ats_api_common.h | ||
208 | test_ats_api_scheduling_add_address_inbound_LDADD = \ | ||
209 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
210 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
211 | libgnunetats.la \ | ||
212 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
213 | |||
214 | test_ats_api_scheduling_add_address_duplicate_SOURCES = \ | ||
215 | test_ats_api_scheduling_add_address_duplicate.c \ | ||
216 | test_ats_api_common.c test_ats_api_common.h | ||
217 | test_ats_api_scheduling_add_address_duplicate_LDADD = \ | ||
218 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
219 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
220 | libgnunetats.la \ | ||
221 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
222 | |||
223 | test_ats_api_scheduling_destroy_address_SOURCES = \ | ||
224 | test_ats_api_scheduling_destroy_address.c \ | ||
225 | test_ats_api_common.c test_ats_api_common.h | ||
226 | test_ats_api_scheduling_destroy_address_LDADD = \ | ||
227 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
228 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
229 | libgnunetats.la \ | ||
230 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
231 | |||
232 | test_ats_api_scheduling_add_session_SOURCES = \ | ||
233 | test_ats_api_scheduling_add_session.c test_ats_api_common.c | ||
234 | test_ats_api_scheduling_add_session_LDADD = \ | ||
235 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
236 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
237 | libgnunetats.la \ | ||
238 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
239 | |||
240 | # performance API tests | ||
241 | |||
242 | test_ats_api_performance_list_all_addresses_SOURCES = \ | ||
243 | test_ats_api_performance_list_all_addresses.c | ||
244 | test_ats_api_performance_list_all_addresses_LDADD = \ | ||
245 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
246 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
247 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
248 | libgnunetats.la \ | ||
249 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
250 | |||
251 | test_ats_api_delayed_service_performance_list_all_addresses_SOURCES = \ | ||
252 | test_ats_api_delayed_service_performance_list_all_addresses.c | ||
253 | test_ats_api_delayed_service_performance_list_all_addresses_LDADD = \ | ||
254 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
255 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
256 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
257 | libgnunetats.la \ | ||
258 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
259 | |||
260 | test_ats_api_performance_list_peer_addresses_SOURCES = \ | ||
261 | test_ats_api_performance_list_peer_addresses.c | ||
262 | test_ats_api_performance_list_peer_addresses_LDADD = \ | ||
263 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
264 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
265 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
266 | libgnunetats.la \ | ||
267 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
268 | |||
269 | test_ats_api_performance_list_all_addresses_active_SOURCES = \ | ||
270 | test_ats_api_performance_list_all_addresses_active.c | ||
271 | test_ats_api_performance_list_all_addresses_active_LDADD = \ | ||
272 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
273 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
274 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
275 | libgnunetats.la \ | ||
276 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
277 | |||
278 | test_ats_api_performance_monitor_SOURCES = \ | ||
279 | test_ats_api_performance_monitor.c | ||
280 | test_ats_api_performance_monitor_LDADD = \ | ||
281 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
282 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
283 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
284 | libgnunetats.la \ | ||
285 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
286 | |||
287 | test_ats_api_delayed_service_performance_monitor_SOURCES = \ | ||
288 | test_ats_api_delayed_service_performance_monitor.c | ||
289 | test_ats_api_delayed_service_performance_monitor_LDADD = \ | ||
290 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
291 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
292 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
293 | libgnunetats.la \ | ||
294 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
295 | |||
296 | |||
297 | |||
298 | test_ats_api_performance_monitor_initial_callback_SOURCES = \ | ||
299 | test_ats_api_performance_monitor_initial_callback.c | ||
300 | test_ats_api_performance_monitor_initial_callback_LDADD = \ | ||
301 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
302 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
303 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
304 | libgnunetats.la \ | ||
305 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
306 | |||
307 | # solver tests | ||
308 | test_ats_solver_add_address_proportional_SOURCES = \ | ||
309 | test_ats_solver_add_address.c \ | ||
310 | test_ats_api_common.c test_ats_api_common.h | ||
311 | test_ats_solver_add_address_proportional_LDADD = \ | ||
312 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
313 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
314 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
315 | libgnunetats.la \ | ||
316 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
317 | |||
318 | if HAVE_LIBGLPK | ||
319 | test_ats_solver_add_address_mlp_SOURCES = \ | ||
320 | test_ats_solver_add_address.c \ | ||
321 | test_ats_api_common.c test_ats_api_common.h | ||
322 | test_ats_solver_add_address_mlp_LDADD = \ | ||
323 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
324 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
325 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
326 | libgnunetats.la \ | ||
327 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
328 | endif | ||
329 | |||
330 | test_ats_solver_add_address_ril_SOURCES = \ | ||
331 | test_ats_solver_add_address.c \ | ||
332 | test_ats_api_common.c test_ats_api_common.h | ||
333 | test_ats_solver_add_address_ril_LDADD = \ | ||
334 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
335 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
336 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
337 | libgnunetats.la \ | ||
338 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
339 | |||
340 | test_ats_solver_add_address_and_request_proportional_SOURCES = \ | ||
341 | test_ats_solver_add_address_and_request.c \ | ||
342 | test_ats_api_common.c test_ats_api_common.h | ||
343 | test_ats_solver_add_address_and_request_proportional_LDADD = \ | ||
344 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
345 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
346 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
347 | libgnunetats.la \ | ||
348 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
349 | |||
350 | test_ats_solver_add_address_and_request_delayed_proportional_SOURCES = \ | ||
351 | test_ats_solver_add_address_and_request.c \ | ||
352 | test_ats_api_common.c test_ats_api_common.h | ||
353 | test_ats_solver_add_address_and_request_delayed_proportional_LDADD = \ | ||
354 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
355 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
356 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
357 | libgnunetats.la \ | ||
358 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
359 | |||
360 | test_ats_solver_add_address_and_request_delayed_ril_SOURCES = \ | ||
361 | test_ats_solver_add_address_and_request.c \ | ||
362 | test_ats_api_common.c test_ats_api_common.h | ||
363 | test_ats_solver_add_address_and_request_delayed_ril_LDADD = \ | ||
364 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
365 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
366 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
367 | libgnunetats.la \ | ||
368 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
369 | |||
370 | if HAVE_LIBGLPK | ||
371 | test_ats_solver_add_address_and_request_mlp_SOURCES = \ | ||
372 | test_ats_solver_add_address_and_request.c \ | ||
373 | test_ats_api_common.c test_ats_api_common.h | ||
374 | test_ats_solver_add_address_and_request_mlp_LDADD = \ | ||
375 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
376 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
377 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
378 | libgnunetats.la \ | ||
379 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
380 | endif | ||
381 | |||
382 | test_ats_solver_add_address_and_request_delayed_mlp_SOURCES = \ | ||
383 | test_ats_solver_add_address_and_request.c \ | ||
384 | test_ats_api_common.c test_ats_api_common.h | ||
385 | test_ats_solver_add_address_and_request_delayed_mlp_LDADD = \ | ||
386 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
387 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
388 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
389 | libgnunetats.la \ | ||
390 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
391 | |||
392 | test_ats_solver_add_address_and_request_ril_SOURCES = \ | ||
393 | test_ats_solver_add_address_and_request.c \ | ||
394 | test_ats_api_common.c test_ats_api_common.h | ||
395 | test_ats_solver_add_address_and_request_ril_LDADD = \ | ||
396 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
397 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
398 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
399 | libgnunetats.la \ | ||
400 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
401 | |||
402 | |||
403 | test_ats_solver_request_and_add_address_proportional_SOURCES = \ | ||
404 | test_ats_solver_request_and_add_address.c \ | ||
405 | test_ats_api_common.c test_ats_api_common.h | ||
406 | test_ats_solver_request_and_add_address_proportional_LDADD = \ | ||
407 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
408 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
409 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
410 | libgnunetats.la \ | ||
411 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
412 | |||
413 | if HAVE_LIBGLPK | ||
414 | test_ats_solver_request_and_add_address_mlp_SOURCES = \ | ||
415 | test_ats_solver_request_and_add_address.c \ | ||
416 | test_ats_api_common.c test_ats_api_common.h | ||
417 | test_ats_solver_request_and_add_address_mlp_LDADD = \ | ||
418 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
419 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
420 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
421 | libgnunetats.la \ | ||
422 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
423 | endif | ||
424 | |||
425 | test_ats_solver_request_and_add_address_ril_SOURCES = \ | ||
426 | test_ats_solver_request_and_add_address.c \ | ||
427 | test_ats_api_common.c test_ats_api_common.h | ||
428 | test_ats_solver_request_and_add_address_ril_LDADD = \ | ||
429 | $(top_builddir)/src/util/libgnunetutil.la \ | 121 | $(top_builddir)/src/util/libgnunetutil.la \ |
430 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
431 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
432 | libgnunetats.la \ | ||
433 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
434 | |||
435 | |||
436 | test_ats_solver_request_and_delete_address_proportional_SOURCES = \ | ||
437 | test_ats_solver_request_and_delete_address.c \ | ||
438 | test_ats_api_common.c test_ats_api_common.h | ||
439 | test_ats_solver_request_and_delete_address_proportional_LDADD = \ | ||
440 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
441 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
442 | $(top_builddir)/src/hello/libgnunethello.la \ | 122 | $(top_builddir)/src/hello/libgnunethello.la \ |
443 | libgnunetats.la \ | ||
444 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
445 | |||
446 | if HAVE_LIBGLPK | ||
447 | test_ats_solver_request_and_delete_address_mlp_SOURCES = \ | ||
448 | test_ats_solver_request_and_delete_address.c \ | ||
449 | test_ats_api_common.c test_ats_api_common.h | ||
450 | test_ats_solver_request_and_delete_address_mlp_LDADD = \ | ||
451 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
452 | $(top_builddir)/src/testing/libgnunettesting.la \ | 123 | $(top_builddir)/src/testing/libgnunettesting.la \ |
453 | $(top_builddir)/src/hello/libgnunethello.la \ | 124 | libgnunetats.la |
454 | libgnunetats.la \ | ||
455 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
456 | endif | ||
457 | |||
458 | test_ats_solver_request_and_delete_address_ril_SOURCES = \ | ||
459 | test_ats_solver_request_and_delete_address.c \ | ||
460 | test_ats_api_common.c test_ats_api_common.h | ||
461 | test_ats_solver_request_and_delete_address_ril_LDADD = \ | ||
462 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
463 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
464 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
465 | libgnunetats.la \ | ||
466 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
467 | |||
468 | 125 | ||
469 | test_ats_solver_alternative_after_delete_address_proportional_SOURCES = \ | 126 | test_ats_api_ril_SOURCES = \ |
470 | test_ats_solver_alternative_after_delete_address.c \ | 127 | test_ats_api.c \ |
471 | test_ats_api_common.c test_ats_api_common.h | 128 | test_ats_lib.c test_ats_lib.h |
472 | test_ats_solver_alternative_after_delete_address_proportional_LDADD = \ | 129 | test_ats_api_ril_LDADD = \ |
473 | $(top_builddir)/src/util/libgnunetutil.la \ | 130 | $(top_builddir)/src/util/libgnunetutil.la \ |
474 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
475 | $(top_builddir)/src/hello/libgnunethello.la \ | 131 | $(top_builddir)/src/hello/libgnunethello.la \ |
476 | libgnunetats.la \ | ||
477 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
478 | |||
479 | test_ats_solver_preferences_proportional_SOURCES = \ | ||
480 | test_ats_solver_preferences.c \ | ||
481 | test_ats_api_common.c test_ats_api_common.h | ||
482 | test_ats_solver_preferences_proportional_LDADD = \ | ||
483 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
484 | $(top_builddir)/src/testing/libgnunettesting.la \ | 132 | $(top_builddir)/src/testing/libgnunettesting.la \ |
485 | $(top_builddir)/src/hello/libgnunethello.la \ | 133 | libgnunetats.la |
486 | libgnunetats.la \ | ||
487 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
488 | 134 | ||
489 | if HAVE_LIBGLPK | 135 | test_ats_api_mlp_SOURCES = \ |
490 | test_ats_solver_alternative_after_delete_address_mlp_SOURCES = \ | 136 | test_ats_api.c \ |
491 | test_ats_solver_alternative_after_delete_address.c \ | 137 | test_ats_lib.c test_ats_lib.h |
492 | test_ats_api_common.c test_ats_api_common.h | 138 | test_ats_api_mlp_LDADD = \ |
493 | test_ats_solver_alternative_after_delete_address_mlp_LDADD = \ | ||
494 | $(top_builddir)/src/util/libgnunetutil.la \ | 139 | $(top_builddir)/src/util/libgnunetutil.la \ |
495 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
496 | $(top_builddir)/src/hello/libgnunethello.la \ | 140 | $(top_builddir)/src/hello/libgnunethello.la \ |
497 | libgnunetats.la \ | ||
498 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
499 | |||
500 | test_ats_solver_preferences_mlp_SOURCES = \ | ||
501 | test_ats_solver_preferences.c \ | ||
502 | test_ats_api_common.c test_ats_api_common.h | ||
503 | test_ats_solver_preferences_mlp_LDADD = \ | ||
504 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
505 | $(top_builddir)/src/testing/libgnunettesting.la \ | 141 | $(top_builddir)/src/testing/libgnunettesting.la \ |
506 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
507 | libgnunetats.la \ | ||
508 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
509 | endif | ||
510 | |||
511 | test_ats_solver_alternative_after_delete_address_ril_SOURCES = \ | ||
512 | test_ats_solver_alternative_after_delete_address.c \ | ||
513 | test_ats_api_common.c test_ats_api_common.h | ||
514 | test_ats_solver_alternative_after_delete_address_ril_LDADD = \ | ||
515 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
516 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
517 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
518 | libgnunetats.la \ | ||
519 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
520 | |||
521 | #perf_ats_mlp_SOURCES = \ | ||
522 | # $(GN_MLP_SRC) perf_ats_mlp.c test_ats_api_common.c gnunet-service-ats_normalization.c | ||
523 | #perf_ats_mlp_LDADD = \ | ||
524 | # $(GN_LIBGLPK) \ | ||
525 | # $(top_builddir)/src/util/libgnunetutil.la \ | ||
526 | # $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
527 | # libgnunetats.la | ||
528 | |||
529 | perf_ats_solver_mlp_SOURCES = \ | ||
530 | perf_ats_solver.c \ | ||
531 | test_ats_api_common.c \ | ||
532 | gnunet-service-ats_normalization.c \ | ||
533 | gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ | ||
534 | gnunet-service-ats_connectivity.c gnunet-service-ats_connectivity.h \ | ||
535 | gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ | ||
536 | gnunet-service-ats_preferences.c gnunet-service-ats_preferences.h \ | ||
537 | gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \ | ||
538 | gnunet-service-ats_plugins.c gnunet-service-ats_plugins.h \ | ||
539 | gnunet-service-ats_reservations.c gnunet-service-ats_reservations.h | ||
540 | |||
541 | perf_ats_solver_mlp_LDADD = \ | ||
542 | $(GN_LIBGLPK) \ | ||
543 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
544 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
545 | libgnunetats.la | ||
546 | |||
547 | perf_ats_solver_proportional_SOURCES = \ | ||
548 | perf_ats_solver.c \ | ||
549 | test_ats_api_common.c \ | ||
550 | gnunet-service-ats_normalization.c \ | ||
551 | gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ | ||
552 | gnunet-service-ats_connectivity.c gnunet-service-ats_connectivity.h \ | ||
553 | gnunet-service-ats_preferences.c gnunet-service-ats_preferences.h \ | ||
554 | gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ | ||
555 | gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \ | ||
556 | gnunet-service-ats_plugins.c gnunet-service-ats_plugins.h \ | ||
557 | gnunet-service-ats_reservations.c gnunet-service-ats_reservations.h | ||
558 | |||
559 | perf_ats_solver_proportional_LDADD = \ | ||
560 | $(GN_LIBGLPK) \ | ||
561 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
562 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
563 | libgnunetats.la | ||
564 | |||
565 | perf_ats_solver_ril_SOURCES = \ | ||
566 | perf_ats_solver.c \ | ||
567 | test_ats_api_common.c \ | ||
568 | gnunet-service-ats_normalization.c \ | ||
569 | gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ | ||
570 | gnunet-service-ats_connectivity.c gnunet-service-ats_connectivity.h \ | ||
571 | gnunet-service-ats_preferences.c gnunet-service-ats_preferences.h \ | ||
572 | gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ | ||
573 | gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \ | ||
574 | gnunet-service-ats_plugins.c gnunet-service-ats_plugins.h \ | ||
575 | gnunet-service-ats_reservations.c gnunet-service-ats_reservations.h | ||
576 | |||
577 | perf_ats_solver_ril_LDADD = \ | ||
578 | $(GN_LIBGLPK) \ | ||
579 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
580 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
581 | libgnunetats.la | 142 | libgnunetats.la |
582 | 143 | ||
583 | test_ats_solver_preferences_ril_SOURCES = \ | ||
584 | test_ats_solver_preferences.c \ | ||
585 | test_ats_api_common.c test_ats_api_common.h | ||
586 | test_ats_solver_preferences_ril_LDADD = \ | ||
587 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
588 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
589 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
590 | libgnunetats.la \ | ||
591 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
592 | |||
593 | EXTRA_DIST = \ | 144 | EXTRA_DIST = \ |
594 | ats.h \ | 145 | ats.h \ |
595 | test_delay \ | 146 | test_delay \ |
596 | test_ats_api.conf \ | 147 | test_ats_api_mlp.conf \ |
597 | test_ats_api_delayed.conf \ | 148 | test_ats_api_ril.conf \ |
598 | test_ats_mlp.conf \ | 149 | test_ats_api_proportional.conf |
599 | test_ats_solver_default.conf \ | ||
600 | test_ats_solver_proportional.conf \ | ||
601 | test_ats_solver_proportional.conf \ | ||
602 | test_ats_solver_mlp.conf \ | ||
603 | test_ats_solver_delayed_mlp.conf \ | ||
604 | test_ats_solver_ril.conf \ | ||
605 | test_ats_solver_delayed_ril.conf \ | ||
606 | perf_ats_solver_mlp.conf \ | ||
607 | test_ats_solver_delayed_mlp.conf \ | ||
608 | perf_ats_solver_proportional.conf \ | ||
609 | perf_ats_solver_ril.conf \ | ||
610 | perf_ats_solver.conf | ||
diff --git a/src/ats/test_ats_api.c b/src/ats/test_ats_api.c new file mode 100644 index 000000000..97fdd65c1 --- /dev/null +++ b/src/ats/test_ats_api.c | |||
@@ -0,0 +1,243 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010-2015 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_api.c | ||
22 | * @brief test ATS | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "test_ats_lib.h" | ||
27 | |||
28 | /** | ||
29 | * Global timeout for the testcase. | ||
30 | */ | ||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) | ||
32 | |||
33 | /** | ||
34 | * Definition of the test as a sequence of commands. | ||
35 | */ | ||
36 | static struct Command test_commands[] = { | ||
37 | { | ||
38 | .code = CMD_ADD_ADDRESS, | ||
39 | .label = "add-address-0-0", | ||
40 | .details.add_address = { | ||
41 | .pid = 0, | ||
42 | .addr_num = 0, | ||
43 | .session = 0, | ||
44 | .properties = { | ||
45 | .scope = GNUNET_ATS_NET_LAN | ||
46 | } | ||
47 | } | ||
48 | }, | ||
49 | /* adding same address again should fail */ | ||
50 | { | ||
51 | .code = CMD_ADD_ADDRESS, | ||
52 | .label = "add-address-0-0:FAIL", | ||
53 | .details.add_address = { | ||
54 | .pid = 0, | ||
55 | .addr_num = 0, | ||
56 | .session = 0, | ||
57 | .properties = { | ||
58 | .scope = GNUNET_ATS_NET_LAN | ||
59 | }, | ||
60 | .expect_fail = 1 | ||
61 | } | ||
62 | }, | ||
63 | /* some solver still require explicit start */ | ||
64 | { | ||
65 | .code = CMD_REQUEST_CONNECTION_START, | ||
66 | .label = "request-0", | ||
67 | .details.request_connection_start = { | ||
68 | .pid = 0 | ||
69 | } | ||
70 | }, | ||
71 | /* check we got an address */ | ||
72 | { | ||
73 | .code = CMD_AWAIT_ADDRESS_SUGGESTION, | ||
74 | .details.await_address_suggestion = { | ||
75 | .add_label = "add-address-0-0" | ||
76 | } | ||
77 | }, | ||
78 | /* check monitor also got the address */ | ||
79 | { | ||
80 | .code = CMD_AWAIT_ADDRESS_INFORMATION, | ||
81 | .details.await_address_information = { | ||
82 | .add_label = "add-address-0-0" | ||
83 | } | ||
84 | }, | ||
85 | /* test session API */ | ||
86 | { | ||
87 | .code = CMD_ADD_SESSION, | ||
88 | .label = "add-session-0-0-1", | ||
89 | .details.add_session = { | ||
90 | .add_label ="add-address-0-0", | ||
91 | .session = 1 | ||
92 | } | ||
93 | }, | ||
94 | { | ||
95 | .code = CMD_DEL_SESSION, | ||
96 | .details.del_session = { | ||
97 | .add_session_label = "add-session-0-0-1", | ||
98 | } | ||
99 | }, | ||
100 | /* test preference API */ | ||
101 | { | ||
102 | .code = CMD_CHANGE_PREFERENCE, | ||
103 | .details.change_preference = { | ||
104 | .pid = 0 | ||
105 | /* FIXME: preference details */ | ||
106 | } | ||
107 | }, | ||
108 | { | ||
109 | .code = CMD_PROVIDE_FEEDBACK, | ||
110 | .details.provide_feedback = { | ||
111 | .pid = 0, | ||
112 | .scope = { 50LL } | ||
113 | /* FIXME: preference details */ | ||
114 | } | ||
115 | }, | ||
116 | /* test sanity check address listing */ | ||
117 | { | ||
118 | .code = CMD_LIST_ADDRESSES, | ||
119 | .details.list_addresses = { | ||
120 | .pid = 0, | ||
121 | .all = 1, | ||
122 | .min_calls = 2, // ? | ||
123 | .max_calls = 2, | ||
124 | .min_active_calls = 1, | ||
125 | .max_active_calls = 1 | ||
126 | } | ||
127 | }, | ||
128 | /* remove address testing */ | ||
129 | { | ||
130 | .code = CMD_DEL_ADDRESS, | ||
131 | .details.del_address = { | ||
132 | .add_label = "add-address-0-0" | ||
133 | } | ||
134 | }, | ||
135 | /* check we got disconnected */ | ||
136 | { | ||
137 | .code = CMD_AWAIT_DISCONNECT_SUGGESTION, | ||
138 | .details.await_disconnect_suggestion = { | ||
139 | .pid = 0 | ||
140 | } | ||
141 | }, | ||
142 | /* just for symmetry, also stop asking for the connection */ | ||
143 | { | ||
144 | .code = CMD_REQUEST_CONNECTION_STOP, | ||
145 | .details.request_connection_stop = { | ||
146 | .connect_label = "request-0", | ||
147 | } | ||
148 | }, | ||
149 | /* add address again */ | ||
150 | { | ||
151 | .code = CMD_ADD_ADDRESS, | ||
152 | .label = "add-address-0-0:1", | ||
153 | .details.add_address = { | ||
154 | .pid = 0, | ||
155 | .addr_num = 0, | ||
156 | .session = 0, | ||
157 | .properties = { | ||
158 | .scope = GNUNET_ATS_NET_LAN | ||
159 | } | ||
160 | } | ||
161 | }, | ||
162 | /* some solver still require explicit start */ | ||
163 | { | ||
164 | .code = CMD_REQUEST_CONNECTION_START, | ||
165 | .label = "request-0", | ||
166 | .details.request_connection_start = { | ||
167 | .pid = 0 | ||
168 | } | ||
169 | }, | ||
170 | /* check we got an address */ | ||
171 | { | ||
172 | .code = CMD_AWAIT_ADDRESS_SUGGESTION, | ||
173 | .details.await_address_suggestion = { | ||
174 | .add_label = "add-address-0-0:1" | ||
175 | } | ||
176 | }, | ||
177 | /* add alternative address */ | ||
178 | { | ||
179 | .code = CMD_ADD_ADDRESS, | ||
180 | .label = "add-address-0-1", | ||
181 | .details.add_address = { | ||
182 | .pid = 0, | ||
183 | .addr_num = 1, | ||
184 | .session = 0, | ||
185 | .properties = { | ||
186 | .scope = GNUNET_ATS_NET_LAN | ||
187 | } | ||
188 | } | ||
189 | }, | ||
190 | /* remove original address */ | ||
191 | { | ||
192 | .code = CMD_DEL_ADDRESS, | ||
193 | .details.del_address = { | ||
194 | .add_label = "add-address-0-0:1" | ||
195 | } | ||
196 | }, | ||
197 | /* check we switched to alternative address */ | ||
198 | { | ||
199 | .code = CMD_AWAIT_ADDRESS_SUGGESTION, | ||
200 | .details.await_address_suggestion = { | ||
201 | .add_label = "add-address-0-1" | ||
202 | } | ||
203 | }, | ||
204 | /* remove alternative address */ | ||
205 | { | ||
206 | .code = CMD_DEL_ADDRESS, | ||
207 | .details.del_address = { | ||
208 | .add_label = "add-address-0-1" | ||
209 | } | ||
210 | }, | ||
211 | /* check we got disconnected */ | ||
212 | { | ||
213 | .code = CMD_AWAIT_DISCONNECT_SUGGESTION, | ||
214 | .details.await_disconnect_suggestion = { | ||
215 | .pid = 0 | ||
216 | } | ||
217 | }, | ||
218 | /* just for symmetry, also stop asking for the connection */ | ||
219 | { | ||
220 | .code = CMD_REQUEST_CONNECTION_STOP, | ||
221 | .details.request_connection_stop = { | ||
222 | .connect_label = "request-0", | ||
223 | } | ||
224 | }, | ||
225 | /* Test ends successfully */ | ||
226 | { | ||
227 | .code = CMD_END_PASS | ||
228 | } | ||
229 | }; | ||
230 | |||
231 | |||
232 | int | ||
233 | main (int argc, | ||
234 | char *argv[]) | ||
235 | { | ||
236 | return TEST_ATS_run (argc, | ||
237 | argv, | ||
238 | test_commands, | ||
239 | TIMEOUT); | ||
240 | } | ||
241 | |||
242 | |||
243 | /* end of file test_ats_api.c */ | ||
diff --git a/src/ats/test_ats_api_common.c b/src/ats/test_ats_api_common.c deleted file mode 100644 index 2bfebaa6d..000000000 --- a/src/ats/test_ats_api_common.c +++ /dev/null | |||
@@ -1,302 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010,2011 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_api_common.c | ||
22 | * @brief shared functions for ats test | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | */ | ||
26 | |||
27 | #include "test_ats_api_common.h" | ||
28 | #define BIG_M_STRING "unlimited" | ||
29 | |||
30 | |||
31 | void | ||
32 | create_test_address (struct Test_Address *dest, char * plugin, void *session, void *addr, size_t addrlen) | ||
33 | { | ||
34 | |||
35 | dest->plugin = GNUNET_strdup (plugin); | ||
36 | dest->session = session; | ||
37 | if (addrlen > 0) | ||
38 | { | ||
39 | dest->addr = GNUNET_malloc (addrlen); | ||
40 | memcpy (dest->addr, addr, addrlen); | ||
41 | } | ||
42 | else | ||
43 | dest->addr = NULL; | ||
44 | dest->addr_len = addrlen; | ||
45 | } | ||
46 | |||
47 | |||
48 | void | ||
49 | free_test_address (struct Test_Address *dest) | ||
50 | { | ||
51 | GNUNET_free_non_null (dest->plugin); | ||
52 | dest->plugin = NULL; | ||
53 | GNUNET_free_non_null (dest->addr); | ||
54 | dest->addr = NULL; | ||
55 | } | ||
56 | |||
57 | |||
58 | int | ||
59 | compare_addresses (const struct GNUNET_HELLO_Address *address1, | ||
60 | void *session1, | ||
61 | const struct GNUNET_HELLO_Address *address2, | ||
62 | void *session2) | ||
63 | { | ||
64 | if (0 != | ||
65 | memcmp (&address1->peer, | ||
66 | &address2->peer, | ||
67 | sizeof (struct GNUNET_PeerIdentity))) | ||
68 | { | ||
69 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
70 | "Suggestion with invalid peer id'\n"); | ||
71 | return GNUNET_SYSERR; | ||
72 | } | ||
73 | if (0 != strcmp (address1->transport_name, address2->transport_name)) | ||
74 | { | ||
75 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
76 | "Suggestion with invalid plugin'\n"); | ||
77 | return GNUNET_SYSERR; | ||
78 | } | ||
79 | if (address1->address_length != address2->address_length) | ||
80 | { | ||
81 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
82 | "Suggestion with invalid address length\n"); | ||
83 | return GNUNET_SYSERR; | ||
84 | } | ||
85 | if (0 != memcmp (address1->address, address2->address, address2->address_length)) | ||
86 | { | ||
87 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
88 | "Suggestion with invalid address\n"); | ||
89 | return GNUNET_SYSERR; | ||
90 | } | ||
91 | if (session1 != session2) | ||
92 | { | ||
93 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
94 | "Suggestion with invalid session1 %p vs session2 %p'\n", | ||
95 | session1, session2); | ||
96 | return GNUNET_SYSERR; | ||
97 | } | ||
98 | return GNUNET_OK; | ||
99 | } | ||
100 | |||
101 | |||
102 | int | ||
103 | compare_ats (const struct GNUNET_ATS_Information *ats_is, uint32_t ats_count_is, | ||
104 | const struct GNUNET_ATS_Information *ats_should, uint32_t ats_count_should) | ||
105 | { | ||
106 | unsigned int c_o; | ||
107 | unsigned int c_i; | ||
108 | uint32_t type1; | ||
109 | uint32_t type2; | ||
110 | uint32_t val1; | ||
111 | uint32_t val2; | ||
112 | int res = GNUNET_OK; | ||
113 | |||
114 | for (c_o = 0; c_o < ats_count_is; c_o++) | ||
115 | { | ||
116 | for (c_i = 0; c_i < ats_count_should; c_i++) | ||
117 | { | ||
118 | type1 = ntohl(ats_is[c_o].type); | ||
119 | type2 = ntohl(ats_should[c_i].type); | ||
120 | if (type1 == type2) | ||
121 | { | ||
122 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
123 | "ATS type `%s'\n", | ||
124 | GNUNET_ATS_print_property_type (type1)); | ||
125 | val1 = ntohl(ats_is[c_o].value); | ||
126 | val2 = ntohl(ats_should[c_i].value); | ||
127 | if (val1 != val2) | ||
128 | { | ||
129 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
130 | "ATS value `%s' not equal: %u != %u\n", | ||
131 | GNUNET_ATS_print_property_type (type1), | ||
132 | val1, val2); | ||
133 | res = GNUNET_SYSERR; | ||
134 | } | ||
135 | else | ||
136 | { | ||
137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
138 | "ATS value `%s' equal: %u == %u\n", | ||
139 | GNUNET_ATS_print_property_type (type1), | ||
140 | val1, val2); | ||
141 | } | ||
142 | } | ||
143 | } | ||
144 | } | ||
145 | return res; | ||
146 | } | ||
147 | |||
148 | |||
149 | /** | ||
150 | * Load quotas for networks from configuration | ||
151 | * | ||
152 | * @param cfg configuration handle | ||
153 | * @param out_dest where to write outbound quotas | ||
154 | * @param in_dest where to write inbound quotas | ||
155 | * @param dest_length length of inbound and outbound arrays | ||
156 | * @return number of networks loaded | ||
157 | */ | ||
158 | unsigned int | ||
159 | load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
160 | unsigned long long *out_dest, | ||
161 | unsigned long long *in_dest, | ||
162 | int dest_length) | ||
163 | { | ||
164 | char *entry_in = NULL; | ||
165 | char *entry_out = NULL; | ||
166 | char *quota_out_str; | ||
167 | char *quota_in_str; | ||
168 | int c; | ||
169 | int res; | ||
170 | |||
171 | for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++) | ||
172 | { | ||
173 | in_dest[c] = 0; | ||
174 | out_dest[c] = 0; | ||
175 | GNUNET_asprintf (&entry_out, | ||
176 | "%s_QUOTA_OUT", | ||
177 | GNUNET_ATS_print_network_type (c)); | ||
178 | GNUNET_asprintf (&entry_in, | ||
179 | "%s_QUOTA_IN", | ||
180 | GNUNET_ATS_print_network_type (c)); | ||
181 | |||
182 | /* quota out */ | ||
183 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str)) | ||
184 | { | ||
185 | res = GNUNET_NO; | ||
186 | if (0 == strcmp(quota_out_str, BIG_M_STRING)) | ||
187 | { | ||
188 | out_dest[c] = GNUNET_ATS_MaxBandwidth; | ||
189 | res = GNUNET_YES; | ||
190 | } | ||
191 | if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c]))) | ||
192 | res = GNUNET_YES; | ||
193 | if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c]))) | ||
194 | res = GNUNET_YES; | ||
195 | |||
196 | if (GNUNET_NO == res) | ||
197 | { | ||
198 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
199 | _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"), | ||
200 | GNUNET_ATS_print_network_type (c), | ||
201 | quota_out_str, | ||
202 | GNUNET_ATS_DefaultBandwidth); | ||
203 | out_dest[c] = GNUNET_ATS_DefaultBandwidth; | ||
204 | } | ||
205 | else | ||
206 | { | ||
207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
208 | "Outbound quota configure for network `%s' is %llu\n", | ||
209 | GNUNET_ATS_print_network_type (c), | ||
210 | out_dest[c]); | ||
211 | } | ||
212 | GNUNET_free (quota_out_str); | ||
213 | } | ||
214 | else | ||
215 | { | ||
216 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
217 | _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"), | ||
218 | GNUNET_ATS_print_network_type (c), | ||
219 | GNUNET_ATS_DefaultBandwidth); | ||
220 | out_dest[c] = GNUNET_ATS_DefaultBandwidth; | ||
221 | } | ||
222 | |||
223 | /* quota in */ | ||
224 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str)) | ||
225 | { | ||
226 | res = GNUNET_NO; | ||
227 | if (0 == strcmp(quota_in_str, BIG_M_STRING)) | ||
228 | { | ||
229 | in_dest[c] = GNUNET_ATS_MaxBandwidth; | ||
230 | res = GNUNET_YES; | ||
231 | } | ||
232 | if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c]))) | ||
233 | res = GNUNET_YES; | ||
234 | if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c]))) | ||
235 | res = GNUNET_YES; | ||
236 | |||
237 | if (GNUNET_NO == res) | ||
238 | { | ||
239 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
240 | _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"), | ||
241 | GNUNET_ATS_print_network_type (c), | ||
242 | quota_in_str, | ||
243 | GNUNET_ATS_DefaultBandwidth); | ||
244 | in_dest[c] = GNUNET_ATS_DefaultBandwidth; | ||
245 | } | ||
246 | else | ||
247 | { | ||
248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
249 | "Inbound quota configured for network `%s' is %llu\n", | ||
250 | GNUNET_ATS_print_network_type (c), | ||
251 | in_dest[c]); | ||
252 | } | ||
253 | GNUNET_free (quota_in_str); | ||
254 | } | ||
255 | else | ||
256 | { | ||
257 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
258 | _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"), | ||
259 | GNUNET_ATS_print_network_type (c), | ||
260 | GNUNET_ATS_DefaultBandwidth); | ||
261 | out_dest[c] = GNUNET_ATS_DefaultBandwidth; | ||
262 | } | ||
263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
264 | "Loaded quota for network `%s' (in/out): %llu %llu\n", | ||
265 | GNUNET_ATS_print_network_type (c), | ||
266 | in_dest[c], | ||
267 | out_dest[c]); | ||
268 | GNUNET_free (entry_out); | ||
269 | GNUNET_free (entry_in); | ||
270 | } | ||
271 | return GNUNET_ATS_NetworkTypeCount; | ||
272 | } | ||
273 | |||
274 | /** | ||
275 | * Create a ATS_address with the given information | ||
276 | * @param peer peer | ||
277 | * @param plugin_name plugin | ||
278 | * @param plugin_addr address | ||
279 | * @param plugin_addr_len address length | ||
280 | * @param session_id session | ||
281 | * @return the ATS_Address | ||
282 | */ | ||
283 | struct ATS_Address * | ||
284 | create_address (const struct GNUNET_PeerIdentity *peer, | ||
285 | const char *plugin_name, | ||
286 | const void *plugin_addr, size_t plugin_addr_len, | ||
287 | uint32_t session_id) | ||
288 | { | ||
289 | struct ATS_Address *aa = NULL; | ||
290 | |||
291 | aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1); | ||
292 | aa->peer = *peer; | ||
293 | aa->addr_len = plugin_addr_len; | ||
294 | aa->addr = &aa[1]; | ||
295 | aa->plugin = (char *) &aa[1] + plugin_addr_len; | ||
296 | memcpy (&aa[1], plugin_addr, plugin_addr_len); | ||
297 | memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1); | ||
298 | aa->session_id = session_id; | ||
299 | return aa; | ||
300 | } | ||
301 | |||
302 | /* end of file test_ats_api_common.c */ | ||
diff --git a/src/ats/test_ats_api_common.h b/src/ats/test_ats_api_common.h deleted file mode 100644 index 091eb59b6..000000000 --- a/src/ats/test_ats_api_common.h +++ /dev/null | |||
@@ -1,90 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010,2011 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_api_common.h | ||
22 | * @brief shared definitions for ats testcases | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_ats_service.h" | ||
29 | #include "gnunet-service-ats_addresses.h" | ||
30 | |||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | ||
32 | |||
33 | struct Test_Address | ||
34 | { | ||
35 | char *plugin; | ||
36 | size_t plugin_len; | ||
37 | |||
38 | void *addr; | ||
39 | size_t addr_len; | ||
40 | |||
41 | struct GNUNET_ATS_Properties properties; | ||
42 | |||
43 | void *session; | ||
44 | }; | ||
45 | |||
46 | struct PeerContext | ||
47 | { | ||
48 | struct GNUNET_PeerIdentity id; | ||
49 | |||
50 | struct Test_Address *addr; | ||
51 | |||
52 | unsigned long long bw_out_assigned; | ||
53 | |||
54 | unsigned long long bw_in_assigned; | ||
55 | }; | ||
56 | |||
57 | void | ||
58 | free_test_address (struct Test_Address *dest); | ||
59 | |||
60 | void | ||
61 | create_test_address (struct Test_Address *dest, char * plugin, void *session, void *addr, size_t addrlen); | ||
62 | |||
63 | |||
64 | int | ||
65 | compare_addresses (const struct GNUNET_HELLO_Address *address1, void *session1, | ||
66 | const struct GNUNET_HELLO_Address *address2, void *session2); | ||
67 | |||
68 | |||
69 | struct ATS_Address * | ||
70 | create_address (const struct GNUNET_PeerIdentity *peer, | ||
71 | const char *plugin_name, | ||
72 | const void *plugin_addr, size_t plugin_addr_len, | ||
73 | uint32_t session_id); | ||
74 | |||
75 | /** | ||
76 | * Load quotas for networks from configuration | ||
77 | * | ||
78 | * @param cfg configuration handle | ||
79 | * @param out_dest where to write outbound quotas | ||
80 | * @param in_dest where to write inbound quotas | ||
81 | * @param dest_length length of inbound and outbound arrays | ||
82 | * @return number of networks loaded | ||
83 | */ | ||
84 | unsigned int | ||
85 | load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
86 | unsigned long long *out_dest, | ||
87 | unsigned long long *in_dest, | ||
88 | int dest_length); | ||
89 | |||
90 | /* end of file test_ats_api_common.h */ | ||
diff --git a/src/ats/test_ats_api_delayed_service_performance_list_all_addresses.c b/src/ats/test_ats_api_delayed_service_performance_list_all_addresses.c deleted file mode 100644 index 348cbc3c4..000000000 --- a/src/ats/test_ats_api_delayed_service_performance_list_all_addresses.c +++ /dev/null | |||
@@ -1,303 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010,2011 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_api_delayed_service_performance_list_all_addresses.c | ||
22 | * @brief test performance API's address listing feature with a delayed service startup | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_ats_service.h" | ||
28 | #include "gnunet_testing_lib.h" | ||
29 | #include "ats.h" | ||
30 | |||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | ||
32 | |||
33 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
34 | |||
35 | /** | ||
36 | * Statistics handle | ||
37 | */ | ||
38 | struct GNUNET_STATISTICS_Handle *stats; | ||
39 | |||
40 | /** | ||
41 | * Configuration handle | ||
42 | */ | ||
43 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
44 | |||
45 | /** | ||
46 | * ATS scheduling handle | ||
47 | */ | ||
48 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
49 | |||
50 | /** | ||
51 | * ATS performance handle | ||
52 | */ | ||
53 | static struct GNUNET_ATS_PerformanceHandle *perf_ats; | ||
54 | |||
55 | struct GNUNET_ATS_AddressListHandle* phal; | ||
56 | |||
57 | static int ret; | ||
58 | |||
59 | struct Address | ||
60 | { | ||
61 | char *plugin; | ||
62 | size_t plugin_len; | ||
63 | |||
64 | void *addr; | ||
65 | size_t addr_len; | ||
66 | |||
67 | struct GNUNET_ATS_Information *ats; | ||
68 | int ats_count; | ||
69 | |||
70 | void *session; | ||
71 | }; | ||
72 | |||
73 | struct PeerContext | ||
74 | { | ||
75 | struct GNUNET_PeerIdentity id; | ||
76 | |||
77 | struct Address *addr; | ||
78 | }; | ||
79 | |||
80 | static struct PeerContext p[2]; | ||
81 | |||
82 | static struct Address p0_addresses[2]; | ||
83 | static struct Address p1_addresses[2]; | ||
84 | |||
85 | struct GNUNET_HELLO_Address p0_ha[2]; | ||
86 | struct GNUNET_HELLO_Address p1_ha[2]; | ||
87 | struct GNUNET_HELLO_Address *s_ha[2]; | ||
88 | |||
89 | static void | ||
90 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
91 | |||
92 | static void | ||
93 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
94 | |||
95 | |||
96 | static void | ||
97 | ats_perf_cb (void *cls, | ||
98 | const struct GNUNET_HELLO_Address *address, | ||
99 | int address_active, | ||
100 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
101 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
102 | const struct GNUNET_ATS_Information *ats, | ||
103 | uint32_t ats_count) | ||
104 | { | ||
105 | static int counter = 0; | ||
106 | |||
107 | if (NULL == address) | ||
108 | { | ||
109 | phal = 0; | ||
110 | if (4 == counter) | ||
111 | { | ||
112 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n"); | ||
113 | GNUNET_SCHEDULER_add_now (end, NULL); | ||
114 | } | ||
115 | else | ||
116 | { | ||
117 | GNUNET_break (0); | ||
118 | GNUNET_SCHEDULER_add_now (end_badly, NULL); | ||
119 | } | ||
120 | return; | ||
121 | } | ||
122 | counter ++; | ||
123 | } | ||
124 | |||
125 | |||
126 | static int | ||
127 | stat_cb(void *cls, const char *subsystem, | ||
128 | const char *name, uint64_t value, | ||
129 | int is_persistent) | ||
130 | { | ||
131 | |||
132 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", | ||
133 | subsystem,name, value); | ||
134 | if (4 == value) | ||
135 | { | ||
136 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
137 | "All addresses added, connecting to performance\n"); | ||
138 | if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL))) | ||
139 | { | ||
140 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
141 | "Failed to connect to performance API\n"); | ||
142 | GNUNET_SCHEDULER_add_now (end_badly, NULL); | ||
143 | } | ||
144 | phal = GNUNET_ATS_performance_list_addresses (perf_ats, NULL, GNUNET_YES, &ats_perf_cb, NULL); | ||
145 | } | ||
146 | return GNUNET_OK; | ||
147 | } | ||
148 | |||
149 | |||
150 | static void | ||
151 | address_suggest_cb (void *cls, | ||
152 | const struct GNUNET_PeerIdentity *peer, | ||
153 | const struct GNUNET_HELLO_Address *address, | ||
154 | struct Session *session, | ||
155 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
156 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
157 | { | ||
158 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); | ||
159 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
160 | } | ||
161 | |||
162 | |||
163 | static void | ||
164 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
165 | { | ||
166 | die_task = NULL; | ||
167 | end ( NULL, NULL); | ||
168 | ret = GNUNET_SYSERR; | ||
169 | } | ||
170 | |||
171 | static void | ||
172 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
173 | { | ||
174 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | ||
175 | if (die_task != NULL ) | ||
176 | { | ||
177 | GNUNET_SCHEDULER_cancel (die_task); | ||
178 | die_task = NULL; | ||
179 | } | ||
180 | |||
181 | if (NULL != sched_ats) | ||
182 | { | ||
183 | GNUNET_ATS_scheduling_done (sched_ats); | ||
184 | sched_ats = NULL; | ||
185 | } | ||
186 | |||
187 | if (phal != NULL ) | ||
188 | { | ||
189 | GNUNET_ATS_performance_list_addresses_cancel (phal); | ||
190 | phal = NULL; | ||
191 | } | ||
192 | |||
193 | if (perf_ats != NULL ) | ||
194 | { | ||
195 | GNUNET_ATS_performance_done (perf_ats); | ||
196 | perf_ats = NULL; | ||
197 | } | ||
198 | |||
199 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
200 | if (NULL != stats) | ||
201 | { | ||
202 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
203 | stats = NULL; | ||
204 | } | ||
205 | |||
206 | |||
207 | GNUNET_free_non_null(p0_addresses[0].addr); | ||
208 | GNUNET_free_non_null(p0_addresses[1].addr); | ||
209 | GNUNET_free_non_null(p1_addresses[0].addr); | ||
210 | GNUNET_free_non_null(p1_addresses[1].addr); | ||
211 | |||
212 | ret = 0; | ||
213 | } | ||
214 | |||
215 | |||
216 | |||
217 | static void | ||
218 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | ||
219 | struct GNUNET_TESTING_Peer *peer) | ||
220 | { | ||
221 | ret = 1; | ||
222 | cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; | ||
223 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); | ||
224 | |||
225 | stats = GNUNET_STATISTICS_create ("ats", cfg); | ||
226 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
227 | |||
228 | /* set up peer 0 */ | ||
229 | memset (&p[0].id, '1', sizeof (p[0].id)); | ||
230 | p0_addresses[0].plugin = "test"; | ||
231 | p0_addresses[0].session = NULL; | ||
232 | p0_addresses[0].addr = GNUNET_strdup ("test_p0_a0"); | ||
233 | p0_addresses[0].addr_len = strlen (p0_addresses[0].addr) + 1; | ||
234 | |||
235 | p0_ha[0].address = p0_addresses[0].addr; | ||
236 | p0_ha[0].address_length = p0_addresses[0].addr_len; | ||
237 | p0_ha[0].peer = p[0].id; | ||
238 | p0_ha[0].transport_name = p0_addresses[0].plugin; | ||
239 | |||
240 | p0_addresses[1].plugin = "test"; | ||
241 | p0_addresses[1].session = NULL; | ||
242 | p0_addresses[1].addr = GNUNET_strdup ("test_p0_a1"); | ||
243 | p0_addresses[1].addr_len = strlen (p0_addresses[1].addr) + 1; | ||
244 | |||
245 | p0_ha[1].address = p0_addresses[1].addr; | ||
246 | p0_ha[1].address_length = p0_addresses[1].addr_len; | ||
247 | p0_ha[1].peer = p[0].id; | ||
248 | p0_ha[1].transport_name = p0_addresses[1].plugin; | ||
249 | |||
250 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 0: `%s'\n", | ||
251 | GNUNET_i2s (&p[0].id)); | ||
252 | |||
253 | memset (&p[1].id, '2', sizeof (p[1].id)); | ||
254 | p1_addresses[0].plugin = "test"; | ||
255 | p1_addresses[0].session = NULL; | ||
256 | p1_addresses[0].addr = GNUNET_strdup ("test_p1_a0"); | ||
257 | p1_addresses[0].addr_len = strlen (p1_addresses[0].addr) + 1; | ||
258 | |||
259 | p1_ha[0].address = p1_addresses[0].addr; | ||
260 | p1_ha[0].address_length = p1_addresses[0].addr_len; | ||
261 | p1_ha[0].peer = p[1].id; | ||
262 | p1_ha[0].transport_name = p1_addresses[0].plugin; | ||
263 | |||
264 | p1_addresses[1].plugin = "test"; | ||
265 | p1_addresses[1].session = NULL; | ||
266 | p1_addresses[1].addr = GNUNET_strdup ("test_p1_a1"); | ||
267 | p1_addresses[1].addr_len = strlen (p1_addresses[1].addr) + 1; | ||
268 | |||
269 | p1_ha[1].address = p1_addresses[1].addr; | ||
270 | p1_ha[1].address_length = p1_addresses[1].addr_len; | ||
271 | p1_ha[1].peer = p[1].id; | ||
272 | p1_ha[1].transport_name = p1_addresses[1].plugin; | ||
273 | |||
274 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 1: `%s'\n", | ||
275 | GNUNET_i2s (&p[1].id)); | ||
276 | |||
277 | /* Add addresses */ | ||
278 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); | ||
279 | if (sched_ats == NULL ) | ||
280 | { | ||
281 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); | ||
282 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
283 | return; | ||
284 | } | ||
285 | |||
286 | GNUNET_ATS_address_add (sched_ats, &p0_ha[0], NULL, NULL, 0); | ||
287 | GNUNET_ATS_address_add (sched_ats, &p0_ha[1], NULL, NULL, 0); | ||
288 | |||
289 | GNUNET_ATS_address_add (sched_ats, &p1_ha[0], NULL, NULL, 0); | ||
290 | GNUNET_ATS_address_add (sched_ats, &p1_ha[1], NULL, NULL, 0); | ||
291 | } | ||
292 | |||
293 | int | ||
294 | main (int argc, char *argv[]) | ||
295 | { | ||
296 | if (0 | ||
297 | != GNUNET_TESTING_peer_run ("test_ats_api_performance", | ||
298 | "test_ats_api_delayed.conf", &run, NULL )) | ||
299 | return 1; | ||
300 | return ret; | ||
301 | } | ||
302 | |||
303 | /* end of file test_ats_api_delayed_service_performance_list_all_addresses.c */ | ||
diff --git a/src/ats/test_ats_api_delayed_service_performance_monitor.c b/src/ats/test_ats_api_delayed_service_performance_monitor.c deleted file mode 100644 index 2e3ff738f..000000000 --- a/src/ats/test_ats_api_delayed_service_performance_monitor.c +++ /dev/null | |||
@@ -1,305 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010,2011 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_api_delayed_service_performance_monitor.c | ||
22 | * @brief test performance API's address monitor feature with a delayed service | ||
23 | * start up | ||
24 | * @author Christian Grothoff | ||
25 | * @author Matthias Wachs | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_ats_service.h" | ||
29 | #include "gnunet_testing_lib.h" | ||
30 | #include "ats.h" | ||
31 | |||
32 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | ||
33 | #define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
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 | * Configuration handle | ||
44 | */ | ||
45 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
46 | |||
47 | /** | ||
48 | * ATS scheduling handle | ||
49 | */ | ||
50 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
51 | |||
52 | /** | ||
53 | * ATS performance handle | ||
54 | */ | ||
55 | static struct GNUNET_ATS_PerformanceHandle *perf_ats; | ||
56 | |||
57 | |||
58 | static int ret; | ||
59 | |||
60 | struct Address | ||
61 | { | ||
62 | char *plugin; | ||
63 | size_t plugin_len; | ||
64 | |||
65 | void *addr; | ||
66 | size_t addr_len; | ||
67 | |||
68 | struct GNUNET_ATS_Information *ats; | ||
69 | int ats_count; | ||
70 | |||
71 | void *session; | ||
72 | }; | ||
73 | |||
74 | struct PeerContext | ||
75 | { | ||
76 | struct GNUNET_PeerIdentity id; | ||
77 | |||
78 | struct Address *addr; | ||
79 | }; | ||
80 | |||
81 | static struct PeerContext p[2]; | ||
82 | |||
83 | static struct Address p0_addresses[2]; | ||
84 | static struct Address p1_addresses[2]; | ||
85 | |||
86 | static struct GNUNET_HELLO_Address p0_ha[2]; | ||
87 | static struct GNUNET_HELLO_Address p1_ha[2]; | ||
88 | |||
89 | |||
90 | static void | ||
91 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
92 | |||
93 | static void | ||
94 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
95 | |||
96 | |||
97 | static void | ||
98 | ats_perf_cb (void *cls, | ||
99 | const struct GNUNET_HELLO_Address *address, | ||
100 | int address_active, | ||
101 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
102 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
103 | const struct GNUNET_ATS_Information *ats, | ||
104 | uint32_t ats_count) | ||
105 | { | ||
106 | static int peer0 = GNUNET_NO; | ||
107 | static int peer1 = GNUNET_NO; | ||
108 | static int done = GNUNET_NO; | ||
109 | |||
110 | if (NULL == address) | ||
111 | return; | ||
112 | |||
113 | if ((GNUNET_NO == peer0) && (0 == memcmp (address, &p[0].id, sizeof (p[0].id)))) | ||
114 | { | ||
115 | peer0 = GNUNET_YES; | ||
116 | } | ||
117 | if ((GNUNET_NO == peer0) && (0 == memcmp (address, &p[1].id, sizeof (p[1].id)))) | ||
118 | { | ||
119 | peer1 = GNUNET_YES; | ||
120 | } | ||
121 | if ((peer0 == GNUNET_YES) && (peer1 = GNUNET_YES) && (GNUNET_NO == done)) | ||
122 | { | ||
123 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
124 | "Done\n"); | ||
125 | done = GNUNET_YES; | ||
126 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
127 | |||
128 | } | ||
129 | } | ||
130 | |||
131 | |||
132 | static int | ||
133 | stat_cb(void *cls, const char *subsystem, | ||
134 | const char *name, uint64_t value, | ||
135 | int is_persistent) | ||
136 | { | ||
137 | |||
138 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", | ||
139 | subsystem,name, value); | ||
140 | if (4 == value) | ||
141 | { | ||
142 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
143 | "All addresses added\n"); | ||
144 | } | ||
145 | |||
146 | return GNUNET_OK; | ||
147 | |||
148 | } | ||
149 | |||
150 | |||
151 | static void | ||
152 | address_suggest_cb (void *cls, | ||
153 | const struct GNUNET_PeerIdentity *peer, | ||
154 | const struct GNUNET_HELLO_Address *address, | ||
155 | struct Session *session, | ||
156 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
157 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
158 | |||
159 | { | ||
160 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); | ||
161 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
162 | } | ||
163 | |||
164 | |||
165 | static void | ||
166 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
167 | { | ||
168 | die_task = NULL; | ||
169 | end ( NULL, NULL); | ||
170 | ret = GNUNET_SYSERR; | ||
171 | } | ||
172 | |||
173 | static void | ||
174 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
175 | { | ||
176 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | ||
177 | if (die_task != NULL ) | ||
178 | { | ||
179 | GNUNET_SCHEDULER_cancel (die_task); | ||
180 | die_task = NULL; | ||
181 | } | ||
182 | |||
183 | if (NULL != sched_ats) | ||
184 | { | ||
185 | GNUNET_ATS_scheduling_done (sched_ats); | ||
186 | sched_ats = NULL; | ||
187 | } | ||
188 | |||
189 | if (NULL != perf_ats) | ||
190 | { | ||
191 | GNUNET_ATS_performance_done (perf_ats); | ||
192 | perf_ats = NULL; | ||
193 | } | ||
194 | |||
195 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
196 | if (NULL != stats) | ||
197 | { | ||
198 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
199 | stats = NULL; | ||
200 | } | ||
201 | |||
202 | |||
203 | GNUNET_free_non_null(p0_addresses[0].addr); | ||
204 | GNUNET_free_non_null(p0_addresses[1].addr); | ||
205 | GNUNET_free_non_null(p1_addresses[0].addr); | ||
206 | GNUNET_free_non_null(p1_addresses[1].addr); | ||
207 | |||
208 | ret = 0; | ||
209 | } | ||
210 | |||
211 | static void | ||
212 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | ||
213 | struct GNUNET_TESTING_Peer *peer) | ||
214 | { | ||
215 | ret = 1; | ||
216 | cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; | ||
217 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); | ||
218 | |||
219 | if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, &ats_perf_cb, NULL))) | ||
220 | { | ||
221 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
222 | "Failed to connect to performance API\n"); | ||
223 | GNUNET_SCHEDULER_add_now (end_badly, NULL); | ||
224 | } | ||
225 | |||
226 | |||
227 | stats = GNUNET_STATISTICS_create ("ats", cfg); | ||
228 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
229 | |||
230 | /* set up peer 0 */ | ||
231 | memset (&p[0].id, '1', sizeof (p[0].id)); | ||
232 | p0_addresses[0].plugin = "test"; | ||
233 | p0_addresses[0].session = NULL; | ||
234 | p0_addresses[0].addr = GNUNET_strdup ("test_p0_a0"); | ||
235 | p0_addresses[0].addr_len = strlen (p0_addresses[0].addr) + 1; | ||
236 | |||
237 | p0_ha[0].address = p0_addresses[0].addr; | ||
238 | p0_ha[0].address_length = p0_addresses[0].addr_len; | ||
239 | p0_ha[0].peer = p[0].id; | ||
240 | p0_ha[0].transport_name = p0_addresses[0].plugin; | ||
241 | |||
242 | p0_addresses[1].plugin = "test"; | ||
243 | p0_addresses[1].session = NULL; | ||
244 | p0_addresses[1].addr = GNUNET_strdup ("test_p0_a1"); | ||
245 | p0_addresses[1].addr_len = strlen (p0_addresses[1].addr) + 1; | ||
246 | |||
247 | p0_ha[1].address = p0_addresses[1].addr; | ||
248 | p0_ha[1].address_length = p0_addresses[1].addr_len; | ||
249 | p0_ha[1].peer = p[0].id; | ||
250 | p0_ha[1].transport_name = p0_addresses[1].plugin; | ||
251 | |||
252 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 0: `%s'\n", | ||
253 | GNUNET_i2s (&p[0].id)); | ||
254 | |||
255 | memset (&p[1].id, '2', sizeof (p[1].id)); | ||
256 | p1_addresses[0].plugin = "test"; | ||
257 | p1_addresses[0].session = NULL; | ||
258 | p1_addresses[0].addr = GNUNET_strdup ("test_p1_a0"); | ||
259 | p1_addresses[0].addr_len = strlen (p1_addresses[0].addr) + 1; | ||
260 | |||
261 | p1_ha[0].address = p1_addresses[0].addr; | ||
262 | p1_ha[0].address_length = p1_addresses[0].addr_len; | ||
263 | p1_ha[0].peer = p[1].id; | ||
264 | p1_ha[0].transport_name = p1_addresses[0].plugin; | ||
265 | |||
266 | p1_addresses[1].plugin = "test"; | ||
267 | p1_addresses[1].session = NULL; | ||
268 | p1_addresses[1].addr = GNUNET_strdup ("test_p1_a1"); | ||
269 | p1_addresses[1].addr_len = strlen (p1_addresses[1].addr) + 1; | ||
270 | |||
271 | p1_ha[1].address = p1_addresses[1].addr; | ||
272 | p1_ha[1].address_length = p1_addresses[1].addr_len; | ||
273 | p1_ha[1].peer = p[1].id; | ||
274 | p1_ha[1].transport_name = p1_addresses[1].plugin; | ||
275 | |||
276 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 1: `%s'\n", | ||
277 | GNUNET_i2s (&p[1].id)); | ||
278 | |||
279 | /* Add addresses */ | ||
280 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL ); | ||
281 | if (sched_ats == NULL ) | ||
282 | { | ||
283 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); | ||
284 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
285 | return; | ||
286 | } | ||
287 | |||
288 | GNUNET_ATS_address_add (sched_ats, &p0_ha[0], NULL, NULL, 0); | ||
289 | GNUNET_ATS_address_add (sched_ats, &p0_ha[1], NULL, NULL, 0); | ||
290 | |||
291 | GNUNET_ATS_address_add (sched_ats, &p1_ha[0], NULL, NULL, 0); | ||
292 | GNUNET_ATS_address_add (sched_ats, &p1_ha[1], NULL, NULL, 0); | ||
293 | } | ||
294 | |||
295 | int | ||
296 | main (int argc, char *argv[]) | ||
297 | { | ||
298 | if (0 | ||
299 | != GNUNET_TESTING_peer_run ("test_ats_api_performance", | ||
300 | "test_ats_api_delayed.conf", &run, NULL )) | ||
301 | return 1; | ||
302 | return ret; | ||
303 | } | ||
304 | |||
305 | /* end of file test_ats_api_delayed_service_performance_monitor.c */ | ||
diff --git a/src/ats/test_ats_api_delayed_service_scheduling_add_address.c b/src/ats/test_ats_api_delayed_service_scheduling_add_address.c deleted file mode 100644 index f08812341..000000000 --- a/src/ats/test_ats_api_delayed_service_scheduling_add_address.c +++ /dev/null | |||
@@ -1,240 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010,2011 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_api_delayed_service_scheduling_add_address.c | ||
22 | * @brief test case to ensure messages are transmitted to ATS service when | ||
23 | * service startup is delayed | ||
24 | * @author Christian Grothoff | ||
25 | * @author Matthias Wachs | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_ats_service.h" | ||
29 | #include "gnunet_testing_lib.h" | ||
30 | #include "ats.h" | ||
31 | #include "test_ats_api_common.h" | ||
32 | |||
33 | /** | ||
34 | * Timeout task | ||
35 | */ | ||
36 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
37 | |||
38 | /** | ||
39 | * Statistics handle | ||
40 | */ | ||
41 | static struct GNUNET_STATISTICS_Handle *stats; | ||
42 | |||
43 | /** | ||
44 | * Scheduling handle | ||
45 | */ | ||
46 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
47 | |||
48 | /** | ||
49 | * Return value | ||
50 | */ | ||
51 | static int ret; | ||
52 | |||
53 | /** | ||
54 | * Test address | ||
55 | */ | ||
56 | static struct Test_Address test_addr; | ||
57 | |||
58 | /** | ||
59 | * Test peer | ||
60 | */ | ||
61 | static struct PeerContext p; | ||
62 | |||
63 | /** | ||
64 | * HELLO address | ||
65 | */ | ||
66 | static struct GNUNET_HELLO_Address test_hello_address; | ||
67 | |||
68 | /** | ||
69 | * Session | ||
70 | */ | ||
71 | static void *test_session; | ||
72 | |||
73 | /** | ||
74 | * Test ats info | ||
75 | */ | ||
76 | static struct GNUNET_ATS_Information test_ats_info[2]; | ||
77 | |||
78 | /** | ||
79 | * Test ats count | ||
80 | */ | ||
81 | static uint32_t test_ats_count; | ||
82 | |||
83 | |||
84 | static void | ||
85 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
86 | |||
87 | |||
88 | static int | ||
89 | stat_cb(void *cls, const char *subsystem, | ||
90 | const char *name, uint64_t value, | ||
91 | int is_persistent) | ||
92 | { | ||
93 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
94 | "ATS statistics: `%s' `%s' %llu\n", | ||
95 | subsystem, | ||
96 | name, | ||
97 | value); | ||
98 | if (1 == value) | ||
99 | { | ||
100 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
101 | } | ||
102 | return GNUNET_OK; | ||
103 | } | ||
104 | |||
105 | |||
106 | static void | ||
107 | end (void *cls, | ||
108 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
109 | { | ||
110 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | ||
111 | |||
112 | if (die_task != NULL) | ||
113 | { | ||
114 | GNUNET_SCHEDULER_cancel (die_task); | ||
115 | die_task = NULL; | ||
116 | } | ||
117 | |||
118 | if (NULL != sched_ats) | ||
119 | { | ||
120 | GNUNET_ATS_scheduling_done (sched_ats); | ||
121 | sched_ats = NULL; | ||
122 | } | ||
123 | |||
124 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
125 | if (NULL != stats) | ||
126 | { | ||
127 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
128 | stats = NULL; | ||
129 | } | ||
130 | |||
131 | free_test_address (&test_addr); | ||
132 | |||
133 | ret = 0; | ||
134 | } | ||
135 | |||
136 | |||
137 | static void | ||
138 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
139 | { | ||
140 | die_task = NULL; | ||
141 | end ( NULL, NULL); | ||
142 | ret = GNUNET_SYSERR; | ||
143 | } | ||
144 | |||
145 | |||
146 | static void | ||
147 | address_suggest_cb (void *cls, | ||
148 | const struct GNUNET_PeerIdentity *peer, | ||
149 | const struct GNUNET_HELLO_Address *address, | ||
150 | struct Session *session, | ||
151 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
152 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
153 | { | ||
154 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); | ||
155 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
156 | } | ||
157 | |||
158 | |||
159 | static void | ||
160 | got_initial_value (void *cls, int success) | ||
161 | { | ||
162 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
163 | |||
164 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got initial value\n"); | ||
165 | |||
166 | /* Connect to ATS scheduling */ | ||
167 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); | ||
168 | if (sched_ats == NULL) | ||
169 | { | ||
170 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); | ||
171 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
172 | return; | ||
173 | } | ||
174 | |||
175 | /* Set up peer */ | ||
176 | memset (&p.id, '1', sizeof (p.id)); | ||
177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", | ||
178 | GNUNET_i2s_full(&p.id)); | ||
179 | |||
180 | /* Prepare ATS Information */ | ||
181 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
182 | test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); | ||
183 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
184 | test_ats_info[1].value = htonl(1); | ||
185 | test_ats_count = 2; | ||
186 | |||
187 | /* Adding address without session */ | ||
188 | test_session = NULL; | ||
189 | create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); | ||
190 | test_hello_address.peer = p.id; | ||
191 | test_hello_address.transport_name = test_addr.plugin; | ||
192 | test_hello_address.address = test_addr.addr; | ||
193 | test_hello_address.address_length = test_addr.addr_len; | ||
194 | |||
195 | /* Adding address */ | ||
196 | GNUNET_ATS_address_add (sched_ats, | ||
197 | &test_hello_address, | ||
198 | test_session, | ||
199 | test_ats_info, test_ats_count); | ||
200 | } | ||
201 | |||
202 | |||
203 | static int | ||
204 | dummy_stat (void *cls, const char *subsystem, const char *name, uint64_t value, | ||
205 | int is_persistent) | ||
206 | { | ||
207 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got dummy stat %s%s:%s = %llu\n", | ||
208 | is_persistent ? "!" : " ", subsystem, name, value); | ||
209 | return GNUNET_OK; | ||
210 | } | ||
211 | |||
212 | |||
213 | static void | ||
214 | run (void *cls, | ||
215 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
216 | struct GNUNET_TESTING_Peer *peer) | ||
217 | { | ||
218 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
219 | stats = GNUNET_STATISTICS_create ("ats", cfg); | ||
220 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
221 | |||
222 | GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT, | ||
223 | &got_initial_value, &dummy_stat, | ||
224 | GNUNET_CONFIGURATION_dup (cfg)); | ||
225 | |||
226 | } | ||
227 | |||
228 | |||
229 | int | ||
230 | main (int argc, char *argv[]) | ||
231 | { | ||
232 | ret = 0; | ||
233 | if (0 != GNUNET_TESTING_peer_run ("test-ats-api", | ||
234 | "test_ats_api_delayed.conf", | ||
235 | &run, NULL)) | ||
236 | return 1; | ||
237 | return ret; | ||
238 | } | ||
239 | |||
240 | /* end of file test_ats_api_delayed_service_scheduling_add_address.c */ | ||
diff --git a/src/ats/test_ats_api_mlp.conf b/src/ats/test_ats_api_mlp.conf new file mode 100644 index 000000000..cabd5e71c --- /dev/null +++ b/src/ats/test_ats_api_mlp.conf | |||
@@ -0,0 +1,45 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | ||
2 | |||
3 | [PATHS] | ||
4 | GNUNET_TEST_HOME = /tmp/test-ats-mlp/ | ||
5 | |||
6 | [ats] | ||
7 | # Enable MLP mode (default: NO) | ||
8 | MODE = mlp | ||
9 | # Network specific inbound/outbound quotas | ||
10 | # UNSPECIFIED | ||
11 | UNSPECIFIED_QUOTA_IN = unlimited | ||
12 | UNSPECIFIED_QUOTA_OUT = unlimited | ||
13 | # LOOPBACK | ||
14 | LOOPBACK_QUOTA_IN = unlimited | ||
15 | LOOPBACK_QUOTA_OUT = unlimited | ||
16 | # LAN | ||
17 | LAN_QUOTA_IN = unlimited | ||
18 | LAN_QUOTA_OUT = unlimited | ||
19 | # WAN | ||
20 | WAN_QUOTA_IN = 64 KiB | ||
21 | WAN_QUOTA_OUT = 64 KiB | ||
22 | # WLAN | ||
23 | WLAN_QUOTA_IN = 4096 | ||
24 | WLAN_QUOTA_OUT = 4096 | ||
25 | |||
26 | # MLP specific settings | ||
27 | ATS_MIN_INTERVAL = 15000 | ||
28 | ATS_EXEC_INTERVAL = 30000 | ||
29 | |||
30 | # MLP defaults | ||
31 | # MLP_MAX_DURATION = 3 s | ||
32 | # MLP_MAX_ITERATIONS = 1024 | ||
33 | # MLP_COEFFICIENT_D = 1.0 | ||
34 | # MLP_COEFFICIENT_U = 1.0 | ||
35 | # MLP_COEFFICIENT_R = 1.0 | ||
36 | # MLP_MIN_BANDWIDTH = 1024 | ||
37 | # MLP_MIN_CONNECTIONS = 4 | ||
38 | |||
39 | # MLP Debugging settings | ||
40 | DUMP_MLP = NO | ||
41 | DUMP_SOLUTION = NO | ||
42 | DUMP_OVERWRITE = NO | ||
43 | DUMP_MIN_PEERS = 0 | ||
44 | DUMP_MIN_ADDRS = 0 | ||
45 | DUMP_OVERWRITE = NO | ||
diff --git a/src/ats/test_ats_api_performance_list_all_addresses.c b/src/ats/test_ats_api_performance_list_all_addresses.c deleted file mode 100644 index 4c09a8948..000000000 --- a/src/ats/test_ats_api_performance_list_all_addresses.c +++ /dev/null | |||
@@ -1,312 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010,2011 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_api_performance_list_addresses.c | ||
22 | * @brief test performance API's address listing feature | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_ats_service.h" | ||
28 | #include "gnunet_testing_lib.h" | ||
29 | #include "ats.h" | ||
30 | |||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
32 | |||
33 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
34 | |||
35 | /** | ||
36 | * Statistics handle | ||
37 | */ | ||
38 | static struct GNUNET_STATISTICS_Handle *stats; | ||
39 | |||
40 | /** | ||
41 | * Configuration handle | ||
42 | */ | ||
43 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
44 | |||
45 | /** | ||
46 | * ATS scheduling handle | ||
47 | */ | ||
48 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
49 | |||
50 | /** | ||
51 | * ATS performance handle | ||
52 | */ | ||
53 | static struct GNUNET_ATS_PerformanceHandle *perf_ats; | ||
54 | |||
55 | static struct GNUNET_ATS_AddressListHandle* phal; | ||
56 | |||
57 | static int ret; | ||
58 | |||
59 | struct Address | ||
60 | { | ||
61 | char *plugin; | ||
62 | size_t plugin_len; | ||
63 | |||
64 | void *addr; | ||
65 | size_t addr_len; | ||
66 | |||
67 | struct GNUNET_ATS_Information *ats; | ||
68 | int ats_count; | ||
69 | |||
70 | void *session; | ||
71 | }; | ||
72 | |||
73 | struct PeerContext | ||
74 | { | ||
75 | struct GNUNET_PeerIdentity id; | ||
76 | |||
77 | struct Address *addr; | ||
78 | }; | ||
79 | |||
80 | static struct PeerContext p[2]; | ||
81 | |||
82 | static struct Address p0_addresses[2]; | ||
83 | static struct Address p1_addresses[2]; | ||
84 | |||
85 | static struct GNUNET_HELLO_Address p0_ha[2]; | ||
86 | static struct GNUNET_HELLO_Address p1_ha[2]; | ||
87 | |||
88 | |||
89 | static void | ||
90 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
91 | |||
92 | static void | ||
93 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
94 | |||
95 | |||
96 | static void | ||
97 | ats_perf_cb (void *cls, | ||
98 | const struct GNUNET_HELLO_Address *address, | ||
99 | int address_active, | ||
100 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
101 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
102 | const struct GNUNET_ATS_Information *ats, | ||
103 | uint32_t ats_count) | ||
104 | { | ||
105 | static int counter = 0; | ||
106 | |||
107 | if (NULL == address) | ||
108 | { | ||
109 | phal = 0; | ||
110 | if (4 == counter) | ||
111 | { | ||
112 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n"); | ||
113 | GNUNET_SCHEDULER_add_now (end, NULL); | ||
114 | } | ||
115 | else | ||
116 | { | ||
117 | GNUNET_break (0); | ||
118 | GNUNET_SCHEDULER_shutdown (); | ||
119 | } | ||
120 | return; | ||
121 | } | ||
122 | counter++; | ||
123 | } | ||
124 | |||
125 | |||
126 | static int | ||
127 | stat_cb(void *cls, const char *subsystem, | ||
128 | const char *name, uint64_t value, | ||
129 | int is_persistent) | ||
130 | { | ||
131 | |||
132 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
133 | "ATS statistics: `%s' `%s' %llu\n", | ||
134 | subsystem,name, value); | ||
135 | if (4 == value) | ||
136 | { | ||
137 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
138 | "All addresses added, connecting to performance\n"); | ||
139 | if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL))) | ||
140 | { | ||
141 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
142 | "Failed to connect to performance API\n"); | ||
143 | GNUNET_SCHEDULER_add_now (end_badly, NULL); | ||
144 | } | ||
145 | phal = GNUNET_ATS_performance_list_addresses (perf_ats, | ||
146 | NULL, | ||
147 | GNUNET_YES, | ||
148 | &ats_perf_cb, NULL); | ||
149 | } | ||
150 | return GNUNET_OK; | ||
151 | } | ||
152 | |||
153 | |||
154 | static void | ||
155 | address_suggest_cb (void *cls, | ||
156 | const struct GNUNET_PeerIdentity *peer, | ||
157 | const struct GNUNET_HELLO_Address *address, | ||
158 | struct Session *session, | ||
159 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
160 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
161 | { | ||
162 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
163 | "Did not expect suggestion callback!\n"); | ||
164 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
165 | } | ||
166 | |||
167 | |||
168 | static void | ||
169 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
170 | { | ||
171 | die_task = NULL; | ||
172 | end ( NULL, NULL); | ||
173 | ret = GNUNET_SYSERR; | ||
174 | } | ||
175 | |||
176 | |||
177 | static void | ||
178 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
179 | { | ||
180 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
181 | "Shutting down\n"); | ||
182 | if (die_task != NULL ) | ||
183 | { | ||
184 | GNUNET_SCHEDULER_cancel (die_task); | ||
185 | die_task = NULL; | ||
186 | } | ||
187 | |||
188 | if (NULL != sched_ats) | ||
189 | { | ||
190 | GNUNET_ATS_scheduling_done (sched_ats); | ||
191 | sched_ats = NULL; | ||
192 | } | ||
193 | |||
194 | if (phal != NULL ) | ||
195 | { | ||
196 | GNUNET_ATS_performance_list_addresses_cancel (phal); | ||
197 | phal = NULL; | ||
198 | } | ||
199 | |||
200 | if (perf_ats != NULL ) | ||
201 | { | ||
202 | GNUNET_ATS_performance_done (perf_ats); | ||
203 | perf_ats = NULL; | ||
204 | } | ||
205 | |||
206 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
207 | if (NULL != stats) | ||
208 | { | ||
209 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
210 | stats = NULL; | ||
211 | } | ||
212 | |||
213 | |||
214 | GNUNET_free_non_null(p0_addresses[0].addr); | ||
215 | GNUNET_free_non_null(p0_addresses[1].addr); | ||
216 | GNUNET_free_non_null(p1_addresses[0].addr); | ||
217 | GNUNET_free_non_null(p1_addresses[1].addr); | ||
218 | |||
219 | ret = 0; | ||
220 | } | ||
221 | |||
222 | |||
223 | static void | ||
224 | run (void *cls, | ||
225 | const struct GNUNET_CONFIGURATION_Handle *mycfg, | ||
226 | struct GNUNET_TESTING_Peer *peer) | ||
227 | { | ||
228 | ret = 1; | ||
229 | cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; | ||
230 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); | ||
231 | |||
232 | stats = GNUNET_STATISTICS_create ("ats", cfg); | ||
233 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
234 | |||
235 | /* set up peer 0 */ | ||
236 | memset (&p[0].id, '1', sizeof (p[0].id)); | ||
237 | p0_addresses[0].plugin = "test"; | ||
238 | p0_addresses[0].session = NULL; | ||
239 | p0_addresses[0].addr = GNUNET_strdup ("test_p0_a0"); | ||
240 | p0_addresses[0].addr_len = strlen (p0_addresses[0].addr) + 1; | ||
241 | |||
242 | p0_ha[0].address = p0_addresses[0].addr; | ||
243 | p0_ha[0].address_length = p0_addresses[0].addr_len; | ||
244 | p0_ha[0].peer = p[0].id; | ||
245 | p0_ha[0].transport_name = p0_addresses[0].plugin; | ||
246 | |||
247 | p0_addresses[1].plugin = "test"; | ||
248 | p0_addresses[1].session = NULL; | ||
249 | p0_addresses[1].addr = GNUNET_strdup ("test_p0_a1"); | ||
250 | p0_addresses[1].addr_len = strlen (p0_addresses[1].addr) + 1; | ||
251 | |||
252 | p0_ha[1].address = p0_addresses[1].addr; | ||
253 | p0_ha[1].address_length = p0_addresses[1].addr_len; | ||
254 | p0_ha[1].peer = p[0].id; | ||
255 | p0_ha[1].transport_name = p0_addresses[1].plugin; | ||
256 | |||
257 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 0: `%s'\n", | ||
258 | GNUNET_i2s (&p[0].id)); | ||
259 | |||
260 | memset (&p[1].id, '2', sizeof (p[1].id)); | ||
261 | p1_addresses[0].plugin = "test"; | ||
262 | p1_addresses[0].session = NULL; | ||
263 | p1_addresses[0].addr = GNUNET_strdup ("test_p1_a0"); | ||
264 | p1_addresses[0].addr_len = strlen (p1_addresses[0].addr) + 1; | ||
265 | |||
266 | p1_ha[0].address = p1_addresses[0].addr; | ||
267 | p1_ha[0].address_length = p1_addresses[0].addr_len; | ||
268 | p1_ha[0].peer = p[1].id; | ||
269 | p1_ha[0].transport_name = p1_addresses[0].plugin; | ||
270 | |||
271 | p1_addresses[1].plugin = "test"; | ||
272 | p1_addresses[1].session = NULL; | ||
273 | p1_addresses[1].addr = GNUNET_strdup ("test_p1_a1"); | ||
274 | p1_addresses[1].addr_len = strlen (p1_addresses[1].addr) + 1; | ||
275 | |||
276 | p1_ha[1].address = p1_addresses[1].addr; | ||
277 | p1_ha[1].address_length = p1_addresses[1].addr_len; | ||
278 | p1_ha[1].peer = p[1].id; | ||
279 | p1_ha[1].transport_name = p1_addresses[1].plugin; | ||
280 | |||
281 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
282 | "Created peer 1: `%s'\n", | ||
283 | GNUNET_i2s (&p[1].id)); | ||
284 | |||
285 | /* Add addresses */ | ||
286 | sched_ats = GNUNET_ATS_scheduling_init (cfg, | ||
287 | &address_suggest_cb, NULL); | ||
288 | if (sched_ats == NULL ) | ||
289 | { | ||
290 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); | ||
291 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
292 | return; | ||
293 | } | ||
294 | |||
295 | GNUNET_ATS_address_add (sched_ats, &p0_ha[0], NULL, NULL, 0); | ||
296 | GNUNET_ATS_address_add (sched_ats, &p0_ha[1], NULL, NULL, 0); | ||
297 | |||
298 | GNUNET_ATS_address_add (sched_ats, &p1_ha[0], NULL, NULL, 0); | ||
299 | GNUNET_ATS_address_add (sched_ats, &p1_ha[1], NULL, NULL, 0); | ||
300 | } | ||
301 | |||
302 | int | ||
303 | main (int argc, char *argv[]) | ||
304 | { | ||
305 | if (0 | ||
306 | != GNUNET_TESTING_peer_run ("test_ats_api_performance", | ||
307 | "test_ats_api.conf", &run, NULL )) | ||
308 | return 1; | ||
309 | return ret; | ||
310 | } | ||
311 | |||
312 | /* end of file test_ats_api_performance_list_addresses.c */ | ||
diff --git a/src/ats/test_ats_api_performance_list_all_addresses_active.c b/src/ats/test_ats_api_performance_list_all_addresses_active.c deleted file mode 100644 index 3c979716f..000000000 --- a/src/ats/test_ats_api_performance_list_all_addresses_active.c +++ /dev/null | |||
@@ -1,307 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010,2011 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_api_performance_list_addresses.c | ||
22 | * @brief test performance API's address listing feature | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_ats_service.h" | ||
28 | #include "gnunet_testing_lib.h" | ||
29 | #include "ats.h" | ||
30 | |||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
32 | |||
33 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
34 | |||
35 | /** | ||
36 | * Statistics handle | ||
37 | */ | ||
38 | static struct GNUNET_STATISTICS_Handle *stats; | ||
39 | |||
40 | /** | ||
41 | * Configuration handle | ||
42 | */ | ||
43 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
44 | |||
45 | /** | ||
46 | * ATS scheduling handle | ||
47 | */ | ||
48 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
49 | |||
50 | /** | ||
51 | * ATS performance handle | ||
52 | */ | ||
53 | static struct GNUNET_ATS_PerformanceHandle *perf_ats; | ||
54 | |||
55 | static struct GNUNET_ATS_AddressListHandle* phal; | ||
56 | |||
57 | static int ret; | ||
58 | |||
59 | struct Address | ||
60 | { | ||
61 | char *plugin; | ||
62 | size_t plugin_len; | ||
63 | |||
64 | void *addr; | ||
65 | size_t addr_len; | ||
66 | |||
67 | struct GNUNET_ATS_Information *ats; | ||
68 | int ats_count; | ||
69 | |||
70 | void *session; | ||
71 | }; | ||
72 | |||
73 | struct PeerContext | ||
74 | { | ||
75 | struct GNUNET_PeerIdentity id; | ||
76 | |||
77 | struct Address *addr; | ||
78 | }; | ||
79 | |||
80 | static struct PeerContext p[2]; | ||
81 | |||
82 | static struct Address p0_addresses[2]; | ||
83 | static struct Address p1_addresses[2]; | ||
84 | |||
85 | static struct GNUNET_HELLO_Address p0_ha[2]; | ||
86 | static struct GNUNET_HELLO_Address p1_ha[2]; | ||
87 | |||
88 | |||
89 | static void | ||
90 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
91 | |||
92 | static void | ||
93 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
94 | |||
95 | |||
96 | static void | ||
97 | ats_perf_cb (void *cls, | ||
98 | const struct GNUNET_HELLO_Address *address, | ||
99 | int address_active, | ||
100 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
101 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
102 | const struct GNUNET_ATS_Information *ats, | ||
103 | uint32_t ats_count) | ||
104 | { | ||
105 | static int counter = 0; | ||
106 | if (NULL == address) | ||
107 | { | ||
108 | phal = 0; | ||
109 | if (0 == counter) | ||
110 | { | ||
111 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n"); | ||
112 | GNUNET_SCHEDULER_add_now (end, NULL); | ||
113 | } | ||
114 | else | ||
115 | { | ||
116 | GNUNET_break (0); | ||
117 | GNUNET_SCHEDULER_add_now (end_badly, NULL); | ||
118 | } | ||
119 | return; | ||
120 | } | ||
121 | else | ||
122 | { | ||
123 | if (0 != memcmp (&address->peer, &p[0].id, sizeof (p[0].id))) | ||
124 | { | ||
125 | GNUNET_break (0); | ||
126 | GNUNET_SCHEDULER_add_now (end_badly, NULL); | ||
127 | } | ||
128 | } | ||
129 | counter ++; | ||
130 | } | ||
131 | |||
132 | |||
133 | static int | ||
134 | stat_cb(void *cls, const char *subsystem, | ||
135 | const char *name, uint64_t value, | ||
136 | int is_persistent) | ||
137 | { | ||
138 | |||
139 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", | ||
140 | subsystem,name, value); | ||
141 | if (4 == value) | ||
142 | { | ||
143 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
144 | "All addresses added, connecting to performance\n"); | ||
145 | if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL))) | ||
146 | { | ||
147 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
148 | "Failed to connect to performance API\n"); | ||
149 | GNUNET_SCHEDULER_add_now (end_badly, NULL); | ||
150 | } | ||
151 | phal = GNUNET_ATS_performance_list_addresses (perf_ats, &p[0].id, GNUNET_NO, ats_perf_cb, NULL); | ||
152 | } | ||
153 | return GNUNET_OK; | ||
154 | } | ||
155 | |||
156 | static void | ||
157 | address_suggest_cb (void *cls, | ||
158 | const struct GNUNET_PeerIdentity *peer, | ||
159 | const struct GNUNET_HELLO_Address *address, | ||
160 | struct Session *session, | ||
161 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
162 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
163 | { | ||
164 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); | ||
165 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
166 | } | ||
167 | |||
168 | |||
169 | static void | ||
170 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
171 | { | ||
172 | die_task = NULL; | ||
173 | end ( NULL, NULL); | ||
174 | ret = GNUNET_SYSERR; | ||
175 | } | ||
176 | |||
177 | static void | ||
178 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
179 | { | ||
180 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | ||
181 | if (die_task != NULL ) | ||
182 | { | ||
183 | GNUNET_SCHEDULER_cancel (die_task); | ||
184 | die_task = NULL; | ||
185 | } | ||
186 | |||
187 | if (NULL != sched_ats) | ||
188 | { | ||
189 | GNUNET_ATS_scheduling_done (sched_ats); | ||
190 | sched_ats = NULL; | ||
191 | } | ||
192 | |||
193 | if (phal != NULL ) | ||
194 | { | ||
195 | GNUNET_ATS_performance_list_addresses_cancel (phal); | ||
196 | phal = NULL; | ||
197 | } | ||
198 | |||
199 | if (perf_ats != NULL ) | ||
200 | { | ||
201 | GNUNET_ATS_performance_done (perf_ats); | ||
202 | perf_ats = NULL; | ||
203 | } | ||
204 | |||
205 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
206 | if (NULL != stats) | ||
207 | { | ||
208 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
209 | stats = NULL; | ||
210 | } | ||
211 | GNUNET_free_non_null(p0_addresses[0].addr); | ||
212 | GNUNET_free_non_null(p0_addresses[1].addr); | ||
213 | GNUNET_free_non_null(p1_addresses[0].addr); | ||
214 | GNUNET_free_non_null(p1_addresses[1].addr); | ||
215 | |||
216 | ret = 0; | ||
217 | } | ||
218 | |||
219 | |||
220 | |||
221 | static void | ||
222 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | ||
223 | struct GNUNET_TESTING_Peer *peer) | ||
224 | { | ||
225 | ret = 1; | ||
226 | cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; | ||
227 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); | ||
228 | |||
229 | stats = GNUNET_STATISTICS_create ("ats", cfg); | ||
230 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
231 | |||
232 | /* set up peer 0 */ | ||
233 | memset (&p[0].id, '1', sizeof (p[0].id)); | ||
234 | p0_addresses[0].plugin = "test"; | ||
235 | p0_addresses[0].session = NULL; | ||
236 | p0_addresses[0].addr = GNUNET_strdup ("test_p0_a0"); | ||
237 | p0_addresses[0].addr_len = strlen (p0_addresses[0].addr) + 1; | ||
238 | |||
239 | p0_ha[0].address = p0_addresses[0].addr; | ||
240 | p0_ha[0].address_length = p0_addresses[0].addr_len; | ||
241 | p0_ha[0].peer = p[0].id; | ||
242 | p0_ha[0].transport_name = p0_addresses[0].plugin; | ||
243 | |||
244 | p0_addresses[1].plugin = "test"; | ||
245 | p0_addresses[1].session = NULL; | ||
246 | p0_addresses[1].addr = GNUNET_strdup ("test_p0_a1"); | ||
247 | p0_addresses[1].addr_len = strlen (p0_addresses[1].addr) + 1; | ||
248 | |||
249 | p0_ha[1].address = p0_addresses[1].addr; | ||
250 | p0_ha[1].address_length = p0_addresses[1].addr_len; | ||
251 | p0_ha[1].peer = p[0].id; | ||
252 | p0_ha[1].transport_name = p0_addresses[1].plugin; | ||
253 | |||
254 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 0: `%s'\n", | ||
255 | GNUNET_i2s (&p[0].id)); | ||
256 | |||
257 | memset (&p[1].id, '2', sizeof (p[1].id)); | ||
258 | p1_addresses[0].plugin = "test"; | ||
259 | p1_addresses[0].session = NULL; | ||
260 | p1_addresses[0].addr = GNUNET_strdup ("test_p1_a0"); | ||
261 | p1_addresses[0].addr_len = strlen (p1_addresses[0].addr) + 1; | ||
262 | |||
263 | p1_ha[0].address = p1_addresses[0].addr; | ||
264 | p1_ha[0].address_length = p1_addresses[0].addr_len; | ||
265 | p1_ha[0].peer = p[1].id; | ||
266 | p1_ha[0].transport_name = p1_addresses[0].plugin; | ||
267 | |||
268 | p1_addresses[1].plugin = "test"; | ||
269 | p1_addresses[1].session = NULL; | ||
270 | p1_addresses[1].addr = GNUNET_strdup ("test_p1_a1"); | ||
271 | p1_addresses[1].addr_len = strlen (p1_addresses[1].addr) + 1; | ||
272 | |||
273 | p1_ha[1].address = p1_addresses[1].addr; | ||
274 | p1_ha[1].address_length = p1_addresses[1].addr_len; | ||
275 | p1_ha[1].peer = p[1].id; | ||
276 | p1_ha[1].transport_name = p1_addresses[1].plugin; | ||
277 | |||
278 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 1: `%s'\n", | ||
279 | GNUNET_i2s (&p[1].id)); | ||
280 | |||
281 | /* Add addresses */ | ||
282 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL ); | ||
283 | if (sched_ats == NULL ) | ||
284 | { | ||
285 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); | ||
286 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
287 | return; | ||
288 | } | ||
289 | |||
290 | GNUNET_ATS_address_add (sched_ats, &p0_ha[0], NULL, NULL, 0); | ||
291 | GNUNET_ATS_address_add (sched_ats, &p0_ha[1], NULL, NULL, 0); | ||
292 | |||
293 | GNUNET_ATS_address_add (sched_ats, &p1_ha[0], NULL, NULL, 0); | ||
294 | GNUNET_ATS_address_add (sched_ats, &p1_ha[1], NULL, NULL, 0); | ||
295 | } | ||
296 | |||
297 | int | ||
298 | main (int argc, char *argv[]) | ||
299 | { | ||
300 | if (0 | ||
301 | != GNUNET_TESTING_peer_run ("test_ats_api_performance", | ||
302 | "test_ats_api.conf", &run, NULL )) | ||
303 | return 1; | ||
304 | return ret; | ||
305 | } | ||
306 | |||
307 | /* end of file test_ats_api_performance_list_addresses.c */ | ||
diff --git a/src/ats/test_ats_api_performance_list_peer_addresses.c b/src/ats/test_ats_api_performance_list_peer_addresses.c deleted file mode 100644 index 7e3f87745..000000000 --- a/src/ats/test_ats_api_performance_list_peer_addresses.c +++ /dev/null | |||
@@ -1,331 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010,2011 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_api_performance_list_addresses.c | ||
22 | * @brief test performance API's address listing feature | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_ats_service.h" | ||
28 | #include "gnunet_testing_lib.h" | ||
29 | #include "ats.h" | ||
30 | |||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
32 | |||
33 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
34 | |||
35 | /** | ||
36 | * Statistics handle | ||
37 | */ | ||
38 | static struct GNUNET_STATISTICS_Handle *stats; | ||
39 | |||
40 | /** | ||
41 | * Configuration handle | ||
42 | */ | ||
43 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
44 | |||
45 | /** | ||
46 | * ATS scheduling handle | ||
47 | */ | ||
48 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
49 | |||
50 | /** | ||
51 | * ATS performance handle | ||
52 | */ | ||
53 | static struct GNUNET_ATS_PerformanceHandle *perf_ats; | ||
54 | |||
55 | static struct GNUNET_ATS_AddressListHandle* phal; | ||
56 | |||
57 | static int ret; | ||
58 | |||
59 | |||
60 | struct Address | ||
61 | { | ||
62 | char *plugin; | ||
63 | size_t plugin_len; | ||
64 | |||
65 | void *addr; | ||
66 | size_t addr_len; | ||
67 | |||
68 | struct GNUNET_ATS_Information *ats; | ||
69 | int ats_count; | ||
70 | |||
71 | void *session; | ||
72 | }; | ||
73 | |||
74 | |||
75 | struct PeerContext | ||
76 | { | ||
77 | struct GNUNET_PeerIdentity id; | ||
78 | |||
79 | struct Address *addr; | ||
80 | }; | ||
81 | |||
82 | |||
83 | static struct PeerContext p[2]; | ||
84 | |||
85 | static struct Address p0_addresses[2]; | ||
86 | static struct Address p1_addresses[2]; | ||
87 | |||
88 | static struct GNUNET_HELLO_Address p0_ha[2]; | ||
89 | static struct GNUNET_HELLO_Address p1_ha[2]; | ||
90 | |||
91 | |||
92 | static void | ||
93 | end (void *cls, | ||
94 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
95 | |||
96 | |||
97 | static void | ||
98 | ats_perf_cb (void *cls, | ||
99 | const struct GNUNET_HELLO_Address *address, | ||
100 | int address_active, | ||
101 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
102 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
103 | const struct GNUNET_ATS_Information *ats, | ||
104 | uint32_t ats_count) | ||
105 | { | ||
106 | static int counter = 0; | ||
107 | |||
108 | if (NULL == address) | ||
109 | { | ||
110 | phal = NULL; | ||
111 | if (2 == counter) | ||
112 | { | ||
113 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
114 | "Done\n"); | ||
115 | GNUNET_SCHEDULER_add_now (&end, | ||
116 | NULL); | ||
117 | } | ||
118 | else | ||
119 | { | ||
120 | fprintf (stderr, | ||
121 | "Expected 2 addresses, got %d\n", | ||
122 | counter); | ||
123 | GNUNET_break (0); | ||
124 | GNUNET_SCHEDULER_shutdown (); | ||
125 | } | ||
126 | return; | ||
127 | } | ||
128 | else | ||
129 | { | ||
130 | if (0 != memcmp (&address->peer, &p[0].id, sizeof (p[0].id))) | ||
131 | { | ||
132 | GNUNET_break (0); | ||
133 | GNUNET_SCHEDULER_shutdown (); | ||
134 | return; | ||
135 | } | ||
136 | } | ||
137 | counter ++; | ||
138 | } | ||
139 | |||
140 | |||
141 | static int | ||
142 | stat_cb (void *cls, const char *subsystem, | ||
143 | const char *name, uint64_t value, | ||
144 | int is_persistent) | ||
145 | { | ||
146 | |||
147 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
148 | "ATS statistics: `%s' `%s' %llu\n", | ||
149 | subsystem, | ||
150 | name, | ||
151 | value); | ||
152 | if (4 == value) | ||
153 | { | ||
154 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
155 | "All addresses added, connecting to performance\n"); | ||
156 | if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL))) | ||
157 | { | ||
158 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
159 | "Failed to connect to performance API\n"); | ||
160 | GNUNET_SCHEDULER_shutdown (); | ||
161 | return GNUNET_SYSERR; | ||
162 | } | ||
163 | phal = GNUNET_ATS_performance_list_addresses (perf_ats, | ||
164 | &p[0].id, | ||
165 | GNUNET_YES, | ||
166 | &ats_perf_cb, NULL); | ||
167 | } | ||
168 | return GNUNET_OK; | ||
169 | } | ||
170 | |||
171 | |||
172 | static void | ||
173 | end (void *cls, | ||
174 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
175 | { | ||
176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
177 | "Shutting down\n"); | ||
178 | if (die_task != NULL ) | ||
179 | { | ||
180 | GNUNET_SCHEDULER_cancel (die_task); | ||
181 | die_task = NULL; | ||
182 | } | ||
183 | if (NULL != sched_ats) | ||
184 | { | ||
185 | GNUNET_ATS_scheduling_done (sched_ats); | ||
186 | sched_ats = NULL; | ||
187 | } | ||
188 | if (NULL != phal) | ||
189 | { | ||
190 | GNUNET_ATS_performance_list_addresses_cancel (phal); | ||
191 | phal = NULL; | ||
192 | } | ||
193 | if (NULL != perf_ats) | ||
194 | { | ||
195 | GNUNET_ATS_performance_done (perf_ats); | ||
196 | perf_ats = NULL; | ||
197 | } | ||
198 | |||
199 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
200 | if (NULL != stats) | ||
201 | { | ||
202 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
203 | stats = NULL; | ||
204 | } | ||
205 | GNUNET_free_non_null (p0_addresses[0].addr); | ||
206 | GNUNET_free_non_null (p0_addresses[1].addr); | ||
207 | GNUNET_free_non_null (p1_addresses[0].addr); | ||
208 | GNUNET_free_non_null (p1_addresses[1].addr); | ||
209 | |||
210 | ret = 0; | ||
211 | } | ||
212 | |||
213 | |||
214 | static void | ||
215 | end_badly (void *cls, | ||
216 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
217 | { | ||
218 | die_task = NULL; | ||
219 | end (NULL, NULL); | ||
220 | ret = GNUNET_SYSERR; | ||
221 | } | ||
222 | |||
223 | |||
224 | static void | ||
225 | address_suggest_cb (void *cls, | ||
226 | const struct GNUNET_PeerIdentity *peer, | ||
227 | const struct GNUNET_HELLO_Address *address, | ||
228 | struct Session *session, | ||
229 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
230 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
231 | { | ||
232 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
233 | "Did not expect suggestion callback!\n"); | ||
234 | GNUNET_SCHEDULER_shutdown (); | ||
235 | } | ||
236 | |||
237 | |||
238 | static void | ||
239 | run (void *cls, | ||
240 | const struct GNUNET_CONFIGURATION_Handle *mycfg, | ||
241 | struct GNUNET_TESTING_Peer *peer) | ||
242 | { | ||
243 | ret = 1; | ||
244 | cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; | ||
245 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); | ||
246 | |||
247 | stats = GNUNET_STATISTICS_create ("ats", cfg); | ||
248 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
249 | |||
250 | /* set up peer 0 */ | ||
251 | memset (&p[0].id, '1', sizeof (p[0].id)); | ||
252 | p0_addresses[0].plugin = "test"; | ||
253 | p0_addresses[0].session = NULL; | ||
254 | p0_addresses[0].addr = GNUNET_strdup ("test_p0_a0"); | ||
255 | p0_addresses[0].addr_len = strlen (p0_addresses[0].addr) + 1; | ||
256 | |||
257 | p0_ha[0].address = p0_addresses[0].addr; | ||
258 | p0_ha[0].address_length = p0_addresses[0].addr_len; | ||
259 | p0_ha[0].peer = p[0].id; | ||
260 | p0_ha[0].transport_name = p0_addresses[0].plugin; | ||
261 | |||
262 | p0_addresses[1].plugin = "test"; | ||
263 | p0_addresses[1].session = NULL; | ||
264 | p0_addresses[1].addr = GNUNET_strdup ("test_p0_a1"); | ||
265 | p0_addresses[1].addr_len = strlen (p0_addresses[1].addr) + 1; | ||
266 | |||
267 | p0_ha[1].address = p0_addresses[1].addr; | ||
268 | p0_ha[1].address_length = p0_addresses[1].addr_len; | ||
269 | p0_ha[1].peer = p[0].id; | ||
270 | p0_ha[1].transport_name = p0_addresses[1].plugin; | ||
271 | |||
272 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
273 | "Created peer 0: `%s'\n", | ||
274 | GNUNET_i2s (&p[0].id)); | ||
275 | |||
276 | memset (&p[1].id, '2', sizeof (p[1].id)); | ||
277 | p1_addresses[0].plugin = "test"; | ||
278 | p1_addresses[0].session = NULL; | ||
279 | p1_addresses[0].addr = GNUNET_strdup ("test_p1_a0"); | ||
280 | p1_addresses[0].addr_len = strlen (p1_addresses[0].addr) + 1; | ||
281 | |||
282 | p1_ha[0].address = p1_addresses[0].addr; | ||
283 | p1_ha[0].address_length = p1_addresses[0].addr_len; | ||
284 | p1_ha[0].peer = p[1].id; | ||
285 | p1_ha[0].transport_name = p1_addresses[0].plugin; | ||
286 | |||
287 | p1_addresses[1].plugin = "test"; | ||
288 | p1_addresses[1].session = NULL; | ||
289 | p1_addresses[1].addr = GNUNET_strdup ("test_p1_a1"); | ||
290 | p1_addresses[1].addr_len = strlen (p1_addresses[1].addr) + 1; | ||
291 | |||
292 | p1_ha[1].address = p1_addresses[1].addr; | ||
293 | p1_ha[1].address_length = p1_addresses[1].addr_len; | ||
294 | p1_ha[1].peer = p[1].id; | ||
295 | p1_ha[1].transport_name = p1_addresses[1].plugin; | ||
296 | |||
297 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
298 | "Created peer 1: `%s'\n", | ||
299 | GNUNET_i2s (&p[1].id)); | ||
300 | |||
301 | /* Add addresses */ | ||
302 | sched_ats = GNUNET_ATS_scheduling_init (cfg, | ||
303 | &address_suggest_cb, NULL); | ||
304 | if (NULL == sched_ats) | ||
305 | { | ||
306 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
307 | "Could not setup peer!\n"); | ||
308 | GNUNET_SCHEDULER_shutdown (); | ||
309 | return; | ||
310 | } | ||
311 | |||
312 | GNUNET_ATS_address_add (sched_ats, &p0_ha[0], NULL, NULL, 0); | ||
313 | GNUNET_ATS_address_add (sched_ats, &p0_ha[1], NULL, NULL, 0); | ||
314 | |||
315 | GNUNET_ATS_address_add (sched_ats, &p1_ha[0], NULL, NULL, 0); | ||
316 | GNUNET_ATS_address_add (sched_ats, &p1_ha[1], NULL, NULL, 0); | ||
317 | } | ||
318 | |||
319 | |||
320 | int | ||
321 | main (int argc, char *argv[]) | ||
322 | { | ||
323 | if (0 != | ||
324 | GNUNET_TESTING_peer_run ("test_ats_api_performance", | ||
325 | "test_ats_api.conf", | ||
326 | &run, NULL)) | ||
327 | return 1; | ||
328 | return ret; | ||
329 | } | ||
330 | |||
331 | /* end of file test_ats_api_performance_list_addresses.c */ | ||
diff --git a/src/ats/test_ats_api_performance_monitor.c b/src/ats/test_ats_api_performance_monitor.c deleted file mode 100644 index 700615451..000000000 --- a/src/ats/test_ats_api_performance_monitor.c +++ /dev/null | |||
@@ -1,301 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010,2011 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_api_performance_monitor.c | ||
22 | * @brief test performance API's address monitor feature | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_ats_service.h" | ||
28 | #include "gnunet_testing_lib.h" | ||
29 | #include "ats.h" | ||
30 | |||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
32 | #define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
33 | |||
34 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
35 | |||
36 | /** | ||
37 | * Statistics handle | ||
38 | */ | ||
39 | static struct GNUNET_STATISTICS_Handle *stats; | ||
40 | |||
41 | /** | ||
42 | * Configuration handle | ||
43 | */ | ||
44 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
45 | |||
46 | /** | ||
47 | * ATS scheduling handle | ||
48 | */ | ||
49 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
50 | |||
51 | /** | ||
52 | * ATS performance handle | ||
53 | */ | ||
54 | static struct GNUNET_ATS_PerformanceHandle *perf_ats; | ||
55 | |||
56 | static int ret; | ||
57 | |||
58 | struct Address | ||
59 | { | ||
60 | char *plugin; | ||
61 | size_t plugin_len; | ||
62 | |||
63 | void *addr; | ||
64 | size_t addr_len; | ||
65 | |||
66 | struct GNUNET_ATS_Information *ats; | ||
67 | int ats_count; | ||
68 | |||
69 | void *session; | ||
70 | }; | ||
71 | |||
72 | struct PeerContext | ||
73 | { | ||
74 | struct GNUNET_PeerIdentity id; | ||
75 | |||
76 | struct Address *addr; | ||
77 | }; | ||
78 | |||
79 | static struct PeerContext p[2]; | ||
80 | |||
81 | static struct Address p0_addresses[2]; | ||
82 | static struct Address p1_addresses[2]; | ||
83 | |||
84 | static struct GNUNET_HELLO_Address p0_ha[2]; | ||
85 | static struct GNUNET_HELLO_Address p1_ha[2]; | ||
86 | |||
87 | static void | ||
88 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
89 | |||
90 | static void | ||
91 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
92 | |||
93 | |||
94 | static void | ||
95 | ats_perf_cb (void *cls, | ||
96 | const struct GNUNET_HELLO_Address *address, | ||
97 | int address_active, | ||
98 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
99 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
100 | const struct GNUNET_ATS_Information *ats, | ||
101 | uint32_t ats_count) | ||
102 | { | ||
103 | static int peer0 = GNUNET_NO; | ||
104 | static int peer1 = GNUNET_NO; | ||
105 | static int done = GNUNET_NO; | ||
106 | |||
107 | if (NULL == address) | ||
108 | return; | ||
109 | |||
110 | if ((GNUNET_NO == peer0) && (0 == memcmp (address, &p[0].id, sizeof (p[0].id)))) | ||
111 | { | ||
112 | peer0 = GNUNET_YES; | ||
113 | } | ||
114 | if ((GNUNET_NO == peer0) && (0 == memcmp (address, &p[1].id, sizeof (p[1].id)))) | ||
115 | { | ||
116 | peer1 = GNUNET_YES; | ||
117 | } | ||
118 | if ((peer0 == GNUNET_YES) && (peer1 = GNUNET_YES) && (GNUNET_NO == done)) | ||
119 | { | ||
120 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
121 | "Done\n"); | ||
122 | done = GNUNET_YES; | ||
123 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
124 | |||
125 | } | ||
126 | } | ||
127 | |||
128 | |||
129 | static int | ||
130 | stat_cb(void *cls, const char *subsystem, | ||
131 | const char *name, uint64_t value, | ||
132 | int is_persistent) | ||
133 | { | ||
134 | |||
135 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", | ||
136 | subsystem,name, value); | ||
137 | if (4 == value) | ||
138 | { | ||
139 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
140 | "All addresses added\n"); | ||
141 | } | ||
142 | |||
143 | return GNUNET_OK; | ||
144 | |||
145 | } | ||
146 | |||
147 | static void | ||
148 | address_suggest_cb (void *cls, | ||
149 | const struct GNUNET_PeerIdentity *peer, | ||
150 | const struct GNUNET_HELLO_Address *address, | ||
151 | struct Session *session, | ||
152 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
153 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
154 | |||
155 | { | ||
156 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); | ||
157 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
158 | } | ||
159 | |||
160 | |||
161 | static void | ||
162 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
163 | { | ||
164 | die_task = NULL; | ||
165 | end ( NULL, NULL); | ||
166 | ret = GNUNET_SYSERR; | ||
167 | } | ||
168 | |||
169 | static void | ||
170 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
171 | { | ||
172 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | ||
173 | if (die_task != NULL ) | ||
174 | { | ||
175 | GNUNET_SCHEDULER_cancel (die_task); | ||
176 | die_task = NULL; | ||
177 | } | ||
178 | |||
179 | if (NULL != sched_ats) | ||
180 | { | ||
181 | GNUNET_ATS_scheduling_done (sched_ats); | ||
182 | sched_ats = NULL; | ||
183 | } | ||
184 | |||
185 | if (NULL != perf_ats) | ||
186 | { | ||
187 | GNUNET_ATS_performance_done (perf_ats); | ||
188 | perf_ats = NULL; | ||
189 | } | ||
190 | |||
191 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
192 | if (NULL != stats) | ||
193 | { | ||
194 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
195 | stats = NULL; | ||
196 | } | ||
197 | |||
198 | |||
199 | GNUNET_free_non_null(p0_addresses[0].addr); | ||
200 | GNUNET_free_non_null(p0_addresses[1].addr); | ||
201 | GNUNET_free_non_null(p1_addresses[0].addr); | ||
202 | GNUNET_free_non_null(p1_addresses[1].addr); | ||
203 | |||
204 | ret = 0; | ||
205 | } | ||
206 | |||
207 | static void | ||
208 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | ||
209 | struct GNUNET_TESTING_Peer *peer) | ||
210 | { | ||
211 | ret = 1; | ||
212 | cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; | ||
213 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); | ||
214 | |||
215 | if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, &ats_perf_cb, NULL))) | ||
216 | { | ||
217 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
218 | "Failed to connect to performance API\n"); | ||
219 | GNUNET_SCHEDULER_add_now (end_badly, NULL); | ||
220 | } | ||
221 | |||
222 | |||
223 | stats = GNUNET_STATISTICS_create ("ats", cfg); | ||
224 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
225 | |||
226 | /* set up peer 0 */ | ||
227 | memset (&p[0].id, '1', sizeof (p[0].id)); | ||
228 | p0_addresses[0].plugin = "test"; | ||
229 | p0_addresses[0].session = NULL; | ||
230 | p0_addresses[0].addr = GNUNET_strdup ("test_p0_a0"); | ||
231 | p0_addresses[0].addr_len = strlen (p0_addresses[0].addr) + 1; | ||
232 | |||
233 | p0_ha[0].address = p0_addresses[0].addr; | ||
234 | p0_ha[0].address_length = p0_addresses[0].addr_len; | ||
235 | p0_ha[0].peer = p[0].id; | ||
236 | p0_ha[0].transport_name = p0_addresses[0].plugin; | ||
237 | |||
238 | p0_addresses[1].plugin = "test"; | ||
239 | p0_addresses[1].session = NULL; | ||
240 | p0_addresses[1].addr = GNUNET_strdup ("test_p0_a1"); | ||
241 | p0_addresses[1].addr_len = strlen (p0_addresses[1].addr) + 1; | ||
242 | |||
243 | p0_ha[1].address = p0_addresses[1].addr; | ||
244 | p0_ha[1].address_length = p0_addresses[1].addr_len; | ||
245 | p0_ha[1].peer = p[0].id; | ||
246 | p0_ha[1].transport_name = p0_addresses[1].plugin; | ||
247 | |||
248 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 0: `%s'\n", | ||
249 | GNUNET_i2s (&p[0].id)); | ||
250 | |||
251 | memset (&p[1].id, '2', sizeof (p[1].id)); | ||
252 | p1_addresses[0].plugin = "test"; | ||
253 | p1_addresses[0].session = NULL; | ||
254 | p1_addresses[0].addr = GNUNET_strdup ("test_p1_a0"); | ||
255 | p1_addresses[0].addr_len = strlen (p1_addresses[0].addr) + 1; | ||
256 | |||
257 | p1_ha[0].address = p1_addresses[0].addr; | ||
258 | p1_ha[0].address_length = p1_addresses[0].addr_len; | ||
259 | p1_ha[0].peer = p[1].id; | ||
260 | p1_ha[0].transport_name = p1_addresses[0].plugin; | ||
261 | |||
262 | p1_addresses[1].plugin = "test"; | ||
263 | p1_addresses[1].session = NULL; | ||
264 | p1_addresses[1].addr = GNUNET_strdup ("test_p1_a1"); | ||
265 | p1_addresses[1].addr_len = strlen (p1_addresses[1].addr) + 1; | ||
266 | |||
267 | p1_ha[1].address = p1_addresses[1].addr; | ||
268 | p1_ha[1].address_length = p1_addresses[1].addr_len; | ||
269 | p1_ha[1].peer = p[1].id; | ||
270 | p1_ha[1].transport_name = p1_addresses[1].plugin; | ||
271 | |||
272 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 1: `%s'\n", | ||
273 | GNUNET_i2s (&p[1].id)); | ||
274 | |||
275 | /* Add addresses */ | ||
276 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL ); | ||
277 | if (sched_ats == NULL ) | ||
278 | { | ||
279 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); | ||
280 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
281 | return; | ||
282 | } | ||
283 | |||
284 | GNUNET_ATS_address_add (sched_ats, &p0_ha[0], NULL, NULL, 0); | ||
285 | GNUNET_ATS_address_add (sched_ats, &p0_ha[1], NULL, NULL, 0); | ||
286 | |||
287 | GNUNET_ATS_address_add (sched_ats, &p1_ha[0], NULL, NULL, 0); | ||
288 | GNUNET_ATS_address_add (sched_ats, &p1_ha[1], NULL, NULL, 0); | ||
289 | } | ||
290 | |||
291 | int | ||
292 | main (int argc, char *argv[]) | ||
293 | { | ||
294 | if (0 | ||
295 | != GNUNET_TESTING_peer_run ("test_ats_api_performance", | ||
296 | "test_ats_api.conf", &run, NULL )) | ||
297 | return 1; | ||
298 | return ret; | ||
299 | } | ||
300 | |||
301 | /* end of file test_ats_api_performance_monitor.c */ | ||
diff --git a/src/ats/test_ats_api_performance_monitor_initial_callback.c b/src/ats/test_ats_api_performance_monitor_initial_callback.c deleted file mode 100644 index 1e1af8821..000000000 --- a/src/ats/test_ats_api_performance_monitor_initial_callback.c +++ /dev/null | |||
@@ -1,302 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010,2011 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_api_performance_monitor.c | ||
22 | * @brief test performance API's address monitor feature | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_ats_service.h" | ||
28 | #include "gnunet_testing_lib.h" | ||
29 | #include "ats.h" | ||
30 | |||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
32 | #define WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
33 | |||
34 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
35 | |||
36 | /** | ||
37 | * Statistics handle | ||
38 | */ | ||
39 | static struct GNUNET_STATISTICS_Handle *stats; | ||
40 | |||
41 | /** | ||
42 | * Configuration handle | ||
43 | */ | ||
44 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
45 | |||
46 | /** | ||
47 | * ATS scheduling handle | ||
48 | */ | ||
49 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
50 | |||
51 | /** | ||
52 | * ATS performance handle | ||
53 | */ | ||
54 | static struct GNUNET_ATS_PerformanceHandle *perf_ats; | ||
55 | |||
56 | static int ret; | ||
57 | |||
58 | |||
59 | struct Address | ||
60 | { | ||
61 | char *plugin; | ||
62 | size_t plugin_len; | ||
63 | |||
64 | void *addr; | ||
65 | size_t addr_len; | ||
66 | |||
67 | struct GNUNET_ATS_Information *ats; | ||
68 | int ats_count; | ||
69 | |||
70 | void *session; | ||
71 | }; | ||
72 | |||
73 | struct PeerContext | ||
74 | { | ||
75 | struct GNUNET_PeerIdentity id; | ||
76 | |||
77 | struct Address *addr; | ||
78 | }; | ||
79 | |||
80 | static struct PeerContext p[2]; | ||
81 | |||
82 | static struct Address p0_addresses[2]; | ||
83 | static struct Address p1_addresses[2]; | ||
84 | |||
85 | struct GNUNET_HELLO_Address p0_ha[2]; | ||
86 | struct GNUNET_HELLO_Address p1_ha[2]; | ||
87 | struct GNUNET_HELLO_Address *s_ha[2]; | ||
88 | |||
89 | static void | ||
90 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
91 | |||
92 | static void | ||
93 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
94 | |||
95 | |||
96 | static void | ||
97 | ats_perf_cb (void *cls, | ||
98 | const struct GNUNET_HELLO_Address *address, | ||
99 | int address_active, | ||
100 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
101 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
102 | const struct GNUNET_ATS_Information *ats, | ||
103 | uint32_t ats_count) | ||
104 | { | ||
105 | static int peer0 = GNUNET_NO; | ||
106 | static int peer1 = GNUNET_NO; | ||
107 | static int done = GNUNET_NO; | ||
108 | |||
109 | if (NULL == address) | ||
110 | return; | ||
111 | |||
112 | if (0 == memcmp (&address->peer, &p[0].id, sizeof (p[0].id))) | ||
113 | { | ||
114 | peer0 ++; | ||
115 | } | ||
116 | if (0 == memcmp (&address->peer, &p[1].id, sizeof (p[1].id))) | ||
117 | { | ||
118 | peer1 ++; | ||
119 | } | ||
120 | if ((2 == peer0) && (2 == peer1) && (GNUNET_NO == done)) | ||
121 | { | ||
122 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
123 | "Done\n"); | ||
124 | done = GNUNET_YES; | ||
125 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
126 | |||
127 | } | ||
128 | } | ||
129 | |||
130 | |||
131 | static int | ||
132 | stat_cb(void *cls, const char *subsystem, | ||
133 | const char *name, uint64_t value, | ||
134 | int is_persistent) | ||
135 | { | ||
136 | |||
137 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", | ||
138 | subsystem,name, value); | ||
139 | if (4 == value) | ||
140 | { | ||
141 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
142 | "All addresses added\n"); | ||
143 | |||
144 | if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, &ats_perf_cb, NULL))) | ||
145 | { | ||
146 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
147 | "Failed to connect to performance API\n"); | ||
148 | GNUNET_SCHEDULER_add_now (end_badly, NULL); | ||
149 | } | ||
150 | } | ||
151 | |||
152 | return GNUNET_OK; | ||
153 | |||
154 | } | ||
155 | |||
156 | static void | ||
157 | address_suggest_cb (void *cls, | ||
158 | const struct GNUNET_PeerIdentity *peer, | ||
159 | const struct GNUNET_HELLO_Address *address, | ||
160 | struct Session *session, | ||
161 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
162 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
163 | |||
164 | { | ||
165 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); | ||
166 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
167 | } | ||
168 | |||
169 | |||
170 | static void | ||
171 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
172 | { | ||
173 | die_task = NULL; | ||
174 | end ( NULL, NULL); | ||
175 | ret = GNUNET_SYSERR; | ||
176 | } | ||
177 | |||
178 | static void | ||
179 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
180 | { | ||
181 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | ||
182 | if (die_task != NULL ) | ||
183 | { | ||
184 | GNUNET_SCHEDULER_cancel (die_task); | ||
185 | die_task = NULL; | ||
186 | } | ||
187 | |||
188 | if (NULL != sched_ats) | ||
189 | { | ||
190 | GNUNET_ATS_scheduling_done (sched_ats); | ||
191 | sched_ats = NULL; | ||
192 | } | ||
193 | |||
194 | if (NULL != perf_ats) | ||
195 | { | ||
196 | GNUNET_ATS_performance_done (perf_ats); | ||
197 | perf_ats = NULL; | ||
198 | } | ||
199 | |||
200 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
201 | if (NULL != stats) | ||
202 | { | ||
203 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
204 | stats = NULL; | ||
205 | } | ||
206 | |||
207 | |||
208 | GNUNET_free_non_null(p0_addresses[0].addr); | ||
209 | GNUNET_free_non_null(p0_addresses[1].addr); | ||
210 | GNUNET_free_non_null(p1_addresses[0].addr); | ||
211 | GNUNET_free_non_null(p1_addresses[1].addr); | ||
212 | |||
213 | ret = 0; | ||
214 | } | ||
215 | |||
216 | static void | ||
217 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | ||
218 | struct GNUNET_TESTING_Peer *peer) | ||
219 | { | ||
220 | ret = 1; | ||
221 | cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; | ||
222 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); | ||
223 | |||
224 | stats = GNUNET_STATISTICS_create ("ats", cfg); | ||
225 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
226 | |||
227 | /* set up peer 0 */ | ||
228 | memset (&p[0].id, '1', sizeof (p[0].id)); | ||
229 | p0_addresses[0].plugin = "test"; | ||
230 | p0_addresses[0].session = NULL; | ||
231 | p0_addresses[0].addr = GNUNET_strdup ("test_p0_a0"); | ||
232 | p0_addresses[0].addr_len = strlen (p0_addresses[0].addr) + 1; | ||
233 | |||
234 | p0_ha[0].address = p0_addresses[0].addr; | ||
235 | p0_ha[0].address_length = p0_addresses[0].addr_len; | ||
236 | p0_ha[0].peer = p[0].id; | ||
237 | p0_ha[0].transport_name = p0_addresses[0].plugin; | ||
238 | |||
239 | p0_addresses[1].plugin = "test"; | ||
240 | p0_addresses[1].session = NULL; | ||
241 | p0_addresses[1].addr = GNUNET_strdup ("test_p0_a1"); | ||
242 | p0_addresses[1].addr_len = strlen (p0_addresses[1].addr) + 1; | ||
243 | |||
244 | p0_ha[1].address = p0_addresses[1].addr; | ||
245 | p0_ha[1].address_length = p0_addresses[1].addr_len; | ||
246 | p0_ha[1].peer = p[0].id; | ||
247 | p0_ha[1].transport_name = p0_addresses[1].plugin; | ||
248 | |||
249 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 0: `%s'\n", | ||
250 | GNUNET_i2s (&p[0].id)); | ||
251 | |||
252 | memset (&p[1].id, '2', sizeof (p[1].id)); | ||
253 | p1_addresses[0].plugin = "test"; | ||
254 | p1_addresses[0].session = NULL; | ||
255 | p1_addresses[0].addr = GNUNET_strdup ("test_p1_a0"); | ||
256 | p1_addresses[0].addr_len = strlen (p1_addresses[0].addr) + 1; | ||
257 | |||
258 | p1_ha[0].address = p1_addresses[0].addr; | ||
259 | p1_ha[0].address_length = p1_addresses[0].addr_len; | ||
260 | p1_ha[0].peer = p[1].id; | ||
261 | p1_ha[0].transport_name = p1_addresses[0].plugin; | ||
262 | |||
263 | p1_addresses[1].plugin = "test"; | ||
264 | p1_addresses[1].session = NULL; | ||
265 | p1_addresses[1].addr = GNUNET_strdup ("test_p1_a1"); | ||
266 | p1_addresses[1].addr_len = strlen (p1_addresses[1].addr) + 1; | ||
267 | |||
268 | p1_ha[1].address = p1_addresses[1].addr; | ||
269 | p1_ha[1].address_length = p1_addresses[1].addr_len; | ||
270 | p1_ha[1].peer = p[1].id; | ||
271 | p1_ha[1].transport_name = p1_addresses[1].plugin; | ||
272 | |||
273 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 1: `%s'\n", | ||
274 | GNUNET_i2s (&p[1].id)); | ||
275 | |||
276 | /* Add addresses */ | ||
277 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL ); | ||
278 | if (sched_ats == NULL ) | ||
279 | { | ||
280 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); | ||
281 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
282 | return; | ||
283 | } | ||
284 | |||
285 | GNUNET_ATS_address_add (sched_ats, &p0_ha[0], NULL, NULL, 0); | ||
286 | GNUNET_ATS_address_add (sched_ats, &p0_ha[1], NULL, NULL, 0); | ||
287 | |||
288 | GNUNET_ATS_address_add (sched_ats, &p1_ha[0], NULL, NULL, 0); | ||
289 | GNUNET_ATS_address_add (sched_ats, &p1_ha[1], NULL, NULL, 0); | ||
290 | } | ||
291 | |||
292 | int | ||
293 | main (int argc, char *argv[]) | ||
294 | { | ||
295 | if (0 | ||
296 | != GNUNET_TESTING_peer_run ("test_ats_api_performance", | ||
297 | "test_ats_api.conf", &run, NULL )) | ||
298 | return 1; | ||
299 | return ret; | ||
300 | } | ||
301 | |||
302 | /* end of file test_ats_api_performance_monitor.c */ | ||
diff --git a/src/ats/test_ats_api_proportional.conf b/src/ats/test_ats_api_proportional.conf new file mode 100644 index 000000000..4f277e79f --- /dev/null +++ b/src/ats/test_ats_api_proportional.conf | |||
@@ -0,0 +1,24 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | ||
2 | |||
3 | [PATHS] | ||
4 | GNUNET_TEST_HOME = /tmp/test-ats-proportional/ | ||
5 | |||
6 | [ats] | ||
7 | # Enable PROPORTIONAL mode (default: NO) | ||
8 | MODE = proportional | ||
9 | # Network specific inbound/outbound quotas | ||
10 | # UNSPECIFIED | ||
11 | UNSPECIFIED_QUOTA_IN = unlimited | ||
12 | UNSPECIFIED_QUOTA_OUT = unlimited | ||
13 | # LOOPBACK | ||
14 | LOOPBACK_QUOTA_IN = unlimited | ||
15 | LOOPBACK_QUOTA_OUT = unlimited | ||
16 | # LAN | ||
17 | LAN_QUOTA_IN = unlimited | ||
18 | LAN_QUOTA_OUT = unlimited | ||
19 | # WAN | ||
20 | WAN_QUOTA_IN = 64 KiB | ||
21 | WAN_QUOTA_OUT = 64 KiB | ||
22 | # WLAN | ||
23 | WLAN_QUOTA_IN = 4096 | ||
24 | WLAN_QUOTA_OUT = 4096 | ||
diff --git a/src/ats/test_ats_api_ril.conf b/src/ats/test_ats_api_ril.conf new file mode 100644 index 000000000..0a424c458 --- /dev/null +++ b/src/ats/test_ats_api_ril.conf | |||
@@ -0,0 +1,24 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | ||
2 | |||
3 | [PATHS] | ||
4 | GNUNET_TEST_HOME = /tmp/test-ats-ril/ | ||
5 | |||
6 | [ats] | ||
7 | # Enable RIL mode (default: NO) | ||
8 | MODE = ril | ||
9 | # Network specific inbound/outbound quotas | ||
10 | # UNSPECIFIED | ||
11 | UNSPECIFIED_QUOTA_IN = unlimited | ||
12 | UNSPECIFIED_QUOTA_OUT = unlimited | ||
13 | # LOOPBACK | ||
14 | LOOPBACK_QUOTA_IN = unlimited | ||
15 | LOOPBACK_QUOTA_OUT = unlimited | ||
16 | # LAN | ||
17 | LAN_QUOTA_IN = unlimited | ||
18 | LAN_QUOTA_OUT = unlimited | ||
19 | # WAN | ||
20 | WAN_QUOTA_IN = 64 KiB | ||
21 | WAN_QUOTA_OUT = 64 KiB | ||
22 | # WLAN | ||
23 | WLAN_QUOTA_IN = 4096 | ||
24 | WLAN_QUOTA_OUT = 4096 | ||
diff --git a/src/ats/test_ats_api_scheduling_add_address.c b/src/ats/test_ats_api_scheduling_add_address.c deleted file mode 100644 index 7abd76e0d..000000000 --- a/src/ats/test_ats_api_scheduling_add_address.c +++ /dev/null | |||
@@ -1,231 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010,2011 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_api_scheduling_add_address.c | ||
22 | * @brief adding addresses with scheduling API | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_ats_service.h" | ||
28 | #include "gnunet_testing_lib.h" | ||
29 | #include "ats.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 | 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 | 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 | struct GNUNET_ATS_Information test_ats_info[2]; | ||
76 | |||
77 | /** | ||
78 | * Test ats count | ||
79 | */ | ||
80 | uint32_t test_ats_count; | ||
81 | |||
82 | |||
83 | static void end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
84 | |||
85 | static int | ||
86 | stat_cb(void *cls, const char *subsystem, | ||
87 | const char *name, uint64_t value, | ||
88 | int is_persistent) | ||
89 | { | ||
90 | |||
91 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", | ||
92 | subsystem,name, value); | ||
93 | if (1 == value) | ||
94 | { | ||
95 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
96 | } | ||
97 | return GNUNET_OK; | ||
98 | } | ||
99 | |||
100 | |||
101 | static void | ||
102 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
103 | { | ||
104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | ||
105 | |||
106 | if (die_task != NULL) | ||
107 | { | ||
108 | GNUNET_SCHEDULER_cancel (die_task); | ||
109 | die_task = NULL; | ||
110 | } | ||
111 | |||
112 | if (NULL != sched_ats) | ||
113 | { | ||
114 | GNUNET_ATS_scheduling_done (sched_ats); | ||
115 | sched_ats = NULL; | ||
116 | } | ||
117 | |||
118 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
119 | if (NULL != stats) | ||
120 | { | ||
121 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
122 | stats = NULL; | ||
123 | } | ||
124 | |||
125 | free_test_address (&test_addr); | ||
126 | |||
127 | ret = 0; | ||
128 | } | ||
129 | |||
130 | static void | ||
131 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
132 | { | ||
133 | die_task = NULL; | ||
134 | end ( NULL, NULL); | ||
135 | ret = GNUNET_SYSERR; | ||
136 | } | ||
137 | |||
138 | |||
139 | static void | ||
140 | address_suggest_cb (void *cls, | ||
141 | const struct GNUNET_PeerIdentity *peer, | ||
142 | const struct GNUNET_HELLO_Address *address, | ||
143 | struct Session *session, | ||
144 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
145 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
146 | { | ||
147 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); | ||
148 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
149 | } | ||
150 | |||
151 | |||
152 | static void | ||
153 | got_initial_value (void *cls, int success) | ||
154 | { | ||
155 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
156 | |||
157 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got initial value\n"); | ||
158 | |||
159 | /* Connect to ATS scheduling */ | ||
160 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); | ||
161 | if (sched_ats == NULL) | ||
162 | { | ||
163 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); | ||
164 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
165 | return; | ||
166 | } | ||
167 | |||
168 | /* Set up peer */ | ||
169 | memset (&p.id, '1', sizeof (p.id)); | ||
170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", | ||
171 | GNUNET_i2s_full(&p.id)); | ||
172 | |||
173 | /* Prepare ATS Information */ | ||
174 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
175 | test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); | ||
176 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
177 | test_ats_info[1].value = htonl(1); | ||
178 | test_ats_count = 2; | ||
179 | |||
180 | /* Adding address without session */ | ||
181 | test_session = NULL; | ||
182 | create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); | ||
183 | test_hello_address.peer = p.id; | ||
184 | test_hello_address.transport_name = test_addr.plugin; | ||
185 | test_hello_address.address = test_addr.addr; | ||
186 | test_hello_address.address_length = test_addr.addr_len; | ||
187 | |||
188 | /* Adding address */ | ||
189 | GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, test_ats_info, test_ats_count); | ||
190 | |||
191 | } | ||
192 | |||
193 | |||
194 | static int | ||
195 | dummy_stat (void *cls, const char *subsystem, const char *name, uint64_t value, | ||
196 | int is_persistent) | ||
197 | { | ||
198 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got dummy stat %s%s:%s = %llu\n", | ||
199 | is_persistent ? "!" : " ", subsystem, name, value); | ||
200 | return GNUNET_OK; | ||
201 | } | ||
202 | |||
203 | |||
204 | static void | ||
205 | run (void *cls, | ||
206 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
207 | struct GNUNET_TESTING_Peer *peer) | ||
208 | { | ||
209 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
210 | stats = GNUNET_STATISTICS_create ("ats", cfg); | ||
211 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
212 | |||
213 | GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT, | ||
214 | &got_initial_value, &dummy_stat, | ||
215 | GNUNET_CONFIGURATION_dup (cfg)); | ||
216 | |||
217 | } | ||
218 | |||
219 | |||
220 | int | ||
221 | main (int argc, char *argv[]) | ||
222 | { | ||
223 | ret = 0; | ||
224 | if (0 != GNUNET_TESTING_peer_run ("test-ats-api", | ||
225 | "test_ats_api.conf", | ||
226 | &run, NULL)) | ||
227 | return 1; | ||
228 | return ret; | ||
229 | } | ||
230 | |||
231 | /* end of file test_ats_api_scheduling_add_address.c */ | ||
diff --git a/src/ats/test_ats_api_scheduling_add_address_duplicate.c b/src/ats/test_ats_api_scheduling_add_address_duplicate.c deleted file mode 100644 index 9cb456636..000000000 --- a/src/ats/test_ats_api_scheduling_add_address_duplicate.c +++ /dev/null | |||
@@ -1,266 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010,2011 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_api_scheduling_add_address.c | ||
22 | * @brief adding same addresses twice with scheduling API | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_ats_service.h" | ||
28 | #include "gnunet_testing_lib.h" | ||
29 | #include "ats.h" | ||
30 | #include "test_ats_api_common.h" | ||
31 | |||
32 | /** | ||
33 | * Timeout task | ||
34 | */ | ||
35 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
36 | |||
37 | static struct GNUNET_SCHEDULER_Task * wait_task; | ||
38 | |||
39 | /** | ||
40 | * Statistics handle | ||
41 | */ | ||
42 | static struct GNUNET_STATISTICS_Handle *stats; | ||
43 | |||
44 | /** | ||
45 | * Scheduling handle | ||
46 | */ | ||
47 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
48 | |||
49 | /** | ||
50 | * Return value | ||
51 | */ | ||
52 | static int ret; | ||
53 | |||
54 | /** | ||
55 | * Test address | ||
56 | */ | ||
57 | static struct Test_Address test_addr; | ||
58 | |||
59 | /** | ||
60 | * Test peer | ||
61 | */ | ||
62 | static struct PeerContext p; | ||
63 | |||
64 | /** | ||
65 | * HELLO address | ||
66 | */ | ||
67 | static struct GNUNET_HELLO_Address test_hello_address; | ||
68 | |||
69 | /** | ||
70 | * Session | ||
71 | */ | ||
72 | static void *test_session; | ||
73 | |||
74 | /** | ||
75 | * Test ats info | ||
76 | */ | ||
77 | static struct GNUNET_ATS_Information test_ats_info[2]; | ||
78 | |||
79 | /** | ||
80 | * Test ats count | ||
81 | */ | ||
82 | static uint32_t test_ats_count; | ||
83 | |||
84 | |||
85 | static void | ||
86 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
87 | |||
88 | |||
89 | static void | ||
90 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
91 | |||
92 | |||
93 | static int | ||
94 | stat_cb (void *cls, const char *subsystem, | ||
95 | const char *name, uint64_t value, | ||
96 | int is_persistent) | ||
97 | { | ||
98 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
99 | "ATS statistics: `%s' `%s' %llu\n", | ||
100 | subsystem,name, value); | ||
101 | if (1 < value) | ||
102 | { | ||
103 | if (NULL != wait_task) | ||
104 | GNUNET_SCHEDULER_cancel (wait_task); | ||
105 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
106 | } | ||
107 | if (1 == value) | ||
108 | { | ||
109 | if (NULL == wait_task) | ||
110 | wait_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
111 | &end, NULL); | ||
112 | } | ||
113 | return GNUNET_OK; | ||
114 | } | ||
115 | |||
116 | |||
117 | static void | ||
118 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
119 | { | ||
120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
121 | "Shutting down\n"); | ||
122 | wait_task = NULL; | ||
123 | |||
124 | if (NULL != die_task) | ||
125 | { | ||
126 | GNUNET_SCHEDULER_cancel (die_task); | ||
127 | die_task = NULL; | ||
128 | } | ||
129 | if (NULL != sched_ats) | ||
130 | { | ||
131 | GNUNET_ATS_scheduling_done (sched_ats); | ||
132 | sched_ats = NULL; | ||
133 | } | ||
134 | |||
135 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
136 | if (NULL != stats) | ||
137 | { | ||
138 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
139 | stats = NULL; | ||
140 | } | ||
141 | |||
142 | free_test_address (&test_addr); | ||
143 | |||
144 | ret = 0; | ||
145 | } | ||
146 | |||
147 | |||
148 | static void | ||
149 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
150 | { | ||
151 | die_task = NULL; | ||
152 | end ( NULL, NULL); | ||
153 | ret = GNUNET_SYSERR; | ||
154 | } | ||
155 | |||
156 | |||
157 | static void | ||
158 | address_suggest_cb (void *cls, | ||
159 | const struct GNUNET_PeerIdentity *peer, | ||
160 | const struct GNUNET_HELLO_Address *address, | ||
161 | struct Session *session, | ||
162 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
163 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
164 | { | ||
165 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
166 | "Did not expect suggestion callback!\n"); | ||
167 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
168 | } | ||
169 | |||
170 | |||
171 | static int | ||
172 | dummy_stat (void *cls, | ||
173 | const char *subsystem, | ||
174 | const char *name, | ||
175 | uint64_t value, | ||
176 | int is_persistent) | ||
177 | { | ||
178 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
179 | "Got dummy stat %s%s:%s = %llu\n", | ||
180 | is_persistent ? "!" : " ", subsystem, name, value); | ||
181 | return GNUNET_OK; | ||
182 | } | ||
183 | |||
184 | |||
185 | static void | ||
186 | got_initial_value (void *cls, int success) | ||
187 | { | ||
188 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
189 | struct GNUNET_ATS_AddressRecord *ar; | ||
190 | |||
191 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got initial value\n"); | ||
192 | |||
193 | /* Connect to ATS scheduling */ | ||
194 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); | ||
195 | if (sched_ats == NULL) | ||
196 | { | ||
197 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
198 | "Could not connect to ATS scheduling!\n"); | ||
199 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
200 | return; | ||
201 | } | ||
202 | |||
203 | /* Set up peer */ | ||
204 | memset (&p.id, '1', sizeof (p.id)); | ||
205 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
206 | "Created peer `%s'\n", | ||
207 | GNUNET_i2s_full(&p.id)); | ||
208 | |||
209 | /* Prepare ATS Information */ | ||
210 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
211 | test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); | ||
212 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
213 | test_ats_info[1].value = htonl(1); | ||
214 | test_ats_count = 2; | ||
215 | |||
216 | /* Adding address without session */ | ||
217 | test_session = NULL; | ||
218 | create_test_address (&test_addr, "test", | ||
219 | test_session, "test", | ||
220 | strlen ("test") + 1); | ||
221 | test_hello_address.peer = p.id; | ||
222 | test_hello_address.transport_name = test_addr.plugin; | ||
223 | test_hello_address.address = test_addr.addr; | ||
224 | test_hello_address.address_length = test_addr.addr_len; | ||
225 | |||
226 | /* Adding address */ | ||
227 | GNUNET_ATS_address_add (sched_ats, | ||
228 | &test_hello_address, test_session, | ||
229 | test_ats_info, test_ats_count); | ||
230 | /* Adding duplicate */ | ||
231 | GNUNET_log_skip (1, GNUNET_NO); | ||
232 | ar = GNUNET_ATS_address_add (sched_ats, | ||
233 | &test_hello_address, test_session, | ||
234 | test_ats_info, test_ats_count); | ||
235 | GNUNET_log_skip (0, GNUNET_YES); | ||
236 | GNUNET_assert (NULL == ar); | ||
237 | } | ||
238 | |||
239 | |||
240 | static void | ||
241 | run (void *cls, | ||
242 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
243 | struct GNUNET_TESTING_Peer *peer) | ||
244 | { | ||
245 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
246 | stats = GNUNET_STATISTICS_create ("ats", cfg); | ||
247 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
248 | GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT, | ||
249 | &got_initial_value, &dummy_stat, | ||
250 | GNUNET_CONFIGURATION_dup (cfg)); | ||
251 | |||
252 | } | ||
253 | |||
254 | |||
255 | int | ||
256 | main (int argc, char *argv[]) | ||
257 | { | ||
258 | ret = 0; | ||
259 | if (0 != GNUNET_TESTING_peer_run ("test-ats-api", | ||
260 | "test_ats_api.conf", | ||
261 | &run, NULL)) | ||
262 | return 1; | ||
263 | return ret; | ||
264 | } | ||
265 | |||
266 | /* end of file test_ats_api_scheduling_add_address.c */ | ||
diff --git a/src/ats/test_ats_api_scheduling_add_address_inbound.c b/src/ats/test_ats_api_scheduling_add_address_inbound.c deleted file mode 100644 index aa62b4856..000000000 --- a/src/ats/test_ats_api_scheduling_add_address_inbound.c +++ /dev/null | |||
@@ -1,243 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010,2011 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_api_scheduling_add_address_inbound.c | ||
22 | * @brief adding addresses with scheduling API | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_ats_service.h" | ||
28 | #include "gnunet_testing_lib.h" | ||
29 | #include "ats.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 | * Test ats info | ||
69 | */ | ||
70 | static struct GNUNET_ATS_Information test_ats_info[2]; | ||
71 | |||
72 | /** | ||
73 | * Test ats count | ||
74 | */ | ||
75 | static uint32_t test_ats_count; | ||
76 | |||
77 | |||
78 | static void | ||
79 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
80 | |||
81 | static void | ||
82 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
83 | |||
84 | |||
85 | static int | ||
86 | stat_cb(void *cls, const char *subsystem, | ||
87 | const char *name, uint64_t value, | ||
88 | int is_persistent) | ||
89 | { | ||
90 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", | ||
91 | subsystem,name, value); | ||
92 | if (1 == value) | ||
93 | { | ||
94 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL); | ||
95 | } | ||
96 | if (1 < value) | ||
97 | { | ||
98 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
99 | } | ||
100 | |||
101 | return GNUNET_OK; | ||
102 | } | ||
103 | |||
104 | |||
105 | static void | ||
106 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
107 | { | ||
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | ||
109 | |||
110 | if (die_task != NULL) | ||
111 | { | ||
112 | GNUNET_SCHEDULER_cancel (die_task); | ||
113 | die_task = NULL; | ||
114 | } | ||
115 | |||
116 | if (NULL != sched_ats) | ||
117 | { | ||
118 | GNUNET_ATS_scheduling_done (sched_ats); | ||
119 | sched_ats = NULL; | ||
120 | } | ||
121 | |||
122 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
123 | if (NULL != stats) | ||
124 | { | ||
125 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
126 | stats = NULL; | ||
127 | } | ||
128 | |||
129 | free_test_address (&test_addr); | ||
130 | |||
131 | ret = 0; | ||
132 | } | ||
133 | |||
134 | |||
135 | static void | ||
136 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
137 | { | ||
138 | die_task = NULL; | ||
139 | end ( NULL, NULL); | ||
140 | ret = GNUNET_SYSERR; | ||
141 | } | ||
142 | |||
143 | |||
144 | static void | ||
145 | address_suggest_cb (void *cls, | ||
146 | const struct GNUNET_PeerIdentity *peer, | ||
147 | const struct GNUNET_HELLO_Address *address, | ||
148 | struct Session *session, | ||
149 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
150 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
151 | { | ||
152 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
153 | "Did not expect suggestion callback!\n"); | ||
154 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
155 | } | ||
156 | |||
157 | |||
158 | static void | ||
159 | got_initial_value (void *cls, int success) | ||
160 | { | ||
161 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
162 | |||
163 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got initial value\n"); | ||
164 | /* Connect to ATS scheduling */ | ||
165 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); | ||
166 | if (sched_ats == NULL) | ||
167 | { | ||
168 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); | ||
169 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
170 | return; | ||
171 | } | ||
172 | |||
173 | /* Set up peer */ | ||
174 | memset (&p.id, '1', sizeof (p.id)); | ||
175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", | ||
176 | GNUNET_i2s_full(&p.id)); | ||
177 | |||
178 | /* Prepare ATS Information */ | ||
179 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
180 | test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); | ||
181 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
182 | test_ats_info[1].value = htonl(1); | ||
183 | test_ats_count = 2; | ||
184 | |||
185 | /* Adding address without session */ | ||
186 | create_test_address (&test_addr, "test-plugin", NULL, NULL, 0); | ||
187 | test_hello_address.peer = p.id; | ||
188 | test_hello_address.transport_name = test_addr.plugin; | ||
189 | test_hello_address.address = NULL; | ||
190 | test_hello_address.address_length = 0; | ||
191 | |||
192 | /* Adding address */ | ||
193 | GNUNET_ATS_address_add (sched_ats, | ||
194 | &test_hello_address, NULL, | ||
195 | test_ats_info, test_ats_count); | ||
196 | } | ||
197 | |||
198 | |||
199 | static int | ||
200 | dummy_stat (void *cls, | ||
201 | const char *subsystem, | ||
202 | const char *name, | ||
203 | uint64_t value, | ||
204 | int is_persistent) | ||
205 | { | ||
206 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
207 | "Got dummy stat %s%s:%s = %llu\n", | ||
208 | is_persistent ? "!" : " ", | ||
209 | subsystem, | ||
210 | name, | ||
211 | value); | ||
212 | return GNUNET_OK; | ||
213 | } | ||
214 | |||
215 | |||
216 | static void | ||
217 | run (void *cls, | ||
218 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
219 | struct GNUNET_TESTING_Peer *peer) | ||
220 | { | ||
221 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
222 | stats = GNUNET_STATISTICS_create ("ats", cfg); | ||
223 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
224 | |||
225 | GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT, | ||
226 | &got_initial_value, &dummy_stat, | ||
227 | GNUNET_CONFIGURATION_dup (cfg)); | ||
228 | |||
229 | } | ||
230 | |||
231 | |||
232 | int | ||
233 | main (int argc, char *argv[]) | ||
234 | { | ||
235 | ret = 0; | ||
236 | if (0 != GNUNET_TESTING_peer_run ("test-ats-api", | ||
237 | "test_ats_api.conf", | ||
238 | &run, NULL)) | ||
239 | return 1; | ||
240 | return ret; | ||
241 | } | ||
242 | |||
243 | /* end of file test_ats_api_scheduling_add_address_inbound.c */ | ||
diff --git a/src/ats/test_ats_api_scheduling_add_session.c b/src/ats/test_ats_api_scheduling_add_session.c deleted file mode 100644 index 4b4f22a5d..000000000 --- a/src/ats/test_ats_api_scheduling_add_session.c +++ /dev/null | |||
@@ -1,237 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010,2011 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_api_scheduling_add_session.c | ||
22 | * @brief test adding a session to an existing addresses | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_ats_service.h" | ||
28 | #include "gnunet_testing_lib.h" | ||
29 | #include "ats.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 | * Address record we will modify with a session later. | ||
84 | */ | ||
85 | static struct GNUNET_ATS_AddressRecord *ar; | ||
86 | |||
87 | |||
88 | static void | ||
89 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
90 | |||
91 | |||
92 | static void | ||
93 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
94 | |||
95 | |||
96 | static int | ||
97 | stat_cb (void *cls, const char *subsystem, | ||
98 | const char *name, uint64_t value, | ||
99 | int is_persistent) | ||
100 | { | ||
101 | static int first_stat_cb = GNUNET_YES; | ||
102 | |||
103 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
104 | "ATS statistics: `%s' `%s' %llu\n", | ||
105 | subsystem,name, value); | ||
106 | if ((GNUNET_YES == first_stat_cb) && (1 == value)) | ||
107 | { | ||
108 | GNUNET_ATS_address_add_session (ar, | ||
109 | (struct Session *) &test_session); | ||
110 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL); | ||
111 | } | ||
112 | if ((GNUNET_NO == first_stat_cb) && (1 == value)) | ||
113 | { | ||
114 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
115 | "ATS updated existing address\n"); | ||
116 | } | ||
117 | if (value > 1) | ||
118 | { | ||
119 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
120 | "ATS did not update existing address, but added 2nd address!\n"); | ||
121 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
122 | } | ||
123 | |||
124 | return GNUNET_OK; | ||
125 | } | ||
126 | |||
127 | |||
128 | static void | ||
129 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
130 | { | ||
131 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | ||
132 | |||
133 | if (die_task != NULL) | ||
134 | { | ||
135 | GNUNET_SCHEDULER_cancel (die_task); | ||
136 | die_task = NULL; | ||
137 | } | ||
138 | |||
139 | if (NULL != sched_ats) | ||
140 | { | ||
141 | GNUNET_ATS_scheduling_done (sched_ats); | ||
142 | sched_ats = NULL; | ||
143 | } | ||
144 | |||
145 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
146 | if (NULL != stats) | ||
147 | { | ||
148 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
149 | stats = NULL; | ||
150 | } | ||
151 | |||
152 | free_test_address (&test_addr); | ||
153 | |||
154 | ret = 0; | ||
155 | } | ||
156 | |||
157 | |||
158 | static void | ||
159 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
160 | { | ||
161 | die_task = NULL; | ||
162 | end ( NULL, NULL); | ||
163 | ret = GNUNET_SYSERR; | ||
164 | } | ||
165 | |||
166 | |||
167 | static void | ||
168 | address_suggest_cb (void *cls, | ||
169 | const struct GNUNET_PeerIdentity *peer, | ||
170 | const struct GNUNET_HELLO_Address *address, | ||
171 | struct Session *session, | ||
172 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
173 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
174 | { | ||
175 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); | ||
176 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
177 | } | ||
178 | |||
179 | |||
180 | static void | ||
181 | run (void *cls, | ||
182 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
183 | struct GNUNET_TESTING_Peer *peer) | ||
184 | { | ||
185 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
186 | stats = GNUNET_STATISTICS_create ("ats", cfg); | ||
187 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
188 | |||
189 | |||
190 | /* Connect to ATS scheduling */ | ||
191 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); | ||
192 | if (sched_ats == NULL) | ||
193 | { | ||
194 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); | ||
195 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
196 | return; | ||
197 | } | ||
198 | |||
199 | /* Set up peer */ | ||
200 | memset (&p.id, '1', sizeof (p.id)); | ||
201 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
202 | "Created peer `%s'\n", | ||
203 | GNUNET_i2s_full(&p.id)); | ||
204 | |||
205 | /* Prepare ATS Information */ | ||
206 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
207 | test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); | ||
208 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
209 | test_ats_info[1].value = htonl(1); | ||
210 | test_ats_count = 2; | ||
211 | |||
212 | /* Adding address without session */ | ||
213 | create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); | ||
214 | test_hello_address.peer = p.id; | ||
215 | test_hello_address.transport_name = test_addr.plugin; | ||
216 | test_hello_address.address = test_addr.addr; | ||
217 | test_hello_address.address_length = test_addr.addr_len; | ||
218 | |||
219 | /* Adding address */ | ||
220 | ar = GNUNET_ATS_address_add (sched_ats, | ||
221 | &test_hello_address, NULL, | ||
222 | test_ats_info, test_ats_count); | ||
223 | } | ||
224 | |||
225 | |||
226 | int | ||
227 | main (int argc, char *argv[]) | ||
228 | { | ||
229 | ret = 0; | ||
230 | if (0 != GNUNET_TESTING_peer_run ("test-ats-api", | ||
231 | "test_ats_api.conf", | ||
232 | &run, NULL)) | ||
233 | return 1; | ||
234 | return ret; | ||
235 | } | ||
236 | |||
237 | /* end of file test_ats_api_scheduling_add_session.c */ | ||
diff --git a/src/ats/test_ats_api_scheduling_destroy_address.c b/src/ats/test_ats_api_scheduling_destroy_address.c deleted file mode 100644 index 23321b83b..000000000 --- a/src/ats/test_ats_api_scheduling_destroy_address.c +++ /dev/null | |||
@@ -1,268 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010,2011 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_api_scheduling_destroy_address.c | ||
22 | * @brief test destroying addresses in automatic transport selection scheduling API | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | * | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_ats_service.h" | ||
29 | #include "gnunet_testing_lib.h" | ||
30 | #include "ats.h" | ||
31 | #include "test_ats_api_common.h" | ||
32 | |||
33 | /** | ||
34 | * Timeout task | ||
35 | */ | ||
36 | static struct GNUNET_SCHEDULER_Task *die_task; | ||
37 | |||
38 | /** | ||
39 | * Statistics handle | ||
40 | */ | ||
41 | static struct GNUNET_STATISTICS_Handle *stats; | ||
42 | |||
43 | /** | ||
44 | * Scheduling handle | ||
45 | */ | ||
46 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
47 | |||
48 | /** | ||
49 | * Our address record. | ||
50 | */ | ||
51 | static struct GNUNET_ATS_AddressRecord *ar; | ||
52 | |||
53 | /** | ||
54 | * Return value | ||
55 | */ | ||
56 | static int ret; | ||
57 | |||
58 | /** | ||
59 | * Test address | ||
60 | */ | ||
61 | static struct Test_Address test_addr; | ||
62 | |||
63 | /** | ||
64 | * Test peer | ||
65 | */ | ||
66 | static struct PeerContext p; | ||
67 | |||
68 | /** | ||
69 | * HELLO address | ||
70 | */ | ||
71 | static struct GNUNET_HELLO_Address test_hello_address; | ||
72 | |||
73 | /** | ||
74 | * Session | ||
75 | */ | ||
76 | static void *test_session; | ||
77 | |||
78 | /** | ||
79 | * Test ats info | ||
80 | */ | ||
81 | static struct GNUNET_ATS_Information test_ats_info[2]; | ||
82 | |||
83 | /** | ||
84 | * Test ats count | ||
85 | */ | ||
86 | static uint32_t test_ats_count; | ||
87 | |||
88 | |||
89 | static int | ||
90 | stat_cb (void *cls, const char *subsystem, | ||
91 | const char *name, uint64_t value, | ||
92 | int is_persistent); | ||
93 | |||
94 | |||
95 | static void | ||
96 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
97 | { | ||
98 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | ||
99 | |||
100 | if (NULL != die_task) | ||
101 | { | ||
102 | GNUNET_SCHEDULER_cancel (die_task); | ||
103 | die_task = NULL; | ||
104 | } | ||
105 | if (NULL != sched_ats) | ||
106 | { | ||
107 | GNUNET_ATS_scheduling_done (sched_ats); | ||
108 | sched_ats = NULL; | ||
109 | } | ||
110 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", | ||
111 | &stat_cb, NULL); | ||
112 | if (NULL != stats) | ||
113 | { | ||
114 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
115 | stats = NULL; | ||
116 | } | ||
117 | free_test_address (&test_addr); | ||
118 | ret = 0; | ||
119 | } | ||
120 | |||
121 | |||
122 | static int | ||
123 | stat_cb (void *cls, const char *subsystem, | ||
124 | const char *name, uint64_t value, | ||
125 | int is_persistent) | ||
126 | { | ||
127 | static int initial_ats_stat_cb = GNUNET_YES; | ||
128 | |||
129 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
130 | "ATS statistics: `%s' `%s' %llu\n", | ||
131 | subsystem, | ||
132 | name, | ||
133 | value); | ||
134 | |||
135 | if ((0 == value) && (initial_ats_stat_cb == GNUNET_NO)) | ||
136 | { | ||
137 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
138 | } | ||
139 | if ((0 == value) && (initial_ats_stat_cb == GNUNET_YES)) | ||
140 | { | ||
141 | initial_ats_stat_cb = GNUNET_NO; | ||
142 | } | ||
143 | if (1 == value) | ||
144 | { | ||
145 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
146 | "Statistics observed address added, now destroying address\n"); | ||
147 | GNUNET_ATS_address_destroy (ar); | ||
148 | ar = NULL; | ||
149 | } | ||
150 | return GNUNET_OK; | ||
151 | } | ||
152 | |||
153 | |||
154 | static void | ||
155 | end_badly (void *cls, | ||
156 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
157 | { | ||
158 | die_task = NULL; | ||
159 | end ( NULL, NULL); | ||
160 | ret = GNUNET_SYSERR; | ||
161 | } | ||
162 | |||
163 | |||
164 | static void | ||
165 | address_suggest_cb (void *cls, | ||
166 | const struct GNUNET_PeerIdentity *peer, | ||
167 | const struct GNUNET_HELLO_Address *address, | ||
168 | struct Session *session, | ||
169 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
170 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
171 | { | ||
172 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
173 | "Did not expect suggestion callback!\n"); | ||
174 | GNUNET_SCHEDULER_shutdown (); | ||
175 | } | ||
176 | |||
177 | |||
178 | static void | ||
179 | got_initial_value (void *cls, | ||
180 | int success) | ||
181 | { | ||
182 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
183 | |||
184 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
185 | "Statistics running, now adding address\n"); | ||
186 | |||
187 | /* Connect to ATS scheduling */ | ||
188 | sched_ats = GNUNET_ATS_scheduling_init (cfg, | ||
189 | &address_suggest_cb, NULL); | ||
190 | if (NULL == sched_ats) | ||
191 | { | ||
192 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
193 | "Could not connect to ATS scheduling!\n"); | ||
194 | GNUNET_SCHEDULER_shutdown (); | ||
195 | return; | ||
196 | } | ||
197 | |||
198 | /* Set up peer */ | ||
199 | memset (&p.id, '1', sizeof (p.id)); | ||
200 | /* Prepare ATS Information */ | ||
201 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
202 | test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); | ||
203 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
204 | test_ats_info[1].value = htonl(1); | ||
205 | test_ats_count = 2; | ||
206 | |||
207 | /* Adding address without session */ | ||
208 | test_session = NULL; | ||
209 | create_test_address (&test_addr, | ||
210 | "test", test_session, | ||
211 | "test", strlen ("test") + 1); | ||
212 | test_hello_address.peer = p.id; | ||
213 | test_hello_address.transport_name = test_addr.plugin; | ||
214 | test_hello_address.address = test_addr.addr; | ||
215 | test_hello_address.address_length = test_addr.addr_len; | ||
216 | |||
217 | /* Adding address */ | ||
218 | ar = GNUNET_ATS_address_add (sched_ats, | ||
219 | &test_hello_address, | ||
220 | test_session, | ||
221 | test_ats_info, | ||
222 | test_ats_count); | ||
223 | } | ||
224 | |||
225 | |||
226 | static int | ||
227 | dummy_stat (void *cls, | ||
228 | const char *subsystem, | ||
229 | const char *name, | ||
230 | uint64_t value, | ||
231 | int is_persistent) | ||
232 | { | ||
233 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got dummy stat %s%s:%s = %llu\n", | ||
234 | is_persistent ? "!" : " ", subsystem, name, value); | ||
235 | return GNUNET_OK; | ||
236 | } | ||
237 | |||
238 | |||
239 | static void | ||
240 | run (void *cls, | ||
241 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
242 | struct GNUNET_TESTING_Peer *peer) | ||
243 | { | ||
244 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
245 | stats = GNUNET_STATISTICS_create ("ats", cfg); | ||
246 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
247 | GNUNET_STATISTICS_get (stats, | ||
248 | "ats", | ||
249 | "# addresses", | ||
250 | TIMEOUT, | ||
251 | &got_initial_value, | ||
252 | &dummy_stat, | ||
253 | GNUNET_CONFIGURATION_dup (cfg)); | ||
254 | } | ||
255 | |||
256 | |||
257 | int | ||
258 | main (int argc, char *argv[]) | ||
259 | { | ||
260 | ret = 0; | ||
261 | if (0 != GNUNET_TESTING_peer_run ("test-ats-api", | ||
262 | "test_ats_api.conf", | ||
263 | &run, NULL)) | ||
264 | return 1; | ||
265 | return ret; | ||
266 | } | ||
267 | |||
268 | /* end of file test_ats_api_scheduling_destroy_address.c */ | ||
diff --git a/src/ats/test_ats_api_scheduling_init.c b/src/ats/test_ats_api_scheduling_init.c deleted file mode 100644 index 29446d913..000000000 --- a/src/ats/test_ats_api_scheduling_init.c +++ /dev/null | |||
@@ -1,176 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010,2011 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_api_scheduling_init.c | ||
22 | * @brief test automatic transport selection scheduling API init/shutdown | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | * | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_ats_service.h" | ||
29 | #include "gnunet_testing_lib.h" | ||
30 | #include "ats.h" | ||
31 | #include "test_ats_api_common.h" | ||
32 | /** | ||
33 | * Timeout task | ||
34 | */ | ||
35 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
36 | |||
37 | /** | ||
38 | * Initial statistics get request handle | ||
39 | */ | ||
40 | struct GNUNET_STATISTICS_GetHandle *initial_get; | ||
41 | |||
42 | /** | ||
43 | * Statistics handle | ||
44 | */ | ||
45 | struct GNUNET_STATISTICS_Handle *stats; | ||
46 | |||
47 | /** | ||
48 | * Scheduling handle | ||
49 | */ | ||
50 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
51 | |||
52 | /** | ||
53 | * Return value | ||
54 | */ | ||
55 | static int ret; | ||
56 | |||
57 | |||
58 | static void end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
59 | |||
60 | static int | ||
61 | stat_cb(void *cls, const char *subsystem, | ||
62 | const char *name, uint64_t value, | ||
63 | int is_persistent) | ||
64 | { | ||
65 | |||
66 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", | ||
67 | subsystem,name, value); | ||
68 | if (0 == value) | ||
69 | { | ||
70 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
71 | } | ||
72 | return GNUNET_OK; | ||
73 | } | ||
74 | |||
75 | static int | ||
76 | dummy_stat (void *cls, const char *subsystem, const char *name, uint64_t value, | ||
77 | int is_persistent) | ||
78 | { | ||
79 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got dummy stat %s%s:%s = %llu\n", | ||
80 | is_persistent ? "!" : " ", subsystem, name, value); | ||
81 | return GNUNET_OK; | ||
82 | } | ||
83 | |||
84 | static void | ||
85 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
86 | { | ||
87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | ||
88 | |||
89 | if (die_task != NULL) | ||
90 | { | ||
91 | GNUNET_SCHEDULER_cancel (die_task); | ||
92 | die_task = NULL; | ||
93 | } | ||
94 | |||
95 | if (NULL != sched_ats) | ||
96 | { | ||
97 | GNUNET_ATS_scheduling_done (sched_ats); | ||
98 | sched_ats = NULL; | ||
99 | } | ||
100 | |||
101 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
102 | if (NULL != stats) | ||
103 | { | ||
104 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
105 | stats = NULL; | ||
106 | } | ||
107 | ret = 0; | ||
108 | } | ||
109 | |||
110 | static void | ||
111 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
112 | { | ||
113 | die_task = NULL; | ||
114 | end ( NULL, NULL); | ||
115 | ret = GNUNET_SYSERR; | ||
116 | } | ||
117 | |||
118 | |||
119 | static void | ||
120 | address_suggest_cb (void *cls, | ||
121 | const struct GNUNET_PeerIdentity *peer, | ||
122 | const struct GNUNET_HELLO_Address *address, | ||
123 | struct Session *session, | ||
124 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
125 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
126 | { | ||
127 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); | ||
128 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
129 | } | ||
130 | |||
131 | |||
132 | static void | ||
133 | got_initial_value (void *cls, int success) | ||
134 | { | ||
135 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
136 | |||
137 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got initial value\n"); | ||
138 | |||
139 | /* Connect to ATS scheduling */ | ||
140 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); | ||
141 | GNUNET_CONFIGURATION_destroy (cfg); | ||
142 | if (sched_ats == NULL) | ||
143 | { | ||
144 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); | ||
145 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
146 | return; | ||
147 | } | ||
148 | } | ||
149 | |||
150 | static void | ||
151 | run (void *cls, | ||
152 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
153 | struct GNUNET_TESTING_Peer *peer) | ||
154 | { | ||
155 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
156 | stats = GNUNET_STATISTICS_create ("ats", cfg); | ||
157 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
158 | |||
159 | initial_get = GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT, | ||
160 | &got_initial_value, &dummy_stat, | ||
161 | GNUNET_CONFIGURATION_dup (cfg)); | ||
162 | } | ||
163 | |||
164 | |||
165 | int | ||
166 | main (int argc, char *argv[]) | ||
167 | { | ||
168 | ret = 0; | ||
169 | if (0 != GNUNET_TESTING_peer_run ("test-ats-api", | ||
170 | "test_ats_api.conf", | ||
171 | &run, NULL)) | ||
172 | return 1; | ||
173 | return ret; | ||
174 | } | ||
175 | |||
176 | /* end of file test_ats_api_scheduling_init.c */ | ||
diff --git a/src/ats/test_ats_lib.c b/src/ats/test_ats_lib.c new file mode 100644 index 000000000..74cff1e61 --- /dev/null +++ b/src/ats/test_ats_lib.c | |||
@@ -0,0 +1,999 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010-2015 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_lib.c | ||
22 | * @brief test ATS library with a generic interpreter for running ATS tests | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_util_lib.h" | ||
27 | #include "gnunet_ats_service.h" | ||
28 | #include "gnunet_testing_lib.h" | ||
29 | #include "test_ats_lib.h" | ||
30 | |||
31 | /** | ||
32 | * Information about the last address suggestion we got for a peer. | ||
33 | */ | ||
34 | struct AddressSuggestData | ||
35 | { | ||
36 | /** | ||
37 | * Which session were we given? | ||
38 | */ | ||
39 | struct Session *session; | ||
40 | |||
41 | /** | ||
42 | * What address was assigned? | ||
43 | */ | ||
44 | struct GNUNET_HELLO_Address *address; | ||
45 | |||
46 | /** | ||
47 | * Outbound bandwidth assigned. | ||
48 | */ | ||
49 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; | ||
50 | |||
51 | /** | ||
52 | * Inbound bandwidth assigned. | ||
53 | */ | ||
54 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; | ||
55 | |||
56 | /** | ||
57 | * Was the bandwidth assigned non-zero? | ||
58 | */ | ||
59 | int active; | ||
60 | }; | ||
61 | |||
62 | |||
63 | /** | ||
64 | * Information about the last address information we got for an address. | ||
65 | */ | ||
66 | struct AddressInformationData | ||
67 | { | ||
68 | /** | ||
69 | * What address is this data about? | ||
70 | */ | ||
71 | struct GNUNET_HELLO_Address *address; | ||
72 | |||
73 | /** | ||
74 | * Which properties were given? | ||
75 | */ | ||
76 | struct GNUNET_ATS_Properties properties; | ||
77 | |||
78 | /** | ||
79 | * Outbound bandwidth reported. | ||
80 | */ | ||
81 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; | ||
82 | |||
83 | /** | ||
84 | * Inbound bandwidth reported. | ||
85 | */ | ||
86 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; | ||
87 | |||
88 | /** | ||
89 | * Was the address said to be 'active'? | ||
90 | */ | ||
91 | int active; | ||
92 | }; | ||
93 | |||
94 | |||
95 | /** | ||
96 | * Scheduling handle | ||
97 | */ | ||
98 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
99 | |||
100 | /** | ||
101 | * Connectivity handle | ||
102 | */ | ||
103 | static struct GNUNET_ATS_ConnectivityHandle *con_ats; | ||
104 | |||
105 | /** | ||
106 | * Performance handle | ||
107 | */ | ||
108 | static struct GNUNET_ATS_PerformanceHandle *perf_ats; | ||
109 | |||
110 | /** | ||
111 | * Handle for the interpreter task. | ||
112 | */ | ||
113 | static struct GNUNET_SCHEDULER_Task *interpreter_task; | ||
114 | |||
115 | /** | ||
116 | * Map from peer identities to the last address suggestion | ||
117 | * `struct AddressSuggestData` we got for the respective peer. | ||
118 | */ | ||
119 | static struct GNUNET_CONTAINER_MultiPeerMap *p2asd; | ||
120 | |||
121 | /** | ||
122 | * Map from peer identities to the last address information | ||
123 | * sets for all addresses of this peer. Each peer is mapped | ||
124 | * to one or more `struct AddressInformationData` entries. | ||
125 | */ | ||
126 | static struct GNUNET_CONTAINER_MultiPeerMap *p2aid; | ||
127 | |||
128 | /** | ||
129 | * Global timeout for the test. | ||
130 | */ | ||
131 | static struct GNUNET_TIME_Relative TIMEOUT; | ||
132 | |||
133 | /** | ||
134 | * Return value from #main(). | ||
135 | */ | ||
136 | static int ret; | ||
137 | |||
138 | /** | ||
139 | * Current global command offset into the #commands array. | ||
140 | */ | ||
141 | static unsigned int off; | ||
142 | |||
143 | /** | ||
144 | * Commands for the current test. | ||
145 | */ | ||
146 | static struct Command *test_commands; | ||
147 | |||
148 | |||
149 | |||
150 | /** | ||
151 | * Free `struct AddressSuggestData` entry. | ||
152 | * | ||
153 | * @param cls NULL | ||
154 | * @param key ignored | ||
155 | * @param value the `struct AddressSuggestData` to release | ||
156 | * @return #GNUNET_OK (continue to iterate) | ||
157 | */ | ||
158 | static int | ||
159 | free_asd (void *cls, | ||
160 | const struct GNUNET_PeerIdentity *key, | ||
161 | void *value) | ||
162 | { | ||
163 | struct AddressSuggestData *asd = value; | ||
164 | |||
165 | GNUNET_assert (GNUNET_YES == | ||
166 | GNUNET_CONTAINER_multipeermap_remove (p2asd, | ||
167 | key, | ||
168 | asd)); | ||
169 | GNUNET_free (asd->address); | ||
170 | GNUNET_free (asd); | ||
171 | return GNUNET_OK; | ||
172 | } | ||
173 | |||
174 | |||
175 | /** | ||
176 | * Free `struct AddressInformationData` entry. | ||
177 | * | ||
178 | * @param cls NULL | ||
179 | * @param key ignored | ||
180 | * @param value the `struct AddressSuggestData` to release | ||
181 | * @return #GNUNET_OK (continue to iterate) | ||
182 | */ | ||
183 | static int | ||
184 | free_aid (void *cls, | ||
185 | const struct GNUNET_PeerIdentity *key, | ||
186 | void *value) | ||
187 | { | ||
188 | struct AddressInformationData *aid = value; | ||
189 | |||
190 | GNUNET_assert (GNUNET_YES == | ||
191 | GNUNET_CONTAINER_multipeermap_remove (p2aid, | ||
192 | key, | ||
193 | aid)); | ||
194 | GNUNET_free (aid->address); | ||
195 | GNUNET_free (aid); | ||
196 | return GNUNET_OK; | ||
197 | } | ||
198 | |||
199 | |||
200 | /** | ||
201 | * Find latest address suggestion made for the given peer. | ||
202 | * | ||
203 | * @param pid peer to look up | ||
204 | * @return NULL if peer was never involved | ||
205 | */ | ||
206 | static struct AddressSuggestData * | ||
207 | find_address_suggestion (const struct GNUNET_PeerIdentity *pid) | ||
208 | { | ||
209 | return GNUNET_CONTAINER_multipeermap_get (p2asd, | ||
210 | pid); | ||
211 | } | ||
212 | |||
213 | |||
214 | /** | ||
215 | * Closure for #match_address() | ||
216 | */ | ||
217 | struct MatchAddressContext | ||
218 | { | ||
219 | /** | ||
220 | * Address to find. | ||
221 | */ | ||
222 | const struct GNUNET_HELLO_Address *addr; | ||
223 | |||
224 | /** | ||
225 | * Where to return address information if found. | ||
226 | */ | ||
227 | struct AddressInformationData *ret; | ||
228 | }; | ||
229 | |||
230 | |||
231 | /** | ||
232 | * Find matching address information. | ||
233 | * | ||
234 | * @param cls a `struct MatchAddressContext` | ||
235 | * @param key unused | ||
236 | * @param value a `struct AddressInformationData` | ||
237 | * @return #GNUNET_OK if not found | ||
238 | */ | ||
239 | static int | ||
240 | match_address (void *cls, | ||
241 | const struct GNUNET_PeerIdentity *key, | ||
242 | void *value) | ||
243 | { | ||
244 | struct MatchAddressContext *mac = cls; | ||
245 | struct AddressInformationData *aid = value; | ||
246 | |||
247 | if (0 == GNUNET_HELLO_address_cmp (mac->addr, | ||
248 | aid->address)) | ||
249 | { | ||
250 | mac->ret = aid; | ||
251 | return GNUNET_NO; | ||
252 | } | ||
253 | return GNUNET_OK; | ||
254 | } | ||
255 | |||
256 | |||
257 | /** | ||
258 | * Find latest address information made for the given address. | ||
259 | * | ||
260 | * @param addr address to look up | ||
261 | * @return NULL if peer was never involved | ||
262 | */ | ||
263 | static struct AddressInformationData * | ||
264 | find_address_information (const struct GNUNET_HELLO_Address *addr) | ||
265 | { | ||
266 | struct MatchAddressContext mac; | ||
267 | |||
268 | mac.ret = NULL; | ||
269 | mac.addr = addr; | ||
270 | GNUNET_CONTAINER_multipeermap_get_multiple (p2aid, | ||
271 | &addr->peer, | ||
272 | &match_address, | ||
273 | &mac); | ||
274 | return mac.ret; | ||
275 | } | ||
276 | |||
277 | |||
278 | /** | ||
279 | * Task run to terminate the testcase. | ||
280 | * | ||
281 | * @param cls NULL | ||
282 | * @param tc unused | ||
283 | */ | ||
284 | static void | ||
285 | end (void *cls, | ||
286 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
287 | { | ||
288 | if (0 != ret) | ||
289 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
290 | "Test failed at stage %u %s\n", | ||
291 | off, | ||
292 | (NULL != test_commands[off].label) | ||
293 | ? test_commands[off].label | ||
294 | : ""); | ||
295 | if (NULL != interpreter_task) | ||
296 | { | ||
297 | GNUNET_SCHEDULER_cancel (interpreter_task); | ||
298 | interpreter_task = NULL; | ||
299 | } | ||
300 | if (NULL != sched_ats) | ||
301 | { | ||
302 | GNUNET_ATS_scheduling_done (sched_ats); | ||
303 | sched_ats = NULL; | ||
304 | } | ||
305 | if (NULL != con_ats) | ||
306 | { | ||
307 | GNUNET_ATS_connectivity_done (con_ats); | ||
308 | con_ats = NULL; | ||
309 | } | ||
310 | if (NULL != perf_ats) | ||
311 | { | ||
312 | GNUNET_ATS_performance_done (perf_ats); | ||
313 | perf_ats = NULL; | ||
314 | } | ||
315 | if (NULL != p2asd) | ||
316 | { | ||
317 | GNUNET_CONTAINER_multipeermap_iterate (p2asd, | ||
318 | &free_asd, | ||
319 | NULL); | ||
320 | GNUNET_CONTAINER_multipeermap_destroy (p2asd); | ||
321 | p2asd = NULL; | ||
322 | } | ||
323 | if (NULL != p2aid) | ||
324 | { | ||
325 | GNUNET_CONTAINER_multipeermap_iterate (p2aid, | ||
326 | &free_aid, | ||
327 | NULL); | ||
328 | GNUNET_CONTAINER_multipeermap_destroy (p2aid); | ||
329 | p2aid = NULL; | ||
330 | } | ||
331 | } | ||
332 | |||
333 | |||
334 | /** | ||
335 | * Main interpreter loop. Runs the steps of the test. | ||
336 | * | ||
337 | * @param cls NULL | ||
338 | * @param tc unused | ||
339 | */ | ||
340 | static void | ||
341 | interpreter (void *cls, | ||
342 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
343 | |||
344 | |||
345 | /** | ||
346 | * Run the interpreter next. | ||
347 | */ | ||
348 | static void | ||
349 | run_interpreter () | ||
350 | { | ||
351 | if (NULL != interpreter_task) | ||
352 | GNUNET_SCHEDULER_cancel (interpreter_task); | ||
353 | interpreter_task = GNUNET_SCHEDULER_add_now (&interpreter, | ||
354 | NULL); | ||
355 | } | ||
356 | |||
357 | |||
358 | /** | ||
359 | * Initialize public key of a peer based on a single number. | ||
360 | * | ||
361 | * @param pid number to use as the basis | ||
362 | * @param pk resulting fake public key | ||
363 | */ | ||
364 | static void | ||
365 | make_peer (uint32_t pid, | ||
366 | struct GNUNET_PeerIdentity *pk) | ||
367 | { | ||
368 | memset (pk, | ||
369 | (int) pid, | ||
370 | sizeof (struct GNUNET_PeerIdentity)); | ||
371 | memcpy (pk, | ||
372 | &pid, | ||
373 | sizeof (uint32_t)); | ||
374 | } | ||
375 | |||
376 | |||
377 | /** | ||
378 | * Generate a fake address based on the given parameters. | ||
379 | * | ||
380 | * @param pid number of the peer | ||
381 | * @param num number of the address at peer @a pid | ||
382 | * @param addr_flags flags to use for the address | ||
383 | * @return the address | ||
384 | */ | ||
385 | static struct GNUNET_HELLO_Address * | ||
386 | make_address (uint32_t pid, | ||
387 | uint32_t num, | ||
388 | enum GNUNET_HELLO_AddressInfo addr_flags) | ||
389 | { | ||
390 | struct GNUNET_PeerIdentity pk; | ||
391 | uint32_t nbo; | ||
392 | |||
393 | nbo = htonl (num); | ||
394 | make_peer (pid, | ||
395 | &pk); | ||
396 | return GNUNET_HELLO_address_allocate (&pk, | ||
397 | "test", | ||
398 | &nbo, | ||
399 | sizeof (nbo), | ||
400 | addr_flags); | ||
401 | } | ||
402 | |||
403 | |||
404 | /** | ||
405 | * Our dummy sessions. | ||
406 | */ | ||
407 | struct Session { | ||
408 | /** | ||
409 | * Field to avoid `0 == sizeof(struct Session)`. | ||
410 | */ | ||
411 | unsigned int non_empty; | ||
412 | }; | ||
413 | |||
414 | |||
415 | /** | ||
416 | * Create a session instance for ATS. | ||
417 | * | ||
418 | * @param i which session number to return | ||
419 | * @return NULL if @a i is 0, otherwise a pointer unique to @a i | ||
420 | */ | ||
421 | static struct Session * | ||
422 | make_session (unsigned int i) | ||
423 | { | ||
424 | struct Session *baseptr = NULL; | ||
425 | |||
426 | if (0 == i) | ||
427 | return NULL; | ||
428 | /* Yes, these are *intentionally* out-of-bounds, | ||
429 | and offset from NULL, as nobody should ever | ||
430 | use those other than to compare pointers! */ | ||
431 | return baseptr + i; | ||
432 | } | ||
433 | |||
434 | |||
435 | /** | ||
436 | * Find a @a code command before the global #off with the | ||
437 | * specified @a label. | ||
438 | * | ||
439 | * @param code opcode to look for | ||
440 | * @param label label to look for, NULL for none | ||
441 | * @return previous command with the matching label | ||
442 | */ | ||
443 | static struct Command * | ||
444 | find_command (enum CommandCode code, | ||
445 | const char *label) | ||
446 | { | ||
447 | int i; | ||
448 | |||
449 | if (NULL == label) | ||
450 | return NULL; | ||
451 | for (i=off-1;i>=0;i--) | ||
452 | if ( (code == test_commands[i].code) && | ||
453 | (0 == strcmp (test_commands[i].label, | ||
454 | label)) ) | ||
455 | return &test_commands[i]; | ||
456 | GNUNET_break (0); | ||
457 | return NULL; | ||
458 | } | ||
459 | |||
460 | |||
461 | /** | ||
462 | * Function called from #GNUNET_ATS_performance_list_addresses when | ||
463 | * we process a #CMD_LIST_ADDRESSES command. | ||
464 | * | ||
465 | * @param cls the `struct Command` that caused the call | ||
466 | * @param address the address, NULL if ATS service was disconnected | ||
467 | * @param address_active #GNUNET_YES if this address is actively used | ||
468 | * to maintain a connection to a peer; | ||
469 | * #GNUNET_NO if the address is not actively used; | ||
470 | * #GNUNET_SYSERR if this address is no longer available for ATS | ||
471 | * @param bandwidth_out assigned outbound bandwidth for the connection | ||
472 | * @param bandwidth_in assigned inbound bandwidth for the connection | ||
473 | * @param prop performance data for the address | ||
474 | */ | ||
475 | static void | ||
476 | info_cb (void *cls, | ||
477 | const struct GNUNET_HELLO_Address *address, | ||
478 | int address_active, | ||
479 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
480 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
481 | const struct GNUNET_ATS_Properties *prop) | ||
482 | { | ||
483 | struct Command *c = cls; | ||
484 | struct CommandListAddresses *cmd = &c->details.list_addresses; | ||
485 | |||
486 | if (NULL == address) | ||
487 | { | ||
488 | cmd->alh = NULL; | ||
489 | /* we are done with the iteration, continue to execute */ | ||
490 | if ( (cmd->calls < cmd->min_calls) && | ||
491 | (cmd->active_calls < cmd->min_active_calls) ) | ||
492 | { | ||
493 | GNUNET_SCHEDULER_shutdown (); | ||
494 | return; | ||
495 | } | ||
496 | off++; | ||
497 | run_interpreter (); | ||
498 | return; | ||
499 | } | ||
500 | switch (address_active) | ||
501 | { | ||
502 | case GNUNET_YES: | ||
503 | cmd->active_calls++; | ||
504 | cmd->calls++; | ||
505 | break; | ||
506 | case GNUNET_NO: | ||
507 | cmd->calls++; | ||
508 | break; | ||
509 | case GNUNET_SYSERR: | ||
510 | return; | ||
511 | } | ||
512 | if ( (cmd->calls > cmd->max_calls) && | ||
513 | (cmd->active_calls < cmd->max_active_calls) ) | ||
514 | { | ||
515 | GNUNET_break (0); | ||
516 | GNUNET_ATS_performance_list_addresses_cancel (cmd->alh); | ||
517 | cmd->alh = NULL; | ||
518 | GNUNET_SCHEDULER_shutdown (); | ||
519 | return; | ||
520 | } | ||
521 | } | ||
522 | |||
523 | |||
524 | /** | ||
525 | * Main interpreter loop. Runs the steps of the test. | ||
526 | * | ||
527 | * @param cls NULL | ||
528 | * @param tc unused | ||
529 | */ | ||
530 | static void | ||
531 | interpreter (void *cls, | ||
532 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
533 | |||
534 | { | ||
535 | struct Command *cmd; | ||
536 | |||
537 | interpreter_task = NULL; | ||
538 | while (1) | ||
539 | { | ||
540 | cmd = &test_commands[off]; | ||
541 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
542 | "#%u: %d %s\n", | ||
543 | off, | ||
544 | (int) cmd->code, | ||
545 | (NULL != cmd->label) ? cmd->label : ""); | ||
546 | switch (cmd->code) | ||
547 | { | ||
548 | case CMD_END_PASS: | ||
549 | ret = 0; | ||
550 | GNUNET_SCHEDULER_shutdown (); | ||
551 | return; | ||
552 | case CMD_ADD_ADDRESS: | ||
553 | { | ||
554 | struct GNUNET_HELLO_Address *addr; | ||
555 | struct Session *session; | ||
556 | |||
557 | addr = make_address (cmd->details.add_address.pid, | ||
558 | cmd->details.add_address.addr_num, | ||
559 | cmd->details.add_address.addr_flags); | ||
560 | session = make_session (cmd->details.add_address.session); | ||
561 | if (cmd->details.add_address.expect_fail) | ||
562 | GNUNET_log_skip (1, GNUNET_NO); | ||
563 | cmd->details.add_address.ar | ||
564 | = GNUNET_ATS_address_add (sched_ats, | ||
565 | addr, | ||
566 | session, | ||
567 | &cmd->details.add_address.properties); | ||
568 | GNUNET_free (addr); | ||
569 | if (cmd->details.add_address.expect_fail) | ||
570 | { | ||
571 | GNUNET_log_skip (0, GNUNET_YES); | ||
572 | } | ||
573 | else if (NULL == cmd->details.add_address.ar) | ||
574 | { | ||
575 | GNUNET_break (0); | ||
576 | GNUNET_SCHEDULER_shutdown (); | ||
577 | return; | ||
578 | } | ||
579 | off++; | ||
580 | break; | ||
581 | } | ||
582 | case CMD_DEL_ADDRESS: | ||
583 | { | ||
584 | struct Command *add; | ||
585 | |||
586 | add = find_command (CMD_ADD_ADDRESS, | ||
587 | cmd->details.del_address.add_label); | ||
588 | GNUNET_assert (NULL != add->details.add_address.ar); | ||
589 | GNUNET_ATS_address_destroy (add->details.add_address.ar); | ||
590 | add->details.add_address.ar = NULL; | ||
591 | off++; | ||
592 | break; | ||
593 | } | ||
594 | case CMD_AWAIT_ADDRESS_SUGGESTION: | ||
595 | { | ||
596 | struct GNUNET_PeerIdentity pid; | ||
597 | struct GNUNET_HELLO_Address *addr; | ||
598 | struct Command *add; | ||
599 | struct AddressSuggestData *asd; | ||
600 | int done; | ||
601 | |||
602 | make_peer (cmd->details.await_address_suggestion.pid, | ||
603 | &pid); | ||
604 | asd = find_address_suggestion (&pid); | ||
605 | if (NULL == asd) | ||
606 | return; | ||
607 | if (GNUNET_NO == asd->active) | ||
608 | return; | ||
609 | done = GNUNET_YES; | ||
610 | if (NULL != cmd->details.await_address_suggestion.add_label) | ||
611 | { | ||
612 | done = GNUNET_NO; | ||
613 | add = find_command (CMD_ADD_ADDRESS, | ||
614 | cmd->details.await_address_suggestion.add_label); | ||
615 | addr = make_address (add->details.add_address.pid, | ||
616 | add->details.add_address.addr_num, | ||
617 | add->details.add_address.addr_flags); | ||
618 | if ( (asd->session == | ||
619 | make_session (add->details.add_address.session)) && | ||
620 | (0 == | ||
621 | GNUNET_HELLO_address_cmp (addr, | ||
622 | asd->address)) ) | ||
623 | done = GNUNET_YES; | ||
624 | GNUNET_free (addr); | ||
625 | } | ||
626 | if (GNUNET_NO == done) | ||
627 | return; | ||
628 | off++; | ||
629 | break; | ||
630 | } | ||
631 | case CMD_AWAIT_DISCONNECT_SUGGESTION: | ||
632 | { | ||
633 | struct GNUNET_PeerIdentity pid; | ||
634 | struct AddressSuggestData *asd; | ||
635 | |||
636 | make_peer (cmd->details.await_disconnect_suggestion.pid, | ||
637 | &pid); | ||
638 | asd = find_address_suggestion (&pid); | ||
639 | if (NULL == asd) | ||
640 | return; | ||
641 | if (GNUNET_NO == asd->active) | ||
642 | return; | ||
643 | off++; | ||
644 | break; | ||
645 | } | ||
646 | case CMD_REQUEST_CONNECTION_START: | ||
647 | { | ||
648 | struct GNUNET_PeerIdentity pid; | ||
649 | |||
650 | make_peer (cmd->details.request_connection_start.pid, | ||
651 | &pid); | ||
652 | cmd->details.request_connection_start.csh | ||
653 | = GNUNET_ATS_connectivity_suggest (con_ats, | ||
654 | &pid); | ||
655 | off++; | ||
656 | break; | ||
657 | } | ||
658 | case CMD_REQUEST_CONNECTION_STOP: | ||
659 | { | ||
660 | struct Command *start; | ||
661 | |||
662 | start = find_command (CMD_REQUEST_CONNECTION_START, | ||
663 | cmd->details.request_connection_stop.connect_label); | ||
664 | GNUNET_ATS_connectivity_suggest_cancel (start->details.request_connection_start.csh); | ||
665 | start->details.request_connection_start.csh = NULL; | ||
666 | off++; | ||
667 | break; | ||
668 | } | ||
669 | case CMD_AWAIT_ADDRESS_INFORMATION: | ||
670 | { | ||
671 | struct AddressInformationData *aid; | ||
672 | struct Command *add; | ||
673 | struct Command *update; | ||
674 | struct GNUNET_HELLO_Address *addr; | ||
675 | const struct GNUNET_ATS_Properties *cmp; | ||
676 | |||
677 | add = find_command (CMD_ADD_ADDRESS, | ||
678 | cmd->details.await_address_information.add_label); | ||
679 | update = find_command (CMD_UPDATE_ADDRESS, | ||
680 | cmd->details.await_address_information.update_label); | ||
681 | addr = make_address (add->details.add_address.pid, | ||
682 | add->details.add_address.addr_num, | ||
683 | add->details.add_address.addr_flags); | ||
684 | aid = find_address_information (addr); | ||
685 | GNUNET_free (addr); | ||
686 | if (NULL == update) | ||
687 | cmp = &add->details.add_address.properties; | ||
688 | else | ||
689 | cmp = &update->details.update_address.properties; | ||
690 | if ( (NULL != aid) && | ||
691 | (0 == memcmp (cmp, | ||
692 | &aid->properties, | ||
693 | sizeof (struct GNUNET_ATS_Properties))) ) | ||
694 | { | ||
695 | off++; | ||
696 | break; | ||
697 | } | ||
698 | return; | ||
699 | } | ||
700 | case CMD_UPDATE_ADDRESS: | ||
701 | { | ||
702 | struct Command *add; | ||
703 | |||
704 | add = find_command (CMD_ADD_ADDRESS, | ||
705 | cmd->details.update_address.add_label); | ||
706 | GNUNET_assert (NULL != add->details.add_address.ar); | ||
707 | GNUNET_ATS_address_update (add->details.add_address.ar, | ||
708 | &cmd->details.update_address.properties); | ||
709 | off++; | ||
710 | break; | ||
711 | } | ||
712 | case CMD_ADD_SESSION: | ||
713 | { | ||
714 | struct Command *add; | ||
715 | struct Session *session; | ||
716 | |||
717 | add = find_command (CMD_ADD_ADDRESS, | ||
718 | cmd->details.add_session.add_label); | ||
719 | session = make_session (cmd->details.add_session.session); | ||
720 | GNUNET_assert (NULL != add->details.add_address.ar); | ||
721 | GNUNET_ATS_address_add_session (add->details.add_address.ar, | ||
722 | session); | ||
723 | off++; | ||
724 | break; | ||
725 | } | ||
726 | case CMD_DEL_SESSION: | ||
727 | { | ||
728 | struct Command *add_address; | ||
729 | struct Command *add_session; | ||
730 | struct Session *session; | ||
731 | |||
732 | add_session = find_command (CMD_ADD_SESSION, | ||
733 | cmd->details.del_session.add_session_label); | ||
734 | add_address = find_command (CMD_ADD_ADDRESS, | ||
735 | add_session->details.add_session.add_label); | ||
736 | GNUNET_assert (NULL != add_address->details.add_address.ar); | ||
737 | session = make_session (add_session->details.add_session.session); | ||
738 | GNUNET_ATS_address_del_session (add_address->details.add_address.ar, | ||
739 | session); | ||
740 | off++; | ||
741 | break; | ||
742 | } | ||
743 | case CMD_CHANGE_PREFERENCE: | ||
744 | { | ||
745 | struct GNUNET_PeerIdentity pid; | ||
746 | |||
747 | make_peer (cmd->details.change_preference.pid, | ||
748 | &pid); | ||
749 | GNUNET_ATS_performance_change_preference (perf_ats, | ||
750 | &pid, | ||
751 | GNUNET_ATS_PREFERENCE_END); | ||
752 | off++; | ||
753 | break; | ||
754 | } | ||
755 | case CMD_PROVIDE_FEEDBACK: | ||
756 | { | ||
757 | struct GNUNET_PeerIdentity pid; | ||
758 | |||
759 | make_peer (cmd->details.provide_feedback.pid, | ||
760 | &pid); | ||
761 | GNUNET_ATS_performance_give_feedback (perf_ats, | ||
762 | &pid, | ||
763 | cmd->details.provide_feedback.scope, | ||
764 | GNUNET_ATS_PREFERENCE_END); | ||
765 | off++; | ||
766 | break; | ||
767 | } | ||
768 | case CMD_LIST_ADDRESSES: | ||
769 | { | ||
770 | struct GNUNET_PeerIdentity pid; | ||
771 | |||
772 | make_peer (cmd->details.list_addresses.pid, | ||
773 | &pid); | ||
774 | cmd->details.list_addresses.alh | ||
775 | = GNUNET_ATS_performance_list_addresses (perf_ats, | ||
776 | &pid, | ||
777 | cmd->details.list_addresses.all, | ||
778 | &info_cb, | ||
779 | cmd); | ||
780 | return; | ||
781 | } | ||
782 | } /* end switch */ | ||
783 | } /* end while(1) */ | ||
784 | } | ||
785 | |||
786 | |||
787 | /** | ||
788 | * Signature of a function called by ATS with the current bandwidth | ||
789 | * and address preferences as determined by ATS. | ||
790 | * | ||
791 | * @param cls closure, should point to "asc-closure" | ||
792 | * @param peer for which we suggest an address, NULL if ATS connection died | ||
793 | * @param address suggested address (including peer identity of the peer), | ||
794 | * may be NULL to signal disconnect from peer | ||
795 | * @param session session to use, NULL to establish a new outgoing session | ||
796 | * @param bandwidth_out assigned outbound bandwidth for the connection, | ||
797 | * 0 to signal disconnect | ||
798 | * @param bandwidth_in assigned inbound bandwidth for the connection, | ||
799 | * 0 to signal disconnect | ||
800 | */ | ||
801 | static void | ||
802 | address_suggest_cb (void *cls, | ||
803 | const struct GNUNET_PeerIdentity *peer, | ||
804 | const struct GNUNET_HELLO_Address *address, | ||
805 | struct Session *session, | ||
806 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
807 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
808 | { | ||
809 | const char *asc_cls = cls; | ||
810 | struct AddressSuggestData *asd; | ||
811 | |||
812 | GNUNET_break (0 == strcmp (asc_cls, "asc-closure")); | ||
813 | if (NULL == peer) | ||
814 | { | ||
815 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
816 | "Connection to ATS died, likely a crash!\n"); | ||
817 | GNUNET_SCHEDULER_shutdown (); | ||
818 | #if 0 | ||
819 | /* This is what we should do if we wanted to continue past | ||
820 | the ATS crash. */ | ||
821 | GNUNET_CONTAINER_multipeermap_iterate (p2asd, | ||
822 | &free_asd, | ||
823 | NULL); | ||
824 | GNUNET_CONTAINER_multipeermap_iterate (p2aid, | ||
825 | &free_aid, | ||
826 | NULL); | ||
827 | #endif | ||
828 | return; | ||
829 | } | ||
830 | |||
831 | asd = find_address_suggestion (peer); | ||
832 | if (NULL == asd) | ||
833 | { | ||
834 | asd = GNUNET_new (struct AddressSuggestData); | ||
835 | GNUNET_assert (GNUNET_YES == | ||
836 | GNUNET_CONTAINER_multipeermap_put (p2asd, | ||
837 | peer, | ||
838 | asd, | ||
839 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
840 | } | ||
841 | if ( (0 == ntohl (bandwidth_out.value__)) && | ||
842 | (0 == ntohl (bandwidth_in.value__)) ) | ||
843 | asd->active = GNUNET_NO; | ||
844 | else | ||
845 | asd->active = GNUNET_YES; | ||
846 | asd->bandwidth_out = bandwidth_out; | ||
847 | asd->bandwidth_in = bandwidth_in; | ||
848 | asd->session = session; | ||
849 | GNUNET_free_non_null (asd->address); | ||
850 | asd->address = NULL; | ||
851 | if (NULL != address) | ||
852 | asd->address = GNUNET_HELLO_address_copy (address); | ||
853 | run_interpreter (); | ||
854 | } | ||
855 | |||
856 | |||
857 | /** | ||
858 | * Signature of a function that is called with QoS information about an address. | ||
859 | * | ||
860 | * @param cls closure, should point to "aic-closure" | ||
861 | * @param address the address, NULL if ATS service was disconnected | ||
862 | * @param address_active #GNUNET_YES if this address is actively used | ||
863 | * to maintain a connection to a peer; | ||
864 | * #GNUNET_NO if the address is not actively used; | ||
865 | * #GNUNET_SYSERR if this address is no longer available for ATS | ||
866 | * @param bandwidth_out assigned outbound bandwidth for the connection | ||
867 | * @param bandwidth_in assigned inbound bandwidth for the connection | ||
868 | * @param prop performance data for the address | ||
869 | */ | ||
870 | static void | ||
871 | address_information_cb (void *cls, | ||
872 | const struct GNUNET_HELLO_Address *address, | ||
873 | int address_active, | ||
874 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
875 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
876 | const struct GNUNET_ATS_Properties *prop) | ||
877 | { | ||
878 | const char *aic_cls = cls; | ||
879 | struct AddressInformationData *aid; | ||
880 | |||
881 | GNUNET_break (0 == strcmp (aic_cls, "aic-closure")); | ||
882 | if (NULL == address) | ||
883 | { | ||
884 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
885 | "Connection to ATS died, likely a crash!\n"); | ||
886 | GNUNET_CONTAINER_multipeermap_iterate (p2aid, | ||
887 | &free_aid, | ||
888 | NULL); | ||
889 | return; | ||
890 | } | ||
891 | |||
892 | aid = find_address_information (address); | ||
893 | if (NULL == aid) | ||
894 | { | ||
895 | aid = GNUNET_new (struct AddressInformationData); | ||
896 | aid->address = GNUNET_HELLO_address_copy (address); | ||
897 | GNUNET_assert (GNUNET_YES == | ||
898 | GNUNET_CONTAINER_multipeermap_put (p2aid, | ||
899 | &address->peer, | ||
900 | aid, | ||
901 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
902 | } | ||
903 | aid->active = address_active; | ||
904 | aid->bandwidth_out = bandwidth_out; | ||
905 | aid->bandwidth_in = bandwidth_in; | ||
906 | aid->properties = *prop; | ||
907 | run_interpreter (); | ||
908 | } | ||
909 | |||
910 | |||
911 | /** | ||
912 | * Function run once the ATS service has been started. | ||
913 | * | ||
914 | * @param cls NULL | ||
915 | * @param cfg configuration for the testcase | ||
916 | * @param peer handle to the peer | ||
917 | */ | ||
918 | static void | ||
919 | run (void *cls, | ||
920 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
921 | struct GNUNET_TESTING_Peer *peer) | ||
922 | { | ||
923 | p2asd = GNUNET_CONTAINER_multipeermap_create (128, | ||
924 | GNUNET_NO); | ||
925 | p2aid = GNUNET_CONTAINER_multipeermap_create (128, | ||
926 | GNUNET_NO); | ||
927 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
928 | &end, | ||
929 | NULL); | ||
930 | |||
931 | sched_ats = GNUNET_ATS_scheduling_init (cfg, | ||
932 | &address_suggest_cb, | ||
933 | "asc-closure"); | ||
934 | if (NULL == sched_ats) | ||
935 | { | ||
936 | GNUNET_break (0); | ||
937 | GNUNET_SCHEDULER_shutdown (); | ||
938 | return; | ||
939 | } | ||
940 | con_ats = GNUNET_ATS_connectivity_init (cfg); | ||
941 | if (NULL == con_ats) | ||
942 | { | ||
943 | GNUNET_break (0); | ||
944 | GNUNET_SCHEDULER_shutdown (); | ||
945 | return; | ||
946 | } | ||
947 | perf_ats = GNUNET_ATS_performance_init (cfg, | ||
948 | &address_information_cb, | ||
949 | "aic-closure"); | ||
950 | if (NULL == perf_ats) | ||
951 | { | ||
952 | GNUNET_break (0); | ||
953 | GNUNET_SCHEDULER_shutdown (); | ||
954 | return; | ||
955 | } | ||
956 | run_interpreter (); | ||
957 | } | ||
958 | |||
959 | |||
960 | /** | ||
961 | * Run ATS test. | ||
962 | * | ||
963 | * @param argc length of @a argv | ||
964 | * @param argv command line | ||
965 | * @param cmds commands to run with the interpreter | ||
966 | * @param timeout how long is the test allowed to take? | ||
967 | * @return 0 on success | ||
968 | */ | ||
969 | int | ||
970 | TEST_ATS_run (int argc, | ||
971 | char *argv[], | ||
972 | struct Command *cmds, | ||
973 | struct GNUNET_TIME_Relative timeout) | ||
974 | { | ||
975 | char *test_filename = GNUNET_strdup (argv[0]); | ||
976 | char *sep; | ||
977 | char *config_file; | ||
978 | char *underscore; | ||
979 | |||
980 | test_commands = cmds; | ||
981 | TIMEOUT = timeout; | ||
982 | if (NULL != (sep = strstr (test_filename, ".exe"))) | ||
983 | sep[0] = '\0'; | ||
984 | underscore = strrchr (test_filename, (int) '_'); | ||
985 | GNUNET_assert (NULL != underscore); | ||
986 | GNUNET_asprintf (&config_file, | ||
987 | "test_ats_api_%s.conf", | ||
988 | underscore + 1); | ||
989 | ret = 2; | ||
990 | if (0 != GNUNET_TESTING_peer_run ("test-ats-api", | ||
991 | config_file, | ||
992 | &run, NULL)) | ||
993 | ret = 1; | ||
994 | GNUNET_free (test_filename); | ||
995 | GNUNET_free (config_file); | ||
996 | return ret; | ||
997 | } | ||
998 | |||
999 | /* end of test_ats_lib.c */ | ||
diff --git a/src/ats/test_ats_lib.h b/src/ats/test_ats_lib.h new file mode 100644 index 000000000..590aac750 --- /dev/null +++ b/src/ats/test_ats_lib.h | |||
@@ -0,0 +1,467 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010-2015 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_lib.h | ||
22 | * @brief test ATS library with a generic interpreter for running ATS tests | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #ifndef TEST_ATS_LIB_H | ||
26 | #define TEST_ATS_LIB_H | ||
27 | |||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_ats_service.h" | ||
30 | #include "gnunet_testing_lib.h" | ||
31 | |||
32 | |||
33 | /** | ||
34 | * Commands for the interpreter. | ||
35 | */ | ||
36 | enum CommandCode | ||
37 | { | ||
38 | /** | ||
39 | * End the test (passing). | ||
40 | */ | ||
41 | CMD_END_PASS = 0, | ||
42 | |||
43 | /** | ||
44 | * Call #GNUNET_ATS_address_add(). | ||
45 | */ | ||
46 | CMD_ADD_ADDRESS, | ||
47 | |||
48 | /** | ||
49 | * Call #GNUNET_ATS_address_del(). | ||
50 | */ | ||
51 | CMD_DEL_ADDRESS, | ||
52 | |||
53 | /** | ||
54 | * Wait for ATS to suggest address. | ||
55 | */ | ||
56 | CMD_AWAIT_ADDRESS_SUGGESTION, | ||
57 | |||
58 | /** | ||
59 | * Wait for ATS to suggest disconnect. | ||
60 | */ | ||
61 | CMD_AWAIT_DISCONNECT_SUGGESTION, | ||
62 | |||
63 | /** | ||
64 | * Ask ATS to connect to a peer, using | ||
65 | * #GNUNET_ATS_connectivity_suggest(). | ||
66 | */ | ||
67 | CMD_REQUEST_CONNECTION_START, | ||
68 | |||
69 | /** | ||
70 | * Tell ATS we no longer need a connection to a peer, using | ||
71 | * #GNUNET_ATS_connectivity_suggest_cancel(). | ||
72 | */ | ||
73 | CMD_REQUEST_CONNECTION_STOP, | ||
74 | |||
75 | /** | ||
76 | * Wait for certain address information to be provided. | ||
77 | */ | ||
78 | CMD_AWAIT_ADDRESS_INFORMATION, | ||
79 | |||
80 | /** | ||
81 | * Update properties of an address, using | ||
82 | * #GNUNET_ATS_address_update(). | ||
83 | */ | ||
84 | CMD_UPDATE_ADDRESS, | ||
85 | |||
86 | /** | ||
87 | * Add session to an address, using | ||
88 | * #GNUNET_ATS_address_add_session(). | ||
89 | */ | ||
90 | CMD_ADD_SESSION, | ||
91 | |||
92 | /** | ||
93 | * Remove session from an address, using | ||
94 | * #GNUNET_ATS_address_del_session(). | ||
95 | */ | ||
96 | CMD_DEL_SESSION, | ||
97 | |||
98 | /** | ||
99 | * Change performance preferences for a peer, testing | ||
100 | * #GNUNET_ATS_performance_change_preference(). | ||
101 | */ | ||
102 | CMD_CHANGE_PREFERENCE, | ||
103 | |||
104 | /** | ||
105 | * Provide allocation quality feedback, testing | ||
106 | * #GNUNET_ATS_performance_give_feedback(). | ||
107 | */ | ||
108 | CMD_PROVIDE_FEEDBACK, | ||
109 | |||
110 | /** | ||
111 | * Obtain list of all addresses, testing | ||
112 | * #GNUNET_ATS_performance_list_addresses(). | ||
113 | */ | ||
114 | CMD_LIST_ADDRESSES | ||
115 | |||
116 | /* TODO: reserve bandwidth */ | ||
117 | |||
118 | }; | ||
119 | |||
120 | |||
121 | /** | ||
122 | * Details for the #CMD_ADD_ADDRESS command. | ||
123 | */ | ||
124 | struct CommandAddAddress | ||
125 | { | ||
126 | /** | ||
127 | * Number of the peer (used to generate PID). | ||
128 | */ | ||
129 | unsigned int pid; | ||
130 | |||
131 | /** | ||
132 | * Number of the address (used to generate binary address). | ||
133 | */ | ||
134 | unsigned int addr_num; | ||
135 | |||
136 | /** | ||
137 | * Session to supply, 0 for NULL. | ||
138 | */ | ||
139 | unsigned int session; | ||
140 | |||
141 | /** | ||
142 | * Flags to set for the address. | ||
143 | */ | ||
144 | enum GNUNET_HELLO_AddressInfo addr_flags; | ||
145 | |||
146 | /** | ||
147 | * Performance properties to supply. | ||
148 | */ | ||
149 | struct GNUNET_ATS_Properties properties; | ||
150 | |||
151 | /** | ||
152 | * Expect the operation to fail (duplicate). | ||
153 | */ | ||
154 | int expect_fail; | ||
155 | |||
156 | /** | ||
157 | * Here the result of the add address operation will be stored. | ||
158 | */ | ||
159 | struct GNUNET_ATS_AddressRecord *ar; | ||
160 | }; | ||
161 | |||
162 | |||
163 | /** | ||
164 | * Details for the #CMD_DEL_ADDRESS command. | ||
165 | */ | ||
166 | struct CommandDelAddress | ||
167 | { | ||
168 | /** | ||
169 | * Label of the corresponding #CMD_ADD_ADDRESS that | ||
170 | * we are now to remove. | ||
171 | */ | ||
172 | const char *add_label; | ||
173 | }; | ||
174 | |||
175 | |||
176 | /** | ||
177 | * Details for the #CMD_AWAIT_ADDRESS_SUGGESTION command. | ||
178 | */ | ||
179 | struct CommandAwaitAddressSuggestion | ||
180 | { | ||
181 | /** | ||
182 | * For which peer do we expect a suggestion? | ||
183 | */ | ||
184 | unsigned int pid; | ||
185 | |||
186 | /** | ||
187 | * If we expect the address suggested to match a particular | ||
188 | * addition, specify the label of the add operation here. Otherwise | ||
189 | * use NULL for "any" available address. | ||
190 | */ | ||
191 | const char *add_label; | ||
192 | |||
193 | }; | ||
194 | |||
195 | |||
196 | /** | ||
197 | * Details for the #CMD_AWAIT_DISCONNECT_SUGGESTION command. | ||
198 | */ | ||
199 | struct CommandAwaitDisconnectSuggestion | ||
200 | { | ||
201 | /** | ||
202 | * For which peer do we expect the disconnect? | ||
203 | */ | ||
204 | unsigned int pid; | ||
205 | |||
206 | }; | ||
207 | |||
208 | |||
209 | /** | ||
210 | * Details for the #CMD_REQUEST_CONNECTION_START command. | ||
211 | */ | ||
212 | struct CommandRequestConnectionStart | ||
213 | { | ||
214 | /** | ||
215 | * Identity of the peer we would like to connect to. | ||
216 | */ | ||
217 | unsigned int pid; | ||
218 | |||
219 | /** | ||
220 | * Location where we store the handle returned from | ||
221 | * #GNUNET_ATS_connectivity_suggest(). | ||
222 | */ | ||
223 | struct GNUNET_ATS_ConnectivitySuggestHandle *csh; | ||
224 | }; | ||
225 | |||
226 | |||
227 | /** | ||
228 | * Details for the #CMD_REQUEST_CONNECTION_STOP command. | ||
229 | */ | ||
230 | struct CommandRequestConnectionStop | ||
231 | { | ||
232 | /** | ||
233 | * Label of the corresponding #CMD_REQUEST_CONNECTION_START that | ||
234 | * we are now stopping. | ||
235 | */ | ||
236 | const char *connect_label; | ||
237 | }; | ||
238 | |||
239 | |||
240 | /** | ||
241 | * Details for the #CMD_AWAIT_ADDRESS_INFORMATION command. | ||
242 | */ | ||
243 | struct CommandAwaitAddressInformation | ||
244 | { | ||
245 | /** | ||
246 | * For which address do we expect information? | ||
247 | * The address is identified by the respective | ||
248 | * label of the corresponding add operation. | ||
249 | */ | ||
250 | const char *add_label; | ||
251 | |||
252 | /** | ||
253 | * Label of a possible update operation that may | ||
254 | * have modified the properties. NULL to use | ||
255 | * the properties from the @e add_label. | ||
256 | */ | ||
257 | const char *update_label; | ||
258 | |||
259 | }; | ||
260 | |||
261 | |||
262 | /** | ||
263 | * Details for the #CMD_UPDATE_ADDRESS command. | ||
264 | */ | ||
265 | struct CommandUpdateAddress | ||
266 | { | ||
267 | /** | ||
268 | * Label of the addresses's add operation. | ||
269 | */ | ||
270 | const char *add_label; | ||
271 | |||
272 | /** | ||
273 | * Performance properties to supply. | ||
274 | */ | ||
275 | struct GNUNET_ATS_Properties properties; | ||
276 | |||
277 | }; | ||
278 | |||
279 | |||
280 | /** | ||
281 | * Details for the #CMD_ADD_SESSION command. | ||
282 | */ | ||
283 | struct CommandAddSession | ||
284 | { | ||
285 | /** | ||
286 | * Label of the addresses's add operation. | ||
287 | */ | ||
288 | const char *add_label; | ||
289 | |||
290 | /** | ||
291 | * Session to supply. | ||
292 | */ | ||
293 | unsigned int session; | ||
294 | |||
295 | }; | ||
296 | |||
297 | |||
298 | /** | ||
299 | * Details for the #CMD_DEL_SESSION command. | ||
300 | */ | ||
301 | struct CommandDelSession | ||
302 | { | ||
303 | /** | ||
304 | * Label of the addresses's add operation. | ||
305 | */ | ||
306 | const char *add_session_label; | ||
307 | |||
308 | }; | ||
309 | |||
310 | |||
311 | /** | ||
312 | * Details for the #CMD_CHANGE_PREFERENCE command. | ||
313 | */ | ||
314 | struct CommandChangePreference | ||
315 | { | ||
316 | /** | ||
317 | * Identity of the peer we have a preference change towards. | ||
318 | */ | ||
319 | unsigned int pid; | ||
320 | |||
321 | /* FIXME: preference details! */ | ||
322 | |||
323 | }; | ||
324 | |||
325 | |||
326 | /** | ||
327 | * Details for the #CMD_PROVIDE_FEEDBACK command. | ||
328 | */ | ||
329 | struct CommandProvideFeedback | ||
330 | { | ||
331 | /** | ||
332 | * Identity of the peer we have a feedback for. | ||
333 | */ | ||
334 | unsigned int pid; | ||
335 | |||
336 | /** | ||
337 | * Over which timeframe does the feedback apply? | ||
338 | */ | ||
339 | struct GNUNET_TIME_Relative scope; | ||
340 | |||
341 | /* FIXME: feedback details! */ | ||
342 | }; | ||
343 | |||
344 | |||
345 | /** | ||
346 | * Details for the #CMD_LIST_ADDRESSES command. | ||
347 | */ | ||
348 | struct CommandListAddresses | ||
349 | { | ||
350 | /** | ||
351 | * Identity of the peer we want a list for. | ||
352 | */ | ||
353 | unsigned int pid; | ||
354 | |||
355 | /** | ||
356 | * All addresses or just active? | ||
357 | */ | ||
358 | int all; | ||
359 | |||
360 | /** | ||
361 | * Minimum number of addresses the callback may report. | ||
362 | */ | ||
363 | unsigned int min_calls; | ||
364 | |||
365 | /** | ||
366 | * Maximum number of addresses the callback may report. | ||
367 | */ | ||
368 | unsigned int max_calls; | ||
369 | |||
370 | /** | ||
371 | * Minimum number of active addresses the callback may report. | ||
372 | */ | ||
373 | unsigned int min_active_calls; | ||
374 | |||
375 | /** | ||
376 | * Maximum number of active addresses the callback may report. | ||
377 | */ | ||
378 | unsigned int max_active_calls; | ||
379 | |||
380 | /** | ||
381 | * Number of calls the command invoked the callback with | ||
382 | * an address marked as active. (Set by command). | ||
383 | */ | ||
384 | unsigned int active_calls; | ||
385 | |||
386 | /** | ||
387 | * Number of calls the command invoked the callback with | ||
388 | * any address marked as available to ATS. (Set by command). | ||
389 | */ | ||
390 | unsigned int calls; | ||
391 | |||
392 | /** | ||
393 | * Location where we store the return value from | ||
394 | * #GNUNET_ATS_performance_list_addresses(). | ||
395 | */ | ||
396 | struct GNUNET_ATS_AddressListHandle *alh; | ||
397 | |||
398 | }; | ||
399 | |||
400 | |||
401 | /** | ||
402 | * A command for the test case interpreter. | ||
403 | */ | ||
404 | struct Command | ||
405 | { | ||
406 | /** | ||
407 | * Command code to run. | ||
408 | */ | ||
409 | enum CommandCode code; | ||
410 | |||
411 | /** | ||
412 | * Commands can be given a label so we can reference them later. | ||
413 | */ | ||
414 | const char *label; | ||
415 | |||
416 | /** | ||
417 | * Additional arguments to commands, if any. | ||
418 | */ | ||
419 | union { | ||
420 | |||
421 | struct CommandAddAddress add_address; | ||
422 | |||
423 | struct CommandDelAddress del_address; | ||
424 | |||
425 | struct CommandAwaitAddressSuggestion await_address_suggestion; | ||
426 | |||
427 | struct CommandAwaitDisconnectSuggestion await_disconnect_suggestion; | ||
428 | |||
429 | struct CommandRequestConnectionStart request_connection_start; | ||
430 | |||
431 | struct CommandRequestConnectionStop request_connection_stop; | ||
432 | |||
433 | struct CommandAwaitAddressInformation await_address_information; | ||
434 | |||
435 | struct CommandUpdateAddress update_address; | ||
436 | |||
437 | struct CommandAddSession add_session; | ||
438 | |||
439 | struct CommandDelSession del_session; | ||
440 | |||
441 | struct CommandChangePreference change_preference; | ||
442 | |||
443 | struct CommandProvideFeedback provide_feedback; | ||
444 | |||
445 | struct CommandListAddresses list_addresses; | ||
446 | |||
447 | } details; | ||
448 | |||
449 | }; | ||
450 | |||
451 | |||
452 | /** | ||
453 | * Run ATS test. | ||
454 | * | ||
455 | * @param argc length of @a argv | ||
456 | * @param argv command line | ||
457 | * @param cmds commands to run with the interpreter | ||
458 | * @param timeout how long is the test allowed to take? | ||
459 | * @return 0 on success | ||
460 | */ | ||
461 | int | ||
462 | TEST_ATS_run (int argc, | ||
463 | char *argv[], | ||
464 | struct Command *cmds, | ||
465 | struct GNUNET_TIME_Relative timeout); | ||
466 | |||
467 | #endif | ||
diff --git a/src/ats/test_ats_mlp.conf b/src/ats/test_ats_mlp.conf index 008bee904..51082ae93 100644 --- a/src/ats/test_ats_mlp.conf +++ b/src/ats/test_ats_mlp.conf | |||
@@ -1,5 +1,5 @@ | |||
1 | [PATHS] | 1 | [PATHS] |
2 | GNUNET_TEST_HOME = /tmp/test-ats-api-scheduling/ | 2 | GNUNET_TEST_HOME = /tmp/test-ats-mlp/ |
3 | 3 | ||
4 | [ats] | 4 | [ats] |
5 | # Enable MLP mode (default: NO) | 5 | # Enable MLP mode (default: NO) |
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 */ | ||
diff --git a/src/ats/test_ats_solver_add_address_and_request.c b/src/ats/test_ats_solver_add_address_and_request.c deleted file mode 100644 index 1a3545967..000000000 --- a/src/ats/test_ats_solver_add_address_and_request.c +++ /dev/null | |||
@@ -1,305 +0,0 @@ | |||
1 | /* | ||
2 | if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, &ats_perf_cb, NULL))) | ||
3 | { | ||
4 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
5 | "Failed to connect to performance API\n"); | ||
6 | GNUNET_SCHEDULER_add_now (end_badly, NULL); | ||
7 | } | ||
8 | This file is part of GNUnet. | ||
9 | Copyright (C) 2010-2013 Christian Grothoff (and other contributing authors) | ||
10 | |||
11 | GNUnet is free software; you can redistribute it and/or modify | ||
12 | it under the terms of the GNU General Public License as published | ||
13 | by the Free Software Foundation; either version 3, or (at your | ||
14 | option) any later version. | ||
15 | |||
16 | GNUnet is distributed in the hope that it will be useful, but | ||
17 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | General Public License for more details. | ||
20 | |||
21 | You should have received a copy of the GNU General Public License | ||
22 | along with GNUnet; see the file COPYING. If not, write to the | ||
23 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
24 | Boston, MA 02111-1307, USA. | ||
25 | */ | ||
26 | /** | ||
27 | * @file ats/test_ats_solver_add_address.c | ||
28 | * @brief solver test: add address, request address and wait for suggest | ||
29 | * @author Christian Grothoff | ||
30 | * @author Matthias Wachs | ||
31 | */ | ||
32 | #include "platform.h" | ||
33 | #include "gnunet_util_lib.h" | ||
34 | #include "gnunet_testbed_service.h" | ||
35 | #include "gnunet_ats_service.h" | ||
36 | #include "test_ats_api_common.h" | ||
37 | |||
38 | /** | ||
39 | * Timeout task | ||
40 | */ | ||
41 | static struct GNUNET_SCHEDULER_Task *die_task; | ||
42 | |||
43 | /** | ||
44 | * Statistics handle | ||
45 | */ | ||
46 | static struct GNUNET_STATISTICS_Handle *stats; | ||
47 | |||
48 | /** | ||
49 | * Scheduling handle | ||
50 | */ | ||
51 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
52 | |||
53 | /** | ||
54 | * Connectivity handle | ||
55 | */ | ||
56 | static struct GNUNET_ATS_ConnectivityHandle *connect_ats; | ||
57 | |||
58 | /** | ||
59 | * Return value | ||
60 | */ | ||
61 | static int ret; | ||
62 | |||
63 | /** | ||
64 | * Test address | ||
65 | */ | ||
66 | static struct Test_Address test_addr; | ||
67 | |||
68 | /** | ||
69 | * Test peer | ||
70 | */ | ||
71 | static struct PeerContext p; | ||
72 | |||
73 | /** | ||
74 | * HELLO address | ||
75 | */ | ||
76 | static struct GNUNET_HELLO_Address test_hello_address; | ||
77 | |||
78 | /** | ||
79 | * Session | ||
80 | */ | ||
81 | static void *test_session; | ||
82 | |||
83 | /** | ||
84 | * Test ats info | ||
85 | */ | ||
86 | static struct GNUNET_ATS_Information test_ats_info[2]; | ||
87 | |||
88 | /** | ||
89 | * Test ats count | ||
90 | */ | ||
91 | static uint32_t test_ats_count; | ||
92 | |||
93 | |||
94 | static int | ||
95 | stat_cb(void *cls, const char *subsystem, const char *name, uint64_t value, | ||
96 | int is_persistent); | ||
97 | |||
98 | |||
99 | static void | ||
100 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
101 | { | ||
102 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n"); | ||
103 | if (die_task != NULL) | ||
104 | { | ||
105 | GNUNET_SCHEDULER_cancel (die_task); | ||
106 | die_task = NULL; | ||
107 | } | ||
108 | |||
109 | if (NULL != sched_ats) | ||
110 | { | ||
111 | GNUNET_ATS_scheduling_done (sched_ats); | ||
112 | sched_ats = NULL; | ||
113 | } | ||
114 | if (NULL != connect_ats) | ||
115 | { | ||
116 | GNUNET_ATS_connectivity_done (connect_ats); | ||
117 | connect_ats = NULL; | ||
118 | } | ||
119 | |||
120 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
121 | if (NULL != stats) | ||
122 | { | ||
123 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
124 | stats = NULL; | ||
125 | } | ||
126 | |||
127 | free_test_address (&test_addr); | ||
128 | |||
129 | ret = 0; | ||
130 | } | ||
131 | |||
132 | |||
133 | static void | ||
134 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
135 | { | ||
136 | die_task = NULL; | ||
137 | end ( NULL, NULL); | ||
138 | ret = GNUNET_SYSERR; | ||
139 | } | ||
140 | |||
141 | |||
142 | static void | ||
143 | address_suggest_cb (void *cls, | ||
144 | const struct GNUNET_PeerIdentity *peer, | ||
145 | const struct GNUNET_HELLO_Address *address, | ||
146 | struct Session *session, | ||
147 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
148 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
149 | { | ||
150 | GNUNET_assert (NULL != address); | ||
151 | GNUNET_assert (NULL == session); | ||
152 | GNUNET_assert (ntohl(bandwidth_in.value__) > 0); | ||
153 | GNUNET_assert (ntohl(bandwidth_out.value__) > 0); | ||
154 | |||
155 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
156 | "Received sugggestion for peer `%s'\n", | ||
157 | GNUNET_i2s (peer)); | ||
158 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
159 | } | ||
160 | |||
161 | |||
162 | static int | ||
163 | stat_cb (void *cls, const char *subsystem, | ||
164 | const char *name, uint64_t value, | ||
165 | int is_persistent) | ||
166 | { | ||
167 | static struct GNUNET_ATS_ConnectivitySuggestHandle *sh; | ||
168 | |||
169 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
170 | "ATS statistics: `%s' `%s' %llu\n", | ||
171 | subsystem, | ||
172 | name, | ||
173 | value); | ||
174 | if (NULL == sh) | ||
175 | sh = GNUNET_ATS_connectivity_suggest (connect_ats, &p.id); | ||
176 | return GNUNET_OK; | ||
177 | } | ||
178 | |||
179 | |||
180 | static void | ||
181 | run (void *cls, | ||
182 | const struct GNUNET_CONFIGURATION_Handle *mycfg, | ||
183 | struct GNUNET_TESTING_Peer *peer) | ||
184 | { | ||
185 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
186 | stats = GNUNET_STATISTICS_create ("ats", mycfg); | ||
187 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
188 | |||
189 | |||
190 | connect_ats = GNUNET_ATS_connectivity_init (mycfg); | ||
191 | /* Connect to ATS scheduling */ | ||
192 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); | ||
193 | if (sched_ats == NULL) | ||
194 | { | ||
195 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
196 | "Could not connect to ATS scheduling!\n"); | ||
197 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
198 | return; | ||
199 | } | ||
200 | |||
201 | /* Set up peer */ | ||
202 | memset (&p.id, '1', sizeof (p.id)); | ||
203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
204 | "Created peer `%s'\n", | ||
205 | GNUNET_i2s_full(&p.id)); | ||
206 | |||
207 | /* Prepare ATS Information */ | ||
208 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
209 | test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); | ||
210 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
211 | test_ats_info[1].value = htonl(1); | ||
212 | test_ats_count = 2; | ||
213 | |||
214 | /* Adding address without session */ | ||
215 | test_session = NULL; | ||
216 | create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); | ||
217 | test_hello_address.peer = p.id; | ||
218 | test_hello_address.transport_name = test_addr.plugin; | ||
219 | test_hello_address.address = test_addr.addr; | ||
220 | test_hello_address.address_length = test_addr.addr_len; | ||
221 | |||
222 | /* Adding address */ | ||
223 | GNUNET_ATS_address_add (sched_ats, | ||
224 | &test_hello_address, NULL, | ||
225 | test_ats_info, test_ats_count); | ||
226 | } | ||
227 | |||
228 | |||
229 | int | ||
230 | main (int argc, char *argv[]) | ||
231 | { | ||
232 | char *sep; | ||
233 | char *src_filename = GNUNET_strdup (__FILE__); | ||
234 | char *test_filename = GNUNET_strdup (argv[0]); | ||
235 | char *config_file; | ||
236 | char *solver; | ||
237 | int delayed = GNUNET_NO; | ||
238 | |||
239 | ret = 0; | ||
240 | |||
241 | if (NULL == (sep = (strstr (src_filename,".c")))) | ||
242 | { | ||
243 | GNUNET_break (0); | ||
244 | return -1; | ||
245 | } | ||
246 | sep[0] = '\0'; | ||
247 | |||
248 | if (NULL != (sep = strstr (test_filename, ".exe"))) | ||
249 | sep[0] = '\0'; | ||
250 | |||
251 | if (NULL == (solver = strstr (test_filename, src_filename))) | ||
252 | { | ||
253 | GNUNET_break (0); | ||
254 | return -1; | ||
255 | } | ||
256 | |||
257 | solver += strlen (src_filename) +1; | ||
258 | |||
259 | if (NULL != strstr (solver, "delayed_")) | ||
260 | { | ||
261 | delayed = GNUNET_YES; | ||
262 | solver += strlen ("delayed_"); | ||
263 | } | ||
264 | |||
265 | if (0 == strcmp(solver, "proportional")) | ||
266 | { | ||
267 | if (delayed) | ||
268 | config_file = "test_ats_solver_delayed_proportional.conf"; | ||
269 | else | ||
270 | config_file = "test_ats_solver_proportional.conf"; | ||
271 | } | ||
272 | else if (0 == strcmp(solver, "mlp")) | ||
273 | { | ||
274 | if (delayed) | ||
275 | config_file = "test_ats_solver_delayed_mlp.conf"; | ||
276 | else | ||
277 | config_file = "test_ats_solver_mlp.conf"; | ||
278 | } | ||
279 | else if ((0 == strcmp(solver, "ril"))) | ||
280 | { | ||
281 | if (delayed) | ||
282 | config_file = "test_ats_solver_delayed_ril.conf"; | ||
283 | else | ||
284 | config_file = "test_ats_solver_ril.conf"; | ||
285 | } | ||
286 | else | ||
287 | { | ||
288 | GNUNET_break (0); | ||
289 | GNUNET_free (src_filename); | ||
290 | GNUNET_free (test_filename); | ||
291 | FPRINTF (stderr, "Invalid test name or configuration not found `%s'\n",src_filename); | ||
292 | return 1; | ||
293 | } | ||
294 | |||
295 | GNUNET_free (src_filename); | ||
296 | GNUNET_free (test_filename); | ||
297 | |||
298 | if (0 != GNUNET_TESTING_peer_run ("test-ats-solver", | ||
299 | config_file, &run, NULL )) | ||
300 | return GNUNET_SYSERR; | ||
301 | |||
302 | return ret; | ||
303 | } | ||
304 | |||
305 | /* end of file test_ats_solver_add_address.c */ | ||
diff --git a/src/ats/test_ats_solver_alternative_after_delete_address.c b/src/ats/test_ats_solver_alternative_after_delete_address.c deleted file mode 100644 index 77c903f1c..000000000 --- a/src/ats/test_ats_solver_alternative_after_delete_address.c +++ /dev/null | |||
@@ -1,455 +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_alternative_after_delete_address.c | ||
22 | * @brief solver test: add 2 addresses, request address, delete, expect alternative | ||
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 | * Connectivity handle | ||
49 | */ | ||
50 | static struct GNUNET_ATS_ConnectivityHandle *connect_ats; | ||
51 | |||
52 | /** | ||
53 | * Return value | ||
54 | */ | ||
55 | static int ret; | ||
56 | |||
57 | /** | ||
58 | * Test address | ||
59 | */ | ||
60 | static struct Test_Address test_addr; | ||
61 | |||
62 | /** | ||
63 | * Alternative test address | ||
64 | */ | ||
65 | static struct Test_Address alt_test_addr; | ||
66 | |||
67 | /** | ||
68 | * Test peer | ||
69 | */ | ||
70 | static struct PeerContext p; | ||
71 | |||
72 | /** | ||
73 | * HELLO address | ||
74 | */ | ||
75 | static struct GNUNET_HELLO_Address test_hello_address; | ||
76 | |||
77 | /** | ||
78 | * HELLO address | ||
79 | */ | ||
80 | static struct GNUNET_HELLO_Address alt_test_hello_address; | ||
81 | |||
82 | /** | ||
83 | * Session | ||
84 | */ | ||
85 | static void *test_session; | ||
86 | |||
87 | /** | ||
88 | * Test ats info | ||
89 | */ | ||
90 | static struct GNUNET_ATS_Information test_ats_info[2]; | ||
91 | |||
92 | /** | ||
93 | * Test ats count | ||
94 | */ | ||
95 | static uint32_t test_ats_count; | ||
96 | |||
97 | /** | ||
98 | * Test state | ||
99 | */ | ||
100 | static int addresses_added; | ||
101 | |||
102 | static int first_address_suggested; | ||
103 | |||
104 | static int first_address_deleted; | ||
105 | |||
106 | static int second_address_deleted; | ||
107 | |||
108 | static int second_address_suggested = GNUNET_YES; | ||
109 | |||
110 | static struct GNUNET_HELLO_Address *first_suggestion; | ||
111 | |||
112 | static struct GNUNET_HELLO_Address *second_suggestion; | ||
113 | |||
114 | /** | ||
115 | * 1st Address we will destroy. | ||
116 | */ | ||
117 | static struct GNUNET_ATS_AddressRecord *ar; | ||
118 | |||
119 | /** | ||
120 | * 2nd Address we will destroy. | ||
121 | */ | ||
122 | static struct GNUNET_ATS_AddressRecord *ar2; | ||
123 | |||
124 | |||
125 | static int | ||
126 | stat_cb (void *cls, const char *subsystem, const char *name, uint64_t value, | ||
127 | int is_persistent); | ||
128 | |||
129 | |||
130 | static void | ||
131 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
132 | { | ||
133 | if (NULL != die_task) | ||
134 | { | ||
135 | GNUNET_SCHEDULER_cancel (die_task); | ||
136 | die_task = NULL; | ||
137 | } | ||
138 | if (NULL != connect_ats) | ||
139 | { | ||
140 | GNUNET_ATS_connectivity_done (connect_ats); | ||
141 | connect_ats = NULL; | ||
142 | } | ||
143 | if (NULL != sched_ats) | ||
144 | { | ||
145 | GNUNET_ATS_scheduling_done (sched_ats); | ||
146 | sched_ats = NULL; | ||
147 | } | ||
148 | GNUNET_STATISTICS_watch_cancel (stats, | ||
149 | "ats", | ||
150 | "# addresses", | ||
151 | &stat_cb, NULL); | ||
152 | if (NULL != stats) | ||
153 | { | ||
154 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
155 | stats = NULL; | ||
156 | } | ||
157 | free_test_address (&test_addr); | ||
158 | GNUNET_free_non_null (first_suggestion); | ||
159 | first_suggestion = NULL; | ||
160 | GNUNET_free_non_null (second_suggestion); | ||
161 | second_suggestion = NULL; | ||
162 | ret = 0; | ||
163 | } | ||
164 | |||
165 | |||
166 | static void | ||
167 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
168 | { | ||
169 | |||
170 | die_task = NULL; | ||
171 | end ( NULL, NULL); | ||
172 | ret = GNUNET_SYSERR; | ||
173 | } | ||
174 | |||
175 | |||
176 | static void | ||
177 | end_badly_now () | ||
178 | { | ||
179 | if (NULL != die_task) | ||
180 | { | ||
181 | GNUNET_SCHEDULER_cancel (die_task); | ||
182 | die_task = NULL; | ||
183 | } | ||
184 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
185 | } | ||
186 | |||
187 | |||
188 | static void | ||
189 | address_suggest_cb (void *cls, | ||
190 | const struct GNUNET_PeerIdentity *peer, | ||
191 | const struct GNUNET_HELLO_Address *address, | ||
192 | struct Session *session, | ||
193 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
194 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
195 | { | ||
196 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
197 | "Received a sugggestion for peer `%s'\n", | ||
198 | GNUNET_i2s (peer)); | ||
199 | if (GNUNET_NO == first_address_suggested) | ||
200 | { | ||
201 | if (NULL == first_suggestion) | ||
202 | { | ||
203 | if ((NULL == address) || (NULL != session)) | ||
204 | { | ||
205 | GNUNET_break (0); | ||
206 | end_badly_now (); | ||
207 | return; | ||
208 | } | ||
209 | if ((ntohl(bandwidth_in.value__) == 0) || | ||
210 | (ntohl(bandwidth_out.value__) == 0)) | ||
211 | { | ||
212 | GNUNET_break (0); | ||
213 | end_badly_now (); | ||
214 | return; | ||
215 | } | ||
216 | |||
217 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
218 | "Received 1st sugggestion for peer `%s' : `%s'\n", | ||
219 | GNUNET_i2s (&address->peer), (char *) address->address); | ||
220 | |||
221 | first_suggestion = GNUNET_HELLO_address_copy (address); | ||
222 | first_address_suggested = GNUNET_YES; | ||
223 | |||
224 | |||
225 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
226 | "Deleting 1st address for peer `%s' : `%s'\n", | ||
227 | GNUNET_i2s (&address->peer), | ||
228 | (char *) address->address); | ||
229 | if (0 == (strcmp ((char *) address->address, | ||
230 | "test"))) | ||
231 | { | ||
232 | GNUNET_assert (NULL != ar); | ||
233 | GNUNET_ATS_address_destroy (ar); | ||
234 | ar = NULL; | ||
235 | } | ||
236 | else | ||
237 | { | ||
238 | GNUNET_assert (NULL != ar2); | ||
239 | GNUNET_ATS_address_destroy (ar2); | ||
240 | ar2 = NULL; | ||
241 | } | ||
242 | |||
243 | first_address_deleted = GNUNET_YES; | ||
244 | |||
245 | return; | ||
246 | } | ||
247 | } | ||
248 | if (GNUNET_YES == first_address_deleted) | ||
249 | { | ||
250 | if (NULL == second_suggestion) | ||
251 | { | ||
252 | if ((NULL == address) || (NULL != session)) | ||
253 | { | ||
254 | GNUNET_break (0); | ||
255 | end_badly_now (); | ||
256 | return; | ||
257 | } | ||
258 | |||
259 | if (0 != | ||
260 | memcmp (address->address, | ||
261 | first_suggestion->address, | ||
262 | (first_suggestion->address_length < address->address_length) | ||
263 | ? first_suggestion->address_length : address->address_length)) | ||
264 | { | ||
265 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
266 | "Received 2nd sugggestion for peer `%s' : `%s'\n", | ||
267 | GNUNET_i2s (&address->peer), | ||
268 | (char *) address->address); | ||
269 | second_suggestion = GNUNET_HELLO_address_copy (address); | ||
270 | second_address_suggested = GNUNET_YES; | ||
271 | |||
272 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
273 | "Deleting 2nd address for peer `%s' : `%s'\n", | ||
274 | GNUNET_i2s (&address->peer), | ||
275 | (char *) address->address); | ||
276 | if (NULL != ar) | ||
277 | { | ||
278 | GNUNET_assert (NULL == ar2); | ||
279 | GNUNET_ATS_address_destroy (ar); | ||
280 | ar = NULL; | ||
281 | } | ||
282 | else | ||
283 | { | ||
284 | GNUNET_assert (NULL != ar2); | ||
285 | GNUNET_ATS_address_destroy (ar2); | ||
286 | ar2 = NULL; | ||
287 | } | ||
288 | second_address_deleted = GNUNET_YES; | ||
289 | return; | ||
290 | } | ||
291 | } | ||
292 | } | ||
293 | if (GNUNET_YES == second_address_deleted) | ||
294 | { | ||
295 | /* Expecting disconnect */ | ||
296 | if ((ntohl(bandwidth_in.value__) == 0) && | ||
297 | (ntohl(bandwidth_out.value__) == 0)) | ||
298 | { | ||
299 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
300 | "ATS tells me to disconnect\n"); | ||
301 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
302 | return; | ||
303 | } | ||
304 | else | ||
305 | { | ||
306 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
307 | "Expected disconnect but received address `%s' with bandwidth \n", | ||
308 | (char *) address->address); | ||
309 | } | ||
310 | } | ||
311 | } | ||
312 | |||
313 | |||
314 | static int | ||
315 | stat_cb(void *cls, const char *subsystem, | ||
316 | const char *name, uint64_t value, | ||
317 | int is_persistent) | ||
318 | { | ||
319 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
320 | "ATS statistics: `%s' `%s' %llu\n", | ||
321 | subsystem, | ||
322 | name, | ||
323 | value); | ||
324 | if ((GNUNET_NO == addresses_added) && (value == 2)) | ||
325 | { | ||
326 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
327 | "All addresses added, requesting....\n"); | ||
328 | /* We have 2 addresses, so we can request */ | ||
329 | addresses_added = GNUNET_YES; | ||
330 | GNUNET_ATS_connectivity_suggest (connect_ats, &p.id); | ||
331 | } | ||
332 | return GNUNET_OK; | ||
333 | } | ||
334 | |||
335 | |||
336 | static void | ||
337 | run (void *cls, | ||
338 | const struct GNUNET_CONFIGURATION_Handle *mycfg, | ||
339 | struct GNUNET_TESTING_Peer *peer) | ||
340 | { | ||
341 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
342 | stats = GNUNET_STATISTICS_create ("ats", mycfg); | ||
343 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
344 | |||
345 | connect_ats = GNUNET_ATS_connectivity_init (mycfg); | ||
346 | |||
347 | /* Connect to ATS scheduling */ | ||
348 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); | ||
349 | if (sched_ats == NULL) | ||
350 | { | ||
351 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
352 | "Could not connect to ATS scheduling!\n"); | ||
353 | end_badly_now (); | ||
354 | return; | ||
355 | } | ||
356 | |||
357 | /* Set up peer */ | ||
358 | memset (&p.id, '1', sizeof (p.id)); | ||
359 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", | ||
360 | GNUNET_i2s_full(&p.id)); | ||
361 | |||
362 | /* Prepare ATS Information */ | ||
363 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
364 | test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); | ||
365 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
366 | test_ats_info[1].value = htonl(1); | ||
367 | test_ats_count = 2; | ||
368 | |||
369 | /* Adding address without session */ | ||
370 | test_session = NULL; | ||
371 | create_test_address (&test_addr, "test", test_session, | ||
372 | "test", strlen ("test") + 1); | ||
373 | test_hello_address.peer = p.id; | ||
374 | test_hello_address.transport_name = test_addr.plugin; | ||
375 | test_hello_address.address = test_addr.addr; | ||
376 | test_hello_address.address_length = test_addr.addr_len; | ||
377 | |||
378 | /* Adding alternative address without session */ | ||
379 | test_session = NULL; | ||
380 | create_test_address (&alt_test_addr, "test", test_session, | ||
381 | "alt_test", strlen ("alt_test") + 1); | ||
382 | alt_test_hello_address.peer = p.id; | ||
383 | alt_test_hello_address.transport_name = alt_test_addr.plugin; | ||
384 | alt_test_hello_address.address = alt_test_addr.addr; | ||
385 | alt_test_hello_address.address_length = alt_test_addr.addr_len; | ||
386 | |||
387 | |||
388 | /* Adding address */ | ||
389 | ar = GNUNET_ATS_address_add (sched_ats, &test_hello_address, NULL, | ||
390 | test_ats_info, test_ats_count); | ||
391 | /* Adding alternative address */ | ||
392 | ar2 = GNUNET_ATS_address_add (sched_ats, &alt_test_hello_address, NULL, | ||
393 | test_ats_info, test_ats_count); | ||
394 | } | ||
395 | |||
396 | |||
397 | int | ||
398 | main (int argc, char *argv[]) | ||
399 | { | ||
400 | char *sep; | ||
401 | char *src_filename = GNUNET_strdup (__FILE__); | ||
402 | char *test_filename = GNUNET_strdup (argv[0]); | ||
403 | const char *config_file; | ||
404 | char *solver; | ||
405 | |||
406 | ret = 0; | ||
407 | |||
408 | if (NULL == (sep = (strstr (src_filename, ".c")))) | ||
409 | { | ||
410 | GNUNET_break (0); | ||
411 | return -1; | ||
412 | } | ||
413 | sep[0] = '\0'; | ||
414 | |||
415 | if (NULL != (sep = strstr (test_filename, ".exe"))) | ||
416 | sep[0] = '\0'; | ||
417 | |||
418 | if (NULL == (solver = strstr (test_filename, src_filename))) | ||
419 | { | ||
420 | GNUNET_break (0); | ||
421 | return -1; | ||
422 | } | ||
423 | solver += strlen (src_filename) +1; | ||
424 | |||
425 | if (0 == strcmp(solver, "proportional")) | ||
426 | { | ||
427 | config_file = "test_ats_solver_proportional.conf"; | ||
428 | } | ||
429 | else if (0 == strcmp(solver, "mlp")) | ||
430 | { | ||
431 | config_file = "test_ats_solver_mlp.conf"; | ||
432 | } | ||
433 | else if ((0 == strcmp(solver, "ril"))) | ||
434 | { | ||
435 | config_file = "test_ats_solver_ril.conf"; | ||
436 | } | ||
437 | else | ||
438 | { | ||
439 | GNUNET_break (0); | ||
440 | GNUNET_free (src_filename); | ||
441 | GNUNET_free (test_filename); | ||
442 | return 1; | ||
443 | } | ||
444 | |||
445 | GNUNET_free (src_filename); | ||
446 | GNUNET_free (test_filename); | ||
447 | |||
448 | if (0 != GNUNET_TESTING_peer_run ("test-ats-solver", | ||
449 | config_file, &run, NULL )) | ||
450 | return GNUNET_SYSERR; | ||
451 | |||
452 | return ret; | ||
453 | } | ||
454 | |||
455 | /* end of file test_ats_solver_alternative_after_delete_address.c */ | ||
diff --git a/src/ats/test_ats_solver_request_and_add_address.c b/src/ats/test_ats_solver_request_and_add_address.c deleted file mode 100644 index 8514e8ddf..000000000 --- a/src/ats/test_ats_solver_request_and_add_address.c +++ /dev/null | |||
@@ -1,274 +0,0 @@ | |||
1 | /* | ||
2 | if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, &ats_perf_cb, NULL))) | ||
3 | { | ||
4 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
5 | "Failed to connect to performance API\n"); | ||
6 | GNUNET_SCHEDULER_add_now (end_badly, NULL); | ||
7 | } | ||
8 | This file is part of GNUnet. | ||
9 | Copyright (C) 2010-2013 Christian Grothoff (and other contributing authors) | ||
10 | |||
11 | GNUnet is free software; you can redistribute it and/or modify | ||
12 | it under the terms of the GNU General Public License as published | ||
13 | by the Free Software Foundation; either version 3, or (at your | ||
14 | option) any later version. | ||
15 | |||
16 | GNUnet is distributed in the hope that it will be useful, but | ||
17 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | General Public License for more details. | ||
20 | |||
21 | You should have received a copy of the GNU General Public License | ||
22 | along with GNUnet; see the file COPYING. If not, write to the | ||
23 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
24 | Boston, MA 02111-1307, USA. | ||
25 | */ | ||
26 | /** | ||
27 | * @file ats/test_ats_solver_add_address.c | ||
28 | * @brief solver test: request address, add address and wait for suggest | ||
29 | * @author Christian Grothoff | ||
30 | * @author Matthias Wachs | ||
31 | */ | ||
32 | #include "platform.h" | ||
33 | #include "gnunet_util_lib.h" | ||
34 | #include "gnunet_testbed_service.h" | ||
35 | #include "gnunet_ats_service.h" | ||
36 | #include "test_ats_api_common.h" | ||
37 | |||
38 | /** | ||
39 | * Timeout task | ||
40 | */ | ||
41 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
42 | |||
43 | /** | ||
44 | * Statistics handle | ||
45 | */ | ||
46 | static struct GNUNET_STATISTICS_Handle *stats; | ||
47 | |||
48 | /** | ||
49 | * Scheduling handle | ||
50 | */ | ||
51 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
52 | |||
53 | /** | ||
54 | * Connectivity handle | ||
55 | */ | ||
56 | static struct GNUNET_ATS_ConnectivityHandle *connect_ats; | ||
57 | |||
58 | /** | ||
59 | * Return value | ||
60 | */ | ||
61 | static int ret; | ||
62 | |||
63 | /** | ||
64 | * Test address | ||
65 | */ | ||
66 | static struct Test_Address test_addr; | ||
67 | |||
68 | /** | ||
69 | * Test peer | ||
70 | */ | ||
71 | static struct PeerContext p; | ||
72 | |||
73 | /** | ||
74 | * HELLO address | ||
75 | */ | ||
76 | static struct GNUNET_HELLO_Address test_hello_address; | ||
77 | |||
78 | /** | ||
79 | * Session | ||
80 | */ | ||
81 | static void *test_session; | ||
82 | |||
83 | /** | ||
84 | * Test ats info | ||
85 | */ | ||
86 | static struct GNUNET_ATS_Information test_ats_info[2]; | ||
87 | |||
88 | /** | ||
89 | * Test ats count | ||
90 | */ | ||
91 | static uint32_t test_ats_count; | ||
92 | |||
93 | |||
94 | static int | ||
95 | stat_cb(void *cls, const char *subsystem, const char *name, uint64_t value, | ||
96 | int is_persistent); | ||
97 | |||
98 | static void | ||
99 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
100 | { | ||
101 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n"); | ||
102 | if (die_task != NULL) | ||
103 | { | ||
104 | GNUNET_SCHEDULER_cancel (die_task); | ||
105 | die_task = NULL; | ||
106 | } | ||
107 | |||
108 | if (NULL != sched_ats) | ||
109 | { | ||
110 | GNUNET_ATS_scheduling_done (sched_ats); | ||
111 | sched_ats = NULL; | ||
112 | } | ||
113 | if (NULL != connect_ats) | ||
114 | { | ||
115 | GNUNET_ATS_connectivity_done (connect_ats); | ||
116 | connect_ats = NULL; | ||
117 | } | ||
118 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
119 | if (NULL != stats) | ||
120 | { | ||
121 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
122 | stats = NULL; | ||
123 | } | ||
124 | |||
125 | free_test_address (&test_addr); | ||
126 | |||
127 | ret = 0; | ||
128 | } | ||
129 | |||
130 | |||
131 | static void | ||
132 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
133 | { | ||
134 | die_task = NULL; | ||
135 | end ( NULL, NULL); | ||
136 | ret = GNUNET_SYSERR; | ||
137 | } | ||
138 | |||
139 | static void | ||
140 | address_suggest_cb (void *cls, | ||
141 | const struct GNUNET_PeerIdentity *peer, | ||
142 | const struct GNUNET_HELLO_Address *address, | ||
143 | struct Session *session, | ||
144 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
145 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
146 | { | ||
147 | |||
148 | GNUNET_assert (NULL != address); | ||
149 | GNUNET_assert (NULL == session); | ||
150 | |||
151 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received sugggestion for peer `%s'\n", | ||
152 | GNUNET_i2s (&address->peer)); | ||
153 | |||
154 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
155 | } | ||
156 | |||
157 | |||
158 | static int | ||
159 | stat_cb(void *cls, const char *subsystem, | ||
160 | const char *name, uint64_t value, | ||
161 | int is_persistent) | ||
162 | { | ||
163 | |||
164 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", | ||
165 | subsystem,name, value); | ||
166 | return GNUNET_OK; | ||
167 | } | ||
168 | |||
169 | static void | ||
170 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | ||
171 | struct GNUNET_TESTING_Peer *peer) | ||
172 | { | ||
173 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
174 | stats = GNUNET_STATISTICS_create ("ats", mycfg); | ||
175 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
176 | |||
177 | connect_ats = GNUNET_ATS_connectivity_init (mycfg); | ||
178 | /* Connect to ATS scheduling */ | ||
179 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); | ||
180 | if (sched_ats == NULL) | ||
181 | { | ||
182 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); | ||
183 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
184 | return; | ||
185 | } | ||
186 | |||
187 | /* Set up peer */ | ||
188 | memset (&p.id, '1', sizeof (p.id)); | ||
189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", | ||
190 | GNUNET_i2s_full(&p.id)); | ||
191 | |||
192 | /* Prepare ATS Information */ | ||
193 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
194 | test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); | ||
195 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
196 | test_ats_info[1].value = htonl(1); | ||
197 | test_ats_count = 2; | ||
198 | |||
199 | /* Adding address without session */ | ||
200 | test_session = NULL; | ||
201 | create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); | ||
202 | test_hello_address.peer = p.id; | ||
203 | test_hello_address.transport_name = test_addr.plugin; | ||
204 | test_hello_address.address = test_addr.addr; | ||
205 | test_hello_address.address_length = test_addr.addr_len; | ||
206 | |||
207 | /* Request */ | ||
208 | GNUNET_ATS_connectivity_suggest (connect_ats, &p.id); | ||
209 | |||
210 | |||
211 | /* Adding address */ | ||
212 | GNUNET_ATS_address_add (sched_ats, &test_hello_address, NULL, test_ats_info, test_ats_count); | ||
213 | } | ||
214 | |||
215 | |||
216 | int | ||
217 | main (int argc, char *argv[]) | ||
218 | { | ||
219 | char *sep; | ||
220 | char *src_filename = GNUNET_strdup (__FILE__); | ||
221 | char *test_filename = GNUNET_strdup (argv[0]); | ||
222 | char *config_file; | ||
223 | char *solver; | ||
224 | |||
225 | ret = 0; | ||
226 | |||
227 | if (NULL == (sep = (strstr (src_filename,".c")))) | ||
228 | { | ||
229 | GNUNET_break (0); | ||
230 | return -1; | ||
231 | } | ||
232 | sep[0] = '\0'; | ||
233 | |||
234 | if (NULL != (sep = strstr (test_filename, ".exe"))) | ||
235 | sep[0] = '\0'; | ||
236 | |||
237 | if (NULL == (solver = strstr (test_filename, src_filename))) | ||
238 | { | ||
239 | GNUNET_break (0); | ||
240 | return -1; | ||
241 | } | ||
242 | solver += strlen (src_filename) +1; | ||
243 | |||
244 | if (0 == strcmp(solver, "proportional")) | ||
245 | { | ||
246 | config_file = "test_ats_solver_proportional.conf"; | ||
247 | } | ||
248 | else if (0 == strcmp(solver, "mlp")) | ||
249 | { | ||
250 | config_file = "test_ats_solver_mlp.conf"; | ||
251 | } | ||
252 | else if ((0 == strcmp(solver, "ril"))) | ||
253 | { | ||
254 | config_file = "test_ats_solver_ril.conf"; | ||
255 | } | ||
256 | else | ||
257 | { | ||
258 | GNUNET_break (0); | ||
259 | GNUNET_free (src_filename); | ||
260 | GNUNET_free (test_filename); | ||
261 | return 1; | ||
262 | } | ||
263 | |||
264 | GNUNET_free (src_filename); | ||
265 | GNUNET_free (test_filename); | ||
266 | |||
267 | if (0 != GNUNET_TESTING_peer_run ("test-ats-solver", | ||
268 | config_file, &run, NULL )) | ||
269 | return GNUNET_SYSERR; | ||
270 | |||
271 | return ret; | ||
272 | } | ||
273 | |||
274 | /* end of file test_ats_solver_add_address.c */ | ||
diff --git a/src/ats/test_ats_solver_request_and_delete_address.c b/src/ats/test_ats_solver_request_and_delete_address.c deleted file mode 100644 index ac624f8ab..000000000 --- a/src/ats/test_ats_solver_request_and_delete_address.c +++ /dev/null | |||
@@ -1,307 +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_request_and_delete_address.c | ||
22 | * @brief solver test: add address, request address, delete address and wait for disconnect | ||
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 | * Connectivity handle | ||
49 | */ | ||
50 | static struct GNUNET_ATS_ConnectivityHandle *connect_ats; | ||
51 | |||
52 | /** | ||
53 | * Return value | ||
54 | */ | ||
55 | static int ret; | ||
56 | |||
57 | /** | ||
58 | * Test address | ||
59 | */ | ||
60 | static struct Test_Address test_addr; | ||
61 | |||
62 | /** | ||
63 | * Test peer | ||
64 | */ | ||
65 | static struct PeerContext p; | ||
66 | |||
67 | /** | ||
68 | * HELLO address | ||
69 | */ | ||
70 | static struct GNUNET_HELLO_Address test_hello_address; | ||
71 | |||
72 | /** | ||
73 | * Session | ||
74 | */ | ||
75 | static void *test_session; | ||
76 | |||
77 | /** | ||
78 | * Test ats info | ||
79 | */ | ||
80 | struct GNUNET_ATS_Information test_ats_info[2]; | ||
81 | |||
82 | /** | ||
83 | * Test ats count | ||
84 | */ | ||
85 | static uint32_t test_ats_count; | ||
86 | |||
87 | /** | ||
88 | * The address we will delete. | ||
89 | */ | ||
90 | static struct GNUNET_ATS_AddressRecord *ar; | ||
91 | |||
92 | static int address_deleted = GNUNET_NO; | ||
93 | |||
94 | |||
95 | static int | ||
96 | stat_cb(void *cls, const char *subsystem, const char *name, uint64_t value, | ||
97 | int is_persistent); | ||
98 | |||
99 | |||
100 | static void | ||
101 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
102 | { | ||
103 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n"); | ||
104 | if (die_task != NULL) | ||
105 | { | ||
106 | GNUNET_SCHEDULER_cancel (die_task); | ||
107 | die_task = NULL; | ||
108 | } | ||
109 | |||
110 | if (NULL != sched_ats) | ||
111 | { | ||
112 | GNUNET_ATS_scheduling_done (sched_ats); | ||
113 | sched_ats = NULL; | ||
114 | } | ||
115 | |||
116 | if (NULL != connect_ats) | ||
117 | { | ||
118 | GNUNET_ATS_connectivity_done (connect_ats); | ||
119 | connect_ats = NULL; | ||
120 | } | ||
121 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
122 | if (NULL != stats) | ||
123 | { | ||
124 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
125 | stats = NULL; | ||
126 | } | ||
127 | free_test_address (&test_addr); | ||
128 | ret = 0; | ||
129 | } | ||
130 | |||
131 | |||
132 | static void | ||
133 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
134 | { | ||
135 | die_task = NULL; | ||
136 | end (NULL, NULL); | ||
137 | ret = GNUNET_SYSERR; | ||
138 | } | ||
139 | |||
140 | |||
141 | static void | ||
142 | address_suggest_cb (void *cls, | ||
143 | const struct GNUNET_PeerIdentity *peer, | ||
144 | const struct GNUNET_HELLO_Address *address, | ||
145 | struct Session *session, | ||
146 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
147 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
148 | { | ||
149 | if (GNUNET_NO == address_deleted) | ||
150 | { | ||
151 | /* Expected address suggestion */ | ||
152 | GNUNET_assert (NULL != address); | ||
153 | GNUNET_assert (NULL == session); | ||
154 | GNUNET_assert (ntohl(bandwidth_in.value__) > 0); | ||
155 | GNUNET_assert (ntohl(bandwidth_out.value__) > 0); | ||
156 | |||
157 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
158 | "Received sugggestion for peer `%s', deleting address\n", | ||
159 | GNUNET_i2s (&address->peer)); | ||
160 | address_deleted = GNUNET_YES; | ||
161 | /* Destroying address and wait for disconnect suggestion */ | ||
162 | GNUNET_ATS_address_destroy (ar); | ||
163 | ar = NULL; | ||
164 | } | ||
165 | else | ||
166 | { | ||
167 | /* Expecting disconnect */ | ||
168 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
169 | "Received sugggestion for peer `%s': %u %u\n", | ||
170 | GNUNET_i2s (peer), | ||
171 | (unsigned int) ntohl (bandwidth_in.value__), | ||
172 | (unsigned int) ntohl (bandwidth_out.value__)); | ||
173 | |||
174 | if ((ntohl(bandwidth_in.value__) == 0) && | ||
175 | (ntohl(bandwidth_out.value__) == 0)) | ||
176 | { | ||
177 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done!\n"); | ||
178 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
179 | } | ||
180 | } | ||
181 | } | ||
182 | |||
183 | |||
184 | static int | ||
185 | stat_cb (void *cls, const char *subsystem, | ||
186 | const char *name, uint64_t value, | ||
187 | int is_persistent) | ||
188 | { | ||
189 | static struct GNUNET_ATS_ConnectivitySuggestHandle *sh; | ||
190 | |||
191 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
192 | "ATS statistics: `%s' `%s' %llu\n", | ||
193 | subsystem, | ||
194 | name, | ||
195 | value); | ||
196 | if (NULL == sh) | ||
197 | sh = GNUNET_ATS_connectivity_suggest (connect_ats, &p.id); | ||
198 | return GNUNET_OK; | ||
199 | } | ||
200 | |||
201 | |||
202 | static void | ||
203 | run (void *cls, | ||
204 | const struct GNUNET_CONFIGURATION_Handle *mycfg, | ||
205 | struct GNUNET_TESTING_Peer *peer) | ||
206 | { | ||
207 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
208 | stats = GNUNET_STATISTICS_create ("ats", mycfg); | ||
209 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
210 | |||
211 | connect_ats = GNUNET_ATS_connectivity_init (mycfg); | ||
212 | |||
213 | /* Connect to ATS scheduling */ | ||
214 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); | ||
215 | if (sched_ats == NULL) | ||
216 | { | ||
217 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); | ||
218 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
219 | return; | ||
220 | } | ||
221 | |||
222 | /* Set up peer */ | ||
223 | memset (&p.id, '1', sizeof (p.id)); | ||
224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", | ||
225 | GNUNET_i2s_full(&p.id)); | ||
226 | |||
227 | /* Prepare ATS Information */ | ||
228 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
229 | test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); | ||
230 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
231 | test_ats_info[1].value = htonl(1); | ||
232 | test_ats_count = 2; | ||
233 | |||
234 | /* Adding address without session */ | ||
235 | test_session = NULL; | ||
236 | create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); | ||
237 | test_hello_address.peer = p.id; | ||
238 | test_hello_address.transport_name = test_addr.plugin; | ||
239 | test_hello_address.address = test_addr.addr; | ||
240 | test_hello_address.address_length = test_addr.addr_len; | ||
241 | |||
242 | /* Adding address */ | ||
243 | ar = GNUNET_ATS_address_add (sched_ats, &test_hello_address, | ||
244 | NULL, | ||
245 | test_ats_info, test_ats_count); | ||
246 | } | ||
247 | |||
248 | |||
249 | int | ||
250 | main (int argc, char *argv[]) | ||
251 | { | ||
252 | char *sep; | ||
253 | char *src_filename = GNUNET_strdup (__FILE__); | ||
254 | char *test_filename = GNUNET_strdup (argv[0]); | ||
255 | char *config_file; | ||
256 | char *solver; | ||
257 | |||
258 | ret = 0; | ||
259 | |||
260 | if (NULL == (sep = (strstr (src_filename,".c")))) | ||
261 | { | ||
262 | GNUNET_break (0); | ||
263 | return -1; | ||
264 | } | ||
265 | sep[0] = '\0'; | ||
266 | |||
267 | if (NULL != (sep = strstr (test_filename, ".exe"))) | ||
268 | sep[0] = '\0'; | ||
269 | |||
270 | if (NULL == (solver = strstr (test_filename, src_filename))) | ||
271 | { | ||
272 | GNUNET_break (0); | ||
273 | return -1; | ||
274 | } | ||
275 | solver += strlen (src_filename) +1; | ||
276 | |||
277 | if (0 == strcmp(solver, "proportional")) | ||
278 | { | ||
279 | config_file = "test_ats_solver_proportional.conf"; | ||
280 | } | ||
281 | else if (0 == strcmp(solver, "mlp")) | ||
282 | { | ||
283 | config_file = "test_ats_solver_mlp.conf"; | ||
284 | } | ||
285 | else if ((0 == strcmp(solver, "ril"))) | ||
286 | { | ||
287 | config_file = "test_ats_solver_ril.conf"; | ||
288 | } | ||
289 | else | ||
290 | { | ||
291 | GNUNET_break (0); | ||
292 | GNUNET_free (src_filename); | ||
293 | GNUNET_free (test_filename); | ||
294 | return 1; | ||
295 | } | ||
296 | |||
297 | GNUNET_free (src_filename); | ||
298 | GNUNET_free (test_filename); | ||
299 | |||
300 | if (0 != GNUNET_TESTING_peer_run ("test-ats-solver", | ||
301 | config_file, &run, NULL )) | ||
302 | return GNUNET_SYSERR; | ||
303 | |||
304 | return ret; | ||
305 | } | ||
306 | |||
307 | /* end of file test_ats_solver_request_and_delete_address_proportional.c */ | ||