aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_topology.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-11-12 18:13:55 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-11-12 18:13:55 +0000
commitcd07db057216ad47693bde4c38b45013628465b0 (patch)
treecd52fb1986c6b051bf5b67517de2700cf8478869 /src/testbed/testbed_api_topology.c
parent61a51d59b76d8c0ab20e06314e7c2581a2b595a1 (diff)
downloadgnunet-cd07db057216ad47693bde4c38b45013628465b0.tar.gz
gnunet-cd07db057216ad47693bde4c38b45013628465b0.zip
implementing small world ring topology
Diffstat (limited to 'src/testbed/testbed_api_topology.c')
-rw-r--r--src/testbed/testbed_api_topology.c146
1 files changed, 109 insertions, 37 deletions
diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c
index d6575adbb..59d95ef3b 100644
--- a/src/testbed/testbed_api_topology.c
+++ b/src/testbed/testbed_api_topology.c
@@ -92,6 +92,11 @@ struct TopologyContext
92 void *op_cls; 92 void *op_cls;
93 93
94 /** 94 /**
95 * The number of peers
96 */
97 unsigned int num_peers;
98
99 /**
95 * The size of the link array 100 * The size of the link array
96 */ 101 */
97 unsigned int link_array_size; 102 unsigned int link_array_size;
@@ -185,6 +190,97 @@ oprelease_overlay_configure_topology (void *cls)
185 190
186 191
187/** 192/**
193 * Generates line topology
194 *
195 * @param tc the topology context
196 */
197static void
198gen_topo_line (struct TopologyContext *tc)
199{
200 unsigned int cnt;
201
202 tc->link_array_size = tc->num_peers - 1;
203 tc->link_array = GNUNET_malloc (sizeof (struct OverlayLink) *
204 tc->link_array_size);
205 for (cnt=0; cnt < (tc->num_peers - 1); cnt++)
206 {
207 tc->link_array[cnt].A = cnt;
208 tc->link_array[cnt].B = cnt + 1;
209 tc->link_array[cnt].tc = tc;
210 }
211}
212
213
214/**
215 * Generates ring topology
216 *
217 * @param tc the topology context
218 */
219static void
220gen_topo_ring (struct TopologyContext *tc)
221{
222 gen_topo_line (tc);
223 tc->link_array_size++;
224 tc->link_array = GNUNET_realloc (tc->link_array,
225 sizeof (struct OverlayLink) *
226 tc->link_array_size);
227 tc->link_array[tc->link_array_size - 1].op = NULL;
228 tc->link_array[tc->link_array_size - 1].tc = tc;
229 tc->link_array[tc->link_array_size - 1].A = tc->num_peers - 1;
230 tc->link_array[tc->link_array_size - 1].B = 0;
231}
232
233
234/**
235 * Generates ring topology
236 *
237 * @param tc the topology context
238 * @param links the number of random links to establish
239 * @param append GNUNET_YES to add links to existing link array; GNUNET_NO to
240 * create a new link array
241 */
242static void
243gen_topo_random (struct TopologyContext *tc, unsigned int links, int append)
244{
245 unsigned int cnt;
246 unsigned int index;
247 uint32_t A_rand;
248 uint32_t B_rand;
249
250 if (GNUNET_YES == append)
251 {
252 GNUNET_assert ((0 < tc->link_array_size) && (NULL != tc->link_array));
253 index = tc->link_array_size;
254 tc->link_array_size += links;
255 tc->link_array = GNUNET_realloc (tc->link_array,
256 sizeof (struct OverlayLink) *
257 tc->link_array_size);
258 }
259 else
260 {
261 GNUNET_assert ((0 == tc->link_array_size) && (NULL == tc->link_array));
262 index = 0;
263 tc->link_array_size = links;
264 tc->link_array = GNUNET_malloc (sizeof (struct OverlayLink) *
265 tc->link_array_size);
266 }
267 for (cnt = 0; cnt < links; cnt++)
268 {
269 do {
270 A_rand = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
271 tc->num_peers);
272 B_rand = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
273 tc->num_peers);
274 } while (A_rand == B_rand);
275 tc->link_array[index + cnt].op = NULL;
276 tc->link_array[index + cnt].A = A_rand;
277 tc->link_array[index + cnt].B = B_rand;
278 tc->link_array[index + cnt].tc = tc;
279 }
280}
281
282
283/**
188 * Configure overall network topology to have a particular shape. 284 * Configure overall network topology to have a particular shape.
189 * 285 *
190 * @param op_cls closure argument to give with the operation event 286 * @param op_cls closure argument to give with the operation event
@@ -264,50 +360,26 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
264 c = peers[0]->controller; 360 c = peers[0]->controller;
265 tc = GNUNET_malloc (sizeof (struct TopologyContext)); 361 tc = GNUNET_malloc (sizeof (struct TopologyContext));
266 tc->peers = peers; 362 tc->peers = peers;
363 tc->num_peers = num_peers;
267 tc->op_cls = op_cls; 364 tc->op_cls = op_cls;
268 switch (topo) 365 switch (topo)
269 { 366 {
270 case GNUNET_TESTBED_TOPOLOGY_LINE: 367 case GNUNET_TESTBED_TOPOLOGY_LINE:
368 gen_topo_line (tc);
369 break;
271 case GNUNET_TESTBED_TOPOLOGY_RING: 370 case GNUNET_TESTBED_TOPOLOGY_RING:
272 tc->link_array_size = 371 gen_topo_ring (tc);
273 (GNUNET_TESTBED_TOPOLOGY_LINE == topo)
274 ? (num_peers - 1) : num_peers;
275 tc->link_array = GNUNET_malloc (sizeof (struct OverlayLink) *
276 tc->link_array_size);
277 for (cnt=0; cnt < (num_peers - 1); cnt++)
278 {
279 tc->link_array[cnt].A = cnt;
280 tc->link_array[cnt].B = cnt + 1;
281 tc->link_array[cnt].tc = tc;
282 }
283 if (GNUNET_TESTBED_TOPOLOGY_RING == topo)
284 {
285 tc->link_array[cnt].A = num_peers - 1;
286 tc->link_array[cnt].B = 0;
287 tc->link_array[cnt].tc = tc;
288 cnt++;
289 }
290 GNUNET_assert (cnt == tc->link_array_size);
291 break; 372 break;
292 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI: 373 case GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI:
293 tc->link_array_size = va_arg (va, unsigned int); 374 gen_topo_random (tc,
294 tc->link_array = GNUNET_malloc (sizeof (struct OverlayLink) * 375 va_arg (va, unsigned int),
295 tc->link_array_size); 376 GNUNET_NO);
296 for (cnt = 0; cnt < tc->link_array_size; cnt++) 377 break;
297 { 378 case GNUNET_TESTBED_TOPOLOGY_SMALL_WORLD_RING:
298 uint32_t A_rand; 379 gen_topo_ring (tc);
299 uint32_t B_rand; 380 gen_topo_random (tc,
300 381 va_arg (va, unsigned int),
301 do { 382 GNUNET_YES);
302 A_rand = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
303 num_peers);
304 B_rand = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
305 num_peers);
306 } while (A_rand == B_rand);
307 tc->link_array[cnt].A = A_rand;
308 tc->link_array[cnt].B = B_rand;
309 tc->link_array[cnt].tc = tc;
310 }
311 break; 383 break;
312 case GNUNET_TESTBED_TOPOLOGY_CLIQUE: 384 case GNUNET_TESTBED_TOPOLOGY_CLIQUE:
313 tc->link_array_size = num_peers * (num_peers - 1); 385 tc->link_array_size = num_peers * (num_peers - 1);