2 This file is part of GNUnet
3 (C) 2004, 2009 Christian Grothoff (and other contributing authors)
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.
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.
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.
21 * @file fragmentation/test_fragmentation.c
22 * @brief test for fragmentation.c
23 * @author Christian Grothoff
26 #include "gnunet_fragmentation_lib.h"
34 static struct GNUNET_DEFRAGMENT_Context *defrag;
36 static struct GNUNET_FRAGMENT_Context *frags[NUM_MSGS];
40 const struct GNUNET_MessageHeader *hdr)
42 static unsigned int total;
44 fprintf (stderr, "!");
46 if (total == NUM_MSGS)
49 GNUNET_DEFRAGMENT_context_destroy (defrag);
55 * Process ACK (by passing to fragmenter)
59 const struct GNUNET_MessageHeader *hdr)
64 fprintf (stderr, "@");
65 for (i=0;i<NUM_MSGS;i++)
69 ret = GNUNET_FRAGMENT_process_ack (frags[i],
73 GNUNET_FRAGMENT_context_destroy (frags[i]);
80 fprintf (stderr, "Got ACK that nobody feels responsible for...\n");
85 * Process fragment (by passing to defrag).
89 const struct GNUNET_MessageHeader *hdr)
91 fprintf (stderr, ".");
94 GNUNET_DEFRAGMENT_process_fragment (defrag, hdr);
99 * Main function run with scheduler.
104 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
107 struct GNUNET_MessageHeader *msg;
108 char buf[MTU + 32 * 1024];
110 defrag = GNUNET_DEFRAGMENT_context_create (NULL,
112 NUM_MSGS /* enough space for all */,
116 for (i=0;i<sizeof(buf);i++)
118 msg = (struct GNUNET_MessageHeader* ) buf;
119 for (i=0;i<NUM_MSGS;i++)
121 msg->type = htons ((uint16_t) i);
122 msg->size = htons (MTU + 1 + i % (32 * 1024));
123 frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */,
125 NULL /* no tracker -- infinite BW */,
126 GNUNET_TIME_UNIT_MILLISECONDS,
135 main (int argc, char *argv[])
137 struct GNUNET_GETOPT_CommandLineOption options[] = {
138 GNUNET_GETOPT_OPTION_END
140 char *const argv_prog[] = {
141 "test-fragmentation",
143 "test_fragmentation_data.conf",
153 GNUNET_log_setup ("test-fragmentation",
160 GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options, &run, NULL);