aboutsummaryrefslogtreecommitdiff
path: root/src/topology
diff options
context:
space:
mode:
authorxrs <xrs@mail36.net>2018-06-25 16:50:25 +0200
committerxrs <xrs@mail36.net>2018-06-25 16:50:25 +0200
commitd21b525003a8d8088aaf9aad2e45cb4b5ad3ca5a (patch)
tree76b0d20aa4ee2138e284dd26b8c45c2621e616f1 /src/topology
parenta60bc39254a063f93f4b193691504e1bba0cb608 (diff)
downloadgnunet-d21b525003a8d8088aaf9aad2e45cb4b5ad3ca5a.tar.gz
gnunet-d21b525003a8d8088aaf9aad2e45cb4b5ad3ca5a.zip
fix 0002834: test_gnunet_daemon_topology.c now tests the connections of every peer
Diffstat (limited to 'src/topology')
-rw-r--r--src/topology/test_gnunet_daemon_topology.c227
1 files changed, 208 insertions, 19 deletions
diff --git a/src/topology/test_gnunet_daemon_topology.c b/src/topology/test_gnunet_daemon_topology.c
index 7c75d1137..bf9121eb0 100644
--- a/src/topology/test_gnunet_daemon_topology.c
+++ b/src/topology/test_gnunet_daemon_topology.c
@@ -18,47 +18,202 @@
18/** 18/**
19 * @file topology/test_gnunet_daemon_topology.c 19 * @file topology/test_gnunet_daemon_topology.c
20 * @brief testcase for topology maintenance code 20 * @brief testcase for topology maintenance code
21 * @author Christian Grothoff
22 * @author xrs
21 */ 23 */
22#include "platform.h" 24#include "platform.h"
23#include "gnunet_testbed_service.h" 25#include "gnunet_testbed_service.h"
26#include "gnunet_statistics_service.h"
24 27
25 28
26#define NUM_PEERS 8 29#define NUM_PEERS 8
27 30
31/*
32 * The threshold defines the number of connection that are needed
33 * for one peer to pass the test. Be aware that setting NUM_PEERS
34 * too high can cause bandwidth problems for the testing peers.
35 * Normal should be 5KB/s per peer. See gnunet-config -s ats.
36 */
37#define THRESHOLD NUM_PEERS/2
38
28/** 39/**
29 * How long until we give up on connecting the peers? 40 * How long until we give up on connecting the peers?
30 */ 41 */
31#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600) 42#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
32 43
44/*
45 * Store manual connections.
46 */
47static unsigned int connect_left;
33 48
34static int ok; 49/*
50 * Result of the testcase.
51 */
52static int result;
35 53
36static unsigned int connect_left; 54/*
55 * Peers that reached the threshold of connections.
56 */
57static int checked_peers;
58
59/*
60 * Testbed operations.
61 */
62struct GNUNET_TESTBED_Operation *op[NUM_PEERS];
63
64/*
65 * Timeout for testcase.
66 */
67static struct GNUNET_SCHEDULER_Task *timeout_tid;
68
69/*
70 * Peer context for every testbed peer.
71 */
72struct peerctx
73{
74 int index;
75 struct GNUNET_STATISTICS_Handle *statistics;
76 int connections;
77 int reported; /* GNUNET_NO | GNUNET_YES */
78};
79
80
81static void
82shutdown_task (void *cls)
83{
84 unsigned int i;
85
86 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
87 "Shutting down testcase\n");
37 88
89 for (i=0;i<NUM_PEERS;i++) {
90 if (NULL != op[i])
91 GNUNET_TESTBED_operation_done (op[i]);
92 }
93
94 if (NULL != timeout_tid)
95 GNUNET_SCHEDULER_cancel (timeout_tid);
96}
97
98static void
99timeout_task (void *cls)
100{
101 timeout_tid = NULL;
102 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
103 "Testcase timeout\n");
104
105 result = GNUNET_SYSERR;
106 GNUNET_SCHEDULER_shutdown();
107}
108
109/*
110 * The function is called every time the topology of connected
111 * peers to a peer changes.
112 */
113int
114statistics_iterator (void *cls,
115 const char *subsystem,
116 const char *name,
117 uint64_t value,
118 int is_persistent)
119{
120 struct peerctx *p_ctx = (struct peerctx*) cls;
121
122 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
123 "Peer %d: %s = %d\n",
124 p_ctx->index,
125 name,
126 value);
127
128 if (p_ctx->connections < value)
129 p_ctx->connections = value;
130
131 if (THRESHOLD <= value && GNUNET_NO == p_ctx->reported) {
132 p_ctx->reported = GNUNET_YES;
133 checked_peers++;
134 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
135 "Peer %d successfully connected to at least %d peers once.\n",
136 p_ctx->index,
137 THRESHOLD);
138
139 if (checked_peers == NUM_PEERS) {
140 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
141 "Test OK: All peers have connected to %d peers once.\n",
142 THRESHOLD);
143 result = GNUNET_YES;
144 GNUNET_SCHEDULER_shutdown();
145 }
146 }
147
148 return GNUNET_YES;
149}
150
151static void *
152ca_statistics (void *cls,
153 const struct GNUNET_CONFIGURATION_Handle *cfg)
154{
155 return GNUNET_STATISTICS_create ("topology", cfg);
156}
157
158
159void
160da_statistics (void *cls,
161 void *op_result)
162{
163 struct peerctx *p_ctx = (struct peerctx *) cls;
164
165 GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel
166 (p_ctx->statistics, "topology", "# peers connected",
167 statistics_iterator, p_ctx));
168
169 GNUNET_STATISTICS_destroy (p_ctx->statistics, GNUNET_NO);
170 p_ctx->statistics = NULL;
171
172 GNUNET_free (p_ctx);
173}
174
175
176static void
177service_connect_complete (void *cls,
178 struct GNUNET_TESTBED_Operation *op,
179 void *ca_result,
180 const char *emsg)
181{
182 int ret;
183 struct peerctx *p_ctx = (struct peerctx*) cls;
184
185 if (NULL == ca_result)
186 GNUNET_SCHEDULER_shutdown();
187
188 p_ctx->statistics = ca_result;
189
190 ret = GNUNET_STATISTICS_watch (ca_result,
191 "topology",
192 "# peers connected",
193 statistics_iterator,
194 p_ctx);
195
196 if (GNUNET_NO == ret)
197 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
198 "call to GNUNET_STATISTICS_watch() failed\n");
199}
38 200
39static void 201static void
40notify_connect_complete (void *cls, 202notify_connect_complete (void *cls,
41 struct GNUNET_TESTBED_Operation *op, 203 struct GNUNET_TESTBED_Operation *op,
42 const char *emsg) 204 const char *emsg)
43{ 205{
44 GNUNET_TESTBED_operation_done (op); 206 GNUNET_TESTBED_operation_done (op);
45 if (NULL != emsg) 207 if (NULL != emsg)
46 { 208 {
47 FPRINTF (stderr, "Failed to connect two peers: %s\n", emsg); 209 FPRINTF (stderr, "Failed to connect two peers: %s\n", emsg);
210 result = GNUNET_SYSERR;
48 GNUNET_SCHEDULER_shutdown (); 211 GNUNET_SCHEDULER_shutdown ();
49 ok = 1;
50 return; 212 return;
51 } 213 }
52 connect_left--; 214 connect_left--;
53 if (0 == connect_left)
54 {
55 /* FIXME: check that topology adds a few more links
56 * in addition to those that were seeded */
57 GNUNET_SCHEDULER_shutdown ();
58 }
59} 215}
60 216
61
62static void 217static void
63do_connect (void *cls, 218do_connect (void *cls,
64 struct GNUNET_TESTBED_RunHandle *h, 219 struct GNUNET_TESTBED_RunHandle *h,
@@ -68,28 +223,62 @@ do_connect (void *cls,
68 unsigned int links_failed) 223 unsigned int links_failed)
69{ 224{
70 unsigned int i; 225 unsigned int i;
226 struct peerctx *p_ctx;
227
228 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
229 "Threshold is set to %d.\n",
230 THRESHOLD);
71 231
72 GNUNET_assert (NUM_PEERS == num_peers); 232 GNUNET_assert (NUM_PEERS == num_peers);
73 for (i=0;i<num_peers-1;i++) 233
234 for (i=0;i<NUM_PEERS;i++)
74 { 235 {
75 connect_left++; 236 p_ctx = GNUNET_new (struct peerctx);
76 GNUNET_TESTBED_overlay_connect (NULL, 237 p_ctx->index = i;
77 &notify_connect_complete, NULL, 238 p_ctx->connections = 0;
78 peers[i], peers[i+1]); 239 p_ctx->reported = GNUNET_NO;
240
241 if (i<NUM_PEERS-1) {
242 connect_left++;
243 GNUNET_TESTBED_overlay_connect (NULL,
244 &notify_connect_complete, NULL,
245 peers[i], peers[i+1]);
246 }
247
248 op[i] =
249 GNUNET_TESTBED_service_connect (cls,
250 peers[i],
251 "statistics",
252 service_connect_complete,
253 p_ctx, /* cls of completion cb */
254 ca_statistics, /* connect adapter */
255 da_statistics, /* disconnect adapter */
256 p_ctx);
257
79 } 258 }
259
260 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
261 timeout_tid =
262 GNUNET_SCHEDULER_add_delayed (TIMEOUT,
263 &timeout_task,
264 NULL);
80} 265}
81 266
82 267
83int 268int
84main (int argc, char *argv[]) 269main (int argc, char *argv[])
85{ 270{
271 result = GNUNET_SYSERR;
272 checked_peers = 0;
273
86 (void) GNUNET_TESTBED_test_run ("test-gnunet-daemon-topology", 274 (void) GNUNET_TESTBED_test_run ("test-gnunet-daemon-topology",
87 "test_gnunet_daemon_topology_data.conf", 275 "test_gnunet_daemon_topology_data.conf",
88 NUM_PEERS, 276 NUM_PEERS,
89 0, NULL, NULL, 277 0, NULL, NULL,
90 &do_connect, NULL); 278 &do_connect, NULL);
91 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-topology"); 279 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-topology");
92 return ok; 280
281 return (GNUNET_OK != result) ? 1 : 0;
93} 282}
94 283
95/* end of test_gnunet_daemon_topology.c */ 284/* end of test_gnunet_daemon_topology.c */