summaryrefslogtreecommitdiff
path: root/src/transport/test_quota_compliance.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_quota_compliance.c')
-rw-r--r--src/transport/test_quota_compliance.c316
1 files changed, 158 insertions, 158 deletions
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c
index 092935944..c3c46db37 100644
--- a/src/transport/test_quota_compliance.c
+++ b/src/transport/test_quota_compliance.c
@@ -32,9 +32,9 @@
32/** 32/**
33 * Testcase timeout 33 * Testcase timeout
34 */ 34 */
35#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 480) 35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 480)
36 36
37#define DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 80) 37#define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 80)
38 38
39 39
40static struct GNUNET_SCHEDULER_Task *measure_task; 40static struct GNUNET_SCHEDULER_Task *measure_task;
@@ -61,61 +61,61 @@ static struct GNUNET_TIME_Absolute start_time;
61 61
62 62
63static void 63static void
64report() 64report ()
65{ 65{
66 unsigned long long delta; 66 unsigned long long delta;
67 unsigned long long datarate; 67 unsigned long long datarate;
68 68
69 delta = GNUNET_TIME_absolute_get_duration(start_time).rel_value_us; 69 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;
70 if (0 == delta) 70 if (0 == delta)
71 delta = 1; 71 delta = 1;
72 datarate = (total_bytes_recv * 1000 * 1000) / delta; 72 datarate = (total_bytes_recv * 1000 * 1000) / delta;
73 73
74 fprintf(stderr, 74 fprintf (stderr,
75 "Throughput was %llu b/s\n", 75 "Throughput was %llu b/s\n",
76 datarate); 76 datarate);
77 ccc->global_ret = GNUNET_OK; 77 ccc->global_ret = GNUNET_OK;
78 if (datarate > 1.5 * quota_in[1]) 78 if (datarate > 1.5 * quota_in[1])
79 { 79 {
80 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 80 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
81 "Datarate of %llu b/s significantly higher than allowed inbound quota of %llu b/s\n", 81 "Datarate of %llu b/s significantly higher than allowed inbound quota of %llu b/s\n",
82 datarate, 82 datarate,
83 quota_in[1]); 83 quota_in[1]);
84 ccc->global_ret = GNUNET_SYSERR; 84 ccc->global_ret = GNUNET_SYSERR;
85 } 85 }
86 if (datarate > 1.5 * quota_out[0]) 86 if (datarate > 1.5 * quota_out[0])
87 { 87 {
88 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 88 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
89 "Datarate of %llu b/s significantly higher than allowed outbound quota of %llu b/s\n", 89 "Datarate of %llu b/s significantly higher than allowed outbound quota of %llu b/s\n",
90 datarate, 90 datarate,
91 quota_out[0]); 91 quota_out[0]);
92 ccc->global_ret = GNUNET_SYSERR; 92 ccc->global_ret = GNUNET_SYSERR;
93 } 93 }
94 if (GNUNET_OK == ccc->global_ret) 94 if (GNUNET_OK == ccc->global_ret)
95 { 95 {
96 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 96 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
97 "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n", 97 "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n",
98 datarate, 98 datarate,
99 quota_out[0], 99 quota_out[0],
100 quota_in[1]); 100 quota_in[1]);
101 } 101 }
102} 102}
103 103
104 104
105static void 105static void
106custom_shutdown(void *cls) 106custom_shutdown (void *cls)
107{ 107{
108 if (NULL != measure_task) 108 if (NULL != measure_task)
109 { 109 {
110 GNUNET_SCHEDULER_cancel(measure_task); 110 GNUNET_SCHEDULER_cancel (measure_task);
111 measure_task = NULL; 111 measure_task = NULL;
112 } 112 }
113 report(); 113 report ();
114} 114}
115 115
116 116
117static size_t 117static size_t
118get_size(unsigned int iter) 118get_size (unsigned int iter)
119{ 119{
120 size_t ret; 120 size_t ret;
121 121
@@ -126,52 +126,52 @@ get_size(unsigned int iter)
126 126
127 127
128static void 128static void
129notify_receive(void *cls, 129notify_receive (void *cls,
130 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 130 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
131 const struct GNUNET_PeerIdentity *sender, 131 const struct GNUNET_PeerIdentity *sender,
132 const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) 132 const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr)
133{ 133{
134 if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(hdr->header.type)) 134 if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type))
135 return; 135 return;
136 total_bytes_recv += ntohs(hdr->header.size); 136 total_bytes_recv += ntohs (hdr->header.size);
137 137
138 { 138 {
139 char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id)); 139 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id));
140 140
141 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 141 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
142 "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", 142 "Peer %u (`%s') got message %u of size %u from peer (`%s')\n",
143 receiver->no, 143 receiver->no,
144 ps, 144 ps,
145 ntohl(hdr->num), 145 ntohl (hdr->num),
146 ntohs(hdr->header.size), 146 ntohs (hdr->header.size),
147 GNUNET_i2s(sender)); 147 GNUNET_i2s (sender));
148 GNUNET_free(ps); 148 GNUNET_free (ps);
149 } 149 }
150} 150}
151 151
152 152
153static void 153static void
154measure(void *cls) 154measure (void *cls)
155{ 155{
156 static int counter; 156 static int counter;
157 157
158 measure_task = NULL; 158 measure_task = NULL;
159 counter++; 159 counter++;
160 if ((DURATION.rel_value_us / 1000 / 1000LL) < counter) 160 if ((DURATION.rel_value_us / 1000 / 1000LL) < counter)
161 { 161 {
162 fprintf(stderr, "%s", ".\n"); 162 fprintf (stderr, "%s", ".\n");
163 GNUNET_SCHEDULER_shutdown(); 163 GNUNET_SCHEDULER_shutdown ();
164 return; 164 return;
165 } 165 }
166 fprintf(stderr, "%s", "."); 166 fprintf (stderr, "%s", ".");
167 measure_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 167 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
168 &measure, 168 &measure,
169 NULL); 169 NULL);
170} 170}
171 171
172 172
173static void 173static void
174start_task(void *cls) 174start_task (void *cls)
175{ 175{
176 static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 176 static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
177 .num_messages = TOTAL_MSGS, 177 .num_messages = TOTAL_MSGS,
@@ -179,71 +179,71 @@ start_task(void *cls)
179 }; 179 };
180 180
181 sc.ccc = ccc; 181 sc.ccc = ccc;
182 measure_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 182 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
183 &measure, 183 &measure,
184 NULL); 184 NULL);
185 start_time = GNUNET_TIME_absolute_get(); 185 start_time = GNUNET_TIME_absolute_get ();
186 GNUNET_SCHEDULER_add_now(&GNUNET_TRANSPORT_TESTING_simple_send, 186 GNUNET_SCHEDULER_add_now (&GNUNET_TRANSPORT_TESTING_simple_send,
187 &sc); 187 &sc);
188} 188}
189 189
190 190
191static char * 191static char *
192generate_config(const char *cfg_file, 192generate_config (const char *cfg_file,
193 unsigned long long quota_in, 193 unsigned long long quota_in,
194 unsigned long long quota_out) 194 unsigned long long quota_out)
195{ 195{
196 char *in_name; 196 char *in_name;
197 char *out_name; 197 char *out_name;
198 char *fname = NULL; 198 char *fname = NULL;
199 struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create(); 199 struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create ();
200 200
201 GNUNET_assert(GNUNET_OK == 201 GNUNET_assert (GNUNET_OK ==
202 GNUNET_CONFIGURATION_load(cfg, 202 GNUNET_CONFIGURATION_load (cfg,
203 cfg_file)); 203 cfg_file));
204 GNUNET_asprintf(&fname, 204 GNUNET_asprintf (&fname,
205 "q_in_%llu_q_out_%llu_%s", 205 "q_in_%llu_q_out_%llu_%s",
206 quota_in, 206 quota_in,
207 quota_out, 207 quota_out,
208 cfg_file); 208 cfg_file);
209 GNUNET_CONFIGURATION_set_value_string(cfg, 209 GNUNET_CONFIGURATION_set_value_string (cfg,
210 "PATHS", 210 "PATHS",
211 "DEFAULTCONFIG", 211 "DEFAULTCONFIG",
212 fname); 212 fname);
213 for (int c = 0; c < GNUNET_NT_COUNT; c++) 213 for (int c = 0; c < GNUNET_NT_COUNT; c++)
214 { 214 {
215 GNUNET_asprintf(&in_name, 215 GNUNET_asprintf (&in_name,
216 "%s_QUOTA_IN", 216 "%s_QUOTA_IN",
217 GNUNET_NT_to_string(c)); 217 GNUNET_NT_to_string (c));
218 GNUNET_asprintf(&out_name, 218 GNUNET_asprintf (&out_name,
219 "%s_QUOTA_OUT", 219 "%s_QUOTA_OUT",
220 GNUNET_NT_to_string(c)); 220 GNUNET_NT_to_string (c));
221 GNUNET_CONFIGURATION_set_value_number(cfg, 221 GNUNET_CONFIGURATION_set_value_number (cfg,
222 "ats", 222 "ats",
223 in_name, 223 in_name,
224 quota_in); 224 quota_in);
225 GNUNET_CONFIGURATION_set_value_number(cfg, 225 GNUNET_CONFIGURATION_set_value_number (cfg,
226 "ats", 226 "ats",
227 out_name, 227 out_name,
228 quota_out); 228 quota_out);
229 GNUNET_free(in_name); 229 GNUNET_free (in_name);
230 GNUNET_free(out_name); 230 GNUNET_free (out_name);
231 } 231 }
232 GNUNET_assert(GNUNET_OK == 232 GNUNET_assert (GNUNET_OK ==
233 GNUNET_CONFIGURATION_write(cfg, 233 GNUNET_CONFIGURATION_write (cfg,
234 fname)); 234 fname));
235 GNUNET_CONFIGURATION_destroy(cfg); 235 GNUNET_CONFIGURATION_destroy (cfg);
236 return fname; 236 return fname;
237} 237}
238 238
239 239
240static int 240static int
241check(void *cls, 241check (void *cls,
242 struct GNUNET_TRANSPORT_TESTING_Handle *tth_, 242 struct GNUNET_TRANSPORT_TESTING_Handle *tth_,
243 const char *test_plugin_, 243 const char *test_plugin_,
244 const char *test_name_, 244 const char *test_name_,
245 unsigned int num_peers, 245 unsigned int num_peers,
246 char *cfg_files[]) 246 char *cfg_files[])
247{ 247{
248 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 248 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
249 .connect_continuation = &start_task, 249 .connect_continuation = &start_task,
@@ -257,63 +257,63 @@ check(void *cls,
257 257
258 ccc = &my_ccc; 258 ccc = &my_ccc;
259 259
260 if (NULL != strstr(test_name_, 260 if (NULL != strstr (test_name_,
261 "asymmetric")) 261 "asymmetric"))
262 { 262 {
263 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
264 "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n", 264 "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n",
265 quota_in[1], 265 quota_in[1],
266 quota_out[1]); 266 quota_out[1]);
267 quota_out[0] = 1024 * 1024 * 1024; 267 quota_out[0] = 1024 * 1024 * 1024;
268 quota_in[0] = 1024 * 1024 * 1024; 268 quota_in[0] = 1024 * 1024 * 1024;
269 } 269 }
270 else 270 else
271 { 271 {
272 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
273 "Running symmetric test with (in/out) %llu/%llu b/s \n", 273 "Running symmetric test with (in/out) %llu/%llu b/s \n",
274 quota_in[1], 274 quota_in[1],
275 quota_out[1]); 275 quota_out[1]);
276 } 276 }
277 for (unsigned int i = 0; i < 2; i++) 277 for (unsigned int i = 0; i < 2; i++)
278 { 278 {
279 gen_cfgs[i] = generate_config(cfg_files[i], 279 gen_cfgs[i] = generate_config (cfg_files[i],
280 quota_in[i], 280 quota_in[i],
281 quota_out[i]); 281 quota_out[i]);
282 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
283 "Generated config file `%s'\n", 283 "Generated config file `%s'\n",
284 gen_cfgs[i]); 284 gen_cfgs[i]);
285 } 285 }
286 286
287 return GNUNET_TRANSPORT_TESTING_connect_check(&my_ccc, 287 return GNUNET_TRANSPORT_TESTING_connect_check (&my_ccc,
288 tth_, 288 tth_,
289 test_plugin_, 289 test_plugin_,
290 test_name_, 290 test_name_,
291 num_peers, 291 num_peers,
292 gen_cfgs); 292 gen_cfgs);
293} 293}
294 294
295 295
296int 296int
297main(int argc, 297main (int argc,
298 char *argv[]) 298 char *argv[])
299{ 299{
300 if (GNUNET_OK != 300 if (GNUNET_OK !=
301 GNUNET_TRANSPORT_TESTING_main(2, 301 GNUNET_TRANSPORT_TESTING_main (2,
302 &check, 302 &check,
303 NULL)) 303 NULL))
304 { 304 {
305 GNUNET_break(0); 305 GNUNET_break (0);
306 return 1; 306 return 1;
307 } 307 }
308 for (unsigned int i = 0; i < 2; i++) 308 for (unsigned int i = 0; i < 2; i++)
309 {
310 if ((NULL != gen_cfgs[i]) &&
311 (GNUNET_YES == GNUNET_DISK_file_test (gen_cfgs[i])))
309 { 312 {
310 if ((NULL != gen_cfgs[i]) && 313 GNUNET_DISK_directory_remove (gen_cfgs[i]);
311 (GNUNET_YES == GNUNET_DISK_file_test(gen_cfgs[i]))) 314 GNUNET_free (gen_cfgs[i]);
312 {
313 GNUNET_DISK_directory_remove(gen_cfgs[i]);
314 GNUNET_free(gen_cfgs[i]);
315 }
316 } 315 }
316 }
317 return 0; 317 return 0;
318} 318}
319 319