aboutsummaryrefslogtreecommitdiff
path: root/src/fragmentation/test_fragmentation.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-07-11 22:34:11 +0000
committerChristian Grothoff <christian@grothoff.org>2011-07-11 22:34:11 +0000
commit6ce274c7e9fb01c76dc904d907fce9c893d0fc44 (patch)
treec4eec1e43ac6bfe81b29a367244df12637a3a788 /src/fragmentation/test_fragmentation.c
parentc4c451a78270f0e1ef90dd64b14b179d09b24801 (diff)
downloadgnunet-6ce274c7e9fb01c76dc904d907fce9c893d0fc44.tar.gz
gnunet-6ce274c7e9fb01c76dc904d907fce9c893d0fc44.zip
frag
Diffstat (limited to 'src/fragmentation/test_fragmentation.c')
-rw-r--r--src/fragmentation/test_fragmentation.c120
1 files changed, 108 insertions, 12 deletions
diff --git a/src/fragmentation/test_fragmentation.c b/src/fragmentation/test_fragmentation.c
index 639c0ef17..8a9af04e7 100644
--- a/src/fragmentation/test_fragmentation.c
+++ b/src/fragmentation/test_fragmentation.c
@@ -25,14 +25,41 @@
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_fragmentation_lib.h" 26#include "gnunet_fragmentation_lib.h"
27 27
28#define NUM_MSGS 1 28#define VERBOSE GNUNET_NO
29 29
30#define DETAILS GNUNET_NO
31
32/**
33 * Number of messages to transmit (note: each uses ~32k memory!)
34 */
35#define NUM_MSGS 500
36
37/**
38 * MTU to force on fragmentation (must be > 1k + 12)
39 */
30#define MTU 1111 40#define MTU 1111
31 41
42/**
43 * Simulate dropping of 1 out of how many messages? (must be > 1)
44 */
45#define DROPRATE 2
46
32static int ret = 1; 47static int ret = 1;
33 48
49static unsigned int dups;
50
51static unsigned int fragc;
52
53static unsigned int frag_drops;
54
55static unsigned int acks;
56
57static unsigned int ack_drops;
58
34static struct GNUNET_DEFRAGMENT_Context *defrag; 59static struct GNUNET_DEFRAGMENT_Context *defrag;
35 60
61static struct GNUNET_BANDWIDTH_Tracker trackers[NUM_MSGS];
62
36static struct GNUNET_FRAGMENT_Context *frags[NUM_MSGS]; 63static struct GNUNET_FRAGMENT_Context *frags[NUM_MSGS];
37 64
38static void 65static void
@@ -40,17 +67,36 @@ proc_msgs (void *cls,
40 const struct GNUNET_MessageHeader *hdr) 67 const struct GNUNET_MessageHeader *hdr)
41{ 68{
42 static unsigned int total; 69 static unsigned int total;
70 unsigned int i;
71 const char *buf;
43 72
44 fprintf (stderr, "!"); 73#if DETAILS
74 fprintf (stderr, "!"); /* message complete, good! */
75#endif
76 buf = (const char*) hdr;
77 for (i=sizeof (struct GNUNET_MessageHeader);i<ntohs(hdr->size);i++)
78 GNUNET_assert (buf[i] == (char) i);
45 total++; 79 total++;
80#if ! DETAILS
81 if (0 == (total % (NUM_MSGS / 100)))
82 fprintf (stderr, ".");
83#endif
46 if (total == NUM_MSGS) 84 if (total == NUM_MSGS)
47 { 85 {
48 ret = 0; 86 ret = 0;
49 GNUNET_DEFRAGMENT_context_destroy (defrag); 87 GNUNET_DEFRAGMENT_context_destroy (defrag);
50 defrag = NULL; 88 defrag = NULL;
89 for (i=0;i<NUM_MSGS;i++)
90 {
91 if (frags[i] == NULL)
92 continue;
93 GNUNET_FRAGMENT_context_destroy (frags[i]);
94 frags[i] = NULL;
95 }
51 } 96 }
52} 97}
53 98
99
54/** 100/**
55 * Process ACK (by passing to fragmenter) 101 * Process ACK (by passing to fragmenter)
56 */ 102 */
@@ -61,23 +107,39 @@ proc_acks (void *cls,
61 unsigned int i; 107 unsigned int i;
62 int ret; 108 int ret;
63 109
64 fprintf (stderr, "@"); 110 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE))
111 {
112 ack_drops++;
113 return; /* random drop */
114 }
65 for (i=0;i<NUM_MSGS;i++) 115 for (i=0;i<NUM_MSGS;i++)
66 { 116 {
67 if (frags[i] == NULL) 117 if (frags[i] == NULL)
68 return; 118 continue;
69 ret = GNUNET_FRAGMENT_process_ack (frags[i], 119 ret = GNUNET_FRAGMENT_process_ack (frags[i],
70 hdr); 120 hdr);
71 if (ret == GNUNET_OK) 121 if (ret == GNUNET_OK)
72 { 122 {
123#if DETAILS
124 fprintf (stderr, "@"); /* good ACK */
125#endif
73 GNUNET_FRAGMENT_context_destroy (frags[i]); 126 GNUNET_FRAGMENT_context_destroy (frags[i]);
74 frags[i] = NULL; 127 frags[i] = NULL;
128 acks++;
75 return; 129 return;
76 } 130 }
77 if (ret == GNUNET_NO) 131 if (ret == GNUNET_NO)
78 return; 132 {
133#if DETAILS
134 fprintf (stderr, "@"); /* good ACK */
135#endif
136 acks++;
137 return;
138 }
79 } 139 }
80 fprintf (stderr, "Got ACK that nobody feels responsible for...\n"); 140#if DETAILS
141 fprintf (stderr, "_"); /* BAD: ack that nobody feels responsible for... */
142#endif
81} 143}
82 144
83 145
@@ -88,10 +150,33 @@ static void
88proc_frac (void *cls, 150proc_frac (void *cls,
89 const struct GNUNET_MessageHeader *hdr) 151 const struct GNUNET_MessageHeader *hdr)
90{ 152{
91 fprintf (stderr, "."); 153 int ret;
154
155 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE))
156 {
157 frag_drops++;
158 return; /* random drop */
159 }
92 if (NULL == defrag) 160 if (NULL == defrag)
93 return; 161 {
94 GNUNET_DEFRAGMENT_process_fragment (defrag, hdr); 162 fprintf (stderr, "E"); /* Error: frag after shutdown!? */
163 return;
164 }
165 ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr);
166 if (ret == GNUNET_NO)
167 {
168#if DETAILS
169 fprintf (stderr, "?"); /* duplicate fragment */
170#endif
171 dups++;
172 }
173 else if (ret == GNUNET_OK)
174 {
175#if DETAILS
176 fprintf (stderr, "."); /* good fragment */
177#endif
178 fragc++;
179 }
95} 180}
96 181
97 182
@@ -119,11 +204,11 @@ run (void *cls,
119 for (i=0;i<NUM_MSGS;i++) 204 for (i=0;i<NUM_MSGS;i++)
120 { 205 {
121 msg->type = htons ((uint16_t) i); 206 msg->type = htons ((uint16_t) i);
122 msg->size = htons (MTU + 1 + i % (32 * 1024)); 207 msg->size = htons (MTU + 1 + (17 * i) % (32 * 1024));
123 frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */, 208 frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */,
124 MTU, 209 MTU,
125 NULL /* no tracker -- infinite BW */, 210 &trackers[i],
126 GNUNET_TIME_UNIT_MILLISECONDS, 211 GNUNET_TIME_UNIT_SECONDS,
127 msg, 212 msg,
128 &proc_frac, 213 &proc_frac,
129 NULL); 214 NULL);
@@ -149,6 +234,7 @@ main (int argc, char *argv[])
149#endif 234#endif
150 NULL 235 NULL
151 }; 236 };
237 unsigned int i;
152 238
153 GNUNET_log_setup ("test-fragmentation", 239 GNUNET_log_setup ("test-fragmentation",
154#if VERBOSE 240#if VERBOSE
@@ -157,6 +243,16 @@ main (int argc, char *argv[])
157 "WARNING", 243 "WARNING",
158#endif 244#endif
159 NULL); 245 NULL);
246 for (i=0;i<NUM_MSGS;i++)
247 GNUNET_BANDWIDTH_tracker_init (&trackers[i],
248 GNUNET_BANDWIDTH_value_init ((i+1) * 1024),
249 100);
160 GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options, &run, NULL); 250 GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options, &run, NULL);
251 fprintf (stderr,
252 "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n",
253 fragc,
254 dups,
255 acks,
256 ack_drops);
161 return ret; 257 return ret;
162} 258}