aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-05-16 14:45:29 +0000
committerBart Polot <bart@net.in.tum.de>2013-05-16 14:45:29 +0000
commit60dc97e5f97fe81014495f0cb28f7c7815b667d7 (patch)
treedc8c0ce076923d81749dcaf5720fa6269e16f20d /src
parentf5a00303d231d09028cd15296a2382bf48074a1e (diff)
downloadgnunet-60dc97e5f97fe81014495f0cb28f7c7815b667d7.tar.gz
gnunet-60dc97e5f97fe81014495f0cb28f7c7815b667d7.zip
- add mesh2 local testcase
Diffstat (limited to 'src')
-rw-r--r--src/mesh/Makefile.am20
-rw-r--r--src/mesh/mesh2_api.c2
-rw-r--r--src/mesh/test_mesh2_local.c260
3 files changed, 278 insertions, 4 deletions
diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am
index d7dada67c..3531d0647 100644
--- a/src/mesh/Makefile.am
+++ b/src/mesh/Makefile.am
@@ -23,6 +23,8 @@ AM_CLFAGS = -g
23if HAVE_EXPERIMENTAL 23if HAVE_EXPERIMENTAL
24 EXP_LIB = libgnunetmesh2.la 24 EXP_LIB = libgnunetmesh2.la
25 EXP_LIBEXEC = gnunet-service-mesh-new 25 EXP_LIBEXEC = gnunet-service-mesh-new
26 EXP_TESTS = \
27 test_mesh2_local
26endif 28endif
27 29
28libexec_PROGRAMS = \ 30libexec_PROGRAMS = \
@@ -93,7 +95,7 @@ gnunet_service_mesh_LDFLAGS = -lrt
93endif 95endif
94 96
95gnunet_mesh_SOURCES = \ 97gnunet_mesh_SOURCES = \
96 gnunet-mesh.c 98 gnunet-mesh.c
97gnunet_mesh_LDADD = \ 99gnunet_mesh_LDADD = \
98 $(top_builddir)/src/mesh/libgnunetmesh.la \ 100 $(top_builddir)/src/mesh/libgnunetmesh.la \
99 $(top_builddir)/src/util/libgnunetutil.la 101 $(top_builddir)/src/util/libgnunetutil.la
@@ -149,7 +151,8 @@ check_PROGRAMS = \
149 test_mesh_small_speed_nobuf \ 151 test_mesh_small_speed_nobuf \
150 test_mesh_small_speed_backwards \ 152 test_mesh_small_speed_backwards \
151 test_mesh_small_speed_nobuf_backwards \ 153 test_mesh_small_speed_nobuf_backwards \
152 test_mesh_small_speed_ack 154 test_mesh_small_speed_ack \
155 $(EXP_TESTS)
153 156
154test_mesh_api_SOURCES = \ 157test_mesh_api_SOURCES = \
155 test_mesh_api.c 158 test_mesh_api.c
@@ -267,8 +270,19 @@ test_mesh_small_speed_nobuf_backwards_LDADD = $(ld_mesh_test_lib)
267test_mesh_small_speed_nobuf_backwards_DEPENDENCIES = $(dep_mesh_test_lib) 270test_mesh_small_speed_nobuf_backwards_DEPENDENCIES = $(dep_mesh_test_lib)
268 271
269 272
273test_mesh2_local_SOURCES = \
274 test_mesh2_local.c
275test_mesh2_local_LDADD = \
276 $(top_builddir)/src/util/libgnunetutil.la \
277 $(top_builddir)/src/testing/libgnunettesting.la \
278 $(top_builddir)/src/mesh/libgnunetmesh2.la
279test_mesh2_local_DEPENDENCIES = \
280 libgnunetmesh2.la
281
270if ENABLE_TEST_RUN 282if ENABLE_TEST_RUN
271TESTS = test_mesh_api \ 283TESTS = \
284 $(EXP_TESTS) \
285 test_mesh_api \
272 test_mesh_tree_api \ 286 test_mesh_tree_api \
273 test_mesh_local_1 test_mesh_local_2 \ 287 test_mesh_local_1 test_mesh_local_2 \
274 test_mesh_local_traffic_fwd \ 288 test_mesh_local_traffic_fwd \
diff --git a/src/mesh/mesh2_api.c b/src/mesh/mesh2_api.c
index 57a5ce1ed..88a013384 100644
--- a/src/mesh/mesh2_api.c
+++ b/src/mesh/mesh2_api.c
@@ -1602,7 +1602,7 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
1602 return th; 1602 return th;
1603 if (GMC_is_pid_bigger(tunnel->next_send_pid, tunnel->max_send_pid)) 1603 if (GMC_is_pid_bigger(tunnel->next_send_pid, tunnel->max_send_pid))
1604 return th; 1604 return th;
1605 LOG (GNUNET_ERROR_TYPE_DEBUG, " call notify tmt rdy\n"); 1605 LOG (GNUNET_ERROR_TYPE_DEBUG, " call client notify tmt rdy\n");
1606 tunnel->mesh->th = 1606 tunnel->mesh->th =
1607 GNUNET_CLIENT_notify_transmit_ready (tunnel->mesh->client, th->size, 1607 GNUNET_CLIENT_notify_transmit_ready (tunnel->mesh->client, th->size,
1608 GNUNET_TIME_UNIT_FOREVER_REL, 1608 GNUNET_TIME_UNIT_FOREVER_REL,
diff --git a/src/mesh/test_mesh2_local.c b/src/mesh/test_mesh2_local.c
new file mode 100644
index 000000000..49ea791e2
--- /dev/null
+++ b/src/mesh/test_mesh2_local.c
@@ -0,0 +1,260 @@
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/**
22 * @file mesh/test_mesh_local_1.c
23 * @brief test mesh local: test of tunnels with just one peer
24 * @author Bartlomiej Polot
25 */
26
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_dht_service.h"
30#include "gnunet_testing_lib.h"
31#include "gnunet_mesh2_service.h"
32
33struct GNUNET_TESTING_Peer *me;
34
35static struct GNUNET_MESH_Handle *mesh_peer_1;
36
37static struct GNUNET_MESH_Handle *mesh_peer_2;
38
39static struct GNUNET_MESH_Tunnel *t;
40
41static int result = GNUNET_OK;
42
43static GNUNET_SCHEDULER_TaskIdentifier abort_task;
44
45static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
46
47
48/**
49 * Shutdown nicely
50 */
51static void
52do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
53{
54 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: shutdown\n");
55 if (0 != abort_task)
56 {
57 GNUNET_SCHEDULER_cancel (abort_task);
58 }
59 if (NULL != t)
60 {
61 GNUNET_MESH_tunnel_destroy(t);
62 }
63 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: D1\n");
64 if (NULL != mesh_peer_1)
65 {
66 GNUNET_MESH_disconnect (mesh_peer_1);
67 }
68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: D2\n");
69 if (NULL != mesh_peer_2)
70 {
71 GNUNET_MESH_disconnect (mesh_peer_2);
72 }
73}
74
75
76/**
77 * Something went wrong and timed out. Kill everything and set error flag
78 */
79static void
80do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
81{
82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: ABORT\n");
83 result = GNUNET_SYSERR;
84 abort_task = 0;
85 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
86 {
87 GNUNET_SCHEDULER_cancel (shutdown_task);
88 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
89 }
90 do_shutdown (cls, tc);
91}
92
93
94/**
95 * Function is called whenever a message is received.
96 *
97 * @param cls closure (set from GNUNET_MESH_connect)
98 * @param tunnel connection to the other end
99 * @param tunnel_ctx place to store local state associated with the tunnel
100 * @param sender who sent the message
101 * @param message the actual message
102 *
103 * @return GNUNET_OK to keep the connection open,
104 * GNUNET_SYSERR to close it (signal serious error)
105 */
106static int
107data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
108 const struct GNUNET_PeerIdentity *sender,
109 const struct GNUNET_MessageHeader *message)
110{
111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Data callback\n");
112 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
113 GNUNET_SCHEDULER_cancel (shutdown_task);
114 shutdown_task =
115 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown,
116 NULL);
117 return GNUNET_OK;
118}
119
120
121/**
122 * Method called whenever another peer has added us to a tunnel
123 * the other peer initiated.
124 *
125 * @param cls closure
126 * @param tunnel new handle to the tunnel
127 * @param initiator peer that started the tunnel
128 * @param port port number
129 * @return initial tunnel context for the tunnel (can be NULL -- that's not an error)
130 */
131static void *
132inbound_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
133 const struct GNUNET_PeerIdentity *initiator,
134 uint32_t port)
135{
136 long id = (long) cls;
137
138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
139 "test: received incoming tunnel on peer %d, port %u\n",
140 id, port);
141 if (id != 1L)
142 {
143 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
144 "test: wrong peer\n");
145 result = GNUNET_SYSERR;
146 }
147 return NULL;
148}
149
150
151/**
152 * Function called whenever an inbound tunnel is destroyed. Should clean up
153 * any associated state.
154 *
155 * @param cls closure (set from GNUNET_MESH_connect)
156 * @param tunnel connection to the other end (henceforth invalid)
157 * @param tunnel_ctx place where local state associated
158 * with the tunnel is stored
159 */
160static void
161inbound_end (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
162 void *tunnel_ctx)
163{
164 unsigned int id = *(unsigned int *) cls;
165
166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: incoming tunnel closed\n");
167 if (id != 1)
168 {
169 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
170 "test: received closing tunnel on peer 2\n");
171 result = GNUNET_SYSERR;
172 }
173}
174
175
176/**
177 * Handler array for traffic received on peer1
178 */
179static struct GNUNET_MESH_MessageHandler handlers1[] = {
180 {&data_callback, 1, 0},
181 {NULL, 0, 0}
182};
183
184
185/**
186 * Handler array for traffic received on peer2 (none expected)
187 */
188static struct GNUNET_MESH_MessageHandler handlers2[] = { {NULL, 0, 0} };
189
190
191/**
192 * Start looking for a peer by type
193 */
194static void
195do_find (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
196{
197 struct GNUNET_PeerIdentity id;
198
199 GNUNET_TESTING_peer_get_identity (me, &id);
200 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: CONNECT BY TYPE\n");
201 t = GNUNET_MESH_tunnel_create (mesh_peer_1, NULL, &id, 1);
202}
203
204
205/**
206 * Initialize framework and start test
207 */
208static void
209run (void *cls,
210 const struct GNUNET_CONFIGURATION_Handle *cfg,
211 struct GNUNET_TESTING_Peer *peer)
212{
213 static uint32_t ports[] = {1, 0};
214
215 me = peer;
216 abort_task =
217 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
218 (GNUNET_TIME_UNIT_SECONDS, 20), &do_abort,
219 NULL);
220 mesh_peer_1 = GNUNET_MESH_connect (cfg, /* configuration */
221 (void *) 1L, /* cls */
222 &inbound_tunnel, /* inbound new hndlr */
223 &inbound_end, /* inbound end hndlr */
224 handlers1, /* traffic handlers */
225 NULL); /* ports offered */
226
227 mesh_peer_2 = GNUNET_MESH_connect (cfg, /* configuration */
228 (void *) 2L, /* cls */
229 &inbound_tunnel, /* inbound new hndlr */
230 &inbound_end, /* inbound end hndlr */
231 handlers2, /* traffic handlers */
232 ports); /* ports offered */
233 if (NULL == mesh_peer_1 || NULL == mesh_peer_2)
234 {
235 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "test: Couldn't connect to mesh :(\n");
236 result = GNUNET_SYSERR;
237 return;
238 }
239 else
240 {
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: YAY! CONNECTED TO MESH :D\n");
242 }
243 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_find, NULL);
244}
245
246
247/**
248 * Main
249 */
250int
251main (int argc, char *argv[])
252{
253 if (0 != GNUNET_TESTING_peer_run ("test-mesh-local-1",
254 "test_mesh.conf",
255 &run, NULL))
256 return 1;
257 return (result == GNUNET_OK) ? 0 : 1;
258}
259
260/* end of test_mesh_local_1.c */