aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_ats.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-03-31 14:30:30 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-03-31 14:30:30 +0000
commit8296bb1d3fdc501f61eb61cff3d02fddeb6fa1e8 (patch)
treebc63064f317a00f25b0fa4bffc83dc4ecd3db53d /src/transport/test_transport_ats.c
parent417153f60dbac6d5e626978136dc9ea429598a0d (diff)
downloadgnunet-8296bb1d3fdc501f61eb61cff3d02fddeb6fa1e8.tar.gz
gnunet-8296bb1d3fdc501f61eb61cff3d02fddeb6fa1e8.zip
Diffstat (limited to 'src/transport/test_transport_ats.c')
-rw-r--r--src/transport/test_transport_ats.c121
1 files changed, 108 insertions, 13 deletions
diff --git a/src/transport/test_transport_ats.c b/src/transport/test_transport_ats.c
index 9f4e8d05f..2880da8e5 100644
--- a/src/transport/test_transport_ats.c
+++ b/src/transport/test_transport_ats.c
@@ -25,11 +25,12 @@
25#include "gnunet_testing_lib.h" 25#include "gnunet_testing_lib.h"
26#include "gnunet_scheduler_lib.h" 26#include "gnunet_scheduler_lib.h"
27 27
28#define VERBOSE GNUNET_YES 28#define VERBOSE GNUNET_NO
29 29
30#define NUM_PEERS 2 30#define NUM_PEERS 11
31#define MEASUREMENTS 5
31 32
32#define DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 33#define DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
33#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 34#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
34 35
35 36
@@ -39,12 +40,27 @@ static int peers_left;
39 40
40static int failed_peers; 41static int failed_peers;
41 42
43static int measurement_started;
44
42static struct GNUNET_TESTING_PeerGroup *pg; 45static struct GNUNET_TESTING_PeerGroup *pg;
43 46
44static GNUNET_SCHEDULER_TaskIdentifier task; 47static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
48static GNUNET_SCHEDULER_TaskIdentifier stats_task;
45 49
46struct GNUNET_TESTING_Daemon * master_deamon; 50struct GNUNET_TESTING_Daemon * master_deamon;
47 51
52struct GNUNET_STATISTICS_Handle * stats;
53
54struct ATS_result
55{
56 uint64_t timestamp;
57 int mechs;
58 int peers;
59 int solution;
60};
61
62//static int index;
63static struct ATS_result results[MEASUREMENTS];
48 64
49/** 65/**
50 * Check whether peers successfully shut down. 66 * Check whether peers successfully shut down.
@@ -71,26 +87,94 @@ shutdown_callback (void *cls, const char *emsg)
71 87
72static void shutdown_peers() 88static void shutdown_peers()
73{ 89{
90 if (shutdown_task != GNUNET_SCHEDULER_NO_TASK)
91 GNUNET_SCHEDULER_cancel(shutdown_task);
92 if (stats_task != GNUNET_SCHEDULER_NO_TASK)
93 GNUNET_SCHEDULER_cancel(stats_task);
94
74 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 95 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
75} 96}
76 97
98int stats_cb (void *cls,
99 const char *subsystem,
100 const char *name,
101 uint64_t value,
102 int is_persistent)
103{
104 if ((measurement_started == GNUNET_NO) && (0 == strcmp (name, "ATS peers")) && (value == NUM_PEERS-1))
105 {
106 measurement_started = GNUNET_YES;
107 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
108 "All %llu peers connected\n", value);
109 }
110 if (measurement_started == GNUNET_YES)
111 {
112 if (0 == strcmp (name,"ATS timestamp"))
113 {
114 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
115 "ATS timestamp: %s %llu \n",name, value);
116 }
117 if (0 == strcmp (name,"ATS solution"))
118 {
119 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
120 "ATS solution: %s %llu \n",name, value);
121 }
122 if (0 == strcmp (name,"ATS peers"))
123 {
124 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
125 "ATS peers: %s %llu \n",name, value);
126 }
127 if (0 == strcmp (name,"ATS mechanisms"))
128 {
129 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
130 "ATS mechanisms: %s %llu \n",name, value);
131 }
132 if (0 == strcmp (name,"ATS duration"))
133 {
134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
135 "ATS duration: %s %llu \n",name, value);
136 }
137 }
138
139 return GNUNET_OK;
140}
141
142
77void 143void
78delay_task (void *cls, 144stats_get_task (void *cls,
79 const struct GNUNET_SCHEDULER_TaskContext *tc) 145 const struct GNUNET_SCHEDULER_TaskContext *tc)
80{ 146{
81 task = GNUNET_SCHEDULER_NO_TASK; 147 stats_task = GNUNET_SCHEDULER_NO_TASK;
148 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
149 return;
150
151 GNUNET_STATISTICS_get (stats, "transport", "ATS timestamp", TIMEOUT, NULL, &stats_cb, NULL);
152 GNUNET_STATISTICS_get (stats, "transport", "ATS solution", TIMEOUT, NULL, &stats_cb, NULL);
153 GNUNET_assert (NULL != GNUNET_STATISTICS_get (stats, "transport","ATS duration", TIMEOUT, NULL, &stats_cb, NULL));
154 GNUNET_STATISTICS_get (stats, "transport", "ATS peers", TIMEOUT, NULL, &stats_cb, NULL);
155 GNUNET_STATISTICS_get (stats, "transport", "ATS mechanisms", TIMEOUT, NULL, &stats_cb, NULL);
156
157 stats_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), &stats_get_task, NULL);
158}
159
160void
161delay (void *cls,
162 const struct GNUNET_SCHEDULER_TaskContext *tc)
163{
164 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
82 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 165 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
83 return; 166 return;
84 167
85#if VERBOSE 168#if VERBOSE
86 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Delay over\n"); 169 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Delay over\n");
87#endif 170#endif
171 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
88 shutdown_peers (); 172 shutdown_peers ();
89} 173}
90 174
91static void connect_peers() 175static void connect_peers()
92{ 176{
93 task = GNUNET_SCHEDULER_add_delayed(DELAY, &delay_task, NULL); 177 shutdown_task = GNUNET_SCHEDULER_add_delayed(DELAY, &delay, NULL);
94 178
95} 179}
96 180
@@ -104,7 +188,13 @@ void daemon_connect_cb(void *cls,
104 struct GNUNET_TESTING_Daemon *second_daemon, 188 struct GNUNET_TESTING_Daemon *second_daemon,
105 const char *emsg) 189 const char *emsg)
106{ 190{
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected peer `%s' \n", GNUNET_i2s(first), GNUNET_i2s(second)); 191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected peers `%s'<->`%s': `%s' \n", GNUNET_i2s(first), GNUNET_i2s(second), (emsg==NULL) ? "OK" : emsg);
192}
193
194void cont_cb (void *cls, int success)
195{
196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
197 "STATS cont_cb: %i\n", success);
108} 198}
109 199
110static void 200static void
@@ -124,7 +214,7 @@ daemon_start_cb (void *cls,
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
125 "Too many peers failed, ending test!\n"); 215 "Too many peers failed, ending test!\n");
126 ok = 1; 216 ok = 1;
127 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 217 shutdown_peers ();
128 } 218 }
129 return; 219 return;
130 } 220 }
@@ -132,13 +222,17 @@ daemon_start_cb (void *cls,
132 222
133 if (master_deamon == NULL) 223 if (master_deamon == NULL)
134 { 224 {
135 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Master peer `%s'\n", GNUNET_i2s(id)); 225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Master peer `%s' '%s'\n", GNUNET_i2s(id), d->cfgfile);
226
136 master_deamon = d; 227 master_deamon = d;
228 stats = GNUNET_STATISTICS_create("transport", master_deamon->cfg);
229 GNUNET_assert (stats != NULL);
230 stats_task = GNUNET_SCHEDULER_add_now(&stats_get_task, NULL);
137 } 231 }
138 else 232 else
139 { 233 {
140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer `%s'\n", GNUNET_i2s(id)); 234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peer `%s'\n", GNUNET_i2s(id), GNUNET_i2s(&master_deamon->id));
141 GNUNET_TESTING_daemons_connect(master_deamon, d, TIMEOUT, 10, GNUNET_YES,&daemon_connect_cb, NULL); 235 GNUNET_TESTING_daemons_connect(d, master_deamon, TIMEOUT, 0, GNUNET_YES,&daemon_connect_cb, NULL);
142 } 236 }
143 237
144 if (peers_left == 0) 238 if (peers_left == 0)
@@ -164,6 +258,7 @@ run (void *cls,
164 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) 258 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
165{ 259{
166 ok = 1; 260 ok = 1;
261 measurement_started = GNUNET_NO;
167#if VERBOSE 262#if VERBOSE
168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting %i peers.\n", NUM_PEERS); 263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting %i peers.\n", NUM_PEERS);
169#endif 264#endif
@@ -183,7 +278,7 @@ check ()
183{ 278{
184 char *const argv[] = { "test-testing", 279 char *const argv[] = { "test-testing",
185 "-c", 280 "-c",
186 "test_testing_data.conf", 281 "test_transport_ats.conf",
187#if VERBOSE 282#if VERBOSE
188 "-L", "DEBUG", 283 "-L", "DEBUG",
189#endif 284#endif