diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-04-28 12:58:35 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-04-28 12:58:35 +0000 |
commit | a31eacdf89f2c932704cefb6498264895db01eab (patch) | |
tree | 8c3e57361d6634936304909ae95ceebda60c8be9 /src/testing/testing_group.c | |
parent | d83a3d2ac2a33d43239bbd5703574872081ba81f (diff) | |
download | gnunet-a31eacdf89f2c932704cefb6498264895db01eab.tar.gz gnunet-a31eacdf89f2c932704cefb6498264895db01eab.zip |
testing bugfix, add scale free topology
Diffstat (limited to 'src/testing/testing_group.c')
-rw-r--r-- | src/testing/testing_group.c | 69 |
1 files changed, 61 insertions, 8 deletions
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 136b167fb..43ebd5e25 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c | |||
@@ -82,10 +82,15 @@ struct PeerData | |||
82 | */ | 82 | */ |
83 | struct GNUNET_TESTING_Daemon *daemon; | 83 | struct GNUNET_TESTING_Daemon *daemon; |
84 | 84 | ||
85 | /* | 85 | /** |
86 | * Linked list of peer connections (simply indexes of PeerGroup) | 86 | * Linked list of peer connections (simply indexes of PeerGroup) |
87 | */ | 87 | */ |
88 | struct PeerConnection *connected_peers; | 88 | struct PeerConnection *connected_peers; |
89 | |||
90 | /** | ||
91 | * Total number of connections this peer has | ||
92 | */ | ||
93 | int num_connections; | ||
89 | }; | 94 | }; |
90 | 95 | ||
91 | 96 | ||
@@ -332,6 +337,7 @@ add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigne | |||
332 | new_first->daemon = pg->peers[second].daemon; | 337 | new_first->daemon = pg->peers[second].daemon; |
333 | new_first->next = pg->peers[first].connected_peers; | 338 | new_first->next = pg->peers[first].connected_peers; |
334 | pg->peers[first].connected_peers = new_first; | 339 | pg->peers[first].connected_peers = new_first; |
340 | pg->peers[first].num_connections++; | ||
335 | added++; | 341 | added++; |
336 | } | 342 | } |
337 | 343 | ||
@@ -341,12 +347,52 @@ add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigne | |||
341 | new_second->daemon = pg->peers[first].daemon; | 347 | new_second->daemon = pg->peers[first].daemon; |
342 | new_second->next = pg->peers[second].connected_peers; | 348 | new_second->next = pg->peers[second].connected_peers; |
343 | pg->peers[second].connected_peers = new_second; | 349 | pg->peers[second].connected_peers = new_second; |
350 | pg->peers[first].num_connections++; | ||
344 | added++; | 351 | added++; |
345 | } | 352 | } |
346 | 353 | ||
347 | return added; | 354 | return added; |
348 | } | 355 | } |
349 | 356 | ||
357 | static int | ||
358 | create_scale_free (struct GNUNET_TESTING_PeerGroup *pg) | ||
359 | { | ||
360 | |||
361 | int total_connections; | ||
362 | int outer_count; | ||
363 | int i; | ||
364 | int previous_total_connections; | ||
365 | double random; | ||
366 | double probability; | ||
367 | |||
368 | GNUNET_assert(pg->total > 1); | ||
369 | |||
370 | /* Add a connection between the first two nodes */ | ||
371 | total_connections = add_connections(pg, 0, 1); | ||
372 | |||
373 | for (outer_count = 1; outer_count < pg->total - 1; outer_count++) | ||
374 | { | ||
375 | previous_total_connections = total_connections; | ||
376 | for (i = 0; i < outer_count; i++) | ||
377 | { | ||
378 | probability = pg->peers[i].num_connections / previous_total_connections; | ||
379 | random = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, | ||
380 | (uint64_t)-1LL)) / ( (double) (uint64_t) -1LL); | ||
381 | if (random < probability) | ||
382 | { | ||
383 | #if VERBOSE_TESTING | ||
384 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
385 | "Connecting peer %d to peer %d\n", | ||
386 | outer_count, i); | ||
387 | #endif | ||
388 | total_connections += add_connections(pg, outer_count, i); | ||
389 | } | ||
390 | } | ||
391 | } | ||
392 | |||
393 | return total_connections; | ||
394 | } | ||
395 | |||
350 | int | 396 | int |
351 | create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg) | 397 | create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg) |
352 | { | 398 | { |
@@ -1076,52 +1122,59 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg) | |||
1076 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: | 1122 | case GNUNET_TESTING_TOPOLOGY_CLIQUE: |
1077 | #if VERBOSE_TESTING | 1123 | #if VERBOSE_TESTING |
1078 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1079 | _("Creating clique topology (may take a bit!)\n")); | 1125 | _("Creating clique topology\n")); |
1080 | #endif | 1126 | #endif |
1081 | num_connections = create_clique (pg); | 1127 | num_connections = create_clique (pg); |
1082 | break; | 1128 | break; |
1083 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: | 1129 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: |
1084 | #if VERBOSE_TESTING | 1130 | #if VERBOSE_TESTING |
1085 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1131 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1086 | _("Creating small world (ring) topology (may take a bit!)\n")); | 1132 | _("Creating small world (ring) topology\n")); |
1087 | #endif | 1133 | #endif |
1088 | num_connections = create_small_world_ring (pg); | 1134 | num_connections = create_small_world_ring (pg); |
1089 | break; | 1135 | break; |
1090 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: | 1136 | case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: |
1091 | #if VERBOSE_TESTING | 1137 | #if VERBOSE_TESTING |
1092 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1093 | _("Creating small world (2d-torus) topology (may take a bit!)\n")); | 1139 | _("Creating small world (2d-torus) topology\n")); |
1094 | #endif | 1140 | #endif |
1095 | num_connections = create_small_world (pg); | 1141 | num_connections = create_small_world (pg); |
1096 | break; | 1142 | break; |
1097 | case GNUNET_TESTING_TOPOLOGY_RING: | 1143 | case GNUNET_TESTING_TOPOLOGY_RING: |
1098 | #if VERBOSE_TESTING | 1144 | #if VERBOSE_TESTING |
1099 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1100 | _("Creating ring topology (may take a bit!)\n")); | 1146 | _("Creating ring topology\n")); |
1101 | #endif | 1147 | #endif |
1102 | num_connections = create_ring (pg); | 1148 | num_connections = create_ring (pg); |
1103 | break; | 1149 | break; |
1104 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: | 1150 | case GNUNET_TESTING_TOPOLOGY_2D_TORUS: |
1105 | #if VERBOSE_TESTING | 1151 | #if VERBOSE_TESTING |
1106 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1107 | _("Creating 2d torus topology (may take a bit!)\n")); | 1153 | _("Creating 2d torus topology\n")); |
1108 | #endif | 1154 | #endif |
1109 | num_connections = create_2d_torus (pg); | 1155 | num_connections = create_2d_torus (pg); |
1110 | break; | 1156 | break; |
1111 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: | 1157 | case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: |
1112 | #if VERBOSE_TESTING | 1158 | #if VERBOSE_TESTING |
1113 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1114 | _("Creating Erdos-Renyi topology (may take a bit!)\n")); | 1160 | _("Creating Erdos-Renyi topology\n")); |
1115 | #endif | 1161 | #endif |
1116 | num_connections = create_erdos_renyi (pg); | 1162 | num_connections = create_erdos_renyi (pg); |
1117 | break; | 1163 | break; |
1118 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: | 1164 | case GNUNET_TESTING_TOPOLOGY_INTERNAT: |
1119 | #if VERBOSE_TESTING | 1165 | #if VERBOSE_TESTING |
1120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1166 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1121 | _("Creating InterNAT topology (may take a bit!)\n")); | 1167 | _("Creating InterNAT topology\n")); |
1122 | #endif | 1168 | #endif |
1123 | num_connections = create_nated_internet (pg); | 1169 | num_connections = create_nated_internet (pg); |
1124 | break; | 1170 | break; |
1171 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: | ||
1172 | #if VERBOSE_TESTING | ||
1173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1174 | _("Creating Scale Free topology\n")); | ||
1175 | #endif | ||
1176 | num_connections = create_scale_free (pg); | ||
1177 | break; | ||
1125 | case GNUNET_TESTING_TOPOLOGY_NONE: | 1178 | case GNUNET_TESTING_TOPOLOGY_NONE: |
1126 | num_connections = 0; | 1179 | num_connections = 0; |
1127 | break; | 1180 | break; |