diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-11-20 13:08:05 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-11-20 13:08:05 +0000 |
commit | d5764ce0391a8089341a57e9c8cba41b15cc6c7b (patch) | |
tree | 2607abc16e83a28589785724dd297ab7ead2035e /src | |
parent | b0ca95f6c05e8486e252b4d8bdd6ae16b6d2560a (diff) | |
download | gnunet-d5764ce0391a8089341a57e9c8cba41b15cc6c7b.tar.gz gnunet-d5764ce0391a8089341a57e9c8cba41b15cc6c7b.zip |
- topology name handling
Diffstat (limited to 'src')
-rw-r--r-- | src/testbed/testbed_api_testbed.c | 31 | ||||
-rw-r--r-- | src/testbed/testbed_api_topology.c | 119 | ||||
-rw-r--r-- | 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, | |||
655 | "OVERLAY_TOPOLOGY", | 655 | "OVERLAY_TOPOLOGY", |
656 | &topology)) | 656 | &topology)) |
657 | { | 657 | { |
658 | if (0 == strcasecmp (topology, "RANDOM")) | 658 | if (GNUNET_NO == GNUNET_TESTBED_topology_get_ (&rc->topology, |
659 | topology)) | ||
659 | { | 660 | { |
660 | rc->topology = GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI; | ||
661 | } | ||
662 | else if (0 == strcasecmp (topology, "SMALL_WORLD_RING")) | ||
663 | { | ||
664 | rc->topology = GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING; | ||
665 | } | ||
666 | else if (0 == strcasecmp (topology, "SMALL_WORLD")) | ||
667 | { | ||
668 | rc->topology = GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD; | ||
669 | } | ||
670 | else if (0 == strcasecmp (topology, "CLIQUE")) | ||
671 | { | ||
672 | rc->topology = GNUNET_TESTBED_TOPOLOGY_CLIQUE; | ||
673 | } | ||
674 | else if (0 == strcasecmp (topology, "LINE")) | ||
675 | { | ||
676 | rc->topology = GNUNET_TESTBED_TOPOLOGY_LINE; | ||
677 | } | ||
678 | else if (0 == strcasecmp (topology, "RING")) | ||
679 | { | ||
680 | rc->topology = GNUNET_TESTBED_TOPOLOGY_RING; | ||
681 | } | ||
682 | else if (0 == strcasecmp (topology, "2D_TORUS")) | ||
683 | { | ||
684 | rc->topology = GNUNET_TESTBED_TOPOLOGY_2D_TORUS; | ||
685 | } | ||
686 | else | ||
687 | LOG (GNUNET_ERROR_TYPE_WARNING, | 661 | LOG (GNUNET_ERROR_TYPE_WARNING, |
688 | "Unknown topology %s given in configuration\n", topology); | 662 | "Unknown topology %s given in configuration\n", topology); |
663 | } | ||
689 | GNUNET_free (topology); | 664 | GNUNET_free (topology); |
690 | } | 665 | } |
691 | if ( (GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI == rc->topology) | 666 | 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 | |||
@@ -111,6 +111,81 @@ struct TopologyContext | |||
111 | 111 | ||
112 | 112 | ||
113 | /** | 113 | /** |
114 | * A array of names representing topologies. Should be in sync with enum | ||
115 | * GNUNET_TESTBED_TopologyOption | ||
116 | */ | ||
117 | const char * topology_strings[] = { | ||
118 | |||
119 | /** | ||
120 | * A clique (everyone connected to everyone else). No options. If there are N | ||
121 | * peers this topology results in (N * (N -1)) connections. | ||
122 | */ | ||
123 | "CLIQUE", | ||
124 | |||
125 | /** | ||
126 | * Small-world network (2d torus plus random links). Followed | ||
127 | * by the number of random links to add (unsigned int). | ||
128 | */ | ||
129 | "SMALL_WORLD", | ||
130 | |||
131 | /** | ||
132 | * Small-world network (ring plus random links). Followed | ||
133 | * by the number of random links to add (unsigned int). | ||
134 | */ | ||
135 | "SMALL_WORLD_RING", | ||
136 | |||
137 | /** | ||
138 | * Ring topology. No options. | ||
139 | */ | ||
140 | "RING", | ||
141 | |||
142 | /** | ||
143 | * 2-d torus. No options. | ||
144 | */ | ||
145 | "2D_TORUS", | ||
146 | |||
147 | /** | ||
148 | * Random graph. Followed by the number of random links to be established | ||
149 | * (unsigned int) | ||
150 | */ | ||
151 | "RANDOM", // GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI | ||
152 | |||
153 | /** | ||
154 | * Certain percentage of peers are unable to communicate directly | ||
155 | * replicating NAT conditions. Followed by the fraction of | ||
156 | * NAT'ed peers (float). | ||
157 | */ | ||
158 | "INTERNAT", | ||
159 | |||
160 | /** | ||
161 | * Scale free topology. FIXME: options? | ||
162 | */ | ||
163 | "SCALE_FREE", | ||
164 | |||
165 | /** | ||
166 | * Straight line topology. No options. | ||
167 | */ | ||
168 | "LINE", | ||
169 | |||
170 | /** | ||
171 | * Read a topology from a given file. Followed by the name of the file (const char *). | ||
172 | */ | ||
173 | "FROM_FILE", | ||
174 | |||
175 | /** | ||
176 | * All peers are disconnected. No options. | ||
177 | */ | ||
178 | "NONE", | ||
179 | |||
180 | /** | ||
181 | * End of strings | ||
182 | */ | ||
183 | NULL | ||
184 | |||
185 | }; | ||
186 | |||
187 | |||
188 | /** | ||
114 | * Callback to be called when an overlay_link operation complete | 189 | * Callback to be called when an overlay_link operation complete |
115 | * | 190 | * |
116 | * @param cls element of the link_op array which points to the corresponding operation | 191 | * @param cls element of the link_op array which points to the corresponding operation |
@@ -681,4 +756,48 @@ GNUNET_TESTBED_overlay_configure_topology (void *op_cls, unsigned int num_peers, | |||
681 | return op; | 756 | return op; |
682 | } | 757 | } |
683 | 758 | ||
759 | |||
760 | /** | ||
761 | * Get a topology from a string input. | ||
762 | * | ||
763 | * @param topology where to write the retrieved topology | ||
764 | * @param topology_string The string to attempt to | ||
765 | * get a configuration value from | ||
766 | * @return GNUNET_YES if topology string matched a | ||
767 | * known topology, GNUNET_NO if not | ||
768 | */ | ||
769 | int | ||
770 | GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology, | ||
771 | const char *topology_string) | ||
772 | { | ||
773 | unsigned int cnt; | ||
774 | |||
775 | for (cnt = 0; NULL != topology_strings[cnt]; cnt++) | ||
776 | { | ||
777 | if (0 == strcasecmp (topology_string, topology_strings[cnt])) | ||
778 | { | ||
779 | if (NULL != topology) | ||
780 | *topology = cnt; | ||
781 | return GNUNET_YES; | ||
782 | } | ||
783 | } | ||
784 | return GNUNET_NO; | ||
785 | } | ||
786 | |||
787 | |||
788 | /** | ||
789 | * Returns the string corresponding to the given topology | ||
790 | * | ||
791 | * @param topology the topology | ||
792 | * @return the string (freshly allocated) of given topology; NULL if topology cannot be | ||
793 | * expressed as a string | ||
794 | */ | ||
795 | char * | ||
796 | GNUNET_TESTBED_topology_to_str_ (enum GNUNET_TESTBED_TopologyOption topology) | ||
797 | { | ||
798 | if (GNUNET_TESTBED_TOPOLOGY_OPTION_END <= topology) | ||
799 | return NULL; | ||
800 | return GNUNET_strdup (topology_strings[topology]); | ||
801 | } | ||
802 | |||
684 | /* end of testbed_api_topology.c */ | 803 | /* 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, | |||
42 | unsigned int *rows, | 42 | unsigned int *rows, |
43 | unsigned int **rows_len); | 43 | unsigned int **rows_len); |
44 | 44 | ||
45 | |||
46 | /** | ||
47 | * Get a topology from a string input. | ||
48 | * | ||
49 | * @param topology where to write the retrieved topology | ||
50 | * @param topology_string The string to attempt to | ||
51 | * get a configuration value from | ||
52 | * @return GNUNET_YES if topology string matched a | ||
53 | * known topology, GNUNET_NO if not | ||
54 | */ | ||
55 | int | ||
56 | GNUNET_TESTBED_topology_get_ (enum GNUNET_TESTBED_TopologyOption *topology, | ||
57 | const char *topology_string); | ||
58 | |||
59 | |||
60 | /** | ||
61 | * Returns the string corresponding to the given topology | ||
62 | * | ||
63 | * @param topology the topology | ||
64 | * @return the string (freshly allocated) of given topology; NULL if topology cannot be | ||
65 | * expressed as a string | ||
66 | */ | ||
67 | char * | ||
68 | GNUNET_TESTBED_topology_to_str_ (enum GNUNET_TESTBED_TopologyOption topology); | ||
69 | |||
45 | #endif | 70 | #endif |
46 | /* end of testbed_api_topology.h */ | 71 | /* end of testbed_api_topology.h */ |
47 | 72 | ||