aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-05-22 14:11:21 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-05-22 14:11:21 +0000
commita85e05fc57c4f4fddc564cdff31c5a0016637b93 (patch)
treeff8b1f784800ffa4784d922082b288039d039c10 /src
parent1aaecae469e58fca44d6e7a3265e71492a24b126 (diff)
downloadgnunet-a85e05fc57c4f4fddc564cdff31c5a0016637b93.tar.gz
gnunet-a85e05fc57c4f4fddc564cdff31c5a0016637b93.zip
added statistics support
Diffstat (limited to 'src')
-rw-r--r--src/experimentation/test_experimentation_clique.c151
1 files changed, 146 insertions, 5 deletions
diff --git a/src/experimentation/test_experimentation_clique.c b/src/experimentation/test_experimentation_clique.c
index e6b3fbed9..27f9e9cde 100644
--- a/src/experimentation/test_experimentation_clique.c
+++ b/src/experimentation/test_experimentation_clique.c
@@ -33,7 +33,7 @@
33/** 33/**
34 * Number of peers we want to start 34 * Number of peers we want to start
35 */ 35 */
36#define NUM_PEERS 2 36#define NUM_PEERS 5
37 37
38/** 38/**
39 * Array of peers 39 * Array of peers
@@ -60,6 +60,28 @@ static int result;
60 */ 60 */
61static unsigned int overlay_connects; 61static unsigned int overlay_connects;
62 62
63/**
64 * Information we track for a peer in the testbed.
65 */
66struct ExperimentationPeer
67{
68 /**
69 * Handle with testbed.
70 */
71 struct GNUNET_TESTBED_Peer *daemon;
72
73 /**
74 * Testbed operation to connect to statistics service
75 */
76 struct GNUNET_TESTBED_Operation *stat_op;
77
78 /**
79 * Handle to the statistics service
80 */
81 struct GNUNET_STATISTICS_Handle *sh;
82};
83
84struct ExperimentationPeer ph[NUM_PEERS];
63 85
64/** 86/**
65 * Shutdown nicely 87 * Shutdown nicely
@@ -70,7 +92,16 @@ static unsigned int overlay_connects;
70static void 92static void
71do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 93do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
72{ 94{
73 shutdown_task = GNUNET_SCHEDULER_NO_TASK; 95 unsigned int peer;
96 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
97
98 for (peer = 0; peer < NUM_PEERS; peer++)
99 {
100 if (NULL != ph[peer].stat_op)
101 GNUNET_TESTBED_operation_done (ph[peer].stat_op);
102 ph[peer].stat_op = NULL;
103 }
104
74 if (NULL != op) 105 if (NULL != op)
75 { 106 {
76 GNUNET_TESTBED_operation_done (op); 107 GNUNET_TESTBED_operation_done (op);
@@ -96,11 +127,12 @@ controller_event_cb (void *cls,
96 if ((NUM_PEERS * (NUM_PEERS - 1)) == overlay_connects) 127 if ((NUM_PEERS * (NUM_PEERS - 1)) == overlay_connects)
97 { 128 {
98 result = GNUNET_OK; 129 result = GNUNET_OK;
99 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 130 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "All %u peers connected \n", NUM_PEERS);
131
132 //GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
100 } 133 }
101 break; 134 break;
102 case GNUNET_TESTBED_ET_OPERATION_FINISHED: 135 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
103 GNUNET_assert (NULL != event->details.operation_finished.emsg);
104 break; 136 break;
105 default: 137 default:
106 GNUNET_break (0); 138 GNUNET_break (0);
@@ -112,6 +144,105 @@ controller_event_cb (void *cls,
112 144
113 145
114/** 146/**
147 * Callback function to process statistic values.
148 *
149 * @param cls struct StatsContext
150 * @param subsystem name of subsystem that created the statistic
151 * @param name the name of the datum
152 * @param value the current value
153 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
154 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
155 */
156static int
157stat_iterator (void *cls, const char *subsystem, const char *name,
158 uint64_t value, int is_persistent)
159{
160 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "STATS `%s' %s %llu\n", subsystem, name, value);
161 return GNUNET_OK;
162}
163
164/**
165 * Called after successfully opening a connection to a peer's statistics
166 * service; we register statistics monitoring here.
167 *
168 * @param cls the callback closure from functions generating an operation
169 * @param op the operation that has been finished
170 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
171 * @param emsg error message in case the operation has failed; will be NULL if
172 * operation has executed successfully.
173 */
174static void
175stat_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
176 void *ca_result, const char *emsg )
177{
178 struct GNUNET_STATISTICS_Handle *sh = ca_result;
179 struct ExperimentationPeer *peer = cls;
180
181 if (NULL != emsg)
182 {
183 GNUNET_break (0);
184 return;
185 }
186
187 GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
188 (sh, "experimentation", "# nodes active",
189 stat_iterator, peer));
190 GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
191 (sh, "experimentation", "# nodes inactive",
192 stat_iterator, peer));
193 GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch
194 (sh, "experimentation", "# nodes requested",
195 stat_iterator, peer));
196}
197
198/**
199 * Called to open a connection to the peer's statistics
200 *
201 * @param cls peer context
202 * @param cfg configuration of the peer to connect to; will be available until
203 * GNUNET_TESTBED_operation_done() is called on the operation returned
204 * from GNUNET_TESTBED_service_connect()
205 * @return service handle to return in 'op_result', NULL on error
206 */
207static void *
208stat_connect_adapter (void *cls,
209 const struct GNUNET_CONFIGURATION_Handle *cfg)
210{
211 struct ExperimentationPeer *peer = cls;
212 peer->sh = GNUNET_STATISTICS_create ("experimentation", cfg);
213 if (NULL == peer->sh)
214 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create statistics \n");
215 return peer->sh;
216}
217
218
219/**
220 * Called to disconnect from peer's statistics service
221 *
222 * @param cls peer context
223 * @param op_result service handle returned from the connect adapter
224 */
225static void
226stat_disconnect_adapter (void *cls, void *op_result)
227{
228 struct ExperimentationPeer *peer = cls;
229
230 GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
231 (peer->sh, "experimentation", "# nodes active",
232 stat_iterator, peer));
233 GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
234 (peer->sh, "experimentation", "# nodes inactive",
235 stat_iterator, peer));
236 GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
237 (peer->sh, "experimentation", "# nodes requested",
238 stat_iterator, peer));
239 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
240 peer->sh = NULL;
241}
242
243
244
245/**
115 * Signature of a main function for a testcase. 246 * Signature of a main function for a testcase.
116 * 247 *
117 * @param cls closure 248 * @param cls closure
@@ -134,7 +265,17 @@ test_master (void *cls, unsigned int num_peers,
134 GNUNET_assert (NUM_PEERS == num_peers); 265 GNUNET_assert (NUM_PEERS == num_peers);
135 GNUNET_assert (NULL != peers_); 266 GNUNET_assert (NULL != peers_);
136 for (peer = 0; peer < num_peers; peer++) 267 for (peer = 0; peer < num_peers; peer++)
268 {
137 GNUNET_assert (NULL != peers_[peer]); 269 GNUNET_assert (NULL != peers_[peer]);
270 /* Connect to peer's statistic service */
271 ph[peer].stat_op = GNUNET_TESTBED_service_connect (NULL,
272 peers_[peer], "statistics",
273 &stat_comp_cb, &ph[peer],
274 &stat_connect_adapter,
275 &stat_disconnect_adapter,
276 &ph[peer]);
277
278 }
138 peers = peers_; 279 peers = peers_;
139 overlay_connects = 0; 280 overlay_connects = 0;
140 op = GNUNET_TESTBED_overlay_configure_topology (NULL, NUM_PEERS, peers, NULL, 281 op = GNUNET_TESTBED_overlay_configure_topology (NULL, NUM_PEERS, peers, NULL,
@@ -147,7 +288,7 @@ test_master (void *cls, unsigned int num_peers,
147 GNUNET_assert (NULL != op); 288 GNUNET_assert (NULL != op);
148 shutdown_task = 289 shutdown_task =
149 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 290 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
150 (GNUNET_TIME_UNIT_SECONDS, 300), 291 (GNUNET_TIME_UNIT_SECONDS, 20),
151 do_shutdown, NULL); 292 do_shutdown, NULL);
152} 293}
153 294