aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2012-01-24 17:05:04 +0000
committerBart Polot <bart@net.in.tum.de>2012-01-24 17:05:04 +0000
commita97329c6445c3b0b32f61cfd2030734e9998de66 (patch)
tree97cad60cf4e5bd582e15f7bb400a81cad616d65b /src/mesh
parent772d8465381449e08878c0f226994c01f27c35dc (diff)
downloadgnunet-a97329c6445c3b0b32f61cfd2030734e9998de66.tar.gz
gnunet-a97329c6445c3b0b32f61cfd2030734e9998de66.zip
- Added initial speed test, fixed minor bugs
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/Makefile.am24
-rw-r--r--src/mesh/test_mesh_small.c156
-rw-r--r--src/mesh/test_mesh_small.conf5
3 files changed, 172 insertions, 13 deletions
diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am
index 610353610..4656d9824 100644
--- a/src/mesh/Makefile.am
+++ b/src/mesh/Makefile.am
@@ -50,7 +50,9 @@ check_PROGRAMS = \
50 test_mesh_local_2 \ 50 test_mesh_local_2 \
51 test_mesh_2dtorus \ 51 test_mesh_2dtorus \
52 test_mesh_small_unicast \ 52 test_mesh_small_unicast \
53 test_mesh_small_multicast 53 test_mesh_small_multicast \
54 test_mesh_small_speed \
55 test_mesh_small_speed_ack
54 56
55test_mesh_api_SOURCES = \ 57test_mesh_api_SOURCES = \
56 test_mesh_api.c 58 test_mesh_api.c
@@ -110,9 +112,27 @@ test_mesh_small_multicast_LDADD = \
110test_mesh_small_multicast_DEPENDENCIES = \ 112test_mesh_small_multicast_DEPENDENCIES = \
111 libgnunetmesh.la 113 libgnunetmesh.la
112 114
115test_mesh_small_speed_SOURCES = \
116 test_mesh_small.c
117test_mesh_small_speed_LDADD = \
118 $(top_builddir)/src/mesh/libgnunetmesh.la \
119 $(top_builddir)/src/util/libgnunetutil.la \
120 $(top_builddir)/src/testing/libgnunettesting.la
121test_mesh_small_speed_DEPENDENCIES = \
122 libgnunetmesh.la
123
124test_mesh_small_speed_ack_SOURCES = \
125 test_mesh_small.c
126test_mesh_small_speed_ack_LDADD = \
127 $(top_builddir)/src/mesh/libgnunetmesh.la \
128 $(top_builddir)/src/util/libgnunetutil.la \
129 $(top_builddir)/src/testing/libgnunettesting.la
130test_mesh_small_speed_ack_DEPENDENCIES = \
131 libgnunetmesh.la
113 132
114if ENABLE_TEST_RUN 133if ENABLE_TEST_RUN
115TESTS = test_mesh_api test_mesh_tree_api test_mesh_local_1 test_mesh_local_2 test_mesh_2dtorus test_mesh_small_unicast test_mesh_small_multicast 134TESTS = test_mesh_api test_mesh_tree_api test_mesh_local_1 test_mesh_local_2 \
135 test_mesh_2dtorus test_mesh_small_unicast test_mesh_small_multicast
116endif 136endif
117 137
118EXTRA_DIST = \ 138EXTRA_DIST = \
diff --git a/src/mesh/test_mesh_small.c b/src/mesh/test_mesh_small.c
index 9e28e6638..bac494cd6 100644
--- a/src/mesh/test_mesh_small.c
+++ b/src/mesh/test_mesh_small.c
@@ -63,6 +63,8 @@ struct StatsContext
63#define SETUP 0 63#define SETUP 0
64#define UNICAST 1 64#define UNICAST 1
65#define MULTICAST 2 65#define MULTICAST 2
66#define SPEED 3
67#define SPEED_ACK 4
66 68
67/** 69/**
68 * Which test are we running? 70 * Which test are we running?
@@ -78,6 +80,12 @@ static int peers_in_tunnel;
78 80
79static int peers_responded; 81static int peers_responded;
80 82
83static int data_sent;
84
85static int data_received;
86
87static int data_ack;
88
81/** 89/**
82 * Be verbose 90 * Be verbose
83 */ 91 */
@@ -160,6 +168,11 @@ static struct GNUNET_MESH_Tunnel *incoming_t;
160 168
161static struct GNUNET_MESH_Tunnel *incoming_t2; 169static struct GNUNET_MESH_Tunnel *incoming_t2;
162 170
171static struct GNUNET_TIME_Absolute start_time;
172
173static struct GNUNET_TIME_Absolute end_time;
174
175
163static uint16_t *mesh_peers; 176static uint16_t *mesh_peers;
164 177
165/** 178/**
@@ -186,6 +199,9 @@ shutdown_callback (void *cls, const char *emsg)
186} 199}
187 200
188 201
202/**
203 * Shut down peergroup, clean up.
204 */
189static void 205static void
190shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 206shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
191{ 207{
@@ -207,6 +223,9 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
207} 223}
208 224
209 225
226/**
227 * Disconnect from mesh services af all peers, call shutdown.
228 */
210static void 229static void
211disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 230disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
212{ 231{
@@ -224,9 +243,48 @@ disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
224 } 243 }
225} 244}
226 245
246size_t
247tmt_rdy (void *cls, size_t size, void *buf);
248
249static void
250data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
251{
252 struct GNUNET_MESH_TransmitHandle *th;
253 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
254 return;
255 th = GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO, 0,
256 GNUNET_TIME_UNIT_FOREVER_REL, &d2->id,
257 sizeof (struct GNUNET_MessageHeader),
258 &tmt_rdy, (void *) 1L);
259 if (NULL == th)
260 {
261 unsigned long i = (unsigned long) cls;
262
263 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Retransmission\n");
264 if (0 == i)
265 {
266 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " in 1 ms\n");
267 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
268 &data_task, (void *)1UL);
269 }
270 else
271 {
272 i++;
273 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "in %u ms\n", i);
274 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
275 GNUNET_TIME_UNIT_MILLISECONDS,
276 i),
277 &data_task, (void *)i);
278 }
279 }
280}
227 281
228/** 282/**
229 * Transmit ready callback 283 * Transmit ready callback
284 *
285 * @param cls Closure.
286 * @param size Size of the buffer we have.
287 * @param buf Buffer to copy data to.
230 */ 288 */
231size_t 289size_t
232tmt_rdy (void *cls, size_t size, void *buf) 290tmt_rdy (void *cls, size_t size, void *buf)
@@ -239,6 +297,16 @@ tmt_rdy (void *cls, size_t size, void *buf)
239 return 0; 297 return 0;
240 msg->size = htons (sizeof (struct GNUNET_MessageHeader)); 298 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
241 msg->type = htons ((long) cls); 299 msg->type = htons ((long) cls);
300 if (test == SPEED)
301 {
302 data_sent++;
303 if (data_sent < 1000)
304 {
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
306 "***************** test: Scheduling %d packet\n", data_sent);
307 GNUNET_SCHEDULER_add_now(&data_task, NULL);
308 }
309 }
242 return sizeof (struct GNUNET_MessageHeader); 310 return sizeof (struct GNUNET_MessageHeader);
243} 311}
244 312
@@ -270,6 +338,7 @@ data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
270 "***************** test: Origin client got a response!\n"); 338 "***************** test: Origin client got a response!\n");
271 ok++; 339 ok++;
272 peers_responded++; 340 peers_responded++;
341 data_ack++;
273 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) 342 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
274 { 343 {
275 GNUNET_SCHEDULER_cancel (disconnect_task); 344 GNUNET_SCHEDULER_cancel (disconnect_task);
@@ -279,7 +348,29 @@ data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
279 } 348 }
280 if (test == MULTICAST && peers_responded < 2) 349 if (test == MULTICAST && peers_responded < 2)
281 return GNUNET_OK; 350 return GNUNET_OK;
351 if (test == SPEED_ACK)
352 {
353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
354 "***************** test: received ack %u\n", data_ack);
355 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, 0,
356 GNUNET_TIME_UNIT_FOREVER_REL, sender,
357 sizeof (struct GNUNET_MessageHeader),
358 &tmt_rdy, (void *) 1L);
359 if (data_ack < 1000)
360 return GNUNET_OK;
361 end_time = GNUNET_TIME_absolute_get();
362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
363 "***************** test time %u ms\n",
364 GNUNET_TIME_absolute_get_difference(start_time, end_time).rel_value);
365 }
282 GNUNET_MESH_tunnel_destroy (tunnel); 366 GNUNET_MESH_tunnel_destroy (tunnel);
367 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
368 {
369 GNUNET_SCHEDULER_cancel (disconnect_task);
370 disconnect_task =
371 GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers,
372 NULL);
373 }
283 break; 374 break;
284 case 2L: 375 case 2L:
285 case 3L: 376 case 3L:
@@ -287,10 +378,21 @@ data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
287 "***************** test: Destination client %u got a message.\n", 378 "***************** test: Destination client %u got a message.\n",
288 client); 379 client);
289 ok++; 380 ok++;
290 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, 0, 381 if (SPEED != test)
291 GNUNET_TIME_UNIT_FOREVER_REL, sender, 382 {
292 sizeof (struct GNUNET_MessageHeader), 383 GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, 0,
293 &tmt_rdy, (void *) 1L); 384 GNUNET_TIME_UNIT_FOREVER_REL, sender,
385 sizeof (struct GNUNET_MessageHeader),
386 &tmt_rdy, (void *) 1L);
387 }
388 else
389 {
390 data_received++;
391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
392 "***************** test: received data %u\n", data_received);
393 if (data_received < 1000)
394 return GNUNET_OK;
395 }
294 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) 396 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
295 { 397 {
296 GNUNET_SCHEDULER_cancel (disconnect_task); 398 GNUNET_SCHEDULER_cancel (disconnect_task);
@@ -427,6 +529,8 @@ ch (void *cls, const struct GNUNET_PeerIdentity *peer,
427 switch (test) 529 switch (test)
428 { 530 {
429 case UNICAST: 531 case UNICAST:
532 case SPEED:
533 case SPEED_ACK:
430 dest = &d2->id; 534 dest = &d2->id;
431 break; 535 break;
432 case MULTICAST: 536 case MULTICAST:
@@ -446,6 +550,10 @@ ch (void *cls, const struct GNUNET_PeerIdentity *peer,
446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
447 "***************** test: Sending data...\n"); 551 "***************** test: Sending data...\n");
448 peers_responded = 0; 552 peers_responded = 0;
553 data_ack = 0;
554 data_received = 0;
555 data_sent = 0;
556 start_time = GNUNET_TIME_absolute_get();
449 GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO, 0, 557 GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO, 0,
450 GNUNET_TIME_UNIT_FOREVER_REL, dest, 558 GNUNET_TIME_UNIT_FOREVER_REL, dest,
451 sizeof (struct GNUNET_MessageHeader), 559 sizeof (struct GNUNET_MessageHeader),
@@ -595,9 +703,9 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
595 GNUNET_i2s (&d3->id), i); 703 GNUNET_i2s (&d3->id), i);
596 } 704 }
597#endif 705#endif
598 h1 = GNUNET_MESH_connect (d1->cfg, 10, (void *) 1L, NULL, &tunnel_cleaner, 706 h1 = GNUNET_MESH_connect (d1->cfg, 5, (void *) 1L, NULL, &tunnel_cleaner,
599 handlers, &app); 707 handlers, &app);
600 h2 = GNUNET_MESH_connect (d2->cfg, 10, (void *) 2L, &incoming_tunnel, 708 h2 = GNUNET_MESH_connect (d2->cfg, 5, (void *) 2L, &incoming_tunnel,
601 &tunnel_cleaner, handlers, &app); 709 &tunnel_cleaner, handlers, &app);
602 if (test == MULTICAST) 710 if (test == MULTICAST)
603 { 711 {
@@ -849,7 +957,7 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = {
849int 957int
850main (int argc, char *argv[]) 958main (int argc, char *argv[])
851{ 959{
852 char *const argv2[] = { 960 char * argv2[] = {
853 argv[0], 961 argv[0],
854 "-c", 962 "-c",
855 "test_mesh_small.conf", 963 "test_mesh_small.conf",
@@ -859,6 +967,7 @@ main (int argc, char *argv[])
859#endif 967#endif
860 NULL 968 NULL
861 }; 969 };
970 int argc2 = (sizeof (argv2) / sizeof (char *)) - 1;
862 971
863 /* Each peer is supposed to generate the following callbacks: 972 /* Each peer is supposed to generate the following callbacks:
864 * 1 incoming tunnel (@dest) 973 * 1 incoming tunnel (@dest)
@@ -884,6 +993,37 @@ main (int argc, char *argv[])
884 test = MULTICAST; 993 test = MULTICAST;
885 ok_goal = 10; 994 ok_goal = 10;
886 } 995 }
996 else if (strstr (argv[0], "test_mesh_small_speed_ack") != NULL)
997 {
998 /* Each peer is supposed to generate the following callbacks:
999 * 1 incoming tunnel (@dest)
1000 * 1 connected peer (@orig)
1001 * 1000 received data packet (@dest)
1002 * 1000 received data packet (@orig)
1003 * 1 received tunnel destroy (@dest)
1004 * _________________________________
1005 * 5 x ok expected per peer
1006 */
1007 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: SPEED_ACK\n");
1008 test = SPEED_ACK;
1009 ok_goal = 2003;
1010 argv2 [3] = NULL; // remove -L DEBUG
1011 argc2 -= 2;
1012 }
1013 else if (strstr (argv[0], "test_mesh_small_speed") != NULL)
1014 {
1015 /* Each peer is supposed to generate the following callbacks:
1016 * 1 incoming tunnel (@dest)
1017 * 1 connected peer (@orig)
1018 * 1000 received data packet (@dest)
1019 * 1 received tunnel destroy (@dest)
1020 * _________________________________
1021 * 5 x ok expected per peer
1022 */
1023 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: SPEED\n");
1024 test = SPEED;
1025 ok_goal = 1003;
1026 }
887 else 1027 else
888 { 1028 {
889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: UNKNOWN\n"); 1029 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "***************** test: UNKNOWN\n");
@@ -891,7 +1031,7 @@ main (int argc, char *argv[])
891 ok_goal = 0; 1031 ok_goal = 0;
892 } 1032 }
893 1033
894 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, 1034 GNUNET_PROGRAM_run (argc2, argv2,
895 "test_mesh_small", 1035 "test_mesh_small",
896 gettext_noop ("Test mesh in a small network."), options, 1036 gettext_noop ("Test mesh in a small network."), options,
897 &run, NULL); 1037 &run, NULL);
diff --git a/src/mesh/test_mesh_small.conf b/src/mesh/test_mesh_small.conf
index 0aec8ff7f..9f524db30 100644
--- a/src/mesh/test_mesh_small.conf
+++ b/src/mesh/test_mesh_small.conf
@@ -53,7 +53,7 @@ PORT = 10004
53 53
54[mesh] 54[mesh]
55PORT = 10005 55PORT = 10005
56DEBUG=YES 56DEBUG=NO
57ACCEPT_FROM = 127.0.0.1; 57ACCEPT_FROM = 127.0.0.1;
58HOSTNAME = localhost 58HOSTNAME = localhost
59# PREFIX = valgrind --leak-check=full --suppressions=valgrind-mesh.supp 59# PREFIX = valgrind --leak-check=full --suppressions=valgrind-mesh.supp
@@ -62,10 +62,9 @@ HOSTNAME = localhost
62[testing] 62[testing]
63NUM_PEERS = 16 63NUM_PEERS = 16
64WEAKRANDOM = YES 64WEAKRANDOM = YES
65TOPOLOGY = 2D_TORUS 65TOPOLOGY = NONE
66CONNECT_TOPOLOGY = 2D_TORUS 66CONNECT_TOPOLOGY = 2D_TORUS
67#TOPOLOGY_FILE = small.dat 67#TOPOLOGY_FILE = small.dat
68CONNECT_TOPOLOGY = 2D_TORUS
69#CONNECT_TOPOLOGY_OPTION = CONNECT_MINIMUM 68#CONNECT_TOPOLOGY_OPTION = CONNECT_MINIMUM
70#CONNECT_TOPOLOGY_OPTION_MODIFIER = 25 69#CONNECT_TOPOLOGY_OPTION_MODIFIER = 25
71#PERCENTAGE = 3 70#PERCENTAGE = 3