aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_group.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_group.c')
-rw-r--r--src/testing/testing_group.c165
1 files changed, 87 insertions, 78 deletions
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c
index 43ebd5e25..e617bc113 100644
--- a/src/testing/testing_group.c
+++ b/src/testing/testing_group.c
@@ -27,7 +27,7 @@
27#include "gnunet_arm_service.h" 27#include "gnunet_arm_service.h"
28#include "gnunet_testing_lib.h" 28#include "gnunet_testing_lib.h"
29 29
30#define VERBOSE_TESTING GNUNET_NO 30#define VERBOSE_TESTING GNUNET_YES
31 31
32/** 32/**
33 * Lowest port used for GNUnet testing. Should be high enough to not 33 * Lowest port used for GNUnet testing. Should be high enough to not
@@ -354,14 +354,28 @@ add_connections(struct GNUNET_TESTING_PeerGroup *pg, unsigned int first, unsigne
354 return added; 354 return added;
355} 355}
356 356
357/**
358 * Scale free network construction as described in:
359 *
360 * "Emergence of Scaling in Random Networks." Science 286, 509-512, 1999.
361 *
362 * Start with a network of "one" peer, then progressively add
363 * peers up to the total number. At each step, iterate over
364 * all possible peers and connect new peer based on number of
365 * existing connections of the target peer.
366 *
367 * @param pg the peer group we are dealing with
368 *
369 * @return the number of connections created
370 */
357static int 371static int
358create_scale_free (struct GNUNET_TESTING_PeerGroup *pg) 372create_scale_free (struct GNUNET_TESTING_PeerGroup *pg)
359{ 373{
360 374
361 int total_connections; 375 unsigned int total_connections;
362 int outer_count; 376 unsigned int outer_count;
363 int i; 377 unsigned int i;
364 int previous_total_connections; 378 unsigned int previous_total_connections;
365 double random; 379 double random;
366 double probability; 380 double probability;
367 381
@@ -370,14 +384,19 @@ create_scale_free (struct GNUNET_TESTING_PeerGroup *pg)
370 /* Add a connection between the first two nodes */ 384 /* Add a connection between the first two nodes */
371 total_connections = add_connections(pg, 0, 1); 385 total_connections = add_connections(pg, 0, 1);
372 386
373 for (outer_count = 1; outer_count < pg->total - 1; outer_count++) 387 for (outer_count = 1; outer_count < pg->total; outer_count++)
374 { 388 {
375 previous_total_connections = total_connections; 389 previous_total_connections = total_connections;
376 for (i = 0; i < outer_count; i++) 390 for (i = 0; i < outer_count; i++)
377 { 391 {
378 probability = pg->peers[i].num_connections / previous_total_connections; 392 probability = pg->peers[i].num_connections / (double)previous_total_connections;
379 random = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, 393 random = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
380 (uint64_t)-1LL)) / ( (double) (uint64_t) -1LL); 394 (uint64_t)-1LL)) / ( (double) (uint64_t) -1LL);
395#if VERBOSE_TESTING
396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
397 "Considering connecting peer %d to peer %d\n",
398 outer_count, i);
399#endif
381 if (random < probability) 400 if (random < probability)
382 { 401 {
383#if VERBOSE_TESTING 402#if VERBOSE_TESTING
@@ -1099,109 +1118,99 @@ connect_topology (struct GNUNET_TESTING_PeerGroup *pg)
1099 * the connection actually happened. 1118 * the connection actually happened.
1100 * 1119 *
1101 * @param pg the peer group struct representing the running peers 1120 * @param pg the peer group struct representing the running peers
1121 * @param topology which topology to connect the peers in
1102 * 1122 *
1103 * @return the number of connections should be created by the topology, so the 1123 * @return the number of connections should be created by the topology, so the
1104 * caller knows how many to wait for (if it so chooses) 1124 * caller knows how many to wait for (if it so chooses)
1105 * 1125 *
1106 */ 1126 */
1107int 1127int
1108GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg) 1128GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, enum GNUNET_TESTING_Topology topology)
1109{ 1129{
1110 unsigned long long topology_num;
1111 int ret; 1130 int ret;
1112 int num_connections; 1131 int num_connections;
1113 1132
1114 GNUNET_assert (pg->notify_connection != NULL); 1133 GNUNET_assert (pg->notify_connection != NULL);
1115 ret = GNUNET_OK; 1134 ret = GNUNET_OK;
1116 if (GNUNET_YES == 1135
1117 GNUNET_CONFIGURATION_get_value_number (pg->cfg, "testing", "topology", 1136 switch (topology)
1118 &topology_num))
1119 { 1137 {
1120 switch (topology_num) 1138 case GNUNET_TESTING_TOPOLOGY_CLIQUE:
1121 {
1122 case GNUNET_TESTING_TOPOLOGY_CLIQUE:
1123#if VERBOSE_TESTING 1139#if VERBOSE_TESTING
1124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1125 _("Creating clique topology\n")); 1141 _("Creating clique topology\n"));
1126#endif 1142#endif
1127 num_connections = create_clique (pg); 1143 num_connections = create_clique (pg);
1128 break; 1144 break;
1129 case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: 1145 case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING:
1130#if VERBOSE_TESTING 1146#if VERBOSE_TESTING
1131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1132 _("Creating small world (ring) topology\n")); 1148 _("Creating small world (ring) topology\n"));
1133#endif
1134 num_connections = create_small_world_ring (pg);
1135 break;
1136 case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD:
1137#if VERBOSE_TESTING
1138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1139 _("Creating small world (2d-torus) topology\n"));
1140#endif 1149#endif
1141 num_connections = create_small_world (pg); 1150 num_connections = create_small_world_ring (pg);
1142 break; 1151 break;
1143 case GNUNET_TESTING_TOPOLOGY_RING: 1152 case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD:
1144#if VERBOSE_TESTING 1153#if VERBOSE_TESTING
1145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1146 _("Creating ring topology\n")); 1155 _("Creating small world (2d-torus) topology\n"));
1147#endif 1156#endif
1148 num_connections = create_ring (pg); 1157 num_connections = create_small_world (pg);
1149 break; 1158 break;
1150 case GNUNET_TESTING_TOPOLOGY_2D_TORUS: 1159 case GNUNET_TESTING_TOPOLOGY_RING:
1151#if VERBOSE_TESTING 1160#if VERBOSE_TESTING
1152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1153 _("Creating 2d torus topology\n")); 1162 _("Creating ring topology\n"));
1154#endif 1163#endif
1155 num_connections = create_2d_torus (pg); 1164 num_connections = create_ring (pg);
1156 break; 1165 break;
1157 case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: 1166 case GNUNET_TESTING_TOPOLOGY_2D_TORUS:
1158#if VERBOSE_TESTING 1167#if VERBOSE_TESTING
1159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1160 _("Creating Erdos-Renyi topology\n")); 1169 _("Creating 2d torus topology\n"));
1161#endif 1170#endif
1162 num_connections = create_erdos_renyi (pg); 1171 num_connections = create_2d_torus (pg);
1163 break; 1172 break;
1164 case GNUNET_TESTING_TOPOLOGY_INTERNAT: 1173 case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI:
1165#if VERBOSE_TESTING 1174#if VERBOSE_TESTING
1166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1167 _("Creating InterNAT topology\n")); 1176 _("Creating Erdos-Renyi topology\n"));
1168#endif 1177#endif
1169 num_connections = create_nated_internet (pg); 1178 num_connections = create_erdos_renyi (pg);
1170 break; 1179 break;
1171 case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: 1180 case GNUNET_TESTING_TOPOLOGY_INTERNAT:
1172#if VERBOSE_TESTING 1181#if VERBOSE_TESTING
1173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1174 _("Creating Scale Free topology\n")); 1183 _("Creating InterNAT topology\n"));
1175#endif 1184#endif
1176 num_connections = create_scale_free (pg); 1185 num_connections = create_nated_internet (pg);
1177 break; 1186 break;
1178 case GNUNET_TESTING_TOPOLOGY_NONE: 1187 case GNUNET_TESTING_TOPOLOGY_SCALE_FREE:
1179 num_connections = 0;
1180 break;
1181 default:
1182 num_connections = 0;
1183 break;
1184 }
1185 if (num_connections < 1)
1186 return GNUNET_SYSERR;
1187
1188 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", "F2F"))
1189 ret = create_and_copy_friend_files(pg);
1190 if (ret == GNUNET_OK)
1191 connect_topology(pg);
1192 else
1193 {
1194#if VERBOSE_TESTING 1188#if VERBOSE_TESTING
1195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1196 _("Failed during friend file copying!\n")); 1190 _("Creating Scale Free topology\n"));
1197#endif 1191#endif
1198 return GNUNET_SYSERR; 1192 num_connections = create_scale_free (pg);
1199 } 1193 break;
1194 case GNUNET_TESTING_TOPOLOGY_NONE:
1195 num_connections = 0;
1196 break;
1197 default:
1198 num_connections = 0;
1199 break;
1200 } 1200 }
1201 if (num_connections < 1)
1202 return GNUNET_SYSERR;
1203
1204 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", "F2F"))
1205 ret = create_and_copy_friend_files(pg);
1206 if (ret == GNUNET_OK)
1207 connect_topology(pg);
1201 else 1208 else
1202 { 1209 {
1203 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1210#if VERBOSE_TESTING
1204 _("No topology specified, was one intended?\n")); 1211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1212 _("Failed during friend file copying!\n"));
1213#endif
1205 return GNUNET_SYSERR; 1214 return GNUNET_SYSERR;
1206 } 1215 }
1207 1216