summaryrefslogtreecommitdiff
path: root/src/ats-tests/gnunet-ats-sim.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats-tests/gnunet-ats-sim.c')
-rw-r--r--src/ats-tests/gnunet-ats-sim.c386
1 files changed, 195 insertions, 191 deletions
diff --git a/src/ats-tests/gnunet-ats-sim.c b/src/ats-tests/gnunet-ats-sim.c
index d6168d388..c9e7a6d9f 100644
--- a/src/ats-tests/gnunet-ats-sim.c
+++ b/src/ats-tests/gnunet-ats-sim.c
@@ -32,7 +32,8 @@
32#include "gnunet_core_service.h" 32#include "gnunet_core_service.h"
33#include "ats-testing.h" 33#include "ats-testing.h"
34 34
35#define TEST_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) 35#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
36 10)
36 37
37static struct BenchmarkPeer *masters_p; 38static struct BenchmarkPeer *masters_p;
38static struct BenchmarkPeer *slaves_p; 39static struct BenchmarkPeer *slaves_p;
@@ -65,7 +66,7 @@ static struct LoggingHandle *l;
65 66
66 67
67static void 68static void
68evaluate(struct GNUNET_TIME_Relative duration_total) 69evaluate (struct GNUNET_TIME_Relative duration_total)
69{ 70{
70 int c_m; 71 int c_m;
71 int c_s; 72 int c_s;
@@ -84,166 +85,168 @@ evaluate(struct GNUNET_TIME_Relative duration_total)
84 if (0 == duration) 85 if (0 == duration)
85 duration = 1; 86 duration = 1;
86 for (c_m = 0; c_m < e->num_masters; c_m++) 87 for (c_m = 0; c_m < e->num_masters; c_m++)
88 {
89 mp = &masters_p[c_m];
90 fprintf (stderr,
91 _ (
92 "Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"),
93 mp->no, mp->total_bytes_sent / 1024,
94 duration,
95 (mp->total_bytes_sent / 1024) / duration,
96 mp->total_bytes_received / 1024,
97 duration,
98 (mp->total_bytes_received / 1024) / duration);
99
100 for (c_s = 0; c_s < e->num_slaves; c_s++)
87 { 101 {
88 mp = &masters_p[c_m]; 102 p = &mp->partners[c_s];
89 fprintf(stderr, 103
90 _("Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"), 104 b_sent_sec = 0;
91 mp->no, mp->total_bytes_sent / 1024, 105 b_recv_sec = 0;
92 duration, 106 kb_sent_percent = 0.0;
93 (mp->total_bytes_sent / 1024) / duration, 107 kb_recv_percent = 0.0;
94 mp->total_bytes_received / 1024, 108 rtt = 0;
95 duration, 109
96 (mp->total_bytes_received / 1024) / duration); 110 if (duration > 0)
97 111 {
98 for (c_s = 0; c_s < e->num_slaves; c_s++) 112 b_sent_sec = p->bytes_sent / duration;
99 { 113 b_recv_sec = p->bytes_received / duration;
100 p = &mp->partners[c_s]; 114 }
101 115
102 b_sent_sec = 0; 116 if (mp->total_bytes_sent > 0)
103 b_recv_sec = 0; 117 kb_sent_percent = ((double) p->bytes_sent * 100) / mp->total_bytes_sent;
104 kb_sent_percent = 0.0; 118 if (mp->total_bytes_received > 0)
105 kb_recv_percent = 0.0; 119 kb_recv_percent = ((double) p->bytes_received * 100)
106 rtt = 0; 120 / mp->total_bytes_received;
107 121 if (1000 * p->messages_sent > 0)
108 if (duration > 0) 122 rtt = p->total_app_rtt / (1000 * p->messages_sent);
109 { 123 fprintf (stderr,
110 b_sent_sec = p->bytes_sent / duration; 124 "%c Master [%u] -> Slave [%u]: sent %u Bips (%.2f %%), received %u Bips (%.2f %%)\n",
111 b_recv_sec = p->bytes_received / duration; 125 (mp->pref_partner == p->dest) ? '*' : ' ',
112 } 126 mp->no, p->dest->no,
113 127 b_sent_sec, kb_sent_percent,
114 if (mp->total_bytes_sent > 0) 128 b_recv_sec, kb_recv_percent);
115 kb_sent_percent = ((double)p->bytes_sent * 100) / mp->total_bytes_sent; 129 fprintf (stderr,
116 if (mp->total_bytes_received > 0) 130 "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
117 kb_recv_percent = ((double)p->bytes_received * 100) / mp->total_bytes_received; 131 (mp->pref_partner == p->dest) ? '*' : ' ',
118 if (1000 * p->messages_sent > 0) 132 mp->no, p->dest->no, rtt);
119 rtt = p->total_app_rtt / (1000 * p->messages_sent);
120 fprintf(stderr,
121 "%c Master [%u] -> Slave [%u]: sent %u Bips (%.2f %%), received %u Bips (%.2f %%)\n",
122 (mp->pref_partner == p->dest) ? '*' : ' ',
123 mp->no, p->dest->no,
124 b_sent_sec, kb_sent_percent,
125 b_recv_sec, kb_recv_percent);
126 fprintf(stderr,
127 "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
128 (mp->pref_partner == p->dest) ? '*' : ' ',
129 mp->no, p->dest->no, rtt);
130 }
131 } 133 }
134 }
132} 135}
133 136
134 137
135static void 138static void
136do_shutdown(void *cls) 139do_shutdown (void *cls)
137{ 140{
138 fprintf(stderr, "Shutdown\n"); 141 fprintf (stderr, "Shutdown\n");
139 if (NULL != timeout_task) 142 if (NULL != timeout_task)
140 { 143 {
141 GNUNET_SCHEDULER_cancel(timeout_task); 144 GNUNET_SCHEDULER_cancel (timeout_task);
142 timeout_task = NULL; 145 timeout_task = NULL;
143 } 146 }
144 if (NULL != l) 147 if (NULL != l)
145 { 148 {
146 GNUNET_ATS_TEST_logging_stop(l); 149 GNUNET_ATS_TEST_logging_stop (l);
147 GNUNET_ATS_TEST_logging_clean_up(l); 150 GNUNET_ATS_TEST_logging_clean_up (l);
148 l = NULL; 151 l = NULL;
149 } 152 }
150 153
151 /* Stop traffic generation */ 154 /* Stop traffic generation */
152 GNUNET_ATS_TEST_generate_traffic_stop_all(); 155 GNUNET_ATS_TEST_generate_traffic_stop_all ();
153 156
154 /* Stop all preference generations */ 157 /* Stop all preference generations */
155 GNUNET_ATS_TEST_generate_preferences_stop_all(); 158 GNUNET_ATS_TEST_generate_preferences_stop_all ();
156 159
157 if (NULL != e) 160 if (NULL != e)
158 { 161 {
159 GNUNET_ATS_TEST_experimentation_stop(e); 162 GNUNET_ATS_TEST_experimentation_stop (e);
160 e = NULL; 163 e = NULL;
161 } 164 }
162 GNUNET_ATS_TEST_shutdown_topology(); 165 GNUNET_ATS_TEST_shutdown_topology ();
163} 166}
164 167
165 168
166static void 169static void
167do_timeout(void *cls) 170do_timeout (void *cls)
168{ 171{
169 timeout_task = NULL; 172 timeout_task = NULL;
170 GNUNET_SCHEDULER_shutdown(); 173 GNUNET_SCHEDULER_shutdown ();
171} 174}
172 175
173 176
174static void 177static void
175log_request__cb(void *cls, 178log_request__cb (void *cls,
176 const struct GNUNET_HELLO_Address *address, 179 const struct GNUNET_HELLO_Address *address,
177 int address_active, 180 int address_active,
178 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 181 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
179 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 182 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
180 const struct GNUNET_ATS_Properties *ats) 183 const struct GNUNET_ATS_Properties *ats)
181{ 184{
182 if (NULL != l) 185 if (NULL != l)
183 { 186 {
184 //GNUNET_break (0); 187 // GNUNET_break (0);
185 //GNUNET_ATS_TEST_logging_now (l); 188 // GNUNET_ATS_TEST_logging_now (l);
186 } 189 }
187} 190}
188 191
189 192
190static void 193static void
191experiment_done_cb(struct Experiment *e, 194experiment_done_cb (struct Experiment *e,
192 struct GNUNET_TIME_Relative duration, 195 struct GNUNET_TIME_Relative duration,
193 int success) 196 int success)
194{ 197{
195 if (GNUNET_OK == success) 198 if (GNUNET_OK == success)
196 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 199 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
197 "Experiment done successful in %s\n", 200 "Experiment done successful in %s\n",
198 GNUNET_STRINGS_relative_time_to_string(duration, 201 GNUNET_STRINGS_relative_time_to_string (duration,
199 GNUNET_YES)); 202 GNUNET_YES));
200 else 203 else
201 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment failed \n"); 204 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
202 205
203 /* Stop logging */ 206 /* Stop logging */
204 GNUNET_ATS_TEST_logging_stop(l); 207 GNUNET_ATS_TEST_logging_stop (l);
205 208
206 /* Stop traffic generation */ 209 /* Stop traffic generation */
207 GNUNET_ATS_TEST_generate_traffic_stop_all(); 210 GNUNET_ATS_TEST_generate_traffic_stop_all ();
208 211
209 /* Stop all preference generations */ 212 /* Stop all preference generations */
210 GNUNET_ATS_TEST_generate_preferences_stop_all(); 213 GNUNET_ATS_TEST_generate_preferences_stop_all ();
211 214
212 evaluate(duration); 215 evaluate (duration);
213 if (opt_log) 216 if (opt_log)
214 GNUNET_ATS_TEST_logging_write_to_file(l, opt_exp_file, opt_plot); 217 GNUNET_ATS_TEST_logging_write_to_file (l, opt_exp_file, opt_plot);
215 GNUNET_SCHEDULER_shutdown(); 218 GNUNET_SCHEDULER_shutdown ();
216} 219}
217 220
218 221
219static void 222static void
220episode_done_cb(struct Episode *ep) 223episode_done_cb (struct Episode *ep)
221{ 224{
222 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 225 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
223 "Episode %u done\n", 226 "Episode %u done\n",
224 ep->id); 227 ep->id);
225} 228}
226 229
227 230
228static void 231static void
229topology_setup_done(void *cls, 232topology_setup_done (void *cls,
230 struct BenchmarkPeer *masters, 233 struct BenchmarkPeer *masters,
231 struct BenchmarkPeer *slaves) 234 struct BenchmarkPeer *slaves)
232{ 235{
233 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 236 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
234 "Topology setup complete!\n"); 237 "Topology setup complete!\n");
235 238
236 masters_p = masters; 239 masters_p = masters;
237 slaves_p = slaves; 240 slaves_p = slaves;
238 241
239 l = GNUNET_ATS_TEST_logging_start(e->log_freq, 242 l = GNUNET_ATS_TEST_logging_start (e->log_freq,
240 e->name, 243 e->name,
241 masters_p, 244 masters_p,
242 e->num_masters, e->num_slaves, 245 e->num_masters, e->num_slaves,
243 opt_verbose); 246 opt_verbose);
244 GNUNET_ATS_TEST_experimentation_run(e, 247 GNUNET_ATS_TEST_experimentation_run (e,
245 &episode_done_cb, 248 &episode_done_cb,
246 &experiment_done_cb); 249 &experiment_done_cb);
247/* 250/*
248 GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0], 251 GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
249 GNUNET_ATS_TEST_TG_CONSTANT, 1, 1, GNUNET_TIME_UNIT_SECONDS, 252 GNUNET_ATS_TEST_TG_CONSTANT, 1, 1, GNUNET_TIME_UNIT_SECONDS,
@@ -275,58 +278,59 @@ topology_setup_done(void *cls,
275 int c_m; 278 int c_m;
276 int c_s; 279 int c_s;
277 for (c_m = 0; c_m < e->num_masters; c_m++) 280 for (c_m = 0; c_m < e->num_masters; c_m++)
281 {
282 for (c_s = 0; c_s < e->num_slaves; c_s++)
278 { 283 {
279 for (c_s = 0; c_s < e->num_slaves; c_s++) 284 /* Generate maximum traffic to all peers */
280 { 285 /* Example: Generate traffic with constant 10,000 Bytes/s */
281 /* Generate maximum traffic to all peers */ 286 GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
282 /* Example: Generate traffic with constant 10,000 Bytes/s */ 287 &masters[c_m].partners[c_s],
283 GNUNET_ATS_TEST_generate_traffic_start(&masters[c_m], 288 GNUNET_ATS_TEST_TG_CONSTANT,
284 &masters[c_m].partners[c_s], 289 10000,
285 GNUNET_ATS_TEST_TG_CONSTANT, 290 GNUNET_TIME_UNIT_FOREVER_REL);
286 10000, 291 /* Example: Generate traffic with an increasing rate from 1000 to 2000
287 GNUNET_TIME_UNIT_FOREVER_REL); 292 * Bytes/s with in a minute */
288 /* Example: Generate traffic with an increasing rate from 1000 to 2000 293 GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
289 * Bytes/s with in a minute */ 294 &masters[c_m].partners[c_s],
290 GNUNET_ATS_TEST_generate_traffic_start(&masters[c_m], 295 GNUNET_ATS_TEST_TG_LINEAR,
291 &masters[c_m].partners[c_s], 296 1000,
292 GNUNET_ATS_TEST_TG_LINEAR, 297 2000,
293 1000, 298 GNUNET_TIME_UNIT_MINUTES,
294 2000, 299 GNUNET_TIME_UNIT_FOREVER_REL);
295 GNUNET_TIME_UNIT_MINUTES, 300 /* Example: Generate traffic with a random rate between 1000 to 2000
296 GNUNET_TIME_UNIT_FOREVER_REL); 301 * Bytes/s */
297 /* Example: Generate traffic with a random rate between 1000 to 2000 302 GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
298 * Bytes/s */ 303 &masters[c_m].partners[c_s],
299 GNUNET_ATS_TEST_generate_traffic_start(&masters[c_m], 304 GNUNET_ATS_TEST_TG_RANDOM,
300 &masters[c_m].partners[c_s], 305 1000,
301 GNUNET_ATS_TEST_TG_RANDOM, 306 2000,
302 1000, 307 GNUNET_TIME_UNIT_FOREVER_REL,
303 2000, 308 GNUNET_TIME_UNIT_FOREVER_REL);
304 GNUNET_TIME_UNIT_FOREVER_REL, 309 /* Example: Generate traffic with a sinus form, a base rate of
305 GNUNET_TIME_UNIT_FOREVER_REL); 310 * 1000 Bytes/s, an amplitude of (max-base), and a period of 1 minute */
306 /* Example: Generate traffic with a sinus form, a base rate of 311 GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
307 * 1000 Bytes/s, an amplitude of (max-base), and a period of 1 minute */ 312 &masters[c_m].partners[c_s],
308 GNUNET_ATS_TEST_generate_traffic_start(&masters[c_m], 313 GNUNET_ATS_TEST_TG_SINUS,
309 &masters[c_m].partners[c_s], 314 1000,
310 GNUNET_ATS_TEST_TG_SINUS, 315 2000,
311 1000, 316 GNUNET_TIME_UNIT_MINUTES,
312 2000, 317 GNUNET_TIME_UNIT_FOREVER_REL);
313 GNUNET_TIME_UNIT_MINUTES,
314 GNUNET_TIME_UNIT_FOREVER_REL);
315 }
316 } 318 }
319 }
317#endif 320#endif
318 321
319 timeout_task 322 timeout_task
320 = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_add(GNUNET_TIME_UNIT_MINUTES, 323 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add (
321 e->max_duration), 324 GNUNET_TIME_UNIT_MINUTES,
322 &do_timeout, 325 e->max_duration),
323 NULL); 326 &do_timeout,
324 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); 327 NULL);
328 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
325} 329}
326 330
327 331
328static void 332static void
329parse_args(int argc, char *argv[]) 333parse_args (int argc, char *argv[])
330{ 334{
331 int c; 335 int c;
332 336
@@ -335,62 +339,62 @@ parse_args(int argc, char *argv[])
335 opt_plot = GNUNET_NO; 339 opt_plot = GNUNET_NO;
336 340
337 for (c = 0; c < argc; c++) 341 for (c = 0; c < argc; c++)
342 {
343 if ((c < (argc - 1)) && (0 == strcmp (argv[c], "-e")))
344 {
345 GNUNET_free_non_null (opt_exp_file);
346 opt_exp_file = GNUNET_strdup (argv[c + 1]);
347 }
348 if (0 == strcmp (argv[c], "-l"))
338 { 349 {
339 if ((c < (argc - 1)) && (0 == strcmp(argv[c], "-e"))) 350 opt_log = GNUNET_YES;
340 {
341 GNUNET_free_non_null(opt_exp_file);
342 opt_exp_file = GNUNET_strdup(argv[c + 1]);
343 }
344 if (0 == strcmp(argv[c], "-l"))
345 {
346 opt_log = GNUNET_YES;
347 }
348 if (0 == strcmp(argv[c], "-p"))
349 {
350 opt_plot = GNUNET_YES;
351 }
352 if (0 == strcmp(argv[c], "-v"))
353 {
354 opt_verbose = GNUNET_YES;
355 }
356 } 351 }
352 if (0 == strcmp (argv[c], "-p"))
353 {
354 opt_plot = GNUNET_YES;
355 }
356 if (0 == strcmp (argv[c], "-v"))
357 {
358 opt_verbose = GNUNET_YES;
359 }
360 }
357} 361}
358 362
359 363
360int 364int
361main(int argc, char *argv[]) 365main (int argc, char *argv[])
362{ 366{
363 GNUNET_log_setup("gnunet-ats-sim", "INFO", NULL); 367 GNUNET_log_setup ("gnunet-ats-sim", "INFO", NULL);
364 368
365 parse_args(argc, argv); 369 parse_args (argc, argv);
366 if (NULL == opt_exp_file) 370 if (NULL == opt_exp_file)
367 { 371 {
368 fprintf(stderr, "No experiment given...\n"); 372 fprintf (stderr, "No experiment given...\n");
369 return 1; 373 return 1;
370 } 374 }
371 375
372 fprintf(stderr, "Loading experiment `%s' \n", opt_exp_file); 376 fprintf (stderr, "Loading experiment `%s' \n", opt_exp_file);
373 e = GNUNET_ATS_TEST_experimentation_load(opt_exp_file); 377 e = GNUNET_ATS_TEST_experimentation_load (opt_exp_file);
374 if (NULL == e) 378 if (NULL == e)
375 { 379 {
376 fprintf(stderr, "Invalid experiment\n"); 380 fprintf (stderr, "Invalid experiment\n");
377 return 1; 381 return 1;
378 } 382 }
379 if (0 == e->num_episodes) 383 if (0 == e->num_episodes)
380 { 384 {
381 fprintf(stderr, "No episodes included\n"); 385 fprintf (stderr, "No episodes included\n");
382 return 1; 386 return 1;
383 } 387 }
384 388
385 /* Setup a topology with */ 389 /* Setup a topology with */
386 GNUNET_ATS_TEST_create_topology("gnunet-ats-sim", e->cfg_file, 390 GNUNET_ATS_TEST_create_topology ("gnunet-ats-sim", e->cfg_file,
387 e->num_slaves, 391 e->num_slaves,
388 e->num_masters, 392 e->num_masters,
389 GNUNET_NO, 393 GNUNET_NO,
390 &topology_setup_done, 394 &topology_setup_done,
391 NULL, 395 NULL,
392 &log_request__cb); 396 &log_request__cb);
393 GNUNET_free(opt_exp_file); 397 GNUNET_free (opt_exp_file);
394 return 0; 398 return 0;
395} 399}
396/* end of file gnunet-ats-sim.c */ 400/* end of file gnunet-ats-sim.c */