gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r25107 - gnunet/src/testbed


From: gnunet
Subject: [GNUnet-SVN] r25107 - gnunet/src/testbed
Date: Thu, 22 Nov 2012 18:03:48 +0100

Author: harsha
Date: 2012-11-22 18:03:48 +0100 (Thu, 22 Nov 2012)
New Revision: 25107

Added:
   gnunet/src/testbed/overlay_topology.txt
   gnunet/src/testbed/test_testbed_api_testbed_run_topologyfromfile.conf
Modified:
   gnunet/src/testbed/
   gnunet/src/testbed/Makefile.am
   gnunet/src/testbed/test_testbed_api_3peers_3controllers.c
   gnunet/src/testbed/testbed_api_testbed.c
   gnunet/src/testbed/testbed_api_topology.c
Log:
topology loading from file

Index: gnunet/src/testbed
===================================================================
--- gnunet/src/testbed  2012-11-22 15:49:49 UTC (rev 25106)
+++ gnunet/src/testbed  2012-11-22 17:03:48 UTC (rev 25107)

Property changes on: gnunet/src/testbed
___________________________________________________________________
Modified: svn:ignore
## -27,3 +27,4 ##
 test_testbed_api_testbed_run_topologysmallworldring
 test_testbed_api_testbed_run_topology2dtorus
 test_testbed_api_testbed_run_topologysmallworld
+test_testbed_api_testbed_run_topologyfromfile
Modified: gnunet/src/testbed/Makefile.am
===================================================================
--- gnunet/src/testbed/Makefile.am      2012-11-22 15:49:49 UTC (rev 25106)
+++ gnunet/src/testbed/Makefile.am      2012-11-22 17:03:48 UTC (rev 25107)
@@ -97,7 +97,8 @@
  test_testbed_api_testbed_run_topologyring \
  test_testbed_api_testbed_run_topologysmallworldring \
  test_testbed_api_testbed_run_topology2dtorus \
- test_testbed_api_testbed_run_topologysmallworld
+ test_testbed_api_testbed_run_topologysmallworld \
+ test_testbed_api_testbed_run_topologyfromfile
 
 if ENABLE_TEST_RUN
  TESTS = \
@@ -118,7 +119,8 @@
  test_testbed_api_testbed_run_topologyring \
  test_testbed_api_testbed_run_topologysmallworldring \
  test_testbed_api_testbed_run_topology2dtorus \
- test_testbed_api_testbed_run_topologysmallworld
+ test_testbed_api_testbed_run_topologysmallworld \
+ test_testbed_api_testbed_run_topologyfromfile
 endif
 
 test_testbed_api_hosts_SOURCES = \
@@ -234,6 +236,12 @@
  $(top_builddir)/src/util/libgnunetutil.la \
  libgnunettestbed.la
 
+test_testbed_api_testbed_run_topologyfromfile_SOURCES = \
+ test_testbed_api_testbed_run.c
+test_testbed_api_testbed_run_topologyfromfile_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ libgnunettestbed.la
+
 EXTRA_DIST = \
   test_testbed_api.conf \
   test_testbed_api_testbed_run_topologyring.conf \
@@ -243,4 +251,6 @@
   test_testbed_api_testbed_run_topologysmallworldring.conf \
   test_testbed_api_testbed_run_topology2dtorus.conf \
   test_testbed_api_testbed_run_topologysmallworld.conf \
+  test_testbed_api_testbed_run_topologyfromfile.conf \
+  overlay_topology.txt \
   sample_hosts.txt
\ No newline at end of file

Added: gnunet/src/testbed/overlay_topology.txt
===================================================================
--- gnunet/src/testbed/overlay_topology.txt                             (rev 0)
+++ gnunet/src/testbed/overlay_topology.txt     2012-11-22 17:03:48 UTC (rev 
25107)
@@ -0,0 +1,5 @@
+
+1:2|3
+3:4| 0|   1
+2: 3|1|0
+0:     2

Modified: gnunet/src/testbed/test_testbed_api_3peers_3controllers.c
===================================================================
--- gnunet/src/testbed/test_testbed_api_3peers_3controllers.c   2012-11-22 
15:49:49 UTC (rev 25106)
+++ gnunet/src/testbed/test_testbed_api_3peers_3controllers.c   2012-11-22 
17:03:48 UTC (rev 25107)
@@ -232,7 +232,12 @@
   /**
    * Final success stage
    */
-  SUCCESS
+  SUCCESS,
+
+  /**
+   * Optional stage for marking test to be skipped
+   */
+  SKIP
 };
 
 /**
@@ -874,8 +879,8 @@
     (void) PRINTF ("%s",
                    "Unable to run the test as this system is not configured "
                    "to use password less SSH logins to localhost.\n"
-                   "Marking test as successful\n");
-    result = SUCCESS;
+                   "Skipping test\n");
+    result = SKIP;
     return;
   }
   cfg = GNUNET_CONFIGURATION_dup (config);
@@ -908,9 +913,17 @@
       GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
                           "test_testbed_api_3peers_3controllers", "nohelp",
                           options, &run, NULL);
-  if ((GNUNET_OK != ret) || (SUCCESS != result))
+  if (GNUNET_OK != ret)
     return 1;
-  return 0;
+  switch (result)
+  {
+  case SUCCESS:
+    return 0;
+  case SKIP:
+    return 77;                  /* Mark test as skipped */
+  default:
+    return 1;
+  }
 }
 
 /* end of test_testbed_api_3peers_3controllers.c */

Copied: gnunet/src/testbed/test_testbed_api_testbed_run_topologyfromfile.conf 
(from rev 25105, 
gnunet/src/testbed/test_testbed_api_testbed_run_topologyline.conf)
===================================================================
--- gnunet/src/testbed/test_testbed_api_testbed_run_topologyfromfile.conf       
                        (rev 0)
+++ gnunet/src/testbed/test_testbed_api_testbed_run_topologyfromfile.conf       
2012-11-22 17:03:48 UTC (rev 25107)
@@ -0,0 +1,81 @@
+[testbed]
+AUTOSTART = NO
+PORT = 12113
+ACCEPT_FROM = 127.0.0.1;
+HOSTNAME = localhost
+NEIGHBOUR_LIMIT = 100
+OVERLAY_TOPOLOGY = FROM_FILE
+TOPOLOGY_FILE = overlay_topology.txt
+PARALLEL_OVERLAY_CONNECT_THRESHOLD = 2
+#PREFIX = xterm -geometry 100x85 -T peer1 -e libtool --mode=execute gdb --args
+
+[fs]
+AUTOSTART = NO
+
+[resolver]
+AUTOSTART = NO
+
+[mesh]
+AUTOSTART = NO
+
+[dht]
+AUTOSTART = NO
+
+[block]
+plugins = dht test
+
+[dhtcache]
+QUOTA = 1 MB
+DATABASE = sqlite
+
+[transport]
+PLUGINS = tcp
+ACCEPT_FROM6 = ::1;
+ACCEPT_FROM = 127.0.0.1;
+NEIGHBOUR_LIMIT = 50
+PORT = 12365
+
+[ats]
+WAN_QUOTA_OUT = 3932160
+WAN_QUOTA_IN = 3932160
+
+[core]
+PORT = 12092
+AUTOSTART = YES
+
+[arm]
+DEFAULTSERVICES = core transport
+PORT = 12366
+
+[transport-tcp]
+TIMEOUT = 300 s
+PORT = 12368
+
+[TESTING]
+NUM_PEERS = 5
+WEAKRANDOM = YES
+HOSTKEYSFILE = ../../contrib/testing_hostkeys.dat
+MAX_CONCURRENT_SSH = 10
+USE_PROGRESSBARS = YES
+PEERGROUP_TIMEOUT = 2400 s
+
+[gnunetd]
+HOSTKEY = $SERVICEHOME/.hostkey
+
+[PATHS]
+SERVICEHOME = /tmp/test-testbed/
+
+[dns]
+AUTOSTART = NO
+
+[nse]
+AUTOSTART = NO
+
+[vpn]
+AUTOSTART = NO
+
+[nat]
+RETURN_LOCAL_ADDRESSES = YES
+
+[gns-helper-service-w32]
+AUTOSTART = NO

Modified: gnunet/src/testbed/testbed_api_testbed.c
===================================================================
--- gnunet/src/testbed/testbed_api_testbed.c    2012-11-22 15:49:49 UTC (rev 
25106)
+++ gnunet/src/testbed/testbed_api_testbed.c    2012-11-22 17:03:48 UTC (rev 
25107)
@@ -182,6 +182,11 @@
   struct GNUNET_TESTBED_Operation *topology_operation;
 
   /**
+   * The file containing topology data. Only used if the topology is set to 
'FROM_FILE'
+   */
+  char *topo_file;
+
+  /**
    * The event mask for the controller
    */
   uint64_t event_mask;
@@ -320,6 +325,7 @@
       GNUNET_free (dll_op);
     }
   }
+  GNUNET_free_non_null (rc->topo_file);
   GNUNET_free (rc);
 }
 
@@ -458,6 +464,18 @@
                                                      rc->random_links,
                                                      
GNUNET_TESTBED_TOPOLOGY_OPTION_END);
     }
+    else if (GNUNET_TESTBED_TOPOLOGY_FROM_FILE == rc->topology)
+    {
+      GNUNET_assert (NULL != rc->topo_file);
+      rc->topology_operation =
+          GNUNET_TESTBED_overlay_configure_topology (NULL,
+                                                     rc->num_peers,
+                                                     rc->peers,
+                                                     &rc->num_oc,
+                                                     rc->topology,
+                                                     rc->topo_file,
+                                                     
GNUNET_TESTBED_TOPOLOGY_OPTION_END);
+    }
     else
       rc->topology_operation =
           GNUNET_TESTBED_overlay_configure_topology (NULL,
@@ -666,7 +684,7 @@
   if ( (GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI == rc->topology)
        || (GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING == rc->topology)
        || (GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD == rc->topology))
-  { 
+  {
     if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "testbed",
                                                             
"OVERLAY_RANDOM_LINKS",
                                                             &random_links))
@@ -685,6 +703,18 @@
     }
     rc->random_links = (unsigned int) random_links;
   }
+  else if (GNUNET_TESTBED_TOPOLOGY_FROM_FILE == rc->topology)
+  {
+    if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "testbed",
+                                                            "TOPOLOGY_FILE",
+                                                            &rc->topo_file))
+    {
+      /* You need to set TOPOLOGY_FILE option to a topolog file */
+      GNUNET_break (0);
+      GNUNET_free (rc);
+      return;
+    }
+  }
   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
                                 &shutdown_run_task, rc);
 }

Modified: gnunet/src/testbed/testbed_api_topology.c
===================================================================
--- gnunet/src/testbed/testbed_api_topology.c   2012-11-22 15:49:49 UTC (rev 
25106)
+++ gnunet/src/testbed/testbed_api_topology.c   2012-11-22 17:03:48 UTC (rev 
25107)
@@ -502,9 +502,6 @@
  * "Emergence of Scaling in Random Networks." Science 286, 509-512, 1999.
  *
  * @param tc the topology context
- * @param links the number of random links to establish
- * @param append GNUNET_YES to add links to existing link array; GNUNET_NO to
- *          create a new link array
  */
 static void
 gen_scale_free (struct TopologyContext *tc)
@@ -547,6 +544,159 @@
 
 
 /**
+ * Generates topology from the given file
+ *
+ * @param tc the topology context
+ * @param filename the filename of the file containing topology data
+ */
+static void
+gen_topo_from_file (struct TopologyContext *tc, const char *filename)
+{
+  char *data;
+  char *end;
+  char *buf;
+  uint64_t fs;
+  uint64_t offset;
+  unsigned long int peer_id;
+  unsigned long int other_peer_id;
+  enum ParseState {
+    
+    /**
+     * We read the peer index
+     */
+    PEER_INDEX,
+
+    /**
+     * We read the other peer indices
+     */
+    OTHER_PEER_INDEX,
+
+  } state;
+  int status;
+
+  status = GNUNET_SYSERR;
+  if (GNUNET_YES != GNUNET_DISK_file_test (filename))
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s not found\n"), filename);
+    return;
+  }
+  if (GNUNET_OK !=
+      GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s has no data\n"), 
filename);
+    return;
+  }
+  data = GNUNET_malloc (fs);
+  if (fs != GNUNET_DISK_fn_read (filename, data, fs))
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR, _("Topology file %s cannot be read\n"),
+         filename);
+    goto _exit;
+  }
+
+  offset = 0;
+  state = PEER_INDEX;
+  buf = data;
+  while (offset < fs)
+  {
+    if (0 != isspace (data[offset]))
+    {
+      offset++;
+      continue;
+    }
+    switch (state)
+    {
+    case PEER_INDEX:
+      buf = strchr (&data[offset], ':');
+      if (NULL == buf)
+      {
+        LOG (GNUNET_ERROR_TYPE_ERROR,
+             _("Failed to read peer index from toology file: %s"), filename);
+        goto _exit;
+      }
+      *buf = '\0';
+      errno = 0;
+      peer_id = (unsigned int) strtoul (&data[offset], &end, 10);
+      if (0 != errno)
+      {
+        LOG (GNUNET_ERROR_TYPE_ERROR,
+             _("Value in given topology file: %s out of range\n"), filename);
+        goto _exit;
+      }
+      if (&data[offset] == end)
+      {
+        LOG (GNUNET_ERROR_TYPE_ERROR,
+             _("Failed to read peer index from topology file: %s"), filename);
+        goto _exit;
+      }
+      if (tc->num_peers <= peer_id)
+      {
+        LOG (GNUNET_ERROR_TYPE_ERROR,
+             _("Topology file need more peers than the given ones\n"),
+             filename);
+        goto _exit;
+      }
+      state = OTHER_PEER_INDEX;
+      offset += ((unsigned int) (buf - &data[offset])) + 1;
+      break;
+    case OTHER_PEER_INDEX:
+      errno = 0;
+      other_peer_id = (unsigned int) strtoul (&data[offset],  &end, 10);
+      if (0 != errno)
+      {
+        LOG (GNUNET_ERROR_TYPE_ERROR,
+             _("Value in given topology file: %s out of range\n"), filename);
+        goto _exit;
+      }
+      if (&data[offset] == end)
+      {
+        LOG (GNUNET_ERROR_TYPE_ERROR,
+             _("Failed to read peer index from topology file: %s"), filename);
+        goto _exit;
+      }
+      if (tc->num_peers <= other_peer_id)
+      {
+        LOG (GNUNET_ERROR_TYPE_ERROR,
+             _("Topology file need more peers than the given ones\n"),
+             filename);
+        goto _exit;
+      }
+      tc->link_array_size++;
+      tc->link_array = GNUNET_realloc (tc->link_array, 
+                                       sizeof (struct OverlayLink) * 
+                                       tc->link_array_size);
+      offset += end - &data[offset];
+      make_link (&tc->link_array[tc->link_array_size - 1], peer_id,
+                 other_peer_id, tc);
+      while (('\n' != data[offset]) && ('|' != data[offset])
+             && (offset < fs))
+        offset++;
+      if ('\n' == data[offset])
+        state = PEER_INDEX;
+      else if ('|' == data[offset])
+      {
+        state = OTHER_PEER_INDEX;
+        offset++;
+      }
+      break;
+    }
+  }
+  status = GNUNET_OK;
+  
+ _exit:
+  GNUNET_free (data);
+  if (GNUNET_OK != status)
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+         "Removing and link data read from the file\n");
+    tc->link_array_size = 0;
+    GNUNET_free_non_null (tc->link_array);
+    tc->link_array = NULL;
+  }
+}
+
+
+/**
  * Configure overall network topology to have a particular shape.
  *
  * @param op_cls closure argument to give with the operation event
@@ -686,6 +836,15 @@
   case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE:
     gen_scale_free (tc);
     break;
+  case GNUNET_TESTBED_TOPOLOGY_FROM_FILE:
+    {
+      const char *filename;
+      
+      filename = va_arg (va, const char *);
+      GNUNET_assert (NULL != filename);
+      gen_topo_from_file (tc, filename);
+    }
+    break;
   default:
     GNUNET_break (0);
     GNUNET_free (tc);
@@ -715,6 +874,8 @@
   GNUNET_TESTBED_operation_queue_insert_
       (c->opq_parallel_topology_config_operations, op);
   GNUNET_TESTBED_operation_begin_wait_ (op);
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Generated %u connections\n", tc->link_array_size);
   if (NULL != max_connections)
     *max_connections = tc->link_array_size;
   return op;




reply via email to

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