summaryrefslogtreecommitdiff
path: root/src/ats-tests/gnunet-ats-sim.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-01-22 16:22:53 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-01-22 16:22:53 +0000
commit0c7aa062cb988866f9d859a7c67836707cf1041c (patch)
treedde37bec39cf05142a36d0dd40d2fb150c7fd595 /src/ats-tests/gnunet-ats-sim.c
parent3425604d4fa20375309ec016a6f52f5e57578fac (diff)
downloadgnunet-0c7aa062cb988866f9d859a7c67836707cf1041c.tar.gz
gnunet-0c7aa062cb988866f9d859a7c67836707cf1041c.zip
changes to traffic generation
Diffstat (limited to 'src/ats-tests/gnunet-ats-sim.c')
-rw-r--r--src/ats-tests/gnunet-ats-sim.c107
1 files changed, 88 insertions, 19 deletions
diff --git a/src/ats-tests/gnunet-ats-sim.c b/src/ats-tests/gnunet-ats-sim.c
index b394cb8a4..993a8a0e4 100644
--- a/src/ats-tests/gnunet-ats-sim.c
+++ b/src/ats-tests/gnunet-ats-sim.c
@@ -35,8 +35,13 @@
35#define DEFAULT_NUM_SLAVES 5 35#define DEFAULT_NUM_SLAVES 5
36#define DEFAULT_NUM_MASTERS 1 36#define DEFAULT_NUM_MASTERS 1
37 37
38#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
39
38#define TEST_MESSAGE_TYPE_PING 12345 40#define TEST_MESSAGE_TYPE_PING 12345
39#define TEST_MESSAGE_TYPE_PONG 12346 41#define TEST_MESSAGE_TYPE_PONG 1234
42
43static struct BenchmarkPeer *masters_p;
44static struct BenchmarkPeer *slaves_p;
40 45
41/** 46/**
42 * Number of master peers to use 47 * Number of master peers to use
@@ -48,18 +53,74 @@ static int c_masters;
48 */ 53 */
49static int c_slaves; 54static int c_slaves;
50 55
51static int 56static void
52core_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other, 57evaluate ()
53 const struct GNUNET_MessageHeader *message)
54{ 58{
55 return 0; 59 int c_m;
60 int c_s;
61 unsigned int duration;
62 struct BenchmarkPeer *mp;
63 struct BenchmarkPartner *p;
64
65 unsigned int kb_sent_sec;
66 double kb_sent_percent;
67 unsigned int kb_recv_sec;
68 double kb_recv_percent;
69 unsigned int rtt;
70
71 duration = (TEST_TIMEOUT.rel_value_us / (1000 * 1000));
72 for (c_m = 0; c_m < c_masters; c_m++)
73 {
74 mp = &masters_p[c_m];
75 fprintf (stderr,
76 _("Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"),
77 mp->no, mp->total_bytes_sent / 1024, duration,
78 (mp->total_bytes_sent / 1024) / duration,
79 mp->total_bytes_received / 1024, duration,
80 (mp->total_bytes_received / 1024) / duration);
81
82 for (c_s = 0; c_s < c_slaves; c_s++)
83 {
84 p = &mp->partners[c_s];
85
86 kb_sent_sec = 0;
87 kb_recv_sec = 0;
88 kb_sent_percent = 0.0;
89 kb_recv_percent = 0.0;
90 rtt = 0;
91
92 if (duration > 0)
93 {
94 kb_sent_sec = (p->bytes_sent / 1024) / duration;
95 kb_recv_sec = (p->bytes_received / 1024) / duration;
96 }
97
98 if (mp->total_bytes_sent > 0)
99 kb_sent_percent = ((double) p->bytes_sent * 100) / mp->total_bytes_sent;
100 if (mp->total_bytes_received > 0)
101 kb_recv_percent = ((double) p->bytes_received * 100) / mp->total_bytes_received;
102 if (1000 * p->messages_sent > 0)
103 rtt = p->total_app_rtt / (1000 * p->messages_sent);
104 fprintf (stderr,
105 "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n",
106 (mp->pref_partner == p->dest) ? '*' : ' ',
107 mp->no, p->dest->no,
108 kb_sent_sec, kb_sent_percent,
109 kb_recv_sec, kb_recv_percent);
110 fprintf (stderr,
111 "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n",
112 (mp->pref_partner == p->dest) ? '*' : ' ',
113 mp->no, p->dest->no, rtt);
114 }
115 }
56} 116}
57 117
58static int 118static void
59core_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other, 119do_shutdown ()
60 const struct GNUNET_MessageHeader *message)
61{ 120{
62 return 0; 121 /* Shutdown a topology with */
122 evaluate ();
123 GNUNET_ATS_TEST_shutdown_topology ();
63} 124}
64 125
65static void 126static void
@@ -83,21 +144,30 @@ static void topology_setup_done (void *cls,
83 struct BenchmarkPeer *masters, 144 struct BenchmarkPeer *masters,
84 struct BenchmarkPeer *slaves) 145 struct BenchmarkPeer *slaves)
85{ 146{
147 int c_m;
148 int c_s;
86 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Topology setup complete!\n"); 149 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Topology setup complete!\n");
87 150
88 151 masters_p = masters;
89 /* Shutdown a topology with */ 152 slaves_p = slaves;
90 GNUNET_ATS_TEST_shutdown_topology (); 153
154 for (c_m = 0; c_m < c_masters; c_m++)
155 {
156 for (c_s = 0; c_s < c_slaves; c_s++)
157 {
158 /* Generate maximum traffic to all peers */
159 GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
160 &masters[c_m].partners[c_s], 10000,
161 GNUNET_TIME_UNIT_FOREVER_REL);
162 }
163 }
164 GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &do_shutdown, NULL);
91} 165}
92 166
167
93int 168int
94main (int argc, char *argv[]) 169main (int argc, char *argv[])
95{ 170{
96 static struct GNUNET_CORE_MessageHandler handlers[] = {
97 {&core_handle_ping, TEST_MESSAGE_TYPE_PING, 0 },
98 {&core_handle_pong, TEST_MESSAGE_TYPE_PONG, 0 },
99 { NULL, 0, 0 } };
100
101 c_slaves = DEFAULT_NUM_SLAVES; 171 c_slaves = DEFAULT_NUM_SLAVES;
102 c_masters = DEFAULT_NUM_MASTERS; 172 c_masters = DEFAULT_NUM_MASTERS;
103 173
@@ -105,10 +175,9 @@ main (int argc, char *argv[])
105 GNUNET_ATS_TEST_create_topology ("gnunet-ats-sim", "perf_ats_proportional_none.conf", 175 GNUNET_ATS_TEST_create_topology ("gnunet-ats-sim", "perf_ats_proportional_none.conf",
106 c_slaves, 176 c_slaves,
107 c_masters, 177 c_masters,
108 GNUNET_YES, 178 GNUNET_NO,
109 &topology_setup_done, 179 &topology_setup_done,
110 NULL, 180 NULL,
111 handlers,
112 &transport_recv_cb, 181 &transport_recv_cb,
113 &ats_performance_info_cb); 182 &ats_performance_info_cb);
114 return 0; 183 return 0;