summaryrefslogtreecommitdiff
path: root/src/ats-tests/gnunet-ats-sim.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-01-23 14:56:59 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-01-23 14:56:59 +0000
commitee1c5c74a2409a52af706e613bd86a26341abba8 (patch)
treeef18e73357f63737c7560cc3a3ca7fb211bcd468 /src/ats-tests/gnunet-ats-sim.c
parent65b732a465152cf0769651397ff9d2c0980e1727 (diff)
downloadgnunet-ee1c5c74a2409a52af706e613bd86a26341abba8.tar.gz
gnunet-ee1c5c74a2409a52af706e613bd86a26341abba8.zip
new logging functionality
Diffstat (limited to 'src/ats-tests/gnunet-ats-sim.c')
-rw-r--r--src/ats-tests/gnunet-ats-sim.c68
1 files changed, 58 insertions, 10 deletions
diff --git a/src/ats-tests/gnunet-ats-sim.c b/src/ats-tests/gnunet-ats-sim.c
index 8ba68c957..e06ca8887 100644
--- a/src/ats-tests/gnunet-ats-sim.c
+++ b/src/ats-tests/gnunet-ats-sim.c
@@ -37,8 +37,10 @@
37static struct BenchmarkPeer *masters_p; 37static struct BenchmarkPeer *masters_p;
38static struct BenchmarkPeer *slaves_p; 38static struct BenchmarkPeer *slaves_p;
39 39
40struct Experiment *e; 40GNUNET_SCHEDULER_TaskIdentifier timeout_task;
41 41
42struct Experiment *e;
43struct LoggingHandle *l;
42 44
43static void 45static void
44evaluate () 46evaluate ()
@@ -105,8 +107,12 @@ evaluate ()
105static void 107static void
106do_shutdown () 108do_shutdown ()
107{ 109{
108 /* Shutdown a topology with */ 110 /* timeout */
109 evaluate (); 111 if (NULL != e)
112 {
113 GNUNET_ATS_TEST_experimentation_stop (e);
114 e = NULL;
115 }
110 GNUNET_ATS_TEST_shutdown_topology (); 116 GNUNET_ATS_TEST_shutdown_topology ();
111} 117}
112 118
@@ -119,12 +125,45 @@ transport_recv_cb (void *cls,
119} 125}
120 126
121static void 127static void
122ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address, 128log_request__cb (void *cls, const struct GNUNET_HELLO_Address *address,
123 int address_active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 129 int address_active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
124 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 130 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
125 const struct GNUNET_ATS_Information *ats, uint32_t ats_count) 131 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
126{ 132{
133 if (NULL != l)
134 GNUNET_ATS_TEST_logging_now (l);
135}
136
137static void
138experiment_done_cb (struct Experiment *e, int success)
139{
140 if (GNUNET_OK == success)
141 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment `%s' done successful\n", e->name);
142 else
143 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment `%s' failed \n", e->name);
144 if (GNUNET_SCHEDULER_NO_TASK != timeout_task)
145 {
146 GNUNET_SCHEDULER_cancel (timeout_task);
147 timeout_task = GNUNET_SCHEDULER_NO_TASK;
148 }
149 /* Stop logging */
150 GNUNET_ATS_TEST_logging_stop (l);
151 evaluate ();
127 152
153 /* Stop traffic generation */
154 GNUNET_ATS_TEST_generate_traffic_stop_all();
155 /* Clean up experiment */
156 GNUNET_ATS_TEST_experimentation_stop (e);
157 e = NULL;
158
159 /* Shutdown topology */
160 GNUNET_ATS_TEST_shutdown_topology ();
161}
162
163static void
164episode_done_cb (struct Episode *ep)
165{
166 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
128} 167}
129 168
130static void topology_setup_done (void *cls, 169static void topology_setup_done (void *cls,
@@ -138,25 +177,31 @@ static void topology_setup_done (void *cls,
138 masters_p = masters; 177 masters_p = masters;
139 slaves_p = slaves; 178 slaves_p = slaves;
140 179
180 l = GNUNET_ATS_TEST_logging_start (GNUNET_TIME_UNIT_SECONDS, e->name,
181 masters_p, e->num_masters);
182 GNUNET_ATS_TEST_experimentation_run (e, &episode_done_cb, &experiment_done_cb);
183
141 for (c_m = 0; c_m < e->num_masters; c_m++) 184 for (c_m = 0; c_m < e->num_masters; c_m++)
142 { 185 {
143 for (c_s = 0; c_s < e->num_slaves; c_s++) 186 for (c_s = 0; c_s < e->num_slaves; c_s++)
144 { 187 {
145 /* Generate maximum traffic to all peers */ 188 /* Generate maximum traffic to all peers */
146 fprintf (stderr, "c_m %u c_s %u\n", c_m, c_s);
147 GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m], 189 GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m],
148 &masters[c_m].partners[c_s], 190 &masters[c_m].partners[c_s],
149 10000, 191 10000,
150 GNUNET_TIME_UNIT_FOREVER_REL); 192 GNUNET_TIME_UNIT_FOREVER_REL);
151 } 193 }
152 } 194 }
153 GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &do_shutdown, NULL); 195
196 timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add (GNUNET_TIME_UNIT_MINUTES,
197 e->max_duration), &do_shutdown, NULL);
154} 198}
155 199
156 200
157int 201int
158main (int argc, char *argv[]) 202main (int argc, char *argv[])
159{ 203{
204 GNUNET_log_setup("gnunet-ats-sim", "INFO", NULL);
160 if (argc < 2) 205 if (argc < 2)
161 { 206 {
162 fprintf (stderr, "No experiment given...\n"); 207 fprintf (stderr, "No experiment given...\n");
@@ -164,14 +209,17 @@ main (int argc, char *argv[])
164 } 209 }
165 210
166 fprintf (stderr, "Loading experiment `%s' \n", argv[1]); 211 fprintf (stderr, "Loading experiment `%s' \n", argv[1]);
167 e = GNUNET_ATS_TEST_experimentation_start (argv[1]); 212 e = GNUNET_ATS_TEST_experimentation_load (argv[1]);
168 if (NULL == e) 213 if (NULL == e)
169 { 214 {
170 fprintf (stderr, "Invalid experiment\n"); 215 fprintf (stderr, "Invalid experiment\n");
171 return 1; 216 return 1;
172 } 217 }
173 218 if (0 == e->num_episodes)
174 fprintf (stderr, "%llu %llu\n", e->num_masters, e->num_slaves); 219 {
220 fprintf (stderr, "No episodes included\n");
221 return 1;
222 }
175 223
176 /* Setup a topology with */ 224 /* Setup a topology with */
177 GNUNET_ATS_TEST_create_topology ("gnunet-ats-sim", e->cfg_file, 225 GNUNET_ATS_TEST_create_topology ("gnunet-ats-sim", e->cfg_file,
@@ -181,7 +229,7 @@ main (int argc, char *argv[])
181 &topology_setup_done, 229 &topology_setup_done,
182 NULL, 230 NULL,
183 &transport_recv_cb, 231 &transport_recv_cb,
184 &ats_performance_info_cb); 232 &log_request__cb);
185 return 0; 233 return 0;
186} 234}
187/* end of file gnunet-ats-sim.c */ 235/* end of file gnunet-ats-sim.c */