diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-03-26 10:07:05 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-03-26 10:07:05 +0000 |
commit | da961ee2b22e226be17620b3cafee094189cce9e (patch) | |
tree | 7fb020485cc3384276df44c0984ea5b20fdd90b0 /src/ats | |
parent | 89b390847d859ed9edcf9edd3f1b375ca38d1206 (diff) | |
download | gnunet-da961ee2b22e226be17620b3cafee094189cce9e.tar.gz gnunet-da961ee2b22e226be17620b3cafee094189cce9e.zip |
preliminary change
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/test_ats_api_performance_monitor.c | 188 |
1 files changed, 138 insertions, 50 deletions
diff --git a/src/ats/test_ats_api_performance_monitor.c b/src/ats/test_ats_api_performance_monitor.c index 9682b8dc9..86a957fcc 100644 --- a/src/ats/test_ats_api_performance_monitor.c +++ b/src/ats/test_ats_api_performance_monitor.c | |||
@@ -19,7 +19,8 @@ | |||
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/test_ats_api_performance_monitor.c | 21 | * @file ats/test_ats_api_performance_monitor.c |
22 | * @brief test performance monitoring | 22 | * @brief Test performance API: |
23 | * Add an address for a peer and request it. We expect an monitor callback | ||
23 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
24 | * @author Matthias Wachs | 25 | * @author Matthias Wachs |
25 | */ | 26 | */ |
@@ -31,7 +32,7 @@ | |||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) | 32 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) |
32 | #define SHUTDOWN_CORRECT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 33 | #define SHUTDOWN_CORRECT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
33 | 34 | ||
34 | #define ATS_COUNT 3 | 35 | #define ATS_COUNT 2 |
35 | 36 | ||
36 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | 37 | static GNUNET_SCHEDULER_TaskIdentifier die_task; |
37 | static GNUNET_SCHEDULER_TaskIdentifier stage_task; | 38 | static GNUNET_SCHEDULER_TaskIdentifier stage_task; |
@@ -42,23 +43,40 @@ static struct GNUNET_ATS_SchedulingHandle *sh; | |||
42 | 43 | ||
43 | static struct GNUNET_ATS_PerformanceHandle *ph; | 44 | static struct GNUNET_ATS_PerformanceHandle *ph; |
44 | 45 | ||
45 | static struct GNUNET_HELLO_Address addr; | 46 | static struct GNUNET_HELLO_Address addr[2]; |
46 | 47 | ||
47 | static struct GNUNET_ATS_Information atsi[ATS_COUNT]; | 48 | static struct GNUNET_ATS_Information atsi[ATS_COUNT]; |
48 | 49 | ||
49 | static int ret; | 50 | static int ret; |
50 | 51 | ||
52 | static int res_suggest_cb_p0; | ||
53 | static int res_suggest_cb_p1; | ||
54 | |||
55 | static int res_perf_cb_p0; | ||
56 | static int res_perf_cb_p1; | ||
57 | |||
58 | /** | ||
59 | * Stage 0: Init, request address and wait for peer0 suggest cb | ||
60 | * Stage 1: Got peer0 suggest cb, expect monitoring cb | ||
61 | * Stage 2: Got peer0 monitoring cb, update address and expect monitor cb | ||
62 | * Stage 3: Got 2nd peer0 monitoring cb, shutdown | ||
63 | */ | ||
64 | |||
65 | static int stage; | ||
66 | |||
67 | |||
51 | static void cleanup_addresses () | 68 | static void cleanup_addresses () |
52 | { | 69 | { |
53 | GNUNET_ATS_address_destroyed (sh, &addr, NULL); | 70 | GNUNET_ATS_address_destroyed (sh, &addr[0], NULL); |
71 | GNUNET_ATS_address_destroyed (sh, &addr[1], NULL); | ||
54 | } | 72 | } |
55 | 73 | ||
56 | static void setup_addresses () | 74 | static void setup_addresses () |
57 | { | 75 | { |
58 | memset (&addr.peer,'\0', sizeof (addr.peer)); | 76 | memset (&addr[0].peer,'\0', sizeof (addr[0].peer)); |
59 | addr.transport_name = "test"; | 77 | addr[0].transport_name = "test0"; |
60 | addr.address = NULL; | 78 | addr[0].address = "test_addr0"; |
61 | addr.address_length = 0; | 79 | addr[0].address_length = strlen ("test_addr0") + 1; |
62 | atsi[0].type = htonl(GNUNET_ATS_NETWORK_TYPE); | 80 | atsi[0].type = htonl(GNUNET_ATS_NETWORK_TYPE); |
63 | atsi[0].value = htonl(GNUNET_ATS_NET_LAN); | 81 | atsi[0].value = htonl(GNUNET_ATS_NET_LAN); |
64 | 82 | ||
@@ -68,7 +86,14 @@ static void setup_addresses () | |||
68 | atsi[2].type = htonl(GNUNET_ATS_QUALITY_NET_DISTANCE); | 86 | atsi[2].type = htonl(GNUNET_ATS_QUALITY_NET_DISTANCE); |
69 | atsi[2].value = htonl(5); | 87 | atsi[2].value = htonl(5); |
70 | 88 | ||
71 | GNUNET_ATS_address_add (sh, &addr, NULL, atsi, ATS_COUNT); | 89 | GNUNET_ATS_address_add (sh, &addr[0], NULL, atsi, ATS_COUNT); |
90 | |||
91 | memset (&addr[1].peer,'\1', sizeof (addr[1].peer)); | ||
92 | addr[1].transport_name = "test1"; | ||
93 | addr[1].address = "test_addr1"; | ||
94 | addr[1].address_length = strlen ("test_addr1") + 1; | ||
95 | |||
96 | GNUNET_ATS_address_add (sh, &addr[1], NULL, atsi, ATS_COUNT); | ||
72 | } | 97 | } |
73 | 98 | ||
74 | 99 | ||
@@ -125,9 +150,13 @@ next_stage (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
125 | stage_counter++; | 150 | stage_counter++; |
126 | return; | 151 | return; |
127 | } | 152 | } |
153 | if (1 == stage_counter) | ||
154 | { | ||
155 | |||
156 | } | ||
128 | else | 157 | else |
129 | { | 158 | { |
130 | end_now (0); | 159 | end_now (1); |
131 | } | 160 | } |
132 | } | 161 | } |
133 | 162 | ||
@@ -146,62 +175,91 @@ perf_mon_cb (void *cls, | |||
146 | const struct GNUNET_ATS_Information *ats, | 175 | const struct GNUNET_ATS_Information *ats, |
147 | uint32_t ats_count) | 176 | uint32_t ats_count) |
148 | { | 177 | { |
149 | static int stage_counter = 0; | ||
150 | int c1; | 178 | int c1; |
151 | int c2; | 179 | int c2; |
152 | int c3; | 180 | int c3; |
153 | 181 | ||
154 | if (0 == stage_counter) | 182 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
183 | "ATS notifies about perfomance change for peer `%s'\n", GNUNET_i2s (peer)); | ||
184 | |||
185 | if ((1 != stage) || (2 == stage)) | ||
155 | { | 186 | { |
156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received initial callback for peer `%s' with %u information\n", | 187 | GNUNET_break (0); |
157 | GNUNET_i2s (&addr.peer), ats_count); | 188 | end_now(1); |
158 | if ((0 != memcmp (peer, &addr.peer, sizeof (addr.peer))) || | 189 | return; |
159 | (ats_count < ATS_COUNT)) | 190 | } |
160 | { | 191 | |
161 | GNUNET_break (0); | 192 | if (1 == stage) |
162 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 193 | { |
163 | return; | 194 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received 1st callback for peer `%s' with %u information\n", |
164 | } | 195 | GNUNET_i2s (&addr[0].peer), ats_count); |
165 | c3 = 0; | 196 | if ((0 != memcmp (peer, &addr[0].peer, sizeof (addr[0].peer))) || |
166 | for (c1 = 0; c1 < ats_count; c1++) | 197 | (ats_count < ATS_COUNT)) |
167 | { | 198 | { |
168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS information [%u] %u : %u \n", c1, ntohl (ats[c1].type), ntohl (ats[c1].value)); | 199 | GNUNET_break (0); |
200 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
201 | GNUNET_SCHEDULER_cancel (die_task); | ||
202 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
203 | return; | ||
204 | } | ||
205 | |||
206 | c3 = 0; | ||
207 | for (c1 = 0; c1 < ats_count; c1++) | ||
208 | { | ||
209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS information [%u] %u : %u \n", | ||
210 | c1, ntohl (ats[c1].type), ntohl (ats[c1].value)); | ||
169 | for (c2 = 0; c2 < ATS_COUNT; c2++) | 211 | for (c2 = 0; c2 < ATS_COUNT; c2++) |
170 | { | 212 | { |
171 | if (ats[c1].type == atsi[c2].type) | 213 | if (ats[c1].type == atsi[c2].type) |
172 | { | 214 | { |
173 | if (ats[c1].value == atsi[c2].value) | 215 | if (ats[c1].value == atsi[c2].value) |
174 | { | ||
175 | c3++; | 216 | c3++; |
176 | } | ||
177 | else | 217 | else |
178 | { | ||
179 | GNUNET_break (0); | 218 | GNUNET_break (0); |
180 | } | ||
181 | } | 219 | } |
182 | } | 220 | } |
183 | } | 221 | } |
222 | if (ATS_COUNT != c3) | ||
223 | { | ||
224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received only %u correct ATS information \n", c3); | ||
225 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
226 | GNUNET_SCHEDULER_cancel (die_task); | ||
227 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
228 | return; | ||
229 | } | ||
230 | |||
231 | /* Everything OK */ | ||
232 | stage ++; | ||
233 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %u correct ATS information \n", c3); | ||
234 | |||
235 | atsi[1].type = htonl(GNUNET_ATS_QUALITY_NET_DELAY); | ||
236 | atsi[1].value = htonl(1000); | ||
237 | |||
238 | atsi[2].type = htonl(GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
239 | atsi[2].value = htonl(50); | ||
240 | |||
241 | GNUNET_ATS_address_update (sh, &addr[0], NULL, atsi, ATS_COUNT); | ||
242 | } | ||
243 | if (1 == stage) | ||
244 | { | ||
245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received 2nd callback for peer `%s' with %u information\n", | ||
246 | GNUNET_i2s (&addr[0].peer), ats_count); | ||
247 | } | ||
248 | |||
249 | |||
250 | #if 0 | ||
251 | static int stage_counter = 0; | ||
252 | |||
184 | 253 | ||
185 | if (ATS_COUNT != c3) | ||
186 | { | ||
187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received only %u correct ATS information \n", c3); | ||
188 | GNUNET_break (0); | ||
189 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
190 | return; | ||
191 | } | ||
192 | stage_counter ++; | ||
193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %u correct ATS information \n", c3); | ||
194 | 254 | ||
195 | atsi[0].type = htonl(GNUNET_ATS_NETWORK_TYPE); | 255 | if (0 == stage_counter) |
196 | atsi[0].value = htonl(GNUNET_ATS_NET_WAN); | 256 | { |
197 | 257 | ||
198 | atsi[1].type = htonl(GNUNET_ATS_QUALITY_NET_DELAY); | 258 | c3 = 0; |
199 | atsi[1].value = htonl(1000); | ||
200 | 259 | ||
201 | atsi[2].type = htonl(GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
202 | atsi[2].value = htonl(50); | ||
203 | 260 | ||
204 | GNUNET_ATS_address_update (sh, &addr, NULL, atsi, ATS_COUNT); | 261 | stage_counter ++; |
262 | |||
205 | } | 263 | } |
206 | else if (1 == stage_counter) | 264 | else if (1 == stage_counter) |
207 | { | 265 | { |
@@ -247,6 +305,34 @@ perf_mon_cb (void *cls, | |||
247 | GNUNET_SCHEDULER_add_now (&end, NULL); | 305 | GNUNET_SCHEDULER_add_now (&end, NULL); |
248 | return; | 306 | return; |
249 | } | 307 | } |
308 | #endif | ||
309 | } | ||
310 | |||
311 | void ats_suggest_cb (void *cls, | ||
312 | const struct GNUNET_HELLO_Address * address, | ||
313 | struct Session * session, | ||
314 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
315 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
316 | const struct GNUNET_ATS_Information *ats, | ||
317 | uint32_t ats_count) | ||
318 | { | ||
319 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
320 | "ATS is suggesting address for peer `%s'\n", GNUNET_i2s (&address->peer)); | ||
321 | |||
322 | if (0 != stage) | ||
323 | { | ||
324 | GNUNET_break (0); | ||
325 | end_now(1); | ||
326 | return; | ||
327 | } | ||
328 | |||
329 | if (0 == memcmp (&addr[0].peer, &address->peer, sizeof (address->peer))) | ||
330 | { | ||
331 | res_suggest_cb_p0 = GNUNET_YES; | ||
332 | stage = 1; | ||
333 | } | ||
334 | if (0 == memcmp (&addr[1].peer, &address->peer, sizeof (address->peer))) | ||
335 | res_suggest_cb_p1 = GNUNET_YES; | ||
250 | } | 336 | } |
251 | 337 | ||
252 | 338 | ||
@@ -256,19 +342,21 @@ run (void *cls, | |||
256 | struct GNUNET_TESTING_Peer *peer) | 342 | struct GNUNET_TESTING_Peer *peer) |
257 | { | 343 | { |
258 | ret = 1; | 344 | ret = 1; |
345 | stage = 0; | ||
259 | cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; | 346 | cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; |
260 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 347 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
261 | 348 | ||
262 | sh = GNUNET_ATS_scheduling_init (cfg, NULL, NULL); | 349 | sh = GNUNET_ATS_scheduling_init (cfg, &ats_suggest_cb, NULL); |
263 | GNUNET_assert (NULL != sh); | 350 | GNUNET_assert (NULL != sh); |
264 | 351 | ||
265 | setup_addresses (); | ||
266 | |||
267 | ph = GNUNET_ATS_performance_init (cfg, &perf_mon_cb, &ret, NULL, NULL); | 352 | ph = GNUNET_ATS_performance_init (cfg, &perf_mon_cb, &ret, NULL, NULL); |
268 | GNUNET_assert (NULL != ph); | 353 | GNUNET_assert (NULL != ph); |
269 | 354 | ||
355 | /* Add addresses */ | ||
356 | setup_addresses (); | ||
270 | 357 | ||
271 | stage_task = GNUNET_SCHEDULER_add_delayed (SHUTDOWN_CORRECT, &next_stage, NULL); | 358 | /* Get an active address for peer0 and expect callback */ |
359 | GNUNET_ATS_suggest_address (sh, &addr[0].peer); | ||
272 | } | 360 | } |
273 | 361 | ||
274 | 362 | ||