diff options
Diffstat (limited to 'src/fragmentation/test_fragmentation.c')
-rw-r--r-- | src/fragmentation/test_fragmentation.c | 170 |
1 files changed, 79 insertions, 91 deletions
diff --git a/src/fragmentation/test_fragmentation.c b/src/fragmentation/test_fragmentation.c index 25f1c2053..b534a134e 100644 --- a/src/fragmentation/test_fragmentation.c +++ b/src/fragmentation/test_fragmentation.c | |||
@@ -44,7 +44,7 @@ | |||
44 | */ | 44 | */ |
45 | #define DROPRATE 10 | 45 | #define DROPRATE 10 |
46 | 46 | ||
47 | static int ret = 1; | 47 | static int ret = 1; |
48 | 48 | ||
49 | static unsigned int dups; | 49 | static unsigned int dups; |
50 | 50 | ||
@@ -63,18 +63,17 @@ static struct GNUNET_BANDWIDTH_Tracker trackers[NUM_MSGS]; | |||
63 | static struct GNUNET_FRAGMENT_Context *frags[NUM_MSGS]; | 63 | static struct GNUNET_FRAGMENT_Context *frags[NUM_MSGS]; |
64 | 64 | ||
65 | static void | 65 | static void |
66 | proc_msgs (void *cls, | 66 | proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr) |
67 | const struct GNUNET_MessageHeader *hdr) | ||
68 | { | 67 | { |
69 | static unsigned int total; | 68 | static unsigned int total; |
70 | unsigned int i; | 69 | unsigned int i; |
71 | const char *buf; | 70 | const char *buf; |
72 | 71 | ||
73 | #if DETAILS | 72 | #if DETAILS |
74 | fprintf (stderr, "!"); /* message complete, good! */ | 73 | fprintf (stderr, "!"); /* message complete, good! */ |
75 | #endif | 74 | #endif |
76 | buf = (const char*) hdr; | 75 | buf = (const char *) hdr; |
77 | for (i=sizeof (struct GNUNET_MessageHeader);i<ntohs(hdr->size);i++) | 76 | for (i = sizeof (struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++) |
78 | GNUNET_assert (buf[i] == (char) i); | 77 | GNUNET_assert (buf[i] == (char) i); |
79 | total++; | 78 | total++; |
80 | #if ! DETAILS | 79 | #if ! DETAILS |
@@ -83,18 +82,18 @@ proc_msgs (void *cls, | |||
83 | #endif | 82 | #endif |
84 | /* tolerate 10% loss, i.e. due to duplicate fragment IDs */ | 83 | /* tolerate 10% loss, i.e. due to duplicate fragment IDs */ |
85 | if (total >= NUM_MSGS - (NUM_MSGS / 10)) | 84 | if (total >= NUM_MSGS - (NUM_MSGS / 10)) |
85 | { | ||
86 | ret = 0; | ||
87 | GNUNET_DEFRAGMENT_context_destroy (defrag); | ||
88 | defrag = NULL; | ||
89 | for (i = 0; i < NUM_MSGS; i++) | ||
86 | { | 90 | { |
87 | ret = 0; | 91 | if (frags[i] == NULL) |
88 | GNUNET_DEFRAGMENT_context_destroy (defrag); | 92 | continue; |
89 | defrag = NULL; | 93 | GNUNET_FRAGMENT_context_destroy (frags[i]); |
90 | for (i=0;i<NUM_MSGS;i++) | 94 | frags[i] = NULL; |
91 | { | ||
92 | if (frags[i] == NULL) | ||
93 | continue; | ||
94 | GNUNET_FRAGMENT_context_destroy (frags[i]); | ||
95 | frags[i] = NULL; | ||
96 | } | ||
97 | } | 95 | } |
96 | } | ||
98 | } | 97 | } |
99 | 98 | ||
100 | 99 | ||
@@ -102,45 +101,42 @@ proc_msgs (void *cls, | |||
102 | * Process ACK (by passing to fragmenter) | 101 | * Process ACK (by passing to fragmenter) |
103 | */ | 102 | */ |
104 | static void | 103 | static void |
105 | proc_acks (void *cls, | 104 | proc_acks (void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr) |
106 | uint32_t msg_id, | ||
107 | const struct GNUNET_MessageHeader *hdr) | ||
108 | { | 105 | { |
109 | unsigned int i; | 106 | unsigned int i; |
110 | int ret; | 107 | int ret; |
111 | 108 | ||
112 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) | 109 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) |
113 | { | 110 | { |
114 | ack_drops++; | 111 | ack_drops++; |
115 | return; /* random drop */ | 112 | return; /* random drop */ |
116 | } | 113 | } |
117 | for (i=0;i<NUM_MSGS;i++) | 114 | for (i = 0; i < NUM_MSGS; i++) |
115 | { | ||
116 | if (frags[i] == NULL) | ||
117 | continue; | ||
118 | ret = GNUNET_FRAGMENT_process_ack (frags[i], hdr); | ||
119 | if (ret == GNUNET_OK) | ||
118 | { | 120 | { |
119 | if (frags[i] == NULL) | ||
120 | continue; | ||
121 | ret = GNUNET_FRAGMENT_process_ack (frags[i], | ||
122 | hdr); | ||
123 | if (ret == GNUNET_OK) | ||
124 | { | ||
125 | #if DETAILS | 121 | #if DETAILS |
126 | fprintf (stderr, "@"); /* good ACK */ | 122 | fprintf (stderr, "@"); /* good ACK */ |
127 | #endif | 123 | #endif |
128 | GNUNET_FRAGMENT_context_destroy (frags[i]); | 124 | GNUNET_FRAGMENT_context_destroy (frags[i]); |
129 | frags[i] = NULL; | 125 | frags[i] = NULL; |
130 | acks++; | 126 | acks++; |
131 | return; | 127 | return; |
132 | } | 128 | } |
133 | if (ret == GNUNET_NO) | 129 | if (ret == GNUNET_NO) |
134 | { | 130 | { |
135 | #if DETAILS | 131 | #if DETAILS |
136 | fprintf (stderr, "@"); /* good ACK */ | 132 | fprintf (stderr, "@"); /* good ACK */ |
137 | #endif | 133 | #endif |
138 | acks++; | 134 | acks++; |
139 | return; | 135 | return; |
140 | } | ||
141 | } | 136 | } |
137 | } | ||
142 | #if DETAILS | 138 | #if DETAILS |
143 | fprintf (stderr, "_"); /* BAD: ack that nobody feels responsible for... */ | 139 | fprintf (stderr, "_"); /* BAD: ack that nobody feels responsible for... */ |
144 | #endif | 140 | #endif |
145 | } | 141 | } |
146 | 142 | ||
@@ -149,38 +145,37 @@ proc_acks (void *cls, | |||
149 | * Process fragment (by passing to defrag). | 145 | * Process fragment (by passing to defrag). |
150 | */ | 146 | */ |
151 | static void | 147 | static void |
152 | proc_frac (void *cls, | 148 | proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr) |
153 | const struct GNUNET_MessageHeader *hdr) | ||
154 | { | 149 | { |
155 | struct GNUNET_FRAGMENT_Context **fc = cls; | 150 | struct GNUNET_FRAGMENT_Context **fc = cls; |
156 | int ret; | 151 | int ret; |
157 | 152 | ||
158 | GNUNET_FRAGMENT_context_transmission_done (*fc); | 153 | GNUNET_FRAGMENT_context_transmission_done (*fc); |
159 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) | 154 | if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) |
160 | { | 155 | { |
161 | frag_drops++; | 156 | frag_drops++; |
162 | return; /* random drop */ | 157 | return; /* random drop */ |
163 | } | 158 | } |
164 | if (NULL == defrag) | 159 | if (NULL == defrag) |
165 | { | 160 | { |
166 | fprintf (stderr, "E"); /* Error: frag after shutdown!? */ | 161 | fprintf (stderr, "E"); /* Error: frag after shutdown!? */ |
167 | return; | 162 | return; |
168 | } | 163 | } |
169 | ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr); | 164 | ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr); |
170 | if (ret == GNUNET_NO) | 165 | if (ret == GNUNET_NO) |
171 | { | 166 | { |
172 | #if DETAILS | 167 | #if DETAILS |
173 | fprintf (stderr, "?"); /* duplicate fragment */ | 168 | fprintf (stderr, "?"); /* duplicate fragment */ |
174 | #endif | 169 | #endif |
175 | dups++; | 170 | dups++; |
176 | } | 171 | } |
177 | else if (ret == GNUNET_OK) | 172 | else if (ret == GNUNET_OK) |
178 | { | 173 | { |
179 | #if DETAILS | 174 | #if DETAILS |
180 | fprintf (stderr, "."); /* good fragment */ | 175 | fprintf (stderr, "."); /* good fragment */ |
181 | #endif | 176 | #endif |
182 | fragc++; | 177 | fragc++; |
183 | } | 178 | } |
184 | } | 179 | } |
185 | 180 | ||
186 | 181 | ||
@@ -196,27 +191,22 @@ run (void *cls, | |||
196 | struct GNUNET_MessageHeader *msg; | 191 | struct GNUNET_MessageHeader *msg; |
197 | char buf[MTU + 32 * 1024]; | 192 | char buf[MTU + 32 * 1024]; |
198 | 193 | ||
199 | defrag = GNUNET_DEFRAGMENT_context_create (NULL, | 194 | defrag = GNUNET_DEFRAGMENT_context_create (NULL, MTU, NUM_MSGS /* enough space for all */ |
200 | MTU, | 195 | , NULL, &proc_msgs, &proc_acks); |
201 | NUM_MSGS /* enough space for all */, | 196 | for (i = 0; i < sizeof (buf); i++) |
202 | NULL, | ||
203 | &proc_msgs, | ||
204 | &proc_acks); | ||
205 | for (i=0;i<sizeof(buf);i++) | ||
206 | buf[i] = (char) i; | 197 | buf[i] = (char) i; |
207 | msg = (struct GNUNET_MessageHeader* ) buf; | 198 | msg = (struct GNUNET_MessageHeader *) buf; |
208 | for (i=0;i<NUM_MSGS;i++) | 199 | for (i = 0; i < NUM_MSGS; i++) |
209 | { | 200 | { |
210 | msg->type = htons ((uint16_t) i); | 201 | msg->type = htons ((uint16_t) i); |
211 | msg->size = htons (sizeof (struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024)); | 202 | msg->size = |
212 | frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */, | 203 | htons (sizeof (struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024)); |
213 | MTU, | 204 | frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */ , |
214 | &trackers[i], | 205 | MTU, |
215 | GNUNET_TIME_UNIT_SECONDS, | 206 | &trackers[i], |
216 | msg, | 207 | GNUNET_TIME_UNIT_SECONDS, |
217 | &proc_frac, | 208 | msg, &proc_frac, &frags[i]); |
218 | &frags[i]); | 209 | } |
219 | } | ||
220 | } | 210 | } |
221 | 211 | ||
222 | 212 | ||
@@ -247,16 +237,14 @@ main (int argc, char *argv[]) | |||
247 | "WARNING", | 237 | "WARNING", |
248 | #endif | 238 | #endif |
249 | NULL); | 239 | NULL); |
250 | for (i=0;i<NUM_MSGS;i++) | 240 | for (i = 0; i < NUM_MSGS; i++) |
251 | GNUNET_BANDWIDTH_tracker_init (&trackers[i], | 241 | GNUNET_BANDWIDTH_tracker_init (&trackers[i], |
252 | GNUNET_BANDWIDTH_value_init ((i+1) * 1024), | 242 | GNUNET_BANDWIDTH_value_init ((i + 1) * 1024), |
253 | 100); | 243 | 100); |
254 | GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options, &run, NULL); | 244 | GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options, |
255 | fprintf (stderr, | 245 | &run, NULL); |
256 | "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n", | 246 | fprintf (stderr, |
257 | fragc, | 247 | "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n", |
258 | dups, | 248 | fragc, dups, acks, ack_drops); |
259 | acks, | ||
260 | ack_drops); | ||
261 | return ret; | 249 | return ret; |
262 | } | 250 | } |