diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-11-19 14:06:32 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-11-19 14:06:32 +0000 |
commit | 5aeb7f512e5946aec63567e81c72d64523b17530 (patch) | |
tree | bb52f9972837d6bcbc97f6bbace1c9c7200b2ba0 /src/ats | |
parent | 7890a308739d2e4714ec5b9f1371da377c59e6b6 (diff) | |
download | gnunet-5aeb7f512e5946aec63567e81c72d64523b17530.tar.gz gnunet-5aeb7f512e5946aec63567e81c72d64523b17530.zip |
preference client management and test
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/Makefile.am | 33 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 15 | ||||
-rw-r--r-- | src/ats/libgnunet_plugin_ats_mlp.c | 3 | ||||
-rw-r--r-- | src/ats/test_ats_solver_preferences.c | 313 |
4 files changed, 362 insertions, 2 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index 714f3640d..4851ff8a5 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am | |||
@@ -25,6 +25,7 @@ if HAVE_LIBGLPK | |||
25 | GN_MLP_ADD_REQUEST_ADDRESS = test_ats_solver_add_address_and_request_mlp | 25 | GN_MLP_ADD_REQUEST_ADDRESS = test_ats_solver_add_address_and_request_mlp |
26 | GN_MLP_REQUEST_ADD_ADDRESS = test_ats_solver_request_and_add_address_mlp | 26 | GN_MLP_REQUEST_ADD_ADDRESS = test_ats_solver_request_and_add_address_mlp |
27 | GN_MLP_REQUEST_DELETE_ADDRESS = test_ats_solver_request_and_delete_address_mlp | 27 | GN_MLP_REQUEST_DELETE_ADDRESS = test_ats_solver_request_and_delete_address_mlp |
28 | GN_MLP_PREFERENCES_ADDRESS = test_ats_solver_preferences_mlp | ||
28 | GN_MLP_ALTERNATIVE_DELETE_ADDRESS = test_ats_solver_alternative_after_delete_address_mlp | 29 | GN_MLP_ALTERNATIVE_DELETE_ADDRESS = test_ats_solver_alternative_after_delete_address_mlp |
29 | GN_MLP_SOLVER_PERF = perf_ats_solver_mlp | 30 | GN_MLP_SOLVER_PERF = perf_ats_solver_mlp |
30 | endif | 31 | endif |
@@ -123,11 +124,14 @@ TESTING_TESTS = \ | |||
123 | test_ats_solver_request_and_add_address_proportional \ | 124 | test_ats_solver_request_and_add_address_proportional \ |
124 | test_ats_solver_request_and_delete_address_proportional \ | 125 | test_ats_solver_request_and_delete_address_proportional \ |
125 | test_ats_solver_alternative_after_delete_address_proportional \ | 126 | test_ats_solver_alternative_after_delete_address_proportional \ |
127 | test_ats_solver_preferences_proportional \ | ||
128 | test_ats_solver_preferences_ril \ | ||
126 | $(GN_MLP_ADD_ADDRESS) \ | 129 | $(GN_MLP_ADD_ADDRESS) \ |
127 | $(GN_MLP_ADD_REQUEST_ADDRESS) \ | 130 | $(GN_MLP_ADD_REQUEST_ADDRESS) \ |
128 | $(GN_MLP_REQUEST_ADD_ADDRESS) \ | 131 | $(GN_MLP_REQUEST_ADD_ADDRESS) \ |
129 | $(GN_MLP_REQUEST_DELETE_ADDRESS) \ | 132 | $(GN_MLP_REQUEST_DELETE_ADDRESS) \ |
130 | $(GN_MLP_ALTERNATIVE_DELETE_ADDRESS) \ | 133 | $(GN_MLP_ALTERNATIVE_DELETE_ADDRESS) \ |
134 | $(GN_MLP_PREFERENCES_ADDRESS) \ | ||
131 | test_ats_solver_add_address_ril \ | 135 | test_ats_solver_add_address_ril \ |
132 | test_ats_solver_add_address_and_request_ril \ | 136 | test_ats_solver_add_address_and_request_ril \ |
133 | test_ats_solver_request_and_add_address_ril \ | 137 | test_ats_solver_request_and_add_address_ril \ |
@@ -405,6 +409,16 @@ test_ats_solver_alternative_after_delete_address_proportional_LDADD = \ | |||
405 | $(top_builddir)/src/hello/libgnunethello.la \ | 409 | $(top_builddir)/src/hello/libgnunethello.la \ |
406 | $(top_builddir)/src/ats/libgnunetats.la \ | 410 | $(top_builddir)/src/ats/libgnunetats.la \ |
407 | $(top_builddir)/src/statistics/libgnunetstatistics.la | 411 | $(top_builddir)/src/statistics/libgnunetstatistics.la |
412 | |||
413 | test_ats_solver_preferences_proportional_SOURCES = \ | ||
414 | test_ats_solver_preferences.c \ | ||
415 | test_ats_api_common.c test_ats_api_common.h | ||
416 | test_ats_solver_preferences_proportional_LDADD = \ | ||
417 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
418 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
419 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
420 | $(top_builddir)/src/ats/libgnunetats.la \ | ||
421 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
408 | 422 | ||
409 | if HAVE_LIBGLPK | 423 | if HAVE_LIBGLPK |
410 | test_ats_solver_alternative_after_delete_address_mlp_SOURCES = \ | 424 | test_ats_solver_alternative_after_delete_address_mlp_SOURCES = \ |
@@ -416,6 +430,16 @@ test_ats_solver_alternative_after_delete_address_mlp_LDADD = \ | |||
416 | $(top_builddir)/src/hello/libgnunethello.la \ | 430 | $(top_builddir)/src/hello/libgnunethello.la \ |
417 | $(top_builddir)/src/ats/libgnunetats.la \ | 431 | $(top_builddir)/src/ats/libgnunetats.la \ |
418 | $(top_builddir)/src/statistics/libgnunetstatistics.la | 432 | $(top_builddir)/src/statistics/libgnunetstatistics.la |
433 | |||
434 | test_ats_solver_preferences_mlp_SOURCES = \ | ||
435 | test_ats_solver_preferences.c \ | ||
436 | test_ats_api_common.c test_ats_api_common.h | ||
437 | test_ats_solver_preferences_mlp_LDADD = \ | ||
438 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
439 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
440 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
441 | $(top_builddir)/src/ats/libgnunetats.la \ | ||
442 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
419 | endif | 443 | endif |
420 | 444 | ||
421 | test_ats_solver_alternative_after_delete_address_ril_SOURCES = \ | 445 | test_ats_solver_alternative_after_delete_address_ril_SOURCES = \ |
@@ -460,6 +484,15 @@ perf_ats_solver_ril_LDADD = \ | |||
460 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 484 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
461 | $(top_builddir)/src/ats/libgnunetats.la | 485 | $(top_builddir)/src/ats/libgnunetats.la |
462 | 486 | ||
487 | test_ats_solver_preferences_ril_SOURCES = \ | ||
488 | test_ats_solver_preferences.c \ | ||
489 | test_ats_api_common.c test_ats_api_common.h | ||
490 | test_ats_solver_preferences_ril_LDADD = \ | ||
491 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
492 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
493 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
494 | $(top_builddir)/src/ats/libgnunetats.la \ | ||
495 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
463 | 496 | ||
464 | EXTRA_DIST = \ | 497 | EXTRA_DIST = \ |
465 | ats.h \ | 498 | ats.h \ |
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 746dbd7e3..7d0eb48ea 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -291,6 +291,11 @@ struct GAS_Addresses_Handle | |||
291 | int running; | 291 | int running; |
292 | 292 | ||
293 | /** | 293 | /** |
294 | * Preferences clients | ||
295 | */ | ||
296 | int pref_clients; | ||
297 | |||
298 | /** | ||
294 | * Configured ATS solver | 299 | * Configured ATS solver |
295 | */ | 300 | */ |
296 | int ats_mode; | 301 | int ats_mode; |
@@ -1721,8 +1726,10 @@ GAS_addresses_preference_client_disconnect (struct GAS_Addresses_Handle *handle, | |||
1721 | GNUNET_CONTAINER_DLL_remove (handle->preference_clients_head, | 1726 | GNUNET_CONTAINER_DLL_remove (handle->preference_clients_head, |
1722 | handle->preference_clients_tail, pc); | 1727 | handle->preference_clients_tail, pc); |
1723 | GNUNET_free (pc); | 1728 | GNUNET_free (pc); |
1729 | GNUNET_assert (handle->pref_clients > 0); | ||
1730 | handle->pref_clients --; | ||
1731 | GNUNET_STATISTICS_set (handle->stat, "# active performance clients", handle->pref_clients, GNUNET_NO); | ||
1724 | } | 1732 | } |
1725 | |||
1726 | GAS_normalization_preference_client_disconnect (client); | 1733 | GAS_normalization_preference_client_disconnect (client); |
1727 | } | 1734 | } |
1728 | 1735 | ||
@@ -1764,6 +1771,8 @@ GAS_addresses_preference_change (struct GAS_Addresses_Handle *handle, | |||
1764 | pc->client = client; | 1771 | pc->client = client; |
1765 | GNUNET_CONTAINER_DLL_insert (handle->preference_clients_head, | 1772 | GNUNET_CONTAINER_DLL_insert (handle->preference_clients_head, |
1766 | handle->preference_clients_tail, pc); | 1773 | handle->preference_clients_tail, pc); |
1774 | handle->pref_clients ++; | ||
1775 | GNUNET_STATISTICS_set (handle->stat, "# active performance clients", handle->pref_clients, GNUNET_NO); | ||
1767 | } | 1776 | } |
1768 | 1777 | ||
1769 | handle->env.sf.s_bulk_start (handle->solver); | 1778 | handle->env.sf.s_bulk_start (handle->solver); |
@@ -2019,6 +2028,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2019 | ah->stat = (struct GNUNET_STATISTICS_Handle *) stats; | 2028 | ah->stat = (struct GNUNET_STATISTICS_Handle *) stats; |
2020 | /* Initialize the addresses database */ | 2029 | /* Initialize the addresses database */ |
2021 | ah->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); | 2030 | ah->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); |
2031 | ah->pref_clients = 0; | ||
2022 | GNUNET_assert(NULL != ah->addresses); | 2032 | GNUNET_assert(NULL != ah->addresses); |
2023 | 2033 | ||
2024 | /* Figure out configured solution method */ | 2034 | /* Figure out configured solution method */ |
@@ -2205,6 +2215,9 @@ GAS_addresses_done (struct GAS_Addresses_Handle *handle) | |||
2205 | { | 2215 | { |
2206 | GNUNET_CONTAINER_DLL_remove (handle->preference_clients_head, | 2216 | GNUNET_CONTAINER_DLL_remove (handle->preference_clients_head, |
2207 | handle->preference_clients_tail, pcur); | 2217 | handle->preference_clients_tail, pcur); |
2218 | GNUNET_assert (handle->pref_clients > 0); | ||
2219 | handle->pref_clients --; | ||
2220 | GNUNET_STATISTICS_set (handle->stat, "# active performance clients", handle->pref_clients, GNUNET_NO); | ||
2208 | GNUNET_free (pcur); | 2221 | GNUNET_free (pcur); |
2209 | } | 2222 | } |
2210 | 2223 | ||
diff --git a/src/ats/libgnunet_plugin_ats_mlp.c b/src/ats/libgnunet_plugin_ats_mlp.c index cdd9ac64f..07f77161f 100644 --- a/src/ats/libgnunet_plugin_ats_mlp.c +++ b/src/ats/libgnunet_plugin_ats_mlp.c | |||
@@ -1800,8 +1800,9 @@ GAS_mlp_address_change_preference (void *solver, | |||
1800 | return; | 1800 | return; |
1801 | } | 1801 | } |
1802 | p->f = get_peer_pref_value (mlp, peer); | 1802 | p->f = get_peer_pref_value (mlp, peer); |
1803 | /* | ||
1803 | LOG (GNUNET_ERROR_TYPE_ERROR, "PEER PREF: %s %.2f\n", | 1804 | LOG (GNUNET_ERROR_TYPE_ERROR, "PEER PREF: %s %.2f\n", |
1804 | GNUNET_i2s(peer), p->f); | 1805 | GNUNET_i2s(peer), p->f);*/ |
1805 | mlp_create_problem_update_value (&mlp->p, p->r_c9, mlp->p.c_r, -p->f, __LINE__); | 1806 | mlp_create_problem_update_value (&mlp->p, p->r_c9, mlp->p.c_r, -p->f, __LINE__); |
1806 | 1807 | ||
1807 | /* Problem size changed: new address for peer with pending request */ | 1808 | /* Problem size changed: new address for peer with pending request */ |
diff --git a/src/ats/test_ats_solver_preferences.c b/src/ats/test_ats_solver_preferences.c new file mode 100644 index 000000000..0e96dc129 --- /dev/null +++ b/src/ats/test_ats_solver_preferences.c | |||
@@ -0,0 +1,313 @@ | |||
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 | (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_preferences.c | ||
28 | * @brief solver test: preference client handling | ||
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 GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
42 | |||
43 | /** | ||
44 | * Statistics handle | ||
45 | */ | ||
46 | struct GNUNET_STATISTICS_Handle *stats; | ||
47 | |||
48 | /** | ||
49 | * Scheduling handle | ||
50 | */ | ||
51 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
52 | |||
53 | /** | ||
54 | * Scheduling handle | ||
55 | */ | ||
56 | static struct GNUNET_ATS_PerformanceHandle *perf_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 | 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 | struct GNUNET_ATS_Information test_ats_info[2]; | ||
87 | |||
88 | /** | ||
89 | * Test ats count | ||
90 | */ | ||
91 | uint32_t test_ats_count; | ||
92 | |||
93 | static int | ||
94 | stat_cb (void *cls, const char *subsystem, const char *name, uint64_t value, | ||
95 | int is_persistent); | ||
96 | |||
97 | static void | ||
98 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
99 | { | ||
100 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Done!\n"); | ||
101 | |||
102 | if (die_task != GNUNET_SCHEDULER_NO_TASK ) | ||
103 | { | ||
104 | GNUNET_SCHEDULER_cancel (die_task); | ||
105 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
106 | } | ||
107 | |||
108 | if (NULL != sched_ats) | ||
109 | { | ||
110 | GNUNET_ATS_scheduling_done (sched_ats); | ||
111 | sched_ats = NULL; | ||
112 | } | ||
113 | |||
114 | if (NULL != perf_ats) | ||
115 | { | ||
116 | GNUNET_ATS_performance_done (perf_ats); | ||
117 | perf_ats = NULL; | ||
118 | } | ||
119 | |||
120 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# active performance clients", &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 | static void | ||
133 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
134 | { | ||
135 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
136 | end (NULL, NULL ); | ||
137 | ret = GNUNET_SYSERR; | ||
138 | } | ||
139 | |||
140 | |||
141 | static void | ||
142 | perf_info_cb (void *cls, | ||
143 | const struct GNUNET_HELLO_Address *address, int address_active, | ||
144 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
145 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
146 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) | ||
147 | { | ||
148 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "ATS performance info: `%s'\n", | ||
149 | GNUNET_i2s (&address->peer)); | ||
150 | } | ||
151 | |||
152 | static void | ||
153 | address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, | ||
154 | struct Session *session, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
155 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
156 | const struct GNUNET_ATS_Information *atsi, uint32_t ats_count) | ||
157 | { | ||
158 | int c; | ||
159 | double pref_val; | ||
160 | int prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceType; | ||
161 | |||
162 | if (NULL == perf_ats) | ||
163 | return; | ||
164 | for (c = 1; c < GNUNET_ATS_PreferenceCount; c++) | ||
165 | { | ||
166 | pref_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10); | ||
167 | GNUNET_ATS_performance_change_preference (perf_ats, | ||
168 | &test_hello_address.peer, prefs[c], pref_val, | ||
169 | GNUNET_ATS_PREFERENCE_END); | ||
170 | } | ||
171 | } | ||
172 | |||
173 | static int | ||
174 | stat_cb (void *cls, const char *subsystem, const char *name, uint64_t value, | ||
175 | int is_persistent) | ||
176 | { | ||
177 | static int last_value = 0; | ||
178 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", | ||
179 | subsystem, name, value); | ||
180 | |||
181 | if ((0 == last_value) && (1 == value)) | ||
182 | { | ||
183 | if (perf_ats != NULL) | ||
184 | { | ||
185 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Disconnecting performance client\n"); | ||
186 | GNUNET_ATS_performance_done(perf_ats); | ||
187 | perf_ats = NULL; | ||
188 | } | ||
189 | } | ||
190 | if ((1 == last_value) && (0 == value)) | ||
191 | { | ||
192 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
193 | } | ||
194 | last_value = value; | ||
195 | |||
196 | return GNUNET_OK; | ||
197 | } | ||
198 | |||
199 | static void | ||
200 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | ||
201 | struct GNUNET_TESTING_Peer *peer) | ||
202 | { | ||
203 | |||
204 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); | ||
205 | stats = GNUNET_STATISTICS_create ("ats", mycfg); | ||
206 | GNUNET_STATISTICS_watch (stats, "ats", "# active performance clients", &stat_cb, NULL ); | ||
207 | |||
208 | /* Connect to ATS scheduling */ | ||
209 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL ); | ||
210 | if (sched_ats == NULL ) | ||
211 | { | ||
212 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
213 | "Could not connect to ATS scheduling!\n"); | ||
214 | GNUNET_SCHEDULER_add_now (&end_badly, NULL ); | ||
215 | return; | ||
216 | } | ||
217 | |||
218 | perf_ats = GNUNET_ATS_performance_init (mycfg, &perf_info_cb, NULL ); | ||
219 | if (perf_ats == NULL ) | ||
220 | { | ||
221 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
222 | "Could not connect to ATS performance!\n"); | ||
223 | GNUNET_SCHEDULER_add_now (&end_badly, NULL ); | ||
224 | return; | ||
225 | } | ||
226 | |||
227 | /* Set up peer */ | ||
228 | memset (&p.id, '1', sizeof(p.id)); | ||
229 | |||
230 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", | ||
231 | GNUNET_i2s_full (&p.id)); | ||
232 | |||
233 | /* Prepare ATS Information */ | ||
234 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
235 | test_ats_info[0].value = htonl (GNUNET_ATS_NET_WAN); | ||
236 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
237 | test_ats_info[1].value = htonl (1); | ||
238 | test_ats_count = 2; | ||
239 | |||
240 | /* Adding address without session */ | ||
241 | test_session = NULL; | ||
242 | create_test_address (&test_addr, "test", test_session, "test", | ||
243 | strlen ("test") + 1); | ||
244 | test_hello_address.peer = p.id; | ||
245 | test_hello_address.transport_name = test_addr.plugin; | ||
246 | test_hello_address.address = test_addr.addr; | ||
247 | test_hello_address.address_length = test_addr.addr_len; | ||
248 | |||
249 | /* Adding address */ | ||
250 | GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, | ||
251 | test_ats_info, test_ats_count); | ||
252 | GNUNET_ATS_suggest_address(sched_ats, &test_hello_address.peer); | ||
253 | } | ||
254 | |||
255 | int | ||
256 | main (int argc, char *argv[]) | ||
257 | { | ||
258 | char *sep; | ||
259 | char *src_filename = GNUNET_strdup (__FILE__); | ||
260 | char *test_filename = GNUNET_strdup (argv[0]); | ||
261 | char *config_file; | ||
262 | char *solver; | ||
263 | |||
264 | ret = 0; | ||
265 | |||
266 | if (NULL == (sep = (strstr (src_filename, ".c")))) | ||
267 | { | ||
268 | GNUNET_break(0); | ||
269 | return -1; | ||
270 | } | ||
271 | sep[0] = '\0'; | ||
272 | |||
273 | if (NULL != (sep = strstr (test_filename, ".exe"))) | ||
274 | sep[0] = '\0'; | ||
275 | |||
276 | if (NULL == (solver = strstr (test_filename, src_filename))) | ||
277 | { | ||
278 | GNUNET_break(0); | ||
279 | return -1; | ||
280 | } | ||
281 | solver += strlen (src_filename) + 1; | ||
282 | |||
283 | if (0 == strcmp (solver, "proportional")) | ||
284 | { | ||
285 | config_file = "test_ats_solver_proportional.conf"; | ||
286 | } | ||
287 | else if (0 == strcmp (solver, "mlp")) | ||
288 | { | ||
289 | config_file = "test_ats_solver_mlp.conf"; | ||
290 | } | ||
291 | else if ((0 == strcmp (solver, "ril"))) | ||
292 | { | ||
293 | config_file = "test_ats_solver_ril.conf"; | ||
294 | } | ||
295 | else | ||
296 | { | ||
297 | GNUNET_break(0); | ||
298 | GNUNET_free(src_filename); | ||
299 | GNUNET_free(test_filename); | ||
300 | return 1; | ||
301 | } | ||
302 | |||
303 | GNUNET_free(src_filename); | ||
304 | GNUNET_free(test_filename); | ||
305 | |||
306 | if (0 | ||
307 | != GNUNET_TESTING_peer_run ("test-ats-solver", config_file, &run, NULL )) | ||
308 | return GNUNET_SYSERR; | ||
309 | |||
310 | return ret; | ||
311 | } | ||
312 | |||
313 | /* end of file test_ats_solver_preferences.c */ | ||