- fixes, debug
[oweals/gnunet.git] / src / mesh / test_mesh2_small.c
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_mesh2_small.c
22  *
23  * @brief Test for the mesh service: retransmission of traffic.
24  */
25 #include <stdio.h>
26 #include "platform.h"
27 #include "mesh2_test_lib.h"
28 #include "gnunet_mesh2_service.h"
29 #include <gauger.h>
30
31
32 /**
33  * How namy messages to send
34  */
35 #define TOTAL_PACKETS 1000
36
37 /**
38  * How long until we give up on connecting the peers?
39  */
40 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
41
42 /**
43  * Time to wait for stuff that should be rather fast
44  */
45 #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
46
47 /**
48  * DIFFERENT TESTS TO RUN
49  */
50 #define SETUP 0
51 #define FORWARD 1
52 #define SPEED 3
53 #define SPEED_ACK 4
54 #define SPEED_NOBUF 6
55 #define P2P_SIGNAL 10
56
57 /**
58  * Which test are we running?
59  */
60 static int test;
61
62 /**
63  * String with test name
64  */
65 char *test_name;
66
67 /**
68  * Flag to send traffic leaf->root in speed tests to test BCK_ACK logic.
69  */
70 static int test_backwards = GNUNET_NO;
71
72 /**
73  * How many events have happened
74  */
75 static int ok;
76
77  /**
78   * Each peer is supposed to generate the following callbacks:
79   * 1 incoming tunnel (@dest)
80   * 1 connected peer (@orig)
81   * 1 received data packet (@dest)
82   * 1 received data packet (@orig)
83   * 1 received tunnel destroy (@dest)
84   * _________________________________
85   * 5 x ok expected per peer
86   */
87 int ok_goal;
88
89
90 /**
91  * Size of each test packet
92  */
93 size_t size_payload = sizeof (struct GNUNET_MessageHeader) + sizeof (uint32_t);
94
95 /**
96  * Operation to get peer ids.
97  */
98 struct GNUNET_TESTBED_Operation *t_op[2];
99
100 /**
101  * Peer ids.
102  */
103 struct GNUNET_PeerIdentity *p_id[2];
104
105 /**
106  * Peer ids counter.
107  */
108 unsigned int p_ids;
109
110 /**
111  * Is the setup initialized?
112  */
113 static int initialized;
114
115 /**
116  * Peers that have responded
117  */
118 static int peers_responded;
119
120 /**
121  * Number of payload packes sent
122  */
123 static int data_sent;
124
125 /**
126  * Number of payload packets received
127  */
128 static int data_received;
129
130 /**
131  * Number of payload packed explicitly (app level) acknowledged
132  */
133 static int data_ack;
134
135 /**
136  * Total number of currently running peers.
137  */
138 static unsigned long long peers_running;
139
140 /**
141  * Test context (to shut down).
142  */
143 struct GNUNET_MESH_TEST_Context *test_ctx;
144
145 /**
146  * Task called to disconnect peers.
147  */
148 static GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
149
150 /**
151  * Task To perform tests
152  */
153 static GNUNET_SCHEDULER_TaskIdentifier test_task;
154
155 /**
156  * Task called to shutdown test.
157  */
158 static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle;
159
160 /**
161  * Mesh handle for the root peer
162  */
163 static struct GNUNET_MESH_Handle *h1;
164
165 /**
166  * Mesh handle for the first leaf peer
167  */
168 static struct GNUNET_MESH_Handle *h2;
169
170 /**
171  * Tunnel handle for the root peer
172  */
173 static struct GNUNET_MESH_Tunnel *t;
174
175 /**
176  * Tunnel handle for the first leaf peer
177  */
178 static struct GNUNET_MESH_Tunnel *incoming_t;
179
180 /**
181  * Time we started the data transmission (after tunnel has been established
182  * and initilized).
183  */
184 static struct GNUNET_TIME_Absolute start_time;
185
186
187 /**
188  * Show the results of the test (banwidth acheived) and log them to GAUGER
189  */
190 static void
191 show_end_data (void)
192 {
193   static struct GNUNET_TIME_Absolute end_time;
194   static struct GNUNET_TIME_Relative total_time;
195
196   end_time = GNUNET_TIME_absolute_get();
197   total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time);
198   FPRINTF (stderr, "\nResults of test \"%s\"\n", test_name);
199   FPRINTF (stderr, "Test time %llu ms\n",
200             (unsigned long long) total_time.rel_value);
201   FPRINTF (stderr, "Test bandwidth: %f kb/s\n",
202             4 * TOTAL_PACKETS * 1.0 / total_time.rel_value); // 4bytes * ms
203   FPRINTF (stderr, "Test throughput: %f packets/s\n\n",
204             TOTAL_PACKETS * 1000.0 / total_time.rel_value); // packets * ms
205   GAUGER ("MESH", test_name,
206           TOTAL_PACKETS * 1000.0 / total_time.rel_value,
207           "packets/s");
208 }
209
210
211 /**
212  * Shut down peergroup, clean up.
213  * 
214  * @param cls Closure (unused).
215  * @param tc Task Context.
216  */
217 static void
218 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
219 {
220   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");
221   shutdown_handle = GNUNET_SCHEDULER_NO_TASK;
222 }
223
224
225 /**
226  * Disconnect from mesh services af all peers, call shutdown.
227  * 
228  * @param cls Closure (unused).
229  * @param tc Task Context.
230  */
231 static void
232 disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
233 {
234   long line = (long) cls;
235   unsigned int i;
236
237   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
238               "disconnecting mesh service of peers, called from line %ld\n",
239               line);
240   disconnect_task = GNUNET_SCHEDULER_NO_TASK;
241   for (i = 0; i < 2; i++)
242   {
243     GNUNET_TESTBED_operation_done (t_op[i]);
244   }
245   if (NULL != t)
246   {
247     GNUNET_MESH_tunnel_destroy (t);
248     t = NULL;
249   }
250   if (NULL != incoming_t)
251   {
252     GNUNET_MESH_tunnel_destroy (incoming_t);
253     incoming_t = NULL;
254   }
255   GNUNET_MESH_TEST_cleanup (test_ctx);
256   if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle)
257   {
258     GNUNET_SCHEDULER_cancel (shutdown_handle);
259   }
260   shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
261 }
262
263
264 /**
265  * Abort test: schedule disconnect and shutdown immediately
266  * 
267  * @param line Line in the code the abort is requested from (__LINE__).
268  */
269 static void
270 abort_test (long line)
271 {
272   if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
273   {
274     GNUNET_SCHEDULER_cancel (disconnect_task);
275     disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers,
276                                                 (void *) line);
277   }
278 }
279
280 /**
281  * Transmit ready callback.
282  * 
283  * @param cls Closure (message type).
284  * @param size Size of the tranmist buffer.
285  * @param buf Pointer to the beginning of the buffer.
286  * 
287  * @return Number of bytes written to buf.
288  */
289 static size_t
290 tmt_rdy (void *cls, size_t size, void *buf);
291
292
293 /**
294  * Task to schedule a new data transmission.
295  * 
296  * @param cls Closure (peer #).
297  * @param tc Task Context.
298  */
299 static void
300 data_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
301 {
302   struct GNUNET_MESH_TransmitHandle *th;
303   struct GNUNET_MESH_Tunnel *tunnel;
304
305   if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
306     return;
307
308   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data task\n");
309   if (GNUNET_YES == test_backwards)
310   {
311     tunnel = incoming_t;
312   }
313   else
314   {
315     tunnel = t;
316   }
317   th = GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
318                                           GNUNET_TIME_UNIT_FOREVER_REL,
319                                           size_payload, &tmt_rdy, (void *) 1L);
320   if (NULL == th)
321   {
322     unsigned long i = (unsigned long) cls;
323
324     GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Retransmission\n");
325     if (0 == i)
326     {
327       GNUNET_log (GNUNET_ERROR_TYPE_INFO, "  in 1 ms\n");
328       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
329                                     &data_task, (void *)1UL);
330     }
331     else
332     {
333       i++;
334       GNUNET_log (GNUNET_ERROR_TYPE_INFO, "in %u ms\n", i);
335       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
336                                       GNUNET_TIME_UNIT_MILLISECONDS,
337                                       i),
338                                     &data_task, (void *)i);
339     }
340   }
341 }
342
343
344 /**
345  * Transmit ready callback
346  *
347  * @param cls Closure (message type).
348  * @param size Size of the buffer we have.
349  * @param buf Buffer to copy data to.
350  */
351 size_t
352 tmt_rdy (void *cls, size_t size, void *buf)
353 {
354   struct GNUNET_MessageHeader *msg = buf;
355   uint32_t *data;
356
357   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
358               " tmt_rdy called\n");
359   if (size < size_payload || NULL == buf)
360   {
361     GNUNET_break (0);
362     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
363                 "size %u, buf %p, data_sent %u, data_received %u\n",
364                 size,
365                 buf,
366                 data_sent,
367                 data_received);
368     return 0;
369   }
370   msg->size = htons (size);
371   msg->type = htons ((long) cls);
372   data = (uint32_t *) &msg[1];
373   *data = htonl (data_sent);
374   if (SPEED == test && GNUNET_YES == initialized)
375   {
376     data_sent++;
377     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
378               " Sent packet %d\n", data_sent);
379     if (data_sent < TOTAL_PACKETS)
380     {
381       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
382               " Scheduling packet %d\n", data_sent + 1);
383       GNUNET_SCHEDULER_add_now(&data_task, NULL);
384     }
385   }
386   return size_payload;
387 }
388
389
390 /**
391  * Function is called whenever a message is received.
392  *
393  * @param cls closure (set from GNUNET_MESH_connect)
394  * @param tunnel connection to the other end
395  * @param tunnel_ctx place to store local state associated with the tunnel
396  * @param sender who sent the message
397  * @param message the actual message
398  * @return GNUNET_OK to keep the connection open,
399  *         GNUNET_SYSERR to close it (signal serious error)
400  */
401 int
402 data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx,
403                const struct GNUNET_PeerIdentity *sender,
404                const struct GNUNET_MessageHeader *message)
405 {
406   long client = (long) cls;
407   long expected_target_client;
408   uint32_t *data;
409
410   ok++;
411
412   GNUNET_MESH_receive_done (tunnel);
413
414   if ((ok % 20) == 0)
415   {
416     if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
417     {
418       GNUNET_SCHEDULER_cancel (disconnect_task);
419       disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
420                                                       &disconnect_mesh_peers,
421                                                       (void *) __LINE__);
422     }
423   }
424
425   switch (client)
426   {
427   case 0L:
428     GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Root client got a message!\n");
429     peers_responded++;
430     break;
431   case 4L:
432     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
433                 "Leaf client %li got a message.\n",
434                 client);
435     client = 4L;
436     break;
437   default:
438     GNUNET_assert (0);
439     break;
440   }
441   GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: (%d/%d)\n", ok, ok_goal);
442   data = (uint32_t *) &message[1];
443   GNUNET_log (GNUNET_ERROR_TYPE_INFO, " payload: (%u)\n", ntohl (*data));
444   if (SPEED == test && GNUNET_YES == test_backwards)
445   {
446     expected_target_client = 0L;
447   }
448   else
449   {
450     expected_target_client = 4L;
451   }
452
453   if (GNUNET_NO == initialized)
454   {
455     initialized = GNUNET_YES;
456     start_time = GNUNET_TIME_absolute_get ();
457     if (SPEED == test)
458     {
459       GNUNET_assert (4L == client);
460       GNUNET_SCHEDULER_add_now (&data_task, NULL);
461       return GNUNET_OK;
462     }
463   }
464
465   if (client == expected_target_client) // Normally 3 or 4
466   {
467     data_received++;
468     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
469                 " received data %u\n", data_received);
470     if (SPEED != test || (ok_goal - 2) == ok)
471     {
472       GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
473                                          GNUNET_TIME_UNIT_FOREVER_REL,
474                                          size_payload, &tmt_rdy, (void *) 1L);
475       return GNUNET_OK;
476     }
477     else
478     {
479       if (data_received < TOTAL_PACKETS)
480         return GNUNET_OK;
481     }
482   }
483   else // Normally 0
484   {
485     if (test == SPEED_ACK || test == SPEED)
486     {
487       data_ack++;
488       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
489               " received ack %u\n", data_ack);
490       GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO,
491                                          GNUNET_TIME_UNIT_FOREVER_REL,
492                                          size_payload, &tmt_rdy, (void *) 1L);
493       if (data_ack < TOTAL_PACKETS && SPEED != test)
494         return GNUNET_OK;
495       if (ok == 2 && SPEED == test)
496         return GNUNET_OK;
497       show_end_data();
498     }
499     if (test == P2P_SIGNAL)
500     {
501       GNUNET_MESH_tunnel_destroy (incoming_t);
502       incoming_t = NULL;
503     }
504     else
505     {
506       GNUNET_MESH_tunnel_destroy (t);
507       t = NULL;
508     }
509   }
510
511   if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
512   {
513     GNUNET_SCHEDULER_cancel (disconnect_task);
514     disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
515                                                     &disconnect_mesh_peers,
516                                                     (void *) __LINE__);
517   }
518
519   return GNUNET_OK;
520 }
521
522
523 /**
524  * Handlers, for diverse services
525  */
526 static struct GNUNET_MESH_MessageHandler handlers[] = {
527   {&data_callback, 1, sizeof (struct GNUNET_MessageHeader)},
528   {NULL, 0, 0}
529 };
530
531
532 /**
533  * Method called whenever another peer has added us to a tunnel
534  * the other peer initiated.
535  *
536  * @param cls Closure.
537  * @param tunnel New handle to the tunnel.
538  * @param initiator Peer that started the tunnel.
539  * @param port Port this tunnels is connected to.
540  * @return Initial tunnel context for the tunnel
541  *         (can be NULL -- that's not an error).
542  */
543 static void *
544 incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
545                  const struct GNUNET_PeerIdentity *initiator,
546                  uint32_t port)
547 {
548   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
549               "Incoming tunnel from %s to peer %d\n",
550               GNUNET_i2s (initiator), (long) cls);
551   ok++;
552   GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
553   if ((long) cls == 4L)
554     incoming_t = tunnel;
555   else
556   {
557     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
558                 "Incoming tunnel for unknown client %lu\n", (long) cls);
559     GNUNET_break(0);
560   }
561   if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
562   {
563     GNUNET_SCHEDULER_cancel (disconnect_task);
564     disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
565                                                     &disconnect_mesh_peers,
566                                                     (void *) __LINE__);
567   }
568
569   return NULL;
570 }
571
572 /**
573  * Function called whenever an inbound tunnel is destroyed.  Should clean up
574  * any associated state.
575  *
576  * @param cls closure (set from GNUNET_MESH_connect)
577  * @param tunnel connection to the other end (henceforth invalid)
578  * @param tunnel_ctx place where local state associated
579  *                   with the tunnel is stored
580  */
581 static void
582 tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
583                 void *tunnel_ctx)
584 {
585   long i = (long) cls;
586
587   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
588               "Incoming tunnel disconnected at peer %d\n",
589               i);
590   if (4L == i)
591   {
592     ok++;
593     incoming_t = NULL;
594   }
595   else if (0L == i && P2P_SIGNAL == test)
596   {
597     ok ++;
598   }
599   else
600     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
601                 "Unknown peer! %d\n", i);
602   GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
603
604   if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
605   {
606     GNUNET_SCHEDULER_cancel (disconnect_task);
607     disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers,
608                                                 (void *) __LINE__);
609   }
610
611   return;
612 }
613
614
615 /**
616  * START THE TESTCASE ITSELF, AS WE ARE CONNECTED TO THE MESH SERVICES.
617  * 
618  * Testcase continues when the root receives confirmation of connected peers,
619  * on callback funtion ch.
620  * 
621  * @param cls Closure (unsued).
622  * @param tc Task Context.
623  */
624 static void
625 do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
626 {
627   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test_task\n");
628   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "add peer 2\n");
629
630   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
631               "schedule timeout in TIMEOUT\n");
632   if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
633   {
634     GNUNET_SCHEDULER_cancel (disconnect_task);
635   }
636   t = GNUNET_MESH_tunnel_create (h1, NULL, p_id[1], 1);
637   if (SPEED_NOBUF == test)
638   {
639     GNUNET_MESH_tunnel_buffer(t, GNUNET_NO);
640     test = SPEED;
641   }
642
643   disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
644                                                   &disconnect_mesh_peers,
645                                                   (void *) __LINE__);
646   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
647               "Sending data initializer...\n");
648   peers_responded = 0;
649   data_ack = 0;
650   data_received = 0;
651   data_sent = 0;
652   GNUNET_MESH_notify_transmit_ready (t, GNUNET_NO,
653                                      GNUNET_TIME_UNIT_FOREVER_REL, 
654                                      size_payload, &tmt_rdy, (void *) 1L);
655 }
656
657 /**
658  * Callback to be called when the requested peer information is available
659  *
660  * @param cls the closure from GNUNET_TESTBED_peer_get_information()
661  * @param op the operation this callback corresponds to
662  * @param pinfo the result; will be NULL if the operation has failed
663  * @param emsg error message if the operation has failed;
664  *             NULL if the operation is successfull
665  */
666 static void
667 pi_cb (void *cls,
668        struct GNUNET_TESTBED_Operation *op,
669        const struct GNUNET_TESTBED_PeerInformation *pinfo,
670        const char *emsg)
671 {
672   long i = (long) cls;
673
674   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "id callback for %ld\n", i);
675
676   if (NULL == pinfo || NULL != emsg)
677   {
678     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "pi_cb: %s\n", emsg);
679     abort_test (__LINE__);
680     return;
681   }
682   p_id[i] = pinfo->result.id;
683   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  id: %s\n", GNUNET_i2s (p_id[i]));
684   p_ids++;
685   if (p_ids < 2)
686     return;
687   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got all IDs, starting test\n");
688   test_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
689                                             &do_test, NULL);
690 }
691
692 /**
693  * test main: start test when all peers are connected
694  *
695  * @param cls Closure.
696  * @param ctx Argument to give to GNUNET_MESH_TEST_cleanup on test end.
697  * @param num_peers Number of peers that are running.
698  * @param peers Array of peers.
699  * @param meshes Handle to each of the MESHs of the peers.
700  */
701 static void
702 tmain (void *cls,
703        struct GNUNET_MESH_TEST_Context *ctx,
704        unsigned int num_peers,
705        struct GNUNET_TESTBED_Peer **peers,
706        struct GNUNET_MESH_Handle **meshes)
707 {
708   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test main\n");
709   ok = 0;
710   test_ctx = ctx;
711   peers_running = num_peers;
712   h1 = meshes[0];
713   h2 = meshes[num_peers - 1];
714   disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
715                                                   &disconnect_mesh_peers,
716                                                   (void *) __LINE__);
717   shutdown_handle = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
718                                                   &shutdown_task, NULL);
719   t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0],
720                                                  GNUNET_TESTBED_PIT_IDENTITY,
721                                                  &pi_cb, (void *) 0L);
722   t_op[1] = GNUNET_TESTBED_peer_get_information (peers[num_peers - 1],
723                                                  GNUNET_TESTBED_PIT_IDENTITY,
724                                                  &pi_cb, (void *) 1L);
725   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requested peer ids\n");
726 }
727
728
729 /**
730  * Main: start test
731  */
732 int
733 main (int argc, char *argv[])
734 {
735   initialized = GNUNET_NO;
736
737   GNUNET_log_setup ("test", "DEBUG", NULL);
738
739   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start\n");
740   if (strstr (argv[0], "test_mesh2_small_forward") != NULL)
741   {
742     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "FORWARD\n");
743     test = FORWARD;
744     test_name = "unicast2";
745     ok_goal = 4;
746   }
747   else if (strstr (argv[0], "test_mesh_small_signal") != NULL)
748   {
749     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SIGNAL\n");
750     test = P2P_SIGNAL;
751     test_name = "signal2";
752     ok_goal = 4;
753   }
754   else if (strstr (argv[0], "test_mesh_small_speed_ack") != NULL)
755   {
756    /* Each peer is supposed to generate the following callbacks:
757     * 1 incoming tunnel (@dest)
758     * TOTAL_PACKETS received data packet (@dest)
759     * TOTAL_PACKETS received data packet (@orig)
760     * 1 received tunnel destroy (@dest)
761     * _________________________________
762     * 5 x ok expected per peer
763     */
764     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED_ACK\n");
765     test = SPEED_ACK;
766     test_name = "speed2 ack";
767     ok_goal = TOTAL_PACKETS * 2 + 2;
768   }
769   else if (strstr (argv[0], "test_mesh_small_speed") != NULL)
770   {
771    /* Each peer is supposed to generate the following callbacks:
772     * 1 incoming tunnel (@dest)
773     * 1 initial packet (@dest)
774     * TOTAL_PACKETS received data packet (@dest)
775     * 1 received data packet (@orig)
776     * 1 received tunnel destroy (@dest)
777     * _________________________________
778     */
779     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SPEED\n");
780     ok_goal = TOTAL_PACKETS + 4;
781     if (strstr (argv[0], "_nobuf") != NULL)
782     {
783       test = SPEED_NOBUF;
784       test_name = "speed2 nobuf";
785     }
786     else
787     {
788       test = SPEED;
789       test_name = "speed2";
790     }
791   }
792   else
793   {
794     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "UNKNOWN\n");
795     test = SETUP;
796     ok_goal = 0;
797   }
798
799   if (strstr (argv[0], "backwards") != NULL)
800   {
801     char *aux;
802
803     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "BACKWARDS (LEAF TO ROOT)\n");
804     test_backwards = GNUNET_YES;
805     aux = GNUNET_malloc (32);
806     sprintf (aux, "backwards %s", test_name);
807     test_name = aux;
808   }
809
810   p_ids = 0;
811   GNUNET_MESH_TEST_run ("test_mesh2_small",
812                         "test_mesh2.conf",
813                         5,
814                         &tmain,
815                         NULL, /*tmain cls */
816                         &incoming_tunnel,
817                         &tunnel_cleaner,
818                         handlers,
819                         NULL);
820
821   if (ok_goal > ok)
822   {
823     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
824                 "FAILED! (%d/%d)\n", ok, ok_goal);
825     return 1;
826   }
827   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "success\n");
828   return 0;
829 }
830
831 /* end of test_mesh_small.c */
832