aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-11-05 01:47:30 +0000
committerBart Polot <bart@net.in.tum.de>2011-11-05 01:47:30 +0000
commit1a0cfe2842a5d86eb8675b5c4c608d912b362154 (patch)
tree1dcfa3e65a0ae4c369a1a37b6019aabeeff90d81 /src/mesh
parent9457d1e70d656538747775475ba6cd5a8a84adf6 (diff)
downloadgnunet-1a0cfe2842a5d86eb8675b5c4c608d912b362154.tar.gz
gnunet-1a0cfe2842a5d86eb8675b5c4c608d912b362154.zip
Added an empty 2d torus test (connect and to nothing)
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/Makefile.am7
-rw-r--r--src/mesh/test_mesh_2dtorus.c389
-rw-r--r--src/mesh/test_mesh_2dtorus.conf85
-rw-r--r--src/mesh/test_mesh_small.conf6
4 files changed, 484 insertions, 3 deletions
diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am
index fa6af8d7f..d63649ad6 100644
--- a/src/mesh/Makefile.am
+++ b/src/mesh/Makefile.am
@@ -47,6 +47,7 @@ check_PROGRAMS = \
47 test_mesh_tree_api \ 47 test_mesh_tree_api \
48 test_mesh_local_1 \ 48 test_mesh_local_1 \
49 test_mesh_local_2 \ 49 test_mesh_local_2 \
50 test_mesh_2dtorus \
50 test_mesh_small_unicast \ 51 test_mesh_small_unicast \
51 test_mesh_small_unicast_far \ 52 test_mesh_small_unicast_far \
52 test_mesh_small_multicast 53 test_mesh_small_multicast
@@ -85,6 +86,12 @@ test_mesh_local_2_LDADD = \
85test_mesh_local_2_DEPENDENCIES = \ 86test_mesh_local_2_DEPENDENCIES = \
86 libgnunetmesh.la 87 libgnunetmesh.la
87 88
89test_mesh_2dtorus_SOURCES = \
90 test_mesh_2dtorus.c
91test_mesh_2dtorus_LDADD = \
92 $(top_builddir)/src/util/libgnunetutil.la \
93 $(top_builddir)/src/testing/libgnunettesting.la
94
88test_mesh_small_unicast_SOURCES = \ 95test_mesh_small_unicast_SOURCES = \
89 test_mesh_small.c 96 test_mesh_small.c
90test_mesh_small_unicast_LDADD = \ 97test_mesh_small_unicast_LDADD = \
diff --git a/src/mesh/test_mesh_2dtorus.c b/src/mesh/test_mesh_2dtorus.c
new file mode 100644
index 000000000..9b15e3613
--- /dev/null
+++ b/src/mesh/test_mesh_2dtorus.c
@@ -0,0 +1,389 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file mesh/test_mesh_2dtorus.c
22 *
23 * @brief Test for creating a 2dtorus.
24 */
25#include "platform.h"
26#include "gnunet_testing_lib.h"
27
28#define VERBOSE GNUNET_YES
29#define REMOVE_DIR GNUNET_YES
30
31/**
32 * How long until we give up on connecting the peers?
33 */
34#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1500)
35
36/**
37 * Time to wait for stuff that should be rather fast
38 */
39#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
40
41
42/**
43 * How many events have happened
44 */
45static int ok;
46
47/**
48 * Be verbose
49 */
50static int verbose;
51
52/**
53 * Total number of peers in the test.
54 */
55static unsigned long long num_peers;
56
57/**
58 * Global configuration file
59 */
60static struct GNUNET_CONFIGURATION_Handle *testing_cfg;
61
62/**
63 * Total number of currently running peers.
64 */
65static unsigned long long peers_running;
66
67/**
68 * Total number of successful connections in the whole network.
69 */
70static unsigned int total_connections;
71
72/**
73 * Total number of counted topo connections
74 */
75static unsigned int topo_connections;
76
77/**
78 * Total number of failed connections in the whole network.
79 */
80static unsigned int failed_connections;
81
82/**
83 * The currently running peer group.
84 */
85static struct GNUNET_TESTING_PeerGroup *pg;
86
87/**
88 * Task called to disconnect peers
89 */
90static GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
91
92/**
93 * Task called to shutdown test.
94 */
95static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle;
96
97
98/**
99 * Check whether peers successfully shut down.
100 */
101static void
102shutdown_callback (void *cls, const char *emsg)
103{
104 if (emsg != NULL)
105 {
106#if VERBOSE
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
108 "test: Shutdown of peers failed!\n");
109#endif
110 ok--;
111 }
112 else
113 {
114#if VERBOSE
115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
116 "test: All peers successfully shut down!\n");
117#endif
118 }
119}
120
121
122static void
123shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
124{
125#if VERBOSE
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
127 "test: Ending test.\n");
128#endif
129
130 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
131 GNUNET_CONFIGURATION_destroy (testing_cfg);
132}
133
134
135static void
136disconnect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
137{
138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
139 "test: disconnecting peers\n");
140
141 if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle)
142 {
143 GNUNET_SCHEDULER_cancel (shutdown_handle);
144 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
145 }
146}
147
148
149/**
150 * Prototype of a callback function indicating that two peers
151 * are currently connected.
152 *
153 * @param cls closure
154 * @param first peer id for first daemon
155 * @param second peer id for the second daemon
156 * @param distance distance between the connected peers
157 * @param emsg error message (NULL on success)
158 */
159void
160topo_cb (void *cls, const struct GNUNET_PeerIdentity *first,
161 const struct GNUNET_PeerIdentity *second, const char *emsg)
162{
163 topo_connections++;
164 if (NULL != emsg)
165 {
166 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
167 "test: Error by topo %u: %s\n",
168 topo_connections, emsg);
169 }
170 else
171 {
172 if (first == NULL || second == NULL)
173 {
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
175 "test: Connection %u NULL\n",
176 topo_connections);
177 if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
178 {
179 GNUNET_SCHEDULER_cancel (disconnect_task);
180 GNUNET_SCHEDULER_add_now(&disconnect_peers, NULL);
181 }
182 return;
183 }
184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
185 "test: Connection %u ok\n",
186 topo_connections);
187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
188 "test: %s\n",
189 GNUNET_i2s (first));
190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
191 "test: %s\n",
192 GNUNET_i2s (second));
193 }
194}
195
196
197/**
198 * peergroup_ready: start test when all peers are connected
199 * @param cls closure
200 * @param emsg error message
201 */
202static void
203peergroup_ready (void *cls, const char *emsg)
204{
205 if (emsg != NULL)
206 {
207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
208 "test: Peergroup callback called with error, aborting test!\n");
209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
210 "test: Error from testing: `%s'\n", emsg);
211 ok--;
212 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
213 return;
214 }
215#if VERBOSE
216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
217 "************************************************************\n");
218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
219 "test: Peer Group started successfully!\n");
220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
221 "test: Have %u connections\n",
222 total_connections);
223#endif
224
225 peers_running = GNUNET_TESTING_daemons_running (pg);
226 if (0 < failed_connections)
227 {
228 ok = GNUNET_SYSERR;
229 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
230 "test: %u connections have FAILED!\n",
231 failed_connections);
232 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL);
233
234 }
235 else
236 {
237 GNUNET_TESTING_get_topology (pg, &topo_cb, NULL);
238 disconnect_task =
239 GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &disconnect_peers, NULL);
240 ok = GNUNET_OK;
241 }
242
243}
244
245
246/**
247 * Function that will be called whenever two daemons are connected by
248 * the testing library.
249 *
250 * @param cls closure
251 * @param first peer id for first daemon
252 * @param second peer id for the second daemon
253 * @param distance distance between the connected peers
254 * @param first_cfg config for the first daemon
255 * @param second_cfg config for the second daemon
256 * @param first_daemon handle for the first daemon
257 * @param second_daemon handle for the second daemon
258 * @param emsg error message (NULL on success)
259 */
260static void
261connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
262 const struct GNUNET_PeerIdentity *second, uint32_t distance,
263 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
264 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
265 struct GNUNET_TESTING_Daemon *first_daemon,
266 struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg)
267{
268 if (emsg == NULL)
269 {
270 total_connections++;
271 }
272 else
273 {
274 failed_connections++;
275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
276 "test: Problem with new connection (%s)\n",
277 emsg);
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: (%s)\n",
279 GNUNET_i2s (first));
280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: (%s)\n",
281 GNUNET_i2s (second));
282 }
283
284}
285
286
287/**
288 * run: load configuration options and schedule test to run (start peergroup)
289 * @param cls closure
290 * @param args argv
291 * @param cfgfile configuration file name (can be NULL)
292 * @param cfg configuration handle
293 */
294static void
295run (void *cls, char *const *args, const char *cfgfile,
296 const struct GNUNET_CONFIGURATION_Handle *cfg)
297{
298 struct GNUNET_TESTING_Host *hosts;
299
300 ok = GNUNET_NO;
301 total_connections = 0;
302 failed_connections = 0;
303 testing_cfg = GNUNET_CONFIGURATION_dup (cfg);
304
305 GNUNET_log_setup ("test_mesh_2dtorus",
306#if VERBOSE
307 "DEBUG",
308#else
309 "WARNING",
310#endif
311 NULL);
312
313#if VERBOSE
314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
315 "test: Starting daemons.\n");
316 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
317 "use_progressbars", "YES");
318#endif
319
320 if (GNUNET_OK !=
321 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing",
322 "num_peers", &num_peers))
323 {
324 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
325 "Option TESTING:NUM_PEERS is required!\n");
326 return;
327 }
328
329 hosts = GNUNET_TESTING_hosts_load (testing_cfg);
330
331 pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT,
332 &connect_cb, &peergroup_ready, NULL,
333 hosts);
334 GNUNET_assert (pg != NULL);
335 shutdown_handle =
336 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (),
337 &shutdown_task, NULL);
338}
339
340
341/**
342 * test_mesh_2dtorus command line options
343 */
344static struct GNUNET_GETOPT_CommandLineOption options[] = {
345 {'V', "verbose", NULL,
346 gettext_noop ("be verbose (print progress information)"),
347 0, &GNUNET_GETOPT_set_one, &verbose},
348 GNUNET_GETOPT_OPTION_END
349};
350
351
352/**
353 * Main: start test
354 */
355int
356main (int argc, char *argv[])
357{
358 char *const argv2[] = {
359 argv[0],
360 "-c",
361 "test_mesh_2dtorus.conf",
362#if VERBOSE
363 "-L",
364 "DEBUG",
365#endif
366 NULL
367 };
368
369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Start\n");
370
371
372 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
373 "test_mesh_2dtorus",
374 gettext_noop ("Test mesh 2d torus."), options,
375 &run, NULL);
376#if REMOVE_DIR
377 GNUNET_DISK_directory_remove ("/tmp/test_mesh_2dtorus");
378#endif
379 if (GNUNET_OK != ok)
380 {
381 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
382 "test: FAILED!\n");
383 return 1;
384 }
385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: success\n");
386 return 0;
387}
388
389/* end of test_mesh_2dtorus.c */
diff --git a/src/mesh/test_mesh_2dtorus.conf b/src/mesh/test_mesh_2dtorus.conf
new file mode 100644
index 000000000..05eb38faf
--- /dev/null
+++ b/src/mesh/test_mesh_2dtorus.conf
@@ -0,0 +1,85 @@
1[PATHS]
2SERVICEHOME = /tmp/test_mesh_small/
3DEFAULTCONFIG = test_mesh_small.conf
4
5[arm]
6PORT = 10010
7DEFAULTSERVICES = core dht mesh
8#DEBUG = YES
9
10[statistics]
11AUTOSTART = YES
12PORT = 10000
13
14[dht]
15DEBUG = NO
16AUTOSTART = YES
17ACCEPT_FROM6 = ::1;
18ACCEPT_FROM = 127.0.0.1;
19HOSTNAME = localhost
20PORT = 10001
21
22[nse]
23WORKBITS = 0
24
25[dns]
26AUTOSTART = NO
27PORT = 10011
28
29[transport]
30PORT = 10002
31AUTOSTART = YES
32
33[nat]
34DISABLEV6 = YES
35BINDTO = 127.0.0.1
36ENABLE_UPNP = NO
37BEHIND_NAT = NO
38ALLOW_NAT = NO
39INTERNAL_ADDRESS = 127.0.0.1
40EXTERNAL_ADDRESS = 127.0.0.1
41
42[core]
43TOTAL_QUOTA_IN = 999111999
44TOTAL_QUOTA_OUT = 999111999
45AUTOSTART = YES
46PORT = 10003
47
48[peerinfo]
49AUTOSTART = YES
50PORT = 10004
51
52[mesh]
53PORT = 10005
54DEBUG=YES
55ACCEPT_FROM = 127.0.0.1;
56HOSTNAME = localhost
57# PREFIX = valgrind --leak-check=full
58# PREFIX = xterm -geometry 100x85 -T peer1 -e gdb --args
59
60[testing]
61NUM_PEERS = 16
62WEAKRANDOM = YES
63TOPOLOGY = 2D_TORUS
64CONNECT_TOPOLOGY = 2D_TORUS
65#TOPOLOGY_FILE = small.dat
66CONNECT_TOPOLOGY = 2D_TORUS
67#CONNECT_TOPOLOGY_OPTION = CONNECT_MINIMUM
68#CONNECT_TOPOLOGY_OPTION_MODIFIER = 25
69#PERCENTAGE = 3
70#PROBABILITY = .1
71F2F = NO
72CONNECT_TIMEOUT = 60
73CONNECT_ATTEMPTS = 3
74DEBUG = YES
75HOSTKEYSFILE = ../../contrib/testing_hostkeys.dat
76MAX_CONCURRENT_SSH = 10
77USE_PROGRESSBARS = YES
78PEERGROUP_TIMEOUT = 2400
79TOPOLOGY_OUTPUT_FILE = mesh_topo_initial
80MAX_OUTSTANDING_CONNECTIONS = 75
81#SINGLE_PEERINFO_PER_HOST = YES
82#NUM_PEERINFO_PER_HOST = 10
83#SINGLE_STATISTICS_PER_HOST = YES
84#NUM_STATISTICS_PER_HOST = 10
85DELETE_FILES = YES
diff --git a/src/mesh/test_mesh_small.conf b/src/mesh/test_mesh_small.conf
index 9e340aacb..eccd8611d 100644
--- a/src/mesh/test_mesh_small.conf
+++ b/src/mesh/test_mesh_small.conf
@@ -40,8 +40,8 @@ INTERNAL_ADDRESS = 127.0.0.1
40EXTERNAL_ADDRESS = 127.0.0.1 40EXTERNAL_ADDRESS = 127.0.0.1
41 41
42[core] 42[core]
43TOTAL_QUOTA_IN = 99111999 43TOTAL_QUOTA_IN = 999111999
44TOTAL_QUOTA_OUT = 99111999 44TOTAL_QUOTA_OUT = 999111999
45AUTOSTART = YES 45AUTOSTART = YES
46PORT = 10003 46PORT = 10003
47 47
@@ -61,7 +61,7 @@ HOSTNAME = localhost
61NUM_PEERS = 16 61NUM_PEERS = 16
62WEAKRANDOM = YES 62WEAKRANDOM = YES
63TOPOLOGY = 2D_TORUS 63TOPOLOGY = 2D_TORUS
64CONNECT_TOPOLOGY = NONE 64CONNECT_TOPOLOGY = 2D_TORUS
65#TOPOLOGY_FILE = small.dat 65#TOPOLOGY_FILE = small.dat
66CONNECT_TOPOLOGY = 2D_TORUS 66CONNECT_TOPOLOGY = 2D_TORUS
67#CONNECT_TOPOLOGY_OPTION = CONNECT_MINIMUM 67#CONNECT_TOPOLOGY_OPTION = CONNECT_MINIMUM