diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-03-25 14:31:03 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-03-25 14:31:03 +0000 |
commit | 00f87691363acaf94f533793654e610e46bf4e1d (patch) | |
tree | 7598432b2335d378d240dcba84aabea7e0f31a14 /src/fragmentation/test_fragmentation.c | |
parent | f1ba43deea5e7a1fbc22b429196d1f9fb4e1a9f3 (diff) | |
download | gnunet-00f87691363acaf94f533793654e610e46bf4e1d.tar.gz gnunet-00f87691363acaf94f533793654e610e46bf4e1d.zip |
-trying to fix AE's problem on Guix with more fancy retransmission logic
Diffstat (limited to 'src/fragmentation/test_fragmentation.c')
-rw-r--r-- | src/fragmentation/test_fragmentation.c | 204 |
1 files changed, 127 insertions, 77 deletions
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 | ||
45 | static int ret = 1; | 45 | static int ret = 1; |
46 | 46 | ||
@@ -58,26 +58,35 @@ static struct GNUNET_DEFRAGMENT_Context *defrag; | |||
58 | 58 | ||
59 | static struct GNUNET_BANDWIDTH_Tracker trackers[NUM_MSGS]; | 59 | static struct GNUNET_BANDWIDTH_Tracker trackers[NUM_MSGS]; |
60 | 60 | ||
61 | static struct GNUNET_FRAGMENT_Context *frags[NUM_MSGS]; | 61 | static struct GNUNET_FRAGMENT_Context *frag; |
62 | 62 | ||
63 | static struct GNUNET_SCHEDULER_Task * shutdown_task; | 63 | static struct GNUNET_SCHEDULER_Task * shutdown_task; |
64 | 64 | ||
65 | static struct GNUNET_TIME_Relative msg_delay; | ||
66 | |||
67 | static struct GNUNET_TIME_Relative ack_delay; | ||
68 | |||
69 | |||
65 | static void | 70 | static void |
66 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 71 | do_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 | */ |
114 | static void | 123 | static void |
115 | proc_acks (void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr) | 124 | proc_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 | |||
161 | static void | ||
162 | next_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 | */ |
158 | static void | 203 | static void |
159 | proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr) | 204 | proc_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 | */ |
196 | static void | 251 | static void |
197 | run (void *cls, char *const *args, const char *cfgfile, | 252 | run (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 | } |