aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_testbed_service.h4
-rw-r--r--src/testbed/testbed_api_topology.c89
2 files changed, 90 insertions, 3 deletions
diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h
index 058e23706..12f699975 100644
--- a/src/include/gnunet_testbed_service.h
+++ b/src/include/gnunet_testbed_service.h
@@ -939,9 +939,7 @@ enum GNUNET_TESTBED_TopologyOption
939 GNUNET_TESTBED_TOPOLOGY_RING, 939 GNUNET_TESTBED_TOPOLOGY_RING,
940 940
941 /** 941 /**
942 * 2-d torus. Followed by the number `x' (unsigned int) of peers along the 942 * 2-d torus. No options.
943 * poloidal and the number `y' (unsigned int) of peers along the toroidal. The
944 * total number of peers must be equal to `(x * y)'
945 */ 943 */
946 GNUNET_TESTBED_TOPOLOGY_2D_TORUS, 944 GNUNET_TESTBED_TOPOLOGY_2D_TORUS,
947 945
diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c
index 59d95ef3b..964f7f6a2 100644
--- a/src/testbed/testbed_api_topology.c
+++ b/src/testbed/testbed_api_topology.c
@@ -235,6 +235,92 @@ gen_topo_ring (struct TopologyContext *tc)
235 * Generates ring topology 235 * Generates ring topology
236 * 236 *
237 * @param tc the topology context 237 * @param tc the topology context
238 */
239static void
240gen_topo_2dtorus (struct TopologyContext *tc)
241{
242 double sq;
243 unsigned int sq_floor;
244 unsigned int rows;
245 unsigned int *rows_len;
246 unsigned int x;
247 unsigned int y;
248 unsigned int num_peers;
249 unsigned int cnt;
250 unsigned int offset;
251
252 sq = sqrt (tc->num_peers);
253 sq = floor (sq);
254 sq_floor = (unsigned int) sq;
255 rows = (sq_floor + 1);
256 rows_len = GNUNET_malloc (sizeof (unsigned int) * rows);
257 for (y = 0; y < rows - 1; y++)
258 rows_len[y] = sq_floor;
259 num_peers = sq_floor * sq_floor;
260 GNUNET_assert (num_peers <= tc->num_peers);
261 tc->link_array_size = 2 * num_peers;
262 x = 0;
263 y = 0;
264 while (num_peers < tc->num_peers)
265 {
266 if (x < y)
267 rows_len[rows - 1] = ++x;
268 else
269 rows_len[y++]++;
270 }
271 tc->link_array_size += (x < 2) ? x : 2 * x;
272 tc->link_array_size += (y < 2) ? y : 2 * y;
273 tc->link_array = GNUNET_malloc (sizeof (struct OverlayLink) *
274 tc->link_array_size);
275 cnt = 0;
276 offset = 0;
277 for (y = 0; y < rows; y++)
278 {
279 for (x = 0; x < rows_len[y] - 1; x++)
280 {
281 tc->link_array[cnt].tc = tc;
282 tc->link_array[cnt].A = offset + x;
283 tc->link_array[cnt].B = offset + x + 1;
284 cnt++;
285 }
286 if (0 == x)
287 break;
288 tc->link_array[cnt].tc = tc;
289 tc->link_array[cnt].A = offset + x;
290 tc->link_array[cnt].B = offset;
291 cnt++;
292 offset += rows_len[y];
293 }
294 for (x = 0; x < rows_len[0]; x++)
295 {
296 offset = 0;
297 for (y = 0; y < rows - 1; y++)
298 {
299 if (x == rows_len[y+1])
300 break;
301 GNUNET_assert (x < rows_len[y+1]);
302 tc->link_array[cnt].tc= tc;
303 tc->link_array[cnt].A = offset + x;
304 offset += rows_len[y];
305 tc->link_array[cnt].B = offset + x;
306 cnt++;
307 }
308 if (0 == offset)
309 break;
310 tc->link_array[cnt].tc = tc;
311 tc->link_array[cnt].A = offset + x;
312 tc->link_array[cnt].B = x;
313 cnt++;
314 }
315 GNUNET_assert (cnt == tc->link_array_size);
316 GNUNET_free (rows_len);
317}
318
319
320/**
321 * Generates ring topology
322 *
323 * @param tc the topology context
238 * @param links the number of random links to establish 324 * @param links the number of random links to establish
239 * @param append GNUNET_YES to add links to existing link array; GNUNET_NO to 325 * @param append GNUNET_YES to add links to existing link array; GNUNET_NO to
240 * create a new link array 326 * create a new link array
@@ -405,6 +491,9 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
405 } 491 }
406 } 492 }
407 break; 493 break;
494 case GNUNET_TESTBED_TOPOLOGY_2D_TORUS:
495 gen_topo_2dtorus (tc);
496 break;
408 default: 497 default:
409 GNUNET_break (0); 498 GNUNET_break (0);
410 GNUNET_free (tc); 499 GNUNET_free (tc);