diff options
Diffstat (limited to 'src/transport/test_transport_api_manipulation_cfg.c')
-rw-r--r-- | src/transport/test_transport_api_manipulation_cfg.c | 236 |
1 files changed, 136 insertions, 100 deletions
diff --git a/src/transport/test_transport_api_manipulation_cfg.c b/src/transport/test_transport_api_manipulation_cfg.c index b9063ef5e..29d631d80 100644 --- a/src/transport/test_transport_api_manipulation_cfg.c +++ b/src/transport/test_transport_api_manipulation_cfg.c | |||
@@ -20,12 +20,13 @@ | |||
20 | /** | 20 | /** |
21 | * @file transport/test_transport_api_manipulation_send_tcp.c | 21 | * @file transport/test_transport_api_manipulation_send_tcp.c |
22 | * @brief base test case for transport traffic manipulation implementation | 22 | * @brief base test case for transport traffic manipulation implementation |
23 | * based onf cfg | ||
23 | * | 24 | * |
24 | * This test case will setup 2 peers and connect them, the first message | 25 | * Peer 1 has inbound and outbound delay of 100ms |
25 | * will be sent without manipulation, then a send delay of 1 second will | 26 | * Peer 2 has no inbound and outbound delay |
26 | * be configured and 1 more message will be sent. Time will be measured. | ||
27 | * | 27 | * |
28 | * In addition the distance on receiver side will be manipulated to be 10 | 28 | * We send a request from P1 to P2 and expect delay of >= TEST_DELAY ms |
29 | * Then we send response from P2 to P1 and expect delay of >= TEST_DELAY ms | ||
29 | */ | 30 | */ |
30 | #include "platform.h" | 31 | #include "platform.h" |
31 | #include "gnunet_transport_service.h" | 32 | #include "gnunet_transport_service.h" |
@@ -43,7 +44,11 @@ | |||
43 | 44 | ||
44 | #define TEST_MESSAGE_SIZE 2600 | 45 | #define TEST_MESSAGE_SIZE 2600 |
45 | 46 | ||
46 | #define TEST_MESSAGE_TYPE 12345 | 47 | #define TEST_REQUEST_MESSAGE_TYPE 12345 |
48 | |||
49 | #define TEST_RESPONSE_MESSAGE_TYPE 12346 | ||
50 | |||
51 | #define TEST_DELAY 100 | ||
47 | 52 | ||
48 | static char *test_source; | 53 | static char *test_source; |
49 | 54 | ||
@@ -77,13 +82,8 @@ static char *cfg_file_p1; | |||
77 | 82 | ||
78 | static char *cfg_file_p2; | 83 | static char *cfg_file_p2; |
79 | 84 | ||
80 | static int messages_recv; | 85 | static struct GNUNET_TIME_Absolute start_request; |
81 | 86 | static struct GNUNET_TIME_Absolute start_response; | |
82 | static struct GNUNET_TIME_Absolute start_normal; | ||
83 | static struct GNUNET_TIME_Relative dur_normal; | ||
84 | |||
85 | static struct GNUNET_TIME_Absolute start_delayed; | ||
86 | static struct GNUNET_TIME_Relative dur_delayed; | ||
87 | 87 | ||
88 | static void | 88 | static void |
89 | end () | 89 | end () |
@@ -157,80 +157,68 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
157 | } | 157 | } |
158 | 158 | ||
159 | 159 | ||
160 | static void | 160 | static size_t |
161 | sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 161 | notify_request_ready (void *cls, size_t size, void *buf) |
162 | |||
163 | static void | ||
164 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
165 | const struct GNUNET_MessageHeader *message) | ||
166 | { | 162 | { |
167 | struct PeerContext *p = cls; | 163 | struct PeerContext *p = cls; |
168 | struct PeerContext *t = NULL; | 164 | struct GNUNET_MessageHeader *hdr; |
169 | 165 | ||
170 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) | 166 | th = NULL; |
171 | t = p1; | ||
172 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) | ||
173 | t = p2; | ||
174 | GNUNET_assert (t != NULL); | ||
175 | 167 | ||
176 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | 168 | if (buf == NULL) |
169 | { | ||
170 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
171 | "Timeout occurred while waiting for transmit_ready\n"); | ||
172 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
173 | GNUNET_SCHEDULER_cancel (die_task); | ||
174 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
175 | ok = 42; | ||
176 | return 0; | ||
177 | } | ||
177 | 178 | ||
179 | GNUNET_assert (size >= TEST_MESSAGE_SIZE); | ||
180 | if (buf != NULL) | ||
181 | { | ||
182 | memset (buf, '\0', TEST_MESSAGE_SIZE); | ||
183 | hdr = buf; | ||
184 | hdr->size = htons (TEST_MESSAGE_SIZE); | ||
185 | hdr->type = htons (TEST_REQUEST_MESSAGE_TYPE); | ||
186 | } | ||
187 | |||
188 | char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
179 | "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", | 190 | "Sending request message from peer %u (`%4s') with type %u and size %u bytes to peer %u (`%4s')\n", |
180 | p->no, ps, ntohs (message->type), ntohs (message->size), t->no, | 191 | p1->no, ps, ntohs (hdr->type), ntohs (hdr->size), p->no, |
181 | GNUNET_i2s (&t->id)); | 192 | GNUNET_i2s (&p->id)); |
182 | GNUNET_free (ps); | 193 | GNUNET_free (ps); |
194 | return TEST_MESSAGE_SIZE; | ||
195 | } | ||
183 | 196 | ||
184 | if ((TEST_MESSAGE_TYPE == ntohs (message->type)) && | ||
185 | (TEST_MESSAGE_SIZE == ntohs (message->size))) | ||
186 | { | ||
187 | ok = 0; | ||
188 | 197 | ||
189 | } | 198 | static void |
190 | else | 199 | sendtask_request_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
191 | { | 200 | { |
192 | GNUNET_break (0); | 201 | send_task = GNUNET_SCHEDULER_NO_TASK; |
193 | ok = 1; | 202 | |
194 | end (); | 203 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) |
195 | return; | 204 | return; |
196 | } | 205 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p2->id)); |
197 | 206 | ||
198 | if (0 == messages_recv) | 207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
199 | { | 208 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", |
200 | /* Received outbound only delayed message message */ | 209 | p1->no, GNUNET_i2s (&p1->id), p2->no, receiver_s); |
201 | dur_normal = GNUNET_TIME_absolute_get_duration(start_normal); | 210 | GNUNET_free (receiver_s); |
202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 211 | |
203 | "Received outbound message %u after %llu\n", | 212 | s_sending = GNUNET_YES; |
204 | messages_recv, | 213 | start_request = GNUNET_TIME_absolute_get(); |
205 | (long long unsigned int) dur_normal.rel_value); | 214 | th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, &p2->id, TEST_MESSAGE_SIZE, 0, |
206 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); | 215 | TIMEOUT_TRANSMIT, ¬ify_request_ready, |
207 | } | 216 | p2); |
208 | if (1 == messages_recv) | ||
209 | { | ||
210 | /* Received outbound and inbound delayed message */ | ||
211 | dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed); | ||
212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
213 | "Received delayed message %u after %llu\n", | ||
214 | messages_recv, | ||
215 | (long long unsigned int) dur_delayed.rel_value); | ||
216 | if (dur_delayed.rel_value < (dur_normal.rel_value * 1.80)) | ||
217 | { | ||
218 | GNUNET_break (0); | ||
219 | ok += 1; | ||
220 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
221 | "Outbound and inbound delayed message was not delayed correctly: took only %llu\n", | ||
222 | (long long unsigned int) dur_delayed.rel_value); | ||
223 | } | ||
224 | |||
225 | /* shutdown */ | ||
226 | end (); | ||
227 | } | ||
228 | messages_recv ++; | ||
229 | } | 217 | } |
230 | 218 | ||
231 | 219 | ||
232 | static size_t | 220 | static size_t |
233 | notify_ready (void *cls, size_t size, void *buf) | 221 | notify_response_ready (void *cls, size_t size, void *buf) |
234 | { | 222 | { |
235 | struct PeerContext *p = cls; | 223 | struct PeerContext *p = cls; |
236 | struct GNUNET_MessageHeader *hdr; | 224 | struct GNUNET_MessageHeader *hdr; |
@@ -239,7 +227,7 @@ notify_ready (void *cls, size_t size, void *buf) | |||
239 | 227 | ||
240 | if (buf == NULL) | 228 | if (buf == NULL) |
241 | { | 229 | { |
242 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 230 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
243 | "Timeout occurred while waiting for transmit_ready\n"); | 231 | "Timeout occurred while waiting for transmit_ready\n"); |
244 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | 232 | if (GNUNET_SCHEDULER_NO_TASK != die_task) |
245 | GNUNET_SCHEDULER_cancel (die_task); | 233 | GNUNET_SCHEDULER_cancel (die_task); |
@@ -254,31 +242,21 @@ notify_ready (void *cls, size_t size, void *buf) | |||
254 | memset (buf, '\0', TEST_MESSAGE_SIZE); | 242 | memset (buf, '\0', TEST_MESSAGE_SIZE); |
255 | hdr = buf; | 243 | hdr = buf; |
256 | hdr->size = htons (TEST_MESSAGE_SIZE); | 244 | hdr->size = htons (TEST_MESSAGE_SIZE); |
257 | hdr->type = htons (TEST_MESSAGE_TYPE); | 245 | hdr->type = htons (TEST_RESPONSE_MESSAGE_TYPE); |
258 | } | ||
259 | |||
260 | if (0 == messages_recv) | ||
261 | { | ||
262 | start_normal = GNUNET_TIME_absolute_get(); | ||
263 | } | ||
264 | if (1 == messages_recv) | ||
265 | { | ||
266 | start_delayed = GNUNET_TIME_absolute_get(); | ||
267 | } | 246 | } |
268 | 247 | ||
269 | char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id)); | 248 | char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id)); |
270 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 249 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
271 | "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", | 250 | "Sending response message from peer %u (`%4s') with type %u and size %u bytes to peer %u (`%4s')\n", |
272 | p2->no, ps, ntohs (hdr->type), ntohs (hdr->size), p->no, | 251 | p1->no, ps, ntohs (hdr->type), ntohs (hdr->size), p->no, |
273 | GNUNET_i2s (&p->id)); | 252 | GNUNET_i2s (&p->id)); |
274 | GNUNET_free (ps); | 253 | GNUNET_free (ps); |
275 | 254 | ||
276 | return TEST_MESSAGE_SIZE; | 255 | return TEST_MESSAGE_SIZE; |
277 | } | 256 | } |
278 | 257 | ||
279 | |||
280 | static void | 258 | static void |
281 | sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 259 | sendtask_response_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
282 | { | 260 | { |
283 | send_task = GNUNET_SCHEDULER_NO_TASK; | 261 | send_task = GNUNET_SCHEDULER_NO_TASK; |
284 | 262 | ||
@@ -291,15 +269,81 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
291 | p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s); | 269 | p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s); |
292 | GNUNET_free (receiver_s); | 270 | GNUNET_free (receiver_s); |
293 | 271 | ||
294 | |||
295 | |||
296 | s_sending = GNUNET_YES; | 272 | s_sending = GNUNET_YES; |
273 | start_response = GNUNET_TIME_absolute_get(); | ||
297 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, TEST_MESSAGE_SIZE, 0, | 274 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, TEST_MESSAGE_SIZE, 0, |
298 | TIMEOUT_TRANSMIT, ¬ify_ready, | 275 | TIMEOUT_TRANSMIT, ¬ify_response_ready, |
299 | p1); | 276 | p1); |
300 | } | 277 | } |
301 | 278 | ||
302 | 279 | ||
280 | |||
281 | static void | ||
282 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
283 | const struct GNUNET_MessageHeader *message) | ||
284 | { | ||
285 | struct PeerContext *p = cls; | ||
286 | struct PeerContext *t = NULL; | ||
287 | struct GNUNET_TIME_Relative duration; | ||
288 | |||
289 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) | ||
290 | t = p1; | ||
291 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) | ||
292 | t = p2; | ||
293 | GNUNET_assert (t != NULL); | ||
294 | |||
295 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
296 | |||
297 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
298 | "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", | ||
299 | p->no, ps, ntohs (message->type), ntohs (message->size), t->no, | ||
300 | GNUNET_i2s (&t->id)); | ||
301 | GNUNET_free (ps); | ||
302 | |||
303 | switch (ntohs (message->type)) { | ||
304 | case TEST_REQUEST_MESSAGE_TYPE: | ||
305 | duration = GNUNET_TIME_absolute_get_difference(start_request, | ||
306 | GNUNET_TIME_absolute_get()); | ||
307 | if (duration.rel_value >= TEST_DELAY) | ||
308 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
309 | "Request message was delayed for %llu ms\n", | ||
310 | duration.rel_value); | ||
311 | else | ||
312 | { | ||
313 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
314 | "Request message was delayed for %llu ms, should be %u ms\n", | ||
315 | duration.rel_value, TEST_DELAY); | ||
316 | ok = 1; | ||
317 | } | ||
318 | |||
319 | /* Send response */ | ||
320 | send_task = GNUNET_SCHEDULER_add_now (&sendtask_response_task, NULL); | ||
321 | return; | ||
322 | break; | ||
323 | case TEST_RESPONSE_MESSAGE_TYPE: | ||
324 | duration = GNUNET_TIME_absolute_get_difference(start_response, | ||
325 | GNUNET_TIME_absolute_get()); | ||
326 | if (duration.rel_value >= TEST_DELAY) | ||
327 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
328 | "Response message was delayed for %llu ms\n", duration); | ||
329 | else | ||
330 | { | ||
331 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
332 | "Response message was delayed for %llu ms, should be %u ms\n", | ||
333 | duration.rel_value, TEST_DELAY); | ||
334 | ok = 1; | ||
335 | } | ||
336 | /* Done */ | ||
337 | ok = 1; | ||
338 | end(); | ||
339 | break; | ||
340 | default: | ||
341 | break; | ||
342 | } | ||
343 | } | ||
344 | |||
345 | |||
346 | |||
303 | static void | 347 | static void |
304 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | 348 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) |
305 | { | 349 | { |
@@ -353,7 +397,7 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) | |||
353 | GNUNET_free (p1_c); | 397 | GNUNET_free (p1_c); |
354 | 398 | ||
355 | s_connected = GNUNET_YES; | 399 | s_connected = GNUNET_YES; |
356 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); | 400 | send_task = GNUNET_SCHEDULER_add_now (&sendtask_request_task, NULL); |
357 | } | 401 | } |
358 | 402 | ||
359 | 403 | ||
@@ -376,15 +420,7 @@ start_cb (struct PeerContext *p, void *cls) | |||
376 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | 420 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", |
377 | p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); | 421 | p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); |
378 | GNUNET_free (sender_c); | 422 | GNUNET_free (sender_c); |
379 | /* | 423 | |
380 | struct GNUNET_ATS_Information ats[2]; | ||
381 | ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); | ||
382 | ats[0].value = htonl (1000); | ||
383 | ats[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
384 | ats[1].value = htonl (10); | ||
385 | |||
386 | GNUNET_TRANSPORT_set_traffic_metric (p1->th, &p2->id, TM_RECEIVE, ats, 2); | ||
387 | */ | ||
388 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, | 424 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, |
389 | NULL); | 425 | NULL); |
390 | 426 | ||