2 This file is part of GNUnet.
3 (C) 2010-2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file ats-tests/gnunet-ats-sim.c
22 * @brief ats traffic simulator: this tool uses the ats-test library to setup a
23 * topology and generate traffic between these peers. The traffic description
24 * is loaded from a experiment description file
25 * @author Christian Grothoff
26 * @author Matthias Wachs
29 #include "gnunet_util_lib.h"
30 #include "gnunet_testbed_service.h"
31 #include "gnunet_ats_service.h"
32 #include "gnunet_core_service.h"
33 #include "ats-testing.h"
35 #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
37 static struct BenchmarkPeer *masters_p;
38 static struct BenchmarkPeer *slaves_p;
40 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
43 struct LoggingHandle *l;
46 evaluate (struct GNUNET_TIME_Relative duration_total)
50 unsigned int duration;
51 struct BenchmarkPeer *mp;
52 struct BenchmarkPartner *p;
54 unsigned int kb_sent_sec;
55 double kb_sent_percent;
56 unsigned int kb_recv_sec;
57 double kb_recv_percent;
61 duration = (duration_total.rel_value_us / (1000 * 1000));
62 for (c_m = 0; c_m < e->num_masters; c_m++)
66 _("Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"),
67 mp->no, mp->total_bytes_sent / 1024, duration,
68 (mp->total_bytes_sent / 1024) / duration,
69 mp->total_bytes_received / 1024, duration,
70 (mp->total_bytes_received / 1024) / duration);
72 for (c_s = 0; c_s < e->num_slaves; c_s++)
74 p = &mp->partners[c_s];
78 kb_sent_percent = 0.0;
79 kb_recv_percent = 0.0;
84 kb_sent_sec = (p->bytes_sent / 1024) / duration;
85 kb_recv_sec = (p->bytes_received / 1024) / duration;
88 if (mp->total_bytes_sent > 0)
89 kb_sent_percent = ((double) p->bytes_sent * 100) / mp->total_bytes_sent;
90 if (mp->total_bytes_received > 0)
91 kb_recv_percent = ((double) p->bytes_received * 100) / mp->total_bytes_received;
92 if (1000 * p->messages_sent > 0)
93 rtt = p->total_app_rtt / (1000 * p->messages_sent);
95 "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n",
96 (mp->pref_partner == p->dest) ? '*' : ' ',
98 kb_sent_sec, kb_sent_percent,
99 kb_recv_sec, kb_recv_percent);
101 "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
102 (mp->pref_partner == p->dest) ? '*' : ' ',
103 mp->no, p->dest->no, rtt);
114 GNUNET_ATS_TEST_experimentation_stop (e);
117 GNUNET_ATS_TEST_shutdown_topology ();
121 transport_recv_cb (void *cls,
122 const struct GNUNET_PeerIdentity * peer,
123 const struct GNUNET_MessageHeader * message)
129 log_request__cb (void *cls, const struct GNUNET_HELLO_Address *address,
130 int address_active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
131 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
132 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
135 GNUNET_ATS_TEST_logging_now (l);
139 experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success)
141 if (GNUNET_OK == success)
142 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n",
143 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
145 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
146 if (GNUNET_SCHEDULER_NO_TASK != timeout_task)
148 GNUNET_SCHEDULER_cancel (timeout_task);
149 timeout_task = GNUNET_SCHEDULER_NO_TASK;
152 GNUNET_ATS_TEST_logging_stop (l);
155 /* Stop traffic generation */
156 GNUNET_ATS_TEST_generate_traffic_stop_all();
157 /* Clean up experiment */
158 GNUNET_ATS_TEST_experimentation_stop (e);
161 /* Shutdown topology */
162 GNUNET_ATS_TEST_shutdown_topology ();
166 episode_done_cb (struct Episode *ep)
168 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
171 static void topology_setup_done (void *cls,
172 struct BenchmarkPeer *masters,
173 struct BenchmarkPeer *slaves)
177 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Topology setup complete!\n");
182 l = GNUNET_ATS_TEST_logging_start (GNUNET_TIME_UNIT_SECONDS, e->name,
183 masters_p, e->num_masters);
184 GNUNET_ATS_TEST_experimentation_run (e, &episode_done_cb, &experiment_done_cb);
186 for (c_m = 0; c_m < e->num_masters; c_m++)
188 for (c_s = 0; c_s < e->num_slaves; c_s++)
190 /* Generate maximum traffic to all peers */
191 GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
192 &masters[c_m].partners[c_s],
194 GNUNET_TIME_UNIT_FOREVER_REL);
198 timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add (GNUNET_TIME_UNIT_MINUTES,
199 e->max_duration), &do_shutdown, NULL);
204 main (int argc, char *argv[])
206 GNUNET_log_setup("gnunet-ats-sim", "INFO", NULL);
209 fprintf (stderr, "No experiment given...\n");
213 fprintf (stderr, "Loading experiment `%s' \n", argv[1]);
214 e = GNUNET_ATS_TEST_experimentation_load (argv[1]);
217 fprintf (stderr, "Invalid experiment\n");
220 if (0 == e->num_episodes)
222 fprintf (stderr, "No episodes included\n");
226 /* Setup a topology with */
227 GNUNET_ATS_TEST_create_topology ("gnunet-ats-sim", e->cfg_file,
231 &topology_setup_done,
237 /* end of file gnunet-ats-sim.c */