/* This file is part of GNUnet (C) 2004, 2009 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNUnet; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** * @file fragmentation/test_fragmentation.c * @brief test for fragmentation.c * @author Christian Grothoff */ #include "platform.h" #include "gnunet_fragmentation_lib.h" #define VERBOSE GNUNET_NO #define DETAILS GNUNET_NO /** * Number of messages to transmit (note: each uses ~32k memory!) */ #define NUM_MSGS 5000 /** * MTU to force on fragmentation (must be > 1k + 12) */ #define MTU 1111 /** * Simulate dropping of 1 out of how many messages? (must be > 1) */ #define DROPRATE 10 static int ret = 1; static unsigned int dups; static unsigned int fragc; static unsigned int frag_drops; static unsigned int acks; static unsigned int ack_drops; static struct GNUNET_DEFRAGMENT_Context *defrag; static struct GNUNET_BANDWIDTH_Tracker trackers[NUM_MSGS]; static struct GNUNET_FRAGMENT_Context *frags[NUM_MSGS]; static void proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr) { static unsigned int total; unsigned int i; const char *buf; #if DETAILS fprintf (stderr, "!"); /* message complete, good! */ #endif buf = (const char*) hdr; for (i=sizeof (struct GNUNET_MessageHeader);isize);i++) GNUNET_assert (buf[i] == (char) i); total++; #if ! DETAILS if (0 == (total % (NUM_MSGS / 100))) fprintf (stderr, "."); #endif /* tolerate 10% loss, i.e. due to duplicate fragment IDs */ if (total >= NUM_MSGS - (NUM_MSGS / 10)) { ret = 0; GNUNET_DEFRAGMENT_context_destroy (defrag); defrag = NULL; for (i=0;itype = htons ((uint16_t) i); msg->size = htons (sizeof (struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024)); frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */, MTU, &trackers[i], GNUNET_TIME_UNIT_SECONDS, msg, &proc_frac, &frags[i]); } } int main (int argc, char *argv[]) { struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; char *const argv_prog[] = { "test-fragmentation", "-c", "test_fragmentation_data.conf", "-L", #if VERBOSE "DEBUG", #else "WARNING", #endif NULL }; unsigned int i; GNUNET_log_setup ("test-fragmentation", #if VERBOSE "DEBUG", #else "WARNING", #endif NULL); for (i=0;i