aboutsummaryrefslogtreecommitdiff
path: root/src/fragmentation
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-03-25 14:31:03 +0000
committerChristian Grothoff <christian@grothoff.org>2015-03-25 14:31:03 +0000
commit00f87691363acaf94f533793654e610e46bf4e1d (patch)
tree7598432b2335d378d240dcba84aabea7e0f31a14 /src/fragmentation
parentf1ba43deea5e7a1fbc22b429196d1f9fb4e1a9f3 (diff)
downloadgnunet-00f87691363acaf94f533793654e610e46bf4e1d.tar.gz
gnunet-00f87691363acaf94f533793654e610e46bf4e1d.zip
-trying to fix AE's problem on Guix with more fancy retransmission logic
Diffstat (limited to 'src/fragmentation')
-rw-r--r--src/fragmentation/Makefile.am13
-rw-r--r--src/fragmentation/defragmentation.c27
-rw-r--r--src/fragmentation/fragmentation.c41
-rw-r--r--src/fragmentation/test_fragmentation.c204
-rw-r--r--src/fragmentation/test_fragmentation_parallel.c253
5 files changed, 436 insertions, 102 deletions
diff --git a/src/fragmentation/Makefile.am b/src/fragmentation/Makefile.am
index e8bb17d53..316f69158 100644
--- a/src/fragmentation/Makefile.am
+++ b/src/fragmentation/Makefile.am
@@ -13,7 +13,7 @@ lib_LTLIBRARIES = libgnunetfragmentation.la
13 13
14libgnunetfragmentation_la_SOURCES = \ 14libgnunetfragmentation_la_SOURCES = \
15 fragmentation.c fragmentation.h \ 15 fragmentation.c fragmentation.h \
16 defragmentation.c 16 defragmentation.c
17libgnunetfragmentation_la_LIBADD = -lm \ 17libgnunetfragmentation_la_LIBADD = -lm \
18 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 18 $(top_builddir)/src/statistics/libgnunetstatistics.la \
19 $(top_builddir)/src/util/libgnunetutil.la \ 19 $(top_builddir)/src/util/libgnunetutil.la \
@@ -23,7 +23,8 @@ libgnunetfragmentation_la_LDFLAGS = \
23 -version-info 2:0:0 23 -version-info 2:0:0
24 24
25check_PROGRAMS = \ 25check_PROGRAMS = \
26 test_fragmentation 26 test_fragmentation \
27 test_fragmentation_parallel
27 28
28if ENABLE_TEST_RUN 29if ENABLE_TEST_RUN
29AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; 30AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;
@@ -34,6 +35,12 @@ test_fragmentation_SOURCES = \
34 test_fragmentation.c 35 test_fragmentation.c
35test_fragmentation_LDADD = \ 36test_fragmentation_LDADD = \
36 libgnunetfragmentation.la \ 37 libgnunetfragmentation.la \
37 $(top_builddir)/src/util/libgnunetutil.la 38 $(top_builddir)/src/util/libgnunetutil.la
39
40test_fragmentation_parallel_SOURCES = \
41 test_fragmentation_parallel.c
42test_fragmentation_parallel_LDADD = \
43 libgnunetfragmentation.la \
44 $(top_builddir)/src/util/libgnunetutil.la
38 45
39EXTRA_DIST = test_fragmentation_data.conf 46EXTRA_DIST = test_fragmentation_data.conf
diff --git a/src/fragmentation/defragmentation.c b/src/fragmentation/defragmentation.c
index 5c4a68416..a89084287 100644
--- a/src/fragmentation/defragmentation.c
+++ b/src/fragmentation/defragmentation.c
@@ -109,13 +109,13 @@ struct MessageContext
109 109
110 /** 110 /**
111 * For the current ACK round, which is the first relevant 111 * For the current ACK round, which is the first relevant
112 * offset in 'frag_times'? 112 * offset in @e frag_times?
113 */ 113 */
114 unsigned int frag_times_start_offset; 114 unsigned int frag_times_start_offset;
115 115
116 /** 116 /**
117 * Which offset whould we write the next frag value into 117 * Which offset whould we write the next frag value into
118 * in the 'frag_times' array? All smaller entries are valid. 118 * in the @e frag_times array? All smaller entries are valid.
119 */ 119 */
120 unsigned int frag_times_write_offset; 120 unsigned int frag_times_write_offset;
121 121
@@ -124,6 +124,11 @@ struct MessageContext
124 */ 124 */
125 uint16_t total_size; 125 uint16_t total_size;
126 126
127 /**
128 * Was the last fragment we got a duplicate?
129 */
130 int16_t last_duplicate;
131
127}; 132};
128 133
129 134
@@ -185,6 +190,7 @@ struct GNUNET_DEFRAGMENT_Context
185 * Maximum message size for each fragment. 190 * Maximum message size for each fragment.
186 */ 191 */
187 uint16_t mtu; 192 uint16_t mtu;
193
188}; 194};
189 195
190 196
@@ -271,6 +277,7 @@ send_ack (void *cls,
271 _("# acknowledgements sent for fragment"), 277 _("# acknowledgements sent for fragment"),
272 1, 278 1,
273 GNUNET_NO); 279 GNUNET_NO);
280 mc->last_duplicate = GNUNET_NO; /* clear flag */
274 dc->ackp (dc->cls, 281 dc->ackp (dc->cls,
275 mc->fragment_id, 282 mc->fragment_id,
276 &fa.header); 283 &fa.header);
@@ -535,11 +542,13 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
535 GNUNET_NO); 542 GNUNET_NO);
536 } 543 }
537 544
538 /* count number of missing fragments */ 545 /* count number of missing fragments after the current one */
539 bc = 0; 546 bc = 0;
540 for (b = 0; b < 64; b++) 547 for (b = bit; b < 64; b++)
541 if (0 != (mc->bits & (1LL << b))) 548 if (0 != (mc->bits & (1LL << b)))
542 bc++; 549 bc++;
550 else
551 bc = 0;
543 552
544 /* notify about complete message */ 553 /* notify about complete message */
545 if ( (GNUNET_NO == duplicate) && 554 if ( (GNUNET_NO == duplicate) &&
@@ -560,23 +569,23 @@ GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc,
560 delay = GNUNET_TIME_relative_multiply (dc->latency, 569 delay = GNUNET_TIME_relative_multiply (dc->latency,
561 bc + 1); 570 bc + 1);
562 if ( (last + fid == num_fragments) || 571 if ( (last + fid == num_fragments) ||
563 ( (0 == mc->bits) && 572 (0 == mc->bits) ||
564 (GNUNET_YES != duplicate)) ) 573 (GNUNET_YES == duplicate) )
565 { 574 {
566 /* message complete or duplicate or last missing fragment in 575 /* message complete or duplicate or last missing fragment in
567 linear sequence; ACK now! */ 576 linear sequence; ACK now! */
568 delay = GNUNET_TIME_UNIT_ZERO; 577 delay = GNUNET_TIME_UNIT_ZERO;
569 } 578 }
570 if (GNUNET_YES == duplicate)
571 delay = GNUNET_TIME_relative_multiply (delay,
572 2);
573 if (NULL != mc->ack_task) 579 if (NULL != mc->ack_task)
574 GNUNET_SCHEDULER_cancel (mc->ack_task); 580 GNUNET_SCHEDULER_cancel (mc->ack_task);
575 mc->ack_task = GNUNET_SCHEDULER_add_delayed (delay, 581 mc->ack_task = GNUNET_SCHEDULER_add_delayed (delay,
576 &send_ack, 582 &send_ack,
577 mc); 583 mc);
578 if (GNUNET_YES == duplicate) 584 if (GNUNET_YES == duplicate)
585 {
586 mc->last_duplicate = GNUNET_YES;
579 return GNUNET_NO; 587 return GNUNET_NO;
588 }
580 return GNUNET_YES; 589 return GNUNET_YES;
581} 590}
582 591
diff --git a/src/fragmentation/fragmentation.c b/src/fragmentation/fragmentation.c
index 9f4a91447..9566444cb 100644
--- a/src/fragmentation/fragmentation.c
+++ b/src/fragmentation/fragmentation.c
@@ -231,10 +231,14 @@ transmit_next (void *cls,
231 fsize - sizeof (struct FragmentHeader)); 231 fsize - sizeof (struct FragmentHeader));
232 if (NULL != fc->tracker) 232 if (NULL != fc->tracker)
233 GNUNET_BANDWIDTH_tracker_consume (fc->tracker, fsize); 233 GNUNET_BANDWIDTH_tracker_consume (fc->tracker, fsize);
234 GNUNET_STATISTICS_update (fc->stats, _("# fragments transmitted"), 1, 234 GNUNET_STATISTICS_update (fc->stats,
235 _("# fragments transmitted"),
236 1,
235 GNUNET_NO); 237 GNUNET_NO);
236 if (0 != fc->last_round.abs_value_us) 238 if (0 != fc->last_round.abs_value_us)
237 GNUNET_STATISTICS_update (fc->stats, _("# fragments retransmitted"), 1, 239 GNUNET_STATISTICS_update (fc->stats,
240 _("# fragments retransmitted"),
241 1,
238 GNUNET_NO); 242 GNUNET_NO);
239 243
240 /* select next message to calculate delay */ 244 /* select next message to calculate delay */
@@ -245,7 +249,8 @@ transmit_next (void *cls,
245 else 249 else
246 fsize = fc->mtu; 250 fsize = fc->mtu;
247 if (NULL != fc->tracker) 251 if (NULL != fc->tracker)
248 delay = GNUNET_BANDWIDTH_tracker_get_delay (fc->tracker, fsize); 252 delay = GNUNET_BANDWIDTH_tracker_get_delay (fc->tracker,
253 fsize);
249 else 254 else
250 delay = GNUNET_TIME_UNIT_ZERO; 255 delay = GNUNET_TIME_UNIT_ZERO;
251 delay = GNUNET_TIME_relative_max (delay, 256 delay = GNUNET_TIME_relative_max (delay,
@@ -260,7 +265,9 @@ transmit_next (void *cls,
260 delay = GNUNET_TIME_relative_max (MIN_ACK_DELAY, delay); 265 delay = GNUNET_TIME_relative_max (MIN_ACK_DELAY, delay);
261 fc->wack = GNUNET_YES; 266 fc->wack = GNUNET_YES;
262 fc->last_round = GNUNET_TIME_absolute_get (); 267 fc->last_round = GNUNET_TIME_absolute_get ();
263 GNUNET_STATISTICS_update (fc->stats, _("# fragments wrap arounds"), 1, 268 GNUNET_STATISTICS_update (fc->stats,
269 _("# fragments wrap arounds"),
270 1,
264 GNUNET_NO); 271 GNUNET_NO);
265 } 272 }
266 fc->proc_busy = GNUNET_YES; 273 fc->proc_busy = GNUNET_YES;
@@ -304,10 +311,14 @@ GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats,
304 size_t size; 311 size_t size;
305 uint64_t bits; 312 uint64_t bits;
306 313
307 GNUNET_STATISTICS_update (stats, _("# messages fragmented"), 1, GNUNET_NO); 314 GNUNET_STATISTICS_update (stats,
315 _("# messages fragmented"),
316 1,
317 GNUNET_NO);
308 GNUNET_assert (mtu >= 1024 + sizeof (struct FragmentHeader)); 318 GNUNET_assert (mtu >= 1024 + sizeof (struct FragmentHeader));
309 size = ntohs (msg->size); 319 size = ntohs (msg->size);
310 GNUNET_STATISTICS_update (stats, _("# total size of fragmented messages"), 320 GNUNET_STATISTICS_update (stats,
321 _("# total size of fragmented messages"),
311 size, GNUNET_NO); 322 size, GNUNET_NO);
312 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); 323 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
313 fc = GNUNET_malloc (sizeof (struct GNUNET_FRAGMENT_Context) + size); 324 fc = GNUNET_malloc (sizeof (struct GNUNET_FRAGMENT_Context) + size);
@@ -395,7 +406,6 @@ GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
395 ndelay = GNUNET_TIME_absolute_get_duration (fc->last_round); 406 ndelay = GNUNET_TIME_absolute_get_duration (fc->last_round);
396 fc->ack_delay.rel_value_us = 407 fc->ack_delay.rel_value_us =
397 (ndelay.rel_value_us / fc->num_transmissions + 3 * fc->ack_delay.rel_value_us) / 4; 408 (ndelay.rel_value_us / fc->num_transmissions + 3 * fc->ack_delay.rel_value_us) / 4;
398 fc->num_transmissions = 0;
399 /* calculate ratio msg sent vs. msg acked */ 409 /* calculate ratio msg sent vs. msg acked */
400 ack_cnt = 0; 410 ack_cnt = 0;
401 snd_cnt = 0; 411 snd_cnt = 0;
@@ -417,18 +427,22 @@ GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
417 else if (snd_cnt > ack_cnt) 427 else if (snd_cnt > ack_cnt)
418 { 428 {
419 /* some loss, slow down proportionally */ 429 /* some loss, slow down proportionally */
420 fprintf (stderr, "Prop loss\n");
421 fc->msg_delay.rel_value_us = ((fc->msg_delay.rel_value_us * ack_cnt) / snd_cnt); 430 fc->msg_delay.rel_value_us = ((fc->msg_delay.rel_value_us * ack_cnt) / snd_cnt);
422 } 431 }
423 else if (100 < fc->msg_delay.rel_value_us) 432 else if (snd_cnt == ack_cnt)
424 { 433 {
425 fc->msg_delay.rel_value_us -= 100; /* try a bit faster */ 434 fc->msg_delay.rel_value_us =
435 (ndelay.rel_value_us / fc->num_transmissions + 3 * fc->msg_delay.rel_value_us) / 5;
426 } 436 }
437 fc->num_transmissions = 0;
427 fc->msg_delay = GNUNET_TIME_relative_min (fc->msg_delay, 438 fc->msg_delay = GNUNET_TIME_relative_min (fc->msg_delay,
428 GNUNET_TIME_UNIT_SECONDS); 439 GNUNET_TIME_UNIT_SECONDS);
440 fc->ack_delay = GNUNET_TIME_relative_min (fc->ack_delay,
441 GNUNET_TIME_UNIT_SECONDS);
429 } 442 }
430 GNUNET_STATISTICS_update (fc->stats, 443 GNUNET_STATISTICS_update (fc->stats,
431 _("# fragment acknowledgements received"), 1, 444 _("# fragment acknowledgements received"),
445 1,
432 GNUNET_NO); 446 GNUNET_NO);
433 if (abits != (fc->acks & abits)) 447 if (abits != (fc->acks & abits))
434 { 448 {
@@ -458,9 +472,10 @@ GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc,
458 472
459 /* all done */ 473 /* all done */
460 GNUNET_STATISTICS_update (fc->stats, 474 GNUNET_STATISTICS_update (fc->stats,
461 _("# fragmentation transmissions completed"), 1, 475 _("# fragmentation transmissions completed"),
476 1,
462 GNUNET_NO); 477 GNUNET_NO);
463 if (fc->task != NULL) 478 if (NULL != fc->task)
464 { 479 {
465 GNUNET_SCHEDULER_cancel (fc->task); 480 GNUNET_SCHEDULER_cancel (fc->task);
466 fc->task = NULL; 481 fc->task = NULL;
diff --git a/src/fragmentation/test_fragmentation.c b/src/fragmentation/test_fragmentation.c
index b55ec58bf..1cd084cd1 100644
--- a/src/fragmentation/test_fragmentation.c
+++ b/src/fragmentation/test_fragmentation.c
@@ -30,7 +30,7 @@
30/** 30/**
31 * Number of messages to transmit (note: each uses ~32k memory!) 31 * Number of messages to transmit (note: each uses ~32k memory!)
32 */ 32 */
33#define NUM_MSGS 500 33#define NUM_MSGS 1000
34 34
35/** 35/**
36 * MTU to force on fragmentation (must be > 1k + 12) 36 * MTU to force on fragmentation (must be > 1k + 12)
@@ -40,7 +40,7 @@
40/** 40/**
41 * Simulate dropping of 1 out of how many messages? (must be > 1) 41 * Simulate dropping of 1 out of how many messages? (must be > 1)
42 */ 42 */
43#define DROPRATE 5 43#define DROPRATE 15
44 44
45static int ret = 1; 45static int ret = 1;
46 46
@@ -58,26 +58,35 @@ static struct GNUNET_DEFRAGMENT_Context *defrag;
58 58
59static struct GNUNET_BANDWIDTH_Tracker trackers[NUM_MSGS]; 59static struct GNUNET_BANDWIDTH_Tracker trackers[NUM_MSGS];
60 60
61static struct GNUNET_FRAGMENT_Context *frags[NUM_MSGS]; 61static struct GNUNET_FRAGMENT_Context *frag;
62 62
63static struct GNUNET_SCHEDULER_Task * shutdown_task; 63static struct GNUNET_SCHEDULER_Task * shutdown_task;
64 64
65static struct GNUNET_TIME_Relative msg_delay;
66
67static struct GNUNET_TIME_Relative ack_delay;
68
69
65static void 70static void
66do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 71do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
67{ 72{
68 unsigned int i;
69
70 ret = 0; 73 ret = 0;
71 shutdown_task = NULL; 74 shutdown_task = NULL;
72 GNUNET_DEFRAGMENT_context_destroy (defrag); 75 GNUNET_DEFRAGMENT_context_destroy (defrag);
73 defrag = NULL; 76 defrag = NULL;
74 for (i = 0; i < NUM_MSGS; i++) 77 if (NULL != frag)
75 { 78 {
76 if (frags[i] == NULL) 79 GNUNET_FRAGMENT_context_destroy (frag, &msg_delay, &ack_delay);
77 continue; 80 frag = NULL;
78 GNUNET_FRAGMENT_context_destroy (frags[i], NULL, NULL);
79 frags[i] = NULL;
80 } 81 }
82 fprintf (stderr,
83 "\nFinal message-delay: %s\n",
84 GNUNET_STRINGS_relative_time_to_string (msg_delay,
85 GNUNET_YES));
86 fprintf (stderr,
87 "Final ack-delay: %s\n",
88 GNUNET_STRINGS_relative_time_to_string (ack_delay,
89 GNUNET_YES));
81} 90}
82 91
83 92
@@ -89,7 +98,7 @@ proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr)
89 const char *buf; 98 const char *buf;
90 99
91#if DETAILS 100#if DETAILS
92 FPRINTF (stderr, "%s", "!"); /* message complete, good! */ 101 FPRINTF (stderr, "%s", "M! "); /* message complete, good! */
93#endif 102#endif
94 buf = (const char *) hdr; 103 buf = (const char *) hdr;
95 for (i = sizeof (struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++) 104 for (i = sizeof (struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++)
@@ -109,84 +118,130 @@ proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr)
109 118
110 119
111/** 120/**
112 * Process ACK (by passing to fragmenter) 121 * Process fragment (by passing to defrag).
113 */ 122 */
114static void 123static void
115proc_acks (void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr) 124proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr)
116{ 125{
117 unsigned int i; 126 struct GNUNET_FRAGMENT_Context **fc = cls;
118 int ret; 127 int ret;
119 128
129 GNUNET_FRAGMENT_context_transmission_done (*fc);
120 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) 130 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE))
121 { 131 {
122 ack_drops++; 132 frag_drops++;
133#if DETAILS
134 FPRINTF (stderr, "%s", "DF "); /* dropped Frag */
135#endif
123 return; /* random drop */ 136 return; /* random drop */
124 } 137 }
125 for (i = 0; i < NUM_MSGS; i++) 138 if (NULL == defrag)
139 {
140 FPRINTF (stderr, "%s", "?E "); /* Error: frag after shutdown!? */
141 return;
142 }
143 ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr);
144 if (ret == GNUNET_NO)
126 { 145 {
127 if (frags[i] == NULL)
128 continue;
129 ret = GNUNET_FRAGMENT_process_ack (frags[i], hdr);
130 if (ret == GNUNET_OK)
131 {
132#if DETAILS 146#if DETAILS
133 FPRINTF (stderr, "%s", "@"); /* good ACK */ 147 FPRINTF (stderr, "%s", "FF "); /* duplicate fragment */
134#endif 148#endif
135 GNUNET_FRAGMENT_context_destroy (frags[i], NULL, NULL); 149 dups++;
136 frags[i] = NULL; 150 }
137 acks++; 151 else if (ret == GNUNET_OK)
138 return; 152 {
139 }
140 if (ret == GNUNET_NO)
141 {
142#if DETAILS 153#if DETAILS
143 FPRINTF (stderr, "%s", "@"); /* good ACK */ 154 FPRINTF (stderr, "%s", "F! "); /* good fragment */
144#endif 155#endif
145 acks++; 156 fragc++;
146 return;
147 }
148 } 157 }
158}
159
160
161static void
162next_transmission ()
163{
164 static unsigned int i;
165 struct GNUNET_MessageHeader *msg;
166 static char buf[MTU + 32 * 1024];
167 unsigned int j;
168
169 if (0 == i)
170 {
171 for (j = 0; j < sizeof (buf); j++)
172 buf[j] = (char) j;
173 }
174 else
175 {
176 GNUNET_FRAGMENT_context_destroy (frag,
177 &msg_delay,
178 &ack_delay);
179 frag = NULL;
180 }
181 if (i == NUM_MSGS)
182 return;
149#if DETAILS 183#if DETAILS
150 FPRINTF (stderr, "%s", "_"); /* BAD: ack that nobody feels responsible for... */ 184 FPRINTF (stderr, "%s", "T! "); /* sending message */
151#endif 185#endif
186 msg = (struct GNUNET_MessageHeader *) buf;
187 msg->type = htons ((uint16_t) i);
188 msg->size =
189 htons (sizeof (struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024));
190 frag = GNUNET_FRAGMENT_context_create (NULL /* no stats */ ,
191 MTU, &trackers[i],
192 msg_delay,
193 ack_delay,
194 msg,
195 &proc_frac, &frag);
196 i++;
152} 197}
153 198
154 199
155/** 200/**
156 * Process fragment (by passing to defrag). 201 * Process ACK (by passing to fragmenter)
157 */ 202 */
158static void 203static void
159proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr) 204proc_acks (void *cls,
205 uint32_t msg_id,
206 const struct GNUNET_MessageHeader *hdr)
160{ 207{
161 struct GNUNET_FRAGMENT_Context **fc = cls; 208 unsigned int i;
162 int ret; 209 int ret;
163 210
164 GNUNET_FRAGMENT_context_transmission_done (*fc);
165 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) 211 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE))
166 { 212 {
167 frag_drops++; 213 ack_drops++;
214#if DETAILS
215 FPRINTF (stderr, "%s", "DA "); /* dropped ACK */
216#endif
168 return; /* random drop */ 217 return; /* random drop */
169 } 218 }
170 if (NULL == defrag) 219 for (i = 0; i < NUM_MSGS; i++)
171 {
172 FPRINTF (stderr, "%s", "E"); /* Error: frag after shutdown!? */
173 return;
174 }
175 ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr);
176 if (ret == GNUNET_NO)
177 { 220 {
221 if (NULL == frag)
222 continue;
223 ret = GNUNET_FRAGMENT_process_ack (frag, hdr);
224 if (ret == GNUNET_OK)
225 {
178#if DETAILS 226#if DETAILS
179 FPRINTF (stderr, "%s", "?"); /* duplicate fragment */ 227 FPRINTF (stderr, "%s", "GA "); /* good ACK */
180#endif 228#endif
181 dups++; 229 next_transmission ();
182 } 230 acks++;
183 else if (ret == GNUNET_OK) 231 return;
184 { 232 }
233 if (ret == GNUNET_NO)
234 {
185#if DETAILS 235#if DETAILS
186 FPRINTF (stderr, "%s", "."); /* good fragment */ 236 FPRINTF (stderr, "%s", "AA "); /* duplciate ACK */
187#endif 237#endif
188 fragc++; 238 acks++;
239 return;
240 }
189 } 241 }
242#if DETAILS
243 FPRINTF (stderr, "%s", "?A "); /* BAD: ack that nobody feels responsible for... */
244#endif
190} 245}
191 246
192 247
@@ -194,30 +249,17 @@ proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr)
194 * Main function run with scheduler. 249 * Main function run with scheduler.
195 */ 250 */
196static void 251static void
197run (void *cls, char *const *args, const char *cfgfile, 252run (void *cls,
253 char *const *args,
254 const char *cfgfile,
198 const struct GNUNET_CONFIGURATION_Handle *cfg) 255 const struct GNUNET_CONFIGURATION_Handle *cfg)
199{ 256{
200 unsigned int i; 257 defrag = GNUNET_DEFRAGMENT_context_create (NULL, MTU,
201 struct GNUNET_MessageHeader *msg; 258 3,
202 char buf[MTU + 32 * 1024]; 259 NULL,
203 260 &proc_msgs,
204 defrag = GNUNET_DEFRAGMENT_context_create (NULL, MTU, NUM_MSGS /* enough space for all */ 261 &proc_acks);
205 , NULL, &proc_msgs, &proc_acks); 262 next_transmission ();
206 for (i = 0; i < sizeof (buf); i++)
207 buf[i] = (char) i;
208 msg = (struct GNUNET_MessageHeader *) buf;
209 for (i = 0; i < NUM_MSGS; i++)
210 {
211 msg->type = htons ((uint16_t) i);
212 msg->size =
213 htons (sizeof (struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024));
214 frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */ ,
215 MTU, &trackers[i],
216 GNUNET_TIME_UNIT_MILLISECONDS,
217 GNUNET_TIME_UNIT_SECONDS,
218 msg,
219 &proc_frac, &frags[i]);
220 }
221} 263}
222 264
223 265
@@ -237,6 +279,8 @@ main (int argc, char *argv[])
237 }; 279 };
238 unsigned int i; 280 unsigned int i;
239 281
282 msg_delay = GNUNET_TIME_UNIT_MILLISECONDS;
283 ack_delay = GNUNET_TIME_UNIT_SECONDS;
240 GNUNET_log_setup ("test-fragmentation", 284 GNUNET_log_setup ("test-fragmentation",
241 "WARNING", 285 "WARNING",
242 NULL); 286 NULL);
@@ -244,10 +288,16 @@ main (int argc, char *argv[])
244 GNUNET_BANDWIDTH_tracker_init (&trackers[i], NULL, NULL, 288 GNUNET_BANDWIDTH_tracker_init (&trackers[i], NULL, NULL,
245 GNUNET_BANDWIDTH_value_init ((i + 1) * 1024), 289 GNUNET_BANDWIDTH_value_init ((i + 1) * 1024),
246 100); 290 100);
247 GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options, 291 GNUNET_PROGRAM_run (5,
292 argv_prog,
293 "test-fragmentation", "nohelp",
294 options,
248 &run, NULL); 295 &run, NULL);
249 FPRINTF (stderr, 296 FPRINTF (stderr,
250 "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n", 297 "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n",
251 fragc, dups, acks, ack_drops); 298 fragc,
299 dups,
300 acks,
301 ack_drops);
252 return ret; 302 return ret;
253} 303}
diff --git a/src/fragmentation/test_fragmentation_parallel.c b/src/fragmentation/test_fragmentation_parallel.c
new file mode 100644
index 000000000..b55ec58bf
--- /dev/null
+++ b/src/fragmentation/test_fragmentation_parallel.c
@@ -0,0 +1,253 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2004, 2009 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 fragmentation/test_fragmentation.c
22 * @brief test for fragmentation.c
23 * @author Christian Grothoff
24 */
25#include "platform.h"
26#include "gnunet_fragmentation_lib.h"
27
28#define DETAILS GNUNET_NO
29
30/**
31 * Number of messages to transmit (note: each uses ~32k memory!)
32 */
33#define NUM_MSGS 500
34
35/**
36 * MTU to force on fragmentation (must be > 1k + 12)
37 */
38#define MTU 1111
39
40/**
41 * Simulate dropping of 1 out of how many messages? (must be > 1)
42 */
43#define DROPRATE 5
44
45static int ret = 1;
46
47static unsigned int dups;
48
49static unsigned int fragc;
50
51static unsigned int frag_drops;
52
53static unsigned int acks;
54
55static unsigned int ack_drops;
56
57static struct GNUNET_DEFRAGMENT_Context *defrag;
58
59static struct GNUNET_BANDWIDTH_Tracker trackers[NUM_MSGS];
60
61static struct GNUNET_FRAGMENT_Context *frags[NUM_MSGS];
62
63static struct GNUNET_SCHEDULER_Task * shutdown_task;
64
65static void
66do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
67{
68 unsigned int i;
69
70 ret = 0;
71 shutdown_task = NULL;
72 GNUNET_DEFRAGMENT_context_destroy (defrag);
73 defrag = NULL;
74 for (i = 0; i < NUM_MSGS; i++)
75 {
76 if (frags[i] == NULL)
77 continue;
78 GNUNET_FRAGMENT_context_destroy (frags[i], NULL, NULL);
79 frags[i] = NULL;
80 }
81}
82
83
84static void
85proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr)
86{
87 static unsigned int total;
88 unsigned int i;
89 const char *buf;
90
91#if DETAILS
92 FPRINTF (stderr, "%s", "!"); /* message complete, good! */
93#endif
94 buf = (const char *) hdr;
95 for (i = sizeof (struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++)
96 GNUNET_assert (buf[i] == (char) i);
97 total++;
98#if ! DETAILS
99 if (0 == (total % (NUM_MSGS / 100)))
100 FPRINTF (stderr, "%s", ".");
101#endif
102 /* tolerate 10% loss, i.e. due to duplicate fragment IDs */
103 if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0))
104 {
105 if (NULL == shutdown_task)
106 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
107 }
108}
109
110
111/**
112 * Process ACK (by passing to fragmenter)
113 */
114static void
115proc_acks (void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr)
116{
117 unsigned int i;
118 int ret;
119
120 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE))
121 {
122 ack_drops++;
123 return; /* random drop */
124 }
125 for (i = 0; i < NUM_MSGS; i++)
126 {
127 if (frags[i] == NULL)
128 continue;
129 ret = GNUNET_FRAGMENT_process_ack (frags[i], hdr);
130 if (ret == GNUNET_OK)
131 {
132#if DETAILS
133 FPRINTF (stderr, "%s", "@"); /* good ACK */
134#endif
135 GNUNET_FRAGMENT_context_destroy (frags[i], NULL, NULL);
136 frags[i] = NULL;
137 acks++;
138 return;
139 }
140 if (ret == GNUNET_NO)
141 {
142#if DETAILS
143 FPRINTF (stderr, "%s", "@"); /* good ACK */
144#endif
145 acks++;
146 return;
147 }
148 }
149#if DETAILS
150 FPRINTF (stderr, "%s", "_"); /* BAD: ack that nobody feels responsible for... */
151#endif
152}
153
154
155/**
156 * Process fragment (by passing to defrag).
157 */
158static void
159proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr)
160{
161 struct GNUNET_FRAGMENT_Context **fc = cls;
162 int ret;
163
164 GNUNET_FRAGMENT_context_transmission_done (*fc);
165 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE))
166 {
167 frag_drops++;
168 return; /* random drop */
169 }
170 if (NULL == defrag)
171 {
172 FPRINTF (stderr, "%s", "E"); /* Error: frag after shutdown!? */
173 return;
174 }
175 ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr);
176 if (ret == GNUNET_NO)
177 {
178#if DETAILS
179 FPRINTF (stderr, "%s", "?"); /* duplicate fragment */
180#endif
181 dups++;
182 }
183 else if (ret == GNUNET_OK)
184 {
185#if DETAILS
186 FPRINTF (stderr, "%s", "."); /* good fragment */
187#endif
188 fragc++;
189 }
190}
191
192
193/**
194 * Main function run with scheduler.
195 */
196static void
197run (void *cls, char *const *args, const char *cfgfile,
198 const struct GNUNET_CONFIGURATION_Handle *cfg)
199{
200 unsigned int i;
201 struct GNUNET_MessageHeader *msg;
202 char buf[MTU + 32 * 1024];
203
204 defrag = GNUNET_DEFRAGMENT_context_create (NULL, MTU, NUM_MSGS /* enough space for all */
205 , NULL, &proc_msgs, &proc_acks);
206 for (i = 0; i < sizeof (buf); i++)
207 buf[i] = (char) i;
208 msg = (struct GNUNET_MessageHeader *) buf;
209 for (i = 0; i < NUM_MSGS; i++)
210 {
211 msg->type = htons ((uint16_t) i);
212 msg->size =
213 htons (sizeof (struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024));
214 frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */ ,
215 MTU, &trackers[i],
216 GNUNET_TIME_UNIT_MILLISECONDS,
217 GNUNET_TIME_UNIT_SECONDS,
218 msg,
219 &proc_frac, &frags[i]);
220 }
221}
222
223
224int
225main (int argc, char *argv[])
226{
227 struct GNUNET_GETOPT_CommandLineOption options[] = {
228 GNUNET_GETOPT_OPTION_END
229 };
230 char *const argv_prog[] = {
231 "test-fragmentation",
232 "-c",
233 "test_fragmentation_data.conf",
234 "-L",
235 "WARNING",
236 NULL
237 };
238 unsigned int i;
239
240 GNUNET_log_setup ("test-fragmentation",
241 "WARNING",
242 NULL);
243 for (i = 0; i < NUM_MSGS; i++)
244 GNUNET_BANDWIDTH_tracker_init (&trackers[i], NULL, NULL,
245 GNUNET_BANDWIDTH_value_init ((i + 1) * 1024),
246 100);
247 GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options,
248 &run, NULL);
249 FPRINTF (stderr,
250 "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n",
251 fragc, dups, acks, ack_drops);
252 return ret;
253}