diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2014-05-20 11:37:19 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2014-05-20 11:37:19 +0000 |
commit | e2d3ca4d4eee401515f94382c160fd9a65230a3c (patch) | |
tree | 3f59d3b0b1e696770b497b1c9d1e53df69a59ec7 /src/transport/test_transport_api_reliability.c | |
parent | 515580c7f27b87831b6b5d4207c72c8acab53ca1 (diff) | |
download | gnunet-e2d3ca4d4eee401515f94382c160fd9a65230a3c.tar.gz gnunet-e2d3ca4d4eee401515f94382c160fd9a65230a3c.zip |
remove unreliability test
- update reliabilitility test: this test only ensures that all messages are delivered and are not corrupted
out of order delivery is not checked any longer
Diffstat (limited to 'src/transport/test_transport_api_reliability.c')
-rw-r--r-- | src/transport/test_transport_api_reliability.c | 403 |
1 files changed, 253 insertions, 150 deletions
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index d2a78d17f..07213722e 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c | |||
@@ -21,87 +21,141 @@ | |||
21 | * @file transport/test_transport_api_reliability.c | 21 | * @file transport/test_transport_api_reliability.c |
22 | * @brief base test case for transport implementations | 22 | * @brief base test case for transport implementations |
23 | * | 23 | * |
24 | * This test case serves as a base for tcp and http | 24 | * This test case serves ensures that messages are reliably sent between peers |
25 | * transport test cases to check that the transports | 25 | * |
26 | * achieve reliable message delivery. | 26 | * This test sends TOTAL_MSGS with message type MTYPE from peer 1 to peer 2 |
27 | * and ensures that all message were received. | ||
27 | */ | 28 | */ |
28 | #include "platform.h" | 29 | #include "platform.h" |
29 | #include "gnunet_transport_service.h" | 30 | #include "gnunet_transport_service.h" |
30 | #include "gauger.h" | 31 | #include "gauger.h" |
31 | #include "transport-testing.h" | 32 | #include "transport-testing.h" |
33 | |||
34 | /** | ||
35 | * Total number of messages to send | ||
36 | * | ||
37 | * Note that this value must not significantly exceed | ||
38 | * 'MAX_PENDING' in 'gnunet-service-transport_clients.c', otherwise | ||
39 | * messages may be dropped even for a reliable transport. | ||
40 | */ | ||
41 | #define TOTAL_MSGS (1024 * 3) | ||
42 | |||
43 | /** | ||
44 | * Message type of test messages | ||
45 | */ | ||
46 | #define MTYPE 12345 | ||
47 | |||
32 | /** | 48 | /** |
33 | * Testcase timeout | 49 | * Testcase timeout |
34 | */ | 50 | */ |
35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 51 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 900) |
36 | 52 | ||
37 | /** | 53 | /** |
38 | * How long until we give up on transmitting the message? | 54 | * How long until we give up on transmitting the message? |
39 | */ | 55 | */ |
40 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 56 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
57 | |||
58 | |||
59 | /** | ||
60 | * Struct for the test message | ||
61 | */ | ||
62 | GNUNET_NETWORK_STRUCT_BEGIN | ||
41 | 63 | ||
64 | struct TestMessage | ||
65 | { | ||
66 | struct GNUNET_MessageHeader header; | ||
67 | uint32_t num; | ||
68 | }; | ||
69 | GNUNET_NETWORK_STRUCT_END | ||
42 | 70 | ||
43 | static char *test_source; | ||
44 | 71 | ||
72 | /** | ||
73 | * Name of the plugin to test | ||
74 | */ | ||
45 | static char *test_plugin; | 75 | static char *test_plugin; |
46 | 76 | ||
77 | /** | ||
78 | * Name of the test | ||
79 | */ | ||
47 | static char *test_name; | 80 | static char *test_name; |
48 | 81 | ||
82 | /** | ||
83 | * Return value of the test | ||
84 | */ | ||
49 | static int ok; | 85 | static int ok; |
50 | 86 | ||
51 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | 87 | /** |
52 | 88 | * Context of peer 1 | |
89 | */ | ||
53 | struct PeerContext *p1; | 90 | struct PeerContext *p1; |
54 | 91 | ||
92 | /** | ||
93 | * Configuration file of peer 1 | ||
94 | */ | ||
95 | char *cfg_file_p1; | ||
96 | |||
97 | /** | ||
98 | * Context of peer 2 | ||
99 | */ | ||
55 | struct PeerContext *p2; | 100 | struct PeerContext *p2; |
56 | 101 | ||
57 | struct PeerContext *sender; | 102 | /** |
103 | * Configuration file of peer 1 | ||
104 | */ | ||
105 | char *cfg_file_p2; | ||
58 | 106 | ||
59 | struct PeerContext *receiver; | 107 | /** |
108 | * Timeout task | ||
109 | */ | ||
110 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
60 | 111 | ||
112 | /** | ||
113 | * Transport transmit handle used | ||
114 | */ | ||
61 | struct GNUNET_TRANSPORT_TransmitHandle *th; | 115 | struct GNUNET_TRANSPORT_TransmitHandle *th; |
62 | 116 | ||
63 | char *cfg_file_p1; | 117 | /** |
64 | 118 | * Transport testing handle | |
65 | char *cfg_file_p2; | 119 | */ |
66 | |||
67 | struct GNUNET_TRANSPORT_TESTING_handle *tth; | 120 | struct GNUNET_TRANSPORT_TESTING_handle *tth; |
68 | 121 | ||
69 | static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; | ||
70 | |||
71 | |||
72 | /* | 122 | /* |
73 | * Testcase specific declarations | 123 | * Total amount of bytes sent |
74 | */ | 124 | */ |
125 | static unsigned long long total_bytes; | ||
75 | 126 | ||
76 | /** | 127 | /** |
77 | * Note that this value must not significantly exceed | 128 | * Time of start |
78 | * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise | ||
79 | * messages may be dropped even for a reliable transport. | ||
80 | */ | 129 | */ |
81 | #define TOTAL_MSGS (1024 * 2) | 130 | static struct GNUNET_TIME_Absolute start_time; |
82 | |||
83 | #define MTYPE 12345 | ||
84 | |||
85 | GNUNET_NETWORK_STRUCT_BEGIN | ||
86 | |||
87 | struct TestMessage | ||
88 | { | ||
89 | struct GNUNET_MessageHeader header; | ||
90 | uint32_t num; | ||
91 | }; | ||
92 | GNUNET_NETWORK_STRUCT_END | ||
93 | 131 | ||
132 | /** | ||
133 | * No. of message currently scheduled to be send | ||
134 | */ | ||
94 | static int msg_scheduled; | 135 | static int msg_scheduled; |
136 | |||
137 | /** | ||
138 | * No. of last message sent | ||
139 | */ | ||
95 | static int msg_sent; | 140 | static int msg_sent; |
96 | static int msg_recv_expected; | 141 | |
142 | /** | ||
143 | * No. of last message received | ||
144 | */ | ||
97 | static int msg_recv; | 145 | static int msg_recv; |
98 | 146 | ||
99 | static int test_failed; | ||
100 | static int test_connected; | 147 | static int test_connected; |
148 | static int test_sending; | ||
149 | static int test_send_timeout; | ||
101 | 150 | ||
102 | static unsigned long long total_bytes; | ||
103 | 151 | ||
104 | static struct GNUNET_TIME_Absolute start_time; | 152 | /** |
153 | * Bitmap storing which messages were received | ||
154 | */ | ||
155 | |||
156 | static char bitmap[TOTAL_MSGS / 8]; | ||
157 | |||
158 | static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; | ||
105 | 159 | ||
106 | /* | 160 | /* |
107 | * END Testcase specific declarations | 161 | * END Testcase specific declarations |
@@ -113,6 +167,8 @@ static struct GNUNET_TIME_Absolute start_time; | |||
113 | #define OKPP do { ok++; } while (0) | 167 | #define OKPP do { ok++; } while (0) |
114 | #endif | 168 | #endif |
115 | 169 | ||
170 | static int | ||
171 | get_bit (const char *map, unsigned int bit); | ||
116 | 172 | ||
117 | static void | 173 | static void |
118 | end () | 174 | end () |
@@ -121,15 +177,15 @@ end () | |||
121 | unsigned long long rate; | 177 | unsigned long long rate; |
122 | char *value_name; | 178 | char *value_name; |
123 | 179 | ||
124 | |||
125 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); | 180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); |
126 | 181 | ||
182 | /* Calculcate statistics */ | ||
127 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; | 183 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; |
128 | rate = (1000LL * 1000LL * total_bytes) / (1024 * delta); | 184 | rate = (1000LL* 1000ll * total_bytes) / (1024 * delta); |
129 | FPRINTF (stderr, "\nThroughput was %llu KiBytes/s\n", | 185 | FPRINTF (stderr, "\nThroughput was %llu KiBytes/s\n", |
130 | rate); | 186 | rate); |
131 | 187 | ||
132 | GNUNET_asprintf (&value_name, "reliable_%s", test_plugin); | 188 | GNUNET_asprintf (&value_name, "unreliable_%s", test_plugin); |
133 | GAUGER ("TRANSPORT", value_name, (int) rate, | 189 | GAUGER ("TRANSPORT", value_name, (int) rate, |
134 | "kb/s"); | 190 | "kb/s"); |
135 | GNUNET_free (value_name); | 191 | GNUNET_free (value_name); |
@@ -143,16 +199,31 @@ end () | |||
143 | 199 | ||
144 | if (cc != NULL) | 200 | if (cc != NULL) |
145 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); | 201 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); |
202 | cc = NULL; | ||
146 | 203 | ||
147 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); | 204 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); |
148 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); | 205 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); |
149 | 206 | ||
150 | GNUNET_TRANSPORT_TESTING_done (tth); | 207 | GNUNET_TRANSPORT_TESTING_done (tth); |
208 | |||
209 | ok = 0; | ||
210 | |||
211 | int i; | ||
212 | |||
213 | for (i = 0; i < TOTAL_MSGS; i++) | ||
214 | { | ||
215 | if (get_bit (bitmap, i) == 0) | ||
216 | { | ||
217 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not receive message %d\n", i); | ||
218 | ok = -1; | ||
219 | } | ||
220 | } | ||
151 | } | 221 | } |
152 | 222 | ||
153 | static void | 223 | static void |
154 | end_badly () | 224 | end_badly () |
155 | { | 225 | { |
226 | int i; | ||
156 | die_task = GNUNET_SCHEDULER_NO_TASK; | 227 | die_task = GNUNET_SCHEDULER_NO_TASK; |
157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); | 228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); |
158 | 229 | ||
@@ -161,20 +232,34 @@ end_badly () | |||
161 | else | 232 | else |
162 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got NOT connected\n"); | 233 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got NOT connected\n"); |
163 | 234 | ||
235 | if (test_sending == GNUNET_NO) | ||
236 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
237 | "Testcase did not send any messages before timeout\n"); | ||
238 | if (test_send_timeout == GNUNET_YES) | ||
239 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
240 | "Test had timeout while waiting to send data\n"); | ||
241 | for (i = 0; i < TOTAL_MSGS; i++) | ||
242 | { | ||
243 | if (get_bit (bitmap, i) == 0) | ||
244 | { | ||
245 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not receive message %d\n", i); | ||
246 | ok = -1; | ||
247 | } | ||
248 | } | ||
249 | |||
164 | if (th != NULL) | 250 | if (th != NULL) |
165 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 251 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
166 | th = NULL; | 252 | th = NULL; |
167 | 253 | ||
168 | if (cc != NULL) | 254 | if (cc != NULL) |
169 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); | 255 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); |
256 | cc = NULL; | ||
170 | 257 | ||
171 | if (p1 != NULL) | 258 | if (p1 != NULL) |
172 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); | 259 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); |
173 | if (p2 != NULL) | 260 | if (p2 != NULL) |
174 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); | 261 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); |
175 | |||
176 | GNUNET_TRANSPORT_TESTING_done (tth); | 262 | GNUNET_TRANSPORT_TESTING_done (tth); |
177 | |||
178 | ok = GNUNET_SYSERR; | 263 | ok = GNUNET_SYSERR; |
179 | } | 264 | } |
180 | 265 | ||
@@ -185,84 +270,126 @@ get_size (unsigned int iter) | |||
185 | unsigned int ret; | 270 | unsigned int ret; |
186 | 271 | ||
187 | ret = (iter * iter * iter); | 272 | ret = (iter * iter * iter); |
273 | |||
274 | #ifndef LINUX | ||
275 | /* FreeBSD/OSX etc. Unix DGRAMs do not work | ||
276 | * with large messages */ | ||
277 | if (0 == strcmp ("unix", test_plugin)) | ||
278 | return sizeof (struct TestMessage) + (ret % 1024); | ||
279 | #endif | ||
188 | return sizeof (struct TestMessage) + (ret % 60000); | 280 | return sizeof (struct TestMessage) + (ret % 60000); |
189 | } | 281 | } |
190 | 282 | ||
191 | 283 | ||
284 | /** | ||
285 | * Sets a bit active in the bitmap. | ||
286 | * | ||
287 | * @param bitIdx which bit to set | ||
288 | * @return GNUNET_SYSERR on error, GNUNET_OK on success | ||
289 | */ | ||
290 | static int | ||
291 | set_bit (unsigned int bitIdx) | ||
292 | { | ||
293 | size_t arraySlot; | ||
294 | unsigned int targetBit; | ||
295 | |||
296 | if (bitIdx >= sizeof (bitmap) * 8) | ||
297 | { | ||
298 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "tried to set bit %d of %d(!?!?)\n", | ||
299 | bitIdx, sizeof (bitmap) * 8); | ||
300 | return GNUNET_SYSERR; | ||
301 | } | ||
302 | arraySlot = bitIdx / 8; | ||
303 | targetBit = (1L << (bitIdx % 8)); | ||
304 | bitmap[arraySlot] |= targetBit; | ||
305 | return GNUNET_OK; | ||
306 | } | ||
307 | |||
308 | /** | ||
309 | * Obtain a bit from bitmap. | ||
310 | * @param map the bitmap | ||
311 | * @param bit index from bitmap | ||
312 | * | ||
313 | * @return Bit \a bit from hashcode \a code | ||
314 | */ | ||
315 | static int | ||
316 | get_bit (const char *map, unsigned int bit) | ||
317 | { | ||
318 | if (bit > TOTAL_MSGS) | ||
319 | { | ||
320 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "get bit %d of %d(!?!?)\n", bit, | ||
321 | sizeof (bitmap) * 8); | ||
322 | return 0; | ||
323 | } | ||
324 | return ((map)[bit >> 3] & (1 << (bit & 7))) > 0; | ||
325 | } | ||
326 | |||
327 | |||
192 | static void | 328 | static void |
193 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | 329 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, |
194 | const struct GNUNET_MessageHeader *message) | 330 | const struct GNUNET_MessageHeader *message) |
195 | { | 331 | { |
196 | static int n; | 332 | static int n; |
333 | |||
197 | unsigned int s; | 334 | unsigned int s; |
198 | char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; | 335 | char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; |
199 | const struct TestMessage *hdr; | 336 | const struct TestMessage *hdr; |
200 | 337 | ||
201 | hdr = (const struct TestMessage *) message; | 338 | hdr = (const struct TestMessage *) message; |
202 | s = get_size (n); | 339 | |
203 | if (MTYPE != ntohs (message->type)) | 340 | if (MTYPE != ntohs (message->type)) |
204 | return; | 341 | return; |
205 | msg_recv_expected = n; | ||
206 | msg_recv = ntohl (hdr->num); | 342 | msg_recv = ntohl (hdr->num); |
207 | if (ntohs (message->size) != (s)) | 343 | s = get_size (ntohl (hdr->num)); |
208 | { | 344 | |
209 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 345 | if (ntohs (message->size) != s) |
210 | "Expected message %u of size %u, got %u bytes of message %u\n", | ||
211 | n, s, ntohs (message->size), ntohl (hdr->num)); | ||
212 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
213 | GNUNET_SCHEDULER_cancel (die_task); | ||
214 | test_failed = GNUNET_YES; | ||
215 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
216 | return; | ||
217 | } | ||
218 | if (ntohl (hdr->num) != n) | ||
219 | { | 346 | { |
220 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 347 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
221 | "Expected message %u of size %u, got %u bytes of message %u\n", | 348 | "Expected message %u of size %u, got %u bytes of message %u\n", |
222 | n, s, ntohs (message->size), ntohl (hdr->num)); | 349 | ntohl (hdr->num), s, ntohs (message->size), ntohl (hdr->num)); |
223 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 350 | if (GNUNET_SCHEDULER_NO_TASK != die_task) |
224 | GNUNET_SCHEDULER_cancel (die_task); | 351 | GNUNET_SCHEDULER_cancel (die_task); |
225 | test_failed = GNUNET_YES; | 352 | test_sending = GNUNET_YES; |
226 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 353 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); |
227 | return; | 354 | return; |
228 | } | 355 | } |
229 | memset (cbuf, n, s - sizeof (struct TestMessage)); | 356 | |
357 | memset (cbuf, ntohl (hdr->num), s - sizeof (struct TestMessage)); | ||
230 | if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage))) | 358 | if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage))) |
231 | { | 359 | { |
232 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 360 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
233 | "Expected message %u with bits %u, but body did not match at position %u\n", n, | 361 | "Expected message %u with bits %u, but body did not match\n", |
234 | (unsigned char) n); | 362 | ntohl (hdr->num), (unsigned char) n); |
235 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 363 | if (GNUNET_SCHEDULER_NO_TASK != die_task) |
236 | GNUNET_SCHEDULER_cancel (die_task); | 364 | GNUNET_SCHEDULER_cancel (die_task); |
237 | test_failed = GNUNET_YES; | 365 | test_sending = GNUNET_YES; |
238 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 366 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); |
239 | return; | 367 | return; |
240 | } | 368 | } |
241 | #if VERBOSE | 369 | #if VERBOSE |
242 | if (ntohl (hdr->num) % 5000 == 0) | 370 | if (ntohl (hdr->num) % 5 == 0) |
243 | { | 371 | { |
244 | struct PeerContext *p = cls; | 372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n", |
245 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | 373 | ntohl (hdr->num), ntohs (message->size)); |
246 | |||
247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
248 | "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", | ||
249 | p->no, ps, ntohl (hdr->num), ntohs (message->size), | ||
250 | GNUNET_i2s (peer)); | ||
251 | GNUNET_free (ps); | ||
252 | } | 374 | } |
253 | #endif | 375 | #endif |
254 | n++; | 376 | n++; |
377 | if (GNUNET_SYSERR == set_bit (ntohl (hdr->num))) | ||
378 | { | ||
379 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
380 | _("Message id %u is bigger than maxmimum number of messages %u expected\n"), | ||
381 | ntohl (hdr->num), TOTAL_MSGS); | ||
382 | } | ||
383 | test_sending = GNUNET_YES; | ||
255 | if (0 == (n % (TOTAL_MSGS / 100))) | 384 | if (0 == (n % (TOTAL_MSGS / 100))) |
256 | { | 385 | { |
257 | FPRINTF (stderr, "%s", "."); | 386 | FPRINTF (stderr, "%s", "."); |
258 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 387 | if (GNUNET_SCHEDULER_NO_TASK != die_task) |
259 | GNUNET_SCHEDULER_cancel (die_task); | 388 | GNUNET_SCHEDULER_cancel (die_task); |
260 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 389 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
261 | } | 390 | } |
262 | if (n == TOTAL_MSGS) | 391 | if (n == TOTAL_MSGS) |
263 | { | 392 | { |
264 | ok = 0; | ||
265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\nAll messages received\n"); | ||
266 | end (); | 393 | end (); |
267 | } | 394 | } |
268 | } | 395 | } |
@@ -278,10 +405,12 @@ notify_ready (void *cls, size_t size, void *buf) | |||
278 | unsigned int ret; | 405 | unsigned int ret; |
279 | 406 | ||
280 | th = NULL; | 407 | th = NULL; |
408 | |||
281 | if (buf == NULL) | 409 | if (buf == NULL) |
282 | { | 410 | { |
411 | test_send_timeout = GNUNET_YES; | ||
283 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 412 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
284 | "Timeout occurred while waiting for transmit_ready for message %u of %u\n", | 413 | "Timeout occurred while waiting for transmit_ready for msg %u of %u\n", |
285 | msg_scheduled, TOTAL_MSGS); | 414 | msg_scheduled, TOTAL_MSGS); |
286 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | 415 | if (GNUNET_SCHEDULER_NO_TASK != die_task) |
287 | GNUNET_SCHEDULER_cancel (die_task); | 416 | GNUNET_SCHEDULER_cancel (die_task); |
@@ -289,14 +418,15 @@ notify_ready (void *cls, size_t size, void *buf) | |||
289 | ok = 42; | 418 | ok = 42; |
290 | return 0; | 419 | return 0; |
291 | } | 420 | } |
292 | |||
293 | ret = 0; | 421 | ret = 0; |
294 | s = get_size (n); | 422 | s = get_size (n); |
295 | GNUNET_assert (size >= s); | 423 | GNUNET_assert (size >= s); |
296 | GNUNET_assert (buf != NULL); | 424 | GNUNET_assert (buf != NULL); |
425 | GNUNET_assert (n < TOTAL_MSGS); | ||
297 | cbuf = buf; | 426 | cbuf = buf; |
298 | do | 427 | do |
299 | { | 428 | { |
429 | GNUNET_assert (n < TOTAL_MSGS); | ||
300 | hdr.header.size = htons (s); | 430 | hdr.header.size = htons (s); |
301 | hdr.header.type = htons (MTYPE); | 431 | hdr.header.type = htons (MTYPE); |
302 | hdr.num = htonl (n); | 432 | hdr.num = htonl (n); |
@@ -305,17 +435,12 @@ notify_ready (void *cls, size_t size, void *buf) | |||
305 | ret += sizeof (struct TestMessage); | 435 | ret += sizeof (struct TestMessage); |
306 | memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); | 436 | memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); |
307 | ret += s - sizeof (struct TestMessage); | 437 | ret += s - sizeof (struct TestMessage); |
438 | |||
308 | #if VERBOSE | 439 | #if VERBOSE |
309 | if (n % 5000 == 0) | 440 | if (n % 5000 == 0) |
310 | { | 441 | { |
311 | 442 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u of size %u\n", n, | |
312 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 443 | s); |
313 | |||
314 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
315 | "Sending message of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", | ||
316 | n, sender->no, GNUNET_i2s (&sender->id), receiver->no, | ||
317 | receiver_s); | ||
318 | GNUNET_free (receiver_s); | ||
319 | } | 444 | } |
320 | #endif | 445 | #endif |
321 | n++; | 446 | n++; |
@@ -323,26 +448,28 @@ notify_ready (void *cls, size_t size, void *buf) | |||
323 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) | 448 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) |
324 | break; /* sometimes pack buffer full, sometimes not */ | 449 | break; /* sometimes pack buffer full, sometimes not */ |
325 | } | 450 | } |
326 | while (size - ret >= s); | 451 | while ((size - ret >= s) && (n < TOTAL_MSGS)); |
327 | if (n < TOTAL_MSGS) | 452 | if (n < TOTAL_MSGS) |
328 | { | 453 | { |
329 | if (th == NULL) | 454 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, s, |
330 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, s, | 455 | TIMEOUT_TRANSMIT, |
331 | TIMEOUT_TRANSMIT, | 456 | ¬ify_ready, NULL); |
332 | ¬ify_ready, NULL); | ||
333 | msg_scheduled = n; | 457 | msg_scheduled = n; |
334 | } | 458 | } |
459 | else | ||
460 | { | ||
461 | FPRINTF (stderr, "%s", "\n"); | ||
462 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages scheduled to be sent\n"); | ||
463 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
464 | GNUNET_SCHEDULER_cancel (die_task); | ||
465 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
466 | } | ||
335 | if (n % 5000 == 0) | 467 | if (n % 5000 == 0) |
336 | { | 468 | { |
337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 469 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
338 | "Returning total message block of size %u\n", ret); | 470 | "Returning total message block of size %u\n", ret); |
339 | } | 471 | } |
340 | total_bytes += ret; | 472 | total_bytes += ret; |
341 | if (n == TOTAL_MSGS) | ||
342 | { | ||
343 | FPRINTF (stderr, "%s", "\n"); | ||
344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages sent\n"); | ||
345 | } | ||
346 | return ret; | 473 | return ret; |
347 | } | 474 | } |
348 | 475 | ||
@@ -350,31 +477,27 @@ notify_ready (void *cls, size_t size, void *buf) | |||
350 | static void | 477 | static void |
351 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | 478 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) |
352 | { | 479 | { |
353 | 480 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", | |
354 | struct PeerContext *p = cls; | 481 | GNUNET_i2s (peer), cls); |
355 | |||
356 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to us!\n", | ||
357 | p->no, GNUNET_i2s (peer)); | ||
358 | } | 482 | } |
359 | 483 | ||
360 | 484 | ||
361 | static void | 485 | static void |
362 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 486 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) |
363 | { | 487 | { |
364 | struct PeerContext *p = cls; | 488 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' disconnected (%p)!\n", |
365 | 489 | GNUNET_i2s (peer), cls); | |
366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') disconnected!\n", p->no, | ||
367 | GNUNET_i2s (peer)); | ||
368 | if (th != NULL) | 490 | if (th != NULL) |
369 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 491 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
370 | th = NULL; | 492 | th = NULL; |
371 | |||
372 | } | 493 | } |
373 | 494 | ||
374 | static void | 495 | static void |
375 | sendtask () | 496 | sendtask () |
376 | { | 497 | { |
377 | start_time = GNUNET_TIME_absolute_get (); | 498 | start_time = GNUNET_TIME_absolute_get (); |
499 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to send %u messages\n", | ||
500 | TOTAL_MSGS); | ||
378 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, get_size (0), | 501 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, get_size (0), |
379 | TIMEOUT_TRANSMIT, ¬ify_ready, | 502 | TIMEOUT_TRANSMIT, ¬ify_ready, |
380 | NULL); | 503 | NULL); |
@@ -385,22 +508,20 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) | |||
385 | { | 508 | { |
386 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | 509 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); |
387 | 510 | ||
388 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", | 511 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", p1_c, |
389 | p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); | 512 | GNUNET_i2s (&p2->id)); |
390 | GNUNET_free (p1_c); | 513 | GNUNET_free (p1_c); |
391 | 514 | ||
392 | test_connected = GNUNET_YES; | 515 | test_connected = GNUNET_YES; |
393 | cc = NULL; | 516 | cc = NULL; |
394 | 517 | ||
395 | GNUNET_SCHEDULER_add_now (&sendtask, NULL); | 518 | GNUNET_SCHEDULER_add_now (&sendtask, NULL); |
396 | |||
397 | } | 519 | } |
398 | 520 | ||
399 | void | 521 | static void |
400 | start_cb (struct PeerContext *p, void *cls) | 522 | start_cb (struct PeerContext *p, void *cls) |
401 | { | 523 | { |
402 | static int started; | 524 | static int started; |
403 | |||
404 | started++; | 525 | started++; |
405 | 526 | ||
406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, | 527 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, |
@@ -410,35 +531,17 @@ start_cb (struct PeerContext *p, void *cls) | |||
410 | return; | 531 | return; |
411 | 532 | ||
412 | test_connected = GNUNET_NO; | 533 | test_connected = GNUNET_NO; |
413 | |||
414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
415 | "Peer %u: `%s' using configuration file `%s'\n", p1->no, | ||
416 | GNUNET_i2s (&p1->id), cfg_file_p1); | ||
417 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
418 | "Peer %u: `%s' using configuration file `%s'\n", p2->no, | ||
419 | GNUNET_i2s (&p2->id), cfg_file_p2); | ||
420 | |||
421 | sender = p2; | ||
422 | receiver = p1; | ||
423 | |||
424 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&sender->id)); | ||
425 | |||
426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
427 | "Test triest to send from %u (%s) -> peer %u (%s)\n", sender->no, | ||
428 | sender_c, receiver->no, GNUNET_i2s (&receiver->id)); | ||
429 | GNUNET_free (sender_c); | ||
430 | |||
431 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, | 534 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, |
432 | NULL); | 535 | NULL); |
433 | 536 | ||
434 | } | 537 | } |
435 | 538 | ||
436 | |||
437 | static void | 539 | static void |
438 | run (void *cls, char *const *args, const char *cfgfile, | 540 | run (void *cls, char *const *args, const char *cfgfile, |
439 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 541 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
440 | { | 542 | { |
441 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 543 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
544 | test_send_timeout = GNUNET_NO; | ||
442 | 545 | ||
443 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, | 546 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, |
444 | ¬ify_receive, ¬ify_connect, | 547 | ¬ify_receive, ¬ify_connect, |
@@ -448,21 +551,24 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
448 | ¬ify_receive, ¬ify_connect, | 551 | ¬ify_receive, ¬ify_connect, |
449 | ¬ify_disconnect, &start_cb, | 552 | ¬ify_disconnect, &start_cb, |
450 | NULL); | 553 | NULL); |
451 | |||
452 | if ((p1 == NULL) || (p2 == NULL)) | 554 | if ((p1 == NULL) || (p2 == NULL)) |
453 | { | 555 | { |
454 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); | 556 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); |
455 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | 557 | if (die_task != GNUNET_SCHEDULER_NO_TASK) |
456 | GNUNET_SCHEDULER_cancel (die_task); | 558 | GNUNET_SCHEDULER_cancel (die_task); |
457 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 559 | //die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); |
458 | return; | 560 | return; |
459 | } | 561 | } |
460 | } | 562 | } |
461 | 563 | ||
462 | static int | 564 | |
463 | check () | 565 | int |
566 | main (int argc, char *argv[]) | ||
464 | { | 567 | { |
465 | static char *argv[] = { "test_transport", | 568 | char *test_source; |
569 | int ret; | ||
570 | |||
571 | static char *const argv_new[] = { "test-transport-api-reliability", | ||
466 | "-c", | 572 | "-c", |
467 | "test_transport_api_data.conf", | 573 | "test_transport_api_data.conf", |
468 | NULL | 574 | NULL |
@@ -471,18 +577,6 @@ check () | |||
471 | GNUNET_GETOPT_OPTION_END | 577 | GNUNET_GETOPT_OPTION_END |
472 | }; | 578 | }; |
473 | 579 | ||
474 | ok = 1; | ||
475 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name, | ||
476 | "nohelp", options, &run, &ok); | ||
477 | |||
478 | return ok; | ||
479 | } | ||
480 | |||
481 | int | ||
482 | main (int argc, char *argv[]) | ||
483 | { | ||
484 | int ret; | ||
485 | |||
486 | GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); | 580 | GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); |
487 | 581 | ||
488 | GNUNET_log_setup (test_name, | 582 | GNUNET_log_setup (test_name, |
@@ -498,7 +592,17 @@ main (int argc, char *argv[]) | |||
498 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1); | 592 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1); |
499 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2); | 593 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2); |
500 | 594 | ||
501 | ret = check (); | 595 | |
596 | |||
597 | #if WRITECONFIG | ||
598 | setTransportOptions ("test_transport_api_data.conf"); | ||
599 | #endif | ||
600 | ok = GNUNET_SYSERR; | ||
601 | |||
602 | ret = GNUNET_PROGRAM_run ((sizeof (argv_new) / sizeof (char *)) - 1, argv_new, test_name, | ||
603 | "nohelp", options, &run, &ok); | ||
604 | if (GNUNET_SYSERR == ret) | ||
605 | ok = -1; | ||
502 | 606 | ||
503 | GNUNET_free (cfg_file_p1); | 607 | GNUNET_free (cfg_file_p1); |
504 | GNUNET_free (cfg_file_p2); | 608 | GNUNET_free (cfg_file_p2); |
@@ -507,8 +611,7 @@ main (int argc, char *argv[]) | |||
507 | GNUNET_free (test_plugin); | 611 | GNUNET_free (test_plugin); |
508 | GNUNET_free (test_name); | 612 | GNUNET_free (test_name); |
509 | 613 | ||
510 | return ret; | 614 | return ok; |
511 | } | 615 | } |
512 | 616 | ||
513 | |||
514 | /* end of test_transport_api_reliability.c */ | 617 | /* end of test_transport_api_reliability.c */ |