- topology name handling
authorSree Harsha Totakura <totakura@in.tum.de>
Tue, 20 Nov 2012 13:08:05 +0000 (13:08 +0000)
committerSree Harsha Totakura <totakura@in.tum.de>
Tue, 20 Nov 2012 13:08:05 +0000 (13:08 +0000)
src/testbed/testbed_api_testbed.c
src/testbed/testbed_api_topology.c
src/testbed/testbed_api_topology.h

index f195baa1ca2769db0799d8277a8dad1d461d6f7c..f99f72f84417ae7f44513c2c7503789f0264cc4c 100644 (file)
@@ -655,37 +655,12 @@ GNUNET_TESTBED_run (const char *host_filename,
                                                           "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)
index 2c1e7b1bc6e14eb0809a7a6369d82d0cd680d483..a49cabd46f00f97cafe312549a822ffb49e90480 100644 (file)
@@ -110,6 +110,81 @@ struct TopologyContext
 };
 
 
+/**
+ * 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
  *
@@ -681,4 +756,48 @@ GNUNET_TESTBED_overlay_configure_topology (void *op_cls, unsigned int num_peers,
   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 */
index b5ae8ce4417e861e8d1162e373ef58beb81c317a..b3430f5f3875b520e5c655e1e69dd5a632a85082 100644 (file)
@@ -42,6 +42,31 @@ GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers,
                                    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 */