gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r35442 - gnunet/src/fragmentation


From: gnunet
Subject: [GNUnet-SVN] r35442 - gnunet/src/fragmentation
Date: Wed, 25 Mar 2015 15:31:03 +0100

Author: grothoff
Date: 2015-03-25 15:31:03 +0100 (Wed, 25 Mar 2015)
New Revision: 35442

Added:
   gnunet/src/fragmentation/test_fragmentation_parallel.c
Modified:
   gnunet/src/fragmentation/Makefile.am
   gnunet/src/fragmentation/defragmentation.c
   gnunet/src/fragmentation/fragmentation.c
   gnunet/src/fragmentation/test_fragmentation.c
Log:
-trying to fix AE's problem on Guix with more fancy retransmission logic

Modified: gnunet/src/fragmentation/Makefile.am
===================================================================
--- gnunet/src/fragmentation/Makefile.am        2015-03-24 09:36:10 UTC (rev 
35441)
+++ gnunet/src/fragmentation/Makefile.am        2015-03-25 14:31:03 UTC (rev 
35442)
@@ -13,7 +13,7 @@
 
 libgnunetfragmentation_la_SOURCES = \
   fragmentation.c fragmentation.h \
-  defragmentation.c 
+  defragmentation.c
 libgnunetfragmentation_la_LIBADD = -lm \
  $(top_builddir)/src/statistics/libgnunetstatistics.la \
  $(top_builddir)/src/util/libgnunetutil.la \
@@ -23,7 +23,8 @@
   -version-info 2:0:0
 
 check_PROGRAMS = \
- test_fragmentation
+ test_fragmentation \
+ test_fragmentation_parallel
 
 if ENABLE_TEST_RUN
 AM_TESTS_ENVIRONMENT=export 
GNUNET_PREFIX=$${GNUNET_PREFIX:address@hidden@};export 
PATH=$${GNUNET_PREFIX:address@hidden@}/bin:$$PATH;
@@ -34,6 +35,12 @@
  test_fragmentation.c
 test_fragmentation_LDADD = \
  libgnunetfragmentation.la \
- $(top_builddir)/src/util/libgnunetutil.la  
+ $(top_builddir)/src/util/libgnunetutil.la
 
+test_fragmentation_parallel_SOURCES = \
+ test_fragmentation_parallel.c
+test_fragmentation_parallel_LDADD = \
+ libgnunetfragmentation.la \
+ $(top_builddir)/src/util/libgnunetutil.la
+
 EXTRA_DIST = test_fragmentation_data.conf

Modified: gnunet/src/fragmentation/defragmentation.c
===================================================================
--- gnunet/src/fragmentation/defragmentation.c  2015-03-24 09:36:10 UTC (rev 
35441)
+++ gnunet/src/fragmentation/defragmentation.c  2015-03-25 14:31:03 UTC (rev 
35442)
@@ -109,13 +109,13 @@
 
   /**
    * For the current ACK round, which is the first relevant
-   * offset in 'frag_times'?
+   * offset in @e frag_times?
    */
   unsigned int frag_times_start_offset;
 
   /**
    * Which offset whould we write the next frag value into
-   * in the 'frag_times' array? All smaller entries are valid.
+   * in the @e frag_times array? All smaller entries are valid.
    */
   unsigned int frag_times_write_offset;
 
@@ -124,6 +124,11 @@
    */
   uint16_t total_size;
 
+  /**
+   * Was the last fragment we got a duplicate?
+   */
+  int16_t last_duplicate;
+
 };
 
 
@@ -185,6 +190,7 @@
    * Maximum message size for each fragment.
    */
   uint16_t mtu;
+
 };
 
 
@@ -271,6 +277,7 @@
                             _("# acknowledgements sent for fragment"),
                             1,
                             GNUNET_NO);
+  mc->last_duplicate = GNUNET_NO; /* clear flag */
   dc->ackp (dc->cls,
             mc->fragment_id,
             &fa.header);
@@ -535,11 +542,13 @@
                               GNUNET_NO);
   }
 
-  /* count number of missing fragments */
+  /* count number of missing fragments after the current one */
   bc = 0;
-  for (b = 0; b < 64; b++)
+  for (b = bit; b < 64; b++)
     if (0 != (mc->bits & (1LL << b)))
       bc++;
+    else
+      bc = 0;
 
   /* notify about complete message */
   if ( (GNUNET_NO == duplicate) &&
@@ -560,23 +569,23 @@
   delay = GNUNET_TIME_relative_multiply (dc->latency,
                                          bc + 1);
   if ( (last + fid == num_fragments) ||
-       ( (0 == mc->bits) &&
-         (GNUNET_YES != duplicate)) )
+       (0 == mc->bits) ||
+       (GNUNET_YES == duplicate) )
   {
     /* message complete or duplicate or last missing fragment in
        linear sequence; ACK now! */
     delay = GNUNET_TIME_UNIT_ZERO;
   }
-  if (GNUNET_YES == duplicate)
-    delay = GNUNET_TIME_relative_multiply (delay,
-                                           2);
   if (NULL != mc->ack_task)
     GNUNET_SCHEDULER_cancel (mc->ack_task);
   mc->ack_task = GNUNET_SCHEDULER_add_delayed (delay,
                                                &send_ack,
                                                mc);
   if (GNUNET_YES == duplicate)
+  {
+    mc->last_duplicate = GNUNET_YES;
     return GNUNET_NO;
+  }
   return GNUNET_YES;
 }
 

Modified: gnunet/src/fragmentation/fragmentation.c
===================================================================
--- gnunet/src/fragmentation/fragmentation.c    2015-03-24 09:36:10 UTC (rev 
35441)
+++ gnunet/src/fragmentation/fragmentation.c    2015-03-25 14:31:03 UTC (rev 
35442)
@@ -231,10 +231,14 @@
           fsize - sizeof (struct FragmentHeader));
   if (NULL != fc->tracker)
     GNUNET_BANDWIDTH_tracker_consume (fc->tracker, fsize);
-  GNUNET_STATISTICS_update (fc->stats, _("# fragments transmitted"), 1,
+  GNUNET_STATISTICS_update (fc->stats,
+                            _("# fragments transmitted"),
+                            1,
                             GNUNET_NO);
   if (0 != fc->last_round.abs_value_us)
-    GNUNET_STATISTICS_update (fc->stats, _("# fragments retransmitted"), 1,
+    GNUNET_STATISTICS_update (fc->stats,
+                              _("# fragments retransmitted"),
+                              1,
                               GNUNET_NO);
 
   /* select next message to calculate delay */
@@ -245,7 +249,8 @@
   else
     fsize = fc->mtu;
   if (NULL != fc->tracker)
-    delay = GNUNET_BANDWIDTH_tracker_get_delay (fc->tracker, fsize);
+    delay = GNUNET_BANDWIDTH_tracker_get_delay (fc->tracker,
+                                                fsize);
   else
     delay = GNUNET_TIME_UNIT_ZERO;
   delay = GNUNET_TIME_relative_max (delay,
@@ -260,7 +265,9 @@
     delay = GNUNET_TIME_relative_max (MIN_ACK_DELAY, delay);
     fc->wack = GNUNET_YES;
     fc->last_round = GNUNET_TIME_absolute_get ();
-    GNUNET_STATISTICS_update (fc->stats, _("# fragments wrap arounds"), 1,
+    GNUNET_STATISTICS_update (fc->stats,
+                              _("# fragments wrap arounds"),
+                              1,
                               GNUNET_NO);
   }
   fc->proc_busy = GNUNET_YES;
@@ -304,10 +311,14 @@
   size_t size;
   uint64_t bits;
 
-  GNUNET_STATISTICS_update (stats, _("# messages fragmented"), 1, GNUNET_NO);
+  GNUNET_STATISTICS_update (stats,
+                            _("# messages fragmented"),
+                            1,
+                            GNUNET_NO);
   GNUNET_assert (mtu >= 1024 + sizeof (struct FragmentHeader));
   size = ntohs (msg->size);
-  GNUNET_STATISTICS_update (stats, _("# total size of fragmented messages"),
+  GNUNET_STATISTICS_update (stats,
+                            _("# total size of fragmented messages"),
                             size, GNUNET_NO);
   GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
   fc = GNUNET_malloc (sizeof (struct GNUNET_FRAGMENT_Context) + size);
@@ -395,7 +406,6 @@
     ndelay = GNUNET_TIME_absolute_get_duration (fc->last_round);
     fc->ack_delay.rel_value_us =
         (ndelay.rel_value_us / fc->num_transmissions + 3 * 
fc->ack_delay.rel_value_us) / 4;
-    fc->num_transmissions = 0;
     /* calculate ratio msg sent vs. msg acked */
     ack_cnt = 0;
     snd_cnt = 0;
@@ -417,18 +427,22 @@
     else if (snd_cnt > ack_cnt)
     {
       /* some loss, slow down proportionally */
-      fprintf (stderr, "Prop loss\n");
       fc->msg_delay.rel_value_us = ((fc->msg_delay.rel_value_us * ack_cnt) / 
snd_cnt);
     }
-    else if (100 < fc->msg_delay.rel_value_us)
+    else if (snd_cnt == ack_cnt)
     {
-      fc->msg_delay.rel_value_us -= 100; /* try a bit faster */
+      fc->msg_delay.rel_value_us =
+        (ndelay.rel_value_us / fc->num_transmissions + 3 * 
fc->msg_delay.rel_value_us) / 5;
     }
+    fc->num_transmissions = 0;
     fc->msg_delay = GNUNET_TIME_relative_min (fc->msg_delay,
                                              GNUNET_TIME_UNIT_SECONDS);
+    fc->ack_delay = GNUNET_TIME_relative_min (fc->ack_delay,
+                                             GNUNET_TIME_UNIT_SECONDS);
   }
   GNUNET_STATISTICS_update (fc->stats,
-                            _("# fragment acknowledgements received"), 1,
+                            _("# fragment acknowledgements received"),
+                            1,
                             GNUNET_NO);
   if (abits != (fc->acks & abits))
   {
@@ -458,9 +472,10 @@
 
   /* all done */
   GNUNET_STATISTICS_update (fc->stats,
-                            _("# fragmentation transmissions completed"), 1,
+                            _("# fragmentation transmissions completed"),
+                            1,
                             GNUNET_NO);
-  if (fc->task != NULL)
+  if (NULL != fc->task)
   {
     GNUNET_SCHEDULER_cancel (fc->task);
     fc->task = NULL;

Modified: gnunet/src/fragmentation/test_fragmentation.c
===================================================================
--- gnunet/src/fragmentation/test_fragmentation.c       2015-03-24 09:36:10 UTC 
(rev 35441)
+++ gnunet/src/fragmentation/test_fragmentation.c       2015-03-25 14:31:03 UTC 
(rev 35442)
@@ -30,7 +30,7 @@
 /**
  * Number of messages to transmit (note: each uses ~32k memory!)
  */
-#define NUM_MSGS 500
+#define NUM_MSGS 1000
 
 /**
  * MTU to force on fragmentation (must be > 1k + 12)
@@ -40,7 +40,7 @@
 /**
  * Simulate dropping of 1 out of how many messages? (must be > 1)
  */
-#define DROPRATE 5
+#define DROPRATE 15
 
 static int ret = 1;
 
@@ -58,26 +58,35 @@
 
 static struct GNUNET_BANDWIDTH_Tracker trackers[NUM_MSGS];
 
-static struct GNUNET_FRAGMENT_Context *frags[NUM_MSGS];
+static struct GNUNET_FRAGMENT_Context *frag;
 
 static struct GNUNET_SCHEDULER_Task * shutdown_task;
 
+static struct GNUNET_TIME_Relative msg_delay;
+
+static struct GNUNET_TIME_Relative ack_delay;
+
+
 static void
 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  unsigned int i;
-
   ret = 0;
   shutdown_task = NULL;
   GNUNET_DEFRAGMENT_context_destroy (defrag);
   defrag = NULL;
-  for (i = 0; i < NUM_MSGS; i++)
+  if (NULL != frag)
   {
-    if (frags[i] == NULL)
-      continue;
-    GNUNET_FRAGMENT_context_destroy (frags[i], NULL, NULL);
-    frags[i] = NULL;
+    GNUNET_FRAGMENT_context_destroy (frag, &msg_delay, &ack_delay);
+    frag = NULL;
   }
+  fprintf (stderr,
+           "\nFinal message-delay: %s\n",
+           GNUNET_STRINGS_relative_time_to_string (msg_delay,
+                                                   GNUNET_YES));
+  fprintf (stderr,
+           "Final ack-delay: %s\n",
+           GNUNET_STRINGS_relative_time_to_string (ack_delay,
+                                                   GNUNET_YES));
 }
 
 
@@ -89,7 +98,7 @@
   const char *buf;
 
 #if DETAILS
-  FPRINTF (stderr, "%s",  "!");        /* message complete, good! */
+  FPRINTF (stderr, "%s",  "M! ");        /* message complete, good! */
 #endif
   buf = (const char *) hdr;
   for (i = sizeof (struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++)
@@ -109,84 +118,130 @@
 
 
 /**
- * Process ACK (by passing to fragmenter)
+ * Process fragment (by passing to defrag).
  */
 static void
-proc_acks (void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr)
+proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr)
 {
-  unsigned int i;
+  struct GNUNET_FRAGMENT_Context **fc = cls;
   int ret;
 
+  GNUNET_FRAGMENT_context_transmission_done (*fc);
   if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE))
   {
-    ack_drops++;
+    frag_drops++;
+#if DETAILS
+    FPRINTF (stderr, "%s",  "DF ");    /* dropped Frag */
+#endif
     return;                     /* random drop */
   }
-  for (i = 0; i < NUM_MSGS; i++)
+  if (NULL == defrag)
   {
-    if (frags[i] == NULL)
-      continue;
-    ret = GNUNET_FRAGMENT_process_ack (frags[i], hdr);
-    if (ret == GNUNET_OK)
-    {
+    FPRINTF (stderr, "%s",  "?E ");      /* Error: frag after shutdown!? */
+    return;
+  }
+  ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr);
+  if (ret == GNUNET_NO)
+  {
 #if DETAILS
-      FPRINTF (stderr, "%s",  "@");    /* good ACK */
+    FPRINTF (stderr, "%s",  "FF ");      /* duplicate fragment */
 #endif
-      GNUNET_FRAGMENT_context_destroy (frags[i], NULL, NULL);
-      frags[i] = NULL;
-      acks++;
-      return;
-    }
-    if (ret == GNUNET_NO)
-    {
+    dups++;
+  }
+  else if (ret == GNUNET_OK)
+  {
 #if DETAILS
-      FPRINTF (stderr, "%s",  "@");    /* good ACK */
+    FPRINTF (stderr, "%s",  "F! ");      /* good fragment */
 #endif
-      acks++;
-      return;
-    }
+    fragc++;
   }
+}
+
+
+static void
+next_transmission ()
+{
+  static unsigned int i;
+  struct GNUNET_MessageHeader *msg;
+  static char buf[MTU + 32 * 1024];
+  unsigned int j;
+
+  if (0 == i)
+  {
+    for (j = 0; j < sizeof (buf); j++)
+      buf[j] = (char) j;
+  }
+  else
+  {
+    GNUNET_FRAGMENT_context_destroy (frag,
+                                     &msg_delay,
+                                     &ack_delay);
+    frag = NULL;
+  }
+  if (i == NUM_MSGS)
+    return;
 #if DETAILS
-  FPRINTF (stderr, "%s",  "_");        /* BAD: ack that nobody feels 
responsible for... */
+  FPRINTF (stderr, "%s",  "T! ");        /* sending message */
 #endif
+  msg = (struct GNUNET_MessageHeader *) buf;
+  msg->type = htons ((uint16_t) i);
+  msg->size =
+    htons (sizeof (struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024));
+  frag = GNUNET_FRAGMENT_context_create (NULL /* no stats */ ,
+                                         MTU, &trackers[i],
+                                         msg_delay,
+                                         ack_delay,
+                                         msg,
+                                         &proc_frac, &frag);
+  i++;
 }
 
 
 /**
- * Process fragment (by passing to defrag).
+ * Process ACK (by passing to fragmenter)
  */
 static void
-proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr)
+proc_acks (void *cls,
+           uint32_t msg_id,
+           const struct GNUNET_MessageHeader *hdr)
 {
-  struct GNUNET_FRAGMENT_Context **fc = cls;
+  unsigned int i;
   int ret;
 
-  GNUNET_FRAGMENT_context_transmission_done (*fc);
   if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE))
   {
-    frag_drops++;
+    ack_drops++;
+#if DETAILS
+    FPRINTF (stderr, "%s",  "DA ");    /* dropped ACK */
+#endif
     return;                     /* random drop */
   }
-  if (NULL == defrag)
+  for (i = 0; i < NUM_MSGS; i++)
   {
-    FPRINTF (stderr, "%s",  "E");      /* Error: frag after shutdown!? */
-    return;
-  }
-  ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr);
-  if (ret == GNUNET_NO)
-  {
+    if (NULL == frag)
+      continue;
+    ret = GNUNET_FRAGMENT_process_ack (frag, hdr);
+    if (ret == GNUNET_OK)
+    {
 #if DETAILS
-    FPRINTF (stderr, "%s",  "?");      /* duplicate fragment */
+      FPRINTF (stderr, "%s",  "GA ");    /* good ACK */
 #endif
-    dups++;
+      next_transmission ();
+      acks++;
+      return;
+    }
+    if (ret == GNUNET_NO)
+    {
+#if DETAILS
+      FPRINTF (stderr, "%s",  "AA ");    /* duplciate ACK */
+#endif
+      acks++;
+      return;
+    }
   }
-  else if (ret == GNUNET_OK)
-  {
 #if DETAILS
-    FPRINTF (stderr, "%s",  ".");      /* good fragment */
+  FPRINTF (stderr, "%s",  "?A ");        /* BAD: ack that nobody feels 
responsible for... */
 #endif
-    fragc++;
-  }
 }
 
 
@@ -194,30 +249,17 @@
  * Main function run with scheduler.
  */
 static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
-  unsigned int i;
-  struct GNUNET_MessageHeader *msg;
-  char buf[MTU + 32 * 1024];
-
-  defrag = GNUNET_DEFRAGMENT_context_create (NULL, MTU, NUM_MSGS        /* 
enough space for all */
-                                             , NULL, &proc_msgs, &proc_acks);
-  for (i = 0; i < sizeof (buf); i++)
-    buf[i] = (char) i;
-  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_MILLISECONDS,
-                                               GNUNET_TIME_UNIT_SECONDS,
-                                              msg,
-                                               &proc_frac, &frags[i]);
-  }
+  defrag = GNUNET_DEFRAGMENT_context_create (NULL, MTU,
+                                             3,
+                                             NULL,
+                                             &proc_msgs,
+                                             &proc_acks);
+  next_transmission ();
 }
 
 
@@ -237,6 +279,8 @@
   };
   unsigned int i;
 
+  msg_delay = GNUNET_TIME_UNIT_MILLISECONDS;
+  ack_delay = GNUNET_TIME_UNIT_SECONDS;
   GNUNET_log_setup ("test-fragmentation",
                     "WARNING",
                     NULL);
@@ -244,10 +288,16 @@
     GNUNET_BANDWIDTH_tracker_init (&trackers[i], NULL, NULL,
                                    GNUNET_BANDWIDTH_value_init ((i + 1) * 
1024),
                                    100);
-  GNUNET_PROGRAM_run (5, argv_prog, "test-fragmentation", "nohelp", options,
+  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);
+           fragc,
+           dups,
+           acks,
+           ack_drops);
   return ret;
 }

Added: gnunet/src/fragmentation/test_fragmentation_parallel.c
===================================================================
--- gnunet/src/fragmentation/test_fragmentation_parallel.c                      
        (rev 0)
+++ gnunet/src/fragmentation/test_fragmentation_parallel.c      2015-03-25 
14:31:03 UTC (rev 35442)
@@ -0,0 +1,253 @@
+/*
+     This file is part of GNUnet
+     Copyright (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 DETAILS GNUNET_NO
+
+/**
+ * Number of messages to transmit (note: each uses ~32k memory!)
+ */
+#define NUM_MSGS 500
+
+/**
+ * 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 5
+
+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 struct GNUNET_SCHEDULER_Task * shutdown_task;
+
+static void
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  unsigned int i;
+
+  ret = 0;
+  shutdown_task = NULL;
+  GNUNET_DEFRAGMENT_context_destroy (defrag);
+  defrag = NULL;
+  for (i = 0; i < NUM_MSGS; i++)
+  {
+    if (frags[i] == NULL)
+      continue;
+    GNUNET_FRAGMENT_context_destroy (frags[i], NULL, NULL);
+    frags[i] = NULL;
+  }
+}
+
+
+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, "%s",  "!");        /* 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 ! DETAILS
+  if (0 == (total % (NUM_MSGS / 100)))
+    FPRINTF (stderr, "%s",  ".");
+#endif
+  /* tolerate 10% loss, i.e. due to duplicate fragment IDs */
+  if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0))
+  {
+    if (NULL == shutdown_task)
+      shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+  }
+}
+
+
+/**
+ * Process ACK (by passing to fragmenter)
+ */
+static void
+proc_acks (void *cls, uint32_t msg_id, const struct GNUNET_MessageHeader *hdr)
+{
+  unsigned int i;
+  int ret;
+
+  if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE))
+  {
+    ack_drops++;
+    return;                     /* random drop */
+  }
+  for (i = 0; i < NUM_MSGS; i++)
+  {
+    if (frags[i] == NULL)
+      continue;
+    ret = GNUNET_FRAGMENT_process_ack (frags[i], hdr);
+    if (ret == GNUNET_OK)
+    {
+#if DETAILS
+      FPRINTF (stderr, "%s",  "@");    /* good ACK */
+#endif
+      GNUNET_FRAGMENT_context_destroy (frags[i], NULL, NULL);
+      frags[i] = NULL;
+      acks++;
+      return;
+    }
+    if (ret == GNUNET_NO)
+    {
+#if DETAILS
+      FPRINTF (stderr, "%s",  "@");    /* good ACK */
+#endif
+      acks++;
+      return;
+    }
+  }
+#if DETAILS
+  FPRINTF (stderr, "%s",  "_");        /* BAD: ack that nobody feels 
responsible for... */
+#endif
+}
+
+
+/**
+ * Process fragment (by passing to defrag).
+ */
+static void
+proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr)
+{
+  struct GNUNET_FRAGMENT_Context **fc = cls;
+  int ret;
+
+  GNUNET_FRAGMENT_context_transmission_done (*fc);
+  if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE))
+  {
+    frag_drops++;
+    return;                     /* random drop */
+  }
+  if (NULL == defrag)
+  {
+    FPRINTF (stderr, "%s",  "E");      /* Error: frag after shutdown!? */
+    return;
+  }
+  ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr);
+  if (ret == GNUNET_NO)
+  {
+#if DETAILS
+    FPRINTF (stderr, "%s",  "?");      /* duplicate fragment */
+#endif
+    dups++;
+  }
+  else if (ret == GNUNET_OK)
+  {
+#if DETAILS
+    FPRINTF (stderr, "%s",  ".");      /* good fragment */
+#endif
+    fragc++;
+  }
+}
+
+
+/**
+ * Main function run with scheduler.
+ */
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+  unsigned int i;
+  struct GNUNET_MessageHeader *msg;
+  char buf[MTU + 32 * 1024];
+
+  defrag = GNUNET_DEFRAGMENT_context_create (NULL, MTU, NUM_MSGS        /* 
enough space for all */
+                                             , NULL, &proc_msgs, &proc_acks);
+  for (i = 0; i < sizeof (buf); i++)
+    buf[i] = (char) i;
+  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_MILLISECONDS,
+                                               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",
+    "WARNING",
+    NULL
+  };
+  unsigned int i;
+
+  GNUNET_log_setup ("test-fragmentation",
+                    "WARNING",
+                    NULL);
+  for (i = 0; i < NUM_MSGS; i++)
+    GNUNET_BANDWIDTH_tracker_init (&trackers[i], NULL, NULL,
+                                   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;
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]