diff options
-rw-r--r-- | src/testbed/Makefile.am | 2 | ||||
-rw-r--r-- | src/testbed/testbed_api_testbed.c | 33 | ||||
-rw-r--r-- | src/testbed/testbed_api_topology.c | 83 | ||||
-rw-r--r-- | src/testbed/testbed_api_topology.h | 47 |
4 files changed, 108 insertions, 57 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index a08f320b8..130014836 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am | |||
@@ -65,7 +65,7 @@ libgnunettestbed_la_SOURCES = \ | |||
65 | testbed_api_statistics.c \ | 65 | testbed_api_statistics.c \ |
66 | testbed_api_testbed.c \ | 66 | testbed_api_testbed.c \ |
67 | testbed_api_test.c \ | 67 | testbed_api_test.c \ |
68 | testbed_api_topology.c | 68 | testbed_api_topology.c testbed_api_topology.h |
69 | libgnunettestbed_la_LIBADD = $(XLIB) \ | 69 | libgnunettestbed_la_LIBADD = $(XLIB) \ |
70 | $(top_builddir)/src/core/libgnunetcore.la \ | 70 | $(top_builddir)/src/core/libgnunetcore.la \ |
71 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 71 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c index cfe6370ea..a7e15dc6b 100644 --- a/src/testbed/testbed_api_testbed.c +++ b/src/testbed/testbed_api_testbed.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include "gnunet_testbed_service.h" | 29 | #include "gnunet_testbed_service.h" |
30 | #include "testbed_api_peers.h" | 30 | #include "testbed_api_peers.h" |
31 | #include "testbed_api_hosts.h" | 31 | #include "testbed_api_hosts.h" |
32 | #include "testbed_api_topology.h" | ||
32 | 33 | ||
33 | /** | 34 | /** |
34 | * Generic loggins shorthand | 35 | * Generic loggins shorthand |
@@ -672,38 +673,8 @@ GNUNET_TESTBED_run (const char *host_filename, | |||
672 | } | 673 | } |
673 | else if (0 == strcasecmp (topology, "2D_TORUS")) | 674 | else if (0 == strcasecmp (topology, "2D_TORUS")) |
674 | { | 675 | { |
675 | double sq; | ||
676 | unsigned int sq_floor; | ||
677 | unsigned int rows; | ||
678 | unsigned int *rows_len; | ||
679 | unsigned int x; | ||
680 | unsigned int y; | ||
681 | unsigned int n; | ||
682 | |||
683 | rc->topology = GNUNET_TESTBED_TOPOLOGY_2D_TORUS; | 676 | rc->topology = GNUNET_TESTBED_TOPOLOGY_2D_TORUS; |
684 | sq = sqrt ((double) num_peers); | 677 | rc->num_oc = GNUNET_TESTBED_2dtorus_calc_links (num_peers, NULL, NULL); |
685 | sq = floor (sq); | ||
686 | sq_floor = (unsigned int) sq; | ||
687 | rows = (sq_floor + 1); | ||
688 | rows_len = GNUNET_malloc (sizeof (unsigned int) * rows); | ||
689 | for (y = 0; y < rows - 1; y++) | ||
690 | rows_len[y] = sq_floor; | ||
691 | n = sq_floor * sq_floor; | ||
692 | GNUNET_assert (n <= num_peers); | ||
693 | rc->num_oc = 2 * n; | ||
694 | x = 0; | ||
695 | y = 0; | ||
696 | while (n < num_peers) | ||
697 | { | ||
698 | if (x < y) | ||
699 | rows_len[rows - 1] = ++x; | ||
700 | else | ||
701 | rows_len[y++]++; | ||
702 | n++; | ||
703 | } | ||
704 | rc->num_oc += (x < 2) ? x : 2 * x; | ||
705 | rc->num_oc += (y < 2) ? y : 2 * y; | ||
706 | GNUNET_free (rows_len); | ||
707 | } | 678 | } |
708 | else | 679 | else |
709 | LOG (GNUNET_ERROR_TYPE_WARNING, | 680 | LOG (GNUNET_ERROR_TYPE_WARNING, |
diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c index effc428e8..9c62502c4 100644 --- a/src/testbed/testbed_api_topology.c +++ b/src/testbed/testbed_api_topology.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "testbed_api.h" | 28 | #include "testbed_api.h" |
29 | #include "testbed_api_peers.h" | 29 | #include "testbed_api_peers.h" |
30 | #include "testbed_api_operations.h" | 30 | #include "testbed_api_operations.h" |
31 | #include "testbed_api_topology.h" | ||
31 | 32 | ||
32 | /** | 33 | /** |
33 | * Generic loggins shorthand | 34 | * Generic loggins shorthand |
@@ -232,49 +233,81 @@ gen_topo_ring (struct TopologyContext *tc) | |||
232 | 233 | ||
233 | 234 | ||
234 | /** | 235 | /** |
235 | * Generates ring topology | 236 | * Returns the number of links that are required to generate a 2d torus for the |
237 | * given number of peers. Also returns the arrangment (number of rows and the | ||
238 | * length of each row) | ||
236 | * | 239 | * |
237 | * @param tc the topology context | 240 | * @param num_peers number of peers |
241 | * @param rows number of rows in the 2d torus. Can be NULL | ||
242 | * @param rows_len the length of each row. This array will be allocated | ||
243 | * fresh. The caller should free it. Can be NULL | ||
238 | */ | 244 | */ |
239 | static void | 245 | unsigned int |
240 | gen_topo_2dtorus (struct TopologyContext *tc) | 246 | GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, |
247 | unsigned int *rows, | ||
248 | unsigned int **rows_len) | ||
241 | { | 249 | { |
242 | double sq; | 250 | double sq; |
243 | unsigned int sq_floor; | 251 | unsigned int sq_floor; |
244 | unsigned int rows; | 252 | unsigned int _rows; |
245 | unsigned int *rows_len; | 253 | unsigned int *_rows_len; |
246 | unsigned int x; | 254 | unsigned int x; |
247 | unsigned int y; | 255 | unsigned int y; |
248 | unsigned int num_peers; | 256 | unsigned int _num_peers; |
249 | unsigned int cnt; | 257 | unsigned int cnt; |
250 | unsigned int offset; | 258 | |
251 | 259 | sq = sqrt (num_peers); | |
252 | sq = sqrt (tc->num_peers); | ||
253 | sq = floor (sq); | 260 | sq = floor (sq); |
254 | sq_floor = (unsigned int) sq; | 261 | sq_floor = (unsigned int) sq; |
255 | rows = (sq_floor + 1); | 262 | _rows = (sq_floor + 1); |
256 | rows_len = GNUNET_malloc (sizeof (unsigned int) * rows); | 263 | _rows_len = GNUNET_malloc (sizeof (unsigned int) * _rows); |
257 | for (y = 0; y < rows - 1; y++) | 264 | for (y = 0; y < _rows - 1; y++) |
258 | rows_len[y] = sq_floor; | 265 | _rows_len[y] = sq_floor; |
259 | num_peers = sq_floor * sq_floor; | 266 | _num_peers = sq_floor * sq_floor; |
260 | GNUNET_assert (num_peers <= tc->num_peers); | 267 | cnt = 2 * _num_peers; |
261 | tc->link_array_size = 2 * num_peers; | ||
262 | x = 0; | 268 | x = 0; |
263 | y = 0; | 269 | y = 0; |
264 | while (num_peers < tc->num_peers) | 270 | while (_num_peers < num_peers) |
265 | { | 271 | { |
266 | if (x < y) | 272 | if (x < y) |
267 | rows_len[rows - 1] = ++x; | 273 | _rows_len[_rows - 1] = ++x; |
268 | else | 274 | else |
269 | rows_len[y++]++; | 275 | _rows_len[y++]++; |
270 | num_peers++; | 276 | _num_peers++; |
271 | } | 277 | } |
272 | tc->link_array_size += (x < 2) ? x : 2 * x; | 278 | cnt += (x < 2) ? x : 2 * x; |
273 | tc->link_array_size += (y < 2) ? y : 2 * y; | 279 | cnt += (y < 2) ? y : 2 * y; |
280 | if (0 == _rows_len[_rows - 1]) | ||
281 | _rows--; | ||
282 | if (NULL != rows) | ||
283 | *rows = _rows; | ||
284 | if (NULL != rows_len) | ||
285 | *rows_len = _rows_len; | ||
286 | else | ||
287 | GNUNET_free (_rows_len); | ||
288 | return cnt; | ||
289 | } | ||
290 | |||
291 | |||
292 | /** | ||
293 | * Generates ring topology | ||
294 | * | ||
295 | * @param tc the topology context | ||
296 | */ | ||
297 | static void | ||
298 | gen_topo_2dtorus (struct TopologyContext *tc) | ||
299 | { | ||
300 | unsigned int rows; | ||
301 | unsigned int *rows_len; | ||
302 | unsigned int x; | ||
303 | unsigned int y; | ||
304 | unsigned int cnt; | ||
305 | unsigned int offset; | ||
306 | |||
307 | tc->link_array_size = GNUNET_TESTBED_2dtorus_calc_links (tc->num_peers, &rows, | ||
308 | &rows_len); | ||
274 | tc->link_array = GNUNET_malloc (sizeof (struct OverlayLink) * | 309 | tc->link_array = GNUNET_malloc (sizeof (struct OverlayLink) * |
275 | tc->link_array_size); | 310 | tc->link_array_size); |
276 | if (0 == rows_len[rows - 1]) | ||
277 | rows--; | ||
278 | cnt = 0; | 311 | cnt = 0; |
279 | offset = 0; | 312 | offset = 0; |
280 | for (y = 0; y < rows; y++) | 313 | for (y = 0; y < rows; y++) |
diff --git a/src/testbed/testbed_api_topology.h b/src/testbed/testbed_api_topology.h new file mode 100644 index 000000000..b5ae8ce44 --- /dev/null +++ b/src/testbed/testbed_api_topology.h | |||
@@ -0,0 +1,47 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2008--2012 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/testbed_api_topology.h | ||
23 | * @brief header for intra library exported functions | ||
24 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | ||
25 | */ | ||
26 | |||
27 | #ifndef TESTBED_API_TOPOLOGY_H | ||
28 | #define TESTBED_API_TOPOLOGY_H | ||
29 | |||
30 | /** | ||
31 | * Returns the number of links that are required to generate a 2d torus for the | ||
32 | * given number of peers. Also returns the arrangment (number of rows and the | ||
33 | * length of each row) | ||
34 | * | ||
35 | * @param num_peers number of peers | ||
36 | * @param rows number of rows in the 2d torus. Can be NULL. | ||
37 | * @param rows_len the length of each row. This array will be allocated | ||
38 | * fresh. The caller should free it. Can be NULL. | ||
39 | */ | ||
40 | unsigned int | ||
41 | GNUNET_TESTBED_2dtorus_calc_links (unsigned int num_peers, | ||
42 | unsigned int *rows, | ||
43 | unsigned int **rows_len); | ||
44 | |||
45 | #endif | ||
46 | /* end of testbed_api_topology.h */ | ||
47 | |||