X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Ffragmentation%2Ftest_fragmentation.c;h=b534a134e5bdc55e1fee53013abc45b075ac0954;hb=502af2167f7c218366666ca4944bd7cc54b5b19a;hp=639c0ef173acc926d6fcfbcddb1d2aea387339fc;hpb=f6882edc3a6a5528897dc92ed8eca0aa1da4ab6a;p=oweals%2Fgnunet.git diff --git a/src/fragmentation/test_fragmentation.c b/src/fragmentation/test_fragmentation.c index 639c0ef17..b534a134e 100644 --- a/src/fragmentation/test_fragmentation.c +++ b/src/fragmentation/test_fragmentation.c @@ -25,59 +25,119 @@ #include "platform.h" #include "gnunet_fragmentation_lib.h" -#define NUM_MSGS 1 +#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 -static int ret = 1; +/** + * 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) +proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr) { static unsigned int total; + unsigned int i; + const char *buf; - fprintf (stderr, "!"); +#if DETAILS + fprintf (stderr, "!"); /* message complete, good! */ +#endif + buf = (const char *) hdr; + for (i = sizeof (struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++) + GNUNET_assert (buf[i] == (char) i); total++; - if (total == NUM_MSGS) +#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; i < NUM_MSGS; i++) { - ret = 0; - GNUNET_DEFRAGMENT_context_destroy (defrag); - defrag = NULL; + if (frags[i] == NULL) + continue; + GNUNET_FRAGMENT_context_destroy (frags[i]); + frags[i] = NULL; } + } } + /** * Process ACK (by passing to fragmenter) */ static void -proc_acks (void *cls, - const struct GNUNET_MessageHeader *hdr) +proc_acks (void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr) { unsigned int i; int ret; - fprintf (stderr, "@"); - for (i=0;itype = htons ((uint16_t) i); - msg->size = htons (MTU + 1 + i % (32 * 1024)); - frags[i] = GNUNET_FRAGMENT_context_create (NULL /* no stats */, - MTU, - NULL /* no tracker -- infinite BW */, - GNUNET_TIME_UNIT_MILLISECONDS, - msg, - &proc_frac, - NULL); - } + msg = (struct GNUNET_MessageHeader *) buf; + for (i = 0; i < NUM_MSGS; i++) + { + msg->type = 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]); + } } @@ -149,6 +228,7 @@ main (int argc, char *argv[]) #endif NULL }; + unsigned int i; GNUNET_log_setup ("test-fragmentation", #if VERBOSE @@ -157,6 +237,14 @@ main (int argc, char *argv[]) "WARNING", #endif NULL); - GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options, &run, NULL); + for (i = 0; i < NUM_MSGS; i++) + GNUNET_BANDWIDTH_tracker_init (&trackers[i], + GNUNET_BANDWIDTH_value_init ((i + 1) * 1024), + 100); + GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options, + &run, NULL); + fprintf (stderr, + "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n", + fragc, dups, acks, ack_drops); return ret; }