diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2014-01-06 16:37:21 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2014-01-06 16:37:21 +0000 |
commit | 57cba940bf568f0337bfc1a8cffb8542a78e8b1e (patch) | |
tree | b49ba4518fffd16997d7163aa578cf04e41fdaae /src/testbed/generate-underlay-topology.c | |
parent | f15d774da10fa73be8c43982b438f55e576a6936 (diff) | |
download | gnunet-57cba940bf568f0337bfc1a8cffb8542a78e8b1e.tar.gz gnunet-57cba940bf568f0337bfc1a8cffb8542a78e8b1e.zip |
- underlay topology generation
Diffstat (limited to 'src/testbed/generate-underlay-topology.c')
-rw-r--r-- | src/testbed/generate-underlay-topology.c | 241 |
1 files changed, 241 insertions, 0 deletions
diff --git a/src/testbed/generate-underlay-topology.c b/src/testbed/generate-underlay-topology.c new file mode 100644 index 000000000..427c8e66a --- /dev/null +++ b/src/testbed/generate-underlay-topology.c | |||
@@ -0,0 +1,241 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2008--2014 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testbed/generate-underlay-topology.c | ||
23 | * @brief Program to generate a database file containing given underlay topology | ||
24 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_testbed_service.h" | ||
30 | #include "testbed_api_topology.h" | ||
31 | |||
32 | #define LOG(type, ...) \ | ||
33 | GNUNET_log (type, __VA_ARGS__) | ||
34 | |||
35 | |||
36 | #define LOG_ERROR(...) \ | ||
37 | LOG (GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__) | ||
38 | |||
39 | |||
40 | /** | ||
41 | * The topology to generate | ||
42 | */ | ||
43 | enum GNUNET_TESTBED_TopologyOption topology; | ||
44 | |||
45 | /** | ||
46 | * The number of peers to include in the topology | ||
47 | */ | ||
48 | static int num_peers; | ||
49 | |||
50 | /** | ||
51 | * program result | ||
52 | */ | ||
53 | static int exit_result; | ||
54 | |||
55 | |||
56 | /** | ||
57 | * Functions of this type are called to process underlay link | ||
58 | * | ||
59 | * @param cls closure | ||
60 | * @param A offset of first peer | ||
61 | * @param B offset of second peer | ||
62 | * @param bandwidth the bandwidth of the link in bytes per second | ||
63 | * @param latency the latency of link in milliseconds | ||
64 | * @param loss the percentage of messages dropped on the link | ||
65 | * @return GNUNET_OK to continue processing; GNUNET_SYSERR to abort | ||
66 | */ | ||
67 | static int | ||
68 | link_processor (void *cls, | ||
69 | unsigned int A, | ||
70 | unsigned int B, | ||
71 | unsigned int bandwidth, | ||
72 | unsigned int latency, | ||
73 | unsigned int loss) | ||
74 | { | ||
75 | GNUNET_break (0); | ||
76 | return GNUNET_OK; | ||
77 | } | ||
78 | |||
79 | |||
80 | /** | ||
81 | * Main run function. | ||
82 | * | ||
83 | * @param cls NULL | ||
84 | * @param args arguments passed to GNUNET_PROGRAM_run | ||
85 | * @param cfgfile the path to configuration file | ||
86 | * @param cfg the configuration file handle | ||
87 | */ | ||
88 | static void | ||
89 | run (void *cls, char *const *args, const char *cfgfile, | ||
90 | const struct GNUNET_CONFIGURATION_Handle *config) | ||
91 | { | ||
92 | const char *dbfile; | ||
93 | const char *topology_string; | ||
94 | unsigned int arg_uint1; | ||
95 | unsigned int arg_uint2; | ||
96 | const char *arg_str1; | ||
97 | const char *value; | ||
98 | unsigned int argc; | ||
99 | |||
100 | argc = 0; | ||
101 | if (NULL == args) | ||
102 | { | ||
103 | LOG_ERROR (_("Need atleast 2 arguments\n")); | ||
104 | return; | ||
105 | } | ||
106 | if (NULL == (dbfile = args[argc++])) | ||
107 | { | ||
108 | LOG_ERROR (_("Database filename missing\n")); | ||
109 | return; | ||
110 | } | ||
111 | if (NULL == (topology_string = args[argc++])) | ||
112 | { | ||
113 | LOG_ERROR (_("Topology string missing\n")); | ||
114 | return; | ||
115 | } | ||
116 | if (GNUNET_YES != GNUNET_TESTBED_topology_get_ (&topology, topology_string)) | ||
117 | { | ||
118 | LOG_ERROR (_("Invalid topology: %s\n"), topology_string); | ||
119 | return; | ||
120 | } | ||
121 | /* parse for first TOPOOPT. This can either be arg_uint1 or arg_str1 */ | ||
122 | switch (topology) | ||
123 | { | ||
124 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: | ||
125 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: | ||
126 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: | ||
127 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: | ||
128 | if (NULL == (value = args[argc++])) | ||
129 | { | ||
130 | LOG_ERROR (_("An argument is missing for given topology `%s'\n"), | ||
131 | topology_string); | ||
132 | return; | ||
133 | } | ||
134 | if (-1 == SSCANF (value, "%u", &arg_uint1)) | ||
135 | { | ||
136 | LOG_ERROR (_("Invalid argument `%s' given as topology argument\n"), | ||
137 | value); | ||
138 | return; | ||
139 | } | ||
140 | break; | ||
141 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: | ||
142 | if (NULL == (arg_str1 = args[argc++])) | ||
143 | { | ||
144 | LOG_ERROR (_("Filename argument missing for topology `%s'\n"), | ||
145 | topology_string); | ||
146 | return; | ||
147 | } | ||
148 | break; | ||
149 | default: | ||
150 | GNUNET_assert (0); | ||
151 | } | ||
152 | /* parse for second TOPOOPT. Only required for SCALE_FREE topology */ | ||
153 | switch (topology) | ||
154 | { | ||
155 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: | ||
156 | if (NULL == (value = args[argc++])) | ||
157 | { | ||
158 | LOG_ERROR (_("Second argument for topology `%s' is missing\n"), | ||
159 | topology_string); | ||
160 | return; | ||
161 | } | ||
162 | if (-1 == SSCANF (value, "%u", &arg_uint2)) | ||
163 | { | ||
164 | LOG_ERROR (_("Invalid argument `%s'; expecting unsigned int\n"), value); | ||
165 | return; | ||
166 | } | ||
167 | break; | ||
168 | default: | ||
169 | GNUNET_assert (0); | ||
170 | } | ||
171 | /* contruct topologies */ | ||
172 | switch (topology) | ||
173 | { | ||
174 | case GNUNET_TESTBED_TOPOLOGY_LINE: | ||
175 | case GNUNET_TESTBED_TOPOLOGY_RING: | ||
176 | case GNUNET_TESTBED_TOPOLOGY_CLIQUE: | ||
177 | case GNUNET_TESTBED_TOPOLOGY_2D_TORUS: | ||
178 | GNUNET_TESTBED_underlay_construct_ (num_peers, link_processor, NULL, | ||
179 | topology); | ||
180 | break; | ||
181 | case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: | ||
182 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING: | ||
183 | case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD: | ||
184 | GNUNET_TESTBED_underlay_construct_ (num_peers, link_processor, NULL, | ||
185 | topology, | ||
186 | arg_uint1); | ||
187 | break; | ||
188 | case GNUNET_TESTBED_TOPOLOGY_FROM_FILE: | ||
189 | GNUNET_TESTBED_underlay_construct_ (num_peers, link_processor, NULL, | ||
190 | topology, | ||
191 | arg_str1); | ||
192 | break; | ||
193 | case GNUNET_TESTBED_TOPOLOGY_SCALE_FREE: | ||
194 | GNUNET_TESTBED_underlay_construct_ (num_peers, link_processor, NULL, | ||
195 | topology, | ||
196 | arg_uint1, | ||
197 | arg_uint2); | ||
198 | break; | ||
199 | default: | ||
200 | GNUNET_assert (0); | ||
201 | } | ||
202 | } | ||
203 | |||
204 | |||
205 | /** | ||
206 | * Main | ||
207 | */ | ||
208 | int | ||
209 | main (int argc, char *const argv[]) | ||
210 | { | ||
211 | struct GNUNET_GETOPT_CommandLineOption option[] = { | ||
212 | GNUNET_GETOPT_OPTION_END | ||
213 | }; | ||
214 | int ret; | ||
215 | |||
216 | exit_result = GNUNET_SYSERR; | ||
217 | ret = | ||
218 | GNUNET_PROGRAM_run (argc, argv, "gnunet-underlay-topology", | ||
219 | _("Generates SQLite3 database representing a given underlay topology.\n" | ||
220 | "Usage: gnunet-underlay-topology [OPTIONS] db-filename TOPO [TOPOOPTS]\n" | ||
221 | "The following options are available for TOPO followed by TOPOOPTS if applicable:\n" | ||
222 | "\t LINE\n" | ||
223 | "\t RING\n" | ||
224 | "\t RANDOM <num_rnd_links>\n" | ||
225 | "\t SMALL_WORLD <num_rnd_links>\n" | ||
226 | "\t SMALL_WORLD_RING <num_rnd_links>\n" | ||
227 | "\t CLIQUE\n" | ||
228 | "\t 2D_TORUS\n" | ||
229 | "\t SCALE_FREE <cap> <m>\n" | ||
230 | "\t FROM_FILE <filename>\n" | ||
231 | "TOPOOPTS:\n" | ||
232 | "\t num_rnd_links: The number of random links\n" | ||
233 | "\t cap: the maximum number of links a node can have\n" | ||
234 | "\t m: the number of links a node should have while joining the network\n" | ||
235 | "\t filename: the path of the file which contains topology information\n" | ||
236 | "NOTE: the format of the above file is descibed here: https://www.gnunet.org/content/topology-file-format\n"), | ||
237 | option, &run, NULL); | ||
238 | if ((GNUNET_OK != ret) || (GNUNET_OK != exit_result)) | ||
239 | return 1; | ||
240 | return 0; | ||
241 | } | ||