- begin work on enhanced multipart receiving
[oweals/gnunet.git] / src / ats-tests / perf_ats.c
index 822666b2f062fd253095ad2f2f52f29b871f7a51..f52bcfb25c578013a791ae753bb15f4ea8e478a0 100644 (file)
@@ -66,22 +66,33 @@ struct TestbedConnectOperation
  */
 struct BenchmarkState
 {
-  /* Are we connected to ATS service of all peers: GNUNET_YES/NO */
+  /**
+   * Are we connected to ATS service of all peers: GNUNET_YES/NO
+   */
   int connected_ATS_service;
 
-  /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
+  /**
+   * Are we connected to CORE service of all peers: GNUNET_YES/NO
+   */
   int connected_COMM_service;
 
-  /* Are we connected to all peers: GNUNET_YES/NO */
+  /**
+   * Are we connected to all peers: GNUNET_YES/NO
+   */
   int connected_PEERS;
 
-  /* Are we connected to all slave peers on CORE level: GNUNET_YES/NO */
+  /**
+   * Are we connected to all slave peers on CORE level: GNUNET_YES/NO
+   */
   int connected_CORE;
 
-  /* Are we connected to CORE service of all peers: GNUNET_YES/NO */
+  /**
+   * Are we connected to CORE service of all peers: GNUNET_YES/NO
+   */
   int benchmarking;
 };
 
+
 /**
  * Shutdown task
  */
@@ -129,17 +140,18 @@ static int pref_val;
 /**
  * Number master peers
  */
-static int num_masters;
+static unsigned int num_masters;
 
 /**
  * Array of master peers
  */
-static  struct BenchmarkPeer *mps;
+static struct BenchmarkPeer *mps;
 
 /**
  * Number slave peers
  */
-static int num_slaves;
+static unsigned int num_slaves;
+
 /**
  * Array of slave peers
  */
@@ -184,7 +196,7 @@ evaluate ()
     {
       p = &mp->partners[c_s];
       fprintf (stderr,
-          "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f \%), received %u KiB/s (%.2f \%)\n",
+          "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n",
           (mp->pref_partner == p->dest) ? '*' : ' ',
           mp->no, p->dest->no,
           (p->bytes_sent / 1024) / duration,
@@ -750,27 +762,15 @@ static int
 comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
     const struct GNUNET_MessageHeader *message)
 {
-  int c_s;
   struct BenchmarkPeer *me = cls;
   struct BenchmarkPartner *p = NULL;
 
-  for (c_s = 0; c_s < num_slaves; c_s++)
-  {
-    if (0
-        == memcmp (other, &me->partners[c_s].dest->id,
-            sizeof(struct GNUNET_PeerIdentity)))
-    {
-      p = &me->partners[c_s];
-      break;
-    }
-  }
-  if (NULL == p)
+  if (NULL == (p = find_partner (me, other)))
   {
     GNUNET_break(0);
     return GNUNET_SYSERR;
   }
 
-
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
       "Master [%u]: Received PONG from [%u], next message\n", me->no,
       p->dest->no);
@@ -920,23 +920,11 @@ ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
 {
   struct BenchmarkPeer *me = cls;
   struct BenchmarkPartner *p;
-  int c_s;
   int c_a;
+  int log;
   char *peer_id;
 
-  p = NULL;
-  for (c_s = 0; c_s < me->num_partners; c_s++)
-  {
-
-    if (0 == memcmp (&address->peer, &me->partners[c_s].dest->id,
-        sizeof (struct GNUNET_PeerIdentity)))
-    {
-      p = &me->partners[c_s];
-      break;
-    }
-
-  }
-
+  p = find_partner (me, &address->peer);
   if (NULL == p)
   {
     /* This is not one of my partners
@@ -944,9 +932,15 @@ ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
      */
     return;
   }
-
   peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
 
+  log = GNUNET_NO;
+  if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) ||
+      (p->bandwidth_out != ntohl (bandwidth_out.value__)))
+      log = GNUNET_YES;
+  p->bandwidth_in = ntohl (bandwidth_in.value__);
+  p->bandwidth_out = ntohl (bandwidth_out.value__);
+
   for (c_a = 0; c_a < ats_count; c_a++)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s [%u] received ATS information: %s %s %u\n",
@@ -959,37 +953,53 @@ ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
     {
       case GNUNET_ATS_ARRAY_TERMINATOR:
         break;
-      case GNUNET_ATS_UTILIZATION_UP:
+      case GNUNET_ATS_UTILIZATION_OUT:
+        if (p->ats_utilization_up != ntohl (ats[c_a].value))
+            log = GNUNET_YES;
         p->ats_utilization_up = ntohl (ats[c_a].value);
+
         break;
-      case GNUNET_ATS_UTILIZATION_DOWN:
+      case GNUNET_ATS_UTILIZATION_IN:
+        if (p->ats_utilization_down != ntohl (ats[c_a].value))
+            log = GNUNET_YES;
         p->ats_utilization_down = ntohl (ats[c_a].value);
         break;
       case GNUNET_ATS_NETWORK_TYPE:
+        if (p->ats_network_type != ntohl (ats[c_a].value))
+            log = GNUNET_YES;
         p->ats_network_type = ntohl (ats[c_a].value);
         break;
       case GNUNET_ATS_QUALITY_NET_DELAY:
+        if (p->ats_delay != ntohl (ats[c_a].value))
+            log = GNUNET_YES;
         p->ats_delay = ntohl (ats[c_a].value);
         break;
       case GNUNET_ATS_QUALITY_NET_DISTANCE:
+        if (p->ats_distance != ntohl (ats[c_a].value))
+            log = GNUNET_YES;
         p->ats_distance = ntohl (ats[c_a].value);
         GNUNET_break (0);
         break;
       case GNUNET_ATS_COST_WAN:
+        if (p->ats_cost_wan != ntohl (ats[c_a].value))
+            log = GNUNET_YES;
         p->ats_cost_wan = ntohl (ats[c_a].value);
         break;
       case GNUNET_ATS_COST_LAN:
+        if (p->ats_cost_lan != ntohl (ats[c_a].value))
+            log = GNUNET_YES;
         p->ats_cost_lan = ntohl (ats[c_a].value);
         break;
       case GNUNET_ATS_COST_WLAN:
+        if (p->ats_cost_wlan != ntohl (ats[c_a].value))
+            log = GNUNET_YES;
         p->ats_cost_wlan = ntohl (ats[c_a].value);
         break;
-        break;
       default:
         break;
     }
   }
-  if (GNUNET_YES == logging)
+  if ((GNUNET_YES == logging) && (GNUNET_YES == log))
     collect_log_now();
   GNUNET_free(peer_id);
 }
@@ -1103,9 +1113,11 @@ peerinformation_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op,
  *          failed
  */
 static void
-main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers,
-    struct GNUNET_TESTBED_Peer **peers_, unsigned int links_succeeded,
-    unsigned int links_failed)
+main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h,
+          unsigned int num_peers,
+          struct GNUNET_TESTBED_Peer **peers_,
+          unsigned int links_succeeded,
+          unsigned int links_failed)
 {
   int c_m;
   int c_s;
@@ -1131,7 +1143,7 @@ main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers,
     mps[c_m].pref_partner = &sps[c_m];
     mps[c_m].pref_value = TEST_ATS_PREFRENCE_START;
     mps[c_m].partners =
-        GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer));
+        GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPartner));
     mps[c_m].num_partners = num_slaves;
     /* Initialize partners */
     for (c_s = 0; c_s < num_slaves; c_s++)
@@ -1151,7 +1163,7 @@ main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers,
     sps[c_s].no = c_s + num_masters;
     sps[c_s].master = GNUNET_NO;
     sps[c_s].partners =
-        GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer));
+        GNUNET_malloc (num_masters * sizeof (struct BenchmarkPartner));
     sps[c_s].num_partners = num_masters;
     /* Initialize partners */
     for (c_m = 0; c_m < num_masters; c_m++)