From d5764ce0391a8089341a57e9c8cba41b15cc6c7b Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Tue, 20 Nov 2012 13:08:05 +0000 Subject: [PATCH] - topology name handling --- src/testbed/testbed_api_testbed.c | 31 +------- src/testbed/testbed_api_topology.c | 119 +++++++++++++++++++++++++++++ src/testbed/testbed_api_topology.h | 25 ++++++ 3 files changed, 147 insertions(+), 28 deletions(-) diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c index f195baa1c..f99f72f84 100644 --- a/src/testbed/testbed_api_testbed.c +++ b/src/testbed/testbed_api_testbed.c @@ -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) diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c index 2c1e7b1bc..a49cabd46 100644 --- a/src/testbed/testbed_api_topology.c +++ b/src/testbed/testbed_api_topology.c @@ -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 */ diff --git a/src/testbed/testbed_api_topology.h b/src/testbed/testbed_api_topology.h index b5ae8ce44..b3430f5f3 100644 --- a/src/testbed/testbed_api_topology.h +++ b/src/testbed/testbed_api_topology.h @@ -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 */ -- 2.25.1