gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r25068 - gnunet/src/testbed
Date: Tue, 20 Nov 2012 14:08:05 +0100

Author: harsha
Date: 2012-11-20 14:08:05 +0100 (Tue, 20 Nov 2012)
New Revision: 25068

Modified:
   gnunet/src/testbed/testbed_api_testbed.c
   gnunet/src/testbed/testbed_api_topology.c
   gnunet/src/testbed/testbed_api_topology.h
Log:
- topology name handling

Modified: gnunet/src/testbed/testbed_api_testbed.c
===================================================================
--- gnunet/src/testbed/testbed_api_testbed.c    2012-11-20 12:29:57 UTC (rev 
25067)
+++ gnunet/src/testbed/testbed_api_testbed.c    2012-11-20 13:08:05 UTC (rev 
25068)
@@ -655,37 +655,12 @@
                                                           "OVERLAY_TOPOLOGY",
                                                           &topology))
   {
-    if (0 == strcasecmp (topology, "RANDOM"))
+    if (GNUNET_NO == GNUNET_TESTBED_topology_get_ (&rc->topology,
+                                                    topology))
     {
-      rc->topology = GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI;      
-    }
-    else if (0 == strcasecmp (topology, "SMALL_WORLD_RING"))
-    {
-      rc->topology = GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING;
-    }
-    else if (0 == strcasecmp (topology, "SMALL_WORLD"))
-    {
-      rc->topology = GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD;
-    }
-    else if (0 == strcasecmp (topology, "CLIQUE"))
-    {
-      rc->topology = GNUNET_TESTBED_TOPOLOGY_CLIQUE;
-    }
-    else if (0 == strcasecmp (topology, "LINE"))
-    {
-      rc->topology = GNUNET_TESTBED_TOPOLOGY_LINE;
-    }
-    else if (0 == strcasecmp (topology, "RING"))
-    {
-      rc->topology = GNUNET_TESTBED_TOPOLOGY_RING;
-    }
-    else if (0 == strcasecmp (topology, "2D_TORUS"))
-    {
-      rc->topology = GNUNET_TESTBED_TOPOLOGY_2D_TORUS;
-    }
-    else
       LOG (GNUNET_ERROR_TYPE_WARNING,
            "Unknown topology %s given in configuration\n", topology);
+    }
     GNUNET_free (topology);
   }
   if ( (GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI == rc->topology)

Modified: gnunet/src/testbed/testbed_api_topology.c
===================================================================
--- gnunet/src/testbed/testbed_api_topology.c   2012-11-20 12:29:57 UTC (rev 
25067)
+++ gnunet/src/testbed/testbed_api_topology.c   2012-11-20 13:08:05 UTC (rev 
25068)
@@ -111,6 +111,81 @@
 
 
 /**
+ * A array of names representing topologies. Should be in sync with enum
+ * GNUNET_TESTBED_TopologyOption
+ */
+const char * topology_strings[] = {
+    
+    /**
+     * A clique (everyone connected to everyone else).  No options. If there 
are N
+     * peers this topology results in (N * (N -1)) connections.
+     */
+    "CLIQUE",
+
+    /**
+     * Small-world network (2d torus plus random links).  Followed
+     * by the number of random links to add (unsigned int).
+     */
+    "SMALL_WORLD",
+
+    /**
+     * Small-world network (ring plus random links).  Followed
+     * by the number of random links to add (unsigned int).
+     */
+    "SMALL_WORLD_RING",
+
+    /**
+     * Ring topology.  No options.
+     */
+    "RING",
+
+    /**
+     * 2-d torus.  No options.
+     */
+    "2D_TORUS",
+
+    /**
+     * Random graph.  Followed by the number of random links to be established
+     * (unsigned int)
+     */
+    "RANDOM", // GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI
+
+    /**
+     * Certain percentage of peers are unable to communicate directly
+     * replicating NAT conditions.  Followed by the fraction of
+     * NAT'ed peers (float).
+     */
+    "INTERNAT",
+
+    /**
+     * Scale free topology.   FIXME: options?
+     */
+    "SCALE_FREE",
+
+    /**
+     * Straight line topology.  No options.
+     */
+    "LINE",
+
+    /**
+     * Read a topology from a given file.  Followed by the name of the file 
(const char *).
+     */
+    "FROM_FILE",
+
+    /**
+     * All peers are disconnected.  No options.
+     */
+    "NONE",
+  
+    /**
+     * End of strings
+     */
+    NULL
+  
+  };
+
+
+/**
  * Callback to be called when an overlay_link operation complete
  *
  * @param cls element of the link_op array which points to the corresponding 
operation
@@ -681,4 +756,48 @@
   return op;
 }
 
+
+/**
+ * Get a topology from a string input.
+ *
+ * @param topology where to write the retrieved topology
+ * @param topology_string The string to attempt to
+ *        get a configuration value from
+ * @return GNUNET_YES if topology string matched a
+ *         known topology, GNUNET_NO if not
+ */
+int
+GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology,
+                              const char *topology_string)
+{  
+  unsigned int cnt;
+
+  for (cnt = 0; NULL != topology_strings[cnt]; cnt++)
+  {
+    if (0 == strcasecmp (topology_string, topology_strings[cnt]))
+    {
+      if (NULL != topology)
+        *topology = cnt;
+      return GNUNET_YES;
+    }
+  }
+  return GNUNET_NO;
+}
+
+
+/**
+ * Returns the string corresponding to the given topology
+ *
+ * @param topology the topology
+ * @return the string (freshly allocated) of given topology; NULL if topology 
cannot be
+ *           expressed as a string
+ */
+char *
+GNUNET_TESTBED_topology_to_str_ (enum GNUNET_TESTBED_TopologyOption topology)
+{
+  if (GNUNET_TESTBED_TOPOLOGY_OPTION_END <= topology)
+    return NULL;
+  return GNUNET_strdup (topology_strings[topology]);
+}
+
 /* end of testbed_api_topology.c */

Modified: gnunet/src/testbed/testbed_api_topology.h
===================================================================
--- gnunet/src/testbed/testbed_api_topology.h   2012-11-20 12:29:57 UTC (rev 
25067)
+++ gnunet/src/testbed/testbed_api_topology.h   2012-11-20 13:08:05 UTC (rev 
25068)
@@ -42,6 +42,31 @@
                                    unsigned int *rows,
                                    unsigned int **rows_len);
 
+
+/**
+ * Get a topology from a string input.
+ *
+ * @param topology where to write the retrieved topology
+ * @param topology_string The string to attempt to
+ *        get a configuration value from
+ * @return GNUNET_YES if topology string matched a
+ *         known topology, GNUNET_NO if not
+ */
+int
+GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology,
+                              const char *topology_string);
+
+
+/**
+ * Returns the string corresponding to the given topology
+ *
+ * @param topology the topology
+ * @return the string (freshly allocated) of given topology; NULL if topology 
cannot be
+ *           expressed as a string
+ */
+char *
+GNUNET_TESTBED_topology_to_str_ (enum GNUNET_TESTBED_TopologyOption topology);
+
 #endif  
 /* end of  testbed_api_topology.h */
 




reply via email to

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