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